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;
}
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);
}
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);
}
}
}
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;
}
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);
}
Aggregations