Added option to have settings not applied after area change.
This commit is contained in:
parent
24e0100efc
commit
652fb0f7c3
8 changed files with 243 additions and 55 deletions
77
res/layout/volume_preference.xml
Normal file
77
res/layout/volume_preference.xml
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2011 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- Modified from: https://github.com/CyanogenMod/android_packages_apps_Settings/blob/jellybean/res/layout/preference_streamvolume.xml -->
|
||||||
|
<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" >
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/text_layout"
|
||||||
|
android:layout_width="0dip"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true" >
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:paddingTop="6dip"
|
||||||
|
android:paddingBottom="6dip"
|
||||||
|
android:gravity="center_vertical" >
|
||||||
|
|
||||||
|
<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"
|
||||||
|
android:paddingLeft="10dip" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="2dip"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginTop="5dip"
|
||||||
|
android:layout_marginBottom="5dip"
|
||||||
|
android:background="@android:drawable/divider_horizontal_dark" />
|
||||||
|
|
||||||
|
<!-- Preference should place its actual preference widget here. -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:minWidth="68dip"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+android:id/profile_checkbox"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clickable="true"
|
||||||
|
android:gravity="center" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
28
res/menu/profile_list_context.xml
Normal file
28
res/menu/profile_list_context.xml
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2012 Felix Ableitner
|
||||||
|
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
|
||||||
|
<item android:title="@string/profilelist_edit"
|
||||||
|
android:id="@+id/edit" />
|
||||||
|
|
||||||
|
<item android:title="@string/profilelist_rename"
|
||||||
|
android:id="@+id/rename" />
|
||||||
|
|
||||||
|
<item android:title="@string/profilelist_delete"
|
||||||
|
android:id="@+id/delete" />
|
||||||
|
|
||||||
|
</menu>
|
|
@ -74,6 +74,7 @@
|
||||||
<string name="profileedit_ringer">Ringer Mode</string>
|
<string name="profileedit_ringer">Ringer Mode</string>
|
||||||
<string name="profileedit_wifi">Wifi Enabled</string>
|
<string name="profileedit_wifi">Wifi Enabled</string>
|
||||||
<string-array name="profileedit_ringer_mode_strings">
|
<string-array name="profileedit_ringer_mode_strings">
|
||||||
|
<item>Keep previous</item>
|
||||||
<item>Normal</item>
|
<item>Normal</item>
|
||||||
<item>Silent</item>
|
<item>Silent</item>
|
||||||
<item>Vibrate only</item>
|
<item>Vibrate only</item>
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
|
|
||||||
<!-- ProfileEdit -->
|
<!-- ProfileEdit -->
|
||||||
<string-array name="profileedit_ringer_mode_values">
|
<string-array name="profileedit_ringer_mode_values">
|
||||||
|
<item>"-1"</item> <!-- ProfileColumns.RINGER_MODE_KEEP -->
|
||||||
<item>"2"</item> <!-- AudioManager.RINGER_MODE_NORMALAudioManager.RINGER_MODE_NORMAL -->
|
<item>"2"</item> <!-- AudioManager.RINGER_MODE_NORMALAudioManager.RINGER_MODE_NORMAL -->
|
||||||
<item>"0"</item> <!-- AudioManager.RINGER_MODE_NORMALAudioManager.RINGER_MODE_SILENT -->
|
<item>"0"</item> <!-- AudioManager.RINGER_MODE_NORMALAudioManager.RINGER_MODE_SILENT -->
|
||||||
<item>"1"</item> <!-- AudioManager.RINGER_MODE_NORMALAudioManager.RINGER_MODE_VIBRATE -->
|
<item>"1"</item> <!-- AudioManager.RINGER_MODE_NORMALAudioManager.RINGER_MODE_VIBRATE -->
|
||||||
|
|
|
@ -252,23 +252,35 @@ public class LocationService extends Service {
|
||||||
WifiManager wm = (WifiManager) context
|
WifiManager wm = (WifiManager) context
|
||||||
.getSystemService(Context.WIFI_SERVICE);
|
.getSystemService(Context.WIFI_SERVICE);
|
||||||
|
|
||||||
|
// Value smaller zero means the volume should not change.
|
||||||
|
if (c.getInt(c.getColumnIndex(ProfileColumns.RINGTONE_VOLUME)) >= 0) {
|
||||||
am.setStreamVolume(AudioManager.STREAM_RING,
|
am.setStreamVolume(AudioManager.STREAM_RING,
|
||||||
c.getInt(c.getColumnIndex(ProfileColumns.RINGTONE_VOLUME)),
|
c.getInt(c.getColumnIndex(ProfileColumns.RINGTONE_VOLUME)),
|
||||||
AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
|
AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c.getInt(c.getColumnIndex(ProfileColumns.NOTIFICATION_VOLUME)) >= 0) {
|
||||||
am.setStreamVolume(AudioManager.STREAM_NOTIFICATION,
|
am.setStreamVolume(AudioManager.STREAM_NOTIFICATION,
|
||||||
c.getInt(c.getColumnIndex(ProfileColumns.NOTIFICATION_VOLUME)),
|
c.getInt(c.getColumnIndex(ProfileColumns.NOTIFICATION_VOLUME)),
|
||||||
AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
|
AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c.getInt(c.getColumnIndex(ProfileColumns.MEDIA_VOLUME)) >= 0) {
|
||||||
am.setStreamVolume(AudioManager.STREAM_MUSIC,
|
am.setStreamVolume(AudioManager.STREAM_MUSIC,
|
||||||
c.getInt(c.getColumnIndex(ProfileColumns.MEDIA_VOLUME)),
|
c.getInt(c.getColumnIndex(ProfileColumns.MEDIA_VOLUME)),
|
||||||
AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
|
AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c.getInt(c.getColumnIndex(ProfileColumns.ALARM_VOLUME)) >= 0) {
|
||||||
am.setStreamVolume(AudioManager.STREAM_ALARM,
|
am.setStreamVolume(AudioManager.STREAM_ALARM,
|
||||||
c.getInt(c.getColumnIndex(ProfileColumns.ALARM_VOLUME)),
|
c.getInt(c.getColumnIndex(ProfileColumns.ALARM_VOLUME)),
|
||||||
AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
|
AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c.getInt(c.getColumnIndex(ProfileColumns.RINGER_MODE)) !=
|
||||||
|
ProfileColumns.RINGER_MODE_KEEP) {
|
||||||
am.setRingerMode(c.getInt(c.getColumnIndex(ProfileColumns.RINGER_MODE)));
|
am.setRingerMode(c.getInt(c.getColumnIndex(ProfileColumns.RINGER_MODE)));
|
||||||
|
}
|
||||||
|
|
||||||
wm.setWifiEnabled((c.getInt(c.getColumnIndex(ProfileColumns.WIFI_ENABLED)) == 0)
|
wm.setWifiEnabled((c.getInt(c.getColumnIndex(ProfileColumns.WIFI_ENABLED)) == 0)
|
||||||
? true : false);
|
? true : false);
|
||||||
|
|
|
@ -16,23 +16,35 @@
|
||||||
|
|
||||||
package com.github.nutomic.pegasus;
|
package com.github.nutomic.pegasus;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.preference.DialogPreference;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.DialogInterface.OnClickListener;
|
||||||
|
import android.preference.Preference;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
|
|
||||||
|
import com.github.nutomic.pegasus.content.ProfileColumns;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preference that opens a SeekBar dialog.
|
* Preference that opens a SeekBar dialog and has a CheckBox, only if the
|
||||||
|
* CheckBox is checked is the value applied (but it is always saved).
|
||||||
*
|
*
|
||||||
* @author Felix Ableitner
|
* @author Felix Ableitner
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class VolumePreference extends DialogPreference {
|
public class VolumePreference extends Preference implements
|
||||||
|
OnCheckedChangeListener, android.view.View.OnClickListener {
|
||||||
|
|
||||||
private int mMax;
|
private CheckBox mCheckBox;
|
||||||
private int mProgress;
|
private int mProgress;
|
||||||
private SeekBar mSeekBar;
|
private int mMax;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize layout, set Preference not persistent-
|
* Initialize layout, set Preference not persistent-
|
||||||
|
@ -41,20 +53,23 @@ public class VolumePreference extends DialogPreference {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
|
||||||
setPersistent(false);
|
setPersistent(false);
|
||||||
setDialogLayoutResource(R.layout.seekbar_dialog);
|
setLayoutResource(R.layout.volume_preference);
|
||||||
|
|
||||||
setPositiveButtonText(android.R.string.ok);
|
|
||||||
setNegativeButtonText(android.R.string.cancel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize OnClickListeners.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onBindDialogView(View view) {
|
public View getView(View convertView, ViewGroup parent) {
|
||||||
super.onBindDialogView(view);
|
View view = super.getView(convertView, parent);
|
||||||
|
|
||||||
mSeekBar = (SeekBar) view.findViewById(R.id.seekbar);
|
View layout = view.findViewById(R.id.text_layout);
|
||||||
|
layout.setOnClickListener(this);
|
||||||
|
|
||||||
mSeekBar.setProgress(mProgress);
|
mCheckBox = (CheckBox) view.findViewById(R.id.profile_checkbox);
|
||||||
mSeekBar.setMax(mMax);
|
mCheckBox.setOnCheckedChangeListener(this);
|
||||||
|
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,8 +78,13 @@ public class VolumePreference extends DialogPreference {
|
||||||
@Override
|
@Override
|
||||||
public void setDefaultValue(Object defaultValue) {
|
public void setDefaultValue(Object defaultValue) {
|
||||||
mProgress = (Integer) defaultValue;
|
mProgress = (Integer) defaultValue;
|
||||||
if (mSeekBar != null) {
|
if (mProgress >= 0) {
|
||||||
mSeekBar.setProgress((Integer) defaultValue);
|
mCheckBox.setChecked(true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mCheckBox.setChecked(false);
|
||||||
|
// Set progress to the actual volume value.
|
||||||
|
mProgress += ProfileColumns.VOLUME_APPLY_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,19 +93,55 @@ public class VolumePreference extends DialogPreference {
|
||||||
*/
|
*/
|
||||||
public void setMaxValue(int max) {
|
public void setMaxValue(int max) {
|
||||||
mMax = max;
|
mMax = max;
|
||||||
if (mSeekBar != null) {
|
|
||||||
mSeekBar.setMax(max);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send new value to listener (if positive button was clicked).
|
* CheckBox value was changed.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onDialogClosed(boolean positiveResult) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
if (positiveResult) {
|
callChangeListener();
|
||||||
mProgress = mSeekBar.getProgress();
|
|
||||||
callChangeListener(mProgress);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls the change listener for this preference, with VOLUME_APPLY_FALSE
|
||||||
|
* subtracted if the CheckBox is unchecked.
|
||||||
|
*/
|
||||||
|
private void callChangeListener() {
|
||||||
|
callChangeListener((mCheckBox.isChecked())
|
||||||
|
? mProgress
|
||||||
|
: mProgress - ProfileColumns.VOLUME_APPLY_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Left part (text) clicked, show volume dialog.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
// Initialize dialog layout.
|
||||||
|
LayoutInflater inflater = (LayoutInflater) getContext()
|
||||||
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
View view = inflater.inflate(R.layout.seekbar_dialog, null);
|
||||||
|
final SeekBar seekBar = (SeekBar) view.findViewById(R.id.seekbar);
|
||||||
|
seekBar.setMax(mMax);
|
||||||
|
seekBar.setProgress((mProgress >= 0)
|
||||||
|
? mProgress
|
||||||
|
: mProgress + ProfileColumns.VOLUME_APPLY_FALSE);
|
||||||
|
|
||||||
|
// Create and show dialog.
|
||||||
|
new AlertDialog.Builder(getContext())
|
||||||
|
.setTitle(getTitle())
|
||||||
|
.setView(view)
|
||||||
|
.setPositiveButton(android.R.string.ok, new OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
mProgress = seekBar.getProgress();
|
||||||
|
callChangeListener();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -75,26 +75,27 @@ public class Database extends SQLiteOpenHelper {
|
||||||
db.execSQL(CellColumns.CREATE_TABLE);
|
db.execSQL(CellColumns.CREATE_TABLE);
|
||||||
db.execSQL(CellLogColumns.CREATE_TABLE);
|
db.execSQL(CellLogColumns.CREATE_TABLE);
|
||||||
|
|
||||||
// Insert "Normal" profile.
|
// Insert "Normal" profile. Does not change any settings by default.
|
||||||
ContentValues cv = new ContentValues();
|
ContentValues cv = new ContentValues();
|
||||||
cv.put(ProfileColumns.NAME, mContext.getResources()
|
cv.put(ProfileColumns.NAME, mContext.getResources()
|
||||||
.getString(R.string.sql_profile_normal));
|
.getString(R.string.sql_profile_normal));
|
||||||
cv.put(ProfileColumns.RINGTONE_VOLUME, 5);
|
cv.put(ProfileColumns.RINGTONE_VOLUME, 5 - ProfileColumns.VOLUME_APPLY_FALSE);
|
||||||
cv.put(ProfileColumns.NOTIFICATION_VOLUME, 5);
|
cv.put(ProfileColumns.NOTIFICATION_VOLUME, 5 - ProfileColumns.VOLUME_APPLY_FALSE);
|
||||||
cv.put(ProfileColumns.MEDIA_VOLUME, 9);
|
cv.put(ProfileColumns.MEDIA_VOLUME, 9 - ProfileColumns.VOLUME_APPLY_FALSE);
|
||||||
cv.put(ProfileColumns.ALARM_VOLUME, 5);
|
cv.put(ProfileColumns.ALARM_VOLUME, 5 - ProfileColumns.VOLUME_APPLY_FALSE);
|
||||||
cv.put(ProfileColumns.WIFI_ENABLED, true);
|
cv.put(ProfileColumns.WIFI_ENABLED, true);
|
||||||
cv.put(ProfileColumns.RINGER_MODE, AudioManager.RINGER_MODE_NORMAL);
|
cv.put(ProfileColumns.RINGER_MODE, ProfileColumns.RINGER_MODE_KEEP);
|
||||||
long normal = db.insert(ProfileColumns.TABLE_NAME, null, cv);
|
long normal = db.insert(ProfileColumns.TABLE_NAME, null, cv);
|
||||||
|
|
||||||
// Insert "Silent" profile.
|
// Insert "Silent" profile. Changes ringtone and notification
|
||||||
|
// volume by default and enables vibration.
|
||||||
cv = new ContentValues();
|
cv = new ContentValues();
|
||||||
cv.put(ProfileColumns.NAME, mContext.getResources()
|
cv.put(ProfileColumns.NAME, mContext.getResources()
|
||||||
.getString(R.string.sql_profile_silent));
|
.getString(R.string.sql_profile_silent));
|
||||||
cv.put(ProfileColumns.RINGTONE_VOLUME, 0);
|
cv.put(ProfileColumns.RINGTONE_VOLUME, 0);
|
||||||
cv.put(ProfileColumns.NOTIFICATION_VOLUME, 0);
|
cv.put(ProfileColumns.NOTIFICATION_VOLUME, 0);
|
||||||
cv.put(ProfileColumns.MEDIA_VOLUME, 0);
|
cv.put(ProfileColumns.MEDIA_VOLUME, 0 - ProfileColumns.VOLUME_APPLY_FALSE);
|
||||||
cv.put(ProfileColumns.ALARM_VOLUME, 0);
|
cv.put(ProfileColumns.ALARM_VOLUME, 0 - ProfileColumns.VOLUME_APPLY_FALSE);
|
||||||
cv.put(ProfileColumns.WIFI_ENABLED, true);
|
cv.put(ProfileColumns.WIFI_ENABLED, true);
|
||||||
cv.put(ProfileColumns.RINGER_MODE, AudioManager.RINGER_MODE_VIBRATE);
|
cv.put(ProfileColumns.RINGER_MODE, AudioManager.RINGER_MODE_VIBRATE);
|
||||||
long silent = db.insert(ProfileColumns.TABLE_NAME, null, cv);
|
long silent = db.insert(ProfileColumns.TABLE_NAME, null, cv);
|
||||||
|
|
|
@ -49,4 +49,16 @@ public class ProfileColumns implements BaseColumns {
|
||||||
RINGER_MODE + " INTEGER" +
|
RINGER_MODE + " INTEGER" +
|
||||||
");";
|
");";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This value is subtracted from any volume value if it should not
|
||||||
|
* be applied (only saved). Generally allows for easy testing by
|
||||||
|
* checking if the value is smaller than zero.
|
||||||
|
*/
|
||||||
|
public static final int VOLUME_APPLY_FALSE = 100;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Value to indicate that AlarmManager.setRingerMode should not be used.
|
||||||
|
*/
|
||||||
|
public static final int RINGER_MODE_KEEP = -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue