Skip to content

Commit fd10e3e

Browse files
committedMar 31, 2012
Add PreferencesDemo
1 parent 55cc276 commit fd10e3e

File tree

15 files changed

+231
-0
lines changed

15 files changed

+231
-0
lines changed
 

‎PreferencesDemo/.classpath

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

‎PreferencesDemo/.cvsignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bin
2+
gen
3+
classes

‎PreferencesDemo/.project

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>PreferencesDemo</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.jdt.core.javabuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
</natures>
33+
</projectDescription>

‎PreferencesDemo/AndroidManifest.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.preferences"
4+
android:versionCode="1"
5+
android:versionName="1.0">
6+
<uses-sdk android:minSdkVersion="4" />
7+
8+
<application android:icon="@drawable/icon" android:label="@string/app_name">
9+
<activity android:name=".Main"
10+
android:label="@string/app_name">
11+
<intent-filter>
12+
<action android:name="android.intent.action.MAIN" />
13+
<category android:name="android.intent.category.LAUNCHER" />
14+
</intent-filter>
15+
</activity>
16+
17+
<activity android:name=".DemoPreferenceActivity"/>
18+
19+
</application>
20+
</manifest>

‎PreferencesDemo/default.properties

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must be checked in Version Control Systems.
5+
#
6+
# To customize properties used by the Ant build system use,
7+
# "build.properties", and override values to adapt the script to your
8+
# project structure.
9+
10+
# Project target.
11+
target=android-10

‎PreferencesDemo/proguard.cfg

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
-optimizationpasses 5
2+
-dontusemixedcaseclassnames
3+
-dontskipnonpubliclibraryclasses
4+
-dontpreverify
5+
-verbose
6+
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
7+
8+
-keep public class * extends android.app.Activity
9+
-keep public class * extends android.app.Application
10+
-keep public class * extends android.app.Service
11+
-keep public class * extends android.content.BroadcastReceiver
12+
-keep public class * extends android.content.ContentProvider
13+
-keep public class * extends android.app.backup.BackupAgentHelper
14+
-keep public class * extends android.preference.Preference
15+
-keep public class com.android.vending.licensing.ILicensingService
16+
17+
-keepclasseswithmembernames class * {
18+
native <methods>;
19+
}
20+
21+
-keepclasseswithmembers class * {
22+
public <init>(android.content.Context, android.util.AttributeSet);
23+
}
24+
25+
-keepclasseswithmembers class * {
26+
public <init>(android.content.Context, android.util.AttributeSet, int);
27+
}
28+
29+
-keepclassmembers class * extends android.app.Activity {
30+
public void *(android.view.View);
31+
}
32+
33+
-keepclassmembers enum * {
34+
public static **[] values();
35+
public static ** valueOf(java.lang.String);
36+
}
37+
38+
-keep class * implements android.os.Parcelable {
39+
public static final android.os.Parcelable$Creator *;
40+
}
4.05 KB
Loading
1.68 KB
Loading
2.51 KB
Loading

‎PreferencesDemo/res/layout/main.xml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical"
4+
android:layout_width="fill_parent"
5+
android:layout_height="fill_parent"
6+
>
7+
<TextView
8+
android:layout_width="fill_parent"
9+
android:layout_height="wrap_content"
10+
android:text="@string/hello"
11+
android:gravity="center_horizontal"
12+
android:textColor="#ffffff"
13+
android:textSize="16pt"
14+
/>
15+
<LinearLayout
16+
android:layout_width="match_parent"
17+
android:id="@+id/linearLayout1"
18+
android:layout_height="wrap_content"
19+
android:gravity="center_horizontal"
20+
/>
21+
22+
<Button android:id="@+id/prefsButton"
23+
android:text="Prefs"
24+
android:onClick="showPrefs"
25+
android:layout_width="fill_parent"
26+
android:layout_height="wrap_content"
27+
/>
28+
29+
</LinearLayout>

‎PreferencesDemo/res/layout/prefs.xml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
2+
3+
<ListPreference
4+
android:key="listChoice"
5+
android:title="List Choice"
6+
android:entries="@array/choices"
7+
android:entryValues="@array/choices"
8+
/>
9+
10+
<PreferenceCategory
11+
android:title="Personal">
12+
13+
<EditTextPreference
14+
android:key="nameChoice"
15+
android:title="Name"
16+
android:hint="Name"
17+
/>
18+
19+
<CheckBoxPreference
20+
android:key="booleanChoice"
21+
android:title="Binary Choice"
22+
/>
23+
24+
</PreferenceCategory>
25+
26+
</PreferenceScreen>

‎PreferencesDemo/res/values/arrays.xml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<resources>
2+
<string-array name="choices">
3+
<item>One</item>
4+
<item>Two</item>
5+
</string-array>
6+
</resources>
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="app_name">PreferencesDemo</string><string name="hello">Hello Preferences</string>
4+
5+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.example.preferences;
2+
3+
import android.os.Bundle;
4+
import android.preference.PreferenceActivity;
5+
6+
public class DemoPreferenceActivity extends PreferenceActivity {
7+
8+
@Override
9+
protected void onCreate(Bundle savedInstanceState) {
10+
super.onCreate(savedInstanceState);
11+
addPreferencesFromResource(R.layout.prefs);
12+
}
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.example.preferences;
2+
3+
import android.app.Activity;
4+
import android.content.Intent;
5+
import android.content.SharedPreferences;
6+
import android.os.Bundle;
7+
import android.preference.PreferenceManager;
8+
import android.view.View;
9+
import android.widget.Toast;
10+
11+
public class Main extends Activity {
12+
private SharedPreferences sharedPreferences;
13+
14+
/** Called when the activity is first created. */
15+
@Override
16+
public void onCreate(Bundle savedInstanceState) {
17+
super.onCreate(savedInstanceState);
18+
setContentView(R.layout.main);
19+
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
20+
}
21+
22+
@Override
23+
protected void onResume() {
24+
super.onResume();
25+
String message = String.format(
26+
"Prefs: List %s, Name %s, Choice %b",
27+
sharedPreferences.getString("listChoice", "None"),
28+
sharedPreferences.getString("nameChoice", "No name"),
29+
sharedPreferences.getBoolean("booleanChoice", false));
30+
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
31+
}
32+
33+
public void showPrefs(View v) {
34+
Intent intent = new Intent(Main.this, DemoPreferenceActivity.class);
35+
startActivity(intent);
36+
}
37+
}

0 commit comments

Comments
 (0)
Please sign in to comment.