1 /*
2  * Copyright (C) 2015 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 package com.android.messaging.ui;
17 
18 import android.content.Context;
19 import android.util.AttributeSet;
20 import android.widget.ImageView;
21 import android.widget.ViewSwitcher;
22 
23 import com.android.messaging.R;
24 
25 /**
26  * Shows a tinted play pause button.
27  */
28 public class AudioAttachmentPlayPauseButton extends ViewSwitcher {
29     private ImageView mPlayButton;
30     private ImageView mPauseButton;
31 
32     private boolean mShowAsIncoming;
33 
AudioAttachmentPlayPauseButton(final Context context, final AttributeSet attrs)34     public AudioAttachmentPlayPauseButton(final Context context, final AttributeSet attrs) {
35         super(context, attrs);
36     }
37 
38     @Override
onFinishInflate()39     protected void onFinishInflate() {
40         super.onFinishInflate();
41         mPlayButton = (ImageView) findViewById(R.id.play_button);
42         mPauseButton = (ImageView) findViewById(R.id.pause_button);
43         updateAppearance();
44     }
45 
setVisualStyle(final boolean showAsIncoming)46     public void setVisualStyle(final boolean showAsIncoming) {
47         if (mShowAsIncoming != showAsIncoming) {
48             mShowAsIncoming = showAsIncoming;
49             updateAppearance();
50         }
51     }
52 
updateAppearance()53     private void updateAppearance() {
54         mPlayButton.setImageDrawable(ConversationDrawables.get()
55                 .getPlayButtonDrawable(mShowAsIncoming));
56         mPauseButton.setImageDrawable(ConversationDrawables.get()
57                 .getPauseButtonDrawable(mShowAsIncoming));
58     }
59 }
60