mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-22 07:28:16 +01:00
support alert onDismiss listener
New way of adding onDismiss listener to DialogFragment-based alerts required API change to DBAlert and the makeDialog() method. Fixes customizing default player name.
This commit is contained in:
parent
f5c022bb72
commit
13adebdc51
6 changed files with 50 additions and 26 deletions
|
@ -19,9 +19,10 @@
|
|||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.os.Bundle;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
@ -31,8 +32,13 @@ public class DBAlert extends DialogFragment {
|
|||
private static final String DLG_ID_KEY = "DLG_ID_KEY";
|
||||
private static final String PARMS_KEY = "PARMS_KEY";
|
||||
|
||||
public interface OnDismissListener {
|
||||
void onDismissed();
|
||||
}
|
||||
|
||||
private Object[] mParams;
|
||||
private DlgID mDlgID;
|
||||
private OnDismissListener m_onDismiss;
|
||||
|
||||
public static DBAlert newInstance( DlgID dlgID, Object[] params )
|
||||
{
|
||||
|
@ -52,6 +58,8 @@ public class DBAlert extends DialogFragment {
|
|||
|
||||
public DBAlert() {}
|
||||
|
||||
public DlgID getDlgID() { return mDlgID; }
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState( Bundle bundle )
|
||||
{
|
||||
|
@ -70,6 +78,20 @@ public class DBAlert extends DialogFragment {
|
|||
mParams = (Object[])sis.getSerializable(PARMS_KEY);
|
||||
|
||||
XWActivity activity = (XWActivity)getActivity();
|
||||
return activity.makeDialog( mDlgID, mParams );
|
||||
return activity.makeDialog( this, mParams );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss( DialogInterface dif )
|
||||
{
|
||||
if ( null != m_onDismiss ) {
|
||||
m_onDismiss.onDismissed();
|
||||
}
|
||||
super.onDismiss( dif );
|
||||
}
|
||||
|
||||
protected void setOnDismiss( OnDismissListener lstnr )
|
||||
{
|
||||
m_onDismiss = lstnr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -423,8 +423,9 @@ public class DelegateBase implements DlgClickNotify,
|
|||
m_dlgDelegate.showDialog( dlgID );
|
||||
}
|
||||
|
||||
protected Dialog makeDialog( DlgID dlgID, Object[] params )
|
||||
protected Dialog makeDialog( DBAlert alert, Object[] params )
|
||||
{
|
||||
DlgID dlgID = alert.getDlgID();
|
||||
DbgUtils.logd( TAG, "makeDialog(): not handling %s", dlgID.toString() );
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -359,14 +359,14 @@ public class DictsDelegate extends ListDelegateBase
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Dialog makeDialog( DlgID dlgID, Object[] params )
|
||||
protected Dialog makeDialog( DBAlert alert, Object[] params )
|
||||
{
|
||||
OnClickListener lstnr, lstnr2;
|
||||
Dialog dialog;
|
||||
String message;
|
||||
boolean doRemove = true;
|
||||
|
||||
switch( dlgID ) {
|
||||
switch( alert.getDlgID() ) {
|
||||
case MOVE_DICT: {
|
||||
final String[] selNames = getSelNames();
|
||||
final int[] moveTo = { -1 };
|
||||
|
@ -460,7 +460,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
}
|
||||
|
||||
default:
|
||||
dialog = super.makeDialog( dlgID, params );
|
||||
dialog = super.makeDialog( alert, params );
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,13 +47,13 @@ public class DualpaneDelegate extends DelegateBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Dialog makeDialog( DlgID dlgID, Object[] params )
|
||||
protected Dialog makeDialog( DBAlert alert, Object[] params )
|
||||
{
|
||||
Dialog dialog = null;
|
||||
MainActivity main = (MainActivity)m_activity;
|
||||
XWFragment[] frags = main.getVisibleFragments();
|
||||
for ( XWFragment frag : frags ) {
|
||||
dialog = frag.getDelegate().makeDialog( dlgID, params );
|
||||
dialog = frag.getDelegate().makeDialog( alert, params );
|
||||
if ( null != dialog ) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -607,12 +607,13 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Dialog makeDialog( DlgID dlgID, Object[] params )
|
||||
protected Dialog makeDialog( DBAlert alert, Object[] params )
|
||||
{
|
||||
Dialog dialog = null;
|
||||
OnClickListener lstnr, lstnr2;
|
||||
AlertDialog.Builder ab;
|
||||
|
||||
DlgID dlgID = alert.getDlgID();
|
||||
switch ( dlgID ) {
|
||||
case WARN_NODICT:
|
||||
case WARN_NODICT_NEW:
|
||||
|
@ -824,25 +825,25 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
(EditText)layout.findViewById( R.id.name_edit );
|
||||
etext.setText( CommonPrefs.getDefaultPlayerName( m_activity,
|
||||
0, true ) );
|
||||
alert.setOnDismiss( new DBAlert.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismissed() {
|
||||
String name = etext.getText().toString();
|
||||
if ( 0 == name.length() ) {
|
||||
name = CommonPrefs.
|
||||
getDefaultPlayerName( m_activity, 0, true );
|
||||
} else {
|
||||
CommonPrefs.setDefaultPlayerName( m_activity, name );
|
||||
}
|
||||
makeThenLaunchOrConfigure();
|
||||
}
|
||||
} );
|
||||
dialog = makeAlertBuilder()
|
||||
.setTitle( R.string.default_name_title )
|
||||
.setMessage( R.string.default_name_message )
|
||||
.setPositiveButton( android.R.string.ok, null )
|
||||
.setView( layout )
|
||||
.create();
|
||||
dialog.setOnDismissListener(new DialogInterface.
|
||||
OnDismissListener() {
|
||||
public void onDismiss( DialogInterface dlg ) {
|
||||
String name = etext.getText().toString();
|
||||
if ( 0 == name.length() ) {
|
||||
name = CommonPrefs.
|
||||
getDefaultPlayerName( m_activity, 0, true );
|
||||
}
|
||||
CommonPrefs.setDefaultPlayerName( m_activity, name );
|
||||
|
||||
makeThenLaunchOrConfigure();
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -922,7 +923,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
break;
|
||||
|
||||
default:
|
||||
dialog = super.makeDialog( dlgID, params );
|
||||
dialog = super.makeDialog( alert, params );
|
||||
break;
|
||||
}
|
||||
return dialog;
|
||||
|
|
|
@ -280,9 +280,9 @@ public class XWActivity extends FragmentActivity
|
|||
df.show( getSupportFragmentManager(), "dialog" );
|
||||
}
|
||||
|
||||
protected Dialog makeDialog( DlgID dlgID, Object[] params )
|
||||
protected Dialog makeDialog( DBAlert alert, Object[] params )
|
||||
{
|
||||
return m_dlgt.makeDialog( dlgID, params );
|
||||
return m_dlgt.makeDialog( alert, params );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in a new issue