Skip to content

Commit

Permalink
Improve bottom navigation view
Browse files Browse the repository at this point in the history
Fix typos in javadocs.
  • Loading branch information
pranavpandey committed Jan 24, 2020
1 parent 4bc0ef1 commit 8abbb02
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 27 deletions.
Expand Up @@ -152,11 +152,11 @@ protected boolean isSupportActionBar() {
}

/**
* Retrieves a parcelable form the fragment arguments associated with the supplied key.
* Retrieves a parcelable from the fragment arguments associated with the supplied key.
*
* @param key The key to be retrieved.
*
* @return The parcelable form the fragment arguments.
* @return The parcelable from the fragment arguments.
*
* @see Fragment#getArguments()
*/
Expand All @@ -173,11 +173,11 @@ protected boolean isSupportActionBar() {
}

/**
* Retrieves a string form the fragment arguments associated with the supplied key.
* Retrieves a string from the fragment arguments associated with the supplied key.
*
* @param key The key to be retrieved.
*
* @return The string form the fragment arguments.
* @return The string from the fragment arguments.
*
* @see Fragment#getArguments()
*/
Expand Down
Expand Up @@ -346,7 +346,7 @@ public static synchronized DynamicTheme getInstance() {
}

/**
* Initialize colors form the supplied theme resource.
* Initialize colors from the supplied theme resource.
*
* @param theme The theme resource to initialize colors.
* @param initializeRemoteColors {@code true} to initialize remote colors also.
Expand Down Expand Up @@ -408,7 +408,7 @@ public static synchronized DynamicTheme getInstance() {
}

/**
* Initialize colors form the supplied dynamic app theme.
* Initialize colors from the supplied dynamic app theme.
*
* @param theme The dynamic app theme to initialize colors.
* @param initializeRemoteColors {@code true} to initialize remote colors also.
Expand All @@ -435,7 +435,7 @@ public static synchronized DynamicTheme getInstance() {
}

/**
* Initialize colors form the supplied local theme resource.
* Initialize colors from the supplied local theme resource.
*
* @param localTheme The local theme resource to initialize colors.
*
Expand Down Expand Up @@ -497,7 +497,7 @@ public static synchronized DynamicTheme getInstance() {
}

/**
* Initialize colors form the supplied local dynamic app theme.
* Initialize colors from the supplied local dynamic app theme.
*
* @param dynamicLocalTheme The local dynamic app theme to initialize colors.
*
Expand Down
Expand Up @@ -221,7 +221,7 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d
/**
* Show dialog to import the theme.
*
* @param file {@code true} to import form the file.
* @param file {@code true} to import from the file.
*
* @see DynamicThemeDialog
* @see DynamicThemeDialog.Type#THEME_IMPORT
Expand All @@ -247,7 +247,7 @@ public void onImportTheme(@NonNull String theme) {
* Try to import the supplied theme string.
*
* @param theme The theme string to be imported.
* @param file {@code true} if importing form the file.
* @param file {@code true} if importing from the file.
**/
protected void importTheme(@Nullable String theme, boolean file) {
if (theme == null || !DynamicThemeUtils.isValidTheme(theme)) {
Expand All @@ -270,7 +270,7 @@ protected void importTheme(@Nullable String theme, boolean file) {
/**
* Show dialog for the invalid theme.
*
* @param file {@code true} if imported form the file.
* @param file {@code true} if imported from the file.
*
* @see DynamicThemeDialog
* @see DynamicThemeDialog.Type#THEME_INVALID
Expand Down
Expand Up @@ -39,6 +39,8 @@
import androidx.appcompat.view.menu.MenuView;
import androidx.appcompat.widget.ActionMenuView;

import com.google.android.material.bottomnavigation.BottomNavigationItemView;
import com.google.android.material.bottomnavigation.BottomNavigationMenuView;
import com.pranavpandey.android.dynamic.support.widget.tooltip.DynamicTooltip;
import com.pranavpandey.android.dynamic.utils.DynamicDrawableUtils;
import com.pranavpandey.android.dynamic.utils.DynamicSdkUtils;
Expand Down Expand Up @@ -83,54 +85,58 @@ public static void forceMenuIcons(@Nullable Menu menu) {
*
* @param view The view to set its items color.
* @param color The tint color to be applied.
* @param background The background color for the tooltip.
* @param tint {@code true} to tint views according to the supplied parameters.
*/
@TargetApi(Build.VERSION_CODES.M)
@SuppressLint("RestrictedApi")
public static void setViewItemsTint(@NonNull final View view,
@ColorInt final int color, @ColorInt final int background) {
@ColorInt final int color, @ColorInt final int background, boolean tint) {
final PorterDuffColorFilter colorFilter
= new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);

if (view instanceof ViewGroup){
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++){
setViewItemsTint(((ViewGroup) view).getChildAt(i), color, background);
setViewItemsTint(((ViewGroup) view).getChildAt(i), color, background, tint);
}
}

if (view instanceof ImageButton) {
if (tint && view instanceof ImageButton) {
((ImageButton) view).getDrawable().setAlpha(255);
((ImageButton) view).getDrawable().setColorFilter(colorFilter);
DynamicTintUtils.setViewBackgroundTint(view, color, true);
}

if (view instanceof ImageView) {
((ImageView) view).getDrawable().setAlpha(255);
((ImageView) view).getDrawable().setColorFilter(colorFilter);
DynamicTintUtils.setViewBackgroundTint(view, color, true);
if (tint) {
((ImageView) view).getDrawable().setAlpha(255);
((ImageView) view).getDrawable().setColorFilter(colorFilter);
DynamicTintUtils.setViewBackgroundTint(view, color, true);
}

if (!TextUtils.isEmpty(view.getContentDescription())) {
DynamicTooltip.set(view, color, background, view.getContentDescription());
}
}

if (view instanceof AutoCompleteTextView) {
if (tint && view instanceof AutoCompleteTextView) {
((AutoCompleteTextView) view).setTextColor(color);
}

if (view instanceof TextView) {
if (tint && view instanceof TextView) {
((TextView) view).setTextColor(color);
DynamicTintUtils.setViewBackgroundTint(view, color, true);
}

if (view instanceof EditText) {
if (tint && view instanceof EditText) {
((EditText) view).setTextColor(color);
}

if (view instanceof ActionMenuView) {
for (int j = 0; j < ((ActionMenuView) view).getChildCount(); j++) {
final View innerView = ((ActionMenuView) view).getChildAt(j);

if (innerView instanceof ActionMenuItemView) {
if (tint && innerView instanceof ActionMenuItemView) {
final Drawable[] compoundDrawables =
((ActionMenuItemView) innerView).getCompoundDrawables();
if (DynamicSdkUtils.is23()) {
Expand All @@ -146,11 +152,43 @@ public static void setViewItemsTint(@NonNull final View view,
}

if (innerView instanceof MenuView.ItemView) {
DynamicTintUtils.setViewBackgroundTint(view, color, true);
if (tint) {
DynamicTintUtils.setViewBackgroundTint(view, color, true);
}

DynamicTooltip.set(innerView, color, background,
((MenuView.ItemView) innerView).getItemData().getTitle());
}
}
}

if (view instanceof BottomNavigationMenuView) {
for (int j = 0; j < ((BottomNavigationMenuView) view).getChildCount(); j++) {
final View innerView = ((BottomNavigationMenuView) view).getChildAt(j);

if (innerView instanceof BottomNavigationItemView) {
if (tint) {
DynamicTintUtils.setViewBackgroundTint(view, color, true);
}

DynamicTooltip.set(innerView, color, background,
((MenuView.ItemView) innerView).getItemData().getTitle());
}
}
}
}

/**
* Set other items color of this view according to the supplied values.
* <p>Generally, it should be a tint color so that items will be visible on this view
* background.
*
* @param view The view to set its items color.
* @param color The tint color to be applied.
* @param background The background color for the tooltip.
*/
public static void setViewItemsTint(@NonNull final View view,
@ColorInt final int color, @ColorInt final int background) {
setViewItemsTint(view, color, background, true);
}
}
Expand Up @@ -29,6 +29,7 @@
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.pranavpandey.android.dynamic.support.R;
import com.pranavpandey.android.dynamic.support.theme.DynamicTheme;
import com.pranavpandey.android.dynamic.support.utils.DynamicMenuUtils;
import com.pranavpandey.android.dynamic.support.utils.DynamicResourceUtils;
import com.pranavpandey.android.dynamic.support.widget.base.DynamicTextWidget;
import com.pranavpandey.android.dynamic.theme.Theme;
Expand Down Expand Up @@ -261,6 +262,14 @@ public void setEnabled(boolean enabled) {
setAlpha(enabled ? WidgetDefaults.ADS_ALPHA_ENABLED : WidgetDefaults.ADS_ALPHA_DISABLED);
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);

setColor();
setTextColor();
}

@Override
public void setColor() {
if (mColor != WidgetDefaults.ADS_COLOR_UNKNOWN) {
Expand All @@ -275,8 +284,8 @@ public void setTextColor() {
mTextColor = DynamicColorUtils.getContrastColor(mTextColor, mContrastWithColor);
}

@ColorInt int normalColor = DynamicColorUtils.adjustAlpha(mTextColor,
WidgetDefaults.ADS_ALPHA_UNCHECKED);
@ColorInt int normalColor = DynamicColorUtils.adjustAlpha(
DynamicColorUtils.getTintColor(mColor), WidgetDefaults.ADS_ALPHA_UNSELECTED);
setItemTextColor(DynamicResourceUtils.getColorStateList(
normalColor, mTextColor, true));
setItemIconTintList(DynamicResourceUtils.getColorStateList(
Expand All @@ -285,5 +294,7 @@ public void setTextColor() {
Color.TRANSPARENT, DynamicColorUtils.adjustAlpha(
mTextColor, WidgetDefaults.ADS_ALPHA_PRESSED), false));
}

DynamicMenuUtils.setViewItemsTint(this, mTextColor, mColor, false);
}
}
Expand Up @@ -75,6 +75,11 @@ public class WidgetDefaults {
*/
public static final float ADS_ALPHA_HINT = 0.8f;

/**
* Default alpha for the unselected state.
*/
public static final float ADS_ALPHA_UNSELECTED = 0.8f;

/**
* Default alpha value for the unselected state to generate color state list dynamically.
*/
Expand Down
Expand Up @@ -29,7 +29,6 @@ import com.pranavpandey.android.dynamic.support.sample.fragment.HomeFragment
import com.pranavpandey.android.dynamic.support.sample.fragment.SettingsFragment
import com.pranavpandey.android.dynamic.support.theme.DynamicTheme
import com.pranavpandey.android.dynamic.support.widget.DynamicBottomNavigationView
import com.pranavpandey.android.dynamic.utils.DynamicColorUtils
import com.pranavpandey.android.dynamic.utils.DynamicLinkUtils
import java.util.*

Expand Down Expand Up @@ -132,8 +131,7 @@ class BottomNavigationActivity : DynamicActivity() {
if (mBottomNavigationView != null) {
frameFooter!!.setBackgroundColor(mBottomNavigationView!!.color)
mBottomNavigationView!!.color = DynamicTheme.getInstance().get().primaryColor
mBottomNavigationView!!.textColor = DynamicColorUtils.getTintColor(
DynamicTheme.getInstance().get().primaryColor)
mBottomNavigationView!!.textColor = DynamicTheme.getInstance().get().accentColor
}
}

Expand Down

0 comments on commit 8abbb02

Please sign in to comment.