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
5c8657b3
Commit
5c8657b3
authored
Nov 15, 2017
by
Nastuzzi Samy
Browse files
Handle updates
Can download, and install new versions
parent
6f302781
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/src/main/AndroidManifest.xml
View file @
5c8657b3
<?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"
...
...
@@ -15,7 +16,6 @@
android:label=
"@string/app_name"
android:roundIcon=
"@mipmap/ic_launcher_round"
android:launchMode=
"singleTask"
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/FoundationsOptionsActivity.java
View file @
5c8657b3
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,6 +31,7 @@ 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
;
...
...
@@ -34,6 +47,10 @@ import fr.utc.simde.jessy.adapters.OptionsAdapter;
public
class
FoundationsOptionsActivity
extends
BaseActivity
{
private
static
final
String
LOG_TAG
=
"_FoundationsOptionsActi"
;
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
)
+
"/"
;
TabHost
tabHost
;
ListView
foundationList
;
ListView
optionList
;
...
...
@@ -48,6 +65,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 +132,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 +147,8 @@ public class FoundationsOptionsActivity extends BaseActivity {
keyNemopayDialog
();
else
if
(
isOption
(
position
,
7
))
keyGingerDialog
();
else
if
(
isOption
(
position
,
8
))
update
(
"0.8.4"
);
else
configDialog
();
}
...
...
@@ -135,6 +157,55 @@ public class FoundationsOptionsActivity extends BaseActivity {
this
.
optionList
.
setAdapter
(
this
.
optionsAdapter
);
}
public
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
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
);
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
;
}
protected
void
keyNemopayDialog
()
{
hasRights
(
getString
(
R
.
string
.
nemopay
),
new
String
[]{},
new
Runnable
(){
@Override
...
...
app/src/main/res/values/options.xml
View file @
5c8657b3
...
...
@@ -9,5 +9,6 @@
<item>
Gestion des cartes/cotisations
</item>
<item>
Modifier la clé Nemopay
</item>
<item>
Modifier la clé Ginger
</item>
<item>
Vérifier les mises à jour
</item>
</string-array>
</resources>
\ No newline at end of file
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