diff --git a/ProjectDetails.md b/ProjectDetails.md index 135234ec..4059e189 100644 --- a/ProjectDetails.md +++ b/ProjectDetails.md @@ -6,7 +6,11 @@ * app:关于 APP 功能实现的业务逻辑代码,集成了一些常用的框架 -* baselibrary:只存放关于技术实现的代码,不集成任何框架 +* base:只存放关于技术实现的代码,不集成任何框架 + +* widget:自定义一些精品的 View + +* umeng:集成友盟 SDK 相关文件 > 本项目基于最新的 Android SDK 28 编译,[点击此处查看配置](build.gradle),最低安装要求为 Android 4.0 diff --git a/app/build.gradle b/app/build.gradle index 061cfc95..f19a1ede 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -84,7 +84,12 @@ dependencies { // 依赖 libs 目录下所有 Jar 包 implementation fileTree(include: ['*.jar'], dir: 'libs') // 基础库(不包任何第三方框架) - implementation project(':baselibrary') + implementation project(':base') + // 自定义 View + implementation project(':widget') + // 友盟 + implementation project(':umeng') + // 示例:添加一个 aar 包 // implementation(name: 'password_dialog', ext: 'aar') @@ -115,9 +120,6 @@ dependencies { // ButterKnife注解库:https://github.com/JakeWharton/butterknife implementation "com.jakewharton:butterknife:$rootProject.ext.butterknifeVersion" annotationProcessor "com.jakewharton:butterknife-compiler:$rootProject.ext.butterknifeVersion" - - // 友盟统计 - compileOnly 'com.umeng.analytics:analytics:6.1.4' } repositories { diff --git a/app/libs/umeng-analytics-v6.1.2.jar b/app/libs/umeng-analytics-v6.1.2.jar deleted file mode 100644 index 73588734..00000000 Binary files a/app/libs/umeng-analytics-v6.1.2.jar and /dev/null differ diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index f3cbe042..a52b2bba 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -195,11 +195,6 @@ public void openFileChooser(...); } -#友盟统计 --keepclassmembers class * { - public (org.json.JSONObject); -} - #极光推送 -dontoptimize -dontpreverify @@ -225,3 +220,17 @@ -keep public class android.support.design.R$* { *; } ######################################################## + +#友盟统计 +-keep class com.umeng.** {*;} +-keepclassmembers class * { + public (org.json.JSONObject); +} +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +-keep public class [您的应用包名].R$*{ + public static final int *; +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d195a5a4..2dd3ba9e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,32 +12,17 @@ - - - - - - - - - - - @@ -52,29 +37,29 @@ diff --git a/app/src/main/java/com/hjq/demo/common/CommonActivity.java b/app/src/main/java/com/hjq/demo/base/MyActivity.java similarity index 81% rename from app/src/main/java/com/hjq/demo/common/CommonActivity.java rename to app/src/main/java/com/hjq/demo/base/MyActivity.java index 1be7bbde..c1d57fdc 100644 --- a/app/src/main/java/com/hjq/demo/common/CommonActivity.java +++ b/app/src/main/java/com/hjq/demo/base/MyActivity.java @@ -1,133 +1,129 @@ -package com.hjq.demo.common; - -import android.content.pm.ActivityInfo; -import android.view.View; - -import com.hjq.bar.OnTitleBarListener; -import com.hjq.bar.TitleBar; -import com.hjq.toast.ToastUtils; -import com.umeng.analytics.MobclickAgent; - -import butterknife.ButterKnife; -import butterknife.Unbinder; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 项目中的Activity基类 - */ -public abstract class CommonActivity extends UIActivity - implements OnTitleBarListener { - - private Unbinder mButterKnife;//View注解 - - @Override - public void init() { - - //初始化标题栏的监听 - if (getTitleBarId() > 0) { - if (findViewById(getTitleBarId()) instanceof TitleBar) { - ((TitleBar) findViewById(getTitleBarId())).setOnTitleBarListener(this); - } - } - - mButterKnife = ButterKnife.bind(this); - - initOrientation(); - - super.init(); - } - - /** - * 初始化横竖屏方向,会和 LauncherTheme 主题样式有冲突,注意不要同时使用 - */ - protected void initOrientation() { - //如果没有指定屏幕方向,则默认为竖屏 - if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); - } - } - - /** - * 设置标题栏的标题 - */ - @Override - public void setTitle(int titleId) { - setTitle(getText(titleId)); - } - - /** - * 设置标题栏的标题 - */ - @Override - public void setTitle(CharSequence title) { - super.setTitle(title); - TitleBar titleBar = getTitleBar(); - if (titleBar != null) { - titleBar.setTitle(title); - } - } - - protected TitleBar getTitleBar() { - if (getTitleBarId() > 0 && findViewById(getTitleBarId()) instanceof TitleBar) { - return findViewById(getTitleBarId()); - } - return null; - } - - @Override - public boolean statusBarDarkFont() { - //返回true表示黑色字体 - return true; - } - - /** - * {@link OnTitleBarListener} - */ - - // 标题栏左边的View被点击了 - @Override - public void onLeftClick(View v) { - onBackPressed(); - } - - // 标题栏中间的View被点击了 - @Override - public void onTitleClick(View v) {} - - // 标题栏右边的View被点击了 - @Override - public void onRightClick(View v) {} - - @Override - protected void onResume() { - super.onResume(); - // 手动统计页面 - MobclickAgent.onPageStart(getClass().getSimpleName()); - // 友盟统计 - MobclickAgent.onResume(this); - } - - @Override - protected void onPause() { - super.onPause(); - // 手动统计页面,必须保证 onPageEnd 在 onPause 之前调用,因为SDK会在 onPause 中保存onPageEnd统计到的页面数据 - MobclickAgent.onPageEnd(getClass().getSimpleName()); - // 友盟统计 - MobclickAgent.onPause(this); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (mButterKnife != null) mButterKnife.unbind(); - } - - /** - * 显示一个吐司 - */ - public void toast(CharSequence s) { - ToastUtils.show(s); - } +package com.hjq.demo.base; + +import android.content.pm.ActivityInfo; +import android.view.View; + +import com.hjq.bar.OnTitleBarListener; +import com.hjq.bar.TitleBar; +import com.hjq.toast.ToastUtils; +import com.hjq.umeng.UmengHelper; + +import butterknife.ButterKnife; +import butterknife.Unbinder; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 项目中的Activity基类 + */ +public abstract class MyActivity extends UIActivity + implements OnTitleBarListener { + + private Unbinder mButterKnife;//View注解 + + @Override + public void init() { + + //初始化标题栏的监听 + if (getTitleBarId() > 0) { + if (findViewById(getTitleBarId()) instanceof TitleBar) { + ((TitleBar) findViewById(getTitleBarId())).setOnTitleBarListener(this); + } + } + + mButterKnife = ButterKnife.bind(this); + + initOrientation(); + + super.init(); + } + + /** + * 初始化横竖屏方向,会和 LauncherTheme 主题样式有冲突,注意不要同时使用 + */ + protected void initOrientation() { + //如果没有指定屏幕方向,则默认为竖屏 + if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } + } + + /** + * 设置标题栏的标题 + */ + @Override + public void setTitle(int titleId) { + setTitle(getText(titleId)); + } + + /** + * 设置标题栏的标题 + */ + @Override + public void setTitle(CharSequence title) { + super.setTitle(title); + TitleBar titleBar = getTitleBar(); + if (titleBar != null) { + titleBar.setTitle(title); + } + } + + protected TitleBar getTitleBar() { + if (getTitleBarId() > 0 && findViewById(getTitleBarId()) instanceof TitleBar) { + return findViewById(getTitleBarId()); + } + return null; + } + + @Override + public boolean statusBarDarkFont() { + //返回true表示黑色字体 + return true; + } + + /** + * {@link OnTitleBarListener} + */ + + // 标题栏左边的View被点击了 + @Override + public void onLeftClick(View v) { + onBackPressed(); + } + + // 标题栏中间的View被点击了 + @Override + public void onTitleClick(View v) {} + + // 标题栏右边的View被点击了 + @Override + public void onRightClick(View v) {} + + @Override + protected void onResume() { + super.onResume(); + // 友盟统计 + UmengHelper.onResume(this); + } + + @Override + protected void onPause() { + super.onPause(); + // 友盟统计 + UmengHelper.onPause(this); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + if (mButterKnife != null) mButterKnife.unbind(); + } + + /** + * 显示一个吐司 + */ + public void toast(CharSequence s) { + ToastUtils.show(s); + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/common/CommonApplication.java b/app/src/main/java/com/hjq/demo/base/MyApplication.java similarity index 67% rename from app/src/main/java/com/hjq/demo/common/CommonApplication.java rename to app/src/main/java/com/hjq/demo/base/MyApplication.java index 984ca0e6..fff2ce84 100644 --- a/app/src/main/java/com/hjq/demo/common/CommonApplication.java +++ b/app/src/main/java/com/hjq/demo/base/MyApplication.java @@ -1,38 +1,38 @@ -package com.hjq.demo.common; - -import android.content.Context; -import android.support.multidex.MultiDex; - -import com.hjq.baselibrary.utils.ActivityStackManager; -import com.hjq.toast.ToastUtils; -import com.umeng.analytics.MobclickAgent; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 项目中的Application基类 - */ -public class CommonApplication extends UIApplication { - - @Override - public void onCreate() { - super.onCreate(); - - // 初始化吐司工具类 - ToastUtils.init(this); - - // 友盟统计 - MobclickAgent.setScenarioType(getApplicationContext(), MobclickAgent.EScenarioType.E_UM_NORMAL); - - // Activity 栈管理 - ActivityStackManager.init(this); - } - - @Override - protected void attachBaseContext(Context base) { - super.attachBaseContext(base); - // 使用 Dex分包 - MultiDex.install(this); - } +package com.hjq.demo.base; + +import android.content.Context; +import android.support.multidex.MultiDex; + +import com.hjq.demo.utils.ActivityStackManager; +import com.hjq.toast.ToastUtils; +import com.hjq.umeng.UmengHelper; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 项目中的Application基类 + */ +public class MyApplication extends UIApplication { + + @Override + public void onCreate() { + super.onCreate(); + + // 初始化吐司工具类 + ToastUtils.init(this); + + // 友盟统计 + UmengHelper.init(this); + + // Activity 栈管理 + ActivityStackManager.init(this); + } + + @Override + protected void attachBaseContext(Context base) { + super.attachBaseContext(base); + // 使用 Dex分包 + MultiDex.install(this); + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/common/CommonLazyFragment.java b/app/src/main/java/com/hjq/demo/base/MyLazyFragment.java similarity index 80% rename from app/src/main/java/com/hjq/demo/common/CommonLazyFragment.java rename to app/src/main/java/com/hjq/demo/base/MyLazyFragment.java index 95b51fce..c6b56feb 100644 --- a/app/src/main/java/com/hjq/demo/common/CommonLazyFragment.java +++ b/app/src/main/java/com/hjq/demo/base/MyLazyFragment.java @@ -1,58 +1,58 @@ -package com.hjq.demo.common; - -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import com.hjq.toast.ToastUtils; -import com.umeng.analytics.MobclickAgent; - -import butterknife.ButterKnife; -import butterknife.Unbinder; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 项目中Fragment懒加载基类 - */ -public abstract class CommonLazyFragment extends UILazyFragment { - - private Unbinder mButterKnife;// View注解 - - @Override - public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = super.onCreateView(inflater, container, savedInstanceState); - mButterKnife = ButterKnife.bind(this, view); - return view; - } - - @Override - public void onResume() { - super.onResume(); - // 友盟统计 - MobclickAgent.onResume(getContext()); - } - - @Override - public void onPause() { - super.onPause(); - // 友盟统计 - MobclickAgent.onPause(getContext()); - } - - @Override - public void onDestroy() { - super.onDestroy(); - mButterKnife.unbind(); - } - - /** - * 显示一个吐司 - */ - public void toast(CharSequence s) { - ToastUtils.show(s); - } +package com.hjq.demo.base; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.hjq.toast.ToastUtils; +import com.hjq.umeng.UmengHelper; + +import butterknife.ButterKnife; +import butterknife.Unbinder; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 项目中Fragment懒加载基类 + */ +public abstract class MyLazyFragment extends UILazyFragment { + + private Unbinder mButterKnife;// View注解 + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = super.onCreateView(inflater, container, savedInstanceState); + mButterKnife = ButterKnife.bind(this, view); + return view; + } + + @Override + public void onResume() { + super.onResume(); + // 友盟统计 + UmengHelper.onResume(this); + } + + @Override + public void onPause() { + super.onPause(); + // 友盟统计 + UmengHelper.onPause(this); + } + + @Override + public void onDestroy() { + super.onDestroy(); + mButterKnife.unbind(); + } + + /** + * 显示一个吐司 + */ + public void toast(CharSequence s) { + ToastUtils.show(s); + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/common/UIActivity.java b/app/src/main/java/com/hjq/demo/base/UIActivity.java similarity index 95% rename from app/src/main/java/com/hjq/demo/common/UIActivity.java rename to app/src/main/java/com/hjq/demo/base/UIActivity.java index e3f91af7..96826d92 100644 --- a/app/src/main/java/com/hjq/demo/common/UIActivity.java +++ b/app/src/main/java/com/hjq/demo/base/UIActivity.java @@ -1,173 +1,173 @@ -package com.hjq.demo.common; - -import android.os.Build; -import android.os.Bundle; -import android.view.ViewTreeObserver; -import android.view.WindowManager; - -import com.gyf.barlibrary.ImmersionBar; -import com.hjq.baselibrary.base.BaseActivity; -import com.hjq.demo.R; - -import cn.bingoogolapple.swipebacklayout.BGASwipeBackHelper; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 支持沉浸式和侧滑的Activity基类(默认开启沉浸式状态栏和侧滑功能) - */ -public abstract class UIActivity extends BaseActivity - implements BGASwipeBackHelper.Delegate, ViewTreeObserver.OnGlobalLayoutListener { - - private ImmersionBar mImmersionBar;//状态栏沉浸 - private BGASwipeBackHelper mSwipeBackHelper;//侧滑返回 - - @Override - protected void onCreate(Bundle savedInstanceState) { - // 在 super.onCreate(savedInstanceState) 之前调用该方法 - initSwipeBackFinish(); - super.onCreate(savedInstanceState); - } - - @Override - public void init(){ - - //初始化沉浸式状态栏 - if (isStatusBarEnabled()) { - statusBarConfig().init(); - } - - //设置标题栏 - if (getTitleBarId() > 0) { - ImmersionBar.setTitleBar(this, findViewById(getTitleBarId())); - } - super.init(); - } - - public BGASwipeBackHelper getSwipeBackHelper() { - return mSwipeBackHelper; - } - - /** - * 初始化滑动返回。在 super.onCreate(savedInstanceState) 之前调用该方法 - */ - private void initSwipeBackFinish() { - mSwipeBackHelper = new BGASwipeBackHelper(this, this); - - // 「必须在 Application 的 onCreate 方法中执行 BGASwipeBackHelper.init 来初始化滑动返回」 - // 下面几项可以不配置,这里只是为了讲述接口用法。 - - // 设置滑动返回是否可用。默认值为 true - mSwipeBackHelper.setSwipeBackEnable(true); - // 设置是否仅仅跟踪左侧边缘的滑动返回。默认值为 true - mSwipeBackHelper.setIsOnlyTrackingLeftEdge(true); - // 设置是否是微信滑动返回样式。默认值为 true - mSwipeBackHelper.setIsWeChatStyle(true); - // 设置阴影资源 id。默认值为 R.drawable.bga_sbl_shadow - mSwipeBackHelper.setShadowResId(R.drawable.bga_sbl_shadow); - // 设置是否显示滑动返回的阴影效果。默认值为 true - mSwipeBackHelper.setIsNeedShowShadow(true); - // 设置阴影区域的透明度是否根据滑动的距离渐变。默认值为 true - mSwipeBackHelper.setIsShadowAlphaGradient(true); - // 设置触发释放后自动滑动返回的阈值,默认值为 0.3f - mSwipeBackHelper.setSwipeBackThreshold(0.3f); - // 设置底部导航条是否悬浮在内容上,默认值为 false - mSwipeBackHelper.setIsNavigationBarOverlap(false); - } - - /** - * {@link BGASwipeBackHelper.Delegate} - */ - - /** - * 是否支持滑动返回。这里在父类中默认返回 true 来支持滑动返回,如果某个界面不想支持滑动返回则重写该方法返回 false 即可 - */ - @Override - public boolean isSupportSwipeBack() { - return true; - } - - /** - * 正在滑动返回 - * - * @param slideOffset 从 0 到 1 - */ - @Override - public void onSwipeBackLayoutSlide(float slideOffset) {} - - /** - * 没达到滑动返回的阈值,取消滑动返回动作,回到默认状态 - */ - @Override - public void onSwipeBackLayoutCancel() {} - - /** - * 滑动返回执行完毕,销毁当前 Activity - */ - @Override - public void onSwipeBackLayoutExecuted() { - mSwipeBackHelper.swipeBackward(); - } - - @Override - public void onBackPressed() { - // 正在滑动返回的时候取消返回按钮事件 - if (mSwipeBackHelper.isSliding()) { - return; - } - mSwipeBackHelper.backward(); - super.onBackPressed(); - } - - /** - * 是否使用沉浸式状态栏 - */ - public boolean isStatusBarEnabled() { - return true; - } - - /** - * 获取状态栏沉浸的配置对象 - */ - public ImmersionBar getStatusBarConfig() { - return mImmersionBar; - } - - /** - * 初始化沉浸式状态栏 - */ - private ImmersionBar statusBarConfig() { - //在BaseActivity里初始化 - mImmersionBar = ImmersionBar.with(this) - .statusBarDarkFont(statusBarDarkFont()) //默认状态栏字体颜色为黑色 - .keyboardEnable(false, WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN - | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); //解决软键盘与底部输入框冲突问题,默认为false,还有一个重载方法,可以指定软键盘mode - //必须设置View树布局变化监听,否则软键盘无法顶上去,还有模式必须是SOFT_INPUT_ADJUST_PAN - getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(this); - return mImmersionBar; - } - - /** - * {@link ViewTreeObserver.OnGlobalLayoutListener} - */ - @Override - public void onGlobalLayout() {}//不用写任何方法 - - /** - * 获取状态栏字体颜色 - */ - public boolean statusBarDarkFont() { - //返回false表示白色字体 - return true; - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (mImmersionBar != null) mImmersionBar.destroy(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - getWindow().getDecorView().getViewTreeObserver().removeOnGlobalLayoutListener(this); - } - } +package com.hjq.demo.base; + +import android.os.Build; +import android.os.Bundle; +import android.view.ViewTreeObserver; +import android.view.WindowManager; + +import com.gyf.barlibrary.ImmersionBar; +import com.hjq.demo.R; +import com.hjq.base.BaseActivity; + +import cn.bingoogolapple.swipebacklayout.BGASwipeBackHelper; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 支持沉浸式和侧滑的Activity基类(默认开启沉浸式状态栏和侧滑功能) + */ +public abstract class UIActivity extends BaseActivity + implements BGASwipeBackHelper.Delegate, ViewTreeObserver.OnGlobalLayoutListener { + + private ImmersionBar mImmersionBar;//状态栏沉浸 + private BGASwipeBackHelper mSwipeBackHelper;//侧滑返回 + + @Override + protected void onCreate(Bundle savedInstanceState) { + // 在 super.onCreate(savedInstanceState) 之前调用该方法 + initSwipeBackFinish(); + super.onCreate(savedInstanceState); + } + + @Override + public void init(){ + + //初始化沉浸式状态栏 + if (isStatusBarEnabled()) { + statusBarConfig().init(); + } + + //设置标题栏 + if (getTitleBarId() > 0) { + ImmersionBar.setTitleBar(this, findViewById(getTitleBarId())); + } + super.init(); + } + + public BGASwipeBackHelper getSwipeBackHelper() { + return mSwipeBackHelper; + } + + /** + * 初始化滑动返回。在 super.onCreate(savedInstanceState) 之前调用该方法 + */ + private void initSwipeBackFinish() { + mSwipeBackHelper = new BGASwipeBackHelper(this, this); + + // 「必须在 Application 的 onCreate 方法中执行 BGASwipeBackHelper.init 来初始化滑动返回」 + // 下面几项可以不配置,这里只是为了讲述接口用法。 + + // 设置滑动返回是否可用。默认值为 true + mSwipeBackHelper.setSwipeBackEnable(true); + // 设置是否仅仅跟踪左侧边缘的滑动返回。默认值为 true + mSwipeBackHelper.setIsOnlyTrackingLeftEdge(true); + // 设置是否是微信滑动返回样式。默认值为 true + mSwipeBackHelper.setIsWeChatStyle(true); + // 设置阴影资源 id。默认值为 R.drawable.bga_sbl_shadow + mSwipeBackHelper.setShadowResId(R.drawable.bga_sbl_shadow); + // 设置是否显示滑动返回的阴影效果。默认值为 true + mSwipeBackHelper.setIsNeedShowShadow(true); + // 设置阴影区域的透明度是否根据滑动的距离渐变。默认值为 true + mSwipeBackHelper.setIsShadowAlphaGradient(true); + // 设置触发释放后自动滑动返回的阈值,默认值为 0.3f + mSwipeBackHelper.setSwipeBackThreshold(0.3f); + // 设置底部导航条是否悬浮在内容上,默认值为 false + mSwipeBackHelper.setIsNavigationBarOverlap(false); + } + + /** + * {@link BGASwipeBackHelper.Delegate} + */ + + /** + * 是否支持滑动返回。这里在父类中默认返回 true 来支持滑动返回,如果某个界面不想支持滑动返回则重写该方法返回 false 即可 + */ + @Override + public boolean isSupportSwipeBack() { + return true; + } + + /** + * 正在滑动返回 + * + * @param slideOffset 从 0 到 1 + */ + @Override + public void onSwipeBackLayoutSlide(float slideOffset) {} + + /** + * 没达到滑动返回的阈值,取消滑动返回动作,回到默认状态 + */ + @Override + public void onSwipeBackLayoutCancel() {} + + /** + * 滑动返回执行完毕,销毁当前 Activity + */ + @Override + public void onSwipeBackLayoutExecuted() { + mSwipeBackHelper.swipeBackward(); + } + + @Override + public void onBackPressed() { + // 正在滑动返回的时候取消返回按钮事件 + if (mSwipeBackHelper.isSliding()) { + return; + } + mSwipeBackHelper.backward(); + super.onBackPressed(); + } + + /** + * 是否使用沉浸式状态栏 + */ + public boolean isStatusBarEnabled() { + return true; + } + + /** + * 获取状态栏沉浸的配置对象 + */ + public ImmersionBar getStatusBarConfig() { + return mImmersionBar; + } + + /** + * 初始化沉浸式状态栏 + */ + private ImmersionBar statusBarConfig() { + //在BaseActivity里初始化 + mImmersionBar = ImmersionBar.with(this) + .statusBarDarkFont(statusBarDarkFont()) //默认状态栏字体颜色为黑色 + .keyboardEnable(false, WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN + | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); //解决软键盘与底部输入框冲突问题,默认为false,还有一个重载方法,可以指定软键盘mode + //必须设置View树布局变化监听,否则软键盘无法顶上去,还有模式必须是SOFT_INPUT_ADJUST_PAN + getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(this); + return mImmersionBar; + } + + /** + * {@link ViewTreeObserver.OnGlobalLayoutListener} + */ + @Override + public void onGlobalLayout() {}//不用写任何方法 + + /** + * 获取状态栏字体颜色 + */ + public boolean statusBarDarkFont() { + //返回false表示白色字体 + return true; + } + + @Override + protected void onDestroy() { + super.onDestroy(); + if (mImmersionBar != null) mImmersionBar.destroy(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + getWindow().getDecorView().getViewTreeObserver().removeOnGlobalLayoutListener(this); + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/common/UIApplication.java b/app/src/main/java/com/hjq/demo/base/UIApplication.java similarity index 93% rename from app/src/main/java/com/hjq/demo/common/UIApplication.java rename to app/src/main/java/com/hjq/demo/base/UIApplication.java index b3cb6057..39b3e00b 100644 --- a/app/src/main/java/com/hjq/demo/common/UIApplication.java +++ b/app/src/main/java/com/hjq/demo/base/UIApplication.java @@ -1,25 +1,25 @@ -package com.hjq.demo.common; - -import android.app.Application; - -import cn.bingoogolapple.swipebacklayout.BGASwipeBackHelper; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 支持侧滑的Application基类 - */ -public abstract class UIApplication extends Application { - - @Override - public void onCreate() { - super.onCreate(); - /** - * 必须在 Application 的 onCreate 方法中执行 BGASwipeBackHelper.init 来初始化滑动返回 - * 第一个参数:应用程序上下文 - * 第二个参数:如果发现滑动返回后立即触摸界面时应用崩溃,请把该界面里比较特殊的 View 的 class 添加到该集合中,目前在库中已经添加了 WebView 和 SurfaceView - */ - BGASwipeBackHelper.init(this, null); - } -} +package com.hjq.demo.base; + +import android.app.Application; + +import cn.bingoogolapple.swipebacklayout.BGASwipeBackHelper; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 支持侧滑的Application基类 + */ +public abstract class UIApplication extends Application { + + @Override + public void onCreate() { + super.onCreate(); + /** + * 必须在 Application 的 onCreate 方法中执行 BGASwipeBackHelper.init 来初始化滑动返回 + * 第一个参数:应用程序上下文 + * 第二个参数:如果发现滑动返回后立即触摸界面时应用崩溃,请把该界面里比较特殊的 View 的 class 添加到该集合中,目前在库中已经添加了 WebView 和 SurfaceView + */ + BGASwipeBackHelper.init(this, null); + } +} diff --git a/app/src/main/java/com/hjq/demo/common/UILazyFragment.java b/app/src/main/java/com/hjq/demo/base/UILazyFragment.java similarity index 93% rename from app/src/main/java/com/hjq/demo/common/UILazyFragment.java rename to app/src/main/java/com/hjq/demo/base/UILazyFragment.java index b6e1fbc3..00e59145 100644 --- a/app/src/main/java/com/hjq/demo/common/UILazyFragment.java +++ b/app/src/main/java/com/hjq/demo/base/UILazyFragment.java @@ -1,82 +1,82 @@ -package com.hjq.demo.common; - -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.view.View; - -import com.gyf.barlibrary.ImmersionBar; -import com.hjq.baselibrary.base.BaseLazyFragment; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 支持沉浸式Fragment懒加载基类(默认不开启沉浸式) - */ -public abstract class UILazyFragment extends BaseLazyFragment { - - private ImmersionBar mImmersionBar;//状态栏沉浸 - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - //初始化沉浸式状态栏 - if (isFragmentVisible() && isStatusBarEnabled() && isLazyLoad()) { - statusBarConfig().init(); - } - - //设置标题栏 - if (getTitleBarId() > 0) { - ImmersionBar.setTitleBar(mActivity, findViewById(getTitleBarId())); - } - } - - /** - * 是否在Fragment使用沉浸式 - */ - public boolean isStatusBarEnabled() { - return false; - } - - /** - * 获取状态栏沉浸的配置对象 - */ - protected ImmersionBar getStatusBarConfig() { - return mImmersionBar; - } - - /** - * 初始化沉浸式 - */ - private ImmersionBar statusBarConfig() { - //在BaseActivity里初始化 - mImmersionBar = ImmersionBar.with(this) - .statusBarDarkFont(statusBarDarkFont()) //默认状态栏字体颜色为黑色 - .keyboardEnable(true); //解决软键盘与底部输入框冲突问题,默认为false,还有一个重载方法,可以指定软键盘mode - return mImmersionBar; - } - - /** - * 获取状态栏字体颜色 - */ - protected boolean statusBarDarkFont() { - //返回true表示黑色字体 - return true; - } - - @Override - public void onDestroy() { - super.onDestroy(); - if (mImmersionBar != null) mImmersionBar.destroy(); - } - - @Override - public void setUserVisibleHint(boolean isVisibleToUser) { - super.setUserVisibleHint(isVisibleToUser); - if (isVisibleToUser && isStatusBarEnabled() && isLazyLoad()) { - // 重新初始化状态栏 - statusBarConfig().init(); - } - } +package com.hjq.demo.base; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.view.View; + +import com.gyf.barlibrary.ImmersionBar; +import com.hjq.base.BaseLazyFragment; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 支持沉浸式Fragment懒加载基类(默认不开启沉浸式) + */ +public abstract class UILazyFragment extends BaseLazyFragment { + + private ImmersionBar mImmersionBar;//状态栏沉浸 + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + //初始化沉浸式状态栏 + if (isFragmentVisible() && isStatusBarEnabled() && isLazyLoad()) { + statusBarConfig().init(); + } + + //设置标题栏 + if (getTitleBarId() > 0) { + ImmersionBar.setTitleBar(mActivity, findViewById(getTitleBarId())); + } + } + + /** + * 是否在Fragment使用沉浸式 + */ + public boolean isStatusBarEnabled() { + return false; + } + + /** + * 获取状态栏沉浸的配置对象 + */ + protected ImmersionBar getStatusBarConfig() { + return mImmersionBar; + } + + /** + * 初始化沉浸式 + */ + private ImmersionBar statusBarConfig() { + //在BaseActivity里初始化 + mImmersionBar = ImmersionBar.with(this) + .statusBarDarkFont(statusBarDarkFont()) //默认状态栏字体颜色为黑色 + .keyboardEnable(true); //解决软键盘与底部输入框冲突问题,默认为false,还有一个重载方法,可以指定软键盘mode + return mImmersionBar; + } + + /** + * 获取状态栏字体颜色 + */ + protected boolean statusBarDarkFont() { + //返回true表示黑色字体 + return true; + } + + @Override + public void onDestroy() { + super.onDestroy(); + if (mImmersionBar != null) mImmersionBar.destroy(); + } + + @Override + public void setUserVisibleHint(boolean isVisibleToUser) { + super.setUserVisibleHint(isVisibleToUser); + if (isVisibleToUser && isStatusBarEnabled() && isLazyLoad()) { + // 重新初始化状态栏 + statusBarConfig().init(); + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/mvp/MvpActivity.java b/app/src/main/java/com/hjq/demo/mvp/MvpActivity.java index 610b5b30..f1e2f647 100644 --- a/app/src/main/java/com/hjq/demo/mvp/MvpActivity.java +++ b/app/src/main/java/com/hjq/demo/mvp/MvpActivity.java @@ -1,6 +1,6 @@ package com.hjq.demo.mvp; -import com.hjq.demo.common.CommonActivity; +import com.hjq.demo.base.MyActivity; /** * author : HJQ @@ -8,7 +8,7 @@ * time : 2018/11/17 * desc : MVP Activity 基类 */ -public abstract class MvpActivity

extends CommonActivity { +public abstract class MvpActivity

extends MyActivity { private P mPresenter; diff --git a/app/src/main/java/com/hjq/demo/mvp/MvpLazyFragment.java b/app/src/main/java/com/hjq/demo/mvp/MvpLazyFragment.java index eb1f1ce7..f33c023c 100644 --- a/app/src/main/java/com/hjq/demo/mvp/MvpLazyFragment.java +++ b/app/src/main/java/com/hjq/demo/mvp/MvpLazyFragment.java @@ -1,6 +1,6 @@ package com.hjq.demo.mvp; -import com.hjq.demo.common.CommonLazyFragment; +import com.hjq.demo.base.MyLazyFragment; /** * author : HJQ @@ -8,7 +8,7 @@ * time : 2018/11/17 * desc : MVP 懒加载 Fragment 基类 */ -public abstract class MvpLazyFragment

extends CommonLazyFragment { +public abstract class MvpLazyFragment

extends MyLazyFragment { private P mPresenter; diff --git a/app/src/main/java/com/hjq/demo/mvp/copy/CopyModel.java b/app/src/main/java/com/hjq/demo/mvp/copy/CopyModel.java index 131f37f4..6d3bffcb 100644 --- a/app/src/main/java/com/hjq/demo/mvp/copy/CopyModel.java +++ b/app/src/main/java/com/hjq/demo/mvp/copy/CopyModel.java @@ -18,11 +18,11 @@ public CopyModel() { } public void setAccount(String account) { - this.mAccount = mAccount; + this.mAccount = account; } public void setPassword(String password) { - this.mPassword = mPassword; + this.mPassword = password; } public void login() { diff --git a/app/src/main/java/com/hjq/demo/mvp/copy/CopyPresenter.java b/app/src/main/java/com/hjq/demo/mvp/copy/CopyPresenter.java index 7111dd5c..a71e859e 100644 --- a/app/src/main/java/com/hjq/demo/mvp/copy/CopyPresenter.java +++ b/app/src/main/java/com/hjq/demo/mvp/copy/CopyPresenter.java @@ -37,4 +37,4 @@ public void onFail(String msg) { }); mModel.login(); } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/ui/activity/AboutActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/AboutActivity.java index 979f4f6c..6b334011 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/AboutActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/AboutActivity.java @@ -1,33 +1,33 @@ -package com.hjq.demo.ui.activity; - -import com.hjq.demo.R; -import com.hjq.demo.common.CommonActivity; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 关于界面 - */ -public class AboutActivity extends CommonActivity { - - @Override - protected int getLayoutId() { - return R.layout.activity_about; - } - - @Override - protected int getTitleBarId() { - return R.id.tb_about_title; - } - - @Override - protected void initView() { - - } - - @Override - protected void initData() { - - } -} +package com.hjq.demo.ui.activity; + +import com.hjq.demo.R; +import com.hjq.demo.base.MyActivity; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 关于界面 + */ +public class AboutActivity extends MyActivity { + + @Override + protected int getLayoutId() { + return R.layout.activity_about; + } + + @Override + protected int getTitleBarId() { + return R.id.tb_about_title; + } + + @Override + protected void initView() { + + } + + @Override + protected void initData() { + + } +} diff --git a/app/src/main/java/com/hjq/demo/ui/activity/CopyActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/CopyActivity.java index 3c06f9fb..4a4b1028 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/CopyActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/CopyActivity.java @@ -1,33 +1,33 @@ -package com.hjq.demo.ui.activity; - -import com.hjq.demo.R; -import com.hjq.demo.common.CommonActivity; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 可进行拷贝的副本 - */ -public class CopyActivity extends CommonActivity { - - @Override - protected int getLayoutId() { - return R.layout.activity_copy; - } - - @Override - protected int getTitleBarId() { - return R.id.tb_copy_title; - } - - @Override - protected void initView() { - - } - - @Override - protected void initData() { - - } -} +package com.hjq.demo.ui.activity; + +import com.hjq.demo.R; +import com.hjq.demo.base.MyActivity; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 可进行拷贝的副本 + */ +public class CopyActivity extends MyActivity { + + @Override + protected int getLayoutId() { + return R.layout.activity_copy; + } + + @Override + protected int getTitleBarId() { + return R.id.tb_copy_title; + } + + @Override + protected void initView() { + + } + + @Override + protected void initData() { + + } +} diff --git a/app/src/main/java/com/hjq/demo/ui/activity/HomeActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/HomeActivity.java index fee6d953..a047631e 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/HomeActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/HomeActivity.java @@ -1,142 +1,142 @@ -package com.hjq.demo.ui.activity; - -import android.support.annotation.NonNull; -import android.support.design.widget.BottomNavigationView; -import android.support.v4.view.ViewPager; -import android.view.MenuItem; - -import com.hjq.baselibrary.utils.ActivityStackManager; -import com.hjq.baselibrary.utils.OnClickUtils; -import com.hjq.demo.R; -import com.hjq.demo.common.CommonActivity; -import com.hjq.demo.ui.adapter.HomeFragmentAdapter; - -import butterknife.BindView; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 主页界面 - */ -public class HomeActivity extends CommonActivity implements - ViewPager.OnPageChangeListener, BottomNavigationView.OnNavigationItemSelectedListener { - - @BindView(R.id.vp_home_pager) - ViewPager mViewPager; - @BindView(R.id.bv_home_navigation) - BottomNavigationView mBottomNavigationView; - - private HomeFragmentAdapter mPagerAdapter; - - @Override - protected int getLayoutId() { - return R.layout.activity_home; - } - - @Override - protected int getTitleBarId() { - return 0; - } - - @Override - protected void initView() { - mViewPager.addOnPageChangeListener(this); - - // 不使用图标默认变色 - mBottomNavigationView.setItemIconTintList(null); - mBottomNavigationView.setOnNavigationItemSelectedListener(this); - } - - @Override - protected void initData() { - mPagerAdapter = new HomeFragmentAdapter(this); - mViewPager.setAdapter(mPagerAdapter); - - // 限制页面数量 - mViewPager.setOffscreenPageLimit(mPagerAdapter.getCount()); - } - - /** - * {@link ViewPager.OnPageChangeListener} - */ - - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} - - @Override - public void onPageSelected(int position) { - switch (position) { - case 0: - mBottomNavigationView.setSelectedItemId(R.id.menu_home); - break; - case 1: - mBottomNavigationView.setSelectedItemId(R.id.home_found); - break; - case 2: - mBottomNavigationView.setSelectedItemId(R.id.home_message); - break; - case 3: - mBottomNavigationView.setSelectedItemId(R.id.home_me); - break; - } - } - - @Override - public void onPageScrollStateChanged(int state) {} - - /** - * {@link BottomNavigationView.OnNavigationItemSelectedListener} - */ - - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_home: - mViewPager.setCurrentItem(0); - return true; - case R.id.home_found: - mViewPager.setCurrentItem(1); - return true; - case R.id.home_message: - mViewPager.setCurrentItem(2); - return true; - case R.id.home_me: - mViewPager.setCurrentItem(3); - return true; - } - return false; - } - - @Override - public void onBackPressed() { - if (OnClickUtils.isOnDoubleClick()) { - //移动到上一个任务栈,避免侧滑引起的不良反应 - moveTaskToBack(false); - getWindow().getDecorView().postDelayed(new Runnable() { - - @Override - public void run() { - // 进行内存优化,销毁掉所有的界面 - ActivityStackManager.getInstance().finishAllActivities(); - } - }, 300); - } else { - toast(getResources().getString(R.string.home_exit_hint)); - } - } - - @Override - protected void onDestroy() { - mViewPager.removeOnPageChangeListener(this); - mViewPager.setAdapter(null); - mBottomNavigationView.setOnNavigationItemSelectedListener(null); - super.onDestroy(); - } - - @Override - public boolean isSupportSwipeBack() { - // 不使用侧滑功能 - return !super.isSupportSwipeBack(); - } +package com.hjq.demo.ui.activity; + +import android.support.annotation.NonNull; +import android.support.design.widget.BottomNavigationView; +import android.support.v4.view.ViewPager; +import android.view.MenuItem; + +import com.hjq.demo.utils.ActivityStackManager; +import com.hjq.demo.utils.OnClickUtils; +import com.hjq.demo.R; +import com.hjq.demo.base.MyActivity; +import com.hjq.demo.ui.adapter.HomeFragmentAdapter; + +import butterknife.BindView; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 主页界面 + */ +public class HomeActivity extends MyActivity implements + ViewPager.OnPageChangeListener, BottomNavigationView.OnNavigationItemSelectedListener { + + @BindView(R.id.vp_home_pager) + ViewPager mViewPager; + @BindView(R.id.bv_home_navigation) + BottomNavigationView mBottomNavigationView; + + private HomeFragmentAdapter mPagerAdapter; + + @Override + protected int getLayoutId() { + return R.layout.activity_home; + } + + @Override + protected int getTitleBarId() { + return 0; + } + + @Override + protected void initView() { + mViewPager.addOnPageChangeListener(this); + + // 不使用图标默认变色 + mBottomNavigationView.setItemIconTintList(null); + mBottomNavigationView.setOnNavigationItemSelectedListener(this); + } + + @Override + protected void initData() { + mPagerAdapter = new HomeFragmentAdapter(this); + mViewPager.setAdapter(mPagerAdapter); + + // 限制页面数量 + mViewPager.setOffscreenPageLimit(mPagerAdapter.getCount()); + } + + /** + * {@link ViewPager.OnPageChangeListener} + */ + + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} + + @Override + public void onPageSelected(int position) { + switch (position) { + case 0: + mBottomNavigationView.setSelectedItemId(R.id.menu_home); + break; + case 1: + mBottomNavigationView.setSelectedItemId(R.id.home_found); + break; + case 2: + mBottomNavigationView.setSelectedItemId(R.id.home_message); + break; + case 3: + mBottomNavigationView.setSelectedItemId(R.id.home_me); + break; + } + } + + @Override + public void onPageScrollStateChanged(int state) {} + + /** + * {@link BottomNavigationView.OnNavigationItemSelectedListener} + */ + + @Override + public boolean onNavigationItemSelected(@NonNull MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_home: + mViewPager.setCurrentItem(0); + return true; + case R.id.home_found: + mViewPager.setCurrentItem(1); + return true; + case R.id.home_message: + mViewPager.setCurrentItem(2); + return true; + case R.id.home_me: + mViewPager.setCurrentItem(3); + return true; + } + return false; + } + + @Override + public void onBackPressed() { + if (OnClickUtils.isOnDoubleClick()) { + //移动到上一个任务栈,避免侧滑引起的不良反应 + moveTaskToBack(false); + getWindow().getDecorView().postDelayed(new Runnable() { + + @Override + public void run() { + // 进行内存优化,销毁掉所有的界面 + ActivityStackManager.getInstance().finishAllActivities(); + } + }, 300); + } else { + toast(getResources().getString(R.string.home_exit_hint)); + } + } + + @Override + protected void onDestroy() { + mViewPager.removeOnPageChangeListener(this); + mViewPager.setAdapter(null); + mBottomNavigationView.setOnNavigationItemSelectedListener(null); + super.onDestroy(); + } + + @Override + public boolean isSupportSwipeBack() { + // 不使用侧滑功能 + return !super.isSupportSwipeBack(); + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/ui/activity/LauncherActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/LauncherActivity.java index 74dd0ea7..50097bb6 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/LauncherActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/LauncherActivity.java @@ -1,158 +1,158 @@ -package com.hjq.demo.ui.activity; - -import android.view.View; -import android.view.animation.AlphaAnimation; -import android.view.animation.Animation; -import android.view.animation.RotateAnimation; -import android.view.animation.ScaleAnimation; - -import com.gyf.barlibrary.BarHide; -import com.hjq.demo.R; -import com.hjq.demo.common.CommonActivity; -import com.hjq.permissions.OnPermission; -import com.hjq.permissions.Permission; -import com.hjq.permissions.XXPermissions; - -import java.util.List; - -import butterknife.BindView; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 启动界面 - */ -public class LauncherActivity extends CommonActivity - implements OnPermission, Animation.AnimationListener { - - @BindView(R.id.iv_launcher_bg) - View mImageView; - @BindView(R.id.iv_launcher_icon) - View mIconView; - @BindView(R.id.iv_launcher_name) - View mTextView; - - @Override - protected int getLayoutId() { - return R.layout.activity_launcher; - } - - @Override - protected int getTitleBarId() { - return 0; - } - - @Override - protected void initView() { - //初始化动画 - initStartAnim(); - //设置状态栏和导航栏参数 - getStatusBarConfig() - .fullScreen(true)//有导航栏的情况下,activity全屏显示,也就是activity最下面被导航栏覆盖,不写默认非全屏 - .hideBar(BarHide.FLAG_HIDE_STATUS_BAR)//隐藏状态栏 - .transparentNavigationBar()//透明导航栏,不写默认黑色(设置此方法,fullScreen()方法自动为true) - .init(); - } - - @Override - protected void initData() {} - - private static final int ANIM_TIME = 1000; - - /** - * 启动动画 - */ - private void initStartAnim() { - // 渐变展示启动屏 - AlphaAnimation aa = new AlphaAnimation(0.4f, 1.0f); - aa.setDuration(ANIM_TIME * 2); - aa.setAnimationListener(this); - mImageView.startAnimation(aa); - - ScaleAnimation sa = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); - sa.setDuration(ANIM_TIME); - mIconView.startAnimation(sa); - - RotateAnimation ra = new RotateAnimation(180, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); - ra.setDuration(ANIM_TIME); - mTextView.startAnimation(ra); - } - - private void requestFilePermission() { - XXPermissions.with(this) - .permission(Permission.Group.STORAGE) - .request(this); - } - - /** - * {@link OnPermission} - */ - - @Override - public void hasPermission(List granted, boolean isAll) { - startActivity(HomeActivity.class); - finish(); - } - - @Override - public void noPermission(List denied, boolean quick) { - if (quick) { - toast("没有权限访问文件,请手动授予权限"); - XXPermissions.gotoPermissionSettings(LauncherActivity.this, true); - }else { - toast("请先授予文件读写权限"); - getWindow().getDecorView().postDelayed(new Runnable() { - @Override - public void run() { - requestFilePermission(); - } - }, 2000); - } - } - - @Override - public void onBackPressed() { - //禁用返回键 - //super.onBackPressed(); - } - - @Override - protected void onRestart() { - super.onRestart(); - if (XXPermissions.isHasPermission(LauncherActivity.this, Permission.Group.STORAGE)) { - hasPermission(null, true); - }else { - requestFilePermission(); - } - } - - @Override - public boolean isSupportSwipeBack() { - //不使用侧滑功能 - return !super.isSupportSwipeBack(); - } - - /** - * {@link Animation.AnimationListener} - */ - - @Override - public void onAnimationStart(Animation animation) {} - - @Override - public void onAnimationEnd(Animation animation) { - requestFilePermission(); - } - - @Override - public void onAnimationRepeat(Animation animation) {} - - - @Override - protected void initOrientation() { - //Android 8.0踩坑记录:Only fullscreen opaque activities can request orientation - // https://www.jianshu.com/p/d0d907754603 - //super.initOrientation(); - } -} +package com.hjq.demo.ui.activity; + +import android.view.View; +import android.view.animation.AlphaAnimation; +import android.view.animation.Animation; +import android.view.animation.RotateAnimation; +import android.view.animation.ScaleAnimation; + +import com.gyf.barlibrary.BarHide; +import com.hjq.demo.R; +import com.hjq.demo.base.MyActivity; +import com.hjq.permissions.OnPermission; +import com.hjq.permissions.Permission; +import com.hjq.permissions.XXPermissions; + +import java.util.List; + +import butterknife.BindView; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 启动界面 + */ +public class LauncherActivity extends MyActivity + implements OnPermission, Animation.AnimationListener { + + @BindView(R.id.iv_launcher_bg) + View mImageView; + @BindView(R.id.iv_launcher_icon) + View mIconView; + @BindView(R.id.iv_launcher_name) + View mTextView; + + @Override + protected int getLayoutId() { + return R.layout.activity_launcher; + } + + @Override + protected int getTitleBarId() { + return 0; + } + + @Override + protected void initView() { + //初始化动画 + initStartAnim(); + //设置状态栏和导航栏参数 + getStatusBarConfig() + .fullScreen(true)//有导航栏的情况下,activity全屏显示,也就是activity最下面被导航栏覆盖,不写默认非全屏 + .hideBar(BarHide.FLAG_HIDE_STATUS_BAR)//隐藏状态栏 + .transparentNavigationBar()//透明导航栏,不写默认黑色(设置此方法,fullScreen()方法自动为true) + .init(); + } + + @Override + protected void initData() {} + + private static final int ANIM_TIME = 1000; + + /** + * 启动动画 + */ + private void initStartAnim() { + // 渐变展示启动屏 + AlphaAnimation aa = new AlphaAnimation(0.4f, 1.0f); + aa.setDuration(ANIM_TIME * 2); + aa.setAnimationListener(this); + mImageView.startAnimation(aa); + + ScaleAnimation sa = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); + sa.setDuration(ANIM_TIME); + mIconView.startAnimation(sa); + + RotateAnimation ra = new RotateAnimation(180, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); + ra.setDuration(ANIM_TIME); + mTextView.startAnimation(ra); + } + + private void requestFilePermission() { + XXPermissions.with(this) + .permission(Permission.Group.STORAGE) + .request(this); + } + + /** + * {@link OnPermission} + */ + + @Override + public void hasPermission(List granted, boolean isAll) { + startActivity(HomeActivity.class); + finish(); + } + + @Override + public void noPermission(List denied, boolean quick) { + if (quick) { + toast("没有权限访问文件,请手动授予权限"); + XXPermissions.gotoPermissionSettings(LauncherActivity.this, true); + }else { + toast("请先授予文件读写权限"); + getWindow().getDecorView().postDelayed(new Runnable() { + @Override + public void run() { + requestFilePermission(); + } + }, 2000); + } + } + + @Override + public void onBackPressed() { + //禁用返回键 + //super.onBackPressed(); + } + + @Override + protected void onRestart() { + super.onRestart(); + if (XXPermissions.isHasPermission(LauncherActivity.this, Permission.Group.STORAGE)) { + hasPermission(null, true); + }else { + requestFilePermission(); + } + } + + @Override + public boolean isSupportSwipeBack() { + //不使用侧滑功能 + return !super.isSupportSwipeBack(); + } + + /** + * {@link Animation.AnimationListener} + */ + + @Override + public void onAnimationStart(Animation animation) {} + + @Override + public void onAnimationEnd(Animation animation) { + requestFilePermission(); + } + + @Override + public void onAnimationRepeat(Animation animation) {} + + + @Override + protected void initOrientation() { + //Android 8.0踩坑记录:Only fullscreen opaque activities can request orientation + // https://www.jianshu.com/p/d0d907754603 + //super.initOrientation(); + } +} diff --git a/app/src/main/java/com/hjq/demo/ui/activity/LoginActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/LoginActivity.java index f0afaef2..dbc00cb2 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/LoginActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/LoginActivity.java @@ -1,83 +1,83 @@ -package com.hjq.demo.ui.activity; - -import android.view.View; -import android.widget.Button; -import android.widget.EditText; - -import com.hjq.baselibrary.utils.EditTextInputHelper; -import com.hjq.demo.R; -import com.hjq.demo.common.CommonActivity; -import com.hjq.toast.ToastUtils; - -import butterknife.BindView; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 登录界面 - */ -public class LoginActivity extends CommonActivity - implements View.OnClickListener { - - @BindView(R.id.et_login_phone) - EditText mPhoneView; - @BindView(R.id.et_login_password) - EditText mPasswordView; - @BindView(R.id.btn_login_commit) - Button mCommitView; - - private EditTextInputHelper mEditTextInputHelper; - - @Override - protected int getLayoutId() { - return R.layout.activity_login; - } - - @Override - protected int getTitleBarId() { - return R.id.tb_login_title; - } - - @Override - protected void initView() { - mCommitView.setOnClickListener(this); - mEditTextInputHelper = new EditTextInputHelper(mCommitView, false); - mEditTextInputHelper.addViews(mPhoneView, mPasswordView); - } - - @Override - protected void initData() { - - } - - @Override - public void onRightClick(View v) { - // 跳转到注册界面 - startActivity(RegisterActivity.class); - } - - @Override - protected void onDestroy() { - mEditTextInputHelper.removeViews(); - super.onDestroy(); - } - - @Override - public boolean isSupportSwipeBack() { - //不使用侧滑功能 - return !super.isSupportSwipeBack(); - } - - /** - * {@link View.OnClickListener} - */ - @Override - public void onClick(View v) { - if (v == mCommitView) { - if (mPhoneView.getText().toString().length() != 11) { - ToastUtils.show(getResources().getString(R.string.phone_input_error)); - } - } - } +package com.hjq.demo.ui.activity; + +import android.view.View; +import android.widget.Button; +import android.widget.EditText; + +import com.hjq.demo.utils.EditTextInputHelper; +import com.hjq.demo.R; +import com.hjq.demo.base.MyActivity; +import com.hjq.toast.ToastUtils; + +import butterknife.BindView; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 登录界面 + */ +public class LoginActivity extends MyActivity + implements View.OnClickListener { + + @BindView(R.id.et_login_phone) + EditText mPhoneView; + @BindView(R.id.et_login_password) + EditText mPasswordView; + @BindView(R.id.btn_login_commit) + Button mCommitView; + + private EditTextInputHelper mEditTextInputHelper; + + @Override + protected int getLayoutId() { + return R.layout.activity_login; + } + + @Override + protected int getTitleBarId() { + return R.id.tb_login_title; + } + + @Override + protected void initView() { + mCommitView.setOnClickListener(this); + mEditTextInputHelper = new EditTextInputHelper(mCommitView, false); + mEditTextInputHelper.addViews(mPhoneView, mPasswordView); + } + + @Override + protected void initData() { + + } + + @Override + public void onRightClick(View v) { + // 跳转到注册界面 + startActivity(RegisterActivity.class); + } + + @Override + protected void onDestroy() { + mEditTextInputHelper.removeViews(); + super.onDestroy(); + } + + @Override + public boolean isSupportSwipeBack() { + //不使用侧滑功能 + return !super.isSupportSwipeBack(); + } + + /** + * {@link View.OnClickListener} + */ + @Override + public void onClick(View v) { + if (v == mCommitView) { + if (mPhoneView.getText().toString().length() != 11) { + ToastUtils.show(getResources().getString(R.string.phone_input_error)); + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/ui/activity/RegisterActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/RegisterActivity.java index 2181eee8..0b11965d 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/RegisterActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/RegisterActivity.java @@ -1,100 +1,100 @@ -package com.hjq.demo.ui.activity; - -import android.view.View; -import android.widget.Button; -import android.widget.EditText; - -import com.hjq.baselibrary.utils.EditTextInputHelper; -import com.hjq.baselibrary.widget.CountdownView; -import com.hjq.demo.R; -import com.hjq.demo.common.CommonActivity; - -import butterknife.BindView; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 注册界面 - */ -public class RegisterActivity extends CommonActivity - implements View.OnClickListener { - - @BindView(R.id.et_register_phone) - EditText mPhoneView; - @BindView(R.id.cv_register_countdown) - CountdownView mCountdownView; - - @BindView(R.id.et_register_code) - EditText mCodeView; - - @BindView(R.id.et_register_password1) - EditText mPasswordView1; - @BindView(R.id.et_register_password2) - EditText mPasswordView2; - - @BindView(R.id.btn_register_commit) - Button mCommitView; - - private EditTextInputHelper mEditTextInputHelper; - - @Override - protected int getLayoutId() { - return R.layout.activity_register; - } - - @Override - protected int getTitleBarId() { - return R.id.tb_register_title; - } - - @Override - protected void initView() { - mCountdownView.setOnClickListener(this); - mCommitView.setOnClickListener(this); - - mEditTextInputHelper = new EditTextInputHelper(mCommitView, false); - mEditTextInputHelper.addViews(mPhoneView, mCodeView, mPasswordView1, mPasswordView2); - } - - @Override - protected void initData() { - - } - - /** - * {@link View.OnClickListener} - */ - @Override - public void onClick(View v) { - if (v == mCountdownView) { //获取验证码 - - if (mPhoneView.getText().toString().length() != 11) { - // 重置验证码倒计时控件 - mCountdownView.resetState(); - toast(getResources().getString(R.string.phone_input_error)); - return; - } - - toast(getResources().getString(R.string.countdown_code_send_succeed)); - - }else if (v == mCommitView) { //提交注册 - - if (mPhoneView.getText().toString().length() != 11) { - toast(getResources().getString(R.string.phone_input_error)); - return; - } - - if (!mPasswordView1.getText().toString().equals(mPasswordView2.getText().toString())) { - toast(getResources().getString(R.string.two_password_input_error)); - return; - } - } - } - - @Override - protected void onDestroy() { - mEditTextInputHelper.removeViews(); - super.onDestroy(); - } +package com.hjq.demo.ui.activity; + +import android.view.View; +import android.widget.Button; +import android.widget.EditText; + +import com.hjq.demo.utils.EditTextInputHelper; +import com.hjq.widget.CountdownView; +import com.hjq.demo.R; +import com.hjq.demo.base.MyActivity; + +import butterknife.BindView; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 注册界面 + */ +public class RegisterActivity extends MyActivity + implements View.OnClickListener { + + @BindView(R.id.et_register_phone) + EditText mPhoneView; + @BindView(R.id.cv_register_countdown) + CountdownView mCountdownView; + + @BindView(R.id.et_register_code) + EditText mCodeView; + + @BindView(R.id.et_register_password1) + EditText mPasswordView1; + @BindView(R.id.et_register_password2) + EditText mPasswordView2; + + @BindView(R.id.btn_register_commit) + Button mCommitView; + + private EditTextInputHelper mEditTextInputHelper; + + @Override + protected int getLayoutId() { + return R.layout.activity_register; + } + + @Override + protected int getTitleBarId() { + return R.id.tb_register_title; + } + + @Override + protected void initView() { + mCountdownView.setOnClickListener(this); + mCommitView.setOnClickListener(this); + + mEditTextInputHelper = new EditTextInputHelper(mCommitView, false); + mEditTextInputHelper.addViews(mPhoneView, mCodeView, mPasswordView1, mPasswordView2); + } + + @Override + protected void initData() { + + } + + /** + * {@link View.OnClickListener} + */ + @Override + public void onClick(View v) { + if (v == mCountdownView) { //获取验证码 + + if (mPhoneView.getText().toString().length() != 11) { + // 重置验证码倒计时控件 + mCountdownView.resetState(); + toast(getResources().getString(R.string.phone_input_error)); + return; + } + + toast(getResources().getString(R.string.countdown_code_send_succeed)); + + }else if (v == mCommitView) { //提交注册 + + if (mPhoneView.getText().toString().length() != 11) { + toast(getResources().getString(R.string.phone_input_error)); + return; + } + + if (!mPasswordView1.getText().toString().equals(mPasswordView2.getText().toString())) { + toast(getResources().getString(R.string.two_password_input_error)); + return; + } + } + } + + @Override + protected void onDestroy() { + mEditTextInputHelper.removeViews(); + super.onDestroy(); + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/ui/activity/WebActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/WebActivity.java index 6df502a6..846b1e55 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/WebActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/WebActivity.java @@ -1,183 +1,183 @@ -package com.hjq.demo.ui.activity; - -import android.graphics.Bitmap; -import android.net.Uri; -import android.net.http.SslError; -import android.os.Build; -import android.view.KeyEvent; -import android.view.View; -import android.webkit.SslErrorHandler; -import android.webkit.WebChromeClient; -import android.webkit.WebSettings; -import android.webkit.WebView; -import android.webkit.WebViewClient; -import android.widget.ProgressBar; - -import com.hjq.baselibrary.utils.IntentExtraUtils; -import com.hjq.baselibrary.utils.WebViewLifecycleUtils; -import com.hjq.demo.R; -import com.hjq.demo.common.CommonActivity; - -import butterknife.BindView; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 浏览器界面 - */ -public class WebActivity extends CommonActivity { - - @BindView(R.id.pb_web_progress) - ProgressBar mProgressBar; - @BindView(R.id.wv_web_view) - WebView mWebView; - - @Override - protected int getLayoutId() { - return R.layout.activity_web; - } - - @Override - protected int getTitleBarId() { - return R.id.tb_web_title; - } - - @Override - protected void initView() { - // 不显示滚动条 - mWebView.setVerticalScrollBarEnabled(false); - mWebView.setHorizontalScrollBarEnabled(false); - - WebSettings settings = mWebView.getSettings(); - // 允许文件访问 - settings.setAllowFileAccess(true); - // 支持javaScript - settings.setJavaScriptEnabled(true); - // 允许网页定位 - settings.setGeolocationEnabled(true); - // 允许保存密码 - settings.setSavePassword(true); - - // 支持播放gif动画 - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { - settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); - } - - // 解决Android 5.0上Webview默认不允许加载Http与Https混合内容 - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - //两者都可以 - settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); - } - - // 加快HTML网页加载完成的速度,等页面finish再加载图片 - if(Build.VERSION.SDK_INT >= 19) { - settings.setLoadsImagesAutomatically(true); - } else { - settings.setLoadsImagesAutomatically(false); - } - } - - @Override - protected void initData() { - mWebView.setWebViewClient(new MyWebViewClient()); - mWebView.setWebChromeClient(new MyWebChromeClient()); - - String url = IntentExtraUtils.getInstance(WebActivity.class).getString(); - mWebView.loadUrl(url); - } - - @Override - public void onLeftClick(View v) { - finish(); - } - - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) { - // 后退网页并且拦截该事件 - mWebView.goBack(); - return true; - } - return super.onKeyDown(keyCode, event); - } - - @Override - protected void onResume() { - WebViewLifecycleUtils.onResume(mWebView); - super.onResume(); - } - - @Override - protected void onPause() { - WebViewLifecycleUtils.onPause(mWebView); - super.onPause(); - } - - @Override - protected void onDestroy() { - WebViewLifecycleUtils.onDestroy(mWebView); - super.onDestroy(); - } - - private class MyWebViewClient extends WebViewClient { - - // 网页加载错误时回调,这个方法会在onPageFinished之前调用 - @Override - public void onReceivedError(WebView view, int errorCode, String description, final String failingUrl) { - - } - - // 开始加载网页 - @Override - public void onPageStarted(final WebView view, final String url, Bitmap favicon) { - mProgressBar.setVisibility(View.VISIBLE); - } - - // 完成加载网页 - @Override - public void onPageFinished(WebView view, String url) { - mProgressBar.setVisibility(View.GONE); - } - - @Override - public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { - //super.onReceivedSslError(view, handler, error);注意一定要去除这行代码,否则设置无效。 - // handler.cancel();// Android默认的处理方式 - handler.proceed();// 接受所有网站的证书 - // handleMessage(Message msg);// 进行其他处理 - } - - // 跳转到其他链接 - @Override - public boolean shouldOverrideUrlLoading(WebView view, final String url) { - - String scheme = Uri.parse(url).getScheme(); - if (scheme != null) { - scheme = scheme.toLowerCase(); - } - if ("http".equalsIgnoreCase(scheme) || "https".equalsIgnoreCase(scheme)) { - mWebView.loadUrl(url); - } - // 已经处理该链接请求 - return true; - } - } - - private class MyWebChromeClient extends WebChromeClient { - - // 收到网页标题 - @Override - public void onReceivedTitle(WebView view, String title) { - if (title != null) { - setTitle(title); - } - } - - // 收到加载进度变化 - @Override - public void onProgressChanged(WebView view, int newProgress) { - mProgressBar.setProgress(newProgress); - } - } +package com.hjq.demo.ui.activity; + +import android.graphics.Bitmap; +import android.net.Uri; +import android.net.http.SslError; +import android.os.Build; +import android.view.KeyEvent; +import android.view.View; +import android.webkit.SslErrorHandler; +import android.webkit.WebChromeClient; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.ProgressBar; + +import com.hjq.demo.utils.IntentExtraUtils; +import com.hjq.demo.utils.WebViewLifecycleUtils; +import com.hjq.demo.R; +import com.hjq.demo.base.MyActivity; + +import butterknife.BindView; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 浏览器界面 + */ +public class WebActivity extends MyActivity { + + @BindView(R.id.pb_web_progress) + ProgressBar mProgressBar; + @BindView(R.id.wv_web_view) + WebView mWebView; + + @Override + protected int getLayoutId() { + return R.layout.activity_web; + } + + @Override + protected int getTitleBarId() { + return R.id.tb_web_title; + } + + @Override + protected void initView() { + // 不显示滚动条 + mWebView.setVerticalScrollBarEnabled(false); + mWebView.setHorizontalScrollBarEnabled(false); + + WebSettings settings = mWebView.getSettings(); + // 允许文件访问 + settings.setAllowFileAccess(true); + // 支持javaScript + settings.setJavaScriptEnabled(true); + // 允许网页定位 + settings.setGeolocationEnabled(true); + // 允许保存密码 + settings.setSavePassword(true); + + // 支持播放gif动画 + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { + settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); + } + + // 解决Android 5.0上Webview默认不允许加载Http与Https混合内容 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + //两者都可以 + settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); + } + + // 加快HTML网页加载完成的速度,等页面finish再加载图片 + if(Build.VERSION.SDK_INT >= 19) { + settings.setLoadsImagesAutomatically(true); + } else { + settings.setLoadsImagesAutomatically(false); + } + } + + @Override + protected void initData() { + mWebView.setWebViewClient(new MyWebViewClient()); + mWebView.setWebChromeClient(new MyWebChromeClient()); + + String url = IntentExtraUtils.getInstance(WebActivity.class).getString(); + mWebView.loadUrl(url); + } + + @Override + public void onLeftClick(View v) { + finish(); + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) { + // 后退网页并且拦截该事件 + mWebView.goBack(); + return true; + } + return super.onKeyDown(keyCode, event); + } + + @Override + protected void onResume() { + WebViewLifecycleUtils.onResume(mWebView); + super.onResume(); + } + + @Override + protected void onPause() { + WebViewLifecycleUtils.onPause(mWebView); + super.onPause(); + } + + @Override + protected void onDestroy() { + WebViewLifecycleUtils.onDestroy(mWebView); + super.onDestroy(); + } + + private class MyWebViewClient extends WebViewClient { + + // 网页加载错误时回调,这个方法会在onPageFinished之前调用 + @Override + public void onReceivedError(WebView view, int errorCode, String description, final String failingUrl) { + + } + + // 开始加载网页 + @Override + public void onPageStarted(final WebView view, final String url, Bitmap favicon) { + mProgressBar.setVisibility(View.VISIBLE); + } + + // 完成加载网页 + @Override + public void onPageFinished(WebView view, String url) { + mProgressBar.setVisibility(View.GONE); + } + + @Override + public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { + //super.onReceivedSslError(view, handler, error);注意一定要去除这行代码,否则设置无效。 + // handler.cancel();// Android默认的处理方式 + handler.proceed();// 接受所有网站的证书 + // handleMessage(Message msg);// 进行其他处理 + } + + // 跳转到其他链接 + @Override + public boolean shouldOverrideUrlLoading(WebView view, final String url) { + + String scheme = Uri.parse(url).getScheme(); + if (scheme != null) { + scheme = scheme.toLowerCase(); + } + if ("http".equalsIgnoreCase(scheme) || "https".equalsIgnoreCase(scheme)) { + mWebView.loadUrl(url); + } + // 已经处理该链接请求 + return true; + } + } + + private class MyWebChromeClient extends WebChromeClient { + + // 收到网页标题 + @Override + public void onReceivedTitle(WebView view, String title) { + if (title != null) { + setTitle(title); + } + } + + // 收到加载进度变化 + @Override + public void onProgressChanged(WebView view, int newProgress) { + mProgressBar.setProgress(newProgress); + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/ui/adapter/CopyAdapter.java b/app/src/main/java/com/hjq/demo/ui/adapter/CopyAdapter.java index c5ff391d..57d04057 100644 --- a/app/src/main/java/com/hjq/demo/ui/adapter/CopyAdapter.java +++ b/app/src/main/java/com/hjq/demo/ui/adapter/CopyAdapter.java @@ -3,7 +3,7 @@ import android.content.Context; import android.view.ViewGroup; -import com.hjq.baselibrary.base.BaseRecyclerViewAdapter; +import com.hjq.base.BaseRecyclerViewAdapter; import com.hjq.demo.R; /** diff --git a/app/src/main/java/com/hjq/demo/ui/adapter/HomeFragmentAdapter.java b/app/src/main/java/com/hjq/demo/ui/adapter/HomeFragmentAdapter.java index c05b0d4c..580ddb72 100644 --- a/app/src/main/java/com/hjq/demo/ui/adapter/HomeFragmentAdapter.java +++ b/app/src/main/java/com/hjq/demo/ui/adapter/HomeFragmentAdapter.java @@ -3,8 +3,8 @@ import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; -import com.hjq.baselibrary.base.BaseFragmentPagerAdapter; -import com.hjq.demo.common.CommonLazyFragment; +import com.hjq.base.BaseFragmentPagerAdapter; +import com.hjq.demo.base.MyLazyFragment; import com.hjq.demo.ui.fragment.TestFragmentA; import com.hjq.demo.ui.fragment.TestFragmentB; import com.hjq.demo.ui.fragment.TestFragmentC; @@ -18,14 +18,14 @@ * time : 2018/10/18 * desc : 主页界面 ViewPager + Fragment 适配器 */ -public final class HomeFragmentAdapter extends BaseFragmentPagerAdapter { +public final class HomeFragmentAdapter extends BaseFragmentPagerAdapter { public HomeFragmentAdapter(FragmentActivity activity) { super(activity); } @Override - protected void init(FragmentManager fm, List list) { + protected void init(FragmentManager fm, List list) { list.add(TestFragmentA.newInstance()); list.add(TestFragmentB.newInstance()); list.add(TestFragmentC.newInstance()); diff --git a/app/src/main/java/com/hjq/demo/ui/fragment/CopyFragment.java b/app/src/main/java/com/hjq/demo/ui/fragment/CopyFragment.java index 9847c6b2..70d9bc35 100644 --- a/app/src/main/java/com/hjq/demo/ui/fragment/CopyFragment.java +++ b/app/src/main/java/com/hjq/demo/ui/fragment/CopyFragment.java @@ -1,37 +1,37 @@ -package com.hjq.demo.ui.fragment; - -import com.hjq.demo.R; -import com.hjq.demo.common.CommonLazyFragment; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 可进行拷贝的副本 - */ -public class CopyFragment extends CommonLazyFragment { - - public static CopyFragment newInstance() { - return new CopyFragment(); - } - - @Override - protected int getLayoutId() { - return R.layout.fragment_copy; - } - - @Override - protected int getTitleBarId() { - return R.id.tb_copy_title; - } - - @Override - protected void initView() { - - } - - @Override - protected void initData() { - - } +package com.hjq.demo.ui.fragment; + +import com.hjq.demo.R; +import com.hjq.demo.base.MyLazyFragment; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 可进行拷贝的副本 + */ +public class CopyFragment extends MyLazyFragment { + + public static CopyFragment newInstance() { + return new CopyFragment(); + } + + @Override + protected int getLayoutId() { + return R.layout.fragment_copy; + } + + @Override + protected int getTitleBarId() { + return R.id.tb_copy_title; + } + + @Override + protected void initView() { + + } + + @Override + protected void initData() { + + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/ui/fragment/TestFragmentA.java b/app/src/main/java/com/hjq/demo/ui/fragment/TestFragmentA.java index 3db9f715..a95f3977 100644 --- a/app/src/main/java/com/hjq/demo/ui/fragment/TestFragmentA.java +++ b/app/src/main/java/com/hjq/demo/ui/fragment/TestFragmentA.java @@ -1,93 +1,93 @@ -package com.hjq.demo.ui.fragment; - -import android.support.design.widget.AppBarLayout; -import android.support.v7.widget.Toolbar; -import android.widget.TextView; - -import com.gyf.barlibrary.ImmersionBar; -import com.hjq.bar.TitleBar; -import com.hjq.demo.R; -import com.hjq.demo.common.CommonLazyFragment; -import com.hjq.demo.widget.XCollapsingToolbarLayout; - -import butterknife.BindView; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 项目炫酷效果示例 - */ -public class TestFragmentA extends CommonLazyFragment - implements XCollapsingToolbarLayout.OnScrimsListener { - - @BindView(R.id.abl_test_bar) - AppBarLayout mAppBarLayout; - @BindView(R.id.ctl_test_bar) - XCollapsingToolbarLayout mCollapsingToolbarLayout; - @BindView(R.id.t_test_title) - Toolbar mToolbar; - @BindView(R.id.tb_test_a_bar) - TitleBar mTitleBar; - - @BindView(R.id.tv_test_address) - TextView mAddressView; - @BindView(R.id.tv_test_search) - TextView mSearchView; - - public static TestFragmentA newInstance() { - return new TestFragmentA(); - } - - @Override - protected int getLayoutId() { - return R.layout.fragment_test_a; - } - - @Override - protected int getTitleBarId() { - return R.id.tb_test_a_bar; - } - - @Override - protected void initView() { - // 给这个ToolBar设置顶部内边距,才能和TitleBar进行对齐 - ImmersionBar.setTitleBar(getFragmentActivity(), mToolbar); - - //设置渐变监听 - mCollapsingToolbarLayout.setOnScrimsListener(this); - } - - @Override - protected void initData() { - - } - - @Override - public boolean isStatusBarEnabled() { - // 使用沉浸式状态栏 - return !super.isStatusBarEnabled(); - } - - @Override - public boolean statusBarDarkFont() { - return mCollapsingToolbarLayout.isScrimsShown(); - } - - /** - * {@link XCollapsingToolbarLayout.OnScrimsListener} - */ - @Override - public void onScrimsStateChange(boolean shown) { - // CollapsingToolbarLayout 发生了渐变 - if (shown) { - mAddressView.setTextColor(getResources().getColor(R.color.black)); - mSearchView.setBackgroundResource(R.drawable.bg_home_search_bar_gray); - getStatusBarConfig().statusBarDarkFont(true).init(); - }else { - mAddressView.setTextColor(getResources().getColor(R.color.white)); - mSearchView.setBackgroundResource(R.drawable.bg_home_search_bar_transparent); - getStatusBarConfig().statusBarDarkFont(false).init(); - } - } +package com.hjq.demo.ui.fragment; + +import android.support.design.widget.AppBarLayout; +import android.support.v7.widget.Toolbar; +import android.widget.TextView; + +import com.gyf.barlibrary.ImmersionBar; +import com.hjq.bar.TitleBar; +import com.hjq.demo.R; +import com.hjq.demo.base.MyLazyFragment; +import com.hjq.demo.widget.XCollapsingToolbarLayout; + +import butterknife.BindView; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 项目炫酷效果示例 + */ +public class TestFragmentA extends MyLazyFragment + implements XCollapsingToolbarLayout.OnScrimsListener { + + @BindView(R.id.abl_test_bar) + AppBarLayout mAppBarLayout; + @BindView(R.id.ctl_test_bar) + XCollapsingToolbarLayout mCollapsingToolbarLayout; + @BindView(R.id.t_test_title) + Toolbar mToolbar; + @BindView(R.id.tb_test_a_bar) + TitleBar mTitleBar; + + @BindView(R.id.tv_test_address) + TextView mAddressView; + @BindView(R.id.tv_test_search) + TextView mSearchView; + + public static TestFragmentA newInstance() { + return new TestFragmentA(); + } + + @Override + protected int getLayoutId() { + return R.layout.fragment_test_a; + } + + @Override + protected int getTitleBarId() { + return R.id.tb_test_a_bar; + } + + @Override + protected void initView() { + // 给这个ToolBar设置顶部内边距,才能和TitleBar进行对齐 + ImmersionBar.setTitleBar(getFragmentActivity(), mToolbar); + + //设置渐变监听 + mCollapsingToolbarLayout.setOnScrimsListener(this); + } + + @Override + protected void initData() { + + } + + @Override + public boolean isStatusBarEnabled() { + // 使用沉浸式状态栏 + return !super.isStatusBarEnabled(); + } + + @Override + public boolean statusBarDarkFont() { + return mCollapsingToolbarLayout.isScrimsShown(); + } + + /** + * {@link XCollapsingToolbarLayout.OnScrimsListener} + */ + @Override + public void onScrimsStateChange(boolean shown) { + // CollapsingToolbarLayout 发生了渐变 + if (shown) { + mAddressView.setTextColor(getResources().getColor(R.color.black)); + mSearchView.setBackgroundResource(R.drawable.bg_home_search_bar_gray); + getStatusBarConfig().statusBarDarkFont(true).init(); + }else { + mAddressView.setTextColor(getResources().getColor(R.color.white)); + mSearchView.setBackgroundResource(R.drawable.bg_home_search_bar_transparent); + getStatusBarConfig().statusBarDarkFont(false).init(); + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/ui/fragment/TestFragmentB.java b/app/src/main/java/com/hjq/demo/ui/fragment/TestFragmentB.java index 154d1113..3a2d79c0 100644 --- a/app/src/main/java/com/hjq/demo/ui/fragment/TestFragmentB.java +++ b/app/src/main/java/com/hjq/demo/ui/fragment/TestFragmentB.java @@ -1,63 +1,62 @@ -package com.hjq.demo.ui.fragment; - -import android.view.View; - -import com.hjq.baselibrary.widget.CountdownView; -import com.hjq.demo.R; -import com.hjq.demo.common.CommonLazyFragment; -import com.hjq.toast.ToastUtils; - -import butterknife.BindView; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 项目自定义控件展示 - */ -public class TestFragmentB extends CommonLazyFragment - implements View.OnClickListener { - - @BindView(R.id.cv_test_countdown) - CountdownView mCountdownView; - - public static TestFragmentB newInstance() { - return new TestFragmentB(); - } - - @Override - protected int getLayoutId() { - return R.layout.fragment_test_b; - } - - @Override - protected int getTitleBarId() { - return R.id.tb_test_b_title; - } - - @Override - protected void initView() { - mCountdownView.setOnClickListener(this); - } - - @Override - protected void initData() { - - } - - /** - * {@link View.OnClickListener} - */ - @Override - public void onClick(View v) { - if (v == mCountdownView) { - toast(getResources().getString(R.string.countdown_code_send_succeed)); - } - } - - @Override - public boolean isStatusBarEnabled() { - // 使用沉浸式状态栏 - return !super.isStatusBarEnabled(); - } +package com.hjq.demo.ui.fragment; + +import android.view.View; + +import com.hjq.widget.CountdownView; +import com.hjq.demo.R; +import com.hjq.demo.base.MyLazyFragment; + +import butterknife.BindView; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 项目自定义控件展示 + */ +public class TestFragmentB extends MyLazyFragment + implements View.OnClickListener { + + @BindView(R.id.cv_test_countdown) + CountdownView mCountdownView; + + public static TestFragmentB newInstance() { + return new TestFragmentB(); + } + + @Override + protected int getLayoutId() { + return R.layout.fragment_test_b; + } + + @Override + protected int getTitleBarId() { + return R.id.tb_test_b_title; + } + + @Override + protected void initView() { + mCountdownView.setOnClickListener(this); + } + + @Override + protected void initData() { + + } + + /** + * {@link View.OnClickListener} + */ + @Override + public void onClick(View v) { + if (v == mCountdownView) { + toast(getResources().getString(R.string.countdown_code_send_succeed)); + } + } + + @Override + public boolean isStatusBarEnabled() { + // 使用沉浸式状态栏 + return !super.isStatusBarEnabled(); + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/ui/fragment/TestFragmentC.java b/app/src/main/java/com/hjq/demo/ui/fragment/TestFragmentC.java index 3b6f5087..32ed67cb 100644 --- a/app/src/main/java/com/hjq/demo/ui/fragment/TestFragmentC.java +++ b/app/src/main/java/com/hjq/demo/ui/fragment/TestFragmentC.java @@ -1,125 +1,124 @@ -package com.hjq.demo.ui.fragment; - -import android.view.View; -import android.widget.Button; - -import com.hjq.demo.R; -import com.hjq.demo.common.CommonLazyFragment; -import com.hjq.demo.common.UIActivity; -import com.hjq.permissions.OnPermission; -import com.hjq.permissions.Permission; -import com.hjq.permissions.XXPermissions; -import com.hjq.toast.ToastUtils; - -import java.util.List; - -import butterknife.BindView; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 项目框架使用示例 - */ -public class TestFragmentC extends CommonLazyFragment - implements View.OnClickListener { - - @BindView(R.id.btn_test_toast) - Button mToastView; - @BindView(R.id.btn_test_permission) - Button mPermissionView; - @BindView(R.id.btn_test_state_black) - Button mStateBlackView; - @BindView(R.id.btn_test_state_white) - Button mStateWhiteView; - @BindView(R.id.btn_test_swipe_enabled) - Button mSwipeEnabledView; - @BindView(R.id.btn_test_swipe_disable) - Button mSwipeDisableView; - - public static TestFragmentC newInstance() { - return new TestFragmentC(); - } - - @Override - protected int getLayoutId() { - return R.layout.fragment_test_c; - } - - @Override - protected int getTitleBarId() { - return R.id.tb_test_c_title; - } - - @Override - protected void initView() { - mToastView.setOnClickListener(this); - mPermissionView.setOnClickListener(this); - mStateBlackView.setOnClickListener(this); - mStateWhiteView.setOnClickListener(this); - mSwipeEnabledView.setOnClickListener(this); - mSwipeDisableView.setOnClickListener(this); - } - - @Override - protected void initData() { - - } - - @Override - public boolean isStatusBarEnabled() { - // 使用沉浸式状态栏 - return !super.isStatusBarEnabled(); - } - - /** - * {@link View.OnClickListener} - */ - @Override - public void onClick(View v) { - if (v == mToastView) { - toast("我是吐司"); - }else if (v == mPermissionView) { - XXPermissions.with(getFragmentActivity()) - //.constantRequest() //可设置被拒绝后继续申请,直到用户授权或者永久拒绝 - //.permission(Permission.SYSTEM_ALERT_WINDOW, Permission.REQUEST_INSTALL_PACKAGES) //支持请求6.0悬浮窗权限8.0请求安装权限 - .permission(Permission.CAMERA) //不指定权限则自动获取清单中的危险权限 - .request(new OnPermission() { - - @Override - public void hasPermission(List granted, boolean isAll) { - if (isAll) { - toast("获取权限成功"); - }else { - toast("获取权限成功,部分权限未正常授予"); - } - } - - @Override - public void noPermission(List denied, boolean quick) { - if(quick) { - toast("被永久拒绝授权,请手动授予权限"); - //如果是被永久拒绝就跳转到应用权限系统设置页面 - XXPermissions.gotoPermissionSettings(getFragmentActivity()); - }else { - toast("获取权限失败"); - } - } - }); - }else if (v == mStateBlackView) { - UIActivity activity = (UIActivity) getFragmentActivity(); - activity.getStatusBarConfig().statusBarDarkFont(true).init(); - }else if (v == mStateWhiteView) { - UIActivity activity = (UIActivity) getFragmentActivity(); - activity.getStatusBarConfig().statusBarDarkFont(false).init(); - }else if (v == mSwipeEnabledView) { - UIActivity activity = (UIActivity) getFragmentActivity(); - activity.getSwipeBackHelper().setSwipeBackEnable(true); - toast("当前界面不会生效,其他界面调用才会有效果"); - }else if (v == mSwipeDisableView) { - UIActivity activity = (UIActivity) getFragmentActivity(); - activity.getSwipeBackHelper().setSwipeBackEnable(false); - toast("当前界面不会生效,其他界面调用才会有效果"); - } - } +package com.hjq.demo.ui.fragment; + +import android.view.View; +import android.widget.Button; + +import com.hjq.demo.R; +import com.hjq.demo.base.MyLazyFragment; +import com.hjq.demo.base.UIActivity; +import com.hjq.permissions.OnPermission; +import com.hjq.permissions.Permission; +import com.hjq.permissions.XXPermissions; + +import java.util.List; + +import butterknife.BindView; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 项目框架使用示例 + */ +public class TestFragmentC extends MyLazyFragment + implements View.OnClickListener { + + @BindView(R.id.btn_test_toast) + Button mToastView; + @BindView(R.id.btn_test_permission) + Button mPermissionView; + @BindView(R.id.btn_test_state_black) + Button mStateBlackView; + @BindView(R.id.btn_test_state_white) + Button mStateWhiteView; + @BindView(R.id.btn_test_swipe_enabled) + Button mSwipeEnabledView; + @BindView(R.id.btn_test_swipe_disable) + Button mSwipeDisableView; + + public static TestFragmentC newInstance() { + return new TestFragmentC(); + } + + @Override + protected int getLayoutId() { + return R.layout.fragment_test_c; + } + + @Override + protected int getTitleBarId() { + return R.id.tb_test_c_title; + } + + @Override + protected void initView() { + mToastView.setOnClickListener(this); + mPermissionView.setOnClickListener(this); + mStateBlackView.setOnClickListener(this); + mStateWhiteView.setOnClickListener(this); + mSwipeEnabledView.setOnClickListener(this); + mSwipeDisableView.setOnClickListener(this); + } + + @Override + protected void initData() { + + } + + @Override + public boolean isStatusBarEnabled() { + // 使用沉浸式状态栏 + return !super.isStatusBarEnabled(); + } + + /** + * {@link View.OnClickListener} + */ + @Override + public void onClick(View v) { + if (v == mToastView) { + toast("我是吐司"); + }else if (v == mPermissionView) { + XXPermissions.with(getFragmentActivity()) + //.constantRequest() //可设置被拒绝后继续申请,直到用户授权或者永久拒绝 + //.permission(Permission.SYSTEM_ALERT_WINDOW, Permission.REQUEST_INSTALL_PACKAGES) //支持请求6.0悬浮窗权限8.0请求安装权限 + .permission(Permission.CAMERA) //不指定权限则自动获取清单中的危险权限 + .request(new OnPermission() { + + @Override + public void hasPermission(List granted, boolean isAll) { + if (isAll) { + toast("获取权限成功"); + }else { + toast("获取权限成功,部分权限未正常授予"); + } + } + + @Override + public void noPermission(List denied, boolean quick) { + if(quick) { + toast("被永久拒绝授权,请手动授予权限"); + //如果是被永久拒绝就跳转到应用权限系统设置页面 + XXPermissions.gotoPermissionSettings(getFragmentActivity()); + }else { + toast("获取权限失败"); + } + } + }); + }else if (v == mStateBlackView) { + UIActivity activity = (UIActivity) getFragmentActivity(); + activity.getStatusBarConfig().statusBarDarkFont(true).init(); + }else if (v == mStateWhiteView) { + UIActivity activity = (UIActivity) getFragmentActivity(); + activity.getStatusBarConfig().statusBarDarkFont(false).init(); + }else if (v == mSwipeEnabledView) { + UIActivity activity = (UIActivity) getFragmentActivity(); + activity.getSwipeBackHelper().setSwipeBackEnable(true); + toast("当前界面不会生效,其他界面调用才会有效果"); + }else if (v == mSwipeDisableView) { + UIActivity activity = (UIActivity) getFragmentActivity(); + activity.getSwipeBackHelper().setSwipeBackEnable(false); + toast("当前界面不会生效,其他界面调用才会有效果"); + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/ui/fragment/TestFragmentD.java b/app/src/main/java/com/hjq/demo/ui/fragment/TestFragmentD.java index 65a0db68..dbba9492 100644 --- a/app/src/main/java/com/hjq/demo/ui/fragment/TestFragmentD.java +++ b/app/src/main/java/com/hjq/demo/ui/fragment/TestFragmentD.java @@ -1,84 +1,84 @@ -package com.hjq.demo.ui.fragment; - -import android.view.View; -import android.widget.Button; - -import com.hjq.baselibrary.utils.IntentExtraUtils; -import com.hjq.demo.R; -import com.hjq.demo.common.CommonLazyFragment; -import com.hjq.demo.ui.activity.AboutActivity; -import com.hjq.demo.ui.activity.LoginActivity; -import com.hjq.demo.ui.activity.RegisterActivity; -import com.hjq.demo.ui.activity.WebActivity; - -import butterknife.BindView; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 项目界面跳转示例 - */ -public class TestFragmentD extends CommonLazyFragment - implements View.OnClickListener { - - @BindView(R.id.btn_test_login) - Button mLoginView; - @BindView(R.id.btn_test_register) - Button mRegisterView; - @BindView(R.id.btn_test_about) - Button mAboutView; - @BindView(R.id.btn_test_browser) - Button mBrowserView; - - public static TestFragmentD newInstance() { - return new TestFragmentD(); - } - - @Override - protected int getLayoutId() { - return R.layout.fragment_test_d; - } - - @Override - protected int getTitleBarId() { - return R.id.tb_test_d_title; - } - - @Override - protected void initView() { - mLoginView.setOnClickListener(this); - mRegisterView.setOnClickListener(this); - mAboutView.setOnClickListener(this); - mBrowserView.setOnClickListener(this); - } - - @Override - protected void initData() { - - } - - /** - * {@link View.OnClickListener} - */ - @Override - public void onClick(View v) { - if (v == mLoginView) { - startActivity(LoginActivity.class); - }else if (v == mRegisterView) { - startActivity(RegisterActivity.class); - }else if (v == mAboutView) { - startActivity(AboutActivity.class); - }else if (v == mBrowserView) { - IntentExtraUtils.getInstance(WebActivity.class) - .putString("https://github.com/getActivity/") - .startActivity(getActivity()); - } - } - - @Override - public boolean isStatusBarEnabled() { - // 使用沉浸式状态栏 - return !super.isStatusBarEnabled(); - } +package com.hjq.demo.ui.fragment; + +import android.view.View; +import android.widget.Button; + +import com.hjq.demo.utils.IntentExtraUtils; +import com.hjq.demo.R; +import com.hjq.demo.base.MyLazyFragment; +import com.hjq.demo.ui.activity.AboutActivity; +import com.hjq.demo.ui.activity.LoginActivity; +import com.hjq.demo.ui.activity.RegisterActivity; +import com.hjq.demo.ui.activity.WebActivity; + +import butterknife.BindView; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 项目界面跳转示例 + */ +public class TestFragmentD extends MyLazyFragment + implements View.OnClickListener { + + @BindView(R.id.btn_test_login) + Button mLoginView; + @BindView(R.id.btn_test_register) + Button mRegisterView; + @BindView(R.id.btn_test_about) + Button mAboutView; + @BindView(R.id.btn_test_browser) + Button mBrowserView; + + public static TestFragmentD newInstance() { + return new TestFragmentD(); + } + + @Override + protected int getLayoutId() { + return R.layout.fragment_test_d; + } + + @Override + protected int getTitleBarId() { + return R.id.tb_test_d_title; + } + + @Override + protected void initView() { + mLoginView.setOnClickListener(this); + mRegisterView.setOnClickListener(this); + mAboutView.setOnClickListener(this); + mBrowserView.setOnClickListener(this); + } + + @Override + protected void initData() { + + } + + /** + * {@link View.OnClickListener} + */ + @Override + public void onClick(View v) { + if (v == mLoginView) { + startActivity(LoginActivity.class); + }else if (v == mRegisterView) { + startActivity(RegisterActivity.class); + }else if (v == mAboutView) { + startActivity(AboutActivity.class); + }else if (v == mBrowserView) { + IntentExtraUtils.getInstance(WebActivity.class) + .putString("https://github.com/getActivity/") + .startActivity(getActivity()); + } + } + + @Override + public boolean isStatusBarEnabled() { + // 使用沉浸式状态栏 + return !super.isStatusBarEnabled(); + } } \ No newline at end of file diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/utils/ActivityStackManager.java b/app/src/main/java/com/hjq/demo/utils/ActivityStackManager.java similarity index 98% rename from baselibrary/src/main/java/com/hjq/baselibrary/utils/ActivityStackManager.java rename to app/src/main/java/com/hjq/demo/utils/ActivityStackManager.java index e046354a..403b13e3 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/utils/ActivityStackManager.java +++ b/app/src/main/java/com/hjq/demo/utils/ActivityStackManager.java @@ -1,4 +1,4 @@ -package com.hjq.baselibrary.utils; +package com.hjq.demo.utils; import android.app.Activity; import android.app.Application; diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/utils/DebugUtils.java b/app/src/main/java/com/hjq/demo/utils/DebugUtils.java similarity index 90% rename from baselibrary/src/main/java/com/hjq/baselibrary/utils/DebugUtils.java rename to app/src/main/java/com/hjq/demo/utils/DebugUtils.java index 19afe47c..658e3467 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/utils/DebugUtils.java +++ b/app/src/main/java/com/hjq/demo/utils/DebugUtils.java @@ -1,21 +1,21 @@ -package com.hjq.baselibrary.utils; - -import android.content.Context; -import android.content.pm.ApplicationInfo; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : Debug 判断工具类 - */ -public final class DebugUtils { - - /** - * 当前是否为Debug模式 - */ - public static boolean isDebug(Context context) { - return context.getApplicationInfo() != null - && (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; - } -} +package com.hjq.demo.utils; + +import android.content.Context; +import android.content.pm.ApplicationInfo; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : Debug 判断工具类 + */ +public final class DebugUtils { + + /** + * 当前是否为Debug模式 + */ + public static boolean isDebug(Context context) { + return context.getApplicationInfo() != null + && (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; + } +} diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/utils/DimensUtils.java b/app/src/main/java/com/hjq/demo/utils/DimensUtils.java similarity index 92% rename from baselibrary/src/main/java/com/hjq/baselibrary/utils/DimensUtils.java rename to app/src/main/java/com/hjq/demo/utils/DimensUtils.java index e17f1236..e8aefcbb 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/utils/DimensUtils.java +++ b/app/src/main/java/com/hjq/demo/utils/DimensUtils.java @@ -1,35 +1,35 @@ -package com.hjq.baselibrary.utils; - -import android.content.Context; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 尺寸转换工具类 - */ -public final class DimensUtils { - - /** - * dp转px - * - * @param context 上下文 - * @param dpValue dp值 - * @return px值 - */ - public static int dp2px(Context context, float dpValue) { - final float scale = context.getResources().getDisplayMetrics().density; - return (int) (dpValue * scale + 0.5f); - } - - /** - * sp转px - * @param context 上下文 - * @param spValue sp值 - * @return px值 - */ - public static int sp2px(Context context, float spValue) { - final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; - return (int) (spValue * fontScale + 0.5f); - } -} +package com.hjq.demo.utils; + +import android.content.Context; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 尺寸转换工具类 + */ +public final class DimensUtils { + + /** + * dp转px + * + * @param context 上下文 + * @param dpValue dp值 + * @return px值 + */ + public static int dp2px(Context context, float dpValue) { + final float scale = context.getResources().getDisplayMetrics().density; + return (int) (dpValue * scale + 0.5f); + } + + /** + * sp转px + * @param context 上下文 + * @param spValue sp值 + * @return px值 + */ + public static int sp2px(Context context, float spValue) { + final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; + return (int) (spValue * fontScale + 0.5f); + } +} diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/utils/EditTextInputHelper.java b/app/src/main/java/com/hjq/demo/utils/EditTextInputHelper.java similarity index 98% rename from baselibrary/src/main/java/com/hjq/baselibrary/utils/EditTextInputHelper.java rename to app/src/main/java/com/hjq/demo/utils/EditTextInputHelper.java index 12c16366..5b38b9d7 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/utils/EditTextInputHelper.java +++ b/app/src/main/java/com/hjq/demo/utils/EditTextInputHelper.java @@ -1,4 +1,4 @@ -package com.hjq.baselibrary.utils; +package com.hjq.demo.utils; import android.text.Editable; import android.text.TextWatcher; diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/utils/IntentExtraUtils.java b/app/src/main/java/com/hjq/demo/utils/IntentExtraUtils.java similarity index 95% rename from baselibrary/src/main/java/com/hjq/baselibrary/utils/IntentExtraUtils.java rename to app/src/main/java/com/hjq/demo/utils/IntentExtraUtils.java index 75262b94..7f5c9319 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/utils/IntentExtraUtils.java +++ b/app/src/main/java/com/hjq/demo/utils/IntentExtraUtils.java @@ -1,283 +1,283 @@ -package com.hjq.baselibrary.utils; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; - -import java.util.HashMap; -import java.util.List; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 意图数据存取工具类 - */ -public final class IntentExtraUtils { - - private static Class sCurrentClass; - - private static IntentExtraUtils sInstance; - - private static HashMap sMap; - - private IntentExtraUtils() {} - - public static IntentExtraUtils getInstance(Class cls) { - if (sInstance == null) sInstance = new IntentExtraUtils(); - if (sMap == null) sMap = new HashMap<>(); - sCurrentClass = cls; - return sInstance; - } - - /** - * 跳转到Activity - * - * @param context context对象 - */ - public void startActivity(Context context) { - startActivity(context, false); - } - - /** - * 跳转到Activity后再销毁当前Activity - * - * @param activity activity对象 - */ - public void startActivityFinish(Activity activity) { - startActivity(activity, false); - activity.finish(); - } - - /** - * 跳转到Activity - * - * @param context context对象 - * @param newTask 是否开启新的任务栈 - */ - public void startActivity(Context context, boolean newTask) { - Intent intent = new Intent(context, sCurrentClass); - if (newTask) { - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - } - context.startActivity(intent); - } - - /** - * 跳转到Activity - * - * @param activity activity对象 - * @param requestCode 请求码 - */ - public void startActivity(Activity activity, int requestCode) { - activity.startActivityForResult(new Intent(activity, sCurrentClass), requestCode); - } - - /** - * 设置结果码 - * - * @param activity activity对象 - * @param resultCode 结果码 - */ - public void setResult(Activity activity, int resultCode) { - activity.setResult(resultCode); - } - - /** - * 销毁Activity - * - * @param activity activity对象 - */ - public void finish(Activity activity) { - activity.finish(); - } - - // Object - - public IntentExtraUtils put(Class clazz, Object object) { - return put(sCurrentClass + clazz.getName(), object); - } - - public IntentExtraUtils put(String key, Object object) { - sMap.put(key, object); - return this; - } - - public T get(Class clazz) { - return get(sCurrentClass + clazz.getName()); - } - - public T get(String key) { - T t = (T) sMap.get(key); - //移除这个对象,避免内存泄露 - sMap.remove(key); - return t; - } - - // String - - public IntentExtraUtils putString(String s) { - return put(String.class, s); - } - - public IntentExtraUtils putString(String key, String s) { - return put(key, s); - } - - public String getString() { - return get(String.class); - } - - public String getString(String key) { - return get(key); - } - - // Integer - - public IntentExtraUtils putInteger(Integer i) { - return put(Integer.class, i); - } - - public IntentExtraUtils putInteger(String key, Integer i) { - return put(key, i); - } - - public Integer getInteger() { - return get(Integer.class); - } - - public Integer getInteger(String key) { - return get(key); - } - - // Long - - public IntentExtraUtils putLong(Long l) { - return put(Long.class, l); - } - - public IntentExtraUtils putLong(String key, Long l) { - return put(key, l); - } - - public Long getLong() { - return get(Long.class); - } - - public Long getLong(String key) { - return get(key); - } - - // Boolean - - public IntentExtraUtils putBoolean(Boolean b) { - return put(Boolean.class, b); - } - - public IntentExtraUtils putBoolean(String key, Boolean b) { - return put(key, b); - } - - public Boolean getBoolean() { - return get(Boolean.class); - } - - public Boolean getBoolean(String key) { - return get(key); - } - - // Double - - public IntentExtraUtils putDouble(Double d) { - return put(Double.class, d); - } - - public IntentExtraUtils putDouble(String key, Double d) { - return put(key, d); - } - - public Double getDouble() { - return get(Double.class); - } - - public Double getDouble(String key) { - return get(key); - } - - // Float - - public IntentExtraUtils putFloat(Float f) { - return put(Float.class, f); - } - - public IntentExtraUtils putFloat(String key, Float f) { - return put(key, f); - } - - public Float getFloat() { - return get(Float.class); - } - - public Float getFloat(String key) { - return get(key); - } - - // List - - public IntentExtraUtils putList(List list) { - return put(List.class, list); - } - - public IntentExtraUtils putList(String key, List list) { - return put(key, list); - } - - public List getList() { - return get(List.class); - } - - public List getList(String key) { - return get(key); - } - - public static class Key { - - public static final String ID = "id"; // id - public static final String TOKEN = "token"; // token - public static final String ORDER = "order"; // 订单 - public static final String BALANCE = "balance"; // 余额 - public static final String TIME = "time"; // 时间 - public static final String CODE = "code"; // 错误码或者其他码 - public static final String URL = "url"; // URL - public static final String PATH = "path"; // 路径 - public static final String OTHER = "other"; // 其他 - - // 个人信息 - public static final String NAME = "name"; // 姓名 - public static final String AGE = "age"; // 年龄 - public static final String SEX = "sex"; // 性别 - public static final String PHONE = "phone"; // 手机 - public static final String VIP = "vip"; // 会员 - public static final String DESCRIBE = "describe"; // 描述 - public static final String REMARK = "remark"; // 备注 - public static final String CONSTELLATION = "constellation"; // 星座 - - // 地方 - public static final String ADDRESS = "address"; // 地址 - public static final String PROVINCE = "province"; // 省 - public static final String CITY = "city"; // 市 - public static final String DISTRICT = "district"; // 区 - - // 文件类型相关 - public static final String TXT = "txt"; // 文本 - public static final String PICTURE = "picture"; // 图片 - public static final String VOICE = "voice"; // 音频 - public static final String VIDEO = "video"; // 视频 - - // 支付相关 - public static final String BALANCE_PAY = "balance_pay"; // 余额支付 - public static final String WECHAT_PAY = "wechat_pay"; //微信支付 - public static final String ALI_PAY = "ali_pay"; //支付宝支付 - public static final String UNION_PAY = "union_pay"; // 银联支付 - } +package com.hjq.demo.utils; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; + +import java.util.HashMap; +import java.util.List; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 意图数据存取工具类 + */ +public final class IntentExtraUtils { + + private static Class sCurrentClass; + + private static IntentExtraUtils sInstance; + + private static HashMap sMap; + + private IntentExtraUtils() {} + + public static IntentExtraUtils getInstance(Class cls) { + if (sInstance == null) sInstance = new IntentExtraUtils(); + if (sMap == null) sMap = new HashMap<>(); + sCurrentClass = cls; + return sInstance; + } + + /** + * 跳转到Activity + * + * @param context context对象 + */ + public void startActivity(Context context) { + startActivity(context, false); + } + + /** + * 跳转到Activity后再销毁当前Activity + * + * @param activity activity对象 + */ + public void startActivityFinish(Activity activity) { + startActivity(activity, false); + activity.finish(); + } + + /** + * 跳转到Activity + * + * @param context context对象 + * @param newTask 是否开启新的任务栈 + */ + public void startActivity(Context context, boolean newTask) { + Intent intent = new Intent(context, sCurrentClass); + if (newTask) { + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + } + context.startActivity(intent); + } + + /** + * 跳转到Activity + * + * @param activity activity对象 + * @param requestCode 请求码 + */ + public void startActivity(Activity activity, int requestCode) { + activity.startActivityForResult(new Intent(activity, sCurrentClass), requestCode); + } + + /** + * 设置结果码 + * + * @param activity activity对象 + * @param resultCode 结果码 + */ + public void setResult(Activity activity, int resultCode) { + activity.setResult(resultCode); + } + + /** + * 销毁Activity + * + * @param activity activity对象 + */ + public void finish(Activity activity) { + activity.finish(); + } + + // Object + + public IntentExtraUtils put(Class clazz, Object object) { + return put(sCurrentClass + clazz.getName(), object); + } + + public IntentExtraUtils put(String key, Object object) { + sMap.put(key, object); + return this; + } + + public T get(Class clazz) { + return get(sCurrentClass + clazz.getName()); + } + + public T get(String key) { + T t = (T) sMap.get(key); + //移除这个对象,避免内存泄露 + sMap.remove(key); + return t; + } + + // String + + public IntentExtraUtils putString(String s) { + return put(String.class, s); + } + + public IntentExtraUtils putString(String key, String s) { + return put(key, s); + } + + public String getString() { + return get(String.class); + } + + public String getString(String key) { + return get(key); + } + + // Integer + + public IntentExtraUtils putInteger(Integer i) { + return put(Integer.class, i); + } + + public IntentExtraUtils putInteger(String key, Integer i) { + return put(key, i); + } + + public Integer getInteger() { + return get(Integer.class); + } + + public Integer getInteger(String key) { + return get(key); + } + + // Long + + public IntentExtraUtils putLong(Long l) { + return put(Long.class, l); + } + + public IntentExtraUtils putLong(String key, Long l) { + return put(key, l); + } + + public Long getLong() { + return get(Long.class); + } + + public Long getLong(String key) { + return get(key); + } + + // Boolean + + public IntentExtraUtils putBoolean(Boolean b) { + return put(Boolean.class, b); + } + + public IntentExtraUtils putBoolean(String key, Boolean b) { + return put(key, b); + } + + public Boolean getBoolean() { + return get(Boolean.class); + } + + public Boolean getBoolean(String key) { + return get(key); + } + + // Double + + public IntentExtraUtils putDouble(Double d) { + return put(Double.class, d); + } + + public IntentExtraUtils putDouble(String key, Double d) { + return put(key, d); + } + + public Double getDouble() { + return get(Double.class); + } + + public Double getDouble(String key) { + return get(key); + } + + // Float + + public IntentExtraUtils putFloat(Float f) { + return put(Float.class, f); + } + + public IntentExtraUtils putFloat(String key, Float f) { + return put(key, f); + } + + public Float getFloat() { + return get(Float.class); + } + + public Float getFloat(String key) { + return get(key); + } + + // List + + public IntentExtraUtils putList(List list) { + return put(List.class, list); + } + + public IntentExtraUtils putList(String key, List list) { + return put(key, list); + } + + public List getList() { + return get(List.class); + } + + public List getList(String key) { + return get(key); + } + + public static class Key { + + public static final String ID = "id"; // id + public static final String TOKEN = "token"; // token + public static final String ORDER = "order"; // 订单 + public static final String BALANCE = "balance"; // 余额 + public static final String TIME = "time"; // 时间 + public static final String CODE = "code"; // 错误码或者其他码 + public static final String URL = "url"; // URL + public static final String PATH = "path"; // 路径 + public static final String OTHER = "other"; // 其他 + + // 个人信息 + public static final String NAME = "name"; // 姓名 + public static final String AGE = "age"; // 年龄 + public static final String SEX = "sex"; // 性别 + public static final String PHONE = "phone"; // 手机 + public static final String VIP = "vip"; // 会员 + public static final String DESCRIBE = "describe"; // 描述 + public static final String REMARK = "remark"; // 备注 + public static final String CONSTELLATION = "constellation"; // 星座 + + // 地方 + public static final String ADDRESS = "address"; // 地址 + public static final String PROVINCE = "province"; // 省 + public static final String CITY = "city"; // 市 + public static final String DISTRICT = "district"; // 区 + + // 文件类型相关 + public static final String TXT = "txt"; // 文本 + public static final String PICTURE = "picture"; // 图片 + public static final String VOICE = "voice"; // 音频 + public static final String VIDEO = "video"; // 视频 + + // 支付相关 + public static final String BALANCE_PAY = "balance_pay"; // 余额支付 + public static final String WECHAT_PAY = "wechat_pay"; //微信支付 + public static final String ALI_PAY = "ali_pay"; //支付宝支付 + public static final String UNION_PAY = "union_pay"; // 银联支付 + } } \ No newline at end of file diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/utils/KeyboardUtils.java b/app/src/main/java/com/hjq/demo/utils/KeyboardUtils.java similarity index 94% rename from baselibrary/src/main/java/com/hjq/baselibrary/utils/KeyboardUtils.java rename to app/src/main/java/com/hjq/demo/utils/KeyboardUtils.java index ae02f60d..ee7398ee 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/utils/KeyboardUtils.java +++ b/app/src/main/java/com/hjq/demo/utils/KeyboardUtils.java @@ -1,57 +1,57 @@ -package com.hjq.baselibrary.utils; - -import android.content.Context; -import android.view.View; -import android.view.inputmethod.InputMethodManager; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 软键盘工具类 - */ -public final class KeyboardUtils { - - /** - * 显示软键盘 - * - * @param view 依附的View - */ - public static void showKeyboard(View view) { - if (view == null) return; - InputMethodManager imm = (InputMethodManager) view.getContext() - .getSystemService(Context.INPUT_METHOD_SERVICE); - if (imm != null) { - //view.requestFocus(); - imm.showSoftInput(view, 0); - } - } - - /** - * 隐藏软键盘 - * - * @param view 依附的View - */ - public static void hideKeyboard(View view) { - if (view == null) return; - InputMethodManager imm = (InputMethodManager) view.getContext() - .getSystemService(Context.INPUT_METHOD_SERVICE); - if (imm != null) { - imm.hideSoftInputFromWindow(view.getWindowToken(), 0); - } - } - - /** - * 切换软键盘 - * - * @param view 依附的View - */ - public static void toggleSoftInput(View view) { - if (view == null) return; - InputMethodManager imm = (InputMethodManager) view.getContext() - .getSystemService(Context.INPUT_METHOD_SERVICE); - if (imm != null) { - imm.toggleSoftInput(0, 0); - } - } -} +package com.hjq.demo.utils; + +import android.content.Context; +import android.view.View; +import android.view.inputmethod.InputMethodManager; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 软键盘工具类 + */ +public final class KeyboardUtils { + + /** + * 显示软键盘 + * + * @param view 依附的View + */ + public static void showKeyboard(View view) { + if (view == null) return; + InputMethodManager imm = (InputMethodManager) view.getContext() + .getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) { + //view.requestFocus(); + imm.showSoftInput(view, 0); + } + } + + /** + * 隐藏软键盘 + * + * @param view 依附的View + */ + public static void hideKeyboard(View view) { + if (view == null) return; + InputMethodManager imm = (InputMethodManager) view.getContext() + .getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) { + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } + + /** + * 切换软键盘 + * + * @param view 依附的View + */ + public static void toggleSoftInput(View view) { + if (view == null) return; + InputMethodManager imm = (InputMethodManager) view.getContext() + .getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) { + imm.toggleSoftInput(0, 0); + } + } +} diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/utils/OnClickUtils.java b/app/src/main/java/com/hjq/demo/utils/OnClickUtils.java similarity index 93% rename from baselibrary/src/main/java/com/hjq/baselibrary/utils/OnClickUtils.java rename to app/src/main/java/com/hjq/demo/utils/OnClickUtils.java index f1034e6b..39524cca 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/utils/OnClickUtils.java +++ b/app/src/main/java/com/hjq/demo/utils/OnClickUtils.java @@ -1,28 +1,28 @@ -package com.hjq.baselibrary.utils; - -import android.os.SystemClock; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 防多击判断工具类 - */ -public final class OnClickUtils { - - private static final long[] ONCLICK_TIME = new long[2]; // 数组的长度为2代表只记录双击操作 - private static final int INTERVAL_TIME = 1500; // 限定间隔时长 - - /** - * 是否在短时间内进行了双击操作 - */ - public static boolean isOnDoubleClick() { - System.arraycopy(ONCLICK_TIME, 1, ONCLICK_TIME, 0, ONCLICK_TIME.length - 1); - ONCLICK_TIME[ONCLICK_TIME.length - 1] = SystemClock.uptimeMillis(); - if (ONCLICK_TIME[0] >= (SystemClock.uptimeMillis() - INTERVAL_TIME)) { - return true; - }else { - return false; - } - } -} +package com.hjq.demo.utils; + +import android.os.SystemClock; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 防多击判断工具类 + */ +public final class OnClickUtils { + + private static final long[] ONCLICK_TIME = new long[2]; // 数组的长度为2代表只记录双击操作 + private static final int INTERVAL_TIME = 1500; // 限定间隔时长 + + /** + * 是否在短时间内进行了双击操作 + */ + public static boolean isOnDoubleClick() { + System.arraycopy(ONCLICK_TIME, 1, ONCLICK_TIME, 0, ONCLICK_TIME.length - 1); + ONCLICK_TIME[ONCLICK_TIME.length - 1] = SystemClock.uptimeMillis(); + if (ONCLICK_TIME[0] >= (SystemClock.uptimeMillis() - INTERVAL_TIME)) { + return true; + }else { + return false; + } + } +} diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/utils/PopupWindowHelper.java b/app/src/main/java/com/hjq/demo/utils/PopupWindowHelper.java similarity index 95% rename from baselibrary/src/main/java/com/hjq/baselibrary/utils/PopupWindowHelper.java rename to app/src/main/java/com/hjq/demo/utils/PopupWindowHelper.java index 1f22946f..b5beb3f7 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/utils/PopupWindowHelper.java +++ b/app/src/main/java/com/hjq/demo/utils/PopupWindowHelper.java @@ -1,122 +1,122 @@ -package com.hjq.baselibrary.utils; - -import android.content.Context; -import android.graphics.Color; -import android.graphics.drawable.ColorDrawable; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.view.View; -import android.view.ViewGroup; -import android.view.animation.Animation; -import android.view.animation.ScaleAnimation; -import android.widget.PopupWindow; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : PopupWindow辅助类 - */ -public final class PopupWindowHelper implements PopupWindow.OnDismissListener { - - private PopupWindow mPopupWindow; // PopupWindow对象 - private final View mPopupView; //PopupWindow显示的View - private long mDismissTime; // 记录PopupWindow销毁时间 - - public PopupWindowHelper(View popupView) { - mPopupView = popupView; - } - - public PopupWindowHelper(Context context, int layoutId) { - mPopupView = View.inflate(context, layoutId, null); - } - - /** - * 初始化PopupWindow - */ - private void initPopupWindow() { - // 给PopupWindow的View设置缩放动画 - ScaleAnimation sa = new ScaleAnimation(0.5f, 1.0f, 0.5f, 1.0f, - Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); - sa.setDuration(200); - mPopupView.startAnimation(sa); - - mPopupWindow = new PopupWindow(mPopupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - // 需要在popupWindow使用动画,必须先设置背景,否则动画不能显示出效果,为了不和当前的背景冲突,这里设置全透明背景的图片 - mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); - // 设置外部可触的,点击其他地方会自动消失 - mPopupWindow.setTouchable(true); - mPopupWindow.setFocusable(true); - mPopupWindow.setOutsideTouchable(true); - // 监听PopupWindow销毁监听 - mPopupWindow.setOnDismissListener(this); - } - - /** - * {@link PopupWindow.OnDismissListener} - */ - @Override - public void onDismiss() { - // 记录当前销毁的时间 - mDismissTime = System.currentTimeMillis(); - } - - /** - * 显示一个PopupWindow - * - * @param clickView PopupWindow显示在什么View的下方 - */ - public void show(View clickView) { - - // 如果PopupWindow还未初始化就先进行初始化 - if (mPopupWindow == null) { - initPopupWindow(); - } - - // 避免用户点击clickView导致的销毁后再次显示的Bug - if (System.currentTimeMillis() - mDismissTime < 500) { - return; - } - - /* - //获取某个view对象在窗口的位置,然后计算出PopupWindow的位置 - int[] location = new int[2]; - mClickView.getLocationInWindow(location); - - //将PopupWindow显示出来 - mPopupWindow.showAtLocation(mParentView, Gravity.LEFT + Gravity.TOP, 0, location[1] + mClickView.getHeight()); - */ - - mPopupWindow.showAsDropDown(clickView); - } - - /** - * 销毁当前的PopupWindow - */ - public void dismiss() { - if (isShowing()) { - mPopupWindow.dismiss(); - } - } - - /** - * 当前PopupWindow是否已经显示 - */ - public boolean isShowing() { - return mPopupWindow != null && mPopupWindow.isShowing(); - } - - /** - * 获取当前的PopupWindow对象 - */ - public @Nullable PopupWindow getPopupWindow() { - return mPopupWindow; - } - - /** - * 获取当前的PopupWindow的View对象 - */ - public @NonNull View getPopupView() { - return mPopupView; - } -} +package com.hjq.demo.utils; + +import android.content.Context; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.view.View; +import android.view.ViewGroup; +import android.view.animation.Animation; +import android.view.animation.ScaleAnimation; +import android.widget.PopupWindow; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : PopupWindow辅助类 + */ +public final class PopupWindowHelper implements PopupWindow.OnDismissListener { + + private PopupWindow mPopupWindow; // PopupWindow对象 + private final View mPopupView; //PopupWindow显示的View + private long mDismissTime; // 记录PopupWindow销毁时间 + + public PopupWindowHelper(View popupView) { + mPopupView = popupView; + } + + public PopupWindowHelper(Context context, int layoutId) { + mPopupView = View.inflate(context, layoutId, null); + } + + /** + * 初始化PopupWindow + */ + private void initPopupWindow() { + // 给PopupWindow的View设置缩放动画 + ScaleAnimation sa = new ScaleAnimation(0.5f, 1.0f, 0.5f, 1.0f, + Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); + sa.setDuration(200); + mPopupView.startAnimation(sa); + + mPopupWindow = new PopupWindow(mPopupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + // 需要在popupWindow使用动画,必须先设置背景,否则动画不能显示出效果,为了不和当前的背景冲突,这里设置全透明背景的图片 + mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + // 设置外部可触的,点击其他地方会自动消失 + mPopupWindow.setTouchable(true); + mPopupWindow.setFocusable(true); + mPopupWindow.setOutsideTouchable(true); + // 监听PopupWindow销毁监听 + mPopupWindow.setOnDismissListener(this); + } + + /** + * {@link PopupWindow.OnDismissListener} + */ + @Override + public void onDismiss() { + // 记录当前销毁的时间 + mDismissTime = System.currentTimeMillis(); + } + + /** + * 显示一个PopupWindow + * + * @param clickView PopupWindow显示在什么View的下方 + */ + public void show(View clickView) { + + // 如果PopupWindow还未初始化就先进行初始化 + if (mPopupWindow == null) { + initPopupWindow(); + } + + // 避免用户点击clickView导致的销毁后再次显示的Bug + if (System.currentTimeMillis() - mDismissTime < 500) { + return; + } + + /* + //获取某个view对象在窗口的位置,然后计算出PopupWindow的位置 + int[] location = new int[2]; + mClickView.getLocationInWindow(location); + + //将PopupWindow显示出来 + mPopupWindow.showAtLocation(mParentView, Gravity.LEFT + Gravity.TOP, 0, location[1] + mClickView.getHeight()); + */ + + mPopupWindow.showAsDropDown(clickView); + } + + /** + * 销毁当前的PopupWindow + */ + public void dismiss() { + if (isShowing()) { + mPopupWindow.dismiss(); + } + } + + /** + * 当前PopupWindow是否已经显示 + */ + public boolean isShowing() { + return mPopupWindow != null && mPopupWindow.isShowing(); + } + + /** + * 获取当前的PopupWindow对象 + */ + public @Nullable PopupWindow getPopupWindow() { + return mPopupWindow; + } + + /** + * 获取当前的PopupWindow的View对象 + */ + public @NonNull View getPopupView() { + return mPopupView; + } +} diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/utils/RadioButtonGroupHelper.java b/app/src/main/java/com/hjq/demo/utils/RadioButtonGroupHelper.java similarity index 95% rename from baselibrary/src/main/java/com/hjq/baselibrary/utils/RadioButtonGroupHelper.java rename to app/src/main/java/com/hjq/demo/utils/RadioButtonGroupHelper.java index 6a376899..abf87a6c 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/utils/RadioButtonGroupHelper.java +++ b/app/src/main/java/com/hjq/demo/utils/RadioButtonGroupHelper.java @@ -1,110 +1,110 @@ -package com.hjq.baselibrary.utils; - -import android.support.annotation.IdRes; -import android.view.View; -import android.widget.CompoundButton; -import android.widget.RadioButton; - -import java.util.ArrayList; -import java.util.List; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 多个 CompoundButton 选中处理辅助类(用于代替 RadioGroup) - */ -public final class RadioButtonGroupHelper implements CompoundButton.OnCheckedChangeListener { - - private List mViewSet;//RadioButton集合 - - private OnCheckedChangeListener mListener;//多个RadioButton监听对象 - - public RadioButtonGroupHelper(RadioButton... groups) { - mViewSet = new ArrayList<>(groups.length - 1); - - for (RadioButton view : groups) { - // 如果这个RadioButton没有设置id的话 - if (view.getId() == View.NO_ID) { - throw new IllegalArgumentException("The resource id must be set for the RadioButton"); - } - view.setOnCheckedChangeListener(this); - mViewSet.add(view); - } - } - - public RadioButtonGroupHelper(View rootView, @IdRes int... ids) { - mViewSet = new ArrayList<>(ids.length - 1); - for (int id : ids) { - RadioButton view = rootView.findViewById(id); - view.setOnCheckedChangeListener(this); - mViewSet.add(view); - } - } - - private boolean mTag; // 监听标记,避免重复回调 - - /** - * {@link CompoundButton.OnCheckedChangeListener} - */ - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked && !mTag) { - mTag = true; - for (CompoundButton view : mViewSet) { - if (view != buttonView && view.isChecked()) { - // 这个 API 会触发监听事件 - view.setChecked(false); - } - } - if (mListener != null) { - mListener.onCheckedChanged((RadioButton) buttonView, buttonView.getId()); - } - mTag = false; - } - } - - /** - * 移除监听,避免内存泄露 - */ - public void removeViews() { - if (mViewSet == null) return; - - for (CompoundButton view : mViewSet) { - view.setOnCheckedChangeListener(null); - } - mViewSet.clear(); - mViewSet = null; - } - - /** - * 取消选中 - */ - public void clearCheck() { - for (CompoundButton view : mViewSet) { - if (view.isChecked()) { - view.setChecked(false); - } - } - } - - /** - * 设置多个RadioButton的监听 - */ - public void setOnCheckedChangeListener(OnCheckedChangeListener l) { - mListener = l; - } - - /** - * 多个CompoundButton选中监听 - */ - public interface OnCheckedChangeListener { - /** - * 被选中的CompoundButton对象 - * - * @param radioButton 选中的RadioButton - * @param checkedId 选中的资源id - */ - void onCheckedChanged(RadioButton radioButton, @IdRes int checkedId); - } +package com.hjq.demo.utils; + +import android.support.annotation.IdRes; +import android.view.View; +import android.widget.CompoundButton; +import android.widget.RadioButton; + +import java.util.ArrayList; +import java.util.List; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 多个 CompoundButton 选中处理辅助类(用于代替 RadioGroup) + */ +public final class RadioButtonGroupHelper implements CompoundButton.OnCheckedChangeListener { + + private List mViewSet;//RadioButton集合 + + private OnCheckedChangeListener mListener;//多个RadioButton监听对象 + + public RadioButtonGroupHelper(RadioButton... groups) { + mViewSet = new ArrayList<>(groups.length - 1); + + for (RadioButton view : groups) { + // 如果这个RadioButton没有设置id的话 + if (view.getId() == View.NO_ID) { + throw new IllegalArgumentException("The resource id must be set for the RadioButton"); + } + view.setOnCheckedChangeListener(this); + mViewSet.add(view); + } + } + + public RadioButtonGroupHelper(View rootView, @IdRes int... ids) { + mViewSet = new ArrayList<>(ids.length - 1); + for (int id : ids) { + RadioButton view = rootView.findViewById(id); + view.setOnCheckedChangeListener(this); + mViewSet.add(view); + } + } + + private boolean mTag; // 监听标记,避免重复回调 + + /** + * {@link CompoundButton.OnCheckedChangeListener} + */ + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked && !mTag) { + mTag = true; + for (CompoundButton view : mViewSet) { + if (view != buttonView && view.isChecked()) { + // 这个 API 会触发监听事件 + view.setChecked(false); + } + } + if (mListener != null) { + mListener.onCheckedChanged((RadioButton) buttonView, buttonView.getId()); + } + mTag = false; + } + } + + /** + * 移除监听,避免内存泄露 + */ + public void removeViews() { + if (mViewSet == null) return; + + for (CompoundButton view : mViewSet) { + view.setOnCheckedChangeListener(null); + } + mViewSet.clear(); + mViewSet = null; + } + + /** + * 取消选中 + */ + public void clearCheck() { + for (CompoundButton view : mViewSet) { + if (view.isChecked()) { + view.setChecked(false); + } + } + } + + /** + * 设置多个RadioButton的监听 + */ + public void setOnCheckedChangeListener(OnCheckedChangeListener l) { + mListener = l; + } + + /** + * 多个CompoundButton选中监听 + */ + public interface OnCheckedChangeListener { + /** + * 被选中的CompoundButton对象 + * + * @param radioButton 选中的RadioButton + * @param checkedId 选中的资源id + */ + void onCheckedChanged(RadioButton radioButton, @IdRes int checkedId); + } } \ No newline at end of file diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/utils/WebViewLifecycleUtils.java b/app/src/main/java/com/hjq/demo/utils/WebViewLifecycleUtils.java similarity index 93% rename from baselibrary/src/main/java/com/hjq/baselibrary/utils/WebViewLifecycleUtils.java rename to app/src/main/java/com/hjq/demo/utils/WebViewLifecycleUtils.java index 58ba835e..0be24aed 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/utils/WebViewLifecycleUtils.java +++ b/app/src/main/java/com/hjq/demo/utils/WebViewLifecycleUtils.java @@ -1,39 +1,39 @@ -package com.hjq.baselibrary.utils; - -import android.view.ViewGroup; -import android.webkit.WebView; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : WebView 生命周期优化工具 - */ -public final class WebViewLifecycleUtils { - - public static void onResume(WebView webView) { - webView.onResume(); - webView.resumeTimers(); - } - - public static void onPause(WebView webView) { - webView.onPause(); - webView.pauseTimers(); - } - - public static void onDestroy(WebView webView) { - ((ViewGroup) webView.getParent()).removeView(webView); - //清除历史记录 - webView.clearHistory(); - //停止加载 - webView.stopLoading(); - //加载一个空白页 - webView.loadUrl("about:blank"); - webView.setWebChromeClient(null); - webView.setWebViewClient(null); - //移除WebView所有的View对象 - webView.removeAllViews(); - //销毁此的WebView的内部状态 - webView.destroy(); - } +package com.hjq.demo.utils; + +import android.view.ViewGroup; +import android.webkit.WebView; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : WebView 生命周期优化工具 + */ +public final class WebViewLifecycleUtils { + + public static void onResume(WebView webView) { + webView.onResume(); + webView.resumeTimers(); + } + + public static void onPause(WebView webView) { + webView.onPause(); + webView.pauseTimers(); + } + + public static void onDestroy(WebView webView) { + ((ViewGroup) webView.getParent()).removeView(webView); + //清除历史记录 + webView.clearHistory(); + //停止加载 + webView.stopLoading(); + //加载一个空白页 + webView.loadUrl("about:blank"); + webView.setWebChromeClient(null); + webView.setWebViewClient(null); + //移除WebView所有的View对象 + webView.removeAllViews(); + //销毁此的WebView的内部状态 + webView.destroy(); + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/widget/XCollapsingToolbarLayout.java b/app/src/main/java/com/hjq/demo/widget/XCollapsingToolbarLayout.java index 0bff8b5f..a61bf761 100644 --- a/app/src/main/java/com/hjq/demo/widget/XCollapsingToolbarLayout.java +++ b/app/src/main/java/com/hjq/demo/widget/XCollapsingToolbarLayout.java @@ -1,69 +1,69 @@ -package com.hjq.demo.widget; - -import android.content.Context; -import android.support.design.widget.CollapsingToolbarLayout; -import android.util.AttributeSet; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 支持监听渐变的CollapsingToolbarLayout - */ -public class XCollapsingToolbarLayout extends CollapsingToolbarLayout { - - private OnScrimsListener mListener; // 渐变监听 - private boolean isScrimsShown; // 当前渐变状态 - - public XCollapsingToolbarLayout(Context context) { - super(context); - } - - public XCollapsingToolbarLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public XCollapsingToolbarLayout(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - @Override - public void setScrimsShown(boolean shown, boolean animate) { - super.setScrimsShown(shown, true); - // 判断渐变状态是否改变了 - if (isScrimsShown != shown) { - // 如果是就记录并且回调监听器 - isScrimsShown = shown; - if (mListener != null) { - mListener.onScrimsStateChange(isScrimsShown); - } - } - } - - /** - * 获取当前的渐变状态 - */ - public boolean isScrimsShown() { - return isScrimsShown; - } - - /** - * 设置CollapsingToolbarLayout渐变监听 - */ - public void setOnScrimsListener(OnScrimsListener l) { - mListener = l; - } - - /** - * CollapsingToolbarLayout渐变监听器 - */ - public interface OnScrimsListener { - - /** - * 渐变状态变化 - * - * @param shown 渐变开关 - */ - void onScrimsStateChange(boolean shown); - } +package com.hjq.demo.widget; + +import android.content.Context; +import android.support.design.widget.CollapsingToolbarLayout; +import android.util.AttributeSet; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 支持监听渐变的CollapsingToolbarLayout + */ +public class XCollapsingToolbarLayout extends CollapsingToolbarLayout { + + private OnScrimsListener mListener; // 渐变监听 + private boolean isScrimsShown; // 当前渐变状态 + + public XCollapsingToolbarLayout(Context context) { + super(context); + } + + public XCollapsingToolbarLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public XCollapsingToolbarLayout(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + public void setScrimsShown(boolean shown, boolean animate) { + super.setScrimsShown(shown, true); + // 判断渐变状态是否改变了 + if (isScrimsShown != shown) { + // 如果是就记录并且回调监听器 + isScrimsShown = shown; + if (mListener != null) { + mListener.onScrimsStateChange(isScrimsShown); + } + } + } + + /** + * 获取当前的渐变状态 + */ + public boolean isScrimsShown() { + return isScrimsShown; + } + + /** + * 设置CollapsingToolbarLayout渐变监听 + */ + public void setOnScrimsListener(OnScrimsListener l) { + mListener = l; + } + + /** + * CollapsingToolbarLayout渐变监听器 + */ + public interface OnScrimsListener { + + /** + * 渐变状态变化 + * + * @param shown 渐变开关 + */ + void onScrimsStateChange(boolean shown); + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml index 78dd209c..8704eedf 100644 --- a/app/src/main/res/layout/activity_home.xml +++ b/app/src/main/res/layout/activity_home.xml @@ -7,7 +7,7 @@ android:orientation="vertical" tools:context=".ui.activity.HomeActivity"> - - - - - - - - + - - + - @@ -172,9 +172,9 @@ android:text="这是一个正方形的RelativeLayout" android:textColor="@color/white" /> - + - \ No newline at end of file diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/base/BaseActivity.java b/base/src/main/java/com/hjq/base/BaseActivity.java similarity index 84% rename from baselibrary/src/main/java/com/hjq/baselibrary/base/BaseActivity.java rename to base/src/main/java/com/hjq/base/BaseActivity.java index 9a7dd5f6..30579169 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/base/BaseActivity.java +++ b/base/src/main/java/com/hjq/base/BaseActivity.java @@ -1,98 +1,102 @@ -package com.hjq.baselibrary.base; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.os.Handler; -import android.support.v7.app.AppCompatActivity; - -import com.hjq.baselibrary.utils.KeyboardUtils; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : Activity 基类 - */ -public abstract class BaseActivity extends AppCompatActivity { - - // 单例的 Handler 对象 - private static final Handler HANDLER = new Handler(); - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - if (getLayoutId() > 0) { - setContentView(getLayoutId()); - } - - init(); - } - - public void init(){ - initView(); - initData(); - } - - //引入布局 - protected abstract int getLayoutId(); - - //标题栏id - protected abstract int getTitleBarId(); - - //初始化控件 - protected abstract void initView(); - - //初始化数据 - protected abstract void initData(); - - @Override - public void finish() { - // 隐藏软键盘,避免软键盘引发的内存泄露 - KeyboardUtils.hideKeyboard(getCurrentFocus()); - super.finish(); - } - - /** - * 获取一个 Context 对象 - */ - public Context getContext() { - return getBaseContext(); - } - - - /** - * 获取当前 Activity 对象 - */ - public A getActivity() { - return (A) this; - } - - /** - * 跳转到其他 Activity - * - * @param cls 目标Activity的Class - */ - public void startActivity(Class cls) { - startActivity(new Intent(this, cls)); - } - - /** - * 跳转到其他 Activity 并销毁当前 Activity - * - * @param cls 目标Activity的Class - */ - public void startActivityFinish(Class cls) { - startActivity(cls); - finish(); - } - - /** - * 获取一个 Handler 对象 - */ - public static Handler getHandler() { - return HANDLER; - } +package com.hjq.base; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.view.inputmethod.InputMethodManager; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : Activity 基类 + */ +public abstract class BaseActivity extends AppCompatActivity { + + // 单例的 Handler 对象 + private static final Handler HANDLER = new Handler(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (getLayoutId() > 0) { + setContentView(getLayoutId()); + } + + init(); + } + + public void init(){ + initView(); + initData(); + } + + //引入布局 + protected abstract int getLayoutId(); + + //标题栏id + protected abstract int getTitleBarId(); + + //初始化控件 + protected abstract void initView(); + + //初始化数据 + protected abstract void initData(); + + @Override + public void finish() { + // 隐藏软键盘,避免软键盘引发的内存泄露 + View view = getCurrentFocus(); + if (view != null) { + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + super.finish(); + } + + /** + * 获取一个 Context 对象 + */ + public Context getContext() { + return getBaseContext(); + } + + + /** + * 获取当前 Activity 对象 + */ + public A getActivity() { + return (A) this; + } + + /** + * 跳转到其他 Activity + * + * @param cls 目标Activity的Class + */ + public void startActivity(Class cls) { + startActivity(new Intent(this, cls)); + } + + /** + * 跳转到其他 Activity 并销毁当前 Activity + * + * @param cls 目标Activity的Class + */ + public void startActivityFinish(Class cls) { + startActivity(cls); + finish(); + } + + /** + * 获取一个 Handler 对象 + */ + public static Handler getHandler() { + return HANDLER; + } } \ No newline at end of file diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/base/BaseActivityHandler.java b/base/src/main/java/com/hjq/base/BaseActivityHandler.java similarity index 92% rename from baselibrary/src/main/java/com/hjq/baselibrary/base/BaseActivityHandler.java rename to base/src/main/java/com/hjq/base/BaseActivityHandler.java index 4862f953..6417d37c 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/base/BaseActivityHandler.java +++ b/base/src/main/java/com/hjq/base/BaseActivityHandler.java @@ -1,43 +1,43 @@ -package com.hjq.baselibrary.base; - -import android.app.Activity; -import android.os.Handler; - -import java.lang.ref.WeakReference; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 在 Activity 中优化 Handler 基类 - */ -public abstract class BaseActivityHandler extends Handler { - - private final WeakReference mActivity; - - public BaseActivityHandler(T activity) { - mActivity = new WeakReference<>(activity); - } - - /** - * 判断当前Handler是否可用 - */ - public boolean isEnabled() { - return getActivity() != null && !getActivity().isFinishing(); - } - - /** - * 获取Activity对象 - */ - public T getActivity() { - return mActivity.get(); - } - - /** - * 在Activity销毁前移除所有的任务 - */ - public void onDestroy() { - //删除所有的回调函数和消息 - removeCallbacksAndMessages(null); - } +package com.hjq.base; + +import android.app.Activity; +import android.os.Handler; + +import java.lang.ref.WeakReference; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 在 Activity 中优化 Handler 基类 + */ +public abstract class BaseActivityHandler extends Handler { + + private final WeakReference mActivity; + + public BaseActivityHandler(T activity) { + mActivity = new WeakReference<>(activity); + } + + /** + * 判断当前Handler是否可用 + */ + public boolean isEnabled() { + return getActivity() != null && !getActivity().isFinishing(); + } + + /** + * 获取Activity对象 + */ + public T getActivity() { + return mActivity.get(); + } + + /** + * 在Activity销毁前移除所有的任务 + */ + public void onDestroy() { + //删除所有的回调函数和消息 + removeCallbacksAndMessages(null); + } } \ No newline at end of file diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/base/BaseDialog.java b/base/src/main/java/com/hjq/base/BaseDialog.java similarity index 99% rename from baselibrary/src/main/java/com/hjq/baselibrary/base/BaseDialog.java rename to base/src/main/java/com/hjq/base/BaseDialog.java index 0682fdf4..771dd635 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/base/BaseDialog.java +++ b/base/src/main/java/com/hjq/base/BaseDialog.java @@ -1,4 +1,4 @@ -package com.hjq.baselibrary.base; +package com.hjq.base; import android.content.Context; import android.content.DialogInterface; @@ -14,8 +14,6 @@ import android.widget.ImageView; import android.widget.TextView; -import com.hjq.baselibrary.R; - /** * author : HJQ * github : https://github.com/getActivity/AndroidProject diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/base/BaseDialogFragment.java b/base/src/main/java/com/hjq/base/BaseDialogFragment.java similarity index 96% rename from baselibrary/src/main/java/com/hjq/baselibrary/base/BaseDialogFragment.java rename to base/src/main/java/com/hjq/base/BaseDialogFragment.java index 97814d90..23c8a74b 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/base/BaseDialogFragment.java +++ b/base/src/main/java/com/hjq/base/BaseDialogFragment.java @@ -1,4 +1,4 @@ -package com.hjq.baselibrary.base; +package com.hjq.base; import android.app.Dialog; import android.os.Bundle; diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/base/BaseFragmentPagerAdapter.java b/base/src/main/java/com/hjq/base/BaseFragmentPagerAdapter.java similarity index 94% rename from baselibrary/src/main/java/com/hjq/baselibrary/base/BaseFragmentPagerAdapter.java rename to base/src/main/java/com/hjq/base/BaseFragmentPagerAdapter.java index d52b048d..ebdb7241 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/base/BaseFragmentPagerAdapter.java +++ b/base/src/main/java/com/hjq/base/BaseFragmentPagerAdapter.java @@ -1,78 +1,78 @@ -package com.hjq.baselibrary.base; - -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentActivity; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; -import android.view.ViewGroup; - -import java.util.ArrayList; -import java.util.List; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : FragmentPagerAdapter 基类 - */ -public abstract class BaseFragmentPagerAdapter extends FragmentPagerAdapter { - - private List mFragmentSet = new ArrayList<>(); // Fragment集合 - - private T mCurrentFragment; // 当前显示的Fragment - - /** - * 在Activity中使用ViewPager适配器 - */ - public BaseFragmentPagerAdapter(FragmentActivity activity) { - this(activity.getSupportFragmentManager()); - } - - /** - * 在Fragment中使用ViewPager适配器 - */ - public BaseFragmentPagerAdapter(Fragment fragment) { - this(fragment.getChildFragmentManager()); - } - - public BaseFragmentPagerAdapter(FragmentManager fm) { - super(fm); - init(fm, mFragmentSet); - } - - //初始化Fragment - protected abstract void init(FragmentManager fm, List list); - - @Override - public T getItem(int position) { - return mFragmentSet.get(position); - } - - @Override - public int getCount() { - return mFragmentSet.size(); - } - - @Override - public void setPrimaryItem(ViewGroup container, int position, Object object) { - if (getCurrentFragment() != object) { - // 记录当前的Fragment对象 - mCurrentFragment = (T) object; - } - super.setPrimaryItem(container, position, object); - } - - /** - * 获取Fragment集合 - */ - public List getAllFragment() { - return mFragmentSet; - } - - /** - * 获取当前的Fragment - */ - public T getCurrentFragment() { - return mCurrentFragment; - } +package com.hjq.base; + +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; +import android.view.ViewGroup; + +import java.util.ArrayList; +import java.util.List; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : FragmentPagerAdapter 基类 + */ +public abstract class BaseFragmentPagerAdapter extends FragmentPagerAdapter { + + private List mFragmentSet = new ArrayList<>(); // Fragment集合 + + private T mCurrentFragment; // 当前显示的Fragment + + /** + * 在Activity中使用ViewPager适配器 + */ + public BaseFragmentPagerAdapter(FragmentActivity activity) { + this(activity.getSupportFragmentManager()); + } + + /** + * 在Fragment中使用ViewPager适配器 + */ + public BaseFragmentPagerAdapter(Fragment fragment) { + this(fragment.getChildFragmentManager()); + } + + public BaseFragmentPagerAdapter(FragmentManager fm) { + super(fm); + init(fm, mFragmentSet); + } + + //初始化Fragment + protected abstract void init(FragmentManager fm, List list); + + @Override + public T getItem(int position) { + return mFragmentSet.get(position); + } + + @Override + public int getCount() { + return mFragmentSet.size(); + } + + @Override + public void setPrimaryItem(ViewGroup container, int position, Object object) { + if (getCurrentFragment() != object) { + // 记录当前的Fragment对象 + mCurrentFragment = (T) object; + } + super.setPrimaryItem(container, position, object); + } + + /** + * 获取Fragment集合 + */ + public List getAllFragment() { + return mFragmentSet; + } + + /** + * 获取当前的Fragment + */ + public T getCurrentFragment() { + return mCurrentFragment; + } } \ No newline at end of file diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/base/BaseLazyFragment.java b/base/src/main/java/com/hjq/base/BaseLazyFragment.java similarity index 95% rename from baselibrary/src/main/java/com/hjq/baselibrary/base/BaseLazyFragment.java rename to base/src/main/java/com/hjq/base/BaseLazyFragment.java index 87a330f8..417f8d3c 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/base/BaseLazyFragment.java +++ b/base/src/main/java/com/hjq/base/BaseLazyFragment.java @@ -1,4 +1,4 @@ -package com.hjq.baselibrary.base; +package com.hjq.base; import android.app.Activity; import android.content.Context; diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/base/BaseListViewAdapter.java b/base/src/main/java/com/hjq/base/BaseListViewAdapter.java similarity index 95% rename from baselibrary/src/main/java/com/hjq/baselibrary/base/BaseListViewAdapter.java rename to base/src/main/java/com/hjq/base/BaseListViewAdapter.java index 028254a9..004106a4 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/base/BaseListViewAdapter.java +++ b/base/src/main/java/com/hjq/base/BaseListViewAdapter.java @@ -1,4 +1,4 @@ -package com.hjq.baselibrary.base; +package com.hjq.base; import android.content.Context; import android.support.annotation.ColorInt; diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/base/BaseRecyclerViewAdapter.java b/base/src/main/java/com/hjq/base/BaseRecyclerViewAdapter.java similarity index 96% rename from baselibrary/src/main/java/com/hjq/baselibrary/base/BaseRecyclerViewAdapter.java rename to base/src/main/java/com/hjq/base/BaseRecyclerViewAdapter.java index a402ab7f..61b89001 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/base/BaseRecyclerViewAdapter.java +++ b/base/src/main/java/com/hjq/base/BaseRecyclerViewAdapter.java @@ -1,455 +1,455 @@ -package com.hjq.baselibrary.base; - -import android.content.Context; -import android.support.annotation.ColorInt; -import android.support.annotation.IdRes; -import android.support.annotation.NonNull; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.util.SparseArray; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : RecyclerView 适配器基类 - */ -public abstract class BaseRecyclerViewAdapter - extends RecyclerView.Adapter { - //列表数据 - private List mDataSet; - //RecyclerView对象 - private RecyclerView mRecyclerView; - //上下文对象,注意不要在构造函数中使用 - private Context mContext; - - //当前列表的页码,默认为第一页,用于分页加载功能 - private int mPageNumber = 1; - //是否是最后一页,默认为false,用于分页加载功能 - private boolean mLastPage; - //标记对象 - private Object mTag; - - public BaseRecyclerViewAdapter(Context context) { - mContext = context; - } - - @Override - public int getItemCount() { - return mDataSet == null ? 0 : mDataSet.size(); - } - - @Override - public long getItemId(int position) { - return position; - } - - /** - * 设置新的数据 - */ - public void setData(List data) { - mDataSet = data; - notifyDataSetChanged(); - } - - /** - * 获取当前数据 - */ - public List getData() { - return mDataSet; - } - - /** - * 追加一些数据 - */ - public void addData(List data) { - //追加的数据不能为空 - if (data == null || data.size() == 0) return; - - if (mDataSet == null || mDataSet.size() == 0) { - setData(data); - }else { - mDataSet.addAll(data); - notifyItemRangeInserted(mDataSet.size() - data.size(), data.size()); - } - } - - /** - * 清空当前数据 - */ - public void clearData() { - //当前的数据不能为空 - if (mDataSet == null || mDataSet.size() == 0) return; - - mDataSet.clear(); - notifyDataSetChanged(); - } - - /** - * 获取某个位置上的数据 - */ - public T getItem(int position) { - return mDataSet.get(position); - } - - /** - * 更新某个位置上的数据 - */ - public void setItem(int position, T item) { - if (mDataSet == null) mDataSet = new ArrayList<>(); - mDataSet.set(position, item); - notifyItemChanged(position); - } - - /** - * 添加单条数据 - */ - public void addItem(T item) { - addItem(mDataSet.size() - 1, item); - } - - public void addItem(int position, T item) { - if (mDataSet == null) mDataSet = new ArrayList<>(); - - //如果是在for循环添加后要记得position++ - if (position < mDataSet.size()) { - mDataSet.add(position, item); - }else { - mDataSet.add(item); - position = mDataSet.size() - 1; - } - //告诉适配器添加数据的位置,会有动画效果 - notifyItemInserted(position); - } - - /** - * 删除单条数据 - */ - public void removeItem(T item) { - int index = mDataSet.indexOf(item); - if (index != -1) { - removeItem(index); - } - } - - public void removeItem(int position) { - //如果是在for循环删除后要记得i-- - mDataSet.remove(position); - //告诉适配器删除数据的位置,会有动画效果 - notifyItemRemoved(position); - } - - /** - * 获取RecyclerView对象,需要在setAdapter之后绑定 - */ - public RecyclerView getRecyclerView() { - return mRecyclerView; - } - - /** - * 获取上下文对象,注意不要在构造方法中调用 - */ - public Context getContext() { - return mContext; - } - - /** - * 获取当前的页码 - */ - public int getPageNumber() { - return mPageNumber; - } - - /** - * 设置当前的页码 - */ - public void setPageNumber(int pageNumber) { - mPageNumber = pageNumber; - } - - /** - * 当前是否为最后一页 - */ - public boolean isLastPage() { - return mLastPage; - } - - /** - * 设置是否为最后一页 - */ - public void setLastPage(boolean lastPage) { - mLastPage = lastPage; - } - - /** - * 获取标记 - */ - public Object getTag() { - return mTag; - } - - /** - * 设置标记 - */ - public void setTag(Object tag) { - mTag = tag; - } - - /** - * 条目ViewHolder,需要子类ViewHolder继承 - */ - public class ViewHolder extends RecyclerView.ViewHolder - implements View.OnClickListener, View.OnLongClickListener { - - // 内存优化和防止泄露 - private SparseArray> mViews = new SparseArray<>(); - - public ViewHolder(ViewGroup parent, int layoutId) { - this(LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false)); - } - - public ViewHolder(View itemView) { - super(itemView); - //这里可以设置条目的监听事件 - itemView.setOnClickListener(this); - itemView.setOnLongClickListener(this); - } - - @Override - public void onClick(View v) { - if(onItemClickListener != null) { - onItemClickListener.onItemClick(v, getLayoutPosition()); - } - } - - @Override - public boolean onLongClick(View v) { - if (onItemLongClickListener != null) { - return onItemLongClickListener.onItemLongClick(v, getLayoutPosition()); - } - return false; - } - - public final V findView(@IdRes int id) { - WeakReference reference = mViews.get(id); - if (reference != null && reference.get() != null) { - return (V) reference.get(); - }else { - View view = itemView.findViewById(id); - mViews.put(id, new WeakReference<>(view)); - return (V) view; - } - } - - public final ViewHolder setText(@IdRes int id, String text) { - if (text == null) text = ""; - View view = findView(id); - if (view instanceof TextView) { - ((TextView) view).setText(text); - } - return this; - } - - public final ViewHolder setVisibility(@IdRes int id, int visibility) { - View view = findView(id); - if (view != null) { - view.setVisibility(visibility); - } - return this; - } - - public final ViewHolder setColor(@IdRes int id, @ColorInt int color) { - View view = findView(id); - if (view instanceof TextView) { - ((TextView) view).setTextColor(color); - } - return this; - } - - public final ViewHolder setImage(@IdRes int id, int resID) { - View view = findView(id); - if (view instanceof ImageView) { - ((ImageView) view).setImageResource(resID); - } - return this; - } - } - - @Override - public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) { - mRecyclerView = recyclerView; - //用户设置了滚动监听,需要给RecyclerView设置监听 - if (mScrollListener != null) { - //添加滚动监听 - mRecyclerView.addOnScrollListener(mScrollListener); - } - //判断当前的布局管理器是否为空,如果为空则设置默认的布局管理器 - if (mRecyclerView.getLayoutManager() == null) { - RecyclerView.LayoutManager manager = getDefaultLayoutManager(mContext); - if (manager != null) { - mRecyclerView.setLayoutManager(manager); - } - } - } - - @Override - public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) { - //移除滚动监听 - if (mScrollListener != null) { - mRecyclerView.removeOnScrollListener(mScrollListener); - } - mRecyclerView = null; - } - - /** - * 获取默认的布局摆放器 - */ - public RecyclerView.LayoutManager getDefaultLayoutManager(Context context) { - return new LinearLayoutManager(context); - } - - /** - * 设置RecyclerView条目点击监听 - */ - private OnItemClickListener onItemClickListener; - public void setOnItemClickListener(OnItemClickListener l) { - onItemClickListener = l; - } - - /** - * 设置RecyclerView条目长按监听 - */ - private OnItemLongClickListener onItemLongClickListener; - public void setOnItemLongClickListener(OnItemLongClickListener l) { - onItemLongClickListener = l; - } - - /** - * 设置RecyclerView条目滚动监听 - */ - private OnScrollingListener onScrollingListener; - public void setOnScrollingListener(OnScrollingListener l) { - onScrollingListener = l; - - //如果当前已经有设置滚动监听,再次设置需要移除原有的监听器 - if (mScrollListener == null) { - mScrollListener = new ScrollListener(); - }else { - mRecyclerView.removeOnScrollListener(mScrollListener); - } - //用户设置了滚动监听,需要给RecyclerView设置监听 - if (mRecyclerView != null) { - //添加滚动监听 - mRecyclerView.addOnScrollListener(mScrollListener); - } - } - - //自定义滚动监听器 - private ScrollListener mScrollListener; - - private class ScrollListener extends RecyclerView.OnScrollListener { - - @Override - public void onScrollStateChanged(RecyclerView recyclerView, int newState) { - - if (onScrollingListener == null) return; - - if (newState == RecyclerView.SCROLL_STATE_IDLE) { - - if (!recyclerView.canScrollVertically(1)) { - //是否能向下滚动,false表示已经滚动到底部 - onScrollingListener.onScrollDown(recyclerView); - }else if (!recyclerView.canScrollVertically(-1)) { - //是否能向上滚动,false表示已经滚动到顶部 - onScrollingListener.onScrollTop(recyclerView); - } - - }else if (newState == RecyclerView.SCROLL_STATE_DRAGGING) { - //正在滚动中 - onScrollingListener.onScrolling(recyclerView); - } - } - } - - /** - * 设置RecyclerView条目点击监听 - */ - private OnItemChildClickListener onItemChildClickListener; - public void setOnItemChildClickListener(OnItemChildClickListener l) { - onItemChildClickListener = l; - notifyDataSetChanged(); - } - - /** - * RecyclerView条目点击监听类 - */ - public interface OnItemClickListener{ - - /** - * 当RecyclerView某个条目被点击时回调 - * - * @param itemView 被点击的条目对象 - * @param position 被点击的条目位置 - */ - void onItemClick(View itemView, int position); - } - - /** - * RecyclerView条目长按监听类 - */ - public interface OnItemLongClickListener { - - /** - * 当RecyclerView某个条目被长按时回调 - * - * @param itemView 被点击的条目对象 - * @param position 被点击的条目位置 - * @return 是否拦截事件 - */ - boolean onItemLongClick(View itemView, int position); - } - - /** - * RecyclerView滚动监听类 - */ - public interface OnScrollingListener { - - /** - * 列表滚动到最顶部 - */ - void onScrollTop(RecyclerView recyclerView); - - /** - * 列表滚动到最底部 - */ - void onScrollDown(RecyclerView recyclerView); - - /** - * 列表滚动中 - */ - void onScrolling(RecyclerView recyclerView); - } - - /** - * RecyclerView条目子View点击监听类 - */ - public interface OnItemChildClickListener{ - - /** - * 当RecyclerView某个条目被点击时回调 - * - * @param viewId 被点击的条目子 View Id - * @param position 被点击的条目位置 - */ - void onItemChildClick(int viewId, int position); - } +package com.hjq.base; + +import android.content.Context; +import android.support.annotation.ColorInt; +import android.support.annotation.IdRes; +import android.support.annotation.NonNull; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.util.SparseArray; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.List; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : RecyclerView 适配器基类 + */ +public abstract class BaseRecyclerViewAdapter + extends RecyclerView.Adapter { + //列表数据 + private List mDataSet; + //RecyclerView对象 + private RecyclerView mRecyclerView; + //上下文对象,注意不要在构造函数中使用 + private Context mContext; + + //当前列表的页码,默认为第一页,用于分页加载功能 + private int mPageNumber = 1; + //是否是最后一页,默认为false,用于分页加载功能 + private boolean mLastPage; + //标记对象 + private Object mTag; + + public BaseRecyclerViewAdapter(Context context) { + mContext = context; + } + + @Override + public int getItemCount() { + return mDataSet == null ? 0 : mDataSet.size(); + } + + @Override + public long getItemId(int position) { + return position; + } + + /** + * 设置新的数据 + */ + public void setData(List data) { + mDataSet = data; + notifyDataSetChanged(); + } + + /** + * 获取当前数据 + */ + public List getData() { + return mDataSet; + } + + /** + * 追加一些数据 + */ + public void addData(List data) { + //追加的数据不能为空 + if (data == null || data.size() == 0) return; + + if (mDataSet == null || mDataSet.size() == 0) { + setData(data); + }else { + mDataSet.addAll(data); + notifyItemRangeInserted(mDataSet.size() - data.size(), data.size()); + } + } + + /** + * 清空当前数据 + */ + public void clearData() { + //当前的数据不能为空 + if (mDataSet == null || mDataSet.size() == 0) return; + + mDataSet.clear(); + notifyDataSetChanged(); + } + + /** + * 获取某个位置上的数据 + */ + public T getItem(int position) { + return mDataSet.get(position); + } + + /** + * 更新某个位置上的数据 + */ + public void setItem(int position, T item) { + if (mDataSet == null) mDataSet = new ArrayList<>(); + mDataSet.set(position, item); + notifyItemChanged(position); + } + + /** + * 添加单条数据 + */ + public void addItem(T item) { + addItem(mDataSet.size() - 1, item); + } + + public void addItem(int position, T item) { + if (mDataSet == null) mDataSet = new ArrayList<>(); + + //如果是在for循环添加后要记得position++ + if (position < mDataSet.size()) { + mDataSet.add(position, item); + }else { + mDataSet.add(item); + position = mDataSet.size() - 1; + } + //告诉适配器添加数据的位置,会有动画效果 + notifyItemInserted(position); + } + + /** + * 删除单条数据 + */ + public void removeItem(T item) { + int index = mDataSet.indexOf(item); + if (index != -1) { + removeItem(index); + } + } + + public void removeItem(int position) { + //如果是在for循环删除后要记得i-- + mDataSet.remove(position); + //告诉适配器删除数据的位置,会有动画效果 + notifyItemRemoved(position); + } + + /** + * 获取RecyclerView对象,需要在setAdapter之后绑定 + */ + public RecyclerView getRecyclerView() { + return mRecyclerView; + } + + /** + * 获取上下文对象,注意不要在构造方法中调用 + */ + public Context getContext() { + return mContext; + } + + /** + * 获取当前的页码 + */ + public int getPageNumber() { + return mPageNumber; + } + + /** + * 设置当前的页码 + */ + public void setPageNumber(int pageNumber) { + mPageNumber = pageNumber; + } + + /** + * 当前是否为最后一页 + */ + public boolean isLastPage() { + return mLastPage; + } + + /** + * 设置是否为最后一页 + */ + public void setLastPage(boolean lastPage) { + mLastPage = lastPage; + } + + /** + * 获取标记 + */ + public Object getTag() { + return mTag; + } + + /** + * 设置标记 + */ + public void setTag(Object tag) { + mTag = tag; + } + + /** + * 条目ViewHolder,需要子类ViewHolder继承 + */ + public class ViewHolder extends RecyclerView.ViewHolder + implements View.OnClickListener, View.OnLongClickListener { + + // 内存优化和防止泄露 + private SparseArray> mViews = new SparseArray<>(); + + public ViewHolder(ViewGroup parent, int layoutId) { + this(LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false)); + } + + public ViewHolder(View itemView) { + super(itemView); + //这里可以设置条目的监听事件 + itemView.setOnClickListener(this); + itemView.setOnLongClickListener(this); + } + + @Override + public void onClick(View v) { + if(onItemClickListener != null) { + onItemClickListener.onItemClick(v, getLayoutPosition()); + } + } + + @Override + public boolean onLongClick(View v) { + if (onItemLongClickListener != null) { + return onItemLongClickListener.onItemLongClick(v, getLayoutPosition()); + } + return false; + } + + public final V findView(@IdRes int id) { + WeakReference reference = mViews.get(id); + if (reference != null && reference.get() != null) { + return (V) reference.get(); + }else { + View view = itemView.findViewById(id); + mViews.put(id, new WeakReference<>(view)); + return (V) view; + } + } + + public final ViewHolder setText(@IdRes int id, String text) { + if (text == null) text = ""; + View view = findView(id); + if (view instanceof TextView) { + ((TextView) view).setText(text); + } + return this; + } + + public final ViewHolder setVisibility(@IdRes int id, int visibility) { + View view = findView(id); + if (view != null) { + view.setVisibility(visibility); + } + return this; + } + + public final ViewHolder setColor(@IdRes int id, @ColorInt int color) { + View view = findView(id); + if (view instanceof TextView) { + ((TextView) view).setTextColor(color); + } + return this; + } + + public final ViewHolder setImage(@IdRes int id, int resID) { + View view = findView(id); + if (view instanceof ImageView) { + ((ImageView) view).setImageResource(resID); + } + return this; + } + } + + @Override + public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) { + mRecyclerView = recyclerView; + //用户设置了滚动监听,需要给RecyclerView设置监听 + if (mScrollListener != null) { + //添加滚动监听 + mRecyclerView.addOnScrollListener(mScrollListener); + } + //判断当前的布局管理器是否为空,如果为空则设置默认的布局管理器 + if (mRecyclerView.getLayoutManager() == null) { + RecyclerView.LayoutManager manager = getDefaultLayoutManager(mContext); + if (manager != null) { + mRecyclerView.setLayoutManager(manager); + } + } + } + + @Override + public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) { + //移除滚动监听 + if (mScrollListener != null) { + mRecyclerView.removeOnScrollListener(mScrollListener); + } + mRecyclerView = null; + } + + /** + * 获取默认的布局摆放器 + */ + public RecyclerView.LayoutManager getDefaultLayoutManager(Context context) { + return new LinearLayoutManager(context); + } + + /** + * 设置RecyclerView条目点击监听 + */ + private OnItemClickListener onItemClickListener; + public void setOnItemClickListener(OnItemClickListener l) { + onItemClickListener = l; + } + + /** + * 设置RecyclerView条目长按监听 + */ + private OnItemLongClickListener onItemLongClickListener; + public void setOnItemLongClickListener(OnItemLongClickListener l) { + onItemLongClickListener = l; + } + + /** + * 设置RecyclerView条目滚动监听 + */ + private OnScrollingListener onScrollingListener; + public void setOnScrollingListener(OnScrollingListener l) { + onScrollingListener = l; + + //如果当前已经有设置滚动监听,再次设置需要移除原有的监听器 + if (mScrollListener == null) { + mScrollListener = new ScrollListener(); + }else { + mRecyclerView.removeOnScrollListener(mScrollListener); + } + //用户设置了滚动监听,需要给RecyclerView设置监听 + if (mRecyclerView != null) { + //添加滚动监听 + mRecyclerView.addOnScrollListener(mScrollListener); + } + } + + //自定义滚动监听器 + private ScrollListener mScrollListener; + + private class ScrollListener extends RecyclerView.OnScrollListener { + + @Override + public void onScrollStateChanged(RecyclerView recyclerView, int newState) { + + if (onScrollingListener == null) return; + + if (newState == RecyclerView.SCROLL_STATE_IDLE) { + + if (!recyclerView.canScrollVertically(1)) { + //是否能向下滚动,false表示已经滚动到底部 + onScrollingListener.onScrollDown(recyclerView); + }else if (!recyclerView.canScrollVertically(-1)) { + //是否能向上滚动,false表示已经滚动到顶部 + onScrollingListener.onScrollTop(recyclerView); + } + + }else if (newState == RecyclerView.SCROLL_STATE_DRAGGING) { + //正在滚动中 + onScrollingListener.onScrolling(recyclerView); + } + } + } + + /** + * 设置RecyclerView条目点击监听 + */ + private OnItemChildClickListener onItemChildClickListener; + public void setOnItemChildClickListener(OnItemChildClickListener l) { + onItemChildClickListener = l; + notifyDataSetChanged(); + } + + /** + * RecyclerView条目点击监听类 + */ + public interface OnItemClickListener{ + + /** + * 当RecyclerView某个条目被点击时回调 + * + * @param itemView 被点击的条目对象 + * @param position 被点击的条目位置 + */ + void onItemClick(View itemView, int position); + } + + /** + * RecyclerView条目长按监听类 + */ + public interface OnItemLongClickListener { + + /** + * 当RecyclerView某个条目被长按时回调 + * + * @param itemView 被点击的条目对象 + * @param position 被点击的条目位置 + * @return 是否拦截事件 + */ + boolean onItemLongClick(View itemView, int position); + } + + /** + * RecyclerView滚动监听类 + */ + public interface OnScrollingListener { + + /** + * 列表滚动到最顶部 + */ + void onScrollTop(RecyclerView recyclerView); + + /** + * 列表滚动到最底部 + */ + void onScrollDown(RecyclerView recyclerView); + + /** + * 列表滚动中 + */ + void onScrolling(RecyclerView recyclerView); + } + + /** + * RecyclerView条目子View点击监听类 + */ + public interface OnItemChildClickListener{ + + /** + * 当RecyclerView某个条目被点击时回调 + * + * @param viewId 被点击的条目子 View Id + * @param position 被点击的条目位置 + */ + void onItemChildClick(int viewId, int position); + } } \ No newline at end of file diff --git a/baselibrary/src/main/res/anim/dialog_bottom_in.xml b/base/src/main/res/anim/dialog_bottom_in.xml similarity index 100% rename from baselibrary/src/main/res/anim/dialog_bottom_in.xml rename to base/src/main/res/anim/dialog_bottom_in.xml diff --git a/baselibrary/src/main/res/anim/dialog_bottom_out.xml b/base/src/main/res/anim/dialog_bottom_out.xml similarity index 100% rename from baselibrary/src/main/res/anim/dialog_bottom_out.xml rename to base/src/main/res/anim/dialog_bottom_out.xml diff --git a/baselibrary/src/main/res/anim/dialog_left_in.xml b/base/src/main/res/anim/dialog_left_in.xml similarity index 100% rename from baselibrary/src/main/res/anim/dialog_left_in.xml rename to base/src/main/res/anim/dialog_left_in.xml diff --git a/baselibrary/src/main/res/anim/dialog_left_out.xml b/base/src/main/res/anim/dialog_left_out.xml similarity index 100% rename from baselibrary/src/main/res/anim/dialog_left_out.xml rename to base/src/main/res/anim/dialog_left_out.xml diff --git a/baselibrary/src/main/res/anim/dialog_right_in.xml b/base/src/main/res/anim/dialog_right_in.xml similarity index 100% rename from baselibrary/src/main/res/anim/dialog_right_in.xml rename to base/src/main/res/anim/dialog_right_in.xml diff --git a/baselibrary/src/main/res/anim/dialog_right_out.xml b/base/src/main/res/anim/dialog_right_out.xml similarity index 100% rename from baselibrary/src/main/res/anim/dialog_right_out.xml rename to base/src/main/res/anim/dialog_right_out.xml diff --git a/baselibrary/src/main/res/anim/dialog_scale_in.xml b/base/src/main/res/anim/dialog_scale_in.xml similarity index 100% rename from baselibrary/src/main/res/anim/dialog_scale_in.xml rename to base/src/main/res/anim/dialog_scale_in.xml diff --git a/baselibrary/src/main/res/anim/dialog_scale_out.xml b/base/src/main/res/anim/dialog_scale_out.xml similarity index 100% rename from baselibrary/src/main/res/anim/dialog_scale_out.xml rename to base/src/main/res/anim/dialog_scale_out.xml diff --git a/baselibrary/src/main/res/anim/dialog_top_in.xml b/base/src/main/res/anim/dialog_top_in.xml similarity index 100% rename from baselibrary/src/main/res/anim/dialog_top_in.xml rename to base/src/main/res/anim/dialog_top_in.xml diff --git a/baselibrary/src/main/res/anim/dialog_top_out.xml b/base/src/main/res/anim/dialog_top_out.xml similarity index 100% rename from baselibrary/src/main/res/anim/dialog_top_out.xml rename to base/src/main/res/anim/dialog_top_out.xml diff --git a/baselibrary/src/main/res/values/ids.xml b/base/src/main/res/values/ids.xml similarity index 100% rename from baselibrary/src/main/res/values/ids.xml rename to base/src/main/res/values/ids.xml diff --git a/baselibrary/src/main/res/values/styles.xml b/base/src/main/res/values/styles.xml similarity index 100% rename from baselibrary/src/main/res/values/styles.xml rename to base/src/main/res/values/styles.xml diff --git a/baselibrary/src/main/AndroidManifest.xml b/baselibrary/src/main/AndroidManifest.xml deleted file mode 100644 index e782d961..00000000 --- a/baselibrary/src/main/AndroidManifest.xml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/baselibrary/.gitignore b/copy/.gitignore similarity index 100% rename from baselibrary/.gitignore rename to copy/.gitignore diff --git a/copy/build.gradle b/copy/build.gradle new file mode 100644 index 00000000..bca2c7b8 --- /dev/null +++ b/copy/build.gradle @@ -0,0 +1,18 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion rootProject.ext.compileSdkVersion + buildToolsVersion rootProject.ext.buildToolsVersion + + defaultConfig { + minSdkVersion 14 + targetSdkVersion rootProject.ext.targetSdkVersion + versionCode 1 + versionName "1.0" + } +} + +dependencies { + implementation "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion" + implementation "com.android.support:design:$rootProject.ext.supportLibraryVersion" +} \ No newline at end of file diff --git a/baselibrary/proguard-rules.pro b/copy/proguard-rules.pro similarity index 100% rename from baselibrary/proguard-rules.pro rename to copy/proguard-rules.pro diff --git a/copy/src/main/AndroidManifest.xml b/copy/src/main/AndroidManifest.xml new file mode 100644 index 00000000..989d6584 --- /dev/null +++ b/copy/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/copy/src/main/java/com/hjq/copy/Copy.java b/copy/src/main/java/com/hjq/copy/Copy.java new file mode 100644 index 00000000..3b7c6d22 --- /dev/null +++ b/copy/src/main/java/com/hjq/copy/Copy.java @@ -0,0 +1,11 @@ +package com.hjq.demo.mvp; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/11/30 + * desc : 占位 + */ +public class Copy { + +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index c2410399..be19dfa9 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':baselibrary' \ No newline at end of file +include ':app', ':base', ':widget', ':umeng' \ No newline at end of file diff --git a/umeng/.gitignore b/umeng/.gitignore new file mode 100644 index 00000000..3543521e --- /dev/null +++ b/umeng/.gitignore @@ -0,0 +1 @@ +/build diff --git a/umeng/build.gradle b/umeng/build.gradle new file mode 100644 index 00000000..c070a307 --- /dev/null +++ b/umeng/build.gradle @@ -0,0 +1,21 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion rootProject.ext.compileSdkVersion + buildToolsVersion rootProject.ext.buildToolsVersion + + defaultConfig { + minSdkVersion 8 + targetSdkVersion rootProject.ext.targetSdkVersion + versionCode 1 + versionName "1.0" + } +} + +dependencies { + // 依赖 libs 目录下所有 Jar 包 + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion" +// implementation 'com.umeng.sdk:common:latest.integration' +// implementation 'com.umeng.sdk:analytics:latest.integration' +} \ No newline at end of file diff --git a/umeng/libs/umeng-analytics-7.5.4.jar b/umeng/libs/umeng-analytics-7.5.4.jar new file mode 100644 index 00000000..58247b3c Binary files /dev/null and b/umeng/libs/umeng-analytics-7.5.4.jar differ diff --git a/umeng/libs/umeng-common-1.5.4.jar b/umeng/libs/umeng-common-1.5.4.jar new file mode 100644 index 00000000..c25014be Binary files /dev/null and b/umeng/libs/umeng-common-1.5.4.jar differ diff --git a/umeng/libs/utdid4all-1.1.5.3_proguard.jar b/umeng/libs/utdid4all-1.1.5.3_proguard.jar new file mode 100644 index 00000000..5eed5bee Binary files /dev/null and b/umeng/libs/utdid4all-1.1.5.3_proguard.jar differ diff --git a/umeng/proguard-rules.pro b/umeng/proguard-rules.pro new file mode 100644 index 00000000..6be4355e --- /dev/null +++ b/umeng/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in D:\SDK\Studio\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/umeng/src/main/AndroidManifest.xml b/umeng/src/main/AndroidManifest.xml new file mode 100644 index 00000000..70fbe599 --- /dev/null +++ b/umeng/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/umeng/src/main/java/com/hjq/umeng/UmengHelper.java b/umeng/src/main/java/com/hjq/umeng/UmengHelper.java new file mode 100644 index 00000000..e5a49659 --- /dev/null +++ b/umeng/src/main/java/com/hjq/umeng/UmengHelper.java @@ -0,0 +1,60 @@ +package com.hjq.umeng; + +import android.app.Activity; +import android.content.Context; +import android.support.v4.app.Fragment; + +import com.umeng.analytics.MobclickAgent; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/11/30 + * desc : 友盟辅助类 + */ +public class UmengHelper { + + /** + * 初始化友盟相关 SDK + */ + public static void init(Context context) { + // 友盟统计 + MobclickAgent.setScenarioType(context, MobclickAgent.EScenarioType.E_UM_NORMAL); + } + + /** + * Activity 统计 + */ + public static void onResume(Activity activity) { + // 手动统计页面 + MobclickAgent.onPageStart(activity.getClass().getSimpleName()); + // 友盟统计 + MobclickAgent.onResume(activity); + } + + /** + * Activity 统计 + */ + public static void onPause(Activity activity) { + // 手动统计页面,必须保证 onPageEnd 在 onPause 之前调用,因为SDK会在 onPause 中保存onPageEnd统计到的页面数据 + MobclickAgent.onPageEnd(activity.getClass().getSimpleName()); + // 友盟统计 + MobclickAgent.onPause(activity); + } + + /** + * Fragment 统计 + */ + public static void onResume(Fragment fragment) { + // 友盟统计 + MobclickAgent.onResume(fragment.getContext()); + } + + /** + * Fragment 统计 + */ + public static void onPause(Fragment fragment) { + // 友盟统计 + MobclickAgent.onPause(fragment.getContext()); + } +} diff --git a/widget/.gitignore b/widget/.gitignore new file mode 100644 index 00000000..3543521e --- /dev/null +++ b/widget/.gitignore @@ -0,0 +1 @@ +/build diff --git a/widget/build.gradle b/widget/build.gradle new file mode 100644 index 00000000..59cbc44d --- /dev/null +++ b/widget/build.gradle @@ -0,0 +1,18 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion rootProject.ext.compileSdkVersion + buildToolsVersion rootProject.ext.buildToolsVersion + + defaultConfig { + minSdkVersion 11 + targetSdkVersion rootProject.ext.targetSdkVersion + versionCode 1 + versionName "1.0" + } +} + +dependencies { + implementation "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion" + implementation "com.android.support:design:$rootProject.ext.supportLibraryVersion" +} \ No newline at end of file diff --git a/widget/proguard-rules.pro b/widget/proguard-rules.pro new file mode 100644 index 00000000..6be4355e --- /dev/null +++ b/widget/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in D:\SDK\Studio\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/widget/src/main/AndroidManifest.xml b/widget/src/main/AndroidManifest.xml new file mode 100644 index 00000000..b084981d --- /dev/null +++ b/widget/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/widget/ClearEditText.java b/widget/src/main/java/com/hjq/widget/ClearEditText.java similarity index 95% rename from baselibrary/src/main/java/com/hjq/baselibrary/widget/ClearEditText.java rename to widget/src/main/java/com/hjq/widget/ClearEditText.java index c498b874..5744553e 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/widget/ClearEditText.java +++ b/widget/src/main/java/com/hjq/widget/ClearEditText.java @@ -1,138 +1,137 @@ -package com.hjq.baselibrary.widget; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.support.v4.content.ContextCompat; -import android.support.v4.graphics.drawable.DrawableCompat; -import android.support.v4.view.ViewCompat; -import android.text.Editable; -import android.text.TextWatcher; -import android.util.AttributeSet; -import android.view.MotionEvent; -import android.view.View; -import android.widget.EditText; - -import com.hjq.baselibrary.R; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 带清除按钮的EditText - */ -@SuppressLint("AppCompatCustomView") -public class ClearEditText extends EditText - implements View.OnTouchListener, View.OnFocusChangeListener, TextWatcher { - - private Drawable mClearIcon; - - private OnTouchListener mOnTouchListener; - private OnFocusChangeListener mOnFocusChangeListener; - - public ClearEditText(Context context) { - super(context); - initialize(context); - } - - public ClearEditText(Context context, AttributeSet attrs) { - super(context, attrs); - initialize(context); - } - - public ClearEditText(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - initialize(context); - } - - private void initialize(final Context context) { - - final Drawable drawable = ContextCompat.getDrawable(context, R.mipmap.icon_input_del); - - final Drawable wrappedDrawable = DrawableCompat.wrap(drawable); //Wrap the drawable so that it can be tinted pre Lollipop - //DrawableCompat.setTint(wrappedDrawable, getCurrentHintTextColor()); - mClearIcon = wrappedDrawable; - mClearIcon.setBounds(0, 0, mClearIcon.getIntrinsicWidth(), mClearIcon.getIntrinsicHeight()); - setClearIconVisible(false); - super.setOnTouchListener(this); - super.setOnFocusChangeListener(this); - super.addTextChangedListener(this); - ViewCompat.setBackgroundTintList(this, ContextCompat.getColorStateList(context, R.color.black60)); - } - - private void setClearIconVisible(final boolean visible) { - if (mClearIcon.isVisible() == visible) return; - - mClearIcon.setVisible(visible, false); - final Drawable[] compoundDrawables = getCompoundDrawables(); - setCompoundDrawables( - compoundDrawables[0], - compoundDrawables[1], - visible ? mClearIcon : null, - compoundDrawables[3]); - } - - @Override - public void setOnFocusChangeListener(final OnFocusChangeListener onFocusChangeListener) { - mOnFocusChangeListener = onFocusChangeListener; - } - - @Override - public void setOnTouchListener(final OnTouchListener onTouchListener) { - mOnTouchListener = onTouchListener; - } - - /** - * {@link View.OnFocusChangeListener} - */ - - @Override - public void onFocusChange(final View view, final boolean hasFocus) { - if (hasFocus && getText() != null) { - setClearIconVisible(getText().length() > 0); - } else { - setClearIconVisible(false); - } - if (mOnFocusChangeListener != null) { - mOnFocusChangeListener.onFocusChange(view, hasFocus); - } - } - - /** - * {@link View.OnTouchListener} - */ - - @Override - public boolean onTouch(final View view, final MotionEvent motionEvent) { - final int x = (int) motionEvent.getX(); - if (mClearIcon.isVisible() && x > getWidth() - getPaddingRight() - mClearIcon.getIntrinsicWidth()) { - if (motionEvent.getAction() == MotionEvent.ACTION_UP) { - setText(""); - } - return true; - } - return mOnTouchListener != null && mOnTouchListener.onTouch(view, motionEvent); - } - - /** - * {@link TextWatcher} - */ - - @Override - public void onTextChanged(final CharSequence s, final int start, final int before, final int count) { - if (isFocused()) { - setClearIconVisible(s.length() > 0); - } - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} - - @Override - public void afterTextChanged(Editable s) {} - -// @Override -// protected void drawableStateChanged() { -// super.drawableStateChanged(); -// } +package com.hjq.widget; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.support.v4.content.ContextCompat; +import android.support.v4.graphics.drawable.DrawableCompat; +import android.support.v4.view.ViewCompat; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; +import android.widget.EditText; + + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 带清除按钮的EditText + */ +@SuppressLint("AppCompatCustomView") +public class ClearEditText extends EditText + implements View.OnTouchListener, View.OnFocusChangeListener, TextWatcher { + + private Drawable mClearIcon; + + private OnTouchListener mOnTouchListener; + private OnFocusChangeListener mOnFocusChangeListener; + + public ClearEditText(Context context) { + super(context); + initialize(context); + } + + public ClearEditText(Context context, AttributeSet attrs) { + super(context, attrs); + initialize(context); + } + + public ClearEditText(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initialize(context); + } + + private void initialize(final Context context) { + + final Drawable drawable = ContextCompat.getDrawable(context, R.mipmap.icon_input_del); + + final Drawable wrappedDrawable = DrawableCompat.wrap(drawable); //Wrap the drawable so that it can be tinted pre Lollipop + //DrawableCompat.setTint(wrappedDrawable, getCurrentHintTextColor()); + mClearIcon = wrappedDrawable; + mClearIcon.setBounds(0, 0, mClearIcon.getIntrinsicWidth(), mClearIcon.getIntrinsicHeight()); + setClearIconVisible(false); + super.setOnTouchListener(this); + super.setOnFocusChangeListener(this); + super.addTextChangedListener(this); + ViewCompat.setBackgroundTintList(this, ContextCompat.getColorStateList(context, R.color.black60)); + } + + private void setClearIconVisible(final boolean visible) { + if (mClearIcon.isVisible() == visible) return; + + mClearIcon.setVisible(visible, false); + final Drawable[] compoundDrawables = getCompoundDrawables(); + setCompoundDrawables( + compoundDrawables[0], + compoundDrawables[1], + visible ? mClearIcon : null, + compoundDrawables[3]); + } + + @Override + public void setOnFocusChangeListener(final OnFocusChangeListener onFocusChangeListener) { + mOnFocusChangeListener = onFocusChangeListener; + } + + @Override + public void setOnTouchListener(final OnTouchListener onTouchListener) { + mOnTouchListener = onTouchListener; + } + + /** + * {@link View.OnFocusChangeListener} + */ + + @Override + public void onFocusChange(final View view, final boolean hasFocus) { + if (hasFocus && getText() != null) { + setClearIconVisible(getText().length() > 0); + } else { + setClearIconVisible(false); + } + if (mOnFocusChangeListener != null) { + mOnFocusChangeListener.onFocusChange(view, hasFocus); + } + } + + /** + * {@link View.OnTouchListener} + */ + + @Override + public boolean onTouch(final View view, final MotionEvent motionEvent) { + final int x = (int) motionEvent.getX(); + if (mClearIcon.isVisible() && x > getWidth() - getPaddingRight() - mClearIcon.getIntrinsicWidth()) { + if (motionEvent.getAction() == MotionEvent.ACTION_UP) { + setText(""); + } + return true; + } + return mOnTouchListener != null && mOnTouchListener.onTouch(view, motionEvent); + } + + /** + * {@link TextWatcher} + */ + + @Override + public void onTextChanged(final CharSequence s, final int start, final int before, final int count) { + if (isFocused()) { + setClearIconVisible(s.length() > 0); + } + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + + @Override + public void afterTextChanged(Editable s) {} + +// @Override +// protected void drawableStateChanged() { +// super.drawableStateChanged(); +// } } \ No newline at end of file diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/widget/CountdownView.java b/widget/src/main/java/com/hjq/widget/CountdownView.java similarity index 94% rename from baselibrary/src/main/java/com/hjq/baselibrary/widget/CountdownView.java rename to widget/src/main/java/com/hjq/widget/CountdownView.java index 21526cf6..998a49bd 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/widget/CountdownView.java +++ b/widget/src/main/java/com/hjq/widget/CountdownView.java @@ -1,89 +1,89 @@ -package com.hjq.baselibrary.widget; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.util.AttributeSet; -import android.widget.TextView; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 验证码倒计时 - */ -@SuppressLint("AppCompatCustomView") -public class CountdownView extends TextView implements Runnable { - - private int mTotalTime = 60; // 倒计时秒数 - private static final String TIME_UNIT = "S"; // 秒数单位文本 - - private int mCurrentTime; // 当前秒数 - private CharSequence mRecordText; // 记录原有的文本 - private boolean mFlag; // 标记是否重置了倒计控件 - - public CountdownView(Context context) { - super(context); - } - - public CountdownView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public CountdownView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - /** - * 设置倒计时总秒数 - */ - public void setTotalTime(int totalTime) { - this.mTotalTime = totalTime; - } - - /** - * 重置倒计时控件 - */ - public void resetState() { - mFlag = true; - } - - @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - //设置点击的属性 - setClickable(true); - } - - @Override - protected void onDetachedFromWindow() { - // 移除延迟任务,避免内存泄露 - removeCallbacks(this); - super.onDetachedFromWindow(); - } - - @Override - public boolean performClick() { - boolean click = super.performClick(); - mRecordText = getText(); - setEnabled(false); - mCurrentTime = mTotalTime; - post(this); - return click; - } - - /** - * {@link Runnable} - */ - @Override - public void run() { - if (mCurrentTime == 0 || mFlag) { - setText(mRecordText); - setEnabled(true); - mFlag = false; - } else { - mCurrentTime--; - setText(mCurrentTime + "\t" + TIME_UNIT); - postDelayed(this, 1000); - } - } +package com.hjq.widget; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.AttributeSet; +import android.widget.TextView; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 验证码倒计时 + */ +@SuppressLint("AppCompatCustomView") +public class CountdownView extends TextView implements Runnable { + + private int mTotalTime = 60; // 倒计时秒数 + private static final String TIME_UNIT = "S"; // 秒数单位文本 + + private int mCurrentTime; // 当前秒数 + private CharSequence mRecordText; // 记录原有的文本 + private boolean mFlag; // 标记是否重置了倒计控件 + + public CountdownView(Context context) { + super(context); + } + + public CountdownView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public CountdownView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + /** + * 设置倒计时总秒数 + */ + public void setTotalTime(int totalTime) { + this.mTotalTime = totalTime; + } + + /** + * 重置倒计时控件 + */ + public void resetState() { + mFlag = true; + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + //设置点击的属性 + setClickable(true); + } + + @Override + protected void onDetachedFromWindow() { + // 移除延迟任务,避免内存泄露 + removeCallbacks(this); + super.onDetachedFromWindow(); + } + + @Override + public boolean performClick() { + boolean click = super.performClick(); + mRecordText = getText(); + setEnabled(false); + mCurrentTime = mTotalTime; + post(this); + return click; + } + + /** + * {@link Runnable} + */ + @Override + public void run() { + if (mCurrentTime == 0 || mFlag) { + setText(mRecordText); + setEnabled(true); + mFlag = false; + } else { + mCurrentTime--; + setText(mCurrentTime + "\t" + TIME_UNIT); + postDelayed(this, 1000); + } + } } \ No newline at end of file diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/widget/NoScrollViewPager.java b/widget/src/main/java/com/hjq/widget/NoScrollViewPager.java similarity index 96% rename from baselibrary/src/main/java/com/hjq/baselibrary/widget/NoScrollViewPager.java rename to widget/src/main/java/com/hjq/widget/NoScrollViewPager.java index 41dca87b..b86cf51d 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/widget/NoScrollViewPager.java +++ b/widget/src/main/java/com/hjq/widget/NoScrollViewPager.java @@ -1,4 +1,4 @@ -package com.hjq.baselibrary.widget; +package com.hjq.widget; import android.annotation.SuppressLint; import android.content.Context; diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/widget/SimpleLayout.java b/widget/src/main/java/com/hjq/widget/SimpleLayout.java similarity index 96% rename from baselibrary/src/main/java/com/hjq/baselibrary/widget/SimpleLayout.java rename to widget/src/main/java/com/hjq/widget/SimpleLayout.java index 9b544939..c5b3d6d3 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/widget/SimpleLayout.java +++ b/widget/src/main/java/com/hjq/widget/SimpleLayout.java @@ -1,89 +1,89 @@ -package com.hjq.baselibrary.widget; - -import android.content.Context; -import android.os.Build; -import android.support.annotation.RequiresApi; -import android.util.AttributeSet; -import android.view.View; -import android.view.ViewGroup; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 简单的 Layout(常用于自定义组合控件继承的基类,可以起到性能优化的作用) - */ -public class SimpleLayout extends ViewGroup { - - public SimpleLayout(Context context) { - super(context); - } - - public SimpleLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public SimpleLayout(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) - public SimpleLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - int maxHeight = 0; - int maxWidth = 0; - int childState = 0; - for (int i = 0; i < getChildCount(); i++) { - final View child = getChildAt(i); - if (child.getVisibility() != GONE) { - measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); - final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); - maxWidth = Math.max(maxWidth, child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin); - maxHeight = Math.max(maxHeight, child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin); - childState = combineMeasuredStates(childState, child.getMeasuredState()); - } - } - - maxWidth += getPaddingLeft() + getPaddingRight(); - maxHeight += getPaddingTop() + getPaddingBottom(); - - maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight()); - maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth()); - - setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState), - resolveSizeAndState(maxHeight, heightMeasureSpec, - childState << MEASURED_HEIGHT_STATE_SHIFT)); - } - - @Override - protected void onLayout(boolean changed, int l, int t, int r, int b) { - for (int i = 0; i < getChildCount(); i++) { - final View child = getChildAt(i); - final MarginLayoutParams params = (MarginLayoutParams) child.getLayoutParams(); - child.layout(getPaddingLeft() + params.leftMargin, - getPaddingTop() + params.topMargin, - getPaddingRight() + child.getMeasuredWidth() + params.rightMargin, - getPaddingBottom() + child.getMeasuredHeight() + params.bottomMargin); - } - } - - @Override - public LayoutParams generateLayoutParams(AttributeSet attrs) { - return new MarginLayoutParams(getContext(), attrs); - } - - @Override - protected LayoutParams generateDefaultLayoutParams() { - return new MarginLayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); - } - - @Override - protected LayoutParams generateLayoutParams(LayoutParams p) { - return new MarginLayoutParams(p); - } +package com.hjq.widget; + +import android.content.Context; +import android.os.Build; +import android.support.annotation.RequiresApi; +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewGroup; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 简单的 Layout(常用于自定义组合控件继承的基类,可以起到性能优化的作用) + */ +public class SimpleLayout extends ViewGroup { + + public SimpleLayout(Context context) { + super(context); + } + + public SimpleLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public SimpleLayout(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + public SimpleLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + int maxHeight = 0; + int maxWidth = 0; + int childState = 0; + for (int i = 0; i < getChildCount(); i++) { + final View child = getChildAt(i); + if (child.getVisibility() != GONE) { + measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); + final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); + maxWidth = Math.max(maxWidth, child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin); + maxHeight = Math.max(maxHeight, child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin); + childState = combineMeasuredStates(childState, child.getMeasuredState()); + } + } + + maxWidth += getPaddingLeft() + getPaddingRight(); + maxHeight += getPaddingTop() + getPaddingBottom(); + + maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight()); + maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth()); + + setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState), + resolveSizeAndState(maxHeight, heightMeasureSpec, + childState << MEASURED_HEIGHT_STATE_SHIFT)); + } + + @Override + protected void onLayout(boolean changed, int l, int t, int r, int b) { + for (int i = 0; i < getChildCount(); i++) { + final View child = getChildAt(i); + final MarginLayoutParams params = (MarginLayoutParams) child.getLayoutParams(); + child.layout(getPaddingLeft() + params.leftMargin, + getPaddingTop() + params.topMargin, + getPaddingRight() + child.getMeasuredWidth() + params.rightMargin, + getPaddingBottom() + child.getMeasuredHeight() + params.bottomMargin); + } + } + + @Override + public LayoutParams generateLayoutParams(AttributeSet attrs) { + return new MarginLayoutParams(getContext(), attrs); + } + + @Override + protected LayoutParams generateDefaultLayoutParams() { + return new MarginLayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); + } + + @Override + protected LayoutParams generateLayoutParams(LayoutParams p) { + return new MarginLayoutParams(p); + } } \ No newline at end of file diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/widget/square/SquareDelegate.java b/widget/src/main/java/com/hjq/widget/square/SquareDelegate.java similarity index 98% rename from baselibrary/src/main/java/com/hjq/baselibrary/widget/square/SquareDelegate.java rename to widget/src/main/java/com/hjq/widget/square/SquareDelegate.java index c1671489..e2131f35 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/widget/square/SquareDelegate.java +++ b/widget/src/main/java/com/hjq/widget/square/SquareDelegate.java @@ -1,4 +1,4 @@ -package com.hjq.baselibrary.widget.square; +package com.hjq.widget.square; import android.view.View; diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/widget/square/SquareFrameLayout.java b/widget/src/main/java/com/hjq/widget/square/SquareFrameLayout.java similarity index 92% rename from baselibrary/src/main/java/com/hjq/baselibrary/widget/square/SquareFrameLayout.java rename to widget/src/main/java/com/hjq/widget/square/SquareFrameLayout.java index 58f098ef..7641132b 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/widget/square/SquareFrameLayout.java +++ b/widget/src/main/java/com/hjq/widget/square/SquareFrameLayout.java @@ -1,32 +1,32 @@ -package com.hjq.baselibrary.widget.square; - -import android.content.Context; -import android.util.AttributeSet; -import android.widget.FrameLayout; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 正方形的FrameLayout - */ -public class SquareFrameLayout extends FrameLayout { - - public SquareFrameLayout(Context context) { - super(context); - } - - public SquareFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - public SquareFrameLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(SquareDelegate.measureWidth(widthMeasureSpec, heightMeasureSpec), - SquareDelegate.measureHeight(widthMeasureSpec, heightMeasureSpec)); - } -} +package com.hjq.widget.square; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.FrameLayout; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 正方形的FrameLayout + */ +public class SquareFrameLayout extends FrameLayout { + + public SquareFrameLayout(Context context) { + super(context); + } + + public SquareFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public SquareFrameLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(SquareDelegate.measureWidth(widthMeasureSpec, heightMeasureSpec), + SquareDelegate.measureHeight(widthMeasureSpec, heightMeasureSpec)); + } +} diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/widget/square/SquareImageView.java b/widget/src/main/java/com/hjq/widget/square/SquareImageView.java similarity index 92% rename from baselibrary/src/main/java/com/hjq/baselibrary/widget/square/SquareImageView.java rename to widget/src/main/java/com/hjq/widget/square/SquareImageView.java index 02a56aac..3d9a3e55 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/widget/square/SquareImageView.java +++ b/widget/src/main/java/com/hjq/widget/square/SquareImageView.java @@ -1,32 +1,32 @@ -package com.hjq.baselibrary.widget.square; - -import android.content.Context; -import android.support.v7.widget.AppCompatImageView; -import android.util.AttributeSet; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 正方形的ImageView - */ -public class SquareImageView extends AppCompatImageView { - - public SquareImageView(Context context) { - super(context); - } - - public SquareImageView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public SquareImageView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(SquareDelegate.measureWidth(widthMeasureSpec, heightMeasureSpec), - SquareDelegate.measureHeight(widthMeasureSpec, heightMeasureSpec)); - } +package com.hjq.widget.square; + +import android.content.Context; +import android.support.v7.widget.AppCompatImageView; +import android.util.AttributeSet; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 正方形的ImageView + */ +public class SquareImageView extends AppCompatImageView { + + public SquareImageView(Context context) { + super(context); + } + + public SquareImageView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public SquareImageView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(SquareDelegate.measureWidth(widthMeasureSpec, heightMeasureSpec), + SquareDelegate.measureHeight(widthMeasureSpec, heightMeasureSpec)); + } } \ No newline at end of file diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/widget/square/SquareLinearLayout.java b/widget/src/main/java/com/hjq/widget/square/SquareLinearLayout.java similarity index 92% rename from baselibrary/src/main/java/com/hjq/baselibrary/widget/square/SquareLinearLayout.java rename to widget/src/main/java/com/hjq/widget/square/SquareLinearLayout.java index 25747ddb..1c2711b5 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/widget/square/SquareLinearLayout.java +++ b/widget/src/main/java/com/hjq/widget/square/SquareLinearLayout.java @@ -1,32 +1,32 @@ -package com.hjq.baselibrary.widget.square; - -import android.content.Context; -import android.util.AttributeSet; -import android.widget.LinearLayout; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 正方形的LinearLayout - */ -public class SquareLinearLayout extends LinearLayout { - - public SquareLinearLayout(Context context) { - super(context); - } - - public SquareLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - public SquareLinearLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(SquareDelegate.measureWidth(widthMeasureSpec, heightMeasureSpec), - SquareDelegate.measureHeight(widthMeasureSpec, heightMeasureSpec)); - } -} +package com.hjq.widget.square; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.LinearLayout; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 正方形的LinearLayout + */ +public class SquareLinearLayout extends LinearLayout { + + public SquareLinearLayout(Context context) { + super(context); + } + + public SquareLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public SquareLinearLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(SquareDelegate.measureWidth(widthMeasureSpec, heightMeasureSpec), + SquareDelegate.measureHeight(widthMeasureSpec, heightMeasureSpec)); + } +} diff --git a/baselibrary/src/main/java/com/hjq/baselibrary/widget/square/SquareRelativeLayout.java b/widget/src/main/java/com/hjq/widget/square/SquareRelativeLayout.java similarity index 92% rename from baselibrary/src/main/java/com/hjq/baselibrary/widget/square/SquareRelativeLayout.java rename to widget/src/main/java/com/hjq/widget/square/SquareRelativeLayout.java index a431fba4..4d6b7c20 100644 --- a/baselibrary/src/main/java/com/hjq/baselibrary/widget/square/SquareRelativeLayout.java +++ b/widget/src/main/java/com/hjq/widget/square/SquareRelativeLayout.java @@ -1,32 +1,32 @@ -package com.hjq.baselibrary.widget.square; - -import android.content.Context; -import android.util.AttributeSet; -import android.widget.RelativeLayout; - -/** - * author : HJQ - * github : https://github.com/getActivity/AndroidProject - * time : 2018/10/18 - * desc : 正方形的RelativeLayout - */ -public class SquareRelativeLayout extends RelativeLayout { - - public SquareRelativeLayout(Context context) { - super(context); - } - - public SquareRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - public SquareRelativeLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(SquareDelegate.measureWidth(widthMeasureSpec, heightMeasureSpec), - SquareDelegate.measureHeight(widthMeasureSpec, heightMeasureSpec)); - } -} +package com.hjq.widget.square; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.RelativeLayout; + +/** + * author : HJQ + * github : https://github.com/getActivity/AndroidProject + * time : 2018/10/18 + * desc : 正方形的RelativeLayout + */ +public class SquareRelativeLayout extends RelativeLayout { + + public SquareRelativeLayout(Context context) { + super(context); + } + + public SquareRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public SquareRelativeLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(SquareDelegate.measureWidth(widthMeasureSpec, heightMeasureSpec), + SquareDelegate.measureHeight(widthMeasureSpec, heightMeasureSpec)); + } +} diff --git a/baselibrary/src/main/res/anim/item_animation_fall_down.xml b/widget/src/main/res/anim/item_animation_fall_down.xml similarity index 100% rename from baselibrary/src/main/res/anim/item_animation_fall_down.xml rename to widget/src/main/res/anim/item_animation_fall_down.xml diff --git a/baselibrary/src/main/res/anim/item_animation_from_bottom.xml b/widget/src/main/res/anim/item_animation_from_bottom.xml similarity index 100% rename from baselibrary/src/main/res/anim/item_animation_from_bottom.xml rename to widget/src/main/res/anim/item_animation_from_bottom.xml diff --git a/baselibrary/src/main/res/anim/item_animation_from_right.xml b/widget/src/main/res/anim/item_animation_from_right.xml similarity index 100% rename from baselibrary/src/main/res/anim/item_animation_from_right.xml rename to widget/src/main/res/anim/item_animation_from_right.xml diff --git a/baselibrary/src/main/res/anim/layout_animation_fall_down.xml b/widget/src/main/res/anim/layout_animation_fall_down.xml similarity index 100% rename from baselibrary/src/main/res/anim/layout_animation_fall_down.xml rename to widget/src/main/res/anim/layout_animation_fall_down.xml diff --git a/baselibrary/src/main/res/anim/layout_animation_from_bottom.xml b/widget/src/main/res/anim/layout_animation_from_bottom.xml similarity index 100% rename from baselibrary/src/main/res/anim/layout_animation_from_bottom.xml rename to widget/src/main/res/anim/layout_animation_from_bottom.xml diff --git a/baselibrary/src/main/res/anim/layout_animation_from_right.xml b/widget/src/main/res/anim/layout_animation_from_right.xml similarity index 100% rename from baselibrary/src/main/res/anim/layout_animation_from_right.xml rename to widget/src/main/res/anim/layout_animation_from_right.xml diff --git a/baselibrary/src/main/res/mipmap-hdpi/icon_input_del.png b/widget/src/main/res/mipmap-hdpi/icon_input_del.png similarity index 100% rename from baselibrary/src/main/res/mipmap-hdpi/icon_input_del.png rename to widget/src/main/res/mipmap-hdpi/icon_input_del.png diff --git a/baselibrary/src/main/res/mipmap-xhdpi/icon_input_del.png b/widget/src/main/res/mipmap-xhdpi/icon_input_del.png similarity index 100% rename from baselibrary/src/main/res/mipmap-xhdpi/icon_input_del.png rename to widget/src/main/res/mipmap-xhdpi/icon_input_del.png diff --git a/baselibrary/src/main/res/mipmap-xxhdpi/icon_input_del.png b/widget/src/main/res/mipmap-xxhdpi/icon_input_del.png similarity index 100% rename from baselibrary/src/main/res/mipmap-xxhdpi/icon_input_del.png rename to widget/src/main/res/mipmap-xxhdpi/icon_input_del.png diff --git a/baselibrary/src/main/res/values/colors.xml b/widget/src/main/res/values/colors.xml similarity index 97% rename from baselibrary/src/main/res/values/colors.xml rename to widget/src/main/res/values/colors.xml index aa5e53ff..d5712eb2 100644 --- a/baselibrary/src/main/res/values/colors.xml +++ b/widget/src/main/res/values/colors.xml @@ -1,49 +1,49 @@ - - - - #00000000 - - #0cFFFFFF - #22FFFFFF - #33FFFFFF - #44FFFFFF - #66FFFFFF - #88FFFFFF - #99FFFFFF - #BBFFFFFF - #CCFFFFFF - #EEFFFFFF - #FFFFFFFF - - #FF000000 - #EE000000 - #CC000000 - #BB000000 - #99000000 - #88000000 - #66000000 - #44000000 - #33000000 - #22000000 - #0c000000 - - - #808080 - - #FF0000 - - #FFD700 - - #FFFF00 - - #008000 - - #0000FF - - #800080 - - #FFC0CB - - #FFA500 - + + + + #00000000 + + #0cFFFFFF + #22FFFFFF + #33FFFFFF + #44FFFFFF + #66FFFFFF + #88FFFFFF + #99FFFFFF + #BBFFFFFF + #CCFFFFFF + #EEFFFFFF + #FFFFFFFF + + #FF000000 + #EE000000 + #CC000000 + #BB000000 + #99000000 + #88000000 + #66000000 + #44000000 + #33000000 + #22000000 + #0c000000 + + + #808080 + + #FF0000 + + #FFD700 + + #FFFF00 + + #008000 + + #0000FF + + #800080 + + #FFC0CB + + #FFA500 + \ No newline at end of file diff --git a/baselibrary/src/main/res/values/dimens.xml b/widget/src/main/res/values/dimens.xml similarity index 97% rename from baselibrary/src/main/res/values/dimens.xml rename to widget/src/main/res/values/dimens.xml index 6d3bc964..e3876eda 100644 --- a/baselibrary/src/main/res/values/dimens.xml +++ b/widget/src/main/res/values/dimens.xml @@ -1,504 +1,504 @@ - - 1dp - 2dp - 3dp - 4dp - 5dp - 6dp - 7dp - 8dp - 9dp - 10dp - 11dp - 12dp - 13dp - 14dp - 15dp - 16dp - 17dp - 18dp - 19dp - 20dp - 21dp - 22dp - 23dp - 24dp - 25dp - 26dp - 27dp - 28dp - 29dp - 30dp - 31dp - 32dp - 33dp - 34dp - 35dp - 36dp - 37dp - 38dp - 39dp - 40dp - 41dp - 42dp - 43dp - 44dp - 45dp - 46dp - 47dp - 48dp - 49dp - 50dp - 51dp - 52dp - 53dp - 54dp - 55dp - 56dp - 57dp - 58dp - 59dp - 60dp - 61dp - 62dp - 63dp - 64dp - 65dp - 66dp - 67dp - 68dp - 69dp - 70dp - 71dp - 72dp - 73dp - 74dp - 75dp - 76dp - 77dp - 78dp - 79dp - 80dp - 81dp - 82dp - 83dp - 84dp - 85dp - 86dp - 87dp - 88dp - 89dp - 90dp - 91dp - 92dp - 93dp - 94dp - 95dp - 96dp - 97dp - 98dp - 99dp - 100dp - 101dp - 102dp - 103dp - 104dp - 105dp - 106dp - 107dp - 108dp - 109dp - 110dp - 111dp - 112dp - 113dp - 114dp - 115dp - 116dp - 117dp - 118dp - 119dp - 120dp - 121dp - 122dp - 123dp - 124dp - 125dp - 126dp - 127dp - 128dp - 129dp - 130dp - 131dp - 132dp - 133dp - 134dp - 135dp - 136dp - 137dp - 138dp - 139dp - 140dp - 141dp - 142dp - 143dp - 144dp - 145dp - 146dp - 147dp - 148dp - 149dp - 150dp - 151dp - 152dp - 153dp - 154dp - 155dp - 156dp - 157dp - 158dp - 159dp - 160dp - 161dp - 162dp - 163dp - 164dp - 165dp - 166dp - 167dp - 168dp - 169dp - 170dp - 171dp - 172dp - 173dp - 174dp - 175dp - 176dp - 177dp - 178dp - 179dp - 180dp - 181dp - 182dp - 183dp - 184dp - 185dp - 186dp - 187dp - 188dp - 189dp - 190dp - 191dp - 192dp - 193dp - 194dp - 195dp - 196dp - 197dp - 198dp - 199dp - 200dp - 201dp - 202dp - 203dp - 204dp - 205dp - 206dp - 207dp - 208dp - 209dp - 210dp - 211dp - 212dp - 213dp - 214dp - 215dp - 216dp - 217dp - 218dp - 219dp - 220dp - 221dp - 222dp - 223dp - 224dp - 225dp - 226dp - 227dp - 228dp - 229dp - 230dp - 231dp - 232dp - 233dp - 234dp - 235dp - 236dp - 237dp - 238dp - 239dp - 240dp - 241dp - 242dp - 243dp - 244dp - 245dp - 246dp - 247dp - 248dp - 249dp - 250dp - 251dp - 252dp - 253dp - 254dp - 255dp - 256dp - 257dp - 258dp - 259dp - 260dp - 261dp - 262dp - 263dp - 264dp - 265dp - 266dp - 267dp - 268dp - 269dp - 270dp - 271dp - 272dp - 273dp - 274dp - 275dp - 276dp - 277dp - 278dp - 279dp - 280dp - 281dp - 282dp - 283dp - 284dp - 285dp - 286dp - 287dp - 288dp - 289dp - 290dp - 291dp - 292dp - 293dp - 294dp - 295dp - 296dp - 297dp - 298dp - 299dp - 300dp - 301dp - 302dp - 303dp - 304dp - 305dp - 306dp - 307dp - 308dp - 309dp - 310dp - 311dp - 312dp - 313dp - 314dp - 315dp - 316dp - 317dp - 318dp - 319dp - 320dp - 321dp - 322dp - 323dp - 324dp - 325dp - 326dp - 327dp - 328dp - 329dp - 330dp - 331dp - 332dp - 333dp - 334dp - 335dp - 336dp - 337dp - 338dp - 339dp - 340dp - 341dp - 342dp - 343dp - 344dp - 345dp - 346dp - 347dp - 348dp - 349dp - 350dp - 351dp - 352dp - 353dp - 354dp - 355dp - 356dp - 357dp - 358dp - 359dp - 360dp - 361dp - 362dp - 363dp - 364dp - 365dp - 366dp - 367dp - 368dp - 369dp - 370dp - 371dp - 372dp - 373dp - 374dp - 375dp - 376dp - 377dp - 378dp - 379dp - 380dp - 381dp - 382dp - 383dp - 384dp - 385dp - 386dp - 387dp - 388dp - 389dp - 390dp - 391dp - 392dp - 393dp - 394dp - 395dp - 396dp - 397dp - 398dp - 399dp - 400dp - - - 1sp - 2sp - 3sp - 4sp - 5sp - 6sp - 7sp - 8sp - 9sp - 10sp - 11sp - 12sp - 13sp - 14sp - 15sp - 16sp - 17sp - 18sp - 19sp - 20sp - 21sp - 22sp - 23sp - 24sp - 25sp - 26sp - 27sp - 28sp - 29sp - 30sp - 31sp - 32sp - 33sp - 34sp - 35sp - 36sp - 37sp - 38sp - 39sp - 40sp - 41sp - 42sp - 43sp - 44sp - 45sp - 46sp - 47sp - 48sp - 49sp - 50sp - 51sp - 52sp - 53sp - 54sp - 55sp - 56sp - 57sp - 58sp - 59sp - 60sp - 61sp - 62sp - 63sp - 64sp - 65sp - 66sp - 67sp - 68sp - 69sp - 70sp - 71sp - 72sp - 73sp - 74sp - 75sp - 76sp - 77sp - 78sp - 79sp - 80sp - 81sp - 82sp - 83sp - 84sp - 85sp - 86sp - 87sp - 88sp - 89sp - 90sp - 91sp - 92sp - 93sp - 94sp - 95sp - 96sp - 97sp - 98sp - 99sp - 100sp + + 1dp + 2dp + 3dp + 4dp + 5dp + 6dp + 7dp + 8dp + 9dp + 10dp + 11dp + 12dp + 13dp + 14dp + 15dp + 16dp + 17dp + 18dp + 19dp + 20dp + 21dp + 22dp + 23dp + 24dp + 25dp + 26dp + 27dp + 28dp + 29dp + 30dp + 31dp + 32dp + 33dp + 34dp + 35dp + 36dp + 37dp + 38dp + 39dp + 40dp + 41dp + 42dp + 43dp + 44dp + 45dp + 46dp + 47dp + 48dp + 49dp + 50dp + 51dp + 52dp + 53dp + 54dp + 55dp + 56dp + 57dp + 58dp + 59dp + 60dp + 61dp + 62dp + 63dp + 64dp + 65dp + 66dp + 67dp + 68dp + 69dp + 70dp + 71dp + 72dp + 73dp + 74dp + 75dp + 76dp + 77dp + 78dp + 79dp + 80dp + 81dp + 82dp + 83dp + 84dp + 85dp + 86dp + 87dp + 88dp + 89dp + 90dp + 91dp + 92dp + 93dp + 94dp + 95dp + 96dp + 97dp + 98dp + 99dp + 100dp + 101dp + 102dp + 103dp + 104dp + 105dp + 106dp + 107dp + 108dp + 109dp + 110dp + 111dp + 112dp + 113dp + 114dp + 115dp + 116dp + 117dp + 118dp + 119dp + 120dp + 121dp + 122dp + 123dp + 124dp + 125dp + 126dp + 127dp + 128dp + 129dp + 130dp + 131dp + 132dp + 133dp + 134dp + 135dp + 136dp + 137dp + 138dp + 139dp + 140dp + 141dp + 142dp + 143dp + 144dp + 145dp + 146dp + 147dp + 148dp + 149dp + 150dp + 151dp + 152dp + 153dp + 154dp + 155dp + 156dp + 157dp + 158dp + 159dp + 160dp + 161dp + 162dp + 163dp + 164dp + 165dp + 166dp + 167dp + 168dp + 169dp + 170dp + 171dp + 172dp + 173dp + 174dp + 175dp + 176dp + 177dp + 178dp + 179dp + 180dp + 181dp + 182dp + 183dp + 184dp + 185dp + 186dp + 187dp + 188dp + 189dp + 190dp + 191dp + 192dp + 193dp + 194dp + 195dp + 196dp + 197dp + 198dp + 199dp + 200dp + 201dp + 202dp + 203dp + 204dp + 205dp + 206dp + 207dp + 208dp + 209dp + 210dp + 211dp + 212dp + 213dp + 214dp + 215dp + 216dp + 217dp + 218dp + 219dp + 220dp + 221dp + 222dp + 223dp + 224dp + 225dp + 226dp + 227dp + 228dp + 229dp + 230dp + 231dp + 232dp + 233dp + 234dp + 235dp + 236dp + 237dp + 238dp + 239dp + 240dp + 241dp + 242dp + 243dp + 244dp + 245dp + 246dp + 247dp + 248dp + 249dp + 250dp + 251dp + 252dp + 253dp + 254dp + 255dp + 256dp + 257dp + 258dp + 259dp + 260dp + 261dp + 262dp + 263dp + 264dp + 265dp + 266dp + 267dp + 268dp + 269dp + 270dp + 271dp + 272dp + 273dp + 274dp + 275dp + 276dp + 277dp + 278dp + 279dp + 280dp + 281dp + 282dp + 283dp + 284dp + 285dp + 286dp + 287dp + 288dp + 289dp + 290dp + 291dp + 292dp + 293dp + 294dp + 295dp + 296dp + 297dp + 298dp + 299dp + 300dp + 301dp + 302dp + 303dp + 304dp + 305dp + 306dp + 307dp + 308dp + 309dp + 310dp + 311dp + 312dp + 313dp + 314dp + 315dp + 316dp + 317dp + 318dp + 319dp + 320dp + 321dp + 322dp + 323dp + 324dp + 325dp + 326dp + 327dp + 328dp + 329dp + 330dp + 331dp + 332dp + 333dp + 334dp + 335dp + 336dp + 337dp + 338dp + 339dp + 340dp + 341dp + 342dp + 343dp + 344dp + 345dp + 346dp + 347dp + 348dp + 349dp + 350dp + 351dp + 352dp + 353dp + 354dp + 355dp + 356dp + 357dp + 358dp + 359dp + 360dp + 361dp + 362dp + 363dp + 364dp + 365dp + 366dp + 367dp + 368dp + 369dp + 370dp + 371dp + 372dp + 373dp + 374dp + 375dp + 376dp + 377dp + 378dp + 379dp + 380dp + 381dp + 382dp + 383dp + 384dp + 385dp + 386dp + 387dp + 388dp + 389dp + 390dp + 391dp + 392dp + 393dp + 394dp + 395dp + 396dp + 397dp + 398dp + 399dp + 400dp + + + 1sp + 2sp + 3sp + 4sp + 5sp + 6sp + 7sp + 8sp + 9sp + 10sp + 11sp + 12sp + 13sp + 14sp + 15sp + 16sp + 17sp + 18sp + 19sp + 20sp + 21sp + 22sp + 23sp + 24sp + 25sp + 26sp + 27sp + 28sp + 29sp + 30sp + 31sp + 32sp + 33sp + 34sp + 35sp + 36sp + 37sp + 38sp + 39sp + 40sp + 41sp + 42sp + 43sp + 44sp + 45sp + 46sp + 47sp + 48sp + 49sp + 50sp + 51sp + 52sp + 53sp + 54sp + 55sp + 56sp + 57sp + 58sp + 59sp + 60sp + 61sp + 62sp + 63sp + 64sp + 65sp + 66sp + 67sp + 68sp + 69sp + 70sp + 71sp + 72sp + 73sp + 74sp + 75sp + 76sp + 77sp + 78sp + 79sp + 80sp + 81sp + 82sp + 83sp + 84sp + 85sp + 86sp + 87sp + 88sp + 89sp + 90sp + 91sp + 92sp + 93sp + 94sp + 95sp + 96sp + 97sp + 98sp + 99sp + 100sp \ No newline at end of file diff --git a/baselibrary/src/main/res/values/integers.xml b/widget/src/main/res/values/integers.xml similarity index 100% rename from baselibrary/src/main/res/values/integers.xml rename to widget/src/main/res/values/integers.xml