Example usage for android.app Activity RESULT_CANCELED

List of usage examples for android.app Activity RESULT_CANCELED

Introduction

In this page you can find the example usage for android.app Activity RESULT_CANCELED.

Prototype

int RESULT_CANCELED

To view the source code for android.app Activity RESULT_CANCELED.

Click Source Link

Document

Standard activity result: operation canceled.

Usage

From source file:it.cosenonjaviste.mv2m.ViewModelManager.java

public void onBackPressed(Activity activity) {
    ActivityResult result = viewModel.onBackPressed();
    if (result != null) {
        Intent intent = new Intent();
        intent.putExtra(RESULT_DATA, result.getData());
        activity.setResult(result.isResultOk() ? Activity.RESULT_OK : Activity.RESULT_CANCELED, intent);
    }//from  w  ww. j av  a  2  s .com
}

From source file:com.csipsimple.service.Downloader.java

@Override
protected void onHandleIntent(Intent intent) {
    HttpGet getMethod = new HttpGet(intent.getData().toString());
    int result = Activity.RESULT_CANCELED;
    String outPath = intent.getStringExtra(EXTRA_OUTPATH);
    boolean checkMd5 = intent.getBooleanExtra(EXTRA_CHECK_MD5, false);
    int icon = intent.getIntExtra(EXTRA_ICON, 0);
    String title = intent.getStringExtra(EXTRA_TITLE);
    boolean showNotif = (icon > 0 && !TextUtils.isEmpty(title));

    // Build notification
    Builder nb = new NotificationCompat.Builder(this);
    nb.setWhen(System.currentTimeMillis());
    nb.setContentTitle(title);/*from  w w  w.ja va2s  .  c om*/
    nb.setSmallIcon(android.R.drawable.stat_sys_download);
    nb.setOngoing(true);
    Intent i = new Intent(this, SipHome.class);
    nb.setContentIntent(PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT));

    RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(),
            R.layout.download_notif);
    contentView.setImageViewResource(R.id.status_icon, icon);
    contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.downloading_text));
    contentView.setProgressBar(R.id.status_progress, 50, 0, false);
    contentView.setViewVisibility(R.id.status_progress_wrapper, View.VISIBLE);
    nb.setContent(contentView);

    final Notification notification = showNotif ? nb.build() : null;
    notification.contentView = contentView;
    if (!TextUtils.isEmpty(outPath)) {
        try {
            File output = new File(outPath);
            if (output.exists()) {
                output.delete();
            }

            if (notification != null) {
                notificationManager.notify(NOTIF_DOWNLOAD, notification);
            }
            ResponseHandler<Boolean> responseHandler = new FileStreamResponseHandler(output, new Progress() {
                private int oldState = 0;

                @Override
                public void run(long progress, long total) {
                    //Log.d(THIS_FILE, "Progress is "+progress+" on "+total);
                    int newState = (int) Math.round(progress * 50.0f / total);
                    if (oldState != newState) {

                        notification.contentView.setProgressBar(R.id.status_progress, 50, newState, false);
                        notificationManager.notify(NOTIF_DOWNLOAD, notification);
                        oldState = newState;
                    }

                }
            });
            boolean hasReply = client.execute(getMethod, responseHandler);

            if (hasReply) {

                if (checkMd5) {
                    URL url = new URL(intent.getData().toString().concat(".md5sum"));
                    InputStream content = (InputStream) url.getContent();
                    if (content != null) {
                        BufferedReader br = new BufferedReader(new InputStreamReader(content));
                        String downloadedMD5 = "";
                        try {
                            downloadedMD5 = br.readLine().split("  ")[0];
                        } catch (NullPointerException e) {
                            throw new IOException("md5_verification : no sum on server");
                        }
                        if (!MD5.checkMD5(downloadedMD5, output)) {
                            throw new IOException("md5_verification : incorrect");
                        }
                    }
                }
                PendingIntent pendingIntent = (PendingIntent) intent
                        .getParcelableExtra(EXTRA_PENDING_FINISH_INTENT);

                try {
                    Runtime.getRuntime().exec("chmod 644 " + outPath);
                } catch (IOException e) {
                    Log.e(THIS_FILE, "Unable to make the apk file readable", e);
                }

                Log.d(THIS_FILE, "Download finished of : " + outPath);
                if (pendingIntent != null) {

                    notification.contentIntent = pendingIntent;
                    notification.flags = Notification.FLAG_AUTO_CANCEL;
                    notification.icon = android.R.drawable.stat_sys_download_done;
                    notification.contentView.setViewVisibility(R.id.status_progress_wrapper, View.GONE);
                    notification.contentView.setTextViewText(R.id.status_text,
                            getResources().getString(R.string.done)
                                    // TODO should be a parameter of this class
                                    + " - Click to install");
                    notificationManager.notify(NOTIF_DOWNLOAD, notification);

                    /*
                    try {
                       pendingIntent.send();
                         notificationManager.cancel(NOTIF_DOWNLOAD);
                    } catch (CanceledException e) {
                       Log.e(THIS_FILE, "Impossible to start pending intent for download finish");
                    }
                    */
                } else {
                    Log.w(THIS_FILE, "Invalid pending intent for finish !!!");
                }

                result = Activity.RESULT_OK;
            }
        } catch (IOException e) {
            Log.e(THIS_FILE, "Exception in download", e);
        }
    }

    if (result == Activity.RESULT_CANCELED) {
        notificationManager.cancel(NOTIF_DOWNLOAD);
    }
}

From source file:com.google.zxing.BarcodeScanner.java

/**
* Called when the barcode scanner intent completes
*
* @param requestCode       The request code originally supplied to startActivityForResult(),
*                          allowing you to identify who this result came from.
* @param resultCode        The integer result code returned by the child activity through its setResult().
* @param intent            An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
*//* ww  w  . j a  va  2s.com*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            JSONObject obj = new JSONObject();
            try {
                obj.put(TEXT, intent.getStringExtra("SCAN_RESULT"));
                obj.put(FORMAT, intent.getStringExtra("SCAN_RESULT_FORMAT"));
                obj.put(CANCELLED, false);
            } catch (JSONException e) {
                //Log.d(LOG_TAG, "This should never happen");
            }
            this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback);
        }
        if (resultCode == Activity.RESULT_CANCELED) {
            JSONObject obj = new JSONObject();
            try {
                obj.put(TEXT, "");
                obj.put(FORMAT, "");
                obj.put(CANCELLED, true);
            } catch (JSONException e) {
                //Log.d(LOG_TAG, "This should never happen");
            }
            this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback);
        } else {
            this.error(new PluginResult(PluginResult.Status.ERROR), this.callback);
        }
    }
}

From source file:com.google.android.gms.samples.wallet.CheckoutActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // retrieve the error code, if available
    int errorCode = -1;
    if (data != null) {
        errorCode = data.getIntExtra(WalletConstants.EXTRA_ERROR_CODE, -1);
    }/*  ww  w  .jav a 2s  .c  om*/
    switch (requestCode) {
    case REQUEST_CODE_MASKED_WALLET:
        switch (resultCode) {
        case Activity.RESULT_OK:
            MaskedWallet maskedWallet = data.getParcelableExtra(WalletConstants.EXTRA_MASKED_WALLET);
            launchConfirmationPage(maskedWallet);
            break;
        case Activity.RESULT_CANCELED:
            break;
        default:
            handleError(errorCode);
            break;
        }
        break;
    case WalletConstants.RESULT_ERROR:
        handleError(errorCode);
        break;
    default:
        super.onActivityResult(requestCode, resultCode, data);
        break;
    }
}

From source file:com.tdispatch.passenger.SearchActivity.java

@Override
public void doSearchCancel() {
    setResult(Activity.RESULT_CANCELED);
    finish();
}

From source file:com.amsterdam.marktbureau.makkelijkemarkt.VervangerDialogActivity.java

/**
 * Onclick on the cancel button close the vervanger dialog
 *//*from   w  w w.j  a v a2s  .c o m*/
@OnClick(R.id.dialog_cancel)
public void onCancelScan() {
    Intent returnIntent = new Intent();
    setResult(Activity.RESULT_CANCELED, returnIntent);
    finish();
}

From source file:org.linesofcode.alltrack.graph.AddValueActivity.java

private void initializeContent() {
    calendar = Calendar.getInstance();
    dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());
    timeFormat = new SimpleDateFormat(TIME_PATTERN, Locale.getDefault());

    dateView = (TextView) findViewById(R.id.add_value_date);
    timeView = (TextView) findViewById(R.id.add_value_time);

    Button okButton = (Button) findViewById(R.id.add_value_ok);
    okButton.setOnClickListener(new View.OnClickListener() {
        @Override/*from   w  ww  .  j a  va2s  . c  om*/
        public void onClick(View v) {
            addValue();
        }
    });

    Button cancelButton = (Button) findViewById(R.id.add_value_cancel);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setResult(Activity.RESULT_CANCELED, new Intent(ADD_VALUE_ACTION_CODE));
            finish();
        }
    });

    EditText value = (EditText) findViewById(R.id.add_value_value);
    value.setOnKeyListener(new View.OnKeyListener() {

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_ENTER:
                    addValue();
                    return true;
                }
            }
            return false;
        }
    });

    dateView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDatePicker();
        }
    });

    timeView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showTimePicker();
        }
    });

    updateDateTimeFields();

    Bundle extras = getIntent().getExtras();
    graphId = extras.getInt("graphId");
    position = extras.getInt("position");
    Log.d(TAG, "Starting addValue Activity for graph [" + graphId + "] in position [" + position + "].");
    graph = graphService.getById(graphId);
}

From source file:edu.missouri.niaaa.ema.activity.AdminManageActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "OnCreate!!~~~");

    ctx = this;/*from  w  ww . j  a v a 2  s.c o m*/
    // Setup the window
    //requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    // Set result CANCELED incase the user backs out
    setResult(Activity.RESULT_CANCELED);

    ////////////////////////////////////////////////////////////////////

    tabHost = getTabHost();
    LayoutInflater.from(this).inflate(R.layout.activity_admin_manage, tabHost.getTabContentView(), true);
    tabHost.addTab(tabHost.newTabSpec("Assign ID").setIndicator("Assign ID", null).setContent(R.id.tab_assign));
    tabHost.addTab(tabHost.newTabSpec("Remove ID").setIndicator("Remove ID", null).setContent(R.id.tab_logoff));

    setContentView(tabHost);

    shp = getSharedPreferences(Utilities.SP_LOGIN, Context.MODE_PRIVATE);
    editor = shp.edit();
    asID = (EditText) findViewById(R.id.assigned_ID);
    deasID = (EditText) findViewById(R.id.deassigned_ID);
    AssignButton = (Button) findViewById(R.id.btn_assign);
    RemoveButton = (Button) findViewById(R.id.btn_remove);

    imm = (InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
    //imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);

    //imm.showSoftInput(asID, InputMethodManager.RESULT_SHOWN); 
    imm.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS, InputMethodManager.RESULT_HIDDEN);

    asID.setFocusable(true);
    asID.setFocusableInTouchMode(true);

    asID.requestFocus();

    setListeners();

    DialadminPin = AdminPinSetDialog(this);
    DialadminPin.show();

    setHints();
}

From source file:edu.missouri.niaaa.pain.activity.AdminManageActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "OnCreate!!~~~");

    ctx = this;//ww w  .j a v  a  2 s .c  om
    // Setup the window
    //requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    // Set result CANCELED in case the user backs out
    setResult(Activity.RESULT_CANCELED);

    ////////////////////////////////////////////////////////////////////

    tabHost = getTabHost();
    LayoutInflater.from(this).inflate(R.layout.activity_admin_manage, tabHost.getTabContentView(), true);
    tabHost.addTab(tabHost.newTabSpec("Assign ID").setIndicator("Assign ID", null).setContent(R.id.tab_assign));
    tabHost.addTab(tabHost.newTabSpec("Remove ID").setIndicator("Remove ID", null).setContent(R.id.tab_logoff));

    setContentView(tabHost);

    shp = getSharedPreferences(Util.SP_LOGIN, Context.MODE_PRIVATE);
    editor = shp.edit();
    asID = (EditText) findViewById(R.id.assigned_ID);
    deasID = (EditText) findViewById(R.id.deassigned_ID);
    AssignButton = (Button) findViewById(R.id.btn_assign);
    RemoveButton = (Button) findViewById(R.id.btn_remove);

    imm = (InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
    //imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);

    //imm.showSoftInput(asID, InputMethodManager.RESULT_SHOWN);
    imm.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS, InputMethodManager.RESULT_HIDDEN);

    asID.setFocusable(true);
    asID.setFocusableInTouchMode(true);

    asID.requestFocus();

    setListeners();

    DialadminPin = AdminPinSetDialog(this);
    DialadminPin.show();

    setHints();
}

From source file:org.benetech.secureapp.activities.BulletinToMbaFileExporter.java

@Override
public void onZipped(Bulletin bulletin, AsyncTaskResult<File> zippedTaskResult) {
    if (zippedTaskResult.getException() != null) {
        indeterminateDialog.dismissAllowingStateLoss();
        setResult(Activity.RESULT_CANCELED);

        return;/*from w ww  . j a v  a2s .c om*/
    }

    try {
        final File externalStoragePublicDirectory = Environment
                .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
        final String fileName = getApplicationName() + "_" + bulletin.toFileName() + MBA_FILE_EXTENSION;
        final File destinationFile = new File(externalStoragePublicDirectory, fileName);
        FileUtils.copyFile(zippedTaskResult.getResult(), destinationFile);

        ZipFile zipFile = new ZipFile(zippedTaskResult.getResult());
        BulletinZipUtilities.validateIntegrityOfZipFilePackets(store.getAccountId(), zipFile, getSecurity());
    } catch (Exception e) {
        Log.e(TAG, getString(R.string.error_message_error_verifying_zip_file), e);
        indeterminateDialog.dismissAllowingStateLoss();
        Toast.makeText(this, getString(R.string.failure_zipping_bulletin), Toast.LENGTH_SHORT).show();
        setResult(Activity.RESULT_CANCELED);
        finish();
        return;
    }

    indeterminateDialog.dismissAllowingStateLoss();
    if (zippedTaskResult.getResult() == null) {
        setResult(Activity.RESULT_CANCELED);
        Toast.makeText(this, getString(R.string.failure_zipping_bulletin), Toast.LENGTH_SHORT).show();
        return;
    }

    setResult(Activity.RESULT_OK);
    finish();
}