Rev 8 | Rev 17 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 8 | Rev 14 | ||
|---|---|---|---|
| Line 31... | Line 31... | ||
| 31 | import android.os.Bundle; |
31 | import android.os.Bundle; |
| 32 | import android.view.View; |
32 | import android.view.View; |
| 33 | import android.widget.ListView; |
33 | import android.widget.ListView; |
| 34 | import android.widget.SimpleAdapter; |
34 | import android.widget.SimpleAdapter; |
| 35 | 35 | ||
| - | 36 | /**
|
|
| - | 37 | * Generates the main menu as a list of activities from the manifest
|
|
| - | 38 | *
|
|
| - | 39 | * @author
|
|
| - | 40 | * Thomas 'PointedEars' Lahn;
|
|
| - | 41 | * Class courtesy of The Android Open Source Project
|
|
| - | 42 | * (Android 2.2 SDK Examples), slightly adapted
|
|
| - | 43 | */
|
|
| 36 | public class MenuActivity extends ListActivity |
44 | public class MenuActivity extends ListActivity |
| 37 | {
|
45 | {
|
| 38 | 46 | ||
| 39 | @Override |
47 | @Override |
| 40 | public void onCreate(Bundle savedInstanceState) |
48 | public void onCreate(Bundle savedInstanceState) |
| 41 | {
|
49 | {
|
| 42 | super.onCreate(savedInstanceState); |
50 | super.onCreate(savedInstanceState); |
| 43 | 51 | ||
| 44 | Intent intent = this.getIntent(); |
52 | Intent intent = this.getIntent(); |
| 45 | String path = intent.getStringExtra("de.pointedears.converter.Path"); |
53 | String path = intent.getStringExtra("de.pointedears.converter.Path"); //$NON-NLS-1$ |
| 46 | 54 | ||
| 47 | if (path == null) |
55 | if (path == null) |
| 48 | {
|
56 | {
|
| 49 | path = ""; |
57 | path = ""; //$NON-NLS-1$ |
| 50 | }
|
58 | }
|
| 51 | 59 | ||
| 52 | this.setListAdapter(new SimpleAdapter(this, this.getData(path), |
60 | this.setListAdapter(new SimpleAdapter(this, this.getData(path), |
| 53 | android.R.layout.simple_list_item_1, new String[] { "title" }, |
61 | android.R.layout.simple_list_item_1, new String[] { "title" }, //$NON-NLS-1$ |
| 54 | new int[] { android.R.id.text1 })); |
62 | new int[] { android.R.id.text1 })); |
| 55 | this.getListView().setTextFilterEnabled(true); |
63 | this.getListView().setTextFilterEnabled(true); |
| 56 | }
|
64 | }
|
| 57 | 65 | ||
| - | 66 | /**
|
|
| - | 67 | * @param prefix
|
|
| - | 68 | * @return
|
|
| - | 69 | */
|
|
| 58 | protected List getData(String prefix) |
70 | protected List getData(String prefix) |
| 59 | {
|
71 | {
|
| 60 | List<Map> myData = new ArrayList<Map>(); |
72 | List<Map> myData = new ArrayList<Map>(); |
| 61 | 73 | ||
| 62 | Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); |
74 | Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); |
| Line 70... | Line 82... | ||
| 70 | return myData; |
82 | return myData; |
| 71 | }
|
83 | }
|
| 72 | 84 | ||
| 73 | String[] prefixPath; |
85 | String[] prefixPath; |
| 74 | 86 | ||
| 75 | if (prefix.equals("")) |
87 | if (prefix.equals("")) //$NON-NLS-1$ |
| 76 | {
|
88 | {
|
| 77 | prefixPath = null; |
89 | prefixPath = null; |
| 78 | }
|
90 | }
|
| 79 | else
|
91 | else
|
| 80 | {
|
92 | {
|
| 81 | prefixPath = prefix.split("/"); |
93 | prefixPath = prefix.split("/"); //$NON-NLS-1$ |
| 82 | }
|
94 | }
|
| 83 | 95 | ||
| 84 | int len = list.size(); |
96 | int len = list.size(); |
| 85 | 97 | ||
| 86 | Map<String, Boolean> entries = new HashMap<String, Boolean>(); |
98 | Map<String, Boolean> entries = new HashMap<String, Boolean>(); |
| Line 94... | Line 106... | ||
| 94 | : info.activityInfo.name; |
106 | : info.activityInfo.name; |
| 95 | 107 | ||
| 96 | if (prefix.length() == 0 || label.startsWith(prefix)) |
108 | if (prefix.length() == 0 || label.startsWith(prefix)) |
| 97 | {
|
109 | {
|
| 98 | 110 | ||
| 99 | String[] labelPath = label.split("/"); |
111 | String[] labelPath = label.split("/"); //$NON-NLS-1$ |
| 100 | 112 | ||
| 101 | String nextLabel = |
113 | String nextLabel = |
| 102 | prefixPath == null ? labelPath[0] : labelPath[prefixPath.length]; |
114 | prefixPath == null ? labelPath[0] : labelPath[prefixPath.length]; |
| 103 | 115 | ||
| 104 | if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) |
116 | if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) |
| Line 112... | Line 124... | ||
| 112 | if (entries.get(nextLabel) == null) |
124 | if (entries.get(nextLabel) == null) |
| 113 | {
|
125 | {
|
| 114 | this.addItem( |
126 | this.addItem( |
| 115 | myData, |
127 | myData, |
| 116 | nextLabel, |
128 | nextLabel, |
| 117 | this.browseIntent(prefix.equals("") ? nextLabel : prefix + "/" |
129 | this.browseIntent(prefix.equals("") ? nextLabel : prefix + "/" //$NON-NLS-1$//$NON-NLS-2$ |
| 118 | + nextLabel)); |
130 | + nextLabel)); |
| 119 | entries.put(nextLabel, true); |
131 | entries.put(nextLabel, true); |
| 120 | }
|
132 | }
|
| 121 | }
|
133 | }
|
| 122 | }
|
134 | }
|
| Line 131... | Line 143... | ||
| 131 | new Comparator<Map>() { |
143 | new Comparator<Map>() { |
| 132 | private final Collator collator = Collator.getInstance(); |
144 | private final Collator collator = Collator.getInstance(); |
| 133 | 145 | ||
| 134 | public int compare(Map map1, Map map2) |
146 | public int compare(Map map1, Map map2) |
| 135 | {
|
147 | {
|
| 136 | return this.collator.compare(map1.get("title"), map2.get("title")); |
148 | return this.collator.compare(map1.get("title"), map2.get("title")); //$NON-NLS-1$ //$NON-NLS-2$ |
| 137 | }
|
149 | }
|
| 138 | }; |
150 | }; |
| 139 | 151 | ||
| - | 152 | /**
|
|
| - | 153 | * @param pkg
|
|
| - | 154 | * @param componentName
|
|
| - | 155 | * @return
|
|
| - | 156 | */
|
|
| 140 | protected Intent activityIntent(String pkg, String componentName) |
157 | protected Intent activityIntent(String pkg, String componentName) |
| 141 | {
|
158 | {
|
| 142 | Intent result = new Intent(); |
159 | Intent result = new Intent(); |
| 143 | result.setClassName(pkg, componentName); |
160 | result.setClassName(pkg, componentName); |
| 144 | return result; |
161 | return result; |
| 145 | }
|
162 | }
|
| 146 | 163 | ||
| - | 164 | /**
|
|
| - | 165 | * @param path
|
|
| - | 166 | * @return
|
|
| - | 167 | */
|
|
| 147 | protected Intent browseIntent(String path) |
168 | protected Intent browseIntent(String path) |
| 148 | {
|
169 | {
|
| 149 | Intent result = new Intent(); |
170 | Intent result = new Intent(); |
| 150 | result.setClass(this, MenuActivity.class); |
171 | result.setClass(this, MenuActivity.class); |
| 151 | result.putExtra("de.pointedears.converter.Path", path); |
172 | result.putExtra("de.pointedears.converter.Path", path); //$NON-NLS-1$ |
| 152 | return result; |
173 | return result; |
| 153 | }
|
174 | }
|
| 154 | 175 | ||
| - | 176 | /**
|
|
| - | 177 | * @param data
|
|
| - | 178 | * @param name
|
|
| - | 179 | * @param intent
|
|
| - | 180 | */
|
|
| 155 | protected void addItem(List<Map> data, String name, Intent intent) |
181 | protected void addItem(List<Map> data, String name, Intent intent) |
| 156 | {
|
182 | {
|
| 157 | Map<String, Object> temp = new HashMap<String, Object>(); |
183 | Map<String, Object> temp = new HashMap<String, Object>(); |
| 158 | temp.put("title", name); |
184 | temp.put("title", name); //$NON-NLS-1$ |
| 159 | temp.put("intent", intent); |
185 | temp.put("intent", intent); //$NON-NLS-1$ |
| 160 | data.add(temp); |
186 | data.add(temp); |
| 161 | }
|
187 | }
|
| 162 | 188 | ||
| - | 189 | /*
|
|
| - | 190 | * (non-Javadoc)
|
|
| - | 191 | *
|
|
| - | 192 | * @see android.app.ListActivity#onListItemClick(android.widget.ListView,
|
|
| - | 193 | * android.view.View, int, long)
|
|
| - | 194 | */
|
|
| 163 | @Override |
195 | @Override |
| 164 | protected void onListItemClick(ListView l, View v, int position, long id) |
196 | protected void onListItemClick(ListView l, View v, int position, long id) |
| 165 | {
|
197 | {
|
| 166 | Map map = (Map) l.getItemAtPosition(position); |
198 | Map map = (Map) l.getItemAtPosition(position); |
| 167 | 199 | ||
| 168 | Intent intent = (Intent) map.get("intent"); |
200 | Intent intent = (Intent) map.get("intent"); //$NON-NLS-1$ |
| 169 | this.startActivity(intent); |
201 | this.startActivity(intent); |
| 170 | }
|
202 | }
|
| 171 | 203 | ||
| 172 | }
|
204 | }
|