PCB v1.1 beta

parent f847ea63
......@@ -11,7 +11,7 @@ android {
versionName "1.0"
resValue "string", "db_name", "PCB.db"
resValue "integer", "db_version", "4"
resValue "string", "app_version", "1.0"
resValue "string", "app_version", "1.1"
resValue "string", "core_vocabulary", "core_vocabulary"
resValue "string", "apk", "to_be_set_in_subproject"
resValue "string", "VersionManagerClass", "to_be_set_in_subproject"
......
......@@ -269,6 +269,7 @@ public class UserLogin {
}
public void login(String username, String password, Activity activity, Class PictogramActivity, Class LoginActivity) {
if (PCBcontext.is_user_logged()) PCBcontext.unset_user();
boolean online= RestapiWrapper.ping(activity.getResources().getString(R.string.server), "server/ping");
if (isSupervisorLoginPattern(username))
manageSupervisorLogin(username,password,online, activity, PictogramActivity, LoginActivity);
......
......@@ -130,11 +130,8 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
public boolean online() {return updated;}
public void restart_app(boolean resetPrevLogin) {
for (iNetServiceStatus listener: listeners) {
Log.e(LOG_TAG,"rest"+resetPrevLogin);
for (iNetServiceStatus listener: listeners)
if (listener instanceof iNetServiceDevice) ((iNetServiceDevice)listener).restart_app(resetPrevLogin);
}
PCBcontext.unset_user();
}
......
......@@ -28,8 +28,8 @@ public class ServerLogin {
private static void login(String operation, String email, String username, String password, final RestapiWrapper.iRestapiListener listener){
Hashtable<String, String> postDataParams = new Hashtable<String, String>();
if (email!=null) postDataParams.put("email", email);
if (username!=null) postDataParams.put("username", username);
postDataParams.put("password", password);
if (username!=null) postDataParams.put("username", username);
if (password!=null) postDataParams.put("password", password);
PCBcontext.getRestapiWrapper().ask(operation, postDataParams, "post", new RestapiWrapper.iRestapiListener() {
@Override
public void preExecute() {
......
......@@ -16,10 +16,13 @@ import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tools.PCBcontext;
import java.util.Vector;
import static android.graphics.Color.argb;
/**
......@@ -27,9 +30,10 @@ import static android.graphics.Color.argb;
*/
public class PictoAnimation {
private final String LOG_TAG = this.getClass().getCanonicalName();
public void animateTapeView(final int position, final ViewGroup view) {
private final static String LOG_TAG = PictoAnimation.class.getCanonicalName();
public void animateTapeView(final PictogramActivity activity,final int position, final ViewGroup view) {
final GridView gridview = (GridView) view.getChildAt(1);
final TapeAdapter tapeAdapter=(TapeAdapter)gridview.getAdapter();
......@@ -66,7 +70,7 @@ public class PictoAnimation {
v.setColorFilter(0);
v.setBackgroundColor(ContextCompat.getColor(PCBcontext.getContext(), R.color.picto_default_background));
if (position < (tapeAdapter.getCount() - 1))
animateTapeView(position + 1, view);
animateTapeView(activity,position + 1, view);
else {
((Activity)view.getContext()).runOnUiThread(new Runnable() {
@Override
......@@ -75,6 +79,8 @@ public class PictoAnimation {
tapeAdapter.endPlay();
}
});
activity.pictoMainGridAdapter.allPictosInGrid();
activity.pictoCategoryGridAdapter.allPictosInGrid();
}
}
......@@ -195,4 +201,129 @@ public class PictoAnimation {
colorAnim.start();
}
public static void animateOnGridView(final RelativeLayout layout) {
final PictogramActivity activity=(PictogramActivity)PCBcontext.getActivityContext();
if (activity.inserting) return;
FrameLayout borderlayout=(FrameLayout)layout.getChildAt(0);
final ImageView v=(ImageView)borderlayout.getChildAt(0);
final TextView t1=(TextView)borderlayout.getChildAt(1);
final TextView t2=(TextView)borderlayout.getChildAt(2);
final ValueAnimator colorAnim = ObjectAnimator.ofFloat(0f, 1f) ;
colorAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float mul = (Float) animation.getAnimatedValue();
if (t2.getVisibility()==View.VISIBLE) {
t2.setAlpha(mul);
v.setImageAlpha(0);
}
else {
v.setImageAlpha((int)(mul*255f));
if (t1.getVisibility() == View.VISIBLE) t1.setAlpha(mul);
}
}
});
colorAnim.addListener(new ValueAnimator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
colorAnim.setDuration(250);
colorAnim.start();
}
public static void animateOutGridView(final PictoGridAdapter pictoGridAdapter, final Picto picto, RelativeLayout layout, final Vector<Picto> pictoLinkedList_inTape) {
final PictogramActivity activity=(PictogramActivity)PCBcontext.getActivityContext();
if (activity.inserting) return;
FrameLayout borderlayout=(FrameLayout)layout.getChildAt(0);
final ImageView v=(ImageView)borderlayout.getChildAt(0);
final TextView t1=(TextView)borderlayout.getChildAt(1);
final TextView t2=(TextView)borderlayout.getChildAt(2);
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();
if (t2.getVisibility()==View.VISIBLE) {
t2.setAlpha(1-mul);
mul=1;
}
int alphaOrange = PictoAnimation.adjustAlpha(orange, mul);
v.setColorFilter(alphaOrange, PorterDuff.Mode.SRC_ATOP);
v.setBackgroundColor(alphaOrange);
v.setPadding(0,0,0,0);
if (mul == 0.0) {
v.setColorFilter(0);
}
if (t1.getVisibility()==View.VISIBLE) t1.setAlpha(1-mul);
}
});
colorAnim.addListener(new ValueAnimator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
if (t2.getVisibility()==View.VISIBLE) v.setBackgroundColor(0);
activity.inserting=true;
}
@Override
public void onAnimationEnd(Animator animation) {
pictoLinkedList_inTape.add(picto);
pictoGridAdapter.notifyDataSetChanged();
if (t1.getVisibility()==View.VISIBLE) t1.setAlpha(1);
if (t2.getVisibility()==View.VISIBLE) t2.setAlpha(1);
v.setColorFilter(0);
v.setBackgroundColor(ContextCompat.getColor(PCBcontext.getContext(), R.color.picto_default_background));
activity.inserting=false;
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
colorAnim.setDuration(200);
colorAnim.start();
}
}
......@@ -3,6 +3,7 @@ package com.yottacode.pictogram.tabletlibrary.gui.communicator;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.RelativeLayout;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.tools.PCBcontext;
......@@ -14,11 +15,13 @@ public class PictoGridAdapter extends ArrayAdapter {
private LinkedList<Picto> pictoLinkedList;
private final String LOG_TAG = this.getClass().getSimpleName();
private Vector<Picto> pictoLinkedList_inTape;
private Vector<Picto> pictoLinkedList_inGrid;
public PictoGridAdapter(LinkedList<Picto> pictoLinkedList){
super(PCBcontext.getContext(), PictoItemViewGenerator.LAYOUT, pictoLinkedList);
this.pictoLinkedList = pictoLinkedList;
pictoLinkedList_inTape=new Vector<>(5);
pictoLinkedList_inGrid=new Vector<>(5);
}
@Override
......@@ -39,27 +42,37 @@ public class PictoGridAdapter extends ArrayAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Picto picto=this.pictoLinkedList.get(position);
if (this.pictoLinkedList_inTape.contains(picto)) picto.set_visible(false);
return PictoItemViewGenerator.getPictoView(
picto,
convertView,
parent
);
int igrid=this.pictoLinkedList_inGrid.indexOf(picto);
int itape = this.pictoLinkedList_inTape.indexOf(picto);
if (itape >= 0)
picto.set_visible(false);
if (igrid>=0)
picto.set_visible(true);
View view = PictoItemViewGenerator.getPictoView(
picto,
convertView,
parent
);
if (igrid>=0) {
this.pictoLinkedList_inGrid.remove(igrid);
if (itape>=0) pictoLinkedList_inTape.remove(itape);
PictoAnimation.animateOnGridView((RelativeLayout)view);
}
return view;
}
public void pictoInTape(Picto p) {
p.set_visible(false);
pictoLinkedList_inTape.add(p);
notifyDataSetChanged();
public void pictoInTape(View view, Picto p) {
PictoAnimation.animateOutGridView(this,p, (RelativeLayout)view, pictoLinkedList_inTape);
}
public void pictoInGrid(Picto p) {
pictoLinkedList_inTape.get(pictoLinkedList_inTape.indexOf(p)).set_visible(true);
pictoLinkedList_inTape.remove(p);
pictoLinkedList_inGrid.add(p);
notifyDataSetChanged();
}
......@@ -70,9 +83,9 @@ public class PictoGridAdapter extends ArrayAdapter {
public void allPictosInGrid() {
for (Picto picto: pictoLinkedList_inTape) {
picto.set_visible(true);
pictoLinkedList_inGrid.add(picto);
}
pictoLinkedList_inTape.clear();
notifyDataSetChanged();
}
......
......@@ -124,6 +124,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
protected boolean tape_delivered=false;
float firstTouchX = -1;
public boolean inserting=false;
@TargetApi(Build.VERSION_CODES.M)
@Override
......@@ -234,14 +235,13 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
if (!deleting) {
Log.i(PictogramActivity.class.getCanonicalName(), " Deleting item " + position + "-" + id + "(" + PictogramActivity.this.tapeAdapter.getItem(position).get_translation() + ")");
Picto deletedPicto=PictogramActivity.this.tapeAdapter.getItem(position);
if (pictoCategoryGridAdapter.pictoInThisCategory(deletedPicto)) {
pictoCategoryGridAdapter.pictoInGrid(deletedPicto);
}
if (pictoMainGridAdapter.pictoInThisCategory(deletedPicto)) {
pictoMainGridAdapter.pictoInGrid(deletedPicto);
}
new PictoAnimation().animateOnDeleteView(PictogramActivity.this,view, position);
PictogramActivity.this.tapeAdapter.notifyDataSetChanged();
if (pictoMainGridAdapter.pictoInThisCategory(deletedPicto))
pictoMainGridAdapter.pictoInGrid(deletedPicto);
if (pictoCategoryGridAdapter.pictoInThisCategory(deletedPicto))
pictoCategoryGridAdapter.pictoInGrid(deletedPicto);
PCBcontext.getActionLog().log(new TalkAction(TalkAction.DELETE, deletedPicto));
}
}});
......@@ -760,7 +760,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
if (v == findViewById(R.id.tape_grid_view) && (viewgroup == findViewById(R.id.picto_category_grid_view) || viewgroup == findViewById(R.id.picto_main_grid_view))) {
Picto p = viewgroup == findViewById(R.id.picto_category_grid_view) ? pictoCategoryGridAdapter.getItem(position)
: pictoMainGridAdapter.getItem(position);
if (!p.is_category()) addPictoWord(p);
if (!p.is_category()) addPictoWord(view, p);
}
// Si el destino es el panel y el origen la cinta de frase
......@@ -791,6 +791,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
private class OnPictoClickListener implements AdapterView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (inserting) return;
Picto p = getCurrentPictoGridAdapter().getItem(position);
if (p != null && p.get_id() != 0 && !p.is_invisible() && p.is_enabled()) {
......@@ -803,16 +804,16 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
hidePictoMainGridView();
} else if (tapeAdapter.getCount() < PictogramActivity.this.maxInTape && !PictogramActivity.this.tapeAdapter.play()) {
addPictoWord(p);
addPictoWord(parent.getChildAt(position),p);
}
}
}
}
private void addPictoWord(Picto p) {
private void addPictoWord(View view, Picto p) {
tapeAdapter.addItem(p);
getCurrentPictoGridAdapter().pictoInTape(p);
getCurrentPictoGridAdapter().pictoInTape(view,p);
currentCategory = null;
tapeAdapter.notifyDataSetChanged();
showPictoMainGridView();
......@@ -915,14 +916,10 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
if (lp.size()>0 && !PictogramActivity.this.tapeAdapter.play()) {
PCBcontext.getActionLog().log(new PictosAction(lp));
tapeAdapter.ttsAllNew(tts);
new PictoAnimation().animateTapeView(0,(ViewGroup)arg0.getParent());
new PictoAnimation().animateTapeView(PictogramActivity.this,0,(ViewGroup)arg0.getParent());
if (PCBcontext.getPcbdb().getCurrentUser().delivery()!= User.JSON_STUDENT_ATTTRS.delivery.clean) {
showOnlyTape(true);
}
pictoMainGridAdapter.allPictosInGrid();
pictoMainGridAdapter.notifyDataSetChanged();
pictoCategoryGridAdapter.allPictosInGrid();
pictoCategoryGridAdapter.notifyDataSetChanged();
}
}
}
......@@ -1044,6 +1041,9 @@ protected void showOnlyTape(boolean onlyTape) {
serialActivity.putExtra("switch_pwd", lastPassword);
}
pictoCategoryGridAdapter.notifyDataSetInvalidated();
pictoMainGridAdapter.notifyDataSetInvalidated();
PictogramActivity.this.finish();
if (SessionActivity.session!=null) SessionActivity.session.finish();
PCBcontext.getNetService().restart_app(true);
......
......@@ -18,6 +18,7 @@ import java.util.LinkedList;
public class TapeAdapter extends BaseAdapter {
private static final String LOG_TAG = TapeAdapter.class.getName();
//private Context mContext;
private LinkedList<Picto> pictoLinkedList;
private boolean play = false;
......@@ -52,7 +53,11 @@ public class TapeAdapter extends BaseAdapter {
// ELIMINAR ITEM DEL ADAPTADOR
public void deleteItem(int position) {
pictoLinkedList.remove(position);
try {
pictoLinkedList.remove(position);
}catch(IndexOutOfBoundsException e) {
Log.e(LOG_TAG,"Error deleting item from tape adapter:"+e.getMessage());
}
}
......
......@@ -169,6 +169,7 @@ public class SerialActivity extends Activity {
@Override
public void onStart() {
Vector<User> users;
Log.i(this.getClass().getCanonicalName(),"Starting serial activity (Reset Prev user:"+getIntent().getBooleanExtra("resetPrevUser", true)+")");
if (!PCBcontext.init()) PCBcontext.init(this, new NetServiceTablet());
......@@ -180,7 +181,6 @@ public class SerialActivity extends Activity {
mSerialViewMail.setText(username);
mSerialViewPass.setText(password);
Log.e(LOG_TAG,"restart prev user"+getIntent().getBooleanExtra("resetPrevUser", true));
if (!username.equals("") && !password.equals("") && !getIntent().getBooleanExtra("resetPrevUser", true))
new UserLogin().login(username, password, SerialActivity.this, PictogramActivity.class, LoginActivity.class);
......
......@@ -89,7 +89,7 @@ public class NetServiceTablet implements NetService.iNetServiceDevice {
Log.e(LOG_TAG,"App restarting, reset last login:"+resetPrevUser);
Context context=PCBcontext.getContext();
Context context=PCBcontext.getActivityContext();
Intent serialActivity = new Intent(context, com.yottacode.pictogram.tabletlibrary.gui.login.SerialActivity.class);
serialActivity.putExtra("resetPrevUser", resetPrevUser);
......
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