• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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.wearable.timer;
18 
19 import android.content.Context;
20 import android.graphics.drawable.GradientDrawable;
21 import android.support.wearable.view.WearableListView;
22 import android.util.AttributeSet;
23 import android.widget.ImageView;
24 import android.widget.LinearLayout;
25 import android.widget.TextView;
26 
27 public class WearableListItemLayout extends LinearLayout
28         implements WearableListView.OnCenterProximityListener {
29     private final float mFadedTextAlpha;
30     private final int mFadedCircleColor;
31     private final int mChosenCircleColor;
32     private ImageView mCircle;
33     private TextView mName;
34 
WearableListItemLayout(Context context)35     public WearableListItemLayout(Context context) {
36         this(context, null);
37     }
38 
WearableListItemLayout(Context context, AttributeSet attrs)39     public WearableListItemLayout(Context context, AttributeSet attrs) {
40         this(context, attrs, 0);
41     }
42 
WearableListItemLayout(Context context, AttributeSet attrs, int defStyle)43     public WearableListItemLayout(Context context, AttributeSet attrs, int defStyle) {
44         super(context, attrs, defStyle);
45         mFadedTextAlpha = getResources().getInteger(R.integer.action_text_faded_alpha) / 100f;
46         mFadedCircleColor = getResources().getColor(R.color.wl_gray);
47         mChosenCircleColor = getResources().getColor(R.color.wl_blue);
48     }
49 
50     @Override
onFinishInflate()51     protected void onFinishInflate() {
52         super.onFinishInflate();
53         mCircle = (ImageView) findViewById(R.id.circle);
54         mName = (TextView) findViewById(R.id.time_text);
55     }
56 
57     @Override
onCenterPosition(boolean animate)58     public void onCenterPosition(boolean animate) {
59         mName.setAlpha(1f);
60         ((GradientDrawable) mCircle.getDrawable()).setColor(mChosenCircleColor);
61     }
62 
63     @Override
onNonCenterPosition(boolean animate)64     public void onNonCenterPosition(boolean animate) {
65         ((GradientDrawable) mCircle.getDrawable()).setColor(mFadedCircleColor);
66         mName.setAlpha(mFadedTextAlpha);
67     }
68 }
69