public String getNotificationLabel(Resources resources) { switch (state) { case LOGIN: return resources.getString(R.string.status_login_details); case CALC: return resources.getString(R.string.status_calc_details); case ERROR: return getErrorMessage(resources); default: return null; } }
public boolean isFinished() { return !isInitialState() && !isRunning(); }
public String[] getMissingPermissions() { if (isPermissionException()) { MissingPermissionException mpe = (MissingPermissionException)exception; return mpe.permissions.toArray(new String[mpe.permissions.size()]); } else { return new String[0]; } } }
private void stateChanged(State state) { setViewAttributes(state.state); switch (state.state) { case INITIAL: idle(); break; case LOGIN: statusLabel.setText(R.string.status_working); syncDetailsLabel.setText(R.string.status_login_details); progressBar.setIndeterminate(true); break; case CALC: calc(); break; case ERROR: if (state.isAuthException()) { onAuthFailed(); } else if (state.isPermissionException()) { displayMissingPermissions(AppPermission.from(state.getMissingPermissions())); } else { final String errorMessage = state.getErrorMessage(getContext().getResources()); statusLabel.setText(R.string.status_unknown_error); syncDetailsLabel.setText(getString(R.string.status_unknown_error_details, errorMessage == null ? "N/A" : errorMessage)); } break; } }
@Override public String getNotificationLabel(Resources resources) { String label = super.getNotificationLabel(resources); if (label != null) return label; if (state == BACKUP) { label = resources.getString(R.string.status_backup_details, currentSyncedItems, itemsToSync); if (dataType != null) { label += " ("+resources.getString(dataType.resId)+")"; } return label; } else { return ""; } } }
public boolean isWorking() { return getState().isRunning(); }
@Override public String getNotificationLabel(Resources resources) { String label = super.getNotificationLabel(resources); if (label != null) return label; switch (state) { case RESTORE: label = resources.getString(R.string.status_restore_details, currentRestoredCount, itemsToRestore); if (dataType != null) { label += " ("+resources.getString(dataType.resId)+")"; } return label; case UPDATING_THREADS: return resources.getString(R.string.status_updating_threads); default: return ""; } } }
public String getDetailedErrorMessage(Resources resources) { final String msg = getErrorMessage(resources); if (msg != null && exception != null) { final String underlying = exception.getCause() != null ? exception.getCause().toString() : null; final StringBuilder message = new StringBuilder().append(msg) .append(" (exception: ") .append(exception.toString()); if (!TextUtils.isEmpty(underlying)) { message.append(", underlying=").append(underlying); } return message.append(")").toString(); } else { return null; } }