mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-14 12:44:15 +02:00
change material calendar button text color
This commit is contained in:
@@ -1,22 +1,21 @@
|
|||||||
/* Copyright (C) 2014 olie.xdev <olie.xdev@googlemail.com>
|
/* Copyright (C) 2014 olie.xdev <olie.xdev@googlemail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
package com.health.openscale.gui.preferences;
|
package com.health.openscale.gui.preferences;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.DatePickerDialog;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
@@ -30,17 +29,21 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.DatePicker;
|
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TableRow;
|
import android.widget.TableRow;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.graphics.drawable.DrawableCompat;
|
import androidx.core.graphics.drawable.DrawableCompat;
|
||||||
|
import androidx.core.view.MenuProvider;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
import androidx.navigation.Navigation;
|
import androidx.navigation.Navigation;
|
||||||
|
|
||||||
|
import com.google.android.material.datepicker.MaterialDatePicker;
|
||||||
|
import com.google.android.material.datepicker.MaterialPickerOnPositiveButtonClickListener;
|
||||||
import com.health.openscale.R;
|
import com.health.openscale.R;
|
||||||
import com.health.openscale.core.OpenScale;
|
import com.health.openscale.core.OpenScale;
|
||||||
import com.health.openscale.core.datatypes.ScaleUser;
|
import com.health.openscale.core.datatypes.ScaleUser;
|
||||||
@@ -85,7 +88,65 @@ public class UserSettingsFragment extends Fragment {
|
|||||||
View root = inflater.inflate(R.layout.fragment_usersettings, container, false);
|
View root = inflater.inflate(R.layout.fragment_usersettings, container, false);
|
||||||
context = getContext();
|
context = getContext();
|
||||||
|
|
||||||
setHasOptionsMenu(true);
|
requireActivity().addMenuProvider(new MenuProvider() {
|
||||||
|
@Override
|
||||||
|
public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater) {
|
||||||
|
menu.clear();
|
||||||
|
menuInflater.inflate(R.menu.userentry_menu, menu);
|
||||||
|
|
||||||
|
// Apply a tint to all icons in the toolbar
|
||||||
|
for (int i = 0; i < menu.size(); ++i) {
|
||||||
|
MenuItem item = menu.getItem(i);
|
||||||
|
final Drawable drawable = item.getIcon();
|
||||||
|
if (drawable == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Drawable wrapped = DrawableCompat.wrap(drawable.mutate());
|
||||||
|
|
||||||
|
if (item.getItemId() == R.id.saveButton) {
|
||||||
|
DrawableCompat.setTint(wrapped, Color.parseColor("#FFFFFF"));
|
||||||
|
} else if (item.getItemId() == R.id.deleteButton) {
|
||||||
|
DrawableCompat.setTint(wrapped, Color.parseColor("#FF4444"));
|
||||||
|
}
|
||||||
|
|
||||||
|
item.setIcon(wrapped);
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuItem deleteButton = menu.findItem(R.id.deleteButton);
|
||||||
|
|
||||||
|
switch (mode) {
|
||||||
|
case ADD:
|
||||||
|
deleteButton.setVisible(false);
|
||||||
|
break;
|
||||||
|
case EDIT:
|
||||||
|
deleteButton.setVisible(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemSelected(@NonNull MenuItem menuItem) {
|
||||||
|
switch (menuItem.getItemId()) {
|
||||||
|
case R.id.saveButton:
|
||||||
|
if (saveUserData()) {
|
||||||
|
if (getActivity().findViewById(R.id.nav_host_fragment) != null){
|
||||||
|
Navigation.findNavController(getActivity(), R.id.nav_host_fragment).getPreviousBackStackEntry().getSavedStateHandle().set("update", true);
|
||||||
|
Navigation.findNavController(getActivity(), R.id.nav_host_fragment).navigateUp();
|
||||||
|
} else {
|
||||||
|
getActivity().finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case R.id.deleteButton:
|
||||||
|
deleteUser();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}, getViewLifecycleOwner(), Lifecycle.State.RESUMED);
|
||||||
|
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
mode = UserSettingsFragmentArgs.fromBundle(getArguments()).getMode();
|
mode = UserSettingsFragmentArgs.fromBundle(getArguments()).getMode();
|
||||||
@@ -129,15 +190,16 @@ public class UserSettingsFragment extends Fragment {
|
|||||||
txtGoalDate.setText(dateFormat.format(goal_date));
|
txtGoalDate.setText(dateFormat.format(goal_date));
|
||||||
|
|
||||||
txtBirthday.setOnClickListener(new View.OnClickListener() {
|
txtBirthday.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Calendar cal = Calendar.getInstance();
|
MaterialDatePicker<Long> datePicker = MaterialDatePicker.Builder
|
||||||
cal.setTime(birthday);
|
.datePicker()
|
||||||
DatePickerDialog datePicker = new DatePickerDialog(
|
.setSelection(birthday.getTime())
|
||||||
context, birthdayPickerListener, cal.get(Calendar.YEAR),
|
.build();
|
||||||
cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
|
|
||||||
datePicker.show();
|
datePicker.addOnPositiveButtonClickListener(birthdayPickerListener);
|
||||||
}
|
datePicker.show(requireActivity().getSupportFragmentManager(), "Birthday_DatePicker");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
chkGoalEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
chkGoalEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
@@ -156,12 +218,13 @@ public class UserSettingsFragment extends Fragment {
|
|||||||
txtGoalDate.setOnClickListener(new View.OnClickListener() {
|
txtGoalDate.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Calendar cal = Calendar.getInstance();
|
MaterialDatePicker<Long> datePicker = MaterialDatePicker.Builder
|
||||||
cal.setTime(goal_date);
|
.datePicker()
|
||||||
DatePickerDialog datePicker = new DatePickerDialog(
|
.setSelection(goal_date.getTime())
|
||||||
context, goalDatePickerListener, cal.get(Calendar.YEAR),
|
.build();
|
||||||
cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
|
|
||||||
datePicker.show();
|
datePicker.addOnPositiveButtonClickListener(goalDatePickerListener);
|
||||||
|
datePicker.show(getActivity().getSupportFragmentManager(), "Goal_DatePicker");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -205,70 +268,13 @@ public class UserSettingsFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (mode == USER_SETTING_MODE.EDIT) {
|
||||||
|
editMode();
|
||||||
|
}
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
||||||
menu.clear();
|
|
||||||
inflater.inflate(R.menu.userentry_menu, menu);
|
|
||||||
|
|
||||||
// Apply a tint to all icons in the toolbar
|
|
||||||
for (int i = 0; i < menu.size(); ++i) {
|
|
||||||
MenuItem item = menu.getItem(i);
|
|
||||||
final Drawable drawable = item.getIcon();
|
|
||||||
if (drawable == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Drawable wrapped = DrawableCompat.wrap(drawable.mutate());
|
|
||||||
|
|
||||||
if (item.getItemId() == R.id.saveButton) {
|
|
||||||
DrawableCompat.setTint(wrapped, Color.parseColor("#FFFFFF"));
|
|
||||||
} else if (item.getItemId() == R.id.deleteButton) {
|
|
||||||
DrawableCompat.setTint(wrapped, Color.parseColor("#FF4444"));
|
|
||||||
}
|
|
||||||
|
|
||||||
item.setIcon(wrapped);
|
|
||||||
}
|
|
||||||
|
|
||||||
MenuItem deleteButton = menu.findItem(R.id.deleteButton);
|
|
||||||
|
|
||||||
switch (mode) {
|
|
||||||
case ADD:
|
|
||||||
deleteButton.setVisible(false);
|
|
||||||
break;
|
|
||||||
case EDIT:
|
|
||||||
editMode();
|
|
||||||
deleteButton.setVisible(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case R.id.saveButton:
|
|
||||||
if (saveUserData()) {
|
|
||||||
if (getActivity().findViewById(R.id.nav_host_fragment) != null){
|
|
||||||
Navigation.findNavController(getActivity(), R.id.nav_host_fragment).getPreviousBackStackEntry().getSavedStateHandle().set("update", true);
|
|
||||||
Navigation.findNavController(getActivity(), R.id.nav_host_fragment).navigateUp();
|
|
||||||
} else {
|
|
||||||
getActivity().finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case R.id.deleteButton:
|
|
||||||
deleteUser();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void editMode()
|
private void editMode()
|
||||||
{
|
{
|
||||||
int id = UserSettingsFragmentArgs.fromBundle(getArguments()).getUserId();
|
int id = UserSettingsFragmentArgs.fromBundle(getArguments()).getUserId();
|
||||||
@@ -367,24 +373,18 @@ public class UserSettingsFragment extends Fragment {
|
|||||||
return validate;
|
return validate;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final DatePickerDialog.OnDateSetListener birthdayPickerListener = new DatePickerDialog.OnDateSetListener() {
|
private final MaterialPickerOnPositiveButtonClickListener<Long> birthdayPickerListener = new MaterialPickerOnPositiveButtonClickListener<Long>() {
|
||||||
@Override
|
@Override
|
||||||
public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDay) {
|
public void onPositiveButtonClick(Long selection) {
|
||||||
Calendar cal = Calendar.getInstance();
|
birthday = new Date(selection);
|
||||||
cal.set(selectedYear, selectedMonth, selectedDay, 0, 0, 0);
|
|
||||||
cal.set(Calendar.MILLISECOND, 0);
|
|
||||||
birthday = cal.getTime();
|
|
||||||
txtBirthday.setText(dateFormat.format(birthday));
|
txtBirthday.setText(dateFormat.format(birthday));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final DatePickerDialog.OnDateSetListener goalDatePickerListener = new DatePickerDialog.OnDateSetListener() {
|
private final MaterialPickerOnPositiveButtonClickListener<Long> goalDatePickerListener = new MaterialPickerOnPositiveButtonClickListener<Long>() {
|
||||||
@Override
|
@Override
|
||||||
public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDay) {
|
public void onPositiveButtonClick(Long selection) {
|
||||||
Calendar cal = Calendar.getInstance();
|
goal_date = new Date(selection);
|
||||||
cal.set(selectedYear, selectedMonth, selectedDay, 0, 0, 0);
|
|
||||||
cal.set(Calendar.MILLISECOND, 0);
|
|
||||||
goal_date = cal.getTime();
|
|
||||||
txtGoalDate.setText(dateFormat.format(goal_date));
|
txtGoalDate.setText(dateFormat.format(goal_date));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
<item name="colorOnPrimary">@color/primaryLightColor</item>
|
<item name="colorOnPrimary">@color/primaryLightColor</item>
|
||||||
<item name="colorPrimaryDark">@color/primaryDarkColor</item>
|
<item name="colorPrimaryDark">@color/primaryDarkColor</item>
|
||||||
<item name="colorAccent">@color/primaryLightColor</item>
|
<item name="colorAccent">@color/primaryLightColor</item>
|
||||||
<item name="android:datePickerStyle">@style/DatePickerStyle</item>
|
<item name="materialCalendarTheme">@style/MaterialCalendarTheme</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="AppTheme_Dark" parent="Theme.MaterialComponents.NoActionBar">
|
<style name="AppTheme_Dark" parent="Theme.MaterialComponents.NoActionBar">
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
<item name="colorOnPrimary">@color/primaryLightColor</item>
|
<item name="colorOnPrimary">@color/primaryLightColor</item>
|
||||||
<item name="colorPrimaryDark">@color/primaryDarkColor</item>
|
<item name="colorPrimaryDark">@color/primaryDarkColor</item>
|
||||||
<item name="colorAccent">@color/primaryLightColor</item>
|
<item name="colorAccent">@color/primaryLightColor</item>
|
||||||
<item name="android:datePickerStyle">@style/DatePickerStyle</item>
|
<item name="materialCalendarTheme">@style/MaterialCalendarTheme</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="AppTheme.NoActionBar">
|
<style name="AppTheme.NoActionBar">
|
||||||
@@ -21,8 +21,17 @@
|
|||||||
<item name="windowNoTitle">true</item>
|
<item name="windowNoTitle">true</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="DatePickerStyle" parent="@android:style/Widget.Material.Light.DatePicker">
|
<style name="MaterialCalendarTheme" parent="ThemeOverlay.MaterialComponents.MaterialCalendar">
|
||||||
<item name="android:datePickerMode">spinner</item>
|
<item name="buttonBarPositiveButtonStyle">@style/CalendarPositiveButtonStyle</item>
|
||||||
|
<item name="buttonBarNegativeButtonStyle">@style/CalendarNegativeButtonStyle</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="CalendarPositiveButtonStyle" parent="@style/Widget.MaterialComponents.Button.TextButton.Dialog">
|
||||||
|
<item name="android:textColor">@color/primaryLightColor</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="CalendarNegativeButtonStyle" parent="@style/Widget.MaterialComponents.Button.TextButton.Dialog">
|
||||||
|
<item name="android:textColor">@color/primaryLightColor</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<!-- Style for an Preference Entry -->
|
<!-- Style for an Preference Entry -->
|
||||||
|
Reference in New Issue
Block a user