1 /* 2 * Copyright (C) 2021 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.cts.verifier.notifications; 18 19 import android.app.Activity; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.os.Bundle; 23 import android.view.WindowManager; 24 import android.widget.TextView; 25 26 import androidx.annotation.Nullable; 27 28 import com.android.cts.verifier.R; 29 30 /** 31 * A simple activity which will show over the lockscreen (like an ongoing phone call). 32 */ 33 public class ShowWhenLockedActivity extends Activity { 34 private static final String KEY_DESCRIPTION = "desc"; 35 36 /** 37 * Create the intent which can start this activity 38 * @param description The text to be shown on the activity 39 */ makeActivityIntent(Context context, String description, boolean clearActivity)40 public static Intent makeActivityIntent(Context context, String description, 41 boolean clearActivity) { 42 Intent intent = new Intent(context, ShowWhenLockedActivity.class) 43 .putExtra(KEY_DESCRIPTION, description); 44 if (clearActivity) { 45 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); 46 } 47 return intent; 48 } 49 50 @Override onCreate(@ullable Bundle savedInstanceState)51 protected void onCreate(@Nullable Bundle savedInstanceState) { 52 getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); 53 super.onCreate(savedInstanceState); 54 setContentView(R.layout.activity_show_when_locked); 55 String description = getIntent().getStringExtra(KEY_DESCRIPTION); 56 this.<TextView>findViewById(R.id.description).setText(description); 57 } 58 } 59