fixed androidstduio derp
fixed stripes aren't loaded correctly
This commit is contained in:
@@ -291,6 +291,7 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
|
|||||||
Snackbar.make(findViewById(android.R.id.content), "LED stripes reloaded", Snackbar.LENGTH_LONG).show();
|
Snackbar.make(findViewById(android.R.id.content), "LED stripes reloaded", Snackbar.LENGTH_LONG).show();
|
||||||
|
|
||||||
for (LedStripe stripe : ledStripes) {
|
for (LedStripe stripe : ledStripes) {
|
||||||
|
System.out.println("now on stripe " + stripe.getName());
|
||||||
MenuItem sItem = nDaemonMenu.add(stripeGroup, View.generateViewId(), stripe.getId(), stripe.getName());
|
MenuItem sItem = nDaemonMenu.add(stripeGroup, View.generateViewId(), stripe.getId(), stripe.getName());
|
||||||
sItem.setIcon(R.drawable.ic_wb_iridescent_black_48dp);
|
sItem.setIcon(R.drawable.ic_wb_iridescent_black_48dp);
|
||||||
}
|
}
|
||||||
|
@@ -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);
|
||||||
|
@@ -144,6 +144,7 @@ public class LedDHelper {
|
|||||||
@Override
|
@Override
|
||||||
public void onResponse(JSONObject response) {
|
public void onResponse(JSONObject response) {
|
||||||
try {
|
try {
|
||||||
|
System.out.println("got resp: " + response.toString());
|
||||||
if (response.getBoolean("success")) {
|
if (response.getBoolean("success")) {
|
||||||
ledDDaemon.getControllers().clear();
|
ledDDaemon.getControllers().clear();
|
||||||
List<LedStripe> list = new ArrayList<>();
|
List<LedStripe> list = new ArrayList<>();
|
||||||
@@ -160,7 +161,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