working on PCB issues

parent bc57f0d4
package com.yottacode.pictogram.dao;
import android.graphics.Bitmap;
import android.animation.ValueAnimator;
import android.graphics.Color;
import android.util.Log;
......@@ -21,18 +21,7 @@ import org.json.JSONObject;
* @version 1.0
*/
public class Picto extends Img {
int cont = 0;
Bitmap bitmap;
boolean lighten=false;
// String constant for logs
private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName()
public void set_ligthen(boolean lighten) {
this.lighten = lighten;
}
public boolean lighten() {
return lighten;
}
public final static class JSON_ATTTRS {
public static String CATEGORY = "id_cat";
......@@ -71,12 +60,31 @@ public class Picto extends Img {
private String translation;
private boolean is_mirror=false;
private boolean highlight_background=false;
ValueAnimator.AnimatorListener lighten=null;
public boolean is_mirror() {return is_mirror;}
public ValueAnimator.AnimatorListener lighten() {
return lighten;
}
public boolean is_highlight_background() {return highlight_background;}
public void set_mirror(boolean is_mirror, boolean highlight_background) {
this.highlight_background =highlight_background;
this.is_mirror=is_mirror;}
public void set_ligthen(ValueAnimator.AnimatorListener lighten) {
this.lighten = lighten;
}
public Picto(Picto p) {
super(p);
try {
this.attributes=new JSONObject(p.attributes.toString());
} catch (JSONException e) {
Log.e(this.getClass().getCanonicalName(),e.getMessage());
}
translation=new String(p.get_translation());
}
public Picto(int id, String url, String translation, int cat, int row, int column, int freeRow, int freeColumn) throws JSONException {
this(id, url, translation, new JSONObject()
.put(JSON_ATTTRS.CATEGORY, cat)
......
......@@ -57,6 +57,18 @@ public class Img {
this.type=type;
this.bitmap=null;
}
public Img(Img i) {
this.id = i.id;
this.url = new String(i.url);
this.type=new String(i.type);
try {
if (PCBcontext.getContext()!=null && i.get_bitmap(PCBcontext.getContext())!=null)
this.bitmap=i.get_bitmap(PCBcontext.getContext()).copy(i.get_bitmap(PCBcontext.getContext()).getConfig(),true);
} catch (IOException e) {
Log.e(this.getClass().getCanonicalName(),e.getMessage());
}
}
public String file_name() { return this.id+"."+Img.FILETYPE; }
public int get_id() { return this.id;}
......
package com.yottacode.pictogram.tabletlibrary.gui;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LightingColorFilter;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.support.v4.content.ContextCompat;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
......@@ -31,7 +33,7 @@ public class PictoItemViewGenerator {
public static final int LAYOUT = R.layout.picto_grid_item;
public static final int LAYOUT_BIG = R.layout.picto_grid_item_big;
public static int mirror_color=0;
public static int lighten=1;
/**
*
......@@ -238,16 +240,8 @@ public class PictoItemViewGenerator {
if (picto.is_highlight_background()) layout.setBackgroundColor(color[mirror_color%color.length]);
}
if (picto.lighten()) {
PictoItemViewGenerator.lighten++;
int light[]={0xE0,0xC8,0xAF,0x64,0x4B,32,16,0};
int lighten=light[(PictoItemViewGenerator.lighten>=light.length) ? 0 : PictoItemViewGenerator.lighten];
int color=lighten*0x10000+lighten*0x100+lighten;
LightingColorFilter lcf = new LightingColorFilter(color,0);
pictoImage.setColorFilter(lcf);
}
if (picto.lighten()!=null)
animateImageView(pictoImage,picto.lighten());
}
} catch (IOException e) {
e.printStackTrace();
......@@ -256,4 +250,37 @@ public class PictoItemViewGenerator {
return convertView;
}
public static void animateImageView(final ImageView v,ValueAnimator.AnimatorListener listener) {
final int orange = ContextCompat.getColor(PCBcontext.getContext(),R.color.picto_default_background);
final ValueAnimator colorAnim = ObjectAnimator.ofFloat(0f, 1f);
colorAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float mul = (Float) animation.getAnimatedValue();
int alphaOrange = adjustAlpha(orange, mul);
v.setColorFilter(alphaOrange, PorterDuff.Mode.SRC_ATOP);
if (mul == 0.0) {
v.setColorFilter(0);
}
}
});
colorAnim.addListener(listener);
colorAnim.setDuration(1500);
colorAnim.start();
}
public static int adjustAlpha(int color, float factor) {
int alpha = Math.round(Color.alpha(color) * factor);
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
return Color.argb(alpha, red, green, blue);
}
}
package com.yottacode.pictogram.tabletlibrary.gui;
import android.animation.Animator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ClipData;
......@@ -63,7 +65,33 @@ import java.util.Locale;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
class PictoAnimationListener implements ValueAnimator.AnimatorListener {
int pos;
TapeAdapter adapter;
public PictoAnimationListener(TapeAdapter adapter, int position) {
pos=position;
this.adapter=adapter;
}
@Override
public void onAnimationStart(Animator animation) {
adapter.getItem(pos).set_ligthen(null);
}
@Override
public void onAnimationEnd(Animator animation) {
adapter.deleteItem(pos);
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
};
public class PictogramActivity extends Activity implements VocabularyTalk.iVocabularyListener {
float firstTouchX = -1;
......@@ -200,15 +228,11 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
this.tapeGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.i(this.getClass().getCanonicalName(), " Delete item " + position + "(" + PictogramActivity.this.tapeAdapter.getItem(position).get_translation() + ")");
PCBcontext.getActionLog().log(new TalkAction(TalkAction.DELETE, PictogramActivity.this.tapeAdapter.getItem(position)));
PictogramActivity.this.tapeAdapter.getItem(position).set_ligthen(true);
execDeletePicto(PictogramActivity.this.tapeAdapter,position);
Log.i(this.getClass().getCanonicalName(),"DELETE PICTO");
}
});
PictogramActivity.this.tapeAdapter.getItem(position).set_ligthen(new PictoAnimationListener(tapeAdapter, position));
}});
((NetServiceTablet) PCBcontext.getNetService().getNetServiceDevice()).setPictogramActivity(this);
if (PCBcontext.getPcbdb().getCurrentUser().is_picto_size_big()) {
......@@ -738,9 +762,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
if (p != null && p.get_id() != 0 && !p.is_invisible() && p.is_enabled()) {
Log.d(LOG_TAG, "Clic en picto: " + p.toString());
if (PictogramActivity.this.feedback_read && !p.is_category())
PictogramActivity.this.tts.play(p.get_translation());
p.set_mirror(false, false);
p.set_mirror(false, false);
// If the picto is a category
if (p.is_category()) {
......@@ -761,29 +783,11 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
tapeAdapter.notifyDataSetChanged();
showPictoMainGridView();
PCBcontext.getActionLog().log(new TalkAction(TalkAction.ADD, p));
if (PictogramActivity.this.feedback_read)
if (PictogramActivity.this.feedback_read && !PictogramActivity.this.tapeAdapter.play())
PictogramActivity.this.tts.play(p.get_translation());
if (PictogramActivity.this.feedback_highlight) execHighligthFeeback(p, false);
}
private void execDeletePicto(final TapeAdapter tapeAdapter, final int position) {
final ScheduledThreadPoolExecutor exec_delete = new ScheduledThreadPoolExecutor(1);
Log.e(this.getClass().getCanonicalName(),"deleting");
exec_delete.scheduleAtFixedRate(new Runnable() {
int repeating = 0;
@Override
public void run() {
if (repeating++ == 4) {
Log.e(this.getClass().getCanonicalName(),"deleting "+repeating);
exec_delete.shutdown();
tapeAdapter.getItem(position).set_ligthen(false);
tapeAdapter.deleteItem(position);
Log.e(this.getClass().getCanonicalName(),"deleted ");
}
}
}, 0, 500, TimeUnit.MILLISECONDS);
}
private void execHighligthFeeback(final Picto picto, boolean highlight_background) {
boolean same_picto = false;
picto.set_mirror(true, highlight_background); //comienza feedback
......@@ -803,9 +807,8 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
prev_picto = picto;
exec_mirror.scheduleAtFixedRate(new Runnable() {
int repeating = 0;
@Override
public void run() { Log.e(this.getClass().getCanonicalName(),"highdele "+repeating);
public void run() {
refresh();
if (repeating++ == 20) {
picto.set_mirror(false, false);
......@@ -876,7 +879,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
public void onClick(View arg0) {
LinkedList<Picto> lp = tapeAdapter.getAll();
// This triggers the "Show" websocket action
if (lp.size()>0) {
if (lp.size()>0 && !PictogramActivity.this.tapeAdapter.play()) {
PCBcontext.getActionLog().log(new PictosAction(lp));
tapeAdapter.ttsAllNew(tts);
}
......
......@@ -97,10 +97,11 @@ public class TapeAdapter extends BaseAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent){
return PictoItemViewGenerator.getPictoView(
this.pictoLinkedList.get(position),
convertView,
parent,true);
View pictoView = PictoItemViewGenerator.getPictoView(
this.pictoLinkedList.get(position),
convertView,
parent, true);
return pictoView;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
......
......@@ -73,14 +73,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
......@@ -89,6 +81,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
......
......@@ -66,14 +66,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavor/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavor/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/DefaultFlavor/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/assets" type="java-test-resource" />
......@@ -82,6 +74,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDefaultFlavor/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDefaultFlavor/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
......@@ -106,14 +106,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
......@@ -122,6 +114,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment