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