add menuitem to main games list view that brings up view of all

installed dicts.  Currently allows to delete them.  Later should allow
invoking a browser like DawgShow.
This commit is contained in:
eehouse 2010-03-14 05:01:55 +00:00
parent 626a7e4a32
commit 7fadce15ef
9 changed files with 157 additions and 18 deletions

View file

@ -50,6 +50,11 @@
<data android:mimeType="vnd.android.cursor.item/vnd.eehouse.org.game" />
</intent-filter>
</activity>
<activity android:name="DictsActivity"
android:label="@string/title_dicts_list"
>
</activity>
<activity android:name="GameConfig"
android:theme="@android:style/Theme.Light"

View file

@ -7,9 +7,16 @@
android:paddingLeft="8dp"
android:paddingRight="8dp">
<WebView android:id="@+id/dict_web_view"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
/>
<ListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
<Button android:id="@+id/download"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/download_dicts"
/>
</LinearLayout>

View file

@ -1,7 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/dicts_item_delete"
android:title="@string/dicts_item_delete"
/>
<item android:id="@+id/dicts_item_details"
android:title="@string/dicts_item_details"
/>
</menu>

View file

@ -10,6 +10,9 @@
<item android:id="@+id/gamel_menu_prefs"
android:title="@string/gamel_menu_prefs"
/>
<item android:id="@+id/gamel_menu_dicts"
android:title="@string/gamel_menu_dicts"
/>
<item android:id="@+id/gamel_menu_about"
android:title="@string/board_menu_file_about"
android:alphabeticShortcut="A"

View file

@ -41,6 +41,7 @@
<string name="title_create">Create game</string>
<string name="title_edit">Edit game</string>
<string name="title_games_list">Crosswords</string>
<string name="title_dicts_list">Crosswords dictionaries</string>
<string name="title_game">Game</string>
<string name="title_edit_title">Game name:</string>
@ -151,6 +152,8 @@
<string name="list_item_up">Up one</string>
<string name="list_item_down">Down one</string>
<string name="dicts_item_delete">Delete dictionary</string>
<string name="dicts_item_details">Details</string>
<string name="dict_label">Dictionary</string>
<string name="role_label">Role</string>
@ -187,6 +190,7 @@
<string name="phonies_warn">Warn</string>
<string name="phonies_disallow">Disallow</string>
<string name="gamel_menu_prefs">Preferences</string>
<string name="gamel_menu_dicts">Dictionaries</string>
<string name="room_label">Room</string>
<string name="hostname_label">Hostname</string>

View file

@ -0,0 +1,109 @@
/* -*- compile-command: "cd ../../../../../; ant install"; -*- */
package org.eehouse.android.xw4;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.widget.AdapterView;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import junit.framework.Assert;
public class DictsActivity extends ListActivity
implements View.OnClickListener {
String[] m_dicts;
private class DictListAdapter extends XWListAdapter {
Context m_context;
public DictListAdapter( Context context ) {
super( context, m_dicts.length );
m_context = context;
}
public Object getItem( int position) { return m_dicts[position]; }
public View getView( final int position, View convertView,
ViewGroup parent ) {
LayoutInflater factory = LayoutInflater.from( DictsActivity.this );
final XWListItem view
= (XWListItem)factory.inflate( R.layout.list_item, null );
view.setPosition( position );
view.setText( m_dicts[position] );
return view;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.dict_browse );
registerForContextMenu( getListView() );
Button download = (Button)findViewById( R.id.download );
download.setOnClickListener( this );
mkListAdapter();
}
@Override
protected void onResume()
{
super.onResume();
mkListAdapter();
}
public void onClick( View v ) {
startActivity( Utils.mkDownloadActivity( this ) );
}
@Override
public void onCreateContextMenu( ContextMenu menu, View view,
ContextMenuInfo menuInfo ) {
MenuInflater inflater = getMenuInflater();
inflater.inflate( R.menu.dicts_item_menu, menu );
}
@Override
public boolean onContextItemSelected( MenuItem item )
{
boolean handled = false;
AdapterView.AdapterContextMenuInfo info;
try {
info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
} catch (ClassCastException e) {
Utils.logf( "bad menuInfo:" + e.toString() );
return false;
}
int id = item.getItemId();
switch( id ) {
case R.id.dicts_item_delete:
deleteFile( m_dicts[info.position] );
mkListAdapter();
handled = true;
break;
case R.id.dicts_item_details:
Utils.notImpl( this );
break;
}
return handled;
}
private void mkListAdapter()
{
m_dicts = Utils.dictList( this );
setListAdapter( new DictListAdapter( this ) );
}
}

View file

@ -440,7 +440,7 @@ public class GameConfig extends Activity implements View.OnClickListener {
ContextMenuInfo menuInfo ) {
MenuInflater inflater = getMenuInflater();
inflater.inflate( R.menu.players_list_item_menu, menu );
m_whichPlayer = ((PlayerView)view).getPosition();
m_whichPlayer = ((XWListItem)view).getPosition();
}
@Override
@ -568,8 +568,8 @@ public class GameConfig extends Activity implements View.OnClickListener {
m_playerLayout.addView( divider );
}
final PlayerView view
= (PlayerView)factory.inflate( R.layout.player_view, null );
final XWListItem view
= (XWListItem)factory.inflate( R.layout.list_item, null );
view.setPosition( ii );
view.setText( names[ii] );
view.setGravity( Gravity.CENTER );
@ -578,7 +578,7 @@ public class GameConfig extends Activity implements View.OnClickListener {
view.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick( View view ) {
m_whichPlayer = ((PlayerView)view).getPosition();
m_whichPlayer = ((XWListItem)view).getPosition();
showDialog( PLAYER_EDIT );
}
} );

View file

@ -209,6 +209,7 @@ public class GamesList extends ListActivity implements View.OnClickListener {
public boolean onOptionsItemSelected( MenuItem item )
{
boolean handled = true;
Intent intent;
switch (item.getItemId()) {
case R.id.gamel_menu_delete_all:
@ -224,8 +225,13 @@ public class GamesList extends ListActivity implements View.OnClickListener {
handled = true;
break;
case R.id.gamel_menu_dicts:
intent = new Intent( this, DictsActivity.class );
startActivity( intent );
break;
case R.id.gamel_menu_prefs:
Intent intent = new Intent( this, PrefsActivity.class );
intent = new Intent( this, PrefsActivity.class );
startActivity( intent );
break;
@ -249,17 +255,14 @@ public class GamesList extends ListActivity implements View.OnClickListener {
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
doOpen( position );
}
private void doOpen( int indx ) {
protected void onListItemClick(ListView l, View v, int position, long id)
{
String[] missingDict = new String[1];
if ( ! Utils.gameDictHere( this, indx, missingDict ) ) {
if ( ! Utils.gameDictHere( this, position, missingDict ) ) {
m_missingDict = missingDict[0];
showDialog( WARN_NODICT );
} else {
String path = Utils.gamesList(this)[indx];
String path = Utils.gamesList(this)[position];
File file = new File( path );
Uri uri = Uri.fromFile( file );
Intent intent = new Intent( Intent.ACTION_EDIT, uri,