use of com.scwang.smartrefresh.util.DensityUtil in project CollapsingRefresh by ckrgithub.
the class ClassicsHeader method initView.
private void initView(Context context, AttributeSet attrs) {
DensityUtil density = new DensityUtil();
setMinimumHeight(density.dip2px(80));
LinearLayout layout = new LinearLayout(context);
layout.setId(android.R.id.widget_frame);
layout.setGravity(Gravity.CENTER_HORIZONTAL);
layout.setOrientation(LinearLayout.VERTICAL);
mHeaderText = new TextView(context);
mHeaderText.setText(REFRESH_HEADER_PULLDOWN);
mHeaderText.setTextColor(0xff666666);
mHeaderText.setTextSize(16);
mLastUpdateText = new TextView(context);
mLastUpdateText.setTextColor(0xff7c7c7c);
mLastUpdateText.setTextSize(12);
LinearLayout.LayoutParams lpHeaderText = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
layout.addView(mHeaderText, lpHeaderText);
LinearLayout.LayoutParams lpUpdateText = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
layout.addView(mLastUpdateText, lpUpdateText);
LayoutParams lpHeaderLayout = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
lpHeaderLayout.addRule(CENTER_IN_PARENT);
addView(layout, lpHeaderLayout);
mProgressView = new ImageView(context);
mProgressView.animate().setInterpolator(new LinearInterpolator());
LayoutParams lpProgress = new LayoutParams(density.dip2px(20), density.dip2px(20));
lpProgress.rightMargin = density.dip2px(20);
lpProgress.addRule(CENTER_VERTICAL);
lpProgress.addRule(LEFT_OF, android.R.id.widget_frame);
addView(mProgressView, lpProgress);
mArrowView = new ImageView(context);
addView(mArrowView, lpProgress);
if (isInEditMode()) {
mArrowView.setVisibility(GONE);
mHeaderText.setText(REFRESH_HEADER_REFRESHING);
} else {
mProgressView.setVisibility(GONE);
}
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ClassicsHeader);
mSpinnerStyle = SpinnerStyle.values()[ta.getInt(R.styleable.ClassicsHeader_srlClassicsSpinnerStyle, mSpinnerStyle.ordinal())];
if (ta.hasValue(R.styleable.ClassicsHeader_srlArrowDrawable)) {
mArrowView.setImageDrawable(ta.getDrawable(R.styleable.ClassicsHeader_srlArrowDrawable));
} else {
mArrowDrawable = new PathsDrawable();
mArrowDrawable.parserColors(0xff666666);
mArrowDrawable.parserPaths("M20,12l-1.41,-1.41L13,16.17V4h-2v12.17l-5.58,-5.59L4,12l8,8 8,-8z");
mArrowView.setImageDrawable(mArrowDrawable);
}
if (ta.hasValue(R.styleable.ClassicsHeader_srlProgressDrawable)) {
mProgressView.setImageDrawable(ta.getDrawable(R.styleable.ClassicsHeader_srlProgressDrawable));
} else {
mProgressDrawable = new ProgressDrawable();
mProgressDrawable.setColor(0xff666666);
mProgressView.setImageDrawable(mProgressDrawable);
}
int primaryColor = ta.getColor(R.styleable.ClassicsHeader_srlPrimaryColor, 0);
int accentColor = ta.getColor(R.styleable.ClassicsHeader_srlAccentColor, 0);
if (primaryColor != 0) {
if (accentColor != 0) {
setPrimaryColors(primaryColor, accentColor);
} else {
setPrimaryColors(primaryColor);
}
} else if (accentColor != 0) {
setPrimaryColors(0, accentColor);
}
ta.recycle();
try {
// try 不能删除-否则会出现兼容性问题
if (context instanceof FragmentActivity) {
FragmentManager manager = ((FragmentActivity) context).getSupportFragmentManager();
if (manager != null) {
List<Fragment> fragments = manager.getFragments();
if (fragments != null && fragments.size() > 0) {
setLastUpdateTime(new Date());
return;
}
}
}
} catch (Throwable e) {
e.printStackTrace();
}
KEY_LAST_UPDATE_TIME += context.getClass().getName();
mShared = context.getSharedPreferences("ClassicsHeader", Context.MODE_PRIVATE);
setLastUpdateTime(new Date(mShared.getLong(KEY_LAST_UPDATE_TIME, System.currentTimeMillis())));
}
use of com.scwang.smartrefresh.util.DensityUtil in project CollapsingRefresh by ckrgithub.
the class SmartRefreshLayout method initView.
private void initView(Context context, AttributeSet attrs) {
setClipToPadding(false);
mScreenHeightPixels = context.getResources().getDisplayMetrics().heightPixels;
mReboundInterpolator = new ViscousFluidInterpolator();
mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);
mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
DensityUtil density = new DensityUtil();
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SmartRefreshLayout);
ViewCompat.setNestedScrollingEnabled(this, ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnableNestedScrolling, false));
mDragRate = ta.getFloat(R.styleable.SmartRefreshLayout_srlDragRate, mDragRate);
mHeaderMaxDragRate = ta.getFloat(R.styleable.SmartRefreshLayout_srlHeaderMaxDragRate, mHeaderMaxDragRate);
mFooterMaxDragRate = ta.getFloat(R.styleable.SmartRefreshLayout_srlFooterMaxDragRate, mFooterMaxDragRate);
mEnableRefresh = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnableRefresh, mEnableRefresh);
mReboundDuration = ta.getInt(R.styleable.SmartRefreshLayout_srlReboundDuration, mReboundDuration);
mEnableLoadmore = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnableLoadmore, mEnableLoadmore);
mHeaderHeight = ta.getDimensionPixelOffset(R.styleable.SmartRefreshLayout_srlHeaderHeight, density.dip2px(100));
mFooterHeight = ta.getDimensionPixelOffset(R.styleable.SmartRefreshLayout_srlFooterHeight, density.dip2px(60));
mDisableContentWhenRefresh = ta.getBoolean(R.styleable.SmartRefreshLayout_srlDisableContentWhenRefresh, mDisableContentWhenRefresh);
mDisableContentWhenLoading = ta.getBoolean(R.styleable.SmartRefreshLayout_srlDisableContentWhenLoading, mDisableContentWhenLoading);
mEnableHeaderTranslationContent = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnableHeaderTranslationContent, mEnableHeaderTranslationContent);
mEnableFooterTranslationContent = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnableFooterTranslationContent, mEnableFooterTranslationContent);
mEnablePreviewInEditMode = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnablePreviewInEditMode, mEnablePreviewInEditMode);
mEnableAutoLoadmore = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnableAutoLoadmore, mEnableAutoLoadmore);
mEnableOverScrollBounce = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnableAutoLoadmore, mEnableOverScrollBounce);
mEnablePureScrollMode = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnablePureScrollMode, mEnablePureScrollMode);
mEnableScrollContentWhenLoaded = ta.getBoolean(R.styleable.SmartRefreshLayout_srlEnableScrollContentWhenLoaded, mEnableScrollContentWhenLoaded);
mFixedHeaderViewId = ta.getResourceId(R.styleable.SmartRefreshLayout_srlFixedHeaderViewId, View.NO_ID);
mFixedFooterViewId = ta.getResourceId(R.styleable.SmartRefreshLayout_srlFixedFooterViewId, View.NO_ID);
mManualLoadmore = ta.hasValue(R.styleable.SmartRefreshLayout_srlEnableLoadmore);
mManualNestedScrolling = ta.hasValue(R.styleable.SmartRefreshLayout_srlEnableNestedScrolling);
mHeaderHeightStatus = ta.hasValue(R.styleable.SmartRefreshLayout_srlHeaderHeight) ? DimensionStatus.XmlLayoutUnNotify : mHeaderHeightStatus;
mFooterHeightStatus = ta.hasValue(R.styleable.SmartRefreshLayout_srlFooterHeight) ? DimensionStatus.XmlLayoutUnNotify : mFooterHeightStatus;
mFooterExtendHeight = (int) Math.max((mFooterHeight * (mHeaderMaxDragRate - 1)), 0);
mHeaderExtendHeight = (int) Math.max((mHeaderHeight * (mHeaderMaxDragRate - 1)), 0);
int accentColor = ta.getColor(R.styleable.SmartRefreshLayout_srlAccentColor, 0);
int primaryColor = ta.getColor(R.styleable.SmartRefreshLayout_srlPrimaryColor, 0);
if (primaryColor != 0) {
if (accentColor != 0) {
mPrimaryColors = new int[] { primaryColor, accentColor };
} else {
mPrimaryColors = new int[] { primaryColor };
}
}
ta.recycle();
}
use of com.scwang.smartrefresh.util.DensityUtil in project CollapsingRefresh by ckrgithub.
the class ClassicsFooter method initView.
private void initView(Context context, AttributeSet attrs, int defStyleAttr) {
DensityUtil density = new DensityUtil();
setMinimumHeight(density.dip2px(60));
mBottomText = new TextView(context);
mBottomText.setId(android.R.id.widget_frame);
mBottomText.setTextColor(0xff666666);
mBottomText.setTextSize(16);
mBottomText.setText(REFRESH_FOOTER_PULLUP);
LayoutParams lpBottomText = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
lpBottomText.addRule(CENTER_IN_PARENT);
addView(mBottomText, lpBottomText);
mProgressView = new ImageView(context);
mProgressView.animate().setInterpolator(new LinearInterpolator());
LayoutParams lpPathView = new LayoutParams(density.dip2px(18), density.dip2px(18));
lpPathView.rightMargin = density.dip2px(20);
lpPathView.addRule(CENTER_VERTICAL);
lpPathView.addRule(LEFT_OF, android.R.id.widget_frame);
addView(mProgressView, lpPathView);
mArrowView = new ImageView(context);
addView(mArrowView, lpPathView);
if (!isInEditMode()) {
mProgressView.setVisibility(GONE);
} else {
mArrowView.setVisibility(GONE);
}
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ClassicsFooter);
mSpinnerStyle = SpinnerStyle.values()[ta.getInt(R.styleable.ClassicsFooter_srlClassicsSpinnerStyle, mSpinnerStyle.ordinal())];
if (ta.hasValue(R.styleable.ClassicsFooter_srlArrowDrawable)) {
mArrowView.setImageDrawable(ta.getDrawable(R.styleable.ClassicsFooter_srlArrowDrawable));
} else {
mArrowDrawable = new PathsDrawable();
mArrowDrawable.parserColors(0xff666666);
mArrowDrawable.parserPaths("M20,12l-1.41,-1.41L13,16.17V4h-2v12.17l-5.58,-5.59L4,12l8,8 8,-8z");
mArrowView.setImageDrawable(mArrowDrawable);
}
if (ta.hasValue(R.styleable.ClassicsFooter_srlProgressDrawable)) {
mProgressView.setImageDrawable(ta.getDrawable(R.styleable.ClassicsFooter_srlProgressDrawable));
} else {
mProgressDrawable = new ProgressDrawable();
mProgressDrawable.setColor(0xff666666);
mProgressView.setImageDrawable(mProgressDrawable);
}
if (ta.hasValue(R.styleable.ClassicsFooter_srlPrimaryColor)) {
setPrimaryColor(ta.getColor(R.styleable.ClassicsFooter_srlPrimaryColor, 0));
}
if (ta.hasValue(R.styleable.ClassicsFooter_srlAccentColor)) {
setAccentColor(ta.getColor(R.styleable.ClassicsFooter_srlAccentColor, 0));
}
ta.recycle();
}
Aggregations