use of androidx.annotation.Nullable in project MVPArms by JessYanCoding.
the class RequestInterceptor method printResult.
/**
* 打印响应结果
*
* @param request {@link Request}
* @param response {@link Response}
* @param logResponse 是否打印响应结果
* @return 解析后的响应结果
* @throws IOException
*/
@Nullable
private String printResult(Request request, Response response, boolean logResponse) throws IOException {
try {
// 读取服务器返回的结果
ResponseBody responseBody = response.newBuilder().build().body();
BufferedSource source = responseBody.source();
// Buffer the entire body.
source.request(Long.MAX_VALUE);
Buffer buffer = source.buffer();
// 获取content的压缩类型
String encoding = response.headers().get("Content-Encoding");
Buffer clone = buffer.clone();
// 解析response content
return parseContent(responseBody, encoding, clone);
} catch (IOException e) {
e.printStackTrace();
return "{\"error\": \"" + e.getMessage() + "\"}";
}
}
use of androidx.annotation.Nullable in project MaterialProgressBar by DreaminginCodeZH.
the class MaterialProgressBar method getTintTargetFromProgressDrawable.
@Nullable
private Drawable getTintTargetFromProgressDrawable(int layerId, boolean shouldFallback) {
Drawable progressDrawable = getProgressDrawable();
if (progressDrawable == null) {
return null;
}
progressDrawable.mutate();
Drawable layerDrawable = null;
if (progressDrawable instanceof LayerDrawable) {
layerDrawable = ((LayerDrawable) progressDrawable).findDrawableByLayerId(layerId);
}
if (layerDrawable == null && shouldFallback) {
layerDrawable = progressDrawable;
}
return layerDrawable;
}
use of androidx.annotation.Nullable in project ExoPlayer by google.
the class SessionPlayerConnectorTest method prepare_notifiesBufferingCompletedOnce.
@Test
@LargeTest
public void prepare_notifiesBufferingCompletedOnce() throws Throwable {
TestUtils.loadResource(R.raw.video_big_buck_bunny, sessionPlayerConnector);
CountDownLatch onBufferingCompletedLatch = new CountDownLatch(2);
CopyOnWriteArrayList<Integer> bufferingStateChanges = new CopyOnWriteArrayList<>();
SessionPlayer.PlayerCallback callback = new SessionPlayer.PlayerCallback() {
@Override
public void onBufferingStateChanged(SessionPlayer player, @Nullable MediaItem item, int buffState) {
bufferingStateChanges.add(buffState);
if (buffState == SessionPlayer.BUFFERING_STATE_COMPLETE) {
onBufferingCompletedLatch.countDown();
}
}
};
sessionPlayerConnector.registerPlayerCallback(executor, callback);
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
assertWithMessage("Expected BUFFERING_STATE_COMPLETE only once. Full changes are %s", bufferingStateChanges).that(onBufferingCompletedLatch.await(PLAYER_STATE_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isFalse();
assertThat(bufferingStateChanges).isNotEmpty();
int lastIndex = bufferingStateChanges.size() - 1;
assertWithMessage("Didn't end with BUFFERING_STATE_COMPLETE. Full changes are %s", bufferingStateChanges).that(bufferingStateChanges.get(lastIndex)).isEqualTo(SessionPlayer.BUFFERING_STATE_COMPLETE);
}
use of androidx.annotation.Nullable in project ExoPlayer by google.
the class DefaultMediaItemConverter method convertToExoPlayerMediaItem.
@Override
public MediaItem convertToExoPlayerMediaItem(androidx.media2.common.MediaItem media2MediaItem) {
if (media2MediaItem instanceof FileMediaItem) {
throw new IllegalStateException("FileMediaItem isn't supported");
}
if (media2MediaItem instanceof CallbackMediaItem) {
throw new IllegalStateException("CallbackMediaItem isn't supported");
}
@Nullable Uri uri = null;
@Nullable String mediaId = null;
@Nullable String title = null;
if (media2MediaItem instanceof UriMediaItem) {
UriMediaItem uriMediaItem = (UriMediaItem) media2MediaItem;
uri = uriMediaItem.getUri();
}
@Nullable androidx.media2.common.MediaMetadata metadata = media2MediaItem.getMetadata();
if (metadata != null) {
@Nullable String uriString = metadata.getString(METADATA_KEY_MEDIA_URI);
mediaId = metadata.getString(METADATA_KEY_MEDIA_ID);
if (uri == null) {
if (uriString != null) {
uri = Uri.parse(uriString);
} else if (mediaId != null) {
uri = Uri.parse("media2:///" + mediaId);
}
}
title = metadata.getString(METADATA_KEY_DISPLAY_TITLE);
if (title == null) {
title = metadata.getString(METADATA_KEY_TITLE);
}
}
if (uri == null) {
// Generate a URI to make it non-null. If not, then the tag passed to setTag will be ignored.
uri = Uri.parse("media2:///");
}
long startPositionMs = media2MediaItem.getStartPosition();
if (startPositionMs == androidx.media2.common.MediaItem.POSITION_UNKNOWN) {
startPositionMs = 0;
}
long endPositionMs = media2MediaItem.getEndPosition();
if (endPositionMs == androidx.media2.common.MediaItem.POSITION_UNKNOWN) {
endPositionMs = C.TIME_END_OF_SOURCE;
}
return new MediaItem.Builder().setUri(uri).setMediaId(mediaId != null ? mediaId : MediaItem.DEFAULT_MEDIA_ID).setMediaMetadata(new MediaMetadata.Builder().setTitle(title).build()).setTag(media2MediaItem).setClippingConfiguration(new MediaItem.ClippingConfiguration.Builder().setStartPositionMs(startPositionMs).setEndPositionMs(endPositionMs).build()).build();
}
use of androidx.annotation.Nullable in project ExoPlayer by google.
the class PlayerCommandQueue method notifyCommandCompleted.
public void notifyCommandCompleted(@AsyncCommandCode int completedCommandCode) {
if (DEBUG) {
Log.d(TAG, "notifyCommandCompleted, completedCommandCode=" + completedCommandCode);
}
postOrRun(handler, () -> {
@Nullable AsyncPlayerCommandResult pendingResult = pendingAsyncPlayerCommandResult;
if (pendingResult == null || pendingResult.commandCode != completedCommandCode) {
if (DEBUG) {
Log.d(TAG, "Unexpected Listener is notified from the Player. Player may be used" + " directly rather than " + toLogFriendlyString(completedCommandCode));
}
return;
}
pendingResult.result.set(new PlayerResult(PlayerResult.RESULT_SUCCESS, player.getCurrentMediaItem()));
pendingAsyncPlayerCommandResult = null;
if (DEBUG) {
Log.d(TAG, "completed " + pendingResult);
}
processPendingCommandOnHandler();
});
}
Aggregations