Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Application-Android-IUT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sofiane Lasri
Application-Android-IUT
Commits
545129ff
Commit
545129ff
authored
3 years ago
by
Sofiane Lasri
Browse files
Options
Downloads
Patches
Plain Diff
Partie 3: Persistance courte
parent
db671e89
No related branches found
No related tags found
No related merge requests found
Pipeline
#3
canceled
3 years ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/com/slprojects/pizzeria/MainActivity.java
+39
-28
39 additions, 28 deletions
app/src/main/java/com/slprojects/pizzeria/MainActivity.java
with
39 additions
and
28 deletions
app/src/main/java/com/slprojects/pizzeria/MainActivity.java
+
39
−
28
View file @
545129ff
package
com.slprojects.pizzeria
;
package
com.slprojects.pizzeria
;
import
androidx.annotation.NonNull
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.os.Bundle
;
import
android.os.Bundle
;
...
@@ -21,53 +22,63 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
...
@@ -21,53 +22,63 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_main
);
setContentView
(
R
.
layout
.
activity_main
);
boutons
=
new
ArrayList
<
Button
>();
boutons
=
new
ArrayList
<>();
idIndexes
=
new
ArrayList
<
Integer
>();
idIndexes
=
new
ArrayList
<>();
numCommands
=
new
ArrayList
<
Integer
>();
numCommands
=
new
ArrayList
<>();
nomBoutons
=
new
ArrayList
<
String
>();
nomBoutons
=
new
ArrayList
<>();
boutons
.
add
(
findViewById
(
R
.
id
.
napolitaine
));
boutons
.
add
(
findViewById
(
R
.
id
.
napolitaine
));
idIndexes
.
add
(
R
.
id
.
napolitaine
);
numCommands
.
add
(
idIndexes
.
indexOf
(
R
.
id
.
napolitaine
),
0
);
boutons
.
add
(
findViewById
(
R
.
id
.
royale
));
boutons
.
add
(
findViewById
(
R
.
id
.
royale
));
idIndexes
.
add
(
R
.
id
.
royale
);
numCommands
.
add
(
idIndexes
.
indexOf
(
R
.
id
.
royale
),
0
);
boutons
.
add
(
findViewById
(
R
.
id
.
quatreFromages
));
boutons
.
add
(
findViewById
(
R
.
id
.
quatreFromages
));
idIndexes
.
add
(
R
.
id
.
quatreFromages
);
numCommands
.
add
(
idIndexes
.
indexOf
(
R
.
id
.
quatreFromages
),
0
);
boutons
.
add
(
findViewById
(
R
.
id
.
montagnarde
));
boutons
.
add
(
findViewById
(
R
.
id
.
montagnarde
));
idIndexes
.
add
(
R
.
id
.
montagnarde
);
numCommands
.
add
(
idIndexes
.
indexOf
(
R
.
id
.
montagnarde
),
0
);
boutons
.
add
(
findViewById
(
R
.
id
.
raclette
));
boutons
.
add
(
findViewById
(
R
.
id
.
raclette
));
idIndexes
.
add
(
R
.
id
.
raclette
);
numCommands
.
add
(
idIndexes
.
indexOf
(
R
.
id
.
raclette
),
0
);
boutons
.
add
(
findViewById
(
R
.
id
.
hawaii
));
boutons
.
add
(
findViewById
(
R
.
id
.
hawaii
));
idIndexes
.
add
(
R
.
id
.
hawaii
);
numCommands
.
add
(
idIndexes
.
indexOf
(
R
.
id
.
hawaii
),
0
);
boutons
.
add
(
findViewById
(
R
.
id
.
pannaCotta
));
boutons
.
add
(
findViewById
(
R
.
id
.
pannaCotta
));
idIndexes
.
add
(
R
.
id
.
pannaCotta
);
numCommands
.
add
(
idIndexes
.
indexOf
(
R
.
id
.
pannaCotta
),
0
);
boutons
.
add
(
findViewById
(
R
.
id
.
tiramisu
));
boutons
.
add
(
findViewById
(
R
.
id
.
tiramisu
));
idIndexes
.
add
(
R
.
id
.
tiramisu
);
numCommands
.
add
(
idIndexes
.
indexOf
(
R
.
id
.
tiramisu
),
0
);
// On ajoute un listener sur chaque bouton
boutons
.
forEach
((
btn
)
->
btn
.
setOnClickListener
(
this
));
boutons
.
forEach
((
btn
)
->
btn
.
setOnClickListener
(
this
));
// On ajoute l'id de chaque bouton (normalement dans l'ordre
boutons
.
forEach
((
btn
)
->
idIndexes
.
add
(
btn
.
getId
()));
// Et on ajoute le nom de chaque bouton (également normalement dans l'ordre)
boutons
.
forEach
((
btn
)
->
nomBoutons
.
add
(
btn
.
getText
().
toString
()));
// On regarde s'il y a déjà eu une instance
if
(
savedInstanceState
!=
null
)
{
// On récupère le nombre de commandes
numCommands
=
savedInstanceState
.
getIntegerArrayList
(
"numCommands"
);
// Et on remet le nom avec les num de commandes aux boutons
boutons
.
forEach
(
this
::
setButtonText
);
}
else
{
// On réserve les espaces pour les commandes
boutons
.
forEach
((
btn
)
->
numCommands
.
add
(
idIndexes
.
indexOf
(
btn
.
getId
()),
0
));
}
}
@Override
protected
void
onSaveInstanceState
(
@NonNull
Bundle
outState
)
{
super
.
onSaveInstanceState
(
outState
);
outState
.
putIntegerArrayList
(
"numCommands"
,
numCommands
);
}
}
public
void
onClick
(
View
v
)
{
public
void
onClick
(
View
v
)
{
try
{
try
{
Button
bouton
=
boutons
.
get
(
idIndexes
.
indexOf
(
v
.
getId
()));
Button
bouton
=
boutons
.
get
(
idIndexes
.
indexOf
(
v
.
getId
()));
numCommands
.
set
(
idIndexes
.
indexOf
(
v
.
getId
()),
numCommands
.
get
(
idIndexes
.
indexOf
(
v
.
getId
()))+
1
);
numCommands
.
set
(
idIndexes
.
indexOf
(
v
.
getId
()),
numCommands
.
get
(
idIndexes
.
indexOf
(
v
.
getId
()))+
1
);
bouton
.
set
Text
(
bouton
.
getText
()
+
" : "
+
numCommands
.
get
(
idIndexes
.
indexOf
(
v
.
getId
()))
);
setButton
Text
(
bouton
);
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
Log
.
e
(
"Erreur"
,
e
.
getMessage
());
Log
.
e
(
"Erreur"
,
e
.
getMessage
());
}
}
}
}
public
void
setButtonText
(
Button
bouton
){
if
(
numCommands
.
get
(
idIndexes
.
indexOf
(
bouton
.
getId
()))
==
0
){
bouton
.
setText
(
nomBoutons
.
get
(
idIndexes
.
indexOf
(
bouton
.
getId
())));
}
else
{
String
titre
=
nomBoutons
.
get
(
idIndexes
.
indexOf
(
bouton
.
getId
()))
+
" : "
+
numCommands
.
get
(
idIndexes
.
indexOf
(
bouton
.
getId
()));
bouton
.
setText
(
titre
);
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment