Search in sources :

Example 66 with Nullable

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() + "\"}";
    }
}
Also used : Buffer(okio.Buffer) IOException(java.io.IOException) ResponseBody(okhttp3.ResponseBody) BufferedSource(okio.BufferedSource) Nullable(androidx.annotation.Nullable)

Example 67 with Nullable

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;
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable) Nullable(androidx.annotation.Nullable)

Example 68 with Nullable

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);
}
Also used : UriMediaItem(androidx.media2.common.UriMediaItem) MediaItem(androidx.media2.common.MediaItem) SessionPlayer(androidx.media2.common.SessionPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(androidx.annotation.Nullable) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MediumTest(androidx.test.filters.MediumTest) LargeTest(androidx.test.filters.LargeTest) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Example 69 with Nullable

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();
}
Also used : CallbackMediaItem(androidx.media2.common.CallbackMediaItem) Uri(android.net.Uri) FileMediaItem(androidx.media2.common.FileMediaItem) Nullable(androidx.annotation.Nullable) UriMediaItem(androidx.media2.common.UriMediaItem)

Example 70 with Nullable

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();
    });
}
Also used : PlayerResult(androidx.media2.common.SessionPlayer.PlayerResult) Nullable(androidx.annotation.Nullable)

Aggregations

Nullable (androidx.annotation.Nullable)1124 View (android.view.View)188 Bundle (android.os.Bundle)111 IOException (java.io.IOException)99 NonNull (androidx.annotation.NonNull)96 ArrayList (java.util.ArrayList)95 Context (android.content.Context)93 TextView (android.widget.TextView)92 Cursor (android.database.Cursor)71 SuppressLint (android.annotation.SuppressLint)69 Uri (android.net.Uri)66 RecyclerView (androidx.recyclerview.widget.RecyclerView)59 List (java.util.List)58 ViewGroup (android.view.ViewGroup)56 Test (org.junit.Test)55 Intent (android.content.Intent)53 Recipient (org.thoughtcrime.securesms.recipients.Recipient)52 R (org.thoughtcrime.securesms.R)46 LayoutInflater (android.view.LayoutInflater)45 ImageView (android.widget.ImageView)43