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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java_staging/src/org/chromium/chrome/browser/ntp/NewTabPageToolbar.java
diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/ntp/NewTabPageToolbar.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/ntp/NewTabPageToolbar.java
new file mode 100644
index 0000000000000000000000000000000000000000..7ece08129b7947e64fe534be4b196728938dc234
--- /dev/null
+++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/ntp/NewTabPageToolbar.java
@@ -0,0 +1,92 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.ntp;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.Gravity;
+import android.view.View;
+import android.view.View.OnLongClickListener;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.google.android.apps.chrome.R;
+
+import org.chromium.base.ApiCompatibilityUtils;
+import org.chromium.chrome.browser.widget.TintedDrawable;
+import org.chromium.ui.base.DeviceFormFactor;
+
+/**
+ * The toolbar at the bottom of the new tab page. Contains buttons to open the bookmarks and
+ * recent tabs pages.
+ */
+public class NewTabPageToolbar extends LinearLayout implements OnLongClickListener {
+
+ private View mBookmarksButton, mRecentTabsButton;
+ private Toast mToast;
+
+ /**
+ * Constructor for inflating from xml.
+ */
+ public NewTabPageToolbar(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public View getBookmarksButton() {
+ return mBookmarksButton;
+ }
+
+ public View getRecentTabsButton() {
+ return mRecentTabsButton;
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ mBookmarksButton = initButton(R.id.bookmarks_button, R.drawable.btn_star);
+ mRecentTabsButton = initButton(R.id.recent_tabs_button, R.drawable.btn_recents);
+ }
+
+ private View initButton(int buttonId, int drawableId) {
+ ViewGroup button = (ViewGroup) findViewById(buttonId);
+ TextView textView = (TextView) button.getChildAt(0);
+
+ TintedDrawable icon = TintedDrawable.constructTintedDrawable(getResources(), drawableId);
+ ApiCompatibilityUtils.setCompoundDrawablesRelativeWithIntrinsicBounds(
+ textView, icon, null, null, null);
+ if (!DeviceFormFactor.isTablet(getContext())) {
+ // On phones, no text is shown, but long pressing shows a tooltip.
+ textView.setText("");
+ textView.setCompoundDrawablePadding(0);
+ button.setOnLongClickListener(this);
+ }
+
+ return button;
+ }
+
+ @Override
+ public boolean onLongClick(View v) {
+ // Display tooltip on long click
+ if (v == mBookmarksButton) {
+ showTooltip(R.string.ntp_bookmarks);
+ } else if (v == mRecentTabsButton) {
+ showTooltip(R.string.recent_tabs);
+ }
+ return true;
+ }
+
+ /**
+ * Shows a tooltip for a button. If a tooltip is already showing, it will be hidden.
+ * @param stringId The string resource ID of the tooltip to be shown.
+ */
+ private void showTooltip(int stringId) {
+ if (mToast != null) mToast.cancel();
+ Context ctx = getContext();
+ mToast = Toast.makeText(ctx, ctx.getResources().getString(stringId), Toast.LENGTH_SHORT);
+ mToast.setGravity(Gravity.BOTTOM | Gravity.CENTER, 0, getHeight());
+ mToast.show();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698