1 /* 2 * Copyright (C) 2016 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.android.car.cluster.sample.cards; 18 19 import android.content.Context; 20 import android.graphics.Bitmap; 21 import android.graphics.BitmapFactory; 22 import android.view.animation.DecelerateInterpolator; 23 import android.widget.ImageView; 24 25 import com.android.car.cluster.sample.DebugUtil; 26 import com.android.car.cluster.sample.R; 27 28 /** 29 * Sample card responsible for displaying weather content. 30 */ 31 public class WeatherCard extends CardView { 32 33 private ImageView mFarCloudImage; 34 private ImageView mNearCloudImage; 35 36 public WeatherCard(Context context, PriorityChangedListener listener) { 37 super(context, CardType.WEATHER, listener); 38 } 39 40 @Override 41 protected void init() { 42 inflate(R.layout.weather_card); 43 44 mPriority = PRIORITY_WEATHER_CARD; 45 mFarCloudImage = viewById(R.id.weather_far_cloud); 46 mNearCloudImage = viewById(R.id.weather_near_cloud); 47 48 mDetailsPanel = viewById(R.id.weather_panel);; 49 Bitmap theSun = BitmapFactory.decodeResource(getResources(), R.drawable.sun_154); 50 setLeftIcon(theSun); 51 mLeftIconSwitcher.setVisibility(VISIBLE); 52 ((ImageView)mRightIconSwitcher.getCurrentView()).setImageDrawable( 53 getResources().getDrawable(R.drawable.cloud_154_shadow, null)); 54 mRightIconSwitcher.setVisibility(VISIBLE); 55 } 56 57 @Override 58 public void onPlayRevealAnimation() { 59 super.onPlayRevealAnimation(); 60 long duration = SHOW_ANIMATION_DURATION * DebugUtil.ANIMATION_FACTOR; 61 62 mNearCloudImage.setTranslationX(400); 63 mNearCloudImage.animate() 64 .translationX(0) 65 .setDuration(duration) 66 .setInterpolator(new DecelerateInterpolator(2f)); 67 68 // Far cloud needs to travel less in screen coordinates so it will make it slower. 69 mFarCloudImage.setTranslationX(100); 70 mFarCloudImage.animate() 71 .translationX(0) 72 .setDuration(duration) 73 .setInterpolator(new DecelerateInterpolator(2f)); 74 } 75 76 @Override 77 protected float getRightIconTargetX() { 78 return super.getRightIconTargetX() - 22; 79 } 80 81 @Override 82 protected float getDetailsPanelTargetX() { 83 return super.getDetailsPanelTargetX() - 70; 84 } 85 } 86