use of com.squareup.picasso.Callback in project iNGAGE by davis123123.
the class UserProfileActivity method downloadAvatar.
private void downloadAvatar() {
final String url = "http://107.170.232.60/avatars/" + username + ".JPG";
Context context = getBaseContext();
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
int screenHeight = metrics.heightPixels;
int screenWidth = metrics.widthPixels;
final int imgHeight = (int) (screenHeight * 0.25);
final int imgWidth = imgHeight;
Picasso.with(this).load(url).resize(imgWidth, imgHeight).onlyScaleDown().noPlaceholder().memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE).into(curr_avatar, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
// If cache fails, try to fetch from url
Picasso.with(getBaseContext()).load(url).resize(imgWidth, imgHeight).onlyScaleDown().noPlaceholder().memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE).into(curr_avatar, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
Log.e("Picasso", "Could not get image");
}
});
}
});
}
use of com.squareup.picasso.Callback in project iNGAGE by davis123123.
the class ChangeAvatarActivity method downloadCurrentAvatar.
/* private void downloadCurrentAvatar(){
Context context = getApplicationContext();
DownloadAvatarHandler avatarHandler = new DownloadAvatarHandler(context);
String type = "download";
//do conversion
try {
//String username = (String) display_username.getText();
String result = avatarHandler.execute(type, username).get();
//Log.d("STATE", "room title: " + threadsHelper.getThread_title());
Log.d("STATE", "download avatar result: " + result);
if(result.length() > default_path.length()) {
int index = result.indexOf(",") + 1;
String code = result.substring(index, result.length());
byte[] decodedString = Base64.decode(code, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
new_avatar_preview.setImageBitmap(decodedByte);
LinearLayout.LayoutParams img_params = new LinearLayout.LayoutParams(700, 700);
new_avatar_preview.setLayoutParams(img_params);
}
else
new_avatar_preview.setImageResource(R.mipmap.user);
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}*/
private void downloadCurrentAvatar() {
final String url = "http://107.170.232.60/avatars/" + username + ".JPG";
Context context = getBaseContext();
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
int screenHeight = metrics.heightPixels;
int screenWidth = metrics.widthPixels;
final int imgHeight = (int) (screenHeight * 0.3);
final int imgWidth = (int) (screenWidth * 0.3);
new_avatar_preview.setAlpha((float) 0.5);
Picasso.with(this).load(url).resize(imgWidth, imgHeight).onlyScaleDown().noPlaceholder().memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE).into(new_avatar_preview, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
// If cache fails, try to fetch from url
Picasso.with(getBaseContext()).load(url).resize(imgWidth, imgHeight).onlyScaleDown().noPlaceholder().memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE).into(new_avatar_preview, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
Log.e("Picasso", "Could not get image");
new_avatar_preview.setImageResource(R.mipmap.user);
}
});
}
});
}
use of com.squareup.picasso.Callback in project iNGAGE by davis123123.
the class MainActivity method downloadAvatar.
private void downloadAvatar() {
final String url = "http://107.170.232.60/avatars/" + userName.getText() + ".JPG";
Context context = getBaseContext();
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
int screenHeight = metrics.heightPixels;
int screenWidth = metrics.widthPixels;
final int imgHeight = (int) (screenHeight * 0.25);
final int imgWidth = imgHeight;
LinearLayout.LayoutParams img_params = new LinearLayout.LayoutParams(imgWidth, imgHeight);
img_params.setMargins(40, 40, 40, 40);
avatar.setLayoutParams(img_params);
Picasso.with(this).load(url).resize(imgWidth, imgHeight).noPlaceholder().memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE).onlyScaleDown().into(avatar, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
// If cache fails, try to fetch from url
Picasso.with(getBaseContext()).load(url).resize(imgWidth, imgHeight).onlyScaleDown().noPlaceholder().memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE).into(avatar, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
Log.e("Picasso", "Could not get image");
}
});
}
});
}
Aggregations