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 org.mozilla.gecko.db.BrowserContract.Combined; michael@0: import org.mozilla.gecko.util.StringUtils; michael@0: michael@0: import android.database.Cursor; michael@0: import android.text.TextUtils; michael@0: import android.view.View; michael@0: import android.widget.AdapterView.AdapterContextMenuInfo; michael@0: michael@0: /** michael@0: * A ContextMenuInfo for HomeListView michael@0: */ michael@0: public class HomeContextMenuInfo extends AdapterContextMenuInfo { michael@0: michael@0: public String url; michael@0: public String title; michael@0: public boolean isFolder = false; michael@0: public int display = Combined.DISPLAY_NORMAL; michael@0: public int historyId = -1; michael@0: public int bookmarkId = -1; michael@0: public int readingListItemId = -1; michael@0: michael@0: public HomeContextMenuInfo(View targetView, int position, long id) { michael@0: super(targetView, position, id); michael@0: } michael@0: michael@0: public boolean hasBookmarkId() { michael@0: return bookmarkId > -1; michael@0: } michael@0: michael@0: public boolean hasHistoryId() { michael@0: return historyId > -1; michael@0: } michael@0: michael@0: public boolean isInReadingList() { michael@0: return readingListItemId > -1; michael@0: } michael@0: michael@0: public boolean canRemove() { michael@0: return hasBookmarkId() || hasHistoryId() || isInReadingList(); michael@0: } michael@0: michael@0: public String getDisplayTitle() { michael@0: if (!TextUtils.isEmpty(title)) { michael@0: return title; michael@0: } michael@0: return StringUtils.stripCommonSubdomains(StringUtils.stripScheme(url, StringUtils.UrlFlags.STRIP_HTTPS)); michael@0: } michael@0: michael@0: /* michael@0: * Interface for creating ContextMenuInfo from cursors michael@0: */ michael@0: public interface Factory { michael@0: public HomeContextMenuInfo makeInfoForCursor(View view, int position, long id, Cursor cursor); michael@0: } michael@0: }