Skip to content

Commit

Permalink
Preference Screen for wallpaper
Browse files Browse the repository at this point in the history
  • Loading branch information
dvhh committed Apr 21, 2015
1 parent b1ca1dc commit 7685122
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 0 deletions.
15 changes: 15 additions & 0 deletions term/src/main/java/jackpal/androidterm/TermPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.database.Cursor;
import android.net.Uri;
import jackpal.androidterm.compat.FileCompat;
import jackpal.androidterm.preferences.SliderPreference;

import android.os.Bundle;
import android.preference.EditTextPreference;
Expand Down Expand Up @@ -56,6 +57,7 @@ public class TermPreferences extends PreferenceActivity {

private static final String CUSTOM_FONT_CHOOSER_KEY ="custom_font_filepath";
private static final String CATEGORY_TEXT_KEY = "text_category";
private static final String TRANSPARENCY_KEY = "system_wallpaper_alpha";

private static final int RESULT_CODE_FONT_CHOOSER=1;

Expand Down Expand Up @@ -180,6 +182,19 @@ public boolean onPreferenceClick(Preference preference) {
}else{
Log.e(TermPreferences.class.getName(), "cannot find 'font selector' preference");
}

SliderPreference transparencyPreference=(SliderPreference)findPreference(TRANSPARENCY_KEY);
if(transparencyPreference!=null) {
transparencyPreference.setOnSeekBarChangeListener(new SliderPreference.OnSeekBarChangeListener(){

@Override
public void onProgressChanged(SliderPreference target, int progress, boolean fromUser) {
target.setValueText(String.format(getString(R.string.format_transparency_preference),100.0*progress/255));
}
});
}else{
Log.e(TermPreferences.class.getName(), "cannot find 'transparency' preference");
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package jackpal.androidterm.preferences;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;

/**
* based on http://stackoverflow.com/questions/1974193/slider-on-my-preferencescreen
*/

public class SliderPreference extends DialogPreference implements SeekBar.OnSeekBarChangeListener,SeekBar.OnClickListener {
private static final String androidns="http://schemas.android.com/apk/res/android";

protected Context mContext=null;
protected TextView mSplashText;
protected CharSequence mDialogMessage;
protected TextView mValueText;
protected SeekBar mSeekBar;
protected int mValue;
protected int mDefault;
protected int mMax;

protected OnSeekBarChangeListener mOnSeekBarChangeListener=null;

public static abstract class OnSeekBarChangeListener{
public abstract void onProgressChanged(SliderPreference target,int progress,boolean fromUser);
}


public void setOnSeekBarChangeListener(OnSeekBarChangeListener onSeekBarChangeListener) {
mOnSeekBarChangeListener=onSeekBarChangeListener;
}

protected static String getAttributeString(Context context, AttributeSet attrs,String namespace,String attribute,String defaultValue) {
String result=defaultValue;
int resourceID=attrs.getAttributeResourceValue(namespace, attribute, 0);
if(resourceID==0) {
result=attrs.getAttributeValue(namespace,attribute);
}else{
result=context.getString(resourceID);
}
return result;
}

public SliderPreference(Context context, AttributeSet attrs) {
super(context,attrs);
mContext=context;

mDialogMessage=getDialogMessage();
mDefault = attrs.getAttributeIntValue(androidns,"defaultValue",0);
mMax = attrs.getAttributeIntValue(androidns,"max",100);
}

@Override
protected View onCreateDialogView() {
LinearLayout.LayoutParams params;
LinearLayout layout = new LinearLayout(mContext);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setPadding(6,6, 6, 6);

mSplashText = new TextView(mContext);
mSplashText.setPadding(30, 10, 30, 10);
if (mDialogMessage != null)
mSplashText.setText(mDialogMessage);
layout.addView(mSplashText);

mValueText = new TextView(mContext);
mValueText.setGravity(Gravity.CENTER_HORIZONTAL);
mValueText.setTextSize(32);
params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
layout.addView(mValueText, params);

mSeekBar = new SeekBar(mContext);
mSeekBar.setOnSeekBarChangeListener(this);
layout.addView(mSeekBar, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));

if (shouldPersist())
mValue = getPersistedInt(mDefault);

mSeekBar.setMax(mMax);
mSeekBar.setProgress(mValue);

return layout;
}

@Override
protected void onBindDialogView(View v) {
super.onBindDialogView(v);
mSeekBar.setMax(mMax);
mSeekBar.setProgress(mValue);
}

public void setValueText(String text) {
mValueText.setText(text);
}

@Override
public void onProgressChanged(SeekBar seek, int value, boolean fromTouch)
{
String t = String.valueOf(value);
setValueText(t);

if(mOnSeekBarChangeListener!=null) {
mOnSeekBarChangeListener.onProgressChanged(this, value, fromTouch);
}

}

@Override
public void onStartTrackingTouch(SeekBar seek) {}
@Override
public void onStopTrackingTouch(SeekBar seek) {}

public void setMax(int max) { mMax = max; }
public int getMax() { return mMax; }

public void setProgress(int progress) {
mValue = progress;
if (mSeekBar != null)
mSeekBar.setProgress(progress);
}
public int getProgress() { return mValue; }

@Override
public void showDialog(Bundle state) {

super.showDialog(state);

Button positiveButton = ((AlertDialog) getDialog()).getButton(AlertDialog.BUTTON_POSITIVE);
positiveButton.setOnClickListener(this);
}

@Override
public void onClick(View v) {

if (shouldPersist()) {

mValue = mSeekBar.getProgress();
persistInt(mSeekBar.getProgress());
callChangeListener(Integer.valueOf(mSeekBar.getProgress()));
}

((AlertDialog) getDialog()).dismiss();
}
}
2 changes: 2 additions & 0 deletions term/src/main/res/values/defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<integer name="pref_actionbar_default">1</integer>
<integer name="pref_orientation_default">0</integer>
<integer name="pref_toast_position_default">4</integer>
<bool name="pref_use_system_wallpaper_default">false</bool>
<integer name="pref_transparency_default" translatable="false">127</integer>
<string name="pref_customfontfilepath_default"></string>
<bool name="pref_safe_margins_default">false</bool>
<string name="pref_cursorstyle_default" translatable="false">0</string>
Expand Down
8 changes: 8 additions & 0 deletions term/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@
<string name="title_safe_margins_preference">Safe margins</string>
<string name="summary_safe_margins_preference">Add overscan margins to the terminal screen.</string>

<string name="title_use_system_wallpaper_preference">Use system wallpaper</string>
<string name="summary_use_system_wallpaper_preference">Use system wallpaper as terminal background</string>

<string name="title_transparency_preference">Wallpaper transparency</string>
<string name="summary_transparency_preference">Set wallpaper transparency</string>
<string name="format_transparency_preference">%.1f%%</string>
<string name="dialog_use_system_wallpaper_preference">Set the wallpaper transparency</string>

<string name="title_cursorstyle_preference">Cursor style</string>
<string name="summary_cursorstyle_preference">Choose cursor style.</string>
<string name="dialog_title_cursorstyle_preference">Cursor style</string>
Expand Down
17 changes: 17 additions & 0 deletions term/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@
android:title="@string/title_safe_margins_preference"
android:summary="@string/summary_safe_margins_preference"
/>

<CheckBoxPreference
android:key="use_system_wallpaper"
android:defaultValue="@bool/pref_use_system_wallpaper_default"
android:title="@string/title_use_system_wallpaper_preference"
android:summary="@string/summary_use_system_wallpaper_preference"/>


<jackpal.androidterm.preferences.SliderPreference
android:key="system_wallpaper_alpha"
android:max="255"
android:defaultValue="@integer/pref_transparency_default"
android:title="@string/title_transparency_preference"
android:dialogTitle="@string/title_transparency_preference"
android:dialogMessage="@string/dialog_use_system_wallpaper_preference"
android:summary="@string/summary_transparency_preference"
/>
<!--
<ListPreference
android:key="cursorstyle"
Expand Down

0 comments on commit 7685122

Please sign in to comment.