效果图:
主activity:
public class TabActivity extends TutorialActivity implements
RCBottomTabMenu.OnTabClickListener, IAnimationDelegate,
RCBaseTitleBar.HeaderClickListener {
private int mCurrentFragment = 0;
RCBottomTabMenu mRcBottomTabMenu;
RCBottomPopMenu mRCBottomPopMenu;
private List<RCTabItem> mRCTabArray;
private View mCoverView;
public static void startActivity(Context context) {
Intent intent = new Intent();
intent.setClass(context,TabActivity.class);
context.startActivity(intent);
}
public static enum MainActivities {
Ringout {
@Override
public String toString() {
return "Ringout";
}
},
Messages {
@Override
public String toString() {
return "Messages";
}
},
Calllog {
@Override
public String toString() {
return "CallLog";
}
},
Contacts {
@Override
public String toString() {
return "Contacts";
}
},
Text {
@Override
public String toString() {
return "Text";
}
},
Favorites {
@Override
public String toString() {
return "Favorites";
}
},
Fax {
@Override
public String toString() {
return "Fax";
}
},
Conferencing {
@Override
public String toString() {
return "Conferencing";
}
},
Meetings {
@Override
public String toString() {
return "Meetings";
}
},
RCDocuments {
@Override
public String toString() {
return "RCDocuments";
}
}
}
private ArrayList<DropDownItem> getTopMenuListData() {
ArrayList<DropDownItem> mTopMenuList = new ArrayList<DropDownItem>();
mTopMenuList.add(new DropDownItem(this.getResources().getString(
R.string.message_all), RCTitleBarWithDropDownFilter.STATE_ALL,
0));
mTopMenuList.add(new DropDownItem(this.getResources().getString(
R.string.message_voice),
RCTitleBarWithDropDownFilter.STATE_VOICE, 0));
mTopMenuList.add(new DropDownItem(this.getResources().getString(
R.string.message_fax), RCTitleBarWithDropDownFilter.STATE_FAX,
0));
mTopMenuList.add(new DropDownItem(this.getResources().getString(
R.string.message_text),
RCTitleBarWithDropDownFilter.STATE_TEXT, 0));
return mTopMenuList;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.tab_activity_main);
final RCTitleBarWithDropDownFilter mainTitleBar = (RCTitleBarWithDropDownFilter) findViewById(R.id.header);
mainTitleBar.setDropDownItemList(getTopMenuListData());
mainTitleBar.setOnDropDownMenuClick(new DropDownMenuClicked() {
@Override
public void onDropDownMenuClicked(int index) {
mainTitleBar.initMessageFilterWithState(index);
}
});
mainTitleBar.setText(R.string.message_all);
mainTitleBar.setButtonsClickCallback(this);
mRCTabArray = updateMenuDataList();
mRcBottomTabMenu = (RCBottomTabMenu) findViewById(R.id.rcBottomTabBar);
mRcBottomTabMenu.setOnTabClickListener(this);
mRcBottomTabMenu.addTabs(this, mRCTabArray);
mRCBottomPopMenu = (RCBottomPopMenu) findViewById(R.id.rcBottomPopWidget);
mRCBottomPopMenu.setOnTabClickListener(this);
mRCBottomPopMenu.setAnimationDelegate(this);
mRCBottomPopMenu.addTabs(this, mRCTabArray);
mCoverView = findViewById(R.id.cover_view);
mCoverView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
popDownWidget(0, false);
}
return true;
}
});
}
private void popDownWidget(final int tab, final boolean isSwitch) {
mRCBottomPopMenu.closeWithAnimation(tab, isSwitch);
}
private List<RCTabItem> updateMenuDataList() {
List<RCTabItem> tabItems = new ArrayList<RCTabItem>();
tabItems.add(new RCTabItem(MainActivities.Ringout.toString(),
MainActivities.Ringout.ordinal(),
R.drawable.launch_bar_button_foreground_call,
R.string.menu_list_dialpad));
tabItems.add(new RCTabItem(MainActivities.Messages.toString(),
MainActivities.Messages.ordinal(),
R.drawable.launch_bar_button_foreground_message,
R.string.menu_list_messages));
tabItems.add(new RCTabItem(MainActivities.Calllog.toString(),
MainActivities.Calllog.ordinal(),
R.drawable.launch_bar_button_foreground_call_log,
R.string.menu_list_recents));
tabItems.add(new RCTabItem(MainActivities.Contacts.toString(),
MainActivities.Contacts.ordinal(),
R.drawable.launch_bar_button_foreground_contact,
R.string.menu_list_contact));
tabItems.add(new RCTabItem(
MainActivities.Text.toString(),
MainActivities.Text.ordinal(),
tabItems.size() >= 4 ? R.drawable.widget_bar_button_foreground_sms
: R.drawable.launch_bar_button_foreground_sms,
R.string.menu_list_sms));
tabItems.add(new RCTabItem(
MainActivities.Favorites.toString(),
MainActivities.Favorites.ordinal(),
tabItems.size() >= 4 ? R.drawable.widget_bar_button_foreground_favorite
: R.drawable.launch_bar_button_foreground_favorite,
R.string.menu_list_favorites));
tabItems.add(new RCTabItem(MainActivities.Fax.toString(),
MainActivities.Fax.ordinal(),
R.drawable.widget_bar_button_foreground_fax,
R.string.menu_list_fax));
tabItems.add(new RCTabItem(MainActivities.Conferencing.toString(),
MainActivities.Conferencing.ordinal(),
R.drawable.widget_bar_button_foreground_conf,
R.string.menu_list_conference));
tabItems.add(new RCTabItem(MainActivities.Meetings.toString(),
MainActivities.Meetings.ordinal(),
R.drawable.widget_bar_button_foreground_meeting,
R.string.tab_name_zoom_video));
tabItems.add(new RCTabItem(MainActivities.RCDocuments.toString(),
MainActivities.RCDocuments.ordinal(),
R.drawable.widget_bar_button_foreground_document,
R.string.menu_list_documents));
return tabItems;
}
@Override
public void onTabClick(int tab) {
if (mRCBottomPopMenu.isShowing()) {
popDownWidget(tab, mCurrentFragment != tab);
} else if (mCurrentFragment != tab) {
setCurrentTab(tab);
}
}
private void setCurrentTab(int tab) {
boolean previous = isSelectItemInPopWidget(mCurrentFragment);
boolean current = isSelectItemInPopWidget(tab);
if (previous && current) {
mRCBottomPopMenu.setItemSelectedState(tab);
} else if (!previous && !current) {
mRcBottomTabMenu.setItemSelectedState(tab);
} else {
mRcBottomTabMenu.setItemSelectedState(tab);
mRCBottomPopMenu.setItemSelectedState(tab);
}
mCurrentFragment = tab;
// setContainer(tab);
}
@Override
public void onPlusClick(boolean isFromMenu) {
if (mRCBottomPopMenu.isShowing()) {
popDownWidget(0, false);
} else {
if (isSelectItemInPopWidget(0)) {
mRCBottomPopMenu.setItemSelectedState(0);
}
popUpWidget();
}
}
private boolean isSelectItemInPopWidget(int tab) {
return tab > mRCTabArray.get(3).getItemId();
}
private void popUpWidget() {
mRCBottomPopMenu.openWithAnimation();
}
@Override
public void onAnimationStart(boolean isToUp) {
if (isToUp) {
mRcBottomTabMenu.rotatePlusButton(this, true);
mCoverView.startAnimation(AnimationUtils.loadAnimation(this,
R.anim.cover_show));
} else {
mRcBottomTabMenu.rotatePlusButton(this, false);
mCoverView.startAnimation(AnimationUtils.loadAnimation(this,
R.anim.cover_dismiss));
}
}
@Override
public void onAnimationEnd(int tab, boolean isSwitch, boolean isToUp) {
if (isToUp) {
mCoverView.setVisibility(View.VISIBLE);
} else {
if (isSwitch) {
// setCurrentTab(tab);
}
mCoverView.setVisibility(View.GONE);
}
}
@Override
public void onRightButtonClicked() {
}
@Override
public void onLeftButtonClicked() {
}
@Override
public void onDropDownFilterClicked() {
}
private void saveFile(String str) {
String fileName = Environment.getExternalStorageDirectory() + "/"
+ "log.txt";
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(fileName));
writer.write(str);
writer.flush();
} catch (IOException ex) {
System.out.println("=====ex="+ex);
} finally {
try {
writer.close();
} catch (IOException ex) {
}
}
}
}xml:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:rcm="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/bgColorMain" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" > <com.ringcentral.android.utils.ui.menu.RCTitleBarWithDropDownFilter android:id="@+id/header" android:layout_width="fill_parent" android:layout_height="@dimen/header_hight" android:background="@color/bgTitleBar" rcm:title_has_dropdown="true" rcm:title_text="@string/messages_bar_item_all" /> <View android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@id/header" android:background="#cc6633" /> </RelativeLayout> <View android:id="@+id/cover_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="@dimen/fragment_margin_bottom" android:background="#7f000000" android:visibility="gone" /> <com.ringcentral.android.utils.ui.menu.RCBottomPopMenu android:id="@+id/rcBottomPopWidget" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:layout_marginBottom="@dimen/fragment_margin_bottom" android:visibility="gone" /> <com.ringcentral.android.utils.ui.menu.RCBottomTabMenu android:id="@+id/rcBottomTabBar" android:layout_width="fill_parent" android:layout_height="@dimen/launch_bar_height" android:layout_gravity="bottom" android:orientation="horizontal" /> </FrameLayout>
buttomTabMenu的代码:
public class RCBottomTabMenu extends RCBottomMenu {
private static final String TAG = "RCBottomTabMenu";
private static final int SPLIT_INDEX = 1;
private LinearLayout mLeftLayout;
private LinearLayout mRightLayout;
private ImageView mPlusBtn;
private int mPadding = 0;
private RCTabView mMessageItem;
private OnTabClickListener mOnTabClickListener;
public RCBottomTabMenu(Context context) {
super(context);
init(context);
}
public RCBottomTabMenu(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public void setOnTabClickListener(OnTabClickListener listener) {
mOnTabClickListener = listener;
}
private void init(Context context) {
LayoutInflater.from(context).inflate(R.layout.ringcentral_bottom, this);
this.setBackgroundColor(getResources().getColor(
R.color.transparentColor));
mPadding = context.getResources().getDimensionPixelSize(
R.dimen.tab_item_padding);
mPlusBtn = (ImageView) findViewById(R.id.btn_plus);
View plusLayout = findViewById(R.id.layout_plus);
plusLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mOnTabClickListener.onPlusClick(false);
}
});
}
public void rotatePlusButton(Context context, boolean isUp) {
AnimatorSet animatorSet = (AnimatorSet) AnimatorInflater.loadAnimator(
context, isUp ? R.anim.flip_down : R.anim.flip_up);
animatorSet.setTarget(mPlusBtn);
animatorSet.start();
}
public void addTabs(Context context, List<RCTabItem> list) {
mLeftLayout = (LinearLayout) findViewById(R.id.left_layout);
mRightLayout = (LinearLayout) findViewById(R.id.right_layout);
mLeftLayout.removeAllViews();
mRightLayout.removeAllViews();
addMobileTabs(context, list);
}
private final OnClickListener mTabClickListener = new OnClickListener() {
public void onClick(View view) {
final int newSelected = ((RCTabView)view).getPosition();
mOnTabClickListener.onTabClick(newSelected);
}
};
private void addMobileTabs(Context context, List<RCTabItem> list) {
for (int i = 0; i < BOTTOM_MENU_TAB_SUM; i++) {
RCTabItem tabItem = list.get(i);
RCTabView view = new RCTabView(context, tabItem.getItemId());
view.setOnClickListener(mTabClickListener);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,
ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
params.gravity = CENTER_IN_PARENT;
view.setLayoutParams(params);
TextView textView = (TextView) view
.findViewById(R.id.tab_main_text);
textView.setText(tabItem.getItemText());
Drawable drawable = context.getResources().getDrawable(
tabItem.getItemIcon());
if (drawable != null) {
drawable.setBounds(0, 0, drawable.getMinimumWidth(),
drawable.getMinimumHeight());
}
textView.setCompoundDrawables(null, drawable, null, null);
if (i <= SPLIT_INDEX) {
mLeftLayout.addView(view);
} else {
mRightLayout.addView(view);
}
}
}
public void setItemSelectedState(int selectedItem) {
final int leftCount = mLeftLayout.getChildCount();
for (int i = 0; i < leftCount; i++) {
final RCTabView tabItem = (RCTabView) mLeftLayout.getChildAt(i);
if (selectedItem != tabItem.getPosition()) {
tabItem.changeSelectedState(false);
} else {
tabItem.changeSelectedState(true);
}
}
final int rightCount = leftCount + mRightLayout.getChildCount();
for (int i = leftCount; i < rightCount; i++) {
final RCTabView tabItem = (RCTabView) mRightLayout.getChildAt(i
- leftCount);
if (selectedItem != tabItem.getPosition()) {
tabItem.changeSelectedState(false);
} else {
tabItem.changeSelectedState(true);
}
}
}
}public class RCBottomMenu extends RelativeLayout {
protected static final int BOTTOM_MENU_TAB_SUM = 4;
public RCBottomMenu(Context context) {
super(context);
}
public RCBottomMenu(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void onUpdateIndicator() {}
public interface OnTabClickListener {
void onTabClick(int tab);
void onPlusClick(boolean isFromMenu);
}
}animation的xml:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <alpha android:toAlpha="1.0" android:fromAlpha="0.0" android:duration="150"/> </set>