Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
yotta
/
pictogram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
60
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c02ecc5e
authored
Apr 05, 2016
by
Fernando Martínez Santiago
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Bug
#377
fixed
parent
f5adcd27
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
50 additions
and
28 deletions
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/MainActivity.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/PictogramActivity.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/SerialActivity.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/StudentFragmentGrid.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/net/NetService.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/tools/PCBcontext.java
android/Pictogram/app/src/main/java/com/yottacode/tools/GUITools.java
android/Pictogram/docs/login.pdf
android/Pictogram/docs/login.pptx
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/MainActivity.java
View file @
c02ecc5e
...
...
@@ -46,7 +46,7 @@ public class MainActivity extends Activity {
Intent
serialActivity
=
new
Intent
(
this
,
SerialActivity
.
class
);
serialActivity
.
putExtra
(
"
activity_name"
,
"MainActivity"
);
serialActivity
.
putExtra
(
"
resetPrevUser"
,
false
);
startActivity
(
serialActivity
);
}
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/PictogramActivity.java
View file @
c02ecc5e
...
...
@@ -403,7 +403,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
//Log.d(LOG_TAG, "SALTO A LOGIN");
// Paso un parámetro a la SerialActivity, para controlar de dónde viene
Intent
serialActivity
=
new
Intent
(
getBaseContext
(),
SerialActivity
.
class
);
serialActivity
.
putExtra
(
"
activity_name"
,
"PictogramActivity"
);
serialActivity
.
putExtra
(
"
resetPrevUser"
,
true
);
startActivity
(
serialActivity
);
}
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/SerialActivity.java
View file @
c02ecc5e
...
...
@@ -215,8 +215,6 @@ public class SerialActivity extends Activity {
GUITools
.
show_alert
(
SerialActivity
.
this
,
R
.
string
.
passErrorMsg
);
else
if
(((
LoginException
)
e
).
no_username_found
())
GUITools
.
show_alert
(
SerialActivity
.
this
,
R
.
string
.
userErrorMsg
);
else
if
(((
LoginException
)
e
).
no_supervisor_students
())
GUITools
.
show_alert
(
SerialActivity
.
this
,
R
.
string
.
noStudentsError
);
else
GUITools
.
show_alert
(
SerialActivity
.
this
,
R
.
string
.
serverError
,
e
.
getMessage
());
...
...
@@ -262,7 +260,13 @@ public class SerialActivity extends Activity {
else
manageStudentLogin
(
username
,
password
,
online
);
}
public
static
void
resetDefaultUser
()
{
SharedPreferences
settings
=
PCBcontext
.
getContext
().
getSharedPreferences
(
PREFS_NAME
,
0
);
SharedPreferences
.
Editor
editor
=
settings
.
edit
();
editor
.
putString
(
"username"
,
""
);
editor
.
putString
(
"password"
,
""
);
}
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
...
...
@@ -270,14 +274,14 @@ public class SerialActivity extends Activity {
setContentView
(
R
.
layout
.
activity_serial
);
Intent
intent
=
getIntent
();
String
activityName
=
intent
.
getStringExtra
(
"activity_name"
);
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
=
activityName
.
equals
(
"MainActivity"
)
?
settings
.
getString
(
"password"
,
""
)
:
""
;
String
password
=
intent
.
getBooleanExtra
(
"resetPrevUser"
,
true
)
?
""
:
settings
.
getString
(
"password"
,
""
)
;
// Escribo el último valor indicado de username
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/StudentFragmentGrid.java
View file @
c02ecc5e
...
...
@@ -220,13 +220,21 @@ public class StudentFragmentGrid extends Fragment{
e
.
printStackTrace
();
}
}
show_student_list_online
();
switch
(
students
.
length
())
{
case
0
:
GUITools
.
show_alert
(
getActivity
(),
R
.
string
.
noStudentsError
);
GUITools
.
show_alert
(
getActivity
(),
R
.
string
.
LoginError
,
getString
(
R
.
string
.
noStudentsError
),
new
GUITools
.
iOKListener
()
{
@Override
public
void
ok
()
{
PCBcontext
.
restart_app
();
}
});
break
;
case
1
:
new_user
(
0
);
break
;
default
:
show_student_list_online
();
}
}
@Override
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/net/NetService.java
View file @
c02ecc5e
...
...
@@ -13,6 +13,7 @@ import com.yottacode.pictogram.R;
import
com.yottacode.pictogram.dao.LoginException
;
import
com.yottacode.pictogram.dao.User
;
import
com.yottacode.pictogram.gui.PictogramActivity
;
import
com.yottacode.pictogram.gui.SerialActivity
;
import
com.yottacode.pictogram.tools.PCBcontext
;
import
org.json.JSONArray
;
...
...
@@ -49,16 +50,6 @@ public class NetService implements Runnable {
exec
.
scheduleWithFixedDelay
(
this
,
0
,
delay
,
TimeUnit
.
SECONDS
);
}
/**
* 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
*/
private
void
restart_app
()
{
Intent
i
=
PCBcontext
.
getContext
().
getPackageManager
()
.
getLaunchIntentForPackage
(
PCBcontext
.
getContext
().
getPackageName
());
i
.
addFlags
(
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
);
PCBcontext
.
getContext
().
startActivity
(
i
);
}
public
void
login
()
{
User
user
=
PCBcontext
.
getPcbdb
().
getCurrentUser
();
...
...
@@ -81,8 +72,8 @@ public class NetService implements Runnable {
@Override
public
void
error
(
Exception
e
)
{
Log
.
e
(
this
.
getClass
().
getSimpleName
(),
"Error un when server login:"
+
e
.
getMessage
());
if
(
e
instanceof
LoginException
)
restart_app
();
Log
.
e
(
this
.
getClass
().
getSimpleName
(),
"Error un when server login:"
+
e
.
getMessage
());
if
(
e
instanceof
LoginException
)
PCBcontext
.
restart_app
();
}
});
else
ServerLogin
.
login_student
(
user
.
get_nickname_stu
(),
user
.
get_pwd_stu
(),
new
iRestapiListener
()
{
...
...
@@ -104,7 +95,7 @@ public class NetService implements Runnable {
@Override
public
void
error
(
Exception
e
)
{
Log
.
e
(
this
.
getClass
().
getSimpleName
(),
"Error un when server login:"
+
e
.
getMessage
());
if
(
e
instanceof
LoginException
)
restart_app
()
;
if
(
e
instanceof
LoginException
)
PCBcontext
.
restart_app
();
;
}
});
}
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/tools/PCBcontext.java
View file @
c02ecc5e
package
com
.
yottacode
.
pictogram
.
tools
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.util.Log
;
import
com.yottacode.net.RestapiWrapper
;
...
...
@@ -11,6 +12,7 @@ import com.yottacode.pictogram.dao.Device;
import
com.yottacode.pictogram.dao.PCBDBHelper
;
import
com.yottacode.pictogram.dao.User
;
import
com.yottacode.pictogram.grammar.Vocabulary
;
import
com.yottacode.pictogram.gui.SerialActivity
;
import
com.yottacode.pictogram.net.NetService
;
import
com.yottacode.pictogram.action.Room
;
import
com.yottacode.pictogram.net.iImgDownloaderListener
;
...
...
@@ -80,10 +82,18 @@ public final class PCBcontext {
room
=
new
Room
();
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
*/
public
static
void
restart_app
()
{
SerialActivity
.
resetDefaultUser
();
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
...
...
android/Pictogram/app/src/main/java/com/yottacode/tools/GUITools.java
View file @
c02ecc5e
...
...
@@ -9,21 +9,30 @@ import android.util.Log;
* Created by Fernando on 01/04/2016.
*/
public
class
GUITools
{
public
static
void
show_alert
(
Context
context
,
int
resource_msg
)
{
show_alert
(
context
,
resource_msg
,
null
);
public
interface
iOKListener
{
public
void
ok
(
);
}
public
static
void
show_alert
(
Context
context
,
int
resource_msg
,
String
additional_msg
)
{
public
static
void
show_alert
(
Context
context
,
int
resource_msg
,
String
additional_msg
,
final
iOKListener
oklistener
)
{
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
context
);
String
msg
=
context
.
getString
(
resource_msg
);
if
(
additional_msg
!=
null
)
msg
+=
": "
+
additional_msg
;
Log
.
i
(
GUITools
.
class
.
getName
(),
"
FERNANDO
Alert:"
+
msg
);
if
(
additional_msg
!=
null
)
msg
+=
": "
+
additional_msg
;
Log
.
i
(
GUITools
.
class
.
getName
(),
"Alert:"
+
msg
);
builder
.
setMessage
(
msg
)
.
setCancelable
(
false
)
.
setPositiveButton
(
"Ok"
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialog
,
int
id
)
{
if
(
oklistener
!=
null
)
oklistener
.
ok
();
}
});
AlertDialog
alert
=
builder
.
create
();
alert
.
show
();
}
public
static
void
show_alert
(
Context
context
,
int
resource_msg
)
{
show_alert
(
context
,
resource_msg
,
null
);
}
public
static
void
show_alert
(
Context
context
,
int
resource_msg
,
String
additional_msg
)
{
show_alert
(
context
,
resource_msg
,
additional_msg
,
null
);
}
}
android/Pictogram/docs/login.pdf
View file @
c02ecc5e
No preview for this file type
android/Pictogram/docs/login.pptx
View file @
c02ecc5e
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment