Permalink
Browse files

Added an option for br0tips

  • Loading branch information...
1 parent 429bb3d commit 44881f930e2e73a2c62a315e15e181723e349c34 @kmobs committed Jun 27, 2010
View
5 AndroidManifest.xml
@@ -14,6 +14,11 @@
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity>
+ <activity android:name=".activities.BrotipsActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ </intent-filter>
+ </activity>
<provider android:name=".provider.SettingsProvider"
android:authorities="com.cyanogenmod.cmparts.provider.Settings" />
</application>
View
7 res/values/strings.xml
@@ -5,6 +5,9 @@
<string name="trackball_settings_title">Trackball Settings</string>
<string name="trackball_settings_summary">Trackball Wake and Unlock</string>
+
+ <string name="brotips_title">Br0tip Settings</string>
+ <string name="brotips_summary">Protips? More like Br0tips</string>
<!-- Trackball Wake -->
<string name="pref_trackball_wake_title">Trackball Wake</string>
@@ -13,4 +16,8 @@
<!-- Trackball Unlock -->
<string name="pref_trackball_unlock_title">Trackball Unlock</string>
<string name="pref_trackball_unlock_summary">Pressing the trackball unlocks the device.</string>
+
+ <!-- br0tips -->
+ <string name="pref_brotips_title">Enable Br0tips</string>
+ <string name="pref_brotips_summary">Change the Home screen tips</string>
</resources>
View
5 res/xml/brotips_settings.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+ <CheckBoxPreference android:key="pref_brotips"
+ android:title="@string/pref_brotips_title" android:summary="@string/pref_brotips_summary" />
+</PreferenceScreen>
View
8 res/xml/cmparts.xml
@@ -9,7 +9,13 @@
android:targetPackage="com.cyanogenmod.cmparts"
android:targetClass="com.cyanogenmod.cmparts.activities.TrackballActivity" />
</PreferenceScreen>
-
+ <PreferenceScreen android:key="brotips"
+ android:title="@string/brotips_title" android:summary="@string/brotips_summary">
+ <intent android:action="android.intent.action.MAIN"
+ android:targetPackage="com.cyanogenmod.cmparts"
+ android:targetClass="com.cyanogenmod.cmparts.activities.BrotipsActivity" />
+ </PreferenceScreen>
+
</PreferenceCategory>
</PreferenceScreen>
View
116 src/com/cyanogenmod/cmparts/activities/BrotipsActivity.java
@@ -0,0 +1,116 @@
+package com.cyanogenmod.cmparts.activities;
+
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceGroup;
+import android.preference.PreferenceScreen;
+import android.provider.Settings;
+
+import com.cyanogenmod.cmparts.R;
+import com.cyanogenmod.cmparts.provider.SettingsProvider;
+
+public class BrotipsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {
+
+ private static final String BROTIPS_PREF= "pref_brotips";
+
+ private CheckBoxPreference mBrotipsPref;
+
+ private String[] DEFAULT_PROJECTION = new String[] {
+ SettingsProvider.Constants._ID,
+ SettingsProvider.Constants.KEY,
+ SettingsProvider.Constants.VALUE
+ };
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setTitle(R.string.brotips_title);
+ addPreferencesFromResource(R.xml.brotips_settings);
+
+ PreferenceScreen prefSet = getPreferenceScreen();
+
+ /* Brotips*/
+ mBrotipsPref = (CheckBoxPreference) prefSet.findPreference(BROTIPS_PREF);
+ mBrotipsPref.setChecked(Settings.System.getInt(getContentResolver(),
+ Settings.System.BROTIPS, 0) == 1);
+
+ final PreferenceGroup parentPreference = getPreferenceScreen();
+ parentPreference.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
+ }
+
+ /*
+ private void writeToProvider(String key, String value) {
+ ContentValues values = new ContentValues();
+
+ values.put(Constants.KEY, key);
+ values.put(Constants.VALUE, value);
+
+ int id = getRowId(key);
+ if (id == -1) {
+ getContentResolver().insert(SettingsProvider.CONTENT_URI, values);
+ } else {
+ final String selection = Constants.KEY + "='" + key + "'";
+ Uri rowuri = Uri.parse("content://"+SettingsProvider.AUTHORITY+"/"+SettingsProvider.TABLE_NAME+"/"+id);
+ getContentResolver().update(rowuri, values, selection, null);
+ }
+ }
+
+ private int getInt(String key, int def) {
+ String value = getString(key);
+ try {
+ return value != null ? Integer.parseInt(value) : def;
+ } catch (NumberFormatException e) {
+ return def;
+ }
+ }
+
+ private String getString(String key) {
+ String value = null;
+ Cursor c = null;
+ String selection = "key='"+key+"'";
+ try {
+ c = managedQuery(SettingsProvider.CONTENT_URI, DEFAULT_PROJECTION, selection, null, null);
+ if (c != null && c.moveToNext()) {
+ value = c.getString(2);
+ }
+ } catch (SQLException e) {
+ // return null
+ } finally {
+ if (c != null) {
+ c.close();
+ }
+ }
+ return value;
+ }
+
+ private int getRowId(String key) {
+ String selection = "key='"+key+"'";
+ Cursor cur = managedQuery(SettingsProvider.CONTENT_URI, DEFAULT_PROJECTION, selection, null, null);
+ cur.moveToFirst();
+ if (cur.getCount() == 0) {
+ return -1;
+ } else {
+ return cur.getInt(0);
+ }
+ }
+ */
+
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
+ String key) {
+ }
+
+ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+ boolean value;
+ if (preference == mBrotipsPref) {
+ value = mBrotipsPref.isChecked();
+ Settings.System.putInt(getContentResolver(),
+ Settings.System.BROTIPS, value ? 1 : 0);
+ }
+ return true;
+ }
+}

0 comments on commit 44881f9

Please sign in to comment.