Search in sources :

Example 71 with ColorDrawable

use of android.graphics.drawable.ColorDrawable 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 72 with ColorDrawable

use of android.graphics.drawable.ColorDrawable in project Hummingbird-for-Android by xiprox.

the class FullscreenImageActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    int black = Color.parseColor("#000000");
    getWindow().setBackgroundDrawable(new ColorDrawable(black));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
        Transition sharedElem = TransitionInflater.from(this).inflateTransition(R.transition.move_transition);
        getWindow().setSharedElementEnterTransition(sharedElem);
        getWindow().setSharedElementExitTransition(sharedElem);
        getWindow().setStatusBarColor(black);
    }
    super.onCreate(savedInstanceState);
    ImageView mImageView = new ImageView(this);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        mImageView.setTransitionName(TRANSITION_NAME_IMAGE);
    setContentView(mImageView);
    Bundle bundle = getIntent().getExtras();
    if (bundle != null && bundle.getString(ARG_IMAGE_URL) != null)
        mImageUrl = bundle.getString(ARG_IMAGE_URL);
    if (mImageUrl != null) {
        Picasso.with(this).load(mImageUrl).into(mImageView);
    } else {
        Toast.makeText(this, R.string.error_cant_load_image, Toast.LENGTH_SHORT).show();
        finish();
    }
    new PhotoViewAttacher(mImageView);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) Bundle(android.os.Bundle) Transition(android.transition.Transition) ImageView(android.widget.ImageView) PhotoViewAttacher(uk.co.senab.photoview.PhotoViewAttacher)

Example 73 with ColorDrawable

use of android.graphics.drawable.ColorDrawable in project PhotoNoter by yydcdut.

the class EditCategoryActivity method initListView.

private void initListView() {
    Menu menu = new Menu(true, true);
    menu.addItem(new MenuItem.Builder().setWidth((int) getResources().getDimension(R.dimen.slv_item_bg_width) * 3 / 2).setBackground(new ColorDrawable(getResources().getColor(R.color.red_colorPrimary))).setText(getResources().getString(R.string.delete)).setTextColor(Color.WHITE).setTextSize((int) getResources().getDimension(R.dimen.txt_small) / 2).build());
    menu.addItem(new MenuItem.Builder().setWidth((int) getResources().getDimension(R.dimen.slv_item_bg_width) * 3 / 2).setBackground(new ColorDrawable(getResources().getColor(R.color.fab_blue))).setText(getResources().getString(R.string.rename)).setDirection(MenuItem.DIRECTION_RIGHT).setTextColor(Color.WHITE).setTextSize((int) getResources().getDimension(R.dimen.txt_small) / 2).build());
    mListView.setMenu(menu);
    mListView.setAdapter(mCategoryAdapter);
    mListView.setOnSlideListener(this);
    mListView.setOnMenuItemClickListener(this);
    mListView.setOnItemDeleteListener(this);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) MenuItem(com.yydcdut.sdlv.MenuItem) Menu(com.yydcdut.sdlv.Menu)

Example 74 with ColorDrawable

use of android.graphics.drawable.ColorDrawable in project PhotoNoter by yydcdut.

the class FloatingActionButton method createInnerStrokesDrawable.

/**
     * 创建内层drawable
     *
     * @param color
     * @param strokeWidth
     * @return
     */
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
    //不描边的话直接返回一个颜色为透明的drawable
    if (!mStrokeVisible) {
        return new ColorDrawable(Color.TRANSPARENT);
    }
    //圆 drawable
    ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
    //这个暗颜色
    final int bottomStrokeColor = darkenColor(color);
    //比bottomStrokeColor透明一半
    final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);
    //这个亮颜色
    final int topStrokeColor = lightenColor(color);
    //比topStrokeColor透明一半
    final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);
    final Paint paint = shapeDrawable.getPaint();
    //锯齿
    paint.setAntiAlias(true);
    //描边宽度
    paint.setStrokeWidth(strokeWidth);
    //描边
    paint.setStyle(Style.STROKE);
    //draws a linear gradient
    shapeDrawable.setShaderFactory(new ShaderFactory() {

        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(width / 2, 0, width / 2, height, new int[] { topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor }, new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f }, TileMode.CLAMP);
        }
    });
    return shapeDrawable;
}
Also used : LinearGradient(android.graphics.LinearGradient) ShaderFactory(android.graphics.drawable.ShapeDrawable.ShaderFactory) ColorDrawable(android.graphics.drawable.ColorDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) Paint(android.graphics.Paint) OvalShape(android.graphics.drawable.shapes.OvalShape) Shader(android.graphics.Shader) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 75 with ColorDrawable

use of android.graphics.drawable.ColorDrawable 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)

Aggregations

ColorDrawable (android.graphics.drawable.ColorDrawable)530 View (android.view.View)113 Drawable (android.graphics.drawable.Drawable)103 BitmapDrawable (android.graphics.drawable.BitmapDrawable)69 ImageView (android.widget.ImageView)62 TextView (android.widget.TextView)55 Bitmap (android.graphics.Bitmap)52 AdapterView (android.widget.AdapterView)32 LinearLayout (android.widget.LinearLayout)32 Test (org.junit.Test)31 Canvas (android.graphics.Canvas)30 ListView (android.widget.ListView)27 FrameLayout (android.widget.FrameLayout)23 ViewGroup (android.view.ViewGroup)22 Handler (android.os.Handler)20 Paint (android.graphics.Paint)19 StateListDrawable (android.graphics.drawable.StateListDrawable)19 TransitionDrawable (android.graphics.drawable.TransitionDrawable)19 WindowManager (android.view.WindowManager)17 Intent (android.content.Intent)16