This commit is contained in:
2024-03-25 17:33:16 +01:00
parent 67a5cd7df0
commit 719762ac01
95 changed files with 1997 additions and 95 deletions

1
DEV4.5/Couleurs/app/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

View File

@@ -0,0 +1,25 @@
apply plugin: 'com.android.application'
android {
compileSdk 33
buildToolsVersion '33.0.0'
defaultConfig {
applicationId "fr.iut_fbleau.apl41.couleurs"
minSdkVersion 19
targetSdk 33
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
}

17
DEV4.5/Couleurs/app/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /opt/android-sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View File

@@ -0,0 +1,13 @@
package fr.iut_fbleau.apl41.couleurs;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.iut_fbleau.apl41.couleurs">
<application
android:label="@string/app_name">
<activity
android:name=".Liste"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,45 @@
package fr.iut_fbleau.apl41.couleurs;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;
public class AccesBaseDeDonnees extends SQLiteOpenHelper {
public final static String NOM_BASE = "base_couleurs";
public final static int VERSION_BASE = 3;
public final static String NOM_TABLE = "couleurs";
public final static String CHAMP_NOM = "couleurs_nom";
public final static String CHAMP_VALEUR = "couleurs_valeur";
public AccesBaseDeDonnees(Context context) {
super(context, AccesBaseDeDonnees.NOM_BASE, null, AccesBaseDeDonnees.VERSION_BASE);
}
@Override
public void onCreate(SQLiteDatabase baseDeDonnees) {
baseDeDonnees.execSQL("create table " + AccesBaseDeDonnees.NOM_TABLE + "(" +
BaseColumns._ID + " integer primary key autoincrement, " +
AccesBaseDeDonnees.CHAMP_NOM + " text not null, " +
AccesBaseDeDonnees.CHAMP_VALEUR + " integer);");
ContentValues tuple = new ContentValues();
tuple.put(AccesBaseDeDonnees.CHAMP_NOM, "bleu Denim");
tuple.put(AccesBaseDeDonnees.CHAMP_VALEUR, 0xFF4B0082);
baseDeDonnees.insert(AccesBaseDeDonnees.NOM_TABLE, null, tuple);
tuple.put(AccesBaseDeDonnees.CHAMP_NOM, "bleu électrique");
tuple.put(AccesBaseDeDonnees.CHAMP_VALEUR, 0xFF1163E3);
baseDeDonnees.insert(AccesBaseDeDonnees.NOM_TABLE, null, tuple);
tuple.put(AccesBaseDeDonnees.CHAMP_NOM, "bleu vert");
tuple.put(AccesBaseDeDonnees.CHAMP_VALEUR, 0xFF40E0D0);
baseDeDonnees.insert(AccesBaseDeDonnees.NOM_TABLE, null, tuple);
}
@Override
public void onUpgrade(SQLiteDatabase baseDeDonnees, int vieux, int nouveau) {
baseDeDonnees.execSQL("drop table if exists " + AccesBaseDeDonnees.NOM_TABLE);
this.onCreate(baseDeDonnees);
}
}

View File

@@ -0,0 +1,20 @@
package fr.iut_fbleau.apl41.couleurs;
import android.app.Activity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;
/**
* Created by hernand on 3/28/17.
*/
public class ControleClic implements AdapterView.OnItemClickListener {
private Activity parent;
public ControleClic(Activity a) {
this.parent = a;
}
@Override
public void onItemClick(AdapterView<?> liste, View vue, int positionListe, long idBase) {
Toast.makeText(this.parent, "Clic sur ligne "+(positionListe+1), Toast.LENGTH_SHORT).show();
}
}

View File

@@ -0,0 +1,16 @@
package fr.iut_fbleau.apl41.couleurs;
import android.database.Cursor;
import android.view.View;
import android.widget.SimpleCursorAdapter;
public class Lieur implements SimpleCursorAdapter.ViewBinder {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if(view.getId() == R.id.couleur) {
view.setBackgroundColor(cursor.getInt(columnIndex));
return true;
}
return false;
}
}

View File

@@ -0,0 +1,59 @@
package fr.iut_fbleau.apl41.couleurs;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
public class Liste extends Activity {
private final static String[] CHAMPS = {AccesBaseDeDonnees.CHAMP_NOM, AccesBaseDeDonnees.CHAMP_VALEUR};
private final static int[] VUES = {R.id.nom, R.id.couleur};
private SimpleCursorAdapter adaptateur;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_liste);
this.adaptateur = new SimpleCursorAdapter(this, R.layout.row_element, null, Liste.CHAMPS, Liste.VUES, 0);
this.adaptateur.setViewBinder(new Lieur());
ListView elements = (ListView) this.findViewById(R.id.elements);
elements.setOnItemClickListener(new ControleClic(this));
elements.setAdapter(this.adaptateur);
this.remplirListe();
}
public void remplirListe() {
AccesBaseDeDonnees acces = new AccesBaseDeDonnees(this);
SQLiteDatabase baseDeDonnees = acces.getReadableDatabase();
Cursor curseur = baseDeDonnees.query(AccesBaseDeDonnees.NOM_TABLE, null, null, null, null, null, null);
if (curseur != null) {
this.adaptateur.swapCursor(curseur);
} else {
Toast.makeText(this, "Erreur d'accès à la base de données", Toast.LENGTH_SHORT).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
this.getMenuInflater().inflate(R.menu.menu_liste, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_ajouter) {
// TODO
return true;
}
return super.onOptionsItemSelected(item);
}
}

View File

@@ -0,0 +1,18 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".Liste"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"
>
<ListView
android:id="@+id/elements"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<View
android:layout_width="@dimen/color_size"
android:layout_height="@dimen/color_size"
android:id="@+id/couleur"
android:layout_margin="@dimen/color_margin"
android:background="#ff20a080"
android:gravity="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Vert"
android:id="@+id/nom"
android:layout_weight="1.0"
android:gravity="center_vertical|start" />
</LinearLayout>

View File

@@ -0,0 +1,13 @@
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".Liste"
>
<item
android:id="@+id/action_ajouter"
android:title="@string/action_ajouter"
android:orderInCategory="100"
android:showAsAction="never"
/>
</menu>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@@ -0,0 +1,5 @@
<resources>
<dimen name="activity_horizontal_margin">
64dp
</dimen>
</resources>

View File

@@ -0,0 +1,14 @@
<resources>
<dimen name="activity_horizontal_margin">
16dp
</dimen>
<dimen name="activity_vertical_margin">
16dp
</dimen>
<dimen name="color_size">
32dp
</dimen>
<dimen name="color_margin">
12dp
</dimen>
</resources>

View File

@@ -0,0 +1,8 @@
<resources>
<string name="app_name">
Couleurs
</string>
<string name="action_ajouter">
Ajouter
</string>
</resources>

View File

@@ -0,0 +1,15 @@
package fr.iut_fbleau.apl41.couleurs;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}