Pages

Cara membuat intro 100 di android

Ini loding 100 setelah 100% maka akan ke halaman selanjutnya, script ini di paste pada halaman main.java.
silahkan mencoba semoga berhasil !!!!



package projek1.com;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class main extends Activity {
    /** Called when the activity is first created. */
    @Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LOADING100();
    }
ProgressDialog progressBar;
    private int progressBarStatus = 0;
    private Handler progressBarHandler = new Handler();
    int fileSize = 0;
public void LOADING100() {
        progressBar = new ProgressDialog(this);
        progressBar.setCancelable(true);
        progressBar.setMessage("Process Opening...");// STYLE_SPINNER
        progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressBar.setProgress(0);
        progressBar.setMax(100);
        progressBar.show();
        progressBarStatus = 0;   
        new Thread(new Runnable() {
public void run() {
        while (progressBarStatus < 100) {
        progressBarStatus = doSomeTasks();
        try {Thread.sleep(1000);}
        catch (InterruptedException e) {e.printStackTrace();}
        progressBarHandler.post(new Runnable() {
public void run() {progressBar.setProgress(progressBarStatus);}});}
        if (progressBarStatus >= 100) {
        try {Thread.sleep(2000);}
        catch (InterruptedException e) {e.printStackTrace();}
        progressBar.dismiss();
        setSplash();
        }}}).start();
    }       
public int doSomeTasks() {
        while (fileSize <= 1000000) {
        fileSize++;
        if (fileSize == 100000) {return 10;}
        else if (fileSize == 200000) {return 20;}
        else if (fileSize == 300000) {return 30;}
        }
        return 100;
    }   

    public void setSplash(){
           new Thread() {
          public void run() {
             try{Thread.sleep(3000);}
             catch (Exception e) {}
                   Intent i = new Intent(main.this, menu.class);
                   main.this.finish();
                   startActivity(i); 
            } }.start(); 
        }
   
}

0 comments:

Post a Comment