PageRenderTime 29ms CodeModel.GetById 21ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/shell/src/com/google/marvin/shell/SettingsShortcutChooserActivity.java

http://eyes-free.googlecode.com/
Java | 84 lines | 71 code | 9 blank | 4 comment | 3 complexity | df1643769a11911c6149cb21a95a38f9 MD5 | raw file
 1// Copyright 2011 Google Inc. All Rights Reserved.
 2
 3package com.google.marvin.shell;
 4
 5import android.app.Activity;
 6import android.app.ListActivity;
 7import android.content.Intent;
 8import android.content.pm.PackageManager;
 9import android.os.Bundle;
10import android.view.View;
11import android.widget.ArrayAdapter;
12import android.widget.ListAdapter;
13import android.widget.ListView;
14
15import java.util.ArrayList;
16import java.util.Collections;
17import java.util.HashMap;
18
19/**
20 * @author credo@google.com (Tim Credo)
21 */
22public class SettingsShortcutChooserActivity extends ListActivity {
23
24    static HashMap<String, String> settingsActions;
25
26    static {
27        settingsActions = new HashMap<String, String>();
28        settingsActions.put(
29                "Accessibility Settings", android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
30        settingsActions.put(
31                "Application Settings", android.provider.Settings.ACTION_APPLICATION_SETTINGS);
32        settingsActions.put(
33                "Bluetooth Settings", android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
34        settingsActions.put("Date Settings", android.provider.Settings.ACTION_DATE_SETTINGS);
35        settingsActions.put(
36                "Input Method Settings", android.provider.Settings.ACTION_INPUT_METHOD_SETTINGS);
37        settingsActions.put("Internal Storage Settings",
38                android.provider.Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
39        settingsActions.put("Locale Settings", android.provider.Settings.ACTION_LOCALE_SETTINGS);
40        settingsActions.put("Location Source Settings",
41                android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
42        settingsActions.put("Manage Applications",
43                android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
44        settingsActions.put(
45                "Memory Card Settings", android.provider.Settings.ACTION_MEMORY_CARD_SETTINGS);
46        settingsActions.put("Privacy Settings", android.provider.Settings.ACTION_PRIVACY_SETTINGS);
47        settingsActions.put(
48                "Security Settings", android.provider.Settings.ACTION_SECURITY_SETTINGS);
49        settingsActions.put("Sound Settings", android.provider.Settings.ACTION_SOUND_SETTINGS);
50        settingsActions.put("Wifi Settings", android.provider.Settings.ACTION_WIFI_SETTINGS);
51        settingsActions.put(
52                "Wireless Settings", android.provider.Settings.ACTION_WIRELESS_SETTINGS);
53    }
54
55    ArrayList<String> availableActions;
56
57    @Override
58    public void onCreate(Bundle savedInstanceState) {
59        super.onCreate(savedInstanceState);
60        PackageManager pm = getPackageManager();
61        availableActions = new ArrayList<String>();
62        for (String key : settingsActions.keySet()) {
63            if (pm.resolveActivity(new Intent(settingsActions.get(key)), 0) != null) {
64                availableActions.add(key);
65            }
66        }
67        Collections.sort(availableActions);
68        ListAdapter adapter = new ArrayAdapter<String>(
69                this, android.R.layout.simple_list_item_1, availableActions);
70        setListAdapter(adapter);
71    }
72
73    @Override
74    protected void onListItemClick(ListView l, View v, int position, long id) {
75        super.onListItemClick(l, v, position, id);
76        String title = availableActions.get(position);
77        String action = settingsActions.get(title);
78        Intent data = new Intent();
79        data.putExtra("TITLE", title);
80        data.putExtra("ACTION", action);
81        this.setResult(Activity.RESULT_OK, data);
82        finish();
83    }
84}