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