From 9761596e6e89c47af9d00987862b8e1f9b77f84b Mon Sep 17 00:00:00 2001 From: ehouse Date: Sat, 9 Jan 2010 14:39:34 +0000 Subject: [PATCH] add system menu to games list with "delete all" item; implement roughly --- .../XWords4/res/menu/games_list_menu.xml | 6 +++++ .../android/XWords4/res/values/strings.xml | 2 ++ .../eehouse/android/xw4/GameListAdapter.java | 27 ++----------------- .../org/eehouse/android/xw4/GamesList.java | 25 +++++++++++++++++ 4 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 xwords4/android/XWords4/res/menu/games_list_menu.xml diff --git a/xwords4/android/XWords4/res/menu/games_list_menu.xml b/xwords4/android/XWords4/res/menu/games_list_menu.xml new file mode 100644 index 000000000..e01b9a173 --- /dev/null +++ b/xwords4/android/XWords4/res/menu/games_list_menu.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 6883dd644..8ca7517ee 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -71,4 +71,6 @@ New game Preferences About Crosswords + + Delete all diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java index bce3b6537..5a6799d99 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java @@ -1,4 +1,4 @@ - +/* -*- compile-command: "cd ../../../../../; ant reinstall"; -*- */ package org.eehouse.android.xw4; @@ -37,30 +37,7 @@ public class GameListAdapter implements ListAdapter { public Object getItem( int position ) { TextView view = new TextView(m_context); - - try { - FileInputStream in = m_context.openFileInput( m_files[position] ); - - InputStreamReader reader = new InputStreamReader( in ); - try { - int len = in.available(); - CharBuffer buf = CharBuffer.allocate(len); - reader.read( buf.array(), 0, len ); - reader.close(); - view.setText( buf ); - } catch ( java.io.IOException ex ) { - Utils.logf( "got IOException: " + ex.toString() ); - } - - try { - in.close(); - } catch ( java.io.IOException ex ) { - Utils.logf( "got IOException: " + ex.toString() ); - } - } catch ( java.io.FileNotFoundException ex ) { - Utils.logf( "got FileNotFoundException: " + ex.toString() ); - } - + view.setText( "one game" ); return view; } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java index 25c272d3c..8b1e4ba7b 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java @@ -1,3 +1,4 @@ +/* -*- compile-command: "cd ../../../../../; ant reinstall"; -*- */ /* * Copyright (C) 2007 The Android Open Source Project * @@ -233,6 +234,30 @@ public class GamesList extends ListActivity implements View.OnClickListener { return handled; } + public boolean onCreateOptionsMenu( Menu menu ) + { + MenuInflater inflater = getMenuInflater(); + inflater.inflate( R.menu.games_list_menu, menu ); + return true; + } + + public boolean onOptionsItemSelected( MenuItem item ) + { + boolean handled = true; + + switch (item.getItemId()) { + case R.id.gamel_menu_delete_all: + for( String file : fileList() ) { + deleteFile( file ); + } + m_adapter = new GameListAdapter( this ); + setListAdapter( m_adapter ); + handled = true; + break; + } + return handled; + } + public void onClick( View v ) { Intent intent = new Intent(); intent.setClassName( "org.eehouse.android.xw4",