Commit a3812f5a by Pablo Molina

Merge branch 'issue/398' into 'develop'

Solved #398
parents 9675647e 3bd187ed
......@@ -2,7 +2,6 @@ package com.yottacode.pictogram.gui;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -11,17 +10,24 @@ import android.widget.ImageView;
import android.widget.TextView;
import com.yottacode.pictogram.R;
import com.yottacode.pictogram.tools.Img;
import java.io.IOException;
import java.util.Vector;
/**
* Creates a View for each student on the list with a photo and his/her name.
* It uses list_single.xml for the layout creation.
*/
public class CustomList extends ArrayAdapter<String>{
private final Activity context;
private final String[] name_surname;
private final Vector<Bitmap> images;
/**
* @param context Context used for rendering the view
* @param name_surname List of students' names
* @param images List of students' photos
*/
public CustomList(Activity context,
String[] name_surname, Vector<Bitmap> images) {
super(context, R.layout.list_single, name_surname);
......@@ -30,13 +36,19 @@ public class CustomList extends ArrayAdapter<String>{
this.images = images;
}
/**
* @param position Student position in the name_surname/images arrays
* @param view @TODO not being used
* @param parent @TODO not being used
* @return The rendered student view
*/
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.list_single, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);
TextView txtTitle = (TextView) rowView.findViewById(R.id.loginStudentName);
ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
ImageView imageView = (ImageView) rowView.findViewById(R.id.loginStudentPhoto);
txtTitle.setText(name_surname[position]);
//imageView.setImageResource(R.drawable.user);
......
package com.yottacode.pictogram.gui;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v4.app.FragmentActivity;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Toast;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.yottacode.pictogram.R;
import com.yottacode.pictogram.net.ImgDownloader;
import com.yottacode.pictogram.net.iImgDownloaderListener;
import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext;
import java.io.IOException;
import java.util.Vector;
/**
* LoginActivity show the login window to select the student and supervisor
* It uses device to read the token value
* @author Miguel Ángel García Cumbreras
* @author Fernando Martínez santiago
* @version 1.0
*/
public class LoginActivity extends FragmentActivity {
private int sup_id;
// String constant for logs
private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName()
/**
* If there is Internet connection it calls the WS to recover the pairs student-supervisor
* @param savedInstanceState
......@@ -39,10 +41,58 @@ public class LoginActivity extends FragmentActivity {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_login);
// Enable logout button
final Button logoutButton = (Button) findViewById(R.id.loginTopbarLogout);
logoutButton.setEnabled(true);
logoutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent serialActivity = new Intent(getBaseContext(), SerialActivity.class);
serialActivity.putExtra("resetPrevUser", true);
startActivity(serialActivity);
}
});
// Set supervisor information on topbar
final TextView supervisorFullNameView = (TextView) findViewById(R.id.loginTopbarSupervisorFullName);
final TextView supervisorUserNameView = (TextView) findViewById(R.id.loginTopbarSupervisorUserName);
final ImageView supervisorPhotoView = (ImageView) findViewById(R.id.loginTopbarSupervisorPhoto);
supervisorFullNameView.setText(
this.getIntent().getStringExtra("name") + " " +
this.getIntent().getStringExtra("surname"));
supervisorUserNameView.setText(this.getIntent().getStringExtra("email"));
final Vector<Img> imgs = new Vector<>(1);
imgs.add(new Img(
this.getIntent().getIntExtra("id", -1),
this.getIntent().getStringExtra("pic"),
Img.SUPERVISOR
));
ImgDownloader downloader = new ImgDownloader(this, new iImgDownloaderListener() {
@Override
public void loadComplete() {
try {
supervisorPhotoView.setImageBitmap(
imgs.get(0).get_bitmap(PCBcontext.getContext())
);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void loadImg(Img image) {}
}, ImgDownloader.tsource.remote);
downloader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, imgs);
}
@Override
protected void onResume() {
super.onResume();
Toast.makeText(this, "onResume", Toast.LENGTH_SHORT).show();
}
}
\ No newline at end of file
......@@ -285,7 +285,7 @@ public class StudentFragmentGrid extends Fragment{
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_new_student, container, false);
gridView = (GridView)view.findViewById(R.id.gridview);
gridView = (GridView)view.findViewById(R.id.loginStudentGridView);
Boolean offline = getActivity().getIntent().getBooleanExtra("offline", false);
if (offline || onlineStudentsOK) showStudentsGrid();
return view;
......
......@@ -17,12 +17,7 @@ import com.yottacode.pictogram.net.NetService;
import com.yottacode.pictogram.action.Room;
import com.yottacode.pictogram.net.iImgDownloaderListener;
/**
* Created by emblanco on 15/10/15.
* Modified by Fernando on 09/11/15: NetService, Room, Vocabulary, RestapiWrapper, Context, Action support
*/
public final class PCBcontext {
private static Context context;
private static PCBDBHelper pcbdb;
private static Device device=null;
......@@ -47,34 +42,40 @@ public final class PCBcontext {
return Holder.INSTANCE;
}
//
// ---------------------------------------------------------------------------------------------
// Rest of class methods
//
// Init method for passing params to the singleton
/**
* Init method for passing params to the singleton
* @param c @TODO application or activity context?
*/
public static void init(Context c){
if (!init) {
init=true;
init = true;
context = c;
device = new Device(c, null, 1);
SSLDummyContext.init(context.getResources().getBoolean(R.bool.ssl_connect));
wrapper = new RestapiWrapper(context.getResources().getString(R.string.server), null);
service = new NetService(context.getResources().getInteger(R.integer.netservice_timing));
device.deleteDeprecatedImgs();
Log.i(PCBcontext.class.getCanonicalName(), "PCB context started. It's required set_user method call");
Log.i(PCBcontext.class.getCanonicalName(), "PCB context started. It's required" +
"set_user method call");
} else {
Log.e(PCBcontext.class.getClass().getCanonicalName(), "Init method was previously" +
"invoked! Please, check your code");
}
else Log.e(PCBcontext.class.getClass().getCanonicalName(), "Init method was previously invoked! Please, revise your code");
}
/**
*
* Init method for passing the rest of params to the singleton.
* It is required to set the device token before calling set_user
* @param student
* @param student @TODO user is not student
* @param listener
*/
public static void set_user(User student, String token, iImgDownloaderListener listener) {
if (!init) throw new java.lang.AssertionError("init must be called once previously ");
if (!init) {
throw new java.lang.AssertionError("init must be called once previously ");
}
Log.i(PCBcontext.class.getCanonicalName(), "User set at student " + student.get_name_stu());
wrapper.setToken(token);
pcbdb = new PCBDBHelper(null, 1, student);
......@@ -83,59 +84,131 @@ public final class PCBcontext {
actionLog = new ActionLog();
vocabulary = new Vocabulary(listener);
}
/**
* if the user becomes from offline to online and the login is failed, then the user relogin in the app
* The most frequent reason is a password change while the user have been logged offline
* if the user becomes from offline to online and the login is failed, then the user relogin in
* the app. The most frequent reason is a password change while the user have been logged
* offline
*/
public static void restart_app() {
SerialActivity.resetDefaultUser();
public static void restart_app() {
SerialActivity.resetDefaultUser();
Intent serialActivity = new Intent(PCBcontext.getContext(), SerialActivity.class);
serialActivity.putExtra("resetPrevUser", true);
PCBcontext.getContext().startActivity(serialActivity);
}
Intent serialActivity = new Intent(PCBcontext.getContext(), SerialActivity.class);
serialActivity.putExtra("resetPrevUser", true);
PCBcontext.getContext().startActivity(serialActivity);
}
/**
*
* @return true if the user is logged offline and it has not been online previously. False in other case (user not logged, user logged online, user offline but it was previously online logged
* @return true if the user is logged offline and it has not been online previously. False in
* other case (user not logged, user logged online, user offline but it was previously online
* logged
*/
public static boolean is_user_offline() {
return pcbdb == null ? false //no hay usuario aun
: !getPcbdb().isUser_online();
if (pcbdb == null) {
return false;
} else {
return !getPcbdb().isUser_online();
}
}
public static boolean is_user_online() {
return pcbdb != null && getPcbdb().isUser_online();
}
// Return the context
// modified by Fernando
public static Context getContext(){ if (context==null) throw new java.lang.NullPointerException("Context is null. PCBcontext.init must be invoked previously"); return context; }
// Return the device
// modified by Fernando
public static Device getDevice(){ if (device==null) throw new java.lang.NullPointerException("Device is null. PCBcontext.init must be invoked previously");return device; }
/**
* @return context
* @TODO complete documentation
*/
public static Context getContext() {
if (context == null) {
throw new java.lang.NullPointerException("Context is null. PCBcontext.init must be" +
"invoked previously");
}
return context;
}
// Return the PCBDB
// modified by Fernando
public static PCBDBHelper getPcbdb(){ if (context==null) throw new java.lang.NullPointerException("PCBDB is null. PCBcontext.set_user must be invoked previously");return pcbdb; }
/**
* @return device
* @TODO complete documentation
*/
public static Device getDevice() {
if (device == null) {
throw new java.lang.NullPointerException("Device is null. PCBcontext.init must be" +
"invoked previously");
}
return device;
}
// Return the NetService
// modified by Fernando
public static NetService getNetService(){ if (service==null) throw new java.lang.NullPointerException("NetService is null. PCBcontext.set_user must be invoked previously"); return service; }
/**
* @return PCBDB
* @TODO complete documentation
*/
public static PCBDBHelper getPcbdb() {
if (context == null) {
throw new java.lang.NullPointerException("PCBDB is null. PCBcontext.set_user must be" +
"invoked previously");
}
return pcbdb;
}
// Return the RestapiWrapper
// modified by Fernando
public static RestapiWrapper getRestapiWrapper(){ if (wrapper==null) throw new java.lang.NullPointerException("RestapiWrapper is null. PCBcontext.init must be invoked previously"); return wrapper; }
/**
* @return NetService
* @TODO complete documentation
*/
public static NetService getNetService(){
if (service == null) {
throw new java.lang.NullPointerException("NetService is null. PCBcontext.set_user" +
"must be invoked previously");
}
return service;
}
// Return the Room
// modified by Fernando
public static Room getRoom(){ if (room==null) throw new java.lang.NullPointerException("Room is null. PCBcontext.set_user must be invoked previously"); return room; }
/**
* @return RestapiWrapper
* @TODO complete documentation
*/
public static RestapiWrapper getRestapiWrapper(){
if (wrapper == null) {
throw new java.lang.NullPointerException("RestapiWrapper is null. PCBcontext.init" +
"must be invoked previously");
}
return wrapper;
}
/**
* @return Room
* @TODO complete documentation
*/
public static Room getRoom(){
if (room == null) {
throw new java.lang.NullPointerException("Room is null. PCBcontext.set_user must" +
"be invoked previously");
}
return room;
}
// Return the Vocabulary
// modified by Fernando
public static Vocabulary getVocabulary(){ if (vocabulary==null) throw new java.lang.NullPointerException("Vocabulary is null. PCBcontext.set_user must be invoked previously"); return vocabulary; }
/**
* @return Vocabulary
* @TODO complete documentation
*/
public static Vocabulary getVocabulary(){
if (vocabulary == null) {
throw new java.lang.NullPointerException("Vocabulary is null. PCBcontext.set_user" +
"must be invoked previously");
}
return vocabulary;
}
// Return the ActionLog
// modified by Fernando
public static ActionLog getActionLog(){ if (actionLog==null) throw new java.lang.NullPointerException("ActionLog is null. PCBcontext.set_user must be invoked previously"); return actionLog; }
/**
* @return ActionLog
* @TODO complete documentation
*/
public static ActionLog getActionLog(){
if (actionLog == null) {
throw new java.lang.NullPointerException("ActionLog is null. PCBcontext.set_user" +
"must be invoked previously");
}
return actionLog;
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
tools:context="com.yottacode.pictogram.gui.LoginActivity">
<TextView
android:layout_width="fill_parent"
android:layout_height="100px"
android:gravity="center"
android:id="@+id/logintitle"
android:text="@string/loginTitle"
android:textStyle="bold"
android:textColor="@color/material_blue_grey_800"
android:textSize="20px"
android:layout_alignParentTop="true"/>
<fragment
android:layout_width="fill_parent"
android:layout_height="400px"
class="com.yottacode.pictogram.gui.StudentFragmentGrid"
android:id="@+id/alumnos"
android:layout_below="@+id/logintitle"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_margin="8dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="0dp"
android:id="@+id/loginTopbarLayout">
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:id="@+id/loginTopbarSupervisorPhoto"
android:layout_gravity="left"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:background="@color/accent_material_dark"
android:scaleType="centerCrop" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/loginTopbarSupervisorNameLayout"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/loginTopbarSupervisorPhoto"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text=""
android:id="@+id/loginTopbarSupervisorFullName" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text=""
android:id="@+id/loginTopbarSupervisorUserName"
android:textColor="@color/abc_secondary_text_material_light" />
</LinearLayout>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/logout"
android:id="@+id/loginTopbarLogout"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:enabled="false" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"
android:layout_marginBottom="16dp"
android:id="@+id/view"
android:layout_below="@+id/loginTopbarLayout"
android:layout_marginTop="0dp" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/loginTopbarLayout">
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
class="com.yottacode.pictogram.gui.StudentFragmentGrid"
android:id="@+id/loginStudentGrid"
android:layout_gravity="center"
tools:layout="@layout/fragment_new_student" />
</FrameLayout>
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:id="@+id/loginStudentGridView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="2dp"
android:numColumns="5"
android:verticalSpacing="1dp"
android:horizontalSpacing="5dp"
android:gravity="center"
android:layout_alignParentTop="true"
/>
android:layout_height="wrap_content"
android:numColumns="auto_fit"
android:gravity="center_vertical|center|center_horizontal"
android:stackFromBottom="false"
android:padding="32dp"
android:horizontalSpacing="16dp"
android:verticalSpacing="16dp" />
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical|center_horizontal">
<ImageView
android:id="@+id/img"
android:layout_width="140dp"
android:layout_height="140dp"
android:layout_alignParentTop="true"/>
android:id="@+id/loginStudentPhoto"
android:layout_width="128dp"
android:layout_height="128dp"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/txt"
android:layout_width="140dp"
android:layout_height="140dp"
android:id="@+id/loginStudentName"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:layout_below="@+id/loginStudentPhoto"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_centerHorizontal="true"
android:layout_below="@+id/img"/>
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:gravity="center" />
</RelativeLayout>
\ No newline at end of file
......@@ -15,6 +15,7 @@
<string name="title_activity_login_activity_fragments">Users login</string>
<string name="title_activity_pictogram">PictogramActivity</string>
<string name="title_activity_splash_screen">SplashScreenActivity</string>
<string name="logout">Logout</string>
<string name="loginTitle">Who are you?</string>
<string name="LoginError">Login</string>
<string name="passErrorMsg">This password is not correct. Try again.</string>
......
......@@ -16,6 +16,7 @@
<string name="prompt_serial_mail">Usuario</string>
<string name="prompt_serial_pass">Contraseña</string>
<string name="action_entrar">Entrar</string>
<string name="logout">Cerrar sesión</string>
<string name="loginTitle">¿Quién eres?</string>
<string name="LoginError">Login</string>
<string name="passErrorMsg">La contraseña indicada no es correcta. Inténtelo de nuevo.</string>
......
......@@ -16,6 +16,7 @@
<string name="prompt_serial_mail">Usuario</string>
<string name="prompt_serial_pass">Contraseña</string>
<string name="action_entrar">Entrar</string>
<string name="logout">Cerrar sesión</string>
<string name="loginTitle">¿Quién eres?</string>
<string name="LoginError">Login</string>
<string name="passErrorMsg">La contraseña indicada no es correcta. Inténtelo de nuevo.</string>
......
......@@ -75,7 +75,7 @@ UPDATE office SET admin=(SELECT id FROM supervisor where name='Fernando' and sur
--
-- Supervisores de CAJA
--
UPDATE supervisor SET pic='http://wwwdi.ujaen.es/sites/default/files/yo.jpg?1448019356' WHERE name='Fernando' and surname='Martínez Santiago';
UPDATE supervisor SET pic='/upload/supervisors/dofer.jpg' WHERE name='Fernando' and surname='Martínez Santiago';
UPDATE supervisor SET pic='http://wwwdi.ujaen.es/sites/default/files/foto1.jpg?1403259981' WHERE name='Arturo' and surname='Montejo Raéz';
UPDATE supervisor SET pic='http://wwwdi.ujaen.es/sites/default/files/magc_0.jpg?1244537764' WHERE name='Miguel Ángel' and surname='García Cumbreras';
UPDATE supervisor SET pic='http://wwwdi.ujaen.es/sites/default/files/foto_informal.jpg?1403609246' WHERE name='Alfonso' and surname='Ureña López';
......
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