From 18b5630c0169d05fec4b40343ac70603c28a6e33 Mon Sep 17 00:00:00 2001 From: ezio84 Date: Wed, 21 Nov 2018 22:00:42 +0530 Subject: [PATCH 1/6] Full gestures nav: longpress to move keyboard cursors [2/2] --- res/values/custom_strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml index 6bd4be8549..9cada1c4d5 100644 --- a/res/values/custom_strings.xml +++ b/res/values/custom_strings.xml @@ -596,7 +596,7 @@ Enable full gesture mode - This mode will disable also the back button and you will be able to trigger a back button action by a left swipe on navbar. Right swipe will still trigger the last-app action and left swipe will move apps. To go home you will be able to tap on any navbar empty space, not only the home button. + This mode disables the back button and you can trigger a back button action by a left swipe on navbar. Right swipe still triggers the last-app and the overview apps scrolling. To go home you can tap on any navbar empty space, not only the home button. When keyboard is showing, long press on navbar to move the text cursor. Enable double tap to sleep Tap on an empty navbar space but not the home button to switch the screen off. From 5b8a883dcaf3f9f9e9429d4aa987b4961509d2b0 Mon Sep 17 00:00:00 2001 From: bigrushdog Date: Wed, 21 Nov 2018 20:28:09 +0100 Subject: [PATCH 2/6] Add Font preference for font manager --- AndroidManifest.xml | 1 + res/drawable/font_dialog_icon.xml | 8 + res/layout/font_item.xml | 60 ++++++++ res/values/custom_strings.xml | 6 +- res/xml/display_settings.xml | 5 + src/com/android/settings/DisplaySettings.java | 41 +++++ .../display/FontDialogPreference.java | 67 +++++++++ .../settings/display/FontListAdapter.java | 142 ++++++++++++++++++ .../FontPickerPreferenceController.java | 102 +++++++++++++ 9 files changed, 431 insertions(+), 1 deletion(-) create mode 100644 res/drawable/font_dialog_icon.xml create mode 100644 res/layout/font_item.xml create mode 100644 src/com/android/settings/display/FontDialogPreference.java create mode 100644 src/com/android/settings/display/FontListAdapter.java create mode 100644 src/com/android/settings/display/FontPickerPreferenceController.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index bbbba36cc3..716028111e 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -23,6 +23,7 @@ + diff --git a/res/drawable/font_dialog_icon.xml b/res/drawable/font_dialog_icon.xml new file mode 100644 index 0000000000..fb1f234f47 --- /dev/null +++ b/res/drawable/font_dialog_icon.xml @@ -0,0 +1,8 @@ + + + + diff --git a/res/layout/font_item.xml b/res/layout/font_item.xml new file mode 100644 index 0000000000..d117753d21 --- /dev/null +++ b/res/layout/font_item.xml @@ -0,0 +1,60 @@ + + + + + + + + + + diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml index 9cada1c4d5..b33bc2fae1 100644 --- a/res/values/custom_strings.xml +++ b/res/values/custom_strings.xml @@ -638,7 +638,7 @@ Transparent - Battery Info + Battery info Advanced battery information Capacity Charge cycles @@ -648,4 +648,8 @@ Voltage Health + + Font manager + Font picker is unavailable to avoid conflicts with Substratum. Uninstall it if you wish to use the font picker. + \ No newline at end of file diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml index 5b434294af..56e2280db7 100644 --- a/res/xml/display_settings.xml +++ b/res/xml/display_settings.xml @@ -219,6 +219,11 @@ android:key="density_category" android:title="@string/density_category"> + + buildPreferenceControllers( controllers.add(new AccentPickerPreferenceController(context, lifecycle, fragment)); controllers.add(new CameraGesturePreferenceController(context)); controllers.add(new DarkUIPreferenceController(context)); + controllers.add(mFontPickerPreference = new FontPickerPreferenceController(context, lifecycle, fragment)); controllers.add(new LiftToWakePreferenceController(context)); controllers.add(new NightDisplayPreferenceController(context)); controllers.add(new NightModePreferenceController(context)); diff --git a/src/com/android/settings/display/FontDialogPreference.java b/src/com/android/settings/display/FontDialogPreference.java new file mode 100644 index 0000000000..5339fbd860 --- /dev/null +++ b/src/com/android/settings/display/FontDialogPreference.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2018 The Dirty Unicorns 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. + * + * preference for managing custom fonts + */ +package com.android.settings.display; +import com.android.settingslib.CustomDialogPreference; +import android.app.AlertDialog.Builder; +import android.content.Context; +import android.content.DialogInterface; +import android.content.FontInfo; +import android.content.IFontService; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.util.AttributeSet; +import android.widget.ListView; +import com.android.settings.R; +public class FontDialogPreference extends CustomDialogPreference { + private static final String TAG = "FontDialogPreference"; + private Context mContext; + private IFontService mFontService; + public FontDialogPreference(Context context, AttributeSet attrs) { + super(context, attrs); + mContext = context; + mFontService = IFontService.Stub.asInterface( + ServiceManager.getService("liquidfont")); + } + @Override + protected void onPrepareDialogBuilder(Builder builder, + DialogInterface.OnClickListener listener) { + super.onPrepareDialogBuilder(builder, listener); + FontListAdapter adapter = new FontListAdapter(mContext); + DialogInterface.OnClickListener l = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + FontInfo info = adapter.getItem(which); + try { + mFontService.applyFont(info); + } catch (RemoteException e) { + } + } + }; + builder.setIcon(R.drawable.font_dialog_icon); + builder.setAdapter(adapter, l); + builder.setCancelable(false); + builder.setNegativeButton(mContext.getString(com.android.internal.R.string.cancel), + listener); + } + @Override + protected void onClick(DialogInterface dialog, int which) { + if (which == DialogInterface.BUTTON_NEGATIVE) { + dialog.dismiss(); + } + } +} diff --git a/src/com/android/settings/display/FontListAdapter.java b/src/com/android/settings/display/FontListAdapter.java new file mode 100644 index 0000000000..ddf10a9427 --- /dev/null +++ b/src/com/android/settings/display/FontListAdapter.java @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2018 The Dirty Unicorns 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. + * + * Adapter for displaying a list of custom fonts with font Typeface + */ +package com.android.settings.display; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import com.android.settings.R; +import android.content.Context; +import android.content.FontInfo; +import android.content.IFontService; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.graphics.Typeface; +import android.graphics.drawable.Drawable; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.text.TextUtils; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.ImageView; +import android.widget.TextView; +public class FontListAdapter extends BaseAdapter { + private static final String TAG = "FontListAdapter"; + private IFontService mFontService; + private List mFontInfo = new ArrayList(); + private Context mContext; + private LayoutInflater mInflater; + private PackageManager mPm; + public FontListAdapter(Context context) { + mContext = context; + mInflater = LayoutInflater.from(context); + mFontService = IFontService.Stub.asInterface( + ServiceManager.getService("liquidfont")); + mPm = context.getPackageManager(); + loadFontList(); + } + public void loadFontList() { + mFontInfo.clear(); + try { + Map> fontMap = mFontService.getAllFonts(); + for (Map.Entry> entry : fontMap.entrySet()) { + String packageName = entry.getKey(); + List fonts = entry.getValue(); + // manually add system font after we sort + if (TextUtils.equals(packageName, FontInfo.DEFAULT_FONT_PACKAGE)) { + continue; + } + for (FontInfo font : fonts) { + mFontInfo.add(new FontInfo(font)); + } + } + Collections.sort(mFontInfo); + } catch (RemoteException e) { + Log.e(TAG, "Error in populating list"); + } + mFontInfo.add(0, FontInfo.getDefaultFontInfo()); + notifyDataSetChanged(); + } + @Override + public int getCount() { + return mFontInfo.size(); + } + @Override + public FontInfo getItem(int position) { + return mFontInfo.get(position); + } + @Override + public long getItemId(int position) { + return 0; + } + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder holder; + final Context ctx = mContext; + if (convertView != null) { + holder = (ViewHolder) convertView.getTag(); + } else { + convertView = mInflater.inflate(R.layout.font_item, null, false); + holder = new ViewHolder(); + convertView.setTag(holder); + holder.title = (TextView) convertView.findViewById(com.android.internal.R.id.title); + holder.summary = (TextView) convertView + .findViewById(com.android.internal.R.id.summary); + holder.icon = (ImageView) convertView.findViewById(R.id.icon); + } + FontInfo info = getItem(position); + Typeface.Builder builder = new Typeface.Builder(info.previewPath); + Typeface tf = builder.build(); + holder.title.setTypeface(tf); + holder.title.setText(info.fontName.replace("_", " ")); + holder.summary.setTypeface(tf); + holder.summary.setText(getPackageLabel(info.packageName).replace("_", " ")); + holder.icon.setImageDrawable(getPackageDrawable(info.packageName)); + return convertView; + } + private String getPackageLabel(String packageName) { + String label = null; + if (packageName.equals("android")) { + return "Android"; + } + try { + ApplicationInfo info = mPm.getApplicationInfo(packageName, 0); + label = (String) info.loadLabel(mPm); + } finally { + return label; + } + } + private Drawable getPackageDrawable(String packageName) { + Drawable icon = null; + try { + ApplicationInfo info = mPm.getApplicationInfo(packageName, 0); + icon = info.loadIcon(mPm); + } finally { + return icon; + } + } + private static class ViewHolder { + TextView title; + TextView summary; + ImageView icon; + } +} diff --git a/src/com/android/settings/display/FontPickerPreferenceController.java b/src/com/android/settings/display/FontPickerPreferenceController.java new file mode 100644 index 0000000000..12e369ca58 --- /dev/null +++ b/src/com/android/settings/display/FontPickerPreferenceController.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2017 The Android Open Source 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.display; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import com.android.settings.core.PreferenceControllerMixin; +import com.android.settingslib.core.AbstractPreferenceController; +import com.android.settingslib.core.lifecycle.Lifecycle; +import com.android.settingslib.core.lifecycle.LifecycleObserver; +import com.android.settingslib.core.lifecycle.events.OnResume; +import com.android.settings.liquid.AccentPicker; +import android.app.Fragment; +import android.content.Context; +import android.content.FontInfo; +import android.content.IFontService; +import android.content.pm.PackageManager; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.support.v7.preference.ListPreference; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceScreen; +import android.support.v7.preference.Preference.OnPreferenceClickListener; +import android.text.TextUtils; +import android.util.Log; +public class FontPickerPreferenceController extends AbstractPreferenceController + implements PreferenceControllerMixin, LifecycleObserver, OnResume { + private static final String TAG = "FontPickerPreferenceController"; + private static final String KEY_FONT_PICKER_FRAGMENT_PREF = "custom_font"; + private static final String SUBS_PACKAGE = "projekt.substratum"; + private FontDialogPreference mFontPreference; + private IFontService mFontService; + public FontPickerPreferenceController(Context context, Lifecycle lifecycle, Fragment parent) { + super(context); + if (lifecycle != null) { + lifecycle.addObserver(this); + } + mFontService = IFontService.Stub.asInterface( + ServiceManager.getService("liquidfont")); + } + @Override + public void onResume() { + if (mFontPreference == null) { + return; + } + if (!isPackageInstalled(SUBS_PACKAGE, mContext)) { + mFontPreference.setSummary(getCurrentFontInfo().fontName.replace("_", " ")); + } else { + mFontPreference.setSummary(mContext.getString( + com.android.settings.R.string.disable_fonts_installed_title)); + } + } + @Override + public void displayPreference(PreferenceScreen screen) { + mFontPreference = (FontDialogPreference) screen.findPreference(KEY_FONT_PICKER_FRAGMENT_PREF); + if (!isPackageInstalled(SUBS_PACKAGE, mContext)) { + mFontPreference.setEnabled(true); + } else { + mFontPreference.setEnabled(false); + } + } + @Override + public boolean isAvailable() { + return true; + } + @Override + public String getPreferenceKey() { + return KEY_FONT_PICKER_FRAGMENT_PREF; + } + private FontInfo getCurrentFontInfo() { + try { + return mFontService.getFontInfo(); + } catch (RemoteException e) { + return FontInfo.getDefaultFontInfo(); + } + } + private boolean isPackageInstalled(String package_name, Context context) { + try { + PackageManager pm = context.getPackageManager(); + pm.getPackageInfo(package_name, PackageManager.GET_ACTIVITIES); + return true; + } catch (Exception e) { + return false; + } + } +} From e82a55c9b540e1e677d541552a43f6655a73d337 Mon Sep 17 00:00:00 2001 From: maxwen Date: Fri, 23 Nov 2018 00:55:37 +0530 Subject: [PATCH 3/6] Add progress for font apply [2/2] --- res/values/custom_strings.xml | 1 + .../display/FontDialogPreference.java | 28 +++++++++++++++++-- .../FontPickerPreferenceController.java | 3 ++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml index b33bc2fae1..c84551b892 100644 --- a/res/values/custom_strings.xml +++ b/res/values/custom_strings.xml @@ -651,5 +651,6 @@ Font manager Font picker is unavailable to avoid conflicts with Substratum. Uninstall it if you wish to use the font picker. + Applying new font\u2026 \ No newline at end of file diff --git a/src/com/android/settings/display/FontDialogPreference.java b/src/com/android/settings/display/FontDialogPreference.java index 5339fbd860..f3c53d6533 100644 --- a/src/com/android/settings/display/FontDialogPreference.java +++ b/src/com/android/settings/display/FontDialogPreference.java @@ -16,8 +16,9 @@ * preference for managing custom fonts */ package com.android.settings.display; -import com.android.settingslib.CustomDialogPreference; + import android.app.AlertDialog.Builder; +import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; import android.content.FontInfo; @@ -25,12 +26,15 @@ import android.os.RemoteException; import android.os.ServiceManager; import android.util.AttributeSet; -import android.widget.ListView; + import com.android.settings.R; +import com.android.settingslib.CustomDialogPreference; + public class FontDialogPreference extends CustomDialogPreference { private static final String TAG = "FontDialogPreference"; private Context mContext; private IFontService mFontService; + private ProgressDialog mProgressDialog; public FontDialogPreference(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; @@ -47,8 +51,10 @@ protected void onPrepareDialogBuilder(Builder builder, public void onClick(DialogInterface dialog, int which) { FontInfo info = adapter.getItem(which); try { + startProgress(); mFontService.applyFont(info); } catch (RemoteException e) { + startProgress(); } } }; @@ -64,4 +70,22 @@ protected void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } } + private void startProgress() { + if(mProgressDialog != null) { + stopProgress(); + } + mProgressDialog = new ProgressDialog(mContext); + mProgressDialog.setIndeterminate(true); + mProgressDialog.setTitle(mContext.getString(R.string.font_picker_title)); + mProgressDialog.setMessage(mContext.getString(R.string.font_picker_progress)); + mProgressDialog.setCancelable(false); + mProgressDialog.setCanceledOnTouchOutside(false); + mProgressDialog.show(); + } + public void stopProgress() { + if (mProgressDialog != null) { + mProgressDialog.dismiss(); + mProgressDialog = null; + } + } } diff --git a/src/com/android/settings/display/FontPickerPreferenceController.java b/src/com/android/settings/display/FontPickerPreferenceController.java index 12e369ca58..54f4d4b30c 100644 --- a/src/com/android/settings/display/FontPickerPreferenceController.java +++ b/src/com/android/settings/display/FontPickerPreferenceController.java @@ -90,6 +90,9 @@ private FontInfo getCurrentFontInfo() { return FontInfo.getDefaultFontInfo(); } } + public void stopProgress() { + mFontPreference.stopProgress(); + } private boolean isPackageInstalled(String package_name, Context context) { try { PackageManager pm = context.getPackageManager(); From bc5afad728c94676add5ee405a04639a495fc944 Mon Sep 17 00:00:00 2001 From: Anushek Prasal Date: Fri, 23 Nov 2018 17:00:58 +0530 Subject: [PATCH 4/6] Make Font Picker play nice with substratum --- .../FontPickerPreferenceController.java | 49 ++++--------------- 1 file changed, 10 insertions(+), 39 deletions(-) diff --git a/src/com/android/settings/display/FontPickerPreferenceController.java b/src/com/android/settings/display/FontPickerPreferenceController.java index 54f4d4b30c..43780255f4 100644 --- a/src/com/android/settings/display/FontPickerPreferenceController.java +++ b/src/com/android/settings/display/FontPickerPreferenceController.java @@ -14,36 +14,25 @@ * limitations under the License. */ package com.android.settings.display; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import com.android.settings.core.PreferenceControllerMixin; -import com.android.settingslib.core.AbstractPreferenceController; -import com.android.settingslib.core.lifecycle.Lifecycle; -import com.android.settingslib.core.lifecycle.LifecycleObserver; -import com.android.settingslib.core.lifecycle.events.OnResume; -import com.android.settings.liquid.AccentPicker; + import android.app.Fragment; import android.content.Context; import android.content.FontInfo; import android.content.IFontService; -import android.content.pm.PackageManager; import android.os.RemoteException; import android.os.ServiceManager; -import android.support.v7.preference.ListPreference; -import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceScreen; -import android.support.v7.preference.Preference.OnPreferenceClickListener; -import android.text.TextUtils; -import android.util.Log; + +import com.android.settings.core.PreferenceControllerMixin; +import com.android.settingslib.core.AbstractPreferenceController; +import com.android.settingslib.core.lifecycle.Lifecycle; +import com.android.settingslib.core.lifecycle.LifecycleObserver; +import com.android.settingslib.core.lifecycle.events.OnResume; + public class FontPickerPreferenceController extends AbstractPreferenceController implements PreferenceControllerMixin, LifecycleObserver, OnResume { private static final String TAG = "FontPickerPreferenceController"; private static final String KEY_FONT_PICKER_FRAGMENT_PREF = "custom_font"; - private static final String SUBS_PACKAGE = "projekt.substratum"; private FontDialogPreference mFontPreference; private IFontService mFontService; public FontPickerPreferenceController(Context context, Lifecycle lifecycle, Fragment parent) { @@ -59,21 +48,12 @@ public void onResume() { if (mFontPreference == null) { return; } - if (!isPackageInstalled(SUBS_PACKAGE, mContext)) { - mFontPreference.setSummary(getCurrentFontInfo().fontName.replace("_", " ")); - } else { - mFontPreference.setSummary(mContext.getString( - com.android.settings.R.string.disable_fonts_installed_title)); - } + mFontPreference.setSummary(getCurrentFontInfo().fontName.replace("_", " ")); } @Override public void displayPreference(PreferenceScreen screen) { mFontPreference = (FontDialogPreference) screen.findPreference(KEY_FONT_PICKER_FRAGMENT_PREF); - if (!isPackageInstalled(SUBS_PACKAGE, mContext)) { - mFontPreference.setEnabled(true); - } else { - mFontPreference.setEnabled(false); - } + mFontPreference.setEnabled(true); } @Override public boolean isAvailable() { @@ -93,13 +73,4 @@ private FontInfo getCurrentFontInfo() { public void stopProgress() { mFontPreference.stopProgress(); } - private boolean isPackageInstalled(String package_name, Context context) { - try { - PackageManager pm = context.getPackageManager(); - pm.getPackageInfo(package_name, PackageManager.GET_ACTIVITIES); - return true; - } catch (Exception e) { - return false; - } - } } From 15c2bdfb99f8c4575f8a483af387e1c2dfd68fb6 Mon Sep 17 00:00:00 2001 From: Ting Yu Date: Thu, 18 Oct 2018 16:56:22 +0800 Subject: [PATCH 5/6] Phone ringtone setting for Multi SIM device Support displaying phone ringtone setting for each slot as follows: "Phone ringtone - SIM 1" "Phone ringtone - SIM 2" The purpose is to distinguish incoming call from each slot by ringtone. This is one of a 3 part commit. While the corresponding commits for fwb and services_Telecomm were already present, the commit for Settings probably got overlooked which caused no ringtone for calls on 2nd sim. Signed-off-by: DennySPB Signed-off-by: sayan7848 --- res/values/custom_strings.xml | 7 +- res/xml/sound_settings.xml | 14 ++- .../settings/DefaultRingtonePreference.java | 6 +- .../android/settings/RingtonePreference.java | 25 ++++- .../PhoneRingtone2PreferenceController.java | 62 ++++++++++++ .../PhoneRingtonePreferenceController.java | 20 ++++ .../RingtonePreferenceControllerBase.java | 4 +- .../settings/notification/SoundSettings.java | 1 + ...honeRingtone2PreferenceControllerTest.java | 98 +++++++++++++++++++ ...PhoneRingtonePreferenceControllerTest.java | 20 ++++ .../settings/ui/SoundSettingsTest.java | 42 ++++++-- 11 files changed, 284 insertions(+), 15 deletions(-) create mode 100644 src/com/android/settings/notification/PhoneRingtone2PreferenceController.java create mode 100644 tests/robotests/src/com/android/settings/notification/PhoneRingtone2PreferenceControllerTest.java diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml index c84551b892..0ef4860a02 100644 --- a/res/values/custom_strings.xml +++ b/res/values/custom_strings.xml @@ -653,4 +653,9 @@ Font picker is unavailable to avoid conflicts with Substratum. Uninstall it if you wish to use the font picker. Applying new font\u2026 - \ No newline at end of file + + Phone ringtone - SIM 1 + + Phone ringtone - SIM 2 + + diff --git a/res/xml/sound_settings.xml b/res/xml/sound_settings.xml index dfb1f9403f..2f2d47e6ef 100644 --- a/res/xml/sound_settings.xml +++ b/res/xml/sound_settings.xml @@ -110,6 +110,16 @@ android:ringtoneType="ringtone" android:order="-100"/> + + + + android:order="-80"/> + android:order="-70"/> * If the user chooses the "Default" item, the saved string will be one of * {@link System#DEFAULT_RINGTONE_URI}, + * {@link System#DEFAULT_RINGTONE2_URI}, * {@link System#DEFAULT_NOTIFICATION_URI}, or * {@link System#DEFAULT_ALARM_ALERT_URI}. If the user chooses the "Silent" * item, the saved string will be an empty string. @@ -50,6 +51,9 @@ public class RingtonePreference extends Preference { private static final String TAG = "RingtonePreference"; + // Default is slot0 + private int mSlotId = 0; + private int mRingtoneType; private boolean mShowDefault; private boolean mShowSilent; @@ -83,6 +87,25 @@ public int getUserId() { return mUserId; } + /** + * Sets the slot id that this preference belongs to. + * + * @param slotId The slot id that this preference belongs to. + */ + public void setSlotId(int slotId) { + mSlotId = slotId; + } + + /** + * Returns the slot id that this preference belongs to. + * + * @return The slot id that this preference belongs to. + * @see #setSlotId(int) + */ + public int getSlotId() { + return mSlotId; + } + /** * Returns the sound type(s) that are shown in the picker. * @@ -161,7 +184,7 @@ public void onPrepareRingtonePickerIntent(Intent ringtonePickerIntent) { ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, mShowDefault); if (mShowDefault) { ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, - RingtoneManager.getDefaultUri(getRingtoneType())); + RingtoneManager.getDefaultUriBySlot(getRingtoneType(), getSlotId())); } ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, mShowSilent); diff --git a/src/com/android/settings/notification/PhoneRingtone2PreferenceController.java b/src/com/android/settings/notification/PhoneRingtone2PreferenceController.java new file mode 100644 index 0000000000..a48590b6cf --- /dev/null +++ b/src/com/android/settings/notification/PhoneRingtone2PreferenceController.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2018 The Android Open Source 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.notification; + +import android.content.Context; +import android.media.RingtoneManager; +import android.telephony.TelephonyManager; + +import android.support.v7.preference.PreferenceScreen; + +import com.android.settings.DefaultRingtonePreference; +import com.android.settings.Utils; + +public class PhoneRingtone2PreferenceController extends RingtonePreferenceControllerBase { + + private static final int SLOT_ID = 1; + private static final String KEY_PHONE_RINGTONE2 = "ringtone2"; + + public PhoneRingtone2PreferenceController(Context context) { + super(context); + } + + @Override + public void displayPreference(PreferenceScreen screen) { + super.displayPreference(screen); + + DefaultRingtonePreference ringtonePreference = + (DefaultRingtonePreference) screen.findPreference(KEY_PHONE_RINGTONE2); + ringtonePreference.setSlotId(SLOT_ID); + } + + @Override + public String getPreferenceKey() { + return KEY_PHONE_RINGTONE2; + } + + @Override + public boolean isAvailable() { + TelephonyManager telephonyManager = + (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); + return Utils.isVoiceCapable(mContext) && telephonyManager.isMultiSimEnabled(); + } + + @Override + public int getRingtoneType() { + return RingtoneManager.TYPE_RINGTONE; + } +} diff --git a/src/com/android/settings/notification/PhoneRingtonePreferenceController.java b/src/com/android/settings/notification/PhoneRingtonePreferenceController.java index cb1115165f..6c7a8f0e39 100644 --- a/src/com/android/settings/notification/PhoneRingtonePreferenceController.java +++ b/src/com/android/settings/notification/PhoneRingtonePreferenceController.java @@ -18,6 +18,12 @@ import android.content.Context; import android.media.RingtoneManager; +import android.telephony.TelephonyManager; + +import android.support.v7.preference.PreferenceScreen; + +import com.android.settings.DefaultRingtonePreference; +import com.android.settings.R; import com.android.settings.Utils; public class PhoneRingtonePreferenceController extends RingtonePreferenceControllerBase { @@ -28,6 +34,20 @@ public PhoneRingtonePreferenceController(Context context) { super(context); } + @Override + public void displayPreference(PreferenceScreen screen) { + super.displayPreference(screen); + + TelephonyManager telephonyManager = + (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); + if (telephonyManager.isMultiSimEnabled()) { + // For Multi SIM device, shoud show "Phone ringtone - SIM 1" for slot1 ringtone setting. + DefaultRingtonePreference ringtonePreference = + (DefaultRingtonePreference) screen.findPreference(KEY_PHONE_RINGTONE); + ringtonePreference.setTitle(mContext.getString(R.string.ringtone1_title)); + } + } + @Override public String getPreferenceKey() { return KEY_PHONE_RINGTONE; diff --git a/src/com/android/settings/notification/RingtonePreferenceControllerBase.java b/src/com/android/settings/notification/RingtonePreferenceControllerBase.java index 09a47b7d30..d02273862a 100644 --- a/src/com/android/settings/notification/RingtonePreferenceControllerBase.java +++ b/src/com/android/settings/notification/RingtonePreferenceControllerBase.java @@ -22,6 +22,7 @@ import android.net.Uri; import android.support.v7.preference.Preference; +import com.android.settings.RingtonePreference; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.core.AbstractPreferenceController; @@ -44,7 +45,8 @@ public boolean isAvailable() { @Override public void updateState(Preference preference) { - Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(mContext, getRingtoneType()); + Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUriBySlot(mContext, + getRingtoneType(), ((RingtonePreference)preference).getSlotId()); final CharSequence summary = Ringtone.getTitle( mContext, ringtoneUri, false /* followSettingsUri */, true /* allowRemote */); if (summary != null) { diff --git a/src/com/android/settings/notification/SoundSettings.java b/src/com/android/settings/notification/SoundSettings.java index 4e68b7e957..49325a13c8 100644 --- a/src/com/android/settings/notification/SoundSettings.java +++ b/src/com/android/settings/notification/SoundSettings.java @@ -269,6 +269,7 @@ private static List buildPreferenceControllers(Con // === Phone & notification ringtone === controllers.add(new PhoneRingtonePreferenceController(context)); + controllers.add(new PhoneRingtone2PreferenceController(context)); controllers.add(new AlarmRingtonePreferenceController(context)); controllers.add(new NotificationRingtonePreferenceController(context)); controllers.add(new IncreasingRingPreferenceController(context)); diff --git a/tests/robotests/src/com/android/settings/notification/PhoneRingtone2PreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/PhoneRingtone2PreferenceControllerTest.java new file mode 100644 index 0000000000..87fa6a5038 --- /dev/null +++ b/tests/robotests/src/com/android/settings/notification/PhoneRingtone2PreferenceControllerTest.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2018 The Android Open Source 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.notification; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.media.RingtoneManager; +import android.telephony.TelephonyManager; + +import android.support.v7.preference.PreferenceScreen; + +import com.android.settings.DefaultRingtonePreference; +import com.android.settings.testutils.SettingsRobolectricTestRunner; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.shadows.ShadowApplication; + +@RunWith(SettingsRobolectricTestRunner.class) +public class PhoneRingtone2PreferenceControllerTest { + + @Mock + private TelephonyManager mTelephonyManager; + @Mock + private PreferenceScreen mPreferenceScreen; + @Mock + private DefaultRingtonePreference mPreference; + + private Context mContext; + private PhoneRingtone2PreferenceController mController; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + ShadowApplication shadowContext = ShadowApplication.getInstance(); + shadowContext.setSystemService(Context.TELEPHONY_SERVICE, mTelephonyManager); + mContext = RuntimeEnvironment.application; + mController = new PhoneRingtone2PreferenceController(mContext); + } + + @Test + public void displayPreference_shouldSetSlotId() { + when(mPreferenceScreen.findPreference(mController.getPreferenceKey())) + .thenReturn(mPreference); + mController.displayPreference(mPreferenceScreen); + + verify(mPreference).setSlotId(1); + } + + @Test + public void isAvailable_notVoiceCapable_shouldReturnFalse() { + when(mTelephonyManager.isVoiceCapable()).thenReturn(false); + + assertThat(mController.isAvailable()).isFalse(); + } + + @Test + public void isAvailable_notMultiSimEnabled_shouldReturnFalse() { + when(mTelephonyManager.isMultiSimEnabled()).thenReturn(false); + + assertThat(mController.isAvailable()).isFalse(); + } + + @Test + public void isAvailable_VoiceCapable_and_MultiSimEnabled_shouldReturnTrue() { + when(mTelephonyManager.isVoiceCapable()).thenReturn(true); + when(mTelephonyManager.isMultiSimEnabled()).thenReturn(true); + + assertThat(mController.isAvailable()).isTrue(); + } + + @Test + public void getRingtoneType_shouldReturnRingtone() { + assertThat(mController.getRingtoneType()).isEqualTo(RingtoneManager.TYPE_RINGTONE); + } +} diff --git a/tests/robotests/src/com/android/settings/notification/PhoneRingtonePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/PhoneRingtonePreferenceControllerTest.java index 98cbc76dc5..425ace3e46 100644 --- a/tests/robotests/src/com/android/settings/notification/PhoneRingtonePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/PhoneRingtonePreferenceControllerTest.java @@ -17,12 +17,18 @@ package com.android.settings.notification; import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.media.RingtoneManager; import android.telephony.TelephonyManager; +import android.support.v7.preference.PreferenceScreen; + +import com.android.settings.DefaultRingtonePreference; +import com.android.settings.R; import com.android.settings.testutils.SettingsRobolectricTestRunner; import org.junit.Before; @@ -38,6 +44,10 @@ public class PhoneRingtonePreferenceControllerTest { @Mock private TelephonyManager mTelephonyManager; + @Mock + private PreferenceScreen mPreferenceScreen; + @Mock + private DefaultRingtonePreference mPreference; private Context mContext; private PhoneRingtonePreferenceController mController; @@ -51,6 +61,16 @@ public void setUp() { mController = new PhoneRingtonePreferenceController(mContext); } + @Test + public void displayPreference_shouldUpdateTitle_for_MultiSimDevice() { + when(mTelephonyManager.isMultiSimEnabled()).thenReturn(true); + when(mPreferenceScreen.findPreference(mController.getPreferenceKey())) + .thenReturn(mPreference); + mController.displayPreference(mPreferenceScreen); + + verify(mPreference).setTitle(mContext.getString(R.string.ringtone1_title)); + } + @Test public void isAvailable_notVoiceCapable_shouldReturnFalse() { when(mTelephonyManager.isVoiceCapable()).thenReturn(false); diff --git a/tests/uitests/src/com/android/settings/ui/SoundSettingsTest.java b/tests/uitests/src/com/android/settings/ui/SoundSettingsTest.java index 0aec505185..742ea4952b 100644 --- a/tests/uitests/src/com/android/settings/ui/SoundSettingsTest.java +++ b/tests/uitests/src/com/android/settings/ui/SoundSettingsTest.java @@ -29,6 +29,7 @@ import android.support.test.uiautomator.By; import android.support.test.uiautomator.UiDevice; import android.support.test.uiautomator.Until; +import android.telephony.TelephonyManager; import android.test.InstrumentationTestCase; import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.Suppress; @@ -42,6 +43,7 @@ public class SoundSettingsTest extends InstrumentationTestCase { private UiDevice mDevice; private ContentResolver mResolver; private SettingsHelper mHelper; + private TelephonyManager mTelephonyManager; private HashMap ringtoneSounds = new HashMap() {{ @@ -106,6 +108,8 @@ public void setUp() throws Exception { mDevice.setOrientationNatural(); mResolver = getInstrumentation().getContext().getContentResolver(); mHelper = new SettingsHelper(); + mTelephonyManager = (TelephonyManager) getInstrumentation().getContext() + .getSystemService(Context.TELEPHONY_SERVICE); } @Override @@ -187,27 +191,49 @@ private void launchSoundSettings() throws Exception { @MediumTest public void testPhoneRingtoneNone() throws Exception { launchSoundSettings(); - mHelper.clickSetting("Phone ringtone"); - verifyRingtone(new RingtoneSetting("None", "null"), - Settings.System.RINGTONE); + if (mTelephonyManager.isMultiSimEnabled()) { + mHelper.clickSetting("Phone ringtone - SIM 1"); + verifyRingtone(new RingtoneSetting("None", "null"), Settings.System.RINGTONE); + mHelper.clickSetting("Phone ringtone - SIM 2"); + verifyRingtone(new RingtoneSetting("None", "null"), Settings.System.RINGTONE2); + } else { + mHelper.clickSetting("Phone ringtone"); + verifyRingtone(new RingtoneSetting("None", "null"), Settings.System.RINGTONE); + } } @MediumTest @Suppress public void testPhoneRingtoneHangouts() throws Exception { launchSoundSettings(); - mHelper.clickSetting("Phone ringtone"); - verifyRingtone(new RingtoneSetting("Hangouts Call", "31"), Settings.System.RINGTONE); + if (mTelephonyManager.isMultiSimEnabled()) { + mHelper.clickSetting("Phone ringtone - SIM 1"); + verifyRingtone(new RingtoneSetting("Hangouts Call", "31"), Settings.System.RINGTONE); + mHelper.clickSetting("Phone ringtone - SIM 2"); + verifyRingtone(new RingtoneSetting("Hangouts Call", "31"), Settings.System.RINGTONE2); + } else { + mHelper.clickSetting("Phone ringtone"); + verifyRingtone(new RingtoneSetting("Hangouts Call", "31"), Settings.System.RINGTONE); + } } @MediumTest public void testPhoneRingtone() throws Exception { launchSoundSettings(); - mHelper.clickSetting("Phone ringtone"); String ringtone = ringtoneSounds.get(mDevice.getProductName()).toString(); String ringtoneSettingValue = ringtoneCodes.get(mDevice.getProductName()).toString(); - verifyRingtone(new RingtoneSetting(ringtone, ringtoneSettingValue), - Settings.System.RINGTONE); + if (mTelephonyManager.isMultiSimEnabled()) { + mHelper.clickSetting("Phone ringtone - SIM 1"); + verifyRingtone(new RingtoneSetting(ringtone, ringtoneSettingValue), + Settings.System.RINGTONE); + mHelper.clickSetting("Phone ringtone - SIM 2"); + verifyRingtone(new RingtoneSetting(ringtone, ringtoneSettingValue), + Settings.System.RINGTONE2); + } else { + mHelper.clickSetting("Phone ringtone"); + verifyRingtone(new RingtoneSetting(ringtone, ringtoneSettingValue), + Settings.System.RINGTONE); + } } @MediumTest From 72f130e4c0c7019dbd6b9279a79d3e0aa66f1e41 Mon Sep 17 00:00:00 2001 From: Ded_Boi Date: Sun, 18 Nov 2018 10:01:58 +0530 Subject: [PATCH 6/6] Remove QS activities for weather tile --- AndroidManifest.xml | 12 ------------ src/com/android/settings/Settings.java | 1 - .../settings/core/gateway/SettingsGateway.java | 2 -- 3 files changed, 15 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 716028111e..e6c5c0bf19 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -3541,18 +3541,6 @@ android:value="com.liquid.liquidlounge.fragments.SmartPixels" /> - - - - - - - - -