diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /mobile/android/base/java/org/mozilla/gecko/prompts/TabInput.java | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-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/prompts/TabInput.java')
-rw-r--r-- | mobile/android/base/java/org/mozilla/gecko/prompts/TabInput.java | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/mobile/android/base/java/org/mozilla/gecko/prompts/TabInput.java b/mobile/android/base/java/org/mozilla/gecko/prompts/TabInput.java new file mode 100644 index 000000000..ab490e79c --- /dev/null +++ b/mobile/android/base/java/org/mozilla/gecko/prompts/TabInput.java @@ -0,0 +1,107 @@ +/* -*- 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.prompts; + +import java.util.LinkedHashMap; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.mozilla.gecko.AppConstants.Versions; +import org.mozilla.gecko.R; +import org.mozilla.gecko.util.ThreadUtils; + +import android.content.Context; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ListView; +import android.widget.TabHost; +import android.widget.TextView; + +public class TabInput extends PromptInput implements AdapterView.OnItemClickListener { + public static final String INPUT_TYPE = "tabs"; + public static final String LOGTAG = "GeckoTabInput"; + + /* Keeping the order of this in sync with the JSON is important. */ + final private LinkedHashMap<String, PromptListItem[]> mTabs; + + private TabHost mHost; + private int mPosition; + + public TabInput(JSONObject obj) { + super(obj); + mTabs = new LinkedHashMap<String, PromptListItem[]>(); + try { + JSONArray tabs = obj.getJSONArray("items"); + for (int i = 0; i < tabs.length(); i++) { + JSONObject tab = tabs.getJSONObject(i); + String title = tab.getString("label"); + JSONArray items = tab.getJSONArray("items"); + mTabs.put(title, PromptListItem.getArray(items)); + } + } catch (JSONException ex) { + Log.e(LOGTAG, "Exception", ex); + } + } + + @Override + public View getView(final Context context) throws UnsupportedOperationException { + final LayoutInflater inflater = LayoutInflater.from(context); + mHost = (TabHost) inflater.inflate(R.layout.tab_prompt_input, null); + mHost.setup(); + + for (String title : mTabs.keySet()) { + final TabHost.TabSpec spec = mHost.newTabSpec(title); + spec.setContent(new TabHost.TabContentFactory() { + @Override + public View createTabContent(final String tag) { + PromptListAdapter adapter = new PromptListAdapter(context, android.R.layout.simple_list_item_1, mTabs.get(tag)); + ListView listView = new ListView(context); + listView.setCacheColorHint(0); + listView.setOnItemClickListener(TabInput.this); + listView.setAdapter(adapter); + return listView; + } + }); + + spec.setIndicator(title); + mHost.addTab(spec); + } + mView = mHost; + return mHost; + } + + @Override + public Object getValue() { + JSONObject obj = new JSONObject(); + try { + obj.put("tab", mHost.getCurrentTab()); + obj.put("item", mPosition); + } catch (JSONException ex) { } + + return obj; + } + + @Override + public boolean getScrollable() { + return true; + } + + @Override + public boolean canApplyInputStyle() { + return false; + } + + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + ThreadUtils.assertOnUiThread(); + mPosition = position; + notifyListeners(Integer.toString(position)); + } + +} |