OSDN Git Service

Add Multiple Resolutions (MultiRes) sample code.
authorRoman Nurik <romannurik@google.com>
Mon, 16 Nov 2009 20:23:42 +0000 (15:23 -0500)
committerRoman Nurik <romannurik@google.com>
Mon, 23 Nov 2009 16:44:11 +0000 (11:44 -0500)
29 files changed:
samples/MultiResolution/Android.mk [new file with mode: 0644]
samples/MultiResolution/AndroidManifest.xml [new file with mode: 0644]
samples/MultiResolution/_index.html [new file with mode: 0644]
samples/MultiResolution/res/drawable-hdpi-v6/ic_launcher.png [new file with mode: 0644]
samples/MultiResolution/res/drawable-hdpi/android.png [new file with mode: 0644]
samples/MultiResolution/res/drawable-hdpi/ic_launcher.png [new file with mode: 0644]
samples/MultiResolution/res/drawable-hdpi/image_container.9.png [new file with mode: 0644]
samples/MultiResolution/res/drawable-ldpi-v6/ic_launcher.png [new file with mode: 0644]
samples/MultiResolution/res/drawable-ldpi/android.png [new file with mode: 0644]
samples/MultiResolution/res/drawable-ldpi/ic_launcher.png [new file with mode: 0644]
samples/MultiResolution/res/drawable-ldpi/image_container.9.png [new file with mode: 0644]
samples/MultiResolution/res/drawable-mdpi-v6/ic_launcher.png [new file with mode: 0644]
samples/MultiResolution/res/drawable-mdpi/android.png [new file with mode: 0644]
samples/MultiResolution/res/drawable-mdpi/ic_launcher.png [new file with mode: 0644]
samples/MultiResolution/res/drawable-mdpi/image_container.9.png [new file with mode: 0644]
samples/MultiResolution/res/drawable/background.9.png [new file with mode: 0644]
samples/MultiResolution/res/drawable/icon.png [new file with mode: 0644]
samples/MultiResolution/res/drawable/sample_0.jpg [new file with mode: 0644]
samples/MultiResolution/res/drawable/sample_1.jpg [new file with mode: 0644]
samples/MultiResolution/res/drawable/sample_2.jpg [new file with mode: 0644]
samples/MultiResolution/res/drawable/sample_3.jpg [new file with mode: 0644]
samples/MultiResolution/res/drawable/sample_4.jpg [new file with mode: 0644]
samples/MultiResolution/res/drawable/sample_5.jpg [new file with mode: 0644]
samples/MultiResolution/res/drawable/sample_6.jpg [new file with mode: 0644]
samples/MultiResolution/res/drawable/sample_7.jpg [new file with mode: 0644]
samples/MultiResolution/res/layout-land/main.xml [new file with mode: 0644]
samples/MultiResolution/res/layout/main.xml [new file with mode: 0644]
samples/MultiResolution/res/values/strings.xml [new file with mode: 0644]
samples/MultiResolution/src/com/example/android/multires/MultiRes.java [new file with mode: 0644]

diff --git a/samples/MultiResolution/Android.mk b/samples/MultiResolution/Android.mk
new file mode 100644 (file)
index 0000000..4a5a038
--- /dev/null
@@ -0,0 +1,16 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := samples
+
+# Only compile source java files in this apk.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := MultiResolution
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_PACKAGE)
+
+# Use the following include to make our test apk.
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/samples/MultiResolution/AndroidManifest.xml b/samples/MultiResolution/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..4719069
--- /dev/null
@@ -0,0 +1,49 @@
+<?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.
+-->
+
+<manifest
+  xmlns:android="http://schemas.android.com/apk/res/android"
+  package="com.example.android.multires"
+  android:versionCode="1"
+  android:versionName="1.0">
+
+  <uses-permission
+    android:name="android.permission.INTERNET"/>
+
+  <application
+    android:icon="@drawable/ic_launcher"
+    android:label="@string/app_name">
+
+    <activity
+      android:name=".MultiRes"
+      android:label="@string/app_name">
+
+      <intent-filter>
+        <action
+          android:name="android.intent.action.MAIN"/>
+        <category
+          android:name="android.intent.category.LAUNCHER"/>
+      </intent-filter>
+
+    </activity>
+
+  </application>
+
+  <uses-sdk
+    android:minSdkVersion="3"
+    android:targetSdkVersion="4"/>
+
+</manifest>
diff --git a/samples/MultiResolution/_index.html b/samples/MultiResolution/_index.html
new file mode 100644 (file)
index 0000000..73089ae
--- /dev/null
@@ -0,0 +1,20 @@
+<p>A sample application that shows how to use resource directory qualifiers to
+show different resources to different screen configurations (layout orientation,
+screen resolution, screen density, etc.).
+
+It demonstrates using:
+<ul>
+<li><a href="../../../reference/android/graphics/NinePatch.html">9-Patch</a>
+  drawables for creating scalable/stretchable graphics.</li>
+<li>Proper layout <a href="../../../guide/practices/screens_support.html#density-independence">size units</a>,
+  such as scale-independent pixels (<code>sp</code>) and density-independent pixels (<code>dip</code>)</li>
+<li><a href="../../../guide/practices/screens_support.html#qualifiers">Resource directory qualifiers</a>
+  such as <code>-land</code>, <code>-mdpi</code>, and <code>-hdpi</code> to customize
+  resources such as layouts and graphical assets for different screen configurations</li>
+<li>Resource directory qualifiers such as <code>-v4</code> and <code>-v6</code>
+  to show different application icons based on platform version, for
+  consistency with system icon styles.</li>
+</ul>
+</p>
+
+<img alt="" src="../images/sample_multires.png"/>
diff --git a/samples/MultiResolution/res/drawable-hdpi-v6/ic_launcher.png b/samples/MultiResolution/res/drawable-hdpi-v6/ic_launcher.png
new file mode 100644 (file)
index 0000000..4964740
Binary files /dev/null and b/samples/MultiResolution/res/drawable-hdpi-v6/ic_launcher.png differ
diff --git a/samples/MultiResolution/res/drawable-hdpi/android.png b/samples/MultiResolution/res/drawable-hdpi/android.png
new file mode 100644 (file)
index 0000000..6ea86cf
Binary files /dev/null and b/samples/MultiResolution/res/drawable-hdpi/android.png differ
diff --git a/samples/MultiResolution/res/drawable-hdpi/ic_launcher.png b/samples/MultiResolution/res/drawable-hdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..122ba8e
Binary files /dev/null and b/samples/MultiResolution/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/MultiResolution/res/drawable-hdpi/image_container.9.png b/samples/MultiResolution/res/drawable-hdpi/image_container.9.png
new file mode 100644 (file)
index 0000000..b0379ef
Binary files /dev/null and b/samples/MultiResolution/res/drawable-hdpi/image_container.9.png differ
diff --git a/samples/MultiResolution/res/drawable-ldpi-v6/ic_launcher.png b/samples/MultiResolution/res/drawable-ldpi-v6/ic_launcher.png
new file mode 100644 (file)
index 0000000..2d12433
Binary files /dev/null and b/samples/MultiResolution/res/drawable-ldpi-v6/ic_launcher.png differ
diff --git a/samples/MultiResolution/res/drawable-ldpi/android.png b/samples/MultiResolution/res/drawable-ldpi/android.png
new file mode 100644 (file)
index 0000000..6cfb3cc
Binary files /dev/null and b/samples/MultiResolution/res/drawable-ldpi/android.png differ
diff --git a/samples/MultiResolution/res/drawable-ldpi/ic_launcher.png b/samples/MultiResolution/res/drawable-ldpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..f5ded00
Binary files /dev/null and b/samples/MultiResolution/res/drawable-ldpi/ic_launcher.png differ
diff --git a/samples/MultiResolution/res/drawable-ldpi/image_container.9.png b/samples/MultiResolution/res/drawable-ldpi/image_container.9.png
new file mode 100644 (file)
index 0000000..406d358
Binary files /dev/null and b/samples/MultiResolution/res/drawable-ldpi/image_container.9.png differ
diff --git a/samples/MultiResolution/res/drawable-mdpi-v6/ic_launcher.png b/samples/MultiResolution/res/drawable-mdpi-v6/ic_launcher.png
new file mode 100644 (file)
index 0000000..3da3d17
Binary files /dev/null and b/samples/MultiResolution/res/drawable-mdpi-v6/ic_launcher.png differ
diff --git a/samples/MultiResolution/res/drawable-mdpi/android.png b/samples/MultiResolution/res/drawable-mdpi/android.png
new file mode 100644 (file)
index 0000000..c570385
Binary files /dev/null and b/samples/MultiResolution/res/drawable-mdpi/android.png differ
diff --git a/samples/MultiResolution/res/drawable-mdpi/ic_launcher.png b/samples/MultiResolution/res/drawable-mdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..47e79a7
Binary files /dev/null and b/samples/MultiResolution/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/MultiResolution/res/drawable-mdpi/image_container.9.png b/samples/MultiResolution/res/drawable-mdpi/image_container.9.png
new file mode 100644 (file)
index 0000000..7dd9895
Binary files /dev/null and b/samples/MultiResolution/res/drawable-mdpi/image_container.9.png differ
diff --git a/samples/MultiResolution/res/drawable/background.9.png b/samples/MultiResolution/res/drawable/background.9.png
new file mode 100644 (file)
index 0000000..561cce8
Binary files /dev/null and b/samples/MultiResolution/res/drawable/background.9.png differ
diff --git a/samples/MultiResolution/res/drawable/icon.png b/samples/MultiResolution/res/drawable/icon.png
new file mode 100644 (file)
index 0000000..7502484
Binary files /dev/null and b/samples/MultiResolution/res/drawable/icon.png differ
diff --git a/samples/MultiResolution/res/drawable/sample_0.jpg b/samples/MultiResolution/res/drawable/sample_0.jpg
new file mode 100644 (file)
index 0000000..9dd3bce
Binary files /dev/null and b/samples/MultiResolution/res/drawable/sample_0.jpg differ
diff --git a/samples/MultiResolution/res/drawable/sample_1.jpg b/samples/MultiResolution/res/drawable/sample_1.jpg
new file mode 100644 (file)
index 0000000..46d06e0
Binary files /dev/null and b/samples/MultiResolution/res/drawable/sample_1.jpg differ
diff --git a/samples/MultiResolution/res/drawable/sample_2.jpg b/samples/MultiResolution/res/drawable/sample_2.jpg
new file mode 100644 (file)
index 0000000..c23dd63
Binary files /dev/null and b/samples/MultiResolution/res/drawable/sample_2.jpg differ
diff --git a/samples/MultiResolution/res/drawable/sample_3.jpg b/samples/MultiResolution/res/drawable/sample_3.jpg
new file mode 100644 (file)
index 0000000..0f0d5b5
Binary files /dev/null and b/samples/MultiResolution/res/drawable/sample_3.jpg differ
diff --git a/samples/MultiResolution/res/drawable/sample_4.jpg b/samples/MultiResolution/res/drawable/sample_4.jpg
new file mode 100644 (file)
index 0000000..d28ce6f
Binary files /dev/null and b/samples/MultiResolution/res/drawable/sample_4.jpg differ
diff --git a/samples/MultiResolution/res/drawable/sample_5.jpg b/samples/MultiResolution/res/drawable/sample_5.jpg
new file mode 100644 (file)
index 0000000..2348c7d
Binary files /dev/null and b/samples/MultiResolution/res/drawable/sample_5.jpg differ
diff --git a/samples/MultiResolution/res/drawable/sample_6.jpg b/samples/MultiResolution/res/drawable/sample_6.jpg
new file mode 100644 (file)
index 0000000..a35fc0c
Binary files /dev/null and b/samples/MultiResolution/res/drawable/sample_6.jpg differ
diff --git a/samples/MultiResolution/res/drawable/sample_7.jpg b/samples/MultiResolution/res/drawable/sample_7.jpg
new file mode 100644 (file)
index 0000000..96a4879
Binary files /dev/null and b/samples/MultiResolution/res/drawable/sample_7.jpg differ
diff --git a/samples/MultiResolution/res/layout-land/main.xml b/samples/MultiResolution/res/layout-land/main.xml
new file mode 100644 (file)
index 0000000..01272d0
--- /dev/null
@@ -0,0 +1,74 @@
+<?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.
+-->
+
+<LinearLayout
+  xmlns:android="http://schemas.android.com/apk/res/android"
+  android:layout_width="fill_parent"
+  android:layout_height="fill_parent"
+  android:orientation="horizontal"
+  android:background="@drawable/background">
+
+  <LinearLayout
+    android:layout_weight="1"
+    android:orientation="vertical"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent">
+
+    <!-- Notice that widget sizes are expressed in dip, or device-independent
+         pixels, while text sizes are expressed in sp, or scale-independent
+         pixels, to factor in user-chosen font sizes. -->
+    <FrameLayout
+      android:background="@drawable/image_container"
+      android:layout_width="fill_parent"
+      android:layout_height="fill_parent"
+      android:id="@+id/image_container">
+      <ImageView
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:id="@+id/image_view"
+        android:scaleType="fitCenter"/>
+      <TextView
+        android:text="-"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="bottom|center_horizontal"
+        android:id="@+id/status_text"
+        android:textColor="@android:color/primary_text_dark"
+        android:textSize="16sp"
+        android:shadowDx="1.0"
+        android:shadowDy="1.0"
+        android:shadowRadius="1"
+        android:layout_margin="5dip"
+        android:shadowColor="@android:color/background_dark"/>
+    </FrameLayout>
+  </LinearLayout>
+
+  <LinearLayout
+    android:layout_width="wrap_content"
+    android:layout_height="fill_parent"
+    android:orientation="vertical"
+    android:layout_marginLeft="10dip"
+    android:gravity="top">
+    <Button
+      android:text="@string/next_button"
+      android:id="@+id/next_button"
+      android:layout_width="wrap_content"
+      android:layout_height="wrap_content"
+      android:drawableLeft="@drawable/android"
+      android:textSize="24sp"/>
+  </LinearLayout>
+
+</LinearLayout>
diff --git a/samples/MultiResolution/res/layout/main.xml b/samples/MultiResolution/res/layout/main.xml
new file mode 100644 (file)
index 0000000..3b06234
--- /dev/null
@@ -0,0 +1,72 @@
+<?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.
+-->
+
+<LinearLayout
+  xmlns:android="http://schemas.android.com/apk/res/android"
+  android:layout_width="fill_parent"
+  android:layout_height="fill_parent"
+  android:orientation="vertical"
+  android:background="@drawable/background">
+
+  <LinearLayout
+    android:layout_weight="1"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent">
+
+    <!-- Notice that widget sizes are expressed in dip, or device-independent
+         pixels, while text sizes are expressed in sp, or scale-independent
+         pixels, to factor in user-chosen font sizes. -->
+    <FrameLayout
+      android:layout_width="fill_parent"
+      android:layout_height="fill_parent"
+      android:id="@+id/image_container"
+      android:background="@drawable/image_container">
+      <ImageView
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:id="@+id/image_view"
+        android:scaleType="fitCenter"/>
+      <TextView
+        android:text="-"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="bottom|center_horizontal"
+        android:id="@+id/status_text"
+        android:textColor="@android:color/primary_text_dark"
+        android:textSize="16sp"
+        android:shadowDx="1.0"
+        android:shadowDy="1.0"
+        android:shadowRadius="1"
+        android:layout_margin="5dip"
+        android:shadowColor="@android:color/background_dark"/>
+    </FrameLayout>
+  </LinearLayout>
+
+  <LinearLayout
+    android:layout_width="fill_parent"
+    android:layout_height="wrap_content"
+    android:layout_marginTop="10dip"
+    android:gravity="center">
+    <Button
+      android:text="@string/next_button"
+      android:id="@+id/next_button"
+      android:layout_width="wrap_content"
+      android:layout_height="wrap_content"
+      android:drawableLeft="@drawable/android"
+      android:textSize="24sp"/>
+  </LinearLayout>
+
+</LinearLayout>
diff --git a/samples/MultiResolution/res/values/strings.xml b/samples/MultiResolution/res/values/strings.xml
new file mode 100644 (file)
index 0000000..be3a410
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="app_name">MultiRes</string>
+    <string name="next_button">Next</string>
+</resources>
diff --git a/samples/MultiResolution/src/com/example/android/multires/MultiRes.java b/samples/MultiResolution/src/com/example/android/multires/MultiRes.java
new file mode 100644 (file)
index 0000000..a89f960
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * 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.multires;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+public final class MultiRes extends Activity {
+
+    private int mCurrentPhotoIndex = 0;
+    private int[] mPhotoIds = new int[] { R.drawable.sample_0,
+            R.drawable.sample_1, R.drawable.sample_2, R.drawable.sample_3,
+            R.drawable.sample_4, R.drawable.sample_5, R.drawable.sample_6,
+            R.drawable.sample_7 };
+
+    /** Called when the activity is first created. */
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.main);
+
+        showPhoto(mCurrentPhotoIndex);
+
+        // Handle clicks on the 'Next' button.
+        Button nextButton = (Button) findViewById(R.id.next_button);
+        nextButton.setOnClickListener(new View.OnClickListener() {
+            public void onClick(View v) {
+                mCurrentPhotoIndex = (mCurrentPhotoIndex + 1)
+                        % mPhotoIds.length;
+                showPhoto(mCurrentPhotoIndex);
+            }
+        });
+    }
+
+    @Override
+    protected void onSaveInstanceState(Bundle outState) {
+        outState.putInt("photo_index", mCurrentPhotoIndex);
+        super.onSaveInstanceState(outState);
+    }
+
+    @Override
+    protected void onRestoreInstanceState(Bundle savedInstanceState) {
+        mCurrentPhotoIndex = savedInstanceState.getInt("photo_index");
+        showPhoto(mCurrentPhotoIndex);
+        super.onRestoreInstanceState(savedInstanceState);
+    }
+
+    private void showPhoto(int photoIndex) {
+        ImageView imageView = (ImageView) findViewById(R.id.image_view);
+        imageView.setImageResource(mPhotoIds[photoIndex]);
+
+        TextView statusText = (TextView) findViewById(R.id.status_text);
+        statusText.setText(String.format("%d/%d", photoIndex + 1,
+                mPhotoIds.length));
+    }
+}