blob: d057a8a43c43c407bd9b12d36032f1bdf1b28216 [file] [log] [blame]
Beth Thibodeau5898ac42018-10-26 13:00:09 -04001/*
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
17package com.android.systemui.screenrecord;
18
Jay Aliomer0bd491a2020-03-16 14:34:10 -040019import static com.android.systemui.screenrecord.ScreenRecordingAudioSource.INTERNAL;
20import static com.android.systemui.screenrecord.ScreenRecordingAudioSource.MIC;
21import static com.android.systemui.screenrecord.ScreenRecordingAudioSource.MIC_AND_INTERNAL;
22import static com.android.systemui.screenrecord.ScreenRecordingAudioSource.NONE;
23
Beth Thibodeau5898ac42018-10-26 13:00:09 -040024import android.app.Activity;
Beth Thibodeau77c25452020-01-09 14:33:47 -050025import android.app.PendingIntent;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040026import android.os.Bundle;
Beth Thibodeau630225c2020-02-04 17:16:45 -050027import android.view.Gravity;
28import android.view.ViewGroup;
29import android.view.Window;
Jay Aliomer0bd491a2020-03-16 14:34:10 -040030import android.widget.ArrayAdapter;
Beth Thibodeau630225c2020-02-04 17:16:45 -050031import android.widget.Button;
Jay Aliomer0bd491a2020-03-16 14:34:10 -040032import android.widget.Spinner;
Beth Thibodeau630225c2020-02-04 17:16:45 -050033import android.widget.Switch;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040034
35import com.android.systemui.R;
36
Jay Aliomer0bd491a2020-03-16 14:34:10 -040037import java.util.ArrayList;
38import java.util.List;
39
Beth Thibodeau77c25452020-01-09 14:33:47 -050040import javax.inject.Inject;
41
Beth Thibodeau5898ac42018-10-26 13:00:09 -040042/**
43 * Activity to select screen recording options
44 */
45public class ScreenRecordDialog extends Activity {
Beth Thibodeau77c25452020-01-09 14:33:47 -050046 private static final long DELAY_MS = 3000;
Beth Thibodeau58772782020-02-18 20:55:38 -050047 private static final long INTERVAL_MS = 1000;
Jay Aliomer0bd491a2020-03-16 14:34:10 -040048 private static final String TAG = "ScreenRecordDialog";
Beth Thibodeau77c25452020-01-09 14:33:47 -050049
50 private final RecordingController mController;
Beth Thibodeau630225c2020-02-04 17:16:45 -050051 private Switch mTapsSwitch;
Jay Aliomer0bd491a2020-03-16 14:34:10 -040052 private Switch mAudioSwitch;
53 private Spinner mOptions;
54 private List<ScreenRecordingAudioSource> mModes;
55 private int mSelected;
56
Beth Thibodeau77c25452020-01-09 14:33:47 -050057
58 @Inject
59 public ScreenRecordDialog(RecordingController controller) {
60 mController = controller;
61 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -040062
63 @Override
64 public void onCreate(Bundle savedInstanceState) {
65 super.onCreate(savedInstanceState);
Beth Thibodeau630225c2020-02-04 17:16:45 -050066
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 Thibodeau63ece8c2020-05-06 15:02:50 -040072 setTitle(R.string.screenrecord_name);
Beth Thibodeau630225c2020-02-04 17:16:45 -050073
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 Aliomer0bd491a2020-03-16 14:34:10 -040087 mModes = new ArrayList<>();
Jay Aliomer0bd491a2020-03-16 14:34:10 -040088 mModes.add(MIC);
Jay Aliomer246a25e2020-05-26 22:57:34 -040089 mModes.add(INTERNAL);
Jay Aliomer0bd491a2020-03-16 14:34:10 -040090 mModes.add(MIC_AND_INTERNAL);
91
Beth Thibodeau630225c2020-02-04 17:16:45 -050092 mAudioSwitch = findViewById(R.id.screenrecord_audio_switch);
93 mTapsSwitch = findViewById(R.id.screenrecord_taps_switch);
Jay Aliomer0bd491a2020-03-16 14:34:10 -040094 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 Thibodeau5898ac42018-10-26 13:00:09 -0400101 }
102
103 private void requestScreenCapture() {
Beth Thibodeau630225c2020-02-04 17:16:45 -0500104 boolean showTaps = mTapsSwitch.isChecked();
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400105 ScreenRecordingAudioSource audioMode = mAudioSwitch.isChecked()
106 ? (ScreenRecordingAudioSource) mOptions.getSelectedItem()
107 : NONE;
Beth Thibodeau630225c2020-02-04 17:16:45 -0500108 PendingIntent startIntent = PendingIntent.getForegroundService(this,
109 RecordingService.REQUEST_CODE,
110 RecordingService.getStartIntent(
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400111 ScreenRecordDialog.this, RESULT_OK,
112 audioMode.ordinal(), showTaps),
Beth Thibodeau630225c2020-02-04 17:16:45 -0500113 PendingIntent.FLAG_UPDATE_CURRENT);
114 PendingIntent stopIntent = PendingIntent.getService(this,
115 RecordingService.REQUEST_CODE,
116 RecordingService.getStopIntent(this),
117 PendingIntent.FLAG_UPDATE_CURRENT);
Beth Thibodeau58772782020-02-18 20:55:38 -0500118 mController.startCountdown(DELAY_MS, INTERVAL_MS, startIntent, stopIntent);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400119 }
120}