• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.example.android.support.wear.app;
18 
19 import android.app.Activity;
20 import android.os.Build;
21 import android.os.Bundle;
22 import android.view.View;
23 import android.widget.TextView;
24 
25 import androidx.annotation.Nullable;
26 import androidx.annotation.RequiresApi;
27 import androidx.core.content.ContextCompat;
28 import androidx.wear.widget.CircularProgressLayout;
29 
30 import com.example.android.support.wear.R;
31 
32 import java.util.concurrent.TimeUnit;
33 
34 /**
35  * Main activity for the CircularProgressLayout demo.
36  */
37 @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
38 public class CircularProgressLayoutDemo extends Activity implements
39         CircularProgressLayout.OnTimerFinishedListener, View.OnClickListener {
40 
41     private static final long TOTAL_TIME = TimeUnit.SECONDS.toMillis(10);
42 
43     CircularProgressLayout mCircularProgressLayout;
44     TextView mChildView;
45 
46     @Override
onCreate(@ullable Bundle savedInstanceState)47     protected void onCreate(@Nullable Bundle savedInstanceState) {
48         super.onCreate(savedInstanceState);
49         setContentView(R.layout.cpl_demo);
50         mCircularProgressLayout = findViewById(R.id.circularProgressLayout_layout);
51         mChildView = findViewById(R.id.circularProgressLayout_child);
52 
53         mCircularProgressLayout.setOnClickListener(this);
54         mCircularProgressLayout.setOnTimerFinishedListener(this);
55 
56         mCircularProgressLayout.setTotalTime(TOTAL_TIME);
57         mCircularProgressLayout.startTimer();
58     }
59 
60     @Override
onTimerFinished(CircularProgressLayout layout)61     public void onTimerFinished(CircularProgressLayout layout) {
62         if (layout == mCircularProgressLayout) {
63             mChildView.setText(getString(R.string.cpl_finished));
64             mCircularProgressLayout.setBackgroundColor(
65                     ContextCompat.getColor(this, R.color.cpl_light_green));
66         }
67     }
68 
69     @Override
onClick(View view)70     public void onClick(View view) {
71         if (view == mCircularProgressLayout && mCircularProgressLayout.isTimerRunning()) {
72             mCircularProgressLayout.stopTimer();
73             mChildView.setText(getString(R.string.cpl_clicked));
74             mCircularProgressLayout.setBackgroundColor(
75                     ContextCompat.getColor(this, R.color.cpl_light_red));
76         }
77     }
78 }
79