general post-release cleanup
removed lots of unused strings/resources/drawables extracted all translatable strings added new logo
@@ -29,7 +29,7 @@
|
||||
android:name=".ColorApplication"
|
||||
android:allowBackup="true"
|
||||
android:fullBackupContent="false"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
|
@@ -50,9 +50,6 @@ import com.idlegandalf.ledd.helper.LedDHelper;
|
||||
import com.larswerkman.holocolorpicker.ColorPicker;
|
||||
import com.larswerkman.holocolorpicker.SVBar;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.Bind;
|
||||
@@ -85,8 +82,14 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
|
||||
// check for connectivity
|
||||
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
|
||||
if (networkInfo == null || !networkInfo.isConnected()) {
|
||||
// TODO: Display error (snackbar)
|
||||
if (networkInfo == null || !networkInfo.isConnected() || networkInfo.getType() != ConnectivityManager.TYPE_WIFI) {
|
||||
Snackbar.make(mDrawerLayout, "We currently only support WLAN networks, please connect to one", Snackbar.LENGTH_INDEFINITE).setAction
|
||||
("RETRY", new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
refreshStripes();
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
colorPicker.addSVBar(svBar);
|
||||
@@ -200,11 +203,7 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
|
||||
super.onResume();
|
||||
ColorApplication.getInstance().onResume();
|
||||
registerReceiver(daemonsListener, new IntentFilter(ColorApplication.INTENT_ACTION_REFRESH));
|
||||
try {
|
||||
refreshStripes();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -222,14 +221,10 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
|
||||
for (LedStripe stripe : ledStripes) {
|
||||
if (stripe.getName().equals(menuItem.getTitle())) {
|
||||
mCurrentStripe = stripe;
|
||||
try {
|
||||
mCurrentHelper = ColorApplication.getInstance().getHelperForDaemon(stripe.getLedDDaemon());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
mDrawerLayout.closeDrawer(Gravity.LEFT);
|
||||
toolbar.setTitle(stripe.getName());
|
||||
try {
|
||||
mCurrentHelper.getColor(mCurrentStripe, new RecieveColorCallback() {
|
||||
@Override
|
||||
public void onColorRecieved(LedStripe stripe) {
|
||||
@@ -238,8 +233,8 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
colorPicker.setColor(Color.HSVToColor(new float[]{(float) cColor.getHue(), (float) cColor.getSaturation(),
|
||||
(float) cColor.getValue()}));
|
||||
colorPicker.setColor(Color.HSVToColor(new float[]{(float) cColor.getHue(), (float) cColor.getSaturation(), (float)
|
||||
cColor.getValue()}));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -254,9 +249,7 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
|
||||
|
||||
}
|
||||
});
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -264,7 +257,7 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
|
||||
return false;
|
||||
}
|
||||
|
||||
public void refreshStripes() throws IOException {
|
||||
public void refreshStripes() {
|
||||
reCreateNavigationView(); // need to recreate the navigationview since we can't remove a once added submenu
|
||||
|
||||
final Menu nvMenu = navigationView.getMenu();
|
||||
@@ -276,7 +269,6 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
|
||||
LedDHelper helper = ColorApplication.getInstance().getHelperForDaemon(dDaemon);
|
||||
|
||||
if (helper != null) {
|
||||
try {
|
||||
final int finalI = i;
|
||||
helper.getStripes(new StripesCallback() {
|
||||
@Override
|
||||
@@ -300,8 +292,7 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
|
||||
|
||||
@Override
|
||||
public void onGetFailed(String message) {
|
||||
Snackbar.make(findViewById(android.R.id.content), "Coudn't get stripes from daemon: " + message, Snackbar.LENGTH_LONG)
|
||||
.show();
|
||||
Snackbar.make(findViewById(android.R.id.content), "Coudn't get stripes from daemon: " + message, Snackbar.LENGTH_LONG).show();
|
||||
|
||||
}
|
||||
|
||||
@@ -310,9 +301,7 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
|
||||
Snackbar.make(findViewById(android.R.id.content), "Coudn't connect to daemon: " + message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
i++;
|
||||
@@ -343,11 +332,7 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(ColorApplication.INTENT_ACTION_REFRESH)) {
|
||||
try {
|
||||
refreshStripes();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -29,9 +29,6 @@ import com.idlegandalf.ledd.callbacks.DiscoverCallback;
|
||||
import com.idlegandalf.ledd.components.LedDDaemon;
|
||||
import com.idlegandalf.ledd.helper.LedDHelper;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -56,12 +53,11 @@ public class ColorApplication extends Application {
|
||||
this.onResume();
|
||||
}
|
||||
|
||||
public LedDHelper getHelperForDaemon(final LedDDaemon ledDDaemon) throws IOException {
|
||||
public LedDHelper getHelperForDaemon(final LedDDaemon ledDDaemon) {
|
||||
if (ledDHelpers.containsKey(ledDDaemon) && ledDHelpers.get(ledDDaemon) != null) {
|
||||
return ledDHelpers.get(ledDDaemon);
|
||||
} else {
|
||||
final LedDHelper dHelper = new LedDHelper(ledDDaemon, getApplicationContext());
|
||||
try {
|
||||
dHelper.discover(new DiscoverCallback() {
|
||||
@Override
|
||||
public void onConnectionFailed(String message) {
|
||||
@@ -73,11 +69,6 @@ public class ColorApplication extends Application {
|
||||
ledDHelpers.put(ledDDaemon, dHelper);
|
||||
}
|
||||
});
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return dHelper;
|
||||
}
|
||||
}
|
||||
@@ -104,7 +95,6 @@ public class ColorApplication extends Application {
|
||||
}.getType());
|
||||
|
||||
for (final LedDDaemon ledDDaemon : ledDDaemons) {
|
||||
try {
|
||||
final LedDHelper helper = new LedDHelper(ledDDaemon, getApplicationContext());
|
||||
|
||||
helper.discover(new DiscoverCallback() {
|
||||
@@ -126,11 +116,6 @@ public class ColorApplication extends Application {
|
||||
sendBroadcast(i);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -19,11 +19,11 @@
|
||||
package com.idlegandalf.ledd;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.idlegandalf.ledd.fragments.SettingsFragment;
|
||||
|
||||
public class SettingsActivity extends ActionBarActivity {
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@@ -21,9 +21,6 @@ package com.idlegandalf.ledd.components;
|
||||
|
||||
import com.idlegandalf.ledd.helper.LedDHelper;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class StripeGroup {
|
||||
@@ -60,7 +57,7 @@ public class StripeGroup {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setRGB(int r, int g, int b, LedDHelper api) throws JSONException, IOException {
|
||||
public void setRGB(int r, int g, int b, LedDHelper api) {
|
||||
for (int i = 0; i < mStripes.size(); i++) {
|
||||
//mStripes.get(i).setRGB(r, g, b, api);
|
||||
}
|
||||
|
@@ -39,9 +39,6 @@ import com.idlegandalf.ledd.components.Controller;
|
||||
import com.idlegandalf.ledd.components.LedDDaemon;
|
||||
import com.idlegandalf.ledd.helper.LedDHelper;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParsePosition;
|
||||
|
||||
@@ -64,6 +61,13 @@ public class AddControllerDialog extends DialogFragment implements DialogInterfa
|
||||
EditText channelText;
|
||||
LedDDaemon dDaemon;
|
||||
|
||||
private static boolean isNumeric(String str) {
|
||||
NumberFormat formatter = NumberFormat.getInstance();
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
formatter.parse(str, pos);
|
||||
return str.length() == pos.getIndex();
|
||||
}
|
||||
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
View v = View.inflate(getActivity(), R.layout.fragment_addcontroller, null);
|
||||
ButterKnife.bind(this, v);
|
||||
@@ -168,15 +172,9 @@ public class AddControllerDialog extends DialogFragment implements DialogInterfa
|
||||
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();
|
||||
}
|
||||
LedDHelper helper = ColorApplication.getInstance().getHelperForDaemon(dDaemon);
|
||||
|
||||
if (helper != null) {
|
||||
try {
|
||||
helper.addController(c, new AddControllerCallback() {
|
||||
@Override
|
||||
public void onControllerAdded(final Controller controller) {
|
||||
@@ -219,18 +217,8 @@ public class AddControllerDialog extends DialogFragment implements DialogInterfa
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean isNumeric(String str) {
|
||||
NumberFormat formatter = NumberFormat.getInstance();
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
formatter.parse(str, pos);
|
||||
return str.length() == pos.getIndex();
|
||||
}
|
||||
}
|
||||
|
@@ -45,9 +45,6 @@ import com.idlegandalf.ledd.R;
|
||||
import com.idlegandalf.ledd.callbacks.DiscoverCallback;
|
||||
import com.idlegandalf.ledd.components.LedDDaemon;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Inet4Address;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -286,7 +283,6 @@ public class AddDaemonDialog extends DialogFragment implements DialogInterface.O
|
||||
}
|
||||
|
||||
private void addDaemon(final LedDDaemon ledDDaemon) {
|
||||
try {
|
||||
ColorApplication.getInstance().getHelperForDaemon(ledDDaemon).discover(new DiscoverCallback() {
|
||||
@Override
|
||||
public void onConnectionFailed(final String message) {
|
||||
@@ -298,7 +294,6 @@ public class AddDaemonDialog extends DialogFragment implements DialogInterface.O
|
||||
" daemon at " + ledDDaemon + ": " + message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
AddStripeDialog stripeAdd = (AddStripeDialog) getFragmentManager().findFragmentByTag("stripeAdd");
|
||||
AddStripeDialog.instance.onResume();
|
||||
dismiss();
|
||||
}
|
||||
@@ -313,17 +308,10 @@ public class AddDaemonDialog extends DialogFragment implements DialogInterface.O
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
((ColorActivity) getActivity()).refreshStripes();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
AddStripeDialog.instance.onResume();
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -50,9 +50,6 @@ import com.idlegandalf.ledd.components.LedDDaemon;
|
||||
import com.idlegandalf.ledd.components.LedStripe;
|
||||
import com.idlegandalf.ledd.helper.LedDHelper;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParsePosition;
|
||||
import java.util.List;
|
||||
@@ -259,24 +256,15 @@ public class AddStripeDialog extends DialogFragment implements DialogInterface.O
|
||||
stripe.setLedDDaemon((LedDDaemon) daemonSpinner.getSelectedItem());
|
||||
stripe.setController((Controller) controllerSpinner.getSelectedItem());
|
||||
|
||||
LedDHelper helper = null;
|
||||
try {
|
||||
helper = ColorApplication.getInstance().getHelperForDaemon((LedDDaemon) daemonSpinner.getSelectedItem());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
LedDHelper helper = ColorApplication.getInstance().getHelperForDaemon((LedDDaemon) daemonSpinner.getSelectedItem());
|
||||
|
||||
|
||||
if (helper != null) {
|
||||
try {
|
||||
helper.addStripe(stripe, new AddStripeCallback() {
|
||||
@Override
|
||||
public void onAddSuccessfully(final LedStripe stripe) {
|
||||
ColorActivity activity = ((ColorActivity) getActivity());
|
||||
try {
|
||||
activity.refreshStripes();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
@@ -300,9 +288,6 @@ public class AddStripeDialog extends DialogFragment implements DialogInterface.O
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -398,19 +383,11 @@ public class AddStripeDialog extends DialogFragment implements DialogInterface.O
|
||||
}
|
||||
text.setTag(toggle);
|
||||
|
||||
LedDHelper helper = null;
|
||||
try {
|
||||
helper = ColorApplication.getInstance().getHelperForDaemon((LedDDaemon) daemonSpinner.getSelectedItem());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
LedDHelper helper = ColorApplication.getInstance().getHelperForDaemon((LedDDaemon) daemonSpinner.getSelectedItem());
|
||||
|
||||
|
||||
if (helper != null) {
|
||||
try {
|
||||
helper.testChannel((Controller) controllerSpinner.getSelectedItem(), Integer.parseInt(text.getText().toString()), val);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -418,15 +395,9 @@ public class AddStripeDialog extends DialogFragment implements DialogInterface.O
|
||||
|
||||
private void refreshController(final LedDDaemon ledDDaemon) {
|
||||
controllerArrayAdapter.clear();
|
||||
LedDHelper helper = null;
|
||||
try {
|
||||
helper = ColorApplication.getInstance().getHelperForDaemon(ledDDaemon);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
LedDHelper helper = ColorApplication.getInstance().getHelperForDaemon(ledDDaemon);
|
||||
|
||||
if (helper != null) {
|
||||
try {
|
||||
helper.getStripes(new StripesCallback() {
|
||||
@Override
|
||||
public void onSuccess(List<LedStripe> stripes) {
|
||||
@@ -449,9 +420,6 @@ public class AddStripeDialog extends DialogFragment implements DialogInterface.O
|
||||
|
||||
}
|
||||
});
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -43,7 +43,6 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
@@ -78,7 +77,7 @@ public class LedDHelper {
|
||||
}
|
||||
};
|
||||
|
||||
public LedDHelper(LedDDaemon ledDDaemon, Context appl) throws IOException {
|
||||
public LedDHelper(LedDDaemon ledDDaemon, Context appl) {
|
||||
this.context = appl;
|
||||
this.dRequests = new LinkedBlockingQueue<>();
|
||||
this.ledDDaemon = ledDDaemon;
|
||||
@@ -91,16 +90,18 @@ public class LedDHelper {
|
||||
* Add controller to ledd daemon
|
||||
*
|
||||
* @param c controller object
|
||||
* @throws JSONException no valid json
|
||||
* @throws IOException socket error
|
||||
*/
|
||||
public void addController(final Controller c, final AddControllerCallback callback) throws JSONException, IOException {
|
||||
public void addController(final Controller c, final AddControllerCallback callback) {
|
||||
JSONObject jnson = new JSONObject();
|
||||
|
||||
try {
|
||||
jnson.put("action", ACTION_ADDCONTROLLER);
|
||||
jnson.put("channels", c.getChannels());
|
||||
jnson.put("i2c_dev", c.getI2c_device());
|
||||
jnson.put("address", c.getAddress());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
addRequestToQueue(jnson, new AnswerTask() {
|
||||
@Override
|
||||
@@ -126,14 +127,15 @@ public class LedDHelper {
|
||||
|
||||
/**
|
||||
* Get stripes known to daemon
|
||||
*
|
||||
* @throws JSONException no valid json
|
||||
* @throws IOException socket error
|
||||
*/
|
||||
public void getStripes(final StripesCallback callback) throws JSONException, IOException {
|
||||
public void getStripes(final StripesCallback callback) {
|
||||
JSONObject jnson = new JSONObject();
|
||||
|
||||
try {
|
||||
jnson.put("action", ACTION_GETALLSTRIPES);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
addRequestToQueue(jnson, new AnswerTask() {
|
||||
@Override
|
||||
@@ -220,14 +222,16 @@ public class LedDHelper {
|
||||
* Get color using the stripeid
|
||||
*
|
||||
* @param ledStripe Stripe
|
||||
* @throws JSONException no valid json
|
||||
* @throws IOException socket error
|
||||
*/
|
||||
public void getColor(final LedStripe ledStripe, final RecieveColorCallback callback) throws JSONException, IOException {
|
||||
public void getColor(final LedStripe ledStripe, final RecieveColorCallback callback) {
|
||||
JSONObject jnson = new JSONObject();
|
||||
|
||||
try {
|
||||
jnson.put("action", ACTION_GETCOLOR);
|
||||
jnson.put("sid", ledStripe.getId());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
addRequestToQueue(jnson, new AnswerTask() {
|
||||
@Override
|
||||
@@ -258,15 +262,19 @@ public class LedDHelper {
|
||||
* @param c controller
|
||||
* @param channel channel number
|
||||
* @param value value (1= on, 0 = off)
|
||||
* @throws JSONException
|
||||
*/
|
||||
public void testChannel(Controller c, int channel, int value) throws JSONException {
|
||||
public void testChannel(Controller c, int channel, int value) {
|
||||
JSONObject jnson = new JSONObject();
|
||||
|
||||
try {
|
||||
jnson.put("action", ACTION_TESTCHANNEL);
|
||||
|
||||
jnson.put("cid", c.getId());
|
||||
jnson.put("channel", channel);
|
||||
jnson.put("value", value);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
addRequestToQueue(jnson, new AnswerTask() {
|
||||
@Override
|
||||
@@ -283,14 +291,15 @@ public class LedDHelper {
|
||||
|
||||
/**
|
||||
* Get information about an ledd daemon
|
||||
*
|
||||
* @throws JSONException no valid json
|
||||
* @throws IOException socket error
|
||||
*/
|
||||
public void discover(final DiscoverCallback callback) throws JSONException, IOException {
|
||||
public void discover(final DiscoverCallback callback) {
|
||||
JSONObject jnson = new JSONObject();
|
||||
|
||||
try {
|
||||
jnson.put("action", ACTION_DISCOVER);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
addRequestToQueue(jnson, new AnswerTask() {
|
||||
@Override
|
||||
@@ -313,14 +322,13 @@ public class LedDHelper {
|
||||
|
||||
/**
|
||||
* Get information about an ledd daemon
|
||||
*
|
||||
* @throws JSONException no valid json
|
||||
* @throws IOException socket error
|
||||
*/
|
||||
public void addStripe(final LedStripe ledStripe, final AddStripeCallback callback) throws JSONException, IOException {
|
||||
public void addStripe(final LedStripe ledStripe, final AddStripeCallback callback) {
|
||||
JSONObject jnson = new JSONObject();
|
||||
|
||||
try {
|
||||
jnson.put("action", ACTION_ADDSTRIPES);
|
||||
|
||||
JSONObject stripe = new JSONObject();
|
||||
|
||||
stripe.put("name", ledStripe.getName());
|
||||
@@ -334,6 +342,10 @@ public class LedDHelper {
|
||||
stripe.put("cid", ledStripe.getController().getId());
|
||||
jnson.put("stripe", stripe);
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
addRequestToQueue(jnson, new AnswerTask() {
|
||||
@Override
|
||||
public void onConnectionFailed(String message) {
|
||||
@@ -355,7 +367,7 @@ public class LedDHelper {
|
||||
}
|
||||
|
||||
private void addRequestToQueue(JSONObject json, AnswerTask task) {
|
||||
dRequests.add(new LedDRequest(json, task));
|
||||
if (json != null && json.length() > 0) dRequests.add(new LedDRequest(json, task));
|
||||
}
|
||||
|
||||
public void teardown() {
|
||||
@@ -389,8 +401,6 @@ public class LedDHelper {
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -65,11 +65,6 @@ public class ColorService extends Service {
|
||||
return mBinder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUnbind(Intent intent) {
|
||||
return super.onUnbind(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
worker.stop();
|
||||
@@ -85,15 +80,9 @@ public class ColorService extends Service {
|
||||
DataCallback dataCallback = new DataCallback() {
|
||||
@Override
|
||||
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
|
||||
JSONObject resp = null;
|
||||
try {
|
||||
resp = new JSONObject(new String(bb.getAllByteArray()));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
JSONObject resp = new JSONObject(new String(bb.getAllByteArray()));
|
||||
|
||||
if (resp != null) {
|
||||
try {
|
||||
if (sendableHashMap.containsKey(resp.getString("ref"))) {
|
||||
sendableHashMap.get(resp.getString("ref")).onResponse(resp);
|
||||
sendableHashMap.remove(resp.getString("ref"));
|
||||
@@ -105,7 +94,6 @@ public class ColorService extends Service {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public Worker(LinkedBlockingQueue<T> workQueue) {
|
||||
@@ -122,36 +110,36 @@ public class ColorService extends Service {
|
||||
final T item = workQueue.take();
|
||||
|
||||
if (item instanceof Sendable) {
|
||||
if (socketHashMap.containsKey(((Sendable) item).getRecipient()) && socketHashMap.get(((Sendable) item).getRecipient())
|
||||
.getServer().isRunning()) {
|
||||
final Sendable sendable = (Sendable) item;
|
||||
if (socketHashMap.containsKey(sendable.getRecipient()) && socketHashMap.get(sendable.getRecipient()).getServer().isRunning
|
||||
()) {
|
||||
|
||||
Util.writeAll(socketHashMap.get(((Sendable) item).getRecipient()), (((Sendable) item).getMessage().toString() + "\n")
|
||||
.getBytes
|
||||
("UTF-8"), null);
|
||||
sendableHashMap.put(((Sendable) item).getRef(), (Sendable) item);
|
||||
Util.writeAll(socketHashMap.get(sendable.getRecipient()), (sendable.getMessage().toString() + "\n").getBytes("UTF-8"),
|
||||
null);
|
||||
sendableHashMap.put(sendable.getRef(), sendable);
|
||||
if (!poolExecutor.isTerminating() && !poolExecutor.isTerminated())
|
||||
timeoutHashMap.put(((Sendable) item).getRef(), poolExecutor.schedule(new Runnable() {
|
||||
timeoutHashMap.put(sendable.getRef(), poolExecutor.schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
((Sendable) item).onNoResponse();
|
||||
timeoutHashMap.remove(((Sendable) item).getRef());
|
||||
sendableHashMap.remove(((Sendable) item).getRef());
|
||||
sendable.onNoResponse();
|
||||
timeoutHashMap.remove(sendable.getRef());
|
||||
sendableHashMap.remove(sendable.getRef());
|
||||
}
|
||||
}, 1000, TimeUnit.MILLISECONDS));
|
||||
} else {
|
||||
AsyncServer.getDefault().connectSocket(new InetSocketAddress(((Sendable) item).getRecipient().getAddress(), ((Sendable)
|
||||
item).getRecipient().getPort()), new ConnectCallback() {
|
||||
AsyncServer.getDefault().connectSocket(new InetSocketAddress(sendable.getRecipient().getAddress(), sendable
|
||||
.getRecipient().getPort()), new ConnectCallback() {
|
||||
@Override
|
||||
public void onConnectCompleted(Exception ex, final AsyncSocket socket) {
|
||||
if (ex == null) {
|
||||
socket.setDataCallback(dataCallback);
|
||||
|
||||
socketHashMap.put(((Sendable) item).getRecipient(), socket);
|
||||
socketHashMap.put(sendable.getRecipient(), socket);
|
||||
|
||||
//if (!workQueue.contains(item)) -> needs equals implementaion
|
||||
//if (!workQueue.contains(item)) -> needs equals implementation
|
||||
workQueue.add(item);
|
||||
} else {
|
||||
((Sendable) item).onConnectionFailed(ex.getMessage());
|
||||
sendable.onConnectionFailed(ex.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -172,10 +160,16 @@ public class ColorService extends Service {
|
||||
}
|
||||
|
||||
public class ColorBinder extends Binder {
|
||||
public String queueSend(LedDDaemon rec, JSONObject msg, AnswerTask answerTask) throws JSONException {
|
||||
Sendable sendable = new Sendable(msg, answerTask, rec);
|
||||
public void queueSend(LedDDaemon rec, JSONObject msg, AnswerTask answerTask) {
|
||||
Sendable sendable = null;
|
||||
try {
|
||||
sendable = new Sendable(msg, answerTask, rec);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (sendable != null) {
|
||||
queue.add(sendable);
|
||||
return sendable.getRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 953 B |
Before Width: | Height: | Size: 114 B |
Before Width: | Height: | Size: 228 B |
Before Width: | Height: | Size: 186 B |
Before Width: | Height: | Size: 721 B |
Before Width: | Height: | Size: 213 B |
Before Width: | Height: | Size: 7.2 KiB |
Before Width: | Height: | Size: 594 B |
Before Width: | Height: | Size: 108 B |
Before Width: | Height: | Size: 168 B |
Before Width: | Height: | Size: 150 B |
Before Width: | Height: | Size: 517 B |
Before Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 9.5 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 119 B |
Before Width: | Height: | Size: 288 B |
Before Width: | Height: | Size: 222 B |
Before Width: | Height: | Size: 963 B |
Before Width: | Height: | Size: 269 B |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 130 B |
Before Width: | Height: | Size: 432 B |
Before Width: | Height: | Size: 294 B |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 402 B |
Before Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 133 B |
Before Width: | Height: | Size: 624 B |
Before Width: | Height: | Size: 373 B |
Before Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 551 B |
@@ -1,23 +0,0 @@
|
||||
<!--
|
||||
~ LEDD Project
|
||||
~ Copyright (C) 2015 LEDD Team
|
||||
~
|
||||
~ This program is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragmentContainer"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
@@ -46,7 +46,7 @@
|
||||
android:layout_marginLeft="7dp"
|
||||
android:layout_toRightOf="@id/img_host"
|
||||
android:gravity="center"
|
||||
android:text="Add Controller"
|
||||
android:text="@string/text_add_controller"
|
||||
android:textAppearance="?android:textAppearanceMedium"
|
||||
/>
|
||||
</RelativeLayout>
|
||||
@@ -62,7 +62,7 @@
|
||||
android:id="@+id/input_i2c"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="i2c device number"
|
||||
android:hint="@string/hint_i2c_device"
|
||||
android:inputType="number"
|
||||
android:minWidth="350dp"/>
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
android:id="@+id/input_address"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="controller address in hex format"
|
||||
android:hint="@string/hint_controller_address"
|
||||
android:minWidth="350dp"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
@@ -95,7 +95,7 @@
|
||||
android:id="@+id/input_channel"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="channels"
|
||||
android:hint="@string/hint_channels"
|
||||
android:inputType="number"
|
||||
android:minWidth="350dp"/>
|
||||
|
||||
|
@@ -80,7 +80,7 @@
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="or"
|
||||
android:text="@string/text_or"
|
||||
android:textAppearance="?android:textAppearanceMedium"/>
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
@@ -93,7 +93,7 @@
|
||||
android:id="@+id/input_ip"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="ip address[:port]"
|
||||
android:hint="@string/hint_daemon_ip_port"
|
||||
android:minWidth="250dp"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
@@ -46,7 +46,7 @@
|
||||
android:layout_marginLeft="7dp"
|
||||
android:layout_toRightOf="@id/img_host"
|
||||
android:gravity="center"
|
||||
android:text="Choose Daemon"
|
||||
android:text="@string/text_choose_daemon"
|
||||
android:textAppearance="?android:textAppearanceSmall"
|
||||
/>
|
||||
|
||||
@@ -99,7 +99,7 @@
|
||||
android:layout_marginLeft="7dp"
|
||||
android:layout_toRightOf="@id/img_controller"
|
||||
android:gravity="center"
|
||||
android:text="Choose Controller"
|
||||
android:text="@string/text_choose_controller"
|
||||
android:textAppearance="?android:textAppearanceSmall"
|
||||
/>
|
||||
|
||||
@@ -151,7 +151,7 @@
|
||||
android:layout_marginLeft="7dp"
|
||||
android:layout_toRightOf="@id/img_stripe"
|
||||
android:gravity="center"
|
||||
android:text="Stripe Properties"
|
||||
android:text="@string/text_stripe_properties"
|
||||
android:textAppearance="?android:textAppearanceSmall"
|
||||
/>
|
||||
|
||||
@@ -169,7 +169,7 @@
|
||||
android:id="@+id/input_stripe_name"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Stripe name"
|
||||
android:hint="@string/hint_stripe_name"
|
||||
android:inputType="text"
|
||||
android:minEms="12"/>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
@@ -180,7 +180,7 @@
|
||||
android:layout_marginLeft="9dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:gravity="center"
|
||||
android:text="Channel Mapping"
|
||||
android:text="@string/text_channel_mapping"
|
||||
android:textAppearance="?android:textAppearanceSmall"
|
||||
/>
|
||||
|
||||
@@ -206,7 +206,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="2"
|
||||
android:hint="R"
|
||||
android:hint="@string/hint_channel_r"
|
||||
android:inputType="number"/>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
@@ -231,7 +231,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="2"
|
||||
android:hint="G"
|
||||
android:hint="@string/hint_channel_g"
|
||||
android:inputType="number"/>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
@@ -256,7 +256,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="2"
|
||||
android:hint="B"
|
||||
android:hint="@string/hint_channel_b"
|
||||
android:inputType="number"/>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
|
@@ -41,7 +41,7 @@
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:clickable="true"
|
||||
android:gravity="center_vertical"
|
||||
android:text="textHost"
|
||||
android:text=""
|
||||
android:textAppearance="?android:textAppearanceMedium"
|
||||
android:textColor="@color/primaryColorDark"/>
|
||||
|
||||
|
@@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ LEDD Project
|
||||
~ Copyright (C) 2015 LEDD Team
|
||||
~
|
||||
~ This program is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/activity_bar"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="-8dp" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/activity_frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="fill_parent" />
|
||||
|
||||
</LinearLayout>
|
@@ -23,13 +23,13 @@
|
||||
android:id="@+id/nv_add_stripe"
|
||||
android:icon="@drawable/ic_add_circle_black_48dp"
|
||||
android:orderInCategory="51"
|
||||
android:title="Add Stripe"/>
|
||||
android:title="@string/text_add_stripe"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/nv_settings"
|
||||
android:icon="@drawable/ic_tune_black_48dp"
|
||||
android:orderInCategory="52"
|
||||
android:title="Settings"/>
|
||||
android:title="@string/test_settings"/>
|
||||
|
||||
|
||||
</menu>
|
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 9.7 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 15 KiB |
@@ -19,9 +19,5 @@
|
||||
<resources>
|
||||
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
<dimen name="nd_icon">30dp</dimen>
|
||||
<dimen name="space_before_icon">7dp</dimen>
|
||||
|
||||
</resources>
|
||||
|
@@ -20,8 +20,21 @@
|
||||
<resources>
|
||||
|
||||
<string name="app_name">LedD</string>
|
||||
<string name="button_label">OK</string>
|
||||
<string name="pref_name">Pick a color</string>
|
||||
<string name="pref_summary">DialogPreference with Color Picker.</string>
|
||||
<string name="text_add_controller">Add Controller</string>
|
||||
<string name="hint_i2c_device">i2c device number</string>
|
||||
<string name="hint_controller_address">controller address in hex format</string>
|
||||
<string name="hint_channels">channels</string>
|
||||
<string name="text_or">or</string>
|
||||
<string name="hint_daemon_ip_port">ip address[:port]</string>
|
||||
<string name="text_choose_daemon">Choose Daemon</string>
|
||||
<string name="text_choose_controller">Choose Controller</string>
|
||||
<string name="text_stripe_properties">Stripe Properties</string>
|
||||
<string name="hint_stripe_name">Stripe name</string>
|
||||
<string name="text_channel_mapping">Channel Mapping</string>
|
||||
<string name="hint_channel_r">R</string>
|
||||
<string name="hint_channel_g">G</string>
|
||||
<string name="hint_channel_b">B</string>
|
||||
<string name="text_add_stripe">Add Stripe</string>
|
||||
<string name="test_settings">Settings</string>
|
||||
|
||||
</resources>
|
||||
|