1/*
2 * Copyright (C) 2012 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.android.bidi;
18
19import android.app.Fragment;
20import android.content.Context;
21import android.os.Bundle;
22import android.view.LayoutInflater;
23import android.view.View;
24import android.view.ViewGroup;
25import android.widget.GridLayout;
26import android.widget.*;
27
28import static android.text.InputType.*;
29import static android.widget.GridLayout.*;
30
31public class BiDiTestGridLayoutCodeLtr extends Fragment {
32
33    private FrameLayout currentView;
34
35    @Override
36    public View onCreateView(LayoutInflater inflater, ViewGroup container,
37            Bundle savedInstanceState) {
38        currentView = (FrameLayout) inflater.inflate(R.layout.grid_layout_code, container, false);
39        return currentView;
40    }
41
42    @Override
43    public void onViewCreated(View view, Bundle savedInstanceState) {
44        super.onViewCreated(view, savedInstanceState);
45        currentView.addView(create(currentView.getContext()));
46    }
47
48    public static View create(Context context) {
49        GridLayout layout = new GridLayout(context);
50        layout.setUseDefaultMargins(true);
51        layout.setAlignmentMode(ALIGN_BOUNDS);
52        layout.setRowOrderPreserved(false);
53        layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
54
55        Spec row1 = spec(0);
56        Spec row2 = spec(1);
57        Spec row3 = spec(2, BASELINE);
58        Spec row4 = spec(3, BASELINE);
59        Spec row5 = spec(2, 3, FILL); // allow the last two rows to overlap the middle two
60        Spec row6 = spec(5);
61        Spec row7 = spec(6);
62
63        Spec col1a = spec(0, 4, CENTER);
64        Spec col1b = spec(0, 4, LEFT);
65        Spec col1c = spec(0, RIGHT);
66        Spec col2 = spec(1, START);
67        Spec col3 = spec(2, FILL);
68        Spec col4a = spec(3);
69        Spec col4b = spec(3, FILL);
70
71        {
72            TextView c = new TextView(context);
73            c.setTextSize(32);
74            c.setText("Email setup");
75            layout.addView(c, new GridLayout.LayoutParams(row1, col1a));
76        }
77        {
78            TextView c = new TextView(context);
79            c.setTextSize(16);
80            c.setText("You can configure email in just a few steps:");
81            layout.addView(c, new GridLayout.LayoutParams(row2, col1b));
82        }
83        {
84            TextView c = new TextView(context);
85            c.setText("Email address:");
86            layout.addView(c, new GridLayout.LayoutParams(row3, col1c));
87        }
88        {
89            EditText c = new EditText(context);
90            c.setEms(10);
91            c.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
92            layout.addView(c, new GridLayout.LayoutParams(row3, col2));
93        }
94        {
95            TextView c = new TextView(context);
96            c.setText("Password:");
97            layout.addView(c, new GridLayout.LayoutParams(row4, col1c));
98        }
99        {
100            TextView c = new EditText(context);
101            c.setEms(8);
102            c.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD);
103            layout.addView(c, new GridLayout.LayoutParams(row4, col2));
104        }
105        {
106            Space c = new Space(context);
107            layout.addView(c, new GridLayout.LayoutParams(row5, col3));
108        }
109        {
110            Button c = new Button(context);
111            c.setText("Manual setup");
112            layout.addView(c, new GridLayout.LayoutParams(row6, col4a));
113        }
114        {
115            Button c = new Button(context);
116            c.setText("Next");
117            layout.addView(c, new GridLayout.LayoutParams(row7, col4b));
118        }
119
120        return layout;
121    }
122}
123