弹出电话页面
This commit is contained in:
parent
938a5df35f
commit
1da1683adc
|
|
@ -4,14 +4,18 @@ import android.os.Bundle;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.czg.cashier_reserve.call.YJCoreListenerStub;
|
||||
import com.czg.cashier_reserve.channel.ChannelManager;
|
||||
|
||||
import cn.kaer.callmodule.CoreImpl;
|
||||
import cn.kaer.callmodule.CoreListener;
|
||||
import cn.kaer.callmodule.KeSdk;
|
||||
import io.flutter.Log;
|
||||
import io.flutter.embedding.android.FlutterActivity;
|
||||
import io.flutter.embedding.engine.FlutterEngine;
|
||||
|
||||
public class MainActivity extends FlutterActivity {
|
||||
private CoreListener coreListener;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
|
@ -21,6 +25,20 @@ public class MainActivity extends FlutterActivity {
|
|||
} else {
|
||||
Log.e("MainActivity", "FlutterEngine or BinaryMessenger is null, cannot setup EventChannel.");
|
||||
}
|
||||
|
||||
coreListener = new YJCoreListenerStub();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
CoreImpl.getCore().addListener(coreListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
CoreImpl.getCore().removeListener(coreListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -29,11 +29,12 @@ public class CallManager {
|
|||
public static void loadCallLog() {
|
||||
Context mainActivityContext = ContextHolder.getInstance().getContext();
|
||||
Log.i("CallManager","loadCallLog -- " + mainActivityContext);
|
||||
Cursor cursor = mainActivityContext.getContentResolver().query(CallLog.Calls.CONTENT_URI,
|
||||
@SuppressLint("Recycle") Cursor cursor = mainActivityContext.getContentResolver().query(CallLog.Calls.CONTENT_URI,
|
||||
columns, null, null, null);
|
||||
|
||||
JSONArray callLogArray = new JSONArray();
|
||||
|
||||
assert cursor != null;
|
||||
Log.i("CallManager","cursor count:" + cursor.getCount());
|
||||
while (cursor.moveToNext()) {
|
||||
@SuppressLint("Range") String name = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME)); //姓名
|
||||
|
|
@ -66,6 +67,5 @@ public class CallManager {
|
|||
Intent broad = new Intent(EventChannelManager.Action.GET_CALL_LOG_FINISH);
|
||||
broad.putExtra("callLog", callLogArray.toString());
|
||||
mainActivityContext.sendBroadcast(broad);
|
||||
Log.i("CallManager", "send broadcast");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
package com.czg.cashier_reserve.call;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.czg.cashier_reserve.ContextHolder;
|
||||
import com.czg.cashier_reserve.channel.EventChannelManager;
|
||||
import com.kaer.subutil.contact.ContactBean;
|
||||
import com.kaer.subutil.contact.ContactUtil;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import cn.kaer.callmodule.Call;
|
||||
import cn.kaer.callmodule.CoreListenerStub;
|
||||
import cn.kaer.callmodule.ctrl.BaseController;
|
||||
import io.flutter.Log;
|
||||
|
||||
public class YJCoreListenerStub extends CoreListenerStub {
|
||||
|
||||
public void onCallStateChanged(BaseController var1, Call var2, Call.State var3, String var4) {
|
||||
ContactBean contactInfo = ContactUtil.getContactInfo(ContextHolder.getInstance().getContext(), var2.getRemoteNumber());
|
||||
Log.i("YJCoreListenerStub", "onCallStateChanged +++ " + var3);
|
||||
|
||||
JSONObject callInfo = new JSONObject();
|
||||
try {
|
||||
callInfo.put("state", var3);
|
||||
callInfo.put("number", var2.getRemoteNumber());
|
||||
callInfo.put("name", contactInfo.getcName());
|
||||
callInfo.put("region", contactInfo.getRegion());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Log.i("YJCoreListenerStub", "onCallStateChanged: " + callInfo);
|
||||
|
||||
Context mainActivityContext = ContextHolder.getInstance().getContext();
|
||||
Intent broad = new Intent(EventChannelManager.Action.CALL_STATUS_CHANGE);
|
||||
broad.putExtra("callStatus", callInfo.toString());
|
||||
mainActivityContext.sendBroadcast(broad);
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,8 @@ public class ChannelNames {
|
|||
|
||||
public static final String CALL_LOG_CALLBACK = "callLogCallback";
|
||||
|
||||
public static final String CALL_STATUS_CHANGE = "callStatusChange";
|
||||
|
||||
public static String getChannelName(String name) {
|
||||
return BASE_NAME + name;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,10 +24,39 @@ public class EventChannelManager {
|
|||
public static Map<String, BroadcastReceiver> receiverMap = new HashMap<>();
|
||||
public static List<BroadcastReceiver> broadcastReceiverList = new ArrayList<>();
|
||||
|
||||
private static EventChannel callLogChannel;
|
||||
|
||||
public static void addEventChannel(BinaryMessenger messenger) {
|
||||
getCallLogCallback(messenger);
|
||||
callStatusChange(messenger);
|
||||
}
|
||||
|
||||
public static void callStatusChange(BinaryMessenger messenger) {
|
||||
if (messenger == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
EventChannel callStatusChannel = new EventChannel(messenger, ChannelNames.getChannelName(ChannelNames.CALL_STATUS_CHANGE));
|
||||
|
||||
callStatusChannel.setStreamHandler(new EventChannel.StreamHandler() {
|
||||
private BroadcastReceiver broadCast;
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
|
||||
@Override
|
||||
public void onListen(Object o, EventChannel.EventSink eventSink) {
|
||||
broadCast = EventChannelManager.getBroadCast(eventSink);
|
||||
Context context = ContextHolder.getInstance().getContext();
|
||||
IntentFilter intentFilter = new IntentFilter(EventChannelManager.Action.CALL_STATUS_CHANGE);
|
||||
context.registerReceiver(broadCast, intentFilter, Context.RECEIVER_NOT_EXPORTED);
|
||||
receiverMap.put(EventChannelManager.Action.CALL_STATUS_CHANGE, broadCast);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(Object o) {
|
||||
Context context = ContextHolder.getInstance().getContext();
|
||||
context.unregisterReceiver(broadCast);
|
||||
broadcastReceiverList.remove(broadCast);
|
||||
broadCast = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void getCallLogCallback(BinaryMessenger messenger) {
|
||||
|
|
@ -35,20 +64,18 @@ public class EventChannelManager {
|
|||
return;
|
||||
}
|
||||
|
||||
Log.i("EventChannelManager", "getCallLogCallback");
|
||||
|
||||
callLogChannel = new EventChannel(messenger, ChannelNames.getChannelName(ChannelNames.CALL_LOG_CALLBACK));
|
||||
EventChannel callLogChannel = new EventChannel(messenger, ChannelNames.getChannelName(ChannelNames.CALL_LOG_CALLBACK));
|
||||
|
||||
callLogChannel.setStreamHandler(new EventChannel.StreamHandler() {
|
||||
private BroadcastReceiver broadCast;
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
|
||||
@Override
|
||||
public void onListen(Object o, EventChannel.EventSink eventSink) {
|
||||
Log.i("EventChannelManager", "onListen");
|
||||
broadCast = EventChannelManager.getBroadCast(eventSink);
|
||||
Context context = ContextHolder.getInstance().getContext();
|
||||
IntentFilter intentFilter = new IntentFilter(EventChannelManager.Action.GET_CALL_LOG_FINISH);
|
||||
context.registerReceiver(broadCast, intentFilter);
|
||||
context.registerReceiver(broadCast, intentFilter, Context.RECEIVER_NOT_EXPORTED);
|
||||
receiverMap.put(EventChannelManager.Action.GET_CALL_LOG_FINISH, broadCast);
|
||||
}
|
||||
|
||||
|
|
@ -66,12 +93,13 @@ public class EventChannelManager {
|
|||
BroadcastReceiver b = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.i("EventChannelManager", "onReceive");
|
||||
String action = intent.getAction();
|
||||
Log.i("EventChannelManager", "action name == " + action);
|
||||
if (Action.GET_CALL_LOG_FINISH.equals(action)) {
|
||||
String extra = intent.getStringExtra("callLog");
|
||||
eventSink.success(extra);
|
||||
} if (Action.CALL_STATUS_CHANGE.equals(action)) {
|
||||
String extra = intent.getStringExtra("callStatus");
|
||||
eventSink.success(extra);
|
||||
} else {
|
||||
eventSink.error("没有该事件", null, null);
|
||||
}
|
||||
|
|
@ -85,5 +113,6 @@ public class EventChannelManager {
|
|||
// 这里假设Action是一个定义了相关常量的类,示例如下,你可以根据实际情况调整
|
||||
public static class Action {
|
||||
public static final String GET_CALL_LOG_FINISH = ChannelNames.BASE_NAME + "get_call_log_finish";
|
||||
public static final String CALL_STATUS_CHANGE = ChannelNames.BASE_NAME + "call_status_change";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
import 'package:cashier_reserve/common/base/ui.dart';
|
||||
import 'package:cashier_reserve/common/channel/model/call_status_change_model.dart';
|
||||
|
||||
class CallView extends StatefulWidget {
|
||||
final CallStatusChangeModel statusModel;
|
||||
|
||||
const CallView({super.key, required this.statusModel});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _CallViewState();
|
||||
}
|
||||
}
|
||||
|
||||
class _CallViewState extends State<CallView> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.black.withOpacity(0.2),
|
||||
body: GestureDetector(
|
||||
onTap: () {
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
},
|
||||
child: Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
height: MediaQuery.of(context).size.height,
|
||||
color: Colors.blue,
|
||||
child: Container(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +1,17 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:cashier_reserve/common/channel/model/call_status_change_model.dart';
|
||||
import 'package:cashier_reserve/common/print/print.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../manager/event_manager.dart';
|
||||
import 'call_log_model.dart';
|
||||
import 'model/call_log_model.dart';
|
||||
import 'names.dart';
|
||||
|
||||
class MyEventChannel {
|
||||
static void startListener() {
|
||||
onGetCallLogResult();
|
||||
onCallStatusChange();
|
||||
}
|
||||
|
||||
static void onGetCallLogResult() {
|
||||
|
|
@ -35,4 +37,18 @@ class MyEventChannel {
|
|||
yjPrint("onGetCallLogResult error");
|
||||
});
|
||||
}
|
||||
|
||||
static void onCallStatusChange() {
|
||||
EventChannel channel = EventChannel(getChannelName(kCallStatusChange));
|
||||
channel.receiveBroadcastStream().listen((Object? o) {
|
||||
yjPrint("onCallStatusChange: $o");
|
||||
if (o is String) {
|
||||
Map<String, dynamic> m = json.decode(o);
|
||||
CallStatusChangeModel model = CallStatusChangeModel.fromJson(m);
|
||||
EventManager.postEvent(CallStatusChangeEvent(model: model));
|
||||
}
|
||||
}, onError: (Object error) {
|
||||
yjPrint("onCallStatusChange error");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
import 'dart:convert';
|
||||
/// state : "Incoming"
|
||||
/// number : "18020143310"
|
||||
/// name : "gong"
|
||||
/// region : "江苏省 南京市"
|
||||
|
||||
CallStatusChangeModel callStatusChangeModelFromJson(String str) => CallStatusChangeModel.fromJson(json.decode(str));
|
||||
String callStatusChangeModelToJson(CallStatusChangeModel data) => json.encode(data.toJson());
|
||||
class CallStatusChangeModel {
|
||||
CallStatusChangeModel({
|
||||
String? state,
|
||||
String? number,
|
||||
String? name,
|
||||
String? region,}){
|
||||
_state = state;
|
||||
_number = number;
|
||||
_name = name;
|
||||
_region = region;
|
||||
}
|
||||
|
||||
CallStatusChangeModel.fromJson(dynamic json) {
|
||||
_state = json['state'];
|
||||
_number = json['number'];
|
||||
_name = json['name'];
|
||||
_region = json['region'];
|
||||
}
|
||||
String? _state;
|
||||
String? _number;
|
||||
String? _name;
|
||||
String? _region;
|
||||
CallStatusChangeModel copyWith({ String? state,
|
||||
String? number,
|
||||
String? name,
|
||||
String? region,
|
||||
}) => CallStatusChangeModel( state: state ?? _state,
|
||||
number: number ?? _number,
|
||||
name: name ?? _name,
|
||||
region: region ?? _region,
|
||||
);
|
||||
String? get state => _state;
|
||||
String? get number => _number;
|
||||
String? get name => _name;
|
||||
String? get region => _region;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
map['state'] = _state;
|
||||
map['number'] = _number;
|
||||
map['name'] = _name;
|
||||
map['region'] = _region;
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,6 +4,8 @@ const String kGetCallLog = 'getCallLog';
|
|||
|
||||
const String kCallLogCallback = 'callLogCallback';
|
||||
|
||||
const String kCallStatusChange = 'callStatusChange';
|
||||
|
||||
String getChannelName(name) {
|
||||
return kChannelBaseName + name;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:cashier_reserve/common/channel/call_log_model.dart';
|
||||
import 'package:cashier_reserve/common/channel/model/call_log_model.dart';
|
||||
import 'package:cashier_reserve/common/channel/model/call_status_change_model.dart';
|
||||
import 'package:event_bus/event_bus.dart';
|
||||
|
||||
|
||||
|
|
@ -51,4 +52,10 @@ class GetCallLogEvent extends MyEvent {
|
|||
bool isSuccess = false;
|
||||
|
||||
GetCallLogEvent({this.callLogs = const [], this.isLoadMore = false, this.isSuccess = false});
|
||||
}
|
||||
|
||||
class CallStatusChangeEvent extends MyEvent {
|
||||
CallStatusChangeModel model;
|
||||
|
||||
CallStatusChangeEvent({required this.model});
|
||||
}
|
||||
|
|
@ -1,7 +1,11 @@
|
|||
import 'package:cashier_reserve/call/call_view.dart';
|
||||
import 'package:cashier_reserve/common/base/ui.dart';
|
||||
import 'package:cashier_reserve/common/base/ui_model.dart';
|
||||
import 'package:cashier_reserve/common/channel/model/call_status_change_model.dart';
|
||||
import 'package:cashier_reserve/common/manager/app_manager.dart';
|
||||
import 'package:cashier_reserve/common/manager/event_manager.dart';
|
||||
import 'package:cashier_reserve/common/print/print.dart';
|
||||
import 'package:cashier_reserve/common/push/push.dart';
|
||||
|
||||
class HomeViewModel extends BaseUIModel {
|
||||
int _currentIndex = 0;
|
||||
|
|
@ -37,12 +41,23 @@ class HomeViewModel extends BaseUIModel {
|
|||
|
||||
PageController? get pageController => _pageController;
|
||||
|
||||
bool isShowCallView = false;
|
||||
|
||||
HomeViewModel() {
|
||||
_pageController = PageController(initialPage: 0);
|
||||
|
||||
Future.delayed(const Duration(milliseconds: 700), () {
|
||||
_checkLogin();
|
||||
});
|
||||
|
||||
EventManager.addListener<CallStatusChangeEvent>(this, (event) {
|
||||
yjPrint("HomeViewModel CallStatusChangeEvent state: ${event.model.state}");
|
||||
if (event.model.state == "Incoming") {
|
||||
showCallInfoView(event.model);
|
||||
} else {
|
||||
hideCallInfoView();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -65,4 +80,20 @@ class HomeViewModel extends BaseUIModel {
|
|||
|
||||
_pageController?.jumpToPage(index);
|
||||
}
|
||||
|
||||
showCallInfoView(CallStatusChangeModel model) {
|
||||
if (isShowCallView) {
|
||||
return;
|
||||
}
|
||||
YJPush.presentWidget(context!, CallView(statusModel: model));
|
||||
isShowCallView = true;
|
||||
}
|
||||
|
||||
hideCallInfoView() {
|
||||
if (!isShowCallView) {
|
||||
return;
|
||||
}
|
||||
Navigator.of(context!).pop();
|
||||
isShowCallView = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:cashier_reserve/common/base/ui.dart';
|
||||
import 'package:cashier_reserve/common/channel/call_log_model.dart';
|
||||
import 'package:cashier_reserve/common/channel/model/call_log_model.dart';
|
||||
import 'package:cashier_reserve/common/print/print.dart';
|
||||
import 'package:cashier_reserve/data_model/reserve/reserve_log_model.dart';
|
||||
import 'package:cashier_reserve/home/reserve_view_model.dart';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import 'package:cashier_reserve/common/base/ui.dart';
|
||||
import 'package:cashier_reserve/common/base/ui_model.dart';
|
||||
import 'package:cashier_reserve/common/channel/call_log_model.dart';
|
||||
import 'package:cashier_reserve/common/channel/model/call_log_model.dart';
|
||||
import 'package:cashier_reserve/common/channel/channel_manager.dart';
|
||||
import 'package:cashier_reserve/common/manager/app_manager.dart';
|
||||
import 'package:cashier_reserve/common/manager/event_manager.dart';
|
||||
|
|
|
|||
Loading…
Reference in New Issue