public static void registerOrUnregister( final Context context, final String deviceRegistrationId, final boolean register) { final SharedPreferences settings = Util.getSharedPreferences(context); final String accountName = settings.getString(Util.ACCOUNT_NAME, "Unknown"); final Intent updateUIIntent = new Intent(Util.UPDATE_UI_INTENT); RegistrationInfoRequest request = getRequest(context); RegistrationInfoProxy proxy = request.create(RegistrationInfoProxy.class); proxy.setDeviceRegistrationId(deviceRegistrationId); String deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); proxy.setDeviceId(deviceId); Request<String> req; if (register) { req = request.register().using(proxy); } else { req = request.unregister().using(proxy); } req.fire( new Receiver<String>() { private void clearPreferences(SharedPreferences.Editor editor) { editor.remove(Util.ACCOUNT_NAME); editor.remove(Util.DEVICE_REGISTRATION_ID); editor.remove(Util.DEVICE_CODE); } @Override public void onFailure(ServerFailure failure) { Log.w(TAG, "Failure, got :" + failure.getMessage()); // Clean up application state SharedPreferences.Editor editor = settings.edit(); clearPreferences(editor); editor.commit(); updateUIIntent.putExtra(ACCOUNT_NAME_EXTRA, accountName); updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS); context.sendBroadcast(updateUIIntent); } @Override public void onSuccess(String response) { SharedPreferences settings = Util.getSharedPreferences(context); SharedPreferences.Editor editor = settings.edit(); if (register) { editor.putString(Util.DEVICE_REGISTRATION_ID, deviceRegistrationId); editor.putString(Util.DEVICE_CODE, response); } else { clearPreferences(editor); } editor.commit(); updateUIIntent.putExtra(ACCOUNT_NAME_EXTRA, accountName); updateUIIntent.putExtra( STATUS_EXTRA, register ? REGISTERED_STATUS : UNREGISTERED_STATUS); context.sendBroadcast(updateUIIntent); } }); }
@Override public void processActualizar() { if (isValidData()) { Date fecha = new Date(); ContextMantenimientoLocalidad context = FACTORY.contextMantenimientoLocalidad(); FACTORY.initialize(EVENTBUS); String keyPublic = UISesion.keyPublic; LocalidadProxy bean = context.create(LocalidadProxy.class); bean.setVersion(fecha.getTime()); bean.setOperacion("A"); bean.setDescripcion(txtDescripcion.getText().toUpperCase()); bean.setIdLocalidad(this.bean.getIdLocalidad()); Request<Boolean> request = context.updateLocalidad(bean, keyPublic); request.fire( new Receiver<Boolean>() { @Override public void onSuccess(Boolean response) { // Window.alert("Actualizado correctamente"); Notification not = new Notification(Notification.INFORMATION, "Actualizado correctamente"); not.showPopup(); goToUILocalidad(); } }); } }
/** * this will create/lookup a user in the datastore according to the Google Login (if logged in or * has logged in) */ private void createUser() { wLoading.showLoading(true, "Checking credentials... "); Request<UserDataProxy> req = clientFactory.getRequestFactory().getUserDataRequest().createUserData(); req.fire( new Receiver<UserDataProxy>() { public void onSuccess(UserDataProxy data) { wLoading.showLoading(false); process(data); } public void onFailure(ServerFailure error) { wLoading.showError( "Oops, I couldn't process credentials...Try reloading this page... "); super.onFailure(error); } }); }
@Override public void onFinish(IUploader uploader) { if (uploader.getStatus().equals(Status.SUCCESS)) { UploadedInfo info = uploader.getServerInfo(); if (info != null && info.message != null && !info.message.equals("noid")) { String entityId = info.message; BinaryRequest binaryRequest = requestFactory.binaryRequest(); Request<BinaryProxy> binaryFileRequest = binaryRequest.getBinary(entityId); binaryFileRequest.fire( new Receiver<BinaryProxy>() { @Override public void onSuccess(BinaryProxy response) { value = response; uploading = false; } @Override public void onFailure(ServerFailure error) { Window.alert("Error retrieving the Binary Description"); super.onFailure(error); } }); if (thumbnail != null && info.ctype.contains("image")) { // Attach thumbnail OnLoadPreloadedImageHandler showImage = new OnLoadPreloadedImageHandler() { public void onLoad(PreloadedImage image) { thumbnail.setUrl(image.getUrl()); } }; new PreloadedImage("servlet.gupld?show=" + entityId, showImage); } } } if (uploader.getStatus().equals(Status.CANCELED)) { setNew(); } }