mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-04 23:02:02 +01:00
use sliders instead of text fields for editing of colors, and store
them as ints. This will probably cause older versions to crash. Need either to change the names of keys or warn with next release.
This commit is contained in:
parent
b20296fbd2
commit
9466203844
4 changed files with 53 additions and 43 deletions
|
@ -8,28 +8,35 @@
|
||||||
android:paddingRight="8dp"
|
android:paddingRight="8dp"
|
||||||
>
|
>
|
||||||
|
|
||||||
<EditText android:id="@+id/edit_red"
|
<TextView android:layout_height="wrap_content"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:text="@string/red"
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:layout_marginRight="6sp"
|
|
||||||
android:numeric="decimal"
|
|
||||||
/>
|
/>
|
||||||
|
<SeekBar android:id="@+id/edit_red"
|
||||||
<EditText android:id="@+id/edit_green"
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:max="255"
|
||||||
|
android:progress="1"
|
||||||
|
/>
|
||||||
|
<TextView android:layout_height="wrap_content"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:text="@string/green"
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:layout_marginRight="6sp"
|
|
||||||
android:numeric="decimal"
|
|
||||||
/>
|
/>
|
||||||
|
<SeekBar android:id="@+id/edit_green"
|
||||||
<EditText android:id="@+id/edit_blue"
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:max="255"
|
||||||
|
android:progress="1"
|
||||||
|
/>
|
||||||
|
<TextView android:layout_height="wrap_content"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:text="@string/blue"
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:layout_marginRight="6sp"
|
|
||||||
android:numeric="decimal"
|
|
||||||
/>
|
/>
|
||||||
|
<SeekBar android:id="@+id/edit_blue"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:max="255"
|
||||||
|
android:progress="1"
|
||||||
|
/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -271,6 +271,10 @@
|
||||||
|
|
||||||
<string name="msg_ask_password">Password for \"%s\":</string>
|
<string name="msg_ask_password">Password for \"%s\":</string>
|
||||||
|
|
||||||
|
<string name="red">Red</string>
|
||||||
|
<string name="green">Green</string>
|
||||||
|
<string name="blue">Blue</string>
|
||||||
|
|
||||||
<!-- These do not require localization -->
|
<!-- These do not require localization -->
|
||||||
<string name="key_color_tiles">key_color_tiles</string>
|
<string name="key_color_tiles">key_color_tiles</string>
|
||||||
<string name="key_show_arrow">key_show_arrow</string>
|
<string name="key_show_arrow">key_show_arrow</string>
|
||||||
|
|
|
@ -5,11 +5,12 @@ package org.eehouse.android.xw4;
|
||||||
import android.preference.DialogPreference;
|
import android.preference.DialogPreference;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.SeekBar;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
// import android.app.AlertDialog;
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
@ -28,6 +29,18 @@ public class EditColorPreference extends DialogPreference {
|
||||||
setDialogLayoutResource( R.layout.color_edit );
|
setDialogLayoutResource( R.layout.color_edit );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object onGetDefaultValue(TypedArray a, int index) {
|
||||||
|
return a.getInteger(index, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
|
||||||
|
if ( !restoreValue ) {
|
||||||
|
persistInt( (Integer)defaultValue );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onBindView( View parent )
|
protected void onBindView( View parent )
|
||||||
{
|
{
|
||||||
|
@ -53,40 +66,31 @@ public class EditColorPreference extends DialogPreference {
|
||||||
int color = (getOneByte( dialog, R.id.edit_red ) << 16)
|
int color = (getOneByte( dialog, R.id.edit_red ) << 16)
|
||||||
| (getOneByte( dialog, R.id.edit_green ) << 8)
|
| (getOneByte( dialog, R.id.edit_green ) << 8)
|
||||||
| getOneByte( dialog, R.id.edit_blue );
|
| getOneByte( dialog, R.id.edit_blue );
|
||||||
color |= 0xFF000000;
|
|
||||||
|
|
||||||
// Need to restore the preference, not set the background color
|
persistInt( color );
|
||||||
persistString( String.format( "%d", color) );
|
m_sample.setBackgroundColor( getPersistedColor() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setOneByte( View parent, int id, int byt ) {
|
private void setOneByte( View parent, int id, int byt ) {
|
||||||
byt &= 0xFF;
|
byt &= 0xFF;
|
||||||
EditText et = (EditText)parent.findViewById( id );
|
SeekBar seekbar = (SeekBar)parent.findViewById( id );
|
||||||
if ( null != et ) {
|
if ( null != seekbar ) {
|
||||||
et.setText( String.format("%d", byt ) );
|
seekbar.setProgress( byt );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getOneByte( DialogInterface parent, int id ) {
|
private int getOneByte( DialogInterface parent, int id ) {
|
||||||
int val = 0;
|
int val = 0;
|
||||||
Dialog dialog = (Dialog)parent;
|
Dialog dialog = (Dialog)parent;
|
||||||
EditText et = (EditText)dialog.findViewById( id );
|
SeekBar seekbar = (SeekBar)dialog.findViewById( id );
|
||||||
if ( null != et ) {
|
if ( null != seekbar ) {
|
||||||
String str = et.getText().toString();
|
val = seekbar.getProgress();
|
||||||
val = Integer.decode( str );
|
|
||||||
}
|
}
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getPersistedColor()
|
private int getPersistedColor()
|
||||||
{
|
{
|
||||||
String val = getPersistedString("");
|
return 0xFF000000 | getPersistedInt(0);
|
||||||
int color;
|
|
||||||
try {
|
|
||||||
color = 0xFF000000 | Integer.decode( val );
|
|
||||||
} catch ( java.lang.NumberFormatException nfe ) {
|
|
||||||
color = 0xFF7F7F7F;
|
|
||||||
}
|
|
||||||
return color;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,12 +90,7 @@ public class CommonPrefs {
|
||||||
private int prefToColor( SharedPreferences sp, int id )
|
private int prefToColor( SharedPreferences sp, int id )
|
||||||
{
|
{
|
||||||
String key = s_context.getString( id );
|
String key = s_context.getString( id );
|
||||||
String val = sp.getString( key, "" );
|
return 0xFF000000 | sp.getInt( key, 0 );
|
||||||
try {
|
|
||||||
return 0xFF000000 | Integer.decode( val );
|
|
||||||
} catch ( java.lang.NumberFormatException nfe ) {
|
|
||||||
return 0xFF7F7F7F;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue