Search in sources :

Example 36 with Callback

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");
                }
            });
        }
    });
}
Also used : Context(android.content.Context) Callback(com.squareup.picasso.Callback) DisplayMetrics(android.util.DisplayMetrics)

Example 37 with Callback

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);
                }
            });
        }
    });
}
Also used : Context(android.content.Context) Callback(com.squareup.picasso.Callback) DisplayMetrics(android.util.DisplayMetrics)

Example 38 with Callback

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");
                }
            });
        }
    });
}
Also used : Context(android.content.Context) Callback(com.squareup.picasso.Callback) DisplayMetrics(android.util.DisplayMetrics) LinearLayout(android.widget.LinearLayout)

Example 39 with Callback

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;
}
Also used : Callback(com.squareup.picasso.Callback) LayoutInflater(android.view.LayoutInflater)

Example 40 with Callback

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);
    }
}
Also used : Callback(com.squareup.picasso.Callback) Picasso(com.squareup.picasso.Picasso)

Aggregations

Callback (com.squareup.picasso.Callback)54 ImageView (android.widget.ImageView)21 View (android.view.View)18 TextView (android.widget.TextView)14 RequestCreator (com.squareup.picasso.RequestCreator)12 LayoutInflater (android.view.LayoutInflater)7 Context (android.content.Context)6 DisplayMetrics (android.util.DisplayMetrics)6 Bitmap (android.graphics.Bitmap)5 Intent (android.content.Intent)4 ViewGroup (android.view.ViewGroup)4 AppCompatImageView (androidx.appcompat.widget.AppCompatImageView)4 JSONArray (org.json.JSONArray)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 Resources (android.content.res.Resources)3 ColorDrawable (android.graphics.drawable.ColorDrawable)3 Bundle (android.os.Bundle)3 MotionEvent (android.view.MotionEvent)3 RecyclerView (androidx.recyclerview.widget.RecyclerView)3