Added icons for the new drawer
Added profiles (not fully completed yet, but it works) Removed some unused icons
@@ -76,7 +76,7 @@ dependencies {
|
||||
compile 'com.larswerkman:HoloColorPicker:1.5@aar'
|
||||
compile 'com.google.guava:guava:19.0'
|
||||
compile 'com.thetransactioncompany:jsonrpc2-base:1.38'
|
||||
compile('com.mikepenz:materialdrawer:5.1.4@aar') {
|
||||
compile('com.mikepenz:materialdrawer:5.1.5@aar') {
|
||||
transitive = true
|
||||
}
|
||||
provided 'org.projectlombok:lombok:1.16.8'
|
||||
|
@@ -27,9 +27,11 @@ import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.SparseArray;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@@ -37,11 +39,15 @@ import android.view.View;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import com.idlegandalf.ledd.callbacks.RecieveColorCallback;
|
||||
import com.idlegandalf.ledd.callbacks.StripesCallback;
|
||||
import com.idlegandalf.ledd.components.HSV;
|
||||
import com.idlegandalf.ledd.components.LedDDaemon;
|
||||
import com.idlegandalf.ledd.components.LedStripe;
|
||||
import com.idlegandalf.ledd.components.Profile;
|
||||
import com.idlegandalf.ledd.fragments.AddProfileDialog;
|
||||
import com.idlegandalf.ledd.fragments.AddStripeDialog;
|
||||
import com.idlegandalf.ledd.helper.LedDHelper;
|
||||
import com.idlegandalf.ledd.utils.RateLimiter;
|
||||
@@ -52,10 +58,13 @@ 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.DividerDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.SecondarySwitchDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -63,7 +72,7 @@ import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import hugo.weaving.DebugLog;
|
||||
|
||||
public class ColorActivity extends AppCompatActivity implements Drawer.OnDrawerItemClickListener, OnCheckedChangeListener {
|
||||
public class ColorActivity extends AppCompatActivity implements Drawer.OnDrawerItemClickListener, Drawer.OnDrawerItemLongClickListener, OnCheckedChangeListener {
|
||||
|
||||
@Bind(R.id.main_layout)
|
||||
LinearLayout scrollView;
|
||||
@@ -79,12 +88,15 @@ public class ColorActivity extends AppCompatActivity implements Drawer.OnDrawerI
|
||||
private List<IDrawerItem> mDaemons;
|
||||
private refreshDaemonsListener daemonsListener;
|
||||
private List<LedStripe> ledStripes;
|
||||
private List<Profile> profiles;
|
||||
private LedStripe mCurrentStripe;
|
||||
private boolean fromOnCreate = true;
|
||||
private boolean autoColorSet = false;
|
||||
private RateLimiter limiter;
|
||||
private boolean isRefreshRunning = false;
|
||||
|
||||
private Type profileList = new TypeToken<List<Profile>>() {
|
||||
}.getType();
|
||||
private PrimaryDrawerItem menuProfiles;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -105,7 +117,7 @@ public class ColorActivity extends AppCompatActivity implements Drawer.OnDrawerI
|
||||
}
|
||||
|
||||
mDaemons = new ArrayList<>();
|
||||
limiter = new RateLimiter(5.0, 100.0);
|
||||
limiter = new RateLimiter(30.0, 1000);
|
||||
|
||||
colorPicker.addSaturationBar(saturationBar);
|
||||
colorPicker.addValueBar(valueBar);
|
||||
@@ -127,12 +139,18 @@ public class ColorActivity extends AppCompatActivity implements Drawer.OnDrawerI
|
||||
.withActivity(this)
|
||||
.withToolbar(toolbar)
|
||||
.withOnDrawerItemClickListener(this)
|
||||
.withOnDrawerItemLongClickListener(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)
|
||||
new PrimaryDrawerItem().withName(R.string.text_add_stripe).withTag("add_stripe").withSelectable(false).withIcon(R.drawable.ic_add_circle_black_48dp),
|
||||
new PrimaryDrawerItem().withName(R.string.text_settings).withTag("settings").withSelectable(false).withIcon(R.drawable.ic_tune_black_48dp)
|
||||
)
|
||||
.addDrawerItems(
|
||||
new DividerDrawerItem(),
|
||||
menuProfiles = new PrimaryDrawerItem().withName("Profiles").withIcon(R.drawable.ic_save_black_48dp).withSelectable(false).withIsExpanded(true)
|
||||
)
|
||||
.build();
|
||||
|
||||
menuProfiles.withSubItems(new SecondaryDrawerItem().withName("Add Profile").withTag("add_profile").withSelectable(false).withIcon(R.drawable.ic_add_circle_outline_black_48dp));
|
||||
|
||||
// enable Homebutton navigation to drawer
|
||||
if (getSupportActionBar() != null) {
|
||||
@@ -140,6 +158,20 @@ public class ColorActivity extends AppCompatActivity implements Drawer.OnDrawerI
|
||||
mDrawer.getActionBarDrawerToggle().setDrawerIndicatorEnabled(true);
|
||||
}
|
||||
|
||||
List<IDrawerItem> subProfiles = menuProfiles.getSubItems();
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this).contains("profiles")) {
|
||||
profiles = new Gson().fromJson(PreferenceManager.getDefaultSharedPreferences(this).getString("profiles", ""), profileList);
|
||||
|
||||
for (Profile profile : profiles) {
|
||||
subProfiles.add(0, new SecondaryDrawerItem().withName(profile.getName()).withTag(profile.getValues()).withSelectable(false).withIcon(R.drawable.ic_note_black_48dp));
|
||||
}
|
||||
} else {
|
||||
profiles = new ArrayList<>();
|
||||
}
|
||||
|
||||
menuProfiles.withSubItems(subProfiles);
|
||||
mDrawer.updateItem(menuProfiles);
|
||||
|
||||
daemonsListener = new refreshDaemonsListener();
|
||||
registerReceiver(daemonsListener, new IntentFilter(ColorApplication.INTENT_ACTION_REFRESH));
|
||||
}
|
||||
@@ -160,6 +192,8 @@ public class ColorActivity extends AppCompatActivity implements Drawer.OnDrawerI
|
||||
@Override
|
||||
protected void onRestart() {
|
||||
super.onRestart();
|
||||
ColorApplication.getInstance().onResume();
|
||||
registerReceiver(daemonsListener, new IntentFilter(ColorApplication.INTENT_ACTION_REFRESH));
|
||||
refreshStripes();
|
||||
}
|
||||
|
||||
@@ -214,7 +248,10 @@ public class ColorActivity extends AppCompatActivity implements Drawer.OnDrawerI
|
||||
unregisterReceiver(daemonsListener);
|
||||
|
||||
if (mCurrentStripe != null)
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit().putInt("lastStripe", mCurrentStripe.getId()).commit();
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit().putInt("lastStripe", mCurrentStripe.getId()).apply();
|
||||
|
||||
if (profiles != null)
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit().putString("profiles", new Gson().toJson(profiles, profileList)).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -236,21 +273,41 @@ public class ColorActivity extends AppCompatActivity implements Drawer.OnDrawerI
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
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")) {
|
||||
switch (tag) {
|
||||
case "add_stripe":
|
||||
new AddStripeDialog().show(getFragmentManager(), "");
|
||||
return true;
|
||||
} else if (tag.equals("settings")) {
|
||||
case "settings":
|
||||
return true;
|
||||
case "add_profile":
|
||||
new AddProfileDialog().show(getFragmentManager(), "");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (drawerItem.getTag() instanceof SparseArray) {
|
||||
SparseArray<HSV> sparseArray = (SparseArray<HSV>) drawerItem.getTag();
|
||||
|
||||
if (ledStripes != null) {
|
||||
for (LedStripe ledStripe : ledStripes) {
|
||||
String json_workaround = new Gson().toJson(sparseArray.get(ledStripe.getId()));
|
||||
HSV nHSV = new Gson().fromJson(json_workaround, new TypeToken<HSV>() {
|
||||
}.getType());
|
||||
|
||||
if (nHSV != null) {
|
||||
ledStripe.setColor(nHSV);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (drawerItem.isSelectable()) {
|
||||
if (drawerItem.getTag() instanceof Integer) {
|
||||
int tag = (int) drawerItem.getTag();
|
||||
|
||||
@@ -265,6 +322,28 @@ public class ColorActivity extends AppCompatActivity implements Drawer.OnDrawerI
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClick(View view, int position, IDrawerItem drawerItem) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<LedStripe> getStripes() {
|
||||
return ledStripes;
|
||||
}
|
||||
|
||||
@DebugLog
|
||||
public void addProfile(Profile profile) {
|
||||
if (profiles != null) {
|
||||
profiles.add(profile);
|
||||
|
||||
List<IDrawerItem> subProfiles = menuProfiles.getSubItems();
|
||||
subProfiles.add(0, new SecondaryDrawerItem().withName(profile.getName()).withSelectable(false).withTag(profile.getValues()));
|
||||
|
||||
menuProfiles.withSubItems(subProfiles);
|
||||
mDrawer.updateItem(menuProfiles);
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshStripes() {
|
||||
if (isRefreshRunning)
|
||||
return;
|
||||
@@ -293,8 +372,8 @@ public class ColorActivity extends AppCompatActivity implements Drawer.OnDrawerI
|
||||
}
|
||||
|
||||
if (nDaemonMenu == null) {
|
||||
nDaemonMenu = new PrimaryDrawerItem().withName(dDaemon.toString()).withTag(finalI).withSelectable(false).withIsExpanded(true);
|
||||
mDrawer.addItem(nDaemonMenu);
|
||||
nDaemonMenu = new PrimaryDrawerItem().withName(dDaemon.toString()).withTag(finalI).withSelectable(false).withIsExpanded(true).withIcon(R.drawable.ic_computer_black_48dp);
|
||||
mDrawer.addItemAtPosition(nDaemonMenu, 0);
|
||||
mDaemons.add(nDaemonMenu);
|
||||
}
|
||||
|
||||
@@ -438,6 +517,7 @@ public class ColorActivity extends AppCompatActivity implements Drawer.OnDrawerI
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@DebugLog
|
||||
private IDrawerItem findItemForStripe(LedStripe stripe) {
|
||||
for (IDrawerItem dItem : mDaemons) {
|
||||
|
@@ -19,6 +19,7 @@
|
||||
package com.idlegandalf.ledd.components;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.idlegandalf.ledd.ColorApplication;
|
||||
import com.idlegandalf.ledd.callbacks.RecieveColorCallback;
|
||||
@@ -90,10 +91,27 @@ public class LedStripe {
|
||||
}
|
||||
|
||||
@DebugLog
|
||||
public void getColor(RecieveColorCallback callback) {
|
||||
public void getColor(@Nullable final RecieveColorCallback callback) {
|
||||
checkHelper();
|
||||
|
||||
helper.getColor(this, callback);
|
||||
helper.getColor(this, new RecieveColorCallback() {
|
||||
@Override
|
||||
public void onColorRecieved(LedStripe stripe) {
|
||||
color = stripe.getColor();
|
||||
if (callback != null)
|
||||
callback.onColorRecieved(LedStripe.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecievFailed(int code, String msg) {
|
||||
if (callback != null) callback.onRecievFailed(code, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionFailed(String message) {
|
||||
if (callback != null) callback.onConnectionFailed(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@DebugLog
|
||||
|
@@ -0,0 +1,22 @@
|
||||
package com.idlegandalf.ledd.components;
|
||||
|
||||
import android.util.SparseArray;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Profile {
|
||||
private SparseArray<HSV> values;
|
||||
private String name;
|
||||
|
||||
public Profile(SparseArray<HSV> hsvHashMap) {
|
||||
setValues(hsvHashMap);
|
||||
}
|
||||
|
||||
public Profile(String name) {
|
||||
setValues(new SparseArray<HSV>());
|
||||
setName(name);
|
||||
}
|
||||
}
|
@@ -0,0 +1,151 @@
|
||||
package com.idlegandalf.ledd.fragments;
|
||||
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.TextInputLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.idlegandalf.ledd.ColorActivity;
|
||||
import com.idlegandalf.ledd.R;
|
||||
import com.idlegandalf.ledd.components.LedStripe;
|
||||
import com.idlegandalf.ledd.components.Profile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import hugo.weaving.DebugLog;
|
||||
|
||||
|
||||
public class AddProfileDialog extends DialogFragment implements DialogInterface.OnShowListener {
|
||||
|
||||
@Bind(R.id.input_profile_name_layout)
|
||||
TextInputLayout nameLayout;
|
||||
@Bind(R.id.input_profile_name)
|
||||
EditText nameText;
|
||||
@Bind(R.id.container_linlay)
|
||||
LinearLayout checkboxContainer;
|
||||
List<LedStripe> mStripes;
|
||||
List<CheckBox> mCheckboxes;
|
||||
|
||||
@DebugLog
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
View v = View.inflate(getActivity(), R.layout.fragment_addprofile, null);
|
||||
ButterKnife.bind(this, v);
|
||||
|
||||
mStripes = ((ColorActivity) getActivity()).getStripes();
|
||||
mCheckboxes = new ArrayList<>();
|
||||
|
||||
for (LedStripe ledStripe : mStripes) {
|
||||
CheckBox nC = (CheckBox) View.inflate(getActivity(), R.layout.fragment_addprofile_item, null);
|
||||
|
||||
nC.setText(ledStripe.getName());
|
||||
mCheckboxes.add(nC);
|
||||
checkboxContainer.addView(nC);
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setView(v).setPositiveButton("Save", null).setNegativeButton("Cancel", null);
|
||||
|
||||
AlertDialog dialog = builder.create();
|
||||
|
||||
dialog.setOnShowListener(this);
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShow(final DialogInterface dialog) {
|
||||
|
||||
final AlertDialog alertDialog = (AlertDialog) dialog;
|
||||
|
||||
nameText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
nameLayout.setError(null);
|
||||
}
|
||||
});
|
||||
|
||||
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (nameText.getText().toString().isEmpty()) {
|
||||
nameLayout.setError("Please enter a name");
|
||||
return;
|
||||
}
|
||||
|
||||
int checked = 0;
|
||||
for (CheckBox c : mCheckboxes) {
|
||||
if (c.isChecked()) {
|
||||
checked++;
|
||||
mStripes.get(checkboxContainer.indexOfChild(c)).getColor();
|
||||
}
|
||||
}
|
||||
|
||||
if (checked < 2) {
|
||||
Toast.makeText(getActivity(), "Please select at least two stripes for your profile", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Profile profile = new Profile(nameText.getText().toString());
|
||||
|
||||
for (CheckBox c : mCheckboxes) {
|
||||
if (c.isChecked()) {
|
||||
LedStripe stripe = mStripes.get(checkboxContainer.indexOfChild(c));
|
||||
profile.getValues().append(stripe.getId(), stripe.getColor());
|
||||
}
|
||||
}
|
||||
|
||||
((ColorActivity) getActivity()).addProfile(profile);
|
||||
Toast.makeText(getActivity(), "Added profile " + nameText.getText().toString(), Toast.LENGTH_SHORT).show();
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -1,146 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 933 B |
Before Width: | Height: | Size: 221 B |
Before Width: | Height: | Size: 347 B |
Before Width: | Height: | Size: 219 B |
Before Width: | Height: | Size: 302 B |
BIN
app/src/main/res/drawable-hdpi/ic_note_black_48dp.png
Normal file
After Width: | Height: | Size: 277 B |
BIN
app/src/main/res/drawable-hdpi/ic_save_black_48dp.png
Normal file
After Width: | Height: | Size: 368 B |
Before Width: | Height: | Size: 411 B |
After Width: | Height: | Size: 638 B |
Before Width: | Height: | Size: 175 B |
Before Width: | Height: | Size: 257 B |
Before Width: | Height: | Size: 165 B |
Before Width: | Height: | Size: 239 B |
BIN
app/src/main/res/drawable-mdpi/ic_note_black_48dp.png
Normal file
After Width: | Height: | Size: 192 B |
BIN
app/src/main/res/drawable-mdpi/ic_save_black_48dp.png
Normal file
After Width: | Height: | Size: 264 B |
Before Width: | Height: | Size: 273 B |
After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 257 B |
Before Width: | Height: | Size: 436 B |
Before Width: | Height: | Size: 239 B |
Before Width: | Height: | Size: 355 B |
BIN
app/src/main/res/drawable-xhdpi/ic_note_black_48dp.png
Normal file
After Width: | Height: | Size: 358 B |
BIN
app/src/main/res/drawable-xhdpi/ic_save_black_48dp.png
Normal file
After Width: | Height: | Size: 477 B |
Before Width: | Height: | Size: 465 B |
After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 347 B |
Before Width: | Height: | Size: 524 B |
Before Width: | Height: | Size: 302 B |
Before Width: | Height: | Size: 522 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_note_black_48dp.png
Normal file
After Width: | Height: | Size: 501 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_save_black_48dp.png
Normal file
After Width: | Height: | Size: 696 B |
Before Width: | Height: | Size: 573 B |
After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 436 B |
Before Width: | Height: | Size: 702 B |
Before Width: | Height: | Size: 355 B |
Before Width: | Height: | Size: 653 B |
BIN
app/src/main/res/drawable-xxxhdpi/ic_note_black_48dp.png
Normal file
After Width: | Height: | Size: 678 B |
BIN
app/src/main/res/drawable-xxxhdpi/ic_save_black_48dp.png
Normal file
After Width: | Height: | Size: 967 B |
Before Width: | Height: | Size: 814 B |
91
app/src/main/res/layout/fragment_addprofile.xml
Normal file
@@ -0,0 +1,91 @@
|
||||
<?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"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusableInTouchMode="true"
|
||||
android:minWidth="350dp"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="15dp"
|
||||
android:paddingTop="15dp">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/img_host"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:src="@drawable/ic_save_black_48dp"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@id/img_host"
|
||||
android:layout_alignTop="@id/img_host"
|
||||
android:layout_marginLeft="7dp"
|
||||
android:layout_toRightOf="@id/img_host"
|
||||
android:gravity="center"
|
||||
android:text="Add Profile"
|
||||
android:textAppearance="?android:textAppearanceMedium"
|
||||
/>
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Choose stripes to include"
|
||||
android:layout_marginTop="20dp"/>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="120dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginTop="10dp" >
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/container_linlay"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" />
|
||||
|
||||
</ScrollView>
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/input_profile_name_layout"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
app:errorEnabled="true">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/input_profile_name"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Profile name"
|
||||
android:inputType="text"
|
||||
android:minWidth="350dp"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
</LinearLayout>
|
7
app/src/main/res/layout/fragment_addprofile_item.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
/>
|
||||
|
@@ -1,86 +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/>.
|
||||
-->
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="192dp"
|
||||
android:background="?attr/colorPrimaryDark"
|
||||
android:gravity="bottom"
|
||||
android:padding="16dp"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nvh_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="15dp"
|
||||
android:text="Name"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
android:textSize="19sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nvh_type"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/nvh_name"
|
||||
android:layout_marginTop="15dp"
|
||||
android:text="type"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nvh_mapping"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/nvh_type"
|
||||
android:layout_marginTop="5dp"
|
||||
android:text="mapping"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nvh_hex_color"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/nvh_mapping"
|
||||
android:layout_marginTop="5dp"
|
||||
android:text="#hex"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/nhv_delete"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:clickable="true"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_clear_white_48dp"/>
|
||||
|
||||
<ImageButton
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_marginRight="15dp"
|
||||
android:layout_toLeftOf="@id/nhv_delete"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:clickable="true"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_mode_edit_white_24dp"/>
|
||||
|
||||
</RelativeLayout>
|
@@ -22,7 +22,7 @@
|
||||
Base application theme, dependent on API level. This theme is replaced
|
||||
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="MaterialDrawerTheme.Light.DarkToolbar.TranslucentStatus">
|
||||
<style name="AppBaseTheme" parent="MaterialDrawerTheme.Light.DarkToolbar">
|
||||
<!--
|
||||
Theme customizations available in newer API levels can go in
|
||||
res/values-vXX/styles.xml, while customizations related to
|
||||
|