Anonymous avatar Anonymous committed 2b90ebf Draft

Add about category to preferences

Comments (0)

Files changed (3)

res/values/strings.xml

     <string name="tv_storage">System Storage: %s</string>
 
     <!-- PREFERENCES -->
+    <string name="pt_about">About</string>
     <string name="pt_check_new_versions">Check for new versions</string>
     <string name="pt_check_weekly_for_new_versions">Check weekly</string>
     <string name="ps_check_weekly_for_new_versions">Check weekly for new busybox versions</string>
     <string name="pt_troubleshoot">Troubleshoot</string>
     <string name="ps_email_logcat">Email logcat</string>
 	<string name="pt_news_check">News check frequency</string>
+	<string name="pt_go_pro">Get the pro version</string>
+	<string name="ps_go_pro">Remove ads and support development</string>
+	<string name="pt_credits">Credits</string>
+	<string name="ps_credits">Developed by JRummy Apps Inc.</string>
+	<string name="pt_version">Version</string>
 
     <!-- CHECKBOX -->
     <string name="cb_symlink">Symlink applets</string>

res/xml/busybox_prefs.xml

 <?xml version="1.0" encoding="utf-8"?>
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
-
     <PreferenceCategory android:title="@string/pt_check_new_versions" >
         <CheckBoxPreference
             android:defaultValue="false"
             android:title="@string/ps_debug_mode" />
 
         <PreferenceScreen
-            android:defaultValue="false"
             android:key="email_logcat"
             android:title="@string/ps_email_logcat" />
     </PreferenceCategory>
+    <PreferenceCategory android:title="@string/pt_about" >
+        <PreferenceScreen
+            android:key="go_pro"
+            android:summary="@string/ps_go_pro"
+            android:title="@string/pt_go_pro" />
+        <PreferenceScreen
+            style="?android:preferenceInformationStyle"
+            android:enabled="true"
+            android:key="credits"
+            android:summary="@string/ps_credits"
+            android:title="@string/pt_credits" />
+        <PreferenceScreen
+            style="?android:preferenceInformationStyle"
+            android:key="version_info"
+            android:title="@string/pt_version" />
+    </PreferenceCategory>
 
 </PreferenceScreen>

src/com/jrummy/busybox/installer/BusyboxPreferences.java

 import android.app.Dialog;
 import android.app.PendingIntent;
 import android.app.ProgressDialog;
+import android.content.ActivityNotFoundException;
 import android.content.DialogInterface;
 import android.content.DialogInterface.OnCancelListener;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.res.Resources;
 import android.graphics.Color;
 import android.graphics.Typeface;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceManager;
 import android.preference.PreferenceScreen;
+import android.util.Log;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.Window;
 public class BusyboxPreferences extends PreferenceActivity 
 implements OnSharedPreferenceChangeListener, OnPreferenceClickListener {
 
-	public static final String KEY_UPDATE_CHECKER = "check_weekly_for_new_versions";
+	private static final String TAG = "BusyboxPreferences";
+
 	public static final String KEY_LAST_BUSYBOX_VERSION = "last_busybox_version";
 	public static final String KEY_CHECK_AT_BOOT = "check_at_boot_for_new_versions";
-	public static final String KEY_SCHEDULE_TIME = "busybox_check_time";
+	public static final String KEY_RUN_SCRIPT_AS_ROOT = "scripter_run_as_root";
+	public static final String KEY_USE_BASH_SHELL = "scripter_use_bash_shell";
+	public static final String KEY_UPDATE_CHECKER = "check_weekly_for_new_versions";
 	public static final String KEY_DAY_OF_WEEK = "busybox_check_day_of_week";
 	public static final String KEY_HOUR_OF_DAY = "busybox_check_hour_of_day";
 	public static final String KEY_MIN_OF_HOUR = "busybox_check_min_of_hour";
-	public static final String KEY_RUN_SCRIPT_AS_ROOT = "scripter_run_as_root";
-	public static final String KEY_USE_BASH_SHELL = "scripter_use_bash_shell";
-	public static final String KEY_DELETE_BUSYBOX = "delete_busybox";
-	public static final String KEY_DEBUG_MODE = "debug_mode";
-	public static final String KEY_EMAIL_LOGCAT = "email_logcat";
+	private static final String KEY_SCHEDULE_TIME = "busybox_check_time";
+	private static final String KEY_DELETE_BUSYBOX = "delete_busybox";
+	private static final String KEY_DEBUG_MODE = "debug_mode";
+	private static final String KEY_EMAIL_LOGCAT = "email_logcat";
+	private static final String KEY_GO_PRO = "go_pro";
+	private static final String KEY_CREDITS = "credits";
+	private static final String KEY_VERSION_INFO = "version_info";
 
-	public static final int LAST_VERSION_NUMBER = 1200;
+	public static final int LAST_VERSION_NUMBER = 1201;
 
 	private static final int MSG_REMOVED_BUSYBOX = 0;
 	private static final int MSG_SEND_LOGCAT = 1;
 	private static final int DIALOG_CONFIRM_DELETE = 1;
 	private static final int DIALOG_DEBUG_MODE_DISABLED = 2;
 
+	private PreferenceScreen mTime;
+	private PreferenceScreen mEmailLogcat;
+	private PreferenceScreen mDeleteBusybox;
+	private PreferenceScreen mGoPro;
+	private PreferenceScreen mCredits;
+
 	private ProgressDialog mPbarDialog;
 	private SharedPreferences mPrefs;
 	private Typeface mTitleFont;
 
 	@Override
 	protected void onCreate(final Bundle savedInstanceState) {
+		if (Build.VERSION.SDK_INT >= 11) {
+			setTheme(android.R.style.Theme_Holo);
+		} else {
+			setTheme(android.R.style.Theme_Black);
+		}
+
 		super.onCreate(savedInstanceState);
 		addPreferencesFromResource(R.xml.busybox_prefs);
-		
+
 		mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
 		mPrefs.registerOnSharedPreferenceChangeListener(this);
-		
+
 		mTitleFont = Typeface.createFromAsset(getAssets(), "fonts/sonysketch.ttf");
 		mMainFont = Typeface.createFromAsset(getAssets(), "fonts/default.ttf");
-		
-		PreferenceScreen time = (PreferenceScreen) getPreferenceScreen()
-				.findPreference(KEY_SCHEDULE_TIME);
-		PreferenceScreen deleteBusybox = (PreferenceScreen) getPreferenceScreen()
-				.findPreference(KEY_DELETE_BUSYBOX);
-		PreferenceScreen emailLogcat = (PreferenceScreen) getPreferenceScreen()
-				.findPreference(KEY_EMAIL_LOGCAT);
-		
-		deleteBusybox.setOnPreferenceClickListener(this);
-		emailLogcat.setOnPreferenceClickListener(this);
-		time.setOnPreferenceClickListener(this);
+
+		PreferenceScreen prefScreen = getPreferenceScreen();
+		mTime = (PreferenceScreen) prefScreen.findPreference(KEY_SCHEDULE_TIME);
+		mDeleteBusybox = (PreferenceScreen) prefScreen.findPreference(KEY_DELETE_BUSYBOX);
+		mEmailLogcat = (PreferenceScreen) prefScreen.findPreference(KEY_EMAIL_LOGCAT);
+		mGoPro = (PreferenceScreen) prefScreen.findPreference(KEY_GO_PRO);
+		mCredits = (PreferenceScreen) prefScreen.findPreference(KEY_CREDITS);
+
+		mDeleteBusybox.setOnPreferenceClickListener(this);
+		mEmailLogcat.setOnPreferenceClickListener(this);
+		mTime.setOnPreferenceClickListener(this);
+		mGoPro.setOnPreferenceClickListener(this);
+		mCredits.setOnPreferenceClickListener(this);
+
+		try {
+			String versionName = getPackageManager().getPackageInfo(
+					getPackageName(), 0).versionName;
+			((PreferenceScreen) prefScreen.findPreference(
+					KEY_VERSION_INFO)).setSummary(versionName);
+		} catch (NameNotFoundException e) {
+			Log.wtf(TAG, "Failed getting version info");
+		}
+
 	}
 
 	@Override
 				intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(
 						"file://" + msg.getData().getString("logcat")));
 				intent.putExtra(Intent.EXTRA_TEXT, debugInfo.toString());
-                startActivity(Intent.createChooser(intent, getString(R.string.ps_email_logcat)));
+				startActivity(Intent.createChooser(intent, getString(R.string.ps_email_logcat)));
 				break;
 			}
 		}
 
 	@Override
 	public boolean onPreferenceClick(Preference preference) {
-		String key = preference.getKey();
-		if (key.equals(KEY_SCHEDULE_TIME)) {
+		if (preference == mTime) {
 			showDialog(DIALOG_SET_SCHEDULE);
 			return true;
-		} else if (key.equals(KEY_DELETE_BUSYBOX)) {
+		} else if (preference == mDeleteBusybox) {
 			showDialog(DIALOG_CONFIRM_DELETE);
 			return true;
-		} else if (key.equals(KEY_EMAIL_LOGCAT)) {
+		} else if (preference == mEmailLogcat) {
 			if (!mPrefs.getBoolean(KEY_DEBUG_MODE, false)) {
 				showDialog(DIALOG_DEBUG_MODE_DISABLED);
 			} else {
 				sendLogcat();
 			}
 			return true;
+		} else if (preference == mGoPro) {
+			startActivity(new Intent(Intent.ACTION_VIEW, 
+					Uri.parse("market://details?id=com.jrummy.busybox.installer.pro")));
+		} else if (preference == mCredits) {
+			openFacebookPage();
 		}
 		return false;
 	}
 			}
 		}.start();
 	}
+
+	private boolean isPackageInstalled(String packageName) {
+		try {
+			if (getPackageManager().getPackageInfo(packageName, 0) == null) {
+				return false;
+			}
+			return true;
+		} catch (NameNotFoundException e) {
+			return false;
+		}
+	}
+
+	private void openFacebookPage() {
+		if (isPackageInstalled("com.facebook.katana")) {
+			try {
+				startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/336227679757310")));
+				return;
+			} catch (ActivityNotFoundException e) {
+			}
+		}
+		startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/JRummyApps")));
+	}
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.