下面列出了怎么用android.util.MutableBoolean的API类实例代码及写法,或者点击链接到github查看源代码。
private void parseAutofillFields(AssistStructure.ViewNode viewNode,
HashMap<String, FieldTypeWithHeuristics> fieldTypesByAutofillHint,
Map<String, FilledAutofillField> filledAutofillFieldsByTypeName,
Dataset.Builder builder, MutableBoolean setValueAtLeastOnce) {
String[] rawHints = viewNode.getAutofillHints();
if (rawHints == null || rawHints.length == 0) {
logv("No af hints at ViewNode - %s", viewNode.getIdEntry());
return;
}
String fieldTypeName = AutofillHints.getFieldTypeNameFromAutofillHints(
fieldTypesByAutofillHint, Arrays.asList(rawHints));
if (fieldTypeName == null) {
return;
}
FilledAutofillField field = filledAutofillFieldsByTypeName.get(fieldTypeName);
if (field == null) {
return;
}
bindValueToNode(viewNode, field, builder, setValueAtLeastOnce);
}
@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 static PointF nextScrollingLocation(OBControl con, MutableBoolean finished)
{
Object data = con.propertyValue("scrolling_data");
if(data == null)
{
finished.value = true;
return OBMisc.copyPoint(con.position());
}
Map<String,Object> scrollingData = (ArrayMap<String,Object>)data;
long currentTime = SystemClock.uptimeMillis();
long lastTime = (long)scrollingData.get("last_action");
float tick = (float)scrollingData.get("tick") ;
scrollingData.put("last_action",currentTime);
return nextScrollingLocationByFrac(con, (currentTime-lastTime)*1.0f/(1000.0f*tick), finished);
}
private void parseAutofillFields(AssistStructure.ViewNode viewNode,
HashMap<String, FieldTypeWithHeuristics> fieldTypesByAutofillHint,
Map<String, FilledAutofillField> filledAutofillFieldsByTypeName,
Dataset.Builder builder, MutableBoolean setValueAtLeastOnce) {
String[] rawHints = viewNode.getAutofillHints();
if (rawHints == null || rawHints.length == 0) {
logv("No af hints at ViewNode - %s", viewNode.getIdEntry());
return;
}
String fieldTypeName = AutofillHints.getFieldTypeNameFromAutofillHints(
fieldTypesByAutofillHint, Arrays.asList(rawHints));
if (fieldTypeName == null) {
return;
}
FilledAutofillField field = filledAutofillFieldsByTypeName.get(fieldTypeName);
if (field == null) {
return;
}
bindValueToNode(viewNode, field, builder, setValueAtLeastOnce);
}
/**
* Build an autofill {@link Dataset} using saved data and the client's AssistStructure.
*/
private boolean bindDataset(HashMap<String, FieldTypeWithHeuristics> fieldTypesByAutofillHint,
DatasetWithFilledAutofillFields datasetWithFilledAutofillFields,
Dataset.Builder datasetBuilder) {
MutableBoolean setValueAtLeastOnce = new MutableBoolean(false);
Map<String, FilledAutofillField> filledAutofillFieldsByTypeName =
datasetWithFilledAutofillFields.filledAutofillFields.stream()
.collect(toMap(FilledAutofillField::getFieldTypeName, Function.identity()));
mClientParser.parse((node) ->
parseAutofillFields(node, fieldTypesByAutofillHint, filledAutofillFieldsByTypeName,
datasetBuilder, setValueAtLeastOnce)
);
return setValueAtLeastOnce.value;
}
private boolean bindDatasetToFocusedNode(FilledAutofillField field,
FieldType fieldType, Dataset.Builder builder) {
MutableBoolean setValueAtLeastOnce = new MutableBoolean(false);
mClientParser.parse((node) -> {
if (node.isFocused() && node.getAutofillId() != null) {
bindValueToNode(node, field, builder, setValueAtLeastOnce);
}
});
return setValueAtLeastOnce.value;
}
public boolean interceptPowerKeyDown(KeyEvent event, boolean interactive,
MutableBoolean outLaunched) {
boolean launched = false;
boolean intercept = false;
long powerTapInterval;
synchronized (this) {
powerTapInterval = event.getEventTime() - mLastPowerDown;
if (mCameraDoubleTapPowerEnabled
&& powerTapInterval < CAMERA_POWER_DOUBLE_TAP_MAX_TIME_MS) {
launched = true;
intercept = interactive;
mPowerButtonConsecutiveTaps++;
} else if (powerTapInterval < POWER_SHORT_TAP_SEQUENCE_MAX_INTERVAL_MS) {
mPowerButtonConsecutiveTaps++;
} else {
mPowerButtonConsecutiveTaps = 1;
}
mLastPowerDown = event.getEventTime();
}
if (DBG && mPowerButtonConsecutiveTaps > 1) {
Slog.i(TAG, Long.valueOf(mPowerButtonConsecutiveTaps) +
" consecutive power button taps detected");
}
if (launched) {
Slog.i(TAG, "Power button double tap gesture detected, launching camera. Interval="
+ powerTapInterval + "ms");
launched = handleCameraGesture(false /* useWakelock */,
StatusBarManager.CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP);
if (launched) {
mMetricsLogger.action(MetricsEvent.ACTION_DOUBLE_TAP_POWER_CAMERA_GESTURE,
(int) powerTapInterval);
}
}
mMetricsLogger.histogram("power_consecutive_short_tap_count", mPowerButtonConsecutiveTaps);
mMetricsLogger.histogram("power_double_tap_interval", (int) powerTapInterval);
outLaunched.value = launched;
return intercept && launched;
}
public static PointF nextScrollingLocationByFrac(OBControl con, float frac, MutableBoolean finished)
{
PointF loc = OBMisc.copyPoint(con.position());
Object data = con.propertyValue("scrolling_data");
if(data == null)
{
finished.value = true;
return loc;
}
Map<String,Object> scrollingData = (ArrayMap<String,Object>)data;
float speedX = (float)scrollingData.get("speed_x");
float speedY = (float)scrollingData.get("speed_y");
float minSpeedX = (float)scrollingData.get("min_speed_x");
float minSpeedY = (float)scrollingData.get("min_speed_y");
if(speedX == 0 && speedY == 0)
{
finished.value = true;
return loc;
}
loc.x += speedX * frac;
loc.y += speedY * frac;
double decay = (double)scrollingData.get("decay");
double decayFrac = Math.pow(decay,frac);
speedX *= decayFrac;
speedY *= decayFrac;
if(minSpeedX >= Math.abs(speedX))
speedX = 0;
if(minSpeedY >= Math.abs(speedY))
speedY = 0;
scrollingData.put("speed_x", speedX);
scrollingData.put("speed_y", speedY);
finished.value = speedX == 0 && speedY == 0;
return loc;
}
public void checkGroupIcon(PointF pt, final OBGroup curGroup, final OBControl curIcon) throws Exception
{
long currTime = SystemClock.currentThreadTimeMillis();
PointF lastPosition = (PointF) curGroup.propertyValue("touch_loc");
if (curIcon != null && (currTime - (long) curGroup.propertyValue("time")) < 1
&& Math.abs(lastPosition.x - pt.x) < snapDist && pointTouchAccepted(pt)
&& pointTouchAccepted(lastPosition))
{
curIcon.highlight();
openBookForIcon(curIcon);
OBUtils.runOnOtherThreadDelayed(1, new OBUtils.RunLambda()
{
public void run() throws Exception
{
curIcon.lowlight();
}
});
}
long time = setStatus(STATUS_WAITING_FOR_DRAG);
if (!curGroup.isEnabled())
return;
curGroup.setProperty("time", time);
MutableBoolean finished = new MutableBoolean(false);
while (!this._aborting && !finished.value && time == (long)curGroup.propertyValue("time"))
{
if (time == (long)curGroup.propertyValue("time"))
{
PointF pos = ScrollingHelper.nextScrollingLocation(curGroup, finished);
if (!setBookLine(curGroup, pos.x))
finished.value = true;
}
waitForSecs(0.001f);
}
if (!this._aborting)
snapClosest(time, curGroup, false);
}
/**
* Build an autofill {@link Dataset} using saved data and the client's AssistStructure.
*/
private boolean bindDataset(HashMap<String, FieldTypeWithHeuristics> fieldTypesByAutofillHint,
DatasetWithFilledAutofillFields datasetWithFilledAutofillFields,
Dataset.Builder datasetBuilder) {
MutableBoolean setValueAtLeastOnce = new MutableBoolean(false);
Map<String, FilledAutofillField> filledAutofillFieldsByTypeName =
datasetWithFilledAutofillFields.filledAutofillFields.stream()
.collect(toMap(FilledAutofillField::getFieldTypeName, Function.identity()));
mClientParser.parse((node) ->
parseAutofillFields(node, fieldTypesByAutofillHint, filledAutofillFieldsByTypeName,
datasetBuilder, setValueAtLeastOnce)
);
return setValueAtLeastOnce.value;
}
private boolean bindDatasetToFocusedNode(FilledAutofillField field,
FieldType fieldType, Dataset.Builder builder) {
MutableBoolean setValueAtLeastOnce = new MutableBoolean(false);
mClientParser.parse((node) -> {
if (node.isFocused() && node.getAutofillId() != null) {
bindValueToNode(node, field, builder, setValueAtLeastOnce);
}
});
return setValueAtLeastOnce.value;
}
void bindValueToNode(AssistStructure.ViewNode viewNode,
FilledAutofillField field, Dataset.Builder builder,
MutableBoolean setValueAtLeastOnce) {
AutofillId autofillId = viewNode.getAutofillId();
if (autofillId == null) {
logw("Autofill ID null for %s", viewNode.toString());
return;
}
int autofillType = viewNode.getAutofillType();
switch (autofillType) {
case View.AUTOFILL_TYPE_LIST:
CharSequence[] options = viewNode.getAutofillOptions();
int listValue = -1;
if (options != null) {
listValue = indexOf(viewNode.getAutofillOptions(), field.getTextValue());
}
if (listValue != -1) {
builder.setValue(autofillId, AutofillValue.forList(listValue));
setValueAtLeastOnce.value = true;
}
break;
case View.AUTOFILL_TYPE_DATE:
Long dateValue = field.getDateValue();
if (dateValue != null) {
builder.setValue(autofillId, AutofillValue.forDate(dateValue));
setValueAtLeastOnce.value = true;
}
break;
case View.AUTOFILL_TYPE_TEXT:
String textValue = field.getTextValue();
if (textValue != null) {
builder.setValue(autofillId, AutofillValue.forText(textValue));
setValueAtLeastOnce.value = true;
}
break;
case View.AUTOFILL_TYPE_TOGGLE:
Boolean toggleValue = field.getToggleValue();
if (toggleValue != null) {
builder.setValue(autofillId, AutofillValue.forToggle(toggleValue));
setValueAtLeastOnce.value = true;
}
break;
case View.AUTOFILL_TYPE_NONE:
default:
logw("Invalid autofill type - %d", autofillType);
break;
}
}
public static boolean scrollControlByFrac(OBControl con, float frac)
{
MutableBoolean finished = new MutableBoolean(true);
con.setPosition(nextScrollingLocationByFrac(con, frac, finished));
return finished.value;
}
public static boolean scrollControl(OBControl con)
{
MutableBoolean finished = new MutableBoolean(true);
con.setPosition(nextScrollingLocation(con, finished));
return finished.value;
}
void bindValueToNode(AssistStructure.ViewNode viewNode,
FilledAutofillField field, Dataset.Builder builder,
MutableBoolean setValueAtLeastOnce) {
AutofillId autofillId = viewNode.getAutofillId();
if (autofillId == null) {
logw("Autofill ID null for %s", viewNode.toString());
return;
}
int autofillType = viewNode.getAutofillType();
switch (autofillType) {
case View.AUTOFILL_TYPE_LIST:
CharSequence[] options = viewNode.getAutofillOptions();
int listValue = -1;
if (options != null) {
listValue = indexOf(viewNode.getAutofillOptions(), field.getTextValue());
}
if (listValue != -1) {
builder.setValue(autofillId, AutofillValue.forList(listValue));
setValueAtLeastOnce.value = true;
}
break;
case View.AUTOFILL_TYPE_DATE:
Long dateValue = field.getDateValue();
if (dateValue != null) {
builder.setValue(autofillId, AutofillValue.forDate(dateValue));
setValueAtLeastOnce.value = true;
}
break;
case View.AUTOFILL_TYPE_TEXT:
String textValue = field.getTextValue();
if (textValue != null) {
builder.setValue(autofillId, AutofillValue.forText(textValue));
setValueAtLeastOnce.value = true;
}
break;
case View.AUTOFILL_TYPE_TOGGLE:
Boolean toggleValue = field.getToggleValue();
if (toggleValue != null) {
builder.setValue(autofillId, AutofillValue.forToggle(toggleValue));
setValueAtLeastOnce.value = true;
}
break;
case View.AUTOFILL_TYPE_NONE:
default:
logw("Invalid autofill type - %d", autofillType);
break;
}
}