Commit 0305010d authored by Danny Baumann's avatar Danny Baumann Committed by Arne Coucheron

Add back increasing ring feature (2/3).

This also squashes in the following fixes from cm-13.0:
Ia4291d8ac3d1dbf76d432db7e0e973844163c4ae Fix NPE.
Ibe7fdf1ee7f0aa1c7c76052df69fa92e8b6a2ffd Fix up increasing ring tone volume preview behaviour.
Id32d6b51aab05e80be59bc1912c4ae7c5d114ac5 Settings: Always set ramp-up time value during bindView

Change-Id: Iafc79a57651db327a100e0f1723b62f442b638be
parent 4ad75bc4
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="#24000000" />
<item android:color="#8a000000" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="@color/audio_icon"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000"
android:pathData="M12,22c1.105,0,2-0.898,2-2h-4C10,21.102,10.896,22,12,22Z M18.5,16v-5.5c0-3.075-2.135-5.643-5-6.321V3.5 C13.5,2.67,12.828,2,12,2s-1.5,0.67-1.5,1.5v0.679c-2.865,0.678-5,3.246-5,6.321V16l-2,2v1h17v-1L18.5,16z M16.504,14.558H7.561 V13.25l8.943-3.808V14.558z" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The CyanogenMod 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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingEnd="?android:attr/scrollbarSize">
<ImageView
android:id="@+android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/ring_notif_increasing"
android:minWidth="48dp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dip"
android:layout_marginEnd="8dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
android:layout_weight="1">
<TextView android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />
<TextView android:id="@+id/start_volume_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
android:layout_alignStart="@android:id/title"
android:text="@string/increasing_ring_min_volume_title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:singleLine="true" />
<SeekBar android:id="@+id/start_volume"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/start_volume_label"
android:layout_alignParentEnd="true"
android:max="1000" />
<TextView android:id="@+id/ramp_up_time_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/start_volume"
android:layout_alignStart="@android:id/title"
android:text="@string/increasing_ring_ramp_up_time_title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:singleLine="true" />
<TextView android:id="@+id/ramp_up_time_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/start_volume"
android:layout_toEndOf="@id/ramp_up_time_label"
android:layout_alignBaseline="@id/ramp_up_time_label"
android:layout_alignParentEnd="true"
android:gravity="end"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:singleLine="true" />
<SeekBar android:id="@+id/ramp_up_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ramp_up_time_label"
android:layout_alignParentEnd="true"
android:max="11" />
<TextView android:id="@android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/ramp_up_time"
android:layout_alignStart="@android:id/title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="4" />
</RelativeLayout>
</LinearLayout>
......@@ -325,4 +325,9 @@
<string name="adb_over_network">ADB over network</string>
<string name="adb_over_network_summary">Enable TCP/IP debugging over network interfaces (Wi\u2011Fi, USB networks). This setting is reset on reboot</string>
<string name="adb_over_network_warning">WARNING: When ADB over network is enabled, your phone is open for intrusions on all connected networks!\n\nOnly use this feature when you are connected on trusted networks.\n\nDo you really want to enable this function?</string>
<!-- Increasing ring tone volume -->
<string name="increasing_ring_volume_option_title">Increasing ring volume</string>
<string name="increasing_ring_min_volume_title">Start volume</string>
<string name="increasing_ring_ramp_up_time_title">Ramp-up time</string>
</resources>
......@@ -38,6 +38,17 @@
android:icon="@*android:drawable/ic_audio_ring_notif"
android:title="@string/ring_volume_option_title" />
<!-- Increasing ring -->
<cyanogenmod.preference.CMSystemSettingSwitchPreference
android:key="increasing_ring"
android:title="@string/increasing_ring_volume_option_title" />
<!-- Increasing ring volume -->
<com.android.settings.notification.IncreasingRingVolumePreference
android:key="increasing_ring_volume"
android:icon="@drawable/ring_notif_increasing"
android:dependency="increasing_ring" />
<!-- Notification volume -->
<com.android.settings.notification.VolumeSeekBarPreference
android:key="notification_volume"
......
/*
* Copyright (C) 2014 CyanogenMod 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.ContentResolver;
import android.content.Context;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceViewHolder;
import android.text.format.Formatter;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;
import com.android.settings.R;
import cyanogenmod.providers.CMSettings;
public class IncreasingRingVolumePreference extends Preference implements
Handler.Callback, SeekBar.OnSeekBarChangeListener {
private static final String TAG = "IncreasingRingMinVolumePreference";
public interface Callback {
void onStartingSample();
}
private SeekBar mStartVolumeSeekBar;
private SeekBar mRampUpTimeSeekBar;
private TextView mRampUpTimeValue;
private Ringtone mRingtone;
private Callback mCallback;
private Handler mHandler;
private final Handler mMainHandler = new Handler(this);
private static final int MSG_START_SAMPLE = 1;
private static final int MSG_STOP_SAMPLE = 2;
private static final int MSG_INIT_SAMPLE = 3;
private static final int MSG_SET_VOLUME = 4;
private static final int CHECK_RINGTONE_PLAYBACK_DELAY_MS = 1000;
public IncreasingRingVolumePreference(Context context) {
this(context, null);
}
public IncreasingRingVolumePreference(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public IncreasingRingVolumePreference(Context context, AttributeSet attrs,
int defStyleAttr) {
this(context, attrs, defStyleAttr, 0);
}
public IncreasingRingVolumePreference(Context context, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
setLayoutResource(R.layout.preference_increasing_ring);
initHandler();
}
public void setCallback(Callback callback) {
mCallback = callback;
}
public void onActivityResume() {
initHandler();
}
public void onActivityStop() {
if (mHandler != null) {
postStopSample();
mHandler.getLooper().quitSafely();
mHandler = null;
}
}
@Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
case MSG_START_SAMPLE:
onStartSample((float) msg.arg1 / 1000F);
break;
case MSG_STOP_SAMPLE:
onStopSample();
break;
case MSG_INIT_SAMPLE:
onInitSample();
break;
case MSG_SET_VOLUME:
onSetVolume((float) msg.arg1 / 1000F);
break;
}
return true;
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
initHandler();
final SeekBar seekBar = (SeekBar) holder.findViewById(R.id.start_volume);
if (seekBar == mStartVolumeSeekBar) return;
mStartVolumeSeekBar = seekBar;
mRampUpTimeSeekBar = (SeekBar) holder.findViewById(R.id.ramp_up_time);
mRampUpTimeValue = (TextView) holder.findViewById(R.id.ramp_up_time_value);
final ContentResolver cr = getContext().getContentResolver();
float startVolume = CMSettings.System.getFloat(cr,
CMSettings.System.INCREASING_RING_START_VOLUME, 0.1f);
int rampUpTime = CMSettings.System.getInt(cr,
CMSettings.System.INCREASING_RING_RAMP_UP_TIME, 10);
mStartVolumeSeekBar.setProgress(Math.round(startVolume * 1000F));
mStartVolumeSeekBar.setOnSeekBarChangeListener(this);
mRampUpTimeSeekBar.setOnSeekBarChangeListener(this);
mRampUpTimeSeekBar.setProgress((rampUpTime / 5) - 1);
mRampUpTimeValue.setText(
Formatter.formatShortElapsedTime(getContext(), rampUpTime * 1000));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
if (seekBar == mStartVolumeSeekBar) {
postStartSample(seekBar.getProgress());
}
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
ContentResolver cr = getContext().getContentResolver();
if (fromTouch && seekBar == mStartVolumeSeekBar) {
CMSettings.System.putFloat(cr, CMSettings.System.INCREASING_RING_START_VOLUME,
(float) progress / 1000F);
} else if (seekBar == mRampUpTimeSeekBar) {
int seconds = (progress + 1) * 5;
mRampUpTimeValue.setText(
Formatter.formatShortElapsedTime(getContext(), seconds * 1000));
if (fromTouch) {
CMSettings.System.putInt(cr,
CMSettings.System.INCREASING_RING_RAMP_UP_TIME, seconds);
}
}
}
private void initHandler() {
if (mHandler != null) return;
HandlerThread thread = new HandlerThread(TAG + ".CallbackHandler");
thread.start();
mHandler = new Handler(thread.getLooper(), this);
mHandler.sendEmptyMessage(MSG_INIT_SAMPLE);
}
private void onInitSample() {
mRingtone = RingtoneManager.getRingtone(getContext(),
Settings.System.DEFAULT_RINGTONE_URI);
if (mRingtone != null) {
mRingtone.setStreamType(AudioManager.STREAM_RING);
mRingtone.setAudioAttributes(
new AudioAttributes.Builder(mRingtone.getAudioAttributes())
.setFlags(AudioAttributes.FLAG_BYPASS_INTERRUPTION_POLICY |
AudioAttributes.FLAG_BYPASS_MUTE)
.build());
}
}
private void postStartSample(int progress) {
boolean playing = isSamplePlaying();
mHandler.removeMessages(MSG_START_SAMPLE);
mHandler.removeMessages(MSG_SET_VOLUME);
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_START_SAMPLE, progress, 0),
playing ? CHECK_RINGTONE_PLAYBACK_DELAY_MS : 0);
if (playing) {
mHandler.sendMessage(mHandler.obtainMessage(MSG_SET_VOLUME, progress, 0));
}
}
private void onStartSample(float volume) {
if (mRingtone == null) {
return;
}
if (!isSamplePlaying()) {
if (mCallback != null) {
mCallback.onStartingSample();
}
try {
mRingtone.play();
} catch (Throwable e) {
Log.w(TAG, "Error playing ringtone", e);
}
}
mRingtone.setVolume(volume);
}
private void onSetVolume(float volume) {
if (mRingtone != null) {
mRingtone.setVolume(volume);
}
}
private boolean isSamplePlaying() {
return mRingtone != null && mRingtone.isPlaying();
}
public void stopSample() {
if (mHandler != null) {
postStopSample();
}
}
private void postStopSample() {
// remove pending delayed start messages
mHandler.removeMessages(MSG_START_SAMPLE);
mHandler.removeMessages(MSG_STOP_SAMPLE);
mHandler.sendEmptyMessage(MSG_STOP_SAMPLE);
}
private void onStopSample() {
if (mRingtone != null) {
mRingtone.stop();
}
}
}
......@@ -47,6 +47,7 @@ import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.TwoStatePreference;
import android.text.TextUtils;
import android.util.Log;
......@@ -61,6 +62,7 @@ import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreference;
import cyanogenmod.providers.CMSettings;
import java.text.NumberFormat;
import java.util.ArrayList;
......@@ -82,6 +84,7 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
private static final String KEY_ALARM_RINGTONE = "alarm_ringtone";
private static final String KEY_VIBRATE_WHEN_RINGING = "vibrate_when_ringing";
private static final String KEY_WIFI_DISPLAY = "wifi_display";
private static final String KEY_INCREASING_RING_VOLUME = "increasing_ring_volume";
private static final String KEY_ZEN_MODE = "zen_mode";
private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";
......@@ -99,6 +102,16 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
private static final int SAMPLE_CUTOFF = 2000; // manually cap sample playback at 2 seconds
private final VolumePreferenceCallback mVolumeCallback = new VolumePreferenceCallback();
private final IncreasingRingVolumePreference.Callback mIncreasingRingVolumeCallback =
new IncreasingRingVolumePreference.Callback() {
@Override
public void onStartingSample() {
mVolumeCallback.stopSample();
mHandler.removeMessages(H.STOP_SAMPLE);
mHandler.sendEmptyMessageDelayed(H.STOP_SAMPLE, SAMPLE_CUTOFF);
}
};
private final H mHandler = new H();
private final SettingsObserver mSettingsObserver = new SettingsObserver();
private final Receiver mReceiver = new Receiver();
......@@ -110,6 +123,8 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
private AudioManager mAudioManager;
private VolumeSeekBarPreference mRingOrNotificationPreference;
private TwoStatePreference mIncreasingRing;
private IncreasingRingVolumePreference mIncreasingRingVolume;
private Preference mPhoneRingtonePreference;
private Preference mNotificationRingtonePreference;
private Preference mAlarmRingtonePreference;
......@@ -178,6 +193,7 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
}
initRingtones();
initVibrateWhenRinging();
initIncreasingRing();
updateRingerMode();
updateEffectsSuppressor();
......@@ -200,6 +216,9 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
for (VolumeSeekBarPreference volumePref : mVolumePrefs) {
volumePref.onActivityResume();
}
if (mIncreasingRingVolume != null) {
mIncreasingRingVolume.onActivityResume();
}
final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(mContext,
UserManager.DISALLOW_ADJUST_VOLUME, UserHandle.myUserId());
......@@ -229,10 +248,21 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
volumePref.onActivityPause();
}
mVolumeCallback.stopSample();
if (mIncreasingRingVolume != null) {
mIncreasingRingVolume.stopSample();
}
mSettingsObserver.register(false);
mReceiver.register(false);
}
@Override
public void onStop() {
super.onStop();
if (mIncreasingRingVolume != null) {
mIncreasingRingVolume.onActivityStop();
}
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (preference instanceof RingtonePreference) {
......@@ -346,6 +376,9 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
if (mCurrent != null && mCurrent != sbv) {
mCurrent.stopSample();
}
if (mIncreasingRingVolume != null) {
mIncreasingRingVolume.stopSample();
}
mCurrent = sbv;
if (mCurrent != null) {
mHandler.removeMessages(H.STOP_SAMPLE);
......@@ -449,6 +482,29 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
return summary;
}
// === Increasing ringtone ===
private void initIncreasingRing() {
PreferenceScreen root = getPreferenceScreen();
mIncreasingRing = (TwoStatePreference)
root.findPreference(CMSettings.System.INCREASING_RING);
mIncreasingRingVolume = (IncreasingRingVolumePreference)
root.findPreference(KEY_INCREASING_RING_VOLUME);
if (mIncreasingRing == null || mIncreasingRingVolume == null || !mVoiceCapable) {
if (mIncreasingRing != null) {
root.removePreference(mIncreasingRing);
mIncreasingRing = null;
}
if (mIncreasingRingVolume != null) {
root.removePreference(mIncreasingRingVolume);
mIncreasingRingVolume = null;
}
} else {
mIncreasingRingVolume.setCallback(mIncreasingRingVolumeCallback);
}
}
// === Vibrate when ringing ===
private void initVibrateWhenRinging() {
......@@ -533,6 +589,9 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
break;
case STOP_SAMPLE:
mVolumeCallback.stopSample();
if (mIncreasingRingVolume != null) {
mIncreasingRingVolume.stopSample();
}
break;
case UPDATE_EFFECTS_SUPPRESSOR:
updateEffectsSuppressor();
......
......@@ -88,6 +88,7 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
mStopped = true;
if (mVolumizer != null) {
mVolumizer.stop();
mVolumizer = null;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment