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.sysprop.SetupWizardProperties; 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 SetupWizardProperties.theme().orElse(""), 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 // Show/hide illo depending on whether one was provided in a resource overlay 69 boolean showIllo = getResources().getBoolean(R.bool.show_sim_app_dialog_illo); 70 View illoContainer = findViewById(R.id.illo_container); 71 illoContainer.setVisibility(showIllo ? View.VISIBLE : View.GONE); 72 73 // Include carrier name in description text if its present in the intent 74 Intent intent = getIntent(); 75 if (intent != null) { 76 String carrierName = intent.getStringExtra(BUNDLE_KEY_CARRIER_NAME); 77 if (!TextUtils.isEmpty(carrierName)) { 78 TextView subtitle = findViewById(R.id.install_carrier_app_description); 79 subtitle.setText(getString(R.string.install_carrier_app_description, carrierName)); 80 } 81 } 82 } 83 84 @Override onClick(View v)85 public void onClick(View v) { 86 switch (v.getId()) { 87 case R.id.skip_button: 88 finish(DEFER_RESULT); 89 break; 90 case R.id.download_button: 91 finish(DOWNLOAD_RESULT); 92 break; 93 } 94 } 95 finish(int resultCode)96 private void finish(int resultCode) { 97 setResult(resultCode); 98 finish(); 99 } 100 } 101