Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java

Issue 1203223003: Replace return button with close button on custom tab toolbar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: get resource from intent data provider Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.customtabs; 5 package org.chromium.chrome.browser.customtabs;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.app.PendingIntent; 8 import android.app.PendingIntent;
9 import android.app.PendingIntent.CanceledException; 9 import android.app.PendingIntent.CanceledException;
10 import android.content.Context; 10 import android.content.Context;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 "android.support.CUSTOM_TABS:session_id"; 46 "android.support.CUSTOM_TABS:session_id";
47 47
48 /** 48 /**
49 * Extra used to keep the caller alive. Its value is an Intent. 49 * Extra used to keep the caller alive. Its value is an Intent.
50 */ 50 */
51 public static final String EXTRA_CUSTOM_TABS_KEEP_ALIVE = 51 public static final String EXTRA_CUSTOM_TABS_KEEP_ALIVE =
52 "android.support.CUSTOM_TABS:keep_alive"; 52 "android.support.CUSTOM_TABS:keep_alive";
53 53
54 /** 54 /**
55 * Extra that changes the background color for the omnibox. colorRes is an i nt that specifies a 55 * Extra that changes the background color for the omnibox. colorRes is an i nt that specifies a
56 * color 56 * color.
57 */ 57 */
58 public static final String EXTRA_CUSTOM_TABS_TOOLBAR_COLOR = 58 public static final String EXTRA_CUSTOM_TABS_TOOLBAR_COLOR =
59 "android.support.CUSTOM_TABS:toolbar_color"; 59 "android.support.CUSTOM_TABS:toolbar_color";
60 60
61 /** 61 /**
62 * Extra int that specifies the style of the back button on the toolbar. Def ault is showing a
63 * cross icon.
64 */
65 public static final String EXTRA_CUSTOM_TABS_CLOSE_BUTTON_STYLE =
66 "android.support.CUSTOM_TABS:close_button_style";
67
68 /**
69 * Uses 'X'-like cross icon for close button.
70 */
71 public static final int CUSTOM_TAB_CLOSE_BUTTON_CROSS = 0;
72
73 /**
74 * Uses '<'-like chevron arrow icon for close button.
75 */
76 public static final int CUSTOM_TAB_CLOSE_BUTTON_ARROW = 1;
77
78 /**
62 * Extra int that specifies state for showing the page title. Default is sho wing only the domain 79 * Extra int that specifies state for showing the page title. Default is sho wing only the domain
63 * and no information about the title. 80 * and no information about the title.
64 */ 81 */
65 public static final String EXTRA_CUSTOM_TABS_TITLE_VISIBILITY_STATE = 82 public static final String EXTRA_CUSTOM_TABS_TITLE_VISIBILITY_STATE =
66 "android.support.CUSTOM_TABS:title_visibility"; 83 "android.support.CUSTOM_TABS:title_visibility";
67 84
68 /** 85 /**
69 * Don't show any title. Shows only the domain. 86 * Don't show any title. Shows only the domain.
70 */ 87 */
71 public static final int CUSTOM_TAB_NO_TITLE = 0; 88 public static final int CUSTOM_TAB_NO_TITLE = 0;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 * An invalid session ID, used when none is provided in the intent. 136 * An invalid session ID, used when none is provided in the intent.
120 */ 137 */
121 public static final long INVALID_SESSION_ID = -1; 138 public static final long INVALID_SESSION_ID = -1;
122 139
123 private static final String BUNDLE_PACKAGE_NAME = "android:packageName"; 140 private static final String BUNDLE_PACKAGE_NAME = "android:packageName";
124 private static final String BUNDLE_ENTER_ANIMATION_RESOURCE = "android:animE nterRes"; 141 private static final String BUNDLE_ENTER_ANIMATION_RESOURCE = "android:animE nterRes";
125 private static final String BUNDLE_EXIT_ANIMATION_RESOURCE = "android:animEx itRes"; 142 private static final String BUNDLE_EXIT_ANIMATION_RESOURCE = "android:animEx itRes";
126 private final long mSessionId; 143 private final long mSessionId;
127 private final Intent mKeepAliveServiceIntent; 144 private final Intent mKeepAliveServiceIntent;
128 private final int mTitleVisibilityState; 145 private final int mTitleVisibilityState;
146 private final int mCloseButtonRes;
129 private int mToolbarColor; 147 private int mToolbarColor;
130 private Bitmap mIcon; 148 private Bitmap mIcon;
131 private PendingIntent mActionButtonPendingIntent; 149 private PendingIntent mActionButtonPendingIntent;
132 private List<Pair<String, PendingIntent>> mMenuEntries = new ArrayList<>(); 150 private List<Pair<String, PendingIntent>> mMenuEntries = new ArrayList<>();
133 private Bundle mAnimationBundle; 151 private Bundle mAnimationBundle;
134 // OnFinished listener for PendingIntents. Used for testing only. 152 // OnFinished listener for PendingIntents. Used for testing only.
135 private PendingIntent.OnFinished mOnFinished; 153 private PendingIntent.OnFinished mOnFinished;
136 154
137 /** 155 /**
138 * Constructs a {@link CustomTabIntentDataProvider}. 156 * Constructs a {@link CustomTabIntentDataProvider}.
(...skipping 29 matching lines...) Expand all
168 PendingIntent pendingIntent = IntentUtils.safeGetParcelable( 186 PendingIntent pendingIntent = IntentUtils.safeGetParcelable(
169 bundle, KEY_CUSTOM_TABS_PENDING_INTENT); 187 bundle, KEY_CUSTOM_TABS_PENDING_INTENT);
170 if (TextUtils.isEmpty(title) || pendingIntent == null) continue; 188 if (TextUtils.isEmpty(title) || pendingIntent == null) continue;
171 mMenuEntries.add(new Pair<String, PendingIntent>(title, pendingI ntent)); 189 mMenuEntries.add(new Pair<String, PendingIntent>(title, pendingI ntent));
172 } 190 }
173 } 191 }
174 192
175 mAnimationBundle = IntentUtils.safeGetBundleExtra( 193 mAnimationBundle = IntentUtils.safeGetBundleExtra(
176 intent, EXTRA_CUSTOM_TABS_EXIT_ANIMATION_BUNDLE); 194 intent, EXTRA_CUSTOM_TABS_EXIT_ANIMATION_BUNDLE);
177 195
196 int closeButtonStyle = IntentUtils.safeGetIntExtra(intent,
197 EXTRA_CUSTOM_TABS_CLOSE_BUTTON_STYLE, CUSTOM_TAB_CLOSE_BUTTON_CR OSS);
198 switch(closeButtonStyle) {
199 case CustomTabIntentDataProvider.CUSTOM_TAB_CLOSE_BUTTON_ARROW:
200 mCloseButtonRes = R.drawable.btn_chevron_left;
201 break;
202 case CustomTabIntentDataProvider.CUSTOM_TAB_CLOSE_BUTTON_CROSS:
203 default:
204 mCloseButtonRes = R.drawable.btn_close;
Yusuf 2015/06/29 23:05:58 mCloseButtonResId
Ian Wen 2015/06/29 23:56:00 Done.
205 }
206
178 mTitleVisibilityState = IntentUtils.safeGetIntExtra( 207 mTitleVisibilityState = IntentUtils.safeGetIntExtra(
179 intent, EXTRA_CUSTOM_TABS_TITLE_VISIBILITY_STATE, CUSTOM_TAB_NO_ TITLE); 208 intent, EXTRA_CUSTOM_TABS_TITLE_VISIBILITY_STATE, CUSTOM_TAB_NO_ TITLE);
180 } 209 }
181 210
182 /** 211 /**
183 * Processes the color passed from the client app and updates {@link #mToolb arColor}. 212 * Processes the color passed from the client app and updates {@link #mToolb arColor}.
184 */ 213 */
185 private void retrieveToolbarColor(Intent intent, Context context) { 214 private void retrieveToolbarColor(Intent intent, Context context) {
186 int color = IntentUtils.safeGetIntExtra(intent, EXTRA_CUSTOM_TABS_TOOLBA R_COLOR, 215 int color = IntentUtils.safeGetIntExtra(intent, EXTRA_CUSTOM_TABS_TOOLBA R_COLOR,
187 context.getResources().getColor(R.color.default_primary_color)); 216 context.getResources().getColor(R.color.default_primary_color));
(...skipping 24 matching lines...) Expand all
212 241
213 /** 242 /**
214 * @return The toolbar color specified in the intent. Will return the color of 243 * @return The toolbar color specified in the intent. Will return the color of
215 * default_primary_color, if not set in the intent. 244 * default_primary_color, if not set in the intent.
216 */ 245 */
217 public int getToolbarColor() { 246 public int getToolbarColor() {
218 return mToolbarColor; 247 return mToolbarColor;
219 } 248 }
220 249
221 /** 250 /**
251 * @return The resource id of the close button shown in the custom tab toolb ar.
252 */
253 public int getCloseButtonIconRes() {
Yusuf 2015/06/29 23:05:58 getCloseButtonIconResId
Ian Wen 2015/06/29 23:56:00 Done.
254 return mCloseButtonRes;
255 }
256
257 /**
222 * @return The title visibility state for the toolbar. 258 * @return The title visibility state for the toolbar.
223 * Default is {@link CustomTabIntentDataProvider#CUSTOM_TAB_NO_TITLE }. 259 * Default is {@link CustomTabIntentDataProvider#CUSTOM_TAB_NO_TITLE }.
224 */ 260 */
225 public int getTitleVisibilityState() { 261 public int getTitleVisibilityState() {
226 return mTitleVisibilityState; 262 return mTitleVisibilityState;
227 } 263 }
228 264
229 /** 265 /**
230 * @return Whether the client app has provided sufficient info for the toolb ar to show the 266 * @return Whether the client app has provided sufficient info for the toolb ar to show the
231 * action button. 267 * action button.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 374
339 /** 375 /**
340 * Set the callback object for {@link PendingIntent}s that are sent in this class. For testing 376 * Set the callback object for {@link PendingIntent}s that are sent in this class. For testing
341 * purpose only. 377 * purpose only.
342 */ 378 */
343 @VisibleForTesting 379 @VisibleForTesting
344 void setPendingIntentOnFinishedForTesting(PendingIntent.OnFinished onFinishe d) { 380 void setPendingIntentOnFinishedForTesting(PendingIntent.OnFinished onFinishe d) {
345 mOnFinished = onFinished; 381 mOnFinished = onFinished;
346 } 382 }
347 } 383 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698