Cambios en Serial y LoginActivity

parent 9c32545c
...@@ -37,17 +37,11 @@ ...@@ -37,17 +37,11 @@
android:name=".gui.MainActivity" android:name=".gui.MainActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="landscape"> android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity> </activity>
<activity <activity
android:name=".gui.SerialActivity" android:name=".gui.SerialActivity"
android:label="@string/title_activity_serial" android:label="@string/title_activity_serial"
android:screenOrientation="landscape"> android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity> </activity>
<activity <activity
android:name=".gui.LoginActivity" android:name=".gui.LoginActivity"
...@@ -55,17 +49,6 @@ ...@@ -55,17 +49,6 @@
android:label="@string/title_activity_login_activity_fragments" android:label="@string/title_activity_login_activity_fragments"
android:screenOrientation="landscape"/> android:screenOrientation="landscape"/>
<activity <activity
android:name="com.yottacode.pictogrammar.UploadActivity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".gui.PictogramActivity" android:name=".gui.PictogramActivity"
android:exported="true" android:exported="true"
android:label="@string/app_name" android:label="@string/app_name"
......
...@@ -33,6 +33,8 @@ import org.json.JSONException; ...@@ -33,6 +33,8 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector; import java.util.Vector;
/** /**
...@@ -42,7 +44,7 @@ import java.util.Vector; ...@@ -42,7 +44,7 @@ import java.util.Vector;
* @version 1.0 * @version 1.0
*/ */
public class LoginActivity extends FragmentActivity implements iRestapiListener { public class LoginActivity extends FragmentActivity implements iRestapiListener{
private static final String TAG_ID = "id"; private static final String TAG_ID = "id";
private static final String TAG_NAME = "name"; private static final String TAG_NAME = "name";
...@@ -154,8 +156,6 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener ...@@ -154,8 +156,6 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener
public void result(JSONArray students_supervisors) { //FERNANDO public void result(JSONArray students_supervisors) { //FERNANDO
try { try {
// Saco los pares estudiante-supervisor // Saco los pares estudiante-supervisor
//Log.d(LOG_TAG, "JSON:"+students_supervisors);
Log.d(LOG_TAG, "students_supervisors size:" + students_supervisors.length());
// looping through All Students // looping through All Students
Vector<User> users = new Vector<User>(students_supervisors.length()); Vector<User> users = new Vector<User>(students_supervisors.length());
...@@ -205,64 +205,72 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener ...@@ -205,64 +205,72 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener
} }
} }
Log.d(LOG_TAG, "users size:" + users.size());
// Si sólo hay 1 estudiante, cargo el st_id // Si sólo hay 1 estudiante, cargo el st_id
if (students_supervisors.length() == 1) if (users.size() == 1){
//User student = PCBcontext.getDevice().findUser(st_id_int, sup_id);
PCBcontext.set_user(student, token, null); // no hay que hacer nada cuando termine
} else{
student = new User(-1, "", "", "", "M", "es-es", "",
sup_id, "", "", "", "M", "es-es", "");
PCBcontext.set_user(student, token, new iImgDownloaderListener() { PCBcontext.set_user(student, token, new iImgDownloaderListener() {
@Override @Override
public void loadComplete() { public void loadComplete() {
Log.d(LOG_TAG, "Images: Load images complete"); //close the progress dialog
progressDialog.dismiss(); //progressDialog.dismiss();
setContentView(R.layout.activity_login); //setContentView(R.layout.activity_login);
} }
// De la interfaz iImgDownloaderListener
@Override @Override
public void loadImg(Img img) { public void loadImg(Img image) {
//close the progress dialog
//progressDialog.dismiss();
//setContentView(R.layout.activity_login);
} }
}); else{ });
student = new User(-1, "", "", "", "M", "es-es", "",
sup_id, "", "", "", "M", "es-es", "");
PCBcontext.set_user(student, token, null);
} }
//Device device = new Device(getApplicationContext(), null, 1); //Device device = new Device(getApplicationContext(), null, 1);
if (users.size() > 0){ if (users.size() > 0){
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String currentDateandTime = sdf.format(new Date());
Log.d(LOG_TAG, "Entro en synchronizeUsers en " + currentDateandTime);
PCBcontext.getDevice().synchronizeUsers(users, new iImgDownloaderListener() { PCBcontext.getDevice().synchronizeUsers(users, new iImgDownloaderListener() {
@Override @Override
public void loadComplete() { public void loadComplete() {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
} String currentDateandTime = sdf.format(new Date());
Log.d(LOG_TAG, "LoadComplete en " + currentDateandTime);
@Override
public void loadImg(Img img) {
Log.d(LOG_TAG, "Load a single image with ID: " + img.get_id());
// Aquí filtro si sólo tiene un único usuario o varios
Vector<User> users = null; Vector<User> users = null;
try { try {
users = PCBcontext.getDevice().getUsers(); users = PCBcontext.getDevice().getUsers();
} catch (JSONException e) {
e.printStackTrace();
}
if (users.size() > 1) { if (users.size() > 1) {
//close the progress dialog
progressDialog.dismiss();
setContentView(R.layout.activity_login); setContentView(R.layout.activity_login);
} }
} catch (JSONException e) {
e.printStackTrace();
} }
@Override
public void loadImg(Img image) {
} }
}); });
PCBcontext.getDevice().deleteDeprecatedImgs(); PCBcontext.getDevice().deleteDeprecatedImgs();
// Si sólo hay 1 estudiante paso a Pictogram // Si sólo hay 1 estudiante paso a Pictogram
if(users.size()==1) if (users.size() == 1){
{
//close the progress dialog //close the progress dialog
progressDialog.dismiss(); progressDialog.dismiss();
Intent pictogramActivity = new Intent(this, PictogramActivity.class); Intent pictogramActivity = new Intent(this, PictogramActivity.class);
startActivity(pictogramActivity); startActivity(pictogramActivity);
} }
}else{ } else {
AlertDialog.Builder builder = AlertDialog.Builder builder =
new AlertDialog.Builder(this); new AlertDialog.Builder(this);
...@@ -289,7 +297,6 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener ...@@ -289,7 +297,6 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener
public void result(JSONObject result) { public void result(JSONObject result) {
} }
@Override protected void onResume() { @Override protected void onResume() {
super.onResume(); super.onResume();
Toast.makeText(this, "onResume", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "onResume", Toast.LENGTH_SHORT).show();
......
...@@ -181,13 +181,6 @@ public class SerialActivity extends Activity implements iRestapiListener { ...@@ -181,13 +181,6 @@ public class SerialActivity extends Activity implements iRestapiListener {
public void onClick(View view) { public void onClick(View view) {
String username = mSerialViewMail.getText().toString(); String username = mSerialViewMail.getText().toString();
String password = mSerialViewPass.getText().toString(); String password = mSerialViewPass.getText().toString();
// DE PRUEBA
// Alumno
//username = "faf0001";
//password = "faf000";
// Supervisor
//username = "dofer@ujaen.es";
//password = "dofer";
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
...@@ -195,6 +188,14 @@ public class SerialActivity extends Activity implements iRestapiListener { ...@@ -195,6 +188,14 @@ public class SerialActivity extends Activity implements iRestapiListener {
editor.putString("password", password); editor.putString("password", password);
editor.commit(); editor.commit();
// DE PRUEBA
// Alumno
//username = "faf0001";
//password = "faf000";
// Supervisor
username = "dofer@ujaen.es";
password = "dofer";
RestapiWrapper wrapper = PCBcontext.getRestapiWrapper(); RestapiWrapper wrapper = PCBcontext.getRestapiWrapper();
if (username.contains("@")){ if (username.contains("@")){
// Es un supervisor // Es un supervisor
...@@ -246,7 +247,7 @@ public class SerialActivity extends Activity implements iRestapiListener { ...@@ -246,7 +247,7 @@ public class SerialActivity extends Activity implements iRestapiListener {
public void result(JSONObject result) { public void result(JSONObject result) {
// Si llego aquí es porque hay un único valor, no un array // Si llego aquí es porque hay un único valor, no un array
try { try {
//Log.d(LOG_TAG, "JSON en result:"+result.toString()); Log.d(LOG_TAG, "JSON en result:"+result.toString());
if (result.toString().contains("error")){ if (result.toString().contains("error")){
progressDialog.dismiss(); progressDialog.dismiss();
...@@ -345,6 +346,18 @@ public class SerialActivity extends Activity implements iRestapiListener { ...@@ -345,6 +346,18 @@ public class SerialActivity extends Activity implements iRestapiListener {
progressDialog.dismiss(); progressDialog.dismiss();
} }
/*
AlertDialog.Builder builder = new AlertDialog.Builder(SerialActivity.this);
builder.setMessage("Es un supervisor. Sigo...")
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
*/
// Llamo a LoginActivity // Llamo a LoginActivity
Intent loginActivity = new Intent(this, LoginActivity.class); Intent loginActivity = new Intent(this, LoginActivity.class);
loginActivity.putExtra("token", jsonToken); loginActivity.putExtra("token", jsonToken);
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<fragment <fragment
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="600px" android:layout_height="400px"
class="com.yottacode.pictogram.gui.StudentFragmentGrid" class="com.yottacode.pictogram.gui.StudentFragmentGrid"
android:id="@+id/alumnos" android:id="@+id/alumnos"
android:layout_below="@+id/logintitle"/> android:layout_below="@+id/logintitle"/>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:padding="2dp" android:padding="2dp"
android:numColumns="5" android:numColumns="5"
android:verticalSpacing="5dp" android:verticalSpacing="1dp"
android:horizontalSpacing="5dp" android:horizontalSpacing="5dp"
android:gravity="center" android:gravity="center"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
......
...@@ -12,5 +12,6 @@ ...@@ -12,5 +12,6 @@
android:id="@+id/txt" android:id="@+id/txt"
android:layout_width="140dp" android:layout_width="140dp"
android:layout_height="140dp" android:layout_height="140dp"
android:layout_centerHorizontal="true"
android:layout_below="@+id/img"/> android:layout_below="@+id/img"/>
</RelativeLayout> </RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<!-- Strings de serial -->
<string name="title_activity_serial">Access data</string>
<string name="action_entrar">Login</string> <string name="action_entrar">Login</string>
<string name="action_settings">Settings</string> <string name="action_settings">Settings</string>
<string name="app_name">Pictogram</string> <string name="app_name">Pictogram</string>
<string name="db_script_error">Fail updating the data base</string> <string name="db_script_error">Fail updating the data base</string>
<string name="error_invalid_serial">These access data are not correct</string>
<string name="prompt_serial_mail">User</string> <string name="prompt_serial_mail">User</string>
<string name="prompt_serial_pass">Password</string> <string name="prompt_serial_pass">Password</string>
<string name="title_activity_login">Login</string> <string name="title_activity_login">Login</string>
...@@ -18,7 +19,7 @@ ...@@ -18,7 +19,7 @@
<string name="passErrorTxt">Invalid password</string> <string name="passErrorTxt">Invalid password</string>
<string name="passErrorMsg">This password is not correct. Try again.</string> <string name="passErrorMsg">This password is not correct. Try again.</string>
<string name="userErrorTxt">User not found</string> <string name="userErrorTxt">User not found</string>
<string name="userErrorMsg">The user is not correct. Try again.</string> <string name="userErrorMsg">The user is not correct. Inténtelo de nuevo.</string>
<!-- Alert dialogs --> <!-- Alert dialogs -->
<string name="exitPictogram">Exit Pictogram</string> <string name="exitPictogram">Exit Pictogram</string>
......
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