Search in sources :

Example 21 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 22 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 23 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)

Aggregations

Callback (com.squareup.picasso.Callback)23 ImageView (android.widget.ImageView)7 View (android.view.View)6 Bitmap (android.graphics.Bitmap)4 TextView (android.widget.TextView)4 Context (android.content.Context)3 ColorDrawable (android.graphics.drawable.ColorDrawable)3 DisplayMetrics (android.util.DisplayMetrics)3 LayoutInflater (android.view.LayoutInflater)3 Bundle (android.os.Bundle)2 Palette (android.support.v7.graphics.Palette)2 MotionEvent (android.view.MotionEvent)2 ViewGroup (android.view.ViewGroup)2 Picasso (com.squareup.picasso.Picasso)2 RequestCreator (com.squareup.picasso.RequestCreator)2 PhotoViewAttacher (uk.co.senab.photoview.PhotoViewAttacher)2 AccountManagerCallback (android.accounts.AccountManagerCallback)1 TargetApi (android.annotation.TargetApi)1 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1