Example usage for android.os Message sendToTarget

List of usage examples for android.os Message sendToTarget

Introduction

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

Prototype

public void sendToTarget() 

Source Link

Document

Sends this Message to the Handler specified by #getTarget .

Usage

From source file:org.ohmage.app.SurveyActivity.java

@Override
public void onLoadFinished(Loader<ArrayList<Prompt>> loader, ArrayList<Prompt> data) {
    if (data == null) {
        Toast.makeText(this, R.string.survey_not_found, Toast.LENGTH_SHORT).show();
        finish();//from ww  w .ja  v  a2  s . c  o m
        return;
    }

    if (mPagerAdapter == null) {
        setPrompts(data);

        // Check for remote activity prompts and make sure they all exist
        if (data != null) {
            ApkSet appItems = ApkSet.fromPromptsIgnoreSkippable(data);
            appItems.clearInstalled(this);

            if (!appItems.isEmpty()) {
                Message msg = handler.obtainMessage(MSG_SHOW_INSTALL_DEPENDENCIES);
                msg.obj = appItems;
                msg.sendToTarget();
            }
        }
    }
}

From source file:com.android.mms.ui.MessageListItem.java

private void sendMessage(MessageItem messageItem, int message) {
    if (mHandler != null) {
        Message msg = Message.obtain(mHandler, message);
        msg.obj = messageItem;//from  w w w  .  ja v a 2 s  .  c om
        msg.sendToTarget(); // See ComposeMessageActivity.mMessageListItemHandler.handleMessage
    }
}

From source file:com.rowland.hashtrace.utility.AsyncTaskEx.java

/**
 * Creates a new asynchronous task. This constructor must be invoked on the
 * UI thread./*from  w w  w .j a  va  2s .  c om*/
 */
public AsyncTaskEx() {
    mWorker = new WorkerRunnable<Params, Result>() {
        @Override
        public Result call() throws Exception {
            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
            return doInBackground(mParams);
        }
    };

    mFuture = new FutureTask<Result>(mWorker) {
        @SuppressWarnings("unchecked")
        @Override
        protected void done() {
            Message message;
            Result result = null;

            try {
                result = get();
            } catch (InterruptedException e) {
                android.util.Log.w(LOG_TAG, e);
            } catch (ExecutionException e) {
                throw new RuntimeException("An error occured while executing doInBackground()", e.getCause());
            } catch (CancellationException e) {
                message = sHandler.obtainMessage(MESSAGE_POST_CANCEL,
                        new AsyncTaskExResult<Result>(AsyncTaskEx.this, (Result[]) null));
                message.sendToTarget();
                return;
            } catch (Throwable t) {
                throw new RuntimeException("An error occured while executing " + "doInBackground()", t);
            }

            message = sHandler.obtainMessage(MESSAGE_POST_RESULT,
                    new AsyncTaskExResult<Result>(AsyncTaskEx.this, result));
            message.sendToTarget();
        }
    };
}

From source file:org.navitproject.navit.Navit.java

private void parseNavigationURI(String schemeSpecificPart) {
    String naviData[] = schemeSpecificPart.split("&");
    Pattern p = Pattern.compile("(.*)=(.*)");
    Map<String, String> params = new HashMap<String, String>();
    for (int count = 0; count < naviData.length; count++) {
        Matcher m = p.matcher(naviData[count]);

        if (m.matches()) {
            params.put(m.group(1), m.group(2));
        }// w w  w  . j a  v a  2  s  . c o  m
    }

    // d: google.navigation:q=blabla-strasse # (this happens when you are offline, or from contacts)
    // a: google.navigation:ll=48.25676,16.643&q=blabla-strasse
    // c: google.navigation:ll=48.25676,16.643
    // b: google.navigation:q=48.25676,16.643

    Float lat;
    Float lon;
    Bundle b = new Bundle();

    String geoString = params.get("ll");
    if (geoString != null) {
        String address = params.get("q");
        if (address != null)
            b.putString("q", address);
    } else {
        geoString = params.get("q");
    }

    if (geoString != null) {
        if (geoString.matches("^[+-]{0,1}\\d+(|\\.\\d*),[+-]{0,1}\\d+(|\\.\\d*)$")) {
            String geo[] = geoString.split(",");
            if (geo.length == 2) {
                try {
                    lat = Float.valueOf(geo[0]);
                    lon = Float.valueOf(geo[1]);
                    b.putFloat("lat", lat);
                    b.putFloat("lon", lon);
                    Message msg = Message.obtain(N_NavitGraphics.callback_handler,
                            NavitGraphics.msg_type.CLB_SET_DESTINATION.ordinal());

                    msg.setData(b);
                    msg.sendToTarget();
                    Log.e("Navit", "target found (b): " + geoString);
                } catch (NumberFormatException e) {
                } // nothing to do here
            }
        } else {
            start_targetsearch_from_intent(geoString);
        }
    }
}

From source file:org.zywx.wbpalmstar.engine.EBrowserWidget.java

public void setWindowFrame(EBrowserWindow window, int x, int y, int duration) {
    EViewEntry en = new EViewEntry();
    en.x = x;//from   www. ja  v  a  2  s . c o m
    en.y = y;
    en.duration = duration;
    en.obj = window;
    Message msg = mWidgetLoop.obtainMessage(F_WIDGET_HANDLER_SET_WINDOW);
    msg.obj = en;
    msg.sendToTarget();
}

From source file:org.navitproject.navit.Navit.java

void setDestination(float latitude, float longitude, String address) {
    Toast.makeText(getApplicationContext(), getString(R.string.address_search_set_destination) + "\n" + address,
            Toast.LENGTH_LONG).show(); //TRANS

    Message msg = Message.obtain(N_NavitGraphics.callback_handler,
            NavitGraphics.msg_type.CLB_SET_DESTINATION.ordinal());
    Bundle b = new Bundle();
    b.putFloat("lat", latitude);
    b.putFloat("lon", longitude);
    b.putString("q", address);
    msg.setData(b);/*from  ww w  . j a  v  a2 s .  c o m*/
    msg.sendToTarget();
}

From source file:org.navitproject.navit.Navit.java

public void runOptionsItem(int id) {
    // Handle item selection
    switch (id) {
    case 1:/*  w ww  .  j  a  v a 2  s .  com*/
        // zoom in
        Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_ZOOM_IN.ordinal())
                .sendToTarget();
        // if we zoom, hide the bubble
        Log.e("Navit", "onOptionsItemSelected -> zoom in");
        break;
    case 2:
        // zoom out
        Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_ZOOM_OUT.ordinal())
                .sendToTarget();
        // if we zoom, hide the bubble
        Log.e("Navit", "onOptionsItemSelected -> zoom out");
        break;
    case 3:
        // map download menu
        Intent map_download_list_activity = new Intent(this, NavitDownloadSelectMapActivity.class);
        startActivityForResult(map_download_list_activity, Navit.NavitDownloaderSelectMap_id);
        break;
    case 5:
        // toggle the normal POI layers and labels (to avoid double POIs)
        Message msg = Message.obtain(N_NavitGraphics.callback_handler,
                NavitGraphics.msg_type.CLB_CALL_CMD.ordinal());
        Bundle b = new Bundle();
        b.putString("cmd", "toggle_layer(\"POI Symbols\");");
        msg.setData(b);
        msg.sendToTarget();

        msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_CALL_CMD.ordinal());
        b = new Bundle();
        b.putString("cmd", "toggle_layer(\"POI Labels\");");
        msg.setData(b);
        msg.sendToTarget();

        // toggle full POI icons on/off
        msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_CALL_CMD.ordinal());
        b = new Bundle();
        b.putString("cmd", "toggle_layer(\"Android-POI-Icons-full\");");
        msg.setData(b);
        msg.sendToTarget();

        break;
    case 6:
        // ok startup address search activity
        Intent search_intent = new Intent(this, NavitAddressSearchActivity.class);
        this.startActivityForResult(search_intent, NavitAddressSearch_id);
        break;
    case 7:
        /* Backup / Restore */
        showDialog(NavitDialogs.DIALOG_BACKUP_RESTORE);
        break;
    case 10:
        setMapLocation();
        break;
    case 99:
        // exit
        this.onStop();
        this.exit();
        break;
    }
}

From source file:ch.luklanis.esscan.history.HistoryActivity.java

private void createDTAFile(final Message message) {
    List<BankProfile> bankProfiles = mHistoryManager.getBankProfiles();

    List<String> banks = new ArrayList<String>();

    for (BankProfile bankProfile : bankProfiles) {
        banks.add(bankProfile.getName());
    }/* w w  w  .ja  v a  2s . c o  m*/

    new BankProfileListDialog(banks).setItemClickListener(new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int which) {
            long bankProfileId = mHistoryManager.getBankProfileId(which);
            Uri uri = createDTAFile(bankProfileId);
            message.obj = uri;
            message.sendToTarget();
        }
    }).show(getFragmentManager(), "HistoryActivity.createDTAFile");
}

From source file:org.openremote.android.console.AppSettingsActivity.java

/**
 * Initializes the SSL related UI widget properties and event handlers to deal with user
 * interactions.//from  w w w  .  j a v a  2s .  c o  m
 */
private void initSSLState() {
    // Get UI Widget references...

    final ToggleButton sslToggleButton = (ToggleButton) findViewById(R.id.ssl_toggle);
    final EditText sslPortEditField = (EditText) findViewById(R.id.ssl_port);

    final TextView pin = (TextView) findViewById(R.id.ssl_clientcert_pin);

    // Configure UI to current settings state...

    boolean sslEnabled = AppSettingsModel.isSSLEnabled(this);

    sslToggleButton.setChecked(sslEnabled);
    sslPortEditField.setText("" + AppSettingsModel.getSSLPort(this));

    // If SSL is off, disable the port edit field by default...

    if (!sslEnabled) {
        sslPortEditField.setEnabled(false);
        sslPortEditField.setFocusable(false);
        sslPortEditField.setFocusableInTouchMode(false);
    }

    // Manage state changes to SSL toggle...

    sslToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isEnabled) {

            // If SSL is being disabled, and the user had soft keyboard open, close it...

            if (!isEnabled) {
                InputMethodManager input = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                input.hideSoftInputFromWindow(sslPortEditField.getWindowToken(), 0);
            }

            // Set SSL state in config model accordingly...

            AppSettingsModel.enableSSL(AppSettingsActivity.this, isEnabled);

            // Enable/Disable SSL Port text field according to SSL toggle on/off state...

            sslPortEditField.setEnabled(isEnabled);
            sslPortEditField.setFocusable(isEnabled);
            sslPortEditField.setFocusableInTouchMode(isEnabled);
        }
    });

    pin.setText("...");

    final Handler pinHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            pin.setText(msg.getData().getString("pin"));
        }
    };

    new Thread() {
        public void run() {
            String pin = ORKeyPair.getInstance().getPIN(getApplicationContext());

            Bundle bundle = new Bundle();
            bundle.putString("pin", pin);

            Message msg = pinHandler.obtainMessage();
            msg.setData(bundle);

            msg.sendToTarget();
        }
    }.start();

    sslPortEditField.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            //TODO not very user friendly
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                String sslPortStr = ((EditText) v).getText().toString();

                try {
                    int sslPort = Integer.parseInt(sslPortStr.trim());
                    AppSettingsModel.setSSLPort(AppSettingsActivity.this, sslPort);
                }

                catch (NumberFormatException ex) {
                    Toast toast = Toast.makeText(getApplicationContext(), "SSL port format is not correct.", 1);
                    toast.show();

                    return false;
                }

                catch (IllegalArgumentException e) {
                    Toast toast = Toast.makeText(getApplicationContext(), e.getMessage(), 2);
                    toast.show();

                    sslPortEditField.setText("" + AppSettingsModel.getSSLPort(AppSettingsActivity.this));

                    return false;
                }
            }

            return false;
        }

    });

}

From source file:com.variable.demo.api.fragment.OxaFragment.java

@Override
public void onOxaUpdate(OxaSensor sensor, SensorReading<Float> reading) {
    Message m = mHandler.obtainMessage(MessageConstants.MESSAGE_OXA_READING);
    m.getData().putFloat(MessageConstants.FLOAT_VALUE_KEY, reading.getValue());
    final Context thiscontext = this.getActivity();
    final String serialnumOne = sensor.getSerialNumber();
    final String serialnum = serialnumOne.replaceAll("[^\\u0000-\\uFFFF]", "");
    final String scan = Float.toString(reading.getValue());
    String json = "oxygen;" + serialnum + ";" + scan;

    // POST to variable dashboard
    Ion.getDefault(thiscontext).getConscryptMiddleware().enable(false);
    Ion.with(thiscontext).load(/*  w  w  w. ja  va2s. c  o  m*/
            "https://datadipity.com/clickslide/fleetplusdata.json?PHPSESSID=gae519f8k5humje0jqb195nob6&update&postparam[payload]="
                    + json)
            .setLogging("MyLogs", Log.DEBUG).asString().withResponse()
            .setCallback(new FutureCallback<Response<String>>() {
                @Override
                public void onCompleted(Exception e, Response<String> result) {
                    if (e == null) {
                        Log.i(TAG, "ION SENT MESSAGE WITH RESULT CODE: " + result.toString());
                    } else {
                        Log.i(TAG, "ION SENT MESSAGE WITH EXCEPTION");
                        e.printStackTrace();
                    }
                }
            });
    m.sendToTarget();
}