Search in sources :

Example 61 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable 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 62 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project WordPress-Android by wordpress-mobile.

the class AztecEditorFragment method appendMediaFile.

@Override
public void appendMediaFile(final MediaFile mediaFile, final String mediaUrl, ImageLoader imageLoader) {
    final String safeMediaUrl = Utils.escapeQuotes(mediaUrl);
    if (URLUtil.isNetworkUrl(mediaUrl)) {
        if (mediaFile.isVideo()) {
            // TODO: insert video
            ToastUtils.showToast(getActivity(), R.string.media_insert_unimplemented);
        } else {
            // TODO: insert image
            ToastUtils.showToast(getActivity(), R.string.media_insert_unimplemented);
        }
        mActionStartedAt = System.currentTimeMillis();
    } else {
        String localMediaId = String.valueOf(mediaFile.getId());
        if (mediaFile.isVideo()) {
            // TODO: insert local video
            ToastUtils.showToast(getActivity(), R.string.media_insert_unimplemented);
        } else {
            AttributesImpl attrs = new AttributesImpl();
            attrs.addAttribute("", "data-wpid", "data-wpid", "string", localMediaId);
            attrs.addAttribute("", "src", "src", "string", safeMediaUrl);
            // load a scaled version of the image to prevent OOM exception
            int maxWidth = DisplayUtils.getDisplayPixelWidth(getActivity());
            Bitmap bitmapToShow = ImageUtils.getWPImageSpanThumbnailFromFilePath(getActivity(), safeMediaUrl, maxWidth);
            if (bitmapToShow != null) {
                content.insertMedia(new BitmapDrawable(getResources(), bitmapToShow), attrs);
            } else {
                // Use a placeholder
                ToastUtils.showToast(getActivity(), R.string.error_media_load);
                Drawable d = getResources().getDrawable(R.drawable.ic_gridicons_image);
                d.setBounds(0, 0, maxWidth, maxWidth);
                content.insertMedia(d, attrs);
            }
            // set intermediate shade overlay
            content.setOverlay(ImagePredicate.localMediaIdPredicate(localMediaId), 0, new ColorDrawable(getResources().getColor(R.color.media_shade_overlay_color)), Gravity.FILL, attrs);
            Drawable progressDrawable = getResources().getDrawable(android.R.drawable.progress_horizontal);
            // set the height of the progress bar to 2 (it's in dp since the drawable will be adjusted by the span)
            progressDrawable.setBounds(0, 0, 0, 4);
            content.setOverlay(ImagePredicate.localMediaIdPredicate(localMediaId), 1, progressDrawable, Gravity.FILL_HORIZONTAL | Gravity.TOP, attrs);
            content.refreshText();
            mUploadingMedia.put(localMediaId, MediaType.IMAGE);
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) AttributesImpl(org.ccil.cowan.tagsoup.AttributesImpl) ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 63 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project xUtils by wyouflf.

the class BitmapFragment method fadeInDisplay.

private void fadeInDisplay(ImageView imageView, Bitmap bitmap) {
    final TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { TRANSPARENT_DRAWABLE, new BitmapDrawable(imageView.getResources(), bitmap) });
    imageView.setImageDrawable(transitionDrawable);
    transitionDrawable.startTransition(500);
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 64 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project XobotOS by xamarin.

the class WaveView method createDrawable.

BitmapDrawable createDrawable(int resId) {
    Resources res = getResources();
    Bitmap bitmap = BitmapFactory.decodeResource(res, resId);
    return new BitmapDrawable(res, bitmap);
}
Also used : Bitmap(android.graphics.Bitmap) Resources(android.content.res.Resources) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 65 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project Transitions-Everywhere by andkulikov.

the class Crossfade method createAnimator.

@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null || endValues == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        return null;
    }
    if (sRectEvaluator == null) {
        sRectEvaluator = new RectEvaluator();
    }
    final boolean useParentOverlay = mFadeBehavior != FADE_BEHAVIOR_REVEAL;
    final View view = endValues.view;
    Map<String, Object> startVals = startValues.values;
    Map<String, Object> endVals = endValues.values;
    Rect startBounds = (Rect) startVals.get(PROPNAME_BOUNDS);
    Rect endBounds = (Rect) endVals.get(PROPNAME_BOUNDS);
    Bitmap startBitmap = (Bitmap) startVals.get(PROPNAME_BITMAP);
    Bitmap endBitmap = (Bitmap) endVals.get(PROPNAME_BITMAP);
    final BitmapDrawable startDrawable = (BitmapDrawable) startVals.get(PROPNAME_DRAWABLE);
    final BitmapDrawable endDrawable = (BitmapDrawable) endVals.get(PROPNAME_DRAWABLE);
    if (Transition.DBG) {
        Log.d(LOG_TAG, "StartBitmap.sameAs(endBitmap) = " + startBitmap.sameAs(endBitmap) + " for start, end: " + startBitmap + ", " + endBitmap);
    }
    if (startDrawable != null && endDrawable != null && !startBitmap.sameAs(endBitmap)) {
        ViewGroupOverlayUtils.addCrossfadeOverlay(useParentOverlay, view, mFadeBehavior, startDrawable, endDrawable);
        // The transition works by placing the end drawable under the start drawable and
        // gradually fading out the start drawable. So it's not really a cross-fade, but rather
        // a reveal of the end scene over time. Also, animate the bounds of both drawables
        // to mimic the change in the size of the view itself between scenes.
        ObjectAnimator anim;
        if (mFadeBehavior == FADE_BEHAVIOR_OUT_IN) {
            // Fade out completely halfway through the transition
            anim = ObjectAnimator.ofInt(startDrawable, "alpha", 255, 0, 0);
        } else {
            anim = ObjectAnimator.ofInt(startDrawable, "alpha", 0);
        }
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                // TODO: some way to auto-invalidate views based on drawable changes? callbacks?
                view.invalidate(startDrawable.getBounds());
            }
        });
        ObjectAnimator anim1 = null;
        if (mFadeBehavior == FADE_BEHAVIOR_OUT_IN) {
            // start fading in halfway through the transition
            anim1 = ObjectAnimator.ofFloat(view, View.ALPHA, 0, 0, 1);
        } else if (mFadeBehavior == FADE_BEHAVIOR_CROSSFADE) {
            anim1 = ObjectAnimator.ofFloat(view, View.ALPHA, 0, 1);
        }
        if (Transition.DBG) {
            Log.d(LOG_TAG, "Crossfade: created anim " + anim + " for start, end values " + startValues + ", " + endValues);
        }
        anim.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                ViewGroupOverlayUtils.removeCrossfadeOverlay(useParentOverlay, view, mFadeBehavior, startDrawable, endDrawable);
            }
        });
        AnimatorSet set = new AnimatorSet();
        set.playTogether(anim);
        if (anim1 != null) {
            set.playTogether(anim1);
        }
        if (mResizeBehavior == RESIZE_BEHAVIOR_SCALE && !startBounds.equals(endBounds)) {
            if (Transition.DBG) {
                Log.d(LOG_TAG, "animating from startBounds to endBounds: " + startBounds + ", " + endBounds);
            }
            Animator anim2 = ObjectAnimator.ofObject(startDrawable, "bounds", sRectEvaluator, startBounds, endBounds);
            set.playTogether(anim2);
            if (mResizeBehavior == RESIZE_BEHAVIOR_SCALE) {
                // TODO: How to handle resizing with a CROSSFADE (vs. REVEAL) effect
                // when we are animating the view directly?
                Animator anim3 = ObjectAnimator.ofObject(endDrawable, "bounds", sRectEvaluator, startBounds, endBounds);
                set.playTogether(anim3);
            }
        }
        return set;
    } else {
        return null;
    }
}
Also used : RectEvaluator(com.transitionseverywhere.utils.RectEvaluator) Rect(android.graphics.Rect) ObjectAnimator(android.animation.ObjectAnimator) AnimatorSet(android.animation.AnimatorSet) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ValueAnimator(android.animation.ValueAnimator) SurfaceView(android.view.SurfaceView) TextureView(android.view.TextureView) View(android.view.View) Bitmap(android.graphics.Bitmap) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Aggregations

BitmapDrawable (android.graphics.drawable.BitmapDrawable)640 Bitmap (android.graphics.Bitmap)426 Drawable (android.graphics.drawable.Drawable)187 Canvas (android.graphics.Canvas)182 Paint (android.graphics.Paint)110 Rect (android.graphics.Rect)77 View (android.view.View)77 ImageView (android.widget.ImageView)63 ColorDrawable (android.graphics.drawable.ColorDrawable)59 TextView (android.widget.TextView)51 IOException (java.io.IOException)40 Resources (android.content.res.Resources)35 LayerDrawable (android.graphics.drawable.LayerDrawable)33 AnimationDrawable (android.graphics.drawable.AnimationDrawable)30 File (java.io.File)27 Test (org.junit.Test)24 Matrix (android.graphics.Matrix)23 Intent (android.content.Intent)22 StateListDrawable (android.graphics.drawable.StateListDrawable)22 InputStream (java.io.InputStream)22