Skip to content

Commit

Permalink
Merge "Weather panel: Redo click options and add longclick" into jb
Browse files Browse the repository at this point in the history
  • Loading branch information
KhasMek authored and Gerrit Code Review committed Oct 30, 2012
2 parents 4f13a7c + 038067b commit 7f341af
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 87 deletions.
10 changes: 10 additions & 0 deletions res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -823,4 +823,14 @@
<item>**assist**</item>
<item>**app**</item>
</string-array>
<string-array name="weather_action_entries" translatable="false">
<item>@string/nothing</item>
<item>@string/update</item>
<item>@string/custom_app</item>
</string-array>
<string-array name="weather_action_values" translatable="false">
<item>**nothing**</item>
<item>**update**</item>
<item>**app**</item>
</string-array>
</resources>
8 changes: 3 additions & 5 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,9 @@
<string name="weather_use_celcius">Metric units</string>
<string name="weather_use_celcius_summary">Enabling this will display weather temperature in Celsius rather than Fahrenheit and windspeed in km/h rather than mph.</string>
<string name="weather_statusbar_style">Statusbar weather style</string>
<string name="weather_start_custom_app">Start custom app</string>
<string name="weather_start_custom_app_summary">Start a custom app when clicking on the weather image.</string>
<string name="weather_custom_app_title">Custom app</string>
<string name="weather_custom_app_dialog_title">Choose your app</string>
<string name="weather_custom_app_dialog_message">Package name for now.</string>
<string name="title_weather_longclick">Weather panel long click actions</string>
<string name="title_weather_shortclick">Weather panel short click actions</string>
<string name="update">Update weather panel</string>
<string name="weather_refreshing">Requesting weather update!</string>
<string name="weather_loc_warning_title">Cannot retrieve location!</string>
<string name="weather_loc_warning_msg">"Obtaining location from network is currently disabled. This breaks the ability to get the current weather in your current location. Please set a custom location or enable obtaining your location from your network."</string>
Expand Down
22 changes: 10 additions & 12 deletions res/xml/prefs_weather.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,17 @@
android:title="@string/weather_use_celcius"
android:summary="@string/weather_use_celcius_summary" />

<ListPreference
android:entries="@array/weather_action_entries"
android:entryValues="@array/weather_action_values"
android:key="weather_shortclick"
android:title="@string/title_weather_shortclick" />

<CheckBoxPreference
android:key="use_custom_app"
android:dependency="enable_weather"
android:title="@string/weather_start_custom_app"
android:summary="@string/weather_start_custom_app_summary" />

<Preference
android:key="custom_app"
android:title="@string/weather_custom_app_title"
android:dependency="use_custom_app" />

<ListPreference
android:entries="@array/weather_action_entries"
android:entryValues="@array/weather_action_values"
android:key="weather_longclick"
android:title="@string/title_weather_longclick" />

<ListPreference
android:entries="@array/weather_interval_entries"
Expand All @@ -51,7 +50,6 @@
android:key="refresh_interval"
android:title="@string/weather_refresh_interval" />


<ListPreference
android:entries="@array/weather_statusbar_location_entries"
android:entryValues="@array/weather_statusbar_location_values"
Expand Down
3 changes: 0 additions & 3 deletions src/com/aokp/romcontrol/fragments/StatusBarClock.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
import com.aokp.romcontrol.util.ShortcutPickerHelper;
import net.margaritov.preference.colorpicker.ColorPickerPreference;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StatusBarClock extends AOKPPreferenceFragment implements
ShortcutPickerHelper.OnPickListener, OnPreferenceChangeListener {

Expand Down
85 changes: 59 additions & 26 deletions src/com/aokp/romcontrol/fragments/Weather.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
import com.aokp.romcontrol.weather.WeatherRefreshService;
import com.aokp.romcontrol.weather.WeatherService;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Weather extends AOKPPreferenceFragment implements
ShortcutPickerHelper.OnPickListener, OnPreferenceChangeListener {

Expand All @@ -49,10 +46,12 @@ public class Weather extends AOKPPreferenceFragment implements
ListPreference mStatusBarLocation;
ListPreference mWeatherSyncInterval;
EditTextPreference mCustomWeatherLoc;
CheckBoxPreference mUseCustomApp;
Preference mCustomWeatherApp;
ListPreference mWeatherShortClick;
ListPreference mWeatherLongClick;

private ShortcutPickerHelper mPicker;
private Preference mPreference;
private String mString;

SharedPreferences prefs;

Expand Down Expand Up @@ -97,18 +96,13 @@ public void onCreate(Bundle savedInstanceState) {
mUseCelcius = (CheckBoxPreference) findPreference(WeatherPrefs.KEY_USE_CELCIUS);
mUseCelcius.setChecked(WeatherPrefs.getUseCelcius(mContext));

mUseCustomApp = (CheckBoxPreference) findPreference(WeatherPrefs.KEY_USE_CUSTOM_APP);
mUseCustomApp.setChecked(WeatherPrefs.getUseCustomApp(mContext));
mWeatherShortClick = (ListPreference) findPreference("weather_shortclick");
mWeatherShortClick.setOnPreferenceChangeListener(this);
mWeatherShortClick.setSummary(getProperSummary(mWeatherShortClick));

mCustomWeatherApp = (Preference) findPreference(WeatherPrefs.KEY_CUSTOM_APP);
mCustomWeatherApp.setOnPreferenceChangeListener(this);
Pattern r = Pattern.compile("^#Intent");
Matcher m = r.matcher(mPicker.getFriendlyNameForUri(WeatherPrefs.getCustomApp(mContext)));
if(m.find( )) {
mCustomWeatherApp.setSummary("");
} else {
mCustomWeatherApp.setSummary(mPicker.getFriendlyNameForUri(WeatherPrefs.getCustomApp(mContext)));
}
mWeatherLongClick = (ListPreference) findPreference("weather_longclick");
mWeatherLongClick.setOnPreferenceChangeListener(this);
mWeatherLongClick.setSummary(getProperSummary(mWeatherLongClick));

setHasOptionsMenu(true);

Expand Down Expand Up @@ -206,18 +200,14 @@ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preferen
} else if (preference == mUseCelcius) {
return WeatherPrefs.setUseCelcius(mContext,
((CheckBoxPreference) preference).isChecked());
} else if (preference == mUseCustomApp) {
return WeatherPrefs.setUseCustomApp(mContext,
((CheckBoxPreference) preference).isChecked());
} else if (preference == mCustomWeatherApp) {
mPicker.pickShortcut();
return true;
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean result = false;

if (preference == mWeatherSyncInterval) {
int newVal = Integer.parseInt((String) newValue);
preference.setSummary(newValue
Expand All @@ -241,16 +231,36 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
return Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STATUSBAR_WEATHER_STYLE,
Integer.parseInt(newVal));

} else if (preference == mWeatherShortClick) {

mPreference = preference;
mString = Settings.System.WEATHER_PANEL_SHORTCLICK;
if (newValue.equals("**app**")) {
mPicker.pickShortcut();
} else {
result = Settings.System.putString(getContentResolver(), Settings.System.WEATHER_PANEL_SHORTCLICK, (String) newValue);
mWeatherShortClick.setSummary(getProperSummary(mWeatherShortClick));
}

} else if (preference == mWeatherLongClick) {

mPreference = preference;
mString = Settings.System.WEATHER_PANEL_LONGCLICK;
if (newValue.equals("**app**")) {
mPicker.pickShortcut();
} else {
result = Settings.System.putString(getContentResolver(), Settings.System.WEATHER_PANEL_LONGCLICK, (String) newValue);
mWeatherLongClick.setSummary(getProperSummary(mWeatherLongClick));
}
}
return false;
}

@Override
public void shortcutPicked(String uri, String friendlyName, Bitmap bmp, boolean isApplication) {

if (WeatherPrefs.setCustomApp(mContext, uri)) {
mCustomWeatherApp.setSummary(friendlyName);
}
mPreference.setSummary(friendlyName);
Settings.System.putString(getContentResolver(), mString, (String) uri);
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
Expand All @@ -263,5 +273,28 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
super.onActivityResult(requestCode, resultCode, data);
}
private String getProperSummary(Preference preference) {
if (preference == mWeatherLongClick) {
mString = Settings.System.WEATHER_PANEL_LONGCLICK;
} else if (preference == mWeatherShortClick) {
mString = Settings.System.WEATHER_PANEL_SHORTCLICK;
}

String uri = Settings.System.getString(getActivity().getContentResolver(),mString);
String empty = "";

if (uri == null)
return empty;

if (uri.startsWith("**")) {
if (uri.equals("**update**"))
return getResources().getString(R.string.update);
else if (uri.equals("**nothing**"))
return getResources().getString(R.string.nothing);
} else {
return mPicker.getFriendlyNameForUri(uri);
}
return null;
}

}
22 changes: 0 additions & 22 deletions src/com/aokp/romcontrol/weather/WeatherPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ public class WeatherPrefs {
public static final String KEY_REFRESH = "refresh_interval";
public static final String KEY_USE_CUSTOM_LOCATION = "use_custom_location";
public static final String KEY_CUSTOM_LOCATION = "custom_location";
public static final String KEY_USE_CUSTOM_APP = "use_custom_app";
public static final String KEY_CUSTOM_APP = "custom_app";

public static int getRefreshInterval(Context c) {
SharedPreferences prefs = c.getSharedPreferences(PREF_NAME, Context.MODE_WORLD_WRITEABLE);
Expand Down Expand Up @@ -54,24 +52,4 @@ public static boolean setUseCelcius(Context c, boolean use) {
SharedPreferences prefs = c.getSharedPreferences(PREF_NAME, Context.MODE_WORLD_WRITEABLE);
return prefs.edit().putBoolean(KEY_USE_CELCIUS, use).commit();
}

public static boolean getUseCustomApp(Context c) {
SharedPreferences prefs = c.getSharedPreferences(PREF_NAME, Context.MODE_WORLD_WRITEABLE);
return prefs.getBoolean(KEY_USE_CUSTOM_APP, false);
}

public static boolean setUseCustomApp(Context c, boolean use) {
SharedPreferences prefs = c.getSharedPreferences(PREF_NAME, Context.MODE_WORLD_WRITEABLE);
return prefs.edit().putBoolean(KEY_USE_CUSTOM_APP, use).commit();
}

public static String getCustomApp(Context c) {
SharedPreferences prefs = c.getSharedPreferences(PREF_NAME, Context.MODE_WORLD_WRITEABLE);
return prefs.getString(KEY_CUSTOM_APP, "");
}

public static boolean setCustomApp(Context c, String packagename) {
SharedPreferences prefs = c.getSharedPreferences(PREF_NAME, Context.MODE_WORLD_WRITEABLE);
return prefs.edit().putString(KEY_CUSTOM_APP, packagename).commit();
}
}
20 changes: 1 addition & 19 deletions src/com/aokp/romcontrol/weather/WeatherReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,7 @@ public void onReceive(Context context, Intent intent) {
if (extras != null) {
String type = extras.getString(WeatherService.INTENT_EXTRA_TYPE, "updateweather");
manual = extras.getBoolean(WeatherService.INTENT_EXTRA_ISMANUAL, false);
if (type != null) {
if (type.equals("startapp")) {
if (WeatherPrefs.getUseCustomApp(context.getApplicationContext())) {
Intent appintent = null;
try {
appintent = Intent.parseUri(WeatherPrefs.getCustomApp(
context.getApplicationContext()), 0);
} catch (URISyntaxException e) {
e.printStackTrace();
}
if (appintent != null) {
appintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
updateweather = false;
context.startActivity(appintent);
collapseStatusBar();
}
}
}
}

}

// SystemUI sends the broadcast to update weather upon booting up,
Expand Down

0 comments on commit 7f341af

Please sign in to comment.