From 2f3f48b6f04cf0c039bfd82e7b28088c62c40fc6 Mon Sep 17 00:00:00 2001 From: youth5201314 <1028729086@qq.com> Date: Fri, 24 Feb 2017 20:10:43 +0800 Subject: [PATCH] no message --- Readme.md | 14 +- app/src/main/java/com/youth/xf/App.java | 2 + .../xf/ui/demo/XLoadingViewActivity.java | 3 +- .../xf/ui/demo/XLoadingViewActivity2.java | 2 +- .../main/res/layout/_loading_layout_error.xml | 39 +++++ .../res/layout/activity_xloading_view2.xml | 4 +- xframe/build.gradle | 4 +- .../main/java/com/youth/xframe/XFrame.java | 19 ++- .../youth/xframe/entity/DateDifference.java | 4 +- .../java/com/youth/xframe/router/XRouter.java | 1 + .../youth/xframe/utils/XOutdatedUtils.java | 12 ++ .../youth/xframe/utils/log/XLogConfig.java | 1 + .../com/youth/xframe/widget/XRoundButton.java | 138 ++++++++++++++++++ .../{ => loadingview}/XLoadingView.java | 16 +- .../loadingview/XLoadingViewConfig.java | 50 +++++++ .../main/res/layout/xloading_error_view.xml | 2 +- .../res/layout/xloading_no_network_view.xml | 2 +- xframe/src/main/res/values/attrs.xml | 19 ++- xframe/src/main/res/values/ids.xml | 1 + 19 files changed, 306 insertions(+), 27 deletions(-) create mode 100644 app/src/main/res/layout/_loading_layout_error.xml create mode 100644 xframe/src/main/java/com/youth/xframe/widget/XRoundButton.java rename xframe/src/main/java/com/youth/xframe/widget/{ => loadingview}/XLoadingView.java (92%) create mode 100644 xframe/src/main/java/com/youth/xframe/widget/loadingview/XLoadingViewConfig.java diff --git a/Readme.md b/Readme.md index e349c7a..143a44b 100644 --- a/Readme.md +++ b/Readme.md @@ -22,12 +22,12 @@ - [x] `XLoadingDialog`:简单实现加载等待对话框 - [x] `XPermission`:简化Android动态权限管理的操作 - [x] `XRecyclerViewAdapter`:一个用于RecyclerView Adapter的开发库,包含添加Header,Footer,加载更多,加载失败,加载到底和支持多种布局 -* `XUpdateApp`:检测更新App,后台下载,应用自动安装 -* `XRouter`:组件化路由框架 -* `XCache`:缓存 -* `XCrash`:异常崩溃统一管理 -* `XTabPage`:Tab+Fragment快速实现 -* `XWebView`:WebView UI与常见的功能封装 + + + + + + - [x] `XStatusBar`:实现沉浸式状态栏 - [x] `XSplashView`:闪屏页或者广告页 - [x] `XToast`:简单的吐司使用 @@ -40,7 +40,7 @@ Gradle ```groovy dependencies{ - compile 'com.youth.xframe:xframe:1.0.0' + compile 'com.youth.xframe:xframe:1.0.1' } ``` 或者引用本地lib diff --git a/app/src/main/java/com/youth/xf/App.java b/app/src/main/java/com/youth/xf/App.java index 0839fc6..f55e165 100644 --- a/app/src/main/java/com/youth/xf/App.java +++ b/app/src/main/java/com/youth/xf/App.java @@ -8,5 +8,7 @@ public class App extends XApplication { public void onCreate() { super.onCreate(); XFrame.initXLog(); + XFrame.initXLoadingView() + .setErrorViewResId(R.layout._loading_layout_error); } } diff --git a/app/src/main/java/com/youth/xf/ui/demo/XLoadingViewActivity.java b/app/src/main/java/com/youth/xf/ui/demo/XLoadingViewActivity.java index 577c9c6..f8e058e 100644 --- a/app/src/main/java/com/youth/xf/ui/demo/XLoadingViewActivity.java +++ b/app/src/main/java/com/youth/xf/ui/demo/XLoadingViewActivity.java @@ -5,11 +5,10 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.widget.Toast; import com.youth.xf.BaseActivity; import com.youth.xf.R; -import com.youth.xframe.widget.XLoadingView; +import com.youth.xframe.widget.loadingview.XLoadingView; import com.youth.xframe.widget.XToast; public class XLoadingViewActivity extends BaseActivity { diff --git a/app/src/main/java/com/youth/xf/ui/demo/XLoadingViewActivity2.java b/app/src/main/java/com/youth/xf/ui/demo/XLoadingViewActivity2.java index 848eea5..8745233 100644 --- a/app/src/main/java/com/youth/xf/ui/demo/XLoadingViewActivity2.java +++ b/app/src/main/java/com/youth/xf/ui/demo/XLoadingViewActivity2.java @@ -7,7 +7,7 @@ import com.youth.xf.BaseActivity; import com.youth.xf.R; -import com.youth.xframe.widget.XLoadingView; +import com.youth.xframe.widget.loadingview.XLoadingView; import com.youth.xframe.widget.XToast; public class XLoadingViewActivity2 extends BaseActivity { diff --git a/app/src/main/res/layout/_loading_layout_error.xml b/app/src/main/res/layout/_loading_layout_error.xml new file mode 100644 index 0000000..6d7656b --- /dev/null +++ b/app/src/main/res/layout/_loading_layout_error.xml @@ -0,0 +1,39 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_xloading_view2.xml b/app/src/main/res/layout/activity_xloading_view2.xml index f32cdc8..8485c6c 100644 --- a/app/src/main/res/layout/activity_xloading_view2.xml +++ b/app/src/main/res/layout/activity_xloading_view2.xml @@ -1,5 +1,5 @@ - @@ -9,4 +9,4 @@ android:gravity="center" android:layout_width="match_parent" android:layout_height="match_parent" /> - + diff --git a/xframe/build.gradle b/xframe/build.gradle index c6f64b5..3c89043 100644 --- a/xframe/build.gradle +++ b/xframe/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.library' apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' -version = "1.0.0" +version = "1.0.1" android { @@ -12,7 +12,7 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 25 - versionCode 1 + versionCode 2 versionName version } buildTypes { diff --git a/xframe/src/main/java/com/youth/xframe/XFrame.java b/xframe/src/main/java/com/youth/xframe/XFrame.java index b70dc39..f3d01e4 100644 --- a/xframe/src/main/java/com/youth/xframe/XFrame.java +++ b/xframe/src/main/java/com/youth/xframe/XFrame.java @@ -7,14 +7,18 @@ import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Build; +import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; import android.util.DisplayMetrics; import android.widget.ImageView; import com.youth.xframe.base.XImageLoader; import com.youth.xframe.utils.XDensityUtils; +import com.youth.xframe.utils.XOutdatedUtils; import com.youth.xframe.utils.log.XLogConfig; import com.youth.xframe.utils.log.XLog; +import com.youth.xframe.widget.loadingview.XLoadingView; +import com.youth.xframe.widget.loadingview.XLoadingViewConfig; public class XFrame { private static Context context; @@ -40,9 +44,14 @@ public static XLogConfig initXLog() { return XLog.init(); } + public static XLoadingViewConfig initXLoadingView() { + return XLoadingView.init(); + } + public static void setImageLoader(XImageLoader imageLoader) { XFrame.imageLoader=imageLoader; } + public static void load(ImageView imageView, Object imageUrl) { if (XFrame.imageLoader==null) throw new NullPointerException("Call XFrame.setImageLoader(XImageLoader imageLoader) within your Application onCreate() method." + @@ -50,6 +59,7 @@ public static void load(ImageView imageView, Object imageUrl) { else XFrame.imageLoader.load(XFrame.context,imageView,imageUrl); } + public static Context getContext() { synchronized (XFrame.class) { if (XFrame.context == null) @@ -72,10 +82,11 @@ public static AssetManager getAssets() { } public static Drawable getDrawable( @DrawableRes int id) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) - return XFrame.getContext().getDrawable(id); - else - return XFrame.getResources().getDrawable(id); + return XOutdatedUtils.getDrawable(id); + } + + public static int getColor( @ColorRes int id) { + return XOutdatedUtils.getColor(id); } public static Object getSystemService(String name){ diff --git a/xframe/src/main/java/com/youth/xframe/entity/DateDifference.java b/xframe/src/main/java/com/youth/xframe/entity/DateDifference.java index df22010..22b2e12 100644 --- a/xframe/src/main/java/com/youth/xframe/entity/DateDifference.java +++ b/xframe/src/main/java/com/youth/xframe/entity/DateDifference.java @@ -1,10 +1,12 @@ package com.youth.xframe.entity; +import com.youth.xframe.common.NotObfuscateInterface; + /** * 时间差计算结果封装类 */ -public class DateDifference { +public class DateDifference implements NotObfuscateInterface{ private long millisecond; private long second; private long minute; diff --git a/xframe/src/main/java/com/youth/xframe/router/XRouter.java b/xframe/src/main/java/com/youth/xframe/router/XRouter.java index fa9be59..0ec5806 100644 --- a/xframe/src/main/java/com/youth/xframe/router/XRouter.java +++ b/xframe/src/main/java/com/youth/xframe/router/XRouter.java @@ -2,6 +2,7 @@ /** * 路由 + * 目的:解耦,模块化开发时组件间通讯或者跳转 */ public class XRouter { diff --git a/xframe/src/main/java/com/youth/xframe/utils/XOutdatedUtils.java b/xframe/src/main/java/com/youth/xframe/utils/XOutdatedUtils.java index 13ff894..a221e72 100644 --- a/xframe/src/main/java/com/youth/xframe/utils/XOutdatedUtils.java +++ b/xframe/src/main/java/com/youth/xframe/utils/XOutdatedUtils.java @@ -3,6 +3,7 @@ import android.content.Context; import android.graphics.drawable.Drawable; import android.os.Build; +import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.view.View; @@ -37,4 +38,15 @@ public static Drawable getDrawable(@DrawableRes int id) { return XFrame.getResources().getDrawable(id); } + /** + * getColor过时方法处理 + * @param id + * @return + */ + public static int getColor(@ColorRes int id) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) + return XFrame.getContext().getColor(id); + else + return XFrame.getResources().getColor(id); + } } diff --git a/xframe/src/main/java/com/youth/xframe/utils/log/XLogConfig.java b/xframe/src/main/java/com/youth/xframe/utils/log/XLogConfig.java index 3a413df..739e901 100644 --- a/xframe/src/main/java/com/youth/xframe/utils/log/XLogConfig.java +++ b/xframe/src/main/java/com/youth/xframe/utils/log/XLogConfig.java @@ -5,6 +5,7 @@ import com.youth.xframe.XFrame; + public class XLogConfig { private boolean showThreadInfo = true; diff --git a/xframe/src/main/java/com/youth/xframe/widget/XRoundButton.java b/xframe/src/main/java/com/youth/xframe/widget/XRoundButton.java new file mode 100644 index 0000000..1521b3e --- /dev/null +++ b/xframe/src/main/java/com/youth/xframe/widget/XRoundButton.java @@ -0,0 +1,138 @@ +package com.youth.xframe.widget; + + +import android.content.Context; +import android.content.res.ColorStateList; +import android.content.res.TypedArray; +import android.graphics.Color; +import android.graphics.Rect; +import android.graphics.RectF; +import android.graphics.drawable.GradientDrawable; +import android.util.AttributeSet; +import android.view.Gravity; +import android.widget.TextView; + +import com.youth.xframe.R; +import com.youth.xframe.utils.XOutdatedUtils; + + +public final class XRoundButton extends TextView { + + public XRoundButton(Context context) { + this(context, null); + } + + public XRoundButton(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public XRoundButton(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.XRoundButton); + + float pressedRatio = a.getFloat(R.styleable.XRoundButton_btnPressedRatio, 0.80f); + int cornerRadius = a.getLayoutDimension(R.styleable.XRoundButton_btnCornerRadius, 0); + + ColorStateList solidColor = a.getColorStateList(R.styleable.XRoundButton_btnSolidColor); + int strokeColor = a.getColor(R.styleable.XRoundButton_btnStrokeColor, 0x0); + int strokeWidth = a.getDimensionPixelSize(R.styleable.XRoundButton_btnStrokeWidth, 0); + int strokeDashWidth = a.getDimensionPixelSize(R.styleable.XRoundButton_btnStrokeDashWidth, 0); + int strokeDashGap = a.getDimensionPixelSize(R.styleable.XRoundButton_btnStrokeDashGap, 0); + + a.recycle(); + + setSingleLine(true); + setGravity(Gravity.CENTER); + + RoundDrawable rd = new RoundDrawable(cornerRadius == -1); + rd.setCornerRadius(cornerRadius == -1 ? 0 : cornerRadius); + rd.setStroke(strokeWidth, strokeColor, strokeDashWidth, strokeDashGap); + + if (solidColor == null) { + solidColor = ColorStateList.valueOf(0); + } + if (solidColor.isStateful()) { + rd.setSolidColors(solidColor); + } else if (pressedRatio > 0.0001f) { + rd.setSolidColors(csl(solidColor.getDefaultColor(), pressedRatio)); + } else { + rd.setColor(solidColor.getDefaultColor()); + } + XOutdatedUtils.setBackground(this,rd); + } + + // 灰度 + int greyer(int color) { + int blue = (color & 0x000000FF) >> 0; + int green = (color & 0x0000FF00) >> 8; + int red = (color & 0x00FF0000) >> 16; + int grey = Math.round(red * 0.299f + green * 0.587f + blue * 0.114f); + return Color.argb(0xff, grey, grey, grey); + } + + // 明度 + int darker(int color, float ratio) { + color = (color >> 24) == 0 ? 0x22808080 : color; + float[] hsv = new float[3]; + Color.colorToHSV(color, hsv); + hsv[2] *= ratio; + return Color.HSVToColor(color >> 24, hsv); + } + + ColorStateList csl(int normal, float ratio) { + // int disabled = greyer(normal); + int pressed = darker(normal, ratio); + int[][] states = new int[][]{{android.R.attr.state_pressed}, {}}; + int[] colors = new int[]{pressed, normal}; + return new ColorStateList(states, colors); + } + + private static class RoundDrawable extends GradientDrawable { + private boolean mIsStadium = false; + + private ColorStateList mSolidColors; + private int mFillColor; + + public RoundDrawable(boolean isStadium) { + mIsStadium = isStadium; + } + + public void setSolidColors(ColorStateList colors) { + mSolidColors = colors; + setColor(colors.getDefaultColor()); + } + + @Override + protected void onBoundsChange(Rect bounds) { + super.onBoundsChange(bounds); + if (mIsStadium) { + RectF rect = new RectF(getBounds()); + setCornerRadius((rect.height() > rect.width() ? rect.width() : rect.height()) / 2); + } + } + + @Override + public void setColor(int argb) { + mFillColor = argb; + super.setColor(argb); + } + + @Override + protected boolean onStateChange(int[] stateSet) { + if (mSolidColors != null) { + final int newColor = mSolidColors.getColorForState(stateSet, 0); + if (mFillColor != newColor) { + setColor(newColor); + return true; + } + } + return false; + } + + @Override + public boolean isStateful() { + return super.isStateful() || (mSolidColors != null && mSolidColors.isStateful()); + } + } +} diff --git a/xframe/src/main/java/com/youth/xframe/widget/XLoadingView.java b/xframe/src/main/java/com/youth/xframe/widget/loadingview/XLoadingView.java similarity index 92% rename from xframe/src/main/java/com/youth/xframe/widget/XLoadingView.java rename to xframe/src/main/java/com/youth/xframe/widget/loadingview/XLoadingView.java index a491fc9..972a3e7 100644 --- a/xframe/src/main/java/com/youth/xframe/widget/XLoadingView.java +++ b/xframe/src/main/java/com/youth/xframe/widget/loadingview/XLoadingView.java @@ -1,4 +1,4 @@ -package com.youth.xframe.widget; +package com.youth.xframe.widget.loadingview; import android.app.Activity; import android.content.Context; @@ -29,6 +29,12 @@ public class XLoadingView extends FrameLayout { private OnClickListener mOnRetryClickListener; private Map mResId = new HashMap<>(); + public static XLoadingViewConfig config=new XLoadingViewConfig(); + + public static XLoadingViewConfig init() { + return config; + } + public static XLoadingView wrap(Activity activity) { return wrap(((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0)); } @@ -68,10 +74,10 @@ public XLoadingView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mInflater = LayoutInflater.from(context); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.XLoadingView, defStyleAttr, 0); - mEmptyViewResId = a.getResourceId(R.styleable.XLoadingView_emptyView, R.layout.xloading_empty_view); - mErrorViewResId = a.getResourceId(R.styleable.XLoadingView_errorView, R.layout.xloading_error_view); - mLoadingViewResId = a.getResourceId(R.styleable.XLoadingView_loadingView, R.layout.xloading_loading_view); - mNoNetworkViewResId = a.getResourceId(R.styleable.XLoadingView_noNetworkView, R.layout.xloading_no_network_view); + mEmptyViewResId = a.getResourceId(R.styleable.XLoadingView_emptyView, config.getEmptyViewResId()); + mErrorViewResId = a.getResourceId(R.styleable.XLoadingView_errorView, config.getErrorViewResId()); + mLoadingViewResId = a.getResourceId(R.styleable.XLoadingView_loadingView, config.getLoadingViewResId()); + mNoNetworkViewResId = a.getResourceId(R.styleable.XLoadingView_noNetworkView, config.getNoNetworkViewResId()); a.recycle(); } diff --git a/xframe/src/main/java/com/youth/xframe/widget/loadingview/XLoadingViewConfig.java b/xframe/src/main/java/com/youth/xframe/widget/loadingview/XLoadingViewConfig.java new file mode 100644 index 0000000..455fad6 --- /dev/null +++ b/xframe/src/main/java/com/youth/xframe/widget/loadingview/XLoadingViewConfig.java @@ -0,0 +1,50 @@ +package com.youth.xframe.widget.loadingview; + + +import android.support.annotation.LayoutRes; + +import com.youth.xframe.R; + +public class XLoadingViewConfig { + + private int emptyViewResId = R.layout.xloading_empty_view; + private int errorViewResId = R.layout.xloading_error_view; + private int loadingViewResId = R.layout.xloading_loading_view; + private int noNetworkViewResId = R.layout.xloading_no_network_view; + + public int getEmptyViewResId() { + return emptyViewResId; + } + + public XLoadingViewConfig setEmptyViewResId(@LayoutRes int emptyViewResId) { + this.emptyViewResId = emptyViewResId; + return this; + } + + public int getErrorViewResId() { + return errorViewResId; + } + + public XLoadingViewConfig setErrorViewResId(@LayoutRes int errorViewResId) { + this.errorViewResId = errorViewResId; + return this; + } + + public int getLoadingViewResId() { + return loadingViewResId; + } + + public XLoadingViewConfig setLoadingViewResId(@LayoutRes int loadingViewResId) { + this.loadingViewResId = loadingViewResId; + return this; + } + + public int getNoNetworkViewResId() { + return noNetworkViewResId; + } + + public XLoadingViewConfig setNoNetworkViewResId(@LayoutRes int noNetworkViewResId) { + this.noNetworkViewResId = noNetworkViewResId; + return this; + } +} diff --git a/xframe/src/main/res/layout/xloading_error_view.xml b/xframe/src/main/res/layout/xloading_error_view.xml index d5312cb..f518406 100644 --- a/xframe/src/main/res/layout/xloading_error_view.xml +++ b/xframe/src/main/res/layout/xloading_error_view.xml @@ -16,7 +16,7 @@ android:textColor="@color/XFrame_text_gray" android:textSize="@dimen/XFrame_text_size" /> - + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xframe/src/main/res/values/ids.xml b/xframe/src/main/res/values/ids.xml index b2fedd3..8e6948e 100644 --- a/xframe/src/main/res/values/ids.xml +++ b/xframe/src/main/res/values/ids.xml @@ -2,4 +2,5 @@ +