summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/voicemail/settings/RecordVoicemailGreetingActivity.java
blob: 17f8282c59a450e0047dedd57be49c050b6924b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.dialer.voicemail.settings;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.IntDef;
import android.view.View;
import android.view.View.OnClickListener;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/** Activity for recording a new voicemail greeting */
public class RecordVoicemailGreetingActivity extends Activity implements OnClickListener {

  /** Possible states of RecordButton and RecordVoicemailGreetingActivity */
  @Retention(RetentionPolicy.SOURCE)
  @IntDef({
    RECORD_GREETING_INIT,
    RECORD_GREETING_RECORDED,
    RECORD_GREETING_RECORDED,
    RECORD_GREETING_PLAYING_BACK
  })
  public @interface ButtonState {}

  public static final int RECORD_GREETING_INIT = 1;
  public static final int RECORD_GREETING_RECORDING = 2;
  public static final int RECORD_GREETING_RECORDED = 3;
  public static final int RECORD_GREETING_PLAYING_BACK = 4;
  public static final int MAX_GREETING_DURATION_MS = 45000;

  private int currentState;
  private int duration;
  private RecordButton recordButton;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_record_voicemail_greeting);

    duration = 0;
    setState(RECORD_GREETING_INIT);
  }

  @Override
  public void onClick(View v) {
    if (v == recordButton) {
      switch (currentState) {
        case RECORD_GREETING_INIT:
          setState(RECORD_GREETING_RECORDING);
          break;
        case RECORD_GREETING_RECORDED:
          setState(RECORD_GREETING_PLAYING_BACK);
          break;
        case RECORD_GREETING_RECORDING:
        case RECORD_GREETING_PLAYING_BACK:
          setState(RECORD_GREETING_RECORDED);
          break;
        default:
          break;
      }
    }
  }

  private void setState(@ButtonState int state) {
    currentState = state;

    switch (state) {
      case RECORD_GREETING_INIT:
        recordButton.setState(state);
        recordButton.setTracks(0, 0);
        break;
      case RECORD_GREETING_PLAYING_BACK:
      case RECORD_GREETING_RECORDED:
        recordButton.setState(state);
        recordButton.setTracks(0, (float) duration / MAX_GREETING_DURATION_MS);
        break;
      case RECORD_GREETING_RECORDING:
        recordButton.setState(state);
        recordButton.setTracks(0, 1f);
        break;
      default:
        break;
    }
  }
}