[lottery] 08_底部导航管理-布局

Android 4.0

底部导航管理

底部导航分类
1、通用导航
2、玩法导航
功能描述:
①管理对象的创建
②初始化各个导航容器及相关控件设置监听
③控制各个导航容器的显示和隐藏
④控制玩法导航内容显示
功能实现:
在MainActivity中调用BottomNavigatorManager创建实例,并进行初始化。
1、布局文件:
<?xml version="1.0" encoding="utf-8"?>
<!-- 底部导航 -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rl_main_buttom_navigator"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    <!-- 1、通用导航 -->
    <LinearLayout
        android:id="@+id/ll_common_buttom_navigator_zl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:visibility="visible" >
        <ImageButton
            android:id="@+id/ib_bottom_home_zl"
            android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:background="@drawable/id_buttom_bg"
            android:clickable="true"
            android:focusable="true"
            android:src="@drawable/id_lottery_home"
            tools:ignore="ContentDescription" />
        <ImageButton
            android:id="@+id/ib_bottom_lottery_hall_zl"
            android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:background="@drawable/id_buttom_bg"
            android:clickable="true"
            android:focusable="true"
            android:src="@drawable/id_lottery_hall"
            tools:ignore="ContentDescription" />
        <ImageButton
            android:id="@+id/ib_bottom_recharge_zl"
            android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:background="@drawable/id_buttom_bg"
            android:clickable="true"
            android:focusable="true"
            android:src="@drawable/id_lottery_recharge"
            tools:ignore="ContentDescription" />
        <ImageButton
            android:id="@+id/ib_bottom_lottery_myself_zl"
            android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:background="@drawable/id_buttom_bg"
            android:clickable="true"
            android:focusable="true"
            android:gravity="center"
            android:src="@drawable/id_lottery_myself"
            tools:ignore="ContentDescription" />
    </LinearLayout>
    <!-- 购彩 -->
    <LinearLayout
        android:id="@+id/ll_game_bottom_zl"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/id_buttom_menu_bg"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:visibility="invisible" >
        <ImageButton
            android:id="@+id/ib_game_choose_clean_zl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dip"
            android:background="@drawable/id_clear_choose"
            tools:ignore="ContentDescription" />
        <TextView
            android:id="@+id/tv_game_choose_notice_zl"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:gravity="center_vertical|center_horizontal"
            android:text="@string/is_ssq_default_notice"
            android:textColor="@android:color/white"
            android:textSize="15sp" />
        <ImageButton
            android:id="@+id/ib_game_choose_ok_zl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dip"
            android:background="@drawable/id_choose_ok"
            tools:ignore="ContentDescription" />
    </LinearLayout>
</RelativeLayout>
2、管理类工具BottomNavigatorManager.java
package cn.zengfansheng.lottery.view.manager;

import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import cn.zengfansheng.lottery.R;
import cn.zengfansheng.lottery.util.LogUtil;

/**
 * 底部菜单导航管理类
 * 
 * @author hacket
 */

public class BottomNavigatorManager {

    protected static final String TAG = "BottomNavigatorManager";
    /********** 底部菜单容器 **********/
    private RelativeLayout bottomMenuContainer;

    /************ 底部导航 ************/
    private LinearLayout commonBottom;
    private LinearLayout playBottom;

    /***************** 导航按钮 ******************/

    /************ 1、通用导航底部按钮 ************/
    private ImageButton ibHomeButton;
    private ImageButton ibHallButton;
    private ImageButton ibRechargeButton;
    private ImageButton ivMyselfButton;

    /************ 2、购彩导航底部按钮及提示信息 ************/
    private ImageButton ivCleanButton;
    private ImageButton ivAddButton;

    private TextView tvPlayBottomNotice;

    /******************* 快速完成一个单例 **********************/
    // 构造私有
    private BottomNavigatorManager() {}

    // 创建一个静态实例
    private static BottomNavigatorManager instrance;

    // 提供统一的对外获取实例的入口
    public static BottomNavigatorManager getBottomNavigatorManagerInstance() {
        if (instrance == null) {
            instrance = new BottomNavigatorManager();
        }
        return instrance;
    }

    /**
     * 1、初始化组件
     * 
     * @param activity
     */

    public void initComponent(Activity activity) {

        /************ 1、底部导航管理容器 ************/
        bottomMenuContainer = (RelativeLayout) activity.findViewById(R.id.in_main_bottom_navitor);

        commonBottom = (LinearLayout) activity.findViewById(R.id.ll_common_buttom_navigator_zl);
        playBottom = (LinearLayout) activity.findViewById(R.id.ll_game_bottom_zl);
       
        /************ 2、通用导航底部按钮 ************/
        ibHomeButton = (ImageButton) activity.findViewById(R.id.ib_bottom_home_zl);
        ibHallButton = (ImageButton) activity.findViewById(R.id.ib_bottom_lottery_hall_zl);
        ibRechargeButton = (ImageButton) activity.findViewById(R.id.ib_bottom_recharge_zl);
        ivMyselfButton =(ImageButton) activity.findViewById(R.id.ib_bottom_lottery_myself_zl);
       
        /************ 3、购彩导航底部按钮及提示信息 ************/
        tvPlayBottomNotice = (TextView) activity.findViewById(R.id.tv_game_choose_notice_zl);
        ivCleanButton = (ImageButton) activity.findViewById(R.id.ib_game_choose_clean_zl);
        ivAddButton = (ImageButton) activity.findViewById(R.id.ib_game_choose_ok_zl);

    }

    public void setBtnListener() {

        /************ 2、通用导航底部按钮 ************/
        ibHomeButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                LogUtil.i(TAG, "Home首页按钮~~~");
            }
        });
        ibHallButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                LogUtil.i(TAG, "Hall购彩大厅按钮~~~");
            }
        });
        ibRechargeButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                LogUtil.i(TAG, "Recharge充值中心按钮~~~");
            }
        });
        ivMyselfButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                LogUtil.i(TAG, "Myself我的彩票按钮~~~");
            }
        });

        /************ 3、购彩导航底部按钮及提示信息 ************/
        // 清空按钮
        ivCleanButton.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                LogUtil.i(TAG, "点击清空按钮");
                // BaseView currentView =
                // UiManager2.getInstance().getCurrentView();
                // if (currentView instanceof PlayGame) {
                // ((PlayGame) currentView).clearSelected();
                // }
            }
        });
        // 选好按钮
        ivAddButton.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                LogUtil.i(TAG, "点击选好按钮");
                // BaseView currentView =
                // UiManager2.getInstance().getCurrentView();
                // if (currentView instanceof PlayGame) {
                // ((PlayGame) currentView).addSelected2ShoppingList();
                // }

            }
        });
    }
   
    /**
     * 2、转换到通用导航
     */

    public void showCommonBottom() {
        if (bottomMenuContainer.getVisibility() == View.GONE
                || bottomMenuContainer.getVisibility() == View.INVISIBLE) {
            bottomMenuContainer.setVisibility(View.VISIBLE);
        }
        commonBottom.setVisibility(View.VISIBLE);
        playBottom.setVisibility(View.INVISIBLE);
    }

    /**
     * 3、转换到购彩
     */

    public void showGameBottom() {
        if (bottomMenuContainer.getVisibility() == View.GONE
                || bottomMenuContainer.getVisibility() == View.INVISIBLE) {
            bottomMenuContainer.setVisibility(View.VISIBLE);
        }
        commonBottom.setVisibility(View.INVISIBLE);
        playBottom.setVisibility(View.VISIBLE);
    }

    /**
     * 4、设置玩法底部提示信息
     * 
     * @param notice
     *            要设置的底部提示的信息
     */

    public void changeGameBottomNotice(String notice) {
        tvPlayBottomNotice.setText(notice);
    }

    /**
     * 5、改变底部导航容器显示情况
     * 
     * @param visibility
     *            所设置底部导航器显示的情况
     */

    public void changeBottomVisiblity(int visibility) {
        if (bottomMenuContainer.getVisibility() != visibility)
            bottomMenuContainer.setVisibility(visibility);
    }
}