diff --git a/platform_tools/android/apps/androidkitdemo/src/main/java/org/skia/androidkitdemo1/NavigationSpinner.java b/platform_tools/android/apps/androidkitdemo/src/main/java/org/skia/androidkitdemo1/NavigationSpinner.java new file mode 100644 index 0000000000..716f11a558 --- /dev/null +++ b/platform_tools/android/apps/androidkitdemo/src/main/java/org/skia/androidkitdemo1/NavigationSpinner.java @@ -0,0 +1,78 @@ +package org.skia.androidkitdemo1; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.util.AttributeSet; +import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Spinner; + +import java.util.ArrayList; + +public class NavigationSpinner extends Spinner { + private final String TAG = "ANDROIDKIT DEMO SPINNER"; + + public NavigationSpinner(Context context) { + super(context); + init(context); + } + public NavigationSpinner(Context context, AttributeSet attr) { + super(context, attr); + init(context); + } + + private void init(Context context) { + ArrayAdapter adapter; + + // populate Spinner + ArrayList navigationOptions; + try { + navigationOptions = getActivityList(context); + } catch (Exception e) { + return; + } + adapter = new ArrayAdapter(context, android.R.layout.simple_spinner_item, navigationOptions); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + this.setAdapter(adapter); + + // set Spinner logic + this.setOnItemSelectedListener(new OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + if (!parent.getItemAtPosition(position).equals("Select Activity")) { + String activityName = parent.getItemAtPosition(position).toString(); + Log.d(TAG, "Navigating to " + activityName); + try { + Intent myIntent = new Intent(context, Class.forName(activityName)); + context.startActivity(myIntent); + } catch (Exception e) { + Log.d(TAG, "Couldn't find selected activity."); + } + } + } + + @Override + public void onNothingSelected(AdapterView parent) { + + } + }); + } + + private ArrayList getActivityList(Context c) throws PackageManager.NameNotFoundException { + PackageManager pm = c.getPackageManager(); + PackageInfo info = pm.getPackageInfo(c.getPackageName(), PackageManager.GET_ACTIVITIES); + ActivityInfo[] list = info.activities; + + ArrayList activityNames = new ArrayList<>(); + for (ActivityInfo activity : list) { + activityNames.add(activity.name); + } + activityNames.add(0, "Select Demo"); + return activityNames; + } +} diff --git a/platform_tools/android/apps/androidkitdemo/src/main/res/layout/activity_animation.xml b/platform_tools/android/apps/androidkitdemo/src/main/res/layout/activity_animation.xml index 51636106ff..79d56b2352 100644 --- a/platform_tools/android/apps/androidkitdemo/src/main/res/layout/activity_animation.xml +++ b/platform_tools/android/apps/androidkitdemo/src/main/res/layout/activity_animation.xml @@ -11,4 +11,10 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"/> + + + \ No newline at end of file diff --git a/platform_tools/android/apps/androidkitdemo/src/main/res/layout/activity_main.xml b/platform_tools/android/apps/androidkitdemo/src/main/res/layout/activity_main.xml index a1622ddea2..00e9d0fb89 100644 --- a/platform_tools/android/apps/androidkitdemo/src/main/res/layout/activity_main.xml +++ b/platform_tools/android/apps/androidkitdemo/src/main/res/layout/activity_main.xml @@ -26,8 +26,12 @@ android:layout_width="200px" android:layout_height="200px" app:layout_constraintLeft_toLeftOf="parent" - app:layout_constraintTop_toBottomOf="@+id/image" - > + app:layout_constraintTop_toBottomOf="@+id/image"> + + \ No newline at end of file