Home | History | Annotate | Download | only in notifications
      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.notifications;
     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 implements WearableListView.Item {
     28 
     29     private final float mFadedTextAlpha;
     30     private final int mFadedCircleColor;
     31     private final int mChosenCircleColor;
     32     private ImageView mCircle;
     33     private float mScale;
     34     private TextView mName;
     35 
     36     public WearableListItemLayout(Context context) {
     37         this(context, null);
     38     }
     39 
     40     public WearableListItemLayout(Context context, AttributeSet attrs) {
     41         this(context, attrs, 0);
     42     }
     43 
     44     public WearableListItemLayout(Context context, AttributeSet attrs, int defStyle) {
     45         super(context, attrs, defStyle);
     46         mFadedTextAlpha = getResources().getInteger(R.integer.action_text_faded_alpha) / 100f;
     47         mFadedCircleColor = getResources().getColor(R.color.wl_gray);
     48         mChosenCircleColor = getResources().getColor(R.color.wl_blue);
     49     }
     50 
     51     @Override
     52     protected void onFinishInflate() {
     53         super.onFinishInflate();
     54         mCircle = (ImageView) findViewById(R.id.circle);
     55         mName = (TextView) findViewById(R.id.name);
     56     }
     57 
     58     @Override
     59     public float getProximityMinValue() {
     60         return 1f;
     61     }
     62 
     63     @Override
     64     public float getProximityMaxValue() {
     65         return 1.6f;
     66     }
     67 
     68     @Override
     69     public float getCurrentProximityValue() {
     70         return mScale;
     71     }
     72 
     73     @Override
     74     public void setScalingAnimatorValue(float scale) {
     75         mScale = scale;
     76         mCircle.setScaleX(scale);
     77         mCircle.setScaleY(scale);
     78     }
     79 
     80     @Override
     81     public void onScaleUpStart() {
     82         mName.setAlpha(1f);
     83         ((GradientDrawable) mCircle.getDrawable()).setColor(mChosenCircleColor);
     84     }
     85 
     86     @Override
     87     public void onScaleDownStart() {
     88         ((GradientDrawable) mCircle.getDrawable()).setColor(mFadedCircleColor);
     89         mName.setAlpha(mFadedTextAlpha);
     90     }
     91 }
     92