diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 63578875ac48030ccba7ae57da3df28fe4e148db..5b948718e24417d8dc35a3af094f92fe24e715da 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -31,8 +31,8 @@ <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> - <activity android:name=".HomeActivity"/> - <activity android:name=".TutorialActivity"/> + <activity android:name=".HomeActivity" /> + <activity android:name=".TutorialActivity" /> <activity android:name=".PublicActivity" android:exported="true" /> @@ -40,6 +40,16 @@ <meta-data android:name="preloaded_fonts" android:resource="@array/preloaded_fonts" /> + + <provider + android:authorities="${applicationId}.fileprovider" + android:name="androidx.core.content.FileProvider" + android:exported="false" + android:grantUriPermissions="true"> + <meta-data + android:name="android.support.FILE_PROVIDER_PATHS" + android:resource="@xml/file_paths" /> + </provider> </application> </manifest> \ No newline at end of file diff --git a/app/src/main/assets/tuto.pdf b/app/src/main/assets/tuto.pdf new file mode 100644 index 0000000000000000000000000000000000000000..a2fb7992c7e0ae35161a7ca4fc0ac8c1a0e9e0d1 Binary files /dev/null and b/app/src/main/assets/tuto.pdf differ diff --git a/app/src/main/java/com/example/myapplication/HomeActivity.java b/app/src/main/java/com/example/myapplication/HomeActivity.java index 1e2be4c6859536abbc88967dfec6f39c0632e92c..8bef76f8915a35f73ba547e15bd381f253907de9 100644 --- a/app/src/main/java/com/example/myapplication/HomeActivity.java +++ b/app/src/main/java/com/example/myapplication/HomeActivity.java @@ -1,11 +1,13 @@ package com.example.myapplication; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import android.widget.Button; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; public class HomeActivity extends AppCompatActivity { @Override @@ -35,6 +37,12 @@ public class HomeActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + // Load the saved theme mode from SharedPreferences + SharedPreferences preferences = getSharedPreferences("theme_prefs", MODE_PRIVATE); + int themeMode = preferences.getInt("theme_mode", AppCompatDelegate.MODE_NIGHT_NO); + AppCompatDelegate.setDefaultNightMode(themeMode); + setContentView(R.layout.activity_home); /* diff --git a/app/src/main/java/com/example/myapplication/MainActivity.java b/app/src/main/java/com/example/myapplication/MainActivity.java index 6f3d67aeabba8f7a1db81acff5563a71c7b4aacf..12f9d387168dae293843e2a41b081a1f50e9c40d 100644 --- a/app/src/main/java/com/example/myapplication/MainActivity.java +++ b/app/src/main/java/com/example/myapplication/MainActivity.java @@ -1,6 +1,7 @@ package com.example.myapplication; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Handler; @@ -10,6 +11,7 @@ import android.widget.ImageView; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import org.tensorflow.lite.support.tensorbuffer.TensorBuffer; @@ -20,7 +22,11 @@ public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - //setContentView(R.layout.activity_main1); + + // Load the saved theme mode from SharedPreferences + SharedPreferences preferences = getSharedPreferences("theme_prefs", MODE_PRIVATE); + int themeMode = preferences.getInt("theme_mode", AppCompatDelegate.MODE_NIGHT_NO); + AppCompatDelegate.setDefaultNightMode(themeMode); setContentView(R.layout.activity_main); diff --git a/app/src/main/java/com/example/myapplication/PublicActivity.java b/app/src/main/java/com/example/myapplication/PublicActivity.java index f50330c8f816d14fb07c7a0b9e6c64e7009df43f..fe0336871e3cde8d7bd9a3befa5e7267f5acd643 100644 --- a/app/src/main/java/com/example/myapplication/PublicActivity.java +++ b/app/src/main/java/com/example/myapplication/PublicActivity.java @@ -30,6 +30,8 @@ public class PublicActivity extends AppCompatActivity { bottomNavigationView.setSelectedItemId(R.id.navigation_statistiques); break; case "SettingsPage": + Intent intent = new Intent(PublicActivity.this, PublicActivity.class); + intent.putExtra("TARGET_FRAGMENT", "SettingsPage"); loadFragment(new SettingsPage()); bottomNavigationView.setSelectedItemId(R.id.navigation_parametres); break; diff --git a/app/src/main/java/com/example/myapplication/SettingsPage.java b/app/src/main/java/com/example/myapplication/SettingsPage.java index d7b6f43eb7211e3ae4db5b055a215ca030e78560..37ef4a1d6a0524c4dc3bc63e8f5a035ea55fab7a 100644 --- a/app/src/main/java/com/example/myapplication/SettingsPage.java +++ b/app/src/main/java/com/example/myapplication/SettingsPage.java @@ -1,12 +1,28 @@ package com.example.myapplication; +import static android.content.Context.MODE_PRIVATE; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.net.Uri; import android.os.Bundle; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatDelegate; +import androidx.core.content.FileProvider; import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.prefs.Preferences; /** * A simple {@link Fragment} subclass. @@ -14,6 +30,8 @@ import android.view.ViewGroup; * create an instance of this fragment. */ public class SettingsPage extends Fragment { + private Button nightModeButton; + private Button downloadButton; // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER @@ -61,4 +79,88 @@ public class SettingsPage extends Fragment { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_settings_page, container, false); } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + // Load the saved theme mode + SharedPreferences preferences = requireContext().getSharedPreferences("theme_prefs", requireContext().MODE_PRIVATE); + int currentMode = preferences.getInt("theme_mode", AppCompatDelegate.MODE_NIGHT_NO); + + nightModeButton = view.findViewById(R.id.night_mode_button); + nightModeButton.setOnClickListener(v -> { + // Toggle between light and dark modes + int newMode = (currentMode == AppCompatDelegate.MODE_NIGHT_NO) + ? AppCompatDelegate.MODE_NIGHT_YES + : AppCompatDelegate.MODE_NIGHT_NO; + + // Apply the theme globally + AppCompatDelegate.setDefaultNightMode(newMode); + + // Save the preference + saveThemeMode(newMode); + }); + + downloadButton = view.findViewById(R.id.download_tuto_button); + downloadButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + // Copy the PDF file from assets to internal storage + File pdfFile = copyPdfToInternalStorage(); + + // Open the PDF if successfully copied + if (pdfFile != null) { + openPdfFile(pdfFile); + } else { + System.out.println("Failed to copy PDF file."); + } + } + }); + } + + private void saveThemeMode(int mode) { + SharedPreferences.Editor editor = requireContext() + .getSharedPreferences("theme_prefs", requireContext().MODE_PRIVATE).edit(); + editor.putInt("theme_mode", mode); + editor.apply(); + } + + private File copyPdfToInternalStorage() { + File outputFile = new File(requireContext().getFilesDir(), "tuto.pdf"); + + // Check if the file already exists to avoid unnecessary copying + if (!outputFile.exists()) { + try (InputStream inputStream = requireContext().getAssets().open("tuto.pdf"); + FileOutputStream outputStream = new FileOutputStream(outputFile)) { + + byte[] buffer = new byte[1024]; + int length; + while ((length = inputStream.read(buffer)) > 0) { + outputStream.write(buffer, 0, length); + } + + System.out.println("PDF successfully copied to: " + outputFile.getAbsolutePath()); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + return outputFile; + } + + private void openPdfFile(File file) { + // Generate a URI using FileProvider + Uri fileUri = FileProvider.getUriForFile(requireContext(), requireContext().getPackageName() + ".fileprovider", file); + + // Create an Intent to view the PDF + Intent viewPdfIntent = new Intent(Intent.ACTION_VIEW); + viewPdfIntent.setDataAndType(fileUri, "application/pdf"); + viewPdfIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + + // Start the activity to open the PDF + Intent chooser = Intent.createChooser(viewPdfIntent, "Open PDF with..."); + startActivity(chooser); + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/TutorialActivity.java b/app/src/main/java/com/example/myapplication/TutorialActivity.java index 2e3466111fbed6f9c2c369eb11b772a476e779e9..9749d0026ec28f764835c03ab945d1071d485d4f 100644 --- a/app/src/main/java/com/example/myapplication/TutorialActivity.java +++ b/app/src/main/java/com/example/myapplication/TutorialActivity.java @@ -1,7 +1,6 @@ package com.example.myapplication; import android.content.Intent; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.View; import android.widget.Button; @@ -10,12 +9,8 @@ import android.widget.LinearLayout; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; -import androidx.core.content.res.ResourcesCompat; import androidx.viewpager2.widget.ViewPager2; -import com.google.android.material.tabs.TabLayout; -import com.google.android.material.tabs.TabLayoutMediator; - import java.util.Arrays; import java.util.List; @@ -25,8 +20,6 @@ public class TutorialActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tutorial); - boolean fromPhotoPage = getIntent().getBooleanExtra("FROM_PHOTO_PAGE", false); - ViewPager2 viewPager2=findViewById(R.id.tutorial_viewpager); List<Integer> layouts = Arrays.asList( @@ -42,17 +35,10 @@ public class TutorialActivity extends AppCompatActivity { View.OnClickListener lTutoEndButton = new View.OnClickListener() { @Override public void onClick(View view) { - if (fromPhotoPage) { - Intent intent = new Intent(TutorialActivity.this, PublicActivity.class); - intent.putExtra("TARGET_FRAGMENT", "PhotoPage"); - startActivity(intent); - finish(); - } else { Intent intent = new Intent(TutorialActivity.this, HomeActivity.class); intent.putExtra("PREFERENCES", false); startActivity(intent); finish(); - } } }; tutoEndButton.setOnClickListener(lTutoEndButton); diff --git a/app/src/main/res/drawable/polygon_10.png b/app/src/main/res/drawable/polygon_10.png index da5e90ae98c572296982a30dcf680075b2d62cdc..3057c3a93b54fd8ae4ed9d2a6df59ea58f6811c8 100644 Binary files a/app/src/main/res/drawable/polygon_10.png and b/app/src/main/res/drawable/polygon_10.png differ diff --git a/app/src/main/res/layout/fragment_settings_page.xml b/app/src/main/res/layout/fragment_settings_page.xml index 23cb9916ae010094cd3e1db936ae809f5e8c0bdb..e794c9853f00746a5534d99eb1c864760a07e382 100644 --- a/app/src/main/res/layout/fragment_settings_page.xml +++ b/app/src/main/res/layout/fragment_settings_page.xml @@ -40,29 +40,34 @@ android:layout_marginBottom="8dp" android:text="@string/mode" /> - <FrameLayout + <LinearLayout style="@style/BottomAppearance" android:layout_marginLeft="40dp" android:layout_marginRight="40dp" - android:layout_marginBottom="23dp"> + android:layout_marginBottom="23dp" + android:orientation="vertical"> <Button - style="@style/ButtonAppearance" + android:id="@+id/night_mode_button" + style="@style/ModeSombreButtonAppearance" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginLeft="15dp" + android:layout_marginTop="5dp" android:layout_marginRight="15dp" - android:layout_marginBottom="15dp" - android:text="@string/mode_sombre" + android:layout_marginBottom="5dp" android:textSize="15sp" app:icon="@drawable/moon" app:iconGravity="textStart" /> <TextView android:layout_width="match_parent" - android:layout_height="wrap_content" /> - </FrameLayout> + android:layout_height="wrap_content" + android:layout_marginLeft="15dp" + android:layout_marginRight="15dp" + android:text="@string/mode_sombre_texte" /> + </LinearLayout> <TextView @@ -73,20 +78,23 @@ android:text="@string/tutorial" android:textSize="15sp" /> - <FrameLayout + <LinearLayout style="@style/BottomAppearance" android:layout_marginLeft="40dp" android:layout_marginRight="40dp" - android:layout_marginBottom="23dp"> + android:layout_marginBottom="23dp" + android:orientation="vertical"> <Button + android:id="@+id/download_tuto_button" style="@style/ButtonAppearance" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginLeft="15dp" + android:layout_marginTop="5dp" android:layout_marginRight="15dp" - android:layout_marginBottom="15dp" + android:layout_marginBottom="5dp" android:text="@string/download" android:textSize="15sp" app:icon="@drawable/folder" @@ -94,8 +102,11 @@ <TextView android:layout_width="match_parent" - android:layout_height="wrap_content" /> - </FrameLayout> + android:layout_height="wrap_content" + android:layout_marginLeft="15dp" + android:layout_marginRight="15dp" + android:text="@string/download_text" /> + </LinearLayout> <TextView style="@style/TopTopAppearance" diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 8ffded9c6e1fa0b30fe91d29c2ea5515f0977d53..b9a3cf863dad1101493a53c83efb68f798d2d7bd 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -1,5 +1,4 @@ -<resources xmlns:tools="http://schemas.android.com/tools" - xmlns:app="http://schemas.android.com/apk/res-auto"> +<resources xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> <!-- Base application theme. --> <style name="Base.Theme.MyApplication" parent="Theme.Material3.DayNight.NoActionBar"> <!-- Customize your dark theme here. --> @@ -14,6 +13,16 @@ <item name="android:textColor">#D9D9D9</item> </style> + + <style name="ModeSombreButtonAppearance" parent="ShapeAppearance.MaterialComponents.SmallComponent"> + <item name="cornerFamily">rounded</item> + <item name="cornerRadius">8dp</item> + <item name="backgroundTint">#565758</item> + <item name="iconTint">#D9D9D9</item> + <item name="android:textColor">#D9D9D9</item> + <item name="android:text">"Mode clair"</item> + </style> + <style name="TopAppearance" parent=""> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">wrap_content</item> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d3d9676275c9da24d9e3ab700b504f0158e46dc0..80d188bf8431d280cfbd3a7e864b5e020505ed5d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -79,6 +79,8 @@ <string name="personal_data">Traitement des données personnelles</string> <string name="download">Télécharger</string> <string name="mode_sombre">Mode sombre</string> + <string name="mode_sombre_texte">Le mode sombre économise votre batterie et lutte contre la fatigue visuelle</string> + <string name="download_text">Télécharge un guide d’utilisation approfondi de l’application au format pdf</string> <string-array name="zone_array"> <item>Zone 1</item> <item>Zone 2</item> diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index a7abaf4179bf36631197adfa25bb923fa72804f8..9fc7d521efbb9d5e529befbb098dcb350bf1a80e 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -14,6 +14,14 @@ <item name="iconTint">#D9D9D9</item> </style> + <style name="ModeSombreButtonAppearance" parent="ShapeAppearance.MaterialComponents.SmallComponent"> + <item name="cornerFamily">rounded</item> + <item name="cornerRadius">8dp</item> + <item name="backgroundTint">#517293</item> + <item name="iconTint">#D9D9D9</item> + <item name="android:text">"Mode sombre"</item> + </style> + <style name="RoundedImageView" parent=""> <item name="cornerFamily">rounded</item> <item name="cornerSize">8dp</item> diff --git a/app/src/main/res/xml/file_paths.xml b/app/src/main/res/xml/file_paths.xml new file mode 100644 index 0000000000000000000000000000000000000000..4448af3c040746e4a98720f8fe4d38e20331c1c1 --- /dev/null +++ b/app/src/main/res/xml/file_paths.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<paths> + <files-path name="internal_files" path="." /> +</paths> \ No newline at end of file