mirror of
https://github.com/LucasVbr/OutilCuisson.git
synced 2026-05-13 17:11:53 +00:00
Les fragments ça fonctionne + Interface Ajouter (pas terminée)
This commit is contained in:
@@ -6,7 +6,33 @@
|
||||
|
||||
package com.example.outilcuisson;
|
||||
|
||||
/**
|
||||
* TODO class comment
|
||||
*/
|
||||
public class AdaptateurPage {}
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
|
||||
public class AdaptateurPage extends FragmentStateAdapter {
|
||||
|
||||
private static final int NB_FRAGMENT = 2;
|
||||
|
||||
public AdaptateurPage(FragmentActivity activite) {
|
||||
super(activite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment createFragment(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return AfficherFragment.newInstance();
|
||||
case 1:
|
||||
return AjouterFragment.newInstance();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return NB_FRAGMENT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,30 @@
|
||||
|
||||
package com.example.outilcuisson;
|
||||
|
||||
/**
|
||||
* TODO class comment
|
||||
*/
|
||||
public class AfficherFragment {}
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
public class AfficherFragment extends Fragment {
|
||||
|
||||
public AfficherFragment() {}
|
||||
|
||||
public static AfficherFragment newInstance() {
|
||||
return new AfficherFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.afficher_fragment, container, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,43 @@
|
||||
|
||||
package com.example.outilcuisson;
|
||||
|
||||
/**
|
||||
* TODO class comment
|
||||
*/
|
||||
public class AjouterFragment {}
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TimePicker;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
public class AjouterFragment extends Fragment {
|
||||
|
||||
EditText inputPlat;
|
||||
TimePicker inputDuree;
|
||||
EditText inputTemperature;
|
||||
|
||||
public AjouterFragment() {
|
||||
}
|
||||
|
||||
public static AjouterFragment newInstance() {
|
||||
return new AjouterFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.ajouter_fragment, container, false);
|
||||
}
|
||||
|
||||
public void actionBtnEffacer(View view) {
|
||||
}
|
||||
|
||||
public void actionBtnAjouter(View view) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,33 @@
|
||||
package com.example.outilcuisson;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.google.android.material.tabs.TabLayoutMediator;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
ViewPager2 gestionnairePagination = findViewById(R.id.activity_main_viewpager);
|
||||
TabLayout gestionnaireOnglet = findViewById(R.id.tab_layout);
|
||||
|
||||
|
||||
gestionnairePagination.setAdapter(new AdaptateurPage(this));
|
||||
|
||||
String[] titreOnglet = {
|
||||
getString(R.string.tab_afficher),
|
||||
getString(R.string.tab_ajouter)
|
||||
};
|
||||
|
||||
new TabLayoutMediator(gestionnaireOnglet, gestionnairePagination,
|
||||
(tab, position) -> tab.setText(titreOnglet[position])
|
||||
).attach();
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/tab_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/activity_main_viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</LinearLayout>
|
||||
@@ -1,6 +1,78 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:stretchColumns="0">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<TableRow> <!-- Titre -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:text="@string/ajouter_titre"
|
||||
android:layout_span="3"/>
|
||||
</TableRow>
|
||||
|
||||
<TableRow> <!-- Plat -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_plat"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/input_plat"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
</TableRow>
|
||||
|
||||
<TableRow> <!-- Durée de cuisson -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_duree"/>
|
||||
|
||||
<TimePicker
|
||||
android:id="@+id/input_duree"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:timePickerMode="spinner"/>
|
||||
</TableRow>
|
||||
|
||||
<TableRow> <!-- Température -->
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_temperature"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/input_temperature"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_column="2"
|
||||
android:inputType="number"/>
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow> <!-- Buttons -->
|
||||
|
||||
<Button
|
||||
android:layout_column="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/btn_effacer"
|
||||
android:onClick="actionBtnEffacer"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/btn_valider"
|
||||
android:onClick="actionBtnAjouter"/>
|
||||
|
||||
</TableRow>
|
||||
|
||||
|
||||
|
||||
</TableLayout>
|
||||
@@ -1,3 +1,19 @@
|
||||
<resources>
|
||||
<string name="app_name">OutilCuisson</string>
|
||||
|
||||
<!-- Tabs -->
|
||||
<string name="tab_afficher">Afficher</string>
|
||||
<string name="tab_ajouter">Ajouter</string>
|
||||
|
||||
<!-- Section Afficher -->
|
||||
|
||||
|
||||
<!-- Section Ajouter -->
|
||||
<string name="ajouter_titre">Description cuisson d\'un plat</string>
|
||||
<string name="label_plat">Plat</string>
|
||||
<string name="label_duree">Durée de la cuisson</string>
|
||||
<string name="label_temperature">Température</string>
|
||||
<string name="btn_effacer">Effacer</string>
|
||||
<string name="btn_valider">Valider</string>
|
||||
|
||||
</resources>
|
||||
Reference in New Issue
Block a user