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);
}
}
}
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();
}
});
}
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);
}
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();
}
}
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();
}
}
Aggregations