From e72f9482de02a04285c7167d1718f53f9aaff56c Mon Sep 17 00:00:00 2001 From: sabowitz Date: Wed, 27 Jun 2018 15:39:01 -0700 Subject: Add voicemail greeting setting screen to voicemail settings. Test: "No tests" PiperOrigin-RevId: 202382580 Change-Id: Ia2dfc2ed10a0500b2b949e3b177279d35ac397e7 --- .../dialer/voicemail/settings/AndroidManifest.xml | 10 +- .../settings/CurrentVoicemailGreetingActivity.java | 139 +++++++++++++++++++++ .../drawable-xhdpi/ic_arrow_back_grey600_48dp.png | Bin 0 -> 208 bytes .../ic_circles_add_googblue_48dp.png | Bin 0 -> 1456 bytes .../ic_play_circle_filled_googblue_48dp.png | Bin 0 -> 1009 bytes .../ic_stop_circle_filled_blue_24dp.png | Bin 0 -> 369 bytes .../layout/activity_current_voicemail_greeting.xml | 104 +++++++++++++++ .../voicemail/settings/res/values/strings.xml | 6 + 8 files changed, 256 insertions(+), 3 deletions(-) create mode 100644 java/com/android/dialer/voicemail/settings/res/drawable-xhdpi/ic_arrow_back_grey600_48dp.png create mode 100644 java/com/android/dialer/voicemail/settings/res/drawable-xhdpi/ic_circles_add_googblue_48dp.png create mode 100644 java/com/android/dialer/voicemail/settings/res/drawable-xhdpi/ic_play_circle_filled_googblue_48dp.png create mode 100644 java/com/android/dialer/voicemail/settings/res/drawable-xhdpi/ic_stop_circle_filled_blue_24dp.png (limited to 'java') diff --git a/java/com/android/dialer/voicemail/settings/AndroidManifest.xml b/java/com/android/dialer/voicemail/settings/AndroidManifest.xml index 71a70da7e..8506ddd41 100644 --- a/java/com/android/dialer/voicemail/settings/AndroidManifest.xml +++ b/java/com/android/dialer/voicemail/settings/AndroidManifest.xml @@ -13,12 +13,10 @@ See the License for the specific language governing permissions and limitations under the License. --> - - @@ -43,7 +41,13 @@ android:parentActivityName="com.android.dialer.app.settings.DialerSettingsActivity" android:theme="@style/SettingsStyle"> - + + + diff --git a/java/com/android/dialer/voicemail/settings/CurrentVoicemailGreetingActivity.java b/java/com/android/dialer/voicemail/settings/CurrentVoicemailGreetingActivity.java index 2b6f27bc3..ff7ae97cc 100644 --- a/java/com/android/dialer/voicemail/settings/CurrentVoicemailGreetingActivity.java +++ b/java/com/android/dialer/voicemail/settings/CurrentVoicemailGreetingActivity.java @@ -16,15 +16,154 @@ package com.android.dialer.voicemail.settings; +import android.Manifest; import android.app.Activity; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.media.MediaPlayer; import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.ActivityCompat; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.ImageButton; +import android.widget.TextView; +import com.android.dialer.common.LogUtil; +import com.android.dialer.widget.DialerToolbar; +import java.io.IOException; +import java.util.Locale; /** Activity to display current voicemail greeting and allow user to navigate to record a new one */ public class CurrentVoicemailGreetingActivity extends Activity { + public static final String VOICEMAIL_GREETING_FILEPATH_KEY = "canonVoicemailGreetingFilePathKey"; + + private static final int REQUEST_RECORD_AUDIO_PERMISSION = 200; + + private boolean permissionToRecordAccepted = false; + + private ImageButton changeGreetingButton; + private ImageButton playButton; + + private DialerToolbar currentVoicemailGreetingDialerToolbar; + + private int greetingDuration = -1; + + private MediaPlayer mediaPlayer; + + private TextView playbackProgressLabel; + private View playbackDisplay; + + private String voicemailGreetingFilePath = ""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_current_voicemail_greeting); + + playbackDisplay = findViewById(R.id.current_voicemail_greeting_recording_display); + playbackProgressLabel = (TextView) findViewById(R.id.playback_progress_text_view); + currentVoicemailGreetingDialerToolbar = (DialerToolbar) findViewById(R.id.toolbar); + + currentVoicemailGreetingDialerToolbar.setTitle( + R.string.voicemail_change_greeting_preference_title); + + changeGreetingButton = (ImageButton) findViewById(R.id.change_greeting_button); + changeGreetingButton.setOnClickListener( + new OnClickListener() { + @Override + public void onClick(View v) { + // TODO(sabowitz): Implement this in CL child beta01. + } + }); + + playButton = (ImageButton) findViewById(R.id.play_button); + playButton.setOnClickListener( + new OnClickListener() { + @Override + public void onClick(View v) { + // TODO(sabowitz): Finish implementing this in CL child beta02. + } + }); + + displayCurrentVoicemailGreetingStatus(); + } + + @Override + public void onStart() { + ActivityCompat.requestPermissions( + this, new String[] {Manifest.permission.RECORD_AUDIO}, REQUEST_RECORD_AUDIO_PERMISSION); + + if (isGreetingRecorded()) { + mediaPlayer = new MediaPlayer(); + try { + mediaPlayer.setDataSource(voicemailGreetingFilePath); + mediaPlayer.prepare(); + } catch (IOException e) { + LogUtil.e("CurrentVoicemailGreetingActivity.onStart", "mediaPlayer setup failed."); + } + } + super.onStart(); + } + + @Override + public void onPause() { + if (isGreetingRecorded()) { + if (mediaPlayer.isPlaying()) { + mediaPlayer.release(); + mediaPlayer = null; + } + } + super.onPause(); + } + + @Override + public void onRequestPermissionsResult( + int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + + if (requestCode == REQUEST_RECORD_AUDIO_PERMISSION) { + permissionToRecordAccepted = grantResults[0] == PackageManager.PERMISSION_GRANTED; + } + if (!permissionToRecordAccepted) { + LogUtil.w( + "CurrentVoicemailGreetingActivity.onRequestPermissionsResult", + "permissionToRecordAccepted = false."); + // TODO(sabowitz): Implement error dialog logic in a child CL. + } + } + + private boolean isGreetingRecorded() { + Intent intent = getIntent(); + if (intent.hasExtra(VOICEMAIL_GREETING_FILEPATH_KEY)) { + String filePathProxy = intent.getStringExtra(VOICEMAIL_GREETING_FILEPATH_KEY); + if (filePathProxy == null || filePathProxy.length() == 0) { + return false; + } + if (mediaPlayer == null) { + mediaPlayer = new MediaPlayer(); + } + try { + mediaPlayer.setDataSource(filePathProxy); + int durationProxy = mediaPlayer.getDuration(); + greetingDuration = durationProxy; + voicemailGreetingFilePath = filePathProxy; + mediaPlayer = null; + return true; + } catch (IOException e) { + LogUtil.e("CurrentVoicemailGreetingActivity.isGreetingRecorded", "bad filepath."); + mediaPlayer = null; + return false; + } + } + return false; + } + + private void displayCurrentVoicemailGreetingStatus() { + if (isGreetingRecorded()) { + String durationLabel = String.format(Locale.US, "00:%d", greetingDuration); + playbackProgressLabel.setText(durationLabel); + } else { + playbackDisplay.setVisibility(View.GONE); + } } } diff --git a/java/com/android/dialer/voicemail/settings/res/drawable-xhdpi/ic_arrow_back_grey600_48dp.png b/java/com/android/dialer/voicemail/settings/res/drawable-xhdpi/ic_arrow_back_grey600_48dp.png new file mode 100644 index 000000000..0a379b484 Binary files /dev/null and b/java/com/android/dialer/voicemail/settings/res/drawable-xhdpi/ic_arrow_back_grey600_48dp.png differ diff --git a/java/com/android/dialer/voicemail/settings/res/drawable-xhdpi/ic_circles_add_googblue_48dp.png b/java/com/android/dialer/voicemail/settings/res/drawable-xhdpi/ic_circles_add_googblue_48dp.png new file mode 100644 index 000000000..5ae52308d Binary files /dev/null and b/java/com/android/dialer/voicemail/settings/res/drawable-xhdpi/ic_circles_add_googblue_48dp.png differ diff --git a/java/com/android/dialer/voicemail/settings/res/drawable-xhdpi/ic_play_circle_filled_googblue_48dp.png b/java/com/android/dialer/voicemail/settings/res/drawable-xhdpi/ic_play_circle_filled_googblue_48dp.png new file mode 100644 index 000000000..065775861 Binary files /dev/null and b/java/com/android/dialer/voicemail/settings/res/drawable-xhdpi/ic_play_circle_filled_googblue_48dp.png differ diff --git a/java/com/android/dialer/voicemail/settings/res/drawable-xhdpi/ic_stop_circle_filled_blue_24dp.png b/java/com/android/dialer/voicemail/settings/res/drawable-xhdpi/ic_stop_circle_filled_blue_24dp.png new file mode 100644 index 000000000..520f860fa Binary files /dev/null and b/java/com/android/dialer/voicemail/settings/res/drawable-xhdpi/ic_stop_circle_filled_blue_24dp.png differ diff --git a/java/com/android/dialer/voicemail/settings/res/layout/activity_current_voicemail_greeting.xml b/java/com/android/dialer/voicemail/settings/res/layout/activity_current_voicemail_greeting.xml index 81d175a4f..30558344e 100644 --- a/java/com/android/dialer/voicemail/settings/res/layout/activity_current_voicemail_greeting.xml +++ b/java/com/android/dialer/voicemail/settings/res/layout/activity_current_voicemail_greeting.xml @@ -21,4 +21,108 @@ android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.android.dialer.voicemail.settings.CurrentVoicemailGreetingActivity"> + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/com/android/dialer/voicemail/settings/res/values/strings.xml b/java/com/android/dialer/voicemail/settings/res/values/strings.xml index 14793fd33..971f37a2e 100644 --- a/java/com/android/dialer/voicemail/settings/res/values/strings.xml +++ b/java/com/android/dialer/voicemail/settings/res/values/strings.xml @@ -36,6 +36,12 @@ Voicemail greeting + + Record a greeting + + + My voicemail greeting + Tap to Record -- cgit v1.2.3