diff --git a/app/build.gradle b/app/build.gradle index 2a75cf8..0531e8e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,12 +12,6 @@ android { // 混淆配置 proguardFiles 'proguard-app.pro' - - // 清单占位符 - addManifestPlaceholders([ - 'AMAP_KEY' : AMAP_KEY, - 'HUAWEI_APP_ID' : HUAWEI_APP_ID - ]) } // 签名参考: https://www.jianshu.com/p/a1f8e5896aa2 @@ -123,6 +117,4 @@ dependencies { implementation DEPENDENCIES['x-banner'] implementation DEPENDENCIES['switch-button'] implementation DEPENDENCIES['aurora-imui'] - implementation 'com.umeng.umsdk:huawei-umengaccs:2.0.0' - implementation 'com.huawei.hms:push:6.9.0.300' } diff --git a/app/proguard-app.pro b/app/proguard-app.pro index 5c93ab1..fcd56cb 100644 --- a/app/proguard-app.pro +++ b/app/proguard-app.pro @@ -71,15 +71,4 @@ # 禁止类名混淆,否则通过类名称找不到类 -keep class com.kanglai.push.entity.**{*;} -keep class com.kanglai.push.ui.activity.**{*;} --keep class com.kanglai.push.ui.fragment.**{*;} - -# 禁止华为厂商混淆 --ignorewarnings --keepattributes *Annotation* --keepattributes Exceptions --keepattributes InnerClasses --keepattributes Signature --keepattributes SourceFile,LineNumberTable --keep class com.huawei.hianalytics.**{*;} --keep class com.huawei.updatesdk.**{*;} --keep class com.huawei.hms.**{*;} \ No newline at end of file +-keep class com.kanglai.push.ui.fragment.**{*;} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 35668a3..caed283 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,6 +4,7 @@ package="com.kanglai.push"> + @@ -24,17 +25,9 @@ - - - - - - - - @@ -54,18 +47,6 @@ tools:replace="android:label" tools:targetApi="q"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/kanglai/push/app/AppApplication.java b/app/src/main/java/com/kanglai/push/app/AppApplication.java index c762503..4c85d9d 100644 --- a/app/src/main/java/com/kanglai/push/app/AppApplication.java +++ b/app/src/main/java/com/kanglai/push/app/AppApplication.java @@ -1,24 +1,15 @@ package com.kanglai.push.app; -import android.content.Intent; -import android.text.TextUtils; - import androidx.core.content.ContextCompat; -import com.blankj.utilcode.util.CacheDiskUtils; -import com.blankj.utilcode.util.LogUtils; import com.bumptech.glide.Glide; import com.dolphin.core.BuildConfig; import com.dolphin.core.base.BaseApplication; import com.dolphin.core.crash.CaocConfig; import com.dolphin.umeng.UmengClient; -import com.huawei.hms.aaid.HmsInstanceId; -import com.huawei.hms.common.ApiException; import com.kanglai.push.R; -import com.kanglai.push.constant.CacheConstant; import com.kanglai.push.di.component.AppComponent; import com.kanglai.push.di.component.DaggerAppComponent; -import com.kanglai.push.offline.HuaWeiHmsMessageService; import com.kanglai.push.ui.activity.LoginActivity; import com.kanglai.push.util.TimeFormatUtil; import com.kongzue.dialogx.DialogX; @@ -28,8 +19,6 @@ import com.scwang.smart.refresh.header.ClassicsHeader; import com.scwang.smart.refresh.layout.SmartRefreshLayout; import com.tencent.bugly.crashreport.CrashReport; -import org.android.agoo.huawei.HuaWeiRegister; - import javax.inject.Inject; import io.github.inflationx.calligraphy3.CalligraphyConfig; @@ -113,7 +102,8 @@ public class AppApplication extends BaseApplication { .setPrimaryColor(ContextCompat.getColor(this, R.color.common_app_them)) .setAccentColor(ContextCompat.getColor(this, R.color.white)); }); - // 第三方 Kongzue DialogX 初始化 + + // 第三方 DialogX 初始化 // https://github.com/kongzue/DialogX/wiki/ DialogX.init(this); DialogX.DEBUGMODE = true; // 开启调试模式 @@ -123,33 +113,6 @@ public class AppApplication extends BaseApplication { DialogX.enterAnimDuration = 100; DialogX.exitAnimDuration = 100; // 动画完成时间 - // 检查华为token - String huawei_token = CacheDiskUtils.getInstance().getString(CacheConstant.HUAWEI_TOKEN, ""); - - if (TextUtils.isEmpty(huawei_token)) HuaweiPushUtils(); // 当华为token为空时才申请华为token - } - - private void HuaweiPushUtils() { - // 获取华为设备token - // https://developer.huawei.com/consumer/cn/doc/development/HMSCore-References/hms-instanceid-0000001050255634#section1796315281618 - new Thread(new Runnable() { - @Override - public void run() { - HmsInstanceId instanceId = HmsInstanceId.getInstance(AppApplication.this); - try { - String huawei_token = instanceId.getToken("108750031", "HCM"); - if (!TextUtils.isEmpty(huawei_token)) { - // 当设备为华为时 才会有华为token 设备token不为空时启动服务 - LogUtils.d("HUAWEI_HMS_TOKEN " + huawei_token); - CacheDiskUtils.getInstance().put(CacheConstant.HUAWEI_TOKEN, huawei_token); - Intent serviceIntent = new Intent(getApplicationContext(), HuaWeiHmsMessageService.class); - getApplicationContext().startForegroundService(serviceIntent); - } - } catch (ApiException e) { - e.printStackTrace(); - } - } - }).start(); } @Override diff --git a/app/src/main/java/com/kanglai/push/constant/CacheConstant.java b/app/src/main/java/com/kanglai/push/constant/CacheConstant.java index 797baa3..80a35a1 100644 --- a/app/src/main/java/com/kanglai/push/constant/CacheConstant.java +++ b/app/src/main/java/com/kanglai/push/constant/CacheConstant.java @@ -1,9 +1,5 @@ package com.kanglai.push.constant; -import com.blankj.utilcode.util.CacheDiskUtils; -import com.kanglai.push.entity.User; -import com.tencent.mmkv.MMKV; - /** *

* 缓存常量 @@ -13,6 +9,7 @@ import com.tencent.mmkv.MMKV; * @since: 2022/10/21 */ public interface CacheConstant { + /** 登录名称存储键 */ String LOGIN_USERNAME = "LOGIN_USERNAME"; @@ -25,9 +22,4 @@ public interface CacheConstant { /** 当前用户信息 */ String USER_INFO = "USER_INFO"; - /** 华为token存储键 只有应用安装后调用一次 */ - String HUAWEI_TOKEN = "HUAWEI_TOKEN"; - - /** 通知设置-app内消息弹窗 - 默认打开*/ - String NOTIFICATION_APP_POP_UP = "NOTIFICATION_APP_POP_UP"; } diff --git a/app/src/main/java/com/kanglai/push/constant/CommonConstant.java b/app/src/main/java/com/kanglai/push/constant/CommonConstant.java index 9aa6b60..c79bc8c 100644 --- a/app/src/main/java/com/kanglai/push/constant/CommonConstant.java +++ b/app/src/main/java/com/kanglai/push/constant/CommonConstant.java @@ -18,9 +18,6 @@ public interface CommonConstant { /** oss文件预览地址 */ String OSS_FILE_URL = BuildConfig.HOST_URL+"system_proxy/system/file/getFile/%s/%s"; - /** 路线规划经纬度 */ - String ROUTE_PLAN_LAT_POINT = "ROUTE_PLAN_LAT_POINT"; - /** 基础用户id */ String USER_LINK_ID = "USER_LINK_ID"; @@ -32,9 +29,12 @@ public interface CommonConstant { */ String USER_LINK_TYPE = "USER_LINK_TYPE"; + /** app 端登录租户id 默认为长沙康来租户id */ String MULTI_TENANT_ID = "1510456530575347712"; + /** app 端登录用户类型 */ String ID_ENTITY_PROVIDER = "app"; + } diff --git a/app/src/main/java/com/kanglai/push/offline/HuaWeiHmsMessageService.java b/app/src/main/java/com/kanglai/push/offline/HuaWeiHmsMessageService.java deleted file mode 100644 index 1c53c29..0000000 --- a/app/src/main/java/com/kanglai/push/offline/HuaWeiHmsMessageService.java +++ /dev/null @@ -1,201 +0,0 @@ -package com.kanglai.push.offline; - -import android.content.Intent; -import android.widget.RemoteViews; - -import com.blankj.utilcode.util.LogUtils; -import com.dolphin.core.util.NotificationUtil; -import com.huawei.hms.push.HmsMessageService; -import com.huawei.hms.push.RemoteMessage; -import com.huawei.hms.push.SendException; - -import java.util.Arrays; - -/** - * 华为离线服务 - * - * 仅用于接收透传消息、获取Token(可删除) - * @Author: liusixiang007 - * @since: 2023/7/24 - */ -public class HuaWeiHmsMessageService extends HmsMessageService { - private static final String TAG = "HuaWeiHmsMessageServiceLog"; - private final static String CODELABS_ACTION = "com.dolphin.umeng.service.action"; - - @Override - public void onNewToken(String token) { - super.onNewToken(token); - LogUtils.d(TAG, "received refresh token:" + token); - if (token == null) { - // 这个方法回调必须在10秒内完成。否则,您需要启动一个新的Job进行回调处理。 - refreshedTokenToServer(token); - } - - LogUtils.d("huaweiseriver-onNewToken"); - Intent intent = new Intent(); - intent.setAction(CODELABS_ACTION); - intent.putExtra("method", "onNewToken"); - intent.putExtra("msg", "onNewToken called, token: " + token); - sendBroadcast(intent); // 进行广播通讯 - } - - private void refreshedTokenToServer(String token) { - LogUtils.i(TAG, "sending token to server. token:" + token); - } - - /** - * 接收服务端推送的透传消息 - * - * 该方法回调必须在10秒内完成。否则,需要启动一个新的Job进行回调处理。 - * @param message - */ - @Override - public void onMessageReceived(RemoteMessage message) { - super.onMessageReceived(message); - - // 判断消息是否为空 - if (message == null) { - LogUtils.e(TAG, "接收的华为推送数据为空!"); - return; - } - // 透传的消息数据 - LogUtils.i(TAG, "get Data: " + message.getData() - + "\n getFrom: " + message.getFrom() - + "\n getTo: " + message.getTo() - + "\n getMessageId: " + message.getMessageId() - + "\n getSentTime: " + message.getSentTime() - + "\n getDataMap: " + message.getDataOfMap() - + "\n getMessageType: " + message.getMessageType() - + "\n getTtl: " + message.getTtl() - + "\n getToken: " + message.getToken()); - -// LogUtils.i(TAG, "getCollapseKey: " + message.getCollapseKey() -// + "\n getData: " + message.getData() -// + "\n getFrom: " + message.getFrom() -// + "\n getTo: " + message.getTo() -// + "\n getMessageId: " + message.getMessageId() -// + "\n getMessageType: " + message.getMessageType() -// + "\n getSendTime: " + message.getSentTime() -// + "\n getTtl: " + message.getTtl() -// + "\n getSendMode: " + message.getSendMode() -// + "\n getReceiptMode: " + message.getReceiptMode() -// + "\n getOriginalUrgency: " + message.getOriginalUrgency() -// + "\n getUrgency: " + message.getUrgency() -// + "\n getToken: " + message.getToken()); - // getBody()获取消息的显示内容 - // getTitle()获取消息的标题 - // getTitleLocalizationKey()获取通知消息显示标题的键。 - // getTitleLocalizationArgs()获取消息显示标题的可变参数 - // getBodyLocalizationkey() - // 获取消息显示内容的密钥getBodyLocalizationArgs() - // 获取消息显示内容的可变参数getIcon() - // 从消息中获取图标getSound() - // 从消息中获取声音getTag() - // 从消息中获取用于消息覆盖的标记 - // getColor()获取消息中图标的颜色 - // getClickAction()获取由消息点击触发的操作 - // getChannelId()获取支持显示消息的通道的 - // idgetImageUr1()从消息中获取图像 - // URLgetLink()从消息获取要访问的URL - // getNotifyId()获取消息的唯一ID - - RemoteMessage.Notification notification = message.getNotification(); - if (notification != null) { - LogUtils.i(TAG, "\n getTitle: " + notification.getTitle() - + "\n getTitleLocalizationKey: " + notification.getTitleLocalizationKey() - + "\n getTitleLocalizationArgs: " + Arrays.toString(notification.getTitleLocalizationArgs()) - + "\n getBody: " + notification.getBody() - + "\n getBodyLocalizationKey: " + notification.getBodyLocalizationKey() - + "\n getBodyLocalizationArgs: " + Arrays.toString(notification.getBodyLocalizationArgs()) - + "\n getIcon: " + notification.getIcon() - + "\n getImageUrl: " + notification.getImageUrl() - + "\n getSound: " + notification.getSound() - + "\n getTag: " + notification.getTag() - + "\n getColor: " + notification.getColor() - + "\n getClickAction: " + notification.getClickAction() - + "\n getIntentUri: " + notification.getIntentUri() - + "\n getChannelId: " + notification.getChannelId() - + "\n getLink: " + notification.getLink() - + "\n getNotifyId: " + notification.getNotifyId() - + "\n isDefaultLight: " + notification.isDefaultLight() - + "\n isDefaultSound: " + notification.isDefaultSound() - + "\n isDefaultVibrate: " + notification.isDefaultVibrate() - + "\n getWhen: " + notification.getWhen() - + "\n getLightSettings: " + Arrays.toString(notification.getLightSettings()) - + "\n isLocalOnly: " + notification.isLocalOnly() - + "\n getBadgeNumber: " + notification.getBadgeNumber() - + "\n isAutoCancel: " + notification.isAutoCancel() - + "\n getImportance: " + notification.getImportance() - + "\n getTicker: " + notification.getTicker() - + "\n getVibrateConfig: " + Arrays.toString(notification.getVibrateConfig()) - + "\n getVisibility: " + notification.getVisibility()); - } - - RemoteViews customNotificationView = new RemoteViews(getApplicationContext().getPackageName(), com.dolphin.umeng.R.layout.layout_notification_view); - customNotificationView.setTextViewText(com.dolphin.umeng.R.id.notification_title, notification.getTitle()); - customNotificationView.setTextViewText(com.dolphin.umeng.R.id.notification_text, notification.getBody()); -// customNotificationView.setImageViewBitmap(com.dolphin.umeng.R.id.notification_large_icon, getLargeIcon(context, msg)); -// customNotificationView.setImageViewResource(com.dolphin.umeng.R.id.notification_small_icon, getSmallIconId(context, msg)); - NotificationUtil.defaultNotificationBuilder().setCustomHeadsUpContentView(customNotificationView).build(); - - Intent intents = new Intent(); - intents.setAction(CODELABS_ACTION); - intents.putExtra("method", "onMessageReceived"); - intents.putExtra("msg", "onMessageReceived called, message id:" + message.getMessageId() + ", payload data:" + message.getData()); - - sendBroadcast(intents); - - Boolean judgeWhetherIn10s = false; - - // 如果10秒内没有处理完消息,应用程序需要使用WorkManager进行处理。 - if (judgeWhetherIn10s) { - startWorkManagerJob(message); - } else { - // 10秒内处理消息 - processWithin10s(message); - } - } - - private void processWithin10s(RemoteMessage message) { - LogUtils.d(TAG, "Processing now."); - } - - private void startWorkManagerJob(RemoteMessage message) { - LogUtils.d(TAG, "Start new Job processing."); - } - - @Override - public void onMessageSent(String msgId) { - LogUtils.i(TAG, "onMessageSent called, Message id:" + msgId); - super.onMessageSent(msgId); - LogUtils.d("huaweiseriver-onNewToken"); - Intent intent = new Intent(); - intent.setAction(CODELABS_ACTION); - intent.putExtra("method", "onMessageSent"); - intent.putExtra("msg", "onMessageSent called, Message id:" + msgId); - sendBroadcast(intent); - } - - @Override - public void onSendError(String s, Exception e) { - super.onSendError(s, e); - LogUtils.i(TAG, "onSendError called, message id:" + s + ", ErrCode:" - + ((SendException) e).getErrorCode() + ", description:" + e.getMessage()); - - LogUtils.d("huaweiseriver-onNewToken"); - Intent intent = new Intent(); - intent.setAction(CODELABS_ACTION); - intent.putExtra("method", "onSendError"); - intent.putExtra("msg", "onSendError called, message id:" + s + ", ErrCode:" - + ((SendException) e).getErrorCode() + ", description:" + e.getMessage()); - - sendBroadcast(intent); - } - - @Override - public void onTokenError(Exception e) { - super.onTokenError(e); - // 获取失败触发 - LogUtils.d("onTokenError:"+e); - } -} diff --git a/app/src/main/java/com/kanglai/push/ui/activity/AuroraActivity.java b/app/src/main/java/com/kanglai/push/ui/activity/AuroraActivity.java deleted file mode 100644 index 197d252..0000000 --- a/app/src/main/java/com/kanglai/push/ui/activity/AuroraActivity.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.kanglai.push.ui.activity; - -import android.os.Bundle; -import android.os.PersistableBundle; - -import androidx.annotation.Nullable; -import androidx.databinding.library.baseAdapters.BR; - -import com.dolphin.core.base.BaseActivity; -import com.kanglai.push.R; -import com.kanglai.push.databinding.ActivityAuroraBinding; -import com.kanglai.push.ui.vm.AuroraViewModel; - -public class AuroraActivity extends BaseActivity { - - - @Override - public int setContentView(Bundle savedInstanceState) { - return R.layout.activity_aurora; - } - - @Override - public int setVariableId() { - return BR.viewModel; - } - - @Override - public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) { - super.onCreate(savedInstanceState, persistentState); - } -} diff --git a/app/src/main/java/com/kanglai/push/ui/activity/InstantActivity.java b/app/src/main/java/com/kanglai/push/ui/activity/InstantActivity.java index 6379c23..cb07633 100644 --- a/app/src/main/java/com/kanglai/push/ui/activity/InstantActivity.java +++ b/app/src/main/java/com/kanglai/push/ui/activity/InstantActivity.java @@ -2,32 +2,24 @@ package com.kanglai.push.ui.activity; import android.content.Context; import android.os.Bundle; -import android.text.Editable; import android.text.InputFilter; -import android.text.TextUtils; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.GridLayout; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.ScrollView; import android.widget.TextView; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.blankj.utilcode.util.CacheDiskUtils; -import com.blankj.utilcode.util.CollectionUtils; -import com.blankj.utilcode.util.LogUtils; import com.dolphin.core.base.BaseActivity; import com.dolphin.core.bus.RxBus; import com.dolphin.core.bus.RxSubscriptions; import com.dolphin.core.util.RxUtil; -import com.dolphin.core.util.ToastUtil; -import com.dolphin.umeng.entity.ChatMsg; import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.kanglai.push.BR; import com.kanglai.push.R; import com.kanglai.push.constant.CacheConstant; @@ -39,15 +31,11 @@ import com.kanglai.push.ui.adapter.SoloChatRoomAdapter; import com.kanglai.push.ui.vm.InstantViewModel; import com.kanglai.push.util.ViewFilterUtil; import com.scwang.smart.refresh.layout.api.RefreshLayout; -import com.taobao.accs.utl.u; import org.json.JSONObject; -import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; -import java.util.OptionalInt; -import java.util.stream.IntStream; import io.reactivex.disposables.Disposable; @@ -90,7 +78,7 @@ public class InstantActivity extends BaseActivity{ @@ -99,7 +87,7 @@ public class InstantActivity extends BaseActivity - * - * - * - * - * - * - * @Author: liusixiang007 - * @since: 2023/7/31 - */ -public class MfrMessageActivity - extends Activity { - private static final String TAG = "MfrMessageActivity"; - - private final UmengNotifyClick mNotificationClick = new UmengNotifyClick() { - @Override - public void onMessage(UMessage msg) { - final String body = msg.getRaw().toString(); - Log.d(TAG, "body: " + body); - if (!TextUtils.isEmpty(body)) { - runOnUiThread(new Runnable() { - @Override - public void run() { - ((TextView) findViewById(R.id.tv_body)).setText(body); - Intent intent = new Intent(getApplicationContext(), LoginActivity.class); - intent.putExtra(CommonConstant.USER_LINK_TYPE, 1); - startActivity(intent); - } - }); - } - } - }; - - - @Override - protected void onCreate(Bundle bundle) { - super.onCreate(bundle); - setContentView(R.layout.mfr_message_layout); - mNotificationClick.onCreate(this, getIntent()); - } - - - @Override - protected void onNewIntent(Intent intent) { - super.onNewIntent(intent); - mNotificationClick.onNewIntent(intent); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/kanglai/push/ui/activity/PushTypeActivity.java b/app/src/main/java/com/kanglai/push/ui/activity/PushTypeActivity.java index 6b96f79..68bdc8f 100644 --- a/app/src/main/java/com/kanglai/push/ui/activity/PushTypeActivity.java +++ b/app/src/main/java/com/kanglai/push/ui/activity/PushTypeActivity.java @@ -15,12 +15,10 @@ import androidx.databinding.library.baseAdapters.BR; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import com.blankj.utilcode.util.CacheDiskUtils; import com.blankj.utilcode.util.CollectionUtils; import com.blankj.utilcode.util.LogUtils; import com.dolphin.core.base.BaseActivity; import com.kanglai.push.R; -import com.kanglai.push.constant.CacheConstant; import com.kanglai.push.databinding.ActivityPushTypeBinding; import com.kanglai.push.entity.PushType; import com.kanglai.push.ui.adapter.PushTypeRecyclerAdapter; @@ -41,8 +39,6 @@ public class PushTypeActivity extends BaseActivity - * 应用后台持续活跃 - * 支持熄屏,app退入后台,保证后台任务不被杀死 - *

- * - * @Author: wangxiang4 - * @since: 2023/2/7 - */ -public class DemoAppKeepActiveFragment extends BaseFragment implements DemoRecyclerAdapter.EventListener { - - private RecyclerView mRecyclerView; - private DemoRecyclerAdapter mAdapter; - private AppKeepActive appKeepActive; - /** 持续保持活跃任务广播 */ - private BroadcastReceiver backgroundKeepActiveTask; - - @Override - public int setContentView(LayoutInflater inflater, @Nullable ViewGroup parentContainer, @Nullable Bundle savedInstanceState) { - return R.layout.fragment_demo; - } - - @Override - public int setVariableId() { - return BR.viewModel; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - appKeepActive = new AppKeepActive(TabBarActivity.class); - } - - @Override - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - mViewModel.setTitleText("应用后台持续活跃"); - mRecyclerView = getView().findViewById(R.id.demo_recycler_view); - List list = CollectionUtils.newArrayList( - new DemoRecyclerAdapter.Entity().setCode("1").setTitle("启动后台免杀持续活跃"), - new DemoRecyclerAdapter.Entity().setCode("2").setTitle("停止后台免杀持续活跃") - ); - final DemoRecyclerAdapter demoRecyclerAdapter = new DemoRecyclerAdapter(list); - demoRecyclerAdapter.setEventListener(this); - mAdapter = demoRecyclerAdapter; - RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity()); - mRecyclerView.setLayoutManager(mLayoutManager); - mRecyclerView.addItemDecoration(new DefaultItemDecoration(ContextCompat.getColor(requireContext(), R.color.common_divider_color))); - mRecyclerView.setAdapter(mAdapter); - } - - @Override - public void onItemViewClicked(DemoRecyclerAdapter.Entity entity) { - switch (entity.code) { - case "1": - registerReceiver(); - appKeepActive.registerService(); - ToastUtil.showCenter("启动成功"); - break; - case "2": - unregisterReceiver(); - appKeepActive.unregisterService(); - ToastUtil.showCenter("停止成功"); - break; - } - } - - public void registerReceiver () { - if (null == backgroundKeepActiveTask) { - backgroundKeepActiveTask = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals(AppConstant.BACKGROUND_KEEP_ACTIVE_TASK_SCHEDULING)) { - ToastUtil.show("APP进入后台执行任务逻辑!"); - LogUtils.i("APP进入后台执行任务逻辑!"); - } - } - }; - } - IntentFilter filter = new IntentFilter(); - filter.addAction(AppConstant.BACKGROUND_KEEP_ACTIVE_TASK_SCHEDULING); - getActivity().registerReceiver(backgroundKeepActiveTask, filter); - } - - public void unregisterReceiver() { - if (null != backgroundKeepActiveTask) getActivity().unregisterReceiver(backgroundKeepActiveTask); - } - - @Override - public void onStart() { - super.onStart(); - } - - @Override - public void onDestroy() { - super.onDestroy(); - } - -} diff --git a/app/src/main/java/com/kanglai/push/ui/fragment/MessageFragment.java b/app/src/main/java/com/kanglai/push/ui/fragment/MessageFragment.java index b2168ca..d657ec5 100644 --- a/app/src/main/java/com/kanglai/push/ui/fragment/MessageFragment.java +++ b/app/src/main/java/com/kanglai/push/ui/fragment/MessageFragment.java @@ -19,7 +19,7 @@ import com.dolphin.core.base.BaseFragment; import com.dolphin.core.bus.RxBus; import com.dolphin.core.bus.RxSubscriptions; import com.dolphin.core.util.RxUtil; -import com.dolphin.umeng.entity.CustomMsg; +import com.dolphin.umeng.entity.PushChatMessage; import com.google.gson.Gson; import com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator; import com.h6ah4i.android.widget.advrecyclerview.animator.SwipeDismissItemAnimator; @@ -78,7 +78,7 @@ public class MessageFragment extends BaseFragment { diff --git a/app/src/main/java/com/kanglai/push/ui/fragment/UserFragment.java b/app/src/main/java/com/kanglai/push/ui/fragment/UserFragment.java index f1bb1b3..8389d6c 100644 --- a/app/src/main/java/com/kanglai/push/ui/fragment/UserFragment.java +++ b/app/src/main/java/com/kanglai/push/ui/fragment/UserFragment.java @@ -1,6 +1,5 @@ package com.kanglai.push.ui.fragment; -import android.graphics.Color; import android.os.Bundle; import android.text.TextUtils; import android.util.Patterns; @@ -14,10 +13,8 @@ import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import com.afollestad.materialdialogs.MaterialDialog; import com.blankj.utilcode.util.CacheDiskUtils; import com.blankj.utilcode.util.CollectionUtils; -import com.blankj.utilcode.util.LogUtils; import com.bumptech.glide.Glide; import com.dolphin.core.BuildConfig; import com.dolphin.core.base.BaseFragment; @@ -28,7 +25,6 @@ import com.kanglai.push.constant.CacheConstant; import com.kanglai.push.databinding.FragmentUserBinding; import com.kanglai.push.entity.User; import com.kanglai.push.ui.activity.AboutActivity; -import com.kanglai.push.ui.activity.AuroraActivity; import com.kanglai.push.ui.activity.LoginSurveyActivity; import com.kanglai.push.ui.activity.PushTypeActivity; import com.kanglai.push.ui.adapter.UserRecyclerAdapter; diff --git a/app/src/main/res/layout/activity_aurora.xml b/app/src/main/res/layout/activity_aurora.xml deleted file mode 100644 index 4abfbde..0000000 --- a/app/src/main/res/layout/activity_aurora.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/activity_push_type.xml b/app/src/main/res/layout/activity_push_type.xml index 695f017..8ccd6f6 100644 --- a/app/src/main/res/layout/activity_push_type.xml +++ b/app/src/main/res/layout/activity_push_type.xml @@ -13,20 +13,6 @@ android:id="@+id/include" layout="@layout/layout_toolbar" binding:toolbarViewModel="@{viewModel.toolbarViewModel}" /> - - - - - - - - - - - - - \ No newline at end of file diff --git a/config.gradle b/config.gradle index 6956f01..a36328c 100644 --- a/config.gradle +++ b/config.gradle @@ -33,21 +33,11 @@ ext { // 友盟消息推送 Secret UMENG_MESSAGE_SECRET = '5plfnl3z4gyebwgzqjbvipciytdkx008' - // 申请 https://connect.qq.com - // QQ AppId - QQ_APP_ID = '101830139' - // QQ Secret - QQ_APP_SECRET = '5d63ae8858f1caab67715ccd6c18d7a5' - // 申请 https://open.weixin.qq.com // 微信 AppId WX_APP_ID = 'wxdc1e388c3822c80b' // 微信 Secret WX_APP_SECRET = '3baf1193c85774b3fd9d18447d76cab0' - // 高德地图 AppKey - AMAP_KEY = '5c32b5bc83e99b3ccc05d5e2eefc3c8b' - // 华为应用AppID - HUAWEI_APP_ID = '108750031' switch(serverType) { case SERVER_TYPE_DEV: @@ -57,7 +47,6 @@ ext { case SERVER_TYPE_PRO: BUGLY_ID = '8bfb5c4a07' HOST_URL = 'http://kicc.kanglailab.com:9999/' -// HOST_URL = 'http://139.9.72.189:9999/' break } @@ -169,13 +158,6 @@ ext { 'umeng-share' : 'com.umeng.umsdk:share-core:7.2.1', // 友盟微信分享 'umeng-share-wx' : 'com.umeng.umsdk:share-wx:7.2.1', - // 友盟QQ分享 - 'umeng-share-qq' : 'com.umeng.umsdk:share-qq:7.2.1', - - // 华为厂商通道 - 'huawei-push' : 'com.huawei.hms:push:6.9.0.300', - // 华为移动服务 - 'huawei-umengaccs' : 'com.umeng.umsdk:huawei-umengaccs:2.0.0', // 微信官方依赖库 // https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/Android.html @@ -231,10 +213,6 @@ ext { // ----------------------- 后续新增依赖框架 ----------------------------- - // 多级树形结构 - // https://github.com/bmelnychuk/AndroidTreeView -// 'android-tree-view' : 'com.github.bmelnychuk:atv:1.2.+', - // 带索引的回收视图 // IndexableRecyclerView 库的androidx版本 // https://gitee.com/androidx_xy/IndexableRecyclerViewX diff --git a/library/core/proguard-core.pro b/library/core/proguard-core.pro index 65d1b7b..03c7782 100644 --- a/library/core/proguard-core.pro +++ b/library/core/proguard-core.pro @@ -55,27 +55,5 @@ @android.webkit.JavascriptInterface ; } -# 3D 地图 V5.0.0之后 --keep class com.amap.api.maps.**{*;} --keep class com.autonavi.**{*;} --keep class com.amap.api.trace.**{*;} - -# 定位 --keep class com.amap.api.location.**{*;} --keep class com.amap.api.fence.**{*;} --keep class com.loc.**{*;} --keep class com.autonavi.aps.amapapi.model.**{*;} - -# 搜索 --keep class com.amap.api.services.**{*;} - -# 导航 --keep class com.amap.api.navi.**{*;} --keep class com.autonavi.**{*;} --keep class com.alibaba.idst.nui.**{*;} - -# 高德api --keep class com.amap.api.**{*;} - # 禁止类名混淆,否则通过类名称找不到类 -keep class com.dolphin.core.entity.**{*;} \ No newline at end of file diff --git a/library/core/src/main/AndroidManifest.xml b/library/core/src/main/AndroidManifest.xml index 128e49b..1a445b6 100644 --- a/library/core/src/main/AndroidManifest.xml +++ b/library/core/src/main/AndroidManifest.xml @@ -6,18 +6,6 @@ - - - - - - - - - - - - diff --git a/library/core/src/main/java/com/dolphin/core/constant/AppConstant.java b/library/core/src/main/java/com/dolphin/core/constant/AppConstant.java index 5faa595..5fc56a1 100644 --- a/library/core/src/main/java/com/dolphin/core/constant/AppConstant.java +++ b/library/core/src/main/java/com/dolphin/core/constant/AppConstant.java @@ -25,18 +25,6 @@ public interface AppConstant { /** 通用权限请求码(可以自定义请求权限对应各自的请求码) */ Integer PERMISSION_REQUEST_CODE = 0; - /** 后台持续活跃定位任务间隔时间(默认5秒) */ - Long KEEP_ACTIVE_TASK_INTERVAL_TIME = 5 * 1000L; - - /** 后台持续活跃前台服务通知ID */ - Integer KEEP_ACTIVE_FRONT_SERVICE_NOTIFICATION_ID = 2023; - - /** 后台持续活跃广播调度 */ - String BACKGROUND_KEEP_ACTIVE_TASK_SCHEDULING = "BACKGROUND_KEEP_ACTIVE_TASK_SCHEDULING"; - - /** 默认线程池数量 */ - Integer DEFAULT_THREAD_POOL_SIZE = 3; - /** 底部标签栏默认选择下标 */ String TAB_BAR_DEFAULT_INDEX = "TAB_BAR_DEFAULT_INDEX"; diff --git a/library/core/src/main/java/com/dolphin/core/entity/DolphinUser.java b/library/core/src/main/java/com/dolphin/core/entity/DolphinUser.java deleted file mode 100644 index 23f030f..0000000 --- a/library/core/src/main/java/com/dolphin/core/entity/DolphinUser.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.dolphin.core.entity; - -import android.os.Parcel; -import android.os.Parcelable; - -import java.util.List; -import java.util.Map; - -import lombok.Data; -import lombok.experimental.Accessors; - -/** - *

- * 扩展安全框架用户信息 - *

- * - * @Author: entfrm开发团队-王翔 - * @Date: 2022/6/28 - */ -@Data -@Accessors -public class DolphinUser implements Parcelable { - - /** 用户id */ - private String id; - - /** 用户名称 */ - private String username; - - /** 用户密码 */ - private String password; - - /** 部门ID */ - private String deptId; - - /** 用户手机号 */ - private String phone; - - /** 账户是否被冻结 */ - private Boolean enabled; - - /** 多租户ID */ - private String tenantId; - - /** 用户按钮权限 */ - private List> authorities; - - /** 帐户未锁定 */ - private Boolean accountNonLocked; - - /** 帐户未过期 */ - private Boolean accountNonExpired; - - /** 凭证未过期 */ - private Boolean credentialsNonExpired; - - public DolphinUser() { - } - - /** 内存反序列化对象 */ - protected DolphinUser(Parcel in) { - id = in.readString(); - username = in.readString(); - password = in.readString(); - deptId = in.readString(); - phone = in.readString(); - enabled = in.readBoolean(); - tenantId = in.readString(); - authorities = in.readArrayList(Map.class.getClassLoader()); - accountNonLocked = in.readBoolean(); - accountNonExpired = in.readBoolean(); - credentialsNonExpired = in.readBoolean(); - } - - /** - * 内存序列化对象 - * @param dest 序列化对象 (包含序列化的一些操作) - * @param flags 0或1 (1表示当前对象需要作为返回值返回,不能立即释放资源,几乎所有情况都为0) - * @return void - */ - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeString(id); - dest.writeString(username); - dest.writeString(password); - dest.writeString(deptId); - dest.writeString(phone); - dest.writeBoolean(enabled); - dest.writeString(tenantId); - dest.writeList(authorities); - dest.writeBoolean(accountNonLocked); - dest.writeBoolean(accountNonExpired); - dest.writeBoolean(credentialsNonExpired); - } - - /** - * unix系统文件描述符,一般情况下为0就行 - * 0:标准输入文件stdin - * 1:标准输出文件stdout - * 2:标准错误输出文件stderr - */ - @Override - public int describeContents() { - return 0; - } - - public static final Creator CREATOR = new Creator() { - @Override - public DolphinUser createFromParcel(Parcel in) { - return new DolphinUser(in); - } - - @Override - public DolphinUser[] newArray(int size) { - return new DolphinUser[size]; - } - }; - -} diff --git a/library/core/src/main/java/com/dolphin/core/service/AppKeepActive.java b/library/core/src/main/java/com/dolphin/core/service/AppKeepActive.java deleted file mode 100644 index ea2d6f5..0000000 --- a/library/core/src/main/java/com/dolphin/core/service/AppKeepActive.java +++ /dev/null @@ -1,174 +0,0 @@ -package com.dolphin.core.service; - -import android.app.AlarmManager; -import android.app.Notification; -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.graphics.BitmapFactory; -import android.os.PowerManager; -import android.os.SystemClock; - -import com.blankj.utilcode.util.Utils; -import com.dolphin.core.R; -import com.dolphin.core.constant.AppConstant; -import com.dolphin.core.util.NotificationUtil; - -/** - *

- * 应用保持活跃 - *

- * - * @Author: wangxiang4 - * @since: 2023/2/6 - */ -public class AppKeepActive { - - /** 活动上下文 */ - private Context mContext; - - /** 前台服务通知 */ - public static volatile Notification notification; - - /** 保持后台活跃服务意图 */ - private Intent backgroundKeepActiveFrontServiceIntent; - - /** 系统警报提醒服务 */ - private AlarmManager alarmManager; - - /** 警报待定异步意图 */ - private PendingIntent alarmPendingIntent; - - /** 屏幕唤醒锁定屏幕接收 */ - private BroadcastReceiver wakeLockScreenReceiver; - - /** 判断屏幕唤醒锁定屏幕接收是否注册 */ - private Boolean isRegisterPowerWakeLockReceiver = false; - - /** 手机电源管理 */ - private PowerManager powerManager; - - /** 屏幕唤醒 */ - private PowerManager.WakeLock wakeLock; - - /** 前台服务通知点击启动活动 */ - private Class notificationClickStartClass; - - public AppKeepActive(Class notificationClickStartClass) { - this(Utils.getApp(), notificationClickStartClass); - } - - public AppKeepActive(Context mContext, Class notificationClickStartClass) { - this.mContext = mContext; - this.notificationClickStartClass = notificationClickStartClass; - powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); - notification = buildNotification(); - } - - /** 注册电源锁屏监听广播 */ - public void registerPowerWakeLockReceiver() { - if (isRegisterPowerWakeLockReceiver) return; - isRegisterPowerWakeLockReceiver = true; - if (null == wakeLock) wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "dolphin:keep-active"); - if (null == wakeLockScreenReceiver) { - wakeLockScreenReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (null == wakeLock) return; - String action = intent.getAction(); - if (Intent.ACTION_SCREEN_OFF.equals(action) && !wakeLock.isHeld()) { - wakeLock.acquire(); - if (null != alarmPendingIntent) return; - // 支持后台熄屏,定时执行后台持续活跃任务 - Intent alarmIntent = new Intent(); - alarmIntent.setAction(AppConstant.BACKGROUND_KEEP_ACTIVE_TASK_SCHEDULING); - // https://www.cnblogs.com/endv/p/11576121.html - alarmPendingIntent = PendingIntent.getBroadcast(mContext, AppConstant.PERMISSION_REQUEST_CODE, alarmIntent, PendingIntent.FLAG_IMMUTABLE); - // 获取系统警报提醒服务 - alarmManager = (AlarmManager) mContext.getSystemService(mContext.ALARM_SERVICE); - // 设置一个闹钟,1秒之后每隔一段时间执行启动一次后台持续活跃任务,防止冻结后台任务 - alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1 * 1000, AppConstant.KEEP_ACTIVE_TASK_INTERVAL_TIME, alarmPendingIntent); - } else if (Intent.ACTION_USER_PRESENT.equals(action) && wakeLock.isHeld()) { - wakeLock.release(); - if (null == alarmManager) return; - alarmManager.cancel(alarmPendingIntent); - alarmPendingIntent = null; - alarmManager = null; - } - } - }; - } - IntentFilter filter = new IntentFilter(); - filter.addAction(Intent.ACTION_SCREEN_OFF); - filter.addAction(Intent.ACTION_USER_PRESENT); - mContext.registerReceiver(wakeLockScreenReceiver, filter); - } - - /** 取消电源锁屏监听广播 */ - public void unregisterPowerWakeLockReceiver() { - if (!isRegisterPowerWakeLockReceiver) return; - if (null != wakeLockScreenReceiver) mContext.unregisterReceiver(wakeLockScreenReceiver); - isRegisterPowerWakeLockReceiver = false; - } - - /** 启动后台活跃前台服务 */ - public void startBackgroundKeepActiveFrontService() { - BackgroundKeepActiveFrontService.startBackgroundKeepActiveTask = true; - backgroundKeepActiveFrontServiceIntent = new Intent(mContext, BackgroundKeepActiveFrontService.class); - mContext.startForegroundService(backgroundKeepActiveFrontServiceIntent); - } - - /** 关闭后台活跃前台服务 */ - public void closeBackgroundKeepActiveFrontService() { - BackgroundKeepActiveFrontService.startBackgroundKeepActiveTask = false; - if (null != backgroundKeepActiveFrontServiceIntent) mContext.stopService(backgroundKeepActiveFrontServiceIntent); - } - - /** 注册应用保持活跃服务 */ - public void registerService() { - startBackgroundKeepActiveFrontService(); - registerPowerWakeLockReceiver(); - } - - /** 解绑应用保持活跃服务 */ - public void unregisterService() { - closeBackgroundKeepActiveFrontService(); - unregisterPowerWakeLockReceiver(); - } - - /** 构建前台服务通知 */ - private Notification buildNotification() { - NotificationUtil.notificationManager.createNotificationChannel(NotificationUtil.defaultNotificationChannel()); - PendingIntent pendingIntent = PendingIntent.getActivity(mContext, AppConstant.PERMISSION_REQUEST_CODE, new Intent(mContext, notificationClickStartClass), PendingIntent.FLAG_MUTABLE); - Notification notification = NotificationUtil.defaultNotificationBuilder() - .setContentTitle(mContext.getString(R.string.app_name)) - .setContentText("正在后台运行") - .setOngoing(true) - .setOnlyAlertOnce(true) - .setContentIntent(pendingIntent).build(); - // 通知栏以不能清除的方式展示 - notification.flags |= Notification.FLAG_NO_CLEAR; - return notification; - } - - public PowerManager getPowerManager() { - return powerManager; - } - - public void setPowerManager(PowerManager powerManager) { - this.powerManager = powerManager; - } - - public PowerManager.WakeLock getWakeLock() { - return wakeLock; - } - - public void setWakeLock(PowerManager.WakeLock wakeLock) { - this.wakeLock = wakeLock; - } - -} diff --git a/library/core/src/main/java/com/dolphin/core/service/BackgroundKeepActiveFrontService.java b/library/core/src/main/java/com/dolphin/core/service/BackgroundKeepActiveFrontService.java deleted file mode 100644 index 78ed12c..0000000 --- a/library/core/src/main/java/com/dolphin/core/service/BackgroundKeepActiveFrontService.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.dolphin.core.service; - -import android.app.ActivityManager; -import android.app.Service; -import android.content.Context; -import android.content.Intent; -import android.media.MediaPlayer; -import android.os.IBinder; -import android.os.PowerManager; - -import com.blankj.utilcode.util.ThreadUtils; -import com.blankj.utilcode.util.Utils; -import com.dolphin.core.R; -import com.dolphin.core.constant.AppConstant; - -import java.util.List; -import java.util.concurrent.TimeUnit; - -/** - *

- * 前台服务 - * 采用媒体锁持续保持后台活跃 - * https://developer.android.com/guide/components/services?hl=zh-cn - *

- * - * @Author: wangxiang4 - * @since: 2023/2/6 - */ -public class BackgroundKeepActiveFrontService extends Service { - - /** 流媒体播放器 */ - private MediaPlayer mediaPlayer; - - /** 启动服务异步处理任务 */ - public static volatile Boolean startBackgroundKeepActiveTask = false; - - /** 判断APP当前是否处于后台运行 */ - private boolean isAppBackstage() { - ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); - List appProcesses = activityManager.getRunningAppProcesses(); - for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) { - if (appProcess.processName.equals(getPackageName())) { - if (appProcess.importance != ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { - return true; - } else { - return false; - } - } - } - return false; - } - - @Override - public void onCreate() { - super.onCreate(); - mediaPlayer = MediaPlayer.create(this, R.raw.media_lock); - // 禁止播放程序进入休眠,熄灭屏幕后唤醒cpu - mediaPlayer.setWakeMode(this, PowerManager.PARTIAL_WAKE_LOCK); - mediaPlayer.setLooping(true); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - if (mediaPlayer != null) mediaPlayer.start(); - ThreadUtils.executeByFixedAtFixRate(AppConstant.DEFAULT_THREAD_POOL_SIZE, - backgroundKeepActiveTask, AppConstant.KEEP_ACTIVE_TASK_INTERVAL_TIME, TimeUnit.MILLISECONDS); - return super.onStartCommand(intent, flags, startId); - } - - /** 后台异步处理持续活跃任务 */ - ThreadUtils.Task backgroundKeepActiveTask = new Utils.Task(result -> {}) { - @Override - public String doInBackground() { - // 设置线程取消 - if (!startBackgroundKeepActiveTask) cancel(); - if(isAppBackstage()){ - Intent intent = new Intent(); - intent.setAction(AppConstant.BACKGROUND_KEEP_ACTIVE_TASK_SCHEDULING); - sendBroadcast(intent); - } - startForeground(AppConstant.KEEP_ACTIVE_FRONT_SERVICE_NOTIFICATION_ID, AppKeepActive.notification); - return null; - } - }; - - @Override - public void onDestroy() { - super.onDestroy(); - mediaPlayer.stop(); - mediaPlayer.release(); - stopForeground(true); - } - - @Override - public IBinder onBind(Intent intent) { - return null; - } - -} diff --git a/library/core/src/main/res/raw/media_lock.wav b/library/core/src/main/res/raw/media_lock.wav deleted file mode 100644 index 27142e2..0000000 Binary files a/library/core/src/main/res/raw/media_lock.wav and /dev/null differ diff --git a/library/umeng/build.gradle b/library/umeng/build.gradle index 1ba4dc0..9ec205e 100644 --- a/library/umeng/build.gradle +++ b/library/umeng/build.gradle @@ -11,17 +11,10 @@ android { buildConfigField('String', 'UMENG_APP_KEY', '"' + UMENG_APP_KEY + '"') buildConfigField('String', 'UMENG_APP_MASTER_SECRET', '"' + UMENG_APP_MASTER_SECRET + '"') buildConfigField('String', 'UMENG_MESSAGE_SECRET', '"' + UMENG_MESSAGE_SECRET + '"') - buildConfigField('String', 'QQ_ID', '"' + QQ_APP_ID + '"') - buildConfigField('String', 'QQ_SECRET', '"' + QQ_APP_SECRET + '"') buildConfigField('String', 'WX_ID', '"' + WX_APP_ID + '"') buildConfigField('String', 'WX_SECRET', '"' + WX_APP_SECRET + '"') buildConfigField('String', 'HOST_URL', '"' + HOST_URL + '"') - // 清单占位符 - addManifestPlaceholders([ - 'QQ_ID' : QQ_APP_ID, - ]) - // dialogx自带主题与引用的ios主题类名重复 排除重复的类 configurations { all*.exclude group: 'com.kongzue.dialogx', module: 'DialogX' @@ -37,10 +30,7 @@ dependencies { api DEPENDENCIES['umeng-push'] api DEPENDENCIES['umeng-share'] api DEPENDENCIES['umeng-share-wx'] - api DEPENDENCIES['umeng-share-qq'] api DEPENDENCIES['wechatcomponent'] api DEPENDENCIES['kongzue-dialog-x'] api DEPENDENCIES['kongzue-dialog-x-ios-style'] - api DEPENDENCIES['huawei-push'] - api DEPENDENCIES['huawei-umengaccs'] } \ No newline at end of file diff --git a/library/umeng/src/main/AndroidManifest.xml b/library/umeng/src/main/AndroidManifest.xml index 860447c..d3254f3 100644 --- a/library/umeng/src/main/AndroidManifest.xml +++ b/library/umeng/src/main/AndroidManifest.xml @@ -27,26 +27,6 @@ - - - - - - - - - - - - - - diff --git a/library/umeng/src/main/java/com/dolphin/umeng/UmengClient.java b/library/umeng/src/main/java/com/dolphin/umeng/UmengClient.java index fcdfa1a..23e1ef0 100644 --- a/library/umeng/src/main/java/com/dolphin/umeng/UmengClient.java +++ b/library/umeng/src/main/java/com/dolphin/umeng/UmengClient.java @@ -1,12 +1,14 @@ package com.dolphin.umeng; -import android.annotation.SuppressLint; import android.app.Activity; import android.app.Application; import android.app.Notification; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.media.MediaPlayer; +import android.net.Uri; +import android.os.PowerManager; import android.text.TextUtils; import android.util.Patterns; import android.widget.RemoteViews; @@ -14,26 +16,25 @@ import android.widget.RemoteViews; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.blankj.utilcode.util.CacheDiskUtils; +import com.blankj.utilcode.util.FlashlightUtils; import com.blankj.utilcode.util.LogUtils; import com.blankj.utilcode.util.StringUtils; +import com.blankj.utilcode.util.ThreadUtils; import com.blankj.utilcode.util.Utils; +import com.blankj.utilcode.util.VibrateUtils; import com.dolphin.core.bus.RxBus; import com.dolphin.core.constant.AppConstant; import com.dolphin.core.util.NotificationUtil; import com.dolphin.core.util.ToastUtil; -import com.dolphin.umeng.entity.ChatMsg; -import com.dolphin.umeng.entity.CustomMsg; +import com.dolphin.umeng.entity.PushChatMessage; import com.dolphin.umeng.enums.PlatformEnum; import com.dolphin.umeng.listener.UmengLoginListener; import com.dolphin.umeng.listener.UmengShareListener; -import com.dolphin.umeng.util.PushTypeHandle; +import com.dolphin.umeng.util.MultimediaUtil; import com.google.gson.Gson; -import com.kongzue.dialogx.dialogs.PopNotification; import com.tencent.mmkv.MMKV; import com.umeng.analytics.MobclickAgent; import com.umeng.commonsdk.UMConfigure; -import com.umeng.commonsdk.utils.UMUtils; import com.umeng.message.MsgConstant; import com.umeng.message.PushAgent; import com.umeng.message.UmengMessageHandler; @@ -44,7 +45,7 @@ import com.umeng.socialize.PlatformConfig; import com.umeng.socialize.ShareAction; import com.umeng.socialize.UMShareAPI; -import org.android.agoo.huawei.HuaWeiRegister; +import java.util.concurrent.TimeUnit; import lombok.experimental.UtilityClass; @@ -68,7 +69,6 @@ public final class UmengClient { * @param application 应用程序上下文 * @param logEnable 友盟日志开关 */ - @SuppressLint("WrongConstant") public void init(Application application, boolean logEnable) { preInit(application, logEnable); // 初始化组件化基础库,统计SDK/推送SDK/分享SDK都必须调用此初始化接口 @@ -78,7 +78,6 @@ public final class UmengClient { UMConfigure.getOaid(application, oaid -> sDeviceOaid = oaid); // 播放器初始化 mApplication = application; -// mediaPlayer.setLooping(true); 关闭循环播放效果 } /** @@ -93,7 +92,6 @@ public final class UmengClient { // 初始化各个平台的 ID 和 Key PlatformConfig.setWeixin(BuildConfig.WX_ID, BuildConfig.WX_SECRET); - PlatformConfig.setQQZone(BuildConfig.QQ_ID, BuildConfig.QQ_SECRET); // 初始化各个平台的文件提供者(必须要初始化,否则会导致无法分享文件) String fileProvider = application.getPackageName() + ".fileProvider"; @@ -146,7 +144,6 @@ public final class UmengClient { @Override public void dealWithCustomAction(Context context, UMessage msg) { - // todo: 新消息单击事件 跳转至消息列表页 if (!StringUtils.isTrimEmpty(msg.custom)) { Intent intent = new Intent("com.android.kanglai.push.TabBarActivity"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); @@ -156,6 +153,7 @@ public final class UmengClient { } }; pushAgent.setNotificationClickHandler(notificationClickHandler); + // 消息通知的回调处理 UmengMessageHandler messageHandler = new UmengMessageHandler() { /** @@ -163,22 +161,40 @@ public final class UmengClient { */ @Override public void dealWithNotificationMessage(Context context, UMessage msg) { - String accessToken = MMKV.defaultMMKV().getString(AppConstant.ACCESS_TOKEN_NAME,null); - // todo 离线铃声 以及 在线铃声需要做一个区分 - if (!StringUtils.isTrimEmpty(msg.custom) && !StringUtils.isEmpty(accessToken)) { // 消息不为空 以及 用户已登录 才接收推送 - CustomMsg custom = new Gson().fromJson(msg.custom, CustomMsg.class); - custom.setText(msg.text); - custom.setTitle(msg.title); - if (!TextUtils.isEmpty(custom.getOnlineRingtone())) custom.setOnlineRingtone(repairOnlineRingtone(custom.getOnlineRingtone())); - - PushTypeHandle pushTypeHandle = new PushTypeHandle(mApplication, custom); // 接收到推送类型后进行响应 - pushTypeHandle.judgePushType(); - RxBus.getInstance().postSticky(custom); // 向消息碎片页传输数据 - RxBus.getInstance().postSticky(new ChatMsg(custom.getFanUserId(), msg.text)); // 向聊天活动页传输数据 - popNotification(msg.title,msg.text); // app内部弹窗 + if (!StringUtils.isTrimEmpty(msg.custom) && !StringUtils.isEmpty(accessToken)) { + PushChatMessage pushChatMessage = new Gson().fromJson(msg.custom, PushChatMessage.class); + pushChatMessage.setTitle(msg.title); + pushChatMessage.setText(msg.text); + // 检测是否拼接后端oss文件服务器地址 + if (!StringUtils.isEmpty(pushChatMessage.getOnlineRingtone()) && !Patterns.WEB_URL.matcher(pushChatMessage.getOnlineRingtone()).matches()) { + pushChatMessage.setOnlineRingtone(BuildConfig.HOST_URL + pushChatMessage.getOnlineRingtone().substring(1)); + } + + // 推送类型相关逻辑 + if (pushChatMessage.getPlayVibrate()) + VibrateUtils.vibrate(800); + if (pushChatMessage.getPlayLights()) { + FlashlightUtils.setFlashlightStatus(true); + ThreadUtils.executeBySingleWithDelay(new Utils.Task(result -> {}) { + @Override + public Void doInBackground() { + FlashlightUtils.setFlashlightStatus(false); + return null; + } + + }, 1000, TimeUnit.MILLISECONDS); + } + if (pushChatMessage.getPlayToText() && pushChatMessage.getPlaySound()) { + MultimediaUtil.playSoundAndTtsSpeak(pushChatMessage.getOnlineRingtone(), pushChatMessage.getText()); + } else if (pushChatMessage.getPlayToText()) { + MultimediaUtil.ttsSpeak(pushChatMessage.getText()); + } else if (pushChatMessage.getPlaySound()) { + MultimediaUtil.playSound(pushChatMessage.getOnlineRingtone()); + } + RxBus.getInstance().postSticky(pushChatMessage); } -// super.dealWithNotificationMessage(context, msg); + super.dealWithNotificationMessage(context, msg); } /** @@ -221,25 +237,6 @@ public final class UmengClient { LogUtils.i("register failed: " + s + " " + s1); } }); - if (UMUtils.isMainProgress(application)) { - HuaWeiRegister.register(application); - } - } - - private static void popNotification(String tit, String text) { - if ("true".equals(CacheDiskUtils.getInstance().getString("NOTIFICATION_APP_POP_UP", "true"))) PopNotification.show(tit, text).showLong(); - } - - /** - * 修复在线铃声 - * 判断是完整的url字符串 - * @param ringtone - * @return - */ - private static String repairOnlineRingtone(String ringtone) { - if (!Patterns.WEB_URL.matcher(ringtone).matches()){ - return BuildConfig.HOST_URL + ringtone.substring(1); - }else return ringtone; } /** diff --git a/library/umeng/src/main/java/com/dolphin/umeng/entity/ChatMsg.java b/library/umeng/src/main/java/com/dolphin/umeng/entity/ChatMsg.java deleted file mode 100644 index c808d9e..0000000 --- a/library/umeng/src/main/java/com/dolphin/umeng/entity/ChatMsg.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.dolphin.umeng.entity; - -import android.os.Parcel; -import android.os.Parcelable; - -import lombok.Data; -import lombok.experimental.Accessors; - -/** - * 用户实时聊天数据 - * @Author: liusixiang007 - * @since: 2023/6/1 - */ -@Data -@Accessors -public class ChatMsg implements Parcelable { - public String concernFanId; - public String content; - - public ChatMsg() {} - public ChatMsg(String userId,String content){ - this.concernFanId = userId; - this.content = content; - } - protected ChatMsg(Parcel in) { - concernFanId = in.readString(); - } - - public static final Creator CREATOR = new Creator() { - @Override - public ChatMsg createFromParcel(Parcel in) { - return new ChatMsg(in); - } - - @Override - public ChatMsg[] newArray(int size) { - return new ChatMsg[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(concernFanId); - } -} diff --git a/library/umeng/src/main/java/com/dolphin/umeng/entity/CustomMsg.java b/library/umeng/src/main/java/com/dolphin/umeng/entity/CustomMsg.java deleted file mode 100644 index 6023bd2..0000000 --- a/library/umeng/src/main/java/com/dolphin/umeng/entity/CustomMsg.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.dolphin.umeng.entity; - -import android.os.Parcel; -import android.os.Parcelable; - -import com.kongzue.dialogx.dialogs.BottomDialog; - -import lombok.Data; -import lombok.experimental.Accessors; - -/** - * 友盟数据传输类 - * 仅传输接收到的有用的数据 - * @Author: liusixiang007 - * @since: 2023/7/6 - */ -@Data -@Accessors -public class CustomMsg implements Parcelable{ - - /**粉丝用户id*/ - private String fanUserId; - /**文字转语音*/ - private String playToText; - /**收到通知是否发出声音*/ - private String playSound; - /**收到通知是否闪灯*/ - private String playLights; - /**收到通知是否震动*/ - private String playVibrate; - /**离线铃声*/ - private String offlineRingtone; - /**在线铃声*/ - private String onlineRingtone; - /**通知标题*/ - private String title; - /**通知文字描述*/ - private String text; - - public CustomMsg(Parcel in) { - title = in.readString(); - text = in.readString(); - playVibrate = in.readString(); - playLights = in.readString(); - playSound = in.readString(); - playToText = in.readString(); - onlineRingtone = in.readString(); - offlineRingtone = in.readString(); - fanUserId = in.readString(); - } - - public static final Creator CREATOR = new Creator() { - @Override - public CustomMsg createFromParcel(Parcel in) { - return new CustomMsg(in); - } - - @Override - public CustomMsg[] newArray(int size) { - return new CustomMsg[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(title); - parcel.writeString(text); - parcel.writeString(playVibrate); - parcel.writeString(playLights); - parcel.writeString(playSound); - parcel.writeString(playToText); - parcel.writeString(onlineRingtone); - parcel.writeString(offlineRingtone); - parcel.writeString(fanUserId); - } -} diff --git a/library/umeng/src/main/java/com/dolphin/umeng/entity/CustomMsgDemo.java b/library/umeng/src/main/java/com/dolphin/umeng/entity/CustomMsgDemo.java deleted file mode 100644 index 84a197e..0000000 --- a/library/umeng/src/main/java/com/dolphin/umeng/entity/CustomMsgDemo.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.dolphin.umeng.entity; - -import android.os.Parcel; -import android.os.Parcelable; - -import lombok.Data; -import lombok.experimental.Accessors; - -/** - *

- * 演示 - * 自定义消息传输数据 - *

- * - * @Author: wangxiang4 - * @since: 2023/2/12 - */ -@Data -@Accessors -public class CustomMsgDemo implements Parcelable { - - protected String title; - - protected String data; - - public CustomMsgDemo() {} - - public CustomMsgDemo(Parcel in) { - title = in.readString(); - data = in.readString(); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeString(title); - dest.writeString(data); - } - - @Override - public int describeContents() { - return 0; - } - - public static final Creator CREATOR = new Creator() { - @Override - public CustomMsgDemo createFromParcel(Parcel in) { - return new CustomMsgDemo(in); - } - - @Override - public CustomMsgDemo[] newArray(int size) { - return new CustomMsgDemo[size]; - } - }; - -} diff --git a/library/umeng/src/main/java/com/dolphin/umeng/entity/PushChatMessage.java b/library/umeng/src/main/java/com/dolphin/umeng/entity/PushChatMessage.java new file mode 100644 index 0000000..a128ad9 --- /dev/null +++ b/library/umeng/src/main/java/com/dolphin/umeng/entity/PushChatMessage.java @@ -0,0 +1,65 @@ +package com.dolphin.umeng.entity; + +import android.os.Parcel; +import android.os.Parcelable; + +import lombok.Data; +import lombok.experimental.Accessors; + +@Data +@Accessors +public class PushChatMessage implements Parcelable{ + + private String fanUserId; + private String offlineRingtone; + private String onlineRingtone; + private Boolean playToText; + private Boolean playSound; + private Boolean playLights; + private Boolean playVibrate; + private String type; + private String title; + private String text; + + public PushChatMessage(Parcel in) { + title = in.readString(); + text = in.readString(); + playVibrate = in.readBoolean(); + playLights = in.readBoolean(); + playSound = in.readBoolean(); + playToText = in.readBoolean(); + onlineRingtone = in.readString(); + offlineRingtone = in.readString(); + fanUserId = in.readString(); + } + + public static final Creator CREATOR = new Creator() { + @Override + public PushChatMessage createFromParcel(Parcel in) { + return new PushChatMessage(in); + } + + @Override + public PushChatMessage[] newArray(int size) { + return new PushChatMessage[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(title); + parcel.writeString(text); + parcel.writeBoolean(playVibrate); + parcel.writeBoolean(playLights); + parcel.writeBoolean(playSound); + parcel.writeBoolean(playToText); + parcel.writeString(onlineRingtone); + parcel.writeString(offlineRingtone); + parcel.writeString(fanUserId); + } +} diff --git a/library/umeng/src/main/java/com/dolphin/umeng/util/BaiduTtsUtil.java b/library/umeng/src/main/java/com/dolphin/umeng/util/BaiduTtsUtil.java new file mode 100644 index 0000000..c68b590 --- /dev/null +++ b/library/umeng/src/main/java/com/dolphin/umeng/util/BaiduTtsUtil.java @@ -0,0 +1,92 @@ +package com.dolphin.umeng.util; + +import android.content.Context; + +import com.baidu.tts.client.SpeechError; +import com.baidu.tts.client.SpeechSynthesizer; +import com.baidu.tts.client.SpeechSynthesizerListener; +import com.baidu.tts.client.TtsMode; +import com.blankj.utilcode.util.LogUtils; +import com.blankj.utilcode.util.Utils; + +import lombok.experimental.UtilityClass; + +@UtilityClass +public class BaiduTtsUtil { + private volatile boolean isInitTts; + private SpeechSynthesizer mSpeechSynthesizer; + private static final String BD_APP_ID = "37122313"; + private static final String BD_APP_KEY = "BNrZhvnx5DgX74j847KKrjzn"; + private static final String BD_APP_SECRET_KEY = "bF33QKfD1grBbO1R0Ur1L0A65wGkj3GR"; + + static { + mSpeechSynthesizer = SpeechSynthesizer.getInstance(); + mSpeechSynthesizer.setContext(Utils.getApp().getApplicationContext()); + mSpeechSynthesizer.setSpeechSynthesizerListener(new SpeechSynthesizerListener() { + @Override + public void onSynthesizeStart(String s) { + LogUtils.d("准备开始合成,序列号:" + s); + } + + @Override + public void onSynthesizeDataArrived(String s, byte[] bytes, int i, int i1) {} + + @Override + public void onSynthesizeFinish(String s) { + LogUtils.d("合成结束回调, 序列号:" + s); + } + + @Override + public void onSpeechStart(String s) { // 开始播放 暂时提高媒体音量 + LogUtils.d("播放开始回调, 序列号:" + s); + } + + @Override + public void onSpeechProgressChanged(String s, int i) { + LogUtils.d("播放进度回调, progress:" + s + ";序列号:" + i); + } + + @Override + public void onSpeechFinish(String s) { // 播放结束之后恢复媒体音量 + LogUtils.d("SpeechSynthesizerListener-onSpeechFinish 播报结束"); + release(); // 播放结束之后就清除占用 + } + + @Override + public void onError(String s, SpeechError speechError) { + mSpeechSynthesizer.pause(); + LogUtils.d("语音合成报错 错误id"+s+" 报错原因 "+speechError); + } + }); + mSpeechSynthesizer.setAppId(BD_APP_ID); + mSpeechSynthesizer.setApiKey(BD_APP_KEY , BD_APP_SECRET_KEY); + // 设置在线发声音人: 0 普通女声(默认) 1 普通男声 2 特别男声 3 情感男声<度逍遥> 4 情感儿童声<度丫丫> + mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_SPEAKER, "0"); + // 设置合成的音量,0-15 ,默认 5 + mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_VOLUME, "15"); + // 设置合成的语速,0-15 ,默认 5 + mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_SPEED, "5"); + // 设置合成的语调,0-15 ,默认 5 + mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_PITCH, "5"); + // 仅需要在线合成并不使用压缩传输 + mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_AUDIO_RATE, SpeechSynthesizer.AUDIO_BITRATE_PCM); + mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_AUDIO_ENCODE, SpeechSynthesizer.AUDIO_ENCODE_PCM); + int result = mSpeechSynthesizer.initTts(TtsMode.ONLINE); + isInitTts = result == 0; + } + + public int ttsSpeak(String text) { + if (mSpeechSynthesizer != null && isInitTts){ + return mSpeechSynthesizer.speak(text); + } else return 1; + } + + public void release() { + if (mSpeechSynthesizer != null){ + mSpeechSynthesizer.stop(); + mSpeechSynthesizer.release(); + isInitTts = false; + mSpeechSynthesizer = null; + } + } +} diff --git a/library/umeng/src/main/java/com/dolphin/umeng/util/MultimediaUtil.java b/library/umeng/src/main/java/com/dolphin/umeng/util/MultimediaUtil.java new file mode 100644 index 0000000..66e770b --- /dev/null +++ b/library/umeng/src/main/java/com/dolphin/umeng/util/MultimediaUtil.java @@ -0,0 +1,42 @@ +package com.dolphin.umeng.util; + +import android.media.AudioManager; +import android.media.MediaPlayer; +import android.net.Uri; +import android.os.PowerManager; +import android.text.TextUtils; + +import com.blankj.utilcode.util.Utils; +import com.blankj.utilcode.util.VolumeUtils; +import com.dolphin.umeng.R; + +import lombok.experimental.UtilityClass; + +@UtilityClass +public class MultimediaUtil { + + private MediaPlayer mediaPlayer; + + public void playSound(String onlineRingtone) { + if (TextUtils.isEmpty(onlineRingtone)) { + mediaPlayer = MediaPlayer.create(Utils.getApp().getApplicationContext(), R.raw.audio_system_hint); + } else mediaPlayer = MediaPlayer.create(Utils.getApp().getApplicationContext(), Uri.parse(onlineRingtone)); + mediaPlayer.setWakeMode(Utils.getApp().getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); + if (VolumeUtils.getMinVolume(AudioManager.STREAM_MUSIC) == 0) { + VolumeUtils.setVolume(AudioManager.STREAM_MUSIC, VolumeUtils.getMaxVolume(AudioManager.STREAM_MUSIC)/3, AudioManager.FLAG_PLAY_SOUND); + } + mediaPlayer.start(); + } + + public void ttsSpeak(String ttsText) { + BaiduTtsUtil.ttsSpeak(ttsText); + } + + public void playSoundAndTtsSpeak(String onlineRingtone, String ttsText) { + playSound(onlineRingtone); + mediaPlayer.setOnCompletionListener(mp -> { + ttsSpeak(ttsText); + }); + } + +} diff --git a/library/umeng/src/main/java/com/dolphin/umeng/util/PushTypeHandle.java b/library/umeng/src/main/java/com/dolphin/umeng/util/PushTypeHandle.java deleted file mode 100644 index b54acad..0000000 --- a/library/umeng/src/main/java/com/dolphin/umeng/util/PushTypeHandle.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.dolphin.umeng.util; - -import android.content.Context; -import android.hardware.camera2.CameraAccessException; -import android.hardware.camera2.CameraManager; -import android.media.AudioManager; -import android.media.MediaPlayer; -import android.net.Uri; -import android.os.PowerManager; -import android.os.VibrationEffect; -import android.os.Vibrator; -import android.text.TextUtils; - -import com.blankj.utilcode.util.LogUtils; -import com.dolphin.umeng.R; -import com.dolphin.umeng.entity.CustomMsg; - -import java.util.Timer; -import java.util.TimerTask; - -/** - * 推送类型响应类 - * @Author: liusixiang007 - * @since: 2023/7/10 - */ -public class PushTypeHandle { - - private Context context; - private MediaPlayer mediaPlayer; // 音乐提示播放器 - private CustomMsg msg; // 响应属性实体类 - private TtsSyntherizer mTtsSyntherizer; - - public PushTypeHandle(Context context, CustomMsg item){ - this.mTtsSyntherizer = new TtsSyntherizer(context); - this.context = context; - this.msg = item; - } - - /** - * 判断响应类型 先闪光 震动 再 提示音 和语音转文字 - */ - public void judgePushType() { - if ("true".equals(msg.getPlayLights())) isPlayLights(); - if ("true".equals(msg.getPlayVibrate())) isPlayVibrate(); - if ("true".equals(msg.getPlaySound())) isPlaySound(msg); - } - - /** - * 是否播放声音 以及 文字转语音 - * @param item - */ - public void isPlaySound(CustomMsg item) { - AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); - if (TextUtils.isEmpty(item.getOnlineRingtone())) { // 没有设置离线铃声 - mediaPlayer = MediaPlayer.create(context, R.raw.audio_system_hint); - }else { // 设置了提示铃声 - mediaPlayer = MediaPlayer.create(context, Uri.parse(item.getOnlineRingtone())); - } - mediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK); // 设置离线播放模式 - int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); - if(currentVolume == 0) { // 媒体通道为静音状态 则设置为33%的音量 - audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) / 3, 0); - } - mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { // 播放结束的逻辑 - @Override - public void onCompletion(MediaPlayer mp) { - if ("true".equals(item.getPlayToText())) mTtsSyntherizer.ttsSpeak(item.getTitle()); // 开始播放语音合成 - if (currentVolume == 0) audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); // 恢复媒体通道静音 - } - }); - mediaPlayer.start(); // 开始播放提示音 - } - - /**闪光灯闪烁 一次 1s 后关闭*/ - public void isPlayLights() { - CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); - try { - String cameraId = cameraManager.getCameraIdList()[0]; - cameraManager.setTorchMode(cameraId, true); // 开启闪光灯 - Timer timer = new Timer(); - timer.schedule(new TimerTask() { - @Override - public void run() { - try { - cameraManager.setTorchMode(cameraId, false); - } catch (CameraAccessException e) { - throw new RuntimeException(e); - } - } - }, 1000); - } catch (CameraAccessException e) { - throw new RuntimeException(e); - } - } - - /**震动 800毫秒*/ - public void isPlayVibrate() { - Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); - // 检查设备是否支持震动 - if (vibrator != null && vibrator.hasVibrator()){ - VibrationEffect vibrationEffect = VibrationEffect.createOneShot(800, VibrationEffect.DEFAULT_AMPLITUDE); // 定义震动时常(单位毫秒)以及震动强度 - vibrator.vibrate(vibrationEffect); // 单位:毫秒 - } - } -} diff --git a/library/umeng/src/main/java/com/dolphin/umeng/util/TtsSyntherizer.java b/library/umeng/src/main/java/com/dolphin/umeng/util/TtsSyntherizer.java deleted file mode 100644 index f7fb80e..0000000 --- a/library/umeng/src/main/java/com/dolphin/umeng/util/TtsSyntherizer.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.dolphin.umeng.util; - -import android.content.Context; - -import com.baidu.tts.client.SpeechError; -import com.baidu.tts.client.SpeechSynthesizer; -import com.baidu.tts.client.SpeechSynthesizerListener; -import com.baidu.tts.client.TtsMode; -import com.blankj.utilcode.util.LogUtils; - -/** - * 百度在线语音合成 - * @Author: liusixiang007 - * @since: 2023/8/11 - */ -public class TtsSyntherizer { - - private Context context; - private volatile boolean isInitTts = false; // 当前播放状态 - protected SpeechSynthesizer mSpeechSynthesizer; - private static final String BD_APP_ID = "37122313"; - private static final String BD_APP_KEY = "BNrZhvnx5DgX74j847KKrjzn"; - private static final String BD_APP_SECRET_KEY = "bF33QKfD1grBbO1R0Ur1L0A65wGkj3GR"; - - public TtsSyntherizer(Context context) { - this.context = context; - initTTs(); - } - - private void initTTs() { - new Thread(new Runnable() { - @Override - public void run() { - mSpeechSynthesizer = SpeechSynthesizer.getInstance(); - mSpeechSynthesizer.setContext(context); - mSpeechSynthesizer.setSpeechSynthesizerListener(new SpeechSynthesizerListener() { - @Override - public void onSynthesizeStart(String s) { - LogUtils.d("准备开始合成,序列号:" + s); - } - - @Override - public void onSynthesizeDataArrived(String s, byte[] bytes, int i, int i1) { - - } - - @Override - public void onSynthesizeFinish(String s) { - LogUtils.d("合成结束回调, 序列号:" + s); - } - - @Override - public void onSpeechStart(String s) { // 开始播放 暂时提高媒体音量 - LogUtils.d("播放开始回调, 序列号:" + s); - } - - @Override - public void onSpeechProgressChanged(String s, int i) { - LogUtils.d("播放进度回调, progress:" + s + ";序列号:" + i); - } - - @Override - public void onSpeechFinish(String s) { // 播放结束之后恢复媒体音量 - LogUtils.d("SpeechSynthesizerListener-onSpeechFinish 播报结束"); - release(); // 播放结束之后就清除占用 - } - - @Override - public void onError(String s, SpeechError speechError) { - mSpeechSynthesizer.pause(); - LogUtils.d("语音合成报错 错误id"+s+" 报错原因 "+speechError); - } - }); - - mSpeechSynthesizer.setAppId(BD_APP_ID); - mSpeechSynthesizer.setApiKey(BD_APP_KEY , BD_APP_SECRET_KEY); - // 设置在线发声音人: 0 普通女声(默认) 1 普通男声 2 特别男声 3 情感男声<度逍遥> 4 情感儿童声<度丫丫> - mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_SPEAKER, "0"); - // 设置合成的音量,0-15 ,默认 5 - mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_VOLUME, "15"); - // 设置合成的语速,0-15 ,默认 5 - mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_SPEED, "5"); - // 设置合成的语调,0-15 ,默认 5 - mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_PITCH, "5"); -// mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_MIX_MODE, SpeechSynthesizer.MIX_MODE_DEFAULT); - // 仅需要在线合成并不使用压缩传输 - mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_AUDIO_RATE, SpeechSynthesizer.AUDIO_BITRATE_PCM); - mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_AUDIO_ENCODE, SpeechSynthesizer.AUDIO_ENCODE_PCM); - int result = mSpeechSynthesizer.initTts(TtsMode.ONLINE); - if (result == 0) { - isInitTts = true; - } else { - isInitTts = false; - } - } - }).start(); - } - - public int ttsSpeak(String text) { - if (mSpeechSynthesizer != null && isInitTts){ - int result = mSpeechSynthesizer.speak(text); - return result; - }else { - return 1; - } - } - - public void release() { - if (mSpeechSynthesizer != null){ - mSpeechSynthesizer.stop(); - mSpeechSynthesizer.release(); - isInitTts = false; - mSpeechSynthesizer = null; - } - } -} diff --git a/library/umeng/src/main/res/xml/file_paths.xml b/library/umeng/src/main/res/xml/file_paths.xml index 437f304..08c9a45 100644 --- a/library/umeng/src/main/res/xml/file_paths.xml +++ b/library/umeng/src/main/res/xml/file_paths.xml @@ -1,8 +1,5 @@ - - - \ No newline at end of file diff --git a/maven.gradle b/maven.gradle index ea792bd..5dfd180 100644 --- a/maven.gradle +++ b/maven.gradle @@ -18,7 +18,6 @@ static def addCommonMaven(RepositoryHandler handler) { handler.mavenCentral() handler.google() handler.maven { url 'https://developer.huawei.com/repo/'} - } ext.addCommonMaven = this.&addCommonMaven \ No newline at end of file