mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
Fire GameConfig activity to edit a game; use file save/open methods in
Utils.
This commit is contained in:
parent
f4535f3408
commit
960fbd0b33
1 changed files with 41 additions and 36 deletions
|
@ -60,7 +60,6 @@ public class GamesList extends ListActivity implements View.OnClickListener {
|
||||||
|
|
||||||
Button newGameB = (Button)findViewById(R.id.new_game);
|
Button newGameB = (Button)findViewById(R.id.new_game);
|
||||||
newGameB.setOnClickListener( this );
|
newGameB.setOnClickListener( this );
|
||||||
Utils.logf( "got button" );
|
|
||||||
|
|
||||||
// If no data was given in the intent (because we were started
|
// If no data was given in the intent (because we were started
|
||||||
// as a MAIN activity), then use our default content provider.
|
// as a MAIN activity), then use our default content provider.
|
||||||
|
@ -103,11 +102,15 @@ public class GamesList extends ListActivity implements View.OnClickListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.list_item_open:
|
// case R.id.list_item_open:
|
||||||
doOpen( info.position );
|
// doOpen( info.position );
|
||||||
|
// handled = true;
|
||||||
|
// break;
|
||||||
|
case R.id.list_item_view:
|
||||||
|
doView( info.position );
|
||||||
handled = true;
|
handled = true;
|
||||||
break;
|
break;
|
||||||
case R.id.list_item_view:
|
|
||||||
case R.id.list_item_hide:
|
case R.id.list_item_hide:
|
||||||
case R.id.list_item_delete:
|
case R.id.list_item_delete:
|
||||||
case R.id.list_item_copy:
|
case R.id.list_item_copy:
|
||||||
|
@ -151,7 +154,7 @@ public class GamesList extends ListActivity implements View.OnClickListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick( View v ) {
|
public void onClick( View v ) {
|
||||||
save( new CurGameInfo() );
|
saveNew( new CurGameInfo() );
|
||||||
onContentChanged();
|
onContentChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,43 +172,45 @@ public class GamesList extends ListActivity implements View.OnClickListener {
|
||||||
startActivity( intent );
|
startActivity( intent );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void save( CurGameInfo gi )
|
private void doView( int indx ) {
|
||||||
|
String path = fileList()[indx];
|
||||||
|
File file = new File( path );
|
||||||
|
Uri uri = Uri.fromFile( file );
|
||||||
|
|
||||||
|
Intent intent = new Intent( Intent.ACTION_EDIT, uri,
|
||||||
|
GamesList.this, GameConfig.class );
|
||||||
|
startActivity( intent );
|
||||||
|
}
|
||||||
|
|
||||||
|
private String newName()
|
||||||
|
{
|
||||||
|
String name = null;
|
||||||
|
Integer num = 0;
|
||||||
|
int ii;
|
||||||
|
String[] files = fileList();
|
||||||
|
|
||||||
|
while ( name == null ) {
|
||||||
|
name = "game " + num.toString();
|
||||||
|
for ( ii = 0; ii < files.length; ++ii ) {
|
||||||
|
Utils.logf( "comparing " + name + " with " + files[ii] );
|
||||||
|
if ( files[ii].equals(name) ) {
|
||||||
|
++num;
|
||||||
|
name = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveNew( CurGameInfo gi )
|
||||||
{
|
{
|
||||||
byte[] bytes = XwJNI.gi_to_stream( gi );
|
byte[] bytes = XwJNI.gi_to_stream( gi );
|
||||||
if ( null != bytes ) {
|
if ( null != bytes ) {
|
||||||
Integer num = 0;
|
String name = newName();
|
||||||
int ii;
|
Utils.saveGame( this, bytes, newName() );
|
||||||
String[] files = fileList();
|
|
||||||
String name = null;
|
|
||||||
|
|
||||||
while ( name == null ) {
|
|
||||||
name = "game " + num.toString();
|
|
||||||
for ( ii = 0; ii < files.length; ++ii ) {
|
|
||||||
Utils.logf( "comparing " + name + " with " + files[ii] );
|
|
||||||
if ( files[ii].equals(name) ) {
|
|
||||||
++num;
|
|
||||||
name = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Utils.logf( "trying to save " + bytes.length + " as " + name );
|
|
||||||
|
|
||||||
FileOutputStream out;
|
|
||||||
try {
|
|
||||||
out = openFileOutput( name, MODE_PRIVATE );
|
|
||||||
out.write( bytes );
|
|
||||||
out.close();
|
|
||||||
Utils.logf( "wrote " + bytes.length + " bytes" );
|
|
||||||
} catch ( java.io.FileNotFoundException ex ) {
|
|
||||||
Utils.logf( "got FileNotFoundException: " + ex.toString() );
|
|
||||||
} catch ( java.io.IOException ex ) {
|
|
||||||
Utils.logf( "got IOException: " + ex.toString() );
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Utils.logf( "gi_to_stream=>null" );
|
Utils.logf( "gi_to_stream=>null" );
|
||||||
}
|
}
|
||||||
Utils.logf( "save done" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
Loading…
Reference in a new issue