Created Settings Activity

created a simple settings activity that we can add various settings to.

Change-Id: I304454bd5543083bf90d1357da2ca8b8d7f1e37a
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-02-06 01:21:05 -05:00
parent 7b167d7cad
commit 4a0479ec01
5 changed files with 119 additions and 6 deletions

View File

@@ -31,6 +31,10 @@
android:name="ExaltedDice"
android:theme="@android:style/Theme.Holo" >
</activity>
<activity
android:name="Settings"
android:theme="@android:style/Theme.Holo" >
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />

View File

@@ -10,5 +10,9 @@
<string name="create_new_game">Create New Game</string>
<string name="delete">Delete</string>
<string name="new_game">New Game</string>
<string name="version_info">Version Information</string>
<string name="email">twentycodes@gmail.com</string>
<string name="email_about">Send an email with ideas or problems to help make this application even better! Good or bad we want to know what you think!</string>
<string name="contact_us">Contact Us</string>
</resources>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="@string/contact_us" >
<Preference
android:key="email"
android:summary="@string/email_about"
android:title="@string/email" >
</Preference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/version_info" >
<com.TwentyCodes.android.exception.VersionInformationPreference />
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -36,6 +36,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
public static final String KEY_GAME_ID = "game_id";
private static final String[] DICE_VALUES = { "D2", "D3", "D4", "D6", "D8", "D10", "D12", "D20", "D100" };
private static final int DELETE = 0;
private static final int SETTINGS = Menu.FIRST + 2;
private ListView mListView;
private NumberPicker mNumberPicker;
@@ -148,6 +149,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
*/
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(1, MENU_CLEAR, 0, "Clear Roll History");
menu.add(1, SETTINGS, 0, "Settings");
menu.add(1, MENU_QUIT, 0, "Quit");
return true;
}
@@ -174,12 +176,15 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_QUIT:
quitDialog();
return true;
case MENU_CLEAR:
clearHistory();
return true;
case MENU_QUIT:
quitDialog();
return true;
case MENU_CLEAR:
clearHistory();
return true;
case SETTINGS:
startActivity(new Intent(this, Settings.class));
break;
}
return false;
}

View File

@@ -0,0 +1,85 @@
/**
* Settings.java
* @date Feb 6, 2012
* @author ricky barrette
* @author Twenty Codes, LLC
*/
package com.TwentyCode.android.ExaltedDice;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
/**
* This activity will be used to allow the user to fine tune exalted dice
*
* TODO
* + game specific settings?
* @author ricky barrette
*/
public class Settings extends PreferenceActivity implements OnPreferenceClickListener {
public static final String SETTINGS = "settings";
private static final CharSequence EMAIL = "email";
/**
* (non-Javadoc)
* @see android.preference.PreferenceActivity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//set shared_prefs name
getPreferenceManager().setSharedPreferencesName(SETTINGS);
//load preferences xml. this load relies on only wether the app is full or not. it will show the check license option if full and leave it out if lite
addPreferencesFromResource(R.xml.settings);
this.findPreference(EMAIL).setOnPreferenceClickListener(this);
}
/**
* called when the email preference button is clicked
*/
@Override
public boolean onPreferenceClick(Preference preference) {
this.startActivity(generateEmailIntent());
return false;
}
/**
* generates the exception repost email intent
* @param report
* @return intent to start users email client
* @author ricky barrette
*/
private Intent generateEmailIntent() {
/*
* get the build information, and build the string
*/
PackageManager pm = this.getPackageManager();
PackageInfo pi;
try {
pi = pm.getPackageInfo(this.getPackageName(), 0);
} catch (NameNotFoundException eNnf) {
//doubt this will ever run since we want info about our own package
pi = new PackageInfo();
pi.versionName = "unknown";
pi.versionCode = 1;
}
Intent intent = new Intent(Intent.ACTION_SEND);
String theSubject = this.getString(R.string.app_name);
String theBody = "\n\n\n"+ Build.FINGERPRINT +"\n"+ this.getString(R.string.app_name)+" "+pi.versionName+" build "+pi.versionCode;
intent.putExtra(Intent.EXTRA_EMAIL,new String[] {this.getString(R.string.email)});
intent.putExtra(Intent.EXTRA_TEXT, theBody);
intent.putExtra(Intent.EXTRA_SUBJECT, theSubject);
intent.setType("message/rfc822");
return intent;
}
}