mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-04 23:02:02 +01:00
Remove ok button from color editor; when cancel chosen don't save changes.
This commit is contained in:
parent
9466203844
commit
d68038b18b
1 changed files with 33 additions and 10 deletions
|
@ -11,6 +11,7 @@ import android.view.View;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
@ -18,7 +19,8 @@ public class EditColorPreference extends DialogPreference {
|
||||||
|
|
||||||
private Context m_context;
|
private Context m_context;
|
||||||
// private int m_color = 0;
|
// private int m_color = 0;
|
||||||
private View m_sample = null;
|
// private View m_sample = null;
|
||||||
|
private boolean m_cancel;
|
||||||
|
|
||||||
public EditColorPreference( Context context, AttributeSet attrs )
|
public EditColorPreference( Context context, AttributeSet attrs )
|
||||||
{
|
{
|
||||||
|
@ -45,30 +47,51 @@ public class EditColorPreference extends DialogPreference {
|
||||||
protected void onBindView( View parent )
|
protected void onBindView( View parent )
|
||||||
{
|
{
|
||||||
super.onBindView( parent );
|
super.onBindView( parent );
|
||||||
m_sample = parent.findViewById( R.id.color_display_sample );
|
View sample = parent.findViewById( R.id.color_display_sample );
|
||||||
if ( null != m_sample ) {
|
sample.setBackgroundColor( getPersistedColor() );
|
||||||
m_sample.setBackgroundColor( getPersistedColor() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onBindDialogView( View view )
|
protected void onBindDialogView( View view )
|
||||||
{
|
{
|
||||||
|
m_cancel = false;
|
||||||
int color = getPersistedColor();
|
int color = getPersistedColor();
|
||||||
setOneByte( view, R.id.edit_red, color >> 16 );
|
setOneByte( view, R.id.edit_red, color >> 16 );
|
||||||
setOneByte( view, R.id.edit_green, color >> 8 );
|
setOneByte( view, R.id.edit_green, color >> 8 );
|
||||||
setOneByte( view, R.id.edit_blue, color );
|
setOneByte( view, R.id.edit_blue, color );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPrepareDialogBuilder( AlertDialog.Builder builder )
|
||||||
|
{
|
||||||
|
builder.setPositiveButton( null, null );
|
||||||
|
builder.setNegativeButton( R.string.button_cancel,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick( DialogInterface dg,
|
||||||
|
int which )
|
||||||
|
{
|
||||||
|
m_cancel = true;
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
super.onPrepareDialogBuilder( builder );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDismiss( DialogInterface dialog )
|
public void onDismiss( DialogInterface dialog )
|
||||||
{
|
{
|
||||||
|
if ( !m_cancel ) {
|
||||||
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 );
|
||||||
|
|
||||||
persistInt( color );
|
persistInt( color );
|
||||||
m_sample.setBackgroundColor( getPersistedColor() );
|
View sample =
|
||||||
|
((AlertDialog)dialog).findViewById( R.id.color_display_sample );
|
||||||
|
if ( null != sample ) {
|
||||||
|
sample.setBackgroundColor( getPersistedColor() );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setOneByte( View parent, int id, int byt ) {
|
private void setOneByte( View parent, int id, int byt ) {
|
||||||
|
|
Loading…
Reference in a new issue