Search in sources :

Example 56 with ColorDrawable

use of android.graphics.drawable.ColorDrawable in project android-Ultra-Pull-To-Refresh by liaohuqiu.

the class MaterialStyleFragment method createView.

@Override
protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_materail_style, null);
    setHeaderTitle(R.string.ptr_demo_material_style);
    final CubeImageView imageView = (CubeImageView) view.findViewById(R.id.material_style_image_view);
    final ImageLoader imageLoader = ImageLoaderFactory.create(getContext());
    mPtrFrameLayout = (PtrFrameLayout) view.findViewById(R.id.material_style_ptr_frame);
    // header
    final MaterialHeader header = new MaterialHeader(getContext());
    int[] colors = getResources().getIntArray(R.array.google_colors);
    header.setColorSchemeColors(colors);
    header.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2));
    header.setPadding(0, LocalDisplay.dp2px(15), 0, LocalDisplay.dp2px(10));
    header.setPtrFrameLayout(mPtrFrameLayout);
    mPtrFrameLayout.setLoadingMinTime(1000);
    mPtrFrameLayout.setDurationToCloseHeader(1500);
    mPtrFrameLayout.setHeaderView(header);
    mPtrFrameLayout.addPtrUIHandler(header);
    mPtrFrameLayout.postDelayed(new Runnable() {

        @Override
        public void run() {
            mPtrFrameLayout.autoRefresh(false);
        }
    }, 100);
    mPtrFrameLayout.setPtrHandler(new PtrHandler() {

        @Override
        public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
            return true;
        }

        @Override
        public void onRefreshBegin(final PtrFrameLayout frame) {
            if (mImageHasLoaded) {
                long delay = (long) (1000 + Math.random() * 2000);
                delay = Math.max(0, delay);
                delay = 0;
                frame.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        frame.refreshComplete();
                    }
                }, delay);
            } else {
                mStartLoadingTime = System.currentTimeMillis();
                imageView.loadImage(imageLoader, mUrl);
            }
        }
    });
    ImageLoadHandler imageLoadHandler = new ImageLoadHandler() {

        @Override
        public void onLoading(ImageTask imageTask, CubeImageView cubeImageView) {
        }

        @Override
        public void onLoadFinish(ImageTask imageTask, final CubeImageView cubeImageView, final BitmapDrawable bitmapDrawable) {
            mImageHasLoaded = true;
            long delay = Math.max(0, 1000 - (System.currentTimeMillis() - mStartLoadingTime));
            delay = 0;
            mPtrFrameLayout.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (cubeImageView != null && bitmapDrawable != null) {
                        TransitionDrawable w1 = new TransitionDrawable(new Drawable[] { new ColorDrawable(Color.WHITE), (Drawable) bitmapDrawable });
                        imageView.setImageDrawable(w1);
                        w1.startTransition(200);
                    }
                    mPtrFrameLayout.refreshComplete();
                }
            }, delay);
        }

        @Override
        public void onLoadError(ImageTask imageTask, CubeImageView cubeImageView, int i) {
        }
    };
    imageLoader.setImageLoadHandler(imageLoadHandler);
    return view;
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) PtrHandler(in.srain.cube.views.ptr.PtrHandler) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ImageLoadHandler(in.srain.cube.image.iface.ImageLoadHandler) BitmapDrawable(android.graphics.drawable.BitmapDrawable) CubeImageView(in.srain.cube.image.CubeImageView) View(android.view.View) MaterialHeader(in.srain.cube.views.ptr.header.MaterialHeader) ColorDrawable(android.graphics.drawable.ColorDrawable) CubeImageView(in.srain.cube.image.CubeImageView) ImageTask(in.srain.cube.image.ImageTask) ImageLoader(in.srain.cube.image.ImageLoader)

Example 57 with ColorDrawable

use of android.graphics.drawable.ColorDrawable in project cube-sdk by liaohuqiu.

the class DefaultImageLoadHandler method setLoadingImageColor.

/**
     * set the placeholder by color
     *
     * @param color
     */
public void setLoadingImageColor(int color) {
    mLoadingColor = color;
    mLoadingDrawable = new ColorDrawable(color);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable)

Example 58 with ColorDrawable

use of android.graphics.drawable.ColorDrawable in project cube-sdk by liaohuqiu.

the class DefaultImageLoadHandler method onLoadFinish.

@Override
public void onLoadFinish(ImageTask imageTask, CubeImageView imageView, BitmapDrawable drawable) {
    if (imageView == null) {
        return;
    }
    Drawable d = drawable;
    if (drawable != null) {
        if (mResizeImageViewAfterLoad) {
            int w = drawable.getBitmap().getWidth();
            int h = drawable.getBitmap().getHeight();
            if (w > 0 && h > 0) {
                ViewGroup.LayoutParams lyp = imageView.getLayoutParams();
                if (lyp != null) {
                    lyp.width = w;
                    lyp.height = h;
                    imageView.setLayoutParams(lyp);
                }
            }
        }
        // RoundedDrawable will not recycle automatically when API level is lower than 11
        if ((mDisplayTag & DISPLAY_ROUNDED) == DISPLAY_ROUNDED && Version.hasHoneycomb()) {
            d = new RoundedDrawable(drawable.getBitmap(), mCornerRadius);
        }
        if ((mDisplayTag & DISPLAY_FADE_IN) == DISPLAY_FADE_IN) {
            int loadingColor = android.R.color.transparent;
            if (mLoadingColor != -1 && (mDisplayTag & DISPLAY_ROUNDED) != DISPLAY_ROUNDED) {
                loadingColor = mLoadingColor;
            }
            final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(loadingColor), d });
            imageView.setImageDrawable(td);
            td.startTransition(200);
        } else {
            if (DEBUG) {
                Drawable oldDrawable = imageView.getDrawable();
                int w = 0, h = 0;
                if (oldDrawable != null) {
                    w = oldDrawable.getIntrinsicWidth();
                    h = oldDrawable.getIntrinsicHeight();
                }
                CLog.d(LOG_TAG, MSG_LOAD_FINISH, imageTask, imageView, w, h, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
            }
            imageView.setImageDrawable(drawable);
        }
    }
}
Also used : RoundedDrawable(in.srain.cube.image.drawable.RoundedDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) ViewGroup(android.view.ViewGroup) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) RoundedDrawable(in.srain.cube.image.drawable.RoundedDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable)

Example 59 with ColorDrawable

use of android.graphics.drawable.ColorDrawable in project PagerSlidingTabStrip by astuetz.

the class MainActivity method changeColor.

private void changeColor(int newColor) {
    tabs.setIndicatorColor(newColor);
    // change ActionBar color just if an ActionBar is available
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        Drawable colorDrawable = new ColorDrawable(newColor);
        Drawable bottomDrawable = getResources().getDrawable(R.drawable.actionbar_bottom);
        LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });
        if (oldBackground == null) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
                ld.setCallback(drawableCallback);
            } else {
                getActionBar().setBackgroundDrawable(ld);
            }
        } else {
            TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
            // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
                td.setCallback(drawableCallback);
            } else {
                getActionBar().setBackgroundDrawable(td);
            }
            td.startTransition(200);
        }
        oldBackground = ld;
        // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler
        getActionBar().setDisplayShowTitleEnabled(false);
        getActionBar().setDisplayShowTitleEnabled(true);
    }
    currentColor = newColor;
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable)

Example 60 with ColorDrawable

use of android.graphics.drawable.ColorDrawable in project MagicIndicator by hackware1993.

the class BadgeTabExampleActivity method initMagicIndicator4.

private void initMagicIndicator4() {
    MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator4);
    CommonNavigator commonNavigator = new CommonNavigator(this);
    commonNavigator.setAdapter(new CommonNavigatorAdapter() {

        @Override
        public int getCount() {
            return mDataList.size();
        }

        @Override
        public IPagerTitleView getTitleView(Context context, final int index) {
            BadgePagerTitleView badgePagerTitleView = new BadgePagerTitleView(context);
            SimplePagerTitleView simplePagerTitleView = new ColorTransitionPagerTitleView(context);
            simplePagerTitleView.setNormalColor(Color.GRAY);
            simplePagerTitleView.setSelectedColor(Color.WHITE);
            simplePagerTitleView.setText(mDataList.get(index));
            simplePagerTitleView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mViewPager.setCurrentItem(index);
                }
            });
            badgePagerTitleView.setInnerPagerTitleView(simplePagerTitleView);
            return badgePagerTitleView;
        }

        @Override
        public IPagerIndicator getIndicator(Context context) {
            LinePagerIndicator linePagerIndicator = new LinePagerIndicator(context);
            linePagerIndicator.setColors(Color.WHITE);
            return linePagerIndicator;
        }
    });
    magicIndicator.setNavigator(commonNavigator);
    // must after setNavigator
    LinearLayout titleContainer = commonNavigator.getTitleContainer();
    titleContainer.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
    titleContainer.setDividerDrawable(new ColorDrawable() {

        @Override
        public int getIntrinsicWidth() {
            return UIUtil.dip2px(BadgeTabExampleActivity.this, 15);
        }
    });
    ViewPagerHelper.bind(magicIndicator, mViewPager);
}
Also used : Context(android.content.Context) CommonNavigator(net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator) IPagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator) MagicIndicator(net.lucode.hackware.magicindicator.MagicIndicator) SimplePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView) ColorTransitionPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView) ScaleTransitionPagerTitleView(net.lucode.hackware.magicindicatordemo.ext.titles.ScaleTransitionPagerTitleView) SimplePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView) ImageView(android.widget.ImageView) ClipPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView) View(android.view.View) BadgePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.badge.BadgePagerTitleView) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) ColorTransitionPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView) TextView(android.widget.TextView) BadgePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.badge.BadgePagerTitleView) CommonNavigatorAdapter(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter) ColorDrawable(android.graphics.drawable.ColorDrawable) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) LinePagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator) LinearLayout(android.widget.LinearLayout)

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