Fabrice Di Meglio | 9f82b58 | 2011-03-08 12:02:59 -0800 | [diff] [blame] | 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.android.bidi; |
| 18 | |
Fabrice Di Meglio | 7af0522 | 2011-06-10 15:42:05 -0700 | [diff] [blame] | 19 | import java.util.ArrayList; |
| 20 | import java.util.HashMap; |
| 21 | import java.util.List; |
| 22 | import java.util.Map; |
Fabrice Di Meglio | eee49c6 | 2011-03-24 17:21:23 -0700 | [diff] [blame] | 23 | |
Fabrice Di Meglio | 7af0522 | 2011-06-10 15:42:05 -0700 | [diff] [blame] | 24 | import android.app.Activity; |
| 25 | import android.app.Fragment; |
| 26 | import android.app.FragmentTransaction; |
| 27 | import android.os.Bundle; |
Fabrice Di Meglio | 53a73bc | 2011-06-20 17:38:41 -0700 | [diff] [blame] | 28 | import android.view.Menu; |
| 29 | import android.view.MenuInflater; |
Fabrice Di Meglio | 7af0522 | 2011-06-10 15:42:05 -0700 | [diff] [blame] | 30 | import android.view.View; |
| 31 | import android.widget.AdapterView; |
| 32 | import android.widget.ListView; |
| 33 | import android.widget.SimpleAdapter; |
| 34 | |
| 35 | public class BiDiTestActivity extends Activity { |
| 36 | |
| 37 | private static final String KEY_CLASS = "class"; |
| 38 | private static final String KEY_TITLE = "title"; |
| 39 | private static final String KEY_FRAGMENT_ID = "id"; |
| 40 | |
| 41 | private ListView mList; |
| 42 | |
| 43 | private AdapterView.OnItemClickListener mOnClickListener = |
| 44 | new AdapterView.OnItemClickListener() { |
| 45 | public void onItemClick(AdapterView<?> parent, View v, int position, long id) { |
| 46 | onListItemClick((ListView)parent, v, position, id); |
| 47 | } |
| 48 | }; |
| 49 | |
| 50 | private void onListItemClick(ListView lv, View v, int position, long id) { |
| 51 | // Show the test |
| 52 | Map<String, Object> map = (Map<String, Object>)lv.getItemAtPosition(position); |
| 53 | int fragmentId = (Integer) map.get(KEY_FRAGMENT_ID); |
| 54 | Fragment fragment = getFragmentManager().findFragmentById(fragmentId); |
| 55 | if (fragment == null) { |
| 56 | try { |
| 57 | // Create an instance of the test |
| 58 | Class<? extends Fragment> clazz = (Class<? extends Fragment>) map.get(KEY_CLASS); |
| 59 | fragment = clazz.newInstance(); |
| 60 | |
| 61 | // Replace the old test fragment with the new one |
| 62 | FragmentTransaction ft = getFragmentManager().beginTransaction(); |
| 63 | ft.replace(R.id.testframe, fragment); |
| 64 | ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); |
| 65 | ft.commit(); |
| 66 | } catch (InstantiationException e) { |
| 67 | } catch (IllegalAccessException e) { |
| 68 | } |
| 69 | } |
| 70 | } |
Fabrice Di Meglio | eee49c6 | 2011-03-24 17:21:23 -0700 | [diff] [blame] | 71 | |
Fabrice Di Meglio | 9f82b58 | 2011-03-08 12:02:59 -0800 | [diff] [blame] | 72 | @Override |
| 73 | protected void onCreate(Bundle savedInstanceState) { |
| 74 | super.onCreate(savedInstanceState); |
| 75 | |
Fabrice Di Meglio | 1e4cfbe | 2010-04-01 15:46:27 -0700 | [diff] [blame] | 76 | setContentView(R.layout.main); |
Fabrice Di Meglio | eee49c6 | 2011-03-24 17:21:23 -0700 | [diff] [blame] | 77 | |
Fabrice Di Meglio | 7af0522 | 2011-06-10 15:42:05 -0700 | [diff] [blame] | 78 | mList = (ListView) findViewById(R.id.testlist); |
| 79 | mList.setChoiceMode(ListView.CHOICE_MODE_SINGLE); |
| 80 | mList.setFocusableInTouchMode(true); |
| 81 | |
| 82 | final SimpleAdapter adapter = new SimpleAdapter(this, getTests(), |
| 83 | R.layout.custom_list_item, new String[]{"title"}, |
| 84 | new int[]{android.R.id.text1}); |
| 85 | mList.setAdapter(adapter); |
| 86 | |
| 87 | mList.setOnItemClickListener(mOnClickListener); |
| 88 | } |
Fabrice Di Meglio | eee49c6 | 2011-03-24 17:21:23 -0700 | [diff] [blame] | 89 | |
Fabrice Di Meglio | 7af0522 | 2011-06-10 15:42:05 -0700 | [diff] [blame] | 90 | private void addItem(List<Map<String, Object>> data, String name, |
| 91 | Class<? extends Fragment> clazz, int fragmentId) { |
| 92 | Map<String, Object> temp = new HashMap<String, Object>(); |
| 93 | temp.put(KEY_TITLE, name); |
| 94 | temp.put(KEY_CLASS, clazz); |
| 95 | temp.put(KEY_FRAGMENT_ID, fragmentId); |
| 96 | data.add(temp); |
| 97 | } |
Fabrice Di Meglio | eee49c6 | 2011-03-24 17:21:23 -0700 | [diff] [blame] | 98 | |
Fabrice Di Meglio | 7af0522 | 2011-06-10 15:42:05 -0700 | [diff] [blame] | 99 | private List<Map<String, Object>> getTests() { |
| 100 | List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); |
Fabrice Di Meglio | eee49c6 | 2011-03-24 17:21:23 -0700 | [diff] [blame] | 101 | |
Fabrice Di Meglio | 7af0522 | 2011-06-10 15:42:05 -0700 | [diff] [blame] | 102 | addItem(result, "Basic", BiDiTestBasic.class, R.id.basic); |
Doug Felt | 468d8af | 2011-06-22 11:01:18 -0700 | [diff] [blame] | 103 | |
Fabrice Di Meglio | c6f247c | 2011-07-15 19:18:59 -0700 | [diff] [blame] | 104 | addItem(result, "Canvas2", BiDiTestCanvas2.class, R.id.canvas2); |
Doug Felt | 468d8af | 2011-06-22 11:01:18 -0700 | [diff] [blame] | 105 | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 106 | addItem(result, "TextView LTR", BiDiTestTextViewLtr.class, R.id.textview_ltr); |
| 107 | addItem(result, "TextView RTL", BiDiTestTextViewRtl.class, R.id.textview_rtl); |
| 108 | addItem(result, "TextView LOC", BiDiTestTextViewLocale.class, R.id.textview_locale); |
| 109 | |
| 110 | addItem(result, "TextDirection LTR", BiDiTestTextViewDirectionLtr.class, R.id.textview_direction_ltr); |
| 111 | addItem(result, "TextDirection RTL", BiDiTestTextViewDirectionRtl.class, R.id.textview_direction_rtl); |
| 112 | |
| 113 | addItem(result, "TextAlignment LTR", BiDiTestTextViewAlignmentLtr.class, R.id.textview_alignment_ltr); |
| 114 | addItem(result, "TextAlignment RTL", BiDiTestTextViewAlignmentRtl.class, R.id.textview_alignment_rtl); |
| 115 | |
Fabrice Di Meglio | 7af0522 | 2011-06-10 15:42:05 -0700 | [diff] [blame] | 116 | addItem(result, "Linear LTR", BiDiTestLinearLayoutLtr.class, R.id.linear_layout_ltr); |
| 117 | addItem(result, "Linear RTL", BiDiTestLinearLayoutRtl.class, R.id.linear_layout_rtl); |
| 118 | addItem(result, "Linear LOC", BiDiTestLinearLayoutLocale.class, R.id.linear_layout_locale); |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 119 | |
Fabrice Di Meglio | bf2ab0b | 2012-02-06 17:05:49 -0800 | [diff] [blame] | 120 | addItem(result, "Grid LTR", BiDiTestGridLayoutLtr.class, R.id.grid_layout_ltr); |
| 121 | addItem(result, "Grid RTL", BiDiTestGridLayoutRtl.class, R.id.grid_layout_rtl); |
| 122 | addItem(result, "Grid LOC", BiDiTestGridLayoutLocale.class, R.id.grid_layout_locale); |
Fabrice Di Meglio | 2a7e7a0 | 2012-02-09 17:32:24 -0800 | [diff] [blame] | 123 | addItem(result, "Grid C-LTR", BiDiTestGridLayoutCodeLtr.class, R.id.grid_layout_code); |
| 124 | addItem(result, "Grid C-RTL", BiDiTestGridLayoutCodeRtl.class, R.id.grid_layout_code); |
Fabrice Di Meglio | bf2ab0b | 2012-02-06 17:05:49 -0800 | [diff] [blame] | 125 | |
Fabrice Di Meglio | 7af0522 | 2011-06-10 15:42:05 -0700 | [diff] [blame] | 126 | addItem(result, "Frame LTR", BiDiTestFrameLayoutLtr.class, R.id.frame_layout_ltr); |
| 127 | addItem(result, "Frame RTL", BiDiTestFrameLayoutRtl.class, R.id.frame_layout_rtl); |
| 128 | addItem(result, "Frame LOC", BiDiTestFrameLayoutLocale.class, R.id.frame_layout_locale); |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 129 | |
Fabrice Di Meglio | 7af0522 | 2011-06-10 15:42:05 -0700 | [diff] [blame] | 130 | addItem(result, "Relative LTR", BiDiTestRelativeLayoutLtr.class, R.id.relative_layout_ltr); |
| 131 | addItem(result, "Relative RTL", BiDiTestRelativeLayoutRtl.class, R.id.relative_layout_rtl); |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 132 | |
Fabrice Di Meglio | 7af0522 | 2011-06-10 15:42:05 -0700 | [diff] [blame] | 133 | addItem(result, "Relative2 LTR", BiDiTestRelativeLayout2Ltr.class, R.id.relative_layout_2_ltr); |
| 134 | addItem(result, "Relative2 RTL", BiDiTestRelativeLayout2Rtl.class, R.id.relative_layout_2_rtl); |
| 135 | addItem(result, "Relative2 LOC", BiDiTestRelativeLayout2Locale.class, R.id.relative_layout_2_locale); |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 136 | |
Fabrice Di Meglio | 7af0522 | 2011-06-10 15:42:05 -0700 | [diff] [blame] | 137 | addItem(result, "Table LTR", BiDiTestTableLayoutLtr.class, R.id.table_layout_ltr); |
| 138 | addItem(result, "Table RTL", BiDiTestTableLayoutRtl.class, R.id.table_layout_rtl); |
| 139 | addItem(result, "Table LOC", BiDiTestTableLayoutLocale.class, R.id.table_layout_locale); |
Fabrice Di Meglio | eee49c6 | 2011-03-24 17:21:23 -0700 | [diff] [blame] | 140 | |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 141 | addItem(result, "Padding", BiDiTestViewPadding.class, R.id.view_padding); |
| 142 | addItem(result, "Padding MIXED", BiDiTestViewPaddingMixed.class, R.id.view_padding_mixed); |
| 143 | |
| 144 | addItem(result, "Margin MIXED", BiDiTestViewGroupMarginMixed.class, R.id.view_group_margin_mixed); |
| 145 | |
Fabrice Di Meglio | a3b6b95 | 2011-06-29 16:44:43 -0700 | [diff] [blame] | 146 | addItem(result, "TextView Drawables LTR", BiDiTestTextViewDrawablesLtr.class, R.id.textview_drawables_ltr); |
| 147 | addItem(result, "TextView Drawables RTL", BiDiTestTextViewDrawablesRtl.class, R.id.textview_drawables_rtl); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 148 | |
Doug Felt | 3d0124f | 2011-07-14 13:55:11 -0700 | [diff] [blame] | 149 | addItem(result, "Gallery LTR", BiDiTestGalleryLtr.class, R.id.gallery_ltr); |
| 150 | addItem(result, "Gallery RTL", BiDiTestGalleryRtl.class, R.id.gallery_rtl); |
Fabrice Di Meglio | a3b6b95 | 2011-06-29 16:44:43 -0700 | [diff] [blame] | 151 | |
Fabrice Di Meglio | 7af0522 | 2011-06-10 15:42:05 -0700 | [diff] [blame] | 152 | return result; |
Fabrice Di Meglio | 9f82b58 | 2011-03-08 12:02:59 -0800 | [diff] [blame] | 153 | } |
Fabrice Di Meglio | 53a73bc | 2011-06-20 17:38:41 -0700 | [diff] [blame] | 154 | |
| 155 | @Override |
| 156 | public boolean onCreateOptionsMenu(Menu menu) { |
| 157 | MenuInflater inflater = getMenuInflater(); |
| 158 | inflater.inflate(R.menu.main_menu, menu); |
| 159 | return true; |
| 160 | } |
Fabrice Di Meglio | 5f9fa88 | 2011-07-19 10:16:04 -0700 | [diff] [blame] | 161 | } |