1 /* 2 * Copyright (C) 2007 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.stk; 18 19 import android.app.Activity; 20 import android.app.Application; 21 22 import androidx.core.graphics.Insets; 23 import androidx.core.view.ViewCompat; 24 import androidx.core.view.WindowInsetsCompat; 25 26 import com.android.internal.telephony.cat.Duration; 27 28 /** 29 * Top-level Application class for STK app. 30 */ 31 abstract class StkApp extends Application { 32 // Application constants 33 public static final boolean DBG = true; 34 35 // Identifiers for option menu items 36 static final int MENU_ID_END_SESSION = android.view.Menu.FIRST; 37 static final int MENU_ID_BACK = android.view.Menu.FIRST + 1; 38 static final int MENU_ID_HELP = android.view.Menu.FIRST + 2; 39 40 // Display Text timeouts 41 static final int DISP_TEXT_CLEAR_AFTER_DELAY_TIMEOUT = (15 * 1000); 42 static final int DISP_TEXT_WAIT_FOR_USER_TIMEOUT = (60 * 1000); 43 44 // UI timeout, 30 seconds - used for menues and input 45 static final int UI_TIMEOUT = (30 * 1000); 46 47 // Tone default timeout - 2 seconds 48 static final int TONE_DEFAULT_TIMEOUT = (2 * 1000); 49 50 public static final String TAG = "STK App"; 51 52 /** 53 * This function calculate the time in MS from a duration instance. 54 * returns zero when duration is null. 55 */ calculateDurationInMilis(Duration duration)56 public static int calculateDurationInMilis(Duration duration) { 57 int timeout = 0; 58 if (duration != null) { 59 switch (duration.timeUnit) { 60 case MINUTE: 61 timeout = 1000 * 60; 62 break; 63 case TENTH_SECOND: 64 timeout = 1000 / 10; 65 break; 66 case SECOND: 67 default: 68 timeout = 1000; 69 break; 70 } 71 timeout *= duration.timeInterval; 72 } 73 return timeout; 74 } 75 76 /** 77 * Given an activity, configure the activity to adjust for edge to edge restrictions. 78 * @param activity the activity. 79 */ setupEdgeToEdge(Activity activity)80 public static void setupEdgeToEdge(Activity activity) { 81 ViewCompat.setOnApplyWindowInsetsListener(activity.findViewById(android.R.id.content), 82 (v, windowInsets) -> { 83 Insets insets = windowInsets.getInsets( 84 WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.ime()); 85 86 // Apply the insets paddings to the view. 87 v.setPadding(insets.left, insets.top, insets.right, insets.bottom); 88 89 // Return CONSUMED if you don't want the window insets to keep being 90 // passed down to descendant views. 91 return WindowInsetsCompat.CONSUMED; 92 }); 93 } 94 } 95