1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/ReaderModeUtils.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,48 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +package org.mozilla.gecko; 1.9 + 1.10 +import org.mozilla.gecko.util.StringUtils; 1.11 + 1.12 +import android.net.Uri; 1.13 + 1.14 +public class ReaderModeUtils { 1.15 + private static final String LOGTAG = "ReaderModeUtils"; 1.16 + 1.17 + public static String getUrlFromAboutReader(String aboutReaderUrl) { 1.18 + return StringUtils.getQueryParameter(aboutReaderUrl, "url"); 1.19 + } 1.20 + 1.21 + public static boolean isEnteringReaderMode(String currentUrl, String newUrl) { 1.22 + if (currentUrl == null || newUrl == null) { 1.23 + return false; 1.24 + } 1.25 + 1.26 + if (!AboutPages.isAboutReader(newUrl)) { 1.27 + return false; 1.28 + } 1.29 + 1.30 + String urlFromAboutReader = getUrlFromAboutReader(newUrl); 1.31 + if (urlFromAboutReader == null) { 1.32 + return false; 1.33 + } 1.34 + 1.35 + return urlFromAboutReader.equals(currentUrl); 1.36 + } 1.37 + 1.38 + public static String getAboutReaderForUrl(String url) { 1.39 + return getAboutReaderForUrl(url, -1); 1.40 + } 1.41 + 1.42 + public static String getAboutReaderForUrl(String url, int tabId) { 1.43 + String aboutReaderUrl = AboutPages.READER + "?url=" + Uri.encode(url); 1.44 + 1.45 + if (tabId >= 0) { 1.46 + aboutReaderUrl += "&tabId=" + tabId; 1.47 + } 1.48 + 1.49 + return aboutReaderUrl; 1.50 + } 1.51 +}