From a420730b1849b16137882c527b064a9c473eabe1 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Thu, 30 Aug 2012 12:53:42 -0700 Subject: [PATCH] Fixed WidgetConfig filter theming issue --- .../astrid/core/CoreFilterExposer.java | 4 +--- .../astrid/core/CustomFilterExposer.java | 7 ++----- .../todoroo/astrid/tags/TagFilterExposer.java | 3 +-- .../todoroo/astrid/service/ThemeService.java | 20 +++++++++++++++++++ .../astrid/widget/WidgetConfigActivity.java | 3 ++- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/core/CoreFilterExposer.java b/astrid/plugin-src/com/todoroo/astrid/core/CoreFilterExposer.java index a4cf15ce0..b4f1e171a 100644 --- a/astrid/plugin-src/com/todoroo/astrid/core/CoreFilterExposer.java +++ b/astrid/plugin-src/com/todoroo/astrid/core/CoreFilterExposer.java @@ -27,7 +27,6 @@ import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.TaskApiDao.TaskCriteria; import com.todoroo.astrid.service.ThemeService; import com.todoroo.astrid.tags.TagService; -import com.todoroo.astrid.utility.AstridPreferences; /** * Exposes Astrid's built in filters to the {@link FilterListFragment} @@ -70,8 +69,7 @@ public final class CoreFilterExposer extends BroadcastReceiver implements Astrid Criterion.and(MetadataCriteria.withKey(TagService.KEY), TagService.TAG.like("x_%", "x"))))))), //$NON-NLS-1$ //$NON-NLS-2$ null); - boolean isTablet = AstridPreferences.useTabletLayout(ContextManager.getContext()); - int themeFlags = isTablet ? ThemeService.FLAG_FORCE_LIGHT : 0; + int themeFlags = ThemeService.getFilterThemeFlags(); inbox.listingIcon = ((BitmapDrawable)r.getDrawable( ThemeService.getDrawable(R.drawable.filter_inbox, themeFlags))).getBitmap(); return inbox; diff --git a/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterExposer.java b/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterExposer.java index 8b464c006..0507e7ac3 100644 --- a/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterExposer.java +++ b/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterExposer.java @@ -43,7 +43,6 @@ import com.todoroo.astrid.gtasks.GtasksPreferenceService; import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.service.ThemeService; import com.todoroo.astrid.taskrabbit.TaskRabbitMetadata; -import com.todoroo.astrid.utility.AstridPreferences; /** * Exposes Astrid's built in filters to the {@link FilterListFragment} @@ -78,8 +77,7 @@ public final class CustomFilterExposer extends BroadcastReceiver implements Astr } private Filter[] buildSavedFilters(Context context, Resources r) { - boolean isTablet = AstridPreferences.useTabletLayout(context); - int themeFlags = isTablet ? ThemeService.FLAG_FORCE_LIGHT : 0; + int themeFlags = ThemeService.getFilterThemeFlags(); StoreObjectDao dao = PluginServices.getStoreObjectDao(); TodorooCursor cursor = dao.query(Query.select(StoreObject.PROPERTIES).where( @@ -134,8 +132,7 @@ public final class CustomFilterExposer extends BroadcastReceiver implements Astr } public static Filter getAssignedByMeFilter(Resources r) { - boolean isTablet = AstridPreferences.useTabletLayout(ContextManager.getContext()); - int themeFlags = isTablet ? ThemeService.FLAG_FORCE_LIGHT : 0; + int themeFlags = ThemeService.getFilterThemeFlags(); Filter f = new Filter(r.getString(R.string.BFE_Assigned), r.getString(R.string.BFE_Assigned), new QueryTemplate().join(Join.left(Metadata.TABLE, Criterion.and(Metadata.KEY.eq(TaskRabbitMetadata.METADATA_KEY), Task.ID.eq(Metadata.TASK)))) diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/TagFilterExposer.java b/astrid/plugin-src/com/todoroo/astrid/tags/TagFilterExposer.java index 5b5c192f3..a8f5d50df 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/TagFilterExposer.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/TagFilterExposer.java @@ -167,8 +167,7 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE Context context = ContextManager.getContext(); Resources r = context.getResources(); - boolean isTablet = AstridPreferences.useTabletLayout(context); - int themeFlags = isTablet ? ThemeService.FLAG_FORCE_LIGHT : 0; + int themeFlags = ThemeService.getFilterThemeFlags(); // --- untagged if (addUntaggedFilter) { diff --git a/astrid/src/com/todoroo/astrid/service/ThemeService.java b/astrid/src/com/todoroo/astrid/service/ThemeService.java index 2a06b25b2..c2dd69132 100644 --- a/astrid/src/com/todoroo/astrid/service/ThemeService.java +++ b/astrid/src/com/todoroo/astrid/service/ThemeService.java @@ -35,6 +35,10 @@ public class ThemeService { private static int currentTheme; + // Widget config activities set this flag since they theme differently than the normal + // filter list. In other cases this should be false + private static boolean forceFilterInvert = false; + public static void applyTheme(Activity activity) { currentTheme = getTheme(); activity.setTheme(currentTheme); @@ -124,6 +128,22 @@ public class ThemeService { return getDrawable(lightDrawable, 0); } + /** + * Only widget config activities should call this (see note on the flag above) + * @param forceInvert + */ + public static void setForceFilterInvert(boolean forceInvert) { + forceFilterInvert = forceInvert; + } + + public static int getFilterThemeFlags() { + if (forceFilterInvert) + return ThemeService.FLAG_INVERT; + if (AstridPreferences.useTabletLayout(ContextManager.getContext())) + return ThemeService.FLAG_FORCE_LIGHT; + return 0; + } + public static int getDrawable(int lightDrawable, int alter) { boolean darkTheme = currentTheme == R.style.Theme || currentTheme == R.style.Theme_Transparent; switch(alter) { diff --git a/astrid/src/com/todoroo/astrid/widget/WidgetConfigActivity.java b/astrid/src/com/todoroo/astrid/widget/WidgetConfigActivity.java index 84f3cab7f..884808422 100644 --- a/astrid/src/com/todoroo/astrid/widget/WidgetConfigActivity.java +++ b/astrid/src/com/todoroo/astrid/widget/WidgetConfigActivity.java @@ -48,7 +48,7 @@ abstract public class WidgetConfigActivity extends ListActivity { @Override public void onCreate(Bundle icicle) { ThemeService.applyTheme(this); - ThemeService.forceTheme(R.style.Theme); + ThemeService.setForceFilterInvert(true); super.onCreate(icicle); // Set the result to CANCELED. This will cause the widget host to cancel @@ -132,6 +132,7 @@ abstract public class WidgetConfigActivity extends ListActivity { protected void onStop() { super.onStop(); StatisticsService.sessionStop(this); + ThemeService.setForceFilterInvert(false); } private void saveConfiguration(FilterListItem filterListItem){