Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hds
flexin
android-app
Commits
3a41b3c0
Commit
3a41b3c0
authored
Nov 17, 2017
by
Nastuzzi Samy
Browse files
Optimization
Better internet management Restart app if not connected at the start
parent
fa0b3977
Changes
5
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/fr/utc/simde/jessy/BaseActivity.java
View file @
3a41b3c0
...
...
@@ -164,35 +164,22 @@ public abstract class BaseActivity extends InternetActivity {
}.
start
();
}
protected
void
restartApp
(
Activity
activity
)
{
protected
void
restartApp
(
final
Activity
activity
)
{
try
{
PackageManager
pm
=
getPackageManager
();
//check if we got the PackageManager
if
(
pm
!=
null
)
{
//create the intent with the default start activity for your application
Intent
mStartActivity
=
pm
.
getLaunchIntentForPackage
(
getPackageName
()
);
if
(
mStartActivity
!=
null
)
{
mStartActivity
.
addFlags
(
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
);
//create a pending intent so the application is restarted after System.exit(0) was called.
// We use an AlarmManager to call this intent in 100ms
int
mPendingIntentId
=
223344
;
PendingIntent
mPendingIntent
=
PendingIntent
.
getActivity
(
activity
,
mPendingIntentId
,
mStartActivity
,
PendingIntent
.
FLAG_CANCEL_CURRENT
);
AlarmManager
mgr
=
(
AlarmManager
)
getSystemService
(
Context
.
ALARM_SERVICE
);
mgr
.
set
(
AlarmManager
.
RTC
,
System
.
currentTimeMillis
()
+
100
,
mPendingIntent
);
//kill the application
System
.
exit
(
0
);
}
else
{
Log
.
e
(
LOG_TAG
,
"Was not able to restart application, mStartActivity null"
);
}
}
else
{
Log
.
e
(
LOG_TAG
,
"Was not able to restart application, PM null"
);
}
}
catch
(
Exception
ex
)
{
Log
.
e
(
LOG_TAG
,
"Was not able to restart application"
);
Intent
mStartActivity
=
pm
.
getLaunchIntentForPackage
(
getPackageName
()
);
mStartActivity
.
addFlags
(
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
);
int
mPendingIntentId
=
223344
;
PendingIntent
mPendingIntent
=
PendingIntent
.
getActivity
(
activity
,
mPendingIntentId
,
mStartActivity
,
PendingIntent
.
FLAG_CANCEL_CURRENT
);
AlarmManager
mgr
=
(
AlarmManager
)
getSystemService
(
Context
.
ALARM_SERVICE
);
mgr
.
set
(
AlarmManager
.
RTC
,
System
.
currentTimeMillis
()
+
100
,
mPendingIntent
);
System
.
exit
(
0
);
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
e
.
getMessage
());
}
}
...
...
app/src/main/java/fr/utc/simde/jessy/InternetActivity.java
View file @
3a41b3c0
...
...
@@ -8,6 +8,7 @@ import android.content.IntentFilter;
import
android.net.ConnectivityManager
;
import
android.net.NetworkInfo
;
import
android.support.v7.app.AlertDialog
;
import
android.widget.TextView
;
import
android.widget.Toast
;
/**
...
...
@@ -38,12 +39,12 @@ public abstract class InternetActivity extends NFCActivity {
this
.
internetAlertDialog
.
setTitle
(
R
.
string
.
connection
)
.
setMessage
(
R
.
string
.
internet_accessibility
)
.
setCancelable
(
true
)
.
setPositiveButton
(
R
.
string
.
pass
,
null
)
.
setOnDismissListener
(
new
DialogInterface
.
OnDismissListener
()
{
.
setCancelable
(
false
)
.
setNegativeButton
(
R
.
string
.
pass
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
on
Dismiss
(
final
DialogInterface
dialog
)
{
public
void
on
Click
(
DialogInterface
dialog
,
int
which
)
{
internetAlertDialog
=
null
;
if
(!
checkInternet
(
context
))
enableInternetDialog
(
context
);
}
...
...
app/src/main/java/fr/utc/simde/jessy/MainActivity.java
View file @
3a41b3c0
...
...
@@ -2,6 +2,7 @@ package fr.utc.simde.jessy;
import
android.app.Activity
;
import
android.app.ProgressDialog
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
...
...
@@ -132,6 +133,21 @@ public class MainActivity extends BaseActivity {
casConnexionDialog
=
false
;
}
@Override
protected
void
enableInternetDialog
(
final
Context
context
)
{
Toast
.
makeText
(
context
,
R
.
string
.
internet_not_available
,
Toast
.
LENGTH_SHORT
).
show
();
dialog
.
infoDialog
(
MainActivity
.
this
,
getString
(
R
.
string
.
connection
),
getString
(
R
.
string
.
internet_accessibility
),
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
if
(!
checkInternet
(
context
))
enableInternetDialog
(
context
);
else
restartApp
(
MainActivity
.
this
);
}
});
}
@Override
public
boolean
onKeyDown
(
int
keyCode
,
KeyEvent
event
)
{
if
(
Integer
.
parseInt
(
android
.
os
.
Build
.
VERSION
.
SDK
)
>
5
&&
keyCode
==
KeyEvent
.
KEYCODE_BACK
&&
event
.
getRepeatCount
()
==
0
)
{
...
...
app/src/main/res/layout/activity_main.xml
View file @
3a41b3c0
...
...
@@ -68,7 +68,7 @@
android:paddingBottom=
"10dp"
android:gravity=
"center"
android:textStyle=
"italic"
android:text=
"@string/app_not_
registr
ed"
/>
android:text=
"@string/app_not_
connect
ed"
/>
</LinearLayout>
</RelativeLayout>
app/src/main/res/values/strings.xml
View file @
3a41b3c0
...
...
@@ -21,6 +21,7 @@
<string
name=
"quit"
>
Quitter
</string>
<string
name=
"app_registred"
>
Appareil enregistré
</string>
<string
name=
"app_not_registred"
>
Appareil non enregistré
</string>
<string
name=
"app_not_connected"
>
Appareil non connectée
</string>
<string
name=
"username_dialog"
>
Connexion par CAS
</string>
<string
name=
"badge_dialog"
>
Connexion par badge
</string>
<string
name=
"username"
>
Login
</string>
...
...
Write
Preview
Supports
Markdown
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