use an enum for startActivityForResult requestCode to ensure they're

unique across the app.
This commit is contained in:
Eric House 2015-12-09 06:10:09 -08:00
parent 2a3bd60740
commit 87c6b3e0fe
10 changed files with 87 additions and 42 deletions

View file

@ -54,12 +54,12 @@ public class BTInviteDelegate extends InviteDelegate {
private BTDevsAdapter m_adapter;
public static void launchForResult( Activity activity, int nMissing,
int requestCode )
RequestCode requestCode )
{
Assert.assertTrue( 0 < nMissing ); // don't call if nMissing == 0
Intent intent = new Intent( activity, BTInviteActivity.class );
intent.putExtra( INTENT_KEY_NMISSING, nMissing );
activity.startActivityForResult( intent, requestCode );
activity.startActivityForResult( intent, requestCode.ordinal() );
}
protected BTInviteDelegate( Delegator delegator, Bundle savedInstanceState )

View file

@ -69,11 +69,6 @@ public class BoardDelegate extends DelegateBase
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 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 ) {
InviteMeans missingMeans = null;
@ -1059,15 +1055,15 @@ public class BoardDelegate extends DelegateBase
break;
case BLUETOOTH:
BTInviteDelegate.launchForResult( m_activity, m_nMissing,
BT_INVITE_RESULT );
RequestCode.BT_INVITE_RESULT );
break;
case SMS:
SMSInviteDelegate.launchForResult( m_activity, m_nMissing,
SMS_INVITE_RESULT );
RequestCode.SMS_INVITE_RESULT );
break;
case RELAY:
RelayInviteDelegate.launchForResult( m_activity, m_nMissing,
RELAY_INVITE_RESULT );
RequestCode.RELAY_INVITE_RESULT );
break;
case EMAIL:
case CLIPBOARD:
@ -2310,7 +2306,7 @@ public class BoardDelegate extends DelegateBase
if ( BuildConstants.CHAT_SUPPORTED ) {
Intent intent = new Intent( m_activity, ChatActivity.class );
intent.putExtra( GameUtils.INTENT_KEY_ROWID, m_rowid );
startActivityForResult( intent, CHAT_REQUEST );
startActivityForResult( intent, RequestCode.CHAT_REQUEST );
}
}

View file

@ -86,7 +86,7 @@ public class DelegateBase implements DlgClickNotify,
protected void onDestroy() {}
protected void onWindowFocusChanged( boolean hasFocus ) {}
protected boolean onBackPressed() { return false; }
protected void onActivityResult( int requestCode, int resultCode,
protected void onActivityResult( RequestCode requestCode, int resultCode,
Intent data )
{
DbgUtils.logf( "DelegateBase.onActivityResult(): subclass responsibility!!!" );
@ -179,9 +179,10 @@ public class DelegateBase implements DlgClickNotify,
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 )

View file

@ -984,7 +984,7 @@ public class DictsDelegate extends ListDelegateBase
// 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 )
{
Intent intent = new Intent( activity, DictsActivity.class );
@ -997,16 +997,16 @@ public class DictsDelegate extends ListDelegateBase
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 )
{
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 );
}

View file

@ -68,8 +68,6 @@ public class GameConfigDelegate extends DelegateBase
private static final String INTENT_FORRESULT_ROWID = "forresult";
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 CheckBox m_joinPublicCheck;
@ -518,7 +516,7 @@ public class GameConfigDelegate extends DelegateBase
}
@Override
protected void onActivityResult( int requestCode, int resultCode, Intent data )
protected void onActivityResult( RequestCode requestCode, int resultCode, Intent data )
{
if ( Activity.RESULT_CANCELED != resultCode ) {
loadGame();
@ -528,7 +526,7 @@ public class GameConfigDelegate extends DelegateBase
configDictSpinner( m_dictSpinner, m_gi.dictLang, dictName );
configDictSpinner( m_playerDictSpinner, m_gi.dictLang, dictName );
break;
case REQUEST_LANG:
case REQUEST_LANG_GC:
String langName = data.getStringExtra( DictsDelegate.RESULT_LAST_LANG );
selLangChanged( langName );
setLangSpinnerSelection( langName );
@ -852,7 +850,7 @@ public class GameConfigDelegate extends DelegateBase
if ( chosen.equals( m_browseText ) ) {
DictsDelegate.downloadForResult( m_activity,
REQUEST_DICT,
RequestCode.REQUEST_DICT,
m_gi.dictLang );
}
}
@ -885,7 +883,9 @@ public class GameConfigDelegate extends DelegateBase
String chosen =
(String)parentView.getItemAtPosition( position );
if ( chosen.equals( m_browseText ) ) {
DictsDelegate.downloadForResult( m_activity, REQUEST_LANG );
DictsDelegate.downloadForResult( m_activity,
RequestCode
.REQUEST_LANG_GC );
} else {
String langName = adapter.getLangAtPosition( position );
selLangChanged( langName );
@ -1196,14 +1196,14 @@ public class GameConfigDelegate extends DelegateBase
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 )
{
Intent intent = new Intent( parent, GameConfigActivity.class );
intent.setAction( Intent.ACTION_EDIT );
intent.putExtra( GameUtils.INTENT_KEY_ROWID, rowID );
intent.putExtra( INTENT_FORRESULT_ROWID, true );
parent.startActivityForResult( intent, requestCode );
parent.startActivityForResult( intent, requestCode.ordinal() );
}
private void setConnLabel()

View file

@ -82,9 +82,6 @@ public class GamesListDelegate extends ListDelegateBase
private static final String SAVE_DICTNAMES = "SAVE_DICTNAMES";
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 ROWID_EXTRA = "rowid";
private static final String GAMEID_EXTRA = "gameid";
@ -620,7 +617,9 @@ public class GamesListDelegate extends ListDelegateBase
public void onClick( DialogInterface dlg, int item ) {
// no name, so user must pick
if ( null == m_missingDictName ) {
DictsDelegate.downloadForResult( m_activity, REQUEST_LANG,
DictsDelegate.downloadForResult( m_activity,
RequestCode
.REQUEST_LANG_GL,
m_missingDictLang );
} else {
DwnldDelegate
@ -1279,12 +1278,12 @@ public class GamesListDelegate extends ListDelegateBase
}
@Override
protected void onActivityResult( int requestCode, int resultCode,
protected void onActivityResult( RequestCode requestCode, int resultCode,
Intent data )
{
boolean cancelled = Activity.RESULT_CANCELED == resultCode;
switch ( requestCode ) {
case REQUEST_LANG:
case REQUEST_LANG_GL:
if ( !cancelled ) {
DbgUtils.logf( "lang need met" );
if ( checkWarnNoDict( m_missingDictRowId ) ) {
@ -2442,7 +2441,8 @@ public class GamesListDelegate extends ListDelegateBase
if ( doConfigure ) {
// configure it
GameConfigDelegate.editForResult( m_activity, CONFIG_GAME, rowID );
GameConfigDelegate.editForResult( m_activity, RequestCode
.CONFIG_GAME, rowID );
} else {
// launch it
GameUtils.launchGame( m_activity, rowID );

View file

@ -69,11 +69,11 @@ public class RelayInviteDelegate extends InviteDelegate {
private Activity m_activity;
public static void launchForResult( Activity activity, int nMissing,
int requestCode )
RequestCode requestCode )
{
Intent intent = new Intent( activity, RelayInviteActivity.class );
intent.putExtra( INTENT_KEY_NMISSING, nMissing );
activity.startActivityForResult( intent, requestCode );
activity.startActivityForResult( intent, requestCode.ordinal() );
}
public RelayInviteDelegate( Delegator delegator, Bundle savedInstanceState )

View file

@ -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,
}

View file

@ -52,7 +52,6 @@ import org.eehouse.android.xw4.DlgDelegate.Action;
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_NUMBER = "SAVE_NUMBER";
@ -65,11 +64,11 @@ public class SMSInviteDelegate extends InviteDelegate {
private Activity m_activity;
public static void launchForResult( Activity activity, int nMissing,
int requestCode )
RequestCode requestCode )
{
Intent intent = new Intent( activity, SMSInviteActivity.class );
intent.putExtra( INTENT_KEY_NMISSING, nMissing );
activity.startActivityForResult( intent, requestCode );
activity.startActivityForResult( intent, requestCode.ordinal() );
}
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 )
{
// super.onActivityResult( requestCode, resultCode, data );
@ -167,7 +167,7 @@ public class SMSInviteDelegate extends InviteDelegate {
Intent intent = new Intent( Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI );
intent.setType( Phone.CONTENT_TYPE );
startActivityForResult( intent, GET_CONTACT );
startActivityForResult( intent, RequestCode.GET_CONTACT );
}
protected void clearSelected()

View file

@ -180,7 +180,8 @@ public class XWActivity extends Activity implements Delegator {
protected void onActivityResult( int requestCode, int resultCode,
Intent data )
{
m_dlgt.onActivityResult( requestCode, resultCode, data );
RequestCode rc = RequestCode.values()[requestCode];
m_dlgt.onActivityResult( rc, resultCode, data );
}
//////////////////////////////////////////////////////////////////////