Initial commit
This commit is contained in:
498
sources/com/ubt/jimu/blockly/view/DialogBlocklyWebView.java
Normal file
498
sources/com/ubt/jimu/blockly/view/DialogBlocklyWebView.java
Normal file
@@ -0,0 +1,498 @@
|
||||
package com.ubt.jimu.blockly.view;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import com.ubt.jimu.R;
|
||||
import com.ubt.jimu.base.dialog.IDialogListener;
|
||||
import com.ubt.jimu.base.dialog.SimpleQuestionDialog;
|
||||
import com.ubt.jimu.base.entities.Course;
|
||||
import com.ubt.jimu.blockly.JimuRobot;
|
||||
import com.ubt.jimu.blockly.Utils;
|
||||
import com.ubt.jimu.blockly.command.JimuBlocklyCommand;
|
||||
import com.ubt.jimu.blockly.command.JimuJavascriptInterface;
|
||||
import com.ubt.jimu.blockly.command.JimuUnityCommand;
|
||||
import com.ubt.jimu.blockly.command.UnityCommandController;
|
||||
import com.ubt.jimu.blockly.exception.BlocklyEvent;
|
||||
import com.ubt.jimu.blockly.exception.JimuRobotMessage;
|
||||
import com.ubt.jimu.blockly.feature.sensor.DeviceDirection;
|
||||
import com.ubt.jimu.diy.view.BrowseCompletedActivity;
|
||||
import com.ubt.jimu.diy.view.DiyBrowseActivity;
|
||||
import com.ubt.jimu.unity.bluetooth.ConnectionStatus;
|
||||
import com.ubt.jimu.unity.bluetooth.UnityActivity;
|
||||
import com.ubt.jimu.utils.JsonHelper;
|
||||
import com.ubt.jimu.utils.PackageHelper;
|
||||
import com.ubt.jimu.utils.SPUtils;
|
||||
import com.ubtech.utils.AndroidVersionCheckUtils;
|
||||
import com.ubtech.view.widget.ToastView;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class DialogBlocklyWebView extends Fragment {
|
||||
public static final String BASE_URL = "https://jimu.ubtrobot.com";
|
||||
public static String CODE = "code";
|
||||
public static String STEP = "step";
|
||||
private final String TAG = DialogBlocklyWebView.class.getSimpleName();
|
||||
private int bleState;
|
||||
private JimuBlocklyCommand blocklyObj;
|
||||
private Course course;
|
||||
private DeviceDirection direction;
|
||||
private SimpleQuestionDialog exceptionDialog;
|
||||
protected ImageView imgNextStep;
|
||||
protected ImageView imgPreviousStep;
|
||||
private ImageView imgWait;
|
||||
private JimuUnityCommand javaInterface;
|
||||
private JimuJavascriptInterface javascriptInterface;
|
||||
private String jimuRobotJSON;
|
||||
protected View llBrowseStep;
|
||||
private LinearLayout llWait;
|
||||
private JimuRobot mJimuRobot;
|
||||
private long modelId;
|
||||
private int moduleType;
|
||||
private Animation rotateAnimaLow;
|
||||
protected TextView tvStep;
|
||||
private JimuWebChromeClient webChromeClient;
|
||||
private WebView webView;
|
||||
private JimuWebViewClient webViewClient;
|
||||
|
||||
private void bleDisconnected(BlocklyEvent blocklyEvent) {
|
||||
commonTips((String) blocklyEvent.getMessage(), 2);
|
||||
JimuBlocklyCommand jimuBlocklyCommand = this.blocklyObj;
|
||||
if (jimuBlocklyCommand == null || jimuBlocklyCommand.getJimuRobot() == null) {
|
||||
return;
|
||||
}
|
||||
this.blocklyObj.getJimuRobot().setBlueState(ConnectionStatus.DIS_CONNECT.getStatus());
|
||||
this.bleState = ConnectionStatus.DIS_CONNECT.getStatus();
|
||||
}
|
||||
|
||||
public static DialogBlocklyWebView getInstance(String str, int i, long j, int i2, int i3, int i4, Course course) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("jimuRobotJSON", str);
|
||||
bundle.putInt("bleState", i);
|
||||
bundle.putLong("modelId", j);
|
||||
bundle.putInt("moduleType", i2);
|
||||
bundle.putInt(CODE, i3);
|
||||
bundle.putInt(STEP, i4);
|
||||
bundle.putSerializable("course", course);
|
||||
DialogBlocklyWebView dialogBlocklyWebView = new DialogBlocklyWebView();
|
||||
dialogBlocklyWebView.setArguments(bundle);
|
||||
return dialogBlocklyWebView;
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
if (this.mJimuRobot == null) {
|
||||
this.mJimuRobot = (JimuRobot) JsonHelper.a(this.jimuRobotJSON, (Class<?>) JimuRobot.class);
|
||||
this.mJimuRobot.setBlueState(this.bleState);
|
||||
this.mJimuRobot.setServerModelId(this.modelId);
|
||||
}
|
||||
if (1007 == getArguments().getInt(CODE)) {
|
||||
this.llBrowseStep.setOnTouchListener(new View.OnTouchListener() { // from class: com.ubt.jimu.blockly.view.DialogBlocklyWebView.1
|
||||
@Override // android.view.View.OnTouchListener
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
final int i = getArguments().getInt(STEP);
|
||||
this.llBrowseStep.setVisibility(0);
|
||||
this.imgPreviousStep.setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.blockly.view.DialogBlocklyWebView.2
|
||||
@Override // android.view.View.OnClickListener
|
||||
public void onClick(View view) {
|
||||
DiyBrowseActivity.start(DialogBlocklyWebView.this.getActivity(), i - 1, UnityActivity.modelBrowse);
|
||||
((UnityActivity) DialogBlocklyWebView.this.getActivity()).setIsBack(true);
|
||||
((UnityActivity) DialogBlocklyWebView.this.getActivity()).closeBlockly();
|
||||
}
|
||||
});
|
||||
this.imgNextStep.setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.blockly.view.DialogBlocklyWebView.3
|
||||
@Override // android.view.View.OnClickListener
|
||||
public void onClick(View view) {
|
||||
BrowseCompletedActivity.start(DialogBlocklyWebView.this.getActivity());
|
||||
SPUtils.b(String.format(DiyBrowseActivity.DIYSTEP, DialogBlocklyWebView.this.mJimuRobot.getModelId()), -5);
|
||||
((UnityActivity) DialogBlocklyWebView.this.getActivity()).setIsBack(true);
|
||||
((UnityActivity) DialogBlocklyWebView.this.getActivity()).closeBlockly();
|
||||
}
|
||||
});
|
||||
this.tvStep.setText(String.format("%s/%s", String.valueOf(i), String.valueOf(i)));
|
||||
} else {
|
||||
this.llBrowseStep.setVisibility(8);
|
||||
}
|
||||
this.blocklyObj = new JimuBlocklyCommand(this.webView, (UnityActivity) getActivity(), this.mJimuRobot);
|
||||
this.blocklyObj.setModuleType(this.moduleType);
|
||||
this.javascriptInterface = new JimuJavascriptInterface(this.webView, getActivity(), this.mJimuRobot);
|
||||
this.javascriptInterface.setDialogBlocklyWebView(this);
|
||||
this.javascriptInterface.setCourse(this.course);
|
||||
this.webChromeClient = new JimuWebChromeClient();
|
||||
this.webViewClient = new JimuWebViewClient(getActivity(), this.blocklyObj);
|
||||
this.webViewClient.setDialog(this);
|
||||
this.webView.removeJavascriptInterface("blocklyObj");
|
||||
this.webView.addJavascriptInterface(this.javascriptInterface, "blocklyObj");
|
||||
this.webView.setWebViewClient(this.webViewClient);
|
||||
this.webView.setWebChromeClient(this.webChromeClient);
|
||||
if (1 != this.moduleType) {
|
||||
this.webView.loadUrl("file:///" + Utils.baseUrl + "teachMaterial/index.html");
|
||||
} else if (this.course != null) {
|
||||
this.webView.loadUrl("file:///" + Utils.baseUrl + "teachOldCourse/course.html");
|
||||
} else {
|
||||
this.webView.loadUrl("file:///" + Utils.baseUrl + "teachCourse/course.html");
|
||||
}
|
||||
this.javaInterface = new JimuUnityCommand(this.webView);
|
||||
showWait();
|
||||
}
|
||||
|
||||
private void initWebView() {
|
||||
PackageHelper.a("CHANNEL_ID");
|
||||
this.webView.getSettings().setTextZoom(100);
|
||||
this.webView.getSettings().setDisplayZoomControls(false);
|
||||
this.webView.getSettings().setSupportZoom(false);
|
||||
this.webView.getSettings().setUseWideViewPort(false);
|
||||
this.webView.getSettings().setJavaScriptEnabled(true);
|
||||
this.webView.getSettings().setLoadWithOverviewMode(true);
|
||||
if (AndroidVersionCheckUtils.c()) {
|
||||
this.webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
|
||||
}
|
||||
if (AndroidVersionCheckUtils.d()) {
|
||||
this.webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
|
||||
}
|
||||
this.webView.getSettings().setAllowContentAccess(true);
|
||||
this.webView.getSettings().setAllowFileAccess(true);
|
||||
this.webView.getSettings().setDatabaseEnabled(true);
|
||||
this.webView.getSettings().setDomStorageEnabled(true);
|
||||
this.webView.getSettings().setAppCacheEnabled(false);
|
||||
this.webView.getSettings().setCacheMode(2);
|
||||
this.webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
|
||||
this.webView.setScrollContainer(false);
|
||||
}
|
||||
|
||||
private void setJSResult(final String str) {
|
||||
if (TextUtils.isEmpty(str)) {
|
||||
return;
|
||||
}
|
||||
this.webView.post(new Runnable() { // from class: com.ubt.jimu.blockly.view.DialogBlocklyWebView.8
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
DialogBlocklyWebView.this.webView.loadUrl(str);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showException(String str) {
|
||||
JimuBlocklyCommand jimuBlocklyCommand = this.blocklyObj;
|
||||
if (jimuBlocklyCommand != null) {
|
||||
jimuBlocklyCommand.stopSensorTimer("");
|
||||
}
|
||||
this.javaInterface.jsShowException("Error");
|
||||
this.exceptionDialog = SimpleQuestionDialog.newInstance(str);
|
||||
this.exceptionDialog.setListener(new IDialogListener() { // from class: com.ubt.jimu.blockly.view.DialogBlocklyWebView.7
|
||||
@Override // com.ubt.jimu.base.dialog.IDialogListener
|
||||
public void onCancle() {
|
||||
UnityActivity.communityWithUnity(DialogBlocklyWebView.this.getActivity(), UnityCommandController.SHOW_EXCEPTION_CALLBACK, "0");
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.base.dialog.IDialogListener
|
||||
public void onOk() {
|
||||
UnityActivity.communityWithUnity(DialogBlocklyWebView.this.getActivity(), UnityCommandController.SHOW_EXCEPTION_CALLBACK, "1");
|
||||
DialogBlocklyWebView.this.showWait();
|
||||
if (DialogBlocklyWebView.this.blocklyObj != null) {
|
||||
DialogBlocklyWebView.this.blocklyObj.startSensorTimer(DialogBlocklyWebView.this.blocklyObj.getQueryUrl(), DialogBlocklyWebView.this.blocklyObj.getQueryCallback());
|
||||
}
|
||||
}
|
||||
});
|
||||
this.exceptionDialog.show(getFragmentManager(), "");
|
||||
}
|
||||
|
||||
public void blueConnectCallBack(String str) {
|
||||
JimuRobot jimuRobot = (JimuRobot) JsonHelper.a(str, (Class<?>) JimuRobot.class);
|
||||
if (jimuRobot != null) {
|
||||
this.mJimuRobot.setLights(jimuRobot.getLights());
|
||||
this.mJimuRobot.setGyroscopeId(jimuRobot.getGyroscopeId());
|
||||
this.mJimuRobot.setInfraredId(jimuRobot.getInfraredId());
|
||||
this.mJimuRobot.setTouchId(jimuRobot.getTouchId());
|
||||
this.mJimuRobot.setIsLithium(jimuRobot.getIsLithium());
|
||||
this.mJimuRobot.setUltrasonicId(jimuRobot.getUltrasonicId());
|
||||
this.mJimuRobot.setColorId(jimuRobot.getColorId());
|
||||
this.mJimuRobot.setUnicornId(jimuRobot.getUnicornId());
|
||||
jimuRobot.setBlueState(this.mJimuRobot.getBlueState());
|
||||
String a = JsonHelper.a(jimuRobot);
|
||||
JimuUnityCommand jimuUnityCommand = this.javaInterface;
|
||||
if (jimuUnityCommand != null) {
|
||||
jimuUnityCommand.blueConnectCallBack(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void chargeProtected(String str) {
|
||||
JimuUnityCommand jimuUnityCommand = this.javaInterface;
|
||||
if (jimuUnityCommand != null) {
|
||||
jimuUnityCommand.chargeProtected(str);
|
||||
}
|
||||
}
|
||||
|
||||
public void commonTips(String str, int i) {
|
||||
ToastView.a(getActivity(), str, i == 2 ? ToastView.Type.ERROR : i == 1 ? ToastView.Type.SUCCESS : ToastView.Type.NORMAL).a();
|
||||
}
|
||||
|
||||
public DeviceDirection getDirection() {
|
||||
return this.direction;
|
||||
}
|
||||
|
||||
public int getModuleType() {
|
||||
return this.moduleType;
|
||||
}
|
||||
|
||||
public void hideWait() {
|
||||
Animation animation = this.rotateAnimaLow;
|
||||
if (animation != null) {
|
||||
animation.cancel();
|
||||
}
|
||||
this.llWait.postDelayed(new Runnable() { // from class: com.ubt.jimu.blockly.view.DialogBlocklyWebView.6
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
DialogBlocklyWebView.this.llWait.setVisibility(8);
|
||||
}
|
||||
}, 100L);
|
||||
}
|
||||
|
||||
public void jsShowException(String str) {
|
||||
JimuUnityCommand jimuUnityCommand = this.javaInterface;
|
||||
if (jimuUnityCommand != null) {
|
||||
jimuUnityCommand.jsShowException(str);
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyKeyboardHidden(String str) {
|
||||
JimuUnityCommand jimuUnityCommand = this.javaInterface;
|
||||
if (jimuUnityCommand != null) {
|
||||
jimuUnityCommand.notifyKeyboardHidden(str);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.app.Fragment
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
}
|
||||
|
||||
@Override // android.app.Fragment
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
Bundle arguments = getArguments();
|
||||
if (arguments != null) {
|
||||
this.jimuRobotJSON = arguments.getString("jimuRobotJSON");
|
||||
this.bleState = arguments.getInt("bleState");
|
||||
this.modelId = arguments.getLong("modelId");
|
||||
this.moduleType = arguments.getInt("moduleType");
|
||||
this.course = (Course) arguments.getSerializable("course");
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.app.Fragment
|
||||
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
|
||||
View inflate = layoutInflater.inflate(R.layout.dialog_blockly_webview, (ViewGroup) null);
|
||||
this.webView = (WebView) inflate.findViewById(R.id.webView);
|
||||
this.llWait = (LinearLayout) inflate.findViewById(R.id.ll_wait);
|
||||
this.imgWait = (ImageView) inflate.findViewById(R.id.wait_img);
|
||||
this.llBrowseStep = inflate.findViewById(R.id.llStep);
|
||||
this.imgPreviousStep = (ImageView) inflate.findViewById(R.id.imgPreviousStep);
|
||||
this.imgNextStep = (ImageView) inflate.findViewById(R.id.imgNextStep);
|
||||
this.tvStep = (TextView) inflate.findViewById(R.id.tvStep);
|
||||
initWebView();
|
||||
initView();
|
||||
this.llWait.setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.blockly.view.DialogBlocklyWebView.4
|
||||
@Override // android.view.View.OnClickListener
|
||||
public void onClick(View view) {
|
||||
DialogBlocklyWebView.this.llWait.setVisibility(8);
|
||||
}
|
||||
});
|
||||
return inflate;
|
||||
}
|
||||
|
||||
@Override // android.app.Fragment
|
||||
public void onDestroy() {
|
||||
WebView webView = this.webView;
|
||||
if (webView != null) {
|
||||
webView.stopLoading();
|
||||
this.webView.clearHistory();
|
||||
this.webView.removeAllViews();
|
||||
this.webView.destroy();
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override // android.app.Fragment
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onMessageEvent(BlocklyEvent blocklyEvent) {
|
||||
switch (blocklyEvent.getType()) {
|
||||
case 1001:
|
||||
JimuRobotMessage jimuRobotMessage = (JimuRobotMessage) blocklyEvent.getMessage();
|
||||
if (jimuRobotMessage != null) {
|
||||
commonTips(jimuRobotMessage.getMsg(), jimuRobotMessage.getLevel());
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 1002:
|
||||
showException((String) blocklyEvent.getMessage());
|
||||
break;
|
||||
case 1003:
|
||||
bleDisconnected(blocklyEvent);
|
||||
break;
|
||||
case 1004:
|
||||
setJSResult((String) blocklyEvent.getMessage());
|
||||
break;
|
||||
case 1006:
|
||||
this.bleState = ConnectionStatus.DIS_CONNECT.getStatus();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.app.Fragment
|
||||
public void onPause() {
|
||||
SimpleQuestionDialog simpleQuestionDialog = this.exceptionDialog;
|
||||
if (simpleQuestionDialog != null && simpleQuestionDialog.isVisible()) {
|
||||
this.exceptionDialog.dismiss();
|
||||
}
|
||||
super.onPause();
|
||||
WebView webView = this.webView;
|
||||
if (webView != null) {
|
||||
try {
|
||||
webView.getClass().getMethod("onPause", new Class[0]).invoke(this.webView, null);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e2) {
|
||||
e2.printStackTrace();
|
||||
} catch (InvocationTargetException e3) {
|
||||
e3.printStackTrace();
|
||||
} catch (Exception e4) {
|
||||
e4.printStackTrace();
|
||||
}
|
||||
}
|
||||
stopQueryTimer();
|
||||
}
|
||||
|
||||
@Override // android.app.Fragment
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
WebView webView = this.webView;
|
||||
if (webView != null) {
|
||||
try {
|
||||
webView.getClass().getMethod("onResume", new Class[0]).invoke(this.webView, null);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e2) {
|
||||
e2.printStackTrace();
|
||||
} catch (InvocationTargetException e3) {
|
||||
e3.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.app.Fragment
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
EventBus.b().c(this);
|
||||
}
|
||||
|
||||
@Override // android.app.Fragment
|
||||
public void onStop() {
|
||||
EventBus.b().d(this);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
public void refreshAllServo(String str, String str2) {
|
||||
JimuRobot jimuRobot = this.mJimuRobot;
|
||||
if (jimuRobot != null) {
|
||||
jimuRobot.setServo(str);
|
||||
this.mJimuRobot.setCircleServos(str2);
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshDirection(DeviceDirection deviceDirection) {
|
||||
this.direction = deviceDirection;
|
||||
}
|
||||
|
||||
public void setBlueState(int i) {
|
||||
JimuRobot jimuRobot = this.mJimuRobot;
|
||||
if (jimuRobot != null) {
|
||||
jimuRobot.setBlueState(i);
|
||||
}
|
||||
setJSResult("BLEStateChanged", String.valueOf(i));
|
||||
}
|
||||
|
||||
public void showInfraredRef(String str, String str2) {
|
||||
JimuUnityCommand jimuUnityCommand = this.javaInterface;
|
||||
if (jimuUnityCommand != null) {
|
||||
jimuUnityCommand.showInfraredRef(str, str2);
|
||||
}
|
||||
}
|
||||
|
||||
public void showWait() {
|
||||
if (this.rotateAnimaLow == null) {
|
||||
this.rotateAnimaLow = AnimationUtils.loadAnimation(getActivity(), R.anim.anima_dialog_wait);
|
||||
}
|
||||
this.llWait.setVisibility(0);
|
||||
this.imgWait.startAnimation(this.rotateAnimaLow);
|
||||
((AnimationDrawable) this.imgWait.getBackground()).start();
|
||||
this.webView.postDelayed(new Runnable() { // from class: com.ubt.jimu.blockly.view.DialogBlocklyWebView.5
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
DialogBlocklyWebView.this.hideWait();
|
||||
}
|
||||
}, 10000L);
|
||||
}
|
||||
|
||||
public void stopQueryTimer() {
|
||||
JimuBlocklyCommand jimuBlocklyCommand = this.blocklyObj;
|
||||
if (jimuBlocklyCommand != null) {
|
||||
jimuBlocklyCommand.stopSensorTimer("");
|
||||
}
|
||||
}
|
||||
|
||||
public void updateJimuRobot(String str) {
|
||||
JimuRobot jimuRobot;
|
||||
JimuRobot jimuRobot2 = (JimuRobot) JsonHelper.a(str, (Class<?>) JimuRobot.class);
|
||||
if (jimuRobot2 == null || (jimuRobot = this.mJimuRobot) == null) {
|
||||
return;
|
||||
}
|
||||
jimuRobot.setGyroscopeId(jimuRobot2.getGyroscopeId());
|
||||
this.mJimuRobot.setInfraredId(jimuRobot2.getInfraredId());
|
||||
this.mJimuRobot.setLights(jimuRobot2.getLights());
|
||||
this.mJimuRobot.setTouchId(jimuRobot2.getTouchId());
|
||||
this.mJimuRobot.setMotor(jimuRobot2.getMotor());
|
||||
this.mJimuRobot.setIsLithium(jimuRobot2.getIsLithium());
|
||||
this.mJimuRobot.setUltrasonicId(jimuRobot2.getUltrasonicId());
|
||||
this.mJimuRobot.setColorId(jimuRobot2.getColorId());
|
||||
this.mJimuRobot.setUnicornId(jimuRobot2.getUnicornId());
|
||||
}
|
||||
|
||||
public void wakeupBlockly(String str, int i, String str2, String str3) {
|
||||
JimuUnityCommand jimuUnityCommand = this.javaInterface;
|
||||
if (jimuUnityCommand != null) {
|
||||
jimuUnityCommand.wakeupBlockly(str, i, str2, str3);
|
||||
}
|
||||
}
|
||||
|
||||
public void setJSResult(String str, String... strArr) {
|
||||
Utils.setJSResult(this.webView, str, strArr);
|
||||
}
|
||||
|
||||
public void refreshAllServo(String str) {
|
||||
this.javaInterface.refreshAllServo(str);
|
||||
}
|
||||
}
|
194
sources/com/ubt/jimu/blockly/view/HelpFragmentCompact.java
Normal file
194
sources/com/ubt/jimu/blockly/view/HelpFragmentCompact.java
Normal file
@@ -0,0 +1,194 @@
|
||||
package com.ubt.jimu.blockly.view;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.ProgressBar;
|
||||
import butterknife.ButterKnife;
|
||||
import com.ubt.jimu.R;
|
||||
import com.ubt.jimu.utils.NetWorkUtil;
|
||||
import com.ubt.jimu.widgets.NavigationBarView;
|
||||
import com.ubtech.utils.AndroidVersionCheckUtils;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class HelpFragmentCompact extends Fragment implements NavigationBarView.OnActionClickListener {
|
||||
private static final String ACTIONBAR_BG_COLOR = "actionbarBackgroundColorResId";
|
||||
private static final String TITLE = "title";
|
||||
private static final String URL = "url";
|
||||
private int actionbarBackgroundColorResId;
|
||||
private OnHelpFragmentInteractionListener mListener;
|
||||
protected NavigationBarView navigationBarView;
|
||||
protected ProgressBar pgLoading;
|
||||
private String title;
|
||||
private String url;
|
||||
protected WebView webView;
|
||||
|
||||
public class MyWebChromeClient extends WebChromeClient {
|
||||
public MyWebChromeClient() {
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebChromeClient
|
||||
public void onProgressChanged(WebView webView, int i) {
|
||||
HelpFragmentCompact.this.pgLoading.setProgress(i);
|
||||
}
|
||||
}
|
||||
|
||||
public class MyWebViewClient extends WebViewClient {
|
||||
public MyWebViewClient() {
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebViewClient
|
||||
public void onPageFinished(WebView webView, String str) {
|
||||
super.onPageFinished(webView, str);
|
||||
HelpFragmentCompact.this.pgLoading.setProgress(100);
|
||||
if (HelpFragmentCompact.this.actionbarBackgroundColorResId == R.color.bg_unicorn_ar_game_help) {
|
||||
HelpFragmentCompact.this.navigationBarView.setLeftIvSrc(R.drawable.back_white);
|
||||
HelpFragmentCompact helpFragmentCompact = HelpFragmentCompact.this;
|
||||
helpFragmentCompact.navigationBarView.setBackgroundResource(helpFragmentCompact.actionbarBackgroundColorResId);
|
||||
}
|
||||
HelpFragmentCompact helpFragmentCompact2 = HelpFragmentCompact.this;
|
||||
helpFragmentCompact2.navigationBarView.setTitle(TextUtils.isEmpty(helpFragmentCompact2.title) ? webView.getTitle() : HelpFragmentCompact.this.title);
|
||||
HelpFragmentCompact.this.pgLoading.postDelayed(new Runnable() { // from class: com.ubt.jimu.blockly.view.HelpFragmentCompact.MyWebViewClient.1
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
HelpFragmentCompact.this.pgLoading.setVisibility(8);
|
||||
}
|
||||
}, 500L);
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebViewClient
|
||||
public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
|
||||
super.onPageStarted(webView, str, bitmap);
|
||||
HelpFragmentCompact.this.pgLoading.setVisibility(0);
|
||||
HelpFragmentCompact.this.pgLoading.setProgress(0);
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnHelpFragmentInteractionListener {
|
||||
void onHelpPageBack();
|
||||
}
|
||||
|
||||
private void initWebView() {
|
||||
this.navigationBarView.setBackgroundResource(R.color.theme_background);
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
this.webView.removeJavascriptInterface("searchBoxJavaBridge_");
|
||||
this.webView.removeJavascriptInterface("accessibility");
|
||||
this.webView.removeJavascriptInterface("accessibilityTraversal");
|
||||
}
|
||||
this.webView.getSettings().setDisplayZoomControls(false);
|
||||
this.webView.getSettings().setSupportZoom(false);
|
||||
this.webView.getSettings().setUseWideViewPort(false);
|
||||
this.webView.getSettings().setJavaScriptEnabled(true);
|
||||
this.webView.getSettings().setLoadWithOverviewMode(true);
|
||||
if (AndroidVersionCheckUtils.c()) {
|
||||
this.webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
|
||||
}
|
||||
if (AndroidVersionCheckUtils.d()) {
|
||||
this.webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
|
||||
}
|
||||
this.webView.getSettings().setAllowContentAccess(true);
|
||||
this.webView.getSettings().setAllowFileAccessFromFileURLs(false);
|
||||
this.webView.getSettings().setAllowUniversalAccessFromFileURLs(false);
|
||||
this.webView.getSettings().setDatabaseEnabled(true);
|
||||
this.webView.getSettings().setDomStorageEnabled(true);
|
||||
this.webView.getSettings().setAppCacheEnabled(false);
|
||||
if (NetWorkUtil.b(getActivity())) {
|
||||
this.webView.getSettings().setCacheMode(2);
|
||||
} else {
|
||||
this.webView.getSettings().setCacheMode(-1);
|
||||
}
|
||||
this.webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
|
||||
this.webView.setScrollContainer(false);
|
||||
this.webView.setWebViewClient(new MyWebViewClient());
|
||||
this.webView.setWebChromeClient(new MyWebChromeClient());
|
||||
this.webView.loadUrl(this.url);
|
||||
}
|
||||
|
||||
public static HelpFragmentCompact newInstance(String str, String str2, int i) {
|
||||
HelpFragmentCompact helpFragmentCompact = new HelpFragmentCompact();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("url", str);
|
||||
bundle.putString("title", str2);
|
||||
bundle.putInt(ACTIONBAR_BG_COLOR, i);
|
||||
helpFragmentCompact.setArguments(bundle);
|
||||
return helpFragmentCompact;
|
||||
}
|
||||
|
||||
public boolean goBack() {
|
||||
if (!this.webView.canGoBack()) {
|
||||
return false;
|
||||
}
|
||||
this.webView.goBack();
|
||||
return true;
|
||||
}
|
||||
|
||||
/* JADX WARN: Multi-variable type inference failed */
|
||||
@Override // android.app.Fragment
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
if (context instanceof OnHelpFragmentInteractionListener) {
|
||||
this.mListener = (OnHelpFragmentInteractionListener) context;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.widgets.NavigationBarView.OnActionClickListener
|
||||
public void onClick(View view) {
|
||||
OnHelpFragmentInteractionListener onHelpFragmentInteractionListener = this.mListener;
|
||||
if (onHelpFragmentInteractionListener != null) {
|
||||
onHelpFragmentInteractionListener.onHelpPageBack();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.app.Fragment
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
if (getArguments() != null) {
|
||||
this.url = getArguments().getString("url");
|
||||
this.title = getArguments().getString("title");
|
||||
this.actionbarBackgroundColorResId = getArguments().getInt(ACTIONBAR_BG_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.app.Fragment
|
||||
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
|
||||
View inflate = layoutInflater.inflate(R.layout.fragment_help, viewGroup, false);
|
||||
ButterKnife.a(this, inflate);
|
||||
initWebView();
|
||||
if (TextUtils.isEmpty(this.title)) {
|
||||
this.navigationBarView.setTitle(this.url);
|
||||
} else {
|
||||
this.navigationBarView.setTitle(this.title);
|
||||
}
|
||||
this.navigationBarView.setListener(this);
|
||||
return inflate;
|
||||
}
|
||||
|
||||
@Override // android.app.Fragment
|
||||
public void onDestroy() {
|
||||
this.webView.stopLoading();
|
||||
this.webView.clearHistory();
|
||||
this.webView.removeAllViews();
|
||||
this.webView.destroy();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override // android.app.Fragment
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
this.mListener = null;
|
||||
}
|
||||
|
||||
public void setListener(OnHelpFragmentInteractionListener onHelpFragmentInteractionListener) {
|
||||
this.mListener = onHelpFragmentInteractionListener;
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package com.ubt.jimu.blockly.view;
|
||||
|
||||
import android.view.View;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.ProgressBar;
|
||||
import butterknife.Unbinder;
|
||||
import butterknife.internal.Utils;
|
||||
import com.ubt.jimu.R;
|
||||
import com.ubt.jimu.widgets.NavigationBarView;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class HelpFragmentCompact_ViewBinding implements Unbinder {
|
||||
private HelpFragmentCompact target;
|
||||
|
||||
public HelpFragmentCompact_ViewBinding(HelpFragmentCompact helpFragmentCompact, View view) {
|
||||
this.target = helpFragmentCompact;
|
||||
helpFragmentCompact.navigationBarView = (NavigationBarView) Utils.b(view, R.id.nbv_bar, "field 'navigationBarView'", NavigationBarView.class);
|
||||
helpFragmentCompact.pgLoading = (ProgressBar) Utils.b(view, R.id.pgLoading, "field 'pgLoading'", ProgressBar.class);
|
||||
helpFragmentCompact.webView = (WebView) Utils.b(view, R.id.webView, "field 'webView'", WebView.class);
|
||||
}
|
||||
|
||||
@Override // butterknife.Unbinder
|
||||
public void unbind() {
|
||||
HelpFragmentCompact helpFragmentCompact = this.target;
|
||||
if (helpFragmentCompact == null) {
|
||||
throw new IllegalStateException("Bindings already cleared.");
|
||||
}
|
||||
this.target = null;
|
||||
helpFragmentCompact.navigationBarView = null;
|
||||
helpFragmentCompact.pgLoading = null;
|
||||
helpFragmentCompact.webView = null;
|
||||
}
|
||||
}
|
13
sources/com/ubt/jimu/blockly/view/JimuWebChromeClient.java
Normal file
13
sources/com/ubt/jimu/blockly/view/JimuWebChromeClient.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.ubt.jimu.blockly.view;
|
||||
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebView;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class JimuWebChromeClient extends WebChromeClient {
|
||||
private String tag = JimuWebChromeClient.class.getSimpleName();
|
||||
|
||||
@Override // android.webkit.WebChromeClient
|
||||
public void onProgressChanged(WebView webView, int i) {
|
||||
}
|
||||
}
|
126
sources/com/ubt/jimu/blockly/view/JimuWebViewClient.java
Normal file
126
sources/com/ubt/jimu/blockly/view/JimuWebViewClient.java
Normal file
@@ -0,0 +1,126 @@
|
||||
package com.ubt.jimu.blockly.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.http.SslError;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.webkit.ClientCertRequest;
|
||||
import android.webkit.HttpAuthHandler;
|
||||
import android.webkit.SslErrorHandler;
|
||||
import android.webkit.WebResourceError;
|
||||
import android.webkit.WebResourceRequest;
|
||||
import android.webkit.WebResourceResponse;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import com.ubt.jimu.blockly.JimuRobot;
|
||||
import com.ubt.jimu.blockly.command.BlocklyCommandController;
|
||||
import com.ubt.jimu.blockly.command.JimuBlocklyCommand;
|
||||
import com.ubtech.utils.FileHelper;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class JimuWebViewClient extends WebViewClient {
|
||||
private BlocklyCommandController command;
|
||||
private Context context;
|
||||
private DialogBlocklyWebView dialog;
|
||||
private String tag = JimuWebViewClient.class.getSimpleName();
|
||||
private boolean init = true;
|
||||
|
||||
public JimuWebViewClient(Context context, JimuBlocklyCommand jimuBlocklyCommand) {
|
||||
this.context = context;
|
||||
this.command = new BlocklyCommandController(jimuBlocklyCommand);
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebViewClient
|
||||
public void doUpdateVisitedHistory(WebView webView, String str, boolean z) {
|
||||
super.doUpdateVisitedHistory(webView, str, z);
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebViewClient
|
||||
public void onFormResubmission(WebView webView, Message message, Message message2) {
|
||||
super.onFormResubmission(webView, message, message2);
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebViewClient
|
||||
public void onLoadResource(WebView webView, String str) {
|
||||
super.onLoadResource(webView, str);
|
||||
Log.i(this.tag, "onLoadResource:" + str);
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebViewClient
|
||||
public void onPageCommitVisible(WebView webView, String str) {
|
||||
super.onPageCommitVisible(webView, str);
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebViewClient
|
||||
public void onPageFinished(WebView webView, String str) {
|
||||
super.onPageFinished(webView, str);
|
||||
if (this.init) {
|
||||
this.init = false;
|
||||
this.dialog.hideWait();
|
||||
JimuRobot jimuRobot = this.command.getJsInterface().getJimuRobot();
|
||||
if ("0".equals(jimuRobot.getModelType())) {
|
||||
FileHelper.a(jimuRobot.getSamplePath() + "loadFlags.file", "1", "");
|
||||
}
|
||||
}
|
||||
Log.i(this.tag, "onPageFinished load url:" + str);
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebViewClient
|
||||
public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
|
||||
super.onPageStarted(webView, str, bitmap);
|
||||
Log.i(this.tag, "onPageStarted: " + str);
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebViewClient
|
||||
public void onReceivedClientCertRequest(WebView webView, ClientCertRequest clientCertRequest) {
|
||||
super.onReceivedClientCertRequest(webView, clientCertRequest);
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebViewClient
|
||||
public void onReceivedError(WebView webView, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
|
||||
super.onReceivedError(webView, webResourceRequest, webResourceError);
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebViewClient
|
||||
public void onReceivedHttpAuthRequest(WebView webView, HttpAuthHandler httpAuthHandler, String str, String str2) {
|
||||
super.onReceivedHttpAuthRequest(webView, httpAuthHandler, str, str2);
|
||||
Log.i(this.tag, "error:onReceivedHttpAuthRequest");
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebViewClient
|
||||
public void onReceivedHttpError(WebView webView, WebResourceRequest webResourceRequest, WebResourceResponse webResourceResponse) {
|
||||
super.onReceivedHttpError(webView, webResourceRequest, webResourceResponse);
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebViewClient
|
||||
public void onReceivedLoginRequest(WebView webView, String str, String str2, String str3) {
|
||||
super.onReceivedLoginRequest(webView, str, str2, str3);
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebViewClient
|
||||
public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
|
||||
super.onReceivedSslError(webView, sslErrorHandler, sslError);
|
||||
Log.i(this.tag, "error:onReceivedSslError");
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebViewClient
|
||||
public void onScaleChanged(WebView webView, float f, float f2) {
|
||||
super.onScaleChanged(webView, f, f2);
|
||||
}
|
||||
|
||||
public void setDialog(DialogBlocklyWebView dialogBlocklyWebView) {
|
||||
this.dialog = dialogBlocklyWebView;
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebViewClient
|
||||
public WebResourceResponse shouldInterceptRequest(WebView webView, WebResourceRequest webResourceRequest) {
|
||||
return super.shouldInterceptRequest(webView, webResourceRequest);
|
||||
}
|
||||
|
||||
@Override // android.webkit.WebViewClient
|
||||
public boolean shouldOverrideUrlLoading(WebView webView, String str) {
|
||||
Log.i(this.tag, str);
|
||||
return this.command.onBlocklyCommand(webView, str);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user