android:Optimize DoricDev header UI

This commit is contained in:
pengfeizhou 2021-02-24 11:05:41 +08:00 committed by osborn
parent cc6355aea7
commit 37222a25d8
10 changed files with 301 additions and 157 deletions

View File

@ -31,13 +31,11 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation "com.google.android.material:material:1.1.0"
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
api 'org.greenrobot:eventbus:3.2.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.zxing:core:3.4.0'
implementation 'com.google.zxing:android-core:3.3.0'
}
apply from: rootProject.file('scripts/upload.gradle')

View File

@ -1,29 +1,41 @@
package pub.doric.devkit;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;
import com.github.pengfeizhou.jscore.JSONBuilder;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONObject;
import java.io.EOFException;
import java.net.ConnectException;
import java.util.HashSet;
import java.util.Set;
import pub.doric.Doric;
import pub.doric.DoricContext;
import pub.doric.DoricContextManager;
import pub.doric.DoricNativeDriver;
import pub.doric.devkit.event.ConnectExceptionEvent;
import pub.doric.devkit.event.EOFExceptionEvent;
import pub.doric.devkit.event.OpenEvent;
import pub.doric.devkit.event.StopDebugEvent;
import pub.doric.devkit.ui.DoricDevActivity;
import pub.doric.devkit.util.SimulatorUtil;
import pub.doric.utils.DoricLog;
public class DoricDev {
public interface StatusCallback {
void onOpen(String url);
void onClose(String url);
void onFailure(Throwable throwable);
}
private final Set<StatusCallback> callbacks = new HashSet<>();
public final boolean isRunningInEmulator;
private final Handler uiHandler = new Handler(Looper.getMainLooper());
private static class Inner {
private static final DoricDev sInstance = new DoricDev();
@ -32,7 +44,6 @@ public class DoricDev {
private DoricDev() {
this.isRunningInEmulator = SimulatorUtil.isSimulator(Doric.application());
DoricNativeDriver.getInstance().getRegistry().registerMonitor(new DoricDevMonitor());
EventBus.getDefault().register(this);
}
public static DoricDev getInstance() {
@ -46,7 +57,10 @@ public class DoricDev {
}
public void closeDevMode() {
disconnectDevKit();
if (wsClient != null) {
wsClient.close();
wsClient = null;
}
}
public boolean isInDevMode() {
@ -59,20 +73,38 @@ public class DoricDev {
private boolean devKitConnected = false;
private DoricContextDebuggable debuggable;
private String url;
public void addStatusListener(StatusCallback listener) {
this.callbacks.add(listener);
}
public void removeStatusListener(StatusCallback listener) {
this.callbacks.remove(listener);
}
public void connectDevKit(String url) {
if (wsClient != null) {
wsClient.close();
}
devKitConnected = false;
wsClient = new WSClient(url);
this.url = url;
}
public String getIP() {
if (wsClient != null) {
return url.replace("ws://", "").replace(":7777", "");
} else {
return "0.0.0.0";
}
}
public void sendDevCommand(String command, JSONObject jsonObject) {
wsClient.sendToServer(command, jsonObject);
}
public void disconnectDevKit() {
wsClient.close();
wsClient = null;
}
public void startDebugging(String source) {
if (debuggable != null) {
debuggable.stopDebug(true);
@ -105,27 +137,48 @@ public class DoricDev {
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onOpenEvent(OpenEvent openEvent) {
public void onOpen() {
devKitConnected = true;
Toast.makeText(Doric.application(), "dev kit connected", Toast.LENGTH_LONG).show();
uiHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(Doric.application(), "dev kit connected", Toast.LENGTH_LONG).show();
for (StatusCallback callback : callbacks) {
callback.onOpen(url);
}
}
});
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEOFEvent(EOFExceptionEvent eofExceptionEvent) {
public void onClose() {
devKitConnected = false;
Toast.makeText(Doric.application(), "dev kit eof exception", Toast.LENGTH_LONG).show();
uiHandler.post(new Runnable() {
@Override
public void run() {
for (StatusCallback callback : callbacks) {
callback.onClose(url);
}
}
});
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onConnectExceptionEvent(ConnectExceptionEvent connectExceptionEvent) {
public void onFailure(final Throwable t) {
devKitConnected = false;
Toast.makeText(Doric.application(), "dev kit connection exception", Toast.LENGTH_LONG).show();
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onQuitDebugEvent(StopDebugEvent quitDebugEvent) {
stopDebugging(true);
uiHandler.post(new Runnable() {
@Override
public void run() {
if (t instanceof EOFException) {
Toast.makeText(Doric.application(), "Devkit lost connection", Toast.LENGTH_LONG).show();
} else if (t instanceof ConnectException) {
Toast.makeText(Doric.application(), "Devkit connect to " + getIP() + " failed", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(Doric.application(), "Devkit connect fail:" + t.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
for (StatusCallback callback : callbacks) {
callback.onFailure(t);
}
}
});
}
public DoricContext matchContext(String source) {

View File

@ -17,12 +17,9 @@ package pub.doric.devkit;
import com.github.pengfeizhou.jscore.JSONBuilder;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.EOFException;
import java.net.ConnectException;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@ -32,9 +29,6 @@ import okhttp3.Request;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import pub.doric.devkit.event.ConnectExceptionEvent;
import pub.doric.devkit.event.EOFExceptionEvent;
import pub.doric.devkit.event.OpenEvent;
/**
* @Description: com.github.penfeizhou.doric.dev
@ -76,8 +70,7 @@ public class WSClient extends WebSocketListener {
@Override
public void onOpen(WebSocket webSocket, Response response) {
super.onOpen(webSocket, response);
EventBus.getDefault().post(new OpenEvent());
DoricDev.getInstance().onOpen();
}
@Override
@ -117,18 +110,13 @@ public class WSClient extends WebSocketListener {
@Override
public void onClosed(WebSocket webSocket, int code, String reason) {
super.onClosed(webSocket, code, reason);
EventBus.getDefault().post(new ConnectExceptionEvent());
DoricDev.getInstance().onClose();
}
@Override
public void onFailure(WebSocket webSocket, Throwable t, Response response) {
super.onFailure(webSocket, t, response);
if (t instanceof EOFException) {
EventBus.getDefault().post(new EOFExceptionEvent());
} else if (t instanceof ConnectException) {
EventBus.getDefault().post(new ConnectExceptionEvent());
}
DoricDev.getInstance().onFailure(t);
}
public void sendToDebugger(String command, JSONObject payload) {

View File

@ -1,4 +0,0 @@
package pub.doric.devkit.event;
public class ConnectExceptionEvent {
}

View File

@ -1,4 +0,0 @@
package pub.doric.devkit.event;
public class EOFExceptionEvent {
}

View File

@ -1,4 +0,0 @@
package pub.doric.devkit.event;
public class OpenEvent {
}

View File

@ -1,5 +0,0 @@
package pub.doric.devkit.event;
public class StopDebugEvent {
}

View File

@ -1,12 +1,19 @@
package pub.doric.devkit.ui;
import android.Manifest;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
@ -17,55 +24,38 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.github.pengfeizhou.jscore.JSONBuilder;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import pub.doric.DoricContext;
import pub.doric.DoricContextManager;
import pub.doric.devkit.DoricDev;
import pub.doric.devkit.R;
import pub.doric.devkit.event.ConnectExceptionEvent;
import pub.doric.devkit.event.EOFExceptionEvent;
import pub.doric.devkit.event.OpenEvent;
import pub.doric.devkit.qrcode.DisplayUtil;
import pub.doric.devkit.qrcode.activity.CaptureActivity;
import pub.doric.devkit.qrcode.activity.CodeUtils;
public class DoricDevActivity extends AppCompatActivity {
public class DoricDevActivity extends AppCompatActivity implements DoricDev.StatusCallback {
private int REQUEST_CODE = 100;
private String debug_off = "iVBORw0KGgoAAAANSUh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A/D+F2An2zQK7I0gO6abs7822VQ+jaUgb0tzcHJgI6B3ieKTPgW9Ui8ieECidEfV30O+Up/9/j8FOQWxxtTAtejoNgDX9Qu1Wtfrzs5CtHP/VbMvVqvu1amWgqzA2V9RKEYWxShIFkrdl6p4c0fRnZ0o2rl/C+8YWaKnIFkoHXfN0MTANQq9BsA1EFTjpd6C3aq6S6PolxSjv8ApSH+83nK147LsVuguWZDfJFeluw3aDHooBbEU/zFZRLcCcrGlafuZ5n8AXlDok5HIrumRdE8/g3ntyQlQkAJ2RmOqvh4duQLApQpcKoJLrf+mXvGaiu6JJHpBgT2yUNs9vfXI4QLaCXpKCrIa8SuiCybjK0RxhQjeq6pnRZGsVZW1gJ4FwVp0sPgven8oYEaBGQAzIjqjkBlAZ0RlpgNpayfavX/r0T+tRumhr0FBQt8B7H9ZAhSEG4QEliFAQbg9SICCcA+QQD4CvIPk48ZRgRCgIIEEzTbzEaAg+bhxVCAEKEggQbPNfAQoSD5uHBUIAQoSSNBsMx+B/wNQA1oj5tl0JAAAAABJRU5ErkJggg==";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EventBus.getDefault().register(this);
DisplayUtil.initDisplayOpinion(getApplicationContext());
setContentView(R.layout.layout_debug_context);
initDisconnect();
if (DoricDev.getInstance().isInDevMode()) {
initViews();
} else {
if (DoricDev.getInstance().isRunningInEmulator) {
DoricDev.getInstance().connectDevKit("ws://" + "10.0.2.2" + ":7777");
} else {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.CAMERA)) {
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.CAMERA,}, 1);
}
} else {
Intent intent = new Intent(DoricDevActivity.this, CaptureActivity.class);
startActivityForResult(intent, REQUEST_CODE);
}
}
}
initViews();
}
@Override
protected void onStart() {
super.onStart();
DoricDev.getInstance().addStatusListener(this);
}
@Override
protected void onStop() {
super.onStop();
DoricDev.getInstance().removeStatusListener(this);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
@ -90,53 +80,98 @@ public class DoricDevActivity extends AppCompatActivity {
}
if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS) {
String result = bundle.getString(CodeUtils.RESULT_STRING);
Toast.makeText(this, "dev kit connecting to " + result, Toast.LENGTH_LONG).show();
DoricDev.getInstance().connectDevKit("ws://" + result + ":7777");
}
}
}
@Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onOpenEvent(OpenEvent openEvent) {
initViews();
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEOFEvent(EOFExceptionEvent eofExceptionEvent) {
finish();
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onConnectExceptionEvent(ConnectExceptionEvent connectExceptionEvent) {
finish();
}
private void initDisconnect() {
LinearLayout container = findViewById(R.id.container);
Button button = new Button(this);
button.setText("断开连接");
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (DoricDev.getInstance().isInDevMode()) {
DoricDev.getInstance().closeDevMode();
}
finish();
}
});
container.addView(button);
private Bitmap getIcon(String str) {
byte[] data = Base64.decode(str, Base64.DEFAULT);
return BitmapFactory.decodeByteArray(data, 0, data.length);
}
private void initViews() {
TextView tvConnection = findViewById(R.id.tv_connect_info);
TextView tvInput = findViewById(R.id.tv_input);
TextView tvScan = findViewById(R.id.tv_scan);
TextView tvDisconnect = findViewById(R.id.tv_disconnect);
if (DoricDev.getInstance().isInDevMode()) {
tvConnection.setText(DoricDev.getInstance().getIP());
tvInput.setVisibility(View.GONE);
tvScan.setVisibility(View.GONE);
tvDisconnect.setVisibility(View.VISIBLE);
tvConnection.setBackgroundColor(Color.parseColor("#2ed573"));
} else {
tvConnection.setText("Disconnected");
tvDisconnect.setVisibility(View.GONE);
tvInput.setVisibility(View.VISIBLE);
tvScan.setVisibility(View.VISIBLE);
tvConnection.setBackgroundColor(Color.parseColor("#a4b0be"));
}
tvScan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (DoricDev.getInstance().isRunningInEmulator) {
DoricDev.getInstance().connectDevKit("ws://" + "10.0.2.2" + ":7777");
} else {
if (ContextCompat.checkSelfPermission(DoricDevActivity.this, Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(DoricDevActivity.this,
Manifest.permission.CAMERA)) {
} else {
ActivityCompat.requestPermissions(DoricDevActivity.this,
new String[]{Manifest.permission.CAMERA,}, 1);
}
} else {
Intent intent = new Intent(DoricDevActivity.this, CaptureActivity.class);
startActivityForResult(intent, REQUEST_CODE);
}
}
}
});
tvInput.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View clickView) {
if (DoricDev.getInstance().isRunningInEmulator) {
DoricDev.getInstance().connectDevKit("ws://" + "10.0.2.2" + ":7777");
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(DoricDevActivity.this, R.style.Theme_Doric_Modal_Prompt);
builder.setTitle("Please input devkit ip");
View v = LayoutInflater.from(DoricDevActivity.this).inflate(R.layout.doric_modal_prompt, null);
final EditText editText = v.findViewById(R.id.edit_input);
editText.setHint("192.168.1.1");
builder.setView(v);
builder
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String ip = editText.getText().toString();
DoricDev.getInstance().connectDevKit("ws://" + ip + ":7777");
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.show();
}
}
});
tvDisconnect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DoricDev.getInstance().closeDevMode();
}
});
LinearLayout container = findViewById(R.id.container);
LayoutInflater inflater = LayoutInflater.from(this);
Bitmap icon_off = getIcon(debug_off);
Bitmap icon_on = getIcon(debug_on);
container.removeAllViews();
for (final DoricContext doricContext : DoricContextManager.aliveContexts()) {
View cell = inflater.inflate(R.layout.layout_debug_context_cell, container, false);
@ -145,19 +180,24 @@ public class DoricDevActivity extends AppCompatActivity {
TextView sourceTextView = cell.findViewById(R.id.source_text_view);
sourceTextView.setText(doricContext.getSource());
cell.findViewById(R.id.debug_text_view).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DoricDev.getInstance().sendDevCommand(
"DEBUG",
new JSONBuilder()
.put("source", doricContext.getSource())
.toJSONObject());
}
});
ImageView imageView = cell.findViewById(R.id.icon_debug);
imageView.setImageBitmap(icon_on);
container.addView(cell);
}
}
@Override
public void onOpen(String url) {
initViews();
}
@Override
public void onClose(String url) {
initViews();
}
@Override
public void onFailure(Throwable throwable) {
initViews();
}
}

View File

@ -4,10 +4,99 @@
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#70a1ff"
android:orientation="horizontal"
android:paddingLeft="15dp"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:paddingBottom="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Devkit"
android:textColor="#ced6e0"
android:textSize="30dp" />
<TextView
android:id="@+id/tv_connect_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
android:background="#a4b0be"
android:paddingLeft="10dp"
android:paddingTop="3dp"
android:paddingRight="10dp"
android:paddingBottom="3dp"
android:text="Disconnected"
android:textColor="#dfe4ea"
android:textSize="12dp" />
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/tv_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
android:background="#1e90ff"
android:paddingLeft="15dp"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:paddingBottom="5dp"
android:text="Input"
android:textColor="#dfe4ea"
android:textSize="15dp" />
<TextView
android:id="@+id/tv_scan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:background="#1e90ff"
android:paddingLeft="15dp"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:paddingBottom="5dp"
android:text="Scan"
android:textColor="#dfe4ea"
android:textSize="15dp" />
<TextView
android:id="@+id/tv_disconnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:background="#1e90ff"
android:paddingLeft="15dp"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:paddingBottom="5dp"
android:text="Disconnect"
android:textColor="#dfe4ea"
android:textSize="15dp"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
</ScrollView>

View File

@ -6,9 +6,8 @@
<TextView
android:id="@+id/context_id_text_view"
android:layout_width="0dp"
android:layout_width="50dp"
android:layout_height="60dp"
android:layout_weight="1"
android:gravity="center"
android:singleLine="true"
android:text="{Context Id}"
@ -18,21 +17,15 @@
android:id="@+id/source_text_view"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="3"
android:layout_weight="1"
android:gravity="center"
android:singleLine="true"
android:text="{Source}"
android:textSize="20sp" />
<TextView
android:id="@+id/debug_text_view"
android:layout_width="0dp"
<ImageView
android:id="@+id/icon_debug"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_weight="1"
android:background="#ff0000"
android:gravity="center"
android:singleLine="true"
android:text="Debug"
android:textColor="#ffffff"
android:textSize="20sp" />
android:background="#ff0000" />
</LinearLayout>