diff options
| author | Luis Vidal <lvidal@cyngn.com> | 2016-03-21 10:08:14 -0700 |
|---|---|---|
| committer | Luis Vidal <lvidal@cyngn.com> | 2016-03-31 17:14:08 -0700 |
| commit | 2703eb717e542ff225611cb9e0217815ee14661c (patch) | |
| tree | 8b0152d2b3da7daf49cf45704df78e9ee5d00e83 | |
| parent | 44a5b78ccbfb7ab39451209cdfa6feeebb0508db (diff) | |
| download | packages_apps_Settings-2703eb717e542ff225611cb9e0217815ee14661c.tar.gz packages_apps_Settings-2703eb717e542ff225611cb9e0217815ee14661c.tar.bz2 packages_apps_Settings-2703eb717e542ff225611cb9e0217815ee14661c.zip | |
Add Weather Content Provider [2/5]
Introduce a new entry in the settings menu to select the available
weather provider services.
This entry will be parked in the System category between Date&Time
and Accessibility
Change-Id: Ida230f3be72eb575a2b09504c99eaa16851c99f8
| -rwxr-xr-x | AndroidManifest.xml | 11 | ||||
| -rw-r--r-- | res/drawable/ic_settings_weather.xml | 30 | ||||
| -rw-r--r-- | res/layout/empty_weather_state.xml | 47 | ||||
| -rw-r--r-- | res/layout/weather_service_provider_info_row.xml | 104 | ||||
| -rw-r--r-- | res/values/cm_colors.xml | 1 | ||||
| -rw-r--r-- | res/values/cm_strings.xml | 6 | ||||
| -rw-r--r-- | res/xml/dashboard_categories.xml | 8 | ||||
| -rw-r--r-- | src/com/android/settings/Settings.java | 1 | ||||
| -rw-r--r-- | src/com/android/settings/SettingsActivity.java | 10 | ||||
| -rw-r--r-- | src/com/android/settings/cyanogenmod/WeatherServiceSettings.java | 343 |
10 files changed, 560 insertions, 1 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 919653261..239abbbc0 100755 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2904,5 +2904,16 @@ </intent-filter> </activity> + <!-- Weather Service Providers settings --> + <activity android:name="Settings$WeatherProviderServicesActivity" + android:taskAffinity="" + android:label="@string/weather_settings_title"> + <intent-filter> + <action android:name="cyanogenmod.intent.action.MANAGE_WEATHER_PROVIDER_SERVICES" /> + <category android:name="android.intent.category.DEFAULT" /> + </intent-filter> + <meta-data android:name="com.android.settings.FRAGMENT_CLASS" + android:value="com.android.settings.cyanogenmod.WeatherServiceSettings" /> + </activity> </application> </manifest> diff --git a/res/drawable/ic_settings_weather.xml b/res/drawable/ic_settings_weather.xml new file mode 100644 index 000000000..1a5a8a922 --- /dev/null +++ b/res/drawable/ic_settings_weather.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (c) 2016 The CyanogenMod Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + + <path + android:fillColor="?android:attr/colorAccent" + android:pathData="M5.3,6.7L3.5,4.9L5,3.5l1.8,1.8L5.3,6.7z M13,1h-2v3h2V1z M1,13h3v-2H1V13z +M20.5,4.9L19,3.5l-1.8,1.8l1.4,1.4L20.5,4.9z +M17.3,9.1c-1-1.9-3-3.2-5.3-3.2c-3.3,0-6,2.7-6,6c0,0.9,0.2,1.7,0.5,2.5C5.6,15.3,5,16.6,5,18c0,2.8,2.2,5,5,5h6c3.9,0,7-3.1,7-7 +C23,12.6,20.5,9.7,17.3,9.1z +M16,11c2.8,0,5,2.2,5,5s-2.2,5-5,5h-6c-1.7,0-3-1.3-3-3s1.3-3,3-3h1.1C11.6,12.7,13.6,11,16,11" /> +</vector>
\ No newline at end of file diff --git a/res/layout/empty_weather_state.xml b/res/layout/empty_weather_state.xml new file mode 100644 index 000000000..09c379452 --- /dev/null +++ b/res/layout/empty_weather_state.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (c) 2016 The CyanogenMod Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/empty_weather_state" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:visibility="gone"> + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center" + android:orientation="vertical"> + <ImageView + android:id="@+id/icon" + android:layout_width="192dp" + android:layout_height="192dp" + android:layout_marginBottom="12dip" + android:src="@drawable/ic_settings_weather" + android:tint="@color/weather_settings_icon_tint" + android:contentDescription="@null"> + </ImageView> + + <TextView + android:id="@+id/message" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textSize="18dp" + android:textColor="?android:attr/textColorSecondary"> + </TextView> + + </LinearLayout> +</FrameLayout> diff --git a/res/layout/weather_service_provider_info_row.xml b/res/layout/weather_service_provider_info_row.xml new file mode 100644 index 000000000..36d547010 --- /dev/null +++ b/res/layout/weather_service_provider_info_row.xml @@ -0,0 +1,104 @@ +<!-- + Copyright (C) 2016 The CyanogenMod Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"> + + <RelativeLayout + android:id="@android:id/widget_frame" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_toStartOf="@+id/divider" + android:clickable="true" + android:focusable="true" + android:background="?android:attr/selectableItemBackground" > + + <!-- Weather Provider Service icon --> + + <ImageView + android:id="@android:id/icon" + android:layout_width="@android:dimen/app_icon_size" + android:layout_height="@android:dimen/app_icon_size" + android:layout_centerVertical="true" + android:layout_marginBottom="10dp" + android:layout_marginStart="0dp" + android:layout_marginEnd="6dp" + android:layout_marginTop="10dp" + android:contentDescription="@null" + android:maxHeight="@android:dimen/app_icon_size" + android:maxWidth="@android:dimen/app_icon_size" + android:scaleType="fitCenter" /> + + <!-- Weather Provider Service caption --> + + <TextView + android:id="@android:id/title" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_centerVertical="true" + android:layout_toStartOf="@android:id/button1" + android:layout_toEndOf="@android:id/icon" + android:ellipsize="end" + android:singleLine="true" + android:textAppearance="?android:attr/textAppearanceMedium" + android:textAlignment="viewStart" + android:labelFor="@android:id/button2" /> + + <!-- Weather Provider Service radio button --> + + <RadioButton + android:id="@android:id/button1" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_alignParentEnd="true" + android:layout_centerVertical="true" + android:duplicateParentState="true" + android:clickable="false" + android:focusable="false" /> + + </RelativeLayout> + + <!-- Divider --> + + <ImageView + android:id="@id/divider" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_centerVertical="true" + android:layout_toStartOf="@android:id/button2" + android:contentDescription="@null" + android:src="@drawable/nav_divider" /> + + <ImageView + android:id="@android:id/button2" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_alignBottom="@android:id/widget_frame" + android:layout_alignParentEnd="true" + android:layout_alignTop="@android:id/widget_frame" + android:layout_centerVertical="true" + android:layout_margin="0dip" + android:background="?android:attr/selectableItemBackground" + android:contentDescription="@string/weather_settings_button" + android:padding="8dip" + android:clickable="true" + android:focusable="true" + android:src="@drawable/ic_bt_config" /> + + +</RelativeLayout> diff --git a/res/values/cm_colors.xml b/res/values/cm_colors.xml index 8fa69ded4..8e0a0f15e 100644 --- a/res/values/cm_colors.xml +++ b/res/values/cm_colors.xml @@ -127,4 +127,5 @@ limitations under the License. <color name="crypt_keeper_emergency_button_text_color">@color/text_color_white</color> <color name="custom_screencolor_buttons_text_color">@color/text_color_white</color> + <color name="weather_settings_icon_tint">#B4B9BA</color> </resources> diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index 6b42f4edd..78c057664 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -1163,4 +1163,10 @@ <string name="restrict_app_cellular_title">Disable app cellular usage</string> <string name="restrict_app_cellular_summary">Prevent app from using cellular data connection</string> <string name="privacy_guard_internet_category">Internet</string> + + <!-- Weather --> + <string name="weather_settings_title">Weather</string> + <string name="weather_settings_no_services_prompt">No weather provider services installed</string> + <string name="weather_settings_button">Provider settings</string> + </resources> diff --git a/res/xml/dashboard_categories.xml b/res/xml/dashboard_categories.xml index 56b3b8e59..24deb20d3 100644 --- a/res/xml/dashboard_categories.xml +++ b/res/xml/dashboard_categories.xml @@ -270,6 +270,14 @@ android:icon="@drawable/ic_settings_date_time" /> + <!-- Weather --> + <dashboard-tile + android:id="@+id/weather_settings" + android:title="@string/weather_settings_title" + android:fragment="com.android.settings.cyanogenmod.WeatherServiceSettings" + android:icon="@drawable/ic_settings_weather" + /> + <!-- Accessibility feedback --> <dashboard-tile android:id="@+id/accessibility_settings" diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index 692b29288..8af3c80cc 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -128,4 +128,5 @@ public class Settings extends SettingsActivity { public static class LockScreenSettingsActivity extends SettingsActivity { /* empty */ } public static class LiveLockScreenSettingsActivity extends SettingsActivity { /* empty */ } public static class NotificationManagerActivity extends SettingsActivity { /* empty */ } + public static class WeatherProviderServicesActivity extends SettingsActivity { /* empty */ } } diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java index 8e0bb9863..dfef1a47a 100644 --- a/src/com/android/settings/SettingsActivity.java +++ b/src/com/android/settings/SettingsActivity.java @@ -84,6 +84,7 @@ import com.android.settings.bluetooth.BluetoothSettings; import com.android.settings.contributors.ContributorsCloudFragment; import com.android.settings.cyanogenmod.DisplayRotation; import com.android.settings.cyanogenmod.LiveLockScreenSettings; +import com.android.settings.cyanogenmod.WeatherServiceSettings; import com.android.settings.dashboard.DashboardCategory; import com.android.settings.dashboard.DashboardSummary; import com.android.settings.dashboard.DashboardTile; @@ -137,6 +138,7 @@ import com.android.settings.wifi.SavedAccessPointsWifiSettings; import com.android.settings.wifi.WifiSettings; import com.android.settings.wifi.p2p.WifiP2pSettings; +import cyanogenmod.app.CMContextConstants; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -377,7 +379,8 @@ public class SettingsActivity extends Activity ProfilesSettings.class.getName(), ContributorsCloudFragment.class.getName(), NotificationManagerSettings.class.getName(), - LiveLockScreenSettings.class.getName() + LiveLockScreenSettings.class.getName(), + WeatherServiceSettings.class.getName() }; @@ -1328,6 +1331,11 @@ public class SettingsActivity extends Activity if (!hasDeviceKeys) { removeTile = true; } + } else if (id == R.id.weather_settings) { + if (!getPackageManager().hasSystemFeature( + CMContextConstants.Features.WEATHER_SERVICES)) { + removeTile = true; + } } if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0 diff --git a/src/com/android/settings/cyanogenmod/WeatherServiceSettings.java b/src/com/android/settings/cyanogenmod/WeatherServiceSettings.java new file mode 100644 index 000000000..424f7de44 --- /dev/null +++ b/src/com/android/settings/cyanogenmod/WeatherServiceSettings.java @@ -0,0 +1,343 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.cyanogenmod; + +import android.app.Activity; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.content.res.Resources; +import android.content.res.TypedArray; +import android.content.res.XmlResourceParser; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.os.Handler; +import android.os.UserHandle; +import android.util.AttributeSet; +import android.util.Log; +import android.util.Xml; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.RadioButton; +import android.widget.TextView; +import com.android.internal.content.PackageMonitor; +import com.android.internal.os.BackgroundThread; +import com.android.settings.R; +import com.android.settings.SettingsPreferenceFragment; +import com.android.settings.Utils; +import cyanogenmod.providers.CMSettings; +import cyanogenmod.weatherservice.WeatherProviderService; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + +import static org.cyanogenmod.internal.logging.CMMetricsLogger.WEATHER_SETTINGS; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class WeatherServiceSettings extends SettingsPreferenceFragment { + + private Context mContext; + private WeatherProviderServiceInfoAdapter mAdapter; + private Handler mHandler; + private static final String TAG = WeatherServiceSettings.class.getSimpleName(); + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + mContext = activity; + mHandler = new Handler(mContext.getMainLooper()); + } + + @Override + protected int getMetricsCategory() { + return WEATHER_SETTINGS; + } + + @Override + public void onResume() { + super.onResume(); + updateAdapter(); + registerPackageMonitor(); + } + + @Override + public void onPause() { + super.onPause(); + unregisterPackageMonitor(); + } + + private void registerPackageMonitor() { + mPackageMonitor.register(mContext, BackgroundThread.getHandler().getLooper(), + UserHandle.ALL, true); + } + + private void unregisterPackageMonitor() { + mPackageMonitor.unregister(); + } + + private PackageMonitor mPackageMonitor = new PackageMonitor() { + @Override + public void onPackageAdded(String packageName, int uid) { + mHandler.post(new Runnable() { + @Override + public void run() { + updateAdapter(); + } + }); + } + + @Override + public void onPackageRemoved(String packageName, int uid) { + mHandler.post(new Runnable() { + @Override + public void run() { + updateAdapter(); + } + }); + } + }; + + private void updateAdapter() { + final PackageManager pm = getContext().getPackageManager(); + final Intent intent = new Intent(WeatherProviderService.SERVICE_INTERFACE); + List<ResolveInfo> resolveInfoList = pm.queryIntentServices(intent, + PackageManager.GET_SERVICES | PackageManager.GET_META_DATA); + List<WeatherProviderServiceInfo> weatherProviderServiceInfos + = new ArrayList<>(resolveInfoList.size()); + ComponentName activeService = getEnabledWeatherServiceProvider(); + for (ResolveInfo resolveInfo : resolveInfoList) { + if (resolveInfo.serviceInfo == null) continue; + + if (resolveInfo.serviceInfo.packageName == null + || resolveInfo.serviceInfo.name == null) { + //Really? + continue; + } + + if (!resolveInfo.serviceInfo.permission.equals( + cyanogenmod.platform.Manifest.permission.BIND_WEATHER_PROVIDER_SERVICE)) { + continue; + } + WeatherProviderServiceInfo serviceInfo = new WeatherProviderServiceInfo(); + serviceInfo.componentName = new ComponentName(resolveInfo.serviceInfo.packageName, + resolveInfo.serviceInfo.name); + serviceInfo.isActive = serviceInfo.componentName.equals(activeService); + serviceInfo.caption = resolveInfo.loadLabel(pm); + serviceInfo.icon = resolveInfo.loadIcon(pm); + serviceInfo.settingsComponentName = getSettingsComponent(pm, resolveInfo); + + weatherProviderServiceInfos.add(serviceInfo); + } + mAdapter.clear(); + mAdapter.addAll(weatherProviderServiceInfos); + + } + + private ComponentName getSettingsComponent(PackageManager pm, ResolveInfo resolveInfo) { + if (resolveInfo == null + || resolveInfo.serviceInfo == null + || resolveInfo.serviceInfo.metaData == null) { + return null; + } + String cn = null; + XmlResourceParser parser = null; + Exception caughtException = null; + + try { + parser = resolveInfo.serviceInfo.loadXmlMetaData(pm, + WeatherProviderService.SERVICE_META_DATA); + if (parser == null) { + Log.w(TAG, "Can't find " + WeatherProviderService.SERVICE_META_DATA + " meta-data"); + return null; + } + Resources res = + pm.getResourcesForApplication(resolveInfo.serviceInfo.applicationInfo); + AttributeSet attrs = Xml.asAttributeSet(parser); + int type; + while ((type=parser.next()) != XmlPullParser.END_DOCUMENT + && type != XmlPullParser.START_TAG) { + } + String nodeName = parser.getName(); + if (!"weather-provider-service".equals(nodeName)) { + Log.w(TAG, "Meta-data does not start with weather-provider-service tag"); + return null; + } + //Will use Dream styleable for now, it has the attribute we need + TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.Dream); + cn = sa.getString(com.android.internal.R.styleable.Dream_settingsActivity); + sa.recycle(); + } catch (PackageManager.NameNotFoundException e) { + caughtException = e; + } catch (IOException e) { + caughtException = e; + } catch (XmlPullParserException e) { + caughtException = e; + } finally { + if (parser != null) parser.close(); + } + if (caughtException != null) { + Log.w(TAG, "Error parsing : " + resolveInfo.serviceInfo.packageName, + caughtException); + return null; + } + if (cn != null && cn.indexOf('/') < 0) { + cn = resolveInfo.serviceInfo.packageName + "/" + cn; + } + return cn == null ? null : ComponentName.unflattenFromString(cn); + } + + private ComponentName getEnabledWeatherServiceProvider() { + String activeWeatherServiceProvider = CMSettings.Secure.getString( + mContext.getContentResolver(), CMSettings.Secure.WEATHER_PROVIDER_SERVICE); + if (activeWeatherServiceProvider == null) return null; + return ComponentName.unflattenFromString(activeWeatherServiceProvider); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + ListView listView = getListView(); + ViewGroup contentRoot = (ViewGroup) listView.getParent(); + listView.setItemsCanFocus(true); + + View emptyView = getActivity().getLayoutInflater().inflate( + R.layout.empty_weather_state, contentRoot, false); + TextView emptyTextView = (TextView) emptyView.findViewById(R.id.message); + emptyTextView.setText(R.string.weather_settings_no_services_prompt); + + listView.setEmptyView(emptyView); + + contentRoot.addView(emptyView); + mAdapter = new WeatherProviderServiceInfoAdapter(mContext); + listView.setAdapter(mAdapter); + } + + private class WeatherProviderServiceInfo { + CharSequence caption; + Drawable icon; + boolean isActive; + ComponentName componentName; + public ComponentName settingsComponentName; + } + + private class WeatherProviderServiceInfoAdapter + extends ArrayAdapter<WeatherProviderServiceInfo> { + + private final LayoutInflater mInflater; + + public WeatherProviderServiceInfoAdapter(Context context) { + super(context, 0); + mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + WeatherProviderServiceInfo info = getItem(position); + final View row = convertView != null ? convertView : + buildRow(parent); + row.setTag(info); + + ((ImageView) row.findViewById(android.R.id.icon)) + .setImageDrawable(info.icon); + + ((TextView) row.findViewById(android.R.id.title)).setText(info.caption); + + RadioButton radioButton = (RadioButton) row.findViewById(android.R.id.button1); + radioButton.setChecked(info.isActive); + radioButton.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + row.onTouchEvent(event); + return false; + } + }); + + boolean showSettings = info.settingsComponentName != null; + View settingsDivider = row.findViewById(R.id.divider); + settingsDivider.setVisibility(showSettings ? View.VISIBLE : View.INVISIBLE); + ImageView settingsButton = (ImageView) row.findViewById(android.R.id.button2); + settingsButton.setVisibility(showSettings ? View.VISIBLE : View.INVISIBLE); + settingsButton.setAlpha(info.isActive ? 1f : Utils.DISABLED_ALPHA); + settingsButton.setEnabled(info.isActive); + settingsButton.setFocusable(info.isActive); + settingsButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + launchSettingsActivity((WeatherProviderServiceInfo)row.getTag()); + } + }); + + return row; + } + + private void launchSettingsActivity(WeatherProviderServiceInfo info) { + if (info != null && info.settingsComponentName != null) { + mContext.startActivity(new Intent().setComponent(info.settingsComponentName)); + } + } + + private View buildRow(ViewGroup parent) { + final View row = mInflater.inflate(R.layout.weather_service_provider_info_row, + parent, false); + final View header = row.findViewById(android.R.id.widget_frame); + header.setOnClickListener(new View.OnClickListener(){ + @Override + public void onClick(View v) { + v.setPressed(true); + setActiveWeatherProviderService((WeatherProviderServiceInfo) row.getTag()); + } + }); + + return row; + } + + private void setActiveWeatherProviderService(WeatherProviderServiceInfo info) { + WeatherProviderServiceInfo currentSelection = getCurrentSelection(); + if (info.equals(currentSelection)) return; + if (currentSelection != null) { + currentSelection.isActive = false; + } + info.isActive = true; + CMSettings.Secure.putString(mContext.getContentResolver(), + CMSettings.Secure.WEATHER_PROVIDER_SERVICE, + info.componentName.flattenToString()); + if (info.settingsComponentName != null) { + mContext.startActivity(new Intent().setComponent(info.settingsComponentName)); + } + notifyDataSetChanged(); + } + + private WeatherProviderServiceInfo getCurrentSelection() { + for (int indx = 0; indx < getCount(); indx++) { + WeatherProviderServiceInfo info = getItem(indx); + if (info.isActive) { + return info; + } + } + return null; + } + } +} |
