ユーザーがボタンをクリックしてからメールが送信されるまで、不確定な進行状況バーを使用しようとしています。メールを送信するために開いたスレッドと進行状況バーに問題があると思います。今のところ、2 つが近くにあるとクラッシュするだけで、プログレス バーを有効にするスマートな方法があるかどうかわかりませんでした (基本的には、ユーザーがいくつかのメールを送信できるように、メールが送信されている間に渦巻く円のアニメーションが必要です)。バックグラウンドで何かが起こっているというフィードバック)。
作成時
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.signin_page);
verify_button = (Button) findViewById(R.id.verify_button);
signin_button = (Button) findViewById(R.id.signin_button);
staysignedin = (CheckBox) findViewById(R.id.staysignedinCheck);
link4help = (TextView) findViewById(R.id.link_to_register);
gmail = (EditText) findViewById(R.id.signin_email);
password = (EditText) findViewById(R.id.signin_password);
email_success = (ImageView) findViewById(R.id.email_authenticate_success);
password_success = (ImageView) findViewById(R.id.password_authenticate_success);
email_success.setVisibility(View.INVISIBLE);
password_success.setVisibility(View.INVISIBLE);
signin_button.setEnabled(false);
verify_button.setOnClickListener(this);
signin_button.setOnClickListener(this);
link4help.setOnClickListener(this);
final float scale = this.getResources().getDisplayMetrics().density;
staysignedin.setPadding(staysignedin.getPaddingLeft() + (int)(10.0f * scale + 0.5f),
staysignedin.getPaddingTop(),
staysignedin.getPaddingRight(),
staysignedin.getPaddingBottom());
/* Setting up handler for ProgressBar */
//b = (ProgressBar) findViewById(R.id.progressBar_verify);
setProgressBarIndeterminateVisibility(false);
}
オンクリック
@Override
public void onClick(View v) {
setProgressBarIndeterminateVisibility(true);
//Log.e("verify clicked","hi");
switch(v.getId()){
case R.id.verify_button:
Thread thread = new Thread(){
public void run(){
String gmailString = gmail.getText().toString();
String passString = password.getText().toString();
String[] recip = new String[]{gmailString};
String body = "\nThis is a test for the amazing Dictation2Go App! Created by --";
MailAccount a = new MailAccount(gmailString,passString);
try {
isGoogleAuthenticated = a.sendEmailTo(recip, "test", body);
} catch (MessagingException e) {
Log.e("failed to connect", "mess: "+e.getMessage());
isGoogleAuthenticated = false;
}
}
};
thread.start();
try {
thread.join();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
Log.e("END RESULT",String.valueOf(isGoogleAuthenticated));
if(isGoogleAuthenticated){
pb.setVisibility(View.INVISIBLE);
email_success.setVisibility(View.VISIBLE);
password_success.setVisibility(View.VISIBLE);
signin_button.setEnabled(true);
password.setEnabled(false);
gmail.setEnabled(false);
gmail.setBackgroundResource(R.layout.bordersuccess);
password.setBackgroundResource(R.layout.bordersuccess);
}else{
gmail.setText("");
password.setText("");
}
setProgressBarIndeterminateVisibility(false);
break;
----- 完全なソリューション ------------------------------------------- --------------
クラスのOnCreateメソッドで
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.signin_page);
setProgressBarIndeterminateVisibility(false); //Sets Default value
//LOOK at Picture #1 for my screen in this state
}
OnClickメソッドで(このアクティビティに setOnClickLister を実装しました)
@Override
public void onClick(View v) {
setProgressBarIndeterminateVisibility(true);
switch(v.getId()){
case R.id.verify_button:
String gmailString = gmail.getText().toString();
String passString = password.getText().toString();
new AsyncTask<String,Void,Boolean>() {
protected void onPreExecute() {
setProgressBarIndeterminateVisibility(true);
//LOOK at Picture #2 for my screen in this state
}
protected Boolean doInBackground(String... args) {
String gmailString = args[0];
String[] recip = new String[] { gmailString };
String passString = args[1];
String body = args[2];
MailAccount a = new MailAccount(gmailString, passString);
try {
return a.sendEmailTo(recip, "test", body);
} catch (MessagingException e) {
Log.e("failed to connect", "mess: "+e.getMessage());
return false;
}
}
protected void onPostExecute(Boolean isGoogleAuthenticated) {
setProgressBarIndeterminateVisibility(false);
if(isGoogleAuthenticated){
email_success.setVisibility(View.VISIBLE);
password_success.setVisibility(View.VISIBLE);
signin_button.setEnabled(true);
password.setEnabled(false);
gmail.setEnabled(false);
gmail.setBackgroundResource(R.layout.bordersuccess);
password.setBackgroundResource(R.layout.bordersuccess);
}else{
gmail.setText("");
password.setText("");
}
}
}.execute(gmailString, passString, "test complete");
//LOOK at Picture #3 for my screen in this state
break;
写真 #1 onCreate
画像 #2 onClick - 読み込み中
Picture #3読み込み完了