Official API support for settings categories

pull/14/head
Tim Su 14 years ago
parent 33ae2cad02
commit 136135cfd0

@ -33,14 +33,14 @@
android:description="@string/read_permission_desc"/>
<uses-permission android:name="com.timsu.astrid.permission.READ_TASKS"/>
<!-- for reading data from plugins or astrid via v3 content provider -->
<!-- for reading data from add-ons or astrid via v3 content provider -->
<permission android:name="com.todoroo.astrid.READ"
android:description="@string/read_permission_desc"
android:protectionLevel="normal"
android:label="@string/read_permission_label" />
<uses-permission android:name="com.todoroo.astrid.READ" />
<!-- for writing data to plugins or astrid via v3 content provider -->
<!-- for writing data to add-ons or astrid via v3 content provider -->
<permission android:name="com.todoroo.astrid.WRITE"
android:description="@string/write_permission_desc"
android:protectionLevel="normal"
@ -358,8 +358,9 @@
</intent-filter>
</receiver>
<activity android:name="com.todoroo.astrid.producteev.ProducteevPreferences"
android:icon="@drawable/ic_menu_producteev"
android:label="@string/producteev_PPr_header">
<meta-data android:name="category"
android:resource="@string/SyP_label" />
<intent-filter>
<action android:name="com.todoroo.astrid.SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />

@ -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";

@ -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);
}
}

@ -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<ResolveInfo> resolveInfoList = pm.queryIntentActivities(queryIntent, 0);
List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(queryIntent,
PackageManager.GET_META_DATA);
int length = resolveInfoList.size();
LinkedHashMap<String, ArrayList<Preference>> applicationPreferences =
LinkedHashMap<String, ArrayList<Preference>> categoryPreferences =
new LinkedHashMap<String, ArrayList<Preference>>();
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<Preference>());
ArrayList<Preference> arrayList = applicationPreferences.get(application);
if(!categoryPreferences.containsKey(category))
categoryPreferences.put(category, new ArrayList<Preference>());
ArrayList<Preference> arrayList = categoryPreferences.get(category);
arrayList.add(preference);
}
for(Entry<String, ArrayList<Preference>> entry : applicationPreferences.entrySet()) {
for(Entry<String, ArrayList<Preference>> entry : categoryPreferences.entrySet()) {
Preference header = new Preference(this);
header.setLayoutResource(android.R.layout.preference_category);
header.setTitle(entry.getKey());

Loading…
Cancel
Save