mobile/android/base/home/HomeContextMenuInfo.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/home/HomeContextMenuInfo.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,62 @@
     1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +package org.mozilla.gecko.home;
    1.10 +
    1.11 +import org.mozilla.gecko.db.BrowserContract.Combined;
    1.12 +import org.mozilla.gecko.util.StringUtils;
    1.13 +
    1.14 +import android.database.Cursor;
    1.15 +import android.text.TextUtils;
    1.16 +import android.view.View;
    1.17 +import android.widget.AdapterView.AdapterContextMenuInfo;
    1.18 +
    1.19 +/**
    1.20 + * A ContextMenuInfo for HomeListView
    1.21 + */
    1.22 +public class HomeContextMenuInfo extends AdapterContextMenuInfo {
    1.23 +
    1.24 +    public String url;
    1.25 +    public String title;
    1.26 +    public boolean isFolder = false;
    1.27 +    public int display = Combined.DISPLAY_NORMAL;
    1.28 +    public int historyId = -1;
    1.29 +    public int bookmarkId = -1;
    1.30 +    public int readingListItemId = -1;
    1.31 +
    1.32 +    public HomeContextMenuInfo(View targetView, int position, long id) {
    1.33 +        super(targetView, position, id);
    1.34 +    }
    1.35 +
    1.36 +    public boolean hasBookmarkId() {
    1.37 +        return bookmarkId > -1;
    1.38 +    }
    1.39 +
    1.40 +    public boolean hasHistoryId() {
    1.41 +        return historyId > -1;
    1.42 +    }
    1.43 +
    1.44 +    public boolean isInReadingList() {
    1.45 +        return readingListItemId > -1;
    1.46 +    }
    1.47 +
    1.48 +    public boolean canRemove() {
    1.49 +        return hasBookmarkId() || hasHistoryId() || isInReadingList();
    1.50 +    }
    1.51 +
    1.52 +    public String getDisplayTitle() {
    1.53 +        if (!TextUtils.isEmpty(title)) {
    1.54 +            return title;
    1.55 +        }
    1.56 +        return StringUtils.stripCommonSubdomains(StringUtils.stripScheme(url, StringUtils.UrlFlags.STRIP_HTTPS));
    1.57 +    }
    1.58 +
    1.59 +    /*
    1.60 +     * Interface for creating ContextMenuInfo from cursors
    1.61 +     */
    1.62 +    public interface Factory {
    1.63 +        public HomeContextMenuInfo makeInfoForCursor(View view, int position, long id, Cursor cursor);
    1.64 +    }
    1.65 +}

mercurial