mirror of https://github.com/BOINC/boinc.git
-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
This commit is contained in:
parent
7e8f2804fc
commit
b539fb57a9
|
@ -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"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:orientation="horizontal"
|
||||
android:padding="10dp">
|
||||
<TextView
|
||||
android:id="@+id/header_platform"
|
||||
android:layout_width="100dp"
|
||||
android:singleLine="true"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="10dp"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="@string/attachproject_login_header_platform"/>
|
||||
<TextView
|
||||
android:id="@+id/project_platform"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -55,6 +55,9 @@
|
|||
<string name="attachproject_login_header_description">Description:</string>
|
||||
<string name="attachproject_login_header_home">Home:</string>
|
||||
<string name="attachproject_login_header_url">Website:</string>
|
||||
<string name="attachproject_login_header_platform">Android:</string>
|
||||
<string name="attachproject_login_platform_supported">This project supports calculation on Android devices.</string>
|
||||
<string name="attachproject_login_platform_not_supported">This project does not support caculation on Android devices yet!</string>
|
||||
<string name="attachproject_login_category_login">Sign in with existing account</string>
|
||||
<string name="attachproject_login_header_id_email">eMail:</string>
|
||||
<string name="attachproject_login_header_id_name">Name:</string>
|
||||
|
@ -88,7 +91,12 @@
|
|||
<string name="attachproject_registration_toast_error_no_email">eMail missing!</string>
|
||||
<string name="attachproject_registration_toast_error_no_pwd">Password missing!</string>
|
||||
<string name="attachproject_registration_toast_error_unknown">Registration failed.</string>
|
||||
<string name="attachproject_registration_toast_error_username_required">User name is required!</string>
|
||||
<string name="attachproject_registration_toast_error_bad_username">user name refused, change and try again!</string>
|
||||
<string name="attachproject_registration_toast_error_email_in_use">eMail is already in use!</string>
|
||||
<string name="attachproject_registration_toast_error_project_down">Can\'t reach project server!</string>
|
||||
<string name="attachproject_registration_toast_error_email_bad_syntax">eMail refused, change and try again!</string>
|
||||
<string name="attachproject_registration_toast_error_bad_pwd">Password refused, change and try again!</string>
|
||||
<string name="attachproject_registration_toast_error_creation_disabled">Account creation is disabled on this project!</string>
|
||||
<string name="attachproject_registration_toast_creation_successful">Account created. Logging in…</string>
|
||||
<string name="attachproject_registration_toast_login_successful">Successful.</string>
|
||||
|
||||
|
|
|
@ -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<Void, Void, Integer> {
|
||||
|
||||
//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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue