Blame view

app/src/main/java/com/sunvote/xpadapp/fragments/TableMainFragment.java 4.21 KB
27983dbe   孙向锦   project init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
  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();
          }
      }
  }