|
1 | 1 | package com.moos.progress;
|
2 | 2 |
|
| 3 | +import android.content.Intent; |
3 | 4 | import android.support.v4.app.Fragment;
|
4 | 5 | import android.support.v4.app.FragmentManager;
|
5 | 6 | import android.support.v4.app.FragmentTransaction;
|
|
11 | 12 | import android.widget.Button;
|
12 | 13 | import android.widget.CompoundButton;
|
13 | 14 | import android.widget.FrameLayout;
|
| 15 | +import android.widget.ImageView; |
14 | 16 | import android.widget.TextView;
|
15 | 17 | import android.widget.Toast;
|
16 | 18 |
|
17 | 19 | import com.moos.library.CircleProgressView;
|
| 20 | +import com.moos.library.HorizontalProgressView; |
18 | 21 | import com.moos.progress.fragment.CircleProgressFragment;
|
19 | 22 | import com.moos.progress.fragment.HorizontalProgressFragment;
|
20 | 23 |
|
21 | 24 | /**
|
22 | 25 | * by Moos on 2018/03/21
|
23 |
| - * just a example to use it |
| 26 | + * just a design example to use it |
24 | 27 | */
|
25 |
| -public class MainActivity extends AppCompatActivity { |
| 28 | +public class MainActivity extends AppCompatActivity implements View.OnClickListener, HorizontalProgressView.HorizontalProgressUpdateListener, CircleProgressView.CircleProgressUpdateListener { |
26 | 29 | private static final String TAG = "MainActivity";
|
27 |
| - private SwitchCompat switcher; |
28 |
| - private FrameLayout container; |
29 |
| - private TextView title; |
| 30 | + private CircleProgressView cpv_main, cpv_small; |
| 31 | + private HorizontalProgressView hpv_language, hpv_math, hpv_history, hpv_english; |
| 32 | + private TextView tv_language, tv_math, tv_history, tv_english, tv_main; |
| 33 | + private Button button; |
| 34 | + private ImageView bt_detail; |
30 | 35 |
|
31 | 36 | @Override
|
32 | 37 | protected void onCreate(Bundle savedInstanceState) {
|
33 | 38 | super.onCreate(savedInstanceState);
|
34 | 39 | setContentView(R.layout.activity_main);
|
| 40 | + initView(); |
| 41 | + |
| 42 | + } |
| 43 | + |
| 44 | + private void initView() { |
| 45 | + cpv_main = (CircleProgressView) findViewById(R.id.progressView_circle_main); |
| 46 | + cpv_small = (CircleProgressView) findViewById(R.id.progressView_circle_small); |
| 47 | + hpv_language = (HorizontalProgressView) findViewById(R.id.hpv_language); |
| 48 | + hpv_math = (HorizontalProgressView) findViewById(R.id.hpv_math); |
| 49 | + hpv_history = (HorizontalProgressView) findViewById(R.id.hpv_history); |
| 50 | + hpv_english = (HorizontalProgressView) findViewById(R.id.hpv_english); |
| 51 | + tv_language = (TextView) findViewById(R.id.progress_text_language); |
| 52 | + tv_english = (TextView) findViewById(R.id.progress_text_english); |
| 53 | + tv_history = (TextView) findViewById(R.id.progress_text_history); |
| 54 | + tv_math = (TextView) findViewById(R.id.progress_text_math); |
| 55 | + tv_main = (TextView) findViewById(R.id.progress_text_main); |
| 56 | + button = (Button) findViewById(R.id.btn_start); |
| 57 | + bt_detail = (ImageView) findViewById(R.id.btn_details); |
| 58 | + button.setOnClickListener(this); |
| 59 | + bt_detail.setOnClickListener(this); |
| 60 | + initProgressViews(); |
| 61 | + } |
| 62 | + |
| 63 | + private void initProgressViews(){ |
| 64 | + hpv_language.setProgressViewUpdateListener(this); |
| 65 | + hpv_english.setProgressViewUpdateListener(this); |
| 66 | + hpv_history.setProgressViewUpdateListener(this); |
| 67 | + hpv_math.setProgressViewUpdateListener(this); |
| 68 | + cpv_small.setProgressViewUpdateListener(this); |
| 69 | + cpv_main.setProgressViewUpdateListener(this); |
| 70 | + } |
35 | 71 |
|
36 |
| - switcher = (SwitchCompat) findViewById(R.id.fragment_switch); |
37 |
| - container = (FrameLayout) findViewById(R.id.fragment_container); |
38 |
| - title = (TextView) findViewById(R.id.fragment_title); |
39 |
| - replaceFragment(new CircleProgressFragment()); |
40 |
| - switcher.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { |
41 |
| - @Override |
42 |
| - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
43 |
| - if(isChecked){ |
44 |
| - title.setText(getString(R.string.fragment_name_horizontal_progress)); |
45 |
| - replaceFragment(new HorizontalProgressFragment()); |
46 |
| - }else { |
47 |
| - title.setText(getString(R.string.fragment_name_circle_progress)); |
48 |
| - replaceFragment(new CircleProgressFragment()); |
49 |
| - } |
50 |
| - } |
51 |
| - }); |
52 | 72 |
|
| 73 | + @Override |
| 74 | + public void onClick(View v) { |
| 75 | + if(v.getId() == R.id.btn_start){ |
| 76 | + //cpv_small.startProgressAnimation(); |
| 77 | + //cpv_main.startProgressAnimation(); |
| 78 | + hpv_language.startProgressAnimation(); |
| 79 | + hpv_math.startProgressAnimation(); |
| 80 | + hpv_history.startProgressAnimation(); |
| 81 | + hpv_english.startProgressAnimation(); |
| 82 | + }else if(v.getId() == R.id.btn_details){ |
| 83 | + Intent intent = new Intent(MainActivity.this, DetailsActivity.class); |
| 84 | + startActivity(intent); |
| 85 | + } |
53 | 86 | }
|
54 | 87 |
|
55 |
| - private void replaceFragment(Fragment fragment){ |
56 |
| - FragmentManager manager = getSupportFragmentManager(); |
57 |
| - FragmentTransaction transaction = manager.beginTransaction(); |
58 |
| - transaction.replace(R.id.fragment_container, fragment); |
59 |
| - transaction.commit(); |
| 88 | + @Override |
| 89 | + public void onHorizontalProgressStart(View view) { |
| 90 | + |
60 | 91 | }
|
61 | 92 |
|
| 93 | + @Override |
| 94 | + public void onHorizontalProgressUpdate(View view, float progress) { |
| 95 | + int progressInt = (int) progress; |
| 96 | + switch (view.getId()){ |
| 97 | + case R.id.hpv_language: |
| 98 | + tv_language.setText(progressInt + "%"); |
| 99 | + break; |
| 100 | + |
| 101 | + case R.id.hpv_english: |
| 102 | + tv_english.setText(progressInt + "%"); |
| 103 | + break; |
| 104 | + |
| 105 | + case R.id.hpv_history: |
| 106 | + tv_history.setText(progressInt + "%"); |
| 107 | + break; |
62 | 108 |
|
| 109 | + case R.id.hpv_math: |
| 110 | + tv_math.setText(progressInt + "%"); |
| 111 | + break; |
| 112 | + |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + @Override |
| 117 | + public void onHorizontalProgressFinished(View view) { |
| 118 | + |
| 119 | + if(view.getId() == R.id.hpv_language){ |
| 120 | + cpv_small.startProgressAnimation(); |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + @Override |
| 125 | + public void onCircleProgressStart(View view) { |
| 126 | + |
| 127 | + } |
| 128 | + |
| 129 | + @Override |
| 130 | + public void onCircleProgressUpdate(View view, float progress) { |
| 131 | + |
| 132 | + int progressInt = (int) progress; |
| 133 | + if(view.getId() == R.id.progressView_circle_main){ |
| 134 | + tv_main.setText(progressInt+""); |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + @Override |
| 139 | + public void onCircleProgressFinished(View view) { |
| 140 | + |
| 141 | + if(view.getId() == R.id.progressView_circle_small){ |
| 142 | + cpv_main.startProgressAnimation(); |
| 143 | + } |
| 144 | + |
| 145 | + } |
63 | 146 | }
|
0 commit comments