androidx.annotation.CheckResult Java Examples

The following examples show how to use androidx.annotation.CheckResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlaybackInfo.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Copies playback info with new playing position.
 *
 * @param periodId New playing media period. See {@link #periodId}.
 * @param positionUs New position. See {@link #positionUs}.
 * @param contentPositionUs New content position. See {@link #contentPositionUs}. Value is ignored
 *     if {@code periodId.isAd()} is true.
 * @param totalBufferedDurationUs New buffered duration. See {@link #totalBufferedDurationUs}.
 * @return Copied playback info with new playing position.
 */
@CheckResult
public PlaybackInfo copyWithNewPosition(
    MediaPeriodId periodId,
    long positionUs,
    long contentPositionUs,
    long totalBufferedDurationUs) {
  return new PlaybackInfo(
      timeline,
      periodId,
      positionUs,
      periodId.isAd() ? contentPositionUs : C.TIME_UNSET,
      playbackState,
      playbackError,
      isLoading,
      trackGroups,
      trackSelectorResult,
      loadingMediaPeriodId,
      bufferedPositionUs,
      totalBufferedDurationUs,
      positionUs);
}
 
Example #2
Source File: AdPlaybackState.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
  @NullableType
  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);
}
 
Example #3
Source File: PlaybackInfo.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Copies playback info with new playback state.
 *
 * @param playbackState New playback state. See {@link #playbackState}.
 * @return Copied playback info with new playback state.
 */
@CheckResult
public PlaybackInfo copyWithPlaybackState(int playbackState) {
  return new PlaybackInfo(
      timeline,
      periodId,
      startPositionUs,
      contentPositionUs,
      playbackState,
      playbackError,
      isLoading,
      trackGroups,
      trackSelectorResult,
      loadingMediaPeriodId,
      bufferedPositionUs,
      totalBufferedDurationUs,
      positionUs);
}
 
Example #4
Source File: Floo.java    From Floo with Apache License 2.0 6 votes vote down vote up
/**
 * Get the result intent. Return null if the intent has been intercepted.
 *
 * @return The Intent, null if the intent has been intercepted.
 * @see #ifIntentNonNullSendTo(IntentReceiver)
 */
@Nullable @Override @CheckResult
public Intent getIntent() {
  sourceUri = appendSourceUri(sourceUri, queries);
  Chain chain = interceptRequest(sourceUri);
  sourceUri = chain.request();
  if (chain.isProceed()) {
    Target target = configuration().getTarget(getIndexUrl());
    if (target != null) {
      targetUri = createTargetUri(sourceUri, target);
    } else {
      log(ERROR, getIndexUrl() + " target not found");
      onTargetNotFound(sourceUri, bundle);
      chain = chain.abort();
    }
  }
  if (chain.isProceed()) {
    assert targetUri != null;
    chain = interceptTarget(targetUri);
    targetUri = chain.request();
    if (chain.isProceed()) {
      return createIntent();
    }
  }
  return null;
}
 
Example #5
Source File: PlaybackInfo.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Copies playback info with new track information.
 *
 * @param trackGroups New track groups. See {@link #trackGroups}.
 * @param trackSelectorResult New track selector result. See {@link #trackSelectorResult}.
 * @return Copied playback info with new track information.
 */
@CheckResult
public PlaybackInfo copyWithTrackInfo(
    TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) {
  return new PlaybackInfo(
      timeline,
      periodId,
      startPositionUs,
      contentPositionUs,
      playbackState,
      playbackError,
      isLoading,
      trackGroups,
      trackSelectorResult,
      loadingMediaPeriodId,
      bufferedPositionUs,
      totalBufferedDurationUs,
      positionUs);
}
 
Example #6
Source File: MediaCodecUtil.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a copy of the provided decoder list sorted such that decoders with format support are
 * listed first. The returned list is modifiable for convenience.
 */
@CheckResult
public static List<MediaCodecInfo> getDecoderInfosSortedByFormatSupport(
    List<MediaCodecInfo> decoderInfos, Format format) {
  decoderInfos = new ArrayList<>(decoderInfos);
  sortByScore(
      decoderInfos,
      decoderInfo -> {
        try {
          return decoderInfo.isFormatSupported(format) ? 1 : 0;
        } catch (DecoderQueryException e) {
          return -1;
        }
      });
  return decoderInfos;
}
 
Example #7
Source File: PlaybackInfo.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Copies playback info with new loading media period.
 *
 * @param loadingMediaPeriodId New loading media period id. See {@link #loadingMediaPeriodId}.
 * @return Copied playback info with new loading media period.
 */
@CheckResult
public PlaybackInfo copyWithLoadingMediaPeriodId(MediaPeriodId loadingMediaPeriodId) {
  return new PlaybackInfo(
      timeline,
      periodId,
      startPositionUs,
      contentPositionUs,
      playbackState,
      playbackError,
      isLoading,
      trackGroups,
      trackSelectorResult,
      loadingMediaPeriodId,
      bufferedPositionUs,
      totalBufferedDurationUs,
      positionUs);
}
 
Example #8
Source File: AdPlaybackState.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
  @NullableType Uri[] uris = Arrays.copyOf(this.uris, states.length);
  uris[index] = uri;
  states[index] = AD_STATE_AVAILABLE;
  return new AdGroup(count, states, uris, durationsUs);
}
 
Example #9
Source File: DownloadManager.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Nullable
@CheckResult
private Task syncQueuedDownload(@Nullable Task activeTask, Download download) {
  if (activeTask != null) {
    // We have a task, which must be a download task. If the download state is queued we need to
    // cancel it and start a new one, since a new request has been merged into the download.
    Assertions.checkState(!activeTask.isRemove);
    activeTask.cancel(/* released= */ false);
    return activeTask;
  }

  if (!canDownloadsRun() || activeDownloadTaskCount >= maxParallelDownloads) {
    return null;
  }

  // We can start a download task.
  download = putDownloadWithState(download, STATE_DOWNLOADING);
  Downloader downloader = downloaderFactory.createDownloader(download.request);
  activeTask =
      new Task(
          download.request,
          downloader,
          download.progress,
          /* isRemove= */ false,
          minRetryCount,
          /* internalHandler= */ this);
  activeTasks.put(download.request.id, activeTask);
  if (activeDownloadTaskCount++ == 0) {
    sendEmptyMessageDelayed(MSG_UPDATE_PROGRESS, UPDATE_PROGRESS_INTERVAL_MS);
  }
  activeTask.start();
  return activeTask;
}
 
Example #10
Source File: Rx2Idler.java    From RxIdler with Apache License 2.0 5 votes vote down vote up
/**
 * Wraps the supplied {@link Scheduler} into one which also implements {@link IdlingResource}.
 * You must {@linkplain IdlingRegistry#register(IdlingResource...) register} the
 * returned instance with Espresso before it will be used. Only work scheduled on the returned
 * instance directly will be registered.
 */
@SuppressWarnings("ConstantConditions") // Public API guarding.
@CheckResult @NonNull
public static IdlingResourceScheduler wrap(@NonNull Scheduler scheduler, @NonNull String name) {
  if (scheduler == null) throw new NullPointerException("scheduler == null");
  if (name == null) throw new NullPointerException("name == null");
  return new DelegatingIdlingResourceScheduler(scheduler, name);
}
 
Example #11
Source File: AdPlaybackState.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #12
Source File: AdPlaybackState.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #13
Source File: AdPlaybackState.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/** Returns an instance with the specified ad URI. */
@CheckResult
public AdPlaybackState withAdUri(int adGroupIndex, int adIndexInAdGroup, Uri uri) {
  AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
  adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdUri(uri, adIndexInAdGroup);
  return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
}
 
Example #14
Source File: RxIdler.java    From RxIdler with Apache License 2.0 5 votes vote down vote up
/**
 * Wraps the supplied {@link Scheduler} into one which also implements {@link IdlingResource}.
 * You must {@linkplain IdlingRegistry#register(IdlingResource...) register} the
 * returned instance with Espresso before it will be used. Only work scheduled on the returned
 * instance directly will be registered.
 */
@SuppressWarnings("ConstantConditions") // Public API guarding.
@CheckResult @NonNull
public static IdlingResourceScheduler wrap(@NonNull Scheduler scheduler, @NonNull String name) {
  if (scheduler == null) throw new NullPointerException("scheduler == null");
  if (name == null) throw new NullPointerException("name == null");
  return new DelegatingIdlingResourceScheduler(scheduler, name);
}
 
Example #15
Source File: AdPlaybackState.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/** Returns an instance with the specified ad marked as played. */
@CheckResult
public AdPlaybackState withPlayedAd(int adGroupIndex, int adIndexInAdGroup) {
  AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
  adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdState(AD_STATE_PLAYED, adIndexInAdGroup);
  return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
}
 
Example #16
Source File: CondomCore.java    From condom with Apache License 2.0 5 votes vote down vote up
@CheckResult <R, T extends Throwable> R proceed(final OutboundType type, final @Nullable Intent intent, final @Nullable R negative_value,
												final WrappedValueProcedureThrows<R, T> procedure) throws T {
	final String target_pkg = intent != null ? getTargetPackage(intent) : null;
	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 = intent != null ? adjustIntentFlags(type, intent) : 0;
	try {
		return procedure.proceed();
	} finally {
		if (intent != null) intent.setFlags(original_flags);
	}
}
 
Example #17
Source File: AdPlaybackState.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/** Returns an instance with the specified ad resume position, in microseconds. */
@CheckResult
public AdPlaybackState withAdResumePositionUs(long adResumePositionUs) {
  if (this.adResumePositionUs == adResumePositionUs) {
    return this;
  } else {
    return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
  }
}
 
Example #18
Source File: AdPlaybackState.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/** 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);
  }
}
 
Example #19
Source File: ThemeStore.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
@CheckResult
@ColorInt
public static int statusBarColor(@NonNull Context context) {
    if (!coloredStatusBar(context)) {
        return Color.BLACK;
    }
    return prefs(context).getInt(KEY_STATUS_BAR_COLOR, primaryColorDark(context));
}
 
Example #20
Source File: Rx2Idler.java    From RxIdler with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a function which wraps the supplied {@link Scheduler} in one which notifies Espresso as
 * to whether it is currently executing work or not.
 * <p>
 * Note: Work scheduled in the future does not mark the idling resource as busy.
 */
@SuppressWarnings("ConstantConditions") // Public API guarding.
@CheckResult @NonNull
public static Function<Callable<Scheduler>, Scheduler> create(@NonNull final String name) {
  if (name == null) throw new NullPointerException("name == null");
  return new Function<Callable<Scheduler>, Scheduler>() {
    @Override public Scheduler apply(Callable<Scheduler> delegate) throws Exception {
      IdlingResourceScheduler scheduler =
          new DelegatingIdlingResourceScheduler(delegate.call(), name);
      IdlingRegistry.getInstance().register(scheduler);
      return scheduler;
    }
  };
}
 
Example #21
Source File: URLFormatUtils.java    From FCM-for-Mojo with GNU General Public License v3.0 5 votes vote down vote up
@CheckResult
public static String addEndSlash(String url) {
    if (!url.endsWith("/")) {
        url += "/";
    }
    return url;
}
 
Example #22
Source File: TintHelper.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
@CheckResult
@Nullable
public static Drawable createTintedDrawable(@Nullable Drawable drawable, @ColorInt int color) {
    if (drawable == null) return null;
    drawable = DrawableCompat.wrap(drawable.mutate());
    DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
    DrawableCompat.setTint(drawable, color);
    return drawable;
}
 
Example #23
Source File: TintHelper.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
@CheckResult
@Nullable
public static Drawable createTintedDrawable(@Nullable Drawable drawable, @NonNull ColorStateList sl) {
    if (drawable == null) return null;
    drawable = DrawableCompat.wrap(drawable.mutate());
    DrawableCompat.setTintList(drawable, sl);
    return drawable;
}
 
Example #24
Source File: ThemeStore.java    From a with GNU General Public License v3.0 5 votes vote down vote up
@CheckResult
@ColorInt
public static int statusBarColor(@NonNull Context context) {
    if (!coloredStatusBar(context)) {
        return Color.BLACK;
    }
    return prefs(context).getInt(KEY_STATUS_BAR_COLOR, primaryColorDark(context));
}
 
Example #25
Source File: AppUtil.java    From weather with Apache License 2.0 5 votes vote down vote up
/**
 * Set the alpha component of {@code color} to be {@code alpha}.
 */
static @CheckResult
@ColorInt
int modifyAlpha(@ColorInt int color,
                @IntRange(from = 0, to = 255) int alpha) {
  return (color & 0x00ffffff) | (alpha << 24);
}
 
Example #26
Source File: AppUtil.java    From weather with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #27
Source File: TintHelper.java    From a with GNU General Public License v3.0 5 votes vote down vote up
@CheckResult
@Nullable
public static Drawable createTintedDrawable(@Nullable Drawable drawable, @ColorInt int color) {
    if (drawable == null) return null;
    drawable = DrawableCompat.wrap(drawable.mutate());
    DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
    DrawableCompat.setTint(drawable, color);
    return drawable;
}
 
Example #28
Source File: Floo.java    From Floo with Apache License 2.0 5 votes vote down vote up
@NonNull @Override @CheckResult
public Navigation putExtras(@NonNull Intent intent) {
  Bundle extras = intent.getExtras();
  if (extras != null) {
    return putExtras(extras);
  }
  return this;
}
 
Example #29
Source File: ThemeStore.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
@CheckResult
@ColorInt
public static int navigationBarColor(@NonNull Context context) {
    if (!coloredNavigationBar(context)) {
        return Color.BLACK;
    }
    return prefs(context).getInt(KEY_NAVIGATION_BAR_COLOR, primaryColor(context));
}
 
Example #30
Source File: RingtoneUtils.java    From android-ringtone-picker with Apache License 2.0 5 votes vote down vote up
/**
 * Get the list of the music (sound) files from the phone storage. It will add title as the key and
 * uri of the sound as value in given {@link LinkedHashMap}.
 *
 * @param context instance of the caller.
 * @return {@link LinkedHashMap} of the title-{@link Uri} pair of all the music tracks.
 * @throws IllegalStateException If storage read permission is not available.
 */
@NonNull
@CheckResult
@SuppressLint("InlinedApi")
@RequiresPermission(anyOf = {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE})
static LinkedHashMap<String, Uri> getMusic(@NonNull final Context context) {
    final LinkedHashMap<String, Uri> ringToneList = new LinkedHashMap<>();

    //Check for the read permission
    if (!RingtoneUtils.checkForStorageReadPermission(context)) {
        throw new IllegalStateException("Storage permission is not available.");
    }

    //Prepare query
    final Cursor mediaCursor = context.getContentResolver()
            .query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                    new String[]{MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media._ID},
                    MediaStore.Audio.Media.IS_MUSIC + "!= 0",
                    null,
                    MediaStore.Audio.Media.TITLE + " ASC");

    if (mediaCursor != null) {
        while (mediaCursor.moveToNext()) {
            ringToneList.put(mediaCursor.getString(mediaCursor.getColumnIndex(MediaStore.Audio.Media.TITLE)),
                    Uri.parse(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI + "/"
                            + mediaCursor.getString(mediaCursor.getColumnIndex(MediaStore.Audio.Media._ID))));
        }
        mediaCursor.close();
    }

    return ringToneList;
}