mobile/android/base/ReaderModeUtils.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 package org.mozilla.gecko;
     7 import org.mozilla.gecko.util.StringUtils;
     9 import android.net.Uri;
    11 public class ReaderModeUtils {
    12     private static final String LOGTAG = "ReaderModeUtils";
    14     public static String getUrlFromAboutReader(String aboutReaderUrl) {
    15         return StringUtils.getQueryParameter(aboutReaderUrl, "url");
    16     }
    18     public static boolean isEnteringReaderMode(String currentUrl, String newUrl) {
    19         if (currentUrl == null || newUrl == null) {
    20             return false;
    21         }
    23         if (!AboutPages.isAboutReader(newUrl)) {
    24             return false;
    25         }
    27         String urlFromAboutReader = getUrlFromAboutReader(newUrl);
    28         if (urlFromAboutReader == null) {
    29             return false;
    30         }
    32         return urlFromAboutReader.equals(currentUrl);
    33     }
    35     public static String getAboutReaderForUrl(String url) {
    36         return getAboutReaderForUrl(url, -1);
    37     }
    39     public static String getAboutReaderForUrl(String url, int tabId) {
    40         String aboutReaderUrl = AboutPages.READER + "?url=" + Uri.encode(url);
    42         if (tabId >= 0) {
    43             aboutReaderUrl += "&tabId=" + tabId;
    44         }
    46         return aboutReaderUrl;
    47     }
    48 }

mercurial