use of android.content.pm.ShortcutManager in project PhoneProfiles by henrichg.
the class DataWrapper method setDynamicLauncherShortcuts.
void setDynamicLauncherShortcuts() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
if (shortcutManager != null) {
List<Profile> countedProfiles = DatabaseHandler.getInstance(context).getProfilesForDynamicShortcuts(true);
List<Profile> notCountedProfiles = DatabaseHandler.getInstance(context).getProfilesForDynamicShortcuts(false);
ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
for (Profile profile : countedProfiles) {
PPApplication.logE("DataWrapper.setDynamicLauncherShortcuts", "countedProfile=" + profile._name);
profile.generateIconBitmap(context, monochrome, monochromeValue);
shortcuts.add(0, createShortcutInfo(profile));
}
int shortcutsCount = countedProfiles.size();
if (shortcutsCount < 4) {
for (Profile profile : notCountedProfiles) {
PPApplication.logE("DataWrapper.setDynamicLauncherShortcuts", "notCountedProfile=" + profile._name);
profile.generateIconBitmap(context, monochrome, monochromeValue);
shortcuts.add(0, createShortcutInfo(profile));
++shortcutsCount;
if (shortcutsCount == 4)
break;
}
}
shortcutManager.setDynamicShortcuts(shortcuts);
}
}
}
use of android.content.pm.ShortcutManager in project RespawnIRC-Android by FranckRJ.
the class AbsNavigationViewActivity method getNewFavs.
@Override
public void getNewFavs(ArrayList<JVCParser.NameAndLink> listOfFavs, int typeOfFav) {
if (listOfFavs != null) {
final int sizeOfListOfFavs = listOfFavs.size();
PrefsManager.IntPref.Names prefFavArraySize;
PrefsManager.StringPref.Names prefFavName;
PrefsManager.StringPref.Names prefFavLink;
int currentFavArraySize;
if (typeOfFav == RefreshFavDialogFragment.FAV_FORUM) {
prefFavArraySize = PrefsManager.IntPref.Names.FORUM_FAV_ARRAY_SIZE;
prefFavName = PrefsManager.StringPref.Names.FORUM_FAV_NAME;
prefFavLink = PrefsManager.StringPref.Names.FORUM_FAV_LINK;
} else {
prefFavArraySize = PrefsManager.IntPref.Names.TOPIC_FAV_ARRAY_SIZE;
prefFavName = PrefsManager.StringPref.Names.TOPIC_FAV_NAME;
prefFavLink = PrefsManager.StringPref.Names.TOPIC_FAV_LINK;
}
currentFavArraySize = PrefsManager.getInt(prefFavArraySize);
for (int i = 0; i < currentFavArraySize; ++i) {
PrefsManager.removeStringWithSufix(prefFavName, String.valueOf(i));
PrefsManager.removeStringWithSufix(prefFavLink, String.valueOf(i));
}
PrefsManager.putInt(prefFavArraySize, sizeOfListOfFavs);
for (int i = 0; i < sizeOfListOfFavs; ++i) {
PrefsManager.putStringWithSufix(prefFavName, String.valueOf(i), listOfFavs.get(i).name);
PrefsManager.putStringWithSufix(prefFavLink, String.valueOf(i), listOfFavs.get(i).link);
}
PrefsManager.applyChanges();
updateFavsInNavigationMenu(true);
if (typeOfFav == RefreshFavDialogFragment.FAV_FORUM && Build.VERSION.SDK_INT >= 25) {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
Utils.updateShortcuts(this, shortcutManager, listOfFavs.size());
}
} else {
Toast.makeText(this, R.string.errorDuringFetchFavs, Toast.LENGTH_SHORT).show();
}
}
use of android.content.pm.ShortcutManager in project RespawnIRC-Android by FranckRJ.
the class MainActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int lastActivityViewed = PrefsManager.getInt(PrefsManager.IntPref.Names.LAST_ACTIVITY_VIEWED);
// vidage du cache des webviews
if (PrefsManager.getInt(PrefsManager.IntPref.Names.NUMBER_OF_WEBVIEW_OPEN_SINCE_CACHE_CLEARED) > 10) {
WebView obj = new WebView(this);
obj.clearCache(true);
PrefsManager.putInt(PrefsManager.IntPref.Names.NUMBER_OF_WEBVIEW_OPEN_SINCE_CACHE_CLEARED, 0);
PrefsManager.applyChanges();
}
File[] listOfImagesCached = getCacheDir().listFiles();
if (listOfImagesCached != null) {
if (listOfImagesCached.length > 100) {
for (File thisFile : listOfImagesCached) {
if (!thisFile.isDirectory() && thisFile.getName().startsWith("img_")) {
// noinspection ResultOfMethodCallIgnored
thisFile.delete();
}
}
}
}
if (Build.VERSION.SDK_INT >= 25) {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
if (shortcutManager != null) {
int sizeOfForumFavArray = PrefsManager.getInt(PrefsManager.IntPref.Names.FORUM_FAV_ARRAY_SIZE);
int oldShortcutVersionNumber = PrefsManager.getInt(PrefsManager.IntPref.Names.SHORTCUT_VERSION_NUMBER);
try {
if (oldShortcutVersionNumber != PrefsManager.CURRENT_SHORTCUT_VERSION_NUMBER) {
Utils.updateShortcuts(this, shortcutManager, sizeOfForumFavArray);
List<ShortcutInfo> currentPinnedShortcuts = shortcutManager.getPinnedShortcuts();
List<ShortcutInfo> currentDynamicShortcuts = shortcutManager.getDynamicShortcuts();
List<String> shortcutsIdToDisable = new ArrayList<>();
/* Désactivation des shortcuts épinglés mais non présents dans la liste. */
for (ShortcutInfo thisPinnedShortcut : currentPinnedShortcuts) {
shortcutsIdToDisable.add(thisPinnedShortcut.getId());
}
for (ShortcutInfo thisDynamicShortcut : currentDynamicShortcuts) {
shortcutsIdToDisable.remove(thisDynamicShortcut.getId());
}
shortcutManager.disableShortcuts(shortcutsIdToDisable, getString(R.string.disabledAfterShortcutUpdate));
PrefsManager.putInt(PrefsManager.IntPref.Names.SHORTCUT_VERSION_NUMBER, PrefsManager.CURRENT_SHORTCUT_VERSION_NUMBER);
PrefsManager.applyChanges();
} else if (sizeOfForumFavArray > 0 && shortcutManager.getDynamicShortcuts().size() == 0) {
Utils.updateShortcuts(this, shortcutManager, sizeOfForumFavArray);
}
} catch (Exception e) {
/* À ce qu'il parait les fonctions de shortcutManager peuvent crash "when the user is locked",
* je sais pas ce que ça veut dire donc dans le doute je mets ça là. */
}
}
}
if (getIntent() != null) {
String actionForLinkToOpen = getIntent().getAction();
String linkToOpen = getIntent().getDataString();
if (!Utils.stringIsEmptyOrNull(linkToOpen) && !Utils.stringIsEmptyOrNull(actionForLinkToOpen)) {
linkToOpen = JVCParser.formatThisUrlToClassicJvcUrl(linkToOpen);
if (actionForLinkToOpen.equals(ACTION_OPEN_SHORTCUT)) {
Intent newShowForumIntent = new Intent(this, ShowForumActivity.class);
newShowForumIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
newShowForumIntent.putExtra(ShowForumActivity.EXTRA_NEW_LINK, linkToOpen);
startActivity(newShowForumIntent);
finish();
return;
} else if (actionForLinkToOpen.equals(Intent.ACTION_VIEW)) {
if (JVCParser.checkIfItsTopicFormatedLink(linkToOpen)) {
Intent newShowTopicIntent = new Intent(this, ShowTopicActivity.class);
newShowTopicIntent.putExtra(ShowTopicActivity.EXTRA_TOPIC_LINK, linkToOpen);
newShowTopicIntent.putExtra(ShowTopicActivity.EXTRA_OPENED_FROM_FORUM, false);
startActivity(newShowTopicIntent);
} else {
Intent newShowForumIntent = new Intent(this, ShowForumActivity.class);
newShowForumIntent.putExtra(ShowForumActivity.EXTRA_NEW_LINK, linkToOpen);
newShowForumIntent.putExtra(ShowForumActivity.EXTRA_IS_FIRST_ACTIVITY, false);
startActivity(newShowForumIntent);
}
finish();
return;
}
}
}
if (lastActivityViewed == ACTIVITY_SELECT_FORUM_IN_LIST) {
Intent newSelectForumInListIntent = new Intent(this, SelectForumInListActivity.class);
newSelectForumInListIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(newSelectForumInListIntent);
} else {
Intent newShowForumIntent = new Intent(this, ShowForumActivity.class);
newShowForumIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
newShowForumIntent.putExtra(ShowForumActivity.EXTRA_ITS_FIRST_START, true);
startActivity(newShowForumIntent);
}
finish();
}
use of android.content.pm.ShortcutManager in project hypertrack-live-android by hypertrack.
the class Home method addDynamicShortcut.
private void addDynamicShortcut(Place place) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
String name = HTTextUtils.isEmpty(place.getName()) ? place.getAddress() : place.getName();
// because shortlabel couldn't be empty.
if (HTTextUtils.isEmpty(name))
return;
int count = 0;
if (shortcutManager.getDynamicShortcuts() != null) {
count = shortcutManager.getDynamicShortcuts().size();
}
if (count > 2) {
String id = shortcutManager.getDynamicShortcuts().get(0).getId();
List<String> shortcutIds = new ArrayList<>();
shortcutIds.add(id);
shortcutManager.removeDynamicShortcuts(shortcutIds);
}
List<ShortcutInfo> shortcut = new ArrayList<>();
shortcut.add(0, new ShortcutInfo.Builder(this, place.getLocation().getLatLng().toString()).setShortLabel(name).setIcon(Icon.createWithResource(this, R.drawable.ic_marker_gray)).setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("share.location://hypertrack"))).build());
shortcutManager.addDynamicShortcuts(shortcut);
}
} catch (Exception e) {
Crashlytics.logException(e);
}
}
use of android.content.pm.ShortcutManager in project plaid by nickbutcher.
the class ShortcutHelper method reportSearchUsed.
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void reportSearchUsed(@NonNull Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1)
return;
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
shortcutManager.reportShortcutUsed(SEARCH_SHORTCUT_ID);
}
Aggregations