• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 
17 package com.android.storagemanager.utils;
18 
19 import android.view.View;
20 import android.view.animation.Animation;
21 import android.view.animation.Animation.AnimationListener;
22 import android.view.animation.AnimationUtils;
23 
24 public class Utils {
25 
handleLoadingContainer( View loading, View doneLoading, boolean done, boolean animate)26     public static void handleLoadingContainer(
27             View loading, View doneLoading, boolean done, boolean animate) {
28         setViewShown(loading, !done, animate);
29         setViewShown(doneLoading, done, animate);
30     }
31 
setViewShown(final View view, boolean shown, boolean animate)32     private static void setViewShown(final View view, boolean shown, boolean animate) {
33         if (animate) {
34             Animation animation =
35                     AnimationUtils.loadAnimation(
36                             view.getContext(),
37                             shown ? android.R.anim.fade_in : android.R.anim.fade_out);
38             if (shown) {
39                 view.setVisibility(View.VISIBLE);
40             } else {
41                 animation.setAnimationListener(
42                         new AnimationListener() {
43                             @Override
44                             public void onAnimationStart(Animation animation) {}
45 
46                             @Override
47                             public void onAnimationRepeat(Animation animation) {}
48 
49                             @Override
50                             public void onAnimationEnd(Animation animation) {
51                                 view.setVisibility(View.GONE);
52                             }
53                         });
54             }
55             view.startAnimation(animation);
56         } else {
57             view.clearAnimation();
58             view.setVisibility(shown ? View.VISIBLE : View.GONE);
59         }
60     }
61 }
62