quelques avancee sur l'ex2

This commit is contained in:
Alexis WAMSTER 2024-03-08 16:35:02 +01:00
parent bc4ede3cee
commit abbc7c0a63
16 changed files with 323 additions and 9 deletions

View File

@ -4,8 +4,9 @@
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" /> <option name="gradleJvm" value="Embedded JDK" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />

View File

@ -4,8 +4,9 @@
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" /> <option name="gradleJvm" value="Embedded JDK" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />

View File

@ -16,6 +16,7 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
this.img = this.findViewById(R.id.imageFleche); this.img = this.findViewById(R.id.imageFleche);
this.bouttonGauche = this.findViewById(R.id.boutonGauche); this.bouttonGauche = this.findViewById(R.id.boutonGauche);
this.bouttonDroite = this.findViewById(R.id.boutonDroite); this.bouttonDroite = this.findViewById(R.id.boutonDroite);

View File

@ -4,8 +4,9 @@
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" /> <option name="gradleJvm" value="Embedded JDK" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@ -26,6 +26,7 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }
buildToolsVersion '34.0.0'
} }
dependencies { dependencies {

View File

@ -0,0 +1,33 @@
package fr.iutfbleau.dev45.wamster.tp05ex02_arcenciel;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import androidx.appcompat.app.AppCompatActivity;
public class Activite2 extends AppCompatActivity {
private CheckBox[] listeChoix;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activite_choix);
this.listeChoix = new CheckBox[ListeCouleur.TAILLE_LISTE];
this.listeChoix[ListeCouleur.INDICE_ROUGE] = findViewById(R.id.coche_rouge);
this.listeChoix[ListeCouleur.INDICE_ORANGE] = findViewById(R.id.coche_orange);
this.listeChoix[ListeCouleur.INDICE_JAUNE] = findViewById(R.id.coche_jaune);
this.listeChoix[ListeCouleur.INDICE_VERT] = findViewById(R.id.coche_vert);
this.listeChoix[ListeCouleur.INDICE_BLEU] = findViewById(R.id.coche_bleu);
this.listeChoix[ListeCouleur.INDICE_INDIGO] = findViewById(R.id.coche_indigo);
this.listeChoix[ListeCouleur.INDICE_VIOLET] = findViewById(R.id.coche_violet);
EvenementBoutonValider evenementBoutonValider = new EvenementBoutonValider(this);
Button boutonValider = findViewById(R.id.bouton_valider);
boutonValider.setOnClickListener(evenementBoutonValider);
}
public CheckBox[] getListeCoche(){
return this.listeChoix;
}
}

View File

@ -0,0 +1,50 @@
package fr.iutfbleau.dev45.wamster.tp05ex02_arcenciel;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
public class DetectClic extends GestureDetector.SimpleOnGestureListener{
private long tempsPression;
private static final int LONG_PRESS_TIME = 500;
private View view;
private ListeCouleur gestionCouleur;
public DetectClic(View view){
this.view = view;
this.gestionCouleur = new ListeCouleur();
}
@Override
public boolean onDown(MotionEvent e) {
this.tempsPression = System.currentTimeMillis();
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
Log.v("test","Fling");
return true;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
if (System.currentTimeMillis() - this.tempsPression < DetectClic.LONG_PRESS_TIME) {
this.view.setBackgroundColor(this.gestionCouleur.couleurSuivante());
Log.v("test","Single Tap");
return true;
}
return false;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
Log.v("test","Double Tap");
return true;
}
@Override
public void onLongPress(MotionEvent e) {
Log.v("test","Long Press");
}
}

View File

@ -0,0 +1,18 @@
package fr.iutfbleau.dev45.wamster.tp05ex02_arcenciel;
import android.content.Intent;
import android.view.View;
public class EvenementBoutonChoix implements View.OnClickListener {
private MainActivity mainActivity;
public EvenementBoutonChoix(MainActivity mainActivity){
this.mainActivity = mainActivity;
}
@Override
public void onClick(View v){
Intent intention = new Intent(this.mainActivity, Activite2.class);
this.mainActivity.startActivity(intention);
}
}

View File

@ -0,0 +1,31 @@
package fr.iutfbleau.dev45.wamster.tp05ex02_arcenciel;
import android.content.Intent;
import android.view.View;
import android.widget.CheckBox;
public class EvenementBoutonValider implements View.OnClickListener {
private Activite2 activite2;
public EvenementBoutonValider(Activite2 activite2){
this.activite2 = activite2;
}
@Override
public void onClick(View v){
boolean[] etatCoche = this.getEtatCoche();
Intent intention = new Intent(this.activite2, MainActivity.class);
this.activite2.startActivity(intention);
}
public boolean[] getEtatCoche(){
CheckBox[] listeCoche = this.activite2.getListeCoche();
boolean[] listeEtatCoche = new boolean[listeCoche.length];
int i;
for (i=0; i<listeEtatCoche.length; i++){
listeEtatCoche[i] = listeCoche[i].isChecked();
}
return listeEtatCoche;
}
}

View File

@ -0,0 +1,20 @@
package fr.iutfbleau.dev45.wamster.tp05ex02_arcenciel;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
public class EvenementClic implements View.OnTouchListener{
private GestureDetector gestureDetector;
private DetectClic listener;
public EvenementClic(View view) {
this.listener = new DetectClic(view);
gestureDetector = new GestureDetector(this.listener);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
}

View File

@ -0,0 +1,61 @@
package fr.iutfbleau.dev45.wamster.tp05ex02_arcenciel;
public class ListeCouleur {
public final static int INDICE_ROUGE = 0;
public final static int INDICE_ORANGE = 1;
public final static int INDICE_JAUNE = 2;
public final static int INDICE_VERT = 3;
public final static int INDICE_BLEU = 4;
public final static int INDICE_INDIGO = 5;
public final static int INDICE_VIOLET = 6;
public final static int TAILLE_LISTE = 7;
private int indexColor;
private boolean [] couleurValide;
private final static int[] listeCouleur = {
0xfff00020,
0xffff7f00,
0xfffdfd96,
0xff00561b,
0xff0080ff,
0xff4b0082,
0xff7f00ff
};
public ListeCouleur(){
this.indexColor = 0;
this.setValideCouleurTrue();
}
public ListeCouleur(boolean[] etatCouleur){
this.indexColor = 0;
if (!this.setValideCouleur(etatCouleur)){
this.setValideCouleurTrue();
}
}
public int couleurSuivante(){
int i;
for (i=0; i<ListeCouleur.listeCouleur.length; i++){
this.indexColor = (this.indexColor+1)%ListeCouleur.listeCouleur.length;
if (this.couleurValide[this.indexColor] == false){
return ListeCouleur.listeCouleur[this.indexColor];
}
}
return 0x00000000;
}
public boolean setValideCouleur(boolean[] nouvelEtat){
if (nouvelEtat.length == ListeCouleur.listeCouleur.length){
this.couleurValide = nouvelEtat;
return true;
}
return false;
}
public void setValideCouleurTrue(){
this.couleurValide = new boolean[ListeCouleur.listeCouleur.length];
int i;
for (i=0; i<ListeCouleur.listeCouleur.length; i++){
this.couleurValide[i] = true;
}
}
}

View File

@ -3,6 +3,8 @@ package fr.iutfbleau.dev45.wamster.tp05ex02_arcenciel;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
@ -10,5 +12,14 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
View arrierePlan = findViewById(R.id.arrierePlan);
Button bouton = findViewById(R.id.bouton);
EvenementClic evenementClic = new EvenementClic(arrierePlan);
EvenementBoutonChoix evenementBoutonChoix = new EvenementBoutonChoix(this);
arrierePlan.setOnTouchListener(evenementClic);
bouton.setOnClickListener(evenementBoutonChoix);
} }
} }

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<CheckBox
android:id="@+id/coche_rouge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Rouge"/>
<CheckBox
android:id="@+id/coche_orange"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Orange"/>
<CheckBox
android:id="@+id/coche_jaune"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Jaune"/>
<CheckBox
android:id="@+id/coche_vert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Vert"/>
<CheckBox
android:id="@+id/coche_bleu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bleu"/>
<CheckBox
android:id="@+id/coche_indigo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Indigo"/>
<CheckBox
android:id="@+id/coche_violet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Violet"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_horizontal">
<Button
android:id="@+id/bouton_valider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Valider"
android:layout_marginEnd="8dp"/>
<Button
android:id="@+id/bouton_annuler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Annuler"
android:layout_marginStart="8dp"/>
</LinearLayout>
</LinearLayout>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -7,12 +7,19 @@
tools:context=".MainActivity"> tools:context=".MainActivity">
<View <View
android:id="@+id/arrierePlan"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"
android:background="#fff00020"/>
<Button <Button
android:id="@+id/bouton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Sélection"/> android:text="Sélection"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="50dp" />
/>
</LinearLayout> </RelativeLayout>