OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.webapps; | 5 package org.chromium.chrome.browser.webapps; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.DialogInterface; | 8 import android.content.DialogInterface; |
9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
10 import android.support.v7.app.AlertDialog; | 10 import android.support.v7.app.AlertDialog; |
11 import android.text.Editable; | 11 import android.text.Editable; |
12 import android.text.TextUtils; | 12 import android.text.TextUtils; |
13 import android.text.TextWatcher; | 13 import android.text.TextWatcher; |
14 import android.view.View; | 14 import android.view.View; |
15 import android.widget.EditText; | 15 import android.widget.EditText; |
16 import android.widget.ImageView; | 16 import android.widget.ImageView; |
17 | 17 |
18 import org.chromium.base.VisibleForTesting; | 18 import org.chromium.base.VisibleForTesting; |
19 import org.chromium.chrome.R; | 19 import org.chromium.chrome.R; |
20 import org.chromium.chrome.browser.ShortcutHelper; | |
21 import org.chromium.chrome.browser.tab.Tab; | 20 import org.chromium.chrome.browser.tab.Tab; |
22 | 21 |
23 /** | 22 /** |
24 * Helper class showing the UI regarding Add to Homescreen and delegate the | 23 * Helper class showing the UI regarding Add to Homescreen and delegate the |
25 * logic to ShortcutHelper. | 24 * logic to ShortcutHelper. |
26 */ | 25 */ |
27 public class AddToHomescreenDialog { | 26 public class AddToHomescreenDialog { |
28 private static AlertDialog sCurrentDialog; | 27 private static AlertDialog sCurrentDialog; |
29 | 28 |
30 @VisibleForTesting | 29 @VisibleForTesting |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // Force the text field to align better with the icon by acc
ounting for the | 68 // Force the text field to align better with the icon by acc
ounting for the |
70 // padding introduced by the background drawable. | 69 // padding introduced by the background drawable. |
71 input.getLayoutParams().height = | 70 input.getLayoutParams().height = |
72 progressBarView.getMeasuredHeight() + input.getPaddi
ngBottom(); | 71 progressBarView.getMeasuredHeight() + input.getPaddi
ngBottom(); |
73 v.requestLayout(); | 72 v.requestLayout(); |
74 v.removeOnLayoutChangeListener(this); | 73 v.removeOnLayoutChangeListener(this); |
75 } | 74 } |
76 } | 75 } |
77 }); | 76 }); |
78 | 77 |
79 final ShortcutHelper shortcutHelper = | 78 final AddToHomescreenDialogHelper shortcutHelper = |
80 new ShortcutHelper(activity.getApplicationContext(), currentTab)
; | 79 new AddToHomescreenDialogHelper(activity.getApplicationContext()
, currentTab); |
81 | 80 |
82 // Initializing the shortcut helper is asynchronous. Until it is | 81 // Initializing the shortcut helper is asynchronous. Until it is |
83 // initialized, the UI will show a disabled text field and OK buttons. | 82 // initialized, the UI will show a disabled text field and OK buttons. |
84 // They will be enabled and pre-filled as soon as the onInitialized | 83 // They will be enabled and pre-filled as soon as the onInitialized |
85 // callback will be run. The user will still be able to cancel the | 84 // callback will be run. The user will still be able to cancel the |
86 // operation. | 85 // operation. |
87 shortcutHelper.initialize(new ShortcutHelper.ShortcutHelperObserver() { | 86 shortcutHelper.initialize(new AddToHomescreenDialogHelper.Observer() { |
88 @Override | 87 @Override |
89 public void onUserTitleAvailable(String title) { | 88 public void onUserTitleAvailable(String title) { |
90 input.setEnabled(true); | 89 input.setEnabled(true); |
91 input.setText(title); | 90 input.setText(title); |
92 } | 91 } |
93 | 92 |
94 @Override | 93 @Override |
95 public void onIconAvailable(Bitmap icon) { | 94 public void onIconAvailable(Bitmap icon) { |
96 progressBarView.setVisibility(View.GONE); | 95 progressBarView.setVisibility(View.GONE); |
97 iconView.setVisibility(View.VISIBLE); | 96 iconView.setVisibility(View.VISIBLE); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 @Override | 144 @Override |
146 public void onDismiss(DialogInterface dialog) { | 145 public void onDismiss(DialogInterface dialog) { |
147 sCurrentDialog = null; | 146 sCurrentDialog = null; |
148 shortcutHelper.destroy(); | 147 shortcutHelper.destroy(); |
149 } | 148 } |
150 }); | 149 }); |
151 | 150 |
152 dialog.show(); | 151 dialog.show(); |
153 } | 152 } |
154 } | 153 } |
OLD | NEW |