1 /* 2 * Copyright (C) 2023 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.packageinstaller; 18 19 import android.app.AlertDialog; 20 import android.app.Dialog; 21 import android.app.DialogFragment; 22 import android.content.DialogInterface; 23 import android.os.Bundle; 24 25 public class UnarchiveFragment extends DialogFragment implements 26 DialogInterface.OnClickListener { 27 28 @Override onCreateDialog(Bundle savedInstanceState)29 public Dialog onCreateDialog(Bundle savedInstanceState) { 30 String appTitle = getArguments().getString(UnarchiveActivity.APP_TITLE); 31 String installerTitle = getArguments().getString(UnarchiveActivity.INSTALLER_TITLE); 32 33 AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity()); 34 35 dialogBuilder.setTitle( 36 String.format(getContext().getString(R.string.unarchive_application_title), 37 appTitle, installerTitle)); 38 dialogBuilder.setMessage(R.string.unarchive_body_text); 39 40 dialogBuilder.setPositiveButton(R.string.restore, this); 41 dialogBuilder.setNegativeButton(android.R.string.cancel, this); 42 43 return dialogBuilder.create(); 44 } 45 46 @Override onClick(DialogInterface dialog, int which)47 public void onClick(DialogInterface dialog, int which) { 48 if (which == Dialog.BUTTON_POSITIVE) { 49 ((UnarchiveActivity) getActivity()).startUnarchive(); 50 } 51 } 52 53 @Override onDismiss(DialogInterface dialog)54 public void onDismiss(DialogInterface dialog) { 55 super.onDismiss(dialog); 56 if (isAdded()) { 57 getActivity().finish(); 58 } 59 } 60 } 61