Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into sebastian/506-text-selection
Browse files Browse the repository at this point in the history
  • Loading branch information
pocmo committed Apr 25, 2017
2 parents 5fb4c04 + cc3ff9c commit 8fe488c
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 1 deletion.
42 changes: 42 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,48 @@ dependencies {
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.7.0'
}

// -------------------------------------------------------------------------------------------------
// Replace placeholders in shortcuts.xml (Android requires a hard-coded package name. But we use
// different packages based on flavor.
// Code based on workaround (comment 16): https://issuetracker.google.com/issues/37124066
// -------------------------------------------------------------------------------------------------

def replacePlaceholdersInFile(basePath, fileName, placeholders) {
def file = new File(basePath, fileName);

if (!file.exists()) {
throw new GradleException("Unable to replace placeholders in " + file.toString() + ". File cannot be found.")
}

logger.debug("Replacing placeholders in " + file.toString())
logger.debug("Placeholders: " + placeholders.toString())

def content = file.getText('UTF-8')

placeholders.each { entry ->
content = content.replaceAll("\\\$\\{${entry.key}\\}", entry.value)
}

file.write(content, 'UTF-8')
}

afterEvaluate {
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
output.processResources.doFirst {
// prepare placeholder map from manifestPlaceholders including applicationId placeholder
def placeholders = variant.mergedFlavor.manifestPlaceholders + [applicationId: variant.applicationId]

replacePlaceholdersInFile(resDir, 'xml-v25/shortcuts.xml', placeholders)
}
}
}
}

// -------------------------------------------------------------------------------------------------
// Generate blocklists
// -------------------------------------------------------------------------------------------------

task buildBlocklists(type:Exec) {
workingDir '..'

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
<data android:mimeType="text/plain"/>
<data android:mimeType="application/xhtml+xml"/>
</intent-filter>
</activity>

<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />
</activity>"

<activity android:name=".activity.TextActionActivity"
android:label="@string/text_selection_search_action"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ protected void onResumeFragments() {

if (ACTION_ERASE.equals(intent.getAction())) {
eraseFromNotification(intent.getBooleanExtra(EXTRA_FINISH, false));

// We do not want to erase again the next time we resume the app.
setIntent(new Intent(Intent.ACTION_MAIN));
}

if (pendingUrl != null && !new Settings(this).shouldShowFirstrun()) {
Expand Down
Binary file added app/src/main/res/drawable-hdpi/ic_shortcut_erase.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@
Clicking this action will launch Focus and perform a search in the default search engine. -->
<string name="text_selection_search_action">Private Search</string>

<!-- On Android 7+ users can add a shortcut for erasing the browsing history to the home screen.
This is the label for this shortcut. Android recommends a maximum length of 10 characters. -->

<string name="shortcut_erase_short_label">Erase</string>
<!-- The same as 'shortcut_erase_short_label' but more descriptive. The launcher shows this
instead of the short title when it has enough space. Android recommends a maximum length
of 25 characters. -->
<string name="shortcut_erase_long_label">Erase browsing history</string>

<!-- Content of about focus. Argument 1 is the app name (Firefox Focus/Firefox Klar/etc).
Argument 2 is the url for the learn-more link. -->
<string name="about_content"><![CDATA[
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/res/xml-v25/shortcuts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="erase"
android:enabled="true"
android:icon="@drawable/ic_shortcut_erase"
android:shortcutShortLabel="@string/shortcut_erase_short_label"
android:shortcutLongLabel="@string/shortcut_erase_long_label">
<intent
android:action="erase"
android:targetPackage="${applicationId}"
android:targetClass="org.mozilla.focus.activity.MainActivity">
<extra android:name="finish" android:value="true" />
</intent>
</shortcut>
</shortcuts>

0 comments on commit 8fe488c

Please sign in to comment.