| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.autofill; | 5 package org.chromium.chrome.browser.autofill; |
| 6 | 6 |
| 7 import java.util.ArrayList; | 7 import java.util.ArrayList; |
| 8 import java.util.List; | 8 import java.util.List; |
| 9 | 9 |
| 10 import android.content.Context; | 10 import android.content.Context; |
| 11 import android.graphics.BitmapFactory; | |
| 12 import android.text.TextUtils; | 11 import android.text.TextUtils; |
| 13 import android.util.AttributeSet; | 12 import android.util.AttributeSet; |
| 14 import android.view.View; | 13 import android.view.View; |
| 15 import android.view.ViewGroup; | 14 import android.view.ViewGroup; |
| 16 import android.view.animation.Animation; | 15 import android.view.animation.Animation; |
| 17 import android.view.animation.AnimationSet; | 16 import android.view.animation.AnimationSet; |
| 18 import android.view.animation.ScaleAnimation; | 17 import android.view.animation.ScaleAnimation; |
| 19 import android.view.animation.TranslateAnimation; | 18 import android.view.animation.TranslateAnimation; |
| 20 import android.widget.AdapterView; | |
| 21 import android.widget.ArrayAdapter; | 19 import android.widget.ArrayAdapter; |
| 22 import android.widget.ImageView; | 20 import android.widget.ImageView; |
| 23 import android.widget.LinearLayout; | 21 import android.widget.LinearLayout; |
| 24 import android.widget.Spinner; | 22 import android.widget.Spinner; |
| 25 import android.widget.TextView; | 23 import android.widget.TextView; |
| 26 import android.widget.AdapterView.OnItemSelectedListener; | 24 import android.widget.AdapterView.OnItemSelectedListener; |
| 27 | 25 |
| 28 import static org.chromium.chrome.browser.autofill.AutofillDialogConstants.NUM_S
ECTIONS; | 26 import static org.chromium.chrome.browser.autofill.AutofillDialogConstants.NUM_S
ECTIONS; |
| 29 import static org.chromium.chrome.browser.autofill.AutofillDialogConstants.SECTI
ON_CC; | 27 import static org.chromium.chrome.browser.autofill.AutofillDialogConstants.SECTI
ON_CC; |
| 30 import static org.chromium.chrome.browser.autofill.AutofillDialogConstants.SECTI
ON_CC_BILLING; | 28 import static org.chromium.chrome.browser.autofill.AutofillDialogConstants.SECTI
ON_CC_BILLING; |
| 31 import static org.chromium.chrome.browser.autofill.AutofillDialogConstants.SECTI
ON_BILLING; | 29 import static org.chromium.chrome.browser.autofill.AutofillDialogConstants.SECTI
ON_BILLING; |
| 32 import static org.chromium.chrome.browser.autofill.AutofillDialogConstants.SECTI
ON_SHIPPING; | 30 import static org.chromium.chrome.browser.autofill.AutofillDialogConstants.SECTI
ON_SHIPPING; |
| 33 | 31 |
| 34 import org.chromium.chrome.R; | 32 import org.chromium.chrome.R; |
| 35 | 33 |
| 36 /** | 34 /** |
| 37 * This is the parent layout that contains the layouts for different states of | 35 * This is the parent layout that contains the layouts for different states of |
| 38 * autofill dialog. In principle it shouldn't contain any logic related with the | 36 * autofill dialog. In principle it shouldn't contain any logic related with the |
| 39 * actual workflow, but rather respond to any UI update messages coming to it | 37 * actual workflow, but rather respond to any UI update messages coming to it |
| 40 * from the AutofillDialog. | 38 * from the AutofillDialog. |
| 41 */ | 39 */ |
| 42 public class AutofillDialogContentView extends LinearLayout { | 40 public class AutofillDialogContentView extends LinearLayout { |
| 43 private static final int ANIMATION_DURATION_MS = 1000; | 41 private static final int ANIMATION_DURATION_MS = 1000; |
| 44 // TODO(yusufo): Remove all placeholders here and also in related layout xml
files. | 42 // TODO(yusufo): Remove all placeholders here and also in related layout xml
files. |
| 45 private final AutofillDialogMenuItem[][] mDefaultMenuItems = | |
| 46 new AutofillDialogMenuItem[NUM_SECTIONS][]; | |
| 47 static final int INVALID_LAYOUT = -1; | 43 static final int INVALID_LAYOUT = -1; |
| 48 static final int LAYOUT_EDITING_SHIPPING = 0; | 44 static final int LAYOUT_EDITING_SHIPPING = 0; |
| 49 static final int LAYOUT_EDITING_CC = 1; | 45 static final int LAYOUT_EDITING_CC = 1; |
| 50 static final int LAYOUT_EDITING_BILLING = 2; | 46 static final int LAYOUT_EDITING_BILLING = 2; |
| 51 static final int LAYOUT_EDITING_CC_BILLING = 3; | 47 static final int LAYOUT_EDITING_CC_BILLING = 3; |
| 52 static final int LAYOUT_FETCHING = 4; | 48 static final int LAYOUT_FETCHING = 4; |
| 53 static final int LAYOUT_STEADY = 5; | 49 static final int LAYOUT_STEADY = 5; |
| 54 private final Runnable mDismissSteadyLayoutRunnable = new Runnable() { | 50 private final Runnable mDismissSteadyLayoutRunnable = new Runnable() { |
| 55 @Override | 51 @Override |
| 56 public void run() { | 52 public void run() { |
| 57 mSteadyLayout.setVisibility(GONE); | 53 mSteadyLayout.setVisibility(GONE); |
| 58 } | 54 } |
| 59 }; | 55 }; |
| 60 private Spinner[] mSpinners = new Spinner[NUM_SECTIONS]; | 56 private Spinner[] mSpinners = new Spinner[NUM_SECTIONS]; |
| 61 private AutofillDialogMenuAdapter[] mAdapters = new AutofillDialogMenuAdapte
r[NUM_SECTIONS]; | 57 private AutofillDialogMenuAdapter[] mAdapters = new AutofillDialogMenuAdapte
r[NUM_SECTIONS]; |
| 62 private ViewGroup mSteadyLayout; | 58 private ViewGroup mSteadyLayout; |
| 63 private ViewGroup[] mEditLayouts = new ViewGroup[NUM_SECTIONS]; | 59 private ViewGroup[] mEditLayouts = new ViewGroup[NUM_SECTIONS]; |
| 64 private int mCurrentLayout = -1; | 60 private int mCurrentLayout = -1; |
| 65 | 61 |
| 66 public AutofillDialogContentView(Context context, AttributeSet attrs) { | 62 public AutofillDialogContentView(Context context, AttributeSet attrs) { |
| 67 super(context, attrs); | 63 super(context, attrs); |
| 68 AutofillDialogMenuItem[] billingItems = { | |
| 69 new AutofillDialogMenuItem(0, | |
| 70 getResources().getString(R.string.autofill_new_billing))
, | |
| 71 new AutofillDialogMenuItem(0, | |
| 72 getResources().getString(R.string.autofill_edit_billing)
) | |
| 73 }; | |
| 74 AutofillDialogMenuItem[] shippingItems = { | |
| 75 new AutofillDialogMenuItem(0, | |
| 76 getResources().getString(R.string.autofill_new_shipping)
), | |
| 77 new AutofillDialogMenuItem(0, | |
| 78 getResources().getString(R.string.autofill_edit_shipping
)) | |
| 79 }; | |
| 80 | |
| 81 mDefaultMenuItems[SECTION_CC_BILLING] = billingItems; | |
| 82 mDefaultMenuItems[SECTION_SHIPPING] = shippingItems; | |
| 83 } | 64 } |
| 84 | 65 |
| 85 @Override | 66 @Override |
| 86 protected void onFinishInflate () { | 67 protected void onFinishInflate () { |
| 87 mSteadyLayout = (ViewGroup) findViewById(R.id.general_layout); | 68 mSteadyLayout = (ViewGroup) findViewById(R.id.general_layout); |
| 88 | 69 |
| 89 for (int i = 0; i < AutofillDialogConstants.NUM_SECTIONS; i++) { | 70 for (int i = 0; i < AutofillDialogConstants.NUM_SECTIONS; i++) { |
| 90 mEditLayouts[i] = (ViewGroup) findViewById( | 71 mEditLayouts[i] = (ViewGroup) findViewById( |
| 91 AutofillDialogUtils.getLayoutIDForSection(i)); | 72 AutofillDialogUtils.getLayoutIDForSection(i)); |
| 92 int id = AutofillDialogUtils.getSpinnerIDForSection(i); | 73 int id = AutofillDialogUtils.getSpinnerIDForSection(i); |
| 93 mSpinners[i] = (Spinner) findViewById(id); | 74 mSpinners[i] = (Spinner) findViewById(id); |
| 94 AutofillDialogMenuAdapter adapter = new AutofillDialogMenuAdapter(ge
tContext(), | 75 AutofillDialogMenuAdapter adapter = new AutofillDialogMenuAdapter(ge
tContext(), |
| 95 new ArrayList<AutofillDialogMenuItem>()); | 76 new ArrayList<AutofillDialogMenuItem>()); |
| 96 mAdapters[i] = adapter; | 77 mAdapters[i] = adapter; |
| 97 if (id == AutofillDialogUtils.INVALID_ID) continue; | 78 if (id == AutofillDialogUtils.INVALID_ID) continue; |
| 98 mSpinners[i].setAdapter(adapter); | 79 mSpinners[i].setAdapter(adapter); |
| 99 } | 80 } |
| 100 | 81 |
| 101 createAndAddPlaceHolders(); | |
| 102 changeLayoutTo(LAYOUT_FETCHING); | 82 changeLayoutTo(LAYOUT_FETCHING); |
| 103 } | 83 } |
| 104 | 84 |
| 105 // TODO(yusufo): Remove this method once glue implements fetching data. | |
| 106 private void createAndAddPlaceHolders() { | |
| 107 AutofillDialogMenuItem[] ccItems = new AutofillDialogMenuItem[1]; | |
| 108 ccItems[0] = new AutofillDialogMenuItem( | |
| 109 0, "XXXX-XXXX-XXXX-1000", "Additional info required", | |
| 110 BitmapFactory.decodeResource(getResources(), R.drawable.
visa)); | |
| 111 AutofillDialogMenuItem[] addressItems = new AutofillDialogMenuItem[1]; | |
| 112 addressItems[0] = new AutofillDialogMenuItem( | |
| 113 0, "Place Holder", "1600 Amphitheatre Pkwy", null); | |
| 114 updateMenuItemsForSection(SECTION_CC_BILLING, ccItems); | |
| 115 updateMenuItemsForSection(SECTION_SHIPPING, addressItems); | |
| 116 } | |
| 117 | |
| 118 @Override | 85 @Override |
| 119 protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) { | 86 protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) { |
| 120 super.onMeasure(widthMeasureSpec, heightMeasureSpec); | 87 super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 121 Spinner ccSpinner = mSpinners[SECTION_CC_BILLING]; | 88 Spinner ccSpinner = mSpinners[SECTION_CC_BILLING]; |
| 122 Spinner addressSpinner = mSpinners[SECTION_SHIPPING]; | 89 Spinner addressSpinner = mSpinners[SECTION_SHIPPING]; |
| 123 ccSpinner.setDropDownWidth(ccSpinner.getMeasuredWidth()); | 90 ccSpinner.setDropDownWidth(ccSpinner.getMeasuredWidth()); |
| 124 ccSpinner.setDropDownVerticalOffset(-ccSpinner.getMeasuredHeight()); | 91 ccSpinner.setDropDownVerticalOffset(-ccSpinner.getMeasuredHeight()); |
| 125 addressSpinner.setDropDownWidth(addressSpinner.getMeasuredWidth()); | 92 addressSpinner.setDropDownWidth(addressSpinner.getMeasuredWidth()); |
| 126 addressSpinner.setDropDownVerticalOffset(-addressSpinner.getMeasuredHeig
ht()); | 93 addressSpinner.setDropDownVerticalOffset(-addressSpinner.getMeasuredHeig
ht()); |
| 127 } | 94 } |
| 128 | 95 |
| 129 /** | 96 /** |
| 130 * Set the listener for all the dropdown members in the layout. | 97 * Set the listener for all the dropdown members in the layout. |
| 131 * @param listener The listener object to attach to the dropdowns. | 98 * @param listener The listener object to attach to the dropdowns. |
| 132 */ | 99 */ |
| 133 public void setOnItemSelectedListener(OnItemSelectedListener listener) { | 100 public void setOnItemSelectedListener(OnItemSelectedListener listener) { |
| 134 for (int i = 0; i < NUM_SECTIONS; i++) { | 101 for (int i = 0; i < NUM_SECTIONS; i++) { |
| 135 if (mSpinners[i] != null) mSpinners[i].setOnItemSelectedListener(lis
tener); | 102 if (mSpinners[i] != null) mSpinners[i].setOnItemSelectedListener(lis
tener); |
| 136 } | 103 } |
| 137 } | 104 } |
| 138 | 105 |
| 139 /** | 106 /** |
| 140 * @param spinner The dropdown that was selected by the user. | 107 * @return Whether the current layout is one of the editing layouts. |
| 141 * @param section The section that the dropdown corresponds to. | |
| 142 * @param position The position for the selected item in the dropdown. | |
| 143 * @return Whether the selection should cause a layout state change. | |
| 144 */ | 108 */ |
| 145 public boolean selectionShouldChangeLayout(AdapterView<?> spinner, int secti
on, int position) { | 109 public boolean isInEditingMode() { |
| 146 int numDefaultItems = mDefaultMenuItems[section] != null ? | 110 return mCurrentLayout != INVALID_LAYOUT && |
| 147 mDefaultMenuItems[section].length : 0; | 111 mCurrentLayout != LAYOUT_STEADY && |
| 148 return position >= spinner.getCount() - numDefaultItems; | 112 mCurrentLayout != LAYOUT_FETCHING; |
| 149 } | 113 } |
| 150 | 114 |
| 151 /** | 115 /** |
| 152 * @return The current layout the content is showing. | 116 * @return The current section if we are in editing mode, INVALID_SECTION ot
herwise. |
| 153 */ | 117 */ |
| 154 // TODO(yusufo): Consider restricting this access more to checks rather than
the | 118 public int getCurrentSection() { |
| 155 // current value. | 119 return getSectionForLayoutMode(mCurrentLayout); |
| 156 public int getCurrentLayout() { | |
| 157 return mCurrentLayout; | |
| 158 } | 120 } |
| 159 | 121 |
| 160 /** | 122 /** |
| 161 * Updates a dropdown with the given items and adds default items to the end
. | 123 * Updates a dropdown with the given items and adds default items to the end
. |
| 162 * @param items The {@link AutofillDialogMenuItem} array to update the dropd
own with. | 124 * @param items The {@link AutofillDialogMenuItem} array to update the dropd
own with. |
| 163 */ | 125 */ |
| 164 public void updateMenuItemsForSection(int section, AutofillDialogMenuItem[]
items) { | 126 public void updateMenuItemsForSection(int section, List<AutofillDialogMenuIt
em> items) { |
| 165 AutofillDialogMenuAdapter adapter = mAdapters[section]; | 127 AutofillDialogMenuAdapter adapter = mAdapters[section]; |
| 166 adapter.clear(); | 128 adapter.clear(); |
| 167 adapter.addAll(items); | 129 adapter.addAll(items); |
| 168 if (mDefaultMenuItems[section] != null) adapter.addAll(mDefaultMenuItems
[section]); | |
| 169 } | 130 } |
| 170 | 131 |
| 171 /** | 132 /** |
| 172 * Transitions the layout shown to a given layout. | 133 * Transitions the layout shown to a given layout. |
| 173 * @param mode The layout mode to transition to. | 134 * @param mode The layout mode to transition to. |
| 174 */ | 135 */ |
| 175 public void changeLayoutTo(int mode) { | 136 public void changeLayoutTo(int mode) { |
| 176 assert(mode != INVALID_LAYOUT); | 137 assert(mode != INVALID_LAYOUT); |
| 177 if (mode == mCurrentLayout || mode == INVALID_LAYOUT) return; | 138 if (mode == mCurrentLayout || mode == INVALID_LAYOUT) return; |
| 178 | 139 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 line2.setVisibility(VISIBLE); | 304 line2.setVisibility(VISIBLE); |
| 344 line2.setText(item.mLine2); | 305 line2.setText(item.mLine2); |
| 345 } else { | 306 } else { |
| 346 line2.setVisibility(GONE); | 307 line2.setVisibility(GONE); |
| 347 } | 308 } |
| 348 } | 309 } |
| 349 return convertView; | 310 return convertView; |
| 350 } | 311 } |
| 351 } | 312 } |
| 352 } | 313 } |
| OLD | NEW |