mirror of https://github.com/tasks/tasks
Apply Android Studio and Lint inspections
* Remove always true/false/null parameters * Remove pointless bitwise expressions * Remove pointless boolean expressions * Remove unnecessary continue statements * Convert fields to local variables * Remove unused resourcespull/46/merge
parent
75315a4951
commit
a1c986d9e2
@ -1,77 +0,0 @@
|
||||
package com.todoroo.astrid.service;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.preference.PreferenceActivity;
|
||||
|
||||
import com.todoroo.andlib.utility.Preferences;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.tasks.R;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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(RESULT_OK);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getPreferenceScreen().addPreference(pref);
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue