156627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu/* 256627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu * Copyright (C) 2017 The Android Open Source Project 356627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu * 456627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu * Licensed under the Apache License, Version 2.0 (the "License"); 556627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu * you may not use this file except in compliance with the License. 656627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu * You may obtain a copy of the License at 756627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu * 856627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu * http://www.apache.org/licenses/LICENSE-2.0 956627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu * 1056627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu * Unless required by applicable law or agreed to in writing, software 1156627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu * distributed under the License is distributed on an "AS IS" BASIS, 1256627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1356627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu * See the License for the specific language governing permissions and 1456627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu * limitations under the License. 1556627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu */ 1656627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu 1756627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdupackage com.example.android.support.wear.app; 1856627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu 1956627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogduimport android.app.Activity; 2056627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogduimport android.os.Build; 2156627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogduimport android.os.Bundle; 2256627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogduimport android.support.annotation.Nullable; 2356627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogduimport android.support.annotation.RequiresApi; 2456627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogduimport android.support.v4.content.ContextCompat; 2556627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogduimport android.support.wear.widget.CircularProgressLayout; 2656627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogduimport android.view.View; 2756627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogduimport android.widget.TextView; 2856627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu 2956627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogduimport com.example.android.support.wear.R; 3056627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu 3156627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogduimport java.util.concurrent.TimeUnit; 3256627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu 3356627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu/** 3456627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu * Main activity for the CircularProgressLayout demo. 3556627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu */ 3656627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu@RequiresApi(Build.VERSION_CODES.LOLLIPOP) 3756627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdupublic class CircularProgressLayoutDemo extends Activity implements 3856627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu CircularProgressLayout.OnTimerFinishedListener, View.OnClickListener { 3956627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu 4056627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu private static final long TOTAL_TIME = TimeUnit.SECONDS.toMillis(10); 4156627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu 4256627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu CircularProgressLayout mCircularProgressLayout; 4356627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu TextView mChildView; 4456627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu 4556627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu @Override 4656627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu protected void onCreate(@Nullable Bundle savedInstanceState) { 4756627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu super.onCreate(savedInstanceState); 4856627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu setContentView(R.layout.cpl_demo); 4956627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu mCircularProgressLayout = findViewById(R.id.circularProgressLayout_layout); 5056627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu mChildView = findViewById(R.id.circularProgressLayout_child); 5156627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu 5256627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu mCircularProgressLayout.setOnClickListener(this); 5356627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu mCircularProgressLayout.setOnTimerFinishedListener(this); 5456627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu 5556627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu mCircularProgressLayout.setTotalTime(TOTAL_TIME); 5656627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu mCircularProgressLayout.startTimer(); 5756627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu } 5856627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu 5956627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu @Override 6056627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu public void onTimerFinished(CircularProgressLayout layout) { 6156627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu if (layout == mCircularProgressLayout) { 6256627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu mChildView.setText(getString(R.string.cpl_finished)); 6356627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu mCircularProgressLayout.setBackgroundColor( 6456627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu ContextCompat.getColor(this, R.color.cpl_light_green)); 6556627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu } 6656627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu } 6756627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu 6856627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu @Override 6956627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu public void onClick(View view) { 7056627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu if (view == mCircularProgressLayout && mCircularProgressLayout.isTimerRunning()) { 7156627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu mCircularProgressLayout.stopTimer(); 7256627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu mChildView.setText(getString(R.string.cpl_clicked)); 7356627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu mCircularProgressLayout.setBackgroundColor( 7456627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu ContextCompat.getColor(this, R.color.cpl_light_red)); 7556627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu } 7656627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu } 7756627a8a90d9af3dae034af27b4114f9eb4e2d90Alper Gundogdu} 78