Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50c70593 authored by Danesh Mondegarian's avatar Danesh Mondegarian Committed by Steve Kondik
Browse files

Settings : Verify weather prior to saving

- Verify weather prior to saving in order to avoid user from having
  to check lockscreen to find out if it was valid or not.

- Set location cursor to end of string.

Patchset 2 : Minor formatting fix
Patchset 3 : Store city returned from xml
Patchset 4 : Switch back to storing user input location
Patchset 5 : Strings cleanup

Change-Id: I314355be30057a32124d2c74214eef2403216e22
parent 2bc234b2
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -956,19 +956,17 @@
    <string name="weather_use_custom_location">Use custom location</string>
    <string name="weather_geolocated">Geolocated using network</string>
    <string name="weather_custom_location_dialog_title">Enter location</string>
    <string name="weather_custom_location_dialog_message">Caution: Entering an invalid location will stop updates.</string>
    <string name="weather_custom_location_hint">City, State/Country</string>
    <string name="weather_custom_location_title">Location</string>
    <string name="weather_show_location_title">Show location</string>
    <string name="weather_show_timestamp_title">Show timestamp</string>
    <string name="weather_refresh_interval">Update interval</string>
    <string name="weather_update">Update</string>
    <string name="weather_use_metric">Use metric</string>
    <string name="weather_refreshing">Updating weather</string>
    <string name="weather_retrieve_location_dialog_title">Cannot retrieve location!</string>
    <string name="weather_retrieve_location_dialog_message">Network geolocation is disabled.\n\nSet a custom location or enable network location</string>
    <string name="weather_retrieve_location_dialog_enable_button">Enable</string>
    <string name="weather_invert_lowhigh">Invert low/high temperatures</string>
    <string name="weather_progress_title">Verifying location</string>

    <!-- Lock screen Weather - Update frequency -->
    <string name="weather_refresh_manual">Manual</string>
+0 −1
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@
        android:key="custom_location"
        android:persistent="false"
        android:dependency="use_custom_location"
        android:dialogMessage="@string/weather_custom_location_dialog_message"
        android:dialogTitle="@string/weather_custom_location_dialog_title"
        android:hint="@string/weather_custom_location_hint"
        android:title="@string/weather_custom_location_title" />
+58 −6
Original line number Diff line number Diff line
@@ -3,12 +3,15 @@ package com.android.settings.cyanogenmod;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
@@ -17,7 +20,13 @@ import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.view.View;
import android.widget.Toast;

import com.android.internal.util.weather.HttpRetriever;
import com.android.internal.util.weather.WeatherInfo;
import com.android.internal.util.weather.WeatherXmlParser;
import com.android.internal.util.weather.YahooPlaceFinder;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;

@@ -33,6 +42,7 @@ public class Weather extends SettingsPreferenceFragment implements
    public static final String KEY_ENABLE_WEATHER = "enable_weather";
    public static final String KEY_REFRESH_INTERVAL = "refresh_interval";
    public static final String KEY_INVERT_LOWHIGH = "invert_lowhigh";
    private static final int WEATHER_CHECK = 0;

    private CheckBoxPreference mEnableWeather;
    private CheckBoxPreference mUseCustomLoc;
@@ -44,6 +54,7 @@ public class Weather extends SettingsPreferenceFragment implements
    private EditTextPreference mCustomWeatherLoc;
    private Context mContext;
    private ContentResolver mResolver;
    private ProgressDialog mProgressDialog;

    private static final int LOC_WARNING = 101;

@@ -64,7 +75,6 @@ public class Weather extends SettingsPreferenceFragment implements
                Settings.System.WEATHER_USE_CUSTOM_LOCATION, 0) == 1);
        mCustomWeatherLoc = (EditTextPreference) findPreference(KEY_CUSTOM_LOCATION);
        updateLocationSummary();
        mCustomWeatherLoc.setOnPreferenceChangeListener(this);
        mCustomWeatherLoc.setOnPreferenceClickListener(this);

        mShowLocation = (CheckBoxPreference) findPreference(KEY_SHOW_LOCATION);
@@ -154,15 +164,31 @@ public class Weather extends SettingsPreferenceFragment implements
            mWeatherSyncInterval.setValue((String) newValue);
            mWeatherSyncInterval.setSummary(mapUpdateValue(newVal));
            preference.setSummary(mapUpdateValue(newVal));
        } else if (preference == mCustomWeatherLoc) {
            String newVal = (String) newValue;
            Settings.System.putString(mResolver, Settings.System.WEATHER_CUSTOM_LOCATION, newVal);
            preference.setSummary(newVal);
        }

        return false;
    }

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case WEATHER_CHECK:
                if (msg.obj == null) {
                    Toast.makeText(mContext, mContext.getString(R.string.weather_retrieve_location_dialog_title),
                            Toast.LENGTH_SHORT).show();
                } else {
                    String cLoc = mCustomWeatherLoc.getEditText().getText().toString();
                    mCustomWeatherLoc.setText(cLoc);
                    Settings.System.putString(mResolver, Settings.System.WEATHER_CUSTOM_LOCATION, cLoc);
                    mCustomWeatherLoc.setSummary(cLoc);
                    mCustomWeatherLoc.getDialog().dismiss();
                }
                mProgressDialog.dismiss();
                break;
            }
        }
    };

    @Override
    public boolean onPreferenceClick(Preference preference) {

@@ -171,9 +197,35 @@ public class Weather extends SettingsPreferenceFragment implements
                    Settings.System.WEATHER_CUSTOM_LOCATION);
            if (location != null) {
                mCustomWeatherLoc.getEditText().setText(location);
                mCustomWeatherLoc.getEditText().setSelection(location.length());
            } else {
                mCustomWeatherLoc.getEditText().setText("");
            }
            mCustomWeatherLoc.getDialog().findViewById(android.R.id.button1)
            .setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mProgressDialog = new ProgressDialog(mContext);
                    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                    mProgressDialog.setMessage(mContext.getString(R.string.weather_progress_title));
                    mProgressDialog.show();
                    new Thread(new Runnable(){
                        @Override
                        public void run() {
                            String woeid = null;
                            try {
                                woeid = YahooPlaceFinder.GeoCode(mContext,
                                        mCustomWeatherLoc.getEditText().getText().toString());
                            } catch (Exception e) {
                            }
                            Message msg = Message.obtain();
                            msg.what = WEATHER_CHECK;
                            msg.obj = woeid;
                            mHandler.sendMessage(msg);
                        }
                    }).start();
                }
            });
            return true;
        }