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