Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 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.systemui.screenrecord; |
| 18 | |
Jay Aliomer | 0bd491a | 2020-03-16 14:34:10 -0400 | [diff] [blame] | 19 | import static com.android.systemui.screenrecord.ScreenRecordingAudioSource.INTERNAL; |
| 20 | import static com.android.systemui.screenrecord.ScreenRecordingAudioSource.MIC; |
| 21 | import static com.android.systemui.screenrecord.ScreenRecordingAudioSource.MIC_AND_INTERNAL; |
| 22 | import static com.android.systemui.screenrecord.ScreenRecordingAudioSource.NONE; |
| 23 | |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 24 | import android.app.Activity; |
Beth Thibodeau | 77c2545 | 2020-01-09 14:33:47 -0500 | [diff] [blame] | 25 | import android.app.PendingIntent; |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 26 | import android.os.Bundle; |
Beth Thibodeau | 630225c | 2020-02-04 17:16:45 -0500 | [diff] [blame] | 27 | import android.view.Gravity; |
| 28 | import android.view.ViewGroup; |
| 29 | import android.view.Window; |
Jay Aliomer | 0bd491a | 2020-03-16 14:34:10 -0400 | [diff] [blame] | 30 | import android.widget.ArrayAdapter; |
Beth Thibodeau | 630225c | 2020-02-04 17:16:45 -0500 | [diff] [blame] | 31 | import android.widget.Button; |
Jay Aliomer | 0bd491a | 2020-03-16 14:34:10 -0400 | [diff] [blame] | 32 | import android.widget.Spinner; |
Beth Thibodeau | 630225c | 2020-02-04 17:16:45 -0500 | [diff] [blame] | 33 | import android.widget.Switch; |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 34 | |
| 35 | import com.android.systemui.R; |
| 36 | |
Jay Aliomer | 0bd491a | 2020-03-16 14:34:10 -0400 | [diff] [blame] | 37 | import java.util.ArrayList; |
| 38 | import java.util.List; |
| 39 | |
Beth Thibodeau | 77c2545 | 2020-01-09 14:33:47 -0500 | [diff] [blame] | 40 | import javax.inject.Inject; |
| 41 | |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 42 | /** |
| 43 | * Activity to select screen recording options |
| 44 | */ |
| 45 | public class ScreenRecordDialog extends Activity { |
Beth Thibodeau | 77c2545 | 2020-01-09 14:33:47 -0500 | [diff] [blame] | 46 | private static final long DELAY_MS = 3000; |
Beth Thibodeau | 5877278 | 2020-02-18 20:55:38 -0500 | [diff] [blame] | 47 | private static final long INTERVAL_MS = 1000; |
Jay Aliomer | 0bd491a | 2020-03-16 14:34:10 -0400 | [diff] [blame] | 48 | private static final String TAG = "ScreenRecordDialog"; |
Beth Thibodeau | 77c2545 | 2020-01-09 14:33:47 -0500 | [diff] [blame] | 49 | |
| 50 | private final RecordingController mController; |
Beth Thibodeau | 630225c | 2020-02-04 17:16:45 -0500 | [diff] [blame] | 51 | private Switch mTapsSwitch; |
Jay Aliomer | 0bd491a | 2020-03-16 14:34:10 -0400 | [diff] [blame] | 52 | private Switch mAudioSwitch; |
| 53 | private Spinner mOptions; |
| 54 | private List<ScreenRecordingAudioSource> mModes; |
| 55 | private int mSelected; |
| 56 | |
Beth Thibodeau | 77c2545 | 2020-01-09 14:33:47 -0500 | [diff] [blame] | 57 | |
| 58 | @Inject |
| 59 | public ScreenRecordDialog(RecordingController controller) { |
| 60 | mController = controller; |
| 61 | } |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 62 | |
| 63 | @Override |
| 64 | public void onCreate(Bundle savedInstanceState) { |
| 65 | super.onCreate(savedInstanceState); |
Beth Thibodeau | 630225c | 2020-02-04 17:16:45 -0500 | [diff] [blame] | 66 | |
| 67 | Window window = getWindow(); |
| 68 | // Inflate the decor view, so the attributes below are not overwritten by the theme. |
| 69 | window.getDecorView(); |
| 70 | window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); |
| 71 | window.setGravity(Gravity.TOP); |
Beth Thibodeau | 63ece8c | 2020-05-06 15:02:50 -0400 | [diff] [blame] | 72 | setTitle(R.string.screenrecord_name); |
Beth Thibodeau | 630225c | 2020-02-04 17:16:45 -0500 | [diff] [blame] | 73 | |
| 74 | setContentView(R.layout.screen_record_dialog); |
| 75 | |
| 76 | Button cancelBtn = findViewById(R.id.button_cancel); |
| 77 | cancelBtn.setOnClickListener(v -> { |
| 78 | finish(); |
| 79 | }); |
| 80 | |
| 81 | Button startBtn = findViewById(R.id.button_start); |
| 82 | startBtn.setOnClickListener(v -> { |
| 83 | requestScreenCapture(); |
| 84 | finish(); |
| 85 | }); |
| 86 | |
Jay Aliomer | 0bd491a | 2020-03-16 14:34:10 -0400 | [diff] [blame] | 87 | mModes = new ArrayList<>(); |
Jay Aliomer | 0bd491a | 2020-03-16 14:34:10 -0400 | [diff] [blame] | 88 | mModes.add(MIC); |
Jay Aliomer | 246a25e | 2020-05-26 22:57:34 -0400 | [diff] [blame] | 89 | mModes.add(INTERNAL); |
Jay Aliomer | 0bd491a | 2020-03-16 14:34:10 -0400 | [diff] [blame] | 90 | mModes.add(MIC_AND_INTERNAL); |
| 91 | |
Beth Thibodeau | 630225c | 2020-02-04 17:16:45 -0500 | [diff] [blame] | 92 | mAudioSwitch = findViewById(R.id.screenrecord_audio_switch); |
| 93 | mTapsSwitch = findViewById(R.id.screenrecord_taps_switch); |
Jay Aliomer | 0bd491a | 2020-03-16 14:34:10 -0400 | [diff] [blame] | 94 | mOptions = findViewById(R.id.screen_recording_options); |
| 95 | ArrayAdapter a = new ScreenRecordingAdapter(getApplicationContext(), |
| 96 | android.R.layout.simple_spinner_dropdown_item, |
| 97 | mModes); |
| 98 | a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
| 99 | mOptions.setAdapter(a); |
| 100 | |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | private void requestScreenCapture() { |
Beth Thibodeau | 630225c | 2020-02-04 17:16:45 -0500 | [diff] [blame] | 104 | boolean showTaps = mTapsSwitch.isChecked(); |
Jay Aliomer | 0bd491a | 2020-03-16 14:34:10 -0400 | [diff] [blame] | 105 | ScreenRecordingAudioSource audioMode = mAudioSwitch.isChecked() |
| 106 | ? (ScreenRecordingAudioSource) mOptions.getSelectedItem() |
| 107 | : NONE; |
Beth Thibodeau | 630225c | 2020-02-04 17:16:45 -0500 | [diff] [blame] | 108 | PendingIntent startIntent = PendingIntent.getForegroundService(this, |
| 109 | RecordingService.REQUEST_CODE, |
| 110 | RecordingService.getStartIntent( |
Jay Aliomer | 0bd491a | 2020-03-16 14:34:10 -0400 | [diff] [blame] | 111 | ScreenRecordDialog.this, RESULT_OK, |
| 112 | audioMode.ordinal(), showTaps), |
Beth Thibodeau | 630225c | 2020-02-04 17:16:45 -0500 | [diff] [blame] | 113 | PendingIntent.FLAG_UPDATE_CURRENT); |
| 114 | PendingIntent stopIntent = PendingIntent.getService(this, |
| 115 | RecordingService.REQUEST_CODE, |
| 116 | RecordingService.getStopIntent(this), |
| 117 | PendingIntent.FLAG_UPDATE_CURRENT); |
Beth Thibodeau | 5877278 | 2020-02-18 20:55:38 -0500 | [diff] [blame] | 118 | mController.startCountdown(DELAY_MS, INTERVAL_MS, startIntent, stopIntent); |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 119 | } |
| 120 | } |