Java Code Examples for android.os.Message#setTarget()

The following examples show how to use android.os.Message#setTarget() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrowserActivity.java    From browser with GNU General Public License v2.0 6 votes vote down vote up
@Override
/**
 * handles long presses for the browser, tries to get the
 * url of the item that was clicked and sends it (it can be null)
 * to the click handler that does cool stuff with it
 */
public void onLongPress() {
	if (mClickHandler == null) {
		mClickHandler = new ClickHandler(mActivity);
	}
	Message click = mClickHandler.obtainMessage();
	if (click != null) {
		click.setTarget(mClickHandler);
		getCurrentWebView().getWebView().requestFocusNodeHref(click);
	}
}
 
Example 2
Source File: WXBridgeManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize JavaScript framework
 * @param framework String representation of the framework to be init.
 */
public synchronized void initScriptsFramework(String framework) {
  Message msg = mJSHandler.obtainMessage();
  msg.obj = framework;
  msg.what = WXJSBridgeMsgType.INIT_FRAMEWORK;
  msg.setTarget(mJSHandler);
  msg.sendToTarget();
}
 
Example 3
Source File: WXBridgeManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public void takeJSHeapSnapshot(String filename) {
  Message msg = mJSHandler.obtainMessage();
  msg.obj = filename;
  msg.what = WXJSBridgeMsgType.TAKE_HEAP_SNAPSHOT;
  msg.setTarget(mJSHandler);
  msg.sendToTarget();
}
 
Example 4
Source File: LightningView.java    From Xndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onLongPress(MotionEvent e) {
    if (mCanTriggerLongPress) {
        Message msg = mWebViewHandler.obtainMessage();
        if (msg != null) {
            msg.setTarget(mWebViewHandler);
            if (mWebView == null) {
                return;
            }
            mWebView.requestFocusNodeHref(msg);
        }
    }
}
 
Example 5
Source File: WXBridgeManager.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Initialize JavaScript framework
 * @param framework String representation of the framework to be init.
 */
public synchronized void initScriptsFramework(String framework) {
  Message msg = mJSHandler.obtainMessage();
  msg.obj = framework;
  msg.what = WXJSBridgeMsgType.INIT_FRAMEWORK;
  msg.setTarget(mJSHandler);
  msg.sendToTarget();
}
 
Example 6
Source File: ComplexActivity.java    From AndroidProjects with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_complex);

    main_image_view = (ImageView) findViewById(R.id.main_image_view);

    bitmapObject = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    main_image_view.setImageBitmap(bitmapObject);


    boolean isUiThread = Looper.getMainLooper().getThread() == Thread.currentThread();

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
        isUiThread = Looper.getMainLooper().isCurrentThread();
    }
    Log.e("Edwin", "isUiThread = " + isUiThread);

    Message message = mHandler2.obtainMessage();
    message.what = 1;
    message.obj = 100;
    message.setTarget(mHandler2);
    message.sendToTarget();

    Message message2 = mHandler2.obtainMessage();
    message2.what = 0;
    message2.obj = 200;
    message2.sendToTarget();


    new LooperThread1().start();
    new LooperThread2().start();

}
 
Example 7
Source File: WXBridgeManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize JavaScript framework
 * @param framework String representation of the framework to be init.
 */
public synchronized void initScriptsFramework(String framework) {
  Message msg = mJSHandler.obtainMessage();
  msg.obj = framework;
  msg.what = WXJSBridgeMsgType.INIT_FRAMEWORK;
  msg.setTarget(mJSHandler);
  msg.sendToTarget();
}
 
Example 8
Source File: LightningView.java    From JumpGo with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void onLongPress(MotionEvent e) {
    if (mCanTriggerLongPress) {
        Message msg = mWebViewHandler.obtainMessage();
        if (msg != null) {
            msg.setTarget(mWebViewHandler);
            if (mWebView == null) {
                return;
            }
            mWebView.requestFocusNodeHref(msg);
        }
    }
}
 
Example 9
Source File: NinjaWebView.java    From Ninja with Apache License 2.0 5 votes vote down vote up
public void onLongPress() {
    Message click = clickHandler.obtainMessage();
    if (click != null) {
        click.setTarget(clickHandler);
    }
    requestFocusNodeHref(click);
}
 
Example 10
Source File: LinkHandler.java    From firefox-echo-show with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    if (callback == null) {
        return false;
    }

    final WebView.HitTestResult hitTestResult = webView.getHitTestResult();

    switch (hitTestResult.getType()) {
        case WebView.HitTestResult.SRC_ANCHOR_TYPE:
            final String linkURL = hitTestResult.getExtra();
            callback.onLongPress(new IWebView.HitTarget(true, linkURL, false, null));
            return true;

        case WebView.HitTestResult.IMAGE_TYPE:
            final String imageURL = hitTestResult.getExtra();
            callback.onLongPress(new IWebView.HitTarget(false, null, true, imageURL));
            return true;

        case WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE:
            // hitTestResult.getExtra() contains only the image URL, and not the link
            // URL. Internally, WebView's HitTestData contains both, but they only
            // make it available via requestFocusNodeHref...
            final Message message = new Message();
            message.setTarget(new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    final Bundle data = msg.getData();
                    final String url = data.getString("url");
                    final String src = data.getString("src");

                    if (url == null || src == null) {
                        throw new IllegalStateException("WebView did not supply url or src for image link");
                    }

                    if (callback != null) {
                        callback.onLongPress(new IWebView.HitTarget(true, url, true, src));
                    }
                }
            });

            webView.requestFocusNodeHref(message);
            return true;

        default:
            return false;
    }
}
 
Example 11
Source File: LinkHandler.java    From focus-android with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    if (callback == null) {
        return false;
    }

    final WebView.HitTestResult hitTestResult = webView.getHitTestResult();

    switch (hitTestResult.getType()) {
        case WebView.HitTestResult.SRC_ANCHOR_TYPE:
            final String linkURL = hitTestResult.getExtra();
            callback.onLongPress(new IWebView.HitTarget(true, linkURL, false, null));
            return true;

        case WebView.HitTestResult.IMAGE_TYPE:
            final String imageURL = hitTestResult.getExtra();
            callback.onLongPress(new IWebView.HitTarget(false, null, true, imageURL));
            return true;

        case WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE:
            // hitTestResult.getExtra() contains only the image URL, and not the link
            // URL. Internally, WebView's HitTestData contains both, but they only
            // make it available via requestFocusNodeHref...
            final Message message = new Message();
            message.setTarget(new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    final Bundle data = msg.getData();
                    final String url = data.getString("url");
                    final String src = data.getString("src");

                    if (url == null || src == null) {
                        throw new IllegalStateException("WebView did not supply url or src for image link");
                    }

                    if (callback != null) {
                        callback.onLongPress(new IWebView.HitTarget(true, url, true, src));
                    }
                }
            });

            webView.requestFocusNodeHref(message);
            return true;

        default:
            return false;
    }
}