Removed labs preferences, more reorganizing of pref screens, temporarily removed plugin prefs structure

pull/14/head
Sam Bosley 13 years ago
parent 12f7da7bf8
commit 219fd78678

@ -30,7 +30,7 @@ import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.core.LabsPreferences;
import com.todoroo.astrid.activity.EditPreferences;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.reminders.NotificationFragment.SnoozeDialog;
import com.todoroo.astrid.reminders.Notifications;
@ -168,7 +168,7 @@ public class MissedCallActivity extends Activity {
ignoreSettingsButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent labsPreferences = new Intent(MissedCallActivity.this, LabsPreferences.class);
Intent labsPreferences = new Intent(MissedCallActivity.this, EditPreferences.class);
startActivity(labsPreferences);
finish();
}

@ -1,103 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.core;
import android.content.res.Resources;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceScreen;
import android.text.TextUtils;
import com.timsu.astrid.R;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.TodorooPreferenceActivity;
import com.todoroo.astrid.activity.EditPreferences;
import com.todoroo.astrid.utility.Constants;
public class LabsPreferences extends TodorooPreferenceActivity {
@Override
public int getPreferenceResource() {
return R.xml.preferences_labs;
}
public static final int RESULT_TLA_NEEDS_REFRESH = 3;
public static final int RESULT_NEEDS_SYNC = 4;
private class SetResultOnPreferenceChangeListener implements OnPreferenceChangeListener {
private final int resultCode;
public SetResultOnPreferenceChangeListener(int resultCode) {
this.resultCode = resultCode;
}
@Override
public boolean onPreferenceChange(Preference p, Object newValue) {
setResult(resultCode);
updatePreferences(p, newValue);
return true;
}
}
@Override
public void onCreate(android.os.Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EditPreferences.removeForbiddenPreferences(getPreferenceScreen(), getResources());
if (!AndroidUtilities.isTabletSized(this)) {
PreferenceScreen screen = getPreferenceScreen();
screen.removePreference(screen.findPreference(getString(R.string.p_force_phone_layout)));
}
}
@Override
public void updatePreferences(Preference preference, Object value) {
final Resources r = getResources();
String key = preference.getKey();
if (r.getString(R.string.p_swipe_lists_performance_key).equals(key)) {
preference.setOnPreferenceChangeListener(new SetResultOnPreferenceChangeListener(RESULT_TLA_NEEDS_REFRESH));
int index = 0;
if(value instanceof String && !TextUtils.isEmpty((String)value))
index = AndroidUtilities.indexOf(r.getStringArray(R.array.EPr_swipe_lists_performance_mode_values), (String)value);
if (index < 0)
index = 0;
String name = r.getStringArray(R.array.EPr_swipe_lists_performance_mode)[index];
String desc = r.getStringArray(R.array.EPr_swipe_lists_performance_desc)[index];
preference.setSummary(r.getString(R.string.EPr_swipe_lists_display, name, desc));
} else if (r.getString(R.string.p_field_missed_calls).equals(key)) {
setEnabledSummary(preference, value,
R.string.MCA_missed_calls_pref_desc_enabled, R.string.MCA_missed_calls_pref_desc_disabled);
} else if (r.getString(R.string.p_use_contact_picker).equals(key)) {
setEnabledSummary(preference, value,
R.string.EPr_use_contact_picker_desc_enabled, R.string.EPr_use_contact_picker_desc_disabled);
} else if (r.getString(R.string.p_third_party_addons).equals(key)) {
setEnabledSummary(preference, value,
R.string.EPr_third_party_addons_desc_enabled, R.string.EPr_third_party_addons_desc_disabled);
} else if (r.getString(R.string.p_end_at_deadline).equals(key)){
setEnabledSummary(preference, value, R.string.EPr_cal_start_at_due_time, R.string.EPr_cal_end_at_due_time);
} else if (r.getString(R.string.p_ideas_tab_enabled).equals(key)) {
if (!Constants.MARKET_STRATEGY.allowIdeasTab()) {
PreferenceScreen screen = getPreferenceScreen();
screen.removePreference(preference);
}
} else if (r.getString(R.string.p_force_phone_layout).equals(key)) {
preference.setOnPreferenceChangeListener(new SetResultOnPreferenceChangeListener(RESULT_TLA_NEEDS_REFRESH));
} else if (r.getString(R.string.p_show_featured_lists_labs).equals(key)) {
preference.setOnPreferenceChangeListener(new SetResultOnPreferenceChangeListener(RESULT_NEEDS_SYNC));
}
}
private void setEnabledSummary(Preference preference, Object value, int enabledStr, int disabledStr) {
if (value != null && (Boolean) value) {
preference.setSummary(enabledStr);
} else {
preference.setSummary(disabledStr);
}
}
}

@ -9,7 +9,7 @@
<!-- ================================================== EditPreferences == -->
<!-- slide 32j: Preference Category: Power Pack -->
<string name="EPr_powerpack_header">Astrid Power Pack</string>
<string name="EPr_powerpack_header">Premium and Misc. Settings</string>
<!-- slide 32e: Preference: Anonymous User Statistics -->
<string name="EPr_statistics_title">Anonymous Usage Stats</string>

@ -75,11 +75,32 @@
android:key="@string/p_autoIdea"
android:title="@string/EPr_ideaAuto_title"
android:defaultValue="true" />
<CheckBoxPreference
android:title="@string/EPr_force_phone_layout"
android:key="@string/p_force_phone_layout"
android:defaultValue="false"/>
<CheckBoxPreference
android:title="@string/EPr_show_featured_lists"
android:key="@string/p_show_featured_lists_labs"
android:defaultValue="false"/>
<CheckBoxPreference
android:key="@string/p_use_contact_picker"
android:title="@string/EPr_use_contact_picker"/>
<ListPreference
android:key="@string/p_swipe_lists_performance_key"
android:title="@string/EPr_swipe_lists_performance_title"
android:entries="@array/EPr_swipe_lists_performance_mode"
android:entryValues="@array/EPr_swipe_lists_performance_mode_values"
android:summary="@string/EPr_swipe_lists_performance_subtitle" />
</PreferenceScreen>
<PreferenceCategory
<PreferenceScreen
android:title="@string/EPr_powerpack_header">
<PreferenceScreen android:title="@string/p_files_dir" android:key="@string/p_files_dir" />
@ -106,12 +127,29 @@
</PreferenceScreen>
<CheckBoxPreference
android:key="@string/p_field_missed_calls"
android:title="@string/MCA_missed_calls_pref_title"/>
<CheckBoxPreference
android:key="@string/p_third_party_addons"
android:title="@string/EPr_third_party_addons" />
<CheckBoxPreference
android:key="@string/p_ideas_tab_enabled"
android:title="@string/EPr_ideas_tab_enabled"
android:summary="@string/EPr_ideas_tab_description" />
<CheckBoxPreference
android:title="@string/EPr_cal_end_or_start_at_due_time"
android:key = "@string/p_end_at_deadline" />
<com.todoroo.astrid.ui.MultilineCheckboxPreference
android:key="@string/p_statistics"
android:title="@string/EPr_statistics_title"
android:defaultValue="true" />
</PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>

@ -1,42 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
** Copyright (c) 2012 Todoroo Inc
**
** See the file "LICENSE" for the full license governing this code.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/EPr_labs_header"
android:summary="@string/EPr_labs_desc">
<ListPreference
android:key="@string/p_swipe_lists_performance_key"
android:title="@string/EPr_swipe_lists_performance_title"
android:entries="@array/EPr_swipe_lists_performance_mode"
android:entryValues="@array/EPr_swipe_lists_performance_mode_values"
android:summary="@string/EPr_swipe_lists_performance_subtitle" />
<CheckBoxPreference
android:key="@string/p_use_contact_picker"
android:title="@string/EPr_use_contact_picker"/>
<CheckBoxPreference
android:key="@string/p_field_missed_calls"
android:title="@string/MCA_missed_calls_pref_title"/>
<CheckBoxPreference
android:key="@string/p_third_party_addons"
android:title="@string/EPr_third_party_addons" />
<CheckBoxPreference
android:key="@string/p_ideas_tab_enabled"
android:title="@string/EPr_ideas_tab_enabled"
android:summary="@string/EPr_ideas_tab_description" />
<CheckBoxPreference
android:title="@string/EPr_cal_end_or_start_at_due_time"
android:key = "@string/p_end_at_deadline" />
<CheckBoxPreference
android:title="@string/EPr_force_phone_layout"
android:key="@string/p_force_phone_layout"
android:defaultValue="false"/>
<CheckBoxPreference
android:title="@string/EPr_show_featured_lists"
android:key="@string/p_show_featured_lists_labs"
android:defaultValue="false"/>
</PreferenceScreen>

@ -5,21 +5,12 @@
*/
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;
@ -46,17 +37,11 @@ import com.todoroo.andlib.utility.Preferences;
import com.todoroo.andlib.utility.TodorooPreferenceActivity;
import com.todoroo.astrid.actfm.ActFmLoginActivity;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.core.LabsPreferences;
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;
@ -85,7 +70,7 @@ public class EditPreferences extends TodorooPreferenceActivity {
private static final int POWER_PACK_PREFERENCE = 2;
private static final int REQUEST_CODE_SYNC = 0;
private static final int REQUEST_CODE_LABS = 1;
// private static final int REQUEST_CODE_LABS = 1;
private static final int REQUEST_CODE_FILES_DIR = 2;
public static final int RESULT_CODE_THEME_CHANGED = 1;
@ -105,6 +90,20 @@ public class EditPreferences extends TodorooPreferenceActivity {
DependencyInjectionService.getInstance().inject(this);
}
private class SetResultOnPreferenceChangeListener implements OnPreferenceChangeListener {
private final int resultCode;
public SetResultOnPreferenceChangeListener(int resultCode) {
this.resultCode = resultCode;
}
@Override
public boolean onPreferenceChange(Preference p, Object newValue) {
setResult(resultCode);
updatePreferences(p, newValue);
return true;
}
}
@Override
public int getPreferenceResource() {
return R.xml.preferences;
@ -119,7 +118,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());
@ -180,6 +179,10 @@ public class EditPreferences extends TodorooPreferenceActivity {
addPreferenceListeners();
if (!AndroidUtilities.isTabletSized(this)) {
screen.removePreference(screen.findPreference(getString(R.string.p_force_phone_layout)));
}
removeForbiddenPreferences(screen, r);
}
@ -243,81 +246,81 @@ public class EditPreferences extends TodorooPreferenceActivity {
private static final HashMap<Class<?>, Integer> PREFERENCE_REQUEST_CODES = new HashMap<Class<?>, Integer>();
static {
PREFERENCE_REQUEST_CODES.put(SyncProviderPreferences.class, REQUEST_CODE_SYNC);
PREFERENCE_REQUEST_CODES.put(LabsPreferences.class, REQUEST_CODE_LABS);
// 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
// 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);
// }
// }
@SuppressWarnings("nls")
private void addDebugPreferences() {
@ -440,7 +443,32 @@ public class EditPreferences extends TodorooPreferenceActivity {
R.string.EPr_statistics_desc_disabled, R.string.EPr_statistics_desc_enabled));
else if (booleanPreference(preference, value, R.string.p_autoIdea,
R.string.EPr_ideaAuto_desc_disabled, R.string.EPr_ideaAuto_desc_enabled));
else if (r.getString(R.string.p_swipe_lists_performance_key).equals(preference.getKey())) {
preference.setOnPreferenceChangeListener(new SetResultOnPreferenceChangeListener(RESULT_CODE_PERFORMANCE_PREF_CHANGED));
int index = 0;
if(value instanceof String && !TextUtils.isEmpty((String)value))
index = AndroidUtilities.indexOf(r.getStringArray(R.array.EPr_swipe_lists_performance_mode_values), (String)value);
if (index < 0)
index = 0;
String name = r.getStringArray(R.array.EPr_swipe_lists_performance_mode)[index];
String desc = r.getStringArray(R.array.EPr_swipe_lists_performance_desc)[index];
preference.setSummary(r.getString(R.string.EPr_swipe_lists_display, name, desc));
}
else if (booleanPreference(preference, value, R.string.p_field_missed_calls,
R.string.MCA_missed_calls_pref_desc_enabled, R.string.MCA_missed_calls_pref_desc_disabled));
else if (booleanPreference(preference, value, R.string.p_use_contact_picker,
R.string.EPr_use_contact_picker_desc_enabled, R.string.EPr_use_contact_picker_desc_disabled));
else if (booleanPreference(preference, value, R.string.p_third_party_addons,
R.string.EPr_third_party_addons_desc_enabled, R.string.EPr_third_party_addons_desc_disabled));
else if (booleanPreference(preference, value, R.string.p_end_at_deadline,
R.string.EPr_cal_start_at_due_time, R.string.EPr_cal_end_at_due_time));
else if (r.getString(R.string.p_force_phone_layout).equals(preference.getKey())) {
preference.setOnPreferenceChangeListener(new SetResultOnPreferenceChangeListener(RESULT_CODE_PERFORMANCE_PREF_CHANGED));
} else if (r.getString(R.string.p_show_featured_lists_labs).equals(preference.getKey())) {
preference.setOnPreferenceChangeListener(new SetResultOnPreferenceChangeListener(SyncProviderPreferences.RESULT_CODE_SYNCHRONIZE));
}
// voice input and output
if(!addOnService.hasPowerPack())
@ -484,13 +512,6 @@ public class EditPreferences extends TodorooPreferenceActivity {
setResult(SyncProviderPreferences.RESULT_CODE_SYNCHRONIZE);
finish();
return;
} else if (requestCode == REQUEST_CODE_LABS && resultCode == LabsPreferences.RESULT_TLA_NEEDS_REFRESH) {
setResult(RESULT_CODE_PERFORMANCE_PREF_CHANGED);
return;
} else if (requestCode == REQUEST_CODE_LABS && resultCode == LabsPreferences.RESULT_NEEDS_SYNC) {
if (Preferences.getBoolean(R.string.p_show_featured_lists_labs, false))
setResult(SyncProviderPreferences.RESULT_CODE_SYNCHRONIZE);
return;
} else if (requestCode == REQUEST_CODE_FILES_DIR && resultCode == RESULT_OK) {
if (data != null) {
String dir = data.getStringExtra(FileExplore.RESULT_DIR_SELECTED);

@ -171,7 +171,8 @@ public abstract class MarketStrategy {
R.string.p_voicePrefSection,
R.string.p_end_at_deadline,
R.string.p_swipe_lists_performance_key,
R.string.p_field_missed_calls
R.string.p_field_missed_calls,
R.string.p_ideas_tab_enabled
};
}

Loading…
Cancel
Save