Skip to content

Commit

Permalink
完善基础组件库
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchong211 committed Aug 19, 2023
1 parent 1ff43ee commit e9493eb
Show file tree
Hide file tree
Showing 143 changed files with 6,811 additions and 1,079 deletions.
2 changes: 1 addition & 1 deletion ActivityManager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
- 直接在maven中依赖如下所示:
``` java
//activity栈管理
implementation 'com.github.yangchong211.YCCommonLib:ActivityManager:1.3.5'
implementation 'com.github.yangchong211.YCCommonLib:ActivityManager:1.4.8'
```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public boolean isExist(Class<?> clazz) {
}

for (int i = 0; i < mActivityStacks.size(); i++) {
if (mActivityStacks.get(i).getClass().getSimpleName()
.equals(clazz.getSimpleName())) {
String simpleName = clazz.getSimpleName();
if (mActivityStacks.get(i).getClass().getSimpleName().equals(simpleName)) {
return true;
}
}
Expand Down
6 changes: 4 additions & 2 deletions AppBaseStore/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apply plugin: 'com.android.library'
apply from: rootProject.projectDir.absolutePath + "/yc.gradle"
apply plugin: 'kotlin-android'
//迁移到jitpack
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'kotlin-android'

android {
compileSdkVersion rootProject.ext.android["compileSdkVersion"]
Expand Down Expand Up @@ -35,7 +35,7 @@ dependencies {
implementation rootProject.ext.dependencies["coreKtx"]
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation(rootProject.ext.dependencies["gson"])
implementation 'com.github.yangchong211.YCCommonLib:AppCommonInter:1.4.3'

implementation project(path: ':ToolUtilsLib')
implementation project(path: ':EventUploadLib')
implementation project(path: ':AppLruDisk')
Expand All @@ -44,5 +44,7 @@ dependencies {
//腾讯mmkv库
implementation "com.tencent:mmkv-static:1.2.7"
implementation project(path: ':AppContextLib')
//通用组件接口库
implementation 'com.github.yangchong211.YCCommonLib:AppCommonInter:1.4.4'
implementation project(path: ':AppFastSp')
}
2 changes: 1 addition & 1 deletion AppBaseStore/src/main/java/com/yc/store/StoreToolHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class StoreToolHelper {

fun setApp(app: Application?) {
if (app == null) {
throw NullPointerException("Argument 'app' of type Application (#0 out of 1, zero-based) is marked by @android.support.annotation.NonNull but got null for it")
throw NullPointerException("Argument 'app' of type Application (#0 out of 1, zero-based) is marked by @androidx.annotation.NonNull but got null for it")
} else {
sApplication = app
}
Expand Down
1 change: 0 additions & 1 deletion AppCallStatus/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ apply from: rootProject.projectDir.absolutePath + "/yc.gradle"
//迁移到jitpack
apply plugin: 'com.github.dcendents.android-maven'


android {
compileSdkVersion rootProject.ext.android["compileSdkVersion"]
//buildToolsVersion rootProject.ext.android["buildToolsVersion"]
Expand Down
1 change: 1 addition & 0 deletions AppClickHelper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
49 changes: 49 additions & 0 deletions AppClickHelper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 多次点击判断库
#### 目录介绍
- 01.基础概念介绍
- 02.常见思路和做法
- 03.Api调用说明
- 04.遇到的坑分析
- 05.其他问题说明



### 01.基础概念介绍
#### 1.1 业务需求说明
- 经常遇到这样的需求类似进入开发者模式,即多次点击后执行操作。


#### 1.5 多次点击事件的原理
- 记录每次点击事件的当前时间,判断最后一次点击与第一次点击事件的时间的差值,如果小于500ms(可以自己定义这个值),认为是多次点击事件。



### 02.常见思路和做法



### 03.Api调用说明




### 04.遇到的坑分析




### 05.其他问题说明



### 06.参考博客说明
- https://www.jb51.net/article/149349.htm









35 changes: 35 additions & 0 deletions AppClickHelper/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
plugins {
id 'com.android.library'
}
apply from: rootProject.projectDir.absolutePath + "/yc.gradle"
//迁移到jitpack
apply plugin: 'com.github.dcendents.android-maven'


android {
compileSdkVersion rootProject.ext.android["compileSdkVersion"]
//buildToolsVersion rootProject.ext.android["buildToolsVersion"]
defaultConfig {
minSdkVersion rootProject.ext.android["minSdkVersion"]
targetSdkVersion rootProject.ext.android["targetSdkVersion"]
versionCode rootProject.ext.android["versionCode"]
versionName rootProject.ext.android["versionName"]
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation(rootProject.ext.dependencies["appcompat"])
implementation(rootProject.ext.dependencies["annotation"])
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yc.componentlib">
package="com.yc.clickhelper">

</manifest>
148 changes: 148 additions & 0 deletions AppClickHelper/src/main/java/com/yc/clickhelper/ClickHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package com.yc.clickhelper;


import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;

import java.util.LinkedList;

public final class ClickHelper {

private final String TAG = ClickHelper.class.getSimpleName();
private static final ClickHelper INSTANCE = new ClickHelper();
private final LinkedList<Long> clickList = new LinkedList<>();
/**
* 检测多次按下的时间间隔
*/
private int TIME_SEP = 300;
private final Handler handler;

private ClickHelper() {
handler = new Handler(Looper.getMainLooper());
}

public static ClickHelper getInstance() {
return ClickHelper.INSTANCE;
}

public void setTimeSep(int timeSep){
if (timeSep < 0){
return;
}
TIME_SEP = timeSep;
}

public void onClickKey(String key) {
if (TextUtils.isEmpty(key)) {
return;
}
//有单击就清理定时器
clearHandle();
//判断三连击
if (clickList.size() == 3) {
clickList.removeFirst();
}
clickList.add(System.currentTimeMillis());
Log.d(TAG, "click add :" + System.currentTimeMillis() + " size:" + clickList.size());
handler.postDelayed(() -> {
//检测是否发生三连击
if (clickList.size() == 3) {
long fistSep = (long) clickList.get(1) - clickList.get(0);
long secondSep = (long) clickList.get(2) - clickList.get(1);
Log.d(TAG, "fistSep :" + fistSep + "secondSep:" + secondSep);
if (fistSep < TIME_SEP && secondSep < TIME_SEP) {
//判定为三连击
onMultipleClick(key);
}
} else {
if (clickList.size() < 3) {
//单击行为
onSingleClick(key);
} else {
Log.d(TAG, "click error " + key);
}
}
//最后一定会清掉
clickList.clear();
}, TIME_SEP);
}

public void onThreeClick(String key) {
onClickKey(key, 3);
}

public void onClickKey(String key, int clickNum) {
if (TextUtils.isEmpty(key)) {
return;
}
//有单击就清理定时器
clearHandle();
//判断三连击
if (clickList.size() == clickNum) {
clickList.removeFirst();
}
clickList.add(System.currentTimeMillis());
Log.d(TAG, "click add :" + System.currentTimeMillis() + " size:" + clickList.size());
handler.postDelayed(() -> {
//检测是否发生三连击
if (clickList.size() == clickNum) {
boolean isMultipleClick = true;
for (int i = 0; (i < clickNum - 1); i++) {
long sep = (long) clickList.get(i + 1) - (long) clickList.get(i);
//只要有一个不符合条件,则就不是num多次连击
if (sep > TIME_SEP) {
isMultipleClick = false;
break;
}
}
if (isMultipleClick) {
onMultipleClick(key);
}
} else {
if (clickList.size() < clickNum) {
//单击行为
onSingleClick(key);
} else {
Log.d(TAG, "click error " + key);
}
}
//最后一定会清掉
clickList.clear();
}, TIME_SEP);
}


private void onSingleClick(String key) {
if (onClickListener != null) {
onClickListener.onSingleClick(key);
}
}

private void onMultipleClick(String key) {
if (onClickListener != null) {
onClickListener.onMultipleClick(key);
}
}

/**
* 清除消息队列
*/
private void clearHandle() {
Log.d(TAG, "clearHandle:清理定时器");
handler.removeCallbacksAndMessages(null);
}

private OnClickListener onClickListener;

public void setOnClickListener(OnClickListener clickListener) {
this.onClickListener = clickListener;
}

public interface OnClickListener {
void onSingleClick(String key);

void onMultipleClick(String key);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.yc.toolutils.click;
package com.yc.clickhelper;

import android.os.Handler;
import android.os.Looper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.yc.toolutils.click;
package com.yc.clickhelper;

import android.text.TextUtils;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.yc.toolutils.click;
package com.yc.clickhelper;


import android.view.View;
Expand Down
15 changes: 10 additions & 5 deletions AppCommonInter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@

### 01.基础概念说明
#### 1.1 业务场景说明
- 背景说明:由于组件化开发中有很多基础组件,由于某些需求,需要统计一些事件,异常上报到平台上,获取控制降级,自定义日志打印等,因此采用接口回调方式实现。
- 背景说明:
- 由于组件化开发中有很多基础组件,由于某些需求,需要统计一些事件,异常上报到平台上,获取控制降级,自定义日志打印等,因此采用接口回调方式实现。


#### 1.3 基础接口库
- IEventTrack,event事件接口,一般用于特殊事件上报作用
- IExceptionTrack,异常事件接口,一般可以用在组件库中catch捕获的时候,上报日志到服务平台操作
- ILogger,log自定义日志接口,一般用于组件库日志打印,暴露给外部开发者
- IMonitorToggle,AB测试开关接口,也可以叫降级开关,一般用于组件库某功能降级操作,暴露给开发者设置
- IEventTrack
- event事件接口,一般用于特殊事件上报作用
- IExceptionTrack
- 异常事件接口,一般可以用在组件库中catch捕获的时候,上报日志到服务平台操作
- ILogger
- log自定义日志接口,一般用于组件库日志打印,暴露给外部开发者
- IMonitorToggle
- AB测试开关接口,也可以叫降级开关,一般用于组件库某功能降级操作,暴露给开发者设置



Expand Down
8 changes: 4 additions & 4 deletions AppCompress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#### 1.2 图片基础概念
- ARGB介绍
- ARGB颜色模型:最常见的颜色模型,设备相关,四种通道,取值均为[0,255],即转化成二进制位0000 0000 ~ 1111 1111。
- ARGB颜色模型:最常见的颜色模型,设备相关,四种通道,取值均为0,255,即转化成二进制位0000 0000 ~ 1111 1111。
- A:Alpha (透明度) R:Red (红) G:Green (绿) B:Blue (蓝)
- Bitmap色彩模式
- Bitmap.Config是Bitmap的一个枚举内部类,它表示的就是每个像素点对ARGB通道值的存储方案。取值有以下四种:
Expand Down Expand Up @@ -49,7 +49,7 @@

#### 2.2 质量压缩
- 在Android中,对图片进行质量压缩,通常我们的实现方式如下所示:
``` java
```
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
//quality 为0~100,0表示最小体积,100表示最高质量,对应体积也是最大
bitmap.compress(Bitmap.CompressFormat.JPEG, quality , outputStream);
Expand All @@ -63,7 +63,7 @@

#### 2.3 尺寸压缩
- 采样率压缩
``` java
```
BitmapFactory.Options options = new BitmapFactory.Options();
//或者 inDensity 搭配 inTargetDensity 使用,算法和 inSampleSize 一样
options.inSampleSize = 2; //设置图片的缩放比例(宽和高) , google推荐用2的倍数:
Expand All @@ -77,7 +77,7 @@

#### 2.4 双线性采样
- 双线性采样(Bilinear Resampling)在 Android 中的使用方式一般有两种:
``` java
```
Bitmap bitmap = BitmapFactory.decodeFile("xxx.png");
Bitmap compress = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth()/2, bitmap.getHeight()/2, true);
Expand Down
Loading

0 comments on commit e9493eb

Please sign in to comment.