package com.wangbb.naruto.app.fragment;
import android.os.Bundle;
import android.os.Message;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.wangbb.naruto.R;
import com.wangbb.naruto.app.activity.MainActivity;
import static com.wangbb.naruto.app.activity.MainActivity.HOME;
import static com.wangbb.naruto.app.activity.MainActivity.SETTING;
import static com.wangbb.naruto.app.activity.MainActivity.SWITCH_FRAGMENT;
import static com.wangbb.naruto.app.activity.MainActivity.TEMP;
/**
* Created by wangbinbin on 15/5/9.
*/
public class MainDrawerMenuFragment extends BaseFragment {
private View view;
private Button main;
private Button temp;
private Button setting;
private MainActivity mainActivity;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_main_drawermenu, container, false);
initView();
setListener();
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
this.mainActivity = (MainActivity) getActivity();
}
private void setListener() {
setting.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Message msg = Message.obtain();
msg.what = SWITCH_FRAGMENT;
msg.obj = SETTING;
mainActivity.handler.sendMessage(msg);
mainActivity.getDrawerLayout().closeDrawer(Gravity.START);
}
});
main.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Message msg = Message.obtain();
msg.what = SWITCH_FRAGMENT;
msg.obj = HOME;
mainActivity.handler.sendMessage(msg);
mainActivity.getDrawerLayout().closeDrawer(Gravity.START);
}
});
temp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Message msg = Message.obtain();
msg.what = SWITCH_FRAGMENT;
msg.obj = TEMP;
mainActivity.handler.sendMessage(msg);
mainActivity.getDrawerLayout().closeDrawer(Gravity.START);
}
});
}
private void initView() {
main = (Button) view.findViewById(R.id.menu_bt_main);
setting = (Button) view.findViewById(R.id.menu_bt_setting);
temp = (Button) view.findViewById(R.id.menu_bt_temp);
}
}