package com.sunvote.xpadapp.fragments; import android.annotation.SuppressLint; import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; import android.os.Build; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.annotation.RequiresApi; import android.support.v4.content.ContextCompat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.sunvote.xpadapp.R; import com.sunvote.xpadapp.base.BaseFragment; import com.sunvote.xpadcomm.XPadApiInterface; /** * 二维表主页 * Created by wutaian on 2017/5/25. */ @SuppressLint("ValidFragment") public class TableMainFragment extends BaseFragment { //界面 private View view; //当前评分,历史评分 private TextView tv_current_score,tv_history_score; //当前评分下划线,历史评分下划线 private View current_score_view,history_score_view; //投票信标信息 private XPadApiInterface.VoteInfo voteInfo; public TableScoreFragment tableScoreFragment ; public TableMainFragment(XPadApiInterface.VoteInfo mVoteInfo){ voteInfo=mVoteInfo; } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view=inflater.inflate(R.layout.fragment_menu_main,container,false); initView(); return view; } @Override public void onResume() { super.onResume(); } private void initView(){ tv_current_score =(TextView)view.findViewById(R.id.tv_current_score); tv_history_score =(TextView)view.findViewById(R.id.tv_history_score); current_score_view=view.findViewById(R.id.current_view); history_score_view=view.findViewById(R.id.history_view); tv_history_score.setOnClickListener(handler); tv_current_score.setOnClickListener(handler); tv_history_score.setEnabled(false); tableScoreFragment = new TableScoreFragment(voteInfo); replaceFragment(tableScoreFragment); } View.OnClickListener handler = new View.OnClickListener(){ @SuppressLint("ResourceAsColor") @RequiresApi(api = Build.VERSION_CODES.M) @Override public void onClick(View v) { //clearSelection(); switch (v.getId()) { case R.id.tv_current_score: tv_history_score.setEnabled(false); replaceFragment(new TableScoreFragment(voteInfo)); current_score_view.setVisibility(View.VISIBLE); tv_current_score.setTextColor(ContextCompat.getColor(getActivity(),R.color.colorGreen)); break; case R.id.tv_history_score: //replaceFragment(new Fragment()); history_score_view.setVisibility(View.VISIBLE); tv_history_score.setTextColor(ContextCompat.getColor(getActivity(),R.color.colorGreen)); break; } } }; /** * 清除掉所有的选中状态。 */ private void clearSelection() { current_score_view.setVisibility(View.INVISIBLE); tv_current_score.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorTextGrey)); history_score_view.setVisibility(View.INVISIBLE); tv_history_score.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorTextGrey)); } /** * 切换fragment界面 * @param fragment */ private void replaceFragment(Fragment fragment){ FragmentManager fragmentManager= getFragmentManager(); FragmentTransaction transaction=fragmentManager.beginTransaction(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); transaction.replace(R.id.single_item_layout,fragment); // mMainActivity.currFragment= (BaseFragment) fragment; transaction.commit(); } @Override public void onVoteSubmitAllOkSuccess() { super.onVoteSubmitAllOkSuccess(); if(tableScoreFragment != null){ tableScoreFragment.onVoteSubmitAllOkSuccess(); } } }