diff options
author | cyBerta <cyberta@riseup.net> | 2023-10-23 17:34:57 +0200 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2023-10-23 17:34:57 +0200 |
commit | 4e563004800af71d326077c8a4de4bee598fd336 (patch) | |
tree | 809f451b6d729d0a5bad0f0ef4017b94f97356e2 /app/src/main | |
parent | 9ad95a20f7500e3b52ae0cc50609635e8c73205f (diff) |
tint actionbar subtitle and icons according to actionbar title color
Diffstat (limited to 'app/src/main')
10 files changed, 77 insertions, 16 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/MainActivity.java b/app/src/main/java/se/leap/bitmaskclient/base/MainActivity.java index b459f75d..7dd01ccb 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/MainActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/MainActivity.java @@ -46,6 +46,7 @@ import static se.leap.bitmaskclient.providersetup.ProviderAPI.USER_MESSAGE; import android.content.Context; import android.content.Intent; +import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; @@ -93,7 +94,6 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener, private NavigationDrawerFragment navigationDrawerFragment; public final static String ACTION_SHOW_VPN_FRAGMENT = "action_show_vpn_fragment"; - public final static String ACTION_SHOW_LOG_FRAGMENT = "action_show_log_fragment"; public final static String ACTION_SHOW_DIALOG_FRAGMENT = "action_show_dialog_fragment"; public final static String ACTION_SHOW_MOTD_FRAGMENT = "action_show_motd_fragment"; @@ -150,6 +150,7 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener, return; } + @ColorInt int tintColor; Fragment fragment = null; switch (intent.getAction()) { case ACTION_SHOW_VPN_FRAGMENT: @@ -161,6 +162,8 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener, bundle.putParcelable(PROVIDER_KEY, provider); fragment.setArguments(bundle); showActionBar(); + int color = ((ActionBarTitle) getSupportActionBar().getCustomView()).getTitleTextColor(); + setActionBarToggleColor(color); break; case ACTION_SHOW_MOTD_FRAGMENT: fragment = new MotdFragment(); @@ -171,10 +174,6 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener, fragment.setArguments(motdBundle); hideActionBar(); break; - case ACTION_SHOW_LOG_FRAGMENT: - fragment = new LogFragment(); - showActionBar(); - break; case ACTION_SHOW_DIALOG_FRAGMENT: if (intent.hasExtra(EIP.ERRORID)) { String errorId = intent.getStringExtra(EIP.ERRORID); @@ -207,6 +206,7 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener, @ColorInt int titleColor = ContextCompat.getColor(context, R.color.colorActionBarTitleFont); actionBarTitle.setTitleTextColor(titleColor); + actionBarTitle.setSubtitleTextColor(titleColor); actionBarTitle.setCentered(BuildConfig.actionbar_center_title); if (BuildConfig.actionbar_center_title) { @@ -220,6 +220,10 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener, } } + public void setActionBarToggleColor(int color) { + navigationDrawerFragment.setDrawerToggleColor(this, color); + } + private void hideActionBar() { ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java index f50b69a5..670cdfd8 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java @@ -416,6 +416,7 @@ public class EipFragment extends Fragment implements Observer { private void setActivityBarColor(@ColorRes int primaryColor, @ColorRes int secondaryColor) { ViewHelper.setActivityBarColor(getActivity(), primaryColor, secondaryColor, R.color.actionbar_connectivity_state_text_color_dark); + ((MainActivity) getActivity()).setActionBarToggleColor(R.color.actionbar_connectivity_state_text_color_dark); } private void handleNewState() { diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/ExcludeAppsFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/ExcludeAppsFragment.java index 89b167f3..07608211 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/ExcludeAppsFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/ExcludeAppsFragment.java @@ -5,6 +5,8 @@ package se.leap.bitmaskclient.base.fragments; +import static se.leap.bitmaskclient.R.string.exclude_apps_fragment_title; + import android.Manifest; import android.app.Activity; import android.content.Context; @@ -41,8 +43,6 @@ import se.leap.bitmaskclient.base.utils.PreferenceHelper; import se.leap.bitmaskclient.base.utils.ViewHelper; import se.leap.bitmaskclient.base.views.SimpleCheckBox; -import static se.leap.bitmaskclient.R.string.exclude_apps_fragment_title; - /** * Created by arne on 16.11.14. */ @@ -271,7 +271,6 @@ public class ExcludeAppsFragment extends Fragment implements AdapterView.OnItemC @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.allowed_apps, menu); - SearchView searchView = (SearchView) menu.findItem( R.id.app_search_widget ).getActionView(); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override @@ -298,9 +297,23 @@ public class ExcludeAppsFragment extends Fragment implements AdapterView.OnItemC return false; }); + tintSearchViewChild(searchView); super.onCreateOptionsMenu(menu, inflater); } + private void tintSearchViewChild(ViewGroup view) { + for (int i = 0; i < view.getChildCount(); i++) { + View v = view.getChildAt(i); + if (v instanceof ViewGroup) { + tintSearchViewChild((ViewGroup) v); + } + if (v instanceof ImageView) { + ((ImageView) v).setColorFilter(getResources().getColor(R.color.colorActionBarTitleFont), + android.graphics.PorterDuff.Mode.SRC_IN); + } + } + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.allowed_vpn_apps, container, false); diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/LogFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/LogFragment.java index c7dd25da..56b7259e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/LogFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/LogFragment.java @@ -8,6 +8,7 @@ package se.leap.bitmaskclient.base.fragments; import static de.blinkt.openvpn.core.OpenVPNService.humanReadableByteCount; import static se.leap.bitmaskclient.R.string.log_fragment_title; import static se.leap.bitmaskclient.base.utils.ViewHelper.setActionBarSubtitle; +import static se.leap.bitmaskclient.base.utils.ViewHelper.setDefaultActivityBarColor; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; @@ -60,6 +61,7 @@ import de.blinkt.openvpn.core.VpnStatus.LogListener; import de.blinkt.openvpn.core.VpnStatus.StateListener; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.base.utils.PreferenceHelper; +import se.leap.bitmaskclient.base.utils.ViewHelper; public class LogFragment extends ListFragment implements StateListener, SeekBar.OnSeekBarChangeListener, RadioGroup.OnCheckedChangeListener, VpnStatus.ByteCountListener { public static final String TAG = LogFragment.class.getSimpleName(); @@ -432,11 +434,11 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.f_log, menu); - if (getResources().getBoolean(R.bool.logSildersAlwaysVisible)) + ViewHelper.tintMenuIcons(getContext(), menu, R.color.colorActionBarTitleFont); + if (getResources().getBoolean(R.bool.logSlidersAlwaysVisible)) menu.removeItem(R.id.toggle_time); } - @Override public void onResume() { super.onResume(); @@ -522,7 +524,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. mLogLevelSlider.setOnSeekBarChangeListener(this); - if (getResources().getBoolean(R.bool.logSildersAlwaysVisible)) + if (getResources().getBoolean(R.bool.logSlidersAlwaysVisible)) mOptionsLayout.setVisibility(View.VISIBLE); mUpStatus = v.findViewById(R.id.speedUp); @@ -532,6 +534,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. mOptionsLayout.setVisibility(View.VISIBLE); setActionBarSubtitle(this, log_fragment_title); + setDefaultActivityBarColor(getActivity()); return v; } @@ -545,7 +548,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. @Override public void onAttach(Context context) { super.onAttach(context); - if (getResources().getBoolean(R.bool.logSildersAlwaysVisible)) { + if (getResources().getBoolean(R.bool.logSlidersAlwaysVisible)) { mShowOptionsLayout = true; if (mOptionsLayout != null) mOptionsLayout.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/NavigationDrawerFragment.java index a06fee5d..60c21c40 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/NavigationDrawerFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/NavigationDrawerFragment.java @@ -46,7 +46,9 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.graphics.drawable.DrawerArrowDrawable; import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; import androidx.core.view.GravityCompat; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; @@ -64,7 +66,6 @@ import se.leap.bitmaskclient.base.utils.PreferenceHelper; import se.leap.bitmaskclient.base.views.IconSwitchEntry; import se.leap.bitmaskclient.base.views.IconTextEntry; import se.leap.bitmaskclient.eip.EipStatus; -import se.leap.bitmaskclient.providersetup.ProviderListActivity; import se.leap.bitmaskclient.providersetup.activities.SetupActivity; import se.leap.bitmaskclient.tethering.TetheringObservable; @@ -202,6 +203,7 @@ public class NavigationDrawerFragment extends Fragment implements SharedPreferen activity.invalidateOptionsMenu(); } }; + setDrawerToggleColor(activity, ContextCompat.getColor(activity, R.color.amber200)); } private void setupEntries() { @@ -222,6 +224,7 @@ public class NavigationDrawerFragment extends Fragment implements SharedPreferen account.setText(currentProvider.getName()); account.setOnClickListener((buttonView) -> { Fragment fragment = new EipFragment(); + setDrawerToggleColor(drawerView.getContext(), ContextCompat.getColor(drawerView.getContext(), R.color.actionbar_connectivity_state_text_color_dark)); Bundle arguments = new Bundle(); arguments.putParcelable(PROVIDER_KEY, currentProvider); fragment.setArguments(arguments); @@ -230,6 +233,13 @@ public class NavigationDrawerFragment extends Fragment implements SharedPreferen }); } + public void setDrawerToggleColor(Context context, int color) { + DrawerArrowDrawable drawable = new DrawerArrowDrawable(context); + drawable.setTint(color); + drawable.setColor(color); + drawerToggle.setDrawerArrowDrawable(drawable); + } + private void initSwitchProviderEntry() { if (isDefaultBitmask()) { IconTextEntry switchProvider = drawerView.findViewById(R.id.switch_provider); @@ -249,6 +259,7 @@ public class NavigationDrawerFragment extends Fragment implements SharedPreferen advancedSettings.setOnClickListener(v -> { closeDrawer(); Fragment fragment = new SettingsFragment(); + setDrawerToggleColor(drawerView.getContext(), ContextCompat.getColor(drawerView.getContext(), R.color.colorActionBarTitleFont)); fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG); }); } @@ -298,6 +309,7 @@ public class NavigationDrawerFragment extends Fragment implements SharedPreferen return; } Fragment fragment = new GatewaySelectionFragment(); + setDrawerToggleColor(drawerView.getContext(), ContextCompat.getColor(drawerView.getContext(), R.color.colorActionBarTitleFont)); fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG); }); } @@ -321,6 +333,7 @@ public class NavigationDrawerFragment extends Fragment implements SharedPreferen log.setOnClickListener((buttonView) -> { closeDrawer(); Fragment fragment = new LogFragment(); + setDrawerToggleColor(drawerView.getContext(), ContextCompat.getColor(drawerView.getContext(), R.color.colorActionBarTitleFont)); fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG); }); } @@ -331,6 +344,7 @@ public class NavigationDrawerFragment extends Fragment implements SharedPreferen about.setOnClickListener((buttonView) -> { closeDrawer(); Fragment fragment = new AboutFragment(); + setDrawerToggleColor(drawerView.getContext(), ContextCompat.getColor(drawerView.getContext(), R.color.colorActionBarTitleFont)); fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG); }); } diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java index ebf26048..ed7bd9f2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java @@ -9,10 +9,13 @@ import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; import android.text.Spannable; import android.text.SpannableString; import android.text.style.ForegroundColorSpan; import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.Window; import android.view.WindowManager; @@ -24,7 +27,9 @@ import androidx.annotation.NonNull; import androidx.annotation.StringRes; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; +import androidx.core.graphics.drawable.DrawableCompat; import androidx.fragment.app.Fragment; import se.leap.bitmaskclient.R; @@ -116,6 +121,12 @@ public class ViewHelper { if (customView instanceof ActionBarTitle) { ActionBarTitle actionBarTitle = (ActionBarTitle) customView; actionBarTitle.setTitleTextColor(ContextCompat.getColor(bar.getThemedContext(), actionBarTextColor)); + actionBarTitle.setSubtitleTextColor(ContextCompat.getColor(bar.getThemedContext(), actionBarTextColor)); + } + + Toolbar tb = activity.findViewById(R.id.toolbar); + if (tb != null && tb.getOverflowIcon() != null) { + tb.getOverflowIcon().setTint(ContextCompat.getColor(bar.getThemedContext(), actionBarTextColor)); } } @@ -139,6 +150,17 @@ public class ViewHelper { return rtnValue; } + public static void tintMenuIcons(Context context, Menu menu, @ColorRes int color) { + for (int i = 0; i < menu.size(); i++) { + MenuItem item = menu.getItem(i); + Drawable normalDrawable = item.getIcon(); + Drawable wrapDrawable = DrawableCompat.wrap(normalDrawable); + DrawableCompat.setTint(wrapDrawable, context.getResources().getColor(color)); + + item.setIcon(wrapDrawable); + } + } + public static void setActionBarTextColor(ActionBar bar, @ColorRes int titleColor) { CharSequence titleCharSequence = bar.getTitle(); if (titleCharSequence == null || titleCharSequence.length() == 0) { diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/ActionBarTitle.java b/app/src/main/java/se/leap/bitmaskclient/base/views/ActionBarTitle.java index 3aa21ae9..a754efa9 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/ActionBarTitle.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/ActionBarTitle.java @@ -67,6 +67,10 @@ public class ActionBarTitle extends LinearLayoutCompat { actionBarTitle.setTextColor(color); } + public @ColorInt int getTitleTextColor() { + return actionBarTitle.getCurrentTextColor(); + } + public void setSubtitleTextColor(@ColorInt int color) { actionBarSubtitle.setTextColor(color); } diff --git a/app/src/main/res/values-sw600dp/dimens.xml b/app/src/main/res/values-sw600dp/dimens.xml index fb8e7ded..ad0fae2c 100644 --- a/app/src/main/res/values-sw600dp/dimens.xml +++ b/app/src/main/res/values-sw600dp/dimens.xml @@ -5,7 +5,7 @@ --> <resources> - <bool name="logSildersAlwaysVisible">true</bool> + <bool name="logSlidersAlwaysVisible">true</bool> <dimen name="bitmask_logo">72dp</dimen> <dimen name="bitmask_logo_compact">56dp</dimen> <dimen name="stdpadding">16dp</dimen> diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 10d802cd..0ad20a63 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -80,7 +80,7 @@ <color name="actionbar_connectivity_state_text_color_light">@color/white</color> <!-- default action bar colors used in other fragments than EipFragment --> <color name="colorActionBarTitleFont">@color/white</color> - <color name="colorActionBarSubtitleFont">@color/black800</color> + <color name="colorActionBarSubtitleFont">@color/white</color> <!-- background color of the splash screen --> <color name="windowSplashScreenBackgroundColor">@color/white</color> diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index b17683ae..edda28c7 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -8,7 +8,7 @@ <dimen name="stdpadding">8dp</dimen> <dimen name="compact_padding">3dp</dimen> <dimen name="standard_margin">8dp</dimen> - <bool name="logSildersAlwaysVisible">false</bool> + <bool name="logSlidersAlwaysVisible">false</bool> <dimen name="diameter">48dp</dimen> |