From 271a70bc4b05dad75251f81ea4cca31bd4da4118 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Thu, 14 Jul 2022 23:15:51 +0800 Subject: [PATCH] Allow simulator input ip address --- .../pub/doric/devkit/ui/DoricDevActivity.java | 52 +++++++++---------- .../Devkit/Classes/DoricDevViewController.m | 52 ++++++++----------- 2 files changed, 47 insertions(+), 57 deletions(-) diff --git a/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevActivity.java b/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevActivity.java index cd5f2ead..7191194b 100644 --- a/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevActivity.java +++ b/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevActivity.java @@ -171,35 +171,31 @@ public class DoricDevActivity extends AppCompatActivity implements DoricDev.Stat 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"); - String ip = DoricDev.getInstance().getIP(); - if (!TextUtils.isEmpty(ip)) { - editText.setText(ip); - editText.setSelection(ip.length()); - } - 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(); + 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"); + String ip = DoricDev.getInstance().getIP(); + if (!TextUtils.isEmpty(ip)) { + editText.setText(ip); + editText.setSelection(ip.length()); } + 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() { diff --git a/doric-iOS/Devkit/Classes/DoricDevViewController.m b/doric-iOS/Devkit/Classes/DoricDevViewController.m index ec1f9531..1f06a76f 100644 --- a/doric-iOS/Devkit/Classes/DoricDevViewController.m +++ b/doric-iOS/Devkit/Classes/DoricDevViewController.m @@ -302,38 +302,32 @@ - (void)disconnect { } - (void)input { - if (self.isSimulator) { - NSString *result = @"127.0.0.1"; - [[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]]; - ShowToast([NSString stringWithFormat:@"Connecting to %@", result], DoricGravityBottom); - } else { - UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Please input devkit ip" - message:@"" - preferredStyle:UIAlertControllerStyleAlert]; - [alert addTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField) { - textField.placeholder = @"192.168.1.1"; - if (DoricDev.instance.ip) { - textField.text = DoricDev.instance.ip; - } - }]; - __weak typeof(alert) _alert = alert; + UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Please input devkit ip" + message:@"" + preferredStyle:UIAlertControllerStyleAlert]; + [alert addTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField) { + textField.placeholder = @"192.168.1.1"; + if (DoricDev.instance.ip) { + textField.text = DoricDev.instance.ip; + } + }]; + __weak typeof(alert) _alert = alert; - UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) - style:UIAlertActionStyleDefault - handler:nil]; - [alert addAction:cancelAction]; - - UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Ok", nil) + UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleDefault - handler:^(UIAlertAction *action) { - __strong typeof(_alert) alert = _alert; - NSString *ip = alert.textFields.lastObject.text; - [[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", ip]]; - }]; - [alert addAction:okAction]; + handler:nil]; + [alert addAction:cancelAction]; - [self presentViewController:alert animated:YES completion:nil]; - } + UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Ok", nil) + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *action) { + __strong typeof(_alert) alert = _alert; + NSString *ip = alert.textFields.lastObject.text; + [[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", ip]]; + }]; + [alert addAction:okAction]; + + [self presentViewController:alert animated:YES completion:nil]; } - (void)scan {