diff options
| author | Jean-Baptiste Queru <jbq@google.com> | 2009-07-09 11:24:20 -0700 |
|---|---|---|
| committer | Jean-Baptiste Queru <jbq@google.com> | 2009-07-09 11:24:20 -0700 |
| commit | 9237d93cdac6a2bb8cd95b157d90517cfde0f740 (patch) | |
| tree | 5f1fe2a42753ce5982c037a32cf63c0e2829647d /samples | |
| parent | 71bc71e1680839c99f0a3a6e2ad045337b779d7d (diff) | |
| parent | 8bbfa508be9430ef8a964af02942ac854a0f9cbb (diff) | |
| download | android_development-9237d93cdac6a2bb8cd95b157d90517cfde0f740.tar.gz android_development-9237d93cdac6a2bb8cd95b157d90517cfde0f740.tar.bz2 android_development-9237d93cdac6a2bb8cd95b157d90517cfde0f740.zip | |
Merge branch 'master' of git://android.git.kernel.org/platform/development into merge_korg_master
* 'master' of git://android.git.kernel.org/platform/development:
Value for windows condition is missing a dot before "exe". "adbexe" should be "adb.exe"
Add the FixedGridLayout sample code.
Fix NullPointer exception in function getBrokenAvds()
Diffstat (limited to 'samples')
| -rw-r--r-- | samples/FixedGridLayout/Android.mk | 12 | ||||
| -rw-r--r-- | samples/FixedGridLayout/AndroidManifest.xml | 15 | ||||
| -rw-r--r-- | samples/FixedGridLayout/res/drawable/bugdroid.png | bin | 0 -> 3019 bytes | |||
| -rw-r--r-- | samples/FixedGridLayout/res/layout/main.xml | 42 | ||||
| -rw-r--r-- | samples/FixedGridLayout/res/values/attrs.xml | 7 | ||||
| -rw-r--r-- | samples/FixedGridLayout/res/values/strings.xml | 4 | ||||
| -rw-r--r-- | samples/FixedGridLayout/src/com/example/android/fixedgridlayout/FixedGridLayout.java | 119 | ||||
| -rw-r--r-- | samples/FixedGridLayout/src/com/example/android/fixedgridlayout/FixedGridLayoutTest.java | 19 |
8 files changed, 218 insertions, 0 deletions
diff --git a/samples/FixedGridLayout/Android.mk b/samples/FixedGridLayout/Android.mk new file mode 100644 index 000000000..1562cb95c --- /dev/null +++ b/samples/FixedGridLayout/Android.mk @@ -0,0 +1,12 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := samples + +LOCAL_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_PACKAGE_NAME := FixedGridLayout + +LOCAL_SDK_VERSION := current + +include $(BUILD_PACKAGE) diff --git a/samples/FixedGridLayout/AndroidManifest.xml b/samples/FixedGridLayout/AndroidManifest.xml new file mode 100644 index 000000000..9acd309ab --- /dev/null +++ b/samples/FixedGridLayout/AndroidManifest.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.android.fixedgridlayout" + android:versionCode="1" + android:versionName="1.0"> + <application android:label="@string/app_name"> + <activity android:name=".FixedGridLayoutTest" + 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> +</manifest> diff --git a/samples/FixedGridLayout/res/drawable/bugdroid.png b/samples/FixedGridLayout/res/drawable/bugdroid.png Binary files differnew file mode 100644 index 000000000..855484a2d --- /dev/null +++ b/samples/FixedGridLayout/res/drawable/bugdroid.png diff --git a/samples/FixedGridLayout/res/layout/main.xml b/samples/FixedGridLayout/res/layout/main.xml new file mode 100644 index 000000000..93e2d5e92 --- /dev/null +++ b/samples/FixedGridLayout/res/layout/main.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="utf-8"?> +<com.example.android.fixedgridlayout.FixedGridLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res/com.example.android.fixedgridlayout" + android:id="@+id/grid" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + app:cellWidth="80dp" + app:cellHeight="100dp" + > + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/bugdroid" + /> + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/bugdroid" + /> + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/bugdroid" + /> + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/bugdroid" + /> + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/bugdroid" + /> + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/bugdroid" + /> +</com.example.android.fixedgridlayout.FixedGridLayout> + diff --git a/samples/FixedGridLayout/res/values/attrs.xml b/samples/FixedGridLayout/res/values/attrs.xml new file mode 100644 index 000000000..8287d0e02 --- /dev/null +++ b/samples/FixedGridLayout/res/values/attrs.xml @@ -0,0 +1,7 @@ +<resources> + <declare-styleable name="FixedGridLayout"> + <attr name="cellWidth" format="dimension" /> + <attr name="cellHeight" format="dimension" /> + </declare-styleable> +</resources> + diff --git a/samples/FixedGridLayout/res/values/strings.xml b/samples/FixedGridLayout/res/values/strings.xml new file mode 100644 index 000000000..14563c7df --- /dev/null +++ b/samples/FixedGridLayout/res/values/strings.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="app_name">FixedGridLayoutTest</string> +</resources> diff --git a/samples/FixedGridLayout/src/com/example/android/fixedgridlayout/FixedGridLayout.java b/samples/FixedGridLayout/src/com/example/android/fixedgridlayout/FixedGridLayout.java new file mode 100644 index 000000000..413157f22 --- /dev/null +++ b/samples/FixedGridLayout/src/com/example/android/fixedgridlayout/FixedGridLayout.java @@ -0,0 +1,119 @@ +/* + * 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.fixedgridlayout; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; +import android.util.SparseIntArray; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewDebug; + +/** + * A layout that arranges its children in a grid. The size of the + * cells is set by the {@link #setCellSize} method and the + * android:cell_width and android:cell_height attributes in XML. + * The number of rows and columns is determined at runtime. Each + * cell contains exactly one view, and they flow in the natural + * child order (the order in which they were added, or the index + * in {@link #addViewAt}. Views can not span multiple cells. + */ +public class FixedGridLayout extends ViewGroup { + int mCellWidth; + int mCellHeight; + + public FixedGridLayout(Context context) { + super(context); + } + + public FixedGridLayout(Context context, AttributeSet attrs) { + super(context, attrs); + + // Read the resource attributes. + TypedArray a = context.obtainStyledAttributes( + attrs, R.styleable.FixedGridLayout); + mCellWidth = a.getDimensionPixelSize( + R.styleable.FixedGridLayout_cellWidth, -1); + mCellHeight = a.getDimensionPixelSize( + R.styleable.FixedGridLayout_cellHeight, -1); + a.recycle(); + } + + public void setCellWidth(int px) { + mCellWidth = px; + requestLayout(); + } + + public void setCellHeight(int px) { + mCellHeight = px; + requestLayout(); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + int cellWidthSpec = MeasureSpec.makeMeasureSpec(mCellWidth, + MeasureSpec.AT_MOST); + int cellHeightSpec = MeasureSpec.makeMeasureSpec(mCellHeight, + MeasureSpec.AT_MOST); + + int count = getChildCount(); + for (int index=0; index<count; index++) { + final View child = getChildAt(index); + child.measure(cellWidthSpec, cellHeightSpec); + } + // Use the size our parents gave us + setMeasuredDimension(resolveSize(mCellWidth*count, widthMeasureSpec), + resolveSize(mCellHeight*count, heightMeasureSpec)); + } + + @Override + protected void onLayout(boolean changed, int l, int t, int r, int b) { + int cellWidth = mCellWidth; + int cellHeight = mCellHeight; + int columns = (r - l) / cellWidth; + if (columns < 0) { + columns = 1; + } + int x = 0; + int y = 0; + int i = 0; + int count = getChildCount(); + for (int index=0; index<count; index++) { + final View child = getChildAt(index); + + int w = child.getMeasuredWidth(); + int h = child.getMeasuredHeight(); + + int left = x + ((cellWidth-w)/2); + int top = y + ((cellHeight-h)/2); + + child.layout(left, top, left+w, top+h); + if (i >= (columns-1)) { + // advance to next row + i = 0; + x = 0; + y += cellHeight; + } else { + i++; + x += cellWidth; + } + } + } +} + diff --git a/samples/FixedGridLayout/src/com/example/android/fixedgridlayout/FixedGridLayoutTest.java b/samples/FixedGridLayout/src/com/example/android/fixedgridlayout/FixedGridLayoutTest.java new file mode 100644 index 000000000..19c9da7dc --- /dev/null +++ b/samples/FixedGridLayout/src/com/example/android/fixedgridlayout/FixedGridLayoutTest.java @@ -0,0 +1,19 @@ +package com.example.android.fixedgridlayout; + +import android.app.Activity; +import android.os.Bundle; + +public class FixedGridLayoutTest extends Activity +{ + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + FixedGridLayout grid = (FixedGridLayout)findViewById(R.id.grid); + grid.setCellWidth(80); + grid.setCellHeight(80); + } +} |
