Skip to content
Open
33 changes: 31 additions & 2 deletions app/src/main/java/net/gsantner/markor/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
Expand All @@ -24,7 +25,6 @@
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;
Expand All @@ -33,6 +33,7 @@

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.navigation.NavigationBarView;

import net.gsantner.markor.BuildConfig;
import net.gsantner.markor.R;
Expand Down Expand Up @@ -101,6 +102,8 @@ public void onPageSelected(int position) {
});

setSupportActionBar(findViewById(R.id.toolbar));
applyActivityBarBackgroundColors();
applyMainBottomTabBarAppearance();
optShowRate();

// Setup viewpager
Expand Down Expand Up @@ -155,7 +158,7 @@ public void onActivityFirstTimeVisible() {

@Override
public Integer getNewNavigationBarColor() {
return ContextCompat.getColor(this, R.color.primary);
return _appSettings.getConfiguredBarBackgroundColor();
}

@Override
Expand Down Expand Up @@ -301,6 +304,7 @@ protected void onResume() {
}

_cu.setKeepScreenOn(this, _appSettings.isKeepScreenOn());
applyMainBottomTabBarAppearance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && _appSettings.isMultiWindowEnabled()) {
setTaskDescription(new ActivityManager.TaskDescription(getString(R.string.app_name)));
}
Expand Down Expand Up @@ -329,6 +333,31 @@ public void onPostResume() {
super.onPostResume();
}

private void applyMainBottomTabBarAppearance() {
if (_bottomNav == null) {
return;
}

final boolean showTabTitles = _appSettings.isMainBottomBarTabTitlesShown();
final int barColor = _appSettings.getConfiguredBarBackgroundColor();

_bottomNav.setBackgroundColor(barColor);
_bottomNav.setItemBackground(new ColorDrawable(barColor));
_bottomNav.setLabelVisibilityMode(showTabTitles
? NavigationBarView.LABEL_VISIBILITY_LABELED
: NavigationBarView.LABEL_VISIBILITY_UNLABELED);
applyMainBottomTabBarMinHeight(showTabTitles);
}

private void applyMainBottomTabBarMinHeight(final boolean showTabTitles) {
final int minHeight = getResources().getDimensionPixelSize(showTabTitles
? R.dimen.main_bottom_bar_min_height_labeled
: R.dimen.main_bottom_bar_min_height_unlabeled);
if (_bottomNav.getMinimumHeight() != minHeight) {
_bottomNav.setMinimumHeight(minHeight);
}
}

// Cycle between recent, favourite, and current
public boolean onLongClickFab(View view) {
if (_notebook != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;

import net.gsantner.markor.R;
Expand All @@ -32,6 +33,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}
}

@Override
protected void onResume() {
super.onResume();
applyActivityBarBackgroundColors();
}

protected boolean onReceiveKeyPress(GsFragmentBase fragment, int keyCode, KeyEvent event) {
return fragment.onReceiveKeyPress(keyCode, event);
}
Expand All @@ -49,6 +56,17 @@ public Integer getNewActivityBackgroundColor() {
return _appSettings.getAppThemeName().contains("black") ? Color.BLACK : null;
}

public void applyActivityBarBackgroundColors() {
final int backgroundColor = _appSettings.getConfiguredBarBackgroundColor();

final Toolbar toolbar = findViewById(R.id.toolbar);
if (toolbar != null) {
toolbar.setBackgroundColor(backgroundColor);
}

_cu.setStatusbarColor(this, backgroundColor);
}

@Override
protected AppSettings createAppSettingsInstance() {
return new AppSettings(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
Expand Down Expand Up @@ -57,7 +56,6 @@ public static class RESULT {
}

public static int activityRetVal = RESULT.NOCHANGE;
private static int iconColor = Color.WHITE;

protected Toolbar toolbar;

Expand All @@ -72,7 +70,6 @@ public void onCreate(Bundle b) {

// Custom code
GsFontPreferenceCompat.additionalyCheckedFolder = new File(_appSettings.getNotebookDirectory(), ".app/fonts");
iconColor = _cu.rcolor(this, R.color.primary_text);
toolbar.setTitle(R.string.settings);
setSupportActionBar(findViewById(R.id.toolbar));
toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp));
Expand Down Expand Up @@ -191,7 +188,6 @@ public void doUpdatePreferences() {
R.string.pref_key__swipe_to_change_mode,
R.string.pref_key__todotxt__hl_delay,
R.string.pref_key__markdown__hl_delay_v2,
R.string.pref_key__theming_hide_system_statusbar,
R.string.pref_key__tab_width_v2,
R.string.pref_key__editor_line_spacing,
};
Expand Down Expand Up @@ -223,6 +219,13 @@ protected void onPreferenceChanged(final SharedPreferences prefs, final String k
} else if (eq(key, R.string.pref_key__theming_hide_system_statusbar)) {
activityRetVal = RESULT.RESTART_REQ;
_appSettings.setRecreateMainRequired(true);
} else if (eq(key, R.string.pref_key__ui_flat_top_bottom_bars)) {
final Activity activity = getActivity();
if (activity instanceof MarkorBaseActivity) {
((MarkorBaseActivity) activity).applyActivityBarBackgroundColors();
}
} else if (eq(key, R.string.pref_key__file_browser_show_dividers)) {
_appSettings.setRecreateMainRequired(true);
} else if (eq(key, R.string.pref_key__is_launcher_for_special_files_enabled)) {
boolean extraLaunchersEnabled = prefs.getBoolean(key, false);
new MarkorContextUtils(getActivity()).applySpecialLaunchersVisibility(getActivity(), extraLaunchersEnabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentActivity;

Expand Down Expand Up @@ -493,19 +498,64 @@ public DateFragment setCalendar(Calendar calendar) {
public DatePickerDialog onCreateDialog(final Bundle savedInstanceState) {
super.onCreateDialog(savedInstanceState);

final DatePickerDialog dialog = new DatePickerDialog(getContext(), _listener, _year, _month, _day);
final Context context = requireContext();
final int backgroundColor = ContextCompat.getColor(context, R.color.background);
final int primaryTextColor = ContextCompat.getColor(context, R.color.primary_text);
final DatePickerDialog dialog = new DatePickerDialog(
context,
R.style.Theme_AppCompat_DayNight_Dialog_Rounded,
_listener,
_year,
_month,
_day
);
styleDatePicker(dialog, backgroundColor, primaryTextColor);

if (_message != null && !_message.isEmpty()) {
dialog.setMessage(_message);
dialog.setTitle(_message);
}

if (_extraListener != null && _extraLabel != null && !_extraLabel.isEmpty()) {
dialog.setButton(DialogInterface.BUTTON_NEUTRAL, _extraLabel, _extraListener);
}

dialog.setOnShowListener(dialogInterface -> {
styleDatePicker(dialog, backgroundColor, primaryTextColor);
final Window win = dialog.getWindow();
if (win != null) {
win.setBackgroundDrawableResource(R.drawable.rounded_corner_background);
win.setLayout(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
}
});

return dialog;
}

private static void styleDatePicker(final DatePickerDialog dialog, final int backgroundColor, final int primaryTextColor) {
dialog.getDatePicker().setBackgroundColor(backgroundColor);

setPlatformDatePickerViewColor(dialog, "date_picker_header", backgroundColor, primaryTextColor);
setPlatformDatePickerViewColor(dialog, "date_picker_header_year", backgroundColor, primaryTextColor);
setPlatformDatePickerViewColor(dialog, "date_picker_header_date", backgroundColor, primaryTextColor);
setPlatformDatePickerViewColor(dialog, "date_picker_header_day", backgroundColor, primaryTextColor);
}

private static void setPlatformDatePickerViewColor(
final DatePickerDialog dialog,
final String name,
final int backgroundColor,
final int primaryTextColor
) {
final int id = dialog.getContext().getResources().getIdentifier(name, "id", "android");
final View view = id != 0 ? dialog.findViewById(id) : null;
if (view != null) {
view.setBackgroundColor(backgroundColor);
if (view instanceof TextView) {
((TextView) view).setTextColor(primaryTextColor);
}
}
}

@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package net.gsantner.markor.frontend;

import android.app.Activity;
import android.content.res.ColorStateList;
import android.content.Context;
import android.content.DialogInterface;
import android.text.Editable;
Expand All @@ -24,6 +25,8 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.core.widget.TextViewCompat;
import androidx.fragment.app.FragmentManager;

import net.gsantner.markor.R;
Expand Down Expand Up @@ -97,10 +100,12 @@ public static void showInsertImageOrLinkDialog(
final EditText inputPathName = view.findViewById(R.id.ui__select_path_dialog__name);
final EditText inputPathUrl = view.findViewById(R.id.ui__select_path_dialog__url);
final Button buttonBrowseFilesystem = view.findViewById(R.id.ui__select_path_dialog__browse_filesystem);
final Button buttonRecordAudio = view.findViewById(R.id.ui__select_path_dialog__record_audio);
final Button buttonSearch = view.findViewById(R.id.ui__select_path_dialog__search);
final Button buttonPictureGallery = view.findViewById(R.id.ui__select_path_dialog__gallery_picture);
final Button buttonPictureCamera = view.findViewById(R.id.ui__select_path_dialog__camera_picture);
final Button buttonPictureEdit = view.findViewById(R.id.ui__select_path_dialog__edit_picture);
styleActionButtons(activity, buttonBrowseFilesystem, buttonRecordAudio, buttonSearch, buttonPictureCamera, buttonPictureGallery, buttonPictureEdit);

builder.setCancelable(true);
builder.setNegativeButton(android.R.string.cancel, (di, b) -> di.dismiss());
Expand Down Expand Up @@ -140,6 +145,7 @@ public static void showInsertImageOrLinkDialog(
browseType = InsertType.IMAGE_BROWSE;
okType = InsertType.IMAGE_DIALOG;
} else if (action == AUDIO_ACTION) {
buttonRecordAudio.setVisibility(View.VISIBLE);
dialog.setTitle(R.string.audio);
browseType = InsertType.AUDIO_BROWSE;
okType = InsertType.AUDIO_DIALOG;
Expand All @@ -153,6 +159,7 @@ public static void showInsertImageOrLinkDialog(
final String ok = activity.getString(android.R.string.ok);
dialog.setButton(DialogInterface.BUTTON_POSITIVE, ok, (di, b) -> _insertItem.callback(okType));
buttonBrowseFilesystem.setOnClickListener(v -> _insertItem.callback(browseType));
buttonRecordAudio.setOnClickListener(v -> _insertItem.callback(InsertType.AUDIO_RECORDING));
buttonSearch.setOnClickListener(v -> _insertItem.callback(InsertType.LINK_SEARCH));
buttonPictureCamera.setOnClickListener(b -> _insertItem.callback(InsertType.IMAGE_CAMERA));
buttonPictureGallery.setOnClickListener(v -> _insertItem.callback(InsertType.IMAGE_GALLERY));
Expand All @@ -167,6 +174,27 @@ public static void showInsertImageOrLinkDialog(
}
}

private static void styleActionButtons(final Context context, final Button... buttons) {
final int textColor = ContextCompat.getColor(context, R.color.primary_text);
final ColorStateList textColorList = ColorStateList.valueOf(textColor);
final int horizontalPadding = dpToPx(context, 16);
final int verticalPadding = dpToPx(context, 10);

for (Button button : buttons) {
button.setAllCaps(false);
button.setMinHeight(dpToPx(context, 48));
button.setTextColor(textColorList);
button.setCompoundDrawablePadding(dpToPx(context, 12));
button.setBackgroundResource(R.drawable.attachment_dialog_action_button_background);
button.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);
TextViewCompat.setCompoundDrawableTintList(button, textColorList);
}
}

private static int dpToPx(final Context context, final int dp) {
return Math.round(dp * context.getResources().getDisplayMetrics().density);
}

private enum InsertType {
IMAGE_CAMERA,
IMAGE_GALLERY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public static void updateFsViewerOpts(final GsFileBrowserOptions.Options opts, f
opts.popularFiles = appSettings.getPopularFiles();

opts.descriptionFormat = appSettings.getString(R.string.pref_key__file_description_format, "");
opts.primaryColor = appSettings.isFlatTopBottomBarColorEnabled() ? R.color.background : R.color.primary;
opts.showDividers = appSettings.isFileBrowserDividerEnabled();

final File downloads = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
opts.addVirtualFile("Download", downloads, R.drawable.baseline_download_24);
Expand Down
27 changes: 23 additions & 4 deletions app/src/main/java/net/gsantner/markor/model/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,29 @@ public String getAppThemeName() {
return getString(R.string.pref_key__app_theme, _context.getString(R.string.app_theme_system));
}

public boolean isFlatTopBottomBarColorEnabled() {
return getBool(R.string.pref_key__ui_flat_top_bottom_bars, false);
}

public boolean isMainBottomBarTabTitlesShown() {
return getBool(R.string.pref_key__main_bottom_bar_show_tab_titles, true);
}

public boolean isFileBrowserDividerEnabled() {
return getBool(R.string.pref_key__file_browser_show_dividers, true);
}

public @ColorInt int getUiBackgroundColor() {
if (getAppThemeName().contains("black")) {
return Color.BLACK;
}
return rcolor(R.color.background);
}

public @ColorInt int getConfiguredBarBackgroundColor() {
return isFlatTopBottomBarColorEnabled() ? getUiBackgroundColor() : rcolor(R.color.primary);
}

public void setEditorBasicColor(boolean forDarkMode, @ColorRes int fgColor, @ColorRes int bgColor) {
int resIdFg = forDarkMode ? R.string.pref_key__basic_color_scheme__fg_dark : R.string.pref_key__basic_color_scheme__fg_light;
int resIdBg = forDarkMode ? R.string.pref_key__basic_color_scheme__bg_dark : R.string.pref_key__basic_color_scheme__bg_light;
Expand Down Expand Up @@ -824,10 +847,6 @@ public boolean isFileBrowserSortFolderFirst() {
return getBool(R.string.pref_key__filesystem_folder_first, true);
}

public String getNavigationBarColor() {
return getString(R.string.pref_key__navigationbar_color, "#000000");
}

public String getAppStartupFolderMenuId() {
return getString(R.string.pref_key__app_start_folder, "notebook");
}
Expand Down
Loading
Loading