blob: abd7e7159260de8724e429576beea50a74d6da6b [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;
Jay Aliomer0bd491a2020-03-16 14:34:10 -040027import android.util.Log;
Beth Thibodeau630225c2020-02-04 17:16:45 -050028import android.view.Gravity;
Jay Aliomer0bd491a2020-03-16 14:34:10 -040029import android.view.View;
Beth Thibodeau630225c2020-02-04 17:16:45 -050030import android.view.ViewGroup;
31import android.view.Window;
Jay Aliomer0bd491a2020-03-16 14:34:10 -040032import android.widget.AdapterView;
33import android.widget.ArrayAdapter;
Beth Thibodeau630225c2020-02-04 17:16:45 -050034import android.widget.Button;
Jay Aliomer0bd491a2020-03-16 14:34:10 -040035import android.widget.Spinner;
Beth Thibodeau630225c2020-02-04 17:16:45 -050036import android.widget.Switch;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040037
38import com.android.systemui.R;
39
Jay Aliomer0bd491a2020-03-16 14:34:10 -040040import java.util.ArrayList;
41import java.util.List;
42
Beth Thibodeau77c25452020-01-09 14:33:47 -050043import javax.inject.Inject;
44
Beth Thibodeau5898ac42018-10-26 13:00:09 -040045/**
46 * Activity to select screen recording options
47 */
48public class ScreenRecordDialog extends Activity {
Beth Thibodeau77c25452020-01-09 14:33:47 -050049 private static final long DELAY_MS = 3000;
Beth Thibodeau58772782020-02-18 20:55:38 -050050 private static final long INTERVAL_MS = 1000;
Jay Aliomer0bd491a2020-03-16 14:34:10 -040051 private static final String TAG = "ScreenRecordDialog";
Beth Thibodeau77c25452020-01-09 14:33:47 -050052
53 private final RecordingController mController;
Beth Thibodeau630225c2020-02-04 17:16:45 -050054 private Switch mTapsSwitch;
Jay Aliomer0bd491a2020-03-16 14:34:10 -040055 private Switch mAudioSwitch;
56 private Spinner mOptions;
57 private List<ScreenRecordingAudioSource> mModes;
58 private int mSelected;
59
Beth Thibodeau77c25452020-01-09 14:33:47 -050060
61 @Inject
62 public ScreenRecordDialog(RecordingController controller) {
63 mController = controller;
64 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -040065
66 @Override
67 public void onCreate(Bundle savedInstanceState) {
68 super.onCreate(savedInstanceState);
Beth Thibodeau630225c2020-02-04 17:16:45 -050069
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);
Beth Thibodeau63ece8c2020-05-06 15:02:50 -040075 setTitle(R.string.screenrecord_name);
Beth Thibodeau630225c2020-02-04 17:16:45 -050076
77 setContentView(R.layout.screen_record_dialog);
78
79 Button cancelBtn = findViewById(R.id.button_cancel);
80 cancelBtn.setOnClickListener(v -> {
81 finish();
82 });
83
84 Button startBtn = findViewById(R.id.button_start);
85 startBtn.setOnClickListener(v -> {
86 requestScreenCapture();
87 finish();
88 });
89
Jay Aliomer0bd491a2020-03-16 14:34:10 -040090 mModes = new ArrayList<>();
91 mModes.add(INTERNAL);
92 mModes.add(MIC);
93 mModes.add(MIC_AND_INTERNAL);
94
Beth Thibodeau630225c2020-02-04 17:16:45 -050095 mAudioSwitch = findViewById(R.id.screenrecord_audio_switch);
96 mTapsSwitch = findViewById(R.id.screenrecord_taps_switch);
Jay Aliomer0bd491a2020-03-16 14:34:10 -040097 mOptions = findViewById(R.id.screen_recording_options);
98 ArrayAdapter a = new ScreenRecordingAdapter(getApplicationContext(),
99 android.R.layout.simple_spinner_dropdown_item,
100 mModes);
101 a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
102 mOptions.setAdapter(a);
103
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400104 }
105
106 private void requestScreenCapture() {
Beth Thibodeau630225c2020-02-04 17:16:45 -0500107 boolean showTaps = mTapsSwitch.isChecked();
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400108 ScreenRecordingAudioSource audioMode = mAudioSwitch.isChecked()
109 ? (ScreenRecordingAudioSource) mOptions.getSelectedItem()
110 : NONE;
Beth Thibodeau630225c2020-02-04 17:16:45 -0500111 PendingIntent startIntent = PendingIntent.getForegroundService(this,
112 RecordingService.REQUEST_CODE,
113 RecordingService.getStartIntent(
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400114 ScreenRecordDialog.this, RESULT_OK,
115 audioMode.ordinal(), showTaps),
Beth Thibodeau630225c2020-02-04 17:16:45 -0500116 PendingIntent.FLAG_UPDATE_CURRENT);
117 PendingIntent stopIntent = PendingIntent.getService(this,
118 RecordingService.REQUEST_CODE,
119 RecordingService.getStopIntent(this),
120 PendingIntent.FLAG_UPDATE_CURRENT);
Beth Thibodeau58772782020-02-18 20:55:38 -0500121 mController.startCountdown(DELAY_MS, INTERVAL_MS, startIntent, stopIntent);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400122 }
123}