summaryrefslogtreecommitdiff
path: root/java/com/android/dialer
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/dialer')
-rw-r--r--java/com/android/dialer/voicemail/settings/RecordButton.java140
-rw-r--r--java/com/android/dialer/voicemail/settings/RecordVoicemailGreetingActivity.java72
-rw-r--r--java/com/android/dialer/voicemail/settings/res/drawable/start_playback_drawable.xml29
-rw-r--r--java/com/android/dialer/voicemail/settings/res/drawable/start_recording_drawable.xml29
-rw-r--r--java/com/android/dialer/voicemail/settings/res/drawable/stop_playback_drawable.xml31
-rw-r--r--java/com/android/dialer/voicemail/settings/res/drawable/stop_recording_drawable.xml31
-rw-r--r--java/com/android/dialer/voicemail/settings/res/values/dimens_record_button.xml20
7 files changed, 349 insertions, 3 deletions
diff --git a/java/com/android/dialer/voicemail/settings/RecordButton.java b/java/com/android/dialer/voicemail/settings/RecordButton.java
index f144576d4..d62637053 100644
--- a/java/com/android/dialer/voicemail/settings/RecordButton.java
+++ b/java/com/android/dialer/voicemail/settings/RecordButton.java
@@ -17,21 +17,157 @@
package com.android.dialer.voicemail.settings;
import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.drawable.Drawable;
+import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.widget.Button;
+import com.android.dialer.voicemail.settings.RecordVoicemailGreetingActivity.ButtonState;
/** Custom Button View for Dialer voicemail greeting recording */
public class RecordButton extends Button {
+ private final float trackWidth = getResources().getDimensionPixelSize(R.dimen.track_width);
+ private final int centerIconRadius =
+ getResources().getDimensionPixelSize(R.dimen.center_icon_radius);
+ private final int secondaryTrackAlpha = 64;
+
+ private float mainTrackFraction;
+ private float secondaryTrackFraction;
+
+ private Rect centerIconRect;
+ private RectF bodyRect;
+
+ private Drawable readyDrawable;
+ private Drawable recordingDrawable;
+ private Drawable recordedDrawable;
+ private Drawable playingDrawable;
+ private Drawable currentCenterDrawable;
+
+ private Paint mainTrackPaint;
+ private Paint secondaryTrackPaint;
+
public RecordButton(Context context) {
super(context);
+ init();
}
public RecordButton(Context context, AttributeSet attrs) {
super(context, attrs);
+ init();
+ }
+
+ public RecordButton(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ init();
+ }
+
+ /**
+ * Updates bounds for main and secondary tracks and the size of the center Drawable based on View
+ * resizing
+ */
+ @Override
+ protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
+ // Canvas.drawArc() method draws from center of stroke, so the trackWidth must be accounted for
+ float viewRadius = Math.min(width, height) / 2f - trackWidth;
+ float centerX = width / 2f;
+ float centerY = viewRadius + trackWidth / 2f;
+
+ bodyRect =
+ new RectF(
+ centerX - viewRadius, centerY - viewRadius, centerX + viewRadius, centerY + viewRadius);
+
+ centerIconRect =
+ new Rect(
+ (int) centerX - centerIconRadius,
+ (int) centerY - centerIconRadius,
+ (int) centerX + centerIconRadius,
+ (int) centerY + centerIconRadius);
+ }
+
+ private void init() {
+ readyDrawable = ContextCompat.getDrawable(getContext(), R.drawable.start_recording_drawable);
+ recordingDrawable = ContextCompat.getDrawable(getContext(), R.drawable.stop_recording_drawable);
+ recordedDrawable = ContextCompat.getDrawable(getContext(), R.drawable.start_playback_drawable);
+ playingDrawable = ContextCompat.getDrawable(getContext(), R.drawable.stop_playback_drawable);
+
+ mainTrackPaint = getBasePaint(R.color.dialer_call_green);
+ secondaryTrackPaint = getBasePaint(R.color.dialer_call_green);
+ secondaryTrackPaint.setAlpha(secondaryTrackAlpha);
+
+ setState(RecordVoicemailGreetingActivity.RECORD_GREETING_INIT);
+ }
+
+ /** Returns Paint with base attributes for drawing the main and secondary tracks */
+ private Paint getBasePaint(int id) {
+ Paint paint = new Paint();
+ paint.setAntiAlias(true);
+ paint.setStrokeWidth(trackWidth);
+ paint.setStrokeCap(Paint.Cap.ROUND);
+ paint.setStyle(Paint.Style.STROKE);
+ paint.setColor(ContextCompat.getColor(getContext(), id));
+ return paint;
+ }
+
+ /** Sets the fraction value of progress tracks, this will trigger a redraw of the button. */
+ public void setTracks(float mainTrackFraction, float secondaryTrackFraction) {
+ this.mainTrackFraction = mainTrackFraction;
+ this.secondaryTrackFraction = secondaryTrackFraction;
+ invalidate();
+ }
+
+ /**
+ * Sets internal state of RecordButton. This will also trigger UI refresh of the button to reflect
+ * the new state.
+ */
+ public void setState(@ButtonState int state) {
+ switch (state) {
+ case RecordVoicemailGreetingActivity.RECORD_GREETING_INIT:
+ mainTrackPaint = getBasePaint(R.color.dialer_call_green);
+ secondaryTrackPaint = getBasePaint(R.color.dialer_call_green);
+ secondaryTrackPaint.setAlpha(secondaryTrackAlpha);
+ currentCenterDrawable = readyDrawable;
+ break;
+ case RecordVoicemailGreetingActivity.RECORD_GREETING_PLAYING_BACK:
+ mainTrackPaint = getBasePaint(R.color.google_blue_500);
+ secondaryTrackPaint = getBasePaint(R.color.google_blue_50);
+ currentCenterDrawable = playingDrawable;
+ break;
+ case RecordVoicemailGreetingActivity.RECORD_GREETING_RECORDED:
+ mainTrackPaint = getBasePaint(R.color.google_blue_500);
+ secondaryTrackPaint = getBasePaint(R.color.google_blue_50);
+ currentCenterDrawable = recordedDrawable;
+ break;
+ case RecordVoicemailGreetingActivity.RECORD_GREETING_RECORDING:
+ mainTrackPaint = getBasePaint(R.color.dialer_red);
+ secondaryTrackPaint = getBasePaint(R.color.dialer_red);
+ secondaryTrackPaint.setAlpha(secondaryTrackAlpha);
+ currentCenterDrawable = recordingDrawable;
+ break;
+ default:
+ throw new RuntimeException("Invalid button state");
+ }
+ refreshDrawableState();
+ invalidate();
}
- public RecordButton(Context context, AttributeSet attrs, int defStyleAttrs) {
- super(context, attrs, defStyleAttrs);
+ /**
+ * Handles drawing the main and secondary track arcs and the center Drawable image based on track
+ * fractions and the Button's current state
+ */
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+
+ canvas.drawArc(bodyRect, -90, secondaryTrackFraction * 360, false, secondaryTrackPaint);
+ canvas.drawArc(bodyRect, -90, mainTrackFraction * 360, false, mainTrackPaint);
+
+ // TODO(marquelle) - Add pulse
+
+ currentCenterDrawable.setBounds(centerIconRect);
+ currentCenterDrawable.draw(canvas);
}
}
diff --git a/java/com/android/dialer/voicemail/settings/RecordVoicemailGreetingActivity.java b/java/com/android/dialer/voicemail/settings/RecordVoicemailGreetingActivity.java
index 750636faa..17f8282c5 100644
--- a/java/com/android/dialer/voicemail/settings/RecordVoicemailGreetingActivity.java
+++ b/java/com/android/dialer/voicemail/settings/RecordVoicemailGreetingActivity.java
@@ -18,13 +18,83 @@ 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 {
+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;
+ }
}
}
diff --git a/java/com/android/dialer/voicemail/settings/res/drawable/start_playback_drawable.xml b/java/com/android/dialer/voicemail/settings/res/drawable/start_playback_drawable.xml
new file mode 100644
index 000000000..2a7ec4a7c
--- /dev/null
+++ b/java/com/android/dialer/voicemail/settings/res/drawable/start_playback_drawable.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item>
+ <shape android:shape="oval">
+ <solid android:color="@color/google_blue_500"/>
+ </shape>
+ </item>
+ <item
+ android:top="24dp"
+ android:bottom="24dp"
+ android:left="24dp"
+ android:right="24dp"
+ android:drawable="@drawable/quantum_ic_play_arrow_vd_theme_24"/>
+</layer-list>
diff --git a/java/com/android/dialer/voicemail/settings/res/drawable/start_recording_drawable.xml b/java/com/android/dialer/voicemail/settings/res/drawable/start_recording_drawable.xml
new file mode 100644
index 000000000..42d27fc2a
--- /dev/null
+++ b/java/com/android/dialer/voicemail/settings/res/drawable/start_recording_drawable.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item>
+ <shape android:shape="oval">
+ <solid android:color="@color/dialer_call_green"/>
+ </shape>
+ </item>
+ <item
+ android:top="24dp"
+ android:bottom="24dp"
+ android:left="24dp"
+ android:right="24dp"
+ android:drawable="@drawable/quantum_ic_mic_vd_theme_24"/>
+</layer-list>
diff --git a/java/com/android/dialer/voicemail/settings/res/drawable/stop_playback_drawable.xml b/java/com/android/dialer/voicemail/settings/res/drawable/stop_playback_drawable.xml
new file mode 100644
index 000000000..24bf90b40
--- /dev/null
+++ b/java/com/android/dialer/voicemail/settings/res/drawable/stop_playback_drawable.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item>
+ <shape android:shape="oval">
+ <solid android:color="@color/google_blue_500"/>
+ </shape>
+ </item>
+ <item
+ android:width="24dp"
+ android:height="24dp"
+ android:gravity="center">
+ <shape android:shape="rectangle">
+ <solid android:color="@android:color/white"/>
+ </shape>
+ </item>
+</layer-list>
diff --git a/java/com/android/dialer/voicemail/settings/res/drawable/stop_recording_drawable.xml b/java/com/android/dialer/voicemail/settings/res/drawable/stop_recording_drawable.xml
new file mode 100644
index 000000000..cff539d54
--- /dev/null
+++ b/java/com/android/dialer/voicemail/settings/res/drawable/stop_recording_drawable.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item>
+ <shape android:shape="oval">
+ <solid android:color="@color/dialer_red"/>
+ </shape>
+ </item>
+ <item
+ android:width="24dp"
+ android:height="24dp"
+ android:gravity="center">
+ <shape android:shape="rectangle">
+ <solid android:color="@android:color/white"/>
+ </shape>
+ </item>
+</layer-list>
diff --git a/java/com/android/dialer/voicemail/settings/res/values/dimens_record_button.xml b/java/com/android/dialer/voicemail/settings/res/values/dimens_record_button.xml
new file mode 100644
index 000000000..a45f987c2
--- /dev/null
+++ b/java/com/android/dialer/voicemail/settings/res/values/dimens_record_button.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <dimen name="track_width">15dp</dimen>
+ <dimen name="center_icon_radius">48dp</dimen>
+</resources>