Ability to launch a custom preference activity from UpdateMessageService

pull/14/head
Sam Bosley 12 years ago
parent 3dc29fdaa9
commit 5614a9a2cc

@ -171,6 +171,9 @@
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Dialog"/>
<activity android:name="com.todoroo.astrid.service.UpdateMessagePreference"
android:theme="@android:style/Theme" />
<!-- Start of Crittercism.com Code -->
<activity android:name="com.crittercism.NewFeedbackSpringboardActivity" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"></activity>
<activity android:name="com.crittercism.NewFeedbackIssueListActivity" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"></activity>

@ -0,0 +1,10 @@
<?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_title">
</PreferenceScreen>

@ -61,13 +61,14 @@ import com.todoroo.astrid.voice.VoiceRecognizer;
public class AstridActivity extends FragmentActivity
implements FilterListFragment.OnFilterItemClickedListener,
TaskListFragment.OnTaskListItemClickedListener,
TaskEditFragment.OnTaskEditDetailsClickedListener,
RecognizerApiListener {
public static final int LAYOUT_SINGLE = 0;
public static final int LAYOUT_DOUBLE = 1;
public static final int LAYOUT_TRIPLE = 2;
public static final int RESULT_RESTART_ACTIVITY = 50;
protected int fragmentLayout = LAYOUT_SINGLE;
private final RepeatConfirmationReceiver repeatConfirmationReceiver = new RepeatConfirmationReceiver();
@ -290,9 +291,13 @@ public class AstridActivity extends FragmentActivity
}
@Override
public void onTaskEditDetailsClicked(int category, int position) {
//
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_RESTART_ACTIVITY) {
finish();
startActivity(getIntent());
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
// --- fragment helpers

@ -0,0 +1,76 @@
package com.todoroo.astrid.service;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import com.timsu.astrid.R;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.activity.AstridActivity;
public class UpdateMessagePreference extends PreferenceActivity {
public static final String TOKEN_PREFS_ARRAY = "prefs_array"; //$NON-NLS-1$
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences_blank);
String prefsArray = getIntent().getStringExtra(TOKEN_PREFS_ARRAY);
try {
JSONArray array = new JSONArray(prefsArray);
if (array.length() == 0)
finish();
for (int i = 0; i < array.length(); i++) {
try {
JSONObject pref = array.getJSONObject(i);
addPreferenceFromJSON(pref);
} catch (JSONException e) {
continue;
}
}
} catch (JSONException e) {
finish();
}
}
@SuppressWarnings("nls")
private void addPreferenceFromJSON(JSONObject obj) {
String type = obj.optString("type", null);
String key = obj.optString("key", null);
String title = obj.optString("title", null);
if (type == null || key == null || title == null)
return;
Preference pref = null;
if ("bool".equals(type)) { // We can add other types we want to support and handle the preference construction here
pref = new CheckBoxPreference(this);
pref.setKey(key);
pref.setTitle(title);
pref.setDefaultValue(Preferences.getBoolean(key, false));
}
if (pref == null)
return;
if (obj.optBoolean("restart")) {
pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
setResult(AstridActivity.RESULT_RESTART_ACTIVITY);
return true;
}
});
}
getPreferenceScreen().addPreference(pref);
}
}

@ -79,21 +79,6 @@ public class UpdateMessageService {
public void processUpdates() {
JSONArray updates = checkForUpdates();
// try {
// JSONObject test = new JSONObject();
// test.put("date", "09/26/12");
// test.put("message", "Screens!");
// test.put("type", "screen");
// test.put("link", "Click me");
// JSONArray screenArray = new JSONArray();
// screenArray.put(ActFmLoginActivity.class.getName());
// screenArray.put(EditPreferences.class.getName());
// test.put("screens", screenArray);
// updates.put(test);
// } catch (JSONException e) {
// e.printStackTrace();
// }
if(updates == null || updates.length() == 0)
return;
@ -108,7 +93,7 @@ public class UpdateMessageService {
void showDialog(Activity activity);
}
private void showDialog(DialogShower ds) {
private void tryShowDialog(DialogShower ds) {
try {
ds.showDialog(activity);
} catch (BadTokenException bt) {
@ -167,7 +152,7 @@ public class UpdateMessageService {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
showDialog(ds);
tryShowDialog(ds);
}
});
@ -226,19 +211,28 @@ public class UpdateMessageService {
private ClickableSpan getClickableSpanForUpdate(JSONObject update, String type) {
if ("pref".equals(type)) {
final String prefSpec = update.optString("prefSpec", null);
if (prefSpec == null)
try {
if (!update.has("prefs"))
return null;
JSONArray prefSpec = update.getJSONArray("prefs");
if (prefSpec.length() == 0)
return null;
final String prefArray = prefSpec.toString();
return new ClickableSpan() {
@Override
public void onClick(View widget) {
Intent prefScreen = new Intent(activity, UpdateMessagePreference.class);
prefScreen.putExtra(UpdateMessagePreference.TOKEN_PREFS_ARRAY, prefArray);
activity.startActivityForResult(prefScreen, 0);
}
};
} catch (JSONException e) {
return null;
return new ClickableSpan() {
@Override
public void onClick(View widget) {
// Intent prefScreen = new Intent(activity, UpdateMessagePreference.class);
// prefScreen.putExtra(UpdateMessagePreference.TOKEN_PREF_SPEC, prefSpec);
// activity.startActivity(prefScreen);
}
};
}
} else if ("screen".equals(type)) {
try {
if (!update.has("screens"))
return null;
JSONArray screens = update.getJSONArray("screens");
if (screens.length() == 0)
return null;
@ -259,7 +253,6 @@ public class UpdateMessageService {
}
}
return null;
}
private boolean pluginConditionMatches(String plugin) {

Loading…
Cancel
Save