Skip to content

Commit

Permalink
Revert "Ambient Play settings improvements"
Browse files Browse the repository at this point in the history
This reverts commit 4d87090.
  • Loading branch information
liquid0624 committed Dec 21, 2018
1 parent c9aaa77 commit c336985
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 177 deletions.
26 changes: 0 additions & 26 deletions res/layout/ambient_play.xml

This file was deleted.

46 changes: 0 additions & 46 deletions res/layout/switch_bar_ambient_play.xml

This file was deleted.

4 changes: 1 addition & 3 deletions res/values/custom_colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@

<color name="accent_picker_white_accent">@android:color/white</color>
<color name="accent_picker_dark_accent">@android:color/black</color>

<color name="switchBarBackgroundColor">#ff80868B</color>
<color name="switchBarBackgroundActivatedColor">@*android:color/accent_device_default_light</color>

</resources>
12 changes: 5 additions & 7 deletions res/values/custom_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,11 @@
<string name="volume_adjust_sounds_title">Volume key sounds</string>

<!-- Ambient Play -->
<string name="ambient_play_title" translatable="false">@*android:string/ambient_recognition_notification</string>
<string name="ambient_play_summary">Show nearby songs</string>
<string name="ambient_play_lockscreen_title">Show songs on lock screen</string>
<string name="ambient_play_notifications_title">Notifications</string>
<string name="ambient_play_switch_bar_on">On</string>
<string name="ambient_play_switch_bar_off">Off</string>
<string name="ambient_play_help_text">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.</string>
<string name="ambient_play_cat">Now Playing</string>
<string name="ambient_recognition_title">Enable Now Playing</string>
<string name="ambient_recognition_summary">Be notified of music being played around you</string>
<string name="ambient_recognition_lockscreen_title">Show Now Playing</string>
<string name="ambient_recognition_lockscreen_summary">On the lockscreen</string>

<!-- Proximity wake -->
<string name="proximity_wake_title">Prevent accidental wake-up</string>
Expand Down
5 changes: 0 additions & 5 deletions res/values/custom_styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,4 @@
<item name="android:lineSpacingMultiplier">1.2</item>
</style>

<style name="Theme.Main.SwitchBar.AmbientPlay" parent="@android:style/Widget.Material.CompoundButton.Switch">
<item name="android:trackTint">@color/switchbar_switch_track_tint</item>
<item name="android:thumbTint">@color/switchbar_switch_thumb_tint</item>
</style>

</resources>
26 changes: 11 additions & 15 deletions res/xml/ambient_play_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,23 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="ambient_play"
android:title="@string/ambient_play_title">
android:key="ambient_play_preference_screen"
android:title="@string/ambient_play_cat">

<!-- Illustration for Ambient Play -->
<Preference android:key="ambient_play_illustration"
android:enabled="false"
android:layout="@layout/ambient_play_illustration" />

<com.liquid.liquidlounge.preferences.SystemSettingSwitchPreference
android:key="ambient_recognition_keyguard"
android:title="@string/ambient_play_lockscreen_title"
android:defaultValue="true" />
<SwitchPreference
android:key="ambient_display_ambient_play"
android:title="@string/ambient_recognition_title"
android:summary="@string/ambient_recognition_summary" />

<com.liquid.liquidlounge.preferences.SystemSettingSwitchPreference
android:key="ambient_recognition_notification"
android:title="@string/ambient_play_notifications_title"
android:defaultValue="true" />

<com.android.settingslib.widget.FooterPreference
android:key="ambient_recognition_footer_preference"
android:title="@string/ambient_play_help_text"
android:selectable="false" />
<SwitchPreference
android:key="ambient_display_ambient_play_keyguard"
android:title="@string/ambient_recognition_lockscreen_title"
android:summary="@string/ambient_recognition_lockscreen_summary"
android:dependency="ambient_display_ambient_play" />

</PreferenceScreen>
89 changes: 14 additions & 75 deletions src/com/android/settings/AmbientPlaySettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,96 +16,35 @@

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
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;
}
}
Original file line number Diff line number Diff line change
@@ -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<String> keys) {
keys.add(getPreferenceKey());
}
}
Loading

0 comments on commit c336985

Please sign in to comment.