mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +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"
|
||||
>
|
||||
|
||||
<EditText android:id="@+id/edit_red"
|
||||
<TextView android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginRight="6sp"
|
||||
android:numeric="decimal"
|
||||
android:text="@string/red"
|
||||
/>
|
||||
|
||||
<EditText android:id="@+id/edit_green"
|
||||
<SeekBar android:id="@+id/edit_red"
|
||||
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_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginRight="6sp"
|
||||
android:numeric="decimal"
|
||||
android:text="@string/green"
|
||||
/>
|
||||
|
||||
<EditText android:id="@+id/edit_blue"
|
||||
<SeekBar 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_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginRight="6sp"
|
||||
android:numeric="decimal"
|
||||
android:text="@string/blue"
|
||||
/>
|
||||
<SeekBar android:id="@+id/edit_blue"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:max="255"
|
||||
android:progress="1"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -270,6 +270,10 @@
|
|||
not found.</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 -->
|
||||
<string name="key_color_tiles">key_color_tiles</string>
|
||||
|
|
|
@ -5,11 +5,12 @@ package org.eehouse.android.xw4;
|
|||
import android.preference.DialogPreference;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.SeekBar;
|
||||
import android.app.Dialog;
|
||||
// import android.app.AlertDialog;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
|
@ -27,6 +28,18 @@ public class EditColorPreference extends DialogPreference {
|
|||
setWidgetLayoutResource( R.layout.color_display );
|
||||
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
|
||||
protected void onBindView( View parent )
|
||||
|
@ -53,40 +66,31 @@ public class EditColorPreference extends DialogPreference {
|
|||
int color = (getOneByte( dialog, R.id.edit_red ) << 16)
|
||||
| (getOneByte( dialog, R.id.edit_green ) << 8)
|
||||
| getOneByte( dialog, R.id.edit_blue );
|
||||
color |= 0xFF000000;
|
||||
|
||||
// Need to restore the preference, not set the background color
|
||||
persistString( String.format( "%d", color) );
|
||||
persistInt( color );
|
||||
m_sample.setBackgroundColor( getPersistedColor() );
|
||||
}
|
||||
|
||||
private void setOneByte( View parent, int id, int byt ) {
|
||||
byt &= 0xFF;
|
||||
EditText et = (EditText)parent.findViewById( id );
|
||||
if ( null != et ) {
|
||||
et.setText( String.format("%d", byt ) );
|
||||
SeekBar seekbar = (SeekBar)parent.findViewById( id );
|
||||
if ( null != seekbar ) {
|
||||
seekbar.setProgress( byt );
|
||||
}
|
||||
}
|
||||
|
||||
private int getOneByte( DialogInterface parent, int id ) {
|
||||
int val = 0;
|
||||
Dialog dialog = (Dialog)parent;
|
||||
EditText et = (EditText)dialog.findViewById( id );
|
||||
if ( null != et ) {
|
||||
String str = et.getText().toString();
|
||||
val = Integer.decode( str );
|
||||
SeekBar seekbar = (SeekBar)dialog.findViewById( id );
|
||||
if ( null != seekbar ) {
|
||||
val = seekbar.getProgress();
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
private int getPersistedColor()
|
||||
{
|
||||
String val = getPersistedString("");
|
||||
int color;
|
||||
try {
|
||||
color = 0xFF000000 | Integer.decode( val );
|
||||
} catch ( java.lang.NumberFormatException nfe ) {
|
||||
color = 0xFF7F7F7F;
|
||||
}
|
||||
return color;
|
||||
return 0xFF000000 | getPersistedInt(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,12 +90,7 @@ public class CommonPrefs {
|
|||
private int prefToColor( SharedPreferences sp, int id )
|
||||
{
|
||||
String key = s_context.getString( id );
|
||||
String val = sp.getString( key, "" );
|
||||
try {
|
||||
return 0xFF000000 | Integer.decode( val );
|
||||
} catch ( java.lang.NumberFormatException nfe ) {
|
||||
return 0xFF7F7F7F;
|
||||
}
|
||||
return 0xFF000000 | sp.getInt( key, 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue