summaryrefslogtreecommitdiffstats
path: root/tests/VoiceInteraction
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2015-04-02 18:25:35 -0700
committerDianne Hackborn <hackbod@google.com>2015-04-02 18:43:31 -0700
commit5688b03f7f4fafd671451ff73103be0f2388b32e (patch)
tree03f3362f7919592e14f2bd56957fc4c722397e26 /tests/VoiceInteraction
parent3425dae8dc63372e8944dce43f7ed2d567512248 (diff)
downloadframeworks_base-5688b03f7f4fafd671451ff73103be0f2388b32e.zip
frameworks_base-5688b03f7f4fafd671451ff73103be0f2388b32e.tar.gz
frameworks_base-5688b03f7f4fafd671451ff73103be0f2388b32e.tar.bz2
Add quick and dirty async AssistStructure building.
New APIs on ViewAssistStructure all the app to request to build a sub-tree asynchronously and indicate when it is done with that. The overall AssistStructure is now only flattened and transfered on-demand, when the app receiving it requests its data -- and at that point we can wait for any asynchronous building to complete. New AsyncStructure view is a very simple example of using this to asynchronously build a child view. Change-Id: I14f9199bee64915ad3dc80b2190916ec874308af
Diffstat (limited to 'tests/VoiceInteraction')
-rw-r--r--tests/VoiceInteraction/res/layout/main.xml8
-rw-r--r--tests/VoiceInteraction/res/values/strings.xml1
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java2
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/AsyncStructure.java58
4 files changed, 68 insertions, 1 deletions
diff --git a/tests/VoiceInteraction/res/layout/main.xml b/tests/VoiceInteraction/res/layout/main.xml
index 3d7a418..092d37d 100644
--- a/tests/VoiceInteraction/res/layout/main.xml
+++ b/tests/VoiceInteraction/res/layout/main.xml
@@ -26,6 +26,14 @@
android:text="@string/start"
/>
+ <com.android.test.voiceinteraction.AsyncStructure
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="64dp"
+ android:paddingBottom="64dp"
+ android:text="@string/asyncStructure"
+ />
+
</LinearLayout>
diff --git a/tests/VoiceInteraction/res/values/strings.xml b/tests/VoiceInteraction/res/values/strings.xml
index 5331457..942c931 100644
--- a/tests/VoiceInteraction/res/values/strings.xml
+++ b/tests/VoiceInteraction/res/values/strings.xml
@@ -17,6 +17,7 @@
<resources>
<string name="start">Start</string>
+ <string name="asyncStructure">(Async structure goes here)</string>
<string name="confirm">Confirm</string>
<string name="abort">Abort</string>
<string name="complete">Complete</string>
diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java
index 782d112..8a72341 100644
--- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java
+++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java
@@ -45,8 +45,8 @@ public class AssistVisualizer extends View {
}
public void setAssistStructure(AssistStructure as) {
- mAssistStructure.dump();
mAssistStructure = as;
+ mAssistStructure.dump();
mTextRects.clear();
final int N = as.getWindowNodeCount();
if (N > 0) {
diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AsyncStructure.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AsyncStructure.java
new file mode 100644
index 0000000..73e04e5
--- /dev/null
+++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AsyncStructure.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2015 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.test.voiceinteraction;
+
+import android.annotation.Nullable;
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewAssistStructure;
+import android.widget.TextView;
+
+/**
+ * Test for asynchronously creating additional assist structure.
+ */
+public class AsyncStructure extends TextView {
+ public AsyncStructure(Context context, @Nullable AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ public void onProvideVirtualAssistStructure(ViewAssistStructure structure) {
+ structure.setChildCount(1);
+ final ViewAssistStructure child = structure.asyncNewChild(0);
+ final int width = getWidth();
+ final int height = getHeight();
+ (new Thread() {
+ @Override
+ public void run() {
+ // Simulate taking a long time to build this.
+ try {
+ sleep(2000);
+ } catch (InterruptedException e) {
+ }
+ child.setClassName(AsyncStructure.class.getName());
+ child.setVisibility(View.VISIBLE);
+ child.setDimens(width / 4, height / 4, 0, 0, width / 2, height / 2);
+ child.setEnabled(true);
+ child.setContentDescription("This is some async content");
+ child.setText("We could have lots and lots of async text!");
+ child.asyncCommit();
+ }
+ }).start();
+ }
+}