下面列出了怎么用android.support.annotation.CheckResult的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Returns a new instance with the specified ad set to the specified {@code state}. The ad
* specified must currently either be in {@link #AD_STATE_UNAVAILABLE} or {@link
* #AD_STATE_AVAILABLE}.
*
* <p>This instance's ad count may be unknown, in which case {@code index} must be less than the
* ad count specified later. Otherwise, {@code index} must be less than the current ad count.
*/
@CheckResult
public AdGroup withAdState(@AdState int state, int index) {
Assertions.checkArgument(count == C.LENGTH_UNSET || index < count);
@AdState int[] states = copyStatesWithSpaceForAdCount(this.states, index + 1);
Assertions.checkArgument(
states[index] == AD_STATE_UNAVAILABLE
|| states[index] == AD_STATE_AVAILABLE
|| states[index] == state);
long[] durationsUs =
this.durationsUs.length == states.length
? this.durationsUs
: copyDurationsUsWithSpaceForAdCount(this.durationsUs, states.length);
Uri[] uris =
this.uris.length == states.length ? this.uris : Arrays.copyOf(this.uris, states.length);
states[index] = state;
return new AdGroup(count, states, uris, durationsUs);
}
/**
* Returns a new instance with the specified ad set to the specified {@code state}. The ad
* specified must currently either be in {@link #AD_STATE_UNAVAILABLE} or {@link
* #AD_STATE_AVAILABLE}.
*
* <p>This instance's ad count may be unknown, in which case {@code index} must be less than the
* ad count specified later. Otherwise, {@code index} must be less than the current ad count.
*/
@CheckResult
public AdGroup withAdState(@AdState int state, int index) {
Assertions.checkArgument(count == C.LENGTH_UNSET || index < count);
@AdState int[] states = copyStatesWithSpaceForAdCount(this.states, index + 1);
Assertions.checkArgument(
states[index] == AD_STATE_UNAVAILABLE
|| states[index] == AD_STATE_AVAILABLE
|| states[index] == state);
long[] durationsUs =
this.durationsUs.length == states.length
? this.durationsUs
: copyDurationsUsWithSpaceForAdCount(this.durationsUs, states.length);
Uri[] uris =
this.uris.length == states.length ? this.uris : Arrays.copyOf(this.uris, states.length);
states[index] = state;
return new AdGroup(count, states, uris, durationsUs);
}
/**
* Parse string.
*
* @param options the options
* @return the string
*/
@CheckResult
public static String parse(Options options) {
switch (options) {
case SILENT:
return SILENT;
case FILE:
return FILE;
case BYTES:
return BYTES;
case COUNT:
return COUNT;
case FORMAT:
return FORMAT;
case CLEAR:
return CLEAR;
case DUMP:
return DUMP;
default:
return DUMP;
}
}
/**
* Parse string.
*
* @param level the level
* @return the string
*/
@CheckResult
public static String parse(Level level) {
switch (level) {
case VERBOSE:
return VERBOSE;
case DEBUG:
return DEBUG;
case INFO:
return INFO;
case WARN:
return WARN;
case ERROR:
return ERROR;
case FATAL:
return FATAL;
case ASSERT:
return ASSERT;
default:
return ASSERT;
}
}
/**
* Parse lev log utils . level.
*
* @param level the level
* @return the log utils . level
*/
@CheckResult
public static Level parseLev(String level) {
switch (level) {
case VERBOSE:
return Level.VERBOSE;
case DEBUG:
return Level.DEBUG;
case INFO:
return Level.INFO;
case WARN:
return Level.WARN;
case ERROR:
return Level.ERROR;
case FATAL:
return Level.FATAL;
case ASSERT:
return Level.ASSERT;
default:
return Level.ASSERT;
}
}
@SuppressWarnings("TypeParameterHidesVisibleType")
@CheckResult <R, T extends Throwable> R proceed(final OutboundType type, final Intent intent, final @Nullable R negative_value,
final CondomCore.WrappedValueProcedureThrows<R, T> procedure) throws T {
final String target_pkg = getTargetPackage(intent);
if (target_pkg != null) {
if (mBase.getPackageName().equals(target_pkg)) return procedure.proceed(); // Self-targeting request is allowed unconditionally
if (shouldBlockRequestTarget(type, intent, target_pkg)) return negative_value;
}
final int original_flags = adjustIntentFlags(type, intent);
try {
return procedure.proceed();
} finally {
intent.setFlags(original_flags);
}
}
@CheckResult <T extends Throwable> List<ResolveInfo> proceedQuery(
final OutboundType type, final Intent intent, final CondomCore.WrappedValueProcedureThrows<List<ResolveInfo>, T> procedure) throws T {
return proceed(type, intent, Collections.<ResolveInfo>emptyList(), new CondomCore.WrappedValueProcedureThrows<List<ResolveInfo>, T>() { @Override public List<ResolveInfo> proceed() throws T {
final List<ResolveInfo> candidates = procedure.proceed();
if (mOutboundJudge != null && getTargetPackage(intent) == null) { // Package-targeted intent is already filtered by OutboundJudge in proceed().
final Iterator<ResolveInfo> iterator = candidates.iterator();
while (iterator.hasNext()) {
final ResolveInfo candidate = iterator.next();
final String pkg = type == OutboundType.QUERY_SERVICES ? candidate.serviceInfo.packageName
: (type == OutboundType.QUERY_RECEIVERS ? candidate.activityInfo.packageName : null);
if (pkg != null && shouldBlockRequestTarget(type, intent, pkg)) // Dry-run is checked inside shouldBlockRequestTarget()
iterator.remove(); // TODO: Not safe to assume the list returned from PackageManager is modifiable.
}
}
return candidates;
}});
}
/**
* Returns a new instance with the specified {@code uri} set for the specified ad, and the ad
* marked as {@link #AD_STATE_AVAILABLE}. The specified ad must currently be in {@link
* #AD_STATE_UNAVAILABLE}, which is the default state.
*
* <p>This instance's ad count may be unknown, in which case {@code index} must be less than the
* ad count specified later. Otherwise, {@code index} must be less than the current ad count.
*/
@CheckResult
public AdGroup withAdUri(Uri uri, int index) {
Assertions.checkArgument(count == C.LENGTH_UNSET || index < count);
@AdState int[] states = copyStatesWithSpaceForAdCount(this.states, index + 1);
Assertions.checkArgument(states[index] == AD_STATE_UNAVAILABLE);
long[] durationsUs =
this.durationsUs.length == states.length
? this.durationsUs
: copyDurationsUsWithSpaceForAdCount(this.durationsUs, states.length);
Uri[] uris = Arrays.copyOf(this.uris, states.length);
uris[index] = uri;
states[index] = AD_STATE_AVAILABLE;
return new AdGroup(count, states, uris, durationsUs);
}
@CheckResult
private static @AdState int[] copyStatesWithSpaceForAdCount(@AdState int[] states, int count) {
int oldStateCount = states.length;
int newStateCount = Math.max(count, oldStateCount);
states = Arrays.copyOf(states, newStateCount);
Arrays.fill(states, oldStateCount, newStateCount, AD_STATE_UNAVAILABLE);
return states;
}
@CheckResult
private static long[] copyDurationsUsWithSpaceForAdCount(long[] durationsUs, int count) {
int oldDurationsUsCount = durationsUs.length;
int newDurationsUsCount = Math.max(count, oldDurationsUsCount);
durationsUs = Arrays.copyOf(durationsUs, newDurationsUsCount);
Arrays.fill(durationsUs, oldDurationsUsCount, newDurationsUsCount, C.TIME_UNSET);
return durationsUs;
}
public static
@CheckResult
Toast custom(@NonNull Context context, @NonNull CharSequence message, @DrawableRes int iconRes,
@ColorInt int textColor, @ColorInt int tintColor, int duration,
boolean withIcon, boolean shouldTint) {
return custom(context, message, ToastyUtils.getDrawable(context, iconRes), textColor,
tintColor, duration, withIcon, shouldTint);
}
/** Returns an instance with the specified ad marked as played. */
@CheckResult
public AdPlaybackState withPlayedAd(int adGroupIndex, int adIndexInAdGroup) {
AdGroup[] adGroups = Arrays.copyOf(this.adGroups, this.adGroups.length);
adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdState(AD_STATE_PLAYED, adIndexInAdGroup);
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
}
/** Returns an instance with the specified ad marked as skipped. */
@CheckResult
public AdPlaybackState withSkippedAd(int adGroupIndex, int adIndexInAdGroup) {
AdGroup[] adGroups = Arrays.copyOf(this.adGroups, this.adGroups.length);
adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdState(AD_STATE_SKIPPED, adIndexInAdGroup);
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
}
/** Returns an instance with the specified ad marked as having a load error. */
@CheckResult
public AdPlaybackState withAdLoadError(int adGroupIndex, int adIndexInAdGroup) {
AdGroup[] adGroups = Arrays.copyOf(this.adGroups, this.adGroups.length);
adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdState(AD_STATE_ERROR, adIndexInAdGroup);
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
}
/**
* Set the alpha component of {@code color} to be {@code alpha}.
*/
public static
@CheckResult
@ColorInt
int modifyAlpha(@ColorInt int color,
@IntRange(from = 0, to = 255) int alpha) {
return (color & 0x00ffffff) | (alpha << 24);
}
/** Returns an instance with the specified ad durations, in microseconds. */
@CheckResult
public AdPlaybackState withAdDurationsUs(long[][] adDurationUs) {
AdGroup[] adGroups = Arrays.copyOf(this.adGroups, this.adGroups.length);
for (int adGroupIndex = 0; adGroupIndex < adGroupCount; adGroupIndex++) {
adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdDurationsUs(adDurationUs[adGroupIndex]);
}
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
}
public static
@CheckResult
Toast custom(@NonNull Context context, @NonNull CharSequence message, Drawable icon,
@ColorInt int textColor, @ColorInt int tintColor, int duration,
boolean withIcon, boolean shouldTint) {
final Toast currentToast = new Toast(context);
final View toastLayout = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.toasty_layout, null);
final ImageView toastIcon = (ImageView) toastLayout.findViewById(R.id.toast_icon);
final TextView toastTextView = (TextView) toastLayout.findViewById(R.id.toast_text);
Drawable drawableFrame;
if (shouldTint)
drawableFrame = ToastyUtils.tint9PatchDrawableFrame(context, tintColor);
else
drawableFrame = ToastyUtils.getDrawable(context, R.drawable.toast_frame);
ToastyUtils.setBackground(toastLayout, drawableFrame);
if (withIcon) {
if (icon == null)
throw new IllegalArgumentException("Avoid passing 'icon' as null if 'withIcon' is set to true");
ToastyUtils.setBackground(toastIcon, icon);
} else
toastIcon.setVisibility(View.GONE);
toastTextView.setTextColor(textColor);
toastTextView.setText(message);
toastTextView.setTypeface(Typeface.create(TOAST_TYPEFACE, Typeface.NORMAL));
currentToast.setView(toastLayout);
currentToast.setDuration(duration);
return currentToast;
}
/** Returns an instance with the specified content duration, in microseconds. */
@CheckResult
public AdPlaybackState withContentDurationUs(long contentDurationUs) {
if (this.contentDurationUs == contentDurationUs) {
return this;
} else {
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
}
}
@CheckResult
private DecoderInitializationException copyWithFallbackException(
DecoderInitializationException fallbackException) {
return new DecoderInitializationException(
getMessage(),
getCause(),
mimeType,
secureDecoderRequired,
decoderName,
diagnosticInfo,
fallbackException);
}
/**
* Called when property has empty value
* @param propName
*/
@CheckResult
protected Object convertEmptyProperty(String propName, Object originalValue) {
switch (propName) {
case Constants.Name.BACKGROUND_COLOR:
return "transparent";
case Constants.Name.BORDER_RADIUS:
case Constants.Name.BORDER_BOTTOM_LEFT_RADIUS:
case Constants.Name.BORDER_BOTTOM_RIGHT_RADIUS:
case Constants.Name.BORDER_TOP_LEFT_RADIUS:
case Constants.Name.BORDER_TOP_RIGHT_RADIUS:
return 0;
case Constants.Name.BORDER_WIDTH:
case Constants.Name.BORDER_TOP_WIDTH:
case Constants.Name.BORDER_LEFT_WIDTH:
case Constants.Name.BORDER_RIGHT_WIDTH:
case Constants.Name.BORDER_BOTTOM_WIDTH:
return 0;
case Constants.Name.BORDER_COLOR:
case Constants.Name.BORDER_TOP_COLOR:
case Constants.Name.BORDER_LEFT_COLOR:
case Constants.Name.BORDER_RIGHT_COLOR:
case Constants.Name.BORDER_BOTTOM_COLOR:
return "black";
}
return originalValue;
}
@CheckResult
@Nullable
public static Drawable createTintedDrawable(@Nullable Drawable drawable, @NonNull ColorStateList colorStateList) {
if (drawable == null) {
return null;
}
Drawable wrap = DrawableCompat.wrap(drawable.mutate());
DrawableCompat.setTintList(wrap, colorStateList);
return wrap;
}
@CheckResult
static Matrix sigmoid(@NonNull Matrix matrix) {
Precondition.checkNotNull(matrix);
final Matrix copy = matrix.copy();
final double[] doubles = copy.getArray();
for (int i = 0, len = doubles.length; i < len; ++i) {
final double cur = -doubles[i];
doubles[i] = 1D / (1D + Math.exp(cur));
}
return copy;
}
/**
* Set the alpha component of {@code color} to be {@code alpha}.
*/
public static
@CheckResult
@ColorInt
int modifyAlpha(@ColorInt int color,
@FloatRange(from = 0f, to = 1f) float alpha) {
return modifyAlpha(color, (int) (255f * alpha));
}
/**
* Creates the operation. Note that you still need to call {@link Operation#execute()} to start
* the operation.
*
* @param device the device on which this operation will run
* @return the created operation
*/
@CheckResult
public Operation build(BluetoothDevice device) {
if (device == null) {
throw new IllegalArgumentException("Device cannot be null");
}
return new OperationImpl(context, device, commands, retryCount, masterObserver);
}
/**
* Returns a new instance with the specified {@code uri} set for the specified ad, and the ad
* marked as {@link #AD_STATE_AVAILABLE}. The specified ad must currently be in {@link
* #AD_STATE_UNAVAILABLE}, which is the default state.
*
* <p>This instance's ad count may be unknown, in which case {@code index} must be less than the
* ad count specified later. Otherwise, {@code index} must be less than the current ad count.
*/
@CheckResult
public AdGroup withAdUri(Uri uri, int index) {
Assertions.checkArgument(count == C.LENGTH_UNSET || index < count);
@AdState int[] states = copyStatesWithSpaceForAdCount(this.states, index + 1);
Assertions.checkArgument(states[index] == AD_STATE_UNAVAILABLE);
long[] durationsUs =
this.durationsUs.length == states.length
? this.durationsUs
: copyDurationsUsWithSpaceForAdCount(this.durationsUs, states.length);
Uri[] uris = Arrays.copyOf(this.uris, states.length);
uris[index] = uri;
states[index] = AD_STATE_AVAILABLE;
return new AdGroup(count, states, uris, durationsUs);
}
/** Returns a new instance with the specified ad durations, in microseconds. */
@CheckResult
public AdGroup withAdDurationsUs(long[] durationsUs) {
Assertions.checkArgument(count == C.LENGTH_UNSET || durationsUs.length <= this.uris.length);
if (durationsUs.length < this.uris.length) {
durationsUs = copyDurationsUsWithSpaceForAdCount(durationsUs, uris.length);
}
return new AdGroup(count, states, uris, durationsUs);
}
@CheckResult
@Nullable
public static Drawable createTintedDrawable(@Nullable Drawable drawable, @ColorInt int i) {
if (drawable == null) {
return null;
}
Drawable wrap = DrawableCompat.wrap(drawable.mutate());
DrawableCompat.setTintMode(wrap, Mode.SRC_IN);
DrawableCompat.setTint(wrap, i);
return wrap;
}
/** Returns an instance with the specified ad URI. */
@CheckResult
public AdPlaybackState withAdUri(int adGroupIndex, int adIndexInAdGroup, Uri uri) {
AdGroup[] adGroups = Arrays.copyOf(this.adGroups, this.adGroups.length);
adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdUri(uri, adIndexInAdGroup);
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
}
/** Returns an instance with the specified ad marked as played. */
@CheckResult
public AdPlaybackState withPlayedAd(int adGroupIndex, int adIndexInAdGroup) {
AdGroup[] adGroups = Arrays.copyOf(this.adGroups, this.adGroups.length);
adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdState(AD_STATE_PLAYED, adIndexInAdGroup);
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
}
/** Returns an instance with the specified ad marked as skipped. */
@CheckResult
public AdPlaybackState withSkippedAd(int adGroupIndex, int adIndexInAdGroup) {
AdGroup[] adGroups = Arrays.copyOf(this.adGroups, this.adGroups.length);
adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdState(AD_STATE_SKIPPED, adIndexInAdGroup);
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
}