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:com.google.zxing.client.android.book.NetworkWorker.java

@Override
public void run() {
    try {/*  ww  w.j a v  a 2s .c om*/
        // These return a JSON result which describes if and where the query was found. This API may
        // break or disappear at any time in the future. Since this is an API call rather than a
        // website, we don't use LocaleManager to change the TLD.
        String uri;
        if (LocaleManager.isBookSearchUrl(isbn)) {
            int equals = isbn.indexOf('=');
            String volumeId = isbn.substring(equals + 1);
            uri = "http://www.google.com/books?id=" + volumeId + "&jscmd=SearchWithinVolume2&q=" + query;
        } else {
            uri = "http://www.google.com/books?vid=isbn" + isbn + "&jscmd=SearchWithinVolume2&q=" + query;
        }

        try {
            String content = HttpHelper.downloadViaHttp(uri, HttpHelper.ContentType.JSON);
            JSONObject json = new JSONObject(content);
            Message message = Message.obtain(handler, R.id.search_book_contents_succeeded);
            message.obj = json;
            message.sendToTarget();
        } catch (IOException ioe) {
            Message message = Message.obtain(handler, R.id.search_book_contents_failed);
            message.sendToTarget();
        }
    } catch (JSONException je) {
        Log.w(TAG, "Error accessing book search", je);
        Message message = Message.obtain(handler, R.id.search_book_contents_failed);
        message.sendToTarget();
    }
}

From source file:org.appcelerator.titanium.util.TiDownloadManager.java

private void sendMessage(URI uri, int what) {
    Message msg = handler.obtainMessage(what);
    msg.obj = uri;
    msg.sendToTarget();
}

From source file:com.zxing.qrcode.decoding.CaptureActivityHandler.java

public void quitSynchronously() {
    state = State.DONE;//from  www  .java2s .c om
    CameraManager.get().stopPreview();
    Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit);
    quit.sendToTarget();
    try {
        decodeThread.join();
    } catch (InterruptedException e) {
        // continue
    }

    // Be absolutely sure we don't send any queued up messages
    removeMessages(R.id.decode_succeeded);
    // removeMessages(R.id.return_scan_result);
    removeMessages(R.id.decode_failed);
}

From source file:ru.tinkoff.acquiring.sdk.EnterCardFragment.java

private static void initPayment(final AcquiringSdk sdk, final InitRequestBuilder requestBuilder,
        final CardData cardData, final String googlePayToken, final String email, final boolean chargeMode) {

    new Thread(new Runnable() {
        @Override/*from w  w  w . j  a  v  a 2s  .co  m*/
        public void run() {
            try {
                requestBuilder.setChargeFlag(chargeMode && googlePayToken == null);
                final Long paymentId = sdk.init(requestBuilder);
                PayFormHandler.INSTANCE.obtainMessage(PayFormHandler.PAYMENT_INIT_COMPLETED, paymentId)
                        .sendToTarget();

                if (!chargeMode || googlePayToken != null) {
                    final ThreeDsData threeDsData;
                    if (googlePayToken == null) {
                        threeDsData = sdk.finishAuthorize(paymentId, cardData, email);
                    } else {
                        threeDsData = sdk.finishAuthorize(paymentId, googlePayToken, email);
                    }
                    if (threeDsData.isThreeDsNeed()) {
                        CommonSdkHandler.INSTANCE.obtainMessage(CommonSdkHandler.START_3DS, threeDsData)
                                .sendToTarget();
                    } else {
                        CommonSdkHandler.INSTANCE.obtainMessage(CommonSdkHandler.SUCCESS).sendToTarget();
                    }
                } else {
                    PaymentInfo paymentInfo = sdk.charge(paymentId, cardData.getRebillId());
                    if (paymentInfo.isSuccess()) {
                        CommonSdkHandler.INSTANCE.obtainMessage(CommonSdkHandler.SUCCESS).sendToTarget();
                    } else {
                        PayFormHandler.INSTANCE
                                .obtainMessage(PayFormHandler.CHARGE_REQUEST_REJECTED, paymentInfo)
                                .sendToTarget();
                    }
                }
            } catch (Exception e) {
                Throwable cause = e.getCause();
                Message msg;
                if (cause != null && cause instanceof NetworkException) {
                    msg = CommonSdkHandler.INSTANCE.obtainMessage(CommonSdkHandler.NO_NETWORK);
                } else {
                    msg = CommonSdkHandler.INSTANCE.obtainMessage(CommonSdkHandler.EXCEPTION, e);
                }
                msg.sendToTarget();
            }
        }
    }).start();
}

From source file:org.peterbaldwin.client.android.delicious.WebPageTitleRequest.java

/**
 * {@inheritDoc}/*  ww  w  .  j  av  a2  s .  com*/
 */
public void run() {
    try {
        DefaultHttpClient client = new DefaultHttpClient();
        client.setRedirectHandler(this);
        try {
            HttpGet request = new HttpGet(mUrl);

            // Set a generic User-Agent to avoid being 
            // redirected to a mobile UI.
            request.addHeader("User-Agent", "Mozilla/5.0");

            HttpResponse response = client.execute(request);
            HttpEntity entity = response.getEntity();
            StatusLine statusLine = response.getStatusLine();
            try {
                int statusCode = statusLine.getStatusCode();
                if (statusCode != HttpStatus.SC_OK) {
                    throw new IOException("Unexpected response code: " + statusCode);
                }

                // Send redirect before checking content type
                // because the redirect is important even if the
                // title cannot be extracted.
                if (mRedirectLocation != null && !mUrl.equals(mRedirectLocation)) {
                    int what = HANDLE_REDIRECT;
                    Object obj = mRedirectLocation;
                    Message msg = mHandler.obtainMessage(what, obj);
                    msg.sendToTarget();
                }
                Header contentType = entity.getContentType();
                if (contentType != null) {
                    String value = contentType.getValue();
                    if (!isHtml(value)) {
                        // This is important because the user might try
                        // bookmarking a video or another large file.
                        throw new IOException("Unsupported content type: " + value);
                    }
                } else {
                    throw new IOException("Content type is missing");
                }
                String source = EntityUtils.toString(entity);
                Html.ImageGetter imageGetter = null;
                Html.TagHandler tagHandler = this;
                Html.fromHtml(source, imageGetter, tagHandler);
            } finally {
                if (entity != null) {
                    entity.consumeContent();
                }
            }
        } finally {
            client.getConnectionManager().shutdown();
        }
    } catch (TerminateParser e) {
        // Thrown by handleTag to terminate parser early.
    } catch (IOException e) {
        Log.e(LOG_TAG, "i/o error", e);
    } catch (RuntimeException e) {
        Log.e(LOG_TAG, "runtime error", e);
    } catch (Error e) {
        Log.e(LOG_TAG, "severe error", e);
    } finally {
        Message msg = mHandler.obtainMessage(HANDLE_TITLE, mTitle);
        msg.sendToTarget();
    }
}

From source file:de.frank_durr.ble_v_monitor.CurrentVoltageFragment.java

/**
 * Trigger an update of the voltage data of the data model by querying the GATT server.
 * All interaction with the GATT server is done by the main activity, thus, we need
 * to send a message to the main activity to trigger the update. After the data model
 * has been updated, this fragment will receive a notification via the
 * update notification handler.//from  ww w. j  a v  a  2  s  .co  m
 */
private void triggerVoltageUpdate() {
    if (activity.updateTriggerHandler != null) {
        Message msg = activity.updateTriggerHandler.obtainMessage();
        msg.arg1 = MainActivity.UPDATE_CURRENT_VOLTAGE;
        msg.sendToTarget();
    }
}

From source file:net.pmarks.chromadoze.NoiseService.java

public void updatePercentAsync(int percent) {
    mPercentHandler.removeMessages(PERCENT_MSG);
    Message m = Message.obtain(mPercentHandler, PERCENT_MSG);
    m.arg1 = percent;//from   www.  j ava 2s .c o m
    m.sendToTarget();
}

From source file:com.activiti.android.app.fragments.HelpDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.app_webview, container, false);

    getToolbar().setVisibility(View.GONE);

    webView = (WebView) v.findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    emptyView = v.findViewById(R.id.empty);
    emptyTextView = (TextView) v.findViewById(R.id.empty_text);
    emptyTextView.setText(Html.fromHtml(getString(R.string.error_offline)));

    final Activity activity = getActivity();

    defaultUrl = activity.getString(R.string.help_user_guide_default_url);

    webView.setWebViewClient(new WebViewClient() {
        boolean hasError = false;

        @Override/*from   w  ww. j a  v a2 s.  c o m*/
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            hasError = false;
            getActivity().setProgressBarIndeterminateVisibility(true);
            refreshIcon.setVisible(false);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);

            // We redirect to default EN documentation if locale docs are
            // not available.
            if ((errorCode == ERROR_FILE_NOT_FOUND || errorCode == ERROR_HOST_LOOKUP) && !isDefault
                    && failingUrl.equals(rootUrl)) {
                hasError = true;
                view.loadUrl(defaultUrl);
                view.setVisibility(View.GONE);
            } else if (!ConnectivityUtils.hasInternetAvailable(getActivity())) {
                view.setVisibility(View.GONE);
                emptyView.setVisibility(View.VISIBLE);
                hasError = true;
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (hasError) {
                view.setVisibility(View.GONE);
            } else {
                view.setVisibility(View.VISIBLE);
            }

            if (getActivity() != null) {
                getActivity().setProgressBarIndeterminateVisibility(false);
                refreshIcon.setVisible(true);
            }
        }

        public void onFormResubmission(WebView view, Message dontResend, Message resend) {
            resend.sendToTarget();
        }

    });

    webView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (webView.canGoBack()) {
                        webView.goBack();
                        return true;
                    }
                    break;
                }
            }
            return false;
        }
    });

    rootUrl = getUrl(activity);
    webView.loadUrl(rootUrl);

    return v;
}

From source file:org.alfresco.mobile.android.application.fragments.help.HelpDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.app_webview, container, false);

    webView = (WebView) v.findViewById(org.alfresco.mobile.android.foundation.R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    emptyView = v.findViewById(org.alfresco.mobile.android.foundation.R.id.empty);
    emptyTextView = (TextView) v.findViewById(org.alfresco.mobile.android.foundation.R.id.empty_text);
    emptyTextView.setText(Html.fromHtml(getString(R.string.error_offline)));

    final FragmentActivity activity = getActivity();

    defaultUrl = activity.getString(R.string.help_user_guide_default_url);

    webView.setWebViewClient(new WebViewClient() {
        boolean hasError = false;

        @Override//from w  w w  .  j  a va 2  s  .  c  o  m
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            hasError = false;
            displayProgress(true);
            if (refreshIcon != null) {
                refreshIcon.setVisible(false);
            }
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);

            // We redirect to default EN documentation if locale docs are
            // not available.
            if ((errorCode == ERROR_FILE_NOT_FOUND || errorCode == ERROR_HOST_LOOKUP) && !isDefault
                    && failingUrl.equals(rootUrl)) {
                hasError = true;
                view.loadUrl(defaultUrl);
                view.setVisibility(View.GONE);
            } else if (!ConnectivityUtils.hasInternetAvailable(getActivity())) {
                view.setVisibility(View.GONE);
                emptyView.setVisibility(View.VISIBLE);
                hasError = true;
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (getActivity() == null) {
                return;
            }
            super.onPageFinished(view, url);
            if (hasError) {
                view.setVisibility(View.GONE);
            } else {
                view.setVisibility(View.VISIBLE);
            }
            displayProgress(false);
            if (refreshIcon != null) {
                refreshIcon.setVisible(true);
            }
        }

        public void onFormResubmission(WebView view, Message dontResend, Message resend) {
            resend.sendToTarget();
        }

    });

    webView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (webView.canGoBack()) {
                        webView.goBack();
                        return true;
                    }
                    break;
                }
            }
            return false;
        }
    });

    rootUrl = getUrl(activity);
    webView.loadUrl(rootUrl);

    return v;
}

From source file:com.dynamsoft.camera.DBR.java

private void openCamera() {
    new Thread(new Runnable() {
        @Override//  ww  w . j a v  a2s. c  om
        public void run() {
            mCamera = getCameraInstance();
            if (mCamera != null) {
                mCamera.setDisplayOrientation(90);
                Camera.Parameters cameraParameters = mCamera.getParameters();
                cameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
                mCamera.setParameters(cameraParameters);
            }

            Message message = handler.obtainMessage(OPEN_CAMERA, 1);
            message.sendToTarget();
        }
    }).start();
}