• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.settings.applications;
17 
18 import android.os.Bundle;
19 import android.view.LayoutInflater;
20 import android.view.Menu;
21 import android.view.MenuInflater;
22 import android.view.MenuItem;
23 import android.view.View;
24 import android.view.ViewGroup;
25 
26 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
27 import com.android.settings.R;
28 import com.android.settings.SettingsPreferenceFragment;
29 import com.android.settings.widget.LoadingViewController;
30 
31 public class RunningServices extends SettingsPreferenceFragment {
32 
33     private static final int SHOW_RUNNING_SERVICES = 1;
34     private static final int SHOW_BACKGROUND_PROCESSES = 2;
35 
36     private RunningProcessesView mRunningProcessesView;
37     private Menu mOptionsMenu;
38     private View mLoadingContainer;
39     private LoadingViewController mLoadingViewController;
40 
41     @Override
onCreate(Bundle savedInstanceState)42     public void onCreate(Bundle savedInstanceState) {
43         super.onCreate(savedInstanceState);
44 
45         setHasOptionsMenu(true);
46     }
47 
48     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)49     public View onCreateView(LayoutInflater inflater, ViewGroup container,
50             Bundle savedInstanceState) {
51         View rootView = inflater.inflate(R.layout.manage_applications_running, null);
52         mRunningProcessesView = rootView.findViewById(R.id.running_processes);
53         mRunningProcessesView.doCreate();
54         mLoadingContainer = rootView.findViewById(R.id.loading_container);
55         mLoadingViewController = new LoadingViewController(
56                 mLoadingContainer, mRunningProcessesView);
57 
58         return rootView;
59     }
60 
61     @Override
onCreateOptionsMenu(Menu menu, MenuInflater inflater)62     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
63         mOptionsMenu = menu;
64         menu.add(0, SHOW_RUNNING_SERVICES, 1, R.string.show_running_services)
65                 .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
66         menu.add(0, SHOW_BACKGROUND_PROCESSES, 2, R.string.show_background_processes)
67                 .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
68         updateOptionsMenu();
69     }
70 
71     @Override
onResume()72     public void onResume() {
73         super.onResume();
74         boolean haveData = mRunningProcessesView.doResume(this, mRunningProcessesAvail);
75         mLoadingViewController.handleLoadingContainer(haveData /* done */, false /* animate */);
76     }
77 
78     @Override
onPause()79     public void onPause() {
80         super.onPause();
81         mRunningProcessesView.doPause();
82     }
83 
84     @Override
onOptionsItemSelected(MenuItem item)85     public boolean onOptionsItemSelected(MenuItem item) {
86         switch (item.getItemId()) {
87             case SHOW_RUNNING_SERVICES:
88                 mRunningProcessesView.mAdapter.setShowBackground(false);
89                 break;
90             case SHOW_BACKGROUND_PROCESSES:
91                 mRunningProcessesView.mAdapter.setShowBackground(true);
92                 break;
93             default:
94                 return false;
95         }
96         updateOptionsMenu();
97         return true;
98     }
99 
100     @Override
onPrepareOptionsMenu(Menu menu)101     public void onPrepareOptionsMenu(Menu menu) {
102         updateOptionsMenu();
103     }
104 
updateOptionsMenu()105     private void updateOptionsMenu() {
106         boolean showingBackground = mRunningProcessesView.mAdapter.getShowBackground();
107         mOptionsMenu.findItem(SHOW_RUNNING_SERVICES).setVisible(showingBackground);
108         mOptionsMenu.findItem(SHOW_BACKGROUND_PROCESSES).setVisible(!showingBackground);
109     }
110 
111     @Override
getMetricsCategory()112     public int getMetricsCategory() {
113         return MetricsEvent.RUNNING_SERVICES;
114     }
115 
116     private final Runnable mRunningProcessesAvail = new Runnable() {
117         @Override
118         public void run() {
119             mLoadingViewController.showContent(true /* animate */);
120         }
121     };
122 
123 }
124