Skip to content

Commit cfa1d2e

Browse files
committed
添加二维码识别 fix 语音
1 parent caefb42 commit cfa1d2e

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

android/src/main/java/cn/jiguang/imui/messagelist/DecodeUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ public static String parseQRcodeBitmap(String bitmapPath) {
7777
e.printStackTrace();
7878
}
7979

80-
return result != null ? result.getText() : "";
80+
return result != null ? result.getText() : null;
8181
}
8282
}

android/src/main/java/cn/jiguang/imui/messagelist/ReactChatInputManager.java

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public class ReactChatInputManager extends ViewGroupManager<ChatInputView> {
6565
private ChatInputView chatInput;
6666
private Map<String, RCTMember> idList = new HashMap();
6767
private Dialog dialog;
68+
private TimerTipView timerTipView;
6869

6970
@Override
7071
public String getName() {
@@ -104,22 +105,7 @@ protected ChatInputView createViewInstance(final ThemedReactContext reactContext
104105
mContext.registerReceiver(RCTChatInputReceiver, intentFilter);
105106

106107
final Activity activity = reactContext.getCurrentActivity();
107-
Log.w(TAG, "SDK_INT:" + Build.VERSION.SDK_INT);
108-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
109-
final String permission = Manifest.permission.RECORD_AUDIO;
110-
Log.w(TAG, "checkCallingOrSelfPermission:" + activity.checkCallingOrSelfPermission(permission));
111-
Log.w(TAG, "checkSelfPermission:" + activity.checkSelfPermission(permission));
112-
Log.w(TAG, "checkCallingPermission:" + activity.checkCallingPermission(permission));
113-
if (activity.checkCallingPermission(permission) != PackageManager.PERMISSION_GRANTED) {
114108

115-
if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
116-
Log.w(TAG, "shouldShowRequestPermissionRationale:true");
117-
} else {
118-
Log.w(TAG, "shouldShowRequestPermissionRationale:false");
119-
}
120-
activity.requestPermissions(new String[]{permission}, 100);
121-
}
122-
}
123109
chatInput = new ChatInputView(activity, null);
124110
// chatInput.setMenuContainerHeight(666);
125111
// Use default layout
@@ -169,7 +155,7 @@ public void onShowKeyboard(int inputHeight, int showType) {
169155

170156
chatInput.setRecordVoiceListener(new RecordVoiceListener() {
171157

172-
TimerTipView view;
158+
173159
Handler handler = new Handler() {
174160
@Override
175161
public void handleMessage(Message msg) {
@@ -189,12 +175,12 @@ public void onStartRecord() {
189175
@Override
190176
public void onFinishRecord(String voiceFile, boolean isTooLong, int duration) {
191177
if (TextUtils.isEmpty(voiceFile)) {
192-
view.updateStatus(0, 2, 0);
178+
timerTipView.updateStatus(0, 2, 0);
193179
handler.sendEmptyMessageDelayed(1, 500);
194180
return;
195181
}
196182
if (isTooLong) {
197-
view.updateStatus(0, 3, 0);
183+
timerTipView.updateStatus(0, 3, 0);
198184
handler.sendEmptyMessageDelayed(1, 500);
199185
} else {
200186
hideDialog();
@@ -213,7 +199,7 @@ public void onCancelRecord() {
213199

214200
@Override
215201
public void onRecording(boolean cancelAble, int dbSize, int time) {
216-
view.updateStatus(dbSize, cancelAble ? 1 : 0, time);
202+
timerTipView.updateStatus(dbSize, cancelAble ? 1 : 0, time);
217203
}
218204

219205
void hideDialog() {
@@ -227,7 +213,7 @@ void showDialog() {
227213
dialog = new Dialog(reactContext.getCurrentActivity(), R.style.Theme_audioDialog);
228214
dialog.setCanceledOnTouchOutside(false);
229215
// dialog.setCancelable(false);
230-
view = new TimerTipView(reactContext);
216+
timerTipView = new TimerTipView(reactContext);
231217
dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
232218
@Override
233219
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
@@ -237,9 +223,9 @@ public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
237223
return false;
238224
}
239225
});
240-
dialog.setContentView(view);
226+
dialog.setContentView(timerTipView);
241227
}
242-
view.updateStatus(0, 0, 0);
228+
timerTipView.updateStatus(0, 0, 0);
243229
dialog.show();
244230
}
245231
});
@@ -259,6 +245,24 @@ public void onTextChanged(String changeText) {
259245
return chatInput;
260246
}
261247

248+
void requestPermission(Activity activity) {
249+
final String permission = Manifest.permission.RECORD_AUDIO;
250+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
251+
252+
Log.w(TAG, "checkCallingOrSelfPermission:" + activity.checkCallingOrSelfPermission(permission));
253+
Log.w(TAG, "checkSelfPermission:" + activity.checkSelfPermission(permission));
254+
Log.w(TAG, "checkCallingPermission:" + activity.checkCallingPermission(permission));
255+
if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
256+
257+
if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
258+
Log.w(TAG, "shouldShowRequestPermissionRationale:true");
259+
} else {
260+
Log.w(TAG, "shouldShowRequestPermissionRationale:false");
261+
}
262+
// activity.requestPermissions(new String[]{permission}, 100);
263+
}
264+
}
265+
}
262266

263267
@ReactProp(name = "menuContainerHeight")
264268
public void setMenuContainerHeight(ChatInputView chatInputView, int height) {

android/src/main/java/cn/jiguang/imui/messagelist/ReactMsgListManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class ReactMsgListManager extends ViewGroupManager<MessageList> implement
7575
private static final String ON_TOUCH_MSG_LIST_EVENT = "onTouchMsgList";
7676
private static final String ON_PULL_TO_REFRESH_EVENT = "onPullToRefresh";
7777
private static final String ON_CLICK_CHANGE_AUTO_SCROLL_EVENT = "onClickChangeAutoScroll";
78-
private static final String ON_DECODE_QR_CODE_EVENT = "onDecodeQRCode";
78+
private static final String ON_DECODE_QR_CODE_EVENT = "onClickScanImageView";
7979

8080
public static final String RCT_APPEND_MESSAGES_ACTION = "cn.jiguang.imui.messagelist.intent.appendMessages";
8181
public static final String RCT_UPDATE_MESSAGE_ACTION = "cn.jiguang.imui.messagelist.intent.updateMessage";
@@ -175,7 +175,7 @@ public void loadImage(ImageView imageView, String string) {
175175
public void onMessageClick(RCTMessage message) {
176176
if (message.getType() == IMessage.MessageType.SEND_IMAGE || message.getType() == IMessage.MessageType.RECEIVE_IMAGE) {
177177
IMediaFile extend = (IMediaFile) message.getExtend();
178-
PhotoViewPagerViewUtil.show(reactContext.getCurrentActivity(), mAdapter.getImageList(), mAdapter.getImageIndex(extend), null);
178+
PhotoViewPagerViewUtil.show(reactContext.getCurrentActivity(), mAdapter.getImageList(), mAdapter.getImageIndex(extend), longClickListener);
179179
return;
180180
}
181181
WritableMap event = Arguments.createMap();
@@ -287,7 +287,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
287287
dialog.dismiss();
288288
Toast.makeText(mContext, finalCode, Toast.LENGTH_SHORT).show();
289289
WritableMap event = Arguments.createMap();
290-
event.putString("code", finalCode);
290+
event.putString("result", finalCode);
291291
mContext.getJSModule(RCTEventEmitter.class).receiveEvent(msgList.getId(),
292292
ON_DECODE_QR_CODE_EVENT, event);
293293
}

0 commit comments

Comments
 (0)