Example usage for android.os Message peekData

List of usage examples for android.os Message peekData

Introduction

In this page you can find the example usage for android.os Message peekData.

Prototype

public Bundle peekData() 

Source Link

Document

Like getData(), but does not lazily create the Bundle.

Usage

From source file:ac.robinson.mediaphone.MediaPhoneActivity.java

public void processIncomingFiles(Message msg) {

    // deal with messages from the BluetoothObserver
    Bundle fileData = msg.peekData();
    if (fileData == null) {
        return; // error - no parameters passed
    }//from w ww. j a  v a2 s . c  om

    String importedFileName = fileData.getString(MediaUtilities.KEY_FILE_NAME);
    if (importedFileName == null) {
        if (msg.what == MediaUtilities.MSG_IMPORT_SERVICE_REGISTERED) {
            onBluetoothServiceRegistered();
        }
        return; // error - no filename
    }

    // get the imported file object
    final File importedFile = new File(importedFileName);
    if (!importedFile.canRead() || !importedFile.canWrite()) {
        if (MediaPhone.IMPORT_DELETE_AFTER_IMPORTING) {
            importedFile.delete(); // error - probably won't work, but might
            // as well try; doesn't throw, so is okay
        }
        return;
    }

    final int messageType = msg.what;
    switch (messageType) {
    case MediaUtilities.MSG_RECEIVED_IMPORT_FILE:
        UIUtilities.showToast(MediaPhoneActivity.this, R.string.import_starting);
        break;

    case MediaUtilities.MSG_RECEIVED_SMIL_FILE:
    case MediaUtilities.MSG_RECEIVED_HTML_FILE:
    case MediaUtilities.MSG_RECEIVED_MOV_FILE:
        if (MediaPhone.IMPORT_CONFIRM_IMPORTING) {
            if (MediaPhoneActivity.this.isFinishing()) {
                if (!(MediaPhoneActivity.this instanceof NarrativeBrowserActivity)) {
                    // TODO: send a delayed message to the next task? (can't from NarrativeBrowser - app exit)
                }
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(MediaPhoneActivity.this);
                builder.setTitle(R.string.import_file_confirmation);
                // fake that we're using the SMIL file if we're actually using .sync.jpg
                builder.setMessage(getString(R.string.import_file_hint,
                        importedFile.getName().replace(MediaUtilities.SYNC_FILE_EXTENSION, "")
                                .replace(MediaUtilities.SMIL_FILE_EXTENSION, "")));
                builder.setIcon(android.R.drawable.ic_dialog_info);
                builder.setNegativeButton(R.string.import_not_now, null);
                builder.setPositiveButton(R.string.import_file, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int whichButton) {
                        importFiles(messageType, importedFile);
                    }
                });
                AlertDialog alert = builder.create();
                alert.show();
            }
        } else {
            importFiles(messageType, importedFile);
        }
        break;
    }
}