general post-release cleanup

removed lots of unused strings/resources/drawables
extracted all translatable strings
added new logo
This commit is contained in:
Giovanni Harting
2015-09-16 13:40:04 +02:00
parent 608a9c48d1
commit 42ff424622
58 changed files with 342 additions and 478 deletions

View File

@@ -29,7 +29,7 @@
android:name=".ColorApplication" android:name=".ColorApplication"
android:allowBackup="true" android:allowBackup="true"
android:fullBackupContent="false" android:fullBackupContent="false"
android:icon="@drawable/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity <activity

View File

@@ -50,9 +50,6 @@ import com.idlegandalf.ledd.helper.LedDHelper;
import com.larswerkman.holocolorpicker.ColorPicker; import com.larswerkman.holocolorpicker.ColorPicker;
import com.larswerkman.holocolorpicker.SVBar; import com.larswerkman.holocolorpicker.SVBar;
import org.json.JSONException;
import java.io.IOException;
import java.util.List; import java.util.List;
import butterknife.Bind; import butterknife.Bind;
@@ -85,8 +82,14 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
// check for connectivity // check for connectivity
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo == null || !networkInfo.isConnected()) { if (networkInfo == null || !networkInfo.isConnected() || networkInfo.getType() != ConnectivityManager.TYPE_WIFI) {
// TODO: Display error (snackbar) 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); colorPicker.addSVBar(svBar);
@@ -200,11 +203,7 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
super.onResume(); super.onResume();
ColorApplication.getInstance().onResume(); ColorApplication.getInstance().onResume();
registerReceiver(daemonsListener, new IntentFilter(ColorApplication.INTENT_ACTION_REFRESH)); registerReceiver(daemonsListener, new IntentFilter(ColorApplication.INTENT_ACTION_REFRESH));
try {
refreshStripes(); refreshStripes();
} catch (IOException e) {
e.printStackTrace();
}
} }
@Override @Override
@@ -222,14 +221,10 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
for (LedStripe stripe : ledStripes) { for (LedStripe stripe : ledStripes) {
if (stripe.getName().equals(menuItem.getTitle())) { if (stripe.getName().equals(menuItem.getTitle())) {
mCurrentStripe = stripe; mCurrentStripe = stripe;
try {
mCurrentHelper = ColorApplication.getInstance().getHelperForDaemon(stripe.getLedDDaemon()); mCurrentHelper = ColorApplication.getInstance().getHelperForDaemon(stripe.getLedDDaemon());
} catch (IOException e) {
e.printStackTrace();
}
mDrawerLayout.closeDrawer(Gravity.LEFT); mDrawerLayout.closeDrawer(Gravity.LEFT);
toolbar.setTitle(stripe.getName()); toolbar.setTitle(stripe.getName());
try {
mCurrentHelper.getColor(mCurrentStripe, new RecieveColorCallback() { mCurrentHelper.getColor(mCurrentStripe, new RecieveColorCallback() {
@Override @Override
public void onColorRecieved(LedStripe stripe) { public void onColorRecieved(LedStripe stripe) {
@@ -238,8 +233,8 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
colorPicker.setColor(Color.HSVToColor(new float[]{(float) cColor.getHue(), (float) cColor.getSaturation(), colorPicker.setColor(Color.HSVToColor(new float[]{(float) cColor.getHue(), (float) cColor.getSaturation(), (float)
(float) cColor.getValue()})); cColor.getValue()}));
} }
}); });
} }
@@ -254,9 +249,7 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
} }
}); });
} catch (JSONException | IOException e) {
e.printStackTrace();
}
return true; return true;
} }
} }
@@ -264,7 +257,7 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
return false; 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 reCreateNavigationView(); // need to recreate the navigationview since we can't remove a once added submenu
final Menu nvMenu = navigationView.getMenu(); final Menu nvMenu = navigationView.getMenu();
@@ -276,7 +269,6 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
LedDHelper helper = ColorApplication.getInstance().getHelperForDaemon(dDaemon); LedDHelper helper = ColorApplication.getInstance().getHelperForDaemon(dDaemon);
if (helper != null) { if (helper != null) {
try {
final int finalI = i; final int finalI = i;
helper.getStripes(new StripesCallback() { helper.getStripes(new StripesCallback() {
@Override @Override
@@ -300,8 +292,7 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
@Override @Override
public void onGetFailed(String message) { public void onGetFailed(String message) {
Snackbar.make(findViewById(android.R.id.content), "Coudn't get stripes from daemon: " + message, Snackbar.LENGTH_LONG) Snackbar.make(findViewById(android.R.id.content), "Coudn't get stripes from daemon: " + message, Snackbar.LENGTH_LONG).show();
.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(); Snackbar.make(findViewById(android.R.id.content), "Coudn't connect to daemon: " + message, Snackbar.LENGTH_LONG).show();
} }
}); });
} catch (JSONException | IOException e) {
e.printStackTrace();
}
} }
i++; i++;
@@ -343,11 +332,7 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ColorApplication.INTENT_ACTION_REFRESH)) { if (intent.getAction().equals(ColorApplication.INTENT_ACTION_REFRESH)) {
try {
refreshStripes(); refreshStripes();
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
} }

View File

@@ -29,9 +29,6 @@ import com.idlegandalf.ledd.callbacks.DiscoverCallback;
import com.idlegandalf.ledd.components.LedDDaemon; import com.idlegandalf.ledd.components.LedDDaemon;
import com.idlegandalf.ledd.helper.LedDHelper; import com.idlegandalf.ledd.helper.LedDHelper;
import org.json.JSONException;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -56,12 +53,11 @@ public class ColorApplication extends Application {
this.onResume(); this.onResume();
} }
public LedDHelper getHelperForDaemon(final LedDDaemon ledDDaemon) throws IOException { public LedDHelper getHelperForDaemon(final LedDDaemon ledDDaemon) {
if (ledDHelpers.containsKey(ledDDaemon) && ledDHelpers.get(ledDDaemon) != null) { if (ledDHelpers.containsKey(ledDDaemon) && ledDHelpers.get(ledDDaemon) != null) {
return ledDHelpers.get(ledDDaemon); return ledDHelpers.get(ledDDaemon);
} else { } else {
final LedDHelper dHelper = new LedDHelper(ledDDaemon, getApplicationContext()); final LedDHelper dHelper = new LedDHelper(ledDDaemon, getApplicationContext());
try {
dHelper.discover(new DiscoverCallback() { dHelper.discover(new DiscoverCallback() {
@Override @Override
public void onConnectionFailed(String message) { public void onConnectionFailed(String message) {
@@ -73,11 +69,6 @@ public class ColorApplication extends Application {
ledDHelpers.put(ledDDaemon, dHelper); ledDHelpers.put(ledDDaemon, dHelper);
} }
}); });
} catch (JSONException e) {
e.printStackTrace();
}
return dHelper; return dHelper;
} }
} }
@@ -104,7 +95,6 @@ public class ColorApplication extends Application {
}.getType()); }.getType());
for (final LedDDaemon ledDDaemon : ledDDaemons) { for (final LedDDaemon ledDDaemon : ledDDaemons) {
try {
final LedDHelper helper = new LedDHelper(ledDDaemon, getApplicationContext()); final LedDHelper helper = new LedDHelper(ledDDaemon, getApplicationContext());
helper.discover(new DiscoverCallback() { helper.discover(new DiscoverCallback() {
@@ -126,11 +116,6 @@ public class ColorApplication extends Application {
sendBroadcast(i); sendBroadcast(i);
} }
}); });
} catch (IOException | JSONException e) {
e.printStackTrace();
}
} }
} }

View File

@@ -19,11 +19,11 @@
package com.idlegandalf.ledd; package com.idlegandalf.ledd;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.AppCompatActivity;
import com.idlegandalf.ledd.fragments.SettingsFragment; import com.idlegandalf.ledd.fragments.SettingsFragment;
public class SettingsActivity extends ActionBarActivity { public class SettingsActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);

View File

@@ -21,9 +21,6 @@ package com.idlegandalf.ledd.components;
import com.idlegandalf.ledd.helper.LedDHelper; import com.idlegandalf.ledd.helper.LedDHelper;
import org.json.JSONException;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
public class StripeGroup { public class StripeGroup {
@@ -60,7 +57,7 @@ public class StripeGroup {
return null; 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++) { for (int i = 0; i < mStripes.size(); i++) {
//mStripes.get(i).setRGB(r, g, b, api); //mStripes.get(i).setRGB(r, g, b, api);
} }

View File

@@ -39,9 +39,6 @@ import com.idlegandalf.ledd.components.Controller;
import com.idlegandalf.ledd.components.LedDDaemon; import com.idlegandalf.ledd.components.LedDDaemon;
import com.idlegandalf.ledd.helper.LedDHelper; import com.idlegandalf.ledd.helper.LedDHelper;
import org.json.JSONException;
import java.io.IOException;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.text.ParsePosition; import java.text.ParsePosition;
@@ -64,6 +61,13 @@ public class AddControllerDialog extends DialogFragment implements DialogInterfa
EditText channelText; EditText channelText;
LedDDaemon dDaemon; 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) { public Dialog onCreateDialog(Bundle savedInstanceState) {
View v = View.inflate(getActivity(), R.layout.fragment_addcontroller, null); View v = View.inflate(getActivity(), R.layout.fragment_addcontroller, null);
ButterKnife.bind(this, v); ButterKnife.bind(this, v);
@@ -168,15 +172,9 @@ public class AddControllerDialog extends DialogFragment implements DialogInterfa
c.setI2c_device(Integer.parseInt(i2cText.getText().toString())); c.setI2c_device(Integer.parseInt(i2cText.getText().toString()));
c.setChannels(Integer.parseInt(channelText.getText().toString())); c.setChannels(Integer.parseInt(channelText.getText().toString()));
LedDHelper helper = null; LedDHelper helper = ColorApplication.getInstance().getHelperForDaemon(dDaemon);
try {
helper = ColorApplication.getInstance().getHelperForDaemon(dDaemon);
} catch (IOException e) {
e.printStackTrace();
}
if (helper != null) { if (helper != null) {
try {
helper.addController(c, new AddControllerCallback() { helper.addController(c, new AddControllerCallback() {
@Override @Override
public void onControllerAdded(final Controller controller) { public void onControllerAdded(final Controller controller) {
@@ -219,18 +217,8 @@ public class AddControllerDialog extends DialogFragment implements DialogInterfa
dismiss(); 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();
}
} }

View File

@@ -45,9 +45,6 @@ import com.idlegandalf.ledd.R;
import com.idlegandalf.ledd.callbacks.DiscoverCallback; import com.idlegandalf.ledd.callbacks.DiscoverCallback;
import com.idlegandalf.ledd.components.LedDDaemon; import com.idlegandalf.ledd.components.LedDDaemon;
import org.json.JSONException;
import java.io.IOException;
import java.net.Inet4Address; import java.net.Inet4Address;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -286,7 +283,6 @@ public class AddDaemonDialog extends DialogFragment implements DialogInterface.O
} }
private void addDaemon(final LedDDaemon ledDDaemon) { private void addDaemon(final LedDDaemon ledDDaemon) {
try {
ColorApplication.getInstance().getHelperForDaemon(ledDDaemon).discover(new DiscoverCallback() { ColorApplication.getInstance().getHelperForDaemon(ledDDaemon).discover(new DiscoverCallback() {
@Override @Override
public void onConnectionFailed(final String message) { 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(); " daemon at " + ledDDaemon + ": " + message, Snackbar.LENGTH_LONG).show();
} }
}); });
AddStripeDialog stripeAdd = (AddStripeDialog) getFragmentManager().findFragmentByTag("stripeAdd");
AddStripeDialog.instance.onResume(); AddStripeDialog.instance.onResume();
dismiss(); dismiss();
} }
@@ -313,17 +308,10 @@ public class AddDaemonDialog extends DialogFragment implements DialogInterface.O
} }
}); });
try {
((ColorActivity) getActivity()).refreshStripes(); ((ColorActivity) getActivity()).refreshStripes();
} catch (IOException e) {
e.printStackTrace();
}
AddStripeDialog.instance.onResume(); AddStripeDialog.instance.onResume();
dismiss(); dismiss();
} }
}); });
} catch (JSONException | IOException e) {
e.printStackTrace();
}
} }
} }

View File

@@ -50,9 +50,6 @@ import com.idlegandalf.ledd.components.LedDDaemon;
import com.idlegandalf.ledd.components.LedStripe; import com.idlegandalf.ledd.components.LedStripe;
import com.idlegandalf.ledd.helper.LedDHelper; import com.idlegandalf.ledd.helper.LedDHelper;
import org.json.JSONException;
import java.io.IOException;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.text.ParsePosition; import java.text.ParsePosition;
import java.util.List; import java.util.List;
@@ -259,24 +256,15 @@ public class AddStripeDialog extends DialogFragment implements DialogInterface.O
stripe.setLedDDaemon((LedDDaemon) daemonSpinner.getSelectedItem()); stripe.setLedDDaemon((LedDDaemon) daemonSpinner.getSelectedItem());
stripe.setController((Controller) controllerSpinner.getSelectedItem()); stripe.setController((Controller) controllerSpinner.getSelectedItem());
LedDHelper helper = null; LedDHelper helper = ColorApplication.getInstance().getHelperForDaemon((LedDDaemon) daemonSpinner.getSelectedItem());
try {
helper = ColorApplication.getInstance().getHelperForDaemon((LedDDaemon) daemonSpinner.getSelectedItem());
} catch (IOException e) {
e.printStackTrace();
}
if (helper != null) { if (helper != null) {
try {
helper.addStripe(stripe, new AddStripeCallback() { helper.addStripe(stripe, new AddStripeCallback() {
@Override @Override
public void onAddSuccessfully(final LedStripe stripe) { public void onAddSuccessfully(final LedStripe stripe) {
ColorActivity activity = ((ColorActivity) getActivity()); ColorActivity activity = ((ColorActivity) getActivity());
try {
activity.refreshStripes(); activity.refreshStripes();
} catch (IOException e) {
e.printStackTrace();
}
getActivity().runOnUiThread(new Runnable() { getActivity().runOnUiThread(new Runnable() {
@Override @Override
@@ -300,9 +288,6 @@ public class AddStripeDialog extends DialogFragment implements DialogInterface.O
dismiss(); dismiss();
} }
}); });
} catch (JSONException | IOException e) {
e.printStackTrace();
}
} }
} }
}); });
@@ -398,19 +383,11 @@ public class AddStripeDialog extends DialogFragment implements DialogInterface.O
} }
text.setTag(toggle); text.setTag(toggle);
LedDHelper helper = null; LedDHelper helper = ColorApplication.getInstance().getHelperForDaemon((LedDDaemon) daemonSpinner.getSelectedItem());
try {
helper = ColorApplication.getInstance().getHelperForDaemon((LedDDaemon) daemonSpinner.getSelectedItem());
} catch (IOException e) {
e.printStackTrace();
}
if (helper != null) { if (helper != null) {
try {
helper.testChannel((Controller) controllerSpinner.getSelectedItem(), Integer.parseInt(text.getText().toString()), val); 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) { private void refreshController(final LedDDaemon ledDDaemon) {
controllerArrayAdapter.clear(); controllerArrayAdapter.clear();
LedDHelper helper = null; LedDHelper helper = ColorApplication.getInstance().getHelperForDaemon(ledDDaemon);
try {
helper = ColorApplication.getInstance().getHelperForDaemon(ledDDaemon);
} catch (IOException e) {
e.printStackTrace();
}
if (helper != null) { if (helper != null) {
try {
helper.getStripes(new StripesCallback() { helper.getStripes(new StripesCallback() {
@Override @Override
public void onSuccess(List<LedStripe> stripes) { public void onSuccess(List<LedStripe> stripes) {
@@ -449,9 +420,6 @@ public class AddStripeDialog extends DialogFragment implements DialogInterface.O
} }
}); });
} catch (JSONException | IOException e) {
e.printStackTrace();
}
} }
} }
} }

View File

@@ -43,7 +43,6 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.LinkedBlockingQueue; 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.context = appl;
this.dRequests = new LinkedBlockingQueue<>(); this.dRequests = new LinkedBlockingQueue<>();
this.ledDDaemon = ledDDaemon; this.ledDDaemon = ledDDaemon;
@@ -91,16 +90,18 @@ public class LedDHelper {
* Add controller to ledd daemon * Add controller to ledd daemon
* *
* @param c controller object * @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(); JSONObject jnson = new JSONObject();
try {
jnson.put("action", ACTION_ADDCONTROLLER); jnson.put("action", ACTION_ADDCONTROLLER);
jnson.put("channels", c.getChannels()); jnson.put("channels", c.getChannels());
jnson.put("i2c_dev", c.getI2c_device()); jnson.put("i2c_dev", c.getI2c_device());
jnson.put("address", c.getAddress()); jnson.put("address", c.getAddress());
} catch (JSONException e) {
e.printStackTrace();
}
addRequestToQueue(jnson, new AnswerTask() { addRequestToQueue(jnson, new AnswerTask() {
@Override @Override
@@ -126,14 +127,15 @@ public class LedDHelper {
/** /**
* Get stripes known to daemon * 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(); JSONObject jnson = new JSONObject();
try {
jnson.put("action", ACTION_GETALLSTRIPES); jnson.put("action", ACTION_GETALLSTRIPES);
} catch (JSONException e) {
e.printStackTrace();
}
addRequestToQueue(jnson, new AnswerTask() { addRequestToQueue(jnson, new AnswerTask() {
@Override @Override
@@ -220,14 +222,16 @@ public class LedDHelper {
* Get color using the stripeid * Get color using the stripeid
* *
* @param ledStripe Stripe * @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(); JSONObject jnson = new JSONObject();
try {
jnson.put("action", ACTION_GETCOLOR); jnson.put("action", ACTION_GETCOLOR);
jnson.put("sid", ledStripe.getId()); jnson.put("sid", ledStripe.getId());
} catch (JSONException e) {
e.printStackTrace();
}
addRequestToQueue(jnson, new AnswerTask() { addRequestToQueue(jnson, new AnswerTask() {
@Override @Override
@@ -258,15 +262,19 @@ public class LedDHelper {
* @param c controller * @param c controller
* @param channel channel number * @param channel channel number
* @param value value (1= on, 0 = off) * @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(); JSONObject jnson = new JSONObject();
try {
jnson.put("action", ACTION_TESTCHANNEL); jnson.put("action", ACTION_TESTCHANNEL);
jnson.put("cid", c.getId()); jnson.put("cid", c.getId());
jnson.put("channel", channel); jnson.put("channel", channel);
jnson.put("value", value); jnson.put("value", value);
} catch (JSONException e) {
e.printStackTrace();
}
addRequestToQueue(jnson, new AnswerTask() { addRequestToQueue(jnson, new AnswerTask() {
@Override @Override
@@ -283,14 +291,15 @@ public class LedDHelper {
/** /**
* Get information about an ledd daemon * 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(); JSONObject jnson = new JSONObject();
try {
jnson.put("action", ACTION_DISCOVER); jnson.put("action", ACTION_DISCOVER);
} catch (JSONException e) {
e.printStackTrace();
}
addRequestToQueue(jnson, new AnswerTask() { addRequestToQueue(jnson, new AnswerTask() {
@Override @Override
@@ -313,14 +322,13 @@ public class LedDHelper {
/** /**
* Get information about an ledd daemon * 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(); JSONObject jnson = new JSONObject();
try {
jnson.put("action", ACTION_ADDSTRIPES); jnson.put("action", ACTION_ADDSTRIPES);
JSONObject stripe = new JSONObject(); JSONObject stripe = new JSONObject();
stripe.put("name", ledStripe.getName()); stripe.put("name", ledStripe.getName());
@@ -334,6 +342,10 @@ public class LedDHelper {
stripe.put("cid", ledStripe.getController().getId()); stripe.put("cid", ledStripe.getController().getId());
jnson.put("stripe", stripe); jnson.put("stripe", stripe);
} catch (JSONException e) {
e.printStackTrace();
}
addRequestToQueue(jnson, new AnswerTask() { addRequestToQueue(jnson, new AnswerTask() {
@Override @Override
public void onConnectionFailed(String message) { public void onConnectionFailed(String message) {
@@ -355,7 +367,7 @@ public class LedDHelper {
} }
private void addRequestToQueue(JSONObject json, AnswerTask task) { 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() { public void teardown() {
@@ -389,8 +401,6 @@ public class LedDHelper {
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
break; break;
} catch (JSONException e) {
e.printStackTrace();
} }
} }
} }

View File

@@ -65,11 +65,6 @@ public class ColorService extends Service {
return mBinder; return mBinder;
} }
@Override
public boolean onUnbind(Intent intent) {
return super.onUnbind(intent);
}
@Override @Override
public void onDestroy() { public void onDestroy() {
worker.stop(); worker.stop();
@@ -85,15 +80,9 @@ public class ColorService extends Service {
DataCallback dataCallback = new DataCallback() { DataCallback dataCallback = new DataCallback() {
@Override @Override
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) { public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
JSONObject resp = null;
try { try {
resp = new JSONObject(new String(bb.getAllByteArray())); JSONObject resp = new JSONObject(new String(bb.getAllByteArray()));
} catch (JSONException e) {
e.printStackTrace();
}
if (resp != null) {
try {
if (sendableHashMap.containsKey(resp.getString("ref"))) { if (sendableHashMap.containsKey(resp.getString("ref"))) {
sendableHashMap.get(resp.getString("ref")).onResponse(resp); sendableHashMap.get(resp.getString("ref")).onResponse(resp);
sendableHashMap.remove(resp.getString("ref")); sendableHashMap.remove(resp.getString("ref"));
@@ -105,7 +94,6 @@ public class ColorService extends Service {
e.printStackTrace(); e.printStackTrace();
} }
} }
}
}; };
public Worker(LinkedBlockingQueue<T> workQueue) { public Worker(LinkedBlockingQueue<T> workQueue) {
@@ -122,36 +110,36 @@ public class ColorService extends Service {
final T item = workQueue.take(); final T item = workQueue.take();
if (item instanceof Sendable) { if (item instanceof Sendable) {
if (socketHashMap.containsKey(((Sendable) item).getRecipient()) && socketHashMap.get(((Sendable) item).getRecipient()) final Sendable sendable = (Sendable) item;
.getServer().isRunning()) { if (socketHashMap.containsKey(sendable.getRecipient()) && socketHashMap.get(sendable.getRecipient()).getServer().isRunning
()) {
Util.writeAll(socketHashMap.get(((Sendable) item).getRecipient()), (((Sendable) item).getMessage().toString() + "\n") Util.writeAll(socketHashMap.get(sendable.getRecipient()), (sendable.getMessage().toString() + "\n").getBytes("UTF-8"),
.getBytes null);
("UTF-8"), null); sendableHashMap.put(sendable.getRef(), sendable);
sendableHashMap.put(((Sendable) item).getRef(), (Sendable) item);
if (!poolExecutor.isTerminating() && !poolExecutor.isTerminated()) if (!poolExecutor.isTerminating() && !poolExecutor.isTerminated())
timeoutHashMap.put(((Sendable) item).getRef(), poolExecutor.schedule(new Runnable() { timeoutHashMap.put(sendable.getRef(), poolExecutor.schedule(new Runnable() {
@Override @Override
public void run() { public void run() {
((Sendable) item).onNoResponse(); sendable.onNoResponse();
timeoutHashMap.remove(((Sendable) item).getRef()); timeoutHashMap.remove(sendable.getRef());
sendableHashMap.remove(((Sendable) item).getRef()); sendableHashMap.remove(sendable.getRef());
} }
}, 1000, TimeUnit.MILLISECONDS)); }, 1000, TimeUnit.MILLISECONDS));
} else { } else {
AsyncServer.getDefault().connectSocket(new InetSocketAddress(((Sendable) item).getRecipient().getAddress(), ((Sendable) AsyncServer.getDefault().connectSocket(new InetSocketAddress(sendable.getRecipient().getAddress(), sendable
item).getRecipient().getPort()), new ConnectCallback() { .getRecipient().getPort()), new ConnectCallback() {
@Override @Override
public void onConnectCompleted(Exception ex, final AsyncSocket socket) { public void onConnectCompleted(Exception ex, final AsyncSocket socket) {
if (ex == null) { if (ex == null) {
socket.setDataCallback(dataCallback); 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); workQueue.add(item);
} else { } 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 class ColorBinder extends Binder {
public String queueSend(LedDDaemon rec, JSONObject msg, AnswerTask answerTask) throws JSONException { public void queueSend(LedDDaemon rec, JSONObject msg, AnswerTask answerTask) {
Sendable sendable = new Sendable(msg, answerTask, rec); Sendable sendable = null;
try {
sendable = new Sendable(msg, answerTask, rec);
} catch (JSONException e) {
e.printStackTrace();
}
if (sendable != null) {
queue.add(sendable); queue.add(sendable);
return sendable.getRef(); }
} }
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 953 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 228 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 721 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 594 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 108 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 517 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 288 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 963 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 269 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 130 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 432 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 402 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 133 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 624 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 373 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 551 B

View File

@@ -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" />

View File

@@ -46,7 +46,7 @@
android:layout_marginLeft="7dp" android:layout_marginLeft="7dp"
android:layout_toRightOf="@id/img_host" android:layout_toRightOf="@id/img_host"
android:gravity="center" android:gravity="center"
android:text="Add Controller" android:text="@string/text_add_controller"
android:textAppearance="?android:textAppearanceMedium" android:textAppearance="?android:textAppearanceMedium"
/> />
</RelativeLayout> </RelativeLayout>
@@ -62,7 +62,7 @@
android:id="@+id/input_i2c" android:id="@+id/input_i2c"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="i2c device number" android:hint="@string/hint_i2c_device"
android:inputType="number" android:inputType="number"
android:minWidth="350dp"/> android:minWidth="350dp"/>
@@ -79,7 +79,7 @@
android:id="@+id/input_address" android:id="@+id/input_address"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="controller address in hex format" android:hint="@string/hint_controller_address"
android:minWidth="350dp"/> android:minWidth="350dp"/>
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
@@ -95,7 +95,7 @@
android:id="@+id/input_channel" android:id="@+id/input_channel"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="channels" android:hint="@string/hint_channels"
android:inputType="number" android:inputType="number"
android:minWidth="350dp"/> android:minWidth="350dp"/>

View File

@@ -80,7 +80,7 @@
android:layout_marginBottom="5dp" android:layout_marginBottom="5dp"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:text="or" android:text="@string/text_or"
android:textAppearance="?android:textAppearanceMedium"/> android:textAppearance="?android:textAppearanceMedium"/>
<android.support.design.widget.TextInputLayout <android.support.design.widget.TextInputLayout
@@ -93,7 +93,7 @@
android:id="@+id/input_ip" android:id="@+id/input_ip"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="ip address[:port]" android:hint="@string/hint_daemon_ip_port"
android:minWidth="250dp"/> android:minWidth="250dp"/>
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>

View File

@@ -46,7 +46,7 @@
android:layout_marginLeft="7dp" android:layout_marginLeft="7dp"
android:layout_toRightOf="@id/img_host" android:layout_toRightOf="@id/img_host"
android:gravity="center" android:gravity="center"
android:text="Choose Daemon" android:text="@string/text_choose_daemon"
android:textAppearance="?android:textAppearanceSmall" android:textAppearance="?android:textAppearanceSmall"
/> />
@@ -99,7 +99,7 @@
android:layout_marginLeft="7dp" android:layout_marginLeft="7dp"
android:layout_toRightOf="@id/img_controller" android:layout_toRightOf="@id/img_controller"
android:gravity="center" android:gravity="center"
android:text="Choose Controller" android:text="@string/text_choose_controller"
android:textAppearance="?android:textAppearanceSmall" android:textAppearance="?android:textAppearanceSmall"
/> />
@@ -151,7 +151,7 @@
android:layout_marginLeft="7dp" android:layout_marginLeft="7dp"
android:layout_toRightOf="@id/img_stripe" android:layout_toRightOf="@id/img_stripe"
android:gravity="center" android:gravity="center"
android:text="Stripe Properties" android:text="@string/text_stripe_properties"
android:textAppearance="?android:textAppearanceSmall" android:textAppearance="?android:textAppearanceSmall"
/> />
@@ -169,7 +169,7 @@
android:id="@+id/input_stripe_name" android:id="@+id/input_stripe_name"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="Stripe name" android:hint="@string/hint_stripe_name"
android:inputType="text" android:inputType="text"
android:minEms="12"/> android:minEms="12"/>
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
@@ -180,7 +180,7 @@
android:layout_marginLeft="9dp" android:layout_marginLeft="9dp"
android:layout_marginTop="15dp" android:layout_marginTop="15dp"
android:gravity="center" android:gravity="center"
android:text="Channel Mapping" android:text="@string/text_channel_mapping"
android:textAppearance="?android:textAppearanceSmall" android:textAppearance="?android:textAppearanceSmall"
/> />
@@ -206,7 +206,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ems="2" android:ems="2"
android:hint="R" android:hint="@string/hint_channel_r"
android:inputType="number"/> android:inputType="number"/>
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
@@ -231,7 +231,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ems="2" android:ems="2"
android:hint="G" android:hint="@string/hint_channel_g"
android:inputType="number"/> android:inputType="number"/>
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
@@ -256,7 +256,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ems="2" android:ems="2"
android:hint="B" android:hint="@string/hint_channel_b"
android:inputType="number"/> android:inputType="number"/>
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>

View File

@@ -41,7 +41,7 @@
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:clickable="true" android:clickable="true"
android:gravity="center_vertical" android:gravity="center_vertical"
android:text="textHost" android:text=""
android:textAppearance="?android:textAppearanceMedium" android:textAppearance="?android:textAppearanceMedium"
android:textColor="@color/primaryColorDark"/> android:textColor="@color/primaryColorDark"/>

View File

@@ -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>

View File

@@ -23,13 +23,13 @@
android:id="@+id/nv_add_stripe" android:id="@+id/nv_add_stripe"
android:icon="@drawable/ic_add_circle_black_48dp" android:icon="@drawable/ic_add_circle_black_48dp"
android:orderInCategory="51" android:orderInCategory="51"
android:title="Add Stripe"/> android:title="@string/text_add_stripe"/>
<item <item
android:id="@+id/nv_settings" android:id="@+id/nv_settings"
android:icon="@drawable/ic_tune_black_48dp" android:icon="@drawable/ic_tune_black_48dp"
android:orderInCategory="52" android:orderInCategory="52"
android:title="Settings"/> android:title="@string/test_settings"/>
</menu> </menu>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -19,9 +19,5 @@
<resources> <resources>
<!-- Default screen margins, per the Android Design guidelines. --> <!-- 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> </resources>

View File

@@ -20,8 +20,21 @@
<resources> <resources>
<string name="app_name">LedD</string> <string name="app_name">LedD</string>
<string name="button_label">OK</string> <string name="text_add_controller">Add Controller</string>
<string name="pref_name">Pick a color</string> <string name="hint_i2c_device">i2c device number</string>
<string name="pref_summary">DialogPreference with Color Picker.</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> </resources>