Skip to content

Commit

Permalink
Merge branch 'wtw-software-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
roughike committed Mar 17, 2016
2 parents 9f16fe4 + 3a02931 commit 58308ad
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 42 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
.gradle
/local.properties
/.idea/workspace.xml
/.idea/tasks.xml
/.idea/libraries
.idea
.DS_Store
/build
/captures
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="bottom_bar_elevation">8dp</dimen>
</resources>
67 changes: 29 additions & 38 deletions bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.graphics.PorterDuff;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.IdRes;
Expand All @@ -17,7 +16,6 @@
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

Expand All @@ -41,14 +39,13 @@ public class BottomBar extends FrameLayout implements View.OnClickListener, View
private static final long ANIMATION_DURATION = 150;
private static final int MAX_FIXED_TAB_COUNT = 3;

private static final String STATE_CURRENT_SELECTED_TAB = "com.roughike.bottombar.STATE_CURRENT_SELECTED_TAB";
private static final String STATE_CURRENT_SELECTED_TAB = "STATE_CURRENT_SELECTED_TAB";
private static final String TAG_BOTTOM_BAR_VIEW_INACTIVE = "BOTTOM_BAR_VIEW_INACTIVE";
private static final String TAG_BOTTOM_BAR_VIEW_ACTIVE = "BOTTOM_BAR_VIEW_ACTIVE";

private Context mContext;
private boolean mIsTabletMode;

private RelativeLayout mRootView;
private FrameLayout mUserContentContainer;
private LinearLayout mItemContainer;

Expand All @@ -72,33 +69,27 @@ public class BottomBar extends FrameLayout implements View.OnClickListener, View
private BottomBarItemBase[] mItems;

public BottomBar(Context context) {
super(context);
init(context, null, 0, 0);
this(context, null, 0, 0);
}

public BottomBar(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0, 0);
this(context, attrs, 0, 0);
}

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public BottomBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr, 0);
this(context, attrs, defStyleAttr, 0);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public BottomBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs, defStyleAttr, defStyleRes);
}

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
mContext = context;

mPrimaryColor = MiscUtils.getColor(mContext, R.attr.colorPrimary);
mInActiveColor = ContextCompat.getColor(mContext, R.color.bb_inActiveBottomBarItemColor);
mWhiteColor = ContextCompat.getColor(mContext, R.color.white);
mPrimaryColor = MiscUtils.getColor(getContext(), R.attr.colorPrimary);
mInActiveColor = ContextCompat.getColor(getContext(), R.color.bb_inActiveBottomBarItemColor);
mWhiteColor = ContextCompat.getColor(getContext(), R.color.white);

mScreenWidth = MiscUtils.getScreenWidth(mContext);
mTwoDp = MiscUtils.dpToPixel(mContext, 2);
Expand All @@ -109,18 +100,17 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr, int def
}

private void initializeViews() {
ViewGroup.LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
ViewGroup.LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
setLayoutParams(params);

mRootView = (RelativeLayout) View.inflate(mContext,
View rootView = View.inflate(mContext,
R.layout.bb_bottom_bar_item_container, null);

mIsTabletMode = mRootView.findViewById(R.id.bb_tablet_right_border) != null;
mUserContentContainer = (FrameLayout) mRootView.findViewById(R.id.bb_user_content_container);
mItemContainer = (LinearLayout) mRootView.findViewById(R.id.bb_bottom_bar_item_container);
mIsTabletMode = rootView.findViewById(R.id.bb_tablet_right_border) != null;
mUserContentContainer = (FrameLayout) rootView.findViewById(R.id.bb_user_content_container);
mItemContainer = (LinearLayout) rootView.findViewById(R.id.bb_bottom_bar_item_container);

addView(mRootView, params);
addView(rootView, params);
}

protected FrameLayout getUserContainer() {
Expand Down Expand Up @@ -224,7 +214,7 @@ public void setItems(BottomBarTab... bottomBarTabs) {
*/
public void setItemsFromMenu(@MenuRes int menuRes, OnMenuTabSelectedListener listener) {
clearItems();
mItems = MiscUtils.inflateMenuFromResource((Activity) mContext, menuRes);
mItems = MiscUtils.inflateMenuFromResource((Activity) getContext(), menuRes);
mMenuListener = listener;
updateItems(mItems);
}
Expand Down Expand Up @@ -265,24 +255,25 @@ public void onSaveInstanceState(Bundle outState) {
@Override
public void onClick(View v) {
if (v.getTag().equals(TAG_BOTTOM_BAR_VIEW_INACTIVE)) {
unselectTab((ViewGroup) findViewWithTag(TAG_BOTTOM_BAR_VIEW_ACTIVE), true);
selectTab((ViewGroup) v, true);

int newPosition = findItemPosition(v);
unselectTab(findViewWithTag(TAG_BOTTOM_BAR_VIEW_ACTIVE), true);
selectTab(v, true);
updateSelectedTab(findItemPosition(v));
}
}

if (newPosition != mCurrentTabPosition) {
mCurrentTabPosition = newPosition;
private void updateSelectedTab(int newPosition) {
if (newPosition != mCurrentTabPosition) {
mCurrentTabPosition = newPosition;

if (mListener != null) {
mListener.onItemSelected(mCurrentTabPosition);
}

if (mMenuListener != null && mItems instanceof BottomBarTab[]) {
mMenuListener.onMenuItemSelected(((BottomBarTab) mItems[mCurrentTabPosition]).id);
}
if (mListener != null) {
mListener.onItemSelected(mCurrentTabPosition);
}

updateCurrentFragment();
if (mMenuListener != null && mItems instanceof BottomBarTab[]) {
mMenuListener.onMenuItemSelected(((BottomBarTab) mItems[mCurrentTabPosition]).id);
}

updateCurrentFragment();
}
}

Expand Down
2 changes: 1 addition & 1 deletion bottom-bar/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="bb_inActiveBottomBarItemColor">#909090</color>
<color name="bb_inActiveBottomBarItemColor">#747474</color>
<color name="white">#FFFFFF</color>
</resources>

0 comments on commit 58308ad

Please sign in to comment.