From e2085b0fbf9bec028bd927283a625b071c8c516d Mon Sep 17 00:00:00 2001 From: rovo89 Date: Sun, 1 Jul 2012 15:45:08 +0200 Subject: [PATCH] Reorganized settings a little --- .../library/ui/SeparatorPreference.java | 83 +-- .../xposed/library/ui/TextViewPreference.java | 89 ++- .../library/ui/ValueSeekBarPreference.java | 543 +++++++++--------- XposedTweakbox/res/layout/settings.xml | 20 - XposedTweakbox/res/xml/preferences.xml | 99 ++-- .../mods/tweakbox/XposedTweakboxSettings.java | 5 +- 6 files changed, 447 insertions(+), 392 deletions(-) delete mode 100644 XposedTweakbox/res/layout/settings.xml diff --git a/XposedLibrary/src/de/robv/android/xposed/library/ui/SeparatorPreference.java b/XposedLibrary/src/de/robv/android/xposed/library/ui/SeparatorPreference.java index 97cf0d3..ef51d5a 100644 --- a/XposedLibrary/src/de/robv/android/xposed/library/ui/SeparatorPreference.java +++ b/XposedLibrary/src/de/robv/android/xposed/library/ui/SeparatorPreference.java @@ -1,36 +1,49 @@ -package de.robv.android.xposed.library.ui; - -import android.content.Context; -import android.graphics.Color; -import android.preference.Preference; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewGroup.LayoutParams; -import android.widget.AbsListView; -import android.widget.ImageView; - -public class SeparatorPreference extends Preference { - int color = Color.GRAY; - int height = 7; - - public SeparatorPreference(Context context) { - super(context); - setSelectable(false); - } - - public void setColor(int color) { - this.color = color; - } - - public void setHeight(int height) { - this.height = height; - } - - @Override - protected View onCreateView(ViewGroup parent) { - ImageView iview = new ImageView(getContext()); - iview.setBackgroundColor(color); - iview.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, height)); - return iview; - } +package de.robv.android.xposed.library.ui; + +import android.content.Context; +import android.graphics.Color; +import android.preference.Preference; +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewGroup.LayoutParams; +import android.widget.AbsListView; +import android.widget.ImageView; + +public class SeparatorPreference extends Preference { + int color = Color.GRAY; + int height = 7; + + public SeparatorPreference(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + setSelectable(false); + + if (attrs != null) { + height = attrs.getAttributeIntValue(null, "height", height); + } + } + + public SeparatorPreference(Context context, AttributeSet attrs) { + this(context, attrs, android.R.attr.preferenceStyle); + } + + public SeparatorPreference(Context context) { + this(context, null); + } + + public void setColor(int color) { + this.color = color; + } + + public void setHeight(int height) { + this.height = height; + } + + @Override + protected View onCreateView(ViewGroup parent) { + ImageView iview = new ImageView(getContext()); + iview.setBackgroundColor(color); + iview.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, height)); + return iview; + } } \ No newline at end of file diff --git a/XposedLibrary/src/de/robv/android/xposed/library/ui/TextViewPreference.java b/XposedLibrary/src/de/robv/android/xposed/library/ui/TextViewPreference.java index f29fcbe..3a60787 100644 --- a/XposedLibrary/src/de/robv/android/xposed/library/ui/TextViewPreference.java +++ b/XposedLibrary/src/de/robv/android/xposed/library/ui/TextViewPreference.java @@ -1,29 +1,60 @@ -package de.robv.android.xposed.library.ui; - -import android.content.Context; -import android.preference.Preference; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -public class TextViewPreference extends Preference { - private TextView textView = null; - - public TextViewPreference(Context context) { - super(context); - } - - @Override - protected View onCreateView(ViewGroup parent) { - return getTextView(); - } - - public TextView getTextView() { - if (textView == null) { - textView = new TextView(getContext()); - textView.setId(android.R.id.title); - textView.setPadding(5,5,5,5); - } - return textView; - } -} +package de.robv.android.xposed.library.ui; + +import android.content.Context; +import android.graphics.Typeface; +import android.preference.Preference; +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +public class TextViewPreference extends Preference { + private TextView textView = null; + private int padding = 7; + private int textSize = -1; + private boolean bold = false; + private boolean italic = false; + + public TextViewPreference(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + + if (attrs != null) { + textSize = attrs.getAttributeIntValue(null, "textSize", textSize); + padding = attrs.getAttributeIntValue(null, "padding", padding); + bold = attrs.getAttributeBooleanValue(null, "bold", bold); + italic = attrs.getAttributeBooleanValue(null, "italic", italic); + } + } + + public TextViewPreference(Context context, AttributeSet attrs) { + this(context, attrs, android.R.attr.preferenceStyle); + } + + public TextViewPreference(Context context) { + this(context, null); + } + + @Override + protected View onCreateView(ViewGroup parent) { + return getTextView(); + } + + public TextView getTextView() { + if (textView == null) { + textView = new TextView(getContext()); + textView.setId(android.R.id.title); + textView.setPadding(padding,padding,padding,padding); + + if (textSize > 0) + textView.setTextSize(textSize); + + if (bold && italic) + textView.setTypeface(null, Typeface.BOLD_ITALIC); + else if (bold) + textView.setTypeface(null, Typeface.BOLD); + else if (italic) + textView.setTypeface(null, Typeface.ITALIC); + } + return textView; + } +} diff --git a/XposedLibrary/src/de/robv/android/xposed/library/ui/ValueSeekBarPreference.java b/XposedLibrary/src/de/robv/android/xposed/library/ui/ValueSeekBarPreference.java index b54ba88..b3e59da 100644 --- a/XposedLibrary/src/de/robv/android/xposed/library/ui/ValueSeekBarPreference.java +++ b/XposedLibrary/src/de/robv/android/xposed/library/ui/ValueSeekBarPreference.java @@ -1,270 +1,273 @@ -/* - * 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. - */ - -package de.robv.android.xposed.library.ui; - -import android.content.Context; -import android.content.res.TypedArray; -import android.os.Parcel; -import android.os.Parcelable; -import android.preference.Preference; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.SeekBar; -import android.widget.SeekBar.OnSeekBarChangeListener; -import android.widget.TextView; -import de.robv.android.xposed.library.R; - -public class ValueSeekBarPreference extends Preference implements OnSeekBarChangeListener { - - private int mProgress; - private int mStep; - private int mMin; - private int mMax; - private String valueDisplayFormat; - private boolean mTrackingTouch; - private TextView tvValue; - - public ValueSeekBarPreference( - Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - setStep(attrs.getAttributeIntValue(null, "step", 1)); - setMin(attrs.getAttributeIntValue(null, "min", 0)); - setMax(attrs.getAttributeIntValue(null, "max", 100)); - valueDisplayFormat = attrs.getAttributeValue(null, "displayFormat"); - if (valueDisplayFormat == null) - valueDisplayFormat = "%d"; - } - - public ValueSeekBarPreference(Context context, AttributeSet attrs) { - this(context, attrs, android.R.attr.preferenceStyle); - } - - public ValueSeekBarPreference(Context context) { - this(context, null); - } - - @Override - protected View onCreateView(ViewGroup parent) { - ViewGroup originalView = (ViewGroup) super.onCreateView(parent); - - final LayoutInflater layoutInflater = - (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); - - ViewGroup newlayout = (ViewGroup) layoutInflater.inflate(R.layout.preference_valueseekbar_extension, null); - newlayout.addView(originalView, 0); - - tvValue = (TextView) newlayout.findViewById(R.id.valueseekbar_preference_value); - - return newlayout; - } - - @Override - protected void onBindView(View view) { - super.onBindView(view); - SeekBar seekBar = (SeekBar) view.findViewById(R.id.valueseekbar_preference_seekbar); - seekBar.setOnSeekBarChangeListener(this); - seekBar.setMax((mMax - mMin) / mStep); - seekBar.setProgress((mProgress - mMin) / mStep); - tvValue.setText(String.format(valueDisplayFormat, mProgress)); - seekBar.setEnabled(isEnabled()); - } - - @Override - protected void onSetInitialValue(boolean restoreValue, Object defaultValue) { - setProgress(restoreValue ? getPersistedInt(mProgress) - : (Integer) defaultValue); - } - - @Override - protected Object onGetDefaultValue(TypedArray a, int index) { - return a.getInt(index, 0); - } - - public void setStep(int step) { - if (step != mStep) { - mStep = step; - notifyChanged(); - } - } - - public void setMin(int min) { - if (min != mMin) { - mMin = min; - notifyChanged(); - } - } - - public void setMax(int max) { - if (max != mMax) { - mMax = max; - notifyChanged(); - } - } - - public void setProgress(int progress) { - setProgress(progress, true); - } - - private void setProgress(int progress, boolean notifyChanged) { - if (progress > mMax) { - progress = mMax; - } - if (progress < mMin) { - progress = mMin; - } - if (progress != mProgress) { - mProgress = progress; - persistInt(progress); - if (notifyChanged) { - notifyChanged(); - } - } - } - - public int getProgress() { - return mProgress; - } - - /** - * Persist the seekBar's progress value if callChangeListener - * returns true, otherwise set the seekBar's progress to the stored value - */ - void syncProgress(SeekBar seekBar) { - int progress = seekBar.getProgress() * mStep + mMin; - if (progress != mProgress) { - if (callChangeListener(progress)) { - setProgress(progress, false); - } else { - seekBar.setProgress((mProgress - mMin) / mStep); - } - } - } - - @Override - public void onProgressChanged( - SeekBar seekBar, int progress, boolean fromUser) { - if (fromUser && !mTrackingTouch) { - syncProgress(seekBar); - } - tvValue.setText(String.format(valueDisplayFormat, progress * mStep + mMin)); - } - - @Override - public void onStartTrackingTouch(SeekBar seekBar) { - mTrackingTouch = true; - } - - @Override - public void onStopTrackingTouch(SeekBar seekBar) { - mTrackingTouch = false; - if (seekBar.getProgress() * mStep + mMin != mProgress) { - syncProgress(seekBar); - } - } - - @Override - protected Parcelable onSaveInstanceState() { - /* - * Suppose a client uses this preference type without persisting. We - * must save the instance state so it is able to, for example, survive - * orientation changes. - */ - - final Parcelable superState = super.onSaveInstanceState(); - if (isPersistent()) { - // No need to save instance state since it's persistent - return superState; - } - - // Save the instance state - final SavedState myState = new SavedState(superState); - myState.progress = mProgress; - myState.step = mStep; - myState.min = mMin; - myState.max = mMax; - return myState; - } - - @Override - protected void onRestoreInstanceState(Parcelable state) { - if (!state.getClass().equals(SavedState.class)) { - // Didn't save state for us in onSaveInstanceState - super.onRestoreInstanceState(state); - return; - } - - // Restore the instance state - SavedState myState = (SavedState) state; - super.onRestoreInstanceState(myState.getSuperState()); - mProgress = myState.progress; - mStep = myState.step; - mMin = myState.min; - mMax = myState.max; - notifyChanged(); - } - - /** - * SavedState, a subclass of {@link BaseSavedState}, will store the state - * of MyPreference, a subclass of Preference. - *

- * It is important to always call through to super methods. - */ - private static class SavedState extends BaseSavedState { - int progress; - int step; - int min; - int max; - - public SavedState(Parcel source) { - super(source); - - // Restore the click counter - progress = source.readInt(); - step = source.readInt(); - min = source.readInt(); - max = source.readInt(); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - - dest.writeInt(progress); - dest.writeInt(step); - dest.writeInt(min); - dest.writeInt(max); - } - - public SavedState(Parcelable superState) { - super(superState); - } - - @SuppressWarnings("unused") - public static final Parcelable.Creator CREATOR = - new Parcelable.Creator() { - public SavedState createFromParcel(Parcel in) { - return new SavedState(in); - } - - public SavedState[] newArray(int size) { - return new SavedState[size]; - } - }; - } -} +/* + * 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. + */ + +package de.robv.android.xposed.library.ui; + +import android.content.Context; +import android.content.res.TypedArray; +import android.os.Parcel; +import android.os.Parcelable; +import android.preference.Preference; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.SeekBar; +import android.widget.SeekBar.OnSeekBarChangeListener; +import android.widget.TextView; +import de.robv.android.xposed.library.R; + +public class ValueSeekBarPreference extends Preference implements OnSeekBarChangeListener { + + private int mProgress; + private int mStep; + private int mMin; + private int mMax; + private String valueDisplayFormat; + private boolean mTrackingTouch; + private TextView tvValue; + + public ValueSeekBarPreference( + Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + + if (attrs != null) { + setStep(attrs.getAttributeIntValue(null, "step", 1)); + setMin(attrs.getAttributeIntValue(null, "min", 0)); + setMax(attrs.getAttributeIntValue(null, "max", 100)); + valueDisplayFormat = attrs.getAttributeValue(null, "displayFormat"); + if (valueDisplayFormat == null) + valueDisplayFormat = "%d"; + } + } + + public ValueSeekBarPreference(Context context, AttributeSet attrs) { + this(context, attrs, android.R.attr.preferenceStyle); + } + + public ValueSeekBarPreference(Context context) { + this(context, null); + } + + @Override + protected View onCreateView(ViewGroup parent) { + ViewGroup originalView = (ViewGroup) super.onCreateView(parent); + + final LayoutInflater layoutInflater = + (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + ViewGroup newlayout = (ViewGroup) layoutInflater.inflate(R.layout.preference_valueseekbar_extension, null); + newlayout.addView(originalView, 0); + + tvValue = (TextView) newlayout.findViewById(R.id.valueseekbar_preference_value); + + return newlayout; + } + + @Override + protected void onBindView(View view) { + super.onBindView(view); + SeekBar seekBar = (SeekBar) view.findViewById(R.id.valueseekbar_preference_seekbar); + seekBar.setOnSeekBarChangeListener(this); + seekBar.setMax((mMax - mMin) / mStep); + seekBar.setProgress((mProgress - mMin) / mStep); + tvValue.setText(String.format(valueDisplayFormat, mProgress)); + seekBar.setEnabled(isEnabled()); + } + + @Override + protected void onSetInitialValue(boolean restoreValue, Object defaultValue) { + setProgress(restoreValue ? getPersistedInt(mProgress) + : (Integer) defaultValue); + } + + @Override + protected Object onGetDefaultValue(TypedArray a, int index) { + return a.getInt(index, 0); + } + + public void setStep(int step) { + if (step != mStep) { + mStep = step; + notifyChanged(); + } + } + + public void setMin(int min) { + if (min != mMin) { + mMin = min; + notifyChanged(); + } + } + + public void setMax(int max) { + if (max != mMax) { + mMax = max; + notifyChanged(); + } + } + + public void setProgress(int progress) { + setProgress(progress, true); + } + + private void setProgress(int progress, boolean notifyChanged) { + if (progress > mMax) { + progress = mMax; + } + if (progress < mMin) { + progress = mMin; + } + if (progress != mProgress) { + mProgress = progress; + persistInt(progress); + if (notifyChanged) { + notifyChanged(); + } + } + } + + public int getProgress() { + return mProgress; + } + + /** + * Persist the seekBar's progress value if callChangeListener + * returns true, otherwise set the seekBar's progress to the stored value + */ + void syncProgress(SeekBar seekBar) { + int progress = seekBar.getProgress() * mStep + mMin; + if (progress != mProgress) { + if (callChangeListener(progress)) { + setProgress(progress, false); + } else { + seekBar.setProgress((mProgress - mMin) / mStep); + } + } + } + + @Override + public void onProgressChanged( + SeekBar seekBar, int progress, boolean fromUser) { + if (fromUser && !mTrackingTouch) { + syncProgress(seekBar); + } + tvValue.setText(String.format(valueDisplayFormat, progress * mStep + mMin)); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + mTrackingTouch = true; + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + mTrackingTouch = false; + if (seekBar.getProgress() * mStep + mMin != mProgress) { + syncProgress(seekBar); + } + } + + @Override + protected Parcelable onSaveInstanceState() { + /* + * Suppose a client uses this preference type without persisting. We + * must save the instance state so it is able to, for example, survive + * orientation changes. + */ + + final Parcelable superState = super.onSaveInstanceState(); + if (isPersistent()) { + // No need to save instance state since it's persistent + return superState; + } + + // Save the instance state + final SavedState myState = new SavedState(superState); + myState.progress = mProgress; + myState.step = mStep; + myState.min = mMin; + myState.max = mMax; + return myState; + } + + @Override + protected void onRestoreInstanceState(Parcelable state) { + if (!state.getClass().equals(SavedState.class)) { + // Didn't save state for us in onSaveInstanceState + super.onRestoreInstanceState(state); + return; + } + + // Restore the instance state + SavedState myState = (SavedState) state; + super.onRestoreInstanceState(myState.getSuperState()); + mProgress = myState.progress; + mStep = myState.step; + mMin = myState.min; + mMax = myState.max; + notifyChanged(); + } + + /** + * SavedState, a subclass of {@link BaseSavedState}, will store the state + * of MyPreference, a subclass of Preference. + *

+ * It is important to always call through to super methods. + */ + private static class SavedState extends BaseSavedState { + int progress; + int step; + int min; + int max; + + public SavedState(Parcel source) { + super(source); + + // Restore the click counter + progress = source.readInt(); + step = source.readInt(); + min = source.readInt(); + max = source.readInt(); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + + dest.writeInt(progress); + dest.writeInt(step); + dest.writeInt(min); + dest.writeInt(max); + } + + public SavedState(Parcelable superState) { + super(superState); + } + + @SuppressWarnings("unused") + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public SavedState createFromParcel(Parcel in) { + return new SavedState(in); + } + + public SavedState[] newArray(int size) { + return new SavedState[size]; + } + }; + } +} diff --git a/XposedTweakbox/res/layout/settings.xml b/XposedTweakbox/res/layout/settings.xml deleted file mode 100644 index e4ba79a..0000000 --- a/XposedTweakbox/res/layout/settings.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/XposedTweakbox/res/xml/preferences.xml b/XposedTweakbox/res/xml/preferences.xml index fbcd158..9dff3dc 100644 --- a/XposedTweakbox/res/xml/preferences.xml +++ b/XposedTweakbox/res/xml/preferences.xml @@ -1,6 +1,10 @@ - + + + @@ -20,6 +24,7 @@ android:key="statusbar_color" android:summary="Color of the statusbar.\nNOTE: This will probably look weird if you are not on the home screen because most applications do not put anything behind the status bar (why should they?)" android:title="Background color" /> + + + + + + + + + + + + + + + - + + + android:key="phone" + android:title="Phone" > + android:key="phone_vibrate_waiting" + android:summary="Vibrate when establishing a call and the destination is in a conversation. Applied immediately." + android:title="Vibrate on Call Wait" /> + + android:defaultValue="true" + android:key="phone_increasing_ringer" + android:summary="Progressively louder volume for incoming call ring sound. Applied immediately." + android:title="Increasing Ringer Volume" /> + + android:key="phone_call_recording" + android:summary="Enable call recording button while in the middle of a call. Applied after reboot." + android:title="Call Recording" /> + + + - + - --> - - - - - + android:title="... also when screen is turned on" /> --> - + \ No newline at end of file diff --git a/XposedTweakbox/src/de/robv/android/xposed/mods/tweakbox/XposedTweakboxSettings.java b/XposedTweakbox/src/de/robv/android/xposed/mods/tweakbox/XposedTweakboxSettings.java index 5c36451..90e2d91 100644 --- a/XposedTweakbox/src/de/robv/android/xposed/mods/tweakbox/XposedTweakboxSettings.java +++ b/XposedTweakbox/src/de/robv/android/xposed/mods/tweakbox/XposedTweakboxSettings.java @@ -9,7 +9,10 @@ public class XposedTweakboxSettings extends Activity { public void onCreate(Bundle savedInstanceState) { setTitle(R.string.app_name); super.onCreate(savedInstanceState); - setContentView(R.layout.settings); + + // Display the fragment as the main content. + getFragmentManager().beginTransaction().replace(android.R.id.content, + new PrefsFragment()).commit(); } public static class PrefsFragment extends PreferenceFragment {