Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | package org.mozilla.gecko.home; |
michael@0 | 7 | |
michael@0 | 8 | import java.util.EnumSet; |
michael@0 | 9 | |
michael@0 | 10 | import org.mozilla.gecko.db.BrowserContract.HomeItems; |
michael@0 | 11 | import org.mozilla.gecko.home.HomeConfig.ItemHandler; |
michael@0 | 12 | import org.mozilla.gecko.home.HomeConfig.ViewConfig; |
michael@0 | 13 | import org.mozilla.gecko.home.HomePager.OnUrlOpenListener; |
michael@0 | 14 | import org.mozilla.gecko.home.PanelLayout.DatasetBacked; |
michael@0 | 15 | import org.mozilla.gecko.home.PanelLayout.FilterManager; |
michael@0 | 16 | import org.mozilla.gecko.home.PanelLayout.OnItemOpenListener; |
michael@0 | 17 | import org.mozilla.gecko.home.PanelLayout.PanelView; |
michael@0 | 18 | |
michael@0 | 19 | import android.content.Context; |
michael@0 | 20 | import android.database.Cursor; |
michael@0 | 21 | import android.util.Log; |
michael@0 | 22 | import android.view.View; |
michael@0 | 23 | import android.widget.AdapterView; |
michael@0 | 24 | |
michael@0 | 25 | public class PanelListView extends HomeListView |
michael@0 | 26 | implements DatasetBacked, PanelView { |
michael@0 | 27 | |
michael@0 | 28 | private static final String LOGTAG = "GeckoPanelListView"; |
michael@0 | 29 | |
michael@0 | 30 | private final ViewConfig viewConfig; |
michael@0 | 31 | private final PanelViewAdapter adapter; |
michael@0 | 32 | private final PanelViewItemHandler itemHandler; |
michael@0 | 33 | private OnItemOpenListener itemOpenListener; |
michael@0 | 34 | |
michael@0 | 35 | public PanelListView(Context context, ViewConfig viewConfig) { |
michael@0 | 36 | super(context); |
michael@0 | 37 | |
michael@0 | 38 | this.viewConfig = viewConfig; |
michael@0 | 39 | itemHandler = new PanelViewItemHandler(viewConfig); |
michael@0 | 40 | |
michael@0 | 41 | adapter = new PanelViewAdapter(context, viewConfig); |
michael@0 | 42 | setAdapter(adapter); |
michael@0 | 43 | |
michael@0 | 44 | setOnItemClickListener(new PanelListItemClickListener()); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | @Override |
michael@0 | 48 | public void onAttachedToWindow() { |
michael@0 | 49 | super.onAttachedToWindow(); |
michael@0 | 50 | itemHandler.setOnItemOpenListener(itemOpenListener); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | @Override |
michael@0 | 54 | public void onDetachedFromWindow() { |
michael@0 | 55 | super.onDetachedFromWindow(); |
michael@0 | 56 | itemHandler.setOnItemOpenListener(null); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | @Override |
michael@0 | 60 | public void setDataset(Cursor cursor) { |
michael@0 | 61 | Log.d(LOGTAG, "Setting dataset: " + viewConfig.getDatasetId()); |
michael@0 | 62 | adapter.swapCursor(cursor); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | @Override |
michael@0 | 66 | public void setOnItemOpenListener(OnItemOpenListener listener) { |
michael@0 | 67 | itemHandler.setOnItemOpenListener(listener); |
michael@0 | 68 | itemOpenListener = listener; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | @Override |
michael@0 | 72 | public void setFilterManager(FilterManager filterManager) { |
michael@0 | 73 | adapter.setFilterManager(filterManager); |
michael@0 | 74 | itemHandler.setFilterManager(filterManager); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | private class PanelListItemClickListener implements AdapterView.OnItemClickListener { |
michael@0 | 78 | @Override |
michael@0 | 79 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
michael@0 | 80 | itemHandler.openItemAtPosition(adapter.getCursor(), position); |
michael@0 | 81 | } |
michael@0 | 82 | } |
michael@0 | 83 | } |