diff options
| author | Roman Nurik <romannurik@google.com> | 2009-11-16 15:23:42 -0500 |
|---|---|---|
| committer | Roman Nurik <romannurik@google.com> | 2009-11-23 11:44:11 -0500 |
| commit | d7f64d53388359b0b3a595a7d5692edcae8a144e (patch) | |
| tree | 7f293df5c9e9e5a75735bd7f9034355b0d50fe32 /samples/MultiResolution | |
| parent | 13dbc2272e41a55f6b8de35102d60eed35c9faa7 (diff) | |
| download | android_development-d7f64d53388359b0b3a595a7d5692edcae8a144e.tar.gz android_development-d7f64d53388359b0b3a595a7d5692edcae8a144e.tar.bz2 android_development-d7f64d53388359b0b3a595a7d5692edcae8a144e.zip | |
Add Multiple Resolutions (MultiRes) sample code.
Diffstat (limited to 'samples/MultiResolution')
29 files changed, 310 insertions, 0 deletions
diff --git a/samples/MultiResolution/Android.mk b/samples/MultiResolution/Android.mk new file mode 100644 index 000000000..4a5a038a3 --- /dev/null +++ b/samples/MultiResolution/Android.mk @@ -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 index 000000000..4719069ec --- /dev/null +++ b/samples/MultiResolution/AndroidManifest.xml @@ -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 index 000000000..73089ae64 --- /dev/null +++ b/samples/MultiResolution/_index.html @@ -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 Binary files differnew file mode 100644 index 000000000..496474017 --- /dev/null +++ b/samples/MultiResolution/res/drawable-hdpi-v6/ic_launcher.png diff --git a/samples/MultiResolution/res/drawable-hdpi/android.png b/samples/MultiResolution/res/drawable-hdpi/android.png Binary files differnew file mode 100644 index 000000000..6ea86cf44 --- /dev/null +++ b/samples/MultiResolution/res/drawable-hdpi/android.png diff --git a/samples/MultiResolution/res/drawable-hdpi/ic_launcher.png b/samples/MultiResolution/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..122ba8eec --- /dev/null +++ b/samples/MultiResolution/res/drawable-hdpi/ic_launcher.png diff --git a/samples/MultiResolution/res/drawable-hdpi/image_container.9.png b/samples/MultiResolution/res/drawable-hdpi/image_container.9.png Binary files differnew file mode 100644 index 000000000..b0379efb3 --- /dev/null +++ b/samples/MultiResolution/res/drawable-hdpi/image_container.9.png diff --git a/samples/MultiResolution/res/drawable-ldpi-v6/ic_launcher.png b/samples/MultiResolution/res/drawable-ldpi-v6/ic_launcher.png Binary files differnew file mode 100644 index 000000000..2d1243395 --- /dev/null +++ b/samples/MultiResolution/res/drawable-ldpi-v6/ic_launcher.png diff --git a/samples/MultiResolution/res/drawable-ldpi/android.png b/samples/MultiResolution/res/drawable-ldpi/android.png Binary files differnew file mode 100644 index 000000000..6cfb3cc4b --- /dev/null +++ b/samples/MultiResolution/res/drawable-ldpi/android.png diff --git a/samples/MultiResolution/res/drawable-ldpi/ic_launcher.png b/samples/MultiResolution/res/drawable-ldpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..f5ded0011 --- /dev/null +++ b/samples/MultiResolution/res/drawable-ldpi/ic_launcher.png diff --git a/samples/MultiResolution/res/drawable-ldpi/image_container.9.png b/samples/MultiResolution/res/drawable-ldpi/image_container.9.png Binary files differnew file mode 100644 index 000000000..406d358ac --- /dev/null +++ b/samples/MultiResolution/res/drawable-ldpi/image_container.9.png diff --git a/samples/MultiResolution/res/drawable-mdpi-v6/ic_launcher.png b/samples/MultiResolution/res/drawable-mdpi-v6/ic_launcher.png Binary files differnew file mode 100644 index 000000000..3da3d17f2 --- /dev/null +++ b/samples/MultiResolution/res/drawable-mdpi-v6/ic_launcher.png diff --git a/samples/MultiResolution/res/drawable-mdpi/android.png b/samples/MultiResolution/res/drawable-mdpi/android.png Binary files differnew file mode 100644 index 000000000..c5703853f --- /dev/null +++ b/samples/MultiResolution/res/drawable-mdpi/android.png diff --git a/samples/MultiResolution/res/drawable-mdpi/ic_launcher.png b/samples/MultiResolution/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..47e79a77b --- /dev/null +++ b/samples/MultiResolution/res/drawable-mdpi/ic_launcher.png diff --git a/samples/MultiResolution/res/drawable-mdpi/image_container.9.png b/samples/MultiResolution/res/drawable-mdpi/image_container.9.png Binary files differnew file mode 100644 index 000000000..7dd98959e --- /dev/null +++ b/samples/MultiResolution/res/drawable-mdpi/image_container.9.png diff --git a/samples/MultiResolution/res/drawable/background.9.png b/samples/MultiResolution/res/drawable/background.9.png Binary files differnew file mode 100644 index 000000000..561cce829 --- /dev/null +++ b/samples/MultiResolution/res/drawable/background.9.png diff --git a/samples/MultiResolution/res/drawable/icon.png b/samples/MultiResolution/res/drawable/icon.png Binary files differnew file mode 100644 index 000000000..75024841d --- /dev/null +++ b/samples/MultiResolution/res/drawable/icon.png diff --git a/samples/MultiResolution/res/drawable/sample_0.jpg b/samples/MultiResolution/res/drawable/sample_0.jpg Binary files differnew file mode 100644 index 000000000..9dd3bce88 --- /dev/null +++ b/samples/MultiResolution/res/drawable/sample_0.jpg diff --git a/samples/MultiResolution/res/drawable/sample_1.jpg b/samples/MultiResolution/res/drawable/sample_1.jpg Binary files differnew file mode 100644 index 000000000..46d06e028 --- /dev/null +++ b/samples/MultiResolution/res/drawable/sample_1.jpg diff --git a/samples/MultiResolution/res/drawable/sample_2.jpg b/samples/MultiResolution/res/drawable/sample_2.jpg Binary files differnew file mode 100644 index 000000000..c23dd6371 --- /dev/null +++ b/samples/MultiResolution/res/drawable/sample_2.jpg diff --git a/samples/MultiResolution/res/drawable/sample_3.jpg b/samples/MultiResolution/res/drawable/sample_3.jpg Binary files differnew file mode 100644 index 000000000..0f0d5b538 --- /dev/null +++ b/samples/MultiResolution/res/drawable/sample_3.jpg diff --git a/samples/MultiResolution/res/drawable/sample_4.jpg b/samples/MultiResolution/res/drawable/sample_4.jpg Binary files differnew file mode 100644 index 000000000..d28ce6f30 --- /dev/null +++ b/samples/MultiResolution/res/drawable/sample_4.jpg diff --git a/samples/MultiResolution/res/drawable/sample_5.jpg b/samples/MultiResolution/res/drawable/sample_5.jpg Binary files differnew file mode 100644 index 000000000..2348c7d39 --- /dev/null +++ b/samples/MultiResolution/res/drawable/sample_5.jpg diff --git a/samples/MultiResolution/res/drawable/sample_6.jpg b/samples/MultiResolution/res/drawable/sample_6.jpg Binary files differnew file mode 100644 index 000000000..a35fc0ce7 --- /dev/null +++ b/samples/MultiResolution/res/drawable/sample_6.jpg diff --git a/samples/MultiResolution/res/drawable/sample_7.jpg b/samples/MultiResolution/res/drawable/sample_7.jpg Binary files differnew file mode 100644 index 000000000..96a4879e8 --- /dev/null +++ b/samples/MultiResolution/res/drawable/sample_7.jpg diff --git a/samples/MultiResolution/res/layout-land/main.xml b/samples/MultiResolution/res/layout-land/main.xml new file mode 100644 index 000000000..01272d047 --- /dev/null +++ b/samples/MultiResolution/res/layout-land/main.xml @@ -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 index 000000000..3b06234f3 --- /dev/null +++ b/samples/MultiResolution/res/layout/main.xml @@ -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 index 000000000..be3a41099 --- /dev/null +++ b/samples/MultiResolution/res/values/strings.xml @@ -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 index 000000000..a89f96057 --- /dev/null +++ b/samples/MultiResolution/src/com/example/android/multires/MultiRes.java @@ -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)); + } +} |
