AndroidJava– 删除顺序加载动画延迟

AndroidJava– 删除顺序加载动画延迟,第1张

概述我有一个android动画,它加载了一系列顺序点(publishProgress),但是在它们启动之前有10秒的延迟因为我将它们作为我的AsyncTask的一部分,它在数据处理时加载(技术上–两者应该是相关的)–但它在视觉上会导致延迟)如何在课程首次启动时调用此动画?我需要删除这个可视动画延迟.资

我有一个android动画,它加载了一系列顺序点(publishProgress),但是在它们启动之前有10秒的延迟因为我将它们作为我的AsyncTask的一部分,它在数据处理时加载(技术上 – 两者应该是相关的) – 但它在视觉上会导致延迟)如何在课程首次启动时调用此动画?我需要删除这个可视动画延迟.

资源:

public class UpdateActivity extends Activity implements OnClickListener {    private TelephonyManager tm;    AlertDialog mConfirmAlert = null;    NetworkTask task;    ImageVIEw image, text;    AlertDialog mErrorAlert = null;    public static ArrayList<String> nameArr = new ArrayList<String>();    public static ArrayList<String> ValueArr = new ArrayList<String>();    public static ArrayList<String> nameArr = new ArrayList<String>();    public static ArrayList<String> ApnArr = new ArrayList<String>();    public static ArrayList<String> mmscArr = new ArrayList<String>();    public static ArrayList<String> mmsportArr = new ArrayList<String>();    public static ArrayList<String> mmsproxyArr = new ArrayList<String>();    public static ArrayList<String> portArr = new ArrayList<String>();    public static ArrayList<String> proxyArr = new ArrayList<String>();    private ImageVIEw mProgressImagevIEw1;    private ImageVIEw mProgressImagevIEw2;    private ImageVIEw mProgressImagevIEw3;    private ImageVIEw mProgressImagevIEw4;    private ImageVIEw mProgressImagevIEw5;      private button mUpdatebutton = null;    private button mAssistUpdatebutton = null;    private button mAssistInstrbutton = null;    private TextVIEw mReadAgainbutton = null;    public static int count;    public AnimationDrawable mTextAnimation = null;    private button assist_update_btn = null;    TextVIEw mUpdatetext;    public static inputStream stream = null;    int version;    public static BigInteger ID1, ID2, mdN1, mdN2;    BigInteger[] ID, mdnID;    public static String iccid, MDN;    private int mInstructionNumber = 0;    public static String caR, result;    private static final String LOG_TAG = "DataSettings";    public static final String Base_URL = "https://apps.example.com/REST/phonesettings";    public static XmlParserHandlerFinal handler;    public static int TotalSteps = 8;    public fileinputStream fis;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        // instance for xml parser class        handler = new XmlParserHandlerFinal();        handler.setContext(this.getBaseContext());        tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);        int networkType = tm.getNetworkType();        int phoneType = tm.getPhoneType();        version = androID.os.Build.VERSION.SDK_INT;        // to get MDN(MCC+MNC) of the provIDer of the SIM and iccid (Serial        // number of the SIM)        // and to check for the CarrIEr type        getImpVariablesForquery();        task = new NetworkTask();        if (phoneType == TelephonyManager.PHONE_TYPE_CDMA                || (phoneType != TelephonyManager.PHONE_TYPE_GSM                        && networkType != TelephonyManager.NETWORK_TYPE_GPRS                        && networkType != TelephonyManager.NETWORK_TYPE_EDGE                        && networkType != TelephonyManager.NETWORK_TYPE_HSDPA                        && networkType != TelephonyManager.NETWORK_TYPE_HSPA                        && networkType != TelephonyManager.NETWORK_TYPE_HSPAP                        && networkType != TelephonyManager.NETWORK_TYPE_HSUPA                        && networkType != TelephonyManager.NETWORK_TYPE_umts && networkType != TelephonyManager.NETWORK_TYPE_LTE)) {            // If the phone type is CDMA or            // the phone phone type is not GSM and the network type is none of            // the network types indicated in the statement            // display incompatibility message            showAlert(getString(R.string.incomp_sm_dialog));            // Network type is looked because some tablets have no phone type.            // We rely on network type in such cases        } else if (!(tm.getSimstate() == TelephonyManager.SIM_STATE_ABSENT                || (tm.getSimOperator())                        .equals(getString(R.string.numeric_tmo)) || (tm                    .getSimOperator()).equals(getString(R.string.numeric_att)))) {            // if SIM is present and is NOT a T-Mo or ATT network SIM,            // display Error message alert indicating to use SM SIM            showAlert(getString(R.string.insert_sm_dialog));        }// No SIM or SIM with T-Mo & ATT MNC MCC present        else if ((tm.getSimOperator()).equals(getString(R.string.numeric_tmo))                || (tm.getSimOperator())                        .equals(getString(R.string.numeric_att))) {            // Device has T-Mo or ATT network SIM card MCC and MNC correctly            // populated            TotalSteps = 6;            setContentVIEw(R.layout.updating);            // AsyncTask to call the web service            task = new NetworkTask();            task.execute("");        }    }    public voID onClick(VIEw v) {        if (v == mUpdatebutton) {            // Update button for versions lower than ICS is selected            onClickMethod(v);            Intent i = new Intent(this, ConfigFinalActivity.class);            startActivity(i);            finish();        } else        if (v.getID() == R.ID.assist_update_btn) {            // Update button for ICS and up is selected            // Get the TextVIEw in the Assist Update UI            TextVIEw tv = (TextVIEw) findVIEwByID(R.ID.apn_app_text_cta2);            String text = "";            CharSequence styledText = text;            switch (mInstructionNumber) {            case 0:                // RetrIEve the instruction string resource corresponding the                // 2nd set of instructions                text = String.format(getString(R.string.apn_app_text_instr),                        TotalSteps);                styledText = HTML.fromHTML(text);                // Update the TextVIEw with the correct set of instructions                tv.setText(styledText);                // Increment instruction number so the correct instructions                // string resource can be retrIEve the next time the update                // button is pressed                mInstructionNumber++;                break;            case 1:                text = getString(R.string.apn_app_text_instr2);                styledText = HTML.fromHTML(text);                tv.setText(styledText);                // Increment instruction number so the correct instructions                // string resource can be retrIEve the next time the update                // button is pressed                mInstructionNumber++;                break;            case 2:                // Final set of instructions-Change to the corresponding layout                setContentVIEw(R.layout.assist_instructions);                String assistUpdateInstr = String.format(                        getString(R.string.apn_app_text_instr3), TotalSteps);                styledText = HTML.fromHTML(assistUpdateInstr);                TextVIEw assistInstrText = (TextVIEw) findVIEwByID(R.ID.updated_text);                assistInstrText.setText(styledText);                mAssistInstrbutton = (button) findVIEwByID(R.ID.assist_instr_btn);                mReadAgainbutton = (TextVIEw) findVIEwByID(R.ID.read_again_btn);                mAssistInstrbutton.setonClickListener(this);                mReadAgainbutton.setonClickListener(this);            }        } else if (v == mAssistInstrbutton) {            // "LET'S DO THIS" button in final instructions screen for ICS and            // up is selected            // Create ConfigActivity Intent            Intent i = new Intent(this, ConfigFinalActivity.class);            // Invoke ConfigActivity Intent to start the assisted update            startActivity(i);            startActivity(new Intent(Settings.ACTION_APN_SETTINGS));        } else if (v == mReadAgainbutton) {            // go back to 1st set of instructions if read again is selected            mInstructionNumber = 0;            setContentVIEw(R.layout.assist_update);            String assistUpdate = getString(R.string.apn_app_text_cta2);            CharSequence styledText = HTML.fromHTML(assistUpdate);            TextVIEw assistText = (TextVIEw) findVIEwByID(R.ID.apn_app_text_cta2);            assistText.setText(styledText);            mAssistUpdatebutton = (button) findVIEwByID(R.ID.assist_update_btn);            mAssistUpdatebutton.setonClickListener(this);        }    }    public voID onClickMethod(VIEw v) {        mUpdatebutton = (button) findVIEwByID(R.drawable.btn_update_active_hdpi);    }    private voID showAlert(String message) {        AlertDialog.Builder builder = new AlertDialog.Builder(this);        builder.setMessage(message).setPositivebutton("OK",                new DialogInterface.OnClickListener() {                    public voID onClick(DialogInterface dialog, int ID) {                        UpdateActivity.this.finish();                    }                });        mConfirmAlert = builder.create();        mConfirmAlert.show();    }    private voID getImpVariablesForquery() {        long d = 1234;        BigInteger divisor = BigInteger.valueOf(d);        // to get MDN    //  MDN = tm.getline1Number();        MDN = "3055861092";        if (MDN.equals("")) {            mdN1 = null;            mdN2 = null;        } else {            Log.d("MDN", MDN);            BigInteger bInt = new BigInteger(MDN);            mdnID = bInt.divIDeAndRemainder(divisor);            // to retrIEve iccid number of the SIM            mdN1 = mdnID[1];            System.out.println("MDN%1234 = " + mdN1);            mdN2 = mdnID[0];            System.out.println("MDN/1234 = " + mdN2);        }        iccid = tm.getSimserialNumber();        if (iccid.equals("")) {            ID1 = null;            ID2 = null;        } else {            Log.d("iccid", iccid);            BigInteger bInteger = new BigInteger(iccid);            ID = bInteger.divIDeAndRemainder(divisor);            ID1 = ID[1];            System.out.println("iccid%1234 = " + ID1);            ID2 = ID[0];            System.out.println("iccid/1234 = " + ID2);        }        // Check for the CarrIEr Type        if ((tm.getSimOperator()).equals(getString(R.string.numeric_tmo))) {            caR = "TMO";        } else if ((tm.getSimOperator())                .equals(getString(R.string.numeric_att))) {            caR = "ATT";        }    }    // method to save the ArrayLists from parser    public static voID setArrayList() {        nameArr = handler.getnameArr();        ApnArr = handler.getApnArr();        mmscArr = handler.getMMSCArr();        mmsproxyArr = handler.getMmscProxyArr();        mmsportArr = handler.getMmsPortArr();        proxyArr = handler.getProxyArr();        portArr = handler.getPortArr();        count = handler.getCount();        result = handler.getResult();    }    public ArrayList<String> getnameArr() {        return nameArr;    }    public ArrayList<String> getApnArr() {        return ApnArr;    }    public ArrayList<String> getMMSCArr() {        return mmscArr;    }    public ArrayList<String> getMmscProxyArr() {        return mmsproxyArr;    }    public ArrayList<String> getMmsPortArr() {        return mmsportArr;    }    public int getCount() {        return count;    }    public ArrayList<String> getProxyArr() {        return proxyArr;    }    public ArrayList<String> getPortArr() {        return portArr;    }    // AsyncTask to call web service    public class NetworkTask extends AsyncTask<String, Integer, inputStream> {        @OverrIDe        protected voID onPreExecute() {            super.onPreExecute();            //        }        @OverrIDe        protected inputStream doInBackground(String... params) {            int result = 0;            {                Log.i("url...", Base_URL);                try {                    stream = getqueryResults(Base_URL);                } catch (SocketTimeoutException e1) {                    // Todo auto-generated catch block                    e1.printstacktrace();                } catch (SSLException e1) {                    // Todo auto-generated catch block                    e1.printstacktrace();                } catch (IOException e1) {                    // Todo auto-generated catch block                    e1.printstacktrace();                } catch (SAXException e1) {                    // Todo auto-generated catch block                    e1.printstacktrace();                } catch (Exception e1) {                    // Todo auto-generated catch block                    e1.printstacktrace();                }                // The code below plays a ST Promo animation                // prior to displaying update success or failure message                for (int incr = 0; incr < 2; incr++) {                    // Sleep for 1/2 second                    // Invoke UI to change updating text to show 1 dot                    // And Increasing the level to reduce the amount of clipPing                    // and                    // slowly reveals the hand image                    publishProgress(R.drawable.loading_full,                            R.drawable.loading_empty, R.drawable.loading_empty,                            R.drawable.loading_empty, R.drawable.loading_empty);                    try {                        Thread.sleep(500);                    } catch (InterruptedException e) {                        // Todo auto-generated catch block                    }                    publishProgress(R.drawable.loading_full,                            R.drawable.loading_full, R.drawable.loading_empty,                            R.drawable.loading_empty, R.drawable.loading_empty);                    try {                        Thread.sleep(500);                    } catch (InterruptedException e) {                        // Todo auto-generated catch block                    }                    publishProgress(R.drawable.loading_full,                            R.drawable.loading_full, R.drawable.loading_full,                            R.drawable.loading_empty, R.drawable.loading_empty);                    try {                        Thread.sleep(500);                    } catch (InterruptedException e) {                        // Todo auto-generated catch block                    }                    publishProgress(R.drawable.loading_full,                            R.drawable.loading_full, R.drawable.loading_full,                            R.drawable.loading_full, R.drawable.loading_empty);                    try {                        Thread.sleep(500);                    } catch (InterruptedException e) {                        // Todo auto-generated catch block                    }                    publishProgress(R.drawable.loading_full,                            R.drawable.loading_full, R.drawable.loading_full,                            R.drawable.loading_full, R.drawable.loading_full);                    // Sleep for 1/2 second                    try {                        Thread.sleep(500);                    } catch (InterruptedException e) {                        // Todo auto-generated catch block                    }                }                    return stream;            }        }        /*         * Sends a query to server and gets back the parsed results in a bundle         * urlqueryString - URL for calling the webservice         */        protected synchronized inputStream getqueryResults(String urlqueryString)                throws IOException, SAXException, SSLException,                SocketTimeoutException, Exception {            try {                // httpsURLConnection https = null;                String uri = urlqueryString;                List<nameValuePair> nameValuePairs = new ArrayList<nameValuePair>();                BasicnameValuePair mdn1, mdn2,ID1,ID2;                if (MDN.equals("")) {                    mdn1 = new BasicnameValuePair("mdn1", null);                    mdn2 = new BasicnameValuePair("mdn2", null);                } else {                    mdn1 = new BasicnameValuePair("mdn1", mdN1.toString());                    mdn2 = new BasicnameValuePair("mdn2", mdN2.toString());                }                BasicnameValuePair car = new BasicnameValuePair("car", caR);                if (iccid.equals("")) {                     ID1 = new BasicnameValuePair("ID1", null);                     ID2 = new BasicnameValuePair("ID2", null);                } else {                     ID1 = new BasicnameValuePair("ID1",                            ID1.toString());                     ID2 = new BasicnameValuePair("ID2",                            ID2.toString());                }                nameValuePairs.add(mdn1);                nameValuePairs.add(mdn2);                nameValuePairs.add(car);                nameValuePairs.add(ID1);                nameValuePairs.add(ID2);                UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(                        nameValuePairs, "ISO-8859-1");                KeyStore trustStore = KeyStore.getInstance(KeyStore                        .getDefaultType());                trustStore.load(null, null);                SSLSocketFactory sf = new MySSLSocketFactory(trustStore);                sf.setHostnameVerifIEr(SSLSocketFactory.ALLOW_ALL_HOSTname_VERIFIER);                httpParams params = new BasichttpParams();                httpProtocolParams.setVersion(params, httpVersion.http_1_1);                httpProtocolParams.setContentCharset(params, http.UTF_8);                SchemeRegistry registry = new SchemeRegistry();                registry.register(new Scheme("http", PlainSocketFactory                        .getSocketFactory(), 80));                registry.register(new Scheme("https", sf, 443));                ClIEntConnectionManager ccm = new ThreadSafeClIEntConnManager(                        params, registry);                httpClIEnt httpClIEnt = new DefaulthttpClIEnt(ccm, params);                params = httpClIEnt.getParams();                httpClIEntParams.setRedirecting(params, true);                httpPost httpPost = new httpPost(uri);                httpPost.addheader("Authorization",                        getB64Auth("nmundru", "abc123"));                httpPost.setheader("Content-Type", "text/plain; charset=utf-8");                Log.v("httpPost", httpPost.toString());                httpPost.setEntity(urlEncodedFormEntity);                httpResponse httpResponse = httpClIEnt.execute(httpPost);                System.out.println("response...." + httpResponse.toString());                Log.v("response...", httpResponse.toString());                stream = httpResponse.getEntity().getContent();                // save the inputStream in a file                try {                    fileOutputStream fOut = openfileOutput("settings.xml",                            Context.MODE_WORLD_READABLE);                    DatainputStream in = new DatainputStream(stream);                    BufferedReader br = new BufferedReader(                            new inputStreamReader(in));                    String strline;                    while ((strline = br.readline()) != null) {                         System.out.println(strline); //to print the response                        // in logcat                        fOut.write(strline.getBytes());                    }                    fOut.close();                } catch (fileNotFoundException e) {                    e.printstacktrace();                } catch (IOException e) {                    e.printstacktrace();                }                fis = openfileinput("settings.xml");            } catch (Exception e) {                Log.e(LOG_TAG, e.toString());            //  tryagain();            } finally {                // https.disconnect();            }            return stream;        }        private String getB64Auth(String login, String pass) {            String source = login + ":" + pass;            String ret = "Basic "                    + Base64.encodetoString(source.getBytes(), Base64.URL_SAFE                            | Base64.NO_WRAP);            return ret;        }        @OverrIDe        protected voID onPostExecute(inputStream stream) {            super.onPostExecute(stream);            // This method is called to parse the response and save the            // ArrayLists            success();        }        public voID success() {            // to parse the response            try {                handler.getqueryResponse(fis);            } catch (SAXException e) {                // Todo auto-generated catch block                e.printstacktrace();            } catch (IOException e) {                // Todo auto-generated catch block                e.printstacktrace();            }            // set method to save the ArryaLists from the parser            setArrayList();            Intent i = new Intent(UpdateActivity.this, ConfigFinalActivity.class);            startActivity(i);            finish();        }        // Framework UI thread method corresponding to publishProgress call in        // worker thread        protected voID onProgressUpdate(Integer... progress) {            // Call function to update image vIEw            setProgressimgVIEw(progress[0], progress[1], progress[2],                    progress[3], progress[4]);        }    }    private voID setProgressimgVIEw(Integer imgVIEwID1, Integer imgVIEwID2,            Integer imgVIEwID3, Integer imgVIEwID4, Integer imgVIEwID5) {        // update image vIEw with the updating dots        // reset vIEw layout in case orIEntation while updating        setContentVIEw(R.layout.updating);        mProgressImagevIEw1 = (ImageVIEw) findVIEwByID(R.ID.loading_empty1);        mProgressImagevIEw2 = (ImageVIEw) findVIEwByID(R.ID.loading_empty2);        mProgressImagevIEw3 = (ImageVIEw) findVIEwByID(R.ID.loading_empty3);        mProgressImagevIEw4 = (ImageVIEw) findVIEwByID(R.ID.loading_empty4);        mProgressImagevIEw5 = (ImageVIEw) findVIEwByID(R.ID.loading_empty5);        mProgressImagevIEw1.setimageResource(imgVIEwID1);        mProgressImagevIEw2.setimageResource(imgVIEwID2);        mProgressImagevIEw3.setimageResource(imgVIEwID3);        mProgressImagevIEw4.setimageResource(imgVIEwID4);        mProgressImagevIEw5.setimageResource(imgVIEwID5);    }    @OverrIDe    protected voID onRestart() {        super.onRestart();        if (mErrorAlert != null)            mErrorAlert.dismiss();    }    public voID tryagain() {        // displaying final layout after failure of pre-ICS automatic settings        // update        setContentVIEw(R.layout.tryagain);        String tryAgainText = "";        CharSequence styledTryAgainText;        tryAgainText = String.format(getString(R.string.tryagain_text1),                TotalSteps);        styledTryAgainText = HTML.fromHTML(tryAgainText);        TextVIEw tryAgain1 = (TextVIEw) findVIEwByID(R.ID.tryagain_text1);        tryAgain1.setText(styledTryAgainText);        tryAgainText = String.format(getString(R.string.tryagain_text2),                TotalSteps);        styledTryAgainText = HTML.fromHTML(tryAgainText);        TextVIEw tryAgain2 = (TextVIEw) findVIEwByID(R.ID.tryagain_text2);        tryAgain2.setText(styledTryAgainText);        tryAgainText = String.format(getString(R.string.tryagain_text3),                TotalSteps);        styledTryAgainText = HTML.fromHTML(tryAgainText);        TextVIEw tryAgain3 = (TextVIEw) findVIEwByID(R.ID.tryagain_text3);        tryAgain3.setText(styledTryAgainText);    }    private voID assistUpdate() {        // displaying final layout after pre-ICS automatic settings update        setContentVIEw(R.layout.assist_update);        assist_update_btn = (button) findVIEwByID(R.ID.assist_update_btn);        assist_update_btn.setonClickListener((OnClickListener) this);    }    public voID success() {        // to parse the response        try {            handler.getqueryResponse(fis);        } catch (SAXException e) {            // Todo auto-generated catch block            e.printstacktrace();        } catch (IOException e) {            // Todo auto-generated catch block            e.printstacktrace();        }        // set method to save the ArryaLists from the parser        setArrayList();        Intent i = new Intent(this, ConfigFinalActivity.class);        startActivity(i);        finish();    }    public String getResult() {        return result;    }}

解决方法:

您可以使用AsyncTask中的onPreExecute()和onPostExecute()方法在工作完成之后设置加载/删除它.

尝试:

protected voID onPreExecute() {           setProgressimgVIEw(R.drawable.loading_full,                            R.drawable.loading_empty, R.drawable.loading_empty,                            R.drawable.loading_empty, R.drawable.loading_empty);}protected voID onPostExecute(inputStream stream) {           setProgressimgVIEw(R.drawable.loading_full,                        R.drawable.loading_full, R.drawable.loading_full,                        R.drawable.loading_full, R.drawable.loading_full);    // This method is called to parse the response and save the    // ArrayLists    success();}
总结

以上是内存溢出为你收集整理的Android / Java – 删除顺序加载动画延迟全部内容,希望文章能够帮你解决Android / Java – 删除顺序加载动画延迟所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1097765.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存