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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuPagerAdapter.java

Issue 2751333006: Create the base Custom Context Menu Dialog. (Closed)
Patch Set: git rebase Created 3 years, 9 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/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuPagerAdapter.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuPagerAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuPagerAdapter.java
new file mode 100644
index 0000000000000000000000000000000000000000..436eca1024249fc9ab9b0d94845e46355b360f55
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuPagerAdapter.java
@@ -0,0 +1,71 @@
+// Copyright 2017 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.contextmenu;
+
+import android.support.v4.text.TextUtilsCompat;
+import android.support.v4.view.PagerAdapter;
+import android.support.v4.view.ViewCompat;
+import android.util.Pair;
+import android.view.View;
+import android.view.ViewGroup;
+
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * Takes a list of views and strings and creates a wrapper for the ViewPager and Tab adapter.
+ */
+class TabularContextMenuPagerAdapter extends PagerAdapter {
+ private final List<Pair<String, ViewGroup>> mViewList;
+ private final boolean mIsRightToLeft;
+
+ /**
+ * Used in combination of a TabLayout to create a multi view layout.
+ * @param views Thew views to use in the pager Adapter.
+ */
+ TabularContextMenuPagerAdapter(List<Pair<String, ViewGroup>> views) {
+ mViewList = views;
+ mIsRightToLeft = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault())
+ == ViewCompat.LAYOUT_DIRECTION_RTL;
+ }
+
+ // Addresses the RTL display bug: https://code.google.com/p/android/issues/detail?id=56831
+ private int adjustIndexForDirectionality(int index, int count) {
+ if (mIsRightToLeft) {
+ return count - 1 - index;
+ }
+ return index;
+ }
+
+ @Override
+ public Object instantiateItem(ViewGroup container, int position) {
+ position = adjustIndexForDirectionality(position, getCount());
+ ViewGroup layout = mViewList.get(position).second;
+ container.addView(layout);
+ return layout;
+ }
+
+ @Override
+ public void destroyItem(ViewGroup container, int position, Object object) {
+ position = adjustIndexForDirectionality(position, getCount());
+ container.removeViewAt(position);
+ }
+
+ @Override
+ public int getCount() {
+ return mViewList.size();
+ }
+
+ @Override
+ public boolean isViewFromObject(View view, Object object) {
+ return view == object;
+ }
+
+ @Override
+ public CharSequence getPageTitle(int position) {
+ position = adjustIndexForDirectionality(position, getCount());
+ return mViewList.get(position).first;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698