有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

安卓 studio活动之间的java进度条

我知道还有其他帖子在讨论这个问题,但它们对我的情况没有帮助。我有一个按钮列表,每个按钮都指向不同的mapActivity。目前,我的灵感来自Android Studio为LoginActivity编写的代码,它也有一个ProgressBar。按钮列表消失,progressBar开始显示,但由于HomeActivity而停止。onPause启动,onCreate of myMap活动也启动,但应用程序在被阻止的进度栏上被冻结。过了一会儿,我的地图显示出来了。在此期间,我如何使进度条旋转

package com.example.florian.myapplication.Activities;

import 安卓.animation.Animator;
import 安卓.animation.AnimatorListenerAdapter;
import 安卓.annotation.TargetApi;
import 安卓.content.ActivityNotFoundException;
import 安卓.content.Intent;
import 安卓.database.Cursor;
import 安卓.os.AsyncTask;
import 安卓.os.Build;
import 安卓.support.v7.app.AppCompatActivity;
import 安卓.os.Bundle;
import 安卓.util.Log;
import 安卓.view.View;
import 安卓.widget.Button;
import 安卓.widget.LinearLayout;
import 安卓.widget.ProgressBar;

import com.example.florian.myapplication.Activities.MapsActivities.MainActivity;
import com.example.florian.myapplication.Activities.MapsActivities.MainActivityRec;
import com.example.florian.myapplication.Activities.MapsActivities.MainActivityRel;
import com.example.florian.myapplication.R;

public class HomeActivity extends AppCompatActivity {

    private ChangeActivityTask changeTask;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        Button obsPonctButton = (Button) findViewById(R.id.obs_ponc_button);
        obsPonctButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showProgress(true);
                changeTask = new ChangeActivityTask(false);
                changeTask.execute((Void) null);
            }
        });

        Button protocoleButton = (Button) findViewById(R.id.protocole_button);
        protocoleButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showProgress(true);
                changeTask = new ChangeActivityTask(false);
                changeTask.execute((Void) null);
            }
        });

        Button releveBouton = (Button) findViewById(R.id.relevé_button);
        releveBouton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showProgress(true);
                changeTask = new ChangeActivityTask(false);
                changeTask.execute((Void) null);
            }
        });

        Button syncButton = (Button) findViewById(R.id.sync_button);
        syncButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                synchroniserMission();
            }
        });
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        showProgress(false);
    }

    public Intent generateIntent (boolean isReleveActivity){
        Intent intent;
        if(isReleveActivity)
            intent = new Intent(HomeActivity.this,MainActivityRel.class);
        else
            intent = new Intent(HomeActivity.this,MainActivityRec.class);
        return intent;
    }

    /**
     * Shows the progress UI and hides the login form.
     */
    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
    private void showProgress(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.
        final LinearLayout buttonList = (LinearLayout) findViewById(R.id.buttonList);
        final ProgressBar mProgressView = (ProgressBar) findViewById(R.id.action_progress);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
            int shortAnimTime = getResources().getInteger(安卓.R.integer.config_shortAnimTime);

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

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

    @Override
    protected void onPause() {
        super.onPause();
        Log.w("Bienvenue", "dans le onpause");
    }

    private void synchroniserMission(){

    }
    public class ChangeActivityTask extends AsyncTask<Void, Void, Boolean> {

        private final boolean isReleveActivity;

        private Intent intent;

        ChangeActivityTask(boolean isReleveActivity) {
            this.isReleveActivity = isReleveActivity;
        }

        @Override
        protected Boolean doInBackground(Void... params) {
            // TODO: attempt authentication against a network service.
            intent = generateIntent(isReleveActivity);
            startActivity(intent);
            return true;
        }

        @Override
        protected void onPostExecute(final Boolean success) {
            showProgress(false);
        }

        @Override
        protected void onCancelled() {
            showProgress(false);
        }


    }
}

我希望我说清楚了,你能帮我扔这个


共 (0) 个答案