michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.home; michael@0: michael@0: import java.util.EnumSet; michael@0: michael@0: import org.mozilla.gecko.db.BrowserContract.HomeItems; michael@0: import org.mozilla.gecko.home.HomeConfig.ItemHandler; michael@0: import org.mozilla.gecko.home.HomeConfig.ViewConfig; michael@0: import org.mozilla.gecko.home.HomePager.OnUrlOpenListener; michael@0: import org.mozilla.gecko.home.PanelLayout.DatasetBacked; michael@0: import org.mozilla.gecko.home.PanelLayout.FilterManager; michael@0: import org.mozilla.gecko.home.PanelLayout.OnItemOpenListener; michael@0: import org.mozilla.gecko.home.PanelLayout.PanelView; michael@0: michael@0: import android.content.Context; michael@0: import android.database.Cursor; michael@0: import android.util.Log; michael@0: import android.view.View; michael@0: import android.widget.AdapterView; michael@0: michael@0: public class PanelListView extends HomeListView michael@0: implements DatasetBacked, PanelView { michael@0: michael@0: private static final String LOGTAG = "GeckoPanelListView"; michael@0: michael@0: private final ViewConfig viewConfig; michael@0: private final PanelViewAdapter adapter; michael@0: private final PanelViewItemHandler itemHandler; michael@0: private OnItemOpenListener itemOpenListener; michael@0: michael@0: public PanelListView(Context context, ViewConfig viewConfig) { michael@0: super(context); michael@0: michael@0: this.viewConfig = viewConfig; michael@0: itemHandler = new PanelViewItemHandler(viewConfig); michael@0: michael@0: adapter = new PanelViewAdapter(context, viewConfig); michael@0: setAdapter(adapter); michael@0: michael@0: setOnItemClickListener(new PanelListItemClickListener()); michael@0: } michael@0: michael@0: @Override michael@0: public void onAttachedToWindow() { michael@0: super.onAttachedToWindow(); michael@0: itemHandler.setOnItemOpenListener(itemOpenListener); michael@0: } michael@0: michael@0: @Override michael@0: public void onDetachedFromWindow() { michael@0: super.onDetachedFromWindow(); michael@0: itemHandler.setOnItemOpenListener(null); michael@0: } michael@0: michael@0: @Override michael@0: public void setDataset(Cursor cursor) { michael@0: Log.d(LOGTAG, "Setting dataset: " + viewConfig.getDatasetId()); michael@0: adapter.swapCursor(cursor); michael@0: } michael@0: michael@0: @Override michael@0: public void setOnItemOpenListener(OnItemOpenListener listener) { michael@0: itemHandler.setOnItemOpenListener(listener); michael@0: itemOpenListener = listener; michael@0: } michael@0: michael@0: @Override michael@0: public void setFilterManager(FilterManager filterManager) { michael@0: adapter.setFilterManager(filterManager); michael@0: itemHandler.setFilterManager(filterManager); michael@0: } michael@0: michael@0: private class PanelListItemClickListener implements AdapterView.OnItemClickListener { michael@0: @Override michael@0: public void onItemClick(AdapterView parent, View view, int position, long id) { michael@0: itemHandler.openItemAtPosition(adapter.getCursor(), position); michael@0: } michael@0: } michael@0: }