Added option to colorize Android's navbar

This commit is contained in:
M66B 2020-03-03 14:36:34 +01:00
parent 940552919e
commit 39045cf366
4 changed files with 48 additions and 1 deletions

View File

@ -203,6 +203,13 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
checkAuthentication();
boolean navbar_colorize = prefs.getBoolean("navbar_colorize", false);
if (navbar_colorize) {
Window window = getWindow();
if (window != null)
window.setNavigationBarColor(Helper.resolveColor(this, R.attr.colorPrimaryDark));
}
super.onCreate(savedInstanceState);
}

View File

@ -25,6 +25,7 @@ import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -33,6 +34,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CompoundButton;
@ -48,6 +50,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SwitchCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.Lifecycle;
import androidx.preference.PreferenceManager;
@ -100,6 +103,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
private SwitchCompat swImagesInline;
private SwitchCompat swSeekbar;
private SwitchCompat swActionbar;
private SwitchCompat swNavBarColorize;
private final static String[] RESET_OPTIONS = new String[]{
"theme", "landscape", "landscape3", "startup", "cards", "indentation", "date", "threading", "highlight_unread", "color_stripe",
@ -108,7 +112,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
"subject_top", "font_size_sender", "font_size_subject", "subject_italic", "subject_ellipsize", "keywords_header",
"flags", "flags_background", "preview", "preview_italic", "preview_lines", "addresses", "attachments_alt",
"contrast", "monospaced", "text_color", "text_size",
"inline_images", "collapse_quotes", "seekbar", "actionbar",
"inline_images", "collapse_quotes", "seekbar", "actionbar", "navbar_colorize"
};
@Override
@ -168,6 +172,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
swImagesInline = view.findViewById(R.id.swImagesInline);
swSeekbar = view.findViewById(R.id.swSeekbar);
swActionbar = view.findViewById(R.id.swActionbar);
swNavBarColorize = view.findViewById(R.id.swNavBarColorize);
setOptions();
@ -566,6 +571,15 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
}
});
swNavBarColorize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("navbar_colorize", checked).apply();
setNavigationBarColor(
checked ? Helper.resolveColor(getContext(), R.attr.colorPrimaryDark) : Color.BLACK);
}
});
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
return view;
@ -606,6 +620,9 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
for (String option : RESET_OPTIONS)
editor.remove(option);
editor.apply();
setNavigationBarColor(Color.BLACK);
ToastEx.makeText(getContext(), R.string.title_setup_done, Toast.LENGTH_LONG).show();
}
@ -700,10 +717,21 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
swImagesInline.setChecked(prefs.getBoolean("inline_images", false));
swSeekbar.setChecked(prefs.getBoolean("seekbar", false));
swActionbar.setChecked(prefs.getBoolean("actionbar", true));
swNavBarColorize.setChecked(prefs.getBoolean("navbar_colorize", false));
updateColor();
}
private void setNavigationBarColor(int color) {
FragmentActivity activity = getActivity();
if (activity == null)
return;
Window window = activity.getWindow();
if (window == null)
return;
window.setNavigationBarColor(color);
}
private void updateColor() {
Context context = getContext();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

View File

@ -734,5 +734,16 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSeekbar"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swNavBarColorize"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_navbar_colorize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swActionbar"
app:switchPadding="12dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

View File

@ -334,6 +334,7 @@
<string name="title_advanced_images_inline">Automatically show inline images</string>
<string name="title_advanced_seekbar">Show relative conversation position with a dot</string>
<string name="title_advanced_actionbar">Show conversation action bar</string>
<string name="title_advanced_navbar_colorize">Colorize the Android navigation bar</string>
<string name="title_advanced_double_back">Double \'back\' to exit</string>
<string name="title_advanced_pull_refresh">Pull down to refresh</string>