How to create a custom widget like Toast and not block the UI?
<p><strong>Note: this is not a question on how to create a custom view</strong></p>

<p>I've created a custom widget, kind of like a combination of <code>Toast</code> and <code>Snackbar</code>. Meaning, you get a snackbar which is not attached at the bottom of the screen and you can assign an <code>onClickListener</code> unlike <code>Toast</code>. My problem is after displaying the widget, it blocks the UI.</p>

<p>This is how I create my widget:</p>

<pre><code>private void createWidget() {
    Context context = view.getContext();
    int gravity;
    final Configuration config = view.getContext().getResources().getConfiguration();
    if (android.os.Build.VERSION.SDK_INT &gt;= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        gravity = Gravity.getAbsoluteGravity(Gravity.BOTTOM, config.getLayoutDirection());
    } else {
        gravity = Gravity.BOTTOM;
    }

    // region setup window parameters
    windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

    DisplayMetrics metrics = new DisplayMetrics();
    windowManager.getDefaultDisplay().getMetrics(metrics);

    params = new WindowManager.LayoutParams();
    params.height = WindowManager.LayoutParams.WRAP_CONTENT;
    params.width = metrics.widthPixels - context.getResources().getDimensionPixelSize(R.dimen.margin);
    params.format = PixelFormat.TRANSLUCENT;

    if((gravity &amp; Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL)
        params.horizontalWeight = 1.0f;

    if((gravity &amp; Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL)
        params.verticalWeight = 1.0f;

    params.gravity = gravity;
    params.verticalMargin = 0.25f;

    windowManager.addView(view, params);
}
</code></pre>

<p>and then I'm calling:</p>

<pre><code>showHandler = new Runnable() {
        @Override
        public void run() {
            createWidget();
        }
    };
....    
Handler handler = new Handler();
handler.post(showHandler);
</code></pre>

<p>I saw the source of <code>Toast</code> and it has this piece of code that I think I need to add to my widget to achieve what I want.</p>

<pre><code>public void show() {
    if (mNextView == null) {
        throw new RuntimeException("setView must have been called");
    }

    INotificationManager service = getService();
    String pkg = mContext.getOpPackageName();
    TN tn = mTN;
    tn.mNextView = mNextView;

    try {
        service.enqueueToast(pkg, tn, mDuration);
    } catch (RemoteException e) {
        // Empty
    }
}
</code></pre>

<p>The piece of code that I'm talking about is <code>service.enqueueToast(pkg, tn, mDuration);</code> but I've searched <code>INotificationManager</code> and it seems that it is a private package.</p>