Skip to content
GitLab
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
5031f6d8
Commit
5031f6d8
authored
Nov 16, 2017
by
Nastuzzi Samy
Browse files
Merge branch 'release/autoupdate'
parents
5e68c563
de236bd2
Changes
6
Hide whitespace changes
Inline
Side-by-side
app/src/main/AndroidManifest.xml
View file @
5031f6d8
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"fr.utc.simde.jessy"
android:versionCode=
"2
2
"
android:versionName=
"0.
8.6
"
>
android:versionCode=
"2
4
"
android:versionName=
"0.
9
"
>
<uses-permission
android:name=
"android.permission.NFC"
/>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.ACCESS_NETWORK_STATE"
/>
<uses-permission
android:name=
"android.permission.VIBRATE"
/>
<uses-permission
android:name=
"android.permission.WRITE_EXTERNAL_STORAGE"
/>
<application
android:allowBackup=
"true"
android:icon=
"@mipmap/ic_launcher"
android:label=
"@string/app_name"
android:roundIcon=
"@mipmap/ic_launcher_round"
android:supportsRtl=
"true"
android:launchMode=
"singleInstance"
android:stateNotNeeded=
"true"
android:theme=
"@style/AppTheme"
>
<activity
android:name=
"fr.utc.simde.jessy.MainActivity"
android:configChanges=
"orientation"
...
...
app/src/main/java/fr/utc/simde/jessy/BaseActivity.java
View file @
5031f6d8
package
fr.utc.simde.jessy
;
import
android.Manifest
;
import
android.app.Activity
;
import
android.app.DownloadManager
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.content.SharedPreferences
;
import
android.content.pm.PackageManager
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Environment
;
import
android.support.v4.app.ActivityCompat
;
import
android.support.v7.app.AlertDialog
;
import
android.util.Log
;
import
android.widget.BaseAdapter
;
import
android.widget.TextView
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
fr.utc.simde.jessy.tools.CASConnexion
;
import
fr.utc.simde.jessy.tools.Config
;
...
...
@@ -28,6 +43,10 @@ import fr.utc.simde.jessy.tools.NemopaySession;
public
abstract
class
BaseActivity
extends
NFCActivity
{
private
static
final
String
LOG_TAG
=
"_BaseActivity"
;
private
static
final
String
gitUrl
=
"https://raw.githubusercontent.com/simde-utc/jessy/master/"
;
private
static
final
String
manifestUrl
=
"app/src/main/AndroidManifest.xml"
;
private
static
final
String
downloadLocation
=
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DOWNLOADS
)
+
"/"
;
protected
static
NemopaySession
nemopaySession
;
protected
static
Ginger
ginger
;
protected
static
CASConnexion
casConnexion
;
...
...
@@ -539,4 +558,110 @@ public abstract class BaseActivity extends NFCActivity {
ginger
.
setKey
(
key
);
}
protected
boolean
haveStoragePermission
()
{
if
(
Build
.
VERSION
.
SDK_INT
>=
23
)
{
if
(
checkSelfPermission
(
android
.
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
)
==
PackageManager
.
PERMISSION_GRANTED
)
{
return
true
;
}
else
{
ActivityCompat
.
requestPermissions
(
this
,
new
String
[]{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
1
);
return
false
;
}
}
else
return
true
;
}
protected
void
checkUpdate
()
{
checkUpdate
(
true
);
}
protected
void
checkUpdate
(
final
boolean
popupIfNot
)
{
dialog
.
startLoading
(
BaseActivity
.
this
,
getString
(
R
.
string
.
information_collection
),
getString
(
R
.
string
.
check_update
));
new
Thread
()
{
@Override
public
void
run
()
{
HTTPRequest
httpRequest
=
new
HTTPRequest
(
gitUrl
+
manifestUrl
);
httpRequest
.
get
();
try
{
final
Matcher
matcher
=
Pattern
.
compile
(
"android:versionCode=\"([0-9]*)\".*android:versionName=\"(\\S*)\""
).
matcher
(
httpRequest
.
getResponse
());
if
(
matcher
.
find
())
{
if
(
BuildConfig
.
VERSION_CODE
>
Integer
.
parseInt
(
matcher
.
group
(
1
)))
{
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
final
AlertDialog
.
Builder
alertDialogBuilder
=
new
AlertDialog
.
Builder
(
BaseActivity
.
this
);
alertDialogBuilder
.
setTitle
(
R
.
string
.
update
)
.
setMessage
(
getString
(
R
.
string
.
available_update
)
+
"\n"
+
getString
(
R
.
string
.
actual_version
)
+
": "
+
BuildConfig
.
VERSION_NAME
+
"\n"
+
getString
(
R
.
string
.
available_version
)
+
": "
+
matcher
.
group
(
2
))
.
setCancelable
(
false
)
.
setPositiveButton
(
R
.
string
.
set_update
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialogInterface
,
int
id
)
{
if
(!
update
(
matcher
.
group
(
2
)))
{
dialog
.
stopLoading
();
dialog
.
errorDialog
(
BaseActivity
.
this
,
getString
(
R
.
string
.
update
),
getString
(
R
.
string
.
can_not_update
));
}
}
})
.
setNegativeButton
(
R
.
string
.
cancel
,
null
);
dialog
.
createDialog
(
alertDialogBuilder
);
}
});
}
else
if
(
popupIfNot
)
throw
new
Exception
(
getString
(
R
.
string
.
no_update
));
}
else
throw
new
Exception
(
getString
(
R
.
string
.
can_not_detect_update
));
}
catch
(
final
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"error: "
+
e
.
getMessage
());
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
dialog
.
stopLoading
();
dialog
.
errorDialog
(
BaseActivity
.
this
,
getString
(
R
.
string
.
update
),
e
.
getMessage
()
+
"\n"
+
getString
(
R
.
string
.
actual_version
)
+
": "
+
BuildConfig
.
VERSION_NAME
);
}
});
}
}
}.
start
();
}
protected
boolean
update
(
final
String
version
)
{
final
String
destination
=
this
.
downloadLocation
+
getString
(
R
.
string
.
app_name
)
+
" "
+
version
+
".apk"
;
final
String
url
=
this
.
gitUrl
+
getString
(
R
.
string
.
app_name
)
+
" "
+
version
+
".apk"
;
final
Uri
uri
=
Uri
.
parse
(
"file://"
+
destination
);
if
(!
haveStoragePermission
())
return
false
;
File
file
=
new
File
(
destination
);
if
(
file
.
exists
())
file
.
delete
();
DownloadManager
.
Request
request
=
new
DownloadManager
.
Request
(
Uri
.
parse
(
url
));
request
.
setDescription
(
getString
(
R
.
string
.
update
));
request
.
setTitle
(
getString
(
R
.
string
.
app_name
));
request
.
setDestinationUri
(
uri
);
final
DownloadManager
manager
=
(
DownloadManager
)
getSystemService
(
DOWNLOAD_SERVICE
);
final
long
downloadId
=
manager
.
enqueue
(
request
);
BroadcastReceiver
onComplete
=
new
BroadcastReceiver
()
{
public
void
onReceive
(
Context
ctx
,
Intent
intent
)
{
Intent
install
=
new
Intent
(
Intent
.
ACTION_VIEW
);
install
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
install
.
setDataAndType
(
uri
,
"application/vnd.android.package-archive"
);
startActivity
(
install
);
unregisterReceiver
(
this
);
finish
();
}
};
registerReceiver
(
onComplete
,
new
IntentFilter
(
DownloadManager
.
ACTION_DOWNLOAD_COMPLETE
));
return
true
;
}
}
app/src/main/java/fr/utc/simde/jessy/FoundationsOptionsActivity.java
View file @
5031f6d8
package
fr.utc.simde.jessy
;
import
android.Manifest
;
import
android.app.DownloadManager
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.content.pm.PackageManager
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Environment
;
import
android.os.StrictMode
;
import
android.support.v4.app.ActivityCompat
;
import
android.support.v7.app.AlertDialog
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
...
...
@@ -19,13 +31,17 @@ import android.widget.Toast;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
fr.utc.simde.jessy.adapters.FoundationsAdapter
;
import
fr.utc.simde.jessy.adapters.OptionChoicesAdapter
;
import
fr.utc.simde.jessy.adapters.OptionsAdapter
;
import
fr.utc.simde.jessy.tools.HTTPRequest
;
/**
* Created by Samy on 26/10/2017.
...
...
@@ -48,6 +64,9 @@ public class FoundationsOptionsActivity extends BaseActivity {
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_foundations_options
);
StrictMode
.
VmPolicy
.
Builder
builder
=
new
StrictMode
.
VmPolicy
.
Builder
();
StrictMode
.
setVmPolicy
(
builder
.
build
());
this
.
tabHost
=
findViewById
(
R
.
id
.
tabs_foundations_options
);
this
.
foundationList
=
findViewById
(
R
.
id
.
list_foundations
);
this
.
optionList
=
findViewById
(
R
.
id
.
list_options
);
...
...
@@ -112,14 +131,14 @@ public class FoundationsOptionsActivity extends BaseActivity {
@Override
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
final
int
position
,
long
id
)
{
if
(
isOption
(
position
,
0
))
dialog
.
infoDialog
(
FoundationsOptionsActivity
.
this
,
"Non encore fait"
,
"Pour la version 0.
9
"
);
dialog
.
infoDialog
(
FoundationsOptionsActivity
.
this
,
"Non encore fait"
,
"Pour la version 0.
10
"
);
else
if
(
isOption
(
position
,
1
))
dialog
.
infoDialog
(
FoundationsOptionsActivity
.
this
,
"Non encore fait"
,
"Pour la version 0.11"
);
else
if
(
isOption
(
position
,
2
))
dialog
.
infoDialog
(
FoundationsOptionsActivity
.
this
,
"Non encore fait"
,
"Pour la version 0.12"
);
else
if
(
isOption
(
position
,
1
))
else
if
(
isOption
(
position
,
3
))
dialog
.
infoDialog
(
FoundationsOptionsActivity
.
this
,
"Non encore fait"
,
"Pour la version 0.12"
);
else
if
(
isOption
(
position
,
2
))
else
if
(
isOption
(
position
,
4
))
dialog
.
infoDialog
(
FoundationsOptionsActivity
.
this
,
"Non encore fait"
,
"Pour la version 0.10"
);
else
if
(
isOption
(
position
,
5
))
startCardManagementActivity
(
FoundationsOptionsActivity
.
this
);
...
...
@@ -127,6 +146,8 @@ public class FoundationsOptionsActivity extends BaseActivity {
keyNemopayDialog
();
else
if
(
isOption
(
position
,
7
))
keyGingerDialog
();
else
if
(
isOption
(
position
,
8
))
checkUpdate
();
else
configDialog
();
}
...
...
app/src/main/java/fr/utc/simde/jessy/MainActivity.java
View file @
5031f6d8
...
...
@@ -3,11 +3,13 @@ package fr.utc.simde.jessy;
import
android.app.Activity
;
import
android.app.ProgressDialog
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.net.ConnectivityManager
;
import
android.os.Bundle
;
import
android.support.v7.app.AlertDialog
;
import
android.util.Log
;
import
android.view.KeyEvent
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.EditText
;
...
...
@@ -90,6 +92,7 @@ public class MainActivity extends BaseActivity {
});
setConfig
();
checkUpdate
(
false
);
}
@Override
...
...
@@ -120,6 +123,25 @@ public class MainActivity extends BaseActivity {
badgeDialog
(
badgeId
);
}
@Override
public
boolean
onKeyDown
(
int
keyCode
,
KeyEvent
event
)
{
if
(
Integer
.
parseInt
(
android
.
os
.
Build
.
VERSION
.
SDK
)
>
5
&&
keyCode
==
KeyEvent
.
KEYCODE_BACK
&&
event
.
getRepeatCount
()
==
0
)
{
onBackPressed
();
return
true
;
}
return
super
.
onKeyDown
(
keyCode
,
event
);
}
@Override
public
void
onBackPressed
()
{
Intent
setIntent
=
new
Intent
(
Intent
.
ACTION_MAIN
);
setIntent
.
addCategory
(
Intent
.
CATEGORY_HOME
);
setIntent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
startActivity
(
setIntent
);
}
@Override
protected
void
unregister
(
final
Activity
activity
)
{
super
.
unregister
(
activity
);
...
...
app/src/main/res/values/options.xml
View file @
5031f6d8
...
...
@@ -9,5 +9,6 @@
<item>
Gestion des cartes/cotisations
</item>
<item>
Modifier la clé Nemopay
</item>
<item>
Modifier la clé Ginger
</item>
<item>
Rechercher une mise à jour
</item>
</string-array>
</resources>
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
5031f6d8
...
...
@@ -57,6 +57,7 @@
<string
name=
"short_tag"
>
Numéro raccourci
</string>
<string
name=
"type"
>
Type
</string>
<string
name=
"day_s_"
>
jour(s)
</string>
<string
name=
"update"
>
Mise à jour
</string>
<string
name=
"author"
>
<
/
>
avec ♥ par Samy NASTUZZI
</string>
<string
name=
"error_unexpected"
>
Une erreur improbable a eu lieu
</string>
...
...
@@ -149,6 +150,14 @@
<string
name=
"contribute_ext"
>
Extérieur (20€)
</string>
<string
name=
"contribute_admin"
>
Membre d\'honneur (0€)
</string>
<string
name=
"contribute_temp"
>
Temporaire
</string>
<string
name=
"set_update"
>
Mettre à jour
</string>
<string
name=
"check_update"
>
Recherche d\'une mise à jour
</string>
<string
name=
"available_update"
>
Mise à jour disponible
</string>
<string
name=
"can_not_detect_update"
>
Impossible de détecter si une mise à jour disponible
</string>
<string
name=
"can_not_update"
>
Impossible de réaliser la mise à jour
</string>
<string
name=
"no_update"
>
Aucune mise à jour disponible
</string>
<string
name=
"actual_version"
>
Version actuelle
</string>
<string
name=
"available_version"
>
Version disponible
</string>
<string
name=
"print_mode"
>
Mode d\'affichage
</string>
<string
name=
"filters"
>
Filtres d\'affichage
</string>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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