mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-09 22:00:39 +01:00
cleanup: get rid of old dialog stuff
showDialog() goes away except for PrefsActivity which can't do fragments. Move stuff required by PrefsDelegate into it from DelegateBase since no other subclasses does old-style Dialogs any more. Remove a bunch of stuff from DlgDelegate, e.g. saving state, that no longer gets used.
This commit is contained in:
parent
a1c92b6957
commit
f18b3c61bf
7 changed files with 80 additions and 262 deletions
|
@ -84,7 +84,7 @@ public class DelegateBase implements DlgClickNotify,
|
|||
Assert.assertTrue( 0 < menuID );
|
||||
m_delegator = delegator;
|
||||
m_activity = delegator.getActivity();
|
||||
m_dlgDelegate = new DlgDelegate( m_activity, this, this, bundle );
|
||||
m_dlgDelegate = new DlgDelegate( m_activity, this, this );
|
||||
m_layoutID = layoutID;
|
||||
m_optionsMenuID = menuID;
|
||||
LocUtils.xlateTitle( m_activity );
|
||||
|
@ -105,8 +105,6 @@ public class DelegateBase implements DlgClickNotify,
|
|||
protected void onWindowFocusChanged( boolean hasFocus ) {}
|
||||
protected boolean handleBackPressed() { return false; }
|
||||
public void orientationChanged() {}
|
||||
protected Dialog onCreateDialog( int id ) { return null; }
|
||||
protected void prepareDialog( DlgID dlgId, Dialog dialog ) {}
|
||||
|
||||
protected void requestWindowFeature( int feature ) {}
|
||||
|
||||
|
@ -415,11 +413,6 @@ public class DelegateBase implements DlgClickNotify,
|
|||
return cbx.isChecked();
|
||||
}
|
||||
|
||||
protected void showDialog( DlgID dlgID )
|
||||
{
|
||||
m_dlgDelegate.showDialog( dlgID );
|
||||
}
|
||||
|
||||
protected Dialog makeDialog( DBAlert alert, Object[] params )
|
||||
{
|
||||
DlgID dlgID = alert.getDlgID();
|
||||
|
@ -469,8 +462,6 @@ public class DelegateBase implements DlgClickNotify,
|
|||
DbgUtils.assertOnUIThread();
|
||||
if ( m_activity instanceof XWActivity ) {
|
||||
((XWActivity)m_activity).show( df );
|
||||
} else if ( m_activity instanceof PrefsActivity ) {
|
||||
((PrefsActivity)m_activity).show( df );
|
||||
} else {
|
||||
Assert.assertTrue( !BuildConfig.DEBUG );
|
||||
}
|
||||
|
|
|
@ -28,28 +28,13 @@ import android.app.ProgressDialog;
|
|||
import android.content.Context;
|
||||
import android.content.DialogInterface.OnCancelListener;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView.OnItemSelectedListener;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Button;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eehouse.android.xw4.DBUtils.SentInvitesInfo;
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
public class DlgDelegate {
|
||||
private static final String TAG = DlgDelegate.class.getSimpleName();
|
||||
|
@ -288,9 +273,6 @@ public class DlgDelegate {
|
|||
public static final int NFC_BTN = AlertDialog.BUTTON_NEUTRAL;
|
||||
public static final int DISMISS_BUTTON = 0;
|
||||
|
||||
private static final String IDS = "IDS";
|
||||
private static final String STATE_KEYF = "STATE_%d";
|
||||
|
||||
public interface DlgClickNotify {
|
||||
// These are stored in the INVITES table. Don't change order
|
||||
// gratuitously
|
||||
|
@ -311,8 +293,6 @@ public class DlgDelegate {
|
|||
NotAgainBuilder makeNotAgainBuilder( int msgID, int prefsKey );
|
||||
}
|
||||
|
||||
private static Map<DlgID, WeakReference<DelegateBase>> s_pendings
|
||||
= new HashMap<DlgID, WeakReference<DelegateBase>>();
|
||||
private Activity m_activity;
|
||||
private DelegateBase m_dlgt;
|
||||
private DlgClickNotify m_clickCallback;
|
||||
|
@ -320,52 +300,13 @@ public class DlgDelegate {
|
|||
private ProgressDialog m_progress;
|
||||
private Handler m_handler;
|
||||
|
||||
private HashMap<DlgID, DlgState> m_dlgStates;
|
||||
|
||||
public DlgDelegate( Activity activity, DelegateBase dlgt,
|
||||
DlgClickNotify callback, Bundle bundle )
|
||||
DlgClickNotify callback )
|
||||
{
|
||||
m_activity = activity;
|
||||
m_dlgt = dlgt;
|
||||
m_clickCallback = callback;
|
||||
m_handler = new Handler();
|
||||
m_dlgStates = new HashMap<DlgID,DlgState>();
|
||||
|
||||
if ( null != bundle ) {
|
||||
int[] ids = bundle.getIntArray( IDS );
|
||||
if ( null != ids ) {
|
||||
for ( int id : ids ) {
|
||||
String key = String.format( STATE_KEYF, id );
|
||||
addState( (DlgState)bundle.getParcelable( key ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onSaveInstanceState( Bundle outState )
|
||||
{
|
||||
int[] ids = new int[m_dlgStates.size()];
|
||||
if ( 0 < ids.length ) {
|
||||
int indx = 0;
|
||||
Iterator<DlgState> iter = m_dlgStates.values().iterator();
|
||||
while ( iter.hasNext() ) {
|
||||
DlgState state = iter.next();
|
||||
int id = state.m_id.ordinal();
|
||||
String key = String.format( STATE_KEYF, id );
|
||||
outState.putParcelable( key, state );
|
||||
ids[indx++] = id;
|
||||
}
|
||||
}
|
||||
outState.putIntArray( IDS, ids );
|
||||
}
|
||||
|
||||
protected void showDialog( DlgID dlgID )
|
||||
{
|
||||
// DbgUtils.logf( "showDialog(%s)", dlgID.toString() );
|
||||
if ( !m_activity.isFinishing() ) {
|
||||
s_pendings.put( dlgID, new WeakReference<DelegateBase>(m_dlgt) );
|
||||
m_activity.showDialog( dlgID.ordinal() );
|
||||
}
|
||||
}
|
||||
|
||||
private void showOKOnlyDialogThen( String msg, Action action,
|
||||
|
@ -544,80 +485,6 @@ public class DlgDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
private DlgState findForID( DlgID dlgID )
|
||||
{
|
||||
DlgState state = m_dlgStates.get( dlgID );
|
||||
// DbgUtils.logf( "findForID(%d)=>%H", id, state );
|
||||
return state;
|
||||
}
|
||||
|
||||
private void dropState( DlgState state )
|
||||
{
|
||||
int nDlgs = m_dlgStates.size();
|
||||
Assert.assertNotNull( state );
|
||||
// Assert.assertTrue( state == m_dlgStates.get( state.m_id ) );
|
||||
m_dlgStates.remove( state.m_id );
|
||||
// DbgUtils.logf( "dropState: active dialogs now %d from %d ",
|
||||
// m_dlgStates.size(), nDlgs );
|
||||
}
|
||||
|
||||
private void addState( DlgState state )
|
||||
{
|
||||
// I'm getting serialization failures on devices pointing at
|
||||
// DlgState but the code below says the object's fine (as it
|
||||
// should be.) Just to have a record....
|
||||
//
|
||||
// Bundle bundle = new Bundle();
|
||||
// DbgUtils.logf( "addState: testing serializable" );
|
||||
// bundle.putSerializable( "foo", state );
|
||||
// state = (DlgState)bundle.getSerializable( "foo" );
|
||||
// DbgUtils.logf( "addState: serializable is ok" );
|
||||
|
||||
m_dlgStates.put( state.m_id, state );
|
||||
}
|
||||
|
||||
public static Dialog onCreateDialog( int id )
|
||||
{
|
||||
Dialog result = null;
|
||||
DlgID dlgID = DlgID.values()[id];
|
||||
WeakReference<DelegateBase> ref = s_pendings.get( dlgID );
|
||||
if ( null != ref ) {
|
||||
DelegateBase dlgt = ref.get();
|
||||
if ( null != dlgt ) {
|
||||
result = dlgt.onCreateDialog( id );
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void onPrepareDialog( int id, Dialog dialog )
|
||||
{
|
||||
DlgID dlgID = DlgID.values()[id];
|
||||
WeakReference<DelegateBase> ref = s_pendings.get( dlgID );
|
||||
DelegateBase dlgt = ref.get();
|
||||
if ( null != dlgt ) {
|
||||
dlgt.prepareDialog( dlgID, dialog );
|
||||
}
|
||||
}
|
||||
|
||||
protected static void closeAlerts( Activity activity, DelegateBase base )
|
||||
{
|
||||
DbgUtils.assertOnUIThread();
|
||||
Iterator<DlgID> iter = s_pendings.keySet().iterator();
|
||||
while ( iter.hasNext() ) {
|
||||
DlgID dlgID = iter.next();
|
||||
DelegateBase oneBase = s_pendings.get( dlgID ).get();
|
||||
if ( null == oneBase ) {
|
||||
iter.remove(); // no point in keeping it
|
||||
} else if ( base.equals( oneBase ) ) {
|
||||
Log.d( TAG, "removing alert %s for %s", dlgID.toString(),
|
||||
oneBase.toString() );
|
||||
activity.removeDialog( dlgID.ordinal() );
|
||||
iter.remove(); // no point in keeping this either
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getString( int id, Object... params )
|
||||
{
|
||||
return m_dlgt.getString( id, params );
|
||||
|
|
|
@ -61,18 +61,6 @@ public class DualpaneDelegate extends DelegateBase {
|
|||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog( int id )
|
||||
{
|
||||
return DlgDelegate.onCreateDialog( id );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareDialog( DlgID dlgId, Dialog dialog )
|
||||
{
|
||||
DlgDelegate.onPrepareDialog( dlgId.ordinal(), dialog );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleNewIntent( Intent intent )
|
||||
{
|
||||
|
|
|
@ -96,13 +96,6 @@ public class PrefsActivity extends PreferenceActivity
|
|||
return m_dlgt.onCreateDialog( id );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareDialog( int id, Dialog dialog )
|
||||
{
|
||||
super.onPrepareDialog( id, dialog );
|
||||
m_dlgt.prepareDialog( DlgID.values()[id], dialog );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult( int requestCode, int resultCode,
|
||||
Intent data )
|
||||
|
@ -163,11 +156,4 @@ public class PrefsActivity extends PreferenceActivity
|
|||
public void addFragment( XWFragment fragment, Bundle extras ) { Assert.fail(); }
|
||||
public void addFragmentForResult( XWFragment fragment, Bundle extras,
|
||||
RequestCode code ) { Assert.fail(); }
|
||||
public void show( DialogFragment fragment )
|
||||
{
|
||||
// This can't work right now because PrefsActivity doesn't inherit
|
||||
// from anything that can show fragments. So I need to convert to the
|
||||
// newer preferences framework too. :-(
|
||||
Assert.fail();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,65 +75,63 @@ public class PrefsDelegate extends DelegateBase
|
|||
|
||||
protected Dialog onCreateDialog( int id )
|
||||
{
|
||||
Dialog dialog = super.onCreateDialog( id );
|
||||
if ( null == dialog ) {
|
||||
DialogInterface.OnClickListener lstnr = null;
|
||||
int confirmID = 0;
|
||||
DialogInterface.OnClickListener lstnr = null;
|
||||
int confirmID = 0;
|
||||
|
||||
switch( DlgID.values()[id] ) {
|
||||
case REVERT_COLORS:
|
||||
confirmID = R.string.confirm_revert_colors;
|
||||
lstnr = new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
PrefsDelegate self = (PrefsDelegate)curThis();
|
||||
SharedPreferences sp = self.getSharedPreferences();
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
int[] colorKeys = {
|
||||
R.string.key_player0,
|
||||
R.string.key_player1,
|
||||
R.string.key_player2,
|
||||
R.string.key_player3,
|
||||
R.string.key_bonus_l2x,
|
||||
R.string.key_bonus_l3x,
|
||||
R.string.key_bonus_w2x,
|
||||
R.string.key_bonus_w3x,
|
||||
R.string.key_tile_back,
|
||||
R.string.key_clr_crosshairs,
|
||||
R.string.key_empty,
|
||||
R.string.key_background,
|
||||
R.string.key_clr_bonushint,
|
||||
};
|
||||
for ( int colorKey : colorKeys ) {
|
||||
editor.remove( getString(colorKey) );
|
||||
}
|
||||
editor.commit();
|
||||
self.relaunch();
|
||||
switch( DlgID.values()[id] ) {
|
||||
case REVERT_COLORS:
|
||||
confirmID = R.string.confirm_revert_colors;
|
||||
lstnr = new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
PrefsDelegate self = (PrefsDelegate)curThis();
|
||||
SharedPreferences sp = self.getSharedPreferences();
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
int[] colorKeys = {
|
||||
R.string.key_player0,
|
||||
R.string.key_player1,
|
||||
R.string.key_player2,
|
||||
R.string.key_player3,
|
||||
R.string.key_bonus_l2x,
|
||||
R.string.key_bonus_l3x,
|
||||
R.string.key_bonus_w2x,
|
||||
R.string.key_bonus_w3x,
|
||||
R.string.key_tile_back,
|
||||
R.string.key_clr_crosshairs,
|
||||
R.string.key_empty,
|
||||
R.string.key_background,
|
||||
R.string.key_clr_bonushint,
|
||||
};
|
||||
for ( int colorKey : colorKeys ) {
|
||||
editor.remove( getString(colorKey) );
|
||||
}
|
||||
};
|
||||
break;
|
||||
case REVERT_ALL:
|
||||
confirmID = R.string.confirm_revert_all;
|
||||
lstnr = new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
PrefsDelegate self = (PrefsDelegate)curThis();
|
||||
SharedPreferences sp = self.getSharedPreferences();
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.clear();
|
||||
editor.commit();
|
||||
self.relaunch();
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
editor.commit();
|
||||
self.relaunch();
|
||||
}
|
||||
};
|
||||
break;
|
||||
case REVERT_ALL:
|
||||
confirmID = R.string.confirm_revert_all;
|
||||
lstnr = new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
PrefsDelegate self = (PrefsDelegate)curThis();
|
||||
SharedPreferences sp = self.getSharedPreferences();
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.clear();
|
||||
editor.commit();
|
||||
self.relaunch();
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
||||
if ( null == dialog && null != lstnr ) {
|
||||
dialog = makeAlertBuilder()
|
||||
.setTitle( R.string.query_title )
|
||||
.setMessage( confirmID )
|
||||
.setPositiveButton( android.R.string.ok, lstnr )
|
||||
.setNegativeButton( android.R.string.cancel, null )
|
||||
.create();
|
||||
}
|
||||
Dialog dialog = null;
|
||||
if ( null != lstnr ) {
|
||||
dialog = makeAlertBuilder()
|
||||
.setTitle( R.string.query_title )
|
||||
.setMessage( confirmID )
|
||||
.setPositiveButton( android.R.string.ok, lstnr )
|
||||
.setNegativeButton( android.R.string.cancel, null )
|
||||
.create();
|
||||
}
|
||||
return dialog;
|
||||
}
|
||||
|
@ -154,13 +152,13 @@ public class PrefsDelegate extends DelegateBase
|
|||
Button button = (Button)findViewById( R.id.revert_colors );
|
||||
button.setOnClickListener( new View.OnClickListener() {
|
||||
public void onClick( View v ) {
|
||||
curThis().showDialog( DlgID.REVERT_COLORS );
|
||||
showDialog( DlgID.REVERT_COLORS );
|
||||
}
|
||||
} );
|
||||
button = (Button)findViewById( R.id.revert_all );
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick( View v ) {
|
||||
curThis().showDialog( DlgID.REVERT_ALL );
|
||||
showDialog( DlgID.REVERT_ALL );
|
||||
}
|
||||
} );
|
||||
|
||||
|
@ -365,6 +363,13 @@ public class PrefsDelegate extends DelegateBase
|
|||
}
|
||||
}
|
||||
|
||||
private void showDialog( DlgID dlgID )
|
||||
{
|
||||
if ( !m_activity.isFinishing() ) {
|
||||
m_activity.showDialog( dlgID.ordinal() );
|
||||
}
|
||||
}
|
||||
|
||||
private void hideStuff()
|
||||
{
|
||||
if ( !Utils.isGSMPhone( m_activity ) || Perms23.haveNativePerms() ) {
|
||||
|
|
|
@ -122,24 +122,23 @@ public class RelayInviteDelegate extends InviteDelegate {
|
|||
@Override
|
||||
protected void onBarButtonClicked( int id )
|
||||
{
|
||||
switch( id ) {
|
||||
case R.id.button_relay_add:
|
||||
Utils.notImpl( m_activity );
|
||||
break;
|
||||
case R.id.manual_add_button:
|
||||
showDialog( DlgID.GET_NUMBER );
|
||||
break;
|
||||
case R.id.button_clear:
|
||||
Utils.notImpl( m_activity );
|
||||
// int count = getChecked().size();
|
||||
// String msg = getQuantityString( R.plurals.confirm_clear_sms_fmt,
|
||||
// count, count );
|
||||
// makeConfirmThenBuilder( msg, Action.CLEAR_ACTION ).show();
|
||||
break;
|
||||
}
|
||||
// switch( id ) {
|
||||
// case R.id.button_relay_add:
|
||||
// Utils.notImpl( m_activity );
|
||||
// break;
|
||||
// case R.id.manual_add_button:
|
||||
// showDialog( DlgID.GET_NUMBER );
|
||||
// break;
|
||||
// case R.id.button_clear:
|
||||
// Utils.notImpl( m_activity );
|
||||
// // int count = getChecked().size();
|
||||
// // String msg = getQuantityString( R.plurals.confirm_clear_sms_fmt,
|
||||
// // count, count );
|
||||
// // makeConfirmThenBuilder( msg, Action.CLEAR_ACTION ).show();
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
// protected void onSaveInstanceState( Bundle outState )
|
||||
// {
|
||||
// outState.putString( SAVE_NAME, m_pendingName );
|
||||
|
|
|
@ -192,24 +192,6 @@ public class XWActivity extends FragmentActivity
|
|||
return m_dlgt.onContextItemSelected( item );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog( int id )
|
||||
{
|
||||
Dialog dialog = super.onCreateDialog( id );
|
||||
Assert.assertNull( dialog );
|
||||
if ( null == dialog ) {
|
||||
dialog = m_dlgt.onCreateDialog( id );
|
||||
}
|
||||
return dialog;
|
||||
} // onCreateDialog
|
||||
|
||||
@Override
|
||||
public void onPrepareDialog( int id, Dialog dialog )
|
||||
{
|
||||
super.onPrepareDialog( id, dialog );
|
||||
m_dlgt.prepareDialog( DlgID.values()[id], dialog );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged( Configuration newConfig )
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue