|
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 org.mozilla.gecko.db.BrowserContract.Combined; |
|
9 import org.mozilla.gecko.util.StringUtils; |
|
10 |
|
11 import android.database.Cursor; |
|
12 import android.text.TextUtils; |
|
13 import android.view.View; |
|
14 import android.widget.AdapterView.AdapterContextMenuInfo; |
|
15 |
|
16 /** |
|
17 * A ContextMenuInfo for HomeListView |
|
18 */ |
|
19 public class HomeContextMenuInfo extends AdapterContextMenuInfo { |
|
20 |
|
21 public String url; |
|
22 public String title; |
|
23 public boolean isFolder = false; |
|
24 public int display = Combined.DISPLAY_NORMAL; |
|
25 public int historyId = -1; |
|
26 public int bookmarkId = -1; |
|
27 public int readingListItemId = -1; |
|
28 |
|
29 public HomeContextMenuInfo(View targetView, int position, long id) { |
|
30 super(targetView, position, id); |
|
31 } |
|
32 |
|
33 public boolean hasBookmarkId() { |
|
34 return bookmarkId > -1; |
|
35 } |
|
36 |
|
37 public boolean hasHistoryId() { |
|
38 return historyId > -1; |
|
39 } |
|
40 |
|
41 public boolean isInReadingList() { |
|
42 return readingListItemId > -1; |
|
43 } |
|
44 |
|
45 public boolean canRemove() { |
|
46 return hasBookmarkId() || hasHistoryId() || isInReadingList(); |
|
47 } |
|
48 |
|
49 public String getDisplayTitle() { |
|
50 if (!TextUtils.isEmpty(title)) { |
|
51 return title; |
|
52 } |
|
53 return StringUtils.stripCommonSubdomains(StringUtils.stripScheme(url, StringUtils.UrlFlags.STRIP_HTTPS)); |
|
54 } |
|
55 |
|
56 /* |
|
57 * Interface for creating ContextMenuInfo from cursors |
|
58 */ |
|
59 public interface Factory { |
|
60 public HomeContextMenuInfo makeInfoForCursor(View view, int position, long id, Cursor cursor); |
|
61 } |
|
62 } |