Cherish: Wired/BT headset: make ringtone audio focus customizable [2/2]

Import GlobalSettingListPreference from https://github.com/crdroidandroid/android_packages_apps_crDroidSettings/blob/10.0/src/com/crdroid/settings/preferences/GlobalSettingListPreference.java
This commit is contained in:
ezio84
2020-05-05 14:26:56 +07:00
committed by Hung Phan
parent e4a1bff5cb
commit d0b86c6d5e
7 changed files with 118 additions and 1 deletions

View File

@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24.0dp"
android:height="24.0dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="#FF000000"
android:pathData="M11,4H13V16L18.5,10.5L19.92,11.92L12,19.84L4.08,11.92L5.5,10.5L11,16V4Z" />
</vector>

10
res/drawable/ic_ring.xml Normal file
View File

@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24.0dp"
android:height="24.0dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="#FF000000"
android:pathData="M23.71 16.67C20.66 13.78 16.54 12 12 12S3.34 13.78.29 16.67c-.18.18-.29.43-.29.71 0 .28.11.53.29.71l2.48 2.48c.18.18.43.29.71.29.27 0 .52-.11.7-.28.79-.74 1.69-1.36 2.66-1.85.33-.16.56-.5.56-.9v-3.1c1.45-.48 3-.73 4.6-.73s3.15.25 4.6.72v3.1c0 .39.23.74.56.9.98.49 1.87 1.12 2.66 1.85.18.18.43.28.7.28.28 0 .53-.11.71-.29l2.48-2.48c.18-.18.29-.43.29-.71a.99.99 0 0 0-.29-.7zM21.16 6.26l-1.41-1.41-3.56 3.55 1.41 1.41s3.45-3.52 3.56-3.55zM13 2h-2v5h2V2zM6.4 9.81L7.81 8.4 4.26 4.84 2.84 6.26c.11.03 3.56 3.55 3.56 3.55z" />
</vector>

View File

@@ -341,4 +341,14 @@
<item>2</item> <item>2</item>
<item>3</item> <item>3</item>
</string-array> </string-array>
<!-- Wired headset ringtone audio focus -->
<string-array name="ringtone_focus_mode_entries">
<item>@string/ringtone_focus_mode_stock</item>
<item>@string/ringtone_focus_mode_dynamic</item>
</string-array>
<string-array name="ringtone_focus_mode_values" translatable="false">
<item>1</item>
<item>0</item>
</string-array>
</resources> </resources>

View File

@@ -431,4 +431,9 @@
<string name="quick_pulldown_right">Right</string> <string name="quick_pulldown_right">Right</string>
<string name="quick_pulldown_always">Always</string> <string name="quick_pulldown_always">Always</string>
<!-- Headset ringtone audio focus -->
<string name="ringtone_focus_mode_title">When headset connected, incoming call plays on</string>
<string name="ringtone_focus_mode_dynamic">Headset only if music is active</string>
<string name="ringtone_focus_mode_stock">Both speaker and headset</string>
</resources> </resources>

View File

@@ -29,6 +29,14 @@
android:key="media" android:key="media"
android:title="@string/media_title"> android:title="@string/media_title">
<com.cherish.settings.preferences.GlobalSettingListPreference
android:icon="@drawable/ic_ring"
android:key="ringtone_focus_mode"
android:title="@string/ringtone_focus_mode_title"
android:entries="@array/ringtone_focus_mode_entries"
android:entryValues="@array/ringtone_focus_mode_values"
android:defaultValue="1" />
<com.cherish.settings.preferences.SystemSettingSwitchPreference <com.cherish.settings.preferences.SystemSettingSwitchPreference
android:key="adaptive_playback_enabled" android:key="adaptive_playback_enabled"
android:icon="@drawable/ic_headset" android:icon="@drawable/ic_headset"

View File

@@ -68,6 +68,7 @@
<ListPreference <ListPreference
android:key="quick_pulldown" android:key="quick_pulldown"
android:icon="@drawable/ic_pulldown"
android:title="@string/quick_pulldown_title" android:title="@string/quick_pulldown_title"
android:entries="@array/quick_pulldown_entries" android:entries="@array/quick_pulldown_entries"
android:entryValues="@array/quick_pulldown_values" android:entryValues="@array/quick_pulldown_values"

View File

@@ -0,0 +1,73 @@
/*
* Copyright (C) 2016-2018 crDroid Android 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.cherish.settings.preferences;
import android.content.Context;
import androidx.preference.ListPreference;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.provider.Settings;
public class GlobalSettingListPreference extends ListPreference {
private boolean mAutoSummary = false;
public GlobalSettingListPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setPreferenceDataStore(new GlobalSettingsStore(context.getContentResolver()));
}
public GlobalSettingListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
setPreferenceDataStore(new GlobalSettingsStore(context.getContentResolver()));
}
public GlobalSettingListPreference(Context context) {
super(context);
setPreferenceDataStore(new GlobalSettingsStore(context.getContentResolver()));
}
@Override
public void setValue(String value) {
super.setValue(value);
if (mAutoSummary || TextUtils.isEmpty(getSummary())) {
setSummary(getEntry(), true);
}
}
@Override
public void setSummary(CharSequence summary) {
setSummary(summary, false);
}
private void setSummary(CharSequence summary, boolean autoSummary) {
mAutoSummary = autoSummary;
super.setSummary(summary);
}
@Override
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
// This is what default ListPreference implementation is doing without respecting
// real default value:
//setValue(restoreValue ? getPersistedString(mValue) : (String) defaultValue);
// Instead, we better do
setValue(restoreValue ? getPersistedString((String) defaultValue) : (String) defaultValue);
}
public int getIntValue(int defValue) {
return getValue() == null ? defValue : Integer.valueOf(getValue());
}
}