Skip to content

actor20170211030627/MyAndroidFrameWork

Repository files navigation

MyAndroidFrameWork

Github, Gitee码云

注意: 这是 Androidx 版, 非Androidx版本在  这儿  (非Androidx版本不再维护)

Androidx版本能很好向下兼容, 包括jar包依赖也能自动转换, 所以建议转换成Androidx.

安卓常用组件&框架(懒得每次都搭架子...)

1.集成框架包括如下列表, 具体见 build.gradle:

  1. //https://github.com/square/okhttp api "com.squareup.okhttp3:okhttp:4.9.3"
  2. //https://github.com/google/gson //不混淆解析类, 示例: -keep class com.package.xxx.info.** { *; } api 'com.google.code.gson:gson:2.10.1'
  3. //https://github.com/bumptech/glide api 'com.github.bumptech.glide:glide:4.12.0'
  4. //https://github.com/Blankj/AndroidUtilCode 许多工具 api 'com.blankj:utilcodex:1.31.1'
  5. //https://github.com/CymChad/BaseRecyclerViewAdapterHelper api 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.7'
  6. //https://github.com/getActivity/XXPermissions 轮子哥权限 api 'com.github.getActivity:XXPermissions:18.6'
  7. // 吐司框架:https://github.com/getActivity/Toaster 轮子哥吐司 api 'com.github.getActivity:Toaster:12.6'
  8. // Shape 框架:https://github.com/getActivity/ShapeView 轮子哥 api 'com.github.getActivity:ShapeView:9.0'
  9. //https://github.com/getActivity/EasyHttp 轮子哥网络请求框架 api 'com.github.getActivity:EasyHttp:12.8'
  10. // 腾讯 MMKV:https://github.com/Tencent/MMKV (EasyHttp缓存需要) api ('com.tencent:mmkv-static:1.3.2') { // 避免版本不一致导致的依赖冲突,从而导致编译报错 exclude group: 'androidx.annotation', module: 'annotation' }
  11. //https://github.com/li-xiaojun/XPopup 各种Dialog & Popup (compileSdkVersion 29) api 'com.github.li-xiaojun:XPopup:2.9.19'

2.一些控件和工具类等

2.1.ViewPager的Adapter

BaseFragmentPagerAdapter
BaseFragmentStatePagerAdapter
BasePagerAdapter

2.2.Dialog(继承对应Dialog并自定义界面, 不用再关注style等. )

BaseAlertDialog (AlertDialog简单说明)
BaseBottomSheetDialog (从底部弹出并停留底部, 可二次滑动)
BaseDialog (Dialog简单封装)
LoadingDialog (加载Dialog, 耗时操作时可显示这个Dialog)
ViewBindingDialog (可以使用viewBinding)
BaseDialogFragment (dialog样式的Fragment)
BasePopupWindow (PopupWindow简单整理, 可一用)

2.3.Utils工具类

AudioUtils (录音/播放音频)
GreenDaoUtils (GreenDao数据库)
EasyHttpConfigUtils (EasyHttp基本配置 & 封装的WebSocket)
IntJsonDeserializer (解决Gson""转换成int报错)
OkHttpConfigUtils (OkHttp基本配置)
SharedElementUtils (元素共享跳转页面)
VideoProcessorUtils (视频压缩)
AssetsUtils (Assets读取)
Base64Utils (Base64编解码)
BaseCountDownTimer (倒计时, 可暂停, 继续, 获取计时时间)
BRVUtils (BaseRecyclerView框架辅助)
ClickUtils2 (防止2次点击)
LogUtils (Log简单打印)
MMKVUtils (数据缓存)
NotificationUtils2 (通知栏)
SPUtils (SP工具, 建议使用MMKVUtils)
TextUtils2 (获取Text, 判空, getStringFormat, ...)
ThreadUtils (线程判断/切换)
ToasterUtils (吐司工具类-轮子哥)

2.4.Widget小控件

AutoCaculateHeightViewpager (自动计算子类高度的ViewPager)
ScrollableViewPager (ViewPager是否能左右滑动)
BaseWebView (WebView简单封装)
BaseItemDecoration (RecyclerView的Item间隔)
BaseRadioGroup (RadioGroup简单封装)
BaseRatingBar (RatingBar星星选择)
BaseSlidingDrawer (抽屉, 从底部或左侧拉出/收回)
BaseSpinner (Spinner增加一些属性)
BaseTabLayout (更简单使用TabLayout)
BaseTextSwitcher (TextView切换)
BaseViewSwitcher (View切换)
DrawableTextView (支持限定 Drawable 大小的 TextView)
LineView (实线, 虚线, 渐变, 角度)
MarqueeTextView (跑马灯)
RatioLayout (百分比布局, 宽高百分比)
RoundCardView (圆角CardView)
StateListImageView (设置各种状态时的图片)
StatusBarHeightView (状态栏占高)
SwipeRefreshLayoutCompatViewPager (SwipeRefreshLayout适配ViewPager里的下拉)
VerticalScrollableTextView (可垂直滑动的TextView)

3.Screenshot


4.Sample

download apk or scan qrcode:

5.minSdkVersion API

如果您项目的minSdkVersion小于21, 集成后可能会报错: Manifest merger failed with multiple errors, see logs

6.How to

To get a Git project into your build:

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
            //如果发现jitpack的依赖下载不下来, 并报错: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
            //那么这是jitpack网站证书问题, 解决办法:
            //1.AndroidStudio -> Settings -> Build -> Build Tools -> Gradle -> 查看Gradle JDK 目录.
            //2.下载 cacerts 文件, 替换上方的 JDK目录jbr\lib\security\cacerts 文件.(原文件记得自己备份)
            //3.Gradle重新同步一下应该就可以了
        }
    }

Step 2. Add the dependency, the latest version(最新版本): Github:   Gitee:

    android {
      ...
      compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
      }
    }

    dependencies {
            //需要在自己项目中集成constraint包, 版本version>=1.1.3
            implementation 'androidx.constraintlayout:constraintlayout:version xxx'

            //https://github.com/actor20170211030627/MyAndroidFrameWork (基类依赖,这个必须添加)
            implementation 'com.github.actor20170211030627.MyAndroidFrameWork:library:github's latest version'
            implementation 'com.gitee.actor20170211030627.MyAndroidFrameWork:library:gitee's latest version'(Gitee在jitpack不能打包,不再维护 Deprecated)
    }
/**
 * 如果需要图片(裁剪,压缩,自定义相机)、视频、音频的选择和预览, 拍照/拍视频/录音频, 需要添加以下依赖(使用的是 PictureSelector 框架) (按需引入)
 * 并可使用: PictureSelectorUtils
 *          AddAudioAdapter(选择添加音频)
 *          AddPicAdapter(选择添加图片)
 *          AddVideoAdapter(选择添加视频)
 */
implementation 'com.github.actor20170211030627.MyAndroidFrameWork:picture_selector:github's latest version'
// 图片压缩 (按需引入): 如果你选择图片/拍照后, 需要使用压缩图片功能, 需要添加下面这行依赖
implementation 'io.github.lucksiege:compress:v3.11.2'
// 图片裁剪 (按需引入)
implementation 'io.github.lucksiege:ucrop:v3.11.2'
// 自定义相机 (按需引入)
implementation 'io.github.lucksiege:camerax:v3.11.2'
/**
 * 如果需要聊天, 可添加如下依赖 (按需引入)
 * 并可使用: VoiceRecorderView (低仿微信录音)
 *          ChatLayout (聊天框,语言,emoji表情,自定义功能按钮, 效果见上图)
 */
implementation 'com.github.actor20170211030627.MyAndroidFrameWork:chat_layout:github's latest version'
//如果聊天时需要表情, 可添加如下依赖(也可以不添加, 自己自定义表情并传入) (按需引入), emoji表情初始化可参考: MyApplication
implementation 'com.github.actor20170211030627.MyAndroidFrameWork:emojis:github's latest version'
/**
 * 如果需要极光推送, 可添加如下依赖 (按需引入)
 * 并可使用:
 * JPushUtils (极光推送)
 */
 implementation 'com.github.actor20170211030627.MyAndroidFrameWork:jpush:github's latest version'
 //https://github.com/greenrobot/EventBus JPush各种操作&收到消息回调后使用EventBus转发
 implementation 'org.greenrobot:eventbus:3.3.1'
/**
 * 如果需要百度/高德地图, 可添加如下依赖 (按需引入)
 * 并可使用:
 * BaiduGeoCoderUtils (百度地理编码)
 * BaiduLocationUtils (百度地图定位)
 * BaiduMapUtils (百度地图)
 * BaiduUriApiUtils (百度地图Uri调起)(注意: 本工具类不用集成百度地图SDK)
 * GaoDe3DMapUtils (高德3D地图)
 * GaoDeGeoCoderUtils (高德地理编码)
 * GaoDeLocationUtils (高德地图定位)
 * GaoDeShapeUtils (高德画形状小工具)
 * GaoDeUiSettingUtils (高德地图UI界面)
 * GaoDeUriApiUtils (高德地图Uri调起)(注意: 本工具类不用集成高德地图SDK)
 */
 implementation 'com.github.actor20170211030627.MyAndroidFrameWork:map:github's latest version'
/**
 * 如果需要MPAndroidChart 图表, 可添加如下依赖(仅简单封装,可供参考) (按需引入)
 * 并可使用:
 * BarChartUtils (柱状图)
 * LineChartUtils (折线图)
 */
 implementation 'com.github.actor20170211030627.MyAndroidFrameWork:mp_android_chart:github's latest version'
/**
 * 如果需要QQ登录等操作, 微信登录支付等操作, 可添加如下依赖 (按需引入)
 * 并可使用: QQUtils (QQ登录, 获取用户信息, 分享图文/图片/音乐/App/文件, 唤起小程序/小游戏...)
 *          WeChatUtils (微信登录, 获取Token, 分享文字/图片/音乐/视频/网页/小程序/文件, 支付, 订阅消息...)
 */
implementation 'com.github.actor20170211030627.MyAndroidFrameWork:qq_wechat:github's latest version'
/**
 * 如果需要阿里支付or授权, 可添加如下依赖 (按需引入)
 * 并可使用: ALiPayUtils (支付, 授权)
 */
implementation 'com.github.actor20170211030627.MyAndroidFrameWork:ali_pay:github's latest version'
/**
 * 如果需要友盟统计/推送, 可添加如下依赖 (按需引入)
 * 并可使用:
 * UMConfigureUtils (友盟基础配置)
 * UMAnalyticsUtils (友盟统计)
 * UMPushUtils (友盟推送)
 */
 implementation 'com.github.actor20170211030627.MyAndroidFrameWork:umeng:github's latest version'
/**
 * 还有一些其它不常用工具类: (按需引入)
 * BirthdayUtils (生日: 天数倒数, 农历生日, 年龄)
 * TextToSpeechUtils (Android自带文字转语音支持)
 * NineGridView (九宫格)
 * ItemRadioGroupLayout (RadioGroup选择)
 * ItemSpinnerLayout (Spinner选择)
 * ItemTextInputLayout (Text输入)
 * QuickSearchBar (快速查找条a-z)
 * ShowPartImageView (仅显示图片指定部分的内容)
 */
 implementation 'com.github.actor20170211030627.MyAndroidFrameWork:others:github's latest version'

7.AndroidManifest.xml合并清单文件报错

  1. 如果报错: AndroidManifest.xml:15:5-134:19: AAPT: error: attribute android:requestLegacyExternalStorage not found. 报错原因: Google不希望app可以随意操作沙箱(一般是"/data/data/packageName")以外的存储文件,compileSdk29以后如果需要操作非沙箱路径,必须配置"android:requestLegacyExternalStorage="true"属性才行 解决办法(3选1): 1.将 compileSdkVersion 升级到 29 2.删除"android:requestLegacyExternalStorage="true"这个设置 3.如果是第三方库配置的该属性,那么在主项目的AndroidManifest.xml的application增加以下配置"tools:remove="android:requestLegacyExternalStorage"

8.项目中已经添加了混淆文件, 如果需要混淆, 只需在自己项目中打开混淆配置:

    android {
        ...
        buildTypes {
            release {
                minifyEnabled true
                ...
            }
        }
    }

9.使用步骤

1.写一个 Application extends ActorApplication, 然后重写方法, 可参考: MyApplication  (非必须继承, ActorApplication里有一些配置, 可把配置代码copy到自己Application)
2.写一个 BaseActivity extends ActorBaseActivity(或ViewBindingActivity)(非必须继承), 然后你的Activity 继承 BaseActivity
3.写一个 BaseFragment extends ActorBaseFragment(或ViewBindingFragment)(非必须继承), 然后你的Fragment 继承 BaseFragment
4.<style name="AppTheme" parent="AppThemeForMyAndroidFrameWork"> 你的style可继承这个style (非必须继承)

10.有问题请升级到最新版本: Github: Gitee:, 或提交 issues, 发邮箱: email

11.License

License