33,6 → 33,14 |
import android.widget.ListView; |
import android.widget.SimpleAdapter; |
|
/** |
* Generates the main menu as a list of activities from the manifest |
* |
* @author |
* Thomas 'PointedEars' Lahn; |
* Class courtesy of The Android Open Source Project |
* (Android 2.2 SDK Examples), slightly adapted |
*/ |
public class MenuActivity extends ListActivity |
{ |
|
42,19 → 50,23 |
super.onCreate(savedInstanceState); |
|
Intent intent = this.getIntent(); |
String path = intent.getStringExtra("de.pointedears.converter.Path"); |
String path = intent.getStringExtra("de.pointedears.converter.Path"); //$NON-NLS-1$ |
|
if (path == null) |
{ |
path = ""; |
path = ""; //$NON-NLS-1$ |
} |
|
this.setListAdapter(new SimpleAdapter(this, this.getData(path), |
android.R.layout.simple_list_item_1, new String[] { "title" }, |
new int[] { android.R.id.text1 })); |
android.R.layout.simple_list_item_1, new String[] { "title" }, //$NON-NLS-1$ |
new int[] { android.R.id.text1 })); |
this.getListView().setTextFilterEnabled(true); |
} |
|
/** |
* @param prefix |
* @return |
*/ |
protected List getData(String prefix) |
{ |
List<Map> myData = new ArrayList<Map>(); |
72,13 → 84,13 |
|
String[] prefixPath; |
|
if (prefix.equals("")) |
if (prefix.equals("")) //$NON-NLS-1$ |
{ |
prefixPath = null; |
} |
else |
{ |
prefixPath = prefix.split("/"); |
prefixPath = prefix.split("/"); //$NON-NLS-1$ |
} |
|
int len = list.size(); |
96,7 → 108,7 |
if (prefix.length() == 0 || label.startsWith(prefix)) |
{ |
|
String[] labelPath = label.split("/"); |
String[] labelPath = label.split("/"); //$NON-NLS-1$ |
|
String nextLabel = |
prefixPath == null ? labelPath[0] : labelPath[prefixPath.length]; |
114,7 → 126,7 |
this.addItem( |
myData, |
nextLabel, |
this.browseIntent(prefix.equals("") ? nextLabel : prefix + "/" |
this.browseIntent(prefix.equals("") ? nextLabel : prefix + "/" //$NON-NLS-1$//$NON-NLS-2$ |
+ nextLabel)); |
entries.put(nextLabel, true); |
} |
133,10 → 145,15 |
|
public int compare(Map map1, Map map2) |
{ |
return this.collator.compare(map1.get("title"), map2.get("title")); |
return this.collator.compare(map1.get("title"), map2.get("title")); //$NON-NLS-1$ //$NON-NLS-2$ |
} |
}; |
|
/** |
* @param pkg |
* @param componentName |
* @return |
*/ |
protected Intent activityIntent(String pkg, String componentName) |
{ |
Intent result = new Intent(); |
144,28 → 161,43 |
return result; |
} |
|
/** |
* @param path |
* @return |
*/ |
protected Intent browseIntent(String path) |
{ |
Intent result = new Intent(); |
result.setClass(this, MenuActivity.class); |
result.putExtra("de.pointedears.converter.Path", path); |
result.putExtra("de.pointedears.converter.Path", path); //$NON-NLS-1$ |
return result; |
} |
|
/** |
* @param data |
* @param name |
* @param intent |
*/ |
protected void addItem(List<Map> data, String name, Intent intent) |
{ |
Map<String, Object> temp = new HashMap<String, Object>(); |
temp.put("title", name); |
temp.put("intent", intent); |
temp.put("title", name); //$NON-NLS-1$ |
temp.put("intent", intent); //$NON-NLS-1$ |
data.add(temp); |
} |
|
/* |
* (non-Javadoc) |
* |
* @see android.app.ListActivity#onListItemClick(android.widget.ListView, |
* android.view.View, int, long) |
*/ |
@Override |
protected void onListItemClick(ListView l, View v, int position, long id) |
{ |
Map map = (Map) l.getItemAtPosition(position); |
|
Intent intent = (Intent) map.get("intent"); |
Intent intent = (Intent) map.get("intent"); //$NON-NLS-1$ |
this.startActivity(intent); |
} |
|