mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-11 08:48:06 +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 );
|
Assert.assertTrue( 0 < menuID );
|
||||||
m_delegator = delegator;
|
m_delegator = delegator;
|
||||||
m_activity = delegator.getActivity();
|
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_layoutID = layoutID;
|
||||||
m_optionsMenuID = menuID;
|
m_optionsMenuID = menuID;
|
||||||
LocUtils.xlateTitle( m_activity );
|
LocUtils.xlateTitle( m_activity );
|
||||||
|
@ -105,8 +105,6 @@ public class DelegateBase implements DlgClickNotify,
|
||||||
protected void onWindowFocusChanged( boolean hasFocus ) {}
|
protected void onWindowFocusChanged( boolean hasFocus ) {}
|
||||||
protected boolean handleBackPressed() { return false; }
|
protected boolean handleBackPressed() { return false; }
|
||||||
public void orientationChanged() {}
|
public void orientationChanged() {}
|
||||||
protected Dialog onCreateDialog( int id ) { return null; }
|
|
||||||
protected void prepareDialog( DlgID dlgId, Dialog dialog ) {}
|
|
||||||
|
|
||||||
protected void requestWindowFeature( int feature ) {}
|
protected void requestWindowFeature( int feature ) {}
|
||||||
|
|
||||||
|
@ -415,11 +413,6 @@ public class DelegateBase implements DlgClickNotify,
|
||||||
return cbx.isChecked();
|
return cbx.isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void showDialog( DlgID dlgID )
|
|
||||||
{
|
|
||||||
m_dlgDelegate.showDialog( dlgID );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Dialog makeDialog( DBAlert alert, Object[] params )
|
protected Dialog makeDialog( DBAlert alert, Object[] params )
|
||||||
{
|
{
|
||||||
DlgID dlgID = alert.getDlgID();
|
DlgID dlgID = alert.getDlgID();
|
||||||
|
@ -469,8 +462,6 @@ public class DelegateBase implements DlgClickNotify,
|
||||||
DbgUtils.assertOnUIThread();
|
DbgUtils.assertOnUIThread();
|
||||||
if ( m_activity instanceof XWActivity ) {
|
if ( m_activity instanceof XWActivity ) {
|
||||||
((XWActivity)m_activity).show( df );
|
((XWActivity)m_activity).show( df );
|
||||||
} else if ( m_activity instanceof PrefsActivity ) {
|
|
||||||
((PrefsActivity)m_activity).show( df );
|
|
||||||
} else {
|
} else {
|
||||||
Assert.assertTrue( !BuildConfig.DEBUG );
|
Assert.assertTrue( !BuildConfig.DEBUG );
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,28 +28,13 @@ import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface.OnCancelListener;
|
import android.content.DialogInterface.OnCancelListener;
|
||||||
import android.content.DialogInterface.OnClickListener;
|
import android.content.DialogInterface.OnClickListener;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.view.View;
|
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 junit.framework.Assert;
|
||||||
|
|
||||||
import org.eehouse.android.xw4.DBUtils.SentInvitesInfo;
|
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 {
|
public class DlgDelegate {
|
||||||
private static final String TAG = DlgDelegate.class.getSimpleName();
|
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 NFC_BTN = AlertDialog.BUTTON_NEUTRAL;
|
||||||
public static final int DISMISS_BUTTON = 0;
|
public static final int DISMISS_BUTTON = 0;
|
||||||
|
|
||||||
private static final String IDS = "IDS";
|
|
||||||
private static final String STATE_KEYF = "STATE_%d";
|
|
||||||
|
|
||||||
public interface DlgClickNotify {
|
public interface DlgClickNotify {
|
||||||
// These are stored in the INVITES table. Don't change order
|
// These are stored in the INVITES table. Don't change order
|
||||||
// gratuitously
|
// gratuitously
|
||||||
|
@ -311,8 +293,6 @@ public class DlgDelegate {
|
||||||
NotAgainBuilder makeNotAgainBuilder( int msgID, int prefsKey );
|
NotAgainBuilder makeNotAgainBuilder( int msgID, int prefsKey );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<DlgID, WeakReference<DelegateBase>> s_pendings
|
|
||||||
= new HashMap<DlgID, WeakReference<DelegateBase>>();
|
|
||||||
private Activity m_activity;
|
private Activity m_activity;
|
||||||
private DelegateBase m_dlgt;
|
private DelegateBase m_dlgt;
|
||||||
private DlgClickNotify m_clickCallback;
|
private DlgClickNotify m_clickCallback;
|
||||||
|
@ -320,52 +300,13 @@ public class DlgDelegate {
|
||||||
private ProgressDialog m_progress;
|
private ProgressDialog m_progress;
|
||||||
private Handler m_handler;
|
private Handler m_handler;
|
||||||
|
|
||||||
private HashMap<DlgID, DlgState> m_dlgStates;
|
|
||||||
|
|
||||||
public DlgDelegate( Activity activity, DelegateBase dlgt,
|
public DlgDelegate( Activity activity, DelegateBase dlgt,
|
||||||
DlgClickNotify callback, Bundle bundle )
|
DlgClickNotify callback )
|
||||||
{
|
{
|
||||||
m_activity = activity;
|
m_activity = activity;
|
||||||
m_dlgt = dlgt;
|
m_dlgt = dlgt;
|
||||||
m_clickCallback = callback;
|
m_clickCallback = callback;
|
||||||
m_handler = new Handler();
|
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,
|
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 )
|
private String getString( int id, Object... params )
|
||||||
{
|
{
|
||||||
return m_dlgt.getString( id, params );
|
return m_dlgt.getString( id, params );
|
||||||
|
|
|
@ -61,18 +61,6 @@ public class DualpaneDelegate extends DelegateBase {
|
||||||
return dialog;
|
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
|
@Override
|
||||||
protected void handleNewIntent( Intent intent )
|
protected void handleNewIntent( Intent intent )
|
||||||
{
|
{
|
||||||
|
|
|
@ -96,13 +96,6 @@ public class PrefsActivity extends PreferenceActivity
|
||||||
return m_dlgt.onCreateDialog( id );
|
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
|
@Override
|
||||||
protected void onActivityResult( int requestCode, int resultCode,
|
protected void onActivityResult( int requestCode, int resultCode,
|
||||||
Intent data )
|
Intent data )
|
||||||
|
@ -163,11 +156,4 @@ public class PrefsActivity extends PreferenceActivity
|
||||||
public void addFragment( XWFragment fragment, Bundle extras ) { Assert.fail(); }
|
public void addFragment( XWFragment fragment, Bundle extras ) { Assert.fail(); }
|
||||||
public void addFragmentForResult( XWFragment fragment, Bundle extras,
|
public void addFragmentForResult( XWFragment fragment, Bundle extras,
|
||||||
RequestCode code ) { Assert.fail(); }
|
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,8 +75,6 @@ public class PrefsDelegate extends DelegateBase
|
||||||
|
|
||||||
protected Dialog onCreateDialog( int id )
|
protected Dialog onCreateDialog( int id )
|
||||||
{
|
{
|
||||||
Dialog dialog = super.onCreateDialog( id );
|
|
||||||
if ( null == dialog ) {
|
|
||||||
DialogInterface.OnClickListener lstnr = null;
|
DialogInterface.OnClickListener lstnr = null;
|
||||||
int confirmID = 0;
|
int confirmID = 0;
|
||||||
|
|
||||||
|
@ -126,7 +124,8 @@ public class PrefsDelegate extends DelegateBase
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( null == dialog && null != lstnr ) {
|
Dialog dialog = null;
|
||||||
|
if ( null != lstnr ) {
|
||||||
dialog = makeAlertBuilder()
|
dialog = makeAlertBuilder()
|
||||||
.setTitle( R.string.query_title )
|
.setTitle( R.string.query_title )
|
||||||
.setMessage( confirmID )
|
.setMessage( confirmID )
|
||||||
|
@ -134,7 +133,6 @@ public class PrefsDelegate extends DelegateBase
|
||||||
.setNegativeButton( android.R.string.cancel, null )
|
.setNegativeButton( android.R.string.cancel, null )
|
||||||
.create();
|
.create();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,13 +152,13 @@ public class PrefsDelegate extends DelegateBase
|
||||||
Button button = (Button)findViewById( R.id.revert_colors );
|
Button button = (Button)findViewById( R.id.revert_colors );
|
||||||
button.setOnClickListener( new View.OnClickListener() {
|
button.setOnClickListener( new View.OnClickListener() {
|
||||||
public void onClick( View v ) {
|
public void onClick( View v ) {
|
||||||
curThis().showDialog( DlgID.REVERT_COLORS );
|
showDialog( DlgID.REVERT_COLORS );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
button = (Button)findViewById( R.id.revert_all );
|
button = (Button)findViewById( R.id.revert_all );
|
||||||
button.setOnClickListener(new View.OnClickListener() {
|
button.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick( View v ) {
|
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()
|
private void hideStuff()
|
||||||
{
|
{
|
||||||
if ( !Utils.isGSMPhone( m_activity ) || Perms23.haveNativePerms() ) {
|
if ( !Utils.isGSMPhone( m_activity ) || Perms23.haveNativePerms() ) {
|
||||||
|
|
|
@ -122,23 +122,22 @@ public class RelayInviteDelegate extends InviteDelegate {
|
||||||
@Override
|
@Override
|
||||||
protected void onBarButtonClicked( int id )
|
protected void onBarButtonClicked( int id )
|
||||||
{
|
{
|
||||||
switch( id ) {
|
// switch( id ) {
|
||||||
case R.id.button_relay_add:
|
// case R.id.button_relay_add:
|
||||||
Utils.notImpl( m_activity );
|
// Utils.notImpl( m_activity );
|
||||||
break;
|
// break;
|
||||||
case R.id.manual_add_button:
|
// case R.id.manual_add_button:
|
||||||
showDialog( DlgID.GET_NUMBER );
|
// showDialog( DlgID.GET_NUMBER );
|
||||||
break;
|
// break;
|
||||||
case R.id.button_clear:
|
// case R.id.button_clear:
|
||||||
Utils.notImpl( m_activity );
|
// Utils.notImpl( m_activity );
|
||||||
// int count = getChecked().size();
|
// // int count = getChecked().size();
|
||||||
// String msg = getQuantityString( R.plurals.confirm_clear_sms_fmt,
|
// // String msg = getQuantityString( R.plurals.confirm_clear_sms_fmt,
|
||||||
// count, count );
|
// // count, count );
|
||||||
// makeConfirmThenBuilder( msg, Action.CLEAR_ACTION ).show();
|
// // makeConfirmThenBuilder( msg, Action.CLEAR_ACTION ).show();
|
||||||
break;
|
// break;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// protected void onSaveInstanceState( Bundle outState )
|
// protected void onSaveInstanceState( Bundle outState )
|
||||||
// {
|
// {
|
||||||
|
|
|
@ -192,24 +192,6 @@ public class XWActivity extends FragmentActivity
|
||||||
return m_dlgt.onContextItemSelected( item );
|
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
|
@Override
|
||||||
public void onConfigurationChanged( Configuration newConfig )
|
public void onConfigurationChanged( Configuration newConfig )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue