Allow simulator input ip address
This commit is contained in:
parent
179a95e2de
commit
271a70bc4b
@ -171,35 +171,31 @@ public class DoricDevActivity extends AppCompatActivity implements DoricDev.Stat
|
|||||||
tvInput.setOnClickListener(new View.OnClickListener() {
|
tvInput.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View clickView) {
|
public void onClick(View clickView) {
|
||||||
if (DoricDev.getInstance().isRunningInEmulator) {
|
AlertDialog.Builder builder = new AlertDialog.Builder(DoricDevActivity.this, R.style.Theme_Doric_Modal_Prompt);
|
||||||
DoricDev.getInstance().connectDevKit("ws://" + "10.0.2.2" + ":7777");
|
builder.setTitle("Please input devkit ip");
|
||||||
} else {
|
View v = LayoutInflater.from(DoricDevActivity.this).inflate(R.layout.doric_modal_prompt, null);
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(DoricDevActivity.this, R.style.Theme_Doric_Modal_Prompt);
|
final EditText editText = v.findViewById(R.id.edit_input);
|
||||||
builder.setTitle("Please input devkit ip");
|
editText.setHint("192.168.1.1");
|
||||||
View v = LayoutInflater.from(DoricDevActivity.this).inflate(R.layout.doric_modal_prompt, null);
|
String ip = DoricDev.getInstance().getIP();
|
||||||
final EditText editText = v.findViewById(R.id.edit_input);
|
if (!TextUtils.isEmpty(ip)) {
|
||||||
editText.setHint("192.168.1.1");
|
editText.setText(ip);
|
||||||
String ip = DoricDev.getInstance().getIP();
|
editText.setSelection(ip.length());
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
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() {
|
tvDisconnect.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -302,38 +302,32 @@ - (void)disconnect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)input {
|
- (void)input {
|
||||||
if (self.isSimulator) {
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Please input devkit ip"
|
||||||
NSString *result = @"127.0.0.1";
|
message:@""
|
||||||
[[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]];
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
ShowToast([NSString stringWithFormat:@"Connecting to %@", result], DoricGravityBottom);
|
[alert addTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField) {
|
||||||
} else {
|
textField.placeholder = @"192.168.1.1";
|
||||||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Please input devkit ip"
|
if (DoricDev.instance.ip) {
|
||||||
message:@""
|
textField.text = DoricDev.instance.ip;
|
||||||
preferredStyle:UIAlertControllerStyleAlert];
|
}
|
||||||
[alert addTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField) {
|
}];
|
||||||
textField.placeholder = @"192.168.1.1";
|
__weak typeof(alert) _alert = alert;
|
||||||
if (DoricDev.instance.ip) {
|
|
||||||
textField.text = DoricDev.instance.ip;
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
__weak typeof(alert) _alert = alert;
|
|
||||||
|
|
||||||
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil)
|
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil)
|
||||||
style:UIAlertActionStyleDefault
|
|
||||||
handler:nil];
|
|
||||||
[alert addAction:cancelAction];
|
|
||||||
|
|
||||||
UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Ok", nil)
|
|
||||||
style:UIAlertActionStyleDefault
|
style:UIAlertActionStyleDefault
|
||||||
handler:^(UIAlertAction *action) {
|
handler:nil];
|
||||||
__strong typeof(_alert) alert = _alert;
|
[alert addAction:cancelAction];
|
||||||
NSString *ip = alert.textFields.lastObject.text;
|
|
||||||
[[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", ip]];
|
|
||||||
}];
|
|
||||||
[alert addAction:okAction];
|
|
||||||
|
|
||||||
[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 {
|
- (void)scan {
|
||||||
|
Reference in New Issue
Block a user