1 /* 2 * Copyright (C) 2016 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.television; 18 19 import android.app.Fragment; 20 import android.content.Intent; 21 import android.os.Bundle; 22 import android.provider.Settings; 23 import android.util.Log; 24 import android.view.LayoutInflater; 25 import android.view.View; 26 import android.view.ViewGroup; 27 import android.widget.Button; 28 import android.widget.TextView; 29 30 import androidx.annotation.Nullable; 31 32 import com.android.packageinstaller.PackageUtil; 33 import com.android.packageinstaller.R; 34 35 public class UninstallAppProgressFragment extends Fragment implements View.OnClickListener, 36 UninstallAppProgress.ProgressFragment { 37 private static final String TAG = "UninstallAppProgressF"; // full class name is too long 38 39 private Button mOkButton; 40 private Button mDeviceManagerButton; 41 private Button mUsersButton; 42 43 @Override onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState)44 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, 45 Bundle savedInstanceState) { 46 final View root = inflater.inflate(R.layout.uninstall_progress, container, false); 47 // Initialize views 48 View snippetView = root.findViewById(R.id.app_snippet); 49 PackageUtil.initSnippetForInstalledApp(getContext(), 50 ((UninstallAppProgress)getActivity()).getAppInfo(), snippetView); 51 mDeviceManagerButton = (Button) root.findViewById(R.id.device_manager_button); 52 mUsersButton = (Button) root.findViewById(R.id.users_button); 53 mDeviceManagerButton.setVisibility(View.GONE); 54 mDeviceManagerButton.setOnClickListener(new View.OnClickListener() { 55 @Override 56 public void onClick(View v) { 57 Intent intent = new Intent(); 58 intent.setClassName("com.android.settings", 59 "com.android.settings.Settings$DeviceAdminSettingsActivity"); 60 intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_NEW_TASK); 61 startActivity(intent); 62 getActivity().finish(); 63 } 64 }); 65 mUsersButton.setVisibility(View.GONE); 66 mUsersButton.setOnClickListener(new View.OnClickListener() { 67 @Override 68 public void onClick(View v) { 69 Intent intent = new Intent(Settings.ACTION_USER_SETTINGS); 70 intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_NEW_TASK); 71 startActivity(intent); 72 getActivity().finish(); 73 } 74 }); 75 // Hide button till progress is being displayed 76 mOkButton = (Button) root.findViewById(R.id.ok_button); 77 mOkButton.setOnClickListener(this); 78 79 return root; 80 } 81 onClick(View v)82 public void onClick(View v) { 83 final UninstallAppProgress activity = (UninstallAppProgress) getActivity(); 84 if(v == mOkButton && activity != null) { 85 Log.i(TAG, "Finished uninstalling pkg: " + 86 activity.getAppInfo().packageName); 87 activity.setResultAndFinish(); 88 } 89 } 90 91 @Override setUsersButtonVisible(boolean visible)92 public void setUsersButtonVisible(boolean visible) { 93 mUsersButton.setVisibility(visible ? View.VISIBLE : View.GONE); 94 } 95 96 @Override setDeviceManagerButtonVisible(boolean visible)97 public void setDeviceManagerButtonVisible(boolean visible) { 98 mDeviceManagerButton.setVisibility(visible ? View.VISIBLE : View.GONE); 99 } 100 101 @Override showCompletion(CharSequence statusText)102 public void showCompletion(CharSequence statusText) { 103 final View root = getView(); 104 root.findViewById(R.id.progress_view).setVisibility(View.GONE); 105 root.findViewById(R.id.status_view).setVisibility(View.VISIBLE); 106 ((TextView) root.findViewById(R.id.status_text)).setText(statusText); 107 root.findViewById(R.id.ok_panel).setVisibility(View.VISIBLE); 108 } 109 } 110