summaryrefslogtreecommitdiffstats
path: root/mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayoutAdapter.java
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayoutAdapter.java
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayoutAdapter.java')
-rw-r--r--mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayoutAdapter.java100
1 files changed, 100 insertions, 0 deletions
diff --git a/mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayoutAdapter.java b/mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayoutAdapter.java
new file mode 100644
index 000000000..367da640f
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayoutAdapter.java
@@ -0,0 +1,100 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.tabs;
+
+import org.mozilla.gecko.R;
+import org.mozilla.gecko.Tab;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+
+import java.util.ArrayList;
+
+// Adapter to bind tabs into a list
+public class TabsLayoutAdapter extends BaseAdapter {
+ public static final String LOGTAG = "Gecko" + TabsLayoutAdapter.class.getSimpleName();
+
+ private final Context mContext;
+ private final int mTabLayoutId;
+ private ArrayList<Tab> mTabs;
+ private final LayoutInflater mInflater;
+
+ public TabsLayoutAdapter (Context context, int tabLayoutId) {
+ mContext = context;
+ mInflater = LayoutInflater.from(mContext);
+ mTabLayoutId = tabLayoutId;
+ }
+
+ final void setTabs (ArrayList<Tab> tabs) {
+ mTabs = tabs;
+ notifyDataSetChanged(); // Be sure to call this whenever mTabs changes.
+ }
+
+ final boolean removeTab (Tab tab) {
+ boolean tabRemoved = mTabs.remove(tab);
+ if (tabRemoved) {
+ notifyDataSetChanged(); // Be sure to call this whenever mTabs changes.
+ }
+ return tabRemoved;
+ }
+
+ final void clear() {
+ mTabs = null;
+
+ notifyDataSetChanged(); // Be sure to call this whenever mTabs changes.
+ }
+
+ @Override
+ public int getCount() {
+ return (mTabs == null ? 0 : mTabs.size());
+ }
+
+ @Override
+ public Tab getItem(int position) {
+ return mTabs.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ final int getPositionForTab(Tab tab) {
+ if (mTabs == null || tab == null)
+ return -1;
+
+ return mTabs.indexOf(tab);
+ }
+
+ @Override
+ public boolean isEnabled(int position) {
+ return true;
+ }
+
+ @Override
+ final public TabsLayoutItemView getView(int position, View convertView, ViewGroup parent) {
+ final TabsLayoutItemView view;
+ if (convertView == null) {
+ view = newView(position, parent);
+ } else {
+ view = (TabsLayoutItemView) convertView;
+ }
+ final Tab tab = mTabs.get(position);
+ bindView(view, tab);
+ return view;
+ }
+
+ TabsLayoutItemView newView(int position, ViewGroup parent) {
+ return (TabsLayoutItemView) mInflater.inflate(mTabLayoutId, parent, false);
+ }
+
+ void bindView(TabsLayoutItemView view, Tab tab) {
+ view.assignValues(tab);
+ }
+} \ No newline at end of file