Skip to content

Commit

Permalink
Class to control showing and hiding of activity indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
slogan621 committed Mar 26, 2021
1 parent ae72031 commit 54ed5e8
Showing 1 changed file with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* (C) Copyright Syd Logan 2021
* (C) Copyright Thousand Smiles Foundation 2021
*
* 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.
*/

package org.thousandsmiles.tscharts_lib;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.view.View;
import android.widget.Toast;

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public class ShowProgress {
public void showProgress(final Activity activity, final View outer, final View progress, final boolean show) {
// On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
// for very easy animations. If available, use these APIs to fade-in
// the progress spinner.
activity.runOnUiThread(new Runnable() {
public void run() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
int shortAnimTime = activity.getResources().getInteger(android.R.integer.config_shortAnimTime);

if (outer != null) {
outer.setVisibility(show ? View.GONE : View.VISIBLE);
outer.animate().setDuration(shortAnimTime).alpha(
show ? 0 : 1).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
outer.setVisibility(show ? View.GONE : View.VISIBLE);
}
});
}

progress.setVisibility(show ? View.VISIBLE : View.GONE);
progress.animate().setDuration(shortAnimTime).alpha(
show ? 1 : 0).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
progress.setVisibility(show ? View.VISIBLE : View.GONE);
}
});
} else {
// The ViewPropertyAnimator APIs are not available, so simply show
// and hide the relevant UI components.
progress.setVisibility(show ? View.VISIBLE : View.GONE);
if (outer != null) {
outer.setVisibility(show ? View.GONE : View.VISIBLE);
}
}
}
});
}
}

0 comments on commit 54ed5e8

Please sign in to comment.