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

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/ntp/NewTabPageToolbar.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.ntp;
6
7 import android.content.Context;
8 import android.util.AttributeSet;
9 import android.view.Gravity;
10 import android.view.View;
11 import android.view.View.OnLongClickListener;
12 import android.view.ViewGroup;
13 import android.widget.LinearLayout;
14 import android.widget.TextView;
15 import android.widget.Toast;
16
17 import com.google.android.apps.chrome.R;
18
19 import org.chromium.base.ApiCompatibilityUtils;
20 import org.chromium.chrome.browser.widget.TintedDrawable;
21 import org.chromium.ui.base.DeviceFormFactor;
22
23 /**
24 * The toolbar at the bottom of the new tab page. Contains buttons to open the b ookmarks and
25 * recent tabs pages.
26 */
27 public class NewTabPageToolbar extends LinearLayout implements OnLongClickListen er {
28
29 private View mBookmarksButton, mRecentTabsButton;
30 private Toast mToast;
31
32 /**
33 * Constructor for inflating from xml.
34 */
35 public NewTabPageToolbar(Context context, AttributeSet attrs) {
36 super(context, attrs);
37 }
38
39 public View getBookmarksButton() {
40 return mBookmarksButton;
41 }
42
43 public View getRecentTabsButton() {
44 return mRecentTabsButton;
45 }
46
47 @Override
48 protected void onFinishInflate() {
49 mBookmarksButton = initButton(R.id.bookmarks_button, R.drawable.btn_star );
50 mRecentTabsButton = initButton(R.id.recent_tabs_button, R.drawable.btn_r ecents);
51 }
52
53 private View initButton(int buttonId, int drawableId) {
54 ViewGroup button = (ViewGroup) findViewById(buttonId);
55 TextView textView = (TextView) button.getChildAt(0);
56
57 TintedDrawable icon = TintedDrawable.constructTintedDrawable(getResource s(), drawableId);
58 ApiCompatibilityUtils.setCompoundDrawablesRelativeWithIntrinsicBounds(
59 textView, icon, null, null, null);
60 if (!DeviceFormFactor.isTablet(getContext())) {
61 // On phones, no text is shown, but long pressing shows a tooltip.
62 textView.setText("");
63 textView.setCompoundDrawablePadding(0);
64 button.setOnLongClickListener(this);
65 }
66
67 return button;
68 }
69
70 @Override
71 public boolean onLongClick(View v) {
72 // Display tooltip on long click
73 if (v == mBookmarksButton) {
74 showTooltip(R.string.ntp_bookmarks);
75 } else if (v == mRecentTabsButton) {
76 showTooltip(R.string.recent_tabs);
77 }
78 return true;
79 }
80
81 /**
82 * Shows a tooltip for a button. If a tooltip is already showing, it will be hidden.
83 * @param stringId The string resource ID of the tooltip to be shown.
84 */
85 private void showTooltip(int stringId) {
86 if (mToast != null) mToast.cancel();
87 Context ctx = getContext();
88 mToast = Toast.makeText(ctx, ctx.getResources().getString(stringId), Toa st.LENGTH_SHORT);
89 mToast.setGravity(Gravity.BOTTOM | Gravity.CENTER, 0, getHeight());
90 mToast.show();
91 }
92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698