fixed androidstduio derp

fixed stripes aren't loaded correctly
This commit is contained in:
Giovanni Harting
2015-09-13 17:18:18 +02:00
parent 3f66b67e4c
commit 1e7e400d49
3 changed files with 3 additions and 148 deletions

View File

@@ -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();
for (LedStripe stripe : ledStripes) {
System.out.println("now on stripe " + stripe.getName());
MenuItem sItem = nDaemonMenu.add(stripeGroup, View.generateViewId(), stripe.getId(), stripe.getName());
sItem.setIcon(R.drawable.ic_wb_iridescent_black_48dp);
}

View File

@@ -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) {
NumberFormat formatter = NumberFormat.getInstance();
ParsePosition pos = new ParsePosition(0);

View File

@@ -144,6 +144,7 @@ public class LedDHelper {
@Override
public void onResponse(JSONObject response) {
try {
System.out.println("got resp: " + response.toString());
if (response.getBoolean("success")) {
ledDDaemon.getControllers().clear();
List<LedStripe> list = new ArrayList<>();
@@ -160,7 +161,7 @@ public class LedDHelper {
JSONArray jstripes = row.getJSONArray("stripes");
for (int o = 0; o < jstripes.length(); o++) {
JSONObject srow = jstripes.getJSONObject(i);
JSONObject srow = jstripes.getJSONObject(o);
LedStripe nStripe = new LedStripe();
nStripe.setId(srow.getInt("id"));
nStripe.setRGB(srow.getBoolean("rgb"));