进度对话框微调器无缝旋转。我希望它是这样的 - 用户单击“Check For Root”按钮,微调器将旋转5秒并显示“Please wait”消息,然后显示带有结果的对话框。 请帮忙!
package com.maverick.checkforroot;
import com.stericson.RootTools.RootTools;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private Handler mTimerHandler = new Handler();
private ProgressDialog mProgressDialog = null;
private Button Root;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView Manufacturer = (TextView) findViewById(R.id.Manufacturer);
String Manu = android.os.Build.MANUFACTURER;;
Manufacturer.setText(Manu);
TextView tv1 = (TextView) findViewById(R.id.tv1);
String Model = android.os.Build.MODEL;
tv1.setText(Model);
TextView Product = (TextView) findViewById(R.id.Product);
String Pro = android.os.Build.PRODUCT;;
Product.setText(Pro);
final Runnable mTimerExecutor = null;
Button Root = (Button) findViewById(R.id.Root);
Root.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
mProgressDialog = ProgressDialog.show(MainActivity.this, "", "Please wait...", true);
mTimerHandler.postDelayed(mTimerExecutor, 5000);
}
});
};
public void run() {
if (mProgressDialog != null) {
mProgressDialog.dismiss();
}
if (RootTools.isAccessGiven()) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("Congratulations!");
builder.setMessage("You Have Root Access!");
builder.setPositiveButton("OKAY", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
else {
AlertDialog.Builder builder1 = new AlertDialog.Builder(MainActivity.this);
builder1.setIcon(R.drawable.ic_launcher);
builder1.setTitle("Oops!");
builder1.setMessage("No Root Access!");
builder1.setPositiveButton("OKAY", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog = builder1.create();
dialog.show();
};
Button BusyBox = (Button) findViewById(R.id.BusyBox);
BusyBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (RootTools.isBusyboxAvailable()) {
Toast.makeText(MainActivity.this,"BusyBox Is Available!", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(MainActivity.this,"No BusyBox!", Toast.LENGTH_LONG).show();
}
}
});
}}
答案 0 :(得分:0)
您的代码似乎没问题。我不确定那是什么问题。我想建议以下内容。值得一试。
private static final int SHOW_PROGRESS = 0x1;
private static final int STOP_PROGRESS = 0x2;
Root.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
mHandler.sendEmptyMessageDelayed(SHOW_PROGRESS);
mHandler.sendEmptyMessage(STOP_PROGRESS, 5000);
}
});
// Handler
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
switch (msg.what) {
case SHOW_PROGRESS:
// Show your progress Bar here.
mHandler.removeMessages(SHOW_PROGRESS);
break;
case STOP_PROGRESS:
progressDialog.dismiss();
if (RootTools.isAccessGiven()) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("Congratulations!");
builder.setMessage("You Have Root Access!");
builder.setPositiveButton("OKAY", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
else {
AlertDialog.Builder builder1 = new AlertDialog.Builder(MainActivity.this);
builder1.setIcon(R.drawable.ic_launcher);
builder1.setTitle("Oops!");
builder1.setMessage("No Root Access!");
builder1.setPositiveButton("OKAY", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog = builder1.create();
dialog.show();
mHandler.removeMessages(STOP_PROGRESS);
break;
}
super.handleMessage(msg);
}
};