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

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

Issue 2751333006: Create the base Custom Context Menu Dialog. (Closed)
Patch Set: 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/CustomContextMenuPagerAdapter.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/CustomContextMenuPagerAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/CustomContextMenuPagerAdapter.java
new file mode 100644
index 0000000000000000000000000000000000000000..8947c86bb40f7ea5e16d7ad01262793111764840
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/CustomContextMenuPagerAdapter.java
@@ -0,0 +1,69 @@
+// 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 CustomContextMenuPagerAdapter extends PagerAdapter {
+ private List<Pair<String, ViewGroup>> mViewList;
David Trainor- moved to gerrit 2017/03/21 16:30:02 I'd say final here as well and everything else tha
JJ 2017/03/22 23:35:33 Done.
+
+ /**
+ * Used in combination of a TabLayout to create a multi view layout.
+ * @param views Thew views to use in the pager Adapter.
+ */
+ CustomContextMenuPagerAdapter(List<Pair<String, ViewGroup>> views) {
+ mViewList = views;
+ }
+
+ // Used thanks due to a bug in displaying RTL.
+ private static int adjustIndexForDirectionality(int index, int count) {
JJ 2017/03/17 20:58:20 Possibly thinking in the future of making a Revers
David Trainor- moved to gerrit 2017/03/21 16:30:02 Adding a TODO isn't a bad idea. Does this logic l
JJ 2017/03/22 23:35:33 Likely an existing bug seeing the last edit was in
+ if (TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault())
David Trainor- moved to gerrit 2017/03/21 16:30:02 Should we cache whether or not the direction is RT
JJ 2017/03/22 23:35:32 Removed static for this class to do this. (I mean
+ == ViewCompat.LAYOUT_DIRECTION_RTL) {
+ 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