@Override @Nullable public Rect getClipBounds(@NonNull View v) { return v.getClipBounds(); }
@Override public void doLaunch(Context context, View v) { Intent viewContact = new Intent(Intent.ACTION_VIEW); viewContact.setData(Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, String.valueOf(contactPojo.lookupKey))); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { viewContact.setSourceBounds(v.getClipBounds()); } viewContact.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); viewContact.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); context.startActivity(viewContact); }
@SuppressLint("MissingPermission") @Override public void doLaunch(Context context, View v) { Intent phone = new Intent(Intent.ACTION_CALL); phone.setData(Uri.parse("tel:" + Uri.encode(phonePojo.phone))); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { phone.setSourceBounds(v.getClipBounds()); } phone.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Make sure we have permission to call someone as this is considered a dangerous permission if (Permission.ensureCallPhonePermission(phone)) { context.startActivity(phone); } }
@Override public void doLaunch(Context context, View v) { Intent intent = new Intent(settingPojo.settingName); if (!settingPojo.packageName.isEmpty()) { intent.setClassName(settingPojo.packageName, settingPojo.settingName); } if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { intent.setSourceBounds(v.getClipBounds()); } intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { context.startActivity(intent); } catch(ActivityNotFoundException e) { e.printStackTrace(); Toast.makeText(context, R.string.application_not_found, Toast.LENGTH_LONG).show(); } } }
@Override public void doLaunch(Context context, View v) { try { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { LauncherApps launcher = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE); assert launcher != null; launcher.startMainActivity(className, appPojo.userHandle.getRealHandle(), v.getClipBounds(), null); } else { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(className); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { intent.setSourceBounds(v.getClipBounds()); } context.startActivity(intent); } } catch (ActivityNotFoundException | NullPointerException e) { // Application was just removed? // (null pointer exception can be thrown on Lollipop+ when app is missing) Toast.makeText(context, R.string.application_not_found, Toast.LENGTH_LONG).show(); } } }
@Override protected void doLaunch(Context context, View v) { if (shortcutPojo.isOreoShortcut()) { // Oreo shortcuts doOreoLaunch(context, v); } else { // Pre-oreo shortcuts try { Intent intent = Intent.parseUri(shortcutPojo.intentUri, 0); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { intent.setSourceBounds(v.getClipBounds()); } context.startActivity(intent); } catch (Exception e) { // Application was just removed? Toast.makeText(context, R.string.application_not_found, Toast.LENGTH_LONG).show(); } } }
@TargetApi(Build.VERSION_CODES.O) private void doOreoLaunch(Context context, View v) { final LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE); assert launcherApps != null; // Only the default launcher is allowed to start shortcuts if (!launcherApps.hasShortcutHostPermission()) { Toast.makeText(context, context.getString(R.string.shortcuts_no_host_permission), Toast.LENGTH_LONG).show(); return; } LauncherApps.ShortcutQuery query = new LauncherApps.ShortcutQuery(); query.setPackage(shortcutPojo.packageName); query.setShortcutIds(Collections.singletonList(shortcutPojo.getOreoId())); query.setQueryFlags(LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED); List<UserHandle> userHandles = launcherApps.getProfiles(); // Find the correct UserHandle, and launch the shortcut. for (UserHandle userHandle : userHandles) { List<ShortcutInfo> shortcuts = launcherApps.getShortcuts(query, userHandle); if (shortcuts != null && shortcuts.size() > 0 && shortcuts.get(0).isEnabled()) { launcherApps.startShortcut(shortcuts.get(0), v.getClipBounds(), null); return; } } // Application removed? Invalid shortcut? Shortcut to an app on an unmounted SD card? Toast.makeText(context, R.string.application_not_found, Toast.LENGTH_LONG).show(); }
@Override public void set(@NonNull View object, @NonNull State value) { final Rect tempRect = mTempRect; if (object.getClipBounds(tempRect)) { if (mTargetDimension == TARGET_X) { tempRect.left = value.lower - (int) value.trans; tempRect.right = value.upper - (int) value.trans; } else { tempRect.top = value.lower - (int) value.trans; tempRect.bottom = value.upper - (int) value.trans; } object.setClipBounds(tempRect); } // if (mTargetDimension == TARGET_X) { // object.setTranslationX(value.trans); // } else { // object.setTranslationY(value.trans); // } } }
private void captureValues(@NonNull TransitionValues values) { final View view = values.view; if (view.getVisibility() == View.GONE) { return; } final Rect bounds = new Rect(0, 0, view.getWidth(), view.getHeight()); values.values.put(PROPNAME_BOUNDS, bounds); values.values.put(PROPNAME_TRANSLATE_X, view.getTranslationX()); values.values.put(PROPNAME_TRANSLATE_Y, view.getTranslationY()); values.values.put(PROPNAME_TRANSLATE_Z, view.getTranslationZ()); values.values.put(PROPNAME_Z, view.getZ()); final Rect clip = view.getClipBounds(); values.values.put(PROPNAME_CLIP, clip); }
@Override public State get(@NonNull View object) { final Rect tempRect = mTempRect; if (!object.getClipBounds(tempRect)) { tempRect.setEmpty(); } final State tempState = mTempState; if (mTargetDimension == TARGET_X) { tempState.trans = object.getTranslationX(); tempState.lower = tempRect.left + (int) tempState.trans; tempState.upper = tempRect.right + (int) tempState.trans; } else { tempState.trans = object.getTranslationY(); tempState.lower = tempRect.top + (int) tempState.trans; tempState.upper = tempRect.bottom + (int) tempState.trans; } return tempState; }
data.put("ClipBounds", String.valueOf(v.getClipBounds())); final ViewOverlay overlay = v.getOverlay(); final ViewOverlayReflector viewOverlayReflector = new ViewOverlayReflector(overlay);