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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user