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
17package com.android.car.cluster.sample.cards;
18
19import android.content.Context;
20import android.graphics.Bitmap;
21import android.util.AttributeSet;
22import android.view.View;
23import android.widget.ViewSwitcher;
24import android.widget.ViewSwitcher.ViewFactory;
25
26import com.android.car.cluster.sample.ManeuverPanel;
27import com.android.car.cluster.sample.R;
28
29/**
30 * Card responsible for showing navigation.
31 */
32public class NavCard extends CardView {
33
34    private ViewSwitcher mDirectionsSwitcher;
35
36    public NavCard(Context context, PriorityChangedListener listener) {
37        this(context, null, CardType.NAV, listener);
38    }
39
40    public NavCard(Context context, AttributeSet attrs, @CardType int cardType,
41            PriorityChangedListener listener) {
42        super(context, attrs, cardType, listener);
43
44    }
45
46    @Override
47    protected void init() {
48        inflate(R.layout.nav_card);
49
50        mPriority = PRIORITY_NAVIGATION_ACTIVE;
51
52        mDirectionsSwitcher = viewById(R.id.nav_directions_switcher);
53        mDetailsPanel = mDirectionsSwitcher;
54
55        mDirectionsSwitcher.setFactory(new ViewFactory() {
56            @Override
57            public View makeView() {
58                return new ManeuverPanel(getContext());
59            }
60        });
61
62        setRightIcon(null);  // To hide it.
63    }
64
65    public void setDistanceToNextManeuver(String distance, String units) {
66        ManeuverPanel maneuver = (ManeuverPanel) mDirectionsSwitcher.getCurrentView();
67        maneuver.setDistanceToNextManeuver(distance, units);
68    }
69
70    public void setStreet(CharSequence street) {
71        ManeuverPanel maneuver = (ManeuverPanel) mDirectionsSwitcher.getNextView();
72        maneuver.setStreet(street);
73        mDirectionsSwitcher.showNext();
74    }
75
76    public void setManeuverImage(Bitmap maneuverImage) {
77        setLeftIcon(maneuverImage, true /* animated */);
78    }
79
80    @Override
81    public void onPlayRevealAnimation() {
82        super.onPlayRevealAnimation();
83    }
84}
85