日期,图片等选择器封装使用
This commit is contained in:
@@ -174,6 +174,28 @@ public abstract class BaseActivity<VB extends ViewBinding> extends AppCompatActi
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置标题以及主题颜色
|
||||
*/
|
||||
protected void setTitleBar(String title, boolean isWhite, boolean isBack) {
|
||||
mToolbar = (Toolbar) findViewById(R.id.common_toolbar);
|
||||
mToolbar.setBackgroundColor(statusColor == -1 ? Color.TRANSPARENT : ContextCompat.getColor(mContext, statusColor));
|
||||
|
||||
if (isBack) {
|
||||
mToolbar.setNavigationIcon(isWhite ? R.drawable.left : R.drawable.left_black);
|
||||
mToolbar.setNavigationOnClickListener(view -> finish());
|
||||
}
|
||||
if (!TextUtils.isEmpty(title)) {//
|
||||
((TextView) findViewById(R.id.common_toolBar_title)).setTextColor(isWhite ? getColor(R.color.colorWhite) : getColor(R.color.black));
|
||||
((TextView) findViewById(R.id.common_toolBar_title)).setText(title);
|
||||
}
|
||||
if (isWhite){
|
||||
StatusBar.cancelLightStatusBar(this);//图标文字白色
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 显示右边标题
|
||||
*
|
||||
@@ -202,10 +224,13 @@ public abstract class BaseActivity<VB extends ViewBinding> extends AppCompatActi
|
||||
* 设置距离顶部距离
|
||||
*/
|
||||
protected void setStatusHeightParams(View llContent) {
|
||||
RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
closeLayoutParams.topMargin = ConvertUtils.dp2px(8) + BarUtils.getStatusBarHeight();
|
||||
// RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
// closeLayoutParams.topMargin = BarUtils.getStatusBarHeight();
|
||||
llContent.setLayoutParams(closeLayoutParams);
|
||||
// closeLayoutParams.topMargin = BarUtils.getStatusBarHeight();
|
||||
// llContent.setLayoutParams(closeLayoutParams);
|
||||
|
||||
|
||||
llContent.setPadding(0,BarUtils.getStatusBarHeight(),0,0);
|
||||
}
|
||||
|
||||
protected abstract void initView(Bundle savedInstanceState);
|
||||
|
||||
@@ -5,7 +5,7 @@ package com.dahe.mylibrary.base
|
||||
* @Author 用户
|
||||
* @Date 2023/12/29 09:49
|
||||
* @Description //要实现单例类,就只需要继承这个 BaseSingleton 即可
|
||||
//P为参数,T为返回值
|
||||
//P为参数,T为返回值
|
||||
*/
|
||||
abstract class BaseSingleton<in P, out T> {
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.dahe.mylibrary.callback
|
||||
|
||||
import com.luck.picture.lib.entity.LocalMedia
|
||||
|
||||
/**
|
||||
* @ClassName OnPicResultListener
|
||||
* @Author john
|
||||
* @Date 2024/2/6 14:48
|
||||
* @Description TODO
|
||||
*/
|
||||
fun interface OnPicResultListener {
|
||||
fun onResult(result: MutableList<LocalMedia>)
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import android.content.Context
|
||||
import android.widget.Button
|
||||
import com.dahe.mylibrary.R
|
||||
import com.dahe.mylibrary.adapter.GridImageAdapter
|
||||
import com.dahe.mylibrary.callback.OnPicResultListener
|
||||
import com.dahe.mylibrary.utils.SelectPicUtils
|
||||
import com.dahe.mylibrary.utils.ToastUtils
|
||||
import com.dahe.mylibrary.weight.GlideEngine
|
||||
@@ -26,11 +27,11 @@ import kotlin.math.min
|
||||
class PopBottomPic(
|
||||
context: Context,
|
||||
myAdapter: GridImageAdapter,
|
||||
onPicResultListener: onPicResultListener
|
||||
onPicResultListener: OnPicResultListener
|
||||
) : BottomPopupView(context) {
|
||||
|
||||
|
||||
private var listener: onPicResultListener
|
||||
private var listener: OnPicResultListener
|
||||
var myAdapter: GridImageAdapter
|
||||
|
||||
init {
|
||||
@@ -38,12 +39,14 @@ class PopBottomPic(
|
||||
this.myAdapter = myAdapter
|
||||
}
|
||||
|
||||
|
||||
override fun getImplLayoutId() = R.layout.choice_car_timg
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
var paizhao = findViewById<Button>(R.id.btn_paizhao)
|
||||
var xiangce = findViewById<Button>(R.id.btnXiangce)
|
||||
var btnQuxiao = findViewById<Button>(R.id.btn_quxiao)
|
||||
paizhao.setOnClickListener {
|
||||
|
||||
// 单独拍照
|
||||
@@ -103,6 +106,11 @@ class PopBottomPic(
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
btnQuxiao.setOnClickListener {
|
||||
dismiss()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun openCam() {
|
||||
@@ -110,13 +118,4 @@ class PopBottomPic(
|
||||
.openCamera(SelectMimeType.TYPE_IMAGE)
|
||||
}
|
||||
|
||||
|
||||
// private listener : onPicResultListener
|
||||
fun interface onPicResultListener {
|
||||
fun onResult(result: java.util.ArrayList<LocalMedia>)
|
||||
}
|
||||
|
||||
// fun setOnPicResultListener(listener: onPicResultListener){
|
||||
// this.listener
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package com.dahe.mylibrary.pop
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.Button
|
||||
import com.dahe.mylibrary.R
|
||||
import com.dahe.mylibrary.adapter.GridImageAdapter
|
||||
import com.dahe.mylibrary.callback.OnPicResultListener
|
||||
import com.dahe.mylibrary.weight.GlideEngine
|
||||
import com.dahe.mylibrary.weight.ImageFileCompressEngine
|
||||
import com.luck.picture.lib.basic.PictureSelectionCameraModel
|
||||
import com.luck.picture.lib.basic.PictureSelectionModel
|
||||
import com.luck.picture.lib.basic.PictureSelector
|
||||
import com.luck.picture.lib.config.SelectMimeType
|
||||
import com.luck.picture.lib.config.SelectModeConfig
|
||||
import com.luck.picture.lib.entity.LocalMedia
|
||||
import com.luck.picture.lib.interfaces.OnResultCallbackListener
|
||||
import com.lxj.xpopup.core.BottomPopupView
|
||||
|
||||
/**
|
||||
* @ClassName PopBottomPic
|
||||
* @Author john
|
||||
* @Date 2024/1/31 11:11
|
||||
* @Description TODO
|
||||
*/
|
||||
class PopNorBottomPic(
|
||||
context: Context,
|
||||
onPicResultListener: OnPicResultListener
|
||||
) : BottomPopupView(context) {
|
||||
|
||||
|
||||
private var listener: OnPicResultListener
|
||||
|
||||
init {
|
||||
this.listener = onPicResultListener
|
||||
}
|
||||
|
||||
|
||||
override fun getImplLayoutId() = R.layout.choice_norcar_img
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
var paizhao = findViewById<Button>(R.id.btn_paizhao)
|
||||
var xiangce = findViewById<Button>(R.id.btnXiangce)
|
||||
var btnQuxiao = findViewById<Button>(R.id.btn_quxiao)
|
||||
paizhao.setOnClickListener {
|
||||
|
||||
// 单独拍照
|
||||
val cameraModel: PictureSelectionCameraModel = PictureSelector.create(context)
|
||||
.openCamera(SelectMimeType.TYPE_IMAGE)
|
||||
// .setCameraInterceptListener(getCustomCameraEvent())//自定义相机
|
||||
// .setRecordAudioInterceptListener(MainActivity.MeOnRecordAudioInterceptListener())//录音回调事件
|
||||
// .setCropEngine(ImageFileCropEngine())//裁剪
|
||||
.setCompressEngine(ImageFileCompressEngine())//压缩
|
||||
|
||||
// .setSelectLimitTipsListener(MainActivity.MeOnSelectLimitTipsListener())//拦截自定义提示
|
||||
// .setAddBitmapWatermarkListener(getAddBitmapWatermarkListener())//给图片添加水印
|
||||
// .setVideoThumbnailListener(getVideoThumbnailEventListener())//处理视频缩略图
|
||||
// .setCustomLoadingListener(getCustomLoadingListener())//自定义loading
|
||||
// .setSandboxFileEngine(MainActivity.MeSandboxFileEngine())//自定义沙盒文件处理
|
||||
// .isOriginalControl(cb_original.isChecked())//是否开启原图功能
|
||||
// .setPermissionDescriptionListener(getPermissionDescriptionListener())//权限说明
|
||||
// .setOutputAudioDir(getSandboxAudioOutputPath())//创建音频自定义输出目录
|
||||
// .setSelectedData(myAdapter.data)
|
||||
cameraModel.forResult(object : OnResultCallbackListener<LocalMedia> {
|
||||
override fun onResult(result: ArrayList<LocalMedia>?) {
|
||||
if (listener != null) {
|
||||
result?.let { it1 -> listener.onResult(it1) }
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
|
||||
override fun onCancel() {
|
||||
dismiss()
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
xiangce.setOnClickListener {
|
||||
|
||||
// 进入相册
|
||||
val selectionModel: PictureSelectionModel = PictureSelector.create(context)
|
||||
.openGallery(SelectMimeType.TYPE_IMAGE)
|
||||
.isDisplayCamera(false)//关闭拍照
|
||||
.setImageEngine(GlideEngine.createGlideEngine())
|
||||
.setCompressEngine(ImageFileCompressEngine())
|
||||
.isPreviewImage(true)
|
||||
.isMaxSelectEnabledMask(true)
|
||||
.setMaxSelectNum(1)
|
||||
.setSelectionMode(SelectModeConfig.SINGLE )
|
||||
.isGif(false)
|
||||
// .isDirectReturnSingle(true)
|
||||
// .setSelectedData(myAdapter.data)
|
||||
selectionModel.forResult(object : OnResultCallbackListener<LocalMedia> {
|
||||
override fun onResult(result: ArrayList<LocalMedia>) {
|
||||
if (listener != null) {
|
||||
result?.let { it1 -> listener.onResult(it1) }
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
|
||||
override fun onCancel() {
|
||||
dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
btnQuxiao.setOnClickListener {
|
||||
dismiss()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun openCam() {
|
||||
PictureSelector.create(context)
|
||||
.openCamera(SelectMimeType.TYPE_IMAGE)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.dahe.mylibrary.utils
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.dahe.mylibrary.base.SingletonNoPHolder
|
||||
import com.github.gzuliyujiang.wheelpicker.BirthdayPicker
|
||||
import com.github.gzuliyujiang.wheelpicker.OptionPicker
|
||||
import com.github.gzuliyujiang.wheelpicker.contract.OnDatePickedListener
|
||||
import com.github.gzuliyujiang.wheelpicker.contract.OnOptionPickedListener
|
||||
import com.github.gzuliyujiang.wheelpicker.entity.DateEntity
|
||||
|
||||
/**
|
||||
* @ClassName PickUtils
|
||||
* @Author john
|
||||
* @Date 2024/2/5 14:48
|
||||
* @Description 选择器工具类
|
||||
*/
|
||||
class PickerUtils private constructor() {
|
||||
companion object : SingletonNoPHolder<PickerUtils>(::PickerUtils)
|
||||
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* 底部弹出生日日期选择
|
||||
* @param activity
|
||||
* @param title 日期选择title
|
||||
* @param dateEntity 默认参数:默认当天
|
||||
* @param listener
|
||||
*/
|
||||
fun showDate(
|
||||
activity: AppCompatActivity,
|
||||
title: String = "",
|
||||
dateEntity: DateEntity = DateEntity.today(),
|
||||
listener: OnDatePickedListener
|
||||
) {
|
||||
val picker = BirthdayPicker(activity)
|
||||
picker.setTitle(title)
|
||||
picker.setDefaultValue(dateEntity.year, dateEntity.month, dateEntity.day)
|
||||
picker.setOnDatePickedListener(listener)
|
||||
picker.wheelLayout.setResetWhenLinkage(false)
|
||||
picker.show()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 选择驾驶证类型
|
||||
* @param activity
|
||||
* @param title
|
||||
* @param listener
|
||||
*/
|
||||
fun showSelectCarType(
|
||||
activity: AppCompatActivity,
|
||||
title: String = "",
|
||||
listener: OnOptionPickedListener
|
||||
) {
|
||||
OptionPicker(activity)
|
||||
.run {
|
||||
setData("A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2")
|
||||
setDefaultValue("B1")
|
||||
setTitle(title)
|
||||
setOnOptionPickedListener(listener)
|
||||
show()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.dahe.mylibrary.utils
|
||||
|
||||
import android.content.Context
|
||||
import com.dahe.mylibrary.adapter.GridImageAdapter
|
||||
import com.dahe.mylibrary.base.SingletonHolder
|
||||
import com.dahe.mylibrary.base.SingletonNoPHolder
|
||||
import com.dahe.mylibrary.callback.OnPicResultListener
|
||||
import com.dahe.mylibrary.pop.PopBottomPic
|
||||
import com.dahe.mylibrary.pop.PopNorBottomPic
|
||||
import com.lxj.xpopup.XPopup
|
||||
|
||||
/**
|
||||
* @ClassName PopsUtils
|
||||
* @Author john
|
||||
* @Date 2024/2/6 10:11
|
||||
* @Description TODO
|
||||
*/
|
||||
class PopsUtils private constructor(){
|
||||
|
||||
|
||||
|
||||
companion object : SingletonNoPHolder<PopsUtils>(::PopsUtils)
|
||||
|
||||
/**
|
||||
* 选择装卸货照片
|
||||
*
|
||||
* @param myAdapter
|
||||
* @param listenter 结果回调
|
||||
*/
|
||||
fun showSelPic(ctx: Context,myAdapter: GridImageAdapter, listenter: OnPicResultListener){
|
||||
XPopup.Builder(ctx)
|
||||
.dismissOnTouchOutside(true)
|
||||
.asCustom(PopBottomPic(ctx, myAdapter, listenter))
|
||||
.show()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 选择照片 拍照或者相机
|
||||
*
|
||||
* @param ctx
|
||||
* @param listenter
|
||||
*/
|
||||
fun showSimSelPic(ctx: Context, listenter: OnPicResultListener){
|
||||
|
||||
XPopup.Builder(ctx)
|
||||
.dismissOnTouchOutside(true)
|
||||
.asCustom(PopNorBottomPic(ctx, listenter))
|
||||
.show()
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,8 @@ class SelectPicUtils private constructor(
|
||||
|
||||
}
|
||||
|
||||
fun openCam(){}
|
||||
fun openCam(){
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/pop_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_marginLeft="@dimen/dp_12"
|
||||
android:layout_marginRight="@dimen/dp_12"
|
||||
android:layout_marginBottom="@dimen/dp_43"
|
||||
android:layout_marginBottom="@dimen/dp_20"
|
||||
android:background="@drawable/bg_bai"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="@dimen/dp_10">
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/pop_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/dp_12"
|
||||
android:layout_marginRight="@dimen/dp_12"
|
||||
android:layout_marginBottom="@dimen/dp_20"
|
||||
android:background="@drawable/bg_bai"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="@dimen/dp_10">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/llXc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnXiangce"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:text="相册"
|
||||
android:textColor="#000"
|
||||
android:textSize="@dimen/sp_15"
|
||||
|
||||
/>
|
||||
|
||||
<View
|
||||
android:id="@+id/v_1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dp_1"
|
||||
android:layout_marginLeft="@dimen/dp_18"
|
||||
android:layout_marginRight="@dimen/dp_18"
|
||||
android:background="#EEEEEE" />
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_paizhao"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:text="拍照"
|
||||
android:textColor="#000"
|
||||
android:textSize="@dimen/sp_15" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dp_1"
|
||||
android:layout_marginLeft="@dimen/dp_18"
|
||||
android:layout_marginRight="@dimen/dp_18"
|
||||
android:background="#EEEEEE" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_quxiao"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:text="取消"
|
||||
android:textColor="#ff999999"
|
||||
android:textSize="@dimen/sp_15"
|
||||
android:textStyle="normal" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
Reference in New Issue
Block a user