1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.example.android.supportv7.view; 18 19import static android.support.v7.widget.GridLayout.ALIGN_BOUNDS; 20import static android.support.v7.widget.GridLayout.BASELINE; 21import static android.support.v7.widget.GridLayout.CENTER; 22import static android.support.v7.widget.GridLayout.FILL; 23import static android.support.v7.widget.GridLayout.LEFT; 24import static android.support.v7.widget.GridLayout.RIGHT; 25import static android.support.v7.widget.GridLayout.spec; 26import static android.text.InputType.TYPE_CLASS_TEXT; 27import static android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; 28import static android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD; 29 30import android.app.Activity; 31import android.content.Context; 32import android.content.res.Configuration; 33import android.os.Bundle; 34import android.support.v7.widget.GridLayout; 35import android.support.v7.widget.GridLayout.LayoutParams; 36import android.support.v7.widget.GridLayout.Spec; 37import android.view.View; 38import android.widget.Button; 39import android.widget.EditText; 40import android.widget.TextView; 41 42/** 43 * A form, showing use of the GridLayout API. Here we demonstrate use of the row/column order 44 * preserved property which allows rows and or columns to pass over each other when needed. 45 * The two buttons in the bottom right corner need to be separated from the other UI elements. 46 * This can either be done by separating rows or separating columns - but we don't need 47 * to do both and may only have enough space to do one or the other. 48 */ 49public class GridLayout3 extends Activity { 50 public static View create(Context context) { 51 GridLayout p = new GridLayout(context); 52 p.setUseDefaultMargins(true); 53 p.setAlignmentMode(ALIGN_BOUNDS); 54 Configuration configuration = context.getResources().getConfiguration(); 55 if ((configuration.orientation == Configuration.ORIENTATION_PORTRAIT)) { 56 p.setColumnOrderPreserved(false); 57 } else { 58 p.setRowOrderPreserved(false); 59 } 60 61 Spec titleRow = spec(0); 62 Spec introRow = spec(1); 63 Spec emailRow = spec(2, BASELINE); 64 Spec passwordRow = spec(3, BASELINE); 65 Spec button1Row = spec(5); 66 Spec button2Row = spec(6); 67 68 Spec centerInAllColumns = spec(0, 4, CENTER); 69 Spec leftAlignInAllColumns = spec(0, 4, LEFT); 70 Spec labelColumn = spec(0, RIGHT); 71 Spec fieldColumn = spec(1, LEFT); 72 Spec defineLastColumn = spec(3); 73 Spec fillLastColumn = spec(3, FILL); 74 75 { 76 TextView c = new TextView(context); 77 c.setTextSize(32); 78 c.setText("Email setup"); 79 p.addView(c, new LayoutParams(titleRow, centerInAllColumns)); 80 } 81 { 82 TextView c = new TextView(context); 83 c.setTextSize(16); 84 c.setText("You can configure email in a few simple steps:"); 85 p.addView(c, new LayoutParams(introRow, leftAlignInAllColumns)); 86 } 87 { 88 TextView c = new TextView(context); 89 c.setText("Email address:"); 90 p.addView(c, new LayoutParams(emailRow, labelColumn)); 91 } 92 { 93 EditText c = new EditText(context); 94 c.setEms(10); 95 c.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_EMAIL_ADDRESS); 96 p.addView(c, new LayoutParams(emailRow, fieldColumn)); 97 } 98 { 99 TextView c = new TextView(context); 100 c.setText("Password:"); 101 p.addView(c, new LayoutParams(passwordRow, labelColumn)); 102 } 103 { 104 EditText c = new EditText(context); 105 c.setEms(8); 106 c.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD); 107 p.addView(c, new LayoutParams(passwordRow, fieldColumn)); 108 } 109 { 110 Button c = new Button(context); 111 c.setText("Manual setup"); 112 p.addView(c, new LayoutParams(button1Row, defineLastColumn)); 113 } 114 { 115 Button c = new Button(context); 116 c.setText("Next"); 117 p.addView(c, new LayoutParams(button2Row, fillLastColumn)); 118 } 119 120 return p; 121 } 122 123 @Override 124 protected void onCreate(Bundle savedInstanceState) { 125 super.onCreate(savedInstanceState); 126 setContentView(create(this)); 127 } 128 129}