Fix loading screens for manage and running apps
Also add loading screen to manage permissions as this can take a long time to load in some circumstances. Build loading screens into Utils and SettingsPreferenceFragment so that it can be easily used other places in the future. Change-Id: I7febd06695487e02ced793a9fd418051b5f0eab8
This commit is contained in:
36
res/layout/loading_container.xml
Normal file
36
res/layout/loading_container.xml
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2015 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/loading_container"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
|
<ProgressBar style="?android:attr/progressBarStyleLarge"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<TextView android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
|
android:text="@string/settings_safetylegal_activity_loading"
|
||||||
|
android:paddingTop="4dip"
|
||||||
|
android:singleLine="true" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@@ -52,25 +52,7 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout android:id="@+id/loading_container"
|
<include layout="@layout/loading_container" />
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:visibility="gone"
|
|
||||||
android:gravity="center">
|
|
||||||
|
|
||||||
<ProgressBar style="?android:attr/progressBarStyleLarge"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
|
|
||||||
<TextView android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:text="@string/settings_safetylegal_activity_loading"
|
|
||||||
android:paddingTop="4dip"
|
|
||||||
android:singleLine="true" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
|
@@ -29,25 +29,7 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<LinearLayout android:id="@+id/loading_container"
|
<include layout="@layout/loading_container" />
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:visibility="gone"
|
|
||||||
android:gravity="center">
|
|
||||||
|
|
||||||
<ProgressBar style="?android:attr/progressBarStyleLarge"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
|
|
||||||
<TextView android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:text="@string/settings_safetylegal_activity_loading"
|
|
||||||
android:paddingTop="4dip"
|
|
||||||
android:singleLine="true" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
|
@@ -29,20 +29,27 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<ListView android:id="@android:id/list"
|
<FrameLayout android:layout_height="0px"
|
||||||
style="@style/PreferenceFragmentListSinglePane"
|
android:layout_weight="1"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent">
|
||||||
android:layout_height="0px"
|
|
||||||
android:layout_weight="1"
|
<ListView android:id="@android:id/list"
|
||||||
android:paddingStart="@dimen/settings_side_margin"
|
style="@style/PreferenceFragmentListSinglePane"
|
||||||
android:paddingEnd="@dimen/settings_side_margin"
|
android:layout_width="match_parent"
|
||||||
android:paddingTop="@dimen/dashboard_padding_top"
|
android:layout_height="wrap_content"
|
||||||
android:paddingBottom="@dimen/dashboard_padding_bottom"
|
android:paddingStart="@dimen/settings_side_margin"
|
||||||
android:scrollbarStyle="@*android:integer/preference_fragment_scrollbarStyle"
|
android:paddingEnd="@dimen/settings_side_margin"
|
||||||
android:clipToPadding="false"
|
android:paddingTop="@dimen/dashboard_padding_top"
|
||||||
android:drawSelectorOnTop="false"
|
android:paddingBottom="@dimen/dashboard_padding_bottom"
|
||||||
android:elevation="@dimen/dashboard_category_elevation"
|
android:scrollbarStyle="@*android:integer/preference_fragment_scrollbarStyle"
|
||||||
android:scrollbarAlwaysDrawVerticalTrack="true" />
|
android:clipToPadding="false"
|
||||||
|
android:drawSelectorOnTop="false"
|
||||||
|
android:elevation="@dimen/dashboard_category_elevation"
|
||||||
|
android:scrollbarAlwaysDrawVerticalTrack="true" />
|
||||||
|
|
||||||
|
<include layout="@layout/loading_container" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
<TextView android:id="@android:id/empty"
|
<TextView android:id="@android:id/empty"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@@ -158,6 +158,11 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
|||||||
unregisterObserverIfNeeded();
|
unregisterObserverIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void showLoadingWhenEmpty() {
|
||||||
|
View loading = getView().findViewById(R.id.loading_container);
|
||||||
|
getListView().setEmptyView(loading);
|
||||||
|
}
|
||||||
|
|
||||||
public void registerObserverIfNeeded() {
|
public void registerObserverIfNeeded() {
|
||||||
if (!mIsDataSetObserverRegistered) {
|
if (!mIsDataSetObserverRegistered) {
|
||||||
if (mCurrentRootAdapter != null) {
|
if (mCurrentRootAdapter != null) {
|
||||||
|
@@ -39,8 +39,8 @@ import android.content.pm.ResolveInfo;
|
|||||||
import android.content.pm.Signature;
|
import android.content.pm.Signature;
|
||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
|
||||||
import android.content.res.Resources.NotFoundException;
|
import android.content.res.Resources.NotFoundException;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
@@ -74,6 +74,9 @@ import android.util.SparseArray;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.animation.Animation;
|
||||||
|
import android.view.animation.Animation.AnimationListener;
|
||||||
|
import android.view.animation.AnimationUtils;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TabWidget;
|
import android.widget.TabWidget;
|
||||||
|
|
||||||
@@ -1158,4 +1161,39 @@ public final class Utils {
|
|||||||
? R.string.launch_defaults_some
|
? R.string.launch_defaults_some
|
||||||
: R.string.launch_defaults_none);
|
: R.string.launch_defaults_none);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void handleLoadingContainer(View loading, View doneLoading, boolean done,
|
||||||
|
boolean animate) {
|
||||||
|
setViewShown(loading, !done, animate);
|
||||||
|
setViewShown(doneLoading, done, animate);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setViewShown(final View view, boolean shown, boolean animate) {
|
||||||
|
if (animate) {
|
||||||
|
Animation animation = AnimationUtils.loadAnimation(view.getContext(),
|
||||||
|
shown ? android.R.anim.fade_in : android.R.anim.fade_out);
|
||||||
|
if (shown) {
|
||||||
|
view.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
animation.setAnimationListener(new AnimationListener() {
|
||||||
|
@Override
|
||||||
|
public void onAnimationStart(Animation animation) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnimationRepeat(Animation animation) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnimationEnd(Animation animation) {
|
||||||
|
view.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
view.startAnimation(animation);
|
||||||
|
} else {
|
||||||
|
view.clearAnimation();
|
||||||
|
view.setVisibility(shown ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -358,6 +358,7 @@ public class ManageApplications extends InstrumentedFragment
|
|||||||
updateOptionsMenu();
|
updateOptionsMenu();
|
||||||
if (mApplications != null) {
|
if (mApplications != null) {
|
||||||
mApplications.resume(mSortOrder);
|
mApplications.resume(mSortOrder);
|
||||||
|
mApplications.updateLoading();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -746,17 +747,20 @@ public class ManageApplications extends InstrumentedFragment
|
|||||||
}
|
}
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
|
|
||||||
if (entries == null) {
|
if (mEntries.size() != 0
|
||||||
mManageApplications.mListContainer.setVisibility(View.INVISIBLE);
|
&& mManageApplications.mListContainer.getVisibility() != View.VISIBLE) {
|
||||||
mManageApplications.mLoadingContainer.setVisibility(View.VISIBLE);
|
Utils.handleLoadingContainer(mManageApplications.mLoadingContainer,
|
||||||
} else {
|
mManageApplications.mListContainer, true, true);
|
||||||
mManageApplications.mListContainer.setVisibility(View.VISIBLE);
|
|
||||||
mManageApplications.mLoadingContainer.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mManageApplications.setHasDisabled(hasDisabledApps());
|
mManageApplications.setHasDisabled(hasDisabledApps());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateLoading() {
|
||||||
|
Utils.handleLoadingContainer(mManageApplications.mLoadingContainer,
|
||||||
|
mManageApplications.mListContainer, mEntries.size() != 0, false);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean hasDisabledApps() {
|
private boolean hasDisabledApps() {
|
||||||
ArrayList<AppEntry> allApps = mSession.getAllApps();
|
ArrayList<AppEntry> allApps = mSession.getAllApps();
|
||||||
for (int i = 0; i < allApps.size(); i++) {
|
for (int i = 0; i < allApps.size(); i++) {
|
||||||
|
@@ -36,7 +36,6 @@ public class ManagePermissions extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
private static final String TAG = "ManagePermissions";
|
private static final String TAG = "ManagePermissions";
|
||||||
|
|
||||||
private boolean mLoadComplete;
|
|
||||||
private PermissionsInfo mPermissionsInfo;
|
private PermissionsInfo mPermissionsInfo;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -46,6 +45,13 @@ public class ManagePermissions extends SettingsPreferenceFragment
|
|||||||
mPermissionsInfo = new PermissionsInfo(getActivity(), this);
|
mPermissionsInfo = new PermissionsInfo(getActivity(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
|
showLoadingWhenEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
private void refreshUi() {
|
private void refreshUi() {
|
||||||
PreferenceScreen screen = getPreferenceScreen();
|
PreferenceScreen screen = getPreferenceScreen();
|
||||||
if (screen == null) {
|
if (screen == null) {
|
||||||
|
@@ -23,9 +23,9 @@ import android.view.MenuInflater;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.animation.AnimationUtils;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.Utils;
|
||||||
|
|
||||||
public class RunningServices extends Fragment {
|
public class RunningServices extends Fragment {
|
||||||
|
|
||||||
@@ -69,12 +69,7 @@ public class RunningServices extends Fragment {
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
boolean haveData = mRunningProcessesView.doResume(this, mRunningProcessesAvail);
|
boolean haveData = mRunningProcessesView.doResume(this, mRunningProcessesAvail);
|
||||||
if (haveData) {
|
Utils.handleLoadingContainer(mLoadingContainer, mRunningProcessesView, haveData, false);
|
||||||
mRunningProcessesView.setVisibility(View.VISIBLE);
|
|
||||||
mLoadingContainer.setVisibility(View.INVISIBLE);
|
|
||||||
} else {
|
|
||||||
mLoadingContainer.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -110,19 +105,10 @@ public class RunningServices extends Fragment {
|
|||||||
mOptionsMenu.findItem(SHOW_BACKGROUND_PROCESSES).setVisible(!showingBackground);
|
mOptionsMenu.findItem(SHOW_BACKGROUND_PROCESSES).setVisible(!showingBackground);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleRunningProcessesAvail() {
|
|
||||||
mLoadingContainer.startAnimation(AnimationUtils.loadAnimation(getActivity(),
|
|
||||||
android.R.anim.fade_out));
|
|
||||||
mRunningProcessesView.startAnimation(AnimationUtils.loadAnimation(getActivity(),
|
|
||||||
android.R.anim.fade_in));
|
|
||||||
mRunningProcessesView.setVisibility(View.VISIBLE);
|
|
||||||
mLoadingContainer.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Runnable mRunningProcessesAvail = new Runnable() {
|
private final Runnable mRunningProcessesAvail = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
handleRunningProcessesAvail();
|
Utils.handleLoadingContainer(mLoadingContainer, mRunningProcessesView, true, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user