Upgraded gradle parts to latest

Switched to another fork of the holo-color-picker
Switched to MaterialDrawer due NavigationView is still very buggy and much more limited
General cleanup
Version bump to 1.0.3
This commit is contained in:
2016-03-17 20:38:16 +01:00
parent 9a3b955d32
commit 9ff32af9f1
23 changed files with 408 additions and 358 deletions

View File

@@ -28,7 +28,7 @@ buildscript {
dependencies { dependencies {
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1' classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.11.3' classpath 'com.github.ben-manes:gradle-versions-plugin:0.12.0'
} }
} }
@@ -46,10 +46,10 @@ android {
defaultConfig { defaultConfig {
applicationId "com.idlegandalf.ledd" applicationId "com.idlegandalf.ledd"
minSdkVersion 17 minSdkVersion 18
targetSdkVersion 23 targetSdkVersion 23
versionCode 2 versionCode 3
versionName "1.0.1" versionName "1.0.3"
} }
buildTypes { buildTypes {
release { release {
@@ -66,15 +66,18 @@ android {
dependencies { dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs') compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:support-v4:23.1.1' compile 'com.android.support:support-v4:23.2.1'
compile 'com.squareup.okhttp:okhttp:2.5.0' compile 'com.squareup.okhttp:okhttp:2.7.5'
compile 'com.google.code.gson:gson:2.4' compile 'com.google.code.gson:gson:2.6.2'
compile 'com.jakewharton:butterknife:7.0.1' compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.koushikdutta.async:androidasync:2.1.6' compile 'com.koushikdutta.async:androidasync:2.1.7'
compile 'com.android.support:design:23.1.1' compile 'com.android.support:design:23.2.1'
compile 'com.larswerkman:HoloColorPicker:1.5@aar' compile 'com.larswerkman:HoloColorPicker:1.5@aar'
compile 'com.google.guava:guava:19.0-rc2' compile 'com.google.guava:guava:19.0'
compile 'com.thetransactioncompany:jsonrpc2-base:1.38' compile 'com.thetransactioncompany:jsonrpc2-base:1.38'
provided 'org.projectlombok:lombok:1.16.6' compile('com.mikepenz:materialdrawer:5.1.4@aar') {
transitive = true
}
provided 'org.projectlombok:lombok:1.16.8'
} }

Binary file not shown.

View File

@@ -25,6 +25,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-feature android:glEsVersion="0x00030000" android:required="true" />
<application <application
android:name=".ColorApplication" android:name=".ColorApplication"

View File

@@ -22,26 +22,20 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.res.Configuration;
import android.graphics.Color; import android.graphics.Color;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View; import android.view.View;
import android.widget.Switch; import android.widget.CompoundButton;
import android.widget.TextView; import android.widget.LinearLayout;
import com.idlegandalf.ledd.callbacks.RecieveColorCallback; import com.idlegandalf.ledd.callbacks.RecieveColorCallback;
import com.idlegandalf.ledd.callbacks.StripesCallback; import com.idlegandalf.ledd.callbacks.StripesCallback;
@@ -54,42 +48,43 @@ import com.idlegandalf.ledd.utils.RateLimiter;
import com.larswerkman.holocolorpicker.ColorPicker; import com.larswerkman.holocolorpicker.ColorPicker;
import com.larswerkman.holocolorpicker.SaturationBar; import com.larswerkman.holocolorpicker.SaturationBar;
import com.larswerkman.holocolorpicker.ValueBar; import com.larswerkman.holocolorpicker.ValueBar;
import com.mikepenz.materialdrawer.Drawer;
import com.mikepenz.materialdrawer.DrawerBuilder;
import com.mikepenz.materialdrawer.holder.BadgeStyle;
import com.mikepenz.materialdrawer.interfaces.OnCheckedChangeListener;
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
import com.mikepenz.materialdrawer.model.SecondarySwitchDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import butterknife.Bind; import butterknife.Bind;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnCheckedChanged;
import hugo.weaving.DebugLog; import hugo.weaving.DebugLog;
public class ColorActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { public class ColorActivity extends AppCompatActivity implements Drawer.OnDrawerItemClickListener, OnCheckedChangeListener {
@Bind(R.id.drawer_layout) @Bind(R.id.main_layout)
DrawerLayout mDrawerLayout; LinearLayout scrollView;
@Bind(R.id.toolbar) @Bind(R.id.toolbar)
Toolbar toolbar; Toolbar toolbar;
@Bind(R.id.drawer)
NavigationView navigationView;
@Bind(R.id.picker) @Bind(R.id.picker)
ColorPicker colorPicker; ColorPicker colorPicker;
@Bind(R.id.saturationbar) @Bind(R.id.saturationbar)
SaturationBar saturationBar; SaturationBar saturationBar;
@Bind(R.id.valuebar) @Bind(R.id.valuebar)
ValueBar valueBar; ValueBar valueBar;
@Bind(R.id.switch_onoff) Drawer mDrawer;
Switch aSwitch; private List<IDrawerItem> mDaemons;
TextView mStripeName;
TextView mStripeMapping;
TextView mStripeType;
TextView mStripeHex;
private ActionBarDrawerToggle mDrawerToggle;
private refreshDaemonsListener daemonsListener; private refreshDaemonsListener daemonsListener;
private List<LedStripe> ledStripes; private List<LedStripe> ledStripes;
private LedStripe mCurrentStripe; private LedStripe mCurrentStripe;
private boolean fromOnCreate = true; private boolean fromOnCreate = true;
private boolean autoColorSet = false; private boolean autoColorSet = false;
private RateLimiter limiter; private RateLimiter limiter;
private View headerLayout; private boolean isRefreshRunning = false;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -97,21 +92,11 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
setContentView(R.layout.activity_color); setContentView(R.layout.activity_color);
ButterKnife.bind(this); ButterKnife.bind(this);
headerLayout = navigationView.getHeaderView(0);
mStripeName = ButterKnife.findById(headerLayout, R.id.nvh_name);
System.out.println("name: " + mStripeName.getText().toString());
mStripeType = ButterKnife.findById(headerLayout, R.id.nvh_type);
System.out.println("type: " + mStripeType.getText().toString());
mStripeHex = ButterKnife.findById(headerLayout, R.id.nvh_hex_color);
System.out.println("hex: " + mStripeHex.getText().toString());
mStripeMapping = ButterKnife.findById(headerLayout, R.id.nvh_mapping);
System.out.println("mapping: " + mStripeMapping.getText().toString());
// 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() || networkInfo.getType() != ConnectivityManager.TYPE_WIFI) { if (networkInfo == null || !networkInfo.isConnected() || networkInfo.getType() != ConnectivityManager.TYPE_WIFI) {
Snackbar.make(mDrawerLayout, R.string.snackbar_no_wlan, Snackbar.LENGTH_INDEFINITE).setAction("RETRY", new View.OnClickListener() { Snackbar.make(scrollView, R.string.snackbar_no_wlan, Snackbar.LENGTH_INDEFINITE).setAction("RETRY", new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
refreshStripes(); refreshStripes();
@@ -119,6 +104,7 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
}).show(); }).show();
} }
mDaemons = new ArrayList<>();
limiter = new RateLimiter(5.0, 100.0); limiter = new RateLimiter(5.0, 100.0);
colorPicker.addSaturationBar(saturationBar); colorPicker.addSaturationBar(saturationBar);
@@ -128,37 +114,30 @@ 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 && limiter.check() && aSwitch.isChecked() && !autoColorSet) { if (mCurrentStripe != null && limiter.check() && !autoColorSet) {
mCurrentStripe.setColor(i); mCurrentStripe.setColor(i);
mStripeHex.setText(String.format("#%06X", (0xFFFFFF & i)));
} }
} }
}); });
navigationView.setNavigationItemSelectedListener(this);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
toolbar.setTitle(R.string.app_name); toolbar.setTitle(R.string.app_name);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.app_name, R.string.app_name) { mDrawer = new DrawerBuilder()
.withActivity(this)
.withToolbar(toolbar)
.withOnDrawerItemClickListener(this)
.addStickyDrawerItems(
new PrimaryDrawerItem().withName(R.string.text_add_stripe).withTag("add_stripe").withSelectable(false),
new PrimaryDrawerItem().withName(R.string.text_settings).withTag("settings").withSelectable(false)
)
.build();
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
// TODO: do things that have to be done here
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
// TODO: do things that have to be done here
}
};
// set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
// enable Homebutton navigation to drawer // enable Homebutton navigation to drawer
if (getSupportActionBar() != null) { if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(true); mDrawer.getActionBarDrawerToggle().setDrawerIndicatorEnabled(true);
} }
daemonsListener = new refreshDaemonsListener(); daemonsListener = new refreshDaemonsListener();
@@ -173,46 +152,43 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
return true; return true;
} }
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle, if it returns
// true, then it has handled the app icon touch event
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle your other action bar items...
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@OnCheckedChanged(R.id.switch_onoff) @Override
public void onOffToggle(boolean checked) { protected void onRestart() {
if (mCurrentStripe != null) { super.onRestart();
if (!checked) { refreshStripes();
HSV nHSV = mCurrentStripe.getColor(); }
if (nHSV != null) {
nHSV.setValue(0.0); @Override
mCurrentStripe.setColor(nHSV); public void onCheckedChanged(IDrawerItem drawerItem, CompoundButton buttonView, boolean isChecked) {
} else { LedStripe stripe = null;
mCurrentStripe.setColor(Color.BLACK); for (LedStripe ledStripe : ledStripes) {
if (((int) drawerItem.getTag()) == ledStripe.getId()) {
stripe = ledStripe;
break;
}
}
if (stripe != null) {
if (isChecked) {
if (stripe == mCurrentStripe) {
if (colorPicker.getColor() != Color.BLACK)
stripe.setColor(colorPicker.getColor());
else {
colorPicker.setColor(Color.WHITE);
} }
//colorPicker.setColor(Color.HSVToColor(new float[]{(float) nHSV.getHue(), (float) nHSV.getSaturation(), (float) nHSV.getValue()}));
} else { } else {
mCurrentStripe.setColor(colorPicker.getColor()); stripe.setColor(Color.WHITE);
}
} else {
if (stripe == mCurrentStripe)
colorPicker.setColor(Color.BLACK);
else
stripe.setColor(Color.BLACK);
} }
} }
} }
@@ -220,10 +196,10 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) { if (keyCode == KeyEvent.KEYCODE_MENU) {
if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) { if (mDrawer.isDrawerOpen()) {
mDrawerLayout.closeDrawer(Gravity.LEFT); mDrawer.closeDrawer();
} else { } else {
mDrawerLayout.openDrawer(Gravity.LEFT); mDrawer.openDrawer();
} }
return true; return true;
@@ -237,7 +213,8 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
ColorApplication.getInstance().teardown(); ColorApplication.getInstance().teardown();
unregisterReceiver(daemonsListener); unregisterReceiver(daemonsListener);
if (mCurrentStripe != null) PreferenceManager.getDefaultSharedPreferences(this).edit().putInt("lastStripe", mCurrentStripe.getId()).commit(); if (mCurrentStripe != null)
PreferenceManager.getDefaultSharedPreferences(this).edit().putInt("lastStripe", mCurrentStripe.getId()).commit();
} }
@Override @Override
@@ -258,68 +235,134 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
} }
} }
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
int id = menuItem.getItemId();
switch (id) { @Override
case R.id.nv_add_stripe: public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if (drawerItem.isSelectable()) {
if (drawerItem.getTag() instanceof String) {
String tag = (String) drawerItem.getTag();
if (tag.equals("add_stripe")) {
new AddStripeDialog().show(getFragmentManager(), ""); new AddStripeDialog().show(getFragmentManager(), "");
return true; return true;
case R.id.nv_settings: } else if (tag.equals("settings")) {
return true; return true;
} }
}
if (drawerItem.getTag() instanceof Integer) {
int tag = (int) drawerItem.getTag();
for (LedStripe stripe : ledStripes) { for (LedStripe stripe : ledStripes) {
if (stripe.getName().equals(menuItem.getTitle())) { if (tag == stripe.getId()) {
selectStripe(stripe); selectStripe(stripe);
return true; return true;
} }
} }
}
}
return false; return false;
} }
public void refreshStripes() { public void refreshStripes() {
reCreateNavigationView(); // need to recreate the navigationview since we can't remove a once added submenu if (isRefreshRunning)
return;
final Menu nvMenu = navigationView.getMenu(); isRefreshRunning = true;
final int stripeGroup = 42;
int i = 1; int i = 1;
for (final LedDDaemon dDaemon : ColorApplication.getInstance().getDaemons()) { for (final LedDDaemon dDaemon : ColorApplication.getInstance().getDaemons()) {
LedDHelper helper = ColorApplication.getInstance().getHelperForDaemon(dDaemon); LedDHelper helper = ColorApplication.getInstance().getHelperForDaemon(dDaemon);
if (helper != null) { if (helper != null) {
final int finalI = i; final int finalI = i;
helper.getStripes(new StripesCallback() { helper.getStripes(new StripesCallback() {
@Override @Override
public void onSuccess(final List<LedStripe> stripes) { public void onSuccess(List<LedStripe> stripes) {
ledStripes = stripes;
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
SubMenu nDaemonMenu = nvMenu.addSubMenu(Menu.NONE, Menu.NONE, finalI, dDaemon.toString()); PrimaryDrawerItem nDaemonMenu = null;
nDaemonMenu.setGroupCheckable(stripeGroup, true, true); long selectedItemId = -1;
for (IDrawerItem drawerItem : mDaemons) {
if (((PrimaryDrawerItem) drawerItem).getName().getText().equals(dDaemon.toString())) {
nDaemonMenu = (PrimaryDrawerItem) drawerItem;
break;
}
}
if (nDaemonMenu == null) {
nDaemonMenu = new PrimaryDrawerItem().withName(dDaemon.toString()).withTag(finalI).withSelectable(false).withIsExpanded(true);
mDrawer.addItem(nDaemonMenu);
mDaemons.add(nDaemonMenu);
}
int lastStripeId = -1; int lastStripeId = -1;
if (PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).contains("lastStripe")) { if (PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).contains("lastStripe")) {
lastStripeId = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getInt("lastStripe", -1); lastStripeId = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getInt("lastStripe", -1);
} }
ledStripes = stripes; List<IDrawerItem> mStripes = new ArrayList<>();
for (LedStripe stripe : ledStripes) { for (LedStripe stripe : ledStripes) {
MenuItem sItem = nDaemonMenu.add(stripeGroup, View.generateViewId(), stripe.getId(), stripe.getName()); final SecondarySwitchDrawerItem sItem = new SecondarySwitchDrawerItem()
sItem.setIcon(R.drawable.ic_wb_iridescent_black_48dp); .withName(stripe.getName())
.withTag(stripe.getId())
.withIcon(R.drawable.ic_wb_iridescent_black_48dp)
.withOnCheckedChangeListener(ColorActivity.this);
mStripes.add(sItem);
if (lastStripeId != -1 && stripe.getId() == lastStripeId) { if (lastStripeId != -1 && stripe.getId() == lastStripeId) {
selectStripe(stripe); selectStripe(stripe);
selectedItemId = sItem.getIdentifier();
} }
} }
nDaemonMenu.withSubItems(mStripes);
nDaemonMenu.withBadge(String.valueOf(mStripes.size()));
nDaemonMenu.withBadgeStyle(new BadgeStyle().withColor(getResources().getColor(R.color.material_drawer_accent)).withTextColor(Color.WHITE));
mDrawer.updateItem(nDaemonMenu);
if (selectedItemId != -1)
mDrawer.setSelection(selectedItemId);
Snackbar.make(findViewById(android.R.id.content), R.string.snackbar_stripes_reloaded, Snackbar.LENGTH_LONG).show(); Snackbar.make(findViewById(android.R.id.content), R.string.snackbar_stripes_reloaded, Snackbar.LENGTH_LONG).show();
} }
}); });
for (LedStripe stripe : ledStripes) {
stripe.getColor(new RecieveColorCallback() {
@Override
public void onConnectionFailed(String message) {
}
@Override
public void onColorRecieved(LedStripe stripe) {
if (stripe.isOn()) {
IDrawerItem sItem = findItemForStripe(stripe);
if (sItem != null) {
final SecondarySwitchDrawerItem cItem = (SecondarySwitchDrawerItem) sItem;
cItem.withSwitchEnabled(true);
runOnUiThread(new Runnable() {
@Override
public void run() {
mDrawer.updateItem(cItem);
}
});
}
}
}
@Override
public void onRecievFailed(int code, String msg) {
}
});
}
} }
@Override @Override
@@ -340,41 +383,20 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
i++; i++;
} }
}
private void reCreateNavigationView() { isRefreshRunning = false;
runOnUiThread(new Runnable() {
@Override
public void run() {
mDrawerLayout.removeView(navigationView);
navigationView = new NavigationView(ColorActivity.this);
DrawerLayout.LayoutParams params = new DrawerLayout.LayoutParams(DrawerLayout.LayoutParams.WRAP_CONTENT, DrawerLayout.LayoutParams
.MATCH_PARENT);
params.gravity = Gravity.START;
navigationView.setLayoutParams(params);
navigationView.inflateMenu(R.menu.navigation_drawer);
navigationView.inflateHeaderView(R.layout.navigation_header);
mDrawerLayout.addView(navigationView, params);
navigationView.setNavigationItemSelectedListener(ColorActivity.this);
mDrawerToggle.syncState();
}
});
} }
@DebugLog @DebugLog
private void selectStripe(LedStripe stripe) { private void selectStripe(LedStripe stripe) {
mCurrentStripe = stripe; mCurrentStripe = stripe;
mStripeName.setText(stripe.getName());
System.out.println("name: " + mStripeName.getText().toString());
mStripeMapping.setText(String.format("R: %d - G: %d - B: %d", stripe.getChannelRed(), stripe.getChannelGreen(), stripe.getChannelBlue()));
headerLayout.invalidate();
mDrawerLayout.closeDrawer(Gravity.LEFT);
toolbar.setTitle(stripe.getName()); toolbar.setTitle(stripe.getName());
autoColorSet = true; autoColorSet = true;
mDrawer.closeDrawer();
mCurrentStripe.getColor(new RecieveColorCallback() { mCurrentStripe.getColor(new RecieveColorCallback() {
@Override @Override
public void onColorRecieved(LedStripe stripe) { public void onColorRecieved(final LedStripe stripe) {
final HSV cColor = stripe.getColor(); final HSV cColor = stripe.getColor();
final int color = Color.HSVToColor(new float[]{(float) cColor.getHue(), (float) cColor.getSaturation(), (float) cColor.getValue()}); final int color = Color.HSVToColor(new float[]{(float) cColor.getHue(), (float) cColor.getSaturation(), (float) cColor.getValue()});
@@ -384,10 +406,11 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
colorPicker.setColor(color); colorPicker.setColor(color);
autoColorSet = false; autoColorSet = false;
if (cColor.getValue() == 0.0) { if (stripe.isOn()) {
aSwitch.setChecked(false); IDrawerItem fItem = findItemForStripe(stripe);
} else {
aSwitch.setChecked(true); if (fItem != null)
((SecondarySwitchDrawerItem) fItem).withSwitchEnabled(true);
} }
} }
}); });
@@ -414,4 +437,19 @@ public class ColorActivity extends AppCompatActivity implements NavigationView.O
} }
} }
} }
@DebugLog
private IDrawerItem findItemForStripe(LedStripe stripe) {
for (IDrawerItem dItem : mDaemons) {
if (((PrimaryDrawerItem) dItem).getSubItems() != null) {
for (IDrawerItem sItem : ((PrimaryDrawerItem) dItem).getSubItems()) {
if (((int) sItem.getTag()) == stripe.getId()) {
return sItem;
}
}
}
}
return null;
}
} }

View File

@@ -47,8 +47,8 @@ public class ColorApplication extends Application {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
singleton = this;
singleton = this;
ledDHelpers = new HashMap<>(); ledDHelpers = new HashMap<>();
this.onResume(); this.onResume();
} }

View File

@@ -95,4 +95,9 @@ public class LedStripe {
helper.getColor(this, callback); helper.getColor(this, callback);
} }
@DebugLog
public boolean isOn() {
return color != null && color.getValue() != 0.0;
}
} }

View File

@@ -0,0 +1,146 @@
package com.idlegandalf.ledd.utils;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.opengl.GLES30;
import android.util.Log;
import java.nio.IntBuffer;
public class GraphicUtils {
int fmt;
int w;
int h;
int nBytes;
int[] PBOs;
int numDownloads = 0;
int numPBOs = 0;
int dx = 0;
IntBuffer pixelBuf;
public GraphicUtils(int fmt, int w, int h, int xbuff) {
if (PBOs != null) {
Log.w("LedD", "Already initialized. Not necessary to initialize again; or shutdown first.");
return;
}
if (xbuff < 1 || xbuff > 10) {
Log.w("LedD", "Invalid number of buffers: more then 10 or less then 1 buffer");
return;
}
this.fmt = fmt;
this.w = w;
this.h = h;
this.numPBOs = xbuff;
if (fmt == GLES30.GL_RED || fmt == GLES30.GL_GREEN || fmt == GLES30.GL_BLUE) {
this.nBytes = w * h;
} else if (fmt == GLES30.GL_RGB) {
this.nBytes = w * h * 3;
} else if (fmt == GLES30.GL_RGBA) {
this.nBytes = w * h * 4;
} else {
Log.w("LedD", "Unhandled pixel format, use GL_R, GL_RG, GL_RGB or GL_RGBA.");
}
if (this.nBytes == 0) {
Log.w("LedD", String.format("Invalid width or height given: %d x %d", w, h));
return;
}
PBOs = new int[xbuff];
pixelBuf = IntBuffer.allocate(nBytes);
GLES30.glGenBuffers(xbuff, PBOs, 0);
for (int i = 0; i < xbuff; i++) {
GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, PBOs[i]);
GLES30.glBufferData(GLES30.GL_PIXEL_PACK_BUFFER, nBytes, null, GLES30.GL_STREAM_READ);
}
GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, 0);
}
public void download() {
long curNanos = System.nanoTime();
if (numDownloads < numPBOs) {
GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, PBOs[dx]);
GLES30.glReadPixels(0, 0, w, h, fmt, GLES30.GL_UNSIGNED_BYTE, null);
Log.d("LedD", String.format("glReadPixels() with pbo: %d", PBOs[dx]));
} else {
Log.d("LedD", String.format("glMapBuffer() with pbo: %d", PBOs[dx]));
GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, PBOs[dx]);
GLES30.glBufferData(GLES30.GL_PIXEL_PACK_BUFFER, nBytes, pixelBuf, GLES30.GL_STATIC_READ);
GLES30.glReadPixels(0, 0, w, h, fmt, GLES30.GL_UNSIGNED_BYTE, null);
}
dx++;
dx = dx % numPBOs;
numDownloads++;
if (numDownloads == Integer.MAX_VALUE) {
numDownloads = 0;
}
GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, 0);
Log.d("LedD", String.format("Download took: %f ms.", ((double) System.nanoTime() - curNanos) / 1000000.0));
}
public Bitmap getCurBufferBitmap() {
int[] b = pixelBuf.array();
int[] bt = new int[w * h];
for (int i = 0; i < h; i++) {
//remember, that OpenGL bitmap is incompatible with Android bitmap
//and so, some correction need.
for (int j = 0; j < w; j++) {
int pix = b[i * w + j];
int pb = (pix >> 16) & 0xff;
int pr = (pix << 16) & 0x00ff0000;
int pix1 = (pix & 0xff00ff00) | pr | pb;
bt[(h - i - 1) * w + j] = pix1;
}
}
Bitmap.Config bconfig = Bitmap.Config.RGB_565;
return Bitmap.createBitmap(bt, w, h, bconfig);
}
public int getAvgBitmapBufferColor() {
download();
Bitmap bitmap = getCurBufferBitmap();
int redBucket = 0;
int greenBucket = 0;
int blueBucket = 0;
int alphaBucket = 0;
boolean hasAlpha = bitmap.hasAlpha();
int pixelCount = bitmap.getWidth() * bitmap.getHeight();
int[] pixels = new int[pixelCount];
bitmap.getPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
for (int y = 0, h = bitmap.getHeight(); y < h; y++) {
for (int x = 0, w = bitmap.getWidth(); x < w; x++) {
int color = pixels[x + y * w]; // x + y * width
redBucket += (color >> 16) & 0xFF; // Color.red
greenBucket += (color >> 8) & 0xFF; // Color.greed
blueBucket += (color & 0xFF); // Color.blue
if (hasAlpha) alphaBucket += (color >>> 24); // Color.alpha
}
}
return Color.argb(
(hasAlpha) ? (alphaBucket / pixelCount) : 255,
redBucket / pixelCount,
greenBucket / pixelCount,
blueBucket / pixelCount);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 465 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 573 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 814 B

View File

@@ -16,38 +16,25 @@
~ along with this program. If not, see <http://www.gnu.org/licenses/>. ~ along with this program. If not, see <http://www.gnu.org/licenses/>.
--> -->
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout" <!-- The main content view -->
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:id="@+id/main_layout"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- The main content view -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:orientation="vertical"> android:orientation="vertical">
<android.support.v7.widget.Toolbar <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar" android:id="@+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/colorPrimary" android:background="?attr/colorPrimary"
android:minHeight="?android:attr/actionBarSize"> android:minHeight="?android:attr/actionBarSize"
app:titleTextColor="@android:color/black">
<Switch
android:id="@+id/switch_onoff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"/>
</android.support.v7.widget.Toolbar> </android.support.v7.widget.Toolbar>
@@ -61,7 +48,7 @@
app:color_pointer_halo_radius="13dp" app:color_pointer_halo_radius="13dp"
app:color_pointer_radius="12dp" app:color_pointer_radius="12dp"
app:color_wheel_radius="180dp" app:color_wheel_radius="180dp"
app:color_wheel_thickness="20dp"/> app:color_wheel_thickness="20dp" />
<com.larswerkman.holocolorpicker.SaturationBar <com.larswerkman.holocolorpicker.SaturationBar
android:id="@+id/saturationbar" android:id="@+id/saturationbar"
@@ -72,7 +59,7 @@
android:layout_marginTop="15dp" android:layout_marginTop="15dp"
app:bar_pointer_halo_radius="11dp" app:bar_pointer_halo_radius="11dp"
app:bar_pointer_radius="10dp" app:bar_pointer_radius="10dp"
app:bar_thickness="15dp"/> app:bar_thickness="15dp" />
<com.larswerkman.holocolorpicker.ValueBar <com.larswerkman.holocolorpicker.ValueBar
android:id="@+id/valuebar" android:id="@+id/valuebar"
@@ -81,20 +68,6 @@
android:layout_margin="10dp" android:layout_margin="10dp"
app:bar_pointer_halo_radius="11dp" app:bar_pointer_halo_radius="11dp"
app:bar_pointer_radius="10dp" app:bar_pointer_radius="10dp"
app:bar_thickness="15dp"/> app:bar_thickness="15dp" />
</LinearLayout> </LinearLayout>
</ScrollView>
<!-- The navigation drawer -->
<android.support.design.widget.NavigationView
android:id="@+id/drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/navigation_header"
app:menu="@menu/navigation_drawer"/>
</android.support.v4.widget.DrawerLayout>

View File

@@ -1,35 +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/>.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/nv_add_stripe"
android:icon="@drawable/ic_add_circle_black_48dp"
android:orderInCategory="51"
android:title="@string/text_add_stripe"/>
<item
android:id="@+id/nv_settings"
android:icon="@drawable/ic_tune_black_48dp"
android:orderInCategory="52"
android:title="@string/test_settings"/>
</menu>

View File

@@ -1,29 +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/>.
-->
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>

View File

@@ -1,30 +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/>.
-->
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>

View File

@@ -22,7 +22,7 @@
Base application theme for API 19+. This theme completely replaces Base application theme for API 19+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 19+ devices. AppBaseTheme from res/values/styles.xml on API 19+ devices.
--> -->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar"> <style name="AppBaseTheme" parent="MaterialDrawerTheme.Light.DarkToolbar.TranslucentStatus">
<!-- API 19 theme customizations can go here. --> <!-- API 19 theme customizations can go here. -->
<item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentStatus">true</item>
</style> </style>

View File

@@ -1,30 +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/>.
-->
<resources>
<!--
Base application theme for API 21+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 21+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>

View File

@@ -20,4 +20,5 @@
<resources> <resources>
<color name="primaryColor">#3ae88d</color> <color name="primaryColor">#3ae88d</color>
<color name="primaryColorDark">#327D26</color> <color name="primaryColorDark">#327D26</color>
<!--- <color name="material_drawer_accent">#</color> -->
</resources> </resources>

View File

@@ -35,7 +35,7 @@
<string name="hint_channel_g">G</string> <string name="hint_channel_g">G</string>
<string name="hint_channel_b">B</string> <string name="hint_channel_b">B</string>
<string name="text_add_stripe">Add Stripe</string> <string name="text_add_stripe">Add Stripe</string>
<string name="test_settings">Settings</string> <string name="text_settings">Settings</string>
<string name="snackbar_no_wlan">We currently only support WLAN, please connect to one</string> <string name="snackbar_no_wlan">We currently only support WLAN, please connect to one</string>
<string name="snackbar_stripes_reloaded">LED stripes reloaded</string> <string name="snackbar_stripes_reloaded">LED stripes reloaded</string>
<string name="snackbar_no_connection_stripes">Couldn\'t get stripes from daemon: </string> <string name="snackbar_no_connection_stripes">Couldn\'t get stripes from daemon: </string>

View File

@@ -22,7 +22,7 @@
Base application theme, dependent on API level. This theme is replaced Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices. by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
--> -->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar"> <style name="AppBaseTheme" parent="MaterialDrawerTheme.Light.DarkToolbar.TranslucentStatus">
<!-- <!--
Theme customizations available in newer API levels can go in Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to res/values-vXX/styles.xml, while customizations related to
@@ -37,7 +37,14 @@
<!-- ...and here we setting appcompats color theming attrs --> <!-- ...and here we setting appcompats color theming attrs -->
<item name="colorPrimary">@color/primaryColor</item> <item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryDark">@color/primaryColorDark</item> <item name="colorPrimaryDark">@color/primaryColorDark</item>
<item name="colorAccent">@color/material_drawer_accent</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style> </style>
<style name="DrawerArrowStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@android:color/black</item>
</style>
</resources> </resources>

View File

@@ -23,7 +23,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:1.3.1' classpath 'com.android.tools.build:gradle:2.0.0-beta7'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files