1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-12-22 10:58:01 +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

@ -6,9 +6,9 @@ ext {
minSdk : 17,
]
version_lib = [
appcompat: "27.0.0",
appcompat : "27.0.0",
butterknife: "8.8.1",
netcipher: "2.0.0-alpha1",
netcipher : "2.0.0-alpha1",
]
}
@ -22,9 +22,7 @@ android {
targetSdkVersion version_sdk.compileSdk
buildConfigField "boolean", "IS_TEST_BUILD", "false"
buildConfigField "boolean", "IS_GPLAY_BUILD", "false"
buildConfigField("String[]", "APPLICATION_LANGUAGES", '{' + getUsedAndroidLanguages().collect {
"\"${it}\""
}.join(",") + '}')
buildConfigField("String[]", "APPLICATION_LANGUAGES", '{' + getUsedAndroidLanguages().collect {"\"${it}\""}.join(",") + '}')
buildConfigField "String", "GITHASH", "\"${getGitHash()}\""
applicationId "com.github.dfa.diaspora_android"
@ -52,7 +50,9 @@ android {
productFlavors {
flavorDefault {
}
/*flavorGplay {
/*
flavorGplay {
buildConfigField "boolean", "IS_GPLAY_BUILD", "true"
}*/
flavorTest {

View file

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

View file

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

View file

@ -30,6 +30,7 @@ import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.view.Menu;
import android.view.MenuInflater;
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.ui.theme.ThemedAlertDialogBuilder;
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.DiasporaUrlHelper;
import com.github.dfa.diaspora_android.web.BrowserFragment;
@ -92,13 +94,12 @@ public class DiasporaStreamFragment extends BrowserFragment {
}
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.stream__menu_top, menu);
super.onCreateOptionsMenu(menu, inflater);
}
inflater.inflate(R.menu.stream__menu_top, menu);
@Override
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.stream__menu_bottom, menu);
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

View file

@ -37,13 +37,13 @@ import android.support.design.widget.AppBarLayout;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
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 java.io.IOException;
import java.lang.reflect.Method;
import butterknife.BindView;
import butterknife.ButterKnife;
@ -138,9 +139,6 @@ public class MainActivity extends ThemedActivity
@BindView(R.id.main__topbar)
Toolbar toolbarTop;
@BindView(R.id.main__bottombar)
ActionMenuView toolbarBottom;
@BindView(R.id.fragment_container)
FrameLayout fragmentContainer;
@ -178,6 +176,7 @@ public class MainActivity extends ThemedActivity
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
// Bind UI
setContentView(R.layout.main__activity);
ButterKnife.bind(this);
@ -267,12 +266,6 @@ public class MainActivity extends ThemedActivity
if (actionBar != null) {
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);
//Setup snackbar
@ -683,22 +676,23 @@ public class MainActivity extends ThemedActivity
//Clear the menus
menu.clear();
toolbarBottom.getMenu().clear();
toolbarBottom.setVisibility(View.VISIBLE);
CustomFragment top = getTopFragment();
if (top != null) {
//PodSelectionFragment?
if (top.getFragmentTag().equals(PodSelectionFragment.TAG)) {
///Hide bottom _toolbar
toolbarBottom.setVisibility(View.GONE);
} else {
cache = _appSettings.isExtendedNotificationsActivated();
getMenuInflater().inflate(R.menu.main__menu_top, menu);
menu.findItem(R.id.action_notifications).setVisible(!cache);
menu.findItem(R.id.action_notifications_extended).setVisible(cache);
}
boolean isPodSel = top.getFragmentTag().equals(PodSelectionFragment.TAG);
// Extended notifications
cache = _appSettings.isExtendedNotificationsActivated();
getMenuInflater().inflate(R.menu.main__menu_top, menu);
menu.findItem(R.id.action_notifications).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;
}
@ -1213,7 +1207,6 @@ public class MainActivity extends ThemedActivity
@Override
protected void applyColorToViews() {
ThemeHelper.updateToolbarColor(toolbarTop);
ThemeHelper.updateActionMenuViewColor(toolbarBottom);
navDrawerLayout.setBackgroundColor(_appSettings.getPrimaryColor());
navProfilePictureArea.setBackgroundColor(_appSettings.getPrimaryColor());
if (_appSettings.isAmoledColorMode()) {
@ -1223,6 +1216,10 @@ public class MainActivity extends ThemedActivity
navheaderTitle.setTextColor(Color.GRAY);
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

View file

@ -28,6 +28,7 @@ import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.MenuItemCompat;
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.setDividerHeight(dividerHeight);
if (appSettings.isAmoledColorMode()) {
buttonUseCustomPod.setSupportBackgroundTintList(ColorStateList.valueOf(Color.DKGRAY));
buttonUseCustomPod.setTextColor(Color.WHITE);
} else {
buttonUseCustomPod.setSupportBackgroundTintList(ColorStateList.valueOf(appSettings.getAccentColor()));
buttonUseCustomPod.setTextColor(ContextUtils.get().shouldColorOnTopBeLight(appSettings.getAccentColor()) ? Color.WHITE : Color.BLACK);
}
}
@ -235,6 +234,7 @@ public class PodSelectionFragment extends ThemedFragment implements SearchView.O
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.podselection__menu, menu);
MenuItem searchItem = menu.findItem(R.id.podselection__action_search);
@ -243,7 +243,8 @@ public class PodSelectionFragment extends ThemedFragment implements SearchView.O
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
@ -299,11 +300,6 @@ public class PodSelectionFragment extends ThemedFragment implements SearchView.O
/*
* Dummy implementations
*/
@Override
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
}
@Override
public boolean onQueryTextSubmit(String query) {
return false;

View file

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

View file

@ -50,14 +50,6 @@ public abstract class CustomFragment extends Fragment {
*/
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.
* 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;
}
@Override
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
/* Nothing to do here */
}
@Override
public void onAttach(Context context) {
super.onAttach(context);

View file

@ -29,6 +29,7 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
@ -37,6 +38,7 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
@ -52,7 +54,10 @@ import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
@ -65,11 +70,12 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.util.Locale;
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 {
//########################
//## 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
public boolean shouldColorOnTopBeLight(int colorOnBottomInt) {
public boolean shouldColorOnTopBeLight(@ColorInt int colorOnBottomInt) {
return 186 > (((0.299 * Color.red(colorOnBottomInt))
+ ((0.587 * Color.green(colorOnBottomInt))
+ (0.114 * Color.blue(colorOnBottomInt)))));
@ -510,4 +516,32 @@ public class ContextUtils {
}
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"
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>

View file

@ -4,29 +4,5 @@
xmlns:tools="http://schemas.android.com/tools"
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>

View file

@ -1,10 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
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
android:id="@+id/action_reload"
android:icon="@drawable/ic_refresh_white_48px"
android:orderInCategory="1000"
android:title="@string/reload"
app:showAsAction="always" />
app:showAsAction="never" />
</menu>

View file

@ -29,4 +29,13 @@
<item name="android:textColor">@color/accent</item>
</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>