Search in sources :

Example 21 with Response

use of retrofit.client.Response in project Timber by naman14.

the class LyricsFragment method loadLyrics.

private void loadLyrics() {
    final View lyricsView = rootView.findViewById(R.id.lyrics);
    final TextView poweredbyTextView = (TextView) lyricsView.findViewById(R.id.lyrics_makeitpersonal);
    poweredbyTextView.setVisibility(View.GONE);
    final TextView lyricsTextView = (TextView) lyricsView.findViewById(R.id.lyrics_text);
    lyricsTextView.setText(getString(R.string.lyrics_loading));
    String filename = getRealPathFromURI(Uri.parse(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI + "/" + MusicPlayer.getCurrentAudioId()));
    if (filename != null && lyrics == null) {
        lyrics = LyricsExtractor.getLyrics(new File(filename));
    }
    if (lyrics != null) {
        lyricsTextView.setText(lyrics);
    } else {
        String artist = MusicPlayer.getArtistName();
        if (artist != null) {
            int i = artist.lastIndexOf(" feat");
            if (i != -1) {
                artist = artist.substring(0, i);
            }
            LyricsLoader.getInstance(this.getContext()).getLyrics(artist, MusicPlayer.getTrackName(), new Callback<String>() {

                @Override
                public void success(String s, Response response) {
                    lyrics = s;
                    if (s.equals("Sorry, We don't have lyrics for this song yet.\n")) {
                        lyricsTextView.setText(R.string.no_lyrics);
                    } else {
                        lyricsTextView.setText(s);
                        poweredbyTextView.setVisibility(View.VISIBLE);
                    }
                }

                @Override
                public void failure(RetrofitError error) {
                    lyricsTextView.setText(R.string.no_lyrics);
                }
            });
        } else {
            lyricsTextView.setText(R.string.no_lyrics);
        }
    }
}
Also used : Response(retrofit.client.Response) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) File(java.io.File) RetrofitError(retrofit.RetrofitError)

Example 22 with Response

use of retrofit.client.Response in project glasquare by davidvavra.

the class CheckInActivity method addPhoto.

private void addPhoto() {
    String checkInId = mCheckInResponse.getCheckInId();
    TypedFile typedFile = new TypedFile("image/jpeg", mPhoto);
    Api.get().create(Photos.class).add(checkInId, typedFile, new Callback<Photos.PhotoAddResponse>() {

        @Override
        public void success(Photos.PhotoAddResponse photoAddResponse, Response response) {
            showCheckInComplete();
        }

        @Override
        public void failure(RetrofitError retrofitError) {
            showCheckInComplete();
        }
    });
}
Also used : Photos(cz.destil.glasquare.api.Photos) Response(retrofit.client.Response) TypedFile(retrofit.mime.TypedFile) RetrofitError(retrofit.RetrofitError)

Example 23 with Response

use of retrofit.client.Response in project enroscar by stanfy.

the class RetrofitClient method readResponse.

private Response readResponse(URLConnection connection) throws IOException {
    int status = HttpURLConnection.HTTP_OK;
    String reason = "";
    if (connection instanceof HttpURLConnection) {
        status = ((HttpURLConnection) connection).getResponseCode();
        reason = ((HttpURLConnection) connection).getResponseMessage();
    }
    List<Header> headers = new ArrayList<>();
    for (Map.Entry<String, List<String>> field : connection.getHeaderFields().entrySet()) {
        String name = field.getKey();
        for (String value : field.getValue()) {
            headers.add(new Header(name, value));
        }
    }
    String mimeType = connection.getContentType();
    int length = connection.getContentLength();
    InputStream stream;
    if (status >= 400 && connection instanceof HttpURLConnection) {
        stream = ((HttpURLConnection) connection).getErrorStream();
    } else {
        stream = connection.getInputStream();
    }
    TypedInput responseBody = new TypedInputStream(mimeType, length, stream);
    return new Response(connection.getURL().toString(), status, reason, headers, responseBody);
}
Also used : InputStream(java.io.InputStream) TypedInput(retrofit.mime.TypedInput) ArrayList(java.util.ArrayList) Response(retrofit.client.Response) HttpURLConnection(java.net.HttpURLConnection) Header(retrofit.client.Header) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 24 with Response

use of retrofit.client.Response in project SpotiQ by ZinoKader.

the class SpotifyAuthenticationActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if (requestCode == ApplicationConstants.LOGIN_INTENT_REQUEST_CODE) {
        AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, intent);
        switch(response.getType()) {
            case TOKEN:
                Log.d(LogTag.LOG_LOGIN, "Logged in successfully!");
                // refresh our authentication token
                spotifyCommunicatorService.getAuthenticator().setExpiryTimeStamp(response.getExpiresIn());
                spotifyCommunicatorService.getAuthenticator().setAccessToken(response.getAccessToken());
                spotifyCommunicatorService.getWebApi().getMe(new Callback<UserPrivate>() {

                    @Override
                    public void success(UserPrivate userPrivate, Response response) {
                        if (userPrivate.product.equals(SpotifyConstants.PRODUCT_PREMIUM)) {
                            setResult(SpotifyConstants.RESULT_CODE_AUTHENTICATED);
                        } else {
                            setResult(SpotifyConstants.RESULT_CODE_NO_PREMIUM);
                        }
                        finish();
                    }

                    @Override
                    public void failure(RetrofitError error) {
                        setResult(SpotifyConstants.RESULT_CODE_CONNECTION_FAILURE);
                        finish();
                    }
                });
                break;
            case CODE:
                setResult(SpotifyConstants.RESULT_CODE_SPOTIFY_CODE);
                finish();
            case EMPTY:
                setResult(SpotifyConstants.RESULT_CODE_EMPTY);
                finish();
            case ERROR:
                setResult(SpotifyConstants.RESULT_CODE_ERROR);
                finish();
            case UNKNOWN:
                setResult(SpotifyConstants.RESULT_CODE_UNKNOWN);
                finish();
            default:
                setResult(SpotifyConstants.RESULT_CODE_WRONG_REQUEST_CODE);
                Log.d(LogTag.LOG_LOGIN, "Something went wrong on login");
                finish();
        }
    } else {
        setResult(SpotifyConstants.RESULT_CODE_WRONG_REQUEST_CODE);
        Log.d(LogTag.LOG_LOGIN, "Wrong request code for Spotify login");
        finish();
    }
}
Also used : AuthenticationResponse(com.spotify.sdk.android.authentication.AuthenticationResponse) Response(retrofit.client.Response) UserPrivate(kaaes.spotify.webapi.android.models.UserPrivate) AuthenticationResponse(com.spotify.sdk.android.authentication.AuthenticationResponse) RetrofitError(retrofit.RetrofitError)

Example 25 with Response

use of retrofit.client.Response in project android-test-demo by abdyer.

the class MockApiService method getEvents.

@Override
public void getEvents(@Path("organization") String organization, Callback<Events> callback) {
    try {
        String json = readFileFromAssets(EVENTS_RESPONSE_FILE);
        Response response = getMockResponse(HTTP_OK_STATUS, json);
        Events events = getMockResponseData(json, Events.class);
        callback.success(events, response);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Response(retrofit.client.Response) IOException(java.io.IOException)

Aggregations

Response (retrofit.client.Response)46 RetrofitError (retrofit.RetrofitError)27 LinkHeaders (com.instructure.canvasapi.utilities.LinkHeaders)8 View (android.view.View)7 TextView (android.widget.TextView)7 ImageView (android.widget.ImageView)6 ArrayList (java.util.ArrayList)5 Callback (retrofit.Callback)5 RestAdapter (retrofit.RestAdapter)5 SharedPreferences (android.content.SharedPreferences)4 User (com.instructure.canvasapi.model.User)4 ClientAuthInterceptor (io.plaidapp.data.api.ClientAuthInterceptor)4 HashMap (java.util.HashMap)4 Intent (android.content.Intent)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 ForgetPasswordResponse (org.matrix.androidsdk.rest.model.ForgetPasswordResponse)3 RequestEmailValidationResponse (org.matrix.androidsdk.rest.model.RequestEmailValidationResponse)3 RequestPhoneNumberValidationResponse (org.matrix.androidsdk.rest.model.RequestPhoneNumberValidationResponse)3 TokenRefreshResponse (org.matrix.androidsdk.rest.model.login.TokenRefreshResponse)3