mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
to deal with not being implement a common superclass for Activity and
ListActivity create a delegate they use for dialog-related stuff. Move code from them into it -- and delegate.
This commit is contained in:
parent
5599f91232
commit
ea617f39fa
5 changed files with 247 additions and 126 deletions
|
@ -53,7 +53,7 @@ import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
|
||||||
|
|
||||||
public class BoardActivity extends XWActivity implements UtilCtxt {
|
public class BoardActivity extends XWActivity implements UtilCtxt {
|
||||||
|
|
||||||
private static final int DLG_OKONLY = XWActivity.DIALOG_LAST + 1;
|
private static final int DLG_OKONLY = DlgDelegate.DIALOG_LAST + 1;
|
||||||
private static final int DLG_BADWORDS = DLG_OKONLY + 1;
|
private static final int DLG_BADWORDS = DLG_OKONLY + 1;
|
||||||
private static final int QUERY_REQUEST_BLK = DLG_OKONLY + 2;
|
private static final int QUERY_REQUEST_BLK = DLG_OKONLY + 2;
|
||||||
private static final int QUERY_INFORM_BLK = DLG_OKONLY + 3;
|
private static final int QUERY_INFORM_BLK = DLG_OKONLY + 3;
|
||||||
|
@ -121,7 +121,7 @@ public class BoardActivity extends XWActivity implements UtilCtxt {
|
||||||
AlertDialog.Builder ab;
|
AlertDialog.Builder ab;
|
||||||
|
|
||||||
switch ( id ) {
|
switch ( id ) {
|
||||||
case DLG_OKONLY:
|
// case DLG_OKONLY:
|
||||||
case DLG_BADWORDS:
|
case DLG_BADWORDS:
|
||||||
case DLG_RETRY:
|
case DLG_RETRY:
|
||||||
case GOT_MESSAGE:
|
case GOT_MESSAGE:
|
||||||
|
@ -510,7 +510,7 @@ public class BoardActivity extends XWActivity implements UtilCtxt {
|
||||||
startActivity( new Intent( this, PrefsActivity.class ) );
|
startActivity( new Intent( this, PrefsActivity.class ) );
|
||||||
break;
|
break;
|
||||||
case R.id.board_menu_file_about:
|
case R.id.board_menu_file_about:
|
||||||
showDialog( DIALOG_ABOUT );
|
showAboutDialog();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -781,6 +781,19 @@ public class BoardActivity extends XWActivity implements UtilCtxt {
|
||||||
}
|
}
|
||||||
} // loadGame
|
} // loadGame
|
||||||
|
|
||||||
|
private void handleChatButton()
|
||||||
|
{
|
||||||
|
Runnable runnable = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
showDialog( GET_MESSAGE );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
showNotAgainDlgThen( R.string.not_again_chat,
|
||||||
|
R.string.key_notagain_chat,
|
||||||
|
runnable );
|
||||||
|
}
|
||||||
|
|
||||||
private void populateToolbar()
|
private void populateToolbar()
|
||||||
{
|
{
|
||||||
m_toolbar.setListener( Toolbar.BUTTON_HINT_PREV,
|
m_toolbar.setListener( Toolbar.BUTTON_HINT_PREV,
|
||||||
|
@ -831,6 +844,13 @@ public class BoardActivity extends XWActivity implements UtilCtxt {
|
||||||
.CMD_UNDO_CUR );
|
.CMD_UNDO_CUR );
|
||||||
}
|
}
|
||||||
}) ;
|
}) ;
|
||||||
|
m_toolbar.setListener( Toolbar.BUTTON_CHAT,
|
||||||
|
new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick( View view ) {
|
||||||
|
handleChatButton();
|
||||||
|
}
|
||||||
|
}) ;
|
||||||
} // populateToolbar
|
} // populateToolbar
|
||||||
|
|
||||||
private DialogInterface.OnDismissListener makeODLforBlocking()
|
private DialogInterface.OnDismissListener makeODLforBlocking()
|
||||||
|
|
|
@ -0,0 +1,181 @@
|
||||||
|
/* -*- compile-command: "cd ../../../../../; ant install"; -*- */
|
||||||
|
/*
|
||||||
|
* Copyright 2009-2010 by Eric House (xwords@eehouse.org). All
|
||||||
|
* rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation; either version 2 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.eehouse.android.xw4;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.net.Uri;
|
||||||
|
import junit.framework.Assert;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
|
||||||
|
import org.eehouse.android.xw4.jni.CommonPrefs;
|
||||||
|
|
||||||
|
|
||||||
|
public class DlgDelegate {
|
||||||
|
|
||||||
|
public static final int DIALOG_ABOUT = 1;
|
||||||
|
public static final int DIALOG_OKONLY = 2;
|
||||||
|
public static final int DIALOG_NOTAGAIN = 3;
|
||||||
|
public static final int DIALOG_LAST = DIALOG_NOTAGAIN;
|
||||||
|
|
||||||
|
private int m_msgID;
|
||||||
|
private Runnable m_proc = null;
|
||||||
|
private int m_prefsKey;
|
||||||
|
private Activity m_activity;
|
||||||
|
|
||||||
|
public DlgDelegate( Activity activity ) {
|
||||||
|
m_activity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dialog onCreateDialog( int id )
|
||||||
|
{
|
||||||
|
Dialog dialog = null;
|
||||||
|
switch( id ) {
|
||||||
|
case DIALOG_ABOUT:
|
||||||
|
dialog = doAboutDialog();
|
||||||
|
break;
|
||||||
|
case DIALOG_OKONLY:
|
||||||
|
dialog = doOKDialog();
|
||||||
|
break;
|
||||||
|
case DIALOG_NOTAGAIN:
|
||||||
|
dialog = doNotAgainDialog();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showOKOnlyDialog( int msgID )
|
||||||
|
{
|
||||||
|
m_msgID = msgID;
|
||||||
|
m_activity.showDialog( DIALOG_OKONLY );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showAboutDialog()
|
||||||
|
{
|
||||||
|
m_activity.showDialog( DIALOG_ABOUT );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showNotAgainDlgThen( int msgID, int prefsKey,
|
||||||
|
Runnable proc )
|
||||||
|
{
|
||||||
|
boolean set = CommonPrefs.getPrefsBoolean( m_activity, prefsKey, false );
|
||||||
|
if ( set ) {
|
||||||
|
proc.run();
|
||||||
|
} else {
|
||||||
|
m_msgID = msgID;
|
||||||
|
m_proc = proc;
|
||||||
|
m_prefsKey = prefsKey;
|
||||||
|
m_activity.showDialog( DIALOG_NOTAGAIN );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dialog doAboutDialog()
|
||||||
|
{
|
||||||
|
LayoutInflater factory = LayoutInflater.from( m_activity );
|
||||||
|
final View view = factory.inflate( R.layout.about_dlg, null );
|
||||||
|
TextView vers = (TextView)view.findViewById( R.id.version_string );
|
||||||
|
vers.setText( String.format( m_activity.getString(R.string.about_versf),
|
||||||
|
XWConstants.VERSION_STR,
|
||||||
|
GitVersion.VERS ) );
|
||||||
|
|
||||||
|
TextView xlator = (TextView)view.findViewById( R.id.about_xlator );
|
||||||
|
String str = m_activity.getString( R.string.xlator );
|
||||||
|
if ( str.length() > 0 ) {
|
||||||
|
xlator.setText( str );
|
||||||
|
} else {
|
||||||
|
xlator.setVisibility( View.GONE );
|
||||||
|
}
|
||||||
|
|
||||||
|
return new AlertDialog.Builder( m_activity )
|
||||||
|
.setIcon( R.drawable.icon48x48 )
|
||||||
|
.setTitle( R.string.app_name )
|
||||||
|
.setView( view )
|
||||||
|
.setPositiveButton( R.string.changes_button,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick( DialogInterface dlg,
|
||||||
|
int which )
|
||||||
|
{
|
||||||
|
FirstRunDialog.show( m_activity, true );
|
||||||
|
}
|
||||||
|
} )
|
||||||
|
.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dialog doOKDialog()
|
||||||
|
{
|
||||||
|
return new AlertDialog.Builder( m_activity )
|
||||||
|
.setTitle( R.string.info_title )
|
||||||
|
.setMessage( m_msgID )
|
||||||
|
.setPositiveButton( R.string.button_ok, null )
|
||||||
|
.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dialog doNotAgainDialog()
|
||||||
|
{
|
||||||
|
DialogInterface.OnClickListener lstnr_p =
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick( DialogInterface dlg, int item ) {
|
||||||
|
if ( null != m_proc ) {
|
||||||
|
m_proc.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
DialogInterface.OnClickListener lstnr_n =
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick( DialogInterface dlg, int item ) {
|
||||||
|
CommonPrefs.setPrefsBoolean( m_activity, m_prefsKey, true );
|
||||||
|
if ( null != m_proc ) {
|
||||||
|
m_proc.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return new AlertDialog.Builder( m_activity )
|
||||||
|
.setTitle( R.string.info_title )
|
||||||
|
.setMessage( m_msgID )
|
||||||
|
.setPositiveButton( R.string.button_ok, lstnr_p )
|
||||||
|
.setNegativeButton( R.string.button_notagain, lstnr_n )
|
||||||
|
.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
// public void setDialogMsgID( int msgID )
|
||||||
|
// {
|
||||||
|
// m_msgID = msgID;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public void setDialogRunnable( Runnable runnable )
|
||||||
|
// {
|
||||||
|
// m_dialogRunnable = runnable;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public void setDialogPrefsKey( int prefsKey )
|
||||||
|
// {
|
||||||
|
// m_prefsKey = prefsKey;
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
|
@ -50,7 +50,7 @@ public class GamesList extends XWListActivity
|
||||||
implements DispatchNotify.HandleRelaysIface,
|
implements DispatchNotify.HandleRelaysIface,
|
||||||
RefreshMsgsTask.RefreshMsgsIface {
|
RefreshMsgsTask.RefreshMsgsIface {
|
||||||
|
|
||||||
private static final int WARN_NODICT = XWActivity.DIALOG_LAST + 1;
|
private static final int WARN_NODICT = DlgDelegate.DIALOG_LAST + 1;
|
||||||
private static final int CONFIRM_DELETE_ALL = WARN_NODICT + 1;
|
private static final int CONFIRM_DELETE_ALL = WARN_NODICT + 1;
|
||||||
|
|
||||||
private GameListAdapter m_adapter;
|
private GameListAdapter m_adapter;
|
||||||
|
@ -286,7 +286,7 @@ public class GamesList extends XWListActivity
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.gamel_menu_about:
|
case R.id.gamel_menu_about:
|
||||||
showDialog( XWActivity.DIALOG_ABOUT );
|
showAboutDialog();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// case R.id.gamel_menu_view_hidden:
|
// case R.id.gamel_menu_view_hidden:
|
||||||
|
|
|
@ -36,14 +36,13 @@ import org.eehouse.android.xw4.jni.CommonPrefs;
|
||||||
|
|
||||||
public class XWActivity extends Activity {
|
public class XWActivity extends Activity {
|
||||||
|
|
||||||
public static final int DIALOG_ABOUT = 1;
|
private DlgDelegate m_delegate;
|
||||||
public static final int DIALOG_OKONLY = 2;
|
|
||||||
public static final int DIALOG_NOTAGAIN = 3;
|
|
||||||
public static final int DIALOG_LAST = DIALOG_NOTAGAIN;
|
|
||||||
|
|
||||||
private static int s_msgID;
|
protected void onCreate( Bundle savedInstanceState )
|
||||||
private static Runnable s_dialogRunnable = null;
|
{
|
||||||
private static int s_prefsKey;
|
super.onCreate( savedInstanceState );
|
||||||
|
m_delegate = new DlgDelegate( this );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart()
|
protected void onStart()
|
||||||
|
@ -64,106 +63,21 @@ public class XWActivity extends Activity {
|
||||||
@Override
|
@Override
|
||||||
protected Dialog onCreateDialog( int id )
|
protected Dialog onCreateDialog( int id )
|
||||||
{
|
{
|
||||||
return onCreateDialog( this, id );
|
return m_delegate.onCreateDialog( id );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dialog onCreateDialog( Context context, int id )
|
// these are duplicated in XWListActivity -- sometimes multiple
|
||||||
|
// inheritance would be nice to have...
|
||||||
|
protected void showAboutDialog()
|
||||||
{
|
{
|
||||||
Dialog dialog = null;
|
m_delegate.showAboutDialog();
|
||||||
switch( id ) {
|
|
||||||
case DIALOG_ABOUT:
|
|
||||||
dialog = doAboutDialog( context );
|
|
||||||
break;
|
|
||||||
case DIALOG_OKONLY:
|
|
||||||
dialog = doOKDialog( context );
|
|
||||||
break;
|
|
||||||
case DIALOG_NOTAGAIN:
|
|
||||||
dialog = doNotAgainDialog( context );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return dialog;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Dialog doAboutDialog( final Context context )
|
protected void showNotAgainDlgThen( int msgID, int prefsKey,
|
||||||
|
Runnable proc )
|
||||||
{
|
{
|
||||||
LayoutInflater factory = LayoutInflater.from( context );
|
m_delegate.showNotAgainDlgThen( msgID, prefsKey, proc );
|
||||||
final View view = factory.inflate( R.layout.about_dlg, null );
|
|
||||||
TextView vers = (TextView)view.findViewById( R.id.version_string );
|
|
||||||
vers.setText( String.format( context.getString(R.string.about_versf),
|
|
||||||
XWConstants.VERSION_STR,
|
|
||||||
GitVersion.VERS ) );
|
|
||||||
|
|
||||||
TextView xlator = (TextView)view.findViewById( R.id.about_xlator );
|
|
||||||
String str = context.getString( R.string.xlator );
|
|
||||||
if ( str.length() > 0 ) {
|
|
||||||
xlator.setText( str );
|
|
||||||
} else {
|
|
||||||
xlator.setVisibility( View.GONE );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AlertDialog.Builder( context )
|
|
||||||
.setIcon( R.drawable.icon48x48 )
|
|
||||||
.setTitle( R.string.app_name )
|
|
||||||
.setView( view )
|
|
||||||
.setPositiveButton( R.string.changes_button,
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick( DialogInterface dlg,
|
|
||||||
int which )
|
|
||||||
{
|
|
||||||
FirstRunDialog.show( context, true );
|
|
||||||
}
|
|
||||||
} )
|
|
||||||
.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Dialog doOKDialog( final Context context )
|
|
||||||
{
|
|
||||||
return new AlertDialog.Builder( context )
|
|
||||||
.setTitle( R.string.info_title )
|
|
||||||
.setMessage( s_msgID )
|
|
||||||
.setPositiveButton( R.string.button_ok, null )
|
|
||||||
.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Dialog doNotAgainDialog( final Context context )
|
|
||||||
{
|
|
||||||
DialogInterface.OnClickListener lstnr_p =
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick( DialogInterface dlg, int item ) {
|
|
||||||
s_dialogRunnable.run();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
DialogInterface.OnClickListener lstnr_n =
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick( DialogInterface dlg, int item ) {
|
|
||||||
CommonPrefs.setPrefsBoolean( context, s_prefsKey, true );
|
|
||||||
s_dialogRunnable.run();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return new AlertDialog.Builder( context )
|
|
||||||
.setTitle( R.string.info_title )
|
|
||||||
.setMessage( s_msgID )
|
|
||||||
.setPositiveButton( R.string.button_ok, lstnr_p )
|
|
||||||
.setNegativeButton( R.string.button_notagain, lstnr_n )
|
|
||||||
.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setDialogMsgID( int msgID )
|
|
||||||
{
|
|
||||||
s_msgID = msgID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setDialogRunnable( Runnable runnable )
|
|
||||||
{
|
|
||||||
s_dialogRunnable = runnable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setDialogPrefsKey( int prefsKey )
|
|
||||||
{
|
|
||||||
s_prefsKey = prefsKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,14 @@ import android.os.Bundle;
|
||||||
import org.eehouse.android.xw4.jni.CommonPrefs;
|
import org.eehouse.android.xw4.jni.CommonPrefs;
|
||||||
|
|
||||||
public class XWListActivity extends ListActivity {
|
public class XWListActivity extends ListActivity {
|
||||||
|
private DlgDelegate m_delegate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate( Bundle savedInstanceState )
|
||||||
|
{
|
||||||
|
super.onCreate( savedInstanceState );
|
||||||
|
m_delegate = new DlgDelegate( this );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart()
|
protected void onStart()
|
||||||
|
@ -36,26 +44,6 @@ public class XWListActivity extends ListActivity {
|
||||||
DispatchNotify.SetRunning( this );
|
DispatchNotify.SetRunning( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void showOKOnlyDialog( int msgID )
|
|
||||||
{
|
|
||||||
XWActivity.setDialogMsgID( msgID );
|
|
||||||
showDialog( XWActivity.DIALOG_OKONLY );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showNotAgainDlgThen( int msgID, int prefsKey,
|
|
||||||
Runnable proc )
|
|
||||||
{
|
|
||||||
boolean set = CommonPrefs.getPrefsBoolean( this, prefsKey, false );
|
|
||||||
if ( set ) {
|
|
||||||
proc.run();
|
|
||||||
} else {
|
|
||||||
XWActivity.setDialogMsgID( msgID );
|
|
||||||
XWActivity.setDialogRunnable( proc );
|
|
||||||
XWActivity.setDialogPrefsKey( prefsKey );
|
|
||||||
showDialog( XWActivity.DIALOG_NOTAGAIN );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop()
|
protected void onStop()
|
||||||
{
|
{
|
||||||
|
@ -67,10 +55,28 @@ public class XWListActivity extends ListActivity {
|
||||||
@Override
|
@Override
|
||||||
protected Dialog onCreateDialog( int id )
|
protected Dialog onCreateDialog( int id )
|
||||||
{
|
{
|
||||||
Dialog dialog = XWActivity.onCreateDialog( this, id );
|
Dialog dialog = m_delegate.onCreateDialog( id );
|
||||||
if ( null == dialog ) {
|
if ( null == dialog ) {
|
||||||
dialog = super.onCreateDialog( id );
|
dialog = super.onCreateDialog( id );
|
||||||
}
|
}
|
||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// It sucks that these must be duplicated here and XWActivity
|
||||||
|
protected void showAboutDialog()
|
||||||
|
{
|
||||||
|
m_delegate.showAboutDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void showNotAgainDlgThen( int msgID, int prefsKey,
|
||||||
|
Runnable proc )
|
||||||
|
{
|
||||||
|
m_delegate.showNotAgainDlgThen( msgID, prefsKey, proc );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void showOKOnlyDialog( int msgID )
|
||||||
|
{
|
||||||
|
m_delegate.showOKOnlyDialog( msgID );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue