Search in sources :

Example 1 with Callback

use of com.squareup.picasso.Callback in project cw-omnibus by commonsguy.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    iv = (ImageView) findViewById(R.id.asset);
    Picasso.with(this).load("file:///android_asset/FreedomTower-Morning.jpg").fit().centerCrop().into(iv, new Callback() {

        @Override
        public void onSuccess() {
            iv.setOnLongClickListener(MainActivity.this);
        }

        @Override
        public void onError() {
        // TODO
        }
    });
}
Also used : Callback(com.squareup.picasso.Callback)

Example 2 with Callback

use of com.squareup.picasso.Callback in project Hummingbird-for-Android by xiprox.

the class LibraryAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final ViewHolder holder;
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.item_library, parent, false);
        holder = new ViewHolder();
        holder.cover = (ImageView) convertView.findViewById(R.id.item_library_cover);
        holder.title = (TextView) convertView.findViewById(R.id.item_library_title);
        holder.desc = (TextView) convertView.findViewById(R.id.item_library_desc);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    LibraryEntry item = mItems.get(position);
    Log.d("TAG", item.getAnime().getCoverImage());
    Picasso.with(context).load(item.getAnime().getCoverImage()).into(holder.cover, new Callback() {

        @Override
        public void onSuccess() {
            try {
                Bitmap bitmap = ((BitmapDrawable) holder.cover.getDrawable()).getBitmap();
                int color = Palette.generate(bitmap).getDarkMutedSwatch().getRgb();
                ColorDrawable background = new ColorDrawable(color);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError() {
        }
    });
    holder.title.setText(item.getAnime().getTitle());
    String itemEpisodesCount = item.getAnime().getEpisodeCount() != 0 ? item.getAnime().getEpisodeCount() + "" : "?";
    if (item.isRewatching()) {
        holder.desc.setText(getString(R.string.content_library_rewatching_at) + " " + item.getEpisodesWatched() + "/" + item.getAnime().getEpisodeCount());
    } else {
        String status = item.getStatus();
        if (status.equals(LibraryFragment.FILTER_CURRENTLY_WATCHING))
            holder.desc.setText(getString(R.string.content_library_watching_at) + " " + item.getEpisodesWatched() + "/" + itemEpisodesCount);
        if (status.equals(LibraryFragment.FILTER_PLAN_TO_WATCH))
            holder.desc.setText(getString(R.string.content_library_planning_to_watch));
        if (status.equals(LibraryFragment.FILTER_COMPLETED))
            holder.desc.setText(getString(R.string.content_library_completed));
        if (status.equals(LibraryFragment.FILTER_ON_HOLD))
            holder.desc.setText(getString(R.string.content_library_on_hold));
        if (status.equals(LibraryFragment.FILTER_DROPPED))
            holder.desc.setText(getString(R.string.content_library_dropped));
    }
    return convertView;
}
Also used : Bitmap(android.graphics.Bitmap) LibraryEntry(tr.bcxip.hummingbird.api.objects.LibraryEntry) Callback(com.squareup.picasso.Callback) ColorDrawable(android.graphics.drawable.ColorDrawable) LayoutInflater(android.view.LayoutInflater)

Example 3 with Callback

use of com.squareup.picasso.Callback in project Hummingbird-for-Android by xiprox.

the class AnimeDetailsActivity method displayAnimeInfo.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void displayAnimeInfo() {
    Resources res = getResources();
    final ImageView imageView = new ImageView(AnimeDetailsActivity.this);
    Picasso.with(AnimeDetailsActivity.this).load(anime.getCoverImage()).into(imageView, new Callback() {

        @Override
        public void onSuccess() {
            coverBitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        }

        @Override
        public void onError() {
        }
    });
    if (coverBitmap != null) {
        mPalette = Palette.generate(coverBitmap);
        if (mPalette != null) {
            darkMutedColor = mPalette.getDarkMutedColor(res.getColor(R.color.neutral_darker));
            vibrantColor = mPalette.getVibrantColor(res.getColor(R.color.apptheme_primary));
            darkVibrantColor = mPalette.getDarkVibrantColor(res.getColor(R.color.apptheme_primary_dark));
        }
    } else
        darkMutedColor = res.getColor(R.color.neutral_darker);
    float[] vibrantColorHsv = new float[3];
    Color.colorToHSV(vibrantColor, vibrantColorHsv);
    vibrantColorHsv[2] = 1.0f - 0.8f * (1.0f - vibrantColorHsv[2]);
    vibrantColorLighter = Color.HSVToColor(vibrantColorHsv);
    float[] darkMutedColorHsv = new float[3];
    Color.colorToHSV(darkMutedColor, darkMutedColorHsv);
    darkMutedColorHsv[2] = 1.0f - 0.9f * (1.0f - darkMutedColorHsv[2]);
    darkMutedColorLighter = Color.HSVToColor(darkMutedColorHsv);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        getWindow().setStatusBarColor(darkMutedColor);
    int alpha = mActionBarBackgroundDrawable.getAlpha();
    mActionBarBackgroundDrawable = new ColorDrawable(darkMutedColorLighter);
    mActionBarBackgroundDrawable.setAlpha(alpha);
    if (toolbar != null)
        toolbar.setBackgroundDrawable(mActionBarBackgroundDrawable);
    mActionButton.setOnClickListener(new OnAddToLibraryClickListener());
    mActionButton.setColorNormal(vibrantColor);
    mActionButton.setColorPressed(vibrantColorLighter);
    mCoverImage.setImageBitmap(coverBitmap);
    mCoverHolder.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(AnimeDetailsActivity.this, FullscreenImageActivity.class);
            intent.putExtra(FullscreenImageActivity.ARG_IMAGE_URL, anime.getCoverImage());
            ActivityOptionsCompat transition = ActivityOptionsCompat.makeSceneTransitionAnimation(AnimeDetailsActivity.this, mCoverImage, FullscreenImageActivity.TRANSITION_NAME_IMAGE);
            Utils.startActivityWithTransition(AnimeDetailsActivity.this, intent, transition);
        }
    });
    // TODO - Put something else here
    mHeaderImage.setImageBitmap(coverBitmap);
    mHeaderHolder.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(AnimeDetailsActivity.this, FullscreenImageActivity.class);
            intent.putExtra(FullscreenImageActivity.ARG_IMAGE_URL, anime.getCoverImage());
            ActivityOptionsCompat transition = ActivityOptionsCompat.makeSceneTransitionAnimation(AnimeDetailsActivity.this, mHeaderImage, FullscreenImageActivity.TRANSITION_NAME_IMAGE);
            Utils.startActivityWithTransition(AnimeDetailsActivity.this, intent, transition);
        }
    });
    mTitle.setText(anime.getTitle());
    mType.setText(anime.getShowType());
    /*
            TODO
            For some reason the API omits genres in the Anime object bundled with the Library Entry
            object. Gotta find a solution for this. God! I really don't wanna have to load all data
            just because of a few damn genres!
         */
    String genres = null;
    if (anime.getGenres() != null) {
        for (int i = 0; i < anime.getGenres().size(); i++) {
            if (i == 0)
                genres = anime.getGenres().get(i).getName();
            else
                genres += ", " + anime.getGenres().get(i).getName();
        }
    }
    mGenre.setText(genres != null ? genres : getString(R.string.content_unknown));
    int episodeCount = anime.getEpisodeCount();
    mEpisodeCount.setText(episodeCount != 0 ? episodeCount + "" : getString(R.string.content_unknown));
    int episodeLength = anime.getEpisodeLength();
    mEpisodeLength.setText(episodeLength != 0 ? episodeLength + " " + getString(R.string.content_minutes).toLowerCase() : getString(R.string.content_unknown));
    mAgeRating.setText(anime.getAgeRating() != null ? anime.getAgeRating() : getString(R.string.content_unknown));
    SimpleDateFormat airDateFormat = new SimpleDateFormat("d MMMM yyyy");
    long airStart = anime.getAiringStartDate();
    long airEnd = anime.getAiringFinishedDate();
    Date airStartDate = new Date(airStart);
    Date airEndDate = new Date(airEnd);
    Calendar todayCal = Calendar.getInstance();
    Calendar airStartCal = Calendar.getInstance();
    airStartCal.setTime(airStartDate);
    if (airStart == 0 && airEnd == 0)
        mAired.setText(R.string.content_not_yet_aired);
    if (airStart == 0 && airEnd != 0)
        mAired.setText(getString(R.string.content_unknown) + " " + getString(R.string.to) + " " + airDateFormat.format(airEnd));
    if (airStart != 0 && airEnd == 0) {
        if (anime.getEpisodeCount() == 1)
            mAired.setText(airDateFormat.format(airStart));
        else
            mAired.setText(getString(R.string.content_airing_since) + " " + airDateFormat.format(airStart));
    }
    if (airStart != 0 && airEnd != 0)
        mAired.setText(airDateFormat.format(airStart) + " " + getString(R.string.to) + " " + airDateFormat.format(airEnd));
    if (airStartCal.get(Calendar.YEAR) > todayCal.get(Calendar.YEAR)) {
        if (anime.getEpisodeCount() == 1)
            mAired.setText(getString(R.string.content_will_air_on) + " " + airDateFormat.format(airStart));
        else
            mAired.setText(getString(R.string.content_will_start_airing_on) + " " + airDateFormat.format(airStart));
    }
    String comRating = String.valueOf(anime.getCommunityRating());
    if (comRating.length() > 3)
        comRating = comRating.substring(0, 4);
    else if (comRating.equals("0.0"))
        comRating = "?";
    mCommunityRating.setText(comRating);
    mSynopsis.setText(anime.getSynopsis());
    mSynopsisHolder.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            MaterialDialog dialog = new MaterialDialog.Builder(AnimeDetailsActivity.this).title(anime.getTitle()).customView(R.layout.dialog_text, true).build();
            ((TextView) dialog.getCustomView()).setText(anime.getSynopsis());
            dialog.show();
        }
    });
    mMoreSimilarAnime.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
        // TODO - More similar activity...
        }
    });
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Calendar(java.util.Calendar) Intent(android.content.Intent) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageView(android.widget.ImageView) ObservableScrollView(tr.bcxip.hummingbird.widget.ObservableScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) SimpleRatingView(tr.xip.widget.simpleratingview.SimpleRatingView) TextView(android.widget.TextView) ActivityOptionsCompat(android.support.v4.app.ActivityOptionsCompat) Date(java.util.Date) Callback(com.squareup.picasso.Callback) ColorDrawable(android.graphics.drawable.ColorDrawable) Resources(android.content.res.Resources) ImageView(android.widget.ImageView) SimpleDateFormat(java.text.SimpleDateFormat) TargetApi(android.annotation.TargetApi)

Example 4 with Callback

use of com.squareup.picasso.Callback in project instructure-android by instructure.

the class ProfileUtils method configureAvatarView.

public static void configureAvatarView(final Context context, final String username, final String avatarURL, final CircleImageView avatar, final boolean isGroup, final int color, Long conversationId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && conversationId != null) {
        avatar.setTransitionName(com.instructure.pandautils.utils.Const.MESSAGE + String.valueOf(conversationId));
    }
    if (!isGroup && avatarURL != null && !avatarURL.contains(noPictureURL) && !avatarURL.contains(noPictureURLAlternate)) {
        avatar.setBorderWidth(0);
        Picasso.with(context).load(avatarURL).fit().centerCrop().into(avatar, new Callback() {

            @Override
            public void onSuccess() {
            }

            @Override
            public void onError() {
                avatar.setImageDrawable(createInitialsAvatar(context, color, username));
            }
        });
    } else {
        if (!isGroup) {
            avatar.setImageDrawable(createInitialsAvatar(context, color, username));
        } else {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inMutable = true;
            Bitmap bm = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_group_32, options);
            avatar.setImageBitmap(ColorUtils.colorIt(color, bm));
            avatar.setBorderWidth((int) Utils.convertDipsToPixels(1, context));
            avatar.setBorderColor(color);
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) Callback(com.squareup.picasso.Callback) BitmapFactory(android.graphics.BitmapFactory)

Example 5 with Callback

use of com.squareup.picasso.Callback in project instructure-android by instructure.

the class TutorialFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.tutorial_fragment, container, false);
    View containerView = rootView.findViewById(R.id.container);
    containerView.setBackgroundColor(getResources().getColor(backgroundColorResIds[pageNumber]));
    TextView text = (TextView) rootView.findViewById(R.id.text);
    text.setText(getString(imageText[pageNumber]));
    deviceImage = (ImageView) rootView.findViewById(R.id.deviceImage);
    try {
        if (!isTablet) {
            Picasso.with(getActivity()).load(backgroundImageResIds_phone[pageNumber]).into(deviceImage, new Callback() {

                @Override
                public void onSuccess() {
                }

                @Override
                public void onError() {
                    if (deviceImage.getDrawable() != null) {
                        ((BitmapDrawable) deviceImage.getDrawable()).getBitmap().recycle();
                    }
                    // try again
                    Picasso.with(getActivity()).load(backgroundImageResIds_phone[pageNumber]).into(deviceImage);
                }
            });
        } else if (isSmallTablet) {
            Picasso.with(getActivity()).load(backgroundImageResIds_smallTablet[pageNumber]).into(deviceImage, new Callback() {

                @Override
                public void onSuccess() {
                }

                @Override
                public void onError() {
                    if (deviceImage.getDrawable() != null) {
                        ((BitmapDrawable) deviceImage.getDrawable()).getBitmap().recycle();
                    }
                    // try again
                    Picasso.with(getActivity()).load(backgroundImageResIds_smallTablet[pageNumber]).into(deviceImage);
                }
            });
        } else {
            Picasso.with(getActivity()).load(backgroundImageResIds_tablet[pageNumber]).into(deviceImage, new Callback() {

                @Override
                public void onSuccess() {
                }

                @Override
                public void onError() {
                    if (deviceImage.getDrawable() != null) {
                        ((BitmapDrawable) deviceImage.getDrawable()).getBitmap().recycle();
                    }
                    // try again
                    Picasso.with(getActivity()).load(backgroundImageResIds_tablet[pageNumber]).into(deviceImage);
                }
            });
        }
    } catch (OutOfMemoryError e) {
        if (callback != null) {
            callback.forceExit_Exception(e);
        }
    }
    return rootView;
}
Also used : Callback(com.squareup.picasso.Callback) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View)

Aggregations

Callback (com.squareup.picasso.Callback)42 ImageView (android.widget.ImageView)15 View (android.view.View)14 TextView (android.widget.TextView)10 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 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 Picasso (com.squareup.picasso.Picasso)3 RequestCreator (com.squareup.picasso.RequestCreator)3 SimpleDateFormat (java.text.SimpleDateFormat)3 SuppressLint (android.annotation.SuppressLint)2