From aec42a08b3cae18bf1771469ef7728de4a9ddfc9 Mon Sep 17 00:00:00 2001 From: minaripenguin Date: Wed, 5 Apr 2023 14:15:30 +0800 Subject: [PATCH] Cherish: Import Weather service API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Trishiraj Co-authored-by: maxwen Co-authored-by: LorDClockaN Signed-off-by: minaripenguin Signed-off-by: Hưng Phan --- res/values/cherish_arrays.xml | 53 +++++ res/values/cherish_strings.xml | 29 +++ res/xml/cherish_settings_misc.xml | 6 + res/xml/omnijaws_settings.xml | 60 ++++++ .../fragments/mics/OmniJawsSettings.java | 189 ++++++++++++++++++ 5 files changed, 337 insertions(+) create mode 100644 res/xml/omnijaws_settings.xml create mode 100644 src/com/cherish/settings/fragments/mics/OmniJawsSettings.java diff --git a/res/values/cherish_arrays.xml b/res/values/cherish_arrays.xml index 0bb17a7..26a9ffe 100644 --- a/res/values/cherish_arrays.xml +++ b/res/values/cherish_arrays.xml @@ -797,4 +797,57 @@ 11 12 + + + + @string/qs_weather_hidden + @string/qs_temperature_image_show_scale + @string/qs_temperature_image_hide_scale + @string/qs_temperature_show_scale_hide_image + @string/qs_temperature_hide_scale_hide_image + @string/qs_show_image + @string/weather_show_all_condition + + + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + + + + + @string/qs_weather_hidden + @string/qs_temperature_image_show_scale + @string/qs_temperature_image_hide_scale + @string/qs_temperature_show_scale_hide_image + @string/qs_temperature_hide_scale_hide_image + @string/qs_show_image + + + + 0 + 1 + 2 + 3 + 4 + 5 + + + + + @string/qsweather_position_qqs + @string/qsweather_position_qsb + @string/qsweather_position_both + + + + 0 + 1 + 2 + diff --git a/res/values/cherish_strings.xml b/res/values/cherish_strings.xml index bb86cbb..daa01de 100644 --- a/res/values/cherish_strings.xml +++ b/res/values/cherish_strings.xml @@ -914,4 +914,33 @@ Parallel space Allow running multiple instances of the same application in parallel + + QS System weather style + Configure system weather + QuickSettings weather location + Hide weather + Show temp with scale and image + Show temp with image without scale + Show temp with scale + Show temp without scale + Show image + Show temp with scale,image and weather condition + QuickSettings + QuickStatusbar + Both + Launcher System weather style + Lockscreen System weather style + + + Weather Settings + Setup icon pack and weather service + Weather Settings + Weather service + System service settings + Condition icon pack + Note\u003a you can install new icon packs from play store by searching for \"Chronus icons\" + Tips\u003a \n\n1. Users can install new icon packs from play store by searching for \"Chronus icons\".\n\n2. Condition icon pack is used for weather icons on quick settings and sushi launcher at a glance.\n\n3. Long press the QuickSettings weather view/logo/temperature to access weather settings with ease. + QuickSettings Weather + Setup quicksettings weather views + diff --git a/res/xml/cherish_settings_misc.xml b/res/xml/cherish_settings_misc.xml index dc4248e..52ea806 100644 --- a/res/xml/cherish_settings_misc.xml +++ b/res/xml/cherish_settings_misc.xml @@ -30,6 +30,12 @@ android:title="@string/laboratory_ignore_window_secure_title" android:summary="@string/laboratory_ignore_window_secure_summary" android:defaultValue="false"/> + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/cherish/settings/fragments/mics/OmniJawsSettings.java b/src/com/cherish/settings/fragments/mics/OmniJawsSettings.java new file mode 100644 index 0000000..15d70c1 --- /dev/null +++ b/src/com/cherish/settings/fragments/mics/OmniJawsSettings.java @@ -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 . + * +*/ + +package com.cherish.settings.fragments.misc; + +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.settingslib.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 entries = new ArrayList(); + List values = new ArrayList(); + 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 entries, List 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 getXmlResourcesToIndex(Context context, + boolean enabled) { + ArrayList result = + new ArrayList(); + + SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.omnijaws_settings; + result.add(sir); + + return result; + } + + @Override + public List getNonIndexableKeys(Context context) { + ArrayList result = new ArrayList(); + return result; + } + }; +}