Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
608a9c48d1 | ||
![]() |
1e7e400d49 |
@@ -40,8 +40,8 @@ android {
|
|||||||
applicationId "com.idlegandalf.ledd"
|
applicationId "com.idlegandalf.ledd"
|
||||||
minSdkVersion 17
|
minSdkVersion 17
|
||||||
targetSdkVersion 23
|
targetSdkVersion 23
|
||||||
versionCode 1
|
versionCode 2
|
||||||
versionName "1.0"
|
versionName "1.0.1"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
@@ -227,153 +227,6 @@ public class AddControllerDialog extends DialogFragment implements DialogInterfa
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onShow(final DialogInterface dialog) {
|
|
||||||
|
|
||||||
final AlertDialog alertDialog = (AlertDialog) dialog;
|
|
||||||
|
|
||||||
addressText.addTextChangedListener(new TextWatcher() {
|
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
addressLayout.setError(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
channelText.addTextChangedListener(new TextWatcher() {
|
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
channelLayout.setError(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
i2cText.addTextChangedListener(new TextWatcher() {
|
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
i2cLayout.setError(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
AddStripeDialog.instance.onResume();
|
|
||||||
alertDialog.dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (i2cText.getText().toString().isEmpty() || !isNumeric(i2cText.getText().toString())) {
|
|
||||||
i2cLayout.setError("No valid i2c device number");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!addressText.getText().toString().contains("0x") || !addressText.getText().toString().split("x")[1].matches("-?[0-9a-fA-F]+")) {
|
|
||||||
addressLayout.setError("No valid hexdecimal address");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (channelText.getText().toString().isEmpty() || !isNumeric(channelText.getText().toString()) && Integer.parseInt(channelText
|
|
||||||
.getText().toString()) <= 0) {
|
|
||||||
channelLayout.setError("No valid channel amount");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Controller c = new Controller();
|
|
||||||
c.setAddress(addressText.getText().toString());
|
|
||||||
c.setI2c_device(Integer.parseInt(i2cText.getText().toString()));
|
|
||||||
c.setChannels(Integer.parseInt(channelText.getText().toString()));
|
|
||||||
|
|
||||||
LedDHelper helper = null;
|
|
||||||
try {
|
|
||||||
helper = ColorApplication.getInstance().getHelperForDaemon(dDaemon);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (helper != null) {
|
|
||||||
try {
|
|
||||||
helper.addController(c, new AddControllerCallback() {
|
|
||||||
@Override
|
|
||||||
public void onControllerAdded(final Controller controller) {
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Snackbar.make(((ViewGroup) getActivity().getWindow().getDecorView().findViewById(android.R.id.content))
|
|
||||||
.getChildAt(0), "Added Controller (" + controller.getId() + ")", Snackbar.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
dDaemon.getControllers().add(controller);
|
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAddFailed(final String msg, String detail) {
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Snackbar.make(((ViewGroup) getActivity().getWindow().getDecorView().findViewById(android.R.id.content))
|
|
||||||
.getChildAt(0), "Error: " + msg, Snackbar.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
AddStripeDialog.instance.onResume();
|
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConnectionFailed(final String message) {
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Snackbar.make(((ViewGroup) getActivity().getWindow().getDecorView().findViewById(android.R.id.content))
|
|
||||||
.getChildAt(0), "Coudn't connect to" +
|
|
||||||
" daemon at " + dDaemon + ": " + message, Snackbar.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
AddStripeDialog.instance.onResume();
|
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (JSONException | IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isNumeric(String str) {
|
private static boolean isNumeric(String str) {
|
||||||
NumberFormat formatter = NumberFormat.getInstance();
|
NumberFormat formatter = NumberFormat.getInstance();
|
||||||
ParsePosition pos = new ParsePosition(0);
|
ParsePosition pos = new ParsePosition(0);
|
||||||
|
@@ -160,7 +160,7 @@ public class LedDHelper {
|
|||||||
JSONArray jstripes = row.getJSONArray("stripes");
|
JSONArray jstripes = row.getJSONArray("stripes");
|
||||||
|
|
||||||
for (int o = 0; o < jstripes.length(); o++) {
|
for (int o = 0; o < jstripes.length(); o++) {
|
||||||
JSONObject srow = jstripes.getJSONObject(i);
|
JSONObject srow = jstripes.getJSONObject(o);
|
||||||
LedStripe nStripe = new LedStripe();
|
LedStripe nStripe = new LedStripe();
|
||||||
nStripe.setId(srow.getInt("id"));
|
nStripe.setId(srow.getInt("id"));
|
||||||
nStripe.setRGB(srow.getBoolean("rgb"));
|
nStripe.setRGB(srow.getBoolean("rgb"));
|
||||||
|
Reference in New Issue
Block a user