1package org.skia.jetskidemo;
5import android.content.pm.ActivityInfo;
6import android.content.pm.PackageInfo;
7import android.content.pm.PackageManager;
11import android.widget.AdapterView;
12import android.widget.ArrayAdapter;
15import java.util.ArrayList;
18 private final String TAG =
"ANDROIDKIT DEMO SPINNER";
29 private void init(Context context) {
30 ArrayAdapter<String> adapter;
33 ArrayList<String> navigationOptions;
35 navigationOptions = getActivityList(context);
36 }
catch (Exception
e) {
39 adapter =
new ArrayAdapter(context,
android.R.layout.simple_spinner_item, navigationOptions);
40 adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
41 this.setAdapter(adapter);
44 this.setOnItemSelectedListener(
new OnItemSelectedListener() {
46 public void onItemSelected(AdapterView<?> parent, View view,
int position,
long id) {
47 if (!parent.getItemAtPosition(position).equals(
"Select Activity")) {
48 String activityName = parent.getItemAtPosition(position).toString();
49 Log.d(TAG,
"Navigating to " + activityName);
51 Intent myIntent =
new Intent(context, Class.forName(activityName));
52 context.startActivity(myIntent);
53 }
catch (Exception
e) {
54 Log.d(TAG,
"Couldn't find selected activity.");
60 public void onNothingSelected(AdapterView<?> parent) {
66 private ArrayList<String> getActivityList(Context c)
throws PackageManager.NameNotFoundException {
67 PackageManager pm = c.getPackageManager();
68 PackageInfo
info = pm.getPackageInfo(c.getPackageName(), PackageManager.GET_ACTIVITIES);
69 ActivityInfo[] list =
info.activities;
71 ArrayList<String> activityNames =
new ArrayList<>();
72 for (ActivityInfo activity : list) {
73 activityNames.add(activity.name);
75 activityNames.add(0,
"Select Demo");
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
NavigationSpinner(Context context, AttributeSet attr)
NavigationSpinner(Context context)
void Log(const char *format,...) SK_PRINTF_LIKE(1