Pictogram Tablet: Fast Switch User implementd. Tablet logo updated (jpg)

parent cfe00c60
......@@ -90,7 +90,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
private void setCurrentUser(User user) {
this.currentUser = user;
PCBcontext.getDevice().setLastStuId(user.get_id_stu());
PCBcontext.getDevice().setLastSupId(user.get_id_sup());
if (user.is_supervisor()) PCBcontext.getDevice().setLastSupId(user.get_id_sup());
}
/**
......
package com.yottacode.pictogram.net;
import android.content.Intent;
import android.util.Log;
import com.yottacode.net.RestapiWrapper;
......@@ -98,6 +99,10 @@ public class NetService implements Runnable {
PCBcontext.unset_user();
this.device.restart_app();
}
public void restart_app(Intent intent) {
PCBcontext.unset_user();
this.device.restart_app(intent);
}
/**
* ping to the server by using a restapi call. If ok, the call will return the empty set
......
package com.yottacode.pictogram.net;
import android.content.Intent;
/**
* Created by Fernando on 12/08/2016.
*/
......@@ -9,4 +11,5 @@ public interface iNetServiceDevice {
public void notifyStatus(boolean updated);
public void closeNotifyStatus();
public void restart_app();
public void restart_app(Intent intent);
}
......@@ -209,8 +209,8 @@ INSTEAD OF INSERT ON users_detail
FOR EACH ROW
WHEN NEW.pwd_stu IS NULL
BEGIN
INSERT OR REPLACE INTO student(id,nickname, name, surname, url_img, gender, lang, attributes)
VALUES (NEW.id_stu, NEW.nickname_stu, NEW.name_stu, NEW.surname_stu, NEW.url_img_stu, NEW.gender_stu, NEW.lang_stu, NEW.attributes_stu);
INSERT OR REPLACE INTO student(id,nickname, pwd, name, surname, url_img, gender, lang, attributes)
VALUES (NEW.id_stu, NEW.nickname_stu, (SELECT pwd FROM student WHERE id=NEW.id_stu), NEW.name_stu, NEW.surname_stu, NEW.url_img_stu, NEW.gender_stu, NEW.lang_stu, NEW.attributes_stu);
INSERT OR REPLACE INTO supervisor VALUES (NEW.id_sup, NEW.email_sup, NEW.pwd_sup, NEW.name_sup, NEW.surname_sup, NEW.url_img_sup, NEW.gender_sup, NEW.lang_sup, NEW.tts_engine_sup);
INSERT OR REPLACE INTO users VALUES (NEW.id_stu,NEW.id_sup);
END
......
......@@ -6,6 +6,7 @@ import android.content.ClipData;
import android.content.ClipDescription;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
......@@ -31,6 +32,7 @@ import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.net.iImgDownloaderListener;
import com.yottacode.pictogram.tablet.R;
import com.yottacode.pictogram.action.PictosAction;
......@@ -43,18 +45,22 @@ import com.yottacode.pictogram.net.PictoUploader;
import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
public class PictogramActivity extends Activity implements iVocabularyListener, TextToSpeech.OnInitListener {
public static final String PREFS_NAME = "MyPrefsFile";
// Main layout for this activity
RelativeLayout mainLayout;
// Adapter for de grid showing the categories grid (and main pictos)
......@@ -736,13 +742,54 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
private class OnDeleteButtonLongClickListener implements View.OnLongClickListener {
@Override
public boolean onLongClick(View v) {
count_deletelong++;
count_deletelong++;
if (count_deletelong >= 3) {
//TODO: COMPROBAR SI LOS USUARIOS QUE BUSCO EXISTEN: SI NO PONER LOS DATOS POR DEFECTO*******************************************************************/
//Cojo los id del ultimo estudiante y el ultimo supervisor
int lastIdStu = PCBcontext.getDevice().getLastStuId();
User actual = PCBcontext.getPcbdb().getCurrentUser();
User usuario_anterior;
String lastUserName = null;
String lastPassword= null;
if (count_deletelong >= 3) {
PictogramActivity.this.finish();
PCBcontext.getNetService().restart_app();
if (actual.is_supervisor()) //Si el que habia es supervisor busco el ultimo niño
try {
usuario_anterior = PCBcontext.getDevice().findUser(lastIdStu,User.NO_SUPERVISOR);
if(usuario_anterior!=null){
lastUserName = usuario_anterior.get_nickname_stu();
lastPassword = usuario_anterior.get_pwd_stu();
}
} catch (JSONException e) {
e.printStackTrace();
}
else {
int lastIdSup = PCBcontext.getDevice().getLastSupId();
try {
usuario_anterior = PCBcontext.getDevice().findUser(lastIdStu,lastIdSup);
if(usuario_anterior!=null){
lastUserName = usuario_anterior.get_email_sup();
lastPassword = usuario_anterior.get_pwd_sup();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
return false;
Intent serialActivity = new Intent(getBaseContext(), SerialActivity.class);
if (lastUserName!=null) {
Log.i(this.getClass().getCanonicalName(), "Switch user to "+ lastUserName);
serialActivity.putExtra("switch_usr", lastUserName);
serialActivity.putExtra("switch_pwd", lastPassword);
}
PictogramActivity.this.finish();
PCBcontext.getNetService().restart_app(serialActivity);
}
return false;
}
}
......
......@@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
......@@ -25,12 +26,24 @@ public class SerialActivity extends Activity {
// String constant for logs
private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName()
public static void resetDefaultUser() {
SharedPreferences settings = PCBcontext.getContext().getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("username", "");
editor.putString("password", "");
/**
* Return the default user+pwd when login.The policy is
* 1. switch user
* 2. last user
* @return user+pwd to be used
*/
private String[] loginUserPolicy() {
Intent intent=getIntent();
String username = intent.getStringExtra("switch_usr");
String password = intent.getStringExtra("switch_pwd");
if (username==null) {
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
username = settings.getString("username", "");
password = settings.getString("password", "");
}
return new String[]{username,password};
}
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -38,21 +51,25 @@ public class SerialActivity extends Activity {
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_serial);
Intent intent=getIntent();
final EditText mSerialViewMail = (EditText) findViewById(R.id.serialmail);
final EditText mSerialViewPass = (EditText) findViewById(R.id.serialpass);
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
String username = settings.getString("username", "");
String password = intent.getBooleanExtra("resetPrevUser", true) ? "" : settings.getString("password", "");
String default_user[]=loginUserPolicy();
String username=default_user[0];
String password=default_user[1];
// Escribo el último valor indicado de username
mSerialViewMail.setText(username);
mSerialViewPass.setText(password);
// Escribo el último valor indicado de username
mSerialViewMail.setText(username);
if (!username.equals("") && !password.equals("")) new UserLogin().login(username, password,SerialActivity.this, PictogramActivity.class, LoginActivity.class);;
if (!username.equals("") && !password.equals("") && !getIntent().getBooleanExtra("resetPrevUser", true)) new UserLogin().login(username, password,SerialActivity.this, PictogramActivity.class, LoginActivity.class);
Button mEntrarButton = (Button) findViewById(R.id.entrar_button);
mEntrarButton.setOnClickListener(new OnClickListener() {
......@@ -66,6 +83,7 @@ public class SerialActivity extends Activity {
editor.putString("username", username);
editor.putString("password", password);
editor.commit();
if (!username.equals("") && !password.equals(""))
new UserLogin().login(username, password,SerialActivity.this, PictogramActivity.class, LoginActivity.class);
}
});
......
......@@ -4,6 +4,7 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TaskStackBuilder;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
......@@ -68,15 +69,13 @@ public class NetServiceTablet implements iNetServiceDevice {
* the app. The most frequent reason is a password change while the user have been logged
* offline
*/
public void restart_app() {
public void restart_app(Intent serialActivity) {
StackTraceElement trace[] = Thread.currentThread().getStackTrace();
Log.i(this.getClass().getCanonicalName(),"App restarted from "+trace[0]+"->"+trace[1]+"..."+
trace[trace.length-2]+"->"+trace[trace.length-1]);
SerialActivity.resetDefaultUser();
Intent serialActivity = new Intent(PCBcontext.getContext(), SerialActivity.class);
Log.i(this.getClass().getCanonicalName(),"App restarting");
if (serialActivity==null) serialActivity = new Intent(PCBcontext.getContext(), SerialActivity.class);
serialActivity.putExtra("resetPrevUser", true);
PCBcontext.getContext().startActivity(serialActivity);
}
public void restart_app() {restart_app(null);}
}
......@@ -47,8 +47,8 @@ public class MainActivity extends Activity {
}
private void login() {
final String username="faf0001";
final String password="faf0001";
final String username="faf0002";
final String password="faf0002";
new UserLogin().login(username,password,this, MainActivity.class,null);
}
}
......@@ -43,13 +43,17 @@ public class NetServiceWatch implements iNetServiceDevice {
* offline
*/
public void restart_app() {
Intent intent= new Intent(PCBcontext.getContext(), Activity);
intent.putExtra("resetPrevUser", true);
PCBcontext.getContext().startActivity(intent);
restart_app(new Intent(PCBcontext.getContext(), Activity));
}
@Override
public void restart_app(Intent intent) {
intent.putExtra("resetPrevUser", true);
PCBcontext.getContext().startActivity(intent);
}
public void set_notifyTextView(TextView _notifyTextView) {
public void set_notifyTextView(TextView _notifyTextView) {
this.status = _notifyTextView;
}
}
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