下面列出了怎么用android.util.MutableInt的API类实例代码及写法,或者点击链接到github查看源代码。
private void parseNode(AssistStructure.ViewNode root, List<String> allHints,
MutableInt autofillSaveType, List<AutofillId> autofillIds,
List<AutofillId> focusedAutofillIds) {
String[] hints = root.getAutofillHints();
if (hints != null) {
for (String hint : hints) {
FieldTypeWithHeuristics fieldTypeWithHints = mFieldTypesByAutofillHint.get(hint);
if (fieldTypeWithHints != null && fieldTypeWithHints.fieldType != null) {
allHints.add(hint);
autofillSaveType.value |= fieldTypeWithHints.fieldType.getSaveInfo();
autofillIds.add(root.getAutofillId());
}
}
}
if (root.isFocused()) {
focusedAutofillIds.add(root.getAutofillId());
}
}
@Override
public boolean isConfigFlagSet(int flag) {
Slog.v(TAG, "isConfigFlagSet " + ConfigFlag.toString(flag));
synchronized (mLock) {
checkNotClosedLocked();
MutableInt halResult = new MutableInt(Result.UNKNOWN_ERROR);
MutableBoolean flagState = new MutableBoolean(false);
try {
mHwSession.isConfigFlagSet(flag, (int result, boolean value) -> {
halResult.value = result;
flagState.value = value;
});
} catch (RemoteException ex) {
throw new RuntimeException("Failed to check flag " + ConfigFlag.toString(flag), ex);
}
Convert.throwOnError("isConfigFlagSet", halResult.value);
return flagState.value;
}
}
public @NonNull TunerSession openSession(@NonNull android.hardware.radio.ITunerCallback userCb)
throws RemoteException {
TunerCallback cb = new TunerCallback(Objects.requireNonNull(userCb));
Mutable<ITunerSession> hwSession = new Mutable<>();
MutableInt halResult = new MutableInt(Result.UNKNOWN_ERROR);
synchronized (mService) {
mService.openSession(cb, (result, session) -> {
hwSession.value = session;
halResult.value = result;
});
}
Convert.throwOnError("openSession", halResult.value);
Objects.requireNonNull(hwSession.value);
return new TunerSession(this, hwSession.value, cb);
}
private void parseNode(AssistStructure.ViewNode root, List<String> allHints,
MutableInt autofillSaveType, List<AutofillId> autofillIds,
List<AutofillId> focusedAutofillIds) {
String[] hints = root.getAutofillHints();
if (hints != null) {
for (String hint : hints) {
FieldTypeWithHeuristics fieldTypeWithHints = mFieldTypesByAutofillHint.get(hint);
if (fieldTypeWithHints != null && fieldTypeWithHints.fieldType != null) {
allHints.add(hint);
autofillSaveType.value |= fieldTypeWithHints.fieldType.getSaveInfo();
autofillIds.add(root.getAutofillId());
}
}
}
if (root.isFocused()) {
focusedAutofillIds.add(root.getAutofillId());
}
}
public ClientViewMetadata buildClientViewMetadata() {
List<String> allHints = new ArrayList<>();
MutableInt saveType = new MutableInt(0);
List<AutofillId> autofillIds = new ArrayList<>();
StringBuilder webDomainBuilder = new StringBuilder();
List<AutofillId> focusedAutofillIds = new ArrayList<>();
mClientParser.parse((node) -> parseNode(node, allHints, saveType, autofillIds, focusedAutofillIds));
mClientParser.parse((node) -> parseWebDomain(node, webDomainBuilder));
String webDomain = webDomainBuilder.toString();
AutofillId[] autofillIdsArray = autofillIds.toArray(new AutofillId[autofillIds.size()]);
AutofillId[] focusedIds = focusedAutofillIds.toArray(new AutofillId[focusedAutofillIds.size()]);
return new ClientViewMetadata(allHints, saveType.value, autofillIdsArray, focusedIds, webDomain);
}
public android.hardware.radio.ICloseHandle addAnnouncementListener(@NonNull int[] enabledTypes,
@NonNull android.hardware.radio.IAnnouncementListener listener) throws RemoteException {
ArrayList<Byte> enabledList = new ArrayList<>();
for (int type : enabledTypes) {
enabledList.add((byte)type);
}
MutableInt halResult = new MutableInt(Result.UNKNOWN_ERROR);
Mutable<ICloseHandle> hwCloseHandle = new Mutable<>();
IAnnouncementListener hwListener = new IAnnouncementListener.Stub() {
public void onListUpdated(ArrayList<Announcement> hwAnnouncements)
throws RemoteException {
listener.onListUpdated(hwAnnouncements.stream().
map(a -> Convert.announcementFromHal(a)).collect(Collectors.toList()));
}
};
synchronized (mService) {
mService.registerAnnouncementListener(enabledList, hwListener, (result, closeHnd) -> {
halResult.value = result;
hwCloseHandle.value = closeHnd;
});
}
Convert.throwOnError("addAnnouncementListener", halResult.value);
return new android.hardware.radio.ICloseHandle.Stub() {
public void close() {
try {
hwCloseHandle.value.close();
} catch (RemoteException ex) {
Slog.e(TAG, "Failed closing announcement listener", ex);
}
}
};
}
synchronized void removeItem(Context context, Iterable<? extends ItemInfo> items) {
for (ItemInfo item : items) {
switch (item.itemType) {
case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
folders.remove(item.id);
workspaceItems.remove(item);
break;
case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT: {
// Decrement pinned shortcut count
ShortcutKey pinnedShortcut = ShortcutKey.fromItemInfo(item);
MutableInt count = pinnedShortcutCounts.get(pinnedShortcut);
if ((count == null || --count.value == 0)
&& !InstallShortcutReceiver.getPendingShortcuts(context)
.contains(pinnedShortcut)) {
DeepShortcutManager.getInstance(context).unpinShortcut(pinnedShortcut);
}
// Fall through.
}
case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
workspaceItems.remove(item);
break;
case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
appWidgets.remove(item);
break;
}
itemsIdMap.remove(item.id);
}
}
public ClientViewMetadata buildClientViewMetadata() {
List<String> allHints = new ArrayList<>();
MutableInt saveType = new MutableInt(0);
List<AutofillId> autofillIds = new ArrayList<>();
StringBuilder webDomainBuilder = new StringBuilder();
List<AutofillId> focusedAutofillIds = new ArrayList<>();
mClientParser.parse((node) -> parseNode(node, allHints, saveType, autofillIds, focusedAutofillIds));
mClientParser.parse((node) -> parseWebDomain(node, webDomainBuilder));
String webDomain = webDomainBuilder.toString();
AutofillId[] autofillIdsArray = autofillIds.toArray(new AutofillId[autofillIds.size()]);
AutofillId[] focusedIds = focusedAutofillIds.toArray(new AutofillId[focusedAutofillIds.size()]);
return new ClientViewMetadata(allHints, saveType.value, autofillIdsArray, focusedIds, webDomain);
}