Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Commit

Permalink
Add a settings activity
Browse files Browse the repository at this point in the history
  • Loading branch information
jdam6431 committed Dec 12, 2020
1 parent f5b58a7 commit c839bb3
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ dependencies {
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "androidx.room:room-runtime:2.2.5"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.preference:preference:1.1.1'
annotationProcessor "androidx.room:room-compiler:2.2.5"
implementation 'com.itextpdf:itextg:5.5.10'
implementation 'com.google.zxing:core:3.4.0'
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName=".MainActivity">
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.action_about:
getAboutDialog();
break;
case R.id.action_settings:
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
return true;
}

return super.onOptionsItemSelected(item);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.poupa.attestationdeplacement;

import android.content.pm.ShortcutManager;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreferenceCompat;

public class SettingsActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings, new SettingsFragment())
.commit();
}
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
}

public static class SettingsFragment extends PreferenceFragmentCompat {

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);

SwitchPreferenceCompat createShortcutPreference = getPreferenceManager().findPreference("create_shortcuts");
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
createShortcutPreference.setOnPreferenceChangeListener((preference, newValue) -> {
if((Boolean) newValue == false) {
ShortcutManager shortcutManager = requireActivity().getSystemService(ShortcutManager.class);
shortcutManager.removeAllDynamicShortcuts();
}
return true;
});
} else {
createShortcutPreference.setSummaryOn(R.string.shortcuts_summary_disabled);
createShortcutPreference.setSummaryOff(R.string.shortcuts_summary_disabled);
createShortcutPreference.setEnabled(false);
}

return view;
}

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.root_preferences, rootKey);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.widget.Toast;

Expand All @@ -12,6 +13,8 @@

import java.lang.ref.WeakReference;

import androidx.preference.PreferenceManager;

public class GeneratePdfTask extends AsyncTask<Void, Void, Void> {
private final WeakReference<CreateAttestationActivity> weakActivity;
ProgressDialog nDialog;
Expand Down Expand Up @@ -59,8 +62,10 @@ protected Void doInBackground(Void... voids) {

attestationGenerator.generate();

weakActivity.get().createShortcut();

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(weakActivity.get());
if(preferences.getBoolean("create_shortcuts", false)) {
weakActivity.get().createShortcut();
}
return null;
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/layout/settings_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:id="@+id/settings"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
9 changes: 7 additions & 2 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.poupa.attestationdeplacement.MainActivity">
<item
android:id="@+id/action_warning"
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/settings"
app:showAsAction="never" />
<item
android:id="@+id/action_warning"
android:orderInCategory="200"
android:title="@string/warning"
app:showAsAction="never" />
<item
android:id="@+id/action_about"
android:orderInCategory="200"
android:orderInCategory="300"
android:title="@string/about"
app:showAsAction="never" />
</menu>
12 changes: 12 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<resources>
<!-- Reply Preference -->
<string-array name="reply_entries">
<item>Reply</item>
<item>Reply to all</item>
</string-array>

<string-array name="reply_values">
<item>reply</item>
<item>reply_all</item>
</string-array>
</resources>
8 changes: 8 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,12 @@
<string name="about_tv_title_txt">xxxxxxxxxxxxxx</string>
<string name="about_tv_version_txt">Version 0.0.0 (build 0)</string>
<string name="profile_hint">Profil</string>

<string name="title_activity_settings">Paramètres</string>
<string name="settings">Paramètres</string>
<string name="shortcuts">Raccourcis</string>
<string name="shortcuts_title">Créer des raccourcis</string>
<string name="shortcuts_summary_on">Des raccourcis sont mis à disposition après la génération d\'une attestation. Ils sont accessibles par un appui long sur l\'icône de l\'application.</string>
<string name="shortcuts_summary_off">Aucun raccourci n\'est proposé par l\'application.</string>
<string name="shortcuts_summary_disabled">Cette option n\'est pas compatible avec votre appareil.</string>
</resources>
10 changes: 10 additions & 0 deletions app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">

<SwitchPreferenceCompat
app:key="create_shortcuts"
app:summaryOff="@string/shortcuts_summary_off"
app:summaryOn="@string/shortcuts_summary_on"
app:title="@string/shortcuts_title"
app:defaultValue="false" />

</PreferenceScreen>

0 comments on commit c839bb3

Please sign in to comment.