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.v2.ui.fragments;
18 
19 import android.app.AlertDialog;
20 import android.app.Dialog;
21 import android.content.DialogInterface;
22 import android.os.Bundle;
23 import android.util.Log;
24 import android.view.View;
25 import android.widget.ProgressBar;
26 import androidx.annotation.NonNull;
27 import androidx.annotation.Nullable;
28 import androidx.fragment.app.DialogFragment;
29 import com.android.packageinstaller.R;
30 
31 public class InstallStagingFragment extends DialogFragment {
32 
33     private static final String LOG_TAG = InstallStagingFragment.class.getSimpleName();
34     private ProgressBar mProgressBar;
35     private AlertDialog mDialog;
36 
37     @NonNull
38     @Override
onCreateDialog(@ullable Bundle savedInstanceState)39     public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
40         Log.i(LOG_TAG, "Creating " + LOG_TAG);
41         View dialogView = getLayoutInflater().inflate(R.layout.install_content_view, null);
42         dialogView.requireViewById(R.id.staging).setVisibility(View.VISIBLE);
43 
44         mDialog = new AlertDialog.Builder(requireContext())
45             .setTitle(getString(R.string.app_name_unknown))
46             .setIcon(R.drawable.ic_file_download)
47             .setView(dialogView)
48             .setNegativeButton(R.string.cancel, null)
49             .setCancelable(false)
50             .create();
51 
52         mDialog.setCanceledOnTouchOutside(false);
53         return mDialog;
54     }
55 
56     @Override
onStart()57     public void onStart() {
58         super.onStart();
59         mDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setEnabled(false);
60         mProgressBar = mDialog.requireViewById(R.id.progress_indeterminate);
61         mProgressBar.setProgress(0);
62         mProgressBar.setMax(100);
63         mProgressBar.setIndeterminate(false);
64     }
65 
setProgress(int progress)66     public void setProgress(int progress) {
67         if (mProgressBar != null) {
68             mProgressBar.setProgress(progress);
69         }
70     }
71 }
72