From 136135cfd05668a3d3bbebebd79fafb7224bc222 Mon Sep 17 00:00:00 2001 From: Tim Su Date: Wed, 25 Aug 2010 14:58:19 -0700 Subject: [PATCH] Official API support for settings categories --- astrid/AndroidManifest.xml | 7 ++-- .../astrid/api/AstridApiConstants.java | 17 +++++--- .../astrid/rmilk/MilkSyncActionExposer.java | 39 ----------------- .../astrid/activity/EditPreferences.java | 42 ++++++++++++------- 4 files changed, 42 insertions(+), 63 deletions(-) delete mode 100644 astrid/plugin-src/com/todoroo/astrid/rmilk/MilkSyncActionExposer.java diff --git a/astrid/AndroidManifest.xml b/astrid/AndroidManifest.xml index ba6a17e1b..26c17a9f4 100644 --- a/astrid/AndroidManifest.xml +++ b/astrid/AndroidManifest.xml @@ -33,14 +33,14 @@ android:description="@string/read_permission_desc"/> - + - + + diff --git a/astrid/api-src/com/todoroo/astrid/api/AstridApiConstants.java b/astrid/api-src/com/todoroo/astrid/api/AstridApiConstants.java index 349971e19..d31d93bb8 100644 --- a/astrid/api-src/com/todoroo/astrid/api/AstridApiConstants.java +++ b/astrid/api-src/com/todoroo/astrid/api/AstridApiConstants.java @@ -33,7 +33,7 @@ public class AstridApiConstants { // --- Content Provider /** - * URI to append to base content URI for making groupby queries + * URI to append to base content URI for making group-by queries */ public static final String GROUP_BY_URI = "/groupby/"; @@ -136,7 +136,7 @@ public class AstridApiConstants { */ public static final String BROADCAST_SEND_DETAILS = PACKAGE + ".SEND_DETAILS"; - // --- Sync Provider API + // --- Sync Action API /** * Action name for broadcast intent requesting a listing of active @@ -198,17 +198,22 @@ public class AstridApiConstants { */ public static final String ACTION_TASK_LIST_MENU = PACKAGE + ".TASK_LIST_MENU"; - // --- Settings API - /** - * Action name for intents to be displayed in Astrid's settings + * Action name for intents to be displayed in Astrid's settings. By default, + * your application will be put into the category named by your application, + * but you can add a string meta-data with name "category" to override this. */ public static final String ACTION_SETTINGS = PACKAGE + ".SETTINGS"; // --- Events API /** - * Action name for broadcast intent notifying task list to refresh + * Action name for broadcast intent notifying add-ons that Astrid started up + */ + public static final String BROADCAST_EVENT_STARTUP = PACKAGE + ".STARTUP"; + + /** + * Action name for broadcast intent notifying Astrid task list to refresh */ public static final String BROADCAST_EVENT_REFRESH = PACKAGE + ".REFRESH"; diff --git a/astrid/plugin-src/com/todoroo/astrid/rmilk/MilkSyncActionExposer.java b/astrid/plugin-src/com/todoroo/astrid/rmilk/MilkSyncActionExposer.java deleted file mode 100644 index 396709dc7..000000000 --- a/astrid/plugin-src/com/todoroo/astrid/rmilk/MilkSyncActionExposer.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * See the file "LICENSE" for the full license governing this code. - */ -package com.todoroo.astrid.rmilk; - -import android.app.PendingIntent; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; - -import com.timsu.astrid.R; -import com.todoroo.astrid.api.AstridApiConstants; -import com.todoroo.astrid.api.SyncAction; - -/** - * Exposes sync action - * - */ -public class MilkSyncActionExposer extends BroadcastReceiver { - - @Override - public void onReceive(Context context, Intent intent) { - // if we aren't logged in, don't expose sync action - if(!MilkUtilities.isLoggedIn()) - return; - - Intent syncIntent = new Intent(MilkBackgroundService.SYNC_ACTION, null, - context, MilkBackgroundService.class); - PendingIntent pendingIntent = PendingIntent.getService(context, 0, syncIntent, PendingIntent.FLAG_UPDATE_CURRENT); - SyncAction syncAction = new SyncAction(context.getString(R.string.rmilk_MPr_header), - pendingIntent); - - Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_SYNC_ACTIONS); - broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, MilkUtilities.IDENTIFIER); - broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, syncAction); - context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ); - } - -} diff --git a/astrid/src/com/todoroo/astrid/activity/EditPreferences.java b/astrid/src/com/todoroo/astrid/activity/EditPreferences.java index f435100ba..e7a897875 100644 --- a/astrid/src/com/todoroo/astrid/activity/EditPreferences.java +++ b/astrid/src/com/todoroo/astrid/activity/EditPreferences.java @@ -14,9 +14,9 @@ import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.os.Bundle; import android.preference.Preference; +import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceCategory; import android.preference.PreferenceScreen; -import android.preference.Preference.OnPreferenceClickListener; import android.widget.Toast; import com.timsu.astrid.R; @@ -30,8 +30,6 @@ import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.dao.Database; import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.model.Task; -import com.todoroo.astrid.producteev.ProducteevPreferences; -import com.todoroo.astrid.rmilk.MilkPreferences; import com.todoroo.astrid.service.StartupService; import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.utility.Constants; @@ -46,6 +44,8 @@ import com.todoroo.astrid.utility.Preferences; */ public class EditPreferences extends TodorooPreferences { + private static final String METADATA_CATEGORY = "category";//$NON-NLS-1$ + // --- instance variables @Autowired @@ -80,9 +80,10 @@ public class EditPreferences extends TodorooPreferences { // load plug-ins Intent queryIntent = new Intent(AstridApiConstants.ACTION_SETTINGS); PackageManager pm = getPackageManager(); - List resolveInfoList = pm.queryIntentActivities(queryIntent, 0); + List resolveInfoList = pm.queryIntentActivities(queryIntent, + PackageManager.GET_META_DATA); int length = resolveInfoList.size(); - LinkedHashMap> applicationPreferences = + LinkedHashMap> categoryPreferences = new LinkedHashMap>(); for(int i = 0; i < length; i++) { ResolveInfo resolveInfo = resolveInfoList.get(i); @@ -94,20 +95,31 @@ public class EditPreferences extends TodorooPreferences { preference.setTitle(resolveInfo.activityInfo.loadLabel(pm)); preference.setIntent(intent); - String application = resolveInfo.activityInfo.applicationInfo.loadLabel(pm).toString(); - - // temporary overrides - if(ProducteevPreferences.class.getName().equals(resolveInfo.activityInfo.name) || - MilkPreferences.class.getName().equals(resolveInfo.activityInfo.name)) - application = getString(R.string.SyP_label); + // category - either from metadata, or the application name + String category = null; + if(resolveInfo.activityInfo.metaData != null && + resolveInfo.activityInfo.metaData.containsKey(METADATA_CATEGORY)) { + int resource = resolveInfo.activityInfo.metaData.getInt(METADATA_CATEGORY, -1); + if(resource > -1) { + try { + category = pm.getResourcesForApplication(resolveInfo.activityInfo.applicationInfo).getString(resource); + } catch (Exception e) { + // + } + } else { + category = resolveInfo.activityInfo.metaData.getString(METADATA_CATEGORY); + } + } + if(category == null) + category = resolveInfo.activityInfo.applicationInfo.loadLabel(pm).toString(); - if(!applicationPreferences.containsKey(application)) - applicationPreferences.put(application, new ArrayList()); - ArrayList arrayList = applicationPreferences.get(application); + if(!categoryPreferences.containsKey(category)) + categoryPreferences.put(category, new ArrayList()); + ArrayList arrayList = categoryPreferences.get(category); arrayList.add(preference); } - for(Entry> entry : applicationPreferences.entrySet()) { + for(Entry> entry : categoryPreferences.entrySet()) { Preference header = new Preference(this); header.setLayoutResource(android.R.layout.preference_category); header.setTitle(entry.getKey());