Bug 1395841 - Part 2: Support creating a shortcut from page option in menu. r=nechen

When page option 'add page shortcut' is clicked, creating a shortcut(not PWA) on launcher.
Also make sure that heavy tasks are executed in background thread.

MozReview-Commit-ID: 8KtwdXENtEd

--HG--
extra : rebase_source : 12a427f549a41f9d8650b4b8d95394bdc4192c4b
This commit is contained in:
Jing-wei Wu 2017-09-28 10:57:48 +08:00
Родитель fa9bbb0da2
Коммит 2baa51b8c6
6 изменённых файлов: 25 добавлений и 13 удалений

Просмотреть файл

@ -1506,7 +1506,7 @@ public class BrowserApp extends GeckoApp
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
GeckoApplication.createShortcut(title, url);
GeckoApplication.createBrowserShortcut(title, url);
}
});

Просмотреть файл

@ -52,6 +52,7 @@ import org.mozilla.gecko.util.GeckoBundle;
import org.mozilla.gecko.util.HardwareUtils;
import org.mozilla.gecko.util.PRNGFixes;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.UIAsyncTask;
import java.io.File;
import java.lang.reflect.Method;
@ -570,12 +571,21 @@ public class GeckoApplication extends Application
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(intent);
// Remember interaction
final UrlAnnotations urlAnnotations = BrowserDB.from(context).getUrlAnnotations();
urlAnnotations.insertHomeScreenShortcut(context.getContentResolver(), aURI, true);
(new UIAsyncTask.WithoutParams<Void>(ThreadUtils.getBackgroundHandler()) {
@Override
public Void doInBackground() {
// Remember interaction, post to background thread to prevent violating StrictMode policy.
final UrlAnnotations urlAnnotations = BrowserDB.from(context).getUrlAnnotations();
urlAnnotations.insertHomeScreenShortcut(context.getContentResolver(), aURI, true);
return null;
}
// After shortcut is created, show the mobile desktop.
ActivityUtils.goToHomeScreen(context);
@Override
public void onPostExecute(Void aVoid) {
// After shortcut is created and db entry is inserted, show the mobile desktop.
ActivityUtils.goToHomeScreen(context);
}
}).execute();
}
private static Bitmap getLauncherIcon(Bitmap aSource, int size) {

Просмотреть файл

@ -284,7 +284,12 @@ public abstract class ActivityStreamContextMenu
break;
case R.id.add_homescreen:
GeckoApplication.createShortcut(item.getTitle(), item.getUrl());
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
GeckoApplication.createBrowserShortcut(item.getTitle(), item.getUrl());
}
});
break;
case R.id.open_new_tab:

Просмотреть файл

@ -185,7 +185,7 @@ public class BookmarkStateChangeDelegate extends BrowserAppDelegateWithReference
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
GeckoApplication.createShortcut(title, url);
GeckoApplication.createBrowserShortcut(title, url);
}
});
}

Просмотреть файл

@ -312,8 +312,7 @@ public abstract class HomeFragment extends Fragment {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
GeckoApplication.createShortcut(displayTitle, info.url);
GeckoApplication.createBrowserShortcut(displayTitle, info.url);
}
});

Просмотреть файл

@ -120,7 +120,7 @@ public class HomeScreenPrompt extends Locales.LocaleAwareActivity implements Ico
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
GeckoApplication.createShortcut(title, url);
GeckoApplication.createBrowserShortcut(title, url);
Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.BUTTON, TELEMETRY_EXTRA);
@ -131,8 +131,6 @@ public class HomeScreenPrompt extends Locales.LocaleAwareActivity implements Ico
});
}
private void loadShortcutIcon() {
Icons.with(this)
.pageUrl(url)