aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorRuben Brunk <rubenbrunk@google.com>2014-05-16 14:03:06 -0700
committerEino-Ville Talvala <etalvala@google.com>2014-07-11 13:57:44 -0700
commit3e2b3ad76d90a3fb663c7b04794afe534a1f9066 (patch)
treecdd14fe4d33cb0110c238589906eaf6045097e56 /apps
parent3093edb9fe9bc4197dc79380b636c5ec273ecca1 (diff)
downloadpdk-3e2b3ad76d90a3fb663c7b04794afe534a1f9066.tar.gz
TestingCamera2: Allow request to target multiple surfaces.
Change-Id: Ida6d1abc0530497a8deb6f9b162d4ee6b8a9e1d6
Diffstat (limited to 'apps')
-rw-r--r--apps/TestingCamera2/res/layout/checkable_list_item.xml22
-rw-r--r--apps/TestingCamera2/res/layout/request_pane.xml11
-rw-r--r--apps/TestingCamera2/src/com/android/testingcamera2/CheckableListAdapter.java126
-rw-r--r--apps/TestingCamera2/src/com/android/testingcamera2/RequestControlPane.java34
4 files changed, 177 insertions, 16 deletions
diff --git a/apps/TestingCamera2/res/layout/checkable_list_item.xml b/apps/TestingCamera2/res/layout/checkable_list_item.xml
new file mode 100644
index 0000000..7b6fb3f
--- /dev/null
+++ b/apps/TestingCamera2/res/layout/checkable_list_item.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/item_checkbox"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:padding="10dp"
+ android:textSize="16sp" /> \ No newline at end of file
diff --git a/apps/TestingCamera2/res/layout/request_pane.xml b/apps/TestingCamera2/res/layout/request_pane.xml
index bd40599..267652c 100644
--- a/apps/TestingCamera2/res/layout/request_pane.xml
+++ b/apps/TestingCamera2/res/layout/request_pane.xml
@@ -37,11 +37,12 @@
android:layout_weight="1"
android:prompt="@string/request_pane_template_prompt" />
</LinearLayout>
- <Spinner
- android:id="@+id/request_pane_output_spinner"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:prompt="@string/request_pane_output_prompt" />
+
+ <!-- FIXME: Should not have a ListView in a scrollable view, need to rethink layout -->
+ <ListView android:id="@+id/request_pane_output_listview"
+ android:layout_width="match_parent"
+ android:layout_height="100dp" />
+
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
diff --git a/apps/TestingCamera2/src/com/android/testingcamera2/CheckableListAdapter.java b/apps/TestingCamera2/src/com/android/testingcamera2/CheckableListAdapter.java
new file mode 100644
index 0000000..d5a7ad3
--- /dev/null
+++ b/apps/TestingCamera2/src/com/android/testingcamera2/CheckableListAdapter.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.testingcamera2;
+
+import android.content.Context;
+import android.util.Pair;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A specialized adapter containing an array of checkboxes.
+ *
+ * <p>
+ * This adapter contains an array of pairs, where each pair represents the name and checked
+ * state of a given item.
+ * </p>
+ */
+public class CheckableListAdapter extends ArrayAdapter<CheckableListAdapter.CheckableItem> {
+ private Context mContext;
+
+ public CheckableListAdapter(Context context, int resource, List<CheckableItem> objects) {
+ super(context, resource, objects);
+ mContext = context;
+ }
+
+ public static class CheckableItem {
+ public String name;
+ public boolean isChecked;
+
+ public CheckableItem(String name, boolean isChecked) {
+ this.name = name;
+ this.isChecked = isChecked;
+ }
+ }
+
+ @Override
+ public View getView(final int position, View convertView, ViewGroup parent) {
+ CheckBox row = (CheckBox) convertView;
+ if (row == null) {
+ LayoutInflater inflater =
+ (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ row = (CheckBox) inflater.inflate(R.layout.checkable_list_item, parent, false);
+ }
+ CheckableItem item = getItem(position);
+ row.setChecked(item.isChecked);
+ row.setText(item.name);
+
+ row.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
+ CheckableItem item = getItem(position);
+ item.isChecked = b;
+ }
+ });
+ return row;
+ }
+
+ /**
+ * Returns a list containing the indexes of the currently checked items.
+ *
+ * @return a {@link java.util.List} of indices.
+ */
+ public List<Integer> getCheckedPositions() {
+ ArrayList<Integer> checkedPositions = new ArrayList<Integer>();
+ int size = getCount();
+ for (int i = 0; i < size; i++) {
+ CheckableItem item = getItem(i);
+ if (item.isChecked) {
+ checkedPositions.add(i);
+ }
+ }
+
+ return checkedPositions;
+ }
+
+ /**
+ * Update the items in this list. Checked state will be preserved for items that are
+ * still included in the list.
+ *
+ * @param elems a list of strings that represents the names of the items to be included.
+ */
+ public void updateItems(String[] elems) {
+ ArrayList<CheckableItem> newList = new ArrayList<CheckableItem>();
+ for (String e : elems) {
+ CheckableItem item = new CheckableItem(e, false);
+ newList.add(item);
+ boolean newItem = true;
+ int size = getCount();
+ for (int i = 0; i < size; i++) {
+ CheckableItem current = getItem(i);
+ if (current.name.equals(e) && current.isChecked) {
+ item.isChecked = true;
+ newItem = false;
+ }
+ }
+ if (newItem) {
+ item.isChecked = newItem;
+ }
+ }
+ clear();
+ addAll(newList);
+ notifyDataSetChanged();
+ }
+
+}
diff --git a/apps/TestingCamera2/src/com/android/testingcamera2/RequestControlPane.java b/apps/TestingCamera2/src/com/android/testingcamera2/RequestControlPane.java
index 90b1b47..18534f7 100644
--- a/apps/TestingCamera2/src/com/android/testingcamera2/RequestControlPane.java
+++ b/apps/TestingCamera2/src/com/android/testingcamera2/RequestControlPane.java
@@ -25,6 +25,7 @@ import android.view.Surface;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
+import android.widget.ListView;
import android.widget.Spinner;
import org.xmlpull.v1.XmlPullParser;
@@ -74,7 +75,9 @@ public class RequestControlPane extends ControlPane {
private Spinner mCameraSpinner;
private Spinner mTemplateSpinner;
- private Spinner mOutputSpinner;
+ private ListView mOutputListView;
+
+ private CheckableListAdapter mOutputAdapter;
/**
* Constructor for tooling only
@@ -154,7 +157,11 @@ public class RequestControlPane extends ControlPane {
mCameraSpinner = (Spinner) findViewById(R.id.request_pane_camera_spinner);
mTemplateSpinner = (Spinner) findViewById(R.id.request_pane_template_spinner);
- mOutputSpinner = (Spinner) findViewById(R.id.request_pane_output_spinner);
+ mOutputListView = (ListView) findViewById(R.id.request_pane_output_listview);
+
+ mOutputAdapter = new CheckableListAdapter(context, R.layout.checkable_list_item,
+ new ArrayList<CheckableListAdapter.CheckableItem>());
+ mOutputListView.setAdapter(mOutputAdapter);
String[] templateNames = new String[TemplateType.values().length];
for (int i = 0; i < templateNames.length; i++) {
@@ -224,17 +231,22 @@ public class RequestControlPane extends ControlPane {
return null;
}
- TargetControlPane target = mTargetPanes.get(mOutputSpinner.getSelectedItemPosition());
- Surface targetSurface = target.getTargetSurfaceForCameraPane(camera.getPaneName());
- if (targetSurface == null) {
- TLog.e("Target not configured for camera");
- return null;
- }
TemplateType template = TemplateType.valueOf((String) mTemplateSpinner.getSelectedItem());
CaptureRequest.Builder builder = camera.getRequestBuilder(template.getTemplateValue());
// TODO: Add setting overrides
- builder.addTarget(targetSurface);
+
+ List<Integer> targetPostions = mOutputAdapter.getCheckedPositions();
+ for (int i : targetPostions) {
+ TargetControlPane target = mTargetPanes.get(i);
+ Surface targetSurface = target.getTargetSurfaceForCameraPane(camera.getPaneName());
+ if (targetSurface == null) {
+ TLog.e("Target not configured for camera");
+ return null;
+ }
+ builder.addTarget(targetSurface);
+ }
+
CaptureRequest request = builder.build();
return request;
}
@@ -270,8 +282,8 @@ public class RequestControlPane extends ControlPane {
for (int i = 0; i < outputSpinnerItems.length; i++) {
outputSpinnerItems[i] = mTargetPanes.get(i).getPaneName();
}
- mOutputSpinner.setAdapter(new ArrayAdapter<String>(getContext(), R.layout.spinner_item,
- outputSpinnerItems));
+
+ mOutputAdapter.updateItems(outputSpinnerItems);
}
}