Skip to content

Commit

Permalink
SettingsFragment überarbeitet und menu entfernt bis auf settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
amarradi committed Jun 20, 2022
1 parent 4e61084 commit c5f79da
Show file tree
Hide file tree
Showing 21 changed files with 209 additions and 141 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.git.amarradi.palatschinkencounter;

import static org.junit.Assert.assertEquals;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.PreferenceManager;

import java.util.Objects;

public class MainActivity extends AppCompatActivity implements WipeDataDialog.WipeDialogListener {
public class MainActivity<nightMode> extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {

public static final String SHARED_PREFS = "sharedPrefs";
public static final String COUNTER = "text";
Expand Down Expand Up @@ -93,30 +93,16 @@ public boolean onOptionsItemSelected(MenuItem item) {
Intent intentSetting = new Intent(this, SettingActivity.class);
startActivity(intentSetting);
return true;
case R.id.item_clean:
openDialog();
return true;
case R.id.item_dn_switch:
switchDayNightMode();
return true;
case R.id.item_recipe:
Intent intentRecipe = new Intent(this, RecipeActivity.class);
startActivity(intentRecipe);
return true;
case R.id.item_about:
Intent intentAbout = new Intent(this, AboutActivity.class);
startActivity(intentAbout);
return true;
default:
return super.onOptionsItemSelected(item);
}

}

/*
public void openDialog() {
WipeDataDialog dialog = new WipeDataDialog();
dialog.show(getSupportFragmentManager(), "open dialog");
}
}*/

public void save_data() {
SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
Expand All @@ -136,23 +122,8 @@ public void updateViews() {
textView.setText(format("%d", counter));
}

public void switchDayNightMode() {
SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
safedNightMode = sharedPreferences.getBoolean(NIGHT_MODE, false);

nightMode = safedNightMode;
if (safedNightMode) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
nightMode = false;
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
nightMode = true;
}
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(NIGHT_MODE, nightMode);
editor.apply();
}

/*
public void reset_counter() {
counter = 0;
Expand All @@ -165,12 +136,43 @@ public void reset_counter() {
public void onYesClicked() {
reset_counter();
}
*/
private void setupSharedPreferences() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
}

public void setupSharedPreferences() {
SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
safedNightMode = sharedPreferences.getBoolean(NIGHT_MODE, false);


@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals("darkmode")) {
Log.d("Value mode onShared:", key);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
} else {
Log.d("Value mode onShared:", key);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
}
}

// Method to pass value from SharedPreferences
private void loadColorFromPreference(SharedPreferences sharedPreferences) {
Log.d("Parzival",sharedPreferences.getString(getString(R.string.theme_key),
getString(R.string.lightmode_preference_option_value)));
changeDarkLightMode(sharedPreferences.getString(getString(R.string.theme_key),
getString(R.string.lightmode_preference_option_value)));
}
// Method to set Color of Text.
private void changeDarkLightMode(String mode) {
Log.d("Value mode:", mode);
if (mode.equals("lightmode")) {
Log.d("Value mode:", mode);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);

} else if(mode.equals("darkmode")) {
Log.d("Value mode:", mode);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);

}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.git.amarradi.palatschinkencounter;

import android.os.Bundle;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class SettingActivity extends AppCompatActivity {

@Override
Expand All @@ -22,6 +22,7 @@ public void onBackPressed() {
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

getSupportFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
package com.git.amarradi.palatschinkencounter;

import static android.content.Context.MODE_PRIVATE;
import static java.lang.String.format;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;

import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.preference.PreferenceScreen;


public class SettingsFragment extends PreferenceFragmentCompat {
public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener, Preference.OnPreferenceClickListener {

@Override
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {

addPreferencesFromResource(R.xml.preferences);

SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
PreferenceScreen prefScreen = getPreferenceScreen();

Preference feedback_preference = (Preference) findPreference("feedback_preference");

feedback_preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
Expand All @@ -44,13 +36,50 @@ public boolean onPreferenceClick(@NonNull Preference preference) {
return true;
}
});
Preference recipe_preference = (Preference) findPreference("recipe");
recipe_preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(@NonNull Preference preference) {
Intent intentRecipe = new Intent(getActivity(), RecipeActivity.class);
startActivity(intentRecipe);
return false;
}
});

Preference checkbox = (Preference) findPreference("check_theme_preference");
checkbox.setOnPreferenceChangeListener((preference, newValue) -> {
Toast.makeText(getContext(), "Test", Toast.LENGTH_SHORT).show();
return true;
Preference about_preference = (Preference) findPreference("about");
about_preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(@NonNull Preference preference) {
Intent intentAbout = new Intent(getActivity(),AboutActivity.class);
startActivity(intentAbout);
return false;
}
});
}



@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

}

@Override
public boolean onPreferenceClick(@NonNull Preference preference) {
return false;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
}

@Override
public void onDestroy() {
super.onDestroy();
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
}
}
14 changes: 9 additions & 5 deletions app/src/main/res/drawable-night/ic_baseline_mail_24.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/black"
android:pathData="M20,4L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM20,8l-8,5 -8,-5L4,6l8,5 8,-5v2z"/>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#000000"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/black"
android:pathData="M20,4L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM20,8l-8,5 -8,-5L4,6l8,5 8,-5v2z" />
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/drawable-night/ic_dn_switch.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/drawable/ic_baseline_contact_support_24.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:autoMirrored="true"
android:tint="?attr/colorControlNormal"
android:autoMirrored="true">
<path
android:fillColor="@android:color/white"
android:pathData="M11.5,2C6.81,2 3,5.81 3,10.5S6.81,19 11.5,19h0.5v3c4.86,-2.34 8,-7 8,-11.5C20,5.81 16.19,2 11.5,2zM12.5,16.5h-2v-2h2v2zM12.5,13h-2c0,-3.25 3,-3 3,-5 0,-1.1 -0.9,-2 -2,-2s-2,0.9 -2,2h-2c0,-2.21 1.79,-4 4,-4s4,1.79 4,4c0,2.5 -3,2.75 -3,5z"/>
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M11.5,2C6.81,2 3,5.81 3,10.5S6.81,19 11.5,19h0.5v3c4.86,-2.34 8,-7 8,-11.5C20,5.81 16.19,2 11.5,2zM12.5,16.5h-2v-2h2v2zM12.5,13h-2c0,-3.25 3,-3 3,-5 0,-1.1 -0.9,-2 -2,-2s-2,0.9 -2,2h-2c0,-2.21 1.79,-4 4,-4s4,1.79 4,4c0,2.5 -3,2.75 -3,5z" />
</vector>
10 changes: 5 additions & 5 deletions app/src/main/res/drawable/ic_baseline_delete_forever_24.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2L18,7L6,7v12zM8.46,11.88l1.41,-1.41L12,12.59l2.12,-2.12 1.41,1.41L13.41,14l2.12,2.12 -1.41,1.41L12,15.41l-2.12,2.12 -1.41,-1.41L10.59,14l-2.13,-2.12zM15.5,4l-1,-1h-5l-1,1L5,4v2h14L19,4z"/>
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2L18,7L6,7v12zM8.46,11.88l1.41,-1.41L12,12.59l2.12,-2.12 1.41,1.41L13.41,14l2.12,2.12 -1.41,1.41L12,15.41l-2.12,2.12 -1.41,-1.41L10.59,14l-2.13,-2.12zM15.5,4l-1,-1h-5l-1,1L5,4v2h14L19,4z" />
</vector>
12 changes: 6 additions & 6 deletions app/src/main/res/drawable/ic_baseline_list_24.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:autoMirrored="true"
android:tint="?attr/colorControlNormal"
android:autoMirrored="true">
<path
android:fillColor="@android:color/white"
android:pathData="M3,13h2v-2L3,11v2zM3,17h2v-2L3,15v2zM3,9h2L5,7L3,7v2zM7,13h14v-2L7,11v2zM7,17h14v-2L7,15v2zM7,7v2h14L21,7L7,7z"/>
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M3,13h2v-2L3,11v2zM3,17h2v-2L3,15v2zM3,9h2L5,7L3,7v2zM7,13h14v-2L7,11v2zM7,17h14v-2L7,15v2zM7,7v2h14L21,7L7,7z" />
</vector>
13 changes: 9 additions & 4 deletions app/src/main/res/drawable/ic_baseline_mail_24.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M20,4L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM20,8l-8,5 -8,-5L4,6l8,5 8,-5v2z"/>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#000000"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M20,4L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM20,8l-8,5 -8,-5L4,6l8,5 8,-5v2z" />
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_dn_switch.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
Expand Down
Loading

0 comments on commit c5f79da

Please sign in to comment.