@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ac_text_editor_main); saveButton_ = (Button) findViewById(R.id.save_button); cancelButton_ = (Button) findViewById(R.id.cancel_button); fileContent_ = (EditText) findViewById(R.id.file_content); TextEditorGDServiceListener gdServiceListener = TextEditorGDServiceListener.getInstance(this); gdServiceListener.setOnOpenFileToEditListener( new OnOpenFileToEditListener() { @Override public void onFileToEditReceived() { runOnUiThread( new Runnable() { @Override public void run() { if (resumed_ && isAppAuthorized_) { loadLastOpenedFile(); } } }); } }); if (!isEditFileServiceWasSetUp_) { try { GDService.setServiceListener(gdServiceListener); } catch (GDServiceException e) { Log.e( TextEditorMainActivity.TAG, "Error while initializing GDService: " + e.getMessage(), e); } isEditFileServiceWasSetUp_ = true; } // Block interface until file will be opened from another app saveButton_.setEnabled(false); cancelButton_.setEnabled(false); fileContent_.setEnabled(false); GDAndroid.getInstance() .authorize( new GDAppEventListener() { @Override public void onGDEvent(GDAppEvent event) { if (event.getEventType() == GDAppEventType.GDAppEventAuthorized) { isAppAuthorized_ = true; loadLastOpenedFile(); } } }); }
public void onCancelFileEditingClicked(View v) { File lastOpenedFile = SharedPreferencesManager.getLastOpenedFile(this); byte[] identificationData = SharedPreferencesManager.getLastOpenedFileIdentificationData(this); String applicationFileOpenedFrom = SharedPreferencesManager.getLastOpenedFileFromApplication(this); if (lastOpenedFile != null) { try { GDServiceClient.setServiceClientListener( new GDServiceClientListener() { @Override public void onReceiveMessage( String application, Object params, String[] attachments, String requestID) { // Do nothing } @Override public void onMessageSent( String application, String requestID, String[] attachments) { // Do nothing } }); Map<String, Object> params = new HashMap<String, Object>(); if (identificationData != null) { params.put("identificationData", identificationData); } GDServiceClient.sendTo( applicationFileOpenedFrom, SAVE_EDITED_FILE_SERVICE_ID, SAVE_EDITED_FILE_SERVICE_VERSION, RELEASE_EDIT_METHOD, params, new String[] {lastOpenedFile.getAbsolutePath()}, GDICCForegroundOptions.PreferPeerInForeground); SharedPreferencesManager.clear(this); lastOpenedFile.delete(); saveButton_.setEnabled(false); cancelButton_.setEnabled(false); fileContent_.setEnabled(false); fileContent_.setText(""); } catch (GDServiceException e) { Toast.makeText(getApplicationContext(), "Error: " + e.getMessage(), Toast.LENGTH_LONG) .show(); } } }