diff mbox

[Branch,~glmark2-dev/glmark2/trunk] Rev 234: Android: Display a list of acceptable values instead of a text entry for options that have such a...

Message ID 20120718161713.20229.80978.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

alexandros.frantzis@linaro.org July 18, 2012, 4:17 p.m. UTC
Merge authors:
  Alexandros Frantzis (afrantzis)
Related merge proposals:
  https://code.launchpad.net/~linaro-graphics-wg/glmark2/android-gui-options-finite-value-set/+merge/115499
  proposed by: Alexandros Frantzis (afrantzis)
  review: Approve - Jesse Barker (jesse-barker)
------------------------------------------------------------
revno: 234 [merge]
committer: Alexandros Frantzis <alexandros.frantzis@linaro.org>
branch nick: trunk
timestamp: Wed 2012-07-18 19:06:30 +0300
message:
  Android: Display a list of acceptable values instead of a text entry for options that have such a list.
modified:
  android/src/org/linaro/glmark2/EditorActivity.java
  android/src/org/linaro/glmark2/SceneInfo.java
  src/android.cpp


--
lp:glmark2
https://code.launchpad.net/~glmark2-dev/glmark2/trunk

You are subscribed to branch lp:glmark2.
To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'android/src/org/linaro/glmark2/EditorActivity.java'
--- android/src/org/linaro/glmark2/EditorActivity.java	2012-07-10 09:44:06 +0000
+++ android/src/org/linaro/glmark2/EditorActivity.java	2012-07-18 09:46:21 +0000
@@ -56,7 +56,8 @@ 
 
 public class EditorActivity extends Activity {
     public static final int DIALOG_SCENE_NAME_ID = 0;
-    public static final int DIALOG_SCENE_OPTION_ID = 1;
+    public static final int DIALOG_SCENE_OPTION_TEXT_ID = 1;
+    public static final int DIALOG_SCENE_OPTION_LIST_ID = 2;
 
     public static final int ITEM_POSITION_SCENE_NAME_HEADER = 0;
     public static final int ITEM_POSITION_SCENE_NAME = 1;
@@ -117,10 +118,16 @@ 
                 Bundle bundle = new Bundle();
                 bundle.putInt("item-pos", position);
                 /* Show the right dialog, depending on the clicked list position */
-                if (position == ITEM_POSITION_SCENE_NAME)
+                if (position == ITEM_POSITION_SCENE_NAME) {
                     showDialog(DIALOG_SCENE_NAME_ID, bundle);
-                else if (position >= ITEM_POSITION_SCENE_OPTION)
-                    showDialog(DIALOG_SCENE_OPTION_ID, bundle);
+                }
+                else if (position >= ITEM_POSITION_SCENE_OPTION) {
+                    String[] values = adapter.getItem(position).option.acceptableValues;
+                    if (values.length == 0)
+                        showDialog(DIALOG_SCENE_OPTION_TEXT_ID, bundle);
+                    else
+                        showDialog(DIALOG_SCENE_OPTION_LIST_ID, bundle);
+                }
             }
         });
 
@@ -161,7 +168,7 @@ 
                 }
                 break;
 
-            case DIALOG_SCENE_OPTION_ID:
+            case DIALOG_SCENE_OPTION_TEXT_ID:
                 {
                 AlertDialog.Builder builder = new AlertDialog.Builder(this);
                 final EditorItem item = adapter.getItem(itemPos);
@@ -176,7 +183,7 @@ 
                              event.getAction() == KeyEvent.ACTION_UP))
                         {
                             item.value = v.getText().toString();
-                            dismissDialog(DIALOG_SCENE_OPTION_ID);
+                            dismissDialog(DIALOG_SCENE_OPTION_TEXT_ID);
                         }
                         return true;
                     }
@@ -192,6 +199,24 @@ 
                 }
                 break;
 
+            case DIALOG_SCENE_OPTION_LIST_ID:
+                {
+                AlertDialog.Builder builder = new AlertDialog.Builder(this);
+                final EditorItem item = adapter.getItem(itemPos);
+                builder.setTitle(item.option.name + ": " + item.option.description);
+
+                builder.setItems(item.option.acceptableValues, new DialogInterface.OnClickListener() {
+                    public void onClick(DialogInterface dialog, int index) {
+                        item.value = item.option.acceptableValues[index];
+                        adapter.notifyDataSetChanged();
+                        dismissDialog(DIALOG_SCENE_OPTION_LIST_ID);
+                    }
+                });
+
+                dialog = builder.create();
+                }
+                break;
+
             default:
                 dialog = null;
                 break;
@@ -350,7 +375,7 @@ 
     private ArrayList<SceneInfo> getSceneInfoList() {
         ArrayList<SceneInfo> l = new ArrayList<SceneInfo>();
         SceneInfo customSceneInfo = new SceneInfo("__custom__");
-        customSceneInfo.addOption("__custom__", "Custom benchmark string", "");
+        customSceneInfo.addOption("__custom__", "Custom benchmark string", "", new String[0]);
 
         for (Parcelable p: getIntent().getParcelableArrayExtra("scene-info"))
             l.add((SceneInfo)p);

=== modified file 'android/src/org/linaro/glmark2/SceneInfo.java'
--- android/src/org/linaro/glmark2/SceneInfo.java	2012-07-05 15:05:49 +0000
+++ android/src/org/linaro/glmark2/SceneInfo.java	2012-07-18 09:45:59 +0000
@@ -30,6 +30,7 @@ 
         String name;
         String description;
         String defaultValue;
+        String[] acceptableValues;
     }
 
     public SceneInfo(String name) {
@@ -37,11 +38,14 @@ 
         this.options = new ArrayList<Option>();
     }
 
-    public void addOption(String name, String description, String defaultValue) {
+    public void addOption(String name, String description, String defaultValue,
+                          String[] acceptableValues)
+    {
         Option opt = new Option();
         opt.name = name;
         opt.description = description;
         opt.defaultValue = defaultValue;
+        opt.acceptableValues = acceptableValues;
         this.options.add(opt);
     }
 
@@ -71,6 +75,7 @@ 
             out.writeString(opt.name);
             out.writeString(opt.description);
             out.writeString(opt.defaultValue);
+            out.writeStringArray(opt.acceptableValues);
         }
     }
 
@@ -84,6 +89,7 @@ 
             opt.name = in.readString();
             opt.description = in.readString();
             opt.defaultValue = in.readString();
+            opt.acceptableValues = in.createStringArray();
             options.add(opt);
         }
     }

=== modified file 'src/android.cpp'
--- src/android.cpp	2012-07-10 09:47:01 +0000
+++ src/android.cpp	2012-07-18 09:45:59 +0000
@@ -179,7 +179,7 @@ 
 {
     jclass cls = env->FindClass("org/linaro/glmark2/SceneInfo");
     jmethodID constructor = env->GetMethodID(cls, "<init>", "(Ljava/lang/String;)V");
-    jmethodID add_option = env->GetMethodID(cls, "addOption", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
+    jmethodID add_option = env->GetMethodID(cls, "addOption", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V");
 
     /* Create the SceneInfo object */
     jstring name = env->NewStringUTF(scene.name().c_str());
@@ -197,14 +197,27 @@ 
         jstring opt_description = env->NewStringUTF(opt.description.c_str());
         jstring opt_default_value = env->NewStringUTF(opt.default_value.c_str());
 
+        /* Create and populate the acceptable values array */
+        jclass string_cls = env->FindClass("java/lang/String");
+        jobjectArray opt_acceptable_values = env->NewObjectArray(opt.acceptable_values.size(),
+                                                                 string_cls, 0);
+        
+        for (size_t i = 0; i < opt.acceptable_values.size(); i++) {
+            jstring opt_value = env->NewStringUTF(opt.acceptable_values[i].c_str());
+            env->SetObjectArrayElement(opt_acceptable_values, i, opt_value);
+            env->DeleteLocalRef(opt_value);
+        }
+
         env->CallVoidMethod(scene_info, add_option,
                             opt_name,
                             opt_description,
-                            opt_default_value);
+                            opt_default_value,
+                            opt_acceptable_values);
 
         env->DeleteLocalRef(opt_name);
         env->DeleteLocalRef(opt_description);
         env->DeleteLocalRef(opt_default_value);
+        env->DeleteLocalRef(opt_acceptable_values);
     }
 
     return scene_info;