Example usage for android.os Message getData

List of usage examples for android.os Message getData

Introduction

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

Prototype

public Bundle getData() 

Source Link

Document

Obtains a Bundle of arbitrary data associated with this event, lazily creating it if necessary.

Usage

From source file:it.angrydroids.epub3reader.BookView.java

@Override
public void onActivityCreated(Bundle saved) {
    super.onActivityCreated(saved);
    view = (WebView) getView().findViewById(R.id.Viewport);

    // enable JavaScript for cool things to happen!
    view.getSettings().setJavaScriptEnabled(true);

    // ----- SWIPE PAGE
    view.setOnTouchListener(new OnTouchListener() {
        @Override/*from  w  w  w .j a  va 2 s  .c  om*/
        public boolean onTouch(View v, MotionEvent event) {

            if (state == ViewStateEnum.books)
                swipePage(v, event, 0);

            WebView view = (WebView) v;
            return view.onTouchEvent(event);
        }
    });

    // ----- NOTE & LINK
    view.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Message msg = new Message();
            msg.setTarget(new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    String url = msg.getData().getString(getString(R.string.url));
                    if (url != null)
                        navigator.setNote(url, index);
                }
            });
            view.requestFocusNodeHref(msg);

            return false;
        }
    });

    view.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            try {
                navigator.setBookPage(url, index);
            } catch (Exception e) {
                errorMessage(getString(R.string.error_LoadPage));
            }
            return true;
        }
    });

    view.addJavascriptInterface(new MyJavaScriptInterface(), "INTERFACE");
    view.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            view.loadUrl(
                    "javascript:window.INTERFACE.processContent(document.getElementsByTagName('body')[0].innerText);");
        }
    });

    PreButton = (Button) getView().findViewById(R.id.btn_prev_chunk);
    TopButton = (Button) getView().findViewById(R.id.btn_display_from_top);
    FwdButton = (Button) getView().findViewById(R.id.btn_fwd_chunk);

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

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

    FwdButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            BtnFwdChunkOnClickListner(v);
        }
    });
    loadPage(viewedPage);
}

From source file:net.networksaremadeofstring.rhybudd.DiagnosticActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_diagnostics);
    try {//from ww  w  .ja  v  a2s .  c o m
        getActionBar().setTitle("Diagnostics App");
        getActionBar().setSubtitle("Helps to pin point any problems getting events");
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);
    } catch (Exception e) {

    }

    DiagnosticOutput = (TextView) findViewById(R.id.DiagOutput);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);

    ((Button) findViewById(R.id.StartDiagButton)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            findViewById(R.id.progressBar2).setVisibility(View.VISIBLE);
            DiagnosticOutput.setText("");
            DoDiagnostics();
            view.setEnabled(false);
        }
    });

    progressHandler = new Handler() {
        public void handleMessage(Message msg) {
            try {
                DiagnosticOutput.setText(DiagnosticOutput.getText().toString()
                        + msg.getData().getString(DIAGNOSTIC_OUTPUT) + "\n");
            } catch (Exception e) {
                DiagnosticOutput.setText(DiagnosticOutput.getText().toString()
                        + "A diagnostic message was received but there was an issue displaying it\n");
            }

            if (msg.what == DIAGNOSTIC_PRE) {
                try {
                    if (progressBar.getSecondaryProgress() < 20)
                        progressBar.setSecondaryProgress((progressBar.getSecondaryProgress() + 1));
                } catch (Exception e) {

                }
            } else if (msg.what == DIAGNOSTIC_SUCCESS) {
                try {
                    if (progressBar.getProgress() < 20)
                        progressBar.setProgress((progressBar.getProgress() + 1));
                } catch (Exception e) {

                }
            } else if (msg.what == DIAGNOSTIC_FAILURE) {
                try {
                    DiagnosticOutput.setTextColor(getResources().getColor(R.color.WarningRed));
                    findViewById(R.id.progressBar2).setVisibility(View.INVISIBLE);
                    findViewById(R.id.StartDiagButton).setEnabled(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else if (msg.what == DIAGNOSTIC_COMPLETE) {
                try {
                    DiagnosticOutput.setTextColor(Color.rgb(50, 102, 50));
                    progressBar.setProgress(20);
                    findViewById(R.id.progressBar2).setVisibility(View.INVISIBLE);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                try {
                    Toast.makeText(DiagnosticActivity.this, "Diagnostics Complete!", Toast.LENGTH_SHORT).show();
                    findViewById(R.id.StartDiagButton).setEnabled(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                //Not much else
            }

            try {
                progressBar.invalidate();
            } catch (Exception e) {

            }
        }
    };
}

From source file:org.sufficientlysecure.keychain.ui.EditIdentitiesFragment.java

private void addUserId() {
    Handler returnHandler = new Handler() {
        @Override/*from   w w w.j  a va  2s. c  om*/
        public void handleMessage(Message message) {
            if (message.what == SetPassphraseDialogFragment.MESSAGE_OKAY) {
                Bundle data = message.getData();

                // add new user id
                mUserIdsAddedAdapter.add(data.getString(AddUserIdDialogFragment.MESSAGE_DATA_USER_ID));
            }
        }
    };

    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(returnHandler);

    // pre-fill out primary name
    String predefinedName = KeyRing.splitUserId(mPrimaryUserId).name;
    AddUserIdDialogFragment addUserIdDialog = AddUserIdDialogFragment.newInstance(messenger, predefinedName);

    addUserIdDialog.show(getActivity().getSupportFragmentManager(), "addUserIdDialog");
}

From source file:com.spoiledmilk.ibikecph.login.LoginSplashActivity.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(getLayoutId());
    this.savedInstanceState = savedInstanceState;
    btnSkip = (RelativeLayout) findViewById(R.id.btnSkip);
    btnRegister = (RelativeLayout) findViewById(R.id.btnRegister);
    btnFacebookLogin = (Button) findViewById(R.id.btnFacebookLogin);
    textSkip = (TextView) findViewById(R.id.textSkip);
    textRegister = (TextView) findViewById(R.id.textRegister);

    btnLogin = (Button) findViewById(R.id.btnLogin);
    btnLogin.setOnClickListener(new OnClickListener() {

        @Override/*from w w w  .  j a  v  a 2  s  . c  o  m*/
        public void onClick(View arg0) {
            disableButtons();
            lg = new LoginDialog();
            lg.createLoginDialog(LoginSplashActivity.this);
        }

    });

    textCreateAccount = (TextView) findViewById(R.id.textCreateAccount);
    textLoginExplanation = (TextView) findViewById(R.id.textLoginExplanation);

    if (handler == null) {
        handler = new Handler(new Handler.Callback() {

            @Override
            public boolean handleMessage(Message msg) {
                Bundle data = msg.getData();
                Boolean success = data.getBoolean("success");
                dismissProgressDialog();
                if (rd != null) {
                    rd.inProgress = false;
                }
                if (success) {
                    String auth_token = data.getString("auth_token");
                    int id = data.getInt("id");
                    if (id < 0) {
                        launchErrorDialog("", "Login failed : " + data.toString());
                    } else {
                        if (auth_token == null || auth_token.equals("") || auth_token.equals("null")) {
                            auth_token = "";
                        }
                        launchMainMapActivity(auth_token, id);
                    }
                } else {
                    String title = "";
                    if (data.containsKey("info_title")) {
                        title = data.getString("info_title");
                    }
                    launchErrorDialog(title, data.getString("info"));
                }
                return true;
            }
        });
    }

    Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

}

From source file:org.sufficientlysecure.keychain.ui.QrCodeScanActivity.java

public void importKeys(String fingerprint) {
    // Message is received after importing is done in KeychainIntentService
    KeychainIntentServiceHandler serviceHandler = new KeychainIntentServiceHandler(this,
            getString(R.string.progress_importing), ProgressDialog.STYLE_HORIZONTAL, true) {
        public void handleMessage(Message message) {
            // handle messages by standard KeychainIntentServiceHandler first
            super.handleMessage(message);

            if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
                // get returned data bundle
                Bundle returnData = message.getData();
                if (returnData == null) {
                    finish();// w w w  .  ja va 2s  .co  m
                    return;
                }
                final ImportKeyResult result = returnData.getParcelable(OperationResult.EXTRA_RESULT);
                if (result == null) {
                    Log.e(Constants.TAG, "result == null");
                    finish();
                    return;
                }

                if (!result.success()) {
                    // only return if no success...
                    Intent data = new Intent();
                    data.putExtras(returnData);
                    returnResult(data);
                    return;
                }

                Intent certifyIntent = new Intent(QrCodeScanActivity.this, CertifyKeyActivity.class);
                certifyIntent.putExtra(CertifyKeyActivity.EXTRA_RESULT, result);
                certifyIntent.putExtra(CertifyKeyActivity.EXTRA_KEY_IDS, result.getImportedMasterKeyIds());
                startActivityForResult(certifyIntent, 0);
            }
        }
    };

    // search config
    Preferences prefs = Preferences.getPreferences(this);
    Preferences.CloudSearchPrefs cloudPrefs = new Preferences.CloudSearchPrefs(true, true,
            prefs.getPreferredKeyserver());

    // Send all information needed to service to query keys in other thread
    Intent intent = new Intent(this, KeychainIntentService.class);

    intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYRING);

    // fill values for this action
    Bundle data = new Bundle();

    data.putString(KeychainIntentService.IMPORT_KEY_SERVER, cloudPrefs.keyserver);

    ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null);
    ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<ParcelableKeyRing>();
    selectedEntries.add(keyEntry);

    data.putParcelableArrayList(KeychainIntentService.IMPORT_KEY_LIST, selectedEntries);

    intent.putExtra(KeychainIntentService.EXTRA_DATA, data);

    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(serviceHandler);
    intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);

    // show progress dialog
    serviceHandler.showProgressDialog(this);

    // start service with intent
    startService(intent);
}

From source file:com.nextgis.mobile.MainActivity.java

void doBindService() {

    mTrackAddPointHandler = new Handler() {
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            Bundle resultData = msg.getData();
            double dfLat = resultData.getDouble("lat");
            double dfLon = resultData.getDouble("lon");
            //               mMap.addPointToRouteOverlay(dfLon, dfLat);
        }//from w w w .  j  a v  a 2s. co m
    };

    bindService(new Intent(this, TrackerService.class), m_oConnection, 0);
}

From source file:org.sufficientlysecure.keychain.ui.ImportKeysActivity.java

/**
 * Show to dialog from where to import keys
 *//*from w  w w  .ja  v  a 2 s  .c  om*/
public void showImportFromFileDialog() {
    // Message is received after file is selected
    Handler returnHandler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            if (message.what == FileDialogFragment.MESSAGE_OKAY) {
                Bundle data = message.getData();
                mImportFilename = data.getString(FileDialogFragment.MESSAGE_DATA_FILENAME);
                mDeleteAfterImport = data.getBoolean(FileDialogFragment.MESSAGE_DATA_CHECKED);

                Log.d(Constants.TAG, "mImportFilename: " + mImportFilename);
                Log.d(Constants.TAG, "mDeleteAfterImport: " + mDeleteAfterImport);

                loadKeyListFragment();
            }
        }
    };

    // Create a new Messenger for the communication back
    final Messenger messenger = new Messenger(returnHandler);

    DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() {
        public void run() {
            mFileDialog = FileDialogFragment.newInstance(messenger, getString(R.string.title_importKeys),
                    getString(R.string.specifyFileToImportFrom), Constants.path.APP_DIR + "/", null,
                    Id.request.filename);

            mFileDialog.show(getSupportFragmentManager(), "fileDialog");
        }
    });
}

From source file:com.first3.viz.download.DownloadManager.java

private Resource getResourceFromMsg(Message msg) {
    Bundle b = msg.getData();
    b.setClassLoader(getClassLoader());//  w  w w . ja  v a2s  . c  o m
    Resource r = b.getParcelable(RESOURCE);
    return r;
}

From source file:kr.ac.kaist.resl.sensorservice.BluetoothService.java

@SuppressLint("HandlerLeak")
@Override/*from w  ww .j  ava  2  s .  co m*/
public void onStart(Intent intent, int startId) {

    androidId = android.provider.Settings.Secure.getString(this.getContentResolver(),
            Settings.Secure.ANDROID_ID);

    invokeBLEmanagerService();
    invokeBLEservice();

    // Check if the android phone supports BLE
    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
        Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
    }

    // Init msg handler for device scanner
    scannerMsgHandler = new Handler() {
        public void handleMessage(Message msg) {

            String deviceName = msg.getData().getString(DeviceScanner.MSG_KEY_DEVICE_NAME);
            String deviceAddress = msg.getData().getString(DeviceScanner.MSG_KEY_DEVICE_ADDRESS);
            if (deviceName.equals("MIO GLOBAL LINK")) {
                connectTo(deviceName, deviceAddress);
            }
        }
    };

    // Init scanner
    scanner = new DeviceScanner((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE),
            scannerMsgHandler);
    mBluetoothAdapter = scanner.initialize();

    if (mBluetoothAdapter == null) {
        Toast.makeText(this, R.string.error_bluetooth_not_supported, Toast.LENGTH_SHORT).show();
        return;
    }

    // Init device-service-characteristic table.
    init_Device_Service_CharacteristicTable();

    // Register braodcast receiver
    registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter());

    if (!scanner.isScanning()) {
        scanner.scanLeDevice(true);
    } else
        bleService.reconnect();

}

From source file:it.angrydroids.epub3reader.TextSelectionSupport.java

@Override
public boolean onLongClick(View v) {

    if (!isInSelectionMode()) {
        mWebView.loadUrl("javascript:android.selection.longTouch();");
        mScrolling = true;/*w  ww  . ja va2s  .  co  m*/
    }
    Message msg = new Message();
    msg.setTarget(new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            String url = msg.getData().getString("url");
            if (url != null)
                navigator.setNote(url, index);
        }
    });
    mWebView.requestFocusNodeHref(msg);
    return true;
}