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 package com.android.simappdialog; 17 18 import android.app.Activity; 19 import android.content.Intent; 20 import android.os.Bundle; 21 import android.os.SystemProperties; 22 import android.text.TextUtils; 23 import android.view.View; 24 import android.widget.Button; 25 import android.widget.TextView; 26 27 import com.android.setupwizardlib.util.WizardManagerHelper; 28 29 /** 30 * Activity that gives a user the choice to download the SIM app or defer until a later time 31 * 32 * Will finish with result {@link #DEFER_RESULT} on defer button press or {@link #DOWNLOAD_RESULT} 33 * if the download button is pressed 34 * 35 * Can display the carrier app name if its passed into the intent with key 36 * {@link #BUNDLE_KEY_CARRIER_NAME} 37 */ 38 public class InstallCarrierAppActivity extends Activity implements View.OnClickListener { 39 /** 40 * Key for the carrier app name that will be displayed as the app to download. If unset, a 41 * default description will be used 42 */ 43 public static final String BUNDLE_KEY_CARRIER_NAME = "carrier_name"; 44 /** Result code when the defer button is pressed */ 45 public static final int DEFER_RESULT = 1; 46 /** Result code when the download button is pressed */ 47 public static final int DOWNLOAD_RESULT = 2; 48 49 @Override onCreate(Bundle icicle)50 protected void onCreate(Bundle icicle) { 51 // Setup theme for aosp/pixel 52 setTheme( 53 WizardManagerHelper.getThemeRes( 54 SystemProperties.get("setupwizard.theme"), 55 R.style.SuwThemeGlif_Light 56 ) 57 ); 58 59 super.onCreate(icicle); 60 setContentView(R.layout.install_carrier_app_activity); 61 62 Button notNowButton = findViewById(R.id.skip_button); 63 notNowButton.setOnClickListener(this); 64 65 Button downloadButton = findViewById(R.id.download_button); 66 downloadButton.setOnClickListener(this); 67 68 // Include carrier name in description text if its present in the intent 69 Intent intent = getIntent(); 70 if (intent != null) { 71 String carrierName = intent.getStringExtra(BUNDLE_KEY_CARRIER_NAME); 72 if (!TextUtils.isEmpty(carrierName)) { 73 TextView subtitle = findViewById(R.id.install_carrier_app_description); 74 subtitle.setText(getString(R.string.install_carrier_app_description, carrierName)); 75 } 76 } 77 } 78 79 @Override onClick(View v)80 public void onClick(View v) { 81 switch (v.getId()) { 82 case R.id.skip_button: 83 finish(DEFER_RESULT); 84 break; 85 case R.id.download_button: 86 finish(DOWNLOAD_RESULT); 87 break; 88 } 89 } 90 finish(int resultCode)91 private void finish(int resultCode) { 92 setResult(resultCode); 93 finish(); 94 } 95 } 96