Refactored some things to better specify plugin preference groups from the manifest

pull/14/head
Sam Bosley 12 years ago
parent 219fd78678
commit 3e25e0fb8a

@ -149,7 +149,10 @@
<string name="SyP_progress_toast">Synchronizing...</string>
<!-- Sync Label: used in menu to denote synchronization -->
<string name="SyP_label">Synchronization</string>
<string name="SyP_label">Sync &amp; Backup</string>
<!-- Sync label subtitle -->
<string name="SyP_summary">Astrid.com, Google Tasks, Saved Data &amp; Local Backup</string>
<!-- Error msg when io exception -->
<string name="SyP_ioerror">Connection Error! Check your Internet connection.</string>

@ -265,6 +265,8 @@
<activity android:name="com.todoroo.astrid.core.DefaultsPreferences"
android:theme="@android:style/Theme"
android:label="@string/EPr_defaults_header">
<meta-data android:name="summary"
android:resource="@string/EPr_defaults_summary" />
<intent-filter>
<action android:name="com.todoroo.astrid.SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
@ -273,24 +275,6 @@
<activity android:name="com.todoroo.astrid.activity.BeastModePreferences"
android:theme="@android:style/Theme">
</activity>
<activity android:name="com.todoroo.astrid.core.OldTaskPreferences"
android:theme="@android:style/Theme"
android:label="@string/EPr_manage_header">
<intent-filter>
<action android:name="com.todoroo.astrid.SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.todoroo.astrid.core.LabsPreferences"
android:theme="@android:style/Theme"
android:label="@string/EPr_labs_header">
<intent-filter>
<action android:name="com.todoroo.astrid.SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.todoroo.astrid.calls.MissedCallActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
@ -502,6 +486,18 @@
</intent-filter>
</receiver>
<!-- old tasks -->
<activity android:name="com.todoroo.astrid.core.OldTaskPreferences"
android:theme="@android:style/Theme"
android:label="@string/EPr_manage_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" />
</intent-filter>
</activity>
<!-- backup -->
<service android:name="com.todoroo.astrid.backup.BackupService"/>
<activity android:name="com.todoroo.astrid.backup.BackupActivity"
@ -509,6 +505,8 @@
<activity android:name="com.todoroo.astrid.backup.BackupPreferences"
android:theme="@android:style/Theme"
android:label="@string/backup_BPr_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" />
@ -569,6 +567,8 @@
<activity android:name="com.todoroo.astrid.reminders.ReminderPreferences"
android:theme="@android:style/Theme"
android:label="@string/rmd_EPr_alerts_header">
<meta-data android:name="summary"
android:resource="@string/rmd_EPr_alerts_summary" />
<intent-filter>
<action android:name="com.todoroo.astrid.SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />

@ -8,6 +8,7 @@
<!-- slide 32g: Preference Category: Defaults Title -->
<string name="EPr_defaults_header">New Task Defaults</string>
<string name="EPr_defaults_summary">Importance, Due Date, Add to Calendar</string>
<!-- slide 41f: Preference: Default Urgency Title -->
<string name="EPr_default_urgency_title">Default Urgency</string>

@ -10,6 +10,7 @@
<!-- slide 32j: Preference Category: Power Pack -->
<string name="EPr_powerpack_header">Premium and Misc. Settings</string>
<string name="EPr_powerpack_summary">Missed call reminders, voice input and miscellaneous settings</string>
<!-- slide 32e: Preference: Anonymous User Statistics -->
<string name="EPr_statistics_title">Anonymous Usage Stats</string>

@ -105,6 +105,7 @@
<!-- slide 33d: Reminder Preference Screen Title -->
<string name="rmd_EPr_alerts_header">Reminder Settings</string>
<string name="rmd_EPr_alerts_summary">Quiet hours, snooze options, persistence level</string>
<!-- Reminder Preference: Reminders Enabled Title -->
<string name="rmd_EPr_enabled_title">Reminders Enabled?</string>

@ -101,7 +101,8 @@
<PreferenceScreen
android:title="@string/EPr_powerpack_header">
android:title="@string/EPr_powerpack_header"
android:summary="@string/EPr_powerpack_summary">
<PreferenceScreen android:title="@string/p_files_dir" android:key="@string/p_files_dir" />

@ -5,12 +5,21 @@
*/
package com.todoroo.astrid.activity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map.Entry;
import org.weloveastrid.rmilk.MilkPreferences;
import org.weloveastrid.rmilk.MilkUtilities;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
@ -20,6 +29,7 @@ import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory;
import android.preference.PreferenceGroup;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.text.TextUtils;
import android.widget.Toast;
@ -41,7 +51,12 @@ import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.files.FileExplore;
import com.todoroo.astrid.files.FileMetadata;
import com.todoroo.astrid.gtasks.GtasksPreferences;
import com.todoroo.astrid.helper.MetadataHelper;
import com.todoroo.astrid.producteev.ProducteevPreferences;
import com.todoroo.astrid.producteev.ProducteevUtilities;
import com.todoroo.astrid.service.AddOnService;
import com.todoroo.astrid.service.MarketStrategy.AmazonMarketStrategy;
import com.todoroo.astrid.service.StartupService;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
@ -118,7 +133,7 @@ public class EditPreferences extends TodorooPreferenceActivity {
PreferenceScreen screen = getPreferenceScreen();
voiceInputAssistant = new VoiceInputAssistant(this);
// addPluginPreferences(screen);
addPluginPreferences(screen);
screen.getPreference(POWER_PACK_PREFERENCE).setEnabled(addOnService.hasPowerPack());
@ -249,78 +264,90 @@ public class EditPreferences extends TodorooPreferenceActivity {
// PREFERENCE_REQUEST_CODES.put(LabsPreferences.class, REQUEST_CODE_LABS);
}
// private void addPluginPreferences(PreferenceScreen screen) {
// Intent queryIntent = new Intent(AstridApiConstants.ACTION_SETTINGS);
// PackageManager pm = getPackageManager();
// List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(queryIntent,
// PackageManager.GET_META_DATA);
// int length = resolveInfoList.size();
// LinkedHashMap<String, ArrayList<Preference>> categoryPreferences =
// new LinkedHashMap<String, ArrayList<Preference>>();
//
// // Loop through a list of all packages (including plugins, addons)
// // that have a settings action
// String labsTitle = getString(R.string.EPr_labs_header);
// for(int i = 0; i < length; i++) {
// ResolveInfo resolveInfo = resolveInfoList.get(i);
// final Intent intent = new Intent(AstridApiConstants.ACTION_SETTINGS);
// intent.setClassName(resolveInfo.activityInfo.packageName,
// resolveInfo.activityInfo.name);
//
// if(MilkPreferences.class.getName().equals(resolveInfo.activityInfo.name) &&
// !MilkUtilities.INSTANCE.isLoggedIn())
// continue;
//
// if (GtasksPreferences.class.getName().equals(resolveInfo.activityInfo.name)
// && AmazonMarketStrategy.isKindleFire())
// continue;
//
// if (ProducteevPreferences.class.getName().equals(resolveInfo.activityInfo.name)
// && !Preferences.getBoolean(R.string.p_third_party_addons, false) && !ProducteevUtilities.INSTANCE.isLoggedIn())
// continue;
//
// Preference preference = new Preference(this);
// preference.setTitle(resolveInfo.activityInfo.loadLabel(pm));
// if (labsTitle.equals(preference.getTitle()))
// preference.setSummary(R.string.EPr_labs_desc);
// try {
// Class<?> intentComponent = Class.forName(intent.getComponent().getClassName());
// if (intentComponent.getSuperclass().equals(SyncProviderPreferences.class))
// intentComponent = SyncProviderPreferences.class;
// if (PREFERENCE_REQUEST_CODES.containsKey(intentComponent)) {
// final int code = PREFERENCE_REQUEST_CODES.get(intentComponent);
// preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
// @Override
// public boolean onPreferenceClick(Preference pref) {
// startActivityForResult(intent, code);
// return true;
// }
// });
// } else {
// preference.setIntent(intent);
// }
// } catch (ClassNotFoundException e) {
// preference.setIntent(intent);
// }
//
// String category = MetadataHelper.resolveActivityCategoryName(resolveInfo, pm);
//
// 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 : categoryPreferences.entrySet()) {
// Preference header = new Preference(this);
// header.setLayoutResource(android.R.layout.preference_category);
// header.setTitle(entry.getKey());
// screen.addPreference(header);
//
// for(Preference preference : entry.getValue())
// screen.addPreference(preference);
// }
// }
private void addPluginPreferences(PreferenceScreen screen) {
Intent queryIntent = new Intent(AstridApiConstants.ACTION_SETTINGS);
PackageManager pm = getPackageManager();
List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(queryIntent,
PackageManager.GET_META_DATA);
int length = resolveInfoList.size();
LinkedHashMap<String, ArrayList<Preference>> categoryPreferences =
new LinkedHashMap<String, ArrayList<Preference>>();
// Loop through a list of all packages (including plugins, addons)
// that have a settings action
for(int i = 0; i < length; i++) {
ResolveInfo resolveInfo = resolveInfoList.get(i);
final Intent intent = new Intent(AstridApiConstants.ACTION_SETTINGS);
intent.setClassName(resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name);
if(MilkPreferences.class.getName().equals(resolveInfo.activityInfo.name) &&
!MilkUtilities.INSTANCE.isLoggedIn())
continue;
if (GtasksPreferences.class.getName().equals(resolveInfo.activityInfo.name)
&& AmazonMarketStrategy.isKindleFire())
continue;
if (ProducteevPreferences.class.getName().equals(resolveInfo.activityInfo.name)
&& !Preferences.getBoolean(R.string.p_third_party_addons, false) && !ProducteevUtilities.INSTANCE.isLoggedIn())
continue;
Preference preference = new Preference(this);
preference.setTitle(resolveInfo.activityInfo.loadLabel(pm));
Bundle metadata = resolveInfo.activityInfo.metaData;
if (metadata != null) {
int resource = metadata.getInt("summary", 0); //$NON-NLS-1$
if (resource > 0)
preference.setSummary(resource);
}
try {
Class<?> intentComponent = Class.forName(intent.getComponent().getClassName());
if (intentComponent.getSuperclass().equals(SyncProviderPreferences.class))
intentComponent = SyncProviderPreferences.class;
if (PREFERENCE_REQUEST_CODES.containsKey(intentComponent)) {
final int code = PREFERENCE_REQUEST_CODES.get(intentComponent);
preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference pref) {
startActivityForResult(intent, code);
return true;
}
});
} else {
preference.setIntent(intent);
}
} catch (ClassNotFoundException e) {
preference.setIntent(intent);
}
String category = MetadataHelper.resolveActivityCategoryName(resolveInfo, pm);
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 : categoryPreferences.entrySet()) {
if (entry.getKey().equals(getString(R.string.app_name))) {
for(Preference preference : entry.getValue())
screen.addPreference(preference);
} else {
PreferenceManager manager = getPreferenceManager();
PreferenceScreen header = manager.createPreferenceScreen(this);
header.setTitle(entry.getKey());
if (entry.getKey().equals(getString(R.string.SyP_label)))
header.setSummary(R.string.SyP_summary);
screen.addPreference(header);
for(Preference preference : entry.getValue())
header.addPreference(preference);
}
}
}
@SuppressWarnings("nls")
private void addDebugPreferences() {

Loading…
Cancel
Save