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 android.view.View;
23import android.widget.TextView;
24
25import androidx.annotation.Nullable;
26import androidx.annotation.RequiresApi;
27import androidx.core.content.ContextCompat;
28import androidx.wear.widget.CircularProgressLayout;
29
30import com.example.android.support.wear.R;
31
32import java.util.concurrent.TimeUnit;
33
34/**
35 * Main activity for the CircularProgressLayout demo.
36 */
37@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
38public 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
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
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
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