Cherish:add back weather parts [3/3]
Change-Id: Ife851b6769ea8e85c32653bb3104ebb0ab2527c1 Signed-off-by: mydongistiny <jaysonedson@gmail.com> Signed-off-by: DennySPb <dennyspb@gmail.com> Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
7
res/drawable/ic_cloud.xml
Normal file
7
res/drawable/ic_cloud.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="M19 18H6C3.79 18 2 16.21 2 14S3.79 10 6 10H6.71C7.37 7.69 9.5 6 12 6C15.04 6 17.5 8.46 17.5 11.5V12H19C20.66 12 22 13.34 22 15S20.66 18 19 18M19.35 10.03C18.67 6.59 15.64 4 12 4C9.11 4 6.6 5.64 5.35 8.03C2.34 8.36 0 10.9 0 14C0 17.31 2.69 20 6 20H19C21.76 20 24 17.76 24 15C24 12.36 21.95 10.22 19.35 10.03M10 17L6.5 13.5L7.91 12.08L10 14.17L14.59 9.59L16 11" />
|
||||
</vector>
|
||||
7
res/drawable/ic_weather.xml
Normal file
7
res/drawable/ic_weather.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="M12.74,5.47C15.1,6.5 16.35,9.03 15.92,11.46C17.19,12.56 18,14.19 18,16V16.17C18.31,16.06 18.65,16 19,16A3,3 0 0,1 22,19A3,3 0 0,1 19,22H6A4,4 0 0,1 2,18A4,4 0 0,1 6,14H6.27C5,12.45 4.6,10.24 5.5,8.26C6.72,5.5 9.97,4.24 12.74,5.47M11.93,7.3C10.16,6.5 8.09,7.31 7.31,9.07C6.85,10.09 6.93,11.22 7.41,12.13C8.5,10.83 10.16,10 12,10C12.7,10 13.38,10.12 14,10.34C13.94,9.06 13.18,7.86 11.93,7.3M13.55,3.64C13,3.4 12.45,3.23 11.88,3.12L14.37,1.82L15.27,4.71C14.76,4.29 14.19,3.93 13.55,3.64M6.09,4.44C5.6,4.79 5.17,5.19 4.8,5.63L4.91,2.82L7.87,3.5C7.25,3.71 6.65,4.03 6.09,4.44M18,9.71C17.91,9.12 17.78,8.55 17.59,8L19.97,9.5L17.92,11.73C18.03,11.08 18.05,10.4 18,9.71M3.04,11.3C3.11,11.9 3.24,12.47 3.43,13L1.06,11.5L3.1,9.28C3,9.93 2.97,10.61 3.04,11.3M19,18H16V16A4,4 0 0,0 12,12A4,4 0 0,0 8,16H6A2,2 0 0,0 4,18A2,2 0 0,0 6,20H19A1,1 0 0,0 20,19A1,1 0 0,0 19,18Z" />
|
||||
</vector>
|
||||
@@ -523,4 +523,18 @@
|
||||
<!-- Hide Lockscreen shortcuts on secure Lockscreen -->
|
||||
<string name="lockscreen_hide_shortcuts_title">Hide Bottom Shortcuts</string>
|
||||
<string name="lockscreen_hide_shortcuts_summary">Hide Left-Right Shortcuts on secure lock screens</string>
|
||||
|
||||
<!-- Lockscreen weather -->
|
||||
<string name="lockscreen_weather_category">Weather</string>
|
||||
<string name="lockscreen_weather_enabled_title">Show on lockscreen</string>
|
||||
<string name="lockscreen_weather_enabled_summary">Show weather information on lockscreen and during doze</string>
|
||||
<string name="lockscreen_weather_settings_title">Setup weather options</string>
|
||||
<string name="lockscreen_weather_settings_summary">Setup icon pack and weather service</string>
|
||||
<string name="weather_config_title">Weather service</string>
|
||||
<string name="weather_config_summary">System service settings</string>
|
||||
<string name="header_weather_title">Header view weather</string>
|
||||
<string name="header_weather_summary">Enable notification panel header weather display</string>
|
||||
<string name="weather_icon_pack_title">Condition icon pack</string>
|
||||
<string name="weather_icon_pack_note">Note\u003a you can install new icon packs from play store by searching for \"Chronus icons\"</string>
|
||||
<string name="weather_icon_pack_info_title">Condition icon pack is used in quick settings and lock screen</string>
|
||||
</resources>
|
||||
|
||||
@@ -195,6 +195,24 @@
|
||||
android:title="@string/lockscreen_hide_shortcuts_title"
|
||||
android:summary="@string/lockscreen_hide_shortcuts_summary"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="lockscreen_weather"
|
||||
android:title="@string/lockscreen_weather_category" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="lockscreen_weather_enabled"
|
||||
android:icon="@drawable/ic_cloud"
|
||||
android:title="@string/lockscreen_weather_enabled_title"
|
||||
android:summary="@string/lockscreen_weather_enabled_summary"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<Preference
|
||||
android:key="omnijaws_settings"
|
||||
android:icon="@drawable/ic_weather"
|
||||
android:title="@string/lockscreen_weather_settings_title"
|
||||
android:summary="@string/lockscreen_weather_settings_summary"
|
||||
android:fragment="com.cherish.settings.fragments.OmniJawsSettings" />
|
||||
|
||||
<!-- Lockscreen Visualizer-->
|
||||
<PreferenceCategory
|
||||
|
||||
39
res/xml/omnijaws_settings.xml
Normal file
39
res/xml/omnijaws_settings.xml
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2017 The OmniROM Project
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:key="omnijaws_settings"
|
||||
android:title="@string/weather_title">
|
||||
|
||||
<PreferenceScreen
|
||||
android:title="@string/weather_config_title"
|
||||
android:summary="@string/weather_config_summary" >
|
||||
<intent android:action="android.intent.action.MAIN"
|
||||
android:targetPackage="org.omnirom.omnijaws"
|
||||
android:targetClass="org.omnirom.omnijaws.SettingsActivityService" />
|
||||
</PreferenceScreen>
|
||||
|
||||
<ListPreference
|
||||
android:key="weather_icon_pack"
|
||||
android:title="@string/weather_icon_pack_title"
|
||||
android:persistent="false" />
|
||||
|
||||
<Preference
|
||||
android:icon="@drawable/ic_info_outline_24dp"
|
||||
android:persistent="false"
|
||||
android:summary="@string/weather_icon_pack_info_title" />
|
||||
</PreferenceScreen>
|
||||
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The OmniROM Project
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.cherish.settings.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class OmniJawsSettings extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener, Indexable {
|
||||
private static final String TAG = "OmniJawsSettings";
|
||||
private static final String CATEGORY_WEATHER = "weather_category";
|
||||
private static final String WEATHER_ICON_PACK = "weather_icon_pack";
|
||||
private static final String DEFAULT_WEATHER_ICON_PACKAGE = "org.omnirom.omnijaws";
|
||||
private static final String DEFAULT_WEATHER_ICON_PREFIX = "outline";
|
||||
private static final String WEATHER_SERVICE_PACKAGE = "org.omnirom.omnijaws";
|
||||
private static final String CHRONUS_ICON_PACK_INTENT = "com.dvtonder.chronus.ICON_PACK";
|
||||
|
||||
private PreferenceCategory mWeatherCategory;
|
||||
private ListPreference mWeatherIconPack;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.omnijaws_settings);
|
||||
final PreferenceScreen prefScreen = getPreferenceScreen();
|
||||
|
||||
mWeatherCategory = (PreferenceCategory) prefScreen.findPreference(CATEGORY_WEATHER);
|
||||
if (mWeatherCategory != null) {
|
||||
prefScreen.removePreference(mWeatherCategory);
|
||||
} else {
|
||||
String settingHeaderPackage = Settings.System.getString(getContentResolver(),
|
||||
Settings.System.OMNIJAWS_WEATHER_ICON_PACK);
|
||||
if (settingHeaderPackage == null) {
|
||||
settingHeaderPackage = DEFAULT_WEATHER_ICON_PACKAGE + "." + DEFAULT_WEATHER_ICON_PREFIX;
|
||||
}
|
||||
mWeatherIconPack = (ListPreference) findPreference(WEATHER_ICON_PACK);
|
||||
|
||||
List<String> entries = new ArrayList<String>();
|
||||
List<String> values = new ArrayList<String>();
|
||||
getAvailableWeatherIconPacks(entries, values);
|
||||
mWeatherIconPack.setEntries(entries.toArray(new String[entries.size()]));
|
||||
mWeatherIconPack.setEntryValues(values.toArray(new String[values.size()]));
|
||||
|
||||
int valueIndex = mWeatherIconPack.findIndexOfValue(settingHeaderPackage);
|
||||
if (valueIndex == -1) {
|
||||
// no longer found
|
||||
settingHeaderPackage = DEFAULT_WEATHER_ICON_PACKAGE + "." + DEFAULT_WEATHER_ICON_PREFIX;
|
||||
Settings.System.putString(getContentResolver(),
|
||||
Settings.System.OMNIJAWS_WEATHER_ICON_PACK, settingHeaderPackage);
|
||||
valueIndex = mWeatherIconPack.findIndexOfValue(settingHeaderPackage);
|
||||
}
|
||||
mWeatherIconPack.setValueIndex(valueIndex >= 0 ? valueIndex : 0);
|
||||
mWeatherIconPack.setSummary(mWeatherIconPack.getEntry());
|
||||
mWeatherIconPack.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
if (preference == mWeatherIconPack) {
|
||||
String value = (String) objValue;
|
||||
Settings.System.putString(getContentResolver(),
|
||||
Settings.System.OMNIJAWS_WEATHER_ICON_PACK, value);
|
||||
int valueIndex = mWeatherIconPack.findIndexOfValue(value);
|
||||
mWeatherIconPack.setSummary(mWeatherIconPack.getEntries()[valueIndex]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void getAvailableWeatherIconPacks(List<String> entries, List<String> values) {
|
||||
Intent i = new Intent();
|
||||
PackageManager packageManager = getPackageManager();
|
||||
i.setAction("org.omnirom.WeatherIconPack");
|
||||
for (ResolveInfo r : packageManager.queryIntentActivities(i, 0)) {
|
||||
String packageName = r.activityInfo.packageName;
|
||||
if (packageName.equals(DEFAULT_WEATHER_ICON_PACKAGE)) {
|
||||
values.add(0, r.activityInfo.name);
|
||||
} else {
|
||||
values.add(r.activityInfo.name);
|
||||
}
|
||||
String label = r.activityInfo.loadLabel(getPackageManager()).toString();
|
||||
if (label == null) {
|
||||
label = r.activityInfo.packageName;
|
||||
}
|
||||
if (packageName.equals(DEFAULT_WEATHER_ICON_PACKAGE)) {
|
||||
entries.add(0, label);
|
||||
} else {
|
||||
entries.add(label);
|
||||
}
|
||||
}
|
||||
i = new Intent(Intent.ACTION_MAIN);
|
||||
i.addCategory(CHRONUS_ICON_PACK_INTENT);
|
||||
for (ResolveInfo r : packageManager.queryIntentActivities(i, 0)) {
|
||||
String packageName = r.activityInfo.packageName;
|
||||
values.add(packageName + ".weather");
|
||||
String label = r.activityInfo.loadLabel(getPackageManager()).toString();
|
||||
if (label == null) {
|
||||
label = r.activityInfo.packageName;
|
||||
}
|
||||
entries.add(label);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOmniJawsEnabled() {
|
||||
final Uri SETTINGS_URI
|
||||
= Uri.parse("content://org.omnirom.omnijaws.provider/settings");
|
||||
|
||||
final String[] SETTINGS_PROJECTION = new String[] {
|
||||
"enabled"
|
||||
};
|
||||
|
||||
final Cursor c = getContentResolver().query(SETTINGS_URI, SETTINGS_PROJECTION,
|
||||
null, null, null);
|
||||
if (c != null) {
|
||||
int count = c.getCount();
|
||||
if (count == 1) {
|
||||
c.moveToPosition(0);
|
||||
boolean enabled = c.getInt(0) == 1;
|
||||
return enabled;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result =
|
||||
new ArrayList<SearchIndexableResource>();
|
||||
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.omnijaws_settings;
|
||||
result.add(sir);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user