CircularProgressLayoutDemo.java revision b31c3281d870e9abb673db239234d580dcc4feff
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
17package com.example.android.support.wear.app;
18
19import android.app.Activity;
20import android.os.Build;
21import android.os.Bundle;
22import androidx.annotation.Nullable;
23import androidx.annotation.RequiresApi;
24import androidx.core.content.ContextCompat;
25import androidx.wear.widget.CircularProgressLayout;
26import android.view.View;
27import android.widget.TextView;
28
29import com.example.android.support.wear.R;
30
31import java.util.concurrent.TimeUnit;
32
33/**
34 * Main activity for the CircularProgressLayout demo.
35 */
36@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
37public class CircularProgressLayoutDemo extends Activity implements
38        CircularProgressLayout.OnTimerFinishedListener, View.OnClickListener {
39
40    private static final long TOTAL_TIME = TimeUnit.SECONDS.toMillis(10);
41
42    CircularProgressLayout mCircularProgressLayout;
43    TextView mChildView;
44
45    @Override
46    protected void onCreate(@Nullable Bundle savedInstanceState) {
47        super.onCreate(savedInstanceState);
48        setContentView(R.layout.cpl_demo);
49        mCircularProgressLayout = findViewById(R.id.circularProgressLayout_layout);
50        mChildView = findViewById(R.id.circularProgressLayout_child);
51
52        mCircularProgressLayout.setOnClickListener(this);
53        mCircularProgressLayout.setOnTimerFinishedListener(this);
54
55        mCircularProgressLayout.setTotalTime(TOTAL_TIME);
56        mCircularProgressLayout.startTimer();
57    }
58
59    @Override
60    public void onTimerFinished(CircularProgressLayout layout) {
61        if (layout == mCircularProgressLayout) {
62            mChildView.setText(getString(R.string.cpl_finished));
63            mCircularProgressLayout.setBackgroundColor(
64                    ContextCompat.getColor(this, R.color.cpl_light_green));
65        }
66    }
67
68    @Override
69    public void onClick(View view) {
70        if (view == mCircularProgressLayout && mCircularProgressLayout.isTimerRunning()) {
71            mCircularProgressLayout.stopTimer();
72            mChildView.setText(getString(R.string.cpl_clicked));
73            mCircularProgressLayout.setBackgroundColor(
74                    ContextCompat.getColor(this, R.color.cpl_light_red));
75        }
76    }
77}
78