From c336985e0d7038eab915c695e1d4beccb70ff441 Mon Sep 17 00:00:00 2001 From: liquid0624 Date: Fri, 21 Dec 2018 13:51:38 -0500 Subject: [PATCH] Revert "Ambient Play settings improvements" This reverts commit 4d870905dedb44b02fefe1c2f34f5f3ae36980ca. --- res/layout/ambient_play.xml | 26 ------ res/layout/switch_bar_ambient_play.xml | 46 ---------- res/values/custom_colors.xml | 4 +- res/values/custom_strings.xml | 12 ++- res/values/custom_styles.xml | 5 -- res/xml/ambient_play_settings.xml | 26 +++--- .../android/settings/AmbientPlaySettings.java | 89 +++---------------- ...bientPlayKeyguardPreferenceController.java | 77 ++++++++++++++++ .../AmbientPlayPreferenceController.java | 77 ++++++++++++++++ 9 files changed, 185 insertions(+), 177 deletions(-) delete mode 100644 res/layout/ambient_play.xml delete mode 100644 res/layout/switch_bar_ambient_play.xml create mode 100644 src/com/android/settings/liquid/AmbientPlayKeyguardPreferenceController.java create mode 100644 src/com/android/settings/liquid/AmbientPlayPreferenceController.java diff --git a/res/layout/ambient_play.xml b/res/layout/ambient_play.xml deleted file mode 100644 index 759a302922..0000000000 --- a/res/layout/ambient_play.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/res/layout/switch_bar_ambient_play.xml b/res/layout/switch_bar_ambient_play.xml deleted file mode 100644 index 37b3aa43be..0000000000 --- a/res/layout/switch_bar_ambient_play.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/res/values/custom_colors.xml b/res/values/custom_colors.xml index ff3093a9fb..36dd65c402 100644 --- a/res/values/custom_colors.xml +++ b/res/values/custom_colors.xml @@ -18,7 +18,5 @@ @android:color/white @android:color/black - - #ff80868B - @*android:color/accent_device_default_light + diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml index a45afb5e90..5978d6c67b 100644 --- a/res/values/custom_strings.xml +++ b/res/values/custom_strings.xml @@ -569,13 +569,11 @@ Volume key sounds - @*android:string/ambient_recognition_notification - Show nearby songs - Show songs on lock screen - Notifications - On - Off - When music is playing nearby, you can see the song name and artist. Battery life and data usage may be affected if this is enabled. + Now Playing + Enable Now Playing + Be notified of music being played around you + Show Now Playing + On the lockscreen Prevent accidental wake-up diff --git a/res/values/custom_styles.xml b/res/values/custom_styles.xml index 9d6c7f78e8..a6c6b18637 100644 --- a/res/values/custom_styles.xml +++ b/res/values/custom_styles.xml @@ -22,9 +22,4 @@ 1.2 - - diff --git a/res/xml/ambient_play_settings.xml b/res/xml/ambient_play_settings.xml index 31e402663c..fd8d8b2f8f 100644 --- a/res/xml/ambient_play_settings.xml +++ b/res/xml/ambient_play_settings.xml @@ -18,27 +18,23 @@ + android:key="ambient_play_preference_screen" + android:title="@string/ambient_play_cat"> - + - - - + diff --git a/src/com/android/settings/AmbientPlaySettings.java b/src/com/android/settings/AmbientPlaySettings.java index d618ae5c40..f03ad6de7c 100644 --- a/src/com/android/settings/AmbientPlaySettings.java +++ b/src/com/android/settings/AmbientPlaySettings.java @@ -16,52 +16,21 @@ package com.android.settings; -import android.os.Bundle; -import android.os.UserHandle; -import android.provider.Settings; -import android.support.v4.content.ContextCompat; -import android.support.v14.preference.SwitchPreference; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CompoundButton; -import android.widget.Switch; -import android.widget.TextView; +import android.content.Context; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; -import com.android.settings.R; -import com.android.settings.SettingsPreferenceFragment; +import com.android.settings.dashboard.DashboardFragment; +import com.android.settings.liquid.AmbientPlayPreferenceController; +import com.android.settings.liquid.AmbientPlayKeyguardPreferenceController; -public class AmbientPlaySettings extends SettingsPreferenceFragment implements CompoundButton.OnCheckedChangeListener { - - private TextView mTextView; - private View switchBar; - - private SwitchPreference mAmbientRecognitionKeyguardPreference; - private SwitchPreference mAmbientRecognitionNotificationPreference; - - private int mBackgroundActivatedColor; - private int mBackgroundColor; - - private String AMBIENT_RECOGNITION_KEYGUARD = "ambient_recognition_keyguard"; - private String AMBIENT_RECOGNITION_NOTIFICATION = "ambient_recognition_notification"; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.ambient_play_settings); - mAmbientRecognitionKeyguardPreference = (SwitchPreference) findPreference(AMBIENT_RECOGNITION_KEYGUARD); - mAmbientRecognitionKeyguardPreference.setEnabled(isEnabled()); - mAmbientRecognitionNotificationPreference = (SwitchPreference) findPreference(AMBIENT_RECOGNITION_NOTIFICATION); - mAmbientRecognitionNotificationPreference.setEnabled(isEnabled()); - - mBackgroundActivatedColor = ContextCompat.getColor(getActivity(), R.color.switchBarBackgroundActivatedColor); - mBackgroundColor = ContextCompat.getColor(getActivity(), R.color.switchBarBackgroundColor); - } +public class AmbientPlaySettings extends DashboardFragment { + private static final String TAG = "AmbientPlaySettings"; @Override - public void onResume() { - super.onResume(); + public void onAttach(Context context) { + super.onAttach(context); + addPreferenceController(new AmbientPlayPreferenceController(context)); + addPreferenceController(new AmbientPlayKeyguardPreferenceController(context)); } @Override @@ -69,43 +38,13 @@ public int getMetricsCategory() { return MetricsEvent.LIQUID; } - private boolean isEnabled() { - return Settings.System.getIntForUser(getActivity().getContentResolver(), - Settings.System.AMBIENT_RECOGNITION, 0, UserHandle.USER_CURRENT) != 0; - } - - private void setEnabled(boolean enabled) { - Settings.System.putIntForUser(getActivity().getContentResolver(), - Settings.System.AMBIENT_RECOGNITION, enabled ? 1 : 0, UserHandle.USER_CURRENT); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - final View view = LayoutInflater.from(getActivity()).inflate(R.layout.ambient_play, container, false); - ((ViewGroup) view).addView(super.onCreateView(inflater, container, savedInstanceState)); - return view; - } - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - mTextView = view.findViewById(R.id.switch_text); - mTextView.setText(getString(isEnabled() ? R.string.ambient_play_switch_bar_on : R.string.ambient_play_switch_bar_off)); - switchBar = view.findViewById(R.id.switch_bar); - switchBar.setBackgroundColor(isEnabled() ? mBackgroundActivatedColor : mBackgroundColor); - Switch switchWidget = switchBar.findViewById(android.R.id.switch_widget); - switchWidget.setChecked(isEnabled()); - switchWidget.setOnCheckedChangeListener(this); - switchBar.setOnClickListener(v -> switchWidget.setChecked(!switchWidget.isChecked())); + protected String getLogTag() { + return TAG; } @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { - setEnabled(isChecked); - mTextView.setText(getString(isChecked ? R.string.ambient_play_switch_bar_on : R.string.ambient_play_switch_bar_off)); - switchBar.setBackgroundColor(isChecked ? mBackgroundActivatedColor : mBackgroundColor); - mAmbientRecognitionKeyguardPreference.setEnabled(isChecked); - mAmbientRecognitionNotificationPreference.setEnabled(isChecked); + protected int getPreferenceScreenResId() { + return R.xml.ambient_play_settings; } } diff --git a/src/com/android/settings/liquid/AmbientPlayKeyguardPreferenceController.java b/src/com/android/settings/liquid/AmbientPlayKeyguardPreferenceController.java new file mode 100644 index 0000000000..0e3232e66b --- /dev/null +++ b/src/com/android/settings/liquid/AmbientPlayKeyguardPreferenceController.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2017 CypherOS + * + * 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.liquid; + +import android.content.Context; +import android.provider.Settings; +import android.support.v14.preference.SwitchPreference; +import android.support.v7.preference.Preference; + +import com.android.settings.core.PreferenceControllerMixin; +import com.android.settings.overlay.FeatureFactory; +import com.android.settings.R; +import com.android.settingslib.core.AbstractPreferenceController; +import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; + +import java.util.List; + +import static android.provider.Settings.Secure.AMBIENT_RECOGNITION_KEYGUARD; + +import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_AMBIENT_DISPLAY; + +public class AmbientPlayKeyguardPreferenceController extends AbstractPreferenceController implements + PreferenceControllerMixin, Preference.OnPreferenceChangeListener { + + private static final String KEY_AMBIENT_DISPLAY_AMBIENT_PLAY_KEYGUARD = "ambient_display_ambient_play_keyguard"; + + private final MetricsFeatureProvider mMetricsFeatureProvider; + + public AmbientPlayKeyguardPreferenceController(Context context) { + super(context); + mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider(); + } + + @Override + public boolean isAvailable() { + return true; + } + + @Override + public String getPreferenceKey() { + return KEY_AMBIENT_DISPLAY_AMBIENT_PLAY_KEYGUARD; + } + + @Override + public void updateState(Preference preference) { + int value = Settings.Secure.getInt(mContext.getContentResolver(), AMBIENT_RECOGNITION_KEYGUARD, 1); + ((SwitchPreference) preference).setChecked(value != 0); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + final boolean enabled = (boolean) newValue; + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.AMBIENT_RECOGNITION_KEYGUARD, enabled ? 1 : 0); + return true; + } + + @Override + public void updateNonIndexableKeys(List keys) { + keys.add(getPreferenceKey()); + } +} diff --git a/src/com/android/settings/liquid/AmbientPlayPreferenceController.java b/src/com/android/settings/liquid/AmbientPlayPreferenceController.java new file mode 100644 index 0000000000..eb508c9062 --- /dev/null +++ b/src/com/android/settings/liquid/AmbientPlayPreferenceController.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2017 CypherOS + * + * 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.liquid; + +import android.content.Context; +import android.provider.Settings; +import android.support.v14.preference.SwitchPreference; +import android.support.v7.preference.Preference; + +import com.android.settings.core.PreferenceControllerMixin; +import com.android.settings.overlay.FeatureFactory; +import com.android.settings.R; +import com.android.settingslib.core.AbstractPreferenceController; +import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; + +import java.util.List; + +import static android.provider.Settings.Secure.AMBIENT_RECOGNITION; + +import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_AMBIENT_DISPLAY; + +public class AmbientPlayPreferenceController extends AbstractPreferenceController implements + PreferenceControllerMixin, Preference.OnPreferenceChangeListener { + + private static final String KEY_AMBIENT_DISPLAY_AMBIENT_PLAY = "ambient_display_ambient_play"; + + private final MetricsFeatureProvider mMetricsFeatureProvider; + + public AmbientPlayPreferenceController(Context context) { + super(context); + mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider(); + } + + @Override + public boolean isAvailable() { + return true; + } + + @Override + public String getPreferenceKey() { + return KEY_AMBIENT_DISPLAY_AMBIENT_PLAY; + } + + @Override + public void updateState(Preference preference) { + int value = Settings.Secure.getInt(mContext.getContentResolver(), AMBIENT_RECOGNITION, 0); + ((SwitchPreference) preference).setChecked(value != 0); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + final boolean enabled = (boolean) newValue; + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.AMBIENT_RECOGNITION, enabled ? 1 : 0); + return true; + } + + @Override + public void updateNonIndexableKeys(List keys) { + keys.add(getPreferenceKey()); + } +}