diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2017-01-13 12:15:53 -0800 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2017-01-18 18:38:34 -0800 |
commit | 278359539c02ca160caf1df54ce96053a2a2ef59 (patch) | |
tree | e4dc8afc511fd553ffe8766855bb9cefdf54656e /src/com/android/launcher3/compat | |
parent | 627006eeb4a9ba3bedacd7c0e4edce4fafdb9ac2 (diff) | |
download | android_packages_apps_Trebuchet-278359539c02ca160caf1df54ce96053a2a2ef59.tar.gz android_packages_apps_Trebuchet-278359539c02ca160caf1df54ce96053a2a2ef59.tar.bz2 android_packages_apps_Trebuchet-278359539c02ca160caf1df54ce96053a2a2ef59.zip |
Adding support for requesting addition of shortcut/widget
on the workspace.
Bug: 33584624
Change-Id: I664366822fe8088742faff2cce006239ab0771bc
Diffstat (limited to 'src/com/android/launcher3/compat')
-rw-r--r-- | src/com/android/launcher3/compat/PinItemRequestCompat.java | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/com/android/launcher3/compat/PinItemRequestCompat.java b/src/com/android/launcher3/compat/PinItemRequestCompat.java new file mode 100644 index 000000000..956b38cb1 --- /dev/null +++ b/src/com/android/launcher3/compat/PinItemRequestCompat.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.compat; + +import android.appwidget.AppWidgetProviderInfo; +import android.content.Intent; +import android.content.pm.ShortcutInfo; +import android.os.Bundle; +import android.os.Parcelable; + +/** + * A wrapper around platform implementation of PinItemRequestCompat until the + * updated SDK is available. + */ +public class PinItemRequestCompat { + + public static final String EXTRA_PIN_ITEM_REQUEST = "android.content.pm.extra.PIN_ITEM_REQUEST"; + + public static final int REQUEST_TYPE_SHORTCUT = 1; + public static final int REQUEST_TYPE_APPWIDGET = 2; + + private final Parcelable mObject; + + private PinItemRequestCompat(Parcelable object) { + mObject = object; + } + + public int getRequestType() { + return (Integer) invokeMethod("getRequestType"); + } + + public ShortcutInfo getShortcutInfo() { + return (ShortcutInfo) invokeMethod("getShortcutInfo"); + } + + public AppWidgetProviderInfo getAppWidgetProviderInfo() { + return (AppWidgetProviderInfo) invokeMethod("getAppWidgetProviderInfo"); + } + + public boolean isValid() { + return (Boolean) invokeMethod("isValid"); + } + + public boolean accept() { + return (Boolean) invokeMethod("accept"); + } + + public boolean accept(Bundle options) { + try { + return (Boolean) mObject.getClass().getDeclaredMethod("accept", Bundle.class) + .invoke(mObject, options); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private Object invokeMethod(String methodName) { + try { + return mObject.getClass().getDeclaredMethod(methodName).invoke(mObject); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static PinItemRequestCompat getPinItemRequest(Intent intent) { + Parcelable extra = intent.getParcelableExtra(EXTRA_PIN_ITEM_REQUEST); + return extra == null ? null : new PinItemRequestCompat(extra); + } +} |