动态获取权限添加顶部文字说明
This commit is contained in:
parent
446aed1574
commit
5fdaa0b213
@ -0,0 +1,11 @@
|
|||||||
|
package com.arpa.hndahesudintocctmsdriver.cuspop
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName MyRequestCallback
|
||||||
|
* @Author john
|
||||||
|
* @Date 2024/10/28 17:19
|
||||||
|
* @Description TODO
|
||||||
|
*/
|
||||||
|
interface MyRequestCallback{
|
||||||
|
fun onResult(allGranted: Boolean, grantedList: List<String?>, deniedList: List<String?>)
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.arpa.hndahesudintocctmsdriver.cuspop
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import com.arpa.hndahesudintocctmsdriver.R
|
||||||
|
import com.lxj.xpopup.core.PositionPopupView
|
||||||
|
import com.lxj.xpopup.enums.DragOrientation
|
||||||
|
import kotlinx.android.synthetic.main.popup_qq_msg.view.tvMessage
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description: 自定义自由定位Position弹窗
|
||||||
|
* Create by dance, at 2019/6/14
|
||||||
|
*/
|
||||||
|
class TopMsgPopup(context: Context, message: String) : PositionPopupView(context) {
|
||||||
|
|
||||||
|
private var message: String
|
||||||
|
|
||||||
|
init {
|
||||||
|
this.message = message
|
||||||
|
}
|
||||||
|
override fun getImplLayoutId(): Int {
|
||||||
|
return R.layout.popup_qq_msg
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getDragOrientation(): DragOrientation {
|
||||||
|
return DragOrientation.DragToLeft
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
tvMessage.text = message
|
||||||
|
}
|
||||||
|
}
|
@ -58,6 +58,7 @@ import com.arpa.hndahesudintocctmsdriver.ui.news.NewActivity;
|
|||||||
import com.arpa.hndahesudintocctmsdriver.ui.wallet.UpBankActivity;
|
import com.arpa.hndahesudintocctmsdriver.ui.wallet.UpBankActivity;
|
||||||
import com.arpa.hndahesudintocctmsdriver.util.MessageUtils;
|
import com.arpa.hndahesudintocctmsdriver.util.MessageUtils;
|
||||||
import com.arpa.hndahesudintocctmsdriver.util.OneDayShowUtils;
|
import com.arpa.hndahesudintocctmsdriver.util.OneDayShowUtils;
|
||||||
|
import com.arpa.hndahesudintocctmsdriver.util.PermissionUtils;
|
||||||
import com.arpa.hndahesudintocctmsdriver.util.SPUtils;
|
import com.arpa.hndahesudintocctmsdriver.util.SPUtils;
|
||||||
import com.arpa.hndahesudintocctmsdriver.util.string.StringUtil;
|
import com.arpa.hndahesudintocctmsdriver.util.string.StringUtil;
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
@ -110,6 +111,7 @@ import org.greenrobot.eventbus.EventBus;
|
|||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import pub.devrel.easypermissions.EasyPermissions;
|
import pub.devrel.easypermissions.EasyPermissions;
|
||||||
@ -564,18 +566,35 @@ public class HomeFragment extends BaseFragment {
|
|||||||
v1.setOnClickListener(v2 -> {
|
v1.setOnClickListener(v2 -> {
|
||||||
switch (position) {
|
switch (position) {
|
||||||
case 0:
|
case 0:
|
||||||
//startActivity(new Intent(con, OrderListActivity.class));
|
PermissionUtils.Companion.getInstance().showPermissionMessage(getActivity(), "用于向您推荐可能感兴趣的住宿、饮食、加油站、汽车维修等",
|
||||||
PermissionX.init(getActivity())
|
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
|
||||||
.permissions(Manifest.permission.ACCESS_FINE_LOCATION)
|
(allGranted, grantedList, deniedList) -> {
|
||||||
.request((allGranted, grantedList, deniedList) -> {
|
|
||||||
if (allGranted) {
|
if (allGranted) {
|
||||||
Intent in = new Intent(con, BusinessActivity.class);
|
Intent in = new Intent(con, BusinessActivity.class);
|
||||||
in.putExtra("type", "餐饮");
|
in.putExtra("type", "餐饮");
|
||||||
startActivity(in);
|
startActivity(in);
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(act.getBaseContext(), "请先开启定位权限", Toast.LENGTH_LONG).show();
|
new MessageUtils().showSimCenPop(con, "缺少定位权限,将无法为您提供服务,去开启!", "取消", "确认", () -> {
|
||||||
|
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||||
|
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||||
|
intent.setData(uri);
|
||||||
|
startActivity(intent);
|
||||||
|
});
|
||||||
|
// Toast.makeText(act.getBaseContext(), "请先开启定位权限", Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
//startActivity(new Intent(con, OrderListActivity.class));
|
||||||
|
// PermissionX.init(getActivity())
|
||||||
|
// .permissions(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||||
|
// .request((allGranted, grantedList, deniedList) -> {
|
||||||
|
// if (allGranted) {
|
||||||
|
// Intent in = new Intent(con, BusinessActivity.class);
|
||||||
|
// in.putExtra("type", "餐饮");
|
||||||
|
// startActivity(in);
|
||||||
|
// } else {
|
||||||
|
// Toast.makeText(act.getBaseContext(), "请先开启定位权限", Toast.LENGTH_LONG).show();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
//Toast.makeText(con,"定位开启失败,请检查配置项",Toast.LENGTH_LONG).show();
|
//Toast.makeText(con,"定位开启失败,请检查配置项",Toast.LENGTH_LONG).show();
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -0,0 +1,136 @@
|
|||||||
|
package com.arpa.hndahesudintocctmsdriver.util
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.annotation.NonNull
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.fragment.app.FragmentActivity
|
||||||
|
import com.arpa.hndahesudintocctmsdriver.cuspop.MessagePop
|
||||||
|
import com.arpa.hndahesudintocctmsdriver.cuspop.MyRequestCallback
|
||||||
|
import com.arpa.hndahesudintocctmsdriver.cuspop.TopMsgPopup
|
||||||
|
import com.arpa.hndahesudintocctmsdriver.cuspop.SimCenterPop
|
||||||
|
import com.lxj.xpopup.XPopup
|
||||||
|
import com.lxj.xpopup.core.BasePopupView
|
||||||
|
import com.permissionx.guolindev.PermissionX
|
||||||
|
import com.permissionx.guolindev.callback.RequestCallback
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName MessageUtils
|
||||||
|
* @Author 用户
|
||||||
|
* @Date 2023/8/15 09:51
|
||||||
|
* @Description TODO
|
||||||
|
*/
|
||||||
|
class PermissionUtils {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun getInstance() = InstanceHelper.sSingle
|
||||||
|
}
|
||||||
|
|
||||||
|
object InstanceHelper {
|
||||||
|
val sSingle = PermissionUtils()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示权限申请
|
||||||
|
* @param activity AppCompatActivity
|
||||||
|
* @param message String
|
||||||
|
* @param permission List<String>
|
||||||
|
* @param callback RequestCallback
|
||||||
|
* @return BasePopupView?
|
||||||
|
*/
|
||||||
|
fun showPermissionMessage(activity: FragmentActivity, message: String,vararg permission:String,callback: MyRequestCallback){
|
||||||
|
val show = XPopup.Builder(activity)
|
||||||
|
.hasShadowBg(false)
|
||||||
|
.hasBlurBg(false)
|
||||||
|
.isTouchThrough(true)
|
||||||
|
.isCenterHorizontal(true)
|
||||||
|
.offsetY(140)
|
||||||
|
.asCustom(
|
||||||
|
TopMsgPopup(
|
||||||
|
activity,
|
||||||
|
message
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.show()
|
||||||
|
|
||||||
|
PermissionX.init(activity)
|
||||||
|
.permissions(listOf(*permission))
|
||||||
|
.request { allGranted, grantedList, deniedList ->
|
||||||
|
show.dismiss()
|
||||||
|
if (callback!=null){
|
||||||
|
callback.onResult(allGranted,grantedList,deniedList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun showCenMessage(ctx: Context, message: String, message2: String) {
|
||||||
|
XPopup.Builder(ctx) //
|
||||||
|
.hasNavigationBar(false)
|
||||||
|
.isDestroyOnDismiss(true) //对于只使用一次的弹窗对象,推荐设置这个
|
||||||
|
.asCustom(MessagePop(ctx, message, message2).setOnMyItemClickListener(object :
|
||||||
|
MessagePop.OnMyItemClickListener {
|
||||||
|
override fun onItemClick(startTime: String, endTime: String) {
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun showSimCenPop(
|
||||||
|
ctx: Context,
|
||||||
|
message: String,
|
||||||
|
onMyItemClickListener: SimCenterPop.OnMyItemClickListener
|
||||||
|
) {
|
||||||
|
|
||||||
|
// XPopup.Builder(ctx) //
|
||||||
|
// .hasNavigationBar(false)
|
||||||
|
// .isDestroyOnDismiss(true) //对于只使用一次的弹窗对象,推荐设置这个
|
||||||
|
// .asCustom(SimCenterPop(ctx,message).setOnMyItemClickListener(object : SimCenterPop.OnMyItemClickListener{
|
||||||
|
// override fun onItemClick() {
|
||||||
|
// val intent = Intent(ctx, CertificatesActivity::class.java)
|
||||||
|
// intent.putExtra("index", type)
|
||||||
|
// ctx.startActivity(intent)
|
||||||
|
// }
|
||||||
|
// }))
|
||||||
|
// .show()
|
||||||
|
|
||||||
|
XPopup.Builder(ctx) //
|
||||||
|
.hasNavigationBar(false)
|
||||||
|
.isDestroyOnDismiss(true) //对于只使用一次的弹窗对象,推荐设置这个
|
||||||
|
.asCustom(SimCenterPop(ctx, message).setOnMyItemClickListener(onMyItemClickListener))
|
||||||
|
.show()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun showSimCenPop(
|
||||||
|
ctx: Context,
|
||||||
|
message: String,
|
||||||
|
left: String,
|
||||||
|
right: String,
|
||||||
|
onMyItemClickListener: SimCenterPop.OnMyItemClickListener
|
||||||
|
) {
|
||||||
|
|
||||||
|
// XPopup.Builder(ctx) //
|
||||||
|
// .hasNavigationBar(false)
|
||||||
|
// .isDestroyOnDismiss(true) //对于只使用一次的弹窗对象,推荐设置这个
|
||||||
|
// .asCustom(SimCenterPop(ctx,message).setOnMyItemClickListener(object : SimCenterPop.OnMyItemClickListener{
|
||||||
|
// override fun onItemClick() {
|
||||||
|
// val intent = Intent(ctx, CertificatesActivity::class.java)
|
||||||
|
// intent.putExtra("index", type)
|
||||||
|
// ctx.startActivity(intent)
|
||||||
|
// }
|
||||||
|
// }))
|
||||||
|
// .show()
|
||||||
|
|
||||||
|
XPopup.Builder(ctx) //
|
||||||
|
.hasNavigationBar(false)
|
||||||
|
.isDestroyOnDismiss(true) //对于只使用一次的弹窗对象,推荐设置这个
|
||||||
|
.asCustom(
|
||||||
|
SimCenterPop(ctx, message, left, right).setOnMyItemClickListener(
|
||||||
|
onMyItemClickListener
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.show()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
5
app/src/main/res/drawable/bg_round2.xml
Normal file
5
app/src/main/res/drawable/bg_round2.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||||
|
<corners android:radius="100dp"/>
|
||||||
|
<solid android:color="#fff"/>
|
||||||
|
</shape>
|
17
app/src/main/res/layout/popup_qq_msg.xml
Normal file
17
app/src/main/res/layout/popup_qq_msg.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical" android:layout_width="match_parent"
|
||||||
|
android:background="@drawable/bg_round2"
|
||||||
|
android:layout_marginLeft="@dimen/dp_16"
|
||||||
|
android:layout_marginRight="@dimen/dp_16"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvMessage"
|
||||||
|
android:padding="20dp"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:text="我是QQ的消息弹窗,嘿嘿!!!"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user