From b539fb57a9e9421cf9312fb507492ce4f88b4bb1 Mon Sep 17 00:00:00 2001 From: Joachim Fritzsch Date: Thu, 28 Mar 2013 12:35:19 +0100 Subject: [PATCH] -android: ProjectAttach: - bug fixes (NullPointerException) at login - added warning in case manually added project does not support Android - usage of lib/error_numbers.h instead of self defined values - added link to project URL --- .../layout/attach_project_login_layout.xml | 23 +++++ android/BOINC/res/values/strings.xml | 10 ++- .../boinc/AttachProjectLoginActivity.java | 90 +++++++++++++------ .../AttachProjectRegistrationActivity.java | 71 ++++++++------- .../edu/berkeley/boinc/utils/BOINCErrors.java | 13 ++- 5 files changed, 143 insertions(+), 64 deletions(-) diff --git a/android/BOINC/res/layout/attach_project_login_layout.xml b/android/BOINC/res/layout/attach_project_login_layout.xml index 7e23a1785f..7b610f7f74 100644 --- a/android/BOINC/res/layout/attach_project_login_layout.xml +++ b/android/BOINC/res/layout/attach_project_login_layout.xml @@ -161,6 +161,29 @@ android:id="@+id/project_url" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:textAppearance="?android:attr/textAppearanceSmall" + android:clickable="true" + android:onClick="projectUrlClicked" + android:textColor="@color/link"/> + + + + + diff --git a/android/BOINC/res/values/strings.xml b/android/BOINC/res/values/strings.xml index 8fc51cc699..d1a20c9b26 100644 --- a/android/BOINC/res/values/strings.xml +++ b/android/BOINC/res/values/strings.xml @@ -55,6 +55,9 @@ Description: Home: Website: + Android: + This project supports calculation on Android devices. + This project does not support caculation on Android devices yet! Sign in with existing account eMail: Name: @@ -88,7 +91,12 @@ eMail missing! Password missing! Registration failed. - User name is required! + user name refused, change and try again! + eMail is already in use! + Can\'t reach project server! + eMail refused, change and try again! + Password refused, change and try again! + Account creation is disabled on this project! Account created. Logging in… Successful. diff --git a/android/BOINC/src/edu/berkeley/boinc/AttachProjectLoginActivity.java b/android/BOINC/src/edu/berkeley/boinc/AttachProjectLoginActivity.java index 563870c638..cd89b8c12e 100644 --- a/android/BOINC/src/edu/berkeley/boinc/AttachProjectLoginActivity.java +++ b/android/BOINC/src/edu/berkeley/boinc/AttachProjectLoginActivity.java @@ -43,8 +43,10 @@ import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; import edu.berkeley.boinc.rpc.AccountOut; +import edu.berkeley.boinc.rpc.PlatformInfo; import edu.berkeley.boinc.rpc.ProjectConfig; import edu.berkeley.boinc.rpc.ProjectInfo; +import edu.berkeley.boinc.utils.BOINCErrors; public class AttachProjectLoginActivity extends Activity{ @@ -59,12 +61,6 @@ public class AttachProjectLoginActivity extends Activity{ private ProjectConfig projectConfig; private Bitmap projectLogo; - // result definitions - public final static int RESULT_OK = 0; - public final static int RESULT_PWD_INCORRECT = -206; - public final static int RESULT_EMAIL_INCORRECT = -136; - public final static int RESULT_NO_CONNECTION = -113; - private ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { // This is called when the connection with the service has been established, getService returns the Monitor object that is needed to call functions. @@ -103,6 +99,11 @@ public class AttachProjectLoginActivity extends Activity{ } } catch (Exception e) {Log.d(TAG,"no project info...");} + if(!projectInfoPresent) { // url can not be taken of ProjectInfo + // format user input on URL right to avoid exceptions + if (!url.startsWith("http://") && !url.startsWith("https://")) url = "http://" + url; // add http:// in case user leaves it out + } + if(!urlPresent && !projectInfoPresent) { // neither url (manual input) nor project info (list selection) is present Log.d(TAG,"neither url nor projectInfo available! finish activity..."); @@ -165,6 +166,15 @@ public class AttachProjectLoginActivity extends Activity{ website.setText(projectConfig.masterUrl); website.setTag(projectConfig.masterUrl); // set tag to use in onClick + // set android support + TextView platform = (TextView) findViewById(R.id.project_platform); + if(platformSupported()) { + platform.setText(R.string.attachproject_login_platform_supported); + } else { + platform.setText(R.string.attachproject_login_platform_not_supported); + platform.setTextColor(getResources().getColor(R.color.warning)); + } + // set ProjectInfo fields, if ProjectInfo available (after list selection) if(projectInfoPresent) { // set layout wrapper visible @@ -248,6 +258,7 @@ public class AttachProjectLoginActivity extends Activity{ new ProjectLoginAsync().execute(); } + // register button's onClick public void register (View view) { Log.d(TAG, "register: " + view.getTag()); Boolean clientCreation = (Boolean) view.getTag(); @@ -266,6 +277,14 @@ public class AttachProjectLoginActivity extends Activity{ } } + // project url textview's onClick + public void projectUrlClicked (View view) { + // start intent to project website + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse(url)); + startActivity(i); + } + private Boolean verifyInput(String id, String pwd) { if(id.length() == 0) { Toast toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_no_name, Toast.LENGTH_SHORT); @@ -281,28 +300,28 @@ public class AttachProjectLoginActivity extends Activity{ } private void showResultToast(Integer code) { + Log.d(TAG,"showResultToast for error: " + code); Toast toast; - toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_unknown, Toast.LENGTH_LONG); if(code == null) { toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_unknown, Toast.LENGTH_LONG); - } - Log.d(TAG,"showResultToast for error: " + code); - switch (code) { - case RESULT_OK: - toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_ok, Toast.LENGTH_LONG); - break; - case RESULT_PWD_INCORRECT: - toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_wrong_pwd, Toast.LENGTH_LONG); - break; - case RESULT_EMAIL_INCORRECT: - toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_wrong_name, Toast.LENGTH_LONG); - break; - case RESULT_NO_CONNECTION: - toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_no_internet, Toast.LENGTH_LONG); - break; - default: - toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_unknown, Toast.LENGTH_LONG); - break; + } else { + switch (code) { + case BOINCErrors.ERR_OK: + toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_ok, Toast.LENGTH_LONG); + break; + case BOINCErrors.ERR_BAD_PASSWD: + toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_wrong_pwd, Toast.LENGTH_LONG); + break; + case BOINCErrors.ERR_DB_NOT_FOUND: + toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_wrong_name, Toast.LENGTH_LONG); + break; + case BOINCErrors.ERR_GETHOSTBYNAME: + toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_no_internet, Toast.LENGTH_LONG); + break; + default: + toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_unknown, Toast.LENGTH_LONG); + break; + } } toast.show(); } @@ -327,6 +346,19 @@ public class AttachProjectLoginActivity extends Activity{ startActivity(intent); } + private Boolean platformSupported() { + if(projectConfig == null) return false; + String platformName = getString(R.string.boinc_platform_name); + Boolean supported = false; + for(PlatformInfo platform: projectConfig.platforms) { + if(platform.name.equals(platformName)) { + supported = true; + continue; + } + } + return supported; + } + private final class ProjectLoginAsync extends AsyncTask { //private final String TAG = "ProjectLoginAsync"; @@ -357,11 +389,13 @@ public class AttachProjectLoginActivity extends Activity{ AccountOut account = monitor.lookupCredentials(url, id, pwd); try { - if(account.error_num == RESULT_OK) { + if(account.error_num == BOINCErrors.ERR_OK) { Boolean attach = monitor.attachProject(url, id, account.authenticator); if(attach) { - return RESULT_OK; + return BOINCErrors.ERR_OK; } else { + Log.d(TAG,"attachProject failed"); + // happens if project already attached return null; } } else { // error code @@ -374,7 +408,7 @@ public class AttachProjectLoginActivity extends Activity{ @Override protected void onPostExecute(Integer errorCode) { showResultToast(errorCode); - if(errorCode == RESULT_OK) { //successful + if((errorCode != null) && (errorCode == BOINCErrors.ERR_OK)) { //successful monitor.forceRefresh(); // force refresh, so "no project banner" disappears goToMainActivity(); } diff --git a/android/BOINC/src/edu/berkeley/boinc/AttachProjectRegistrationActivity.java b/android/BOINC/src/edu/berkeley/boinc/AttachProjectRegistrationActivity.java index 736bbf910e..4d5079544d 100644 --- a/android/BOINC/src/edu/berkeley/boinc/AttachProjectRegistrationActivity.java +++ b/android/BOINC/src/edu/berkeley/boinc/AttachProjectRegistrationActivity.java @@ -36,6 +36,7 @@ import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; import edu.berkeley.boinc.rpc.AccountOut; +import edu.berkeley.boinc.utils.BOINCErrors; public class AttachProjectRegistrationActivity extends Activity{ @@ -48,13 +49,6 @@ public class AttachProjectRegistrationActivity extends Activity{ private String projectName; private Integer minPwdLength; - // result definitions - public final static int RESULT_OK = 0; - public final static int RESULT_PWD_INCORRECT = -206; - public final static int RESULT_EMAIL_INCORRECT = -136; - public final static int RESULT_NO_CONNECTION = -113; - public final static int RESULT_USER_NAME_REQUIRED = -188; - private ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { // This is called when the connection with the service has been established, getService returns the Monitor object that is needed to call functions. @@ -159,31 +153,42 @@ public class AttachProjectRegistrationActivity extends Activity{ } private void showResultToast(Integer code) { + Log.d(TAG,"showResultToast for error: " + code); Toast toast; - toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_unknown, Toast.LENGTH_LONG); if(code == null) { toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_unknown, Toast.LENGTH_LONG); - } - Log.d(TAG,"showResultToast for error: " + code); - switch (code) { - case RESULT_OK: - toast = Toast.makeText(getApplicationContext(), R.string.attachproject_registration_toast_login_successful, Toast.LENGTH_LONG); - break; - case RESULT_PWD_INCORRECT: - toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_wrong_pwd, Toast.LENGTH_LONG); - break; - case RESULT_EMAIL_INCORRECT: - toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_wrong_name, Toast.LENGTH_LONG); - break; - case RESULT_NO_CONNECTION: - toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_no_internet, Toast.LENGTH_LONG); - break; - case RESULT_USER_NAME_REQUIRED: - toast = Toast.makeText(getApplicationContext(), R.string.attachproject_registration_toast_error_username_required, Toast.LENGTH_LONG); - break; - default: - toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_unknown, Toast.LENGTH_LONG); - break; + } else { + switch (code) { + case BOINCErrors.ERR_OK: + toast = Toast.makeText(getApplicationContext(), R.string.attachproject_registration_toast_login_successful, Toast.LENGTH_LONG); + break; + case BOINCErrors.ERR_NONUNIQUE_EMAIL: // treat the same as -137, ERR_DB_NOT_UNIQUE + // no break!! + case BOINCErrors.ERR_DB_NOT_UNIQUE: + toast = Toast.makeText(getApplicationContext(), R.string.attachproject_registration_toast_error_email_in_use, Toast.LENGTH_LONG); + break; + case BOINCErrors.ERR_PROJECT_DOWN: + toast = Toast.makeText(getApplicationContext(), R.string.attachproject_registration_toast_error_project_down, Toast.LENGTH_LONG); + break; + case BOINCErrors.ERR_BAD_EMAIL_ADDR: + toast = Toast.makeText(getApplicationContext(), R.string.attachproject_registration_toast_error_email_bad_syntax, Toast.LENGTH_LONG); + break; + case BOINCErrors.ERR_BAD_PASSWD: + toast = Toast.makeText(getApplicationContext(), R.string.attachproject_registration_toast_error_bad_pwd, Toast.LENGTH_LONG); + break; + case BOINCErrors.ERR_BAD_USER_NAME: + toast = Toast.makeText(getApplicationContext(), R.string.attachproject_registration_toast_error_bad_username, Toast.LENGTH_LONG); + break; + case BOINCErrors.ERR_GETHOSTBYNAME: + toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_no_internet, Toast.LENGTH_LONG); + break; + case BOINCErrors.ERR_ACCT_CREATION_DISABLED: + toast = Toast.makeText(getApplicationContext(), R.string.attachproject_registration_toast_error_creation_disabled, Toast.LENGTH_LONG); + break; + default: + toast = Toast.makeText(getApplicationContext(), R.string.attachproject_login_toast_error_unknown, Toast.LENGTH_LONG); + break; + } } toast.show(); } @@ -246,15 +251,17 @@ public class AttachProjectRegistrationActivity extends Activity{ AccountOut account = monitor.createAccount(projectUrl, email, user, pwd, team); if(account == null) { + Log.d(TAG, "createAccount returned null"); return null; } - if(account.error_num == RESULT_OK) { //only continue if creation succeeded + if(account.error_num == BOINCErrors.ERR_OK) { //only continue if creation succeeded publishProgress(); Boolean attach = monitor.attachProject(projectUrl, email, account.authenticator); if(attach) { - return RESULT_OK; + return BOINCErrors.ERR_OK; } else { + Log.d(TAG, "attachProject returned false"); return null; } } else { // error code @@ -272,7 +279,7 @@ public class AttachProjectRegistrationActivity extends Activity{ @Override protected void onPostExecute(Integer errorCode) { showResultToast(errorCode); - if(errorCode == RESULT_OK) { //successful + if((errorCode != null) && (errorCode == BOINCErrors.ERR_OK)) { //successful monitor.forceRefresh(); // force refresh, so "no project banner" disappears goToMainActivity(); } diff --git a/android/BOINC/src/edu/berkeley/boinc/utils/BOINCErrors.java b/android/BOINC/src/edu/berkeley/boinc/utils/BOINCErrors.java index c0ba2fcbd1..8318fb31fe 100644 --- a/android/BOINC/src/edu/berkeley/boinc/utils/BOINCErrors.java +++ b/android/BOINC/src/edu/berkeley/boinc/utils/BOINCErrors.java @@ -29,9 +29,16 @@ public class BOINCErrors { // old error numbers to avoid confusion between versions. // Add a text description of your error to boincerror() in util.C. // + public final static int ERR_OK = 0; + public final static int ERR_GETHOSTBYNAME = -113; // can not resolve name. no DNS -> no Internet?! public static final int ERR_GIVEUP_DOWNLOAD = -114; public static final int ERR_GIVEUP_UPLOAD = -115; - - - + public final static int ERR_DB_NOT_FOUND = -136; // e.g. eMail invalid + public final static int ERR_DB_NOT_UNIQUE = -137; // name not unique, i.e. email already in use + public final static int ERR_PROJECT_DOWN = -183; // i.e. project error + public final static int ERR_BAD_USER_NAME = -188; // i.e. user name required + public final static int ERR_BAD_EMAIL_ADDR = -205; // i.e. email has invalid syntax + public final static int ERR_BAD_PASSWD = -206; + public final static int ERR_NONUNIQUE_EMAIL = -207; + public final static int ERR_ACCT_CREATION_DISABLED = -208; // i.e. account creation currently disabled }