moved some stuff around
avoid flicker of stripe when selected in app
This commit is contained in:
@@ -40,6 +40,10 @@ android {
|
|||||||
compileSdkVersion 23
|
compileSdkVersion 23
|
||||||
buildToolsVersion '23.0.1'
|
buildToolsVersion '23.0.1'
|
||||||
|
|
||||||
|
lintOptions {
|
||||||
|
abortOnError false
|
||||||
|
}
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.idlegandalf.ledd"
|
applicationId "com.idlegandalf.ledd"
|
||||||
minSdkVersion 17
|
minSdkVersion 17
|
||||||
|
@@ -79,8 +79,8 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
|
|||||||
private refreshDaemonsListener daemonsListener;
|
private refreshDaemonsListener daemonsListener;
|
||||||
private List<LedStripe> ledStripes;
|
private List<LedStripe> ledStripes;
|
||||||
private LedStripe mCurrentStripe;
|
private LedStripe mCurrentStripe;
|
||||||
private LedDHelper mCurrentHelper;
|
|
||||||
private boolean fromOnCreate = true;
|
private boolean fromOnCreate = true;
|
||||||
|
private boolean autoColorSet = false;
|
||||||
private double rate = 5.0;
|
private double rate = 5.0;
|
||||||
private double per = 100.0;
|
private double per = 100.0;
|
||||||
private double allowance = rate;
|
private double allowance = rate;
|
||||||
@@ -111,8 +111,8 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
|
|||||||
colorPicker.setOnColorChangedListener(new ColorPicker.OnColorChangedListener() {
|
colorPicker.setOnColorChangedListener(new ColorPicker.OnColorChangedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onColorChanged(int i) {
|
public void onColorChanged(int i) {
|
||||||
if (mCurrentStripe != null && mCurrentHelper != null && isRateAcceptable() && aSwitch.isChecked()) {
|
if (mCurrentStripe != null && isRateAcceptable() && aSwitch.isChecked() && !autoColorSet) {
|
||||||
setStripeFromColor(i);
|
mCurrentStripe.setColor(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -183,15 +183,14 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
|
|||||||
|
|
||||||
@OnCheckedChanged(R.id.switch_onoff)
|
@OnCheckedChanged(R.id.switch_onoff)
|
||||||
public void onOffToggle(boolean checked) {
|
public void onOffToggle(boolean checked) {
|
||||||
if (mCurrentStripe != null && mCurrentHelper != null) {
|
if (mCurrentStripe != null) {
|
||||||
if (!checked) {
|
if (!checked) {
|
||||||
HSV nHSV = mCurrentStripe.getColor();
|
HSV nHSV = mCurrentStripe.getColor();
|
||||||
nHSV.setValue(0.0);
|
nHSV.setValue(0.0);
|
||||||
mCurrentStripe.setColor(nHSV);
|
mCurrentStripe.setColor(nHSV);
|
||||||
mCurrentHelper.setColor(mCurrentStripe);
|
|
||||||
//colorPicker.setColor(Color.HSVToColor(new float[]{(float) nHSV.getHue(), (float) nHSV.getSaturation(), (float) nHSV.getValue()}));
|
//colorPicker.setColor(Color.HSVToColor(new float[]{(float) nHSV.getHue(), (float) nHSV.getSaturation(), (float) nHSV.getValue()}));
|
||||||
} else {
|
} else {
|
||||||
setStripeFromColor(colorPicker.getColor());
|
mCurrentStripe.setColor(colorPicker.getColor());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -342,11 +341,11 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
|
|||||||
|
|
||||||
private void selectStripe(LedStripe stripe) {
|
private void selectStripe(LedStripe stripe) {
|
||||||
mCurrentStripe = stripe;
|
mCurrentStripe = stripe;
|
||||||
mCurrentHelper = ColorApplication.getInstance().getHelperForDaemon(stripe.getLedDDaemon());
|
|
||||||
|
|
||||||
mDrawerLayout.closeDrawer(Gravity.LEFT);
|
mDrawerLayout.closeDrawer(Gravity.LEFT);
|
||||||
toolbar.setTitle(stripe.getName());
|
toolbar.setTitle(stripe.getName());
|
||||||
mCurrentHelper.getColor(mCurrentStripe, new RecieveColorCallback() {
|
autoColorSet = true;
|
||||||
|
mCurrentStripe.getColor(new RecieveColorCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onColorRecieved(LedStripe stripe) {
|
public void onColorRecieved(LedStripe stripe) {
|
||||||
final HSV cColor = stripe.getColor();
|
final HSV cColor = stripe.getColor();
|
||||||
@@ -356,6 +355,8 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
colorPicker.setColor(color);
|
colorPicker.setColor(color);
|
||||||
|
autoColorSet = false;
|
||||||
|
|
||||||
if (cColor.getValue() == 0.0) {
|
if (cColor.getValue() == 0.0) {
|
||||||
aSwitch.setChecked(false);
|
aSwitch.setChecked(false);
|
||||||
} else {
|
} else {
|
||||||
@@ -394,13 +395,6 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setStripeFromColor(int color) {
|
|
||||||
float[] hsv = new float[3];
|
|
||||||
Color.colorToHSV(color, hsv);
|
|
||||||
mCurrentStripe.setColor(new HSV(hsv[0], hsv[1], hsv[2]));
|
|
||||||
mCurrentHelper.setColor(mCurrentStripe);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class refreshDaemonsListener extends BroadcastReceiver {
|
protected class refreshDaemonsListener extends BroadcastReceiver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -18,6 +18,13 @@
|
|||||||
|
|
||||||
package com.idlegandalf.ledd.components;
|
package com.idlegandalf.ledd.components;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
|
|
||||||
|
import com.idlegandalf.ledd.ColorApplication;
|
||||||
|
import com.idlegandalf.ledd.callbacks.RecieveColorCallback;
|
||||||
|
import com.idlegandalf.ledd.helper.LedDHelper;
|
||||||
|
|
||||||
|
import hugo.weaving.DebugLog;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@@ -34,6 +41,7 @@ public class LedStripe {
|
|||||||
boolean RGB;
|
boolean RGB;
|
||||||
Controller controller;
|
Controller controller;
|
||||||
LedDDaemon ledDDaemon;
|
LedDDaemon ledDDaemon;
|
||||||
|
LedDHelper helper;
|
||||||
|
|
||||||
public LedStripe() {
|
public LedStripe() {
|
||||||
this(-1, -1, -1, -1, "");
|
this(-1, -1, -1, -1, "");
|
||||||
@@ -60,4 +68,31 @@ public class LedStripe {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%s<-%s@%s (r=%d;g=%d;b=%d)", name, controller.getAddress(), ledDDaemon, channelRed, channelGreen, channelBlue);
|
return String.format("%s<-%s@%s (r=%d;g=%d;b=%d)", name, controller.getAddress(), ledDDaemon, channelRed, channelGreen, channelBlue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DebugLog
|
||||||
|
public void setColor(int color) {
|
||||||
|
float[] hsv = new float[3];
|
||||||
|
Color.colorToHSV(color, hsv);
|
||||||
|
setColor(new HSV(hsv[0], hsv[1], hsv[2]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(HSV color) {
|
||||||
|
checkHelper();
|
||||||
|
this.color = color;
|
||||||
|
|
||||||
|
helper.setColor(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkHelper() {
|
||||||
|
if (helper == null) {
|
||||||
|
helper = ColorApplication.getInstance().getHelperForDaemon(ledDDaemon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DebugLog
|
||||||
|
public void getColor(RecieveColorCallback callback) {
|
||||||
|
checkHelper();
|
||||||
|
|
||||||
|
helper.getColor(this, callback);
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user