am 63c90a55: Add grid layout support library samples.

* commit '63c90a5512fa5427d924fa2ae21a386d9c2845dc':
  Add grid layout support library samples.
This commit is contained in:
Jeff Brown
2013-03-21 02:10:08 +00:00
committed by Android Git Automerger
9 changed files with 420 additions and 0 deletions

View File

@@ -60,5 +60,29 @@
<action android:name="android.media.MediaRouteProviderService" />
</intent-filter>
</service>
<!-- GridLayout Support Samples -->
<activity android:name=".view.GridLayout1" android:label="Views/Layouts/GridLayout/1. Simple Form">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.supportv7.SUPPORT4_SAMPLE_CODE" />
</intent-filter>
</activity>
<activity android:name=".view.GridLayout2" android:label="Views/Layouts/GridLayout/2. Form (XML)">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.supportv7.SUPPORT4_SAMPLE_CODE" />
</intent-filter>
</activity>
<activity android:name=".view.GridLayout3" android:label="Views/Layouts/GridLayout/3. Form (Java)">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.supportv7.SUPPORT4_SAMPLE_CODE" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 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.
-->
<android.support.v7.widget.GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:useDefaultMargins="true"
app:alignmentMode="alignBounds"
app:rowOrderPreserved="false"
app:columnCount="4"
>
<TextView
android:text="Email setup"
android:textSize="32dip"
app:layout_columnSpan="4"
app:layout_gravity="center_horizontal"
/>
<TextView
android:text="You can configure email in a few simple steps:"
android:textSize="16dip"
app:layout_columnSpan="4"
app:layout_gravity="left"
/>
<TextView
android:text="Email address:"
app:layout_gravity="right"
/>
<EditText
android:ems="10"
/>
<TextView
android:text="Password:"
app:layout_column="0"
app:layout_gravity="right"
/>
<EditText
android:ems="8"
/>
<Button
android:text="Manual setup"
app:layout_row="5"
app:layout_column="3"
/>
<Button
android:text="Next"
app:layout_column="3"
app:layout_gravity="fill_horizontal"
/>
</android.support.v7.widget.GridLayout>

View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 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 GridLayout to build the "Simple Form" from the
LinearLayout and RelativeLayout demos.
-->
<android.support.v7.widget.GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/blue"
android:padding="10dip"
app:columnCount="4"
>
<TextView
android:text="@string/grid_layout_1_instructions"
/>
<EditText
app:layout_gravity="fill_horizontal"
app:layout_column="0"
app:layout_columnSpan="4"
/>
<Button
android:text="@string/grid_layout_1_cancel"
app:layout_column="2"
/>
<Button
android:text="@string/grid_layout_1_ok"
android:layout_marginLeft="10dip"
/>
</android.support.v7.widget.GridLayout>

View File

@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 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.
-->
<android.support.v7.widget.GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:useDefaultMargins="true"
app:alignmentMode="alignBounds"
app:columnOrderPreserved="false"
app:columnCount="4"
>
<TextView
android:text="Email setup"
android:textSize="32dip"
app:layout_columnSpan="4"
app:layout_gravity="center_horizontal"
/>
<TextView
android:text="You can configure email in a few simple steps:"
android:textSize="16dip"
app:layout_columnSpan="4"
app:layout_gravity="left"
/>
<TextView
android:text="Email address:"
app:layout_gravity="right"
/>
<EditText
android:ems="10"
/>
<TextView
android:text="Password:"
app:layout_column="0"
app:layout_gravity="right"
/>
<EditText
android:ems="8"
/>
<Button
android:text="Manual setup"
app:layout_row="5"
app:layout_column="3"
/>
<Button
android:text="Next"
app:layout_column="3"
app:layout_gravity="fill_horizontal"
/>
</android.support.v7.widget.GridLayout>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 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.
-->
<resources>
<drawable name="blue">#770000ff</drawable>
</resources>

View File

@@ -30,4 +30,10 @@
<string name="sample_media_route_provider_service">Media Route Provider Service Support Library Sample</string>
<string name="fixed_volume_route_name">Fixed Volume Remote Playback Route</string>
<string name="variable_volume_route_name">Variable Volume Remote Playback Route</string>
<!-- GridLayout -->
<string name="grid_layout_1_instructions">Type here:</string>
<string name="grid_layout_1_ok">Ok</string>
<string name="grid_layout_1_cancel">Cancel</string>
</resources>

View File

@@ -0,0 +1,34 @@
/*
* Copyright (C) 2011 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.supportv7.view;
import com.example.android.supportv7.R;
import android.app.Activity;
import android.os.Bundle;
/**
* Demonstrates using GridLayout to build the same "Simple Form" as in the
* LinearLayout and RelativeLayout demos.
*/
public class GridLayout1 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grid_layout_1);
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (C) 2011 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.supportv7.view;
import com.example.android.supportv7.R;
import android.app.Activity;
import android.os.Bundle;
/**
* A form, showing use of the GridLayout API from XML.
*/
public class GridLayout2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grid_layout_2);
}
}

View File

@@ -0,0 +1,129 @@
/*
* Copyright (C) 2011 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.supportv7.view;
import static android.support.v7.widget.GridLayout.ALIGN_BOUNDS;
import static android.support.v7.widget.GridLayout.BASELINE;
import static android.support.v7.widget.GridLayout.CENTER;
import static android.support.v7.widget.GridLayout.FILL;
import static android.support.v7.widget.GridLayout.LEFT;
import static android.support.v7.widget.GridLayout.RIGHT;
import static android.support.v7.widget.GridLayout.spec;
import static android.text.InputType.TYPE_CLASS_TEXT;
import static android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
import static android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.widget.GridLayout;
import android.support.v7.widget.GridLayout.LayoutParams;
import android.support.v7.widget.GridLayout.Spec;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
/**
* A form, showing use of the GridLayout API. Here we demonstrate use of the row/column order
* preserved property which allows rows and or columns to pass over each other when needed.
* The two buttons in the bottom right corner need to be separated from the other UI elements.
* This can either be done by separating rows or separating columns - but we don't need
* to do both and may only have enough space to do one or the other.
*/
public class GridLayout3 extends Activity {
public static View create(Context context) {
GridLayout p = new GridLayout(context);
p.setUseDefaultMargins(true);
p.setAlignmentMode(ALIGN_BOUNDS);
Configuration configuration = context.getResources().getConfiguration();
if ((configuration.orientation == Configuration.ORIENTATION_PORTRAIT)) {
p.setColumnOrderPreserved(false);
} else {
p.setRowOrderPreserved(false);
}
Spec titleRow = spec(0);
Spec introRow = spec(1);
Spec emailRow = spec(2, BASELINE);
Spec passwordRow = spec(3, BASELINE);
Spec button1Row = spec(5);
Spec button2Row = spec(6);
Spec centerInAllColumns = spec(0, 4, CENTER);
Spec leftAlignInAllColumns = spec(0, 4, LEFT);
Spec labelColumn = spec(0, RIGHT);
Spec fieldColumn = spec(1, LEFT);
Spec defineLastColumn = spec(3);
Spec fillLastColumn = spec(3, FILL);
{
TextView c = new TextView(context);
c.setTextSize(32);
c.setText("Email setup");
p.addView(c, new LayoutParams(titleRow, centerInAllColumns));
}
{
TextView c = new TextView(context);
c.setTextSize(16);
c.setText("You can configure email in a few simple steps:");
p.addView(c, new LayoutParams(introRow, leftAlignInAllColumns));
}
{
TextView c = new TextView(context);
c.setText("Email address:");
p.addView(c, new LayoutParams(emailRow, labelColumn));
}
{
EditText c = new EditText(context);
c.setEms(10);
c.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
p.addView(c, new LayoutParams(emailRow, fieldColumn));
}
{
TextView c = new TextView(context);
c.setText("Password:");
p.addView(c, new LayoutParams(passwordRow, labelColumn));
}
{
EditText c = new EditText(context);
c.setEms(8);
c.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD);
p.addView(c, new LayoutParams(passwordRow, fieldColumn));
}
{
Button c = new Button(context);
c.setText("Manual setup");
p.addView(c, new LayoutParams(button1Row, defineLastColumn));
}
{
Button c = new Button(context);
c.setText("Next");
p.addView(c, new LayoutParams(button2Row, fillLastColumn));
}
return p;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(create(this));
}
}