mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-25 07:58:33 +01:00
pass layout and menu into delegate constructor so it can handle
inflation for fragments and activitites.
This commit is contained in:
parent
f4f486403e
commit
ff5df01b28
25 changed files with 81 additions and 84 deletions
|
@ -57,14 +57,13 @@ public class BTInviteDelegate extends InviteDelegate
|
|||
|
||||
protected BTInviteDelegate( ListDelegator delegator, Bundle savedInstanceState )
|
||||
{
|
||||
super( delegator, savedInstanceState );
|
||||
super( delegator, savedInstanceState, R.layout.btinviter );
|
||||
m_activity = delegator.getActivity();
|
||||
}
|
||||
|
||||
protected void init()
|
||||
{
|
||||
super.init( R.layout.btinviter,
|
||||
R.id.button_invite, R.id.button_rescan,
|
||||
super.init( R.id.button_invite, R.id.button_rescan,
|
||||
R.id.button_clear, R.id.invite_desc,
|
||||
R.string.invite_bt_desc_fmt );
|
||||
m_firstScan = true;
|
||||
|
|
|
@ -495,7 +495,7 @@ public class BoardDelegate extends DelegateBase
|
|||
|
||||
public BoardDelegate( Delegator delegator, Bundle savedInstanceState )
|
||||
{
|
||||
super( delegator, savedInstanceState, R.menu.board_menu );
|
||||
super( delegator, savedInstanceState, R.layout.board, R.menu.board_menu );
|
||||
m_activity = delegator.getActivity();
|
||||
m_delegator = delegator;
|
||||
}
|
||||
|
@ -515,9 +515,6 @@ public class BoardDelegate extends DelegateBase
|
|||
|
||||
m_utils = new BoardUtilCtxt();
|
||||
m_jniu = JNIUtilsImpl.get( m_activity );
|
||||
if ( null == getContentView() ) {
|
||||
setContentView( R.layout.board );
|
||||
}
|
||||
m_timers = new TimerRunnable[4]; // needs to be in sync with
|
||||
// XWTimerReason
|
||||
m_view = (BoardView)findViewById( R.id.board_view );
|
||||
|
|
|
@ -40,7 +40,7 @@ public class ChatDelegate extends DelegateBase
|
|||
|
||||
public ChatDelegate( Delegator delegator, Bundle savedInstanceState )
|
||||
{
|
||||
super( delegator, savedInstanceState, R.menu.chat_menu );
|
||||
super( delegator, savedInstanceState, R.layout.chat, R.menu.chat_menu );
|
||||
m_activity = delegator.getActivity();
|
||||
}
|
||||
|
||||
|
@ -48,9 +48,6 @@ public class ChatDelegate extends DelegateBase
|
|||
protected void init( Bundle savedInstanceState )
|
||||
{
|
||||
if ( BuildConstants.CHAT_SUPPORTED ) {
|
||||
|
||||
setContentView( R.layout.chat );
|
||||
|
||||
m_rowid = getIntent().getLongExtra( GameUtils.INTENT_KEY_ROWID, -1 );
|
||||
|
||||
DBUtils.HistoryPair[] pairs = DBUtils.getChatHistory( m_activity, m_rowid );
|
||||
|
|
|
@ -19,16 +19,18 @@
|
|||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.view.MenuInflater;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface.OnCancelListener;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.eehouse.android.xw4.DlgDelegate.Action;
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
@ -43,20 +45,23 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify,
|
|||
private Delegator m_delegator;
|
||||
private Activity m_activity;
|
||||
private int m_optionsMenuID;
|
||||
private int m_layoutID;
|
||||
private View m_rootView;
|
||||
|
||||
public DelegateBase( Delegator delegator, Bundle bundle )
|
||||
public DelegateBase( Delegator delegator, Bundle bundle, int layoutID )
|
||||
{
|
||||
this( delegator, bundle, R.menu.empty );
|
||||
this( delegator, bundle, layoutID, R.menu.empty );
|
||||
}
|
||||
|
||||
public DelegateBase( Delegator delegator, Bundle bundle, int optionsMenu )
|
||||
public DelegateBase( Delegator delegator, Bundle bundle,
|
||||
int layoutID, int menuID )
|
||||
{
|
||||
Assert.assertTrue( 0 < optionsMenu );
|
||||
Assert.assertTrue( 0 < menuID );
|
||||
m_delegator = delegator;
|
||||
m_activity = delegator.getActivity();
|
||||
m_delegate = new DlgDelegate( m_activity, this, bundle );
|
||||
m_optionsMenuID = optionsMenu;
|
||||
m_layoutID = layoutID;
|
||||
m_optionsMenuID = menuID;
|
||||
LocUtils.xlateTitle( m_activity );
|
||||
}
|
||||
|
||||
|
@ -75,6 +80,17 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify,
|
|||
protected void prepareDialog( DlgID dlgID, Dialog dialog ) {}
|
||||
protected void onActivityResult( int requestCode, int resultCode,
|
||||
Intent data ) {}
|
||||
// Fragments only
|
||||
protected View inflateView( LayoutInflater inflater, ViewGroup container )
|
||||
{
|
||||
View view = null;
|
||||
int layoutID = getLayoutID();
|
||||
if ( 0 < layoutID ) {
|
||||
view = inflater.inflate( layoutID, container, false );
|
||||
setContentView( view );
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
public boolean onCreateOptionsMenu( Menu menu, MenuInflater inflater )
|
||||
{
|
||||
|
@ -100,6 +116,11 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify,
|
|||
return m_activity.getIntent();
|
||||
}
|
||||
|
||||
protected int getLayoutID()
|
||||
{
|
||||
return m_layoutID;
|
||||
}
|
||||
|
||||
protected Bundle getArguments()
|
||||
{
|
||||
return m_delegator.getArguments();
|
||||
|
|
|
@ -158,7 +158,7 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
|
||||
protected DictBrowseDelegate( ListDelegator delegator, Bundle savedInstanceState )
|
||||
{
|
||||
super( delegator, savedInstanceState );
|
||||
super( delegator, savedInstanceState, R.layout.dict_browser );
|
||||
m_activity = delegator.getActivity();
|
||||
}
|
||||
|
||||
|
@ -206,8 +206,6 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
m_browseState.m_maxShown = m_maxAvail;
|
||||
}
|
||||
|
||||
setContentView( R.layout.dict_browser );
|
||||
|
||||
Button button = (Button)findViewById( R.id.search_button );
|
||||
button.setOnClickListener( new View.OnClickListener() {
|
||||
public void onClick( View view )
|
||||
|
|
|
@ -299,7 +299,8 @@ public class DictsDelegate extends ListDelegateBase
|
|||
|
||||
protected DictsDelegate( ListDelegator delegator, Bundle savedInstanceState )
|
||||
{
|
||||
super( delegator, savedInstanceState, R.menu.dicts_menu );
|
||||
super( delegator, savedInstanceState, R.layout.dict_browse,
|
||||
R.menu.dicts_menu );
|
||||
m_activity = delegator.getActivity();
|
||||
}
|
||||
|
||||
|
@ -448,7 +449,6 @@ public class DictsDelegate extends ListDelegateBase
|
|||
m_locNames = getStringArray( R.array.loc_names );
|
||||
m_noteNone = getString( R.string.note_none );
|
||||
|
||||
setContentView( R.layout.dict_browse );
|
||||
m_listView = getListView();
|
||||
m_listView.setOnItemLongClickListener( this );
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
|
||||
public DwnldDelegate( ListDelegator delegator, Bundle savedInstanceState )
|
||||
{
|
||||
super( delegator, savedInstanceState );
|
||||
super( delegator, savedInstanceState, R.layout.import_dict );
|
||||
m_activity = delegator.getActivity();
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,6 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
LinearLayout item = null;
|
||||
|
||||
requestWindowFeature( Window.FEATURE_LEFT_ICON );
|
||||
setContentView( R.layout.import_dict );
|
||||
m_activity.getWindow().setFeatureDrawableResource( Window.FEATURE_LEFT_ICON,
|
||||
R.drawable.icon48x48 );
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
|
||||
public GameConfigDelegate( Delegator delegator, Bundle savedInstanceState )
|
||||
{
|
||||
super( delegator, savedInstanceState );
|
||||
super( delegator, savedInstanceState, R.layout.game_config );
|
||||
m_activity = delegator.getActivity();
|
||||
}
|
||||
|
||||
|
@ -408,8 +408,6 @@ public class GameConfigDelegate extends DelegateBase
|
|||
m_forResult = intent.getBooleanExtra( GameUtils.INTENT_FORRESULT_ROWID,
|
||||
false );
|
||||
|
||||
setContentView( R.layout.game_config );
|
||||
|
||||
m_connectSetRelay = findViewById(R.id.connect_set_relay);
|
||||
m_connectSetSMS = findViewById(R.id.connect_set_sms);
|
||||
if ( !XWApp.SMSSUPPORTED ) {
|
||||
|
|
|
@ -525,7 +525,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
|
||||
public GamesListDelegate( GamesListDelegator delegator, Bundle sis )
|
||||
{
|
||||
super( delegator, sis, R.menu.games_list_menu );
|
||||
super( delegator, sis, R.layout.game_list, R.menu.games_list_menu );
|
||||
m_delegator = delegator;
|
||||
m_activity = delegator.getActivity();
|
||||
m_launchedGames = new HashSet<Long>();
|
||||
|
@ -761,8 +761,6 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
m_selGroupIDs = new HashSet<Long>();
|
||||
getBundledData( savedInstanceState );
|
||||
|
||||
// setContentView( R.layout.game_list );
|
||||
// ListView listview = getListView();
|
||||
DBUtils.setDBChangeListener( this );
|
||||
|
||||
boolean isUpgrade = Utils.firstBootThisVersion( m_activity );
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.Window;
|
||||
|
||||
|
|
|
@ -44,17 +44,16 @@ abstract class InviteDelegate extends ListDelegateBase
|
|||
protected Button m_clearButton;
|
||||
private Activity m_activity;
|
||||
|
||||
public InviteDelegate( ListDelegator delegator, Bundle savedInstanceState )
|
||||
public InviteDelegate( ListDelegator delegator, Bundle savedInstanceState,
|
||||
int layoutID )
|
||||
{
|
||||
super( delegator, savedInstanceState );
|
||||
super( delegator, savedInstanceState, layoutID, R.menu.empty );
|
||||
m_activity = delegator.getActivity();
|
||||
}
|
||||
|
||||
protected void init( int view_id, int button_invite, int button_rescan,
|
||||
protected void init( int button_invite, int button_rescan,
|
||||
int button_clear, int desc_id, int desc_strf )
|
||||
{
|
||||
setContentView( view_id );
|
||||
|
||||
Intent intent = getIntent();
|
||||
m_nMissing = intent.getIntExtra( INTENT_KEY_NMISSING, -1 );
|
||||
|
||||
|
|
|
@ -31,16 +31,15 @@ public class ListDelegateBase extends DelegateBase {
|
|||
private ListDelegator m_delegator;
|
||||
|
||||
protected ListDelegateBase( ListDelegator delegator, Bundle savedInstanceState,
|
||||
int menuID )
|
||||
int layoutID )
|
||||
{
|
||||
super( delegator, savedInstanceState, menuID );
|
||||
m_delegator = delegator;
|
||||
m_activity = delegator.getActivity();
|
||||
this( delegator, savedInstanceState, layoutID, R.menu.empty );
|
||||
}
|
||||
|
||||
protected ListDelegateBase( ListDelegator delegator, Bundle savedState )
|
||||
protected ListDelegateBase( ListDelegator delegator, Bundle savedInstanceState,
|
||||
int layoutID, int menuID )
|
||||
{
|
||||
super( delegator, savedState );
|
||||
super( delegator, savedInstanceState, layoutID, menuID );
|
||||
m_delegator = delegator;
|
||||
m_activity = delegator.getActivity();
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public class NewGameDelegate extends DelegateBase {
|
|||
|
||||
protected NewGameDelegate( Delegator delegator, Bundle savedInstanceState )
|
||||
{
|
||||
super( delegator, savedInstanceState );
|
||||
super( delegator, savedInstanceState, R.layout.new_game );
|
||||
m_activity = delegator.getActivity();
|
||||
}
|
||||
|
||||
|
@ -80,8 +80,6 @@ public class NewGameDelegate extends DelegateBase {
|
|||
|
||||
m_groupID = getIntent().getLongExtra( GROUPID_EXTRA, -1 );
|
||||
|
||||
setContentView( R.layout.new_game );
|
||||
|
||||
TextView desc = (TextView)findViewById( R.id.newgame_local_desc );
|
||||
m_dict = CommonPrefs.getDefaultHumanDict( m_activity );
|
||||
String lang = DictLangCache.getLangName( m_activity, m_dict );
|
||||
|
|
|
@ -43,6 +43,12 @@ public class PrefsActivity extends PreferenceActivity implements Delegator {
|
|||
{
|
||||
super.onCreate( savedInstanceState );
|
||||
m_dlgt = new PrefsDelegate( this, this, savedInstanceState );
|
||||
|
||||
int layoutID = m_dlgt.getLayoutID();
|
||||
if ( 0 < layoutID ) {
|
||||
m_dlgt.setContentView( layoutID );
|
||||
}
|
||||
|
||||
m_dlgt.init( savedInstanceState );
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public class PrefsDelegate extends DelegateBase
|
|||
public PrefsDelegate( PreferenceActivity activity, Delegator delegator,
|
||||
Bundle savedInstanceState )
|
||||
{
|
||||
super( delegator, savedInstanceState, R.menu.board_menu );
|
||||
super( delegator, savedInstanceState, R.layout.prefs_w_buttons );
|
||||
m_activity = activity;
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,6 @@ public class PrefsDelegate extends DelegateBase
|
|||
{
|
||||
// Load the preferences from an XML resource
|
||||
m_activity.addPreferencesFromResource( R.xml.xwprefs );
|
||||
setContentView( R.layout.prefs_w_buttons );
|
||||
|
||||
m_keyLogging = getString( R.string.key_logging_on );
|
||||
m_smsToasting = getString( R.string.key_show_sms );
|
||||
|
|
|
@ -49,14 +49,12 @@ public class RelayGameDelegate extends DelegateBase
|
|||
|
||||
protected RelayGameDelegate( Delegator delegator, Bundle savedInstanceState )
|
||||
{
|
||||
super( delegator, savedInstanceState );
|
||||
super( delegator, savedInstanceState, R.layout.relay_game_config );
|
||||
m_activity = delegator.getActivity();
|
||||
}
|
||||
|
||||
protected void init( Bundle savedInstanceState )
|
||||
{
|
||||
setContentView( R.layout.relay_game_config );
|
||||
|
||||
m_rowid = getIntent().getLongExtra( GameUtils.INTENT_KEY_ROWID, -1 );
|
||||
|
||||
m_playButton = (Button)findViewById( R.id.play_button );
|
||||
|
|
|
@ -67,14 +67,13 @@ public class SMSInviteDelegate extends InviteDelegate {
|
|||
|
||||
public SMSInviteDelegate( ListDelegator delegator, Bundle savedInstanceState )
|
||||
{
|
||||
super( delegator, savedInstanceState );
|
||||
super( delegator, savedInstanceState, R.layout.smsinviter );
|
||||
m_activity = delegator.getActivity();
|
||||
}
|
||||
|
||||
protected void init( Bundle savedInstanceState )
|
||||
{
|
||||
super.init( R.layout.smsinviter,
|
||||
R.id.button_invite, R.id.button_add,
|
||||
super.init( R.id.button_invite, R.id.button_add,
|
||||
R.id.button_clear, R.id.invite_desc,
|
||||
R.string.invite_sms_desc_fmt );
|
||||
getBundledData( savedInstanceState );
|
||||
|
|
|
@ -70,16 +70,13 @@ public class StudyListDelegate extends ListDelegateBase
|
|||
|
||||
protected StudyListDelegate( ListDelegator delegator, Bundle savedInstanceState )
|
||||
{
|
||||
super( delegator, savedInstanceState, R.menu.studylist );
|
||||
super( delegator, savedInstanceState, R.layout.studylist, R.menu.studylist );
|
||||
m_activity = delegator.getActivity();
|
||||
}
|
||||
|
||||
protected void init( Bundle savedInstanceState )
|
||||
{
|
||||
DbgUtils.logf( "%s.init() called", getClass().getName() );
|
||||
if ( null == getContentView() ) {
|
||||
setContentView( R.layout.studylist );
|
||||
}
|
||||
m_list = (ListView)findViewById( android.R.id.list );
|
||||
|
||||
m_spinner = (Spinner)findViewById( R.id.pick_lang_spinner );
|
||||
|
|
|
@ -32,7 +32,7 @@ public class StudyListFrag extends XWListFragment implements ListDelegator {
|
|||
{
|
||||
DbgUtils.logf( "StudyListFrag.onCreate()" );
|
||||
m_dlgt = new StudyListDelegate( this, savedInstanceState );
|
||||
super.onCreate( m_dlgt, savedInstanceState, R.layout.studylist );
|
||||
super.onCreate( m_dlgt, savedInstanceState );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,6 +34,12 @@ public class XWActivity extends Activity implements Delegator {
|
|||
{
|
||||
super.onCreate( savedInstanceState );
|
||||
m_dlgt = dlgt;
|
||||
|
||||
int layoutID = m_dlgt.getLayoutID();
|
||||
if ( 0 < layoutID ) {
|
||||
m_dlgt.setContentView( layoutID );
|
||||
}
|
||||
|
||||
dlgt.init( savedInstanceState );
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,12 @@ public class XWListActivity extends ListActivity implements ListDelegator {
|
|||
{
|
||||
super.onCreate( savedInstanceState );
|
||||
m_dlgt = dlgt;
|
||||
|
||||
int layoutID = m_dlgt.getLayoutID();
|
||||
if ( 0 < layoutID ) {
|
||||
m_dlgt.setContentView( layoutID );
|
||||
}
|
||||
|
||||
dlgt.init( savedInstanceState );
|
||||
}
|
||||
|
||||
|
|
|
@ -36,13 +36,6 @@ import org.eehouse.android.xw4.loc.LocUtils;
|
|||
public class XWListFragment extends ListFragment {
|
||||
|
||||
private ListDelegateBase m_dlgt;
|
||||
private int m_layoutID = -1;
|
||||
|
||||
protected void onCreate( ListDelegateBase dlgt, Bundle sis, int layoutID )
|
||||
{
|
||||
onCreate( dlgt, sis );
|
||||
m_layoutID = layoutID;
|
||||
}
|
||||
|
||||
public void onCreate( ListDelegateBase dlgt, Bundle savedInstanceState )
|
||||
{
|
||||
|
@ -55,16 +48,9 @@ public class XWListFragment extends ListFragment {
|
|||
Bundle savedInstanceState )
|
||||
{
|
||||
DbgUtils.logf( "%s.onCreateView() called", this.getClass().getName() );
|
||||
View view = null;
|
||||
if ( 0 < m_layoutID ) {
|
||||
view = inflater.inflate( m_layoutID, container, false );
|
||||
m_dlgt.setContentView( view );
|
||||
// LocUtils.xlateView( getActivity(), view );
|
||||
}
|
||||
return view;
|
||||
return m_dlgt.inflateView( inflater, container );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated( Bundle savedInstanceState )
|
||||
{
|
||||
DbgUtils.logf( "%s.onActivityCreated() called", this.getClass().getName() );
|
||||
|
|
|
@ -35,9 +35,9 @@ public class LocActivity extends XWListActivity {
|
|||
super.onCreate( savedInstanceState, m_dlgt );
|
||||
} // onCreate
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu( Menu menu )
|
||||
{
|
||||
return m_dlgt.onCreateOptionsMenu( menu );
|
||||
}
|
||||
// @Override
|
||||
// public boolean onCreateOptionsMenu( Menu menu )
|
||||
// {
|
||||
// return m_dlgt.onCreateOptionsMenu( menu );
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -53,9 +53,8 @@ public class LocDelegate extends ListDelegateBase
|
|||
|
||||
protected LocDelegate( ListDelegator delegator, Bundle savedInstanceState )
|
||||
{
|
||||
super( delegator, savedInstanceState );
|
||||
super( delegator, savedInstanceState, R.layout.loc_main );
|
||||
m_activity = delegator.getActivity();
|
||||
init( savedInstanceState );
|
||||
}
|
||||
|
||||
protected boolean onBackPressed()
|
||||
|
@ -98,8 +97,6 @@ public class LocDelegate extends ListDelegateBase
|
|||
|
||||
protected void init( Bundle savedInstanceState )
|
||||
{
|
||||
setContentView( R.layout.loc_main );
|
||||
|
||||
m_searchButton = (ImageButton)findViewById( R.id.loc_search_button );
|
||||
m_searchButton.setOnClickListener( this );
|
||||
|
||||
|
|
|
@ -56,13 +56,14 @@ public class LocItemEditDelegate extends DelegateBase implements TextWatcher {
|
|||
|
||||
protected LocItemEditDelegate( Delegator delegator, Bundle savedInstanceState )
|
||||
{
|
||||
super( delegator, savedInstanceState, R.menu.loc_item_menu );
|
||||
super( delegator, savedInstanceState, R.layout.loc_item_edit,
|
||||
R.menu.loc_item_menu );
|
||||
m_activity = delegator.getActivity();
|
||||
}
|
||||
|
||||
protected void init( Bundle savedInstanceState )
|
||||
{
|
||||
setContentView( R.layout.loc_item_edit );
|
||||
// setContentView( R.layout.loc_item_edit );
|
||||
|
||||
String key = getIntent().getStringExtra( KEY );
|
||||
m_key = key;
|
||||
|
|
Loading…
Add table
Reference in a new issue