OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.appmenu; |
| 6 |
| 7 import android.content.Context; |
| 8 import android.util.AttributeSet; |
| 9 import android.view.View; |
| 10 import android.widget.LinearLayout; |
| 11 |
| 12 import org.chromium.base.ApiCompatibilityUtils; |
| 13 import org.chromium.chrome.R; |
| 14 import org.chromium.chrome.browser.ChromeActivity; |
| 15 import org.chromium.chrome.browser.bookmarks.BookmarkBridge; |
| 16 import org.chromium.chrome.browser.download.DownloadUtils; |
| 17 import org.chromium.chrome.browser.tab.Tab; |
| 18 import org.chromium.chrome.browser.widget.TintedImageButton; |
| 19 |
| 20 /** |
| 21 * A {@link LinearLayout} that displays a horizontal row of icons for page actio
ns. |
| 22 */ |
| 23 public class AppMenuIconRowFooter extends LinearLayout implements View.OnClickLi
stener { |
| 24 private ChromeActivity mActivity; |
| 25 private AppMenu mAppMenu; |
| 26 |
| 27 private TintedImageButton mForwardButton; |
| 28 private TintedImageButton mBookmarkButton; |
| 29 private TintedImageButton mDownloadButton; |
| 30 private TintedImageButton mPageInfoButton; |
| 31 private TintedImageButton mReloadButton; |
| 32 |
| 33 public AppMenuIconRowFooter(Context context, AttributeSet attrs) { |
| 34 super(context, attrs); |
| 35 } |
| 36 |
| 37 @Override |
| 38 protected void onFinishInflate() { |
| 39 super.onFinishInflate(); |
| 40 |
| 41 mForwardButton = (TintedImageButton) findViewById(R.id.forward_menu_id); |
| 42 mForwardButton.setOnClickListener(this); |
| 43 |
| 44 mBookmarkButton = (TintedImageButton) findViewById(R.id.bookmark_this_pa
ge_id); |
| 45 mBookmarkButton.setOnClickListener(this); |
| 46 |
| 47 mDownloadButton = (TintedImageButton) findViewById(R.id.offline_page_id)
; |
| 48 mDownloadButton.setOnClickListener(this); |
| 49 |
| 50 mPageInfoButton = (TintedImageButton) findViewById(R.id.info_menu_id); |
| 51 mPageInfoButton.setOnClickListener(this); |
| 52 |
| 53 mReloadButton = (TintedImageButton) findViewById(R.id.reload_menu_id); |
| 54 mReloadButton.setOnClickListener(this); |
| 55 } |
| 56 |
| 57 /** |
| 58 * Initializes the icons, setting enabled state, drawables, and content desc
riptions. |
| 59 * @param activity The {@link ChromeActivity} displaying the menu. |
| 60 * @param appMenu The {@link AppMenu} that contains the icon row. |
| 61 * @param bookmarkBridge The {@link BookmarkBridge} used to retrieve informa
tion about |
| 62 * bookmarks. |
| 63 */ |
| 64 public void initialize( |
| 65 ChromeActivity activity, AppMenu appMenu, BookmarkBridge bookmarkBri
dge) { |
| 66 mActivity = activity; |
| 67 mAppMenu = appMenu; |
| 68 Tab currentTab = mActivity.getActivityTab(); |
| 69 |
| 70 mForwardButton.setEnabled(currentTab.canGoForward()); |
| 71 |
| 72 updateBookmarkMenuItem(bookmarkBridge, currentTab); |
| 73 |
| 74 mDownloadButton.setEnabled(DownloadUtils.isAllowedToDownloadPage(current
Tab)); |
| 75 |
| 76 mReloadButton.setImageResource(R.drawable.btn_reload_stop); |
| 77 loadingStateChanged(currentTab.isLoading()); |
| 78 } |
| 79 |
| 80 @Override |
| 81 public void onClick(View v) { |
| 82 mActivity.onMenuOrKeyboardAction(v.getId(), true); |
| 83 mAppMenu.dismiss(); |
| 84 } |
| 85 |
| 86 /** |
| 87 * Called when the current tab's load state has changed. |
| 88 * @param isLoading Whether the tab is currently loading. |
| 89 */ |
| 90 public void loadingStateChanged(boolean isLoading) { |
| 91 mReloadButton.getDrawable().setLevel(isLoading |
| 92 ? AppMenuPropertiesDelegate.RELOAD_BUTTON_LEVEL_STOP_LOA
DING |
| 93 : AppMenuPropertiesDelegate.RELOAD_BUTTON_LEVEL_RELOAD); |
| 94 mReloadButton.setContentDescription(isLoading |
| 95 ? mActivity.getString(R.string.accessibility_btn_stop_lo
ading) |
| 96 : mActivity.getString(R.string.accessibility_btn_refresh
)); |
| 97 } |
| 98 |
| 99 private void updateBookmarkMenuItem(BookmarkBridge bookmarkBridge, Tab curre
ntTab) { |
| 100 mBookmarkButton.setEnabled(bookmarkBridge.isEditBookmarksEnabled()); |
| 101 |
| 102 if (currentTab.getBookmarkId() != Tab.INVALID_BOOKMARK_ID) { |
| 103 mBookmarkButton.setImageResource(R.drawable.btn_star_filled); |
| 104 mBookmarkButton.setContentDescription(mActivity.getString(R.string.e
dit_bookmark)); |
| 105 mBookmarkButton.setTint(ApiCompatibilityUtils.getColorStateList( |
| 106 getResources(), R.color.blue_mode_tint)); |
| 107 } else { |
| 108 mBookmarkButton.setImageResource(R.drawable.btn_star); |
| 109 mBookmarkButton.setContentDescription( |
| 110 mActivity.getString(R.string.accessibility_menu_bookmark)); |
| 111 } |
| 112 } |
| 113 |
| 114 TintedImageButton getForwardButtonForTests() { |
| 115 return mForwardButton; |
| 116 } |
| 117 |
| 118 TintedImageButton getBookmarkButtonForTests() { |
| 119 return mBookmarkButton; |
| 120 } |
| 121 |
| 122 TintedImageButton getDownloadButtonForTests() { |
| 123 return mDownloadButton; |
| 124 } |
| 125 |
| 126 TintedImageButton getPageInfoButtonForTests() { |
| 127 return mPageInfoButton; |
| 128 } |
| 129 |
| 130 TintedImageButton getReloadButtonForTests() { |
| 131 return mReloadButton; |
| 132 } |
| 133 } |
OLD | NEW |