mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-24 07:58:34 +01:00
use an enum for startActivityForResult requestCode to ensure they're
unique across the app.
This commit is contained in:
parent
2a3bd60740
commit
87c6b3e0fe
10 changed files with 87 additions and 42 deletions
|
@ -54,12 +54,12 @@ public class BTInviteDelegate extends InviteDelegate {
|
||||||
private BTDevsAdapter m_adapter;
|
private BTDevsAdapter m_adapter;
|
||||||
|
|
||||||
public static void launchForResult( Activity activity, int nMissing,
|
public static void launchForResult( Activity activity, int nMissing,
|
||||||
int requestCode )
|
RequestCode requestCode )
|
||||||
{
|
{
|
||||||
Assert.assertTrue( 0 < nMissing ); // don't call if nMissing == 0
|
Assert.assertTrue( 0 < nMissing ); // don't call if nMissing == 0
|
||||||
Intent intent = new Intent( activity, BTInviteActivity.class );
|
Intent intent = new Intent( activity, BTInviteActivity.class );
|
||||||
intent.putExtra( INTENT_KEY_NMISSING, nMissing );
|
intent.putExtra( INTENT_KEY_NMISSING, nMissing );
|
||||||
activity.startActivityForResult( intent, requestCode );
|
activity.startActivityForResult( intent, requestCode.ordinal() );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected BTInviteDelegate( Delegator delegator, Bundle savedInstanceState )
|
protected BTInviteDelegate( Delegator delegator, Bundle savedInstanceState )
|
||||||
|
|
|
@ -69,11 +69,6 @@ public class BoardDelegate extends DelegateBase
|
||||||
|
|
||||||
public static final String INTENT_KEY_CHAT = "chat";
|
public static final String INTENT_KEY_CHAT = "chat";
|
||||||
|
|
||||||
private static final int CHAT_REQUEST = 1;
|
|
||||||
private static final int BT_INVITE_RESULT = 2;
|
|
||||||
private static final int SMS_INVITE_RESULT = 3;
|
|
||||||
private static final int RELAY_INVITE_RESULT = 4;
|
|
||||||
|
|
||||||
private static final int SCREEN_ON_TIME = 10 * 60 * 1000; // 10 mins
|
private static final int SCREEN_ON_TIME = 10 * 60 * 1000; // 10 mins
|
||||||
|
|
||||||
private static final String DLG_TITLE = "DLG_TITLE";
|
private static final String DLG_TITLE = "DLG_TITLE";
|
||||||
|
@ -644,7 +639,8 @@ public class BoardDelegate extends DelegateBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onActivityResult( int requestCode, int resultCode, Intent data )
|
@Override
|
||||||
|
protected void onActivityResult( RequestCode requestCode, int resultCode, Intent data )
|
||||||
{
|
{
|
||||||
if ( Activity.RESULT_CANCELED != resultCode ) {
|
if ( Activity.RESULT_CANCELED != resultCode ) {
|
||||||
InviteMeans missingMeans = null;
|
InviteMeans missingMeans = null;
|
||||||
|
@ -1059,15 +1055,15 @@ public class BoardDelegate extends DelegateBase
|
||||||
break;
|
break;
|
||||||
case BLUETOOTH:
|
case BLUETOOTH:
|
||||||
BTInviteDelegate.launchForResult( m_activity, m_nMissing,
|
BTInviteDelegate.launchForResult( m_activity, m_nMissing,
|
||||||
BT_INVITE_RESULT );
|
RequestCode.BT_INVITE_RESULT );
|
||||||
break;
|
break;
|
||||||
case SMS:
|
case SMS:
|
||||||
SMSInviteDelegate.launchForResult( m_activity, m_nMissing,
|
SMSInviteDelegate.launchForResult( m_activity, m_nMissing,
|
||||||
SMS_INVITE_RESULT );
|
RequestCode.SMS_INVITE_RESULT );
|
||||||
break;
|
break;
|
||||||
case RELAY:
|
case RELAY:
|
||||||
RelayInviteDelegate.launchForResult( m_activity, m_nMissing,
|
RelayInviteDelegate.launchForResult( m_activity, m_nMissing,
|
||||||
RELAY_INVITE_RESULT );
|
RequestCode.RELAY_INVITE_RESULT );
|
||||||
break;
|
break;
|
||||||
case EMAIL:
|
case EMAIL:
|
||||||
case CLIPBOARD:
|
case CLIPBOARD:
|
||||||
|
@ -2310,7 +2306,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
if ( BuildConstants.CHAT_SUPPORTED ) {
|
if ( BuildConstants.CHAT_SUPPORTED ) {
|
||||||
Intent intent = new Intent( m_activity, ChatActivity.class );
|
Intent intent = new Intent( m_activity, ChatActivity.class );
|
||||||
intent.putExtra( GameUtils.INTENT_KEY_ROWID, m_rowid );
|
intent.putExtra( GameUtils.INTENT_KEY_ROWID, m_rowid );
|
||||||
startActivityForResult( intent, CHAT_REQUEST );
|
startActivityForResult( intent, RequestCode.CHAT_REQUEST );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class DelegateBase implements DlgClickNotify,
|
||||||
protected void onDestroy() {}
|
protected void onDestroy() {}
|
||||||
protected void onWindowFocusChanged( boolean hasFocus ) {}
|
protected void onWindowFocusChanged( boolean hasFocus ) {}
|
||||||
protected boolean onBackPressed() { return false; }
|
protected boolean onBackPressed() { return false; }
|
||||||
protected void onActivityResult( int requestCode, int resultCode,
|
protected void onActivityResult( RequestCode requestCode, int resultCode,
|
||||||
Intent data )
|
Intent data )
|
||||||
{
|
{
|
||||||
DbgUtils.logf( "DelegateBase.onActivityResult(): subclass responsibility!!!" );
|
DbgUtils.logf( "DelegateBase.onActivityResult(): subclass responsibility!!!" );
|
||||||
|
@ -179,9 +179,10 @@ public class DelegateBase implements DlgClickNotify,
|
||||||
return m_activity.getTitle().toString();
|
return m_activity.getTitle().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void startActivityForResult( Intent intent, int requestCode )
|
protected void startActivityForResult( Intent intent,
|
||||||
|
RequestCode requestCode )
|
||||||
{
|
{
|
||||||
m_activity.startActivityForResult( intent, requestCode );
|
m_activity.startActivityForResult( intent, requestCode.ordinal() );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setResult( int result, Intent intent )
|
protected void setResult( int result, Intent intent )
|
||||||
|
|
|
@ -984,7 +984,7 @@ public class DictsDelegate extends ListDelegateBase
|
||||||
// return mkDownloadIntent( context, dict_url );
|
// return mkDownloadIntent( context, dict_url );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void downloadForResult( Activity activity, int requestCode,
|
public static void downloadForResult( Activity activity, RequestCode requestCode,
|
||||||
int lang, String name )
|
int lang, String name )
|
||||||
{
|
{
|
||||||
Intent intent = new Intent( activity, DictsActivity.class );
|
Intent intent = new Intent( activity, DictsActivity.class );
|
||||||
|
@ -997,16 +997,16 @@ public class DictsDelegate extends ListDelegateBase
|
||||||
intent.putExtra( DICT_NAME_EXTRA, name );
|
intent.putExtra( DICT_NAME_EXTRA, name );
|
||||||
}
|
}
|
||||||
|
|
||||||
activity.startActivityForResult( intent, requestCode );
|
activity.startActivityForResult( intent, requestCode.ordinal() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void downloadForResult( Activity activity, int requestCode,
|
public static void downloadForResult( Activity activity, RequestCode requestCode,
|
||||||
int lang )
|
int lang )
|
||||||
{
|
{
|
||||||
downloadForResult( activity, requestCode, lang, null );
|
downloadForResult( activity, requestCode, lang, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void downloadForResult( Activity activity, int requestCode )
|
public static void downloadForResult( Activity activity, RequestCode requestCode )
|
||||||
{
|
{
|
||||||
downloadForResult( activity, requestCode, 0, null );
|
downloadForResult( activity, requestCode, 0, null );
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,8 +68,6 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
private static final String INTENT_FORRESULT_ROWID = "forresult";
|
private static final String INTENT_FORRESULT_ROWID = "forresult";
|
||||||
|
|
||||||
private static final String WHICH_PLAYER = "WHICH_PLAYER";
|
private static final String WHICH_PLAYER = "WHICH_PLAYER";
|
||||||
private static final int REQUEST_LANG = 1;
|
|
||||||
private static final int REQUEST_DICT = 2;
|
|
||||||
|
|
||||||
private Activity m_activity;
|
private Activity m_activity;
|
||||||
private CheckBox m_joinPublicCheck;
|
private CheckBox m_joinPublicCheck;
|
||||||
|
@ -518,7 +516,7 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult( int requestCode, int resultCode, Intent data )
|
protected void onActivityResult( RequestCode requestCode, int resultCode, Intent data )
|
||||||
{
|
{
|
||||||
if ( Activity.RESULT_CANCELED != resultCode ) {
|
if ( Activity.RESULT_CANCELED != resultCode ) {
|
||||||
loadGame();
|
loadGame();
|
||||||
|
@ -528,7 +526,7 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
configDictSpinner( m_dictSpinner, m_gi.dictLang, dictName );
|
configDictSpinner( m_dictSpinner, m_gi.dictLang, dictName );
|
||||||
configDictSpinner( m_playerDictSpinner, m_gi.dictLang, dictName );
|
configDictSpinner( m_playerDictSpinner, m_gi.dictLang, dictName );
|
||||||
break;
|
break;
|
||||||
case REQUEST_LANG:
|
case REQUEST_LANG_GC:
|
||||||
String langName = data.getStringExtra( DictsDelegate.RESULT_LAST_LANG );
|
String langName = data.getStringExtra( DictsDelegate.RESULT_LAST_LANG );
|
||||||
selLangChanged( langName );
|
selLangChanged( langName );
|
||||||
setLangSpinnerSelection( langName );
|
setLangSpinnerSelection( langName );
|
||||||
|
@ -852,7 +850,7 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
|
|
||||||
if ( chosen.equals( m_browseText ) ) {
|
if ( chosen.equals( m_browseText ) ) {
|
||||||
DictsDelegate.downloadForResult( m_activity,
|
DictsDelegate.downloadForResult( m_activity,
|
||||||
REQUEST_DICT,
|
RequestCode.REQUEST_DICT,
|
||||||
m_gi.dictLang );
|
m_gi.dictLang );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -885,7 +883,9 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
String chosen =
|
String chosen =
|
||||||
(String)parentView.getItemAtPosition( position );
|
(String)parentView.getItemAtPosition( position );
|
||||||
if ( chosen.equals( m_browseText ) ) {
|
if ( chosen.equals( m_browseText ) ) {
|
||||||
DictsDelegate.downloadForResult( m_activity, REQUEST_LANG );
|
DictsDelegate.downloadForResult( m_activity,
|
||||||
|
RequestCode
|
||||||
|
.REQUEST_LANG_GC );
|
||||||
} else {
|
} else {
|
||||||
String langName = adapter.getLangAtPosition( position );
|
String langName = adapter.getLangAtPosition( position );
|
||||||
selLangChanged( langName );
|
selLangChanged( langName );
|
||||||
|
@ -1196,14 +1196,14 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
return DeviceRole.SERVER_STANDALONE == m_giOrig.serverRole;
|
return DeviceRole.SERVER_STANDALONE == m_giOrig.serverRole;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void editForResult( Activity parent, int requestCode,
|
public static void editForResult( Activity parent, RequestCode requestCode,
|
||||||
long rowID )
|
long rowID )
|
||||||
{
|
{
|
||||||
Intent intent = new Intent( parent, GameConfigActivity.class );
|
Intent intent = new Intent( parent, GameConfigActivity.class );
|
||||||
intent.setAction( Intent.ACTION_EDIT );
|
intent.setAction( Intent.ACTION_EDIT );
|
||||||
intent.putExtra( GameUtils.INTENT_KEY_ROWID, rowID );
|
intent.putExtra( GameUtils.INTENT_KEY_ROWID, rowID );
|
||||||
intent.putExtra( INTENT_FORRESULT_ROWID, true );
|
intent.putExtra( INTENT_FORRESULT_ROWID, true );
|
||||||
parent.startActivityForResult( intent, requestCode );
|
parent.startActivityForResult( intent, requestCode.ordinal() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setConnLabel()
|
private void setConnLabel()
|
||||||
|
|
|
@ -82,9 +82,6 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
private static final String SAVE_DICTNAMES = "SAVE_DICTNAMES";
|
private static final String SAVE_DICTNAMES = "SAVE_DICTNAMES";
|
||||||
private static final String SAVE_NEXTSOLO = "SAVE_NEXTSOLO";
|
private static final String SAVE_NEXTSOLO = "SAVE_NEXTSOLO";
|
||||||
|
|
||||||
private static final int REQUEST_LANG = 1;
|
|
||||||
private static final int CONFIG_GAME = 2;
|
|
||||||
|
|
||||||
private static final String RELAYIDS_EXTRA = "relayids";
|
private static final String RELAYIDS_EXTRA = "relayids";
|
||||||
private static final String ROWID_EXTRA = "rowid";
|
private static final String ROWID_EXTRA = "rowid";
|
||||||
private static final String GAMEID_EXTRA = "gameid";
|
private static final String GAMEID_EXTRA = "gameid";
|
||||||
|
@ -620,7 +617,9 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
public void onClick( DialogInterface dlg, int item ) {
|
public void onClick( DialogInterface dlg, int item ) {
|
||||||
// no name, so user must pick
|
// no name, so user must pick
|
||||||
if ( null == m_missingDictName ) {
|
if ( null == m_missingDictName ) {
|
||||||
DictsDelegate.downloadForResult( m_activity, REQUEST_LANG,
|
DictsDelegate.downloadForResult( m_activity,
|
||||||
|
RequestCode
|
||||||
|
.REQUEST_LANG_GL,
|
||||||
m_missingDictLang );
|
m_missingDictLang );
|
||||||
} else {
|
} else {
|
||||||
DwnldDelegate
|
DwnldDelegate
|
||||||
|
@ -1279,12 +1278,12 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult( int requestCode, int resultCode,
|
protected void onActivityResult( RequestCode requestCode, int resultCode,
|
||||||
Intent data )
|
Intent data )
|
||||||
{
|
{
|
||||||
boolean cancelled = Activity.RESULT_CANCELED == resultCode;
|
boolean cancelled = Activity.RESULT_CANCELED == resultCode;
|
||||||
switch ( requestCode ) {
|
switch ( requestCode ) {
|
||||||
case REQUEST_LANG:
|
case REQUEST_LANG_GL:
|
||||||
if ( !cancelled ) {
|
if ( !cancelled ) {
|
||||||
DbgUtils.logf( "lang need met" );
|
DbgUtils.logf( "lang need met" );
|
||||||
if ( checkWarnNoDict( m_missingDictRowId ) ) {
|
if ( checkWarnNoDict( m_missingDictRowId ) ) {
|
||||||
|
@ -2442,7 +2441,8 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
|
|
||||||
if ( doConfigure ) {
|
if ( doConfigure ) {
|
||||||
// configure it
|
// configure it
|
||||||
GameConfigDelegate.editForResult( m_activity, CONFIG_GAME, rowID );
|
GameConfigDelegate.editForResult( m_activity, RequestCode
|
||||||
|
.CONFIG_GAME, rowID );
|
||||||
} else {
|
} else {
|
||||||
// launch it
|
// launch it
|
||||||
GameUtils.launchGame( m_activity, rowID );
|
GameUtils.launchGame( m_activity, rowID );
|
||||||
|
|
|
@ -69,11 +69,11 @@ public class RelayInviteDelegate extends InviteDelegate {
|
||||||
private Activity m_activity;
|
private Activity m_activity;
|
||||||
|
|
||||||
public static void launchForResult( Activity activity, int nMissing,
|
public static void launchForResult( Activity activity, int nMissing,
|
||||||
int requestCode )
|
RequestCode requestCode )
|
||||||
{
|
{
|
||||||
Intent intent = new Intent( activity, RelayInviteActivity.class );
|
Intent intent = new Intent( activity, RelayInviteActivity.class );
|
||||||
intent.putExtra( INTENT_KEY_NMISSING, nMissing );
|
intent.putExtra( INTENT_KEY_NMISSING, nMissing );
|
||||||
activity.startActivityForResult( intent, requestCode );
|
activity.startActivityForResult( intent, requestCode.ordinal() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public RelayInviteDelegate( Delegator delegator, Bundle savedInstanceState )
|
public RelayInviteDelegate( Delegator delegator, Bundle savedInstanceState )
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
/* -*- compile-command: "find-and-ant.sh debug install"; -*- */
|
||||||
|
/*
|
||||||
|
* Copyright 2015 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;
|
||||||
|
|
||||||
|
// Just make sure all calls to startActivityForResult are using unique codes.
|
||||||
|
|
||||||
|
public enum RequestCode {
|
||||||
|
__UNUSED,
|
||||||
|
|
||||||
|
// BoardDelegate
|
||||||
|
CHAT_REQUEST,
|
||||||
|
BT_INVITE_RESULT,
|
||||||
|
SMS_INVITE_RESULT,
|
||||||
|
RELAY_INVITE_RESULT,
|
||||||
|
|
||||||
|
// PermUtils
|
||||||
|
PERM_REQUEST,
|
||||||
|
|
||||||
|
// GameConfig
|
||||||
|
REQUEST_LANG_GC,
|
||||||
|
REQUEST_DICT,
|
||||||
|
|
||||||
|
// Games list
|
||||||
|
REQUEST_LANG_GL,
|
||||||
|
CONFIG_GAME,
|
||||||
|
|
||||||
|
// SMSInviteDelegate
|
||||||
|
GET_CONTACT,
|
||||||
|
}
|
||||||
|
|
|
@ -52,7 +52,6 @@ import org.eehouse.android.xw4.DlgDelegate.Action;
|
||||||
|
|
||||||
public class SMSInviteDelegate extends InviteDelegate {
|
public class SMSInviteDelegate extends InviteDelegate {
|
||||||
|
|
||||||
private static final int GET_CONTACT = 1;
|
|
||||||
private static final String SAVE_NAME = "SAVE_NAME";
|
private static final String SAVE_NAME = "SAVE_NAME";
|
||||||
private static final String SAVE_NUMBER = "SAVE_NUMBER";
|
private static final String SAVE_NUMBER = "SAVE_NUMBER";
|
||||||
|
|
||||||
|
@ -65,11 +64,11 @@ public class SMSInviteDelegate extends InviteDelegate {
|
||||||
private Activity m_activity;
|
private Activity m_activity;
|
||||||
|
|
||||||
public static void launchForResult( Activity activity, int nMissing,
|
public static void launchForResult( Activity activity, int nMissing,
|
||||||
int requestCode )
|
RequestCode requestCode )
|
||||||
{
|
{
|
||||||
Intent intent = new Intent( activity, SMSInviteActivity.class );
|
Intent intent = new Intent( activity, SMSInviteActivity.class );
|
||||||
intent.putExtra( INTENT_KEY_NMISSING, nMissing );
|
intent.putExtra( INTENT_KEY_NMISSING, nMissing );
|
||||||
activity.startActivityForResult( intent, requestCode );
|
activity.startActivityForResult( intent, requestCode.ordinal() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public SMSInviteDelegate( Delegator delegator, Bundle savedInstanceState )
|
public SMSInviteDelegate( Delegator delegator, Bundle savedInstanceState )
|
||||||
|
@ -114,7 +113,8 @@ public class SMSInviteDelegate extends InviteDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onActivityResult( int requestCode, int resultCode,
|
@Override
|
||||||
|
protected void onActivityResult( RequestCode requestCode, int resultCode,
|
||||||
Intent data )
|
Intent data )
|
||||||
{
|
{
|
||||||
// super.onActivityResult( requestCode, resultCode, data );
|
// super.onActivityResult( requestCode, resultCode, data );
|
||||||
|
@ -167,7 +167,7 @@ public class SMSInviteDelegate extends InviteDelegate {
|
||||||
Intent intent = new Intent( Intent.ACTION_PICK,
|
Intent intent = new Intent( Intent.ACTION_PICK,
|
||||||
ContactsContract.Contacts.CONTENT_URI );
|
ContactsContract.Contacts.CONTENT_URI );
|
||||||
intent.setType( Phone.CONTENT_TYPE );
|
intent.setType( Phone.CONTENT_TYPE );
|
||||||
startActivityForResult( intent, GET_CONTACT );
|
startActivityForResult( intent, RequestCode.GET_CONTACT );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void clearSelected()
|
protected void clearSelected()
|
||||||
|
|
|
@ -180,7 +180,8 @@ public class XWActivity extends Activity implements Delegator {
|
||||||
protected void onActivityResult( int requestCode, int resultCode,
|
protected void onActivityResult( int requestCode, int resultCode,
|
||||||
Intent data )
|
Intent data )
|
||||||
{
|
{
|
||||||
m_dlgt.onActivityResult( requestCode, resultCode, data );
|
RequestCode rc = RequestCode.values()[requestCode];
|
||||||
|
m_dlgt.onActivityResult( rc, resultCode, data );
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Reference in a new issue