| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view.selectiontoolbar; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.SystemService; |
| 21 |
import android.content.Context; |
| 22 |
import android.os.RemoteException; |
| 23 |
import android.provider.DeviceConfig; |
| 24 |
|
| 25 |
import java.util.Objects; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
@SystemService(Context.SELECTION_TOOLBAR_SERVICE) |
| 34 |
public final class SelectionToolbarManager { |
| 35 |
|
| 36 |
private static final String TAG = "SelectionToolbar"; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public static final String LOG_TAG = "SelectionToolbar"; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
private static final String REMOTE_SELECTION_TOOLBAR_ENABLED = |
| 48 |
"remote_selection_toolbar_enabled"; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public static final long NO_TOOLBAR_ID = 0; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public static final int ERROR_DO_NOT_ALLOW_MULTIPLE_TOOL_BAR = 1; |
| 59 |
|
| 60 |
@NonNull |
| 61 |
private final Context mContext; |
| 62 |
private final ISelectionToolbarManager mService; |
| 63 |
|
| 64 |
public SelectionToolbarManager(@NonNull Context context, |
| 65 |
@NonNull ISelectionToolbarManager service) { |
| 66 |
mContext = Objects.requireNonNull(context); |
| 67 |
mService = service; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public void showToolbar(@NonNull ShowInfo showInfo, |
| 74 |
@NonNull ISelectionToolbarCallback callback) { |
| 75 |
try { |
| 76 |
Objects.requireNonNull(showInfo); |
| 77 |
Objects.requireNonNull(callback); |
| 78 |
mService.showToolbar(showInfo, callback, mContext.getUserId()); |
| 79 |
} catch (RemoteException e) { |
| 80 |
throw e.rethrowFromSystemServer(); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public void hideToolbar(long widgetToken) { |
| 88 |
try { |
| 89 |
mService.hideToolbar(widgetToken, mContext.getUserId()); |
| 90 |
} catch (RemoteException e) { |
| 91 |
throw e.rethrowFromSystemServer(); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
public void dismissToolbar(long widgetToken) { |
| 99 |
try { |
| 100 |
mService.dismissToolbar(widgetToken, mContext.getUserId()); |
| 101 |
} catch (RemoteException e) { |
| 102 |
throw e.rethrowFromSystemServer(); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
private boolean isRemoteSelectionToolbarEnabled() { |
| 107 |
return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SELECTION_TOOLBAR, |
| 108 |
REMOTE_SELECTION_TOOLBAR_ENABLED, false); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
public static boolean isRemoteSelectionToolbarEnabled(Context context) { |
| 116 |
SelectionToolbarManager manager = context.getSystemService(SelectionToolbarManager.class); |
| 117 |
if (manager != null) { |
| 118 |
return manager.isRemoteSelectionToolbarEnabled(); |
| 119 |
} |
| 120 |
return false; |
| 121 |
} |
| 122 |
} |