Skip to content
Browse files

Adding a preference activity with a "sort by" option

  • Loading branch information...
1 parent 1a4dc77 commit 356580cbe4e13296e67d3f973d98626cd7cdfc29 @kyriog committed
View
3 AndroidManifest.xml
@@ -20,6 +20,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <activity
+ android:name=".preference.RightsalertPreference"
+ android:label="@string/menu_settings" ></activity>
</application>
</manifest>
View
7 res/values/keys.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string-array name="preferences_sorting_keys">
+ <item>name</item>
+ <item>score</item>
+ </string-array>
+</resources>
View
8 res/values/strings.xml
@@ -5,6 +5,14 @@
<string name="menu_settings">Settings</string>
+ <string name="preferences_category_display">Display</string>
+ <string name="preferences_sorting_title">Sorting</string>
+ <string name="preferences_sorting_dialogtitle">Sort by…</string>
+ <string-array name="preferences_sorting_array">
+ <item>Name</item>
+ <item>Score</item>
+ </string-array>
+
<string name="applist_loading">Loading applications…</string>
<string name="applist_cancel">Cancel</string>
<string name="applist_count">There are %1$d dangerous applications.</string>
View
13 res/xml/main.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
+ <PreferenceCategory
+ android:title="@string/preferences_category_display">
+ <ListPreference
+ android:entries="@array/preferences_sorting_array"
+ android:entryValues="@array/preferences_sorting_keys"
+ android:dialogTitle="@string/preferences_sorting_dialogtitle"
+ android:title="@string/preferences_sorting_title"
+ android:key="sorting"
+ android:defaultValue="name" />
+ </PreferenceCategory>
+</PreferenceScreen>
View
4 src/fr/keuse/rightsalert/activity/ApplistActivity.java
@@ -6,10 +6,12 @@
import fr.keuse.rightsalert.adapter.ApplistAdapter;
import fr.keuse.rightsalert.entity.ApplicationEntity;
import fr.keuse.rightsalert.handler.LoadApplicationsHandler;
+import fr.keuse.rightsalert.preference.RightsalertPreference;
import fr.keuse.rightsalert.thread.LoadApplicationsThread;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
+import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.Menu;
@@ -77,6 +79,8 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.menu_settings:
+ Intent intent = new Intent(this, RightsalertPreference.class);
+ startActivity(intent);
break;
}
return super.onOptionsItemSelected(item);
View
31 src/fr/keuse/rightsalert/preference/RightsalertPreference.java
@@ -0,0 +1,31 @@
+package fr.keuse.rightsalert.preference;
+
+import fr.keuse.rightsalert.R;
+import android.app.ActionBar;
+import android.os.Build;
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+import android.view.MenuItem;
+
+public class RightsalertPreference extends PreferenceActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.main);
+
+ if(Build.VERSION.SDK_INT >= 11) {
+ ActionBar actionbar = getActionBar();
+ actionbar.setDisplayHomeAsUpEnabled(true);
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch(item.getItemId()) {
+ case android.R.id.home:
+ finish();
+ }
+ return super.onOptionsItemSelected(item);
+ }
+}

0 comments on commit 356580c

Please sign in to comment.
Something went wrong with that request. Please try again.