add ability to add shortcuts to the homescreen, more work still needed
This commit is contained in:
parent
c19dbe09bb
commit
416dc4594d
@ -10,6 +10,7 @@
|
|||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||||
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
|
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
|
||||||
<uses-permission android:name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS"/>
|
<uses-permission android:name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS"/>
|
||||||
|
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
|
||||||
|
|
||||||
<uses-feature
|
<uses-feature
|
||||||
android:name="android.hardware.location.gps"
|
android:name="android.hardware.location.gps"
|
||||||
|
@ -676,6 +676,13 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
currentView.goForward();
|
currentView.goForward();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.action_add_to_homescreen:
|
||||||
|
if (currentView != null) {
|
||||||
|
HistoryItem shortcut = new HistoryItem(currentView.getUrl(), currentView.getTitle());
|
||||||
|
shortcut.setBitmap(currentView.getFavicon());
|
||||||
|
Utils.createShortcut(this, shortcut);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
case R.id.action_new_tab:
|
case R.id.action_new_tab:
|
||||||
newTab(null, true);
|
newTab(null, true);
|
||||||
return true;
|
return true;
|
||||||
|
@ -20,12 +20,14 @@ import android.graphics.LinearGradient;
|
|||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Path;
|
import android.graphics.Path;
|
||||||
import android.graphics.Shader;
|
import android.graphics.Shader;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -43,7 +45,9 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import acr.browser.lightning.R;
|
import acr.browser.lightning.R;
|
||||||
|
import acr.browser.lightning.activity.MainActivity;
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
|
import acr.browser.lightning.database.HistoryItem;
|
||||||
import acr.browser.lightning.download.DownloadHandler;
|
import acr.browser.lightning.download.DownloadHandler;
|
||||||
import acr.browser.lightning.preference.PreferenceManager;
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
|
|
||||||
@ -377,4 +381,21 @@ public final class Utils {
|
|||||||
|
|
||||||
canvas.drawPath(wallpath, paint);
|
canvas.drawPath(wallpath, paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void createShortcut(@NonNull Activity activity, HistoryItem item) {
|
||||||
|
Log.d(Constants.TAG, "Creating shortcut: " + item.getTitle() + ' ' + item.getUrl());
|
||||||
|
Intent shortcutIntent = new Intent(activity, MainActivity.class);
|
||||||
|
shortcutIntent.setData(Uri.parse(item.getUrl()));
|
||||||
|
|
||||||
|
final String title = TextUtils.isEmpty(item.getTitle()) ? activity.getString(R.string.untitled) : item.getTitle();
|
||||||
|
|
||||||
|
Intent addIntent = new Intent();
|
||||||
|
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
||||||
|
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
|
||||||
|
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, item.getBitmap());
|
||||||
|
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
|
||||||
|
activity.sendBroadcast(addIntent);
|
||||||
|
Utils.showSnackbar(activity, R.string.message_added_to_homescreen);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto" >
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_back"
|
android:id="@+id/action_back"
|
||||||
@ -53,6 +53,9 @@
|
|||||||
<item
|
<item
|
||||||
android:id="@+id/action_copy"
|
android:id="@+id/action_copy"
|
||||||
android:title="@string/action_copy"/>
|
android:title="@string/action_copy"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_add_to_homescreen"
|
||||||
|
android:title="@string/action_add_to_homescreen"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_bookmarks"
|
android:id="@+id/action_bookmarks"
|
||||||
android:title="@string/action_bookmarks"/>
|
android:title="@string/action_bookmarks"/>
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto" >
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_back"
|
android:id="@+id/action_back"
|
||||||
@ -53,6 +53,9 @@
|
|||||||
<item
|
<item
|
||||||
android:id="@+id/action_copy"
|
android:id="@+id/action_copy"
|
||||||
android:title="@string/action_copy"/>
|
android:title="@string/action_copy"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_add_to_homescreen"
|
||||||
|
android:title="@string/action_add_to_homescreen"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_bookmarks"
|
android:id="@+id/action_bookmarks"
|
||||||
android:title="@string/action_bookmarks"/>
|
android:title="@string/action_bookmarks"/>
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_new_tab"
|
android:id="@+id/action_new_tab"
|
||||||
@ -35,6 +35,9 @@
|
|||||||
<item
|
<item
|
||||||
android:id="@+id/action_copy"
|
android:id="@+id/action_copy"
|
||||||
android:title="@string/action_copy"/>
|
android:title="@string/action_copy"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_add_to_homescreen"
|
||||||
|
android:title="@string/action_add_to_homescreen"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_bookmarks"
|
android:id="@+id/action_bookmarks"
|
||||||
android:title="@string/action_bookmarks"/>
|
android:title="@string/action_bookmarks"/>
|
||||||
|
@ -104,10 +104,10 @@
|
|||||||
<string name="cannot_download">Can only download \"http\" or \"https\" URLs.</string>
|
<string name="cannot_download">Can only download \"http\" or \"https\" URLs.</string>
|
||||||
<string name="problem_download">Invalid URL encountered, cannot download</string>
|
<string name="problem_download">Invalid URL encountered, cannot download</string>
|
||||||
<string name="problem_location_download">Cannot download to the specified location</string>
|
<string name="problem_location_download">Cannot download to the specified location</string>
|
||||||
<string name="download_no_sdcard_dlg_title" >No SD card</string>
|
<string name="download_no_sdcard_dlg_title">No SD card</string>
|
||||||
<string name="download_no_sdcard_dlg_msg" >USB storage is required to download the file.</string>
|
<string name="download_no_sdcard_dlg_msg">USB storage is required to download the file.</string>
|
||||||
<string name="download_sdcard_busy_dlg_title">USB storage unavailable</string>
|
<string name="download_sdcard_busy_dlg_title">USB storage unavailable</string>
|
||||||
<string name="download_sdcard_busy_dlg_msg" >The storage is busy. To allow downloads, touch Turn Off USB Storage in the notification.</string>
|
<string name="download_sdcard_busy_dlg_msg">The storage is busy. To allow downloads, touch Turn Off USB Storage in the notification.</string>
|
||||||
<string name="incognito_cookies">Enable Cookies in Incognito Mode</string>
|
<string name="incognito_cookies">Enable Cookies in Incognito Mode</string>
|
||||||
<string name="title_flash">Adobe Flash</string>
|
<string name="title_flash">Adobe Flash</string>
|
||||||
<string name="action_manual">Manual</string>
|
<string name="action_manual">Manual</string>
|
||||||
@ -204,13 +204,13 @@
|
|||||||
<string name="url_contents">URL Box Contents</string>
|
<string name="url_contents">URL Box Contents</string>
|
||||||
<string name="text_encoding">Text Encoding</string>
|
<string name="text_encoding">Text Encoding</string>
|
||||||
<string-array name="url_content_array">
|
<string-array name="url_content_array">
|
||||||
<item >Domain (default)</item>
|
<item>Domain (default)</item>
|
||||||
<item >URL</item>
|
<item>URL</item>
|
||||||
<item >Title</item>
|
<item>Title</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string name="invert_color">Invert color</string>
|
<string name="invert_color">Invert color</string>
|
||||||
<string name="dark_theme">Dark Theme</string>
|
<string name="dark_theme">Dark Theme</string>
|
||||||
<string name="tabs">Tabs</string>
|
<string name="tabs">Tabs</string>
|
||||||
<string name="theme">App Theme</string>
|
<string name="theme">App Theme</string>
|
||||||
<string name="light_theme">Light Theme</string>
|
<string name="light_theme">Light Theme</string>
|
||||||
<string name="black_theme">Black Theme (AMOLED)</string>
|
<string name="black_theme">Black Theme (AMOLED)</string>
|
||||||
@ -227,4 +227,6 @@
|
|||||||
<string name="tabs_in_drawer">Show tabs in Navigation Drawer</string>
|
<string name="tabs_in_drawer">Show tabs in Navigation Drawer</string>
|
||||||
<string name="do_not_track">Request \'Do Not Track\'</string>
|
<string name="do_not_track">Request \'Do Not Track\'</string>
|
||||||
<string name="remove_identifying_headers">Remove Identifying Headers</string>
|
<string name="remove_identifying_headers">Remove Identifying Headers</string>
|
||||||
|
<string name="action_add_to_homescreen">Add to Homescreen</string>
|
||||||
|
<string name="message_added_to_homescreen">Shortcut Added to Homescreen</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user