OLD | NEW |
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.PendingIntent; |
| 8 import android.app.PendingIntent.CanceledException; |
7 import android.content.Intent; | 9 import android.content.Intent; |
8 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
9 import android.net.Uri; | 11 import android.net.Uri; |
10 import android.os.IBinder; | 12 import android.os.IBinder; |
11 import android.support.customtabs.CustomTabsCallback; | 13 import android.support.customtabs.CustomTabsCallback; |
12 import android.support.customtabs.CustomTabsIntent; | 14 import android.support.customtabs.CustomTabsIntent; |
13 import android.text.TextUtils; | 15 import android.text.TextUtils; |
14 import android.view.KeyEvent; | 16 import android.view.KeyEvent; |
15 import android.view.MenuItem; | 17 import android.view.MenuItem; |
16 import android.view.View; | 18 import android.view.View; |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 ViewGroup bottomBar = (ViewGroup) findViewById(R.id.bottombar); | 477 ViewGroup bottomBar = (ViewGroup) findViewById(R.id.bottombar); |
476 ImageButton button = (ImageButton) bottomBar.findViewById(params.getId()
); | 478 ImageButton button = (ImageButton) bottomBar.findViewById(params.getId()
); |
477 button.setContentDescription(params.getDescription()); | 479 button.setContentDescription(params.getDescription()); |
478 button.setImageDrawable(params.getIcon(getResources())); | 480 button.setImageDrawable(params.getIcon(getResources())); |
479 } | 481 } |
480 | 482 |
481 /** | 483 /** |
482 * Inflates the bottom bar {@link ViewStub} and its shadow, and populates it
with items. | 484 * Inflates the bottom bar {@link ViewStub} and its shadow, and populates it
with items. |
483 */ | 485 */ |
484 private void showBottomBarIfNecessary() { | 486 private void showBottomBarIfNecessary() { |
| 487 // TODO (yusufo): Find a better place for the layout code here and in Cu
stomButtonParams. |
485 // TODO (ianwen): if button icon is too wide, show them in overflow menu
instead. If button | 488 // TODO (ianwen): if button icon is too wide, show them in overflow menu
instead. If button |
486 // id is not specified, the overflow sequence should be toolbar -> botto
m bar -> menu. | 489 // id is not specified, the overflow sequence should be toolbar -> botto
m bar -> menu. |
487 if (!mIntentDataProvider.shouldShowBottomBar()) return; | 490 if (!mIntentDataProvider.shouldShowBottomBar()) return; |
488 | 491 |
489 ViewStub bottomBarStub = ((ViewStub) findViewById(R.id.bottombar_stub)); | 492 ViewStub bottomBarStub = ((ViewStub) findViewById(R.id.bottombar_stub)); |
490 bottomBarStub.setLayoutResource(R.layout.custom_tabs_bottombar); | 493 bottomBarStub.setLayoutResource(R.layout.custom_tabs_bottombar); |
491 bottomBarStub.inflate(); | 494 bottomBarStub.inflate(); |
492 | 495 |
493 // Unlike others, this shadow docks itself at bottom and casts graphics
upwards. | 496 // Unlike others, this shadow docks itself at bottom and casts graphics
upwards. |
494 FadingShadowView shadow = (FadingShadowView) findViewById(R.id.bottombar
_shadow); | 497 FadingShadowView shadow = (FadingShadowView) findViewById(R.id.bottombar
_shadow); |
495 shadow.setVisibility(View.VISIBLE); | 498 shadow.setVisibility(View.VISIBLE); |
496 shadow.init(ApiCompatibilityUtils.getColor(getResources(), | 499 shadow.init(ApiCompatibilityUtils.getColor(getResources(), |
497 R.color.bottom_bar_shadow_color), FadingShadow.POSITION_BOTTOM); | 500 R.color.bottom_bar_shadow_color), FadingShadow.POSITION_BOTTOM); |
498 | 501 |
499 ViewGroup bottomBar = (ViewGroup) findViewById(R.id.bottombar); | 502 ViewGroup bottomBar = (ViewGroup) findViewById(R.id.bottombar); |
500 bottomBar.setBackgroundColor(mIntentDataProvider.getToolbarColor()); | 503 bottomBar.setBackgroundColor(mIntentDataProvider.getToolbarColor()); |
501 List<CustomButtonParams> items = mIntentDataProvider.getCustomButtonsOnB
ottombar(); | 504 List<CustomButtonParams> items = mIntentDataProvider.getCustomButtonsOnB
ottombar(); |
502 for (CustomButtonParams params : items) { | 505 for (CustomButtonParams params : items) { |
503 if (params.showOnToolbar()) continue; | 506 if (params.showOnToolbar()) continue; |
504 ImageButton button = params.buildBottomBarButton(this, bottomBar); | 507 final PendingIntent pendingIntent = params.getPendingIntent(); |
| 508 OnClickListener clickListener = null; |
| 509 if (pendingIntent != null) { |
| 510 clickListener = new OnClickListener() { |
| 511 @Override |
| 512 public void onClick(View v) { |
| 513 Intent addedIntent = new Intent(); |
| 514 addedIntent.setData(Uri.parse(getActivityTab().getUrl())
); |
| 515 try { |
| 516 pendingIntent.send(CustomTabActivity.this, 0, addedI
ntent, null, null); |
| 517 } catch (CanceledException e) { |
| 518 Log.e(TAG, |
| 519 "CanceledException while sending pending int
ent in custom tab"); |
| 520 } |
| 521 } |
| 522 }; |
| 523 } |
| 524 ImageButton button = params.buildBottomBarButton(this, bottomBar, cl
ickListener); |
505 bottomBar.addView(button); | 525 bottomBar.addView(button); |
506 } | 526 } |
507 } | 527 } |
508 | 528 |
509 @Override | 529 @Override |
510 public boolean shouldShowAppMenu() { | 530 public boolean shouldShowAppMenu() { |
511 return getActivityTab() != null && getToolbarManager().isInitialized(); | 531 return getActivityTab() != null && getToolbarManager().isInitialized(); |
512 } | 532 } |
513 | 533 |
514 @Override | 534 @Override |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 | 619 |
600 /** | 620 /** |
601 * @return The {@link CustomTabIntentDataProvider} for this {@link CustomTab
Activity}. For test | 621 * @return The {@link CustomTabIntentDataProvider} for this {@link CustomTab
Activity}. For test |
602 * purposes only. | 622 * purposes only. |
603 */ | 623 */ |
604 @VisibleForTesting | 624 @VisibleForTesting |
605 CustomTabIntentDataProvider getIntentDataProvider() { | 625 CustomTabIntentDataProvider getIntentDataProvider() { |
606 return mIntentDataProvider; | 626 return mIntentDataProvider; |
607 } | 627 } |
608 } | 628 } |
OLD | NEW |