summaryrefslogtreecommitdiffstats
path: root/samples
diff options
context:
space:
mode:
Diffstat (limited to 'samples')
-rw-r--r--samples/ApiDemos/AndroidManifest.xml12
-rw-r--r--samples/ApiDemos/res/layout/reorder_four.xml38
-rw-r--r--samples/ApiDemos/res/layout/reorder_on_launch.xml38
-rw-r--r--samples/ApiDemos/res/layout/reorder_three.xml38
-rw-r--r--samples/ApiDemos/res/layout/reorder_two.xml38
-rw-r--r--samples/ApiDemos/res/values/strings.xml12
-rw-r--r--samples/ApiDemos/res/xml/searchable.xml4
-rw-r--r--samples/ApiDemos/src/com/example/android/apis/app/ReorderFour.java46
-rw-r--r--samples/ApiDemos/src/com/example/android/apis/app/ReorderOnLaunch.java44
-rw-r--r--samples/ApiDemos/src/com/example/android/apis/app/ReorderThree.java44
-rw-r--r--samples/ApiDemos/src/com/example/android/apis/app/ReorderTwo.java44
-rw-r--r--samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.java (renamed from samples/ApiDemos/src/com/android/samples/app/VoiceRecognition.java)2
-rw-r--r--samples/ApiDemos/src/com/example/android/apis/graphics/ProxyDrawable.java10
-rw-r--r--samples/GlobalTime/src/com/android/globaltime/GlobalTime.java152
-rw-r--r--samples/SoftKeyboard/res/values-land/dimens.xml4
-rw-r--r--samples/SoftKeyboard/res/values/dimens.xml2
-rw-r--r--samples/SoftKeyboard/src/com/example/android/softkeyboard/SoftKeyboard.java30
17 files changed, 486 insertions, 72 deletions
diff --git a/samples/ApiDemos/AndroidManifest.xml b/samples/ApiDemos/AndroidManifest.xml
index 67f14e06d..c106ae314 100644
--- a/samples/ApiDemos/AndroidManifest.xml
+++ b/samples/ApiDemos/AndroidManifest.xml
@@ -152,6 +152,18 @@
</intent-filter>
</activity>
+ <activity android:name=".app.ReorderOnLaunch"
+ android:label="@string/activity_reorder">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.SAMPLE_CODE" />
+ </intent-filter>
+ </activity>
+
+ <activity android:name=".app.ReorderTwo" />
+ <activity android:name=".app.ReorderThree" />
+ <activity android:name=".app.ReorderFour" />
+
<!-- Intent Samples -->
<activity android:name=".app.Intents" android:label="@string/activity_intents">
diff --git a/samples/ApiDemos/res/layout/reorder_four.xml b/samples/ApiDemos/res/layout/reorder_four.xml
new file mode 100644
index 000000000..45f13a3f4
--- /dev/null
+++ b/samples/ApiDemos/res/layout/reorder_four.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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.
+-->
+
+<!-- Demonstrates using Intent.FLAG_ACTIVITY_REORDER_TO_FRONT.
+ See corresponding Java code com.example.android.apis.app.ReorderOnLaunch.java. -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:padding="4dip"
+ android:gravity="center_horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <TextView
+ android:layout_width="fill_parent" android:layout_height="wrap_content"
+ android:layout_weight="0"
+ android:paddingBottom="4dip"
+ android:text="@string/reorder_four_text"/>
+
+ <Button android:id="@+id/reorder_second_to_front"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:text="@string/reorder_second_to_front">
+ </Button>
+
+</LinearLayout>
diff --git a/samples/ApiDemos/res/layout/reorder_on_launch.xml b/samples/ApiDemos/res/layout/reorder_on_launch.xml
new file mode 100644
index 000000000..850a2f58c
--- /dev/null
+++ b/samples/ApiDemos/res/layout/reorder_on_launch.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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.
+-->
+
+<!-- Demonstrates using Intent.FLAG_ACTIVITY_REORDER_TO_FRONT.
+ See corresponding Java code com.android.sdk.app.ReorderOnLaunch.java. -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:padding="4dip"
+ android:gravity="center_horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <TextView
+ android:layout_width="fill_parent" android:layout_height="wrap_content"
+ android:layout_weight="0"
+ android:paddingBottom="4dip"
+ android:text="@string/reorder_on_launch"/>
+
+ <Button android:id="@+id/reorder_launch_two"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:text="@string/reorder_launch_two">
+ </Button>
+
+</LinearLayout>
diff --git a/samples/ApiDemos/res/layout/reorder_three.xml b/samples/ApiDemos/res/layout/reorder_three.xml
new file mode 100644
index 000000000..30ef41b55
--- /dev/null
+++ b/samples/ApiDemos/res/layout/reorder_three.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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.
+-->
+
+<!-- Demonstrates using Intent.FLAG_ACTIVITY_REORDER_TO_FRONT.
+ See corresponding Java code com.example.android.apis.app.ReorderOnLaunch.java. -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:padding="4dip"
+ android:gravity="center_horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <TextView
+ android:layout_width="fill_parent" android:layout_height="wrap_content"
+ android:layout_weight="0"
+ android:paddingBottom="4dip"
+ android:text="@string/reorder_three_text"/>
+
+ <Button android:id="@+id/reorder_launch_four"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:text="@string/reorder_launch_four">
+ </Button>
+
+</LinearLayout>
diff --git a/samples/ApiDemos/res/layout/reorder_two.xml b/samples/ApiDemos/res/layout/reorder_two.xml
new file mode 100644
index 000000000..713256194
--- /dev/null
+++ b/samples/ApiDemos/res/layout/reorder_two.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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.
+-->
+
+<!-- Demonstrates using Intent.FLAG_ACTIVITY_REORDER_TO_FRONT.
+ See corresponding Java code com.example.android.apis.app.ReorderOnLaunch.java. -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:padding="4dip"
+ android:gravity="center_horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <TextView
+ android:layout_width="fill_parent" android:layout_height="wrap_content"
+ android:layout_weight="0"
+ android:paddingBottom="4dip"
+ android:text="@string/reorder_two_text"/>
+
+ <Button android:id="@+id/reorder_launch_three"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:text="@string/reorder_launch_three">
+ </Button>
+
+</LinearLayout>
diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml
index 7db3e1b7c..603957f84 100644
--- a/samples/ApiDemos/res/values/strings.xml
+++ b/samples/ApiDemos/res/values/strings.xml
@@ -185,11 +185,21 @@
<string name="custom_title_left_button">Change Left</string>
<string name="custom_title_right_button">Change Right</string>
+ <string name="activity_reorder">App/Activity/Reorder Activities</string>
+ <string name="reorder_on_launch">This is the first of a sequence of four Activities. A button on the fourth will use the Intent.FLAG_ACTIVITY_REORDER_TO_FRONT flag to bring the second of the activities to the front of the history stack. After that, proceeding back through the history should begin with the newly-frontmost second reorder activity, then the fourth, the third, and finally the first.</string>
+ <string name="reorder_launch_two">Go to the second</string>
+ <string name="reorder_two_text">This is the second in a sequence of four Activities.</string>
+ <string name="reorder_launch_three">Go to the third</string>
+ <string name="reorder_three_text">This is the third of a sequence of four Activities.</string>
+ <string name="reorder_launch_four">Go to the fourth</string>
+ <string name="reorder_four_text">This is the last in a sequence of four Activities.</string>
+ <string name="reorder_second_to_front">Bring the second in front</string>
+
<string name="menu_from_xml_title">App/Menu/Inflate from XML</string>
<string name="menu_from_xml_instructions_press_menu">Select a menu resource and press the menu key.</string>
<string name="menu_from_xml_instructions_go_back">If you want to choose another menu resource, go back and re-run this activity.</string>
- <string name="voice_recognition">App/Voice Recognition</string>
+ <string name="voice_recognition">App/Voice Recognition</string>
<!-- ============================== -->
<!-- app/content examples strings -->
diff --git a/samples/ApiDemos/res/xml/searchable.xml b/samples/ApiDemos/res/xml/searchable.xml
index df0924891..df4ef7acc 100644
--- a/samples/ApiDemos/res/xml/searchable.xml
+++ b/samples/ApiDemos/res/xml/searchable.xml
@@ -22,6 +22,10 @@
android:hint="@string/search_hint"
android:searchMode="showSearchLabelAsBadge"
+ android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
+ android:voiceLanguageModel="free_form"
+ android:voicePromptText="@string/search_invoke"
+
android:searchSuggestAuthority="com.example.android.apis.SuggestionProvider"
android:searchSuggestSelection=" ? "
/>
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/ReorderFour.java b/samples/ApiDemos/src/com/example/android/apis/app/ReorderFour.java
new file mode 100644
index 000000000..cdff538f3
--- /dev/null
+++ b/samples/ApiDemos/src/com/example/android/apis/app/ReorderFour.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2009 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.example.android.apis.app;
+
+import com.example.android.apis.R;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+
+public class ReorderFour extends Activity {
+ @Override
+ protected void onCreate(Bundle savedState) {
+ super.onCreate(savedState);
+
+ setContentView(R.layout.reorder_four);
+
+ Button twoButton = (Button) findViewById(R.id.reorder_second_to_front);
+ twoButton.setOnClickListener(mClickListener);
+ }
+
+ private final OnClickListener mClickListener = new OnClickListener() {
+ public void onClick(View v) {
+ Intent intent = new Intent(ReorderFour.this, ReorderTwo.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
+ startActivity(intent);
+ }
+ };
+} \ No newline at end of file
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/ReorderOnLaunch.java b/samples/ApiDemos/src/com/example/android/apis/app/ReorderOnLaunch.java
new file mode 100644
index 000000000..58561848e
--- /dev/null
+++ b/samples/ApiDemos/src/com/example/android/apis/app/ReorderOnLaunch.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2009 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.example.android.apis.app;
+
+import com.example.android.apis.R;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+
+public class ReorderOnLaunch extends Activity {
+ @Override
+ protected void onCreate(Bundle savedState) {
+ super.onCreate(savedState);
+
+ setContentView(R.layout.reorder_on_launch);
+
+ Button twoButton = (Button) findViewById(R.id.reorder_launch_two);
+ twoButton.setOnClickListener(mClickListener);
+ }
+
+ private final OnClickListener mClickListener = new OnClickListener() {
+ public void onClick(View v) {
+ startActivity(new Intent(ReorderOnLaunch.this, ReorderTwo.class));
+ }
+ };
+} \ No newline at end of file
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/ReorderThree.java b/samples/ApiDemos/src/com/example/android/apis/app/ReorderThree.java
new file mode 100644
index 000000000..7f725a67b
--- /dev/null
+++ b/samples/ApiDemos/src/com/example/android/apis/app/ReorderThree.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2009 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.example.android.apis.app;
+
+import com.example.android.apis.R;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+
+public class ReorderThree extends Activity {
+ @Override
+ protected void onCreate(Bundle savedState) {
+ super.onCreate(savedState);
+
+ setContentView(R.layout.reorder_three);
+
+ Button twoButton = (Button) findViewById(R.id.reorder_launch_four);
+ twoButton.setOnClickListener(mClickListener);
+ }
+
+ private final OnClickListener mClickListener = new OnClickListener() {
+ public void onClick(View v) {
+ startActivity(new Intent(ReorderThree.this, ReorderFour.class));
+ }
+ };
+} \ No newline at end of file
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/ReorderTwo.java b/samples/ApiDemos/src/com/example/android/apis/app/ReorderTwo.java
new file mode 100644
index 000000000..a1521d0ad
--- /dev/null
+++ b/samples/ApiDemos/src/com/example/android/apis/app/ReorderTwo.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2009 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.example.android.apis.app;
+
+import com.example.android.apis.R;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+
+public class ReorderTwo extends Activity {
+ @Override
+ protected void onCreate(Bundle savedState) {
+ super.onCreate(savedState);
+
+ setContentView(R.layout.reorder_two);
+
+ Button twoButton = (Button) findViewById(R.id.reorder_launch_three);
+ twoButton.setOnClickListener(mClickListener);
+ }
+
+ private final OnClickListener mClickListener = new OnClickListener() {
+ public void onClick(View v) {
+ startActivity(new Intent(ReorderTwo.this, ReorderThree.class));
+ }
+ };
+} \ No newline at end of file
diff --git a/samples/ApiDemos/src/com/android/samples/app/VoiceRecognition.java b/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.java
index 35d94307d..a784e1587 100644
--- a/samples/ApiDemos/src/com/android/samples/app/VoiceRecognition.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.samples.app;
+package com.example.android.apis.app;
import android.app.Activity;
import android.content.Intent;
diff --git a/samples/ApiDemos/src/com/example/android/apis/graphics/ProxyDrawable.java b/samples/ApiDemos/src/com/example/android/apis/graphics/ProxyDrawable.java
index c6049910e..d26413461 100644
--- a/samples/ApiDemos/src/com/example/android/apis/graphics/ProxyDrawable.java
+++ b/samples/ApiDemos/src/com/example/android/apis/graphics/ProxyDrawable.java
@@ -24,6 +24,7 @@ import android.graphics.drawable.Drawable;
public class ProxyDrawable extends Drawable {
private Drawable mProxy;
+ private boolean mMutated;
public ProxyDrawable(Drawable target) {
mProxy = target;
@@ -88,5 +89,14 @@ public class ProxyDrawable extends Drawable {
mProxy.setAlpha(alpha);
}
}
+
+ @Override
+ public Drawable mutate() {
+ if (mProxy != null && !mMutated && super.mutate() == this) {
+ mProxy.mutate();
+ mMutated = true;
+ }
+ return this;
+ }
}
diff --git a/samples/GlobalTime/src/com/android/globaltime/GlobalTime.java b/samples/GlobalTime/src/com/android/globaltime/GlobalTime.java
index 90a02352b..d96b644a9 100644
--- a/samples/GlobalTime/src/com/android/globaltime/GlobalTime.java
+++ b/samples/GlobalTime/src/com/android/globaltime/GlobalTime.java
@@ -222,15 +222,19 @@ class GTView extends SurfaceView implements SurfaceHolder.Callback {
private float mMotionStartRotVelocity;
private float mMotionStartTiltAngle;
private int mMotionDirection;
-
+
+ private boolean mPaused = true;
+ private boolean mHaveSurface = false;
+ private boolean mStartAnimating = false;
+
public void surfaceCreated(SurfaceHolder holder) {
- EGL10 egl = (EGL10)EGLContext.getEGL();
- mEGLSurface = egl.eglCreateWindowSurface(mEGLDisplay, mEGLConfig, this, null);
- egl.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext);
+ mHaveSurface = true;
+ startEGL();
}
public void surfaceDestroyed(SurfaceHolder holder) {
- // nothing to do
+ mHaveSurface = false;
+ stopEGL();
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
@@ -249,59 +253,114 @@ class GTView extends SurfaceView implements SurfaceHolder.Callback {
getHolder().addCallback(this);
getHolder().setType(SurfaceHolder.SURFACE_TYPE_GPU);
- AssetManager am = context.getAssets();
startTime = System.currentTimeMillis();
- EGL10 egl = (EGL10)EGLContext.getEGL();
- EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
- int[] version = new int[2];
- egl.eglInitialize(dpy, version);
- int[] configSpec = {
- EGL10.EGL_DEPTH_SIZE, 16,
- EGL10.EGL_NONE
- };
- EGLConfig[] configs = new EGLConfig[1];
- int[] num_config = new int[1];
- egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config);
- mEGLConfig = configs[0];
- mEGLContext = egl.eglCreateContext(dpy, mEGLConfig, EGL10.EGL_NO_CONTEXT, null);
- mEGLDisplay = dpy;
-
mClock = new Clock();
+ startEGL();
+
setFocusable(true);
setFocusableInTouchMode(true);
requestFocus();
+ }
- try {
- loadAssets(am);
- } catch (IOException ioe) {
- ioe.printStackTrace();
- throw new RuntimeException(ioe);
- } catch (ArrayIndexOutOfBoundsException aioobe) {
- aioobe.printStackTrace();
- throw new RuntimeException(aioobe);
+ /**
+ * Creates an egl context. If the state of the activity is right, also
+ * creates the egl surface. Otherwise the surface will be created in a
+ * future call to createEGLSurface().
+ */
+ private void startEGL() {
+ EGL10 egl = (EGL10)EGLContext.getEGL();
+
+ if (mEGLContext == null) {
+ EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
+ int[] version = new int[2];
+ egl.eglInitialize(dpy, version);
+ int[] configSpec = {
+ EGL10.EGL_DEPTH_SIZE, 16,
+ EGL10.EGL_NONE
+ };
+ EGLConfig[] configs = new EGLConfig[1];
+ int[] num_config = new int[1];
+ egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config);
+ mEGLConfig = configs[0];
+
+ mEGLContext = egl.eglCreateContext(dpy, mEGLConfig,
+ EGL10.EGL_NO_CONTEXT, null);
+ mEGLDisplay = dpy;
+
+ AssetManager am = mContext.getAssets();
+ try {
+ loadAssets(am);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ throw new RuntimeException(ioe);
+ } catch (ArrayIndexOutOfBoundsException aioobe) {
+ aioobe.printStackTrace();
+ throw new RuntimeException(aioobe);
+ }
+ }
+
+ if (mEGLSurface == null && !mPaused && mHaveSurface) {
+ mEGLSurface = egl.eglCreateWindowSurface(mEGLDisplay, mEGLConfig,
+ this, null);
+ egl.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface,
+ mEGLContext);
+ mInitialized = false;
+ if (mStartAnimating) {
+ startAnimating();
+ mStartAnimating = false;
+ }
}
}
-
+
/**
- * Destroy the view.
+ * Destroys the egl context. If an egl surface has been created, it is
+ * destroyed as well.
*/
- public void destroy() {
+ private void stopEGL() {
EGL10 egl = (EGL10)EGLContext.getEGL();
- egl.eglMakeCurrent(mEGLDisplay,
- egl.EGL_NO_SURFACE, egl.EGL_NO_SURFACE, egl.EGL_NO_CONTEXT);
- egl.eglDestroyContext(mEGLDisplay, mEGLContext);
- egl.eglDestroySurface(mEGLDisplay, mEGLSurface);
- egl.eglTerminate(mEGLDisplay);
- mEGLContext = null;
+ if (mEGLSurface != null) {
+ egl.eglMakeCurrent(mEGLDisplay,
+ egl.EGL_NO_SURFACE, egl.EGL_NO_SURFACE, egl.EGL_NO_CONTEXT);
+ egl.eglDestroySurface(mEGLDisplay, mEGLSurface);
+ mEGLSurface = null;
+ }
+
+ if (mEGLContext != null) {
+ egl.eglDestroyContext(mEGLDisplay, mEGLContext);
+ egl.eglTerminate(mEGLDisplay);
+ mEGLContext = null;
+ mEGLDisplay = null;
+ mEGLConfig = null;
+ }
+ }
+
+ public void onPause() {
+ mPaused = true;
+ stopAnimating();
+ stopEGL();
+ }
+
+ public void onResume() {
+ mPaused = false;
+ startEGL();
+ }
+
+ public void destroy() {
+ stopAnimating();
+ stopEGL();
}
/**
* Begin animation.
*/
public void startAnimating() {
- mHandler.sendEmptyMessage(INVALIDATE);
+ if (mEGLSurface == null) {
+ mStartAnimating = true; // will start when egl surface is created
+ } else {
+ mHandler.sendEmptyMessage(INVALIDATE);
+ }
}
/**
@@ -1390,32 +1449,25 @@ public class GlobalTime extends Activity {
GTView gtView = null;
- private void setGTView() {
- if (gtView == null) {
- gtView = new GTView(this);
- setContentView(gtView);
- }
- }
-
@Override protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
- setGTView();
+ gtView = new GTView(this);
+ setContentView(gtView);
}
@Override protected void onResume() {
super.onResume();
- setGTView();
+ gtView.onResume();
Looper.myQueue().addIdleHandler(new Idler());
}
@Override protected void onPause() {
super.onPause();
- gtView.stopAnimating();
+ gtView.onPause();
}
@Override protected void onStop() {
super.onStop();
- gtView.stopAnimating();
gtView.destroy();
gtView = null;
}
diff --git a/samples/SoftKeyboard/res/values-land/dimens.xml b/samples/SoftKeyboard/res/values-land/dimens.xml
index 1929ae08d..b5f3bc128 100644
--- a/samples/SoftKeyboard/res/values-land/dimens.xml
+++ b/samples/SoftKeyboard/res/values-land/dimens.xml
@@ -19,5 +19,5 @@
-->
<resources>
- <dimen name="key_height">46px</dimen>
-</resources> \ No newline at end of file
+ <dimen name="key_height">46dip</dimen>
+</resources>
diff --git a/samples/SoftKeyboard/res/values/dimens.xml b/samples/SoftKeyboard/res/values/dimens.xml
index cdaf27a2d..caf615cfa 100644
--- a/samples/SoftKeyboard/res/values/dimens.xml
+++ b/samples/SoftKeyboard/res/values/dimens.xml
@@ -19,7 +19,7 @@
-->
<resources>
- <dimen name="key_height">50px</dimen>
+ <dimen name="key_height">50dip</dimen>
<dimen name="candidate_font_height">16sp</dimen>
<dimen name="candidate_vertical_padding">6sp</dimen>
</resources> \ No newline at end of file
diff --git a/samples/SoftKeyboard/src/com/example/android/softkeyboard/SoftKeyboard.java b/samples/SoftKeyboard/src/com/example/android/softkeyboard/SoftKeyboard.java
index d26b1730d..cc1174aa6 100644
--- a/samples/SoftKeyboard/src/com/example/android/softkeyboard/SoftKeyboard.java
+++ b/samples/SoftKeyboard/src/com/example/android/softkeyboard/SoftKeyboard.java
@@ -27,6 +27,7 @@ import android.view.View;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
+import android.view.inputmethod.InputMethodManager;
import java.util.ArrayList;
import java.util.List;
@@ -73,11 +74,19 @@ public class SoftKeyboard extends InputMethodService
private String mWordSeparators;
/**
- * Helper function to generate the various keyboard layouts used by the
- * input method. Takes care of regenerating the layouts if the width
- * of the input method changes.
+ * Main initialization of the input method component. Be sure to call
+ * to super class.
+ */
+ @Override public void onCreate() {
+ super.onCreate();
+ mWordSeparators = getResources().getString(R.string.word_separators);
+ }
+
+ /**
+ * This is the point where you can do all of your UI initialization. It
+ * is called after creation and any configuration change.
*/
- private void makeKeyboards() {
+ @Override public void onInitializeInterface() {
if (mQwertyKeyboard != null) {
// Configuration changes can happen after the keyboard gets recreated,
// so we need to be able to re-build the keyboards if the available
@@ -92,25 +101,12 @@ public class SoftKeyboard extends InputMethodService
}
/**
- * Main initialization of the input method component. Be sure to call
- * to super class.
- */
- @Override public void onCreate() {
- super.onCreate();
- makeKeyboards();
- mWordSeparators = getResources().getString(R.string.word_separators);
- }
-
- /**
* Called by the framework when your view for creating input needs to
* be generated. This will be called the first time your input method
* is displayed, and every time it needs to be re-created such as due to
* a configuration change.
*/
@Override public View onCreateInputView() {
- // We call makeKeyboards() here to regenerate them if needed due to
- // a configuration change.
- makeKeyboards();
mInputView = (KeyboardView) getLayoutInflater().inflate(
R.layout.input, null);
mInputView.setOnKeyboardActionListener(this);