• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.dialer.voicemail.settings;
18 
19 import android.app.Activity;
20 import android.os.Bundle;
21 import android.support.annotation.IntDef;
22 import android.view.View;
23 import android.view.View.OnClickListener;
24 import android.widget.Button;
25 import java.lang.annotation.Retention;
26 import java.lang.annotation.RetentionPolicy;
27 
28 /** Activity for recording a new voicemail greeting */
29 public class RecordVoicemailGreetingActivity extends Activity implements OnClickListener {
30 
31   /** Possible states of RecordButton and RecordVoicemailGreetingActivity */
32   @Retention(RetentionPolicy.SOURCE)
33   @IntDef({
34     RECORD_GREETING_INIT,
35     RECORD_GREETING_RECORDING,
36     RECORD_GREETING_RECORDED,
37     RECORD_GREETING_PLAYING_BACK
38   })
39   public @interface ButtonState {}
40 
41   public static final int RECORD_GREETING_INIT = 1;
42   public static final int RECORD_GREETING_RECORDING = 2;
43   public static final int RECORD_GREETING_RECORDED = 3;
44   public static final int RECORD_GREETING_PLAYING_BACK = 4;
45   public static final int MAX_GREETING_DURATION_MS = 45000;
46 
47   private int currentState;
48   private int duration;
49   private RecordButton recordButton;
50   private Button saveButton;
51   private Button redoButton;
52 
53   @Override
onCreate(Bundle savedInstanceState)54   protected void onCreate(Bundle savedInstanceState) {
55     super.onCreate(savedInstanceState);
56     setContentView(R.layout.activity_record_voicemail_greeting);
57 
58     recordButton = findViewById(R.id.record_button);
59     saveButton = findViewById(R.id.save_button);
60     redoButton = findViewById(R.id.redo_button);
61 
62     duration = 0;
63     setState(RECORD_GREETING_INIT);
64     recordButton.setOnClickListener(this);
65   }
66 
67   @Override
onClick(View v)68   public void onClick(View v) {
69     if (v == recordButton) {
70       switch (currentState) {
71         case RECORD_GREETING_INIT:
72           setState(RECORD_GREETING_RECORDING);
73           break;
74         case RECORD_GREETING_RECORDED:
75           setState(RECORD_GREETING_PLAYING_BACK);
76           break;
77         case RECORD_GREETING_RECORDING:
78         case RECORD_GREETING_PLAYING_BACK:
79           setState(RECORD_GREETING_RECORDED);
80           break;
81         default:
82           break;
83       }
84     }
85   }
86 
setState(@uttonState int state)87   private void setState(@ButtonState int state) {
88     currentState = state;
89 
90     switch (state) {
91       case RECORD_GREETING_INIT:
92         recordButton.setState(state);
93         recordButton.setTracks(0, 0);
94         setSaveRedoButtonsEnabled(false);
95         break;
96       case RECORD_GREETING_PLAYING_BACK:
97       case RECORD_GREETING_RECORDED:
98         recordButton.setState(state);
99         recordButton.setTracks(0, (float) duration / MAX_GREETING_DURATION_MS);
100         setSaveRedoButtonsEnabled(true);
101         break;
102       case RECORD_GREETING_RECORDING:
103         recordButton.setState(state);
104         recordButton.setTracks(0, 1f);
105         setSaveRedoButtonsEnabled(false);
106         break;
107       default:
108         break;
109     }
110   }
111 
112   /** Enables/Disables save and redo buttons in the layout */
setSaveRedoButtonsEnabled(boolean enabled)113   private void setSaveRedoButtonsEnabled(boolean enabled) {
114     if (enabled) {
115       saveButton.setVisibility(View.VISIBLE);
116       redoButton.setVisibility(View.VISIBLE);
117     } else {
118       saveButton.setVisibility(View.GONE);
119       redoButton.setVisibility(View.GONE);
120     }
121   }
122 }
123