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");
}
});
}
});
}
use of com.squareup.picasso.Callback in project instructure-android by instructure.
the class DiscussionEntryRowFactory method buildRowView.
// ///////////////////////////////////////////////////////////////
// Row Factories
// ///////////////////////////////////////////////////////////////
public static View buildRowView(Context context, DiscussionEntry discussionEntry, String author, String avatarURL, boolean showStudentNames, View convertView) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater inflater = LayoutInflater.from(context);
convertView = inflater.inflate(R.layout.listview_item_row_discussion_entry, null);
holder.avatar = (CircleImageView) convertView.findViewById(R.id.avatar);
holder.discussionEntry = (HelveticaTextView) convertView.findViewById(R.id.discussionEntry);
holder.date = (HelveticaTextView) convertView.findViewById(R.id.date);
holder.name = (HelveticaTextView) convertView.findViewById(R.id.name);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (avatarURL != null) {
// I tried doing this using a Target, but it wasn't loading the first time. I think it has to deal with
// the target being garbage collected. See more from Jake Wharton's answer from the link below.
//
// http://stackoverflow.com/questions/23732556/sometimes-picasso-doesnt-load-the-image-from-memory-cache
Picasso.with(context).load(avatarURL).into(holder.avatar, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
holder.avatar.setImageResource(R.drawable.ic_cv_user);
}
});
}
holder.discussionEntry.setText(Html.fromHtml(discussionEntry.getMessage(context.getString(R.string.deletedEntry))));
// make any links in the textview clickable. This will allow the user to view the link in whatever app they want
holder.discussionEntry.setMovementMethod(LinkMovementMethod.getInstance());
holder.date.setText(DateHelpers.getFormattedDate(context, discussionEntry.getCreatedAt()) + " " + DateHelpers.getFormattedTime(context, discussionEntry.getCreatedAt()));
if (showStudentNames) {
holder.name.setText(author);
}
return convertView;
}
use of com.squareup.picasso.Callback in project incubator-weex by apache.
the class ImageAdapter method setImage.
@Override
public void setImage(final String url, final ImageView view, WXImageQuality quality, final WXImageStrategy strategy) {
Runnable runnable = new Runnable() {
@Override
public void run() {
if (view == null || view.getLayoutParams() == null) {
return;
}
if (TextUtils.isEmpty(url)) {
view.setImageBitmap(null);
return;
}
String temp = url;
if (url.startsWith("//")) {
temp = "http:" + url;
}
if (view.getLayoutParams().width <= 0 || view.getLayoutParams().height <= 0) {
return;
}
if (!TextUtils.isEmpty(strategy.placeHolder)) {
Picasso.Builder builder = new Picasso.Builder(WXEnvironment.getApplication());
Picasso picasso = builder.build();
picasso.load(Uri.parse(strategy.placeHolder)).into(view);
view.setTag(strategy.placeHolder.hashCode(), picasso);
}
Picasso.with(WXEnvironment.getApplication()).load(temp).transform(new BlurTransformation(strategy.blurRadius)).into(view, new Callback() {
@Override
public void onSuccess() {
if (strategy.getImageListener() != null) {
strategy.getImageListener().onImageFinish(url, view, true, null);
}
if (!TextUtils.isEmpty(strategy.placeHolder)) {
((Picasso) view.getTag(strategy.placeHolder.hashCode())).cancelRequest(view);
}
}
@Override
public void onError() {
if (strategy.getImageListener() != null) {
strategy.getImageListener().onImageFinish(url, view, false, null);
}
}
});
}
};
if (Thread.currentThread() == Looper.getMainLooper().getThread()) {
runnable.run();
} else {
WXSDKManager.getInstance().postOnUiThread(runnable, 0);
}
}
Aggregations