package com.ubt.jimu.blockly.command; import android.util.Log; import android.webkit.WebView; import com.ubt.jimu.blockly.Utils; import com.ubt.jimu.blockly.feature.audio.AudioRecoder; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; /* loaded from: classes.dex */ public class JimuUnityCommand { public static final String BLE_CONNECT_CALLBACK = "blueConnectCallBack"; public static final String CHARGE_PROTECTION = "chargeProtection"; public static final String NOTIFY_KEYBOARD_HIDDEN = "notifyKeyboardHidden"; public static final String REFRESH_ALL_SERVO = "refreshAllServo"; public static final String SHOW_EXCEPTION = "showException"; public static final String STOP_RECORD_ON_PAUSE = "stopRecordAudioCallBack"; public static final String WAKEUP_BLOCKLY = "continueSteps"; public static final String tag = "JimuUnityCommand"; private WebView webView; public JimuUnityCommand(WebView webView) { this.webView = webView; } public void blueConnectCallBack(String str) { try { Utils.setJSResult(this.webView, BLE_CONNECT_CALLBACK, URLEncoder.encode(str, "utf-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); Log.e(tag, e.getMessage()); } } public void chargeProtected(String str) { setJSResult2(CHARGE_PROTECTION, str); } public void jsExceptionWaitResult() { } public void jsShowException(String str) { Utils.setJSResult(this.webView, SHOW_EXCEPTION, str); if (AudioRecoder.recoding) { Utils.setJSResult(this.webView, STOP_RECORD_ON_PAUSE, new String[0]); } } public void notifyKeyboardHidden(String str) { Utils.setJSResult(this.webView, NOTIFY_KEYBOARD_HIDDEN, str); } public void refreshAllServo(String str) { try { Utils.setJSResult(this.webView, "refreshAllServo", URLEncoder.encode(str, "utf-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } protected void setJSResult2(String str, String... strArr) { StringBuilder sb = new StringBuilder(); sb.append("javascript:"); sb.append(str); sb.append("("); if (strArr != null && strArr.length > 0) { for (int i = 0; i < strArr.length; i++) { sb.append("\""); sb.append(strArr[i]); sb.append("\""); if (i < strArr.length - 1) { sb.append(","); } } } sb.append(")"); final String sb2 = sb.toString(); Log.i(tag, sb2); this.webView.post(new Runnable() { // from class: com.ubt.jimu.blockly.command.JimuUnityCommand.1 @Override // java.lang.Runnable public void run() { JimuUnityCommand.this.webView.loadUrl(sb2); } }); } public void showInfraredRef(String str, String str2) { try { Utils.setJSResult(this.webView, str2, URLEncoder.encode(str, "utf-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); Log.e(tag, e.getMessage()); } } public void wakeupBlockly(String str, int i, String str2, String str3) { try { String encode = URLEncoder.encode(str, "utf-8"); Utils.setJSResult(this.webView, "continueSteps", encode, i + "", str2, str3); } catch (UnsupportedEncodingException e) { e.printStackTrace(); Log.e(tag, e.getMessage()); } } }