What on Default

Updated default ringer to only display the what fragment, and added the
default ringer description to the ringer list view

closes #48

Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-05-17 12:29:21 -04:00
parent 5407d10b29
commit a29ed10fae
3 changed files with 209 additions and 194 deletions

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="ringer_info_titles">
<item>About</item>
<item>Location</item>
<item>What</item>
</string-array>
<string-array name="ringer_info_titles_default">
<item>What</item>
</string-array>
</resources>

View File

@@ -85,198 +85,188 @@ public class RingerDatabase {
public static final String KEY_RINGER_DESCRIPTION = "ringer_description"; public static final String KEY_RINGER_DESCRIPTION = "ringer_description";
/**
* A helper class to manage database creation and version management.
* @author ricky barrette
*/
private class OpenHelper extends SQLiteOpenHelper {
/** /**
* Creates a new OpenHelper * A helper class to manage database creation and version management.
* @param context
* @author ricky barrette * @author ricky barrette
*/ */
public OpenHelper(Context context) { private class OpenHelper extends SQLiteOpenHelper {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
/** /**
* Converts the database from version 2 to 3 * Creates a new OpenHelper
* @param db * @param context
* @author ricky barrette * @author ricky barrette
*/
private void convert2to3(SQLiteDatabase db){
//get all the ringer information from the old table
Cursor cursor = db.query("two", new String[] { KEY_RINGER_NAME, KEY_RINGTONE,
KEY_NOTIFICATION_RINGTONE, KEY_RINGTONE_IS_SILENT,
KEY_NOTIFICATION_IS_SILENT, KEY_IS_ENABLED,
KEY_RADIUS, KEY_LOCATION_LAT, KEY_LOCATION_LON,
KEY_RINGTONE_URI, KEY_NOTIFICATION_RINGTONE_URI,
KEY_RINGTONE_VOLUME, KEY_NOTIFICATION_RINGTONE_VOLUME,
KEY_WIFI, KEY_BT, KEY_MUSIC_VOLUME, KEY_ALARM_VOLUME
}, null, null, null, null, null);
/*
* iterate through the database moving data over to the version 3 tables
*/ */
int count = cursor.getColumnCount(); public OpenHelper(Context context) {
if (cursor.moveToFirst()) { super(context, DATABASE_NAME, null, DATABASE_VERSION);
do { }
ContentValues ringer = new ContentValues();
if(Debug.DEBUG) /**
Log.v(TAG, "Converting: " + cursor.getString(0)); * Converts the database from version 2 to 3
for(int i = 0; i < count; i++){ * @param db
* @author ricky barrette
*/
private void convert2to3(SQLiteDatabase db){
//get all the ringer information from the old table
Cursor cursor = db.query("two", new String[] { KEY_RINGER_NAME, KEY_RINGTONE,
KEY_NOTIFICATION_RINGTONE, KEY_RINGTONE_IS_SILENT,
KEY_NOTIFICATION_IS_SILENT, KEY_IS_ENABLED,
KEY_RADIUS, KEY_LOCATION_LAT, KEY_LOCATION_LON,
KEY_RINGTONE_URI, KEY_NOTIFICATION_RINGTONE_URI,
KEY_RINGTONE_VOLUME, KEY_NOTIFICATION_RINGTONE_VOLUME,
KEY_WIFI, KEY_BT, KEY_MUSIC_VOLUME, KEY_ALARM_VOLUME
}, null, null, null, null, null);
/*
* iterate through the database moving data over to the version 3 tables
*/
int count = cursor.getColumnCount();
if (cursor.moveToFirst()) {
do {
ContentValues ringer = new ContentValues();
if(Debug.DEBUG) if(Debug.DEBUG)
Log.v(TAG, i + " = "+ cursor.getColumnName(i) +" ~ " + cursor.getString(i)); Log.v(TAG, "Converting: " + cursor.getString(0));
switch(i){ for(int i = 0; i < count; i++){
case 0: //ringer name if(Debug.DEBUG)
ringer.put(cursor.getColumnName(i), cursor.getString(0)); Log.v(TAG, i + " = "+ cursor.getColumnName(i) +" ~ " + cursor.getString(i));
break; switch(i){
case 5: //is enabled case 0: //ringer name
ringer.put(KEY_IS_ENABLED, cursor.getString(i)); ringer.put(cursor.getColumnName(i), cursor.getString(0));
break; break;
case 6: //radius case 5: //is enabled
ringer.put(KEY_RADIUS, cursor.getString(i)); ringer.put(KEY_IS_ENABLED, cursor.getString(i));
break; break;
case 7: // lat case 6: //radius
ringer.put(KEY_LOCATION_LAT, cursor.getString(i)); ringer.put(KEY_RADIUS, cursor.getString(i));
break; break;
case 8: // lon case 7: // lat
ringer.put(KEY_LOCATION_LON, cursor.getString(i)); ringer.put(KEY_LOCATION_LAT, cursor.getString(i));
break; break;
default: case 8: // lon
ContentValues values = new ContentValues(); ringer.put(KEY_LOCATION_LON, cursor.getString(i));
values.put(KEY_RINGER_NAME, cursor.getString(0)); break;
values.put(KEY, cursor.getColumnName(i)); default:
values.put(KEY_VALUE, cursor.getString(i)); ContentValues values = new ContentValues();
db.insert(RINGER_INFO_TABLE, null, values); values.put(KEY_RINGER_NAME, cursor.getString(0));
} values.put(KEY, cursor.getColumnName(i));
} values.put(KEY_VALUE, cursor.getString(i));
db.insert(RINGER_TABLE, null, ringer); db.insert(RINGER_INFO_TABLE, null, values);
} while (cursor.moveToNext());
}
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
}
/**
* Creates the initial database structure
* @param db
* @author ricky barrette
*/
private void createDatabase(SQLiteDatabase db){
db.execSQL("CREATE TABLE " + RINGER_TABLE +
"(id INTEGER PRIMARY KEY, " +
KEY_RINGER_NAME+" TEXT, " +
KEY_IS_ENABLED+" TEXT)");
db.execSQL("CREATE TABLE " + RINGER_INFO_TABLE +
"(id INTEGER PRIMARY KEY, " +
KEY_RINGER_NAME+" TEXT, " +
KEY+" TEXT, " +
KEY_VALUE+" TEXT)");
}
/**
* called when the database is created for the first time. this will create our Ringer database
* (non-Javadoc)
* @see android.database.sqlite.SQLiteOpenHelper#onCreate(android.database.sqlite.SQLiteDatabase)
* @author ricky barrette
*/
@Override
public void onCreate(SQLiteDatabase db) {
if(Debug.DROP_TABLE_EVERY_TIME)
db.execSQL("DROP TABLE IF EXISTS " + RINGER_TABLE);
createDatabase(db);
//insert the default ringer into this table
db.execSQL("insert into " + RINGER_TABLE + "(" + KEY_RINGER_NAME + ") values ('"+RingerDatabase.this.mContext.getString(R.string.default_ringer)+"')");
}
/**
* called when the database needs to be updated
* (non-Javadoc)
* @see android.database.sqlite.SQLiteOpenHelper#onUpgrade(android.database.sqlite.SQLiteDatabase, int, int)
* @author ricky barrette
*/
@Override
public void onUpgrade(final SQLiteDatabase db, final int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version "+oldVersion+" to "+newVersion);
if(RingerDatabase.this.mListener != null)
RingerDatabase.this.mListener.onDatabaseUpgrade();
RingerDatabase.this.isUpgrading = true;
final Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
if(RingerDatabase.this.mListener != null)
RingerDatabase.this.mListener.onDatabaseUpgradeComplete();
}
};
//upgrade thread
new Thread( new Runnable(){
@Override
public void run(){
Looper.prepare();
switch(oldVersion){
case 1:
db.execSQL("ALTER TABLE " + RINGER_TABLE + " ADD "+ KEY_MUSIC_VOLUME+" INTEGER");
db.execSQL("ALTER TABLE " + RINGER_TABLE + " ADD "+ KEY_ALARM_VOLUME+" INTEGER");
case 2:
//rename the old ringer table
db.execSQL("ALTER TABLE " + RINGER_TABLE + " RENAME TO two");
//create a new ringer table
createDatabase(db);
//convert database to the new version
convert2to3(db);
//remove old tables
db.execSQL("DROP TABLE IF EXISTS two");
case 3:
Cursor c = db.query(RINGER_TABLE, new String[] { "id", KEY_RINGER_NAME, KEY_LOCATION_LAT, KEY_LOCATION_LON, KEY_RADIUS }, null, null, null, null, null);;
c.moveToFirst();
if (c.moveToFirst()) {
do {
if(Debug.DEBUG)
Log.d(TAG, "Moving: "+c.getInt(0)+" "+c.getString(1)+" "+c.getInt(2)+", "+c.getInt(3)+" @ "+ c.getInt(4) +"m");
ContentValues ringer = new ContentValues();
ContentValues info = new ContentValues();
ringer.put(KEY_RINGER_NAME, c.getString(1));
info.put(KEY_LOCATION_LAT, c.getInt(2));
info.put(KEY_LOCATION_LON, c.getInt(3));
info.put(KEY_RADIUS, c.getInt(4));
updateRinger(c.getInt(0), ringer, info);
} while (c.moveToNext());
} }
//drop old location trigger information }
db.execSQL("CREATE TABLE ringers_new (" + db.insert(RINGER_TABLE, null, ringer);
"id INTEGER PRIMARY KEY, " + } while (cursor.moveToNext());
KEY_RINGER_NAME+" TEXT, " +
KEY_IS_ENABLED+" TEXT)");
db.execSQL("INSERT INTO ringers_new SELECT id, "+ KEY_RINGER_NAME +", "+ KEY_IS_ENABLED +" FROM "+RINGER_TABLE);
db.execSQL("DROP TABLE "+ RINGER_TABLE);
db.execSQL("ALTER TABLE ringers_new RENAME TO "+ RINGER_TABLE);
}
handler.sendEmptyMessage(0);
RingerDatabase.this.isUpgrading = false;
} }
}).start(); if (cursor != null && !cursor.isClosed()) {
} cursor.close();
} }
}
/** /**
* Parses a string boolean from the database * Creates the initial database structure
* @param bool * @param db
* @return true or false * @author ricky barrette
* @author ricky barrette */
*/ private void createDatabase(SQLiteDatabase db){
public static boolean parseBoolean(String bool){ db.execSQL("CREATE TABLE " + RINGER_TABLE +
try { "(id INTEGER PRIMARY KEY, " +
return bool == null ? false : Integer.parseInt(bool) == 1 ? true : false; KEY_RINGER_NAME+" TEXT, " +
} catch (NumberFormatException e) { KEY_IS_ENABLED+" TEXT)");
return false; db.execSQL("CREATE TABLE " + RINGER_INFO_TABLE +
"(id INTEGER PRIMARY KEY, " +
KEY_RINGER_NAME+" TEXT, " +
KEY+" TEXT, " +
KEY_VALUE+" TEXT)");
}
/**
* called when the database is created for the first time. this will create our Ringer database
* (non-Javadoc)
* @see android.database.sqlite.SQLiteOpenHelper#onCreate(android.database.sqlite.SQLiteDatabase)
* @author ricky barrette
*/
@Override
public void onCreate(SQLiteDatabase db) {
if(Debug.DROP_TABLE_EVERY_TIME)
db.execSQL("DROP TABLE IF EXISTS " + RINGER_TABLE);
createDatabase(db);
//insert the default ringer into this table
db.execSQL("insert into " + RINGER_TABLE + "(" + KEY_RINGER_NAME + ") values ('"+RingerDatabase.this.mContext.getString(R.string.default_ringer)+"')");
db.execSQL("insert into " + RINGER_INFO_TABLE + "(" + KEY_RINGER_NAME + ", " + KEY + ", " + KEY_VALUE +
") values ('"+RingerDatabase.this.mContext.getString(R.string.default_ringer)
+ "', '" + KEY_RINGER_DESCRIPTION
+ "', '" + RingerDatabase.this.mContext.getString(R.string.about_default_ringer)+"')");
}
/**
* called when the database needs to be updated
* (non-Javadoc)
* @see android.database.sqlite.SQLiteOpenHelper#onUpgrade(android.database.sqlite.SQLiteDatabase, int, int)
* @author ricky barrette
*/
@Override
public void onUpgrade(final SQLiteDatabase db, final int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version "+oldVersion+" to "+newVersion);
if(RingerDatabase.this.mListener != null)
RingerDatabase.this.mListener.onDatabaseUpgrade();
RingerDatabase.this.isUpgrading = true;
final Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
if(RingerDatabase.this.mListener != null)
RingerDatabase.this.mListener.onDatabaseUpgradeComplete();
}
};
//upgrade thread
new Thread( new Runnable(){
@Override
public void run(){
Looper.prepare();
switch(oldVersion){
case 1:
db.execSQL("ALTER TABLE " + RINGER_TABLE + " ADD "+ KEY_MUSIC_VOLUME+" INTEGER");
db.execSQL("ALTER TABLE " + RINGER_TABLE + " ADD "+ KEY_ALARM_VOLUME+" INTEGER");
case 2:
//rename the old ringer table
db.execSQL("ALTER TABLE " + RINGER_TABLE + " RENAME TO two");
//create a new ringer table
createDatabase(db);
//convert database to the new version
convert2to3(db);
//remove old tables
db.execSQL("DROP TABLE IF EXISTS two");
case 3:
Cursor c = db.query(RINGER_TABLE, new String[] { "id", KEY_RINGER_NAME, KEY_LOCATION_LAT, KEY_LOCATION_LON, KEY_RADIUS }, null, null, null, null, null);;
c.moveToFirst();
if (c.moveToFirst()) {
do {
if(Debug.DEBUG)
Log.d(TAG, "Moving: "+c.getInt(0)+" "+c.getString(1)+" "+c.getInt(2)+", "+c.getInt(3)+" @ "+ c.getInt(4) +"m");
ContentValues ringer = new ContentValues();
ContentValues info = new ContentValues();
ringer.put(KEY_RINGER_NAME, c.getString(1));
info.put(KEY_LOCATION_LAT, c.getInt(2));
info.put(KEY_LOCATION_LON, c.getInt(3));
info.put(KEY_RADIUS, c.getInt(4));
updateRinger(c.getInt(0), ringer, info);
} while (c.moveToNext());
}
//drop old location trigger information
db.execSQL("CREATE TABLE ringers_new (" +
"id INTEGER PRIMARY KEY, " +
KEY_RINGER_NAME+" TEXT, " +
KEY_IS_ENABLED+" TEXT)");
db.execSQL("INSERT INTO ringers_new SELECT id, "+ KEY_RINGER_NAME +", "+ KEY_IS_ENABLED +" FROM "+RINGER_TABLE);
db.execSQL("DROP TABLE "+ RINGER_TABLE);
db.execSQL("ALTER TABLE ringers_new RENAME TO "+ RINGER_TABLE);
}
handler.sendEmptyMessage(0);
RingerDatabase.this.isUpgrading = false;
}
}).start();
} }
} }
@@ -296,6 +286,20 @@ private class OpenHelper extends SQLiteOpenHelper {
this.mDb = new OpenHelper(this.mContext).getWritableDatabase(); this.mDb = new OpenHelper(this.mContext).getWritableDatabase();
} }
/**
* Parses a string boolean from the database
* @param bool
* @return true or false
* @author ricky barrette
*/
public static boolean parseBoolean(String bool){
try {
return bool == null ? false : Integer.parseInt(bool) == 1 ? true : false;
} catch (NumberFormatException e) {
return false;
}
}
/** /**
* Backs up the database * Backs up the database
* @return true if successful * @return true if successful

View File

@@ -75,31 +75,29 @@ public class RingerInformationActivity extends FragmentActivity implements OnCon
/* /*
* set the title * set the title
*/ */
if(this.mRinger.containsKey(RingerDatabase.KEY_RINGER_NAME)) this.setTitle(this.mRinger.containsKey(RingerDatabase.KEY_RINGER_NAME) ?this.getString(R.string.editing)+" "+this.mRinger.getAsString(RingerDatabase.KEY_RINGER_NAME)
this.setTitle(this.getString(R.string.editing)+" "+this.mRinger.getAsString(RingerDatabase.KEY_RINGER_NAME)); : getString(R.string.new_ringer));
else
this.setTitle(R.string.new_ringer); boolean isDefault = getString(R.string.default_ringer).equals(this.mRinger.getAsString(RingerDatabase.KEY_RINGER_NAME));
/* /*
* Page titles * Page titles
*/ */
String[] titles = new String[]{ String[] titles = this.getResources().getStringArray(isDefault ? R.array.ringer_info_titles_default : R.array.ringer_info_titles);
this.getString(R.string.about),
this.getString(R.string.location),
this.getString(R.string.what)
};
ArrayList<Fragment> fragments = new ArrayList<Fragment>(); ArrayList<Fragment> fragments = new ArrayList<Fragment>();
/* /*
* about page * about page
*/ */
fragments.add(new AboutRingerFragment(this.mRinger, this.mInfo, this)); if(!isDefault)
fragments.add(new AboutRingerFragment(this.mRinger, this.mInfo, this));
/* /*
* Location page * Location page
*/ */
fragments.add(new LocationInfomationFragment(this.mInfo, this, this)); if(!isDefault)
fragments.add(new LocationInfomationFragment(this.mInfo, this, this));
/* /*
* What page * What page