Fixed database is closed bug, and added action bar app navigation
Change-Id: If09f348aa0d658bc5bee69de07801dbbe09b5978 Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -453,6 +453,14 @@ public class Database {
|
|||||||
return mDb.insert(GAME_NAME_TABLE, null, game);
|
return mDb.insert(GAME_NAME_TABLE, null, game);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the database is open
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public boolean isOpen(){
|
||||||
|
return mDb.isOpen();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a string boolean from the database
|
* Parses a string boolean from the database
|
||||||
* @param bool
|
* @param bool
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.TwentyCode.android.ExaltedDice;
|
|||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import android.app.ActionBar;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
@@ -20,7 +21,6 @@ import android.view.View.OnClickListener;
|
|||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.NumberPicker;
|
import android.widget.NumberPicker;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@@ -45,7 +45,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
private String mGameName;
|
private String mGameName;
|
||||||
private long mGameId;
|
private long mGameId;
|
||||||
private RollHistoryDatabaseAdapter mListAdapter;
|
private RollHistoryDatabaseAdapter mListAdapter;
|
||||||
private boolean isNewGame;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clears the rollHistory List array and refreshes the listview
|
* clears the rollHistory List array and refreshes the listview
|
||||||
@@ -97,6 +96,15 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
Log.i(TAG, "onCreate()");
|
Log.i(TAG, "onCreate()");
|
||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The following is for api 11 and up
|
||||||
|
*/
|
||||||
|
if(Integer.valueOf(android.os.Build.VERSION.SDK) > 11){
|
||||||
|
ActionBar actionBar = getActionBar();
|
||||||
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
Intent i = this.getIntent();
|
Intent i = this.getIntent();
|
||||||
if(i != null)
|
if(i != null)
|
||||||
if(i.hasExtra(KEY_GAME_NAME)){
|
if(i.hasExtra(KEY_GAME_NAME)){
|
||||||
@@ -124,10 +132,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
|
|
||||||
findViewById(R.id.roll_button).setOnClickListener(this);
|
findViewById(R.id.roll_button).setOnClickListener(this);
|
||||||
|
|
||||||
/*
|
|
||||||
* display hello message
|
|
||||||
*/
|
|
||||||
mListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.hello_msg)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,8 +176,12 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
* @author ricky barrette 3-27-2010
|
* @author ricky barrette 3-27-2010
|
||||||
*/
|
*/
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
|
case android.R.id.home:
|
||||||
|
Intent intent = new Intent(this, GameListActivity.class);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
startActivity(intent);
|
||||||
|
return true;
|
||||||
case MENU_QUIT:
|
case MENU_QUIT:
|
||||||
quitDialog();
|
quitDialog();
|
||||||
return true;
|
return true;
|
||||||
@@ -182,9 +190,10 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
return true;
|
return true;
|
||||||
case SETTINGS:
|
case SETTINGS:
|
||||||
startActivity(new Intent(this, Settings.class));
|
startActivity(new Intent(this, Settings.class));
|
||||||
break;
|
return true;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -192,9 +201,9 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
* @see android.app.Activity#onPause()
|
* @see android.app.Activity#onPause()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onStop() {
|
||||||
mDb.close();
|
mDb.close();
|
||||||
super.onPause();
|
super.onStop();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* resorts application state after rotation
|
* resorts application state after rotation
|
||||||
@@ -213,11 +222,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
if(mDb.getGameRollCount(mGameId) > 0){
|
|
||||||
isNewGame = false;
|
|
||||||
refresh();
|
refresh();
|
||||||
} else
|
|
||||||
isNewGame = true;
|
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,11 +290,8 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void refresh(){
|
public void refresh(){
|
||||||
if(!isNewGame){
|
// mListAdapter.notifyDataSetChanged();
|
||||||
mListView.setAdapter(mListAdapter);
|
mListView.setAdapter(mListAdapter);
|
||||||
isNewGame = false;
|
|
||||||
}
|
|
||||||
mListAdapter.notifyDataSetChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user