• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.example.android.apis.view;
18 
19 import android.app.Activity;
20 import android.content.Context;
21 import android.os.Bundle;
22 import android.view.View;
23 
24 import android.widget.*;
25 
26 import static android.text.InputType.*;
27 import static android.widget.GridLayout.*;
28 
29 /**
30  * A simple form, showing use of the GridLayout API.
31  */
32 public class GridLayout0 extends Activity {
33 
create(Context context)34     public static View create(Context context) {
35         GridLayout p = new GridLayout(context);
36         p.setUseDefaultMargins(true);
37         p.setAlignmentMode(ALIGN_BOUNDS);
38         p.setRowOrderPreserved(false);
39 
40         Spec row1 = spec(0);
41         Spec row2 = spec(1);
42         Spec row3 = spec(2, BASELINE);
43         Spec row4 = spec(3, BASELINE);
44         Spec row5 = spec(2, 3, FILL); // allow the last two rows to overlap the middle two
45         Spec row6 = spec(5);
46         Spec row7 = spec(6);
47 
48         Spec col1a = spec(0, 4, CENTER);
49         Spec col1b = spec(0, 4, LEFT);
50         Spec col1c = spec(0, RIGHT);
51         Spec col2 = spec(1, LEFT);
52         Spec col3 = spec(2, FILL);
53         Spec col4a = spec(3);
54         Spec col4b = spec(3, FILL);
55 
56         {
57             TextView c = new TextView(context);
58             c.setTextSize(32);
59             c.setText("Email setup");
60             p.addView(c, new LayoutParams(row1, col1a));
61         }
62         {
63             TextView c = new TextView(context);
64             c.setTextSize(16);
65             c.setText("You can configure email in just a few steps:");
66             p.addView(c, new LayoutParams(row2, col1b));
67         }
68         {
69             TextView c = new TextView(context);
70             c.setText("Email address:");
71             p.addView(c, new LayoutParams(row3, col1c));
72         }
73         {
74             EditText c = new EditText(context);
75             c.setEms(10);
76             c.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
77             p.addView(c, new LayoutParams(row3, col2));
78         }
79         {
80             TextView c = new TextView(context);
81             c.setText("Password:");
82             p.addView(c, new LayoutParams(row4, col1c));
83         }
84         {
85             TextView c = new EditText(context);
86             c.setEms(8);
87             c.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD);
88             p.addView(c, new LayoutParams(row4, col2));
89         }
90         {
91             Space c = new Space(context);
92             p.addView(c, new LayoutParams(row5, col3));
93         }
94         {
95             Button c = new Button(context);
96             c.setText("Manual setup");
97             p.addView(c, new LayoutParams(row6, col4a));
98         }
99         {
100             Button c = new Button(context);
101             c.setText("Next");
102             p.addView(c, new LayoutParams(row7, col4b));
103         }
104 
105         return p;
106     }
107 
onCreate(Bundle savedInstanceState)108     protected void onCreate(Bundle savedInstanceState) {
109         super.onCreate(savedInstanceState);
110         setContentView(create(this));
111     }
112 
113 }