1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-22 04:12:08 +01:00

Top toolbar with overflow icons and light/dark theme

This commit is contained in:
Gregor Santner 2017-10-29 14:47:00 +01:00
parent aaa2445bef
commit a96e91aefb
No known key found for this signature in database
GPG key ID: 7E83A7834AECB009
14 changed files with 108 additions and 119 deletions

View file

@ -22,9 +22,7 @@ android {
targetSdkVersion version_sdk.compileSdk targetSdkVersion version_sdk.compileSdk
buildConfigField "boolean", "IS_TEST_BUILD", "false" buildConfigField "boolean", "IS_TEST_BUILD", "false"
buildConfigField "boolean", "IS_GPLAY_BUILD", "false" buildConfigField "boolean", "IS_GPLAY_BUILD", "false"
buildConfigField("String[]", "APPLICATION_LANGUAGES", '{' + getUsedAndroidLanguages().collect { buildConfigField("String[]", "APPLICATION_LANGUAGES", '{' + getUsedAndroidLanguages().collect {"\"${it}\""}.join(",") + '}')
"\"${it}\""
}.join(",") + '}')
buildConfigField "String", "GITHASH", "\"${getGitHash()}\"" buildConfigField "String", "GITHASH", "\"${getGitHash()}\""
applicationId "com.github.dfa.diaspora_android" applicationId "com.github.dfa.diaspora_android"
@ -52,7 +50,9 @@ android {
productFlavors { productFlavors {
flavorDefault { flavorDefault {
} }
/*flavorGplay {
/*
flavorGplay {
buildConfigField "boolean", "IS_GPLAY_BUILD", "true" buildConfigField "boolean", "IS_GPLAY_BUILD", "true"
}*/ }*/
flavorTest { flavorTest {

View file

@ -198,11 +198,6 @@ public class AboutActivity extends ThemedActivity
return TAG; return TAG;
} }
@Override
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
/* Nothing to do */
}
@Override @Override
public boolean onBackPressed() { public boolean onBackPressed() {
return false; return false;
@ -300,11 +295,6 @@ public class AboutActivity extends ThemedActivity
return TAG; return TAG;
} }
@Override
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
/* Nothing to do */
}
@Override @Override
public boolean onBackPressed() { public boolean onBackPressed() {
return false; return false;

View file

@ -101,11 +101,6 @@ public class AspectListFragment extends ThemedFragment implements OnSomethingCli
return TAG; return TAG;
} }
@Override
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
/* Nothing to do */
}
@Override @Override
public boolean onBackPressed() { public boolean onBackPressed() {
return false; return false;

View file

@ -30,6 +30,7 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
@ -44,6 +45,7 @@ import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.data.DiasporaUserProfile; import com.github.dfa.diaspora_android.data.DiasporaUserProfile;
import com.github.dfa.diaspora_android.ui.theme.ThemedAlertDialogBuilder; import com.github.dfa.diaspora_android.ui.theme.ThemedAlertDialogBuilder;
import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.AppSettings;
import com.github.dfa.diaspora_android.util.ContextUtils; import com.github.dfa.diaspora_android.util.ContextUtils;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper; import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
import com.github.dfa.diaspora_android.web.BrowserFragment; import com.github.dfa.diaspora_android.web.BrowserFragment;
@ -92,13 +94,12 @@ public class DiasporaStreamFragment extends BrowserFragment {
} }
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.stream__menu_top, menu);
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);
} inflater.inflate(R.menu.stream__menu_top, menu);
@Override
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) { final boolean darkBg = ContextUtils.get().shouldColorOnTopBeLight(AppSettings.get().getPrimaryColor());
inflater.inflate(R.menu.stream__menu_bottom, menu); ContextUtils.get().tintMenuItems(menu, true, ContextCompat.getColor(getActivity(), darkBg ? R.color.white : R.color.black));
} }
@Override @Override

View file

@ -37,13 +37,13 @@ import android.support.design.widget.AppBarLayout;
import android.support.design.widget.NavigationView; import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.GravityCompat; import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
@ -90,6 +90,7 @@ import com.github.dfa.diaspora_android.web.custom_tab.CustomTabActivityHelper;
import net.gsantner.opoc.util.SimpleMarkdownParser; import net.gsantner.opoc.util.SimpleMarkdownParser;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
@ -138,9 +139,6 @@ public class MainActivity extends ThemedActivity
@BindView(R.id.main__topbar) @BindView(R.id.main__topbar)
Toolbar toolbarTop; Toolbar toolbarTop;
@BindView(R.id.main__bottombar)
ActionMenuView toolbarBottom;
@BindView(R.id.fragment_container) @BindView(R.id.fragment_container)
FrameLayout fragmentContainer; FrameLayout fragmentContainer;
@ -178,6 +176,7 @@ public class MainActivity extends ThemedActivity
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
} }
// Bind UI // Bind UI
setContentView(R.layout.main__activity); setContentView(R.layout.main__activity);
ButterKnife.bind(this); ButterKnife.bind(this);
@ -267,12 +266,6 @@ public class MainActivity extends ThemedActivity
if (actionBar != null) { if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
} }
toolbarBottom.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
CustomFragment top = getTopFragment();
return MainActivity.this.onOptionsItemSelected(item) || (top != null && top.onOptionsItemSelected(item));
}
});
setTitle(R.string.app_name); setTitle(R.string.app_name);
//Setup snackbar //Setup snackbar
@ -683,22 +676,23 @@ public class MainActivity extends ThemedActivity
//Clear the menus //Clear the menus
menu.clear(); menu.clear();
toolbarBottom.getMenu().clear();
toolbarBottom.setVisibility(View.VISIBLE);
CustomFragment top = getTopFragment(); CustomFragment top = getTopFragment();
if (top != null) { if (top != null) {
//PodSelectionFragment? boolean isPodSel = top.getFragmentTag().equals(PodSelectionFragment.TAG);
if (top.getFragmentTag().equals(PodSelectionFragment.TAG)) {
///Hide bottom _toolbar // Extended notifications
toolbarBottom.setVisibility(View.GONE);
} else {
cache = _appSettings.isExtendedNotificationsActivated(); cache = _appSettings.isExtendedNotificationsActivated();
getMenuInflater().inflate(R.menu.main__menu_top, menu); getMenuInflater().inflate(R.menu.main__menu_top, menu);
menu.findItem(R.id.action_notifications).setVisible(!cache); menu.findItem(R.id.action_notifications).setVisible(!cache);
menu.findItem(R.id.action_notifications_extended).setVisible(cache); menu.findItem(R.id.action_notifications_extended).setVisible(cache);
} }
}
final boolean darkBg = ContextUtils.get().shouldColorOnTopBeLight(AppSettings.get().getPrimaryColor());
ContextUtils.get()
.tintMenuItems(menu, true, ContextCompat.getColor(this, darkBg ? R.color.white : R.color.black))
.setSubMenuIconsVisiblity(menu, true);
return true; return true;
} }
@ -1213,7 +1207,6 @@ public class MainActivity extends ThemedActivity
@Override @Override
protected void applyColorToViews() { protected void applyColorToViews() {
ThemeHelper.updateToolbarColor(toolbarTop); ThemeHelper.updateToolbarColor(toolbarTop);
ThemeHelper.updateActionMenuViewColor(toolbarBottom);
navDrawerLayout.setBackgroundColor(_appSettings.getPrimaryColor()); navDrawerLayout.setBackgroundColor(_appSettings.getPrimaryColor());
navProfilePictureArea.setBackgroundColor(_appSettings.getPrimaryColor()); navProfilePictureArea.setBackgroundColor(_appSettings.getPrimaryColor());
if (_appSettings.isAmoledColorMode()) { if (_appSettings.isAmoledColorMode()) {
@ -1223,6 +1216,10 @@ public class MainActivity extends ThemedActivity
navheaderTitle.setTextColor(Color.GRAY); navheaderTitle.setTextColor(Color.GRAY);
navheaderDescription.setTextColor(Color.DKGRAY); navheaderDescription.setTextColor(Color.DKGRAY);
} }
int popupTheme = ContextUtils.get().shouldColorOnTopBeLight(AppSettings.get().getPrimaryColor())
? R.style.AppTheme_PopupOverlay_Dark : R.style.AppTheme_PopupOverlay_Light;
toolbarTop.setPopupTheme(popupTheme);
} }
@Override @Override

View file

@ -28,6 +28,7 @@ import android.graphics.drawable.ColorDrawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.AppCompatButton; import android.support.v7.widget.AppCompatButton;
@ -178,10 +179,8 @@ public class PodSelectionFragment extends ThemedFragment implements SearchView.O
listViewPod.setDivider(new ColorDrawable(Color.GRAY)); listViewPod.setDivider(new ColorDrawable(Color.GRAY));
listViewPod.setDividerHeight(dividerHeight); listViewPod.setDividerHeight(dividerHeight);
if (appSettings.isAmoledColorMode()) { if (appSettings.isAmoledColorMode()) {
buttonUseCustomPod.setSupportBackgroundTintList(ColorStateList.valueOf(Color.DKGRAY));
buttonUseCustomPod.setTextColor(Color.WHITE); buttonUseCustomPod.setTextColor(Color.WHITE);
} else { } else {
buttonUseCustomPod.setSupportBackgroundTintList(ColorStateList.valueOf(appSettings.getAccentColor()));
buttonUseCustomPod.setTextColor(ContextUtils.get().shouldColorOnTopBeLight(appSettings.getAccentColor()) ? Color.WHITE : Color.BLACK); buttonUseCustomPod.setTextColor(ContextUtils.get().shouldColorOnTopBeLight(appSettings.getAccentColor()) ? Color.WHITE : Color.BLACK);
} }
} }
@ -235,6 +234,7 @@ public class PodSelectionFragment extends ThemedFragment implements SearchView.O
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.podselection__menu, menu); inflater.inflate(R.menu.podselection__menu, menu);
MenuItem searchItem = menu.findItem(R.id.podselection__action_search); MenuItem searchItem = menu.findItem(R.id.podselection__action_search);
@ -243,7 +243,8 @@ public class PodSelectionFragment extends ThemedFragment implements SearchView.O
searchView.setOnQueryTextListener(this); searchView.setOnQueryTextListener(this);
} }
super.onCreateOptionsMenu(menu, inflater); final boolean darkBg = ContextUtils.get().shouldColorOnTopBeLight(AppSettings.get().getPrimaryColor());
ContextUtils.get().tintMenuItems(menu, true, ContextCompat.getColor(getActivity(), darkBg ? R.color.white : R.color.black));
} }
@Override @Override
@ -299,11 +300,6 @@ public class PodSelectionFragment extends ThemedFragment implements SearchView.O
/* /*
* Dummy implementations * Dummy implementations
*/ */
@Override
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
}
@Override @Override
public boolean onQueryTextSubmit(String query) { public boolean onQueryTextSubmit(String query) {
return false; return false;

View file

@ -100,11 +100,6 @@ public class TagListFragment extends ThemedFragment implements OnSomethingClickL
return TAG; return TAG;
} }
@Override
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
/* Nothing to do */
}
@Override @Override
public boolean onBackPressed() { public boolean onBackPressed() {
return false; return false;

View file

@ -50,14 +50,6 @@ public abstract class CustomFragment extends Fragment {
*/ */
public abstract String getFragmentTag(); public abstract String getFragmentTag();
/**
* Add fragment-dependent options to the bottom options _toolbar
*
* @param menu bottom menu
* @param inflater inflater
*/
public abstract void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater);
/** /**
* Return true if the fragment reacted to a back button press, false else. * Return true if the fragment reacted to a back button press, false else.
* In case the fragment returned false, the parent activity should handle the backPress. * In case the fragment returned false, the parent activity should handle the backPress.

View file

@ -252,11 +252,6 @@ public class BrowserFragment extends ThemedFragment {
return TAG; return TAG;
} }
@Override
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
/* Nothing to do here */
}
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);

View file

@ -29,6 +29,7 @@ import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@ -37,6 +38,7 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes; import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -52,7 +54,10 @@ import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.webkit.WebView; import android.webkit.WebView;
import android.widget.ImageView; import android.widget.ImageView;
@ -65,11 +70,12 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.util.Locale; import java.util.Locale;
import static android.graphics.Bitmap.CompressFormat; import static android.graphics.Bitmap.CompressFormat;
@SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue", "SpellCheckingInspection", "deprecation", "ObsoleteSdkInt"}) @SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue", "SpellCheckingInspection", "deprecation", "ObsoleteSdkInt", "ConstantConditions", "UnusedReturnValue"})
public class ContextUtils { public class ContextUtils {
//######################## //########################
//## Members, Constructors //## Members, Constructors
@ -322,7 +328,7 @@ public class ContextUtils {
} }
// Find out if color above the given color should be light or dark. true if light // Find out if color above the given color should be light or dark. true if light
public boolean shouldColorOnTopBeLight(int colorOnBottomInt) { public boolean shouldColorOnTopBeLight(@ColorInt int colorOnBottomInt) {
return 186 > (((0.299 * Color.red(colorOnBottomInt)) return 186 > (((0.299 * Color.red(colorOnBottomInt))
+ ((0.587 * Color.green(colorOnBottomInt)) + ((0.587 * Color.green(colorOnBottomInt))
+ (0.114 * Color.blue(colorOnBottomInt))))); + (0.114 * Color.blue(colorOnBottomInt)))));
@ -510,4 +516,32 @@ public class ContextUtils {
} }
return bitmap; return bitmap;
} }
public ContextUtils tintMenuItems(Menu menu, boolean recurse, @ColorInt int iconColor) {
for (int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i);
Drawable drawable = item.getIcon();
if (drawable != null) {
drawable.mutate();
drawable.setColorFilter(iconColor, PorterDuff.Mode.SRC_IN);
}
if (item.hasSubMenu() && recurse) {
tintMenuItems(item.getSubMenu(), recurse, iconColor);
}
}
return this;
}
@SuppressLint("PrivateApi")
public ContextUtils setSubMenuIconsVisiblity(Menu menu, boolean visible) {
if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
try {
Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
m.setAccessible(true);
m.invoke(menu, visible);
} catch (Exception ignored) {
}
}
return this;
}
} }

View file

@ -28,22 +28,5 @@
android:layout_height="fill_parent" android:layout_height="fill_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" /> app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:theme="@style/AppTheme.AppBarOverlay"
app:layout_behavior="com.github.dfa.diaspora_android.ui.BottomBarBehavior">
<android.support.v7.widget.ActionMenuView
android:id="@+id/main__bottombar"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@color/colorPrimary"
android:theme="@style/BottomToolbarMenuOverflowStyle"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/Theme.AppCompat.NoActionBar" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout> </android.support.design.widget.CoordinatorLayout>

View file

@ -4,29 +4,5 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
tools:ignore="AlwaysShowAction"> tools:ignore="AlwaysShowAction">
<item
android:icon="@drawable/ic_share_white_48px"
android:orderInCategory="300"
android:title="@string/action_share_dotdotdot"
app:showAsAction="always">
<menu>
<item
android:id="@+id/action_share_screenshot"
android:title="@string/share__share_screenshot" />
<item
android:id="@+id/action_take_screenshot"
android:title="@string/share__take_screenshot" />
<item
android:id="@+id/action_share_link"
android:title="@string/share__share_link_as_text" />
</menu>
</item>
<item
android:id="@+id/action_go_to_top"
android:icon="@drawable/ic_arrow_upward_white_48px"
android:orderInCategory="400"
android:title="@string/action_go_to_top"
app:showAsAction="always" />
</menu> </menu>

View file

@ -1,10 +1,36 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:icon="@drawable/ic_share_white_48px"
android:orderInCategory="300"
android:title="@string/action_share_dotdotdot"
app:showAsAction="never">
<menu>
<item
android:id="@+id/action_share_screenshot"
android:title="@string/share__share_screenshot" />
<item
android:id="@+id/action_take_screenshot"
android:title="@string/share__take_screenshot" />
<item
android:id="@+id/action_share_link"
android:title="@string/share__share_link_as_text" />
</menu>
</item>
<item
android:id="@+id/action_go_to_top"
android:icon="@drawable/ic_arrow_upward_white_48px"
android:orderInCategory="400"
android:title="@string/action_go_to_top"
app:showAsAction="never" />
<item <item
android:id="@+id/action_reload" android:id="@+id/action_reload"
android:icon="@drawable/ic_refresh_white_48px" android:icon="@drawable/ic_refresh_white_48px"
android:orderInCategory="1000" android:orderInCategory="1000"
android:title="@string/reload" android:title="@string/reload"
app:showAsAction="always" /> app:showAsAction="never" />
</menu> </menu>

View file

@ -29,4 +29,13 @@
<item name="android:textColor">@color/accent</item> <item name="android:textColor">@color/accent</item>
</style> </style>
<style name="AppTheme.PopupOverlay.Light" parent="ThemeOverlay.AppCompat.Light">
<item name="android:colorBackground">@color/white</item>
<item name="android:textColor">@color/black</item>
</style>
<style name="AppTheme.PopupOverlay.Dark" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:colorBackground">@color/black</item>
<item name="android:textColor">@color/white</item>
</style>
</resources> </resources>