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

Commit 1827c853 authored by Steve Kondik's avatar Steve Kondik
Browse files

cmparts: Implement SummaryProvider for a few components

Change-Id: I2c29f9ad15cf2a1263344cab9610bae168e36464
parent ee8f6e86
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@
    <string name="yes">Yes</string>
    <string name="no">No</string>
    <string name="search">Search</string>
    <string name="disabled">Disabled</string>
    <string name="enabled">Enabled</string>

    <!-- Privacy Settings Header item -->
    <string name="privacy_settings_title">Privacy</string>
@@ -104,6 +106,7 @@
    <string name="notification_light_use_multiple_leds">Multiple LEDs</string>
    <string name="keywords_lights_brightness_level">dim leds brightness</string>
    <string name="notification_light_automagic">Choose colors automatically</string>
    <string name="notification_light_automagic_summary">Choosing colors automatically</string>

    <!-- Lights settings, LED notification -->
    <string name="led_notification_title">Light settings</string>
@@ -498,7 +501,8 @@
    <!-- Display : Rotation  -->
    <string name="accelerometer_title">Auto-rotate screen</string>
    <string name="display_rotation_title">Rotation settings</string>
    <string name="display_rotation_disabled">Disabled</string>
    <string name="display_rotation_enabled">Auto-rotation is enabled</string>
    <string name="display_rotation_disabled">Auto-rotation is disabled</string>
    <string name="display_rotation_unit">degrees</string>
    <string name="display_lockscreen_rotation_title">Rotate lock screen</string>
    <string name="display_rotation_category_title">Rotation modes</string>
@@ -510,6 +514,7 @@
    <!-- 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_no_services_summary">Install a weather provider to receive weather updates</string>
    <string name="weather_settings_button">Provider settings</string>
    <string name="weather_settings_activity_not_found">Unable to launch the settings menu of this provider</string>
    <string name="weather_settings_add_weather_provider">Add weather provider</string>
+22 −20
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@

package org.cyanogenmod.cmparts.hardware;

import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.preference.CheckBoxPreference;
@@ -51,16 +53,9 @@ public class DisplayRotation extends SettingsPreferenceFragment {
    public static final int ROTATION_180_MODE = 4;
    public static final int ROTATION_270_MODE = 8;

    private ContentObserver mAccelerometerRotationObserver = new ContentObserver(new Handler()) {
    @Override
        public void onChange(boolean selfChange) {
            updateAccelerometerRotationSwitch();
        }
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        addPreferencesFromResource(R.xml.display_rotation);

@@ -104,23 +99,20 @@ public class DisplayRotation extends SettingsPreferenceFragment {
        if (lockScreenRotation != null && !canRotateLockscreen) {
            getPreferenceScreen().removePreference(lockScreenRotation);
        }

        addTrigger(Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION));
    }

    @Override
    public void onResume() {
        super.onResume();

        updateState();
        getContentResolver().registerContentObserver(
                Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION), true,
                mAccelerometerRotationObserver);
    public void onRefresh(Context context, Uri contentUri) {
        super.onRefresh(context, contentUri);
        updateAccelerometerRotationSwitch();
    }

    @Override
    public void onPause() {
        super.onPause();

        getContentResolver().unregisterContentObserver(mAccelerometerRotationObserver);
    public void onResume() {
        super.onResume();
        updateState();
    }

    private void updateState() {
@@ -169,4 +161,14 @@ public class DisplayRotation extends SettingsPreferenceFragment {

        return super.onPreferenceTreeClick(preference);
    }

    public static final SummaryProvider SUMMARY_PROVIDER = new SummaryProvider() {
        @Override
        public String getSummary(Context context, String key) {
            if (RotationPolicy.isRotationLocked(context)) {
                return context.getString(R.string.display_rotation_disabled);
            }
            return context.getString(R.string.display_rotation_enabled);
        }
    };
}
+14 −4
Original line number Diff line number Diff line
@@ -17,19 +17,17 @@
package org.cyanogenmod.cmparts.notificationlight;

import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
import android.support.v14.preference.PreferenceFragment;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import org.cyanogenmod.cmparts.R;

import org.cyanogenmod.cmparts.SettingsPreferenceFragment;

import cyanogenmod.preference.CMSystemSettingSwitchPreference;
@@ -90,6 +88,8 @@ public class BatteryLightSettings extends SettingsPreferenceFragment implements
            prefSet.removePreference(prefSet.findPreference("colors_list"));
            resetColors();
        }

        addTrigger(CMSettings.System.getUriFor(CMSettings.System.BATTERY_LIGHT_ENABLED));
    }

    @Override
@@ -186,7 +186,17 @@ public class BatteryLightSettings extends SettingsPreferenceFragment implements
    public boolean onPreferenceChange(Preference preference, Object objValue) {
        ApplicationLightPreference lightPref = (ApplicationLightPreference) preference;
        updateValues(lightPref.getKey(), lightPref.getColor());

        return true;
    }

    public static final SummaryProvider SUMMARY_PROVIDER = new SummaryProvider() {
        @Override
        public String getSummary(Context context, String key) {
            if (CMSettings.System.getInt(context.getContentResolver(),
                    CMSettings.System.BATTERY_LIGHT_ENABLED, 1) == 1) {
                return context.getString(R.string.enabled);
            }
            return context.getString(R.string.disabled);
        }
    };
}
+18 −4
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package org.cyanogenmod.cmparts.notificationlight;

import android.app.AlertDialog;
import android.app.Application;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.Context;
@@ -32,15 +31,12 @@ import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.PreferenceViewHolder;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
@@ -175,7 +171,10 @@ public class NotificationLightSettings extends SettingsPreferenceFragment implem
            mGeneralPrefs.removePreference(mAutoGenerateColors);
        } else {
            mAutoGenerateColors.setOnPreferenceChangeListener(this);
            addTrigger(CMSettings.System.getUriFor(CMSettings.System.NOTIFICATION_LIGHT_COLOR_AUTO));
        }

        addTrigger(Settings.System.getUriFor(Settings.System.NOTIFICATION_LIGHT_PULSE));
    }

    @Override
@@ -576,4 +575,19 @@ public class NotificationLightSettings extends SettingsPreferenceFragment implem
        }

    }

    public static final SummaryProvider SUMMARY_PROVIDER = new SummaryProvider() {
        @Override
        public String getSummary(Context context, String key) {
            if (Settings.System.getInt(context.getContentResolver(),
                    Settings.System.NOTIFICATION_LIGHT_PULSE, 1) == 1) {
                if (CMSettings.System.getInt(context.getContentResolver(),
                        CMSettings.System.NOTIFICATION_LIGHT_COLOR_AUTO, 1) == 1) {
                    return context.getString(R.string.notification_light_automagic_summary);
                }
                return context.getString(R.string.enabled);
            }
            return context.getString(R.string.disabled);
        }
    };
}
+33 −9
Original line number Diff line number Diff line
@@ -89,8 +89,8 @@ public class WeatherServiceSettings extends SettingsPreferenceFragment
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        addPreferencesFromResource(R.xml.weather_settings);

        final PreferenceScreen ps = getPreferenceScreen();
@@ -98,6 +98,8 @@ public class WeatherServiceSettings extends SettingsPreferenceFragment
        mProvidersCategory = (PreferenceCategory) ps.findPreference(PREFERENCE_PROVIDERS);
        mTemperatureUnit = (ListPreference) ps.findPreference(PREFERENCE_TEMP_UNIT);
        mTemperatureUnit.setOnPreferenceChangeListener(this);

        addTrigger(CMSettings.Secure.getUriFor(CMSettings.Secure.WEATHER_PROVIDER_SERVICE));
    }

    @Override
@@ -168,14 +170,14 @@ public class WeatherServiceSettings extends SettingsPreferenceFragment
        }
    };

    private void updateAdapter() {
        final PackageManager pm = getContext().getPackageManager();
    private static List<WeatherProviderServiceInfo> getInstalledServices(Context context) {
        final PackageManager pm = context.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();
        ComponentName activeService = getEnabledWeatherServiceProvider(context);
        for (ResolveInfo resolveInfo : resolveInfoList) {
            if (resolveInfo.serviceInfo == null) continue;

@@ -199,6 +201,12 @@ public class WeatherServiceSettings extends SettingsPreferenceFragment

            weatherProviderServiceInfos.add(serviceInfo);
        }
        return weatherProviderServiceInfos;
    }

    private void updateAdapter() {
        final List<WeatherProviderServiceInfo> weatherProviderServiceInfos =
                getInstalledServices(getContext());

        final PreferenceScreen ps = getPreferenceScreen();
        if (!weatherProviderServiceInfos.isEmpty()) {
@@ -372,7 +380,7 @@ public class WeatherServiceSettings extends SettingsPreferenceFragment
        }
    }

    private ComponentName getSettingsComponent(PackageManager pm, ResolveInfo resolveInfo) {
    private static ComponentName getSettingsComponent(PackageManager pm, ResolveInfo resolveInfo) {
        if (resolveInfo == null
                || resolveInfo.serviceInfo == null
                || resolveInfo.serviceInfo.metaData == null) {
@@ -425,9 +433,9 @@ public class WeatherServiceSettings extends SettingsPreferenceFragment
        return cn == null ? null : ComponentName.unflattenFromString(cn);
    }

    private ComponentName getEnabledWeatherServiceProvider() {
    private static ComponentName getEnabledWeatherServiceProvider(Context context) {
        String activeWeatherServiceProvider = CMSettings.Secure.getString(
                mContext.getContentResolver(), CMSettings.Secure.WEATHER_PROVIDER_SERVICE);
                context.getContentResolver(), CMSettings.Secure.WEATHER_PROVIDER_SERVICE);
        if (activeWeatherServiceProvider == null) return null;
        return ComponentName.unflattenFromString(activeWeatherServiceProvider);
    }
@@ -454,11 +462,27 @@ public class WeatherServiceSettings extends SettingsPreferenceFragment
        setEmptyView(emptyView);
    }

    private class WeatherProviderServiceInfo {
    private static class WeatherProviderServiceInfo {
        CharSequence caption;
        Drawable icon;
        boolean isActive;
        ComponentName componentName;
        public ComponentName settingsComponentName;
    }

    public static final SummaryProvider SUMMARY_PROVIDER = new SummaryProvider() {
        @Override
        public String getSummary(Context context, String key) {
            final List<WeatherProviderServiceInfo> infos = getInstalledServices(context);
            if (infos != null && infos.size() > 0) {
                for (WeatherProviderServiceInfo info : infos) {
                    if (info.isActive) {
                        Log.d(TAG, "cmparts: found active provider: " + info.caption);
                        return String.valueOf(info.caption);
                    }
                }
            }
            return context.getString(R.string.weather_settings_no_services_summary);
        }
    };
}