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