Example usage for android.app Activity runOnUiThread

List of usage examples for android.app Activity runOnUiThread

Introduction

In this page you can find the example usage for android.app Activity runOnUiThread.

Prototype

public final void runOnUiThread(Runnable action) 

Source Link

Document

Runs the specified action on the UI thread.

Usage

From source file:com.imgtec.hobbyist.fragments.loginsignup.LogInFragment.java

private void setLogsAccessEnabled(boolean enabled) {
    loginError = enabled;//from  w  w  w. ja  v  a  2  s.c o  m
    final Activity activity = getActivity();
    if (activity != null) {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                activity.invalidateOptionsMenu();
            }
        });
    }
}

From source file:im.vector.activity.CommonActivityUtils.java

public static void goToRoomPage(final MXSession aSession, final String roomId, final Activity fromActivity,
        final Intent intentParam) {
    // check first if the 1:1 room already exists
    MXSession session = (aSession == null) ? Matrix.getMXSession(fromActivity, null) : aSession;

    // sanity check
    if ((null == session) || !session.isActive()) {
        return;//from   w w  w. ja v a  2s . co  m
    }

    final MXSession fSession = session;

    Room room = session.getDataHandler().getRoom(roomId);

    // do not open a leaving room.
    // it does not make.
    if ((null != room) && (room.isLeaving())) {
        return;
    }

    fromActivity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // if the activity is not the home activity
            if (!(fromActivity instanceof HomeActivity)) {
                // pop to the home activity
                Intent intent = new Intent(fromActivity, HomeActivity.class);
                intent.setFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP
                        | android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP);
                intent.putExtra(HomeActivity.EXTRA_JUMP_TO_ROOM_ID, roomId);
                intent.putExtra(HomeActivity.EXTRA_JUMP_MATRIX_ID, fSession.getCredentials().userId);
                if (null != intentParam) {
                    intent.putExtra(HomeActivity.EXTRA_ROOM_INTENT, intentParam);
                }
                fromActivity.startActivity(intent);
            } else {
                // already to the home activity
                // so just need to open the room activity
                Intent intent = new Intent(fromActivity, RoomActivity.class);
                intent.putExtra(RoomActivity.EXTRA_ROOM_ID, roomId);
                intent.putExtra(RoomActivity.EXTRA_MATRIX_ID, fSession.getCredentials().userId);
                if (null != intentParam) {
                    intent.putExtra(HomeActivity.EXTRA_ROOM_INTENT, intentParam);
                }
                fromActivity.startActivity(intent);
            }
        }
    });
}

From source file:com.fatelon.partyphotobooth.fragments.NoticeFragment.java

@Override
public void onResume() {
    super.onResume();

    if (mIsScreenValid) {
        // Schedule auto-dismissal of the fragment.
        mDismissalTimer = new Timer(AUTO_DISMISSAL_TIMER_NAME);
        mDismissalTimer.schedule(new TimerTask() {
            @Override/* w w w .j ava2s  .  com*/
            public void run() {
                // Post dismissal request to ui thread.
                final Activity activity = getActivity();
                if (activity != null && !activity.isFinishing()) {
                    activity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            // Call to client.
                            ICallbacks callbacks = getCallbacks();
                            if (callbacks != null) {
                                callbacks.onNoticeDismissRequested();
                            }
                        }
                    });
                }
            }
        }, AUTO_DISMISSAL_TIMEOUT);
    }
}

From source file:com.vuze.android.remote.AndroidUtils.java

public static void showFeatureRequiresVuze(final Activity activity, final String feature) {
    activity.runOnUiThread(new Runnable() {
        public void run() {
            if (activity.isFinishing()) {
                if (DEBUG) {
                    System.out.println("can't display -- finishing");
                }//from   www  . j av a 2 s .  c o  m
                return;
            }
            String msg = activity.getResources().getString(R.string.vuze_required, feature);
            Builder builder = new AlertDialog.Builder(activity).setMessage(msg).setCancelable(true)
                    .setPositiveButton(android.R.string.ok, new OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    });
            builder.show();
        }
    });

}

From source file:me.heron.safefoodscanner.activity.MainActivity.java

private void showNoNetworkError() {

    final Activity activity = this;
    activity.runOnUiThread(new Runnable() {
        @Override/*from  w  w w  .j a  v  a2 s.  com*/
        public void run() {

            DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    finish();
                }
            };

            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setTitle(R.string.error_dialog_title).setMessage(R.string.no_network_connection)
                    .setPositiveButton(R.string.ok, listener).show();

        }
    });

}

From source file:org.messic.android.smartphone.activities.main.fragments.downloaded.DownloadedFragment.java

private void updateAlbums() {
    android.app.Activity activity = getActivity();
    if (activity != null) {
        activity.runOnUiThread(new Runnable() {
            @Override/*from  w ww.  jav  a  2 s  .c om*/
            public void run() {
                mProgressBar.setVisibility(View.VISIBLE);
                mAdapter.clear();
                Observable<MDMAlbum> observable = presenter.getDownloadedAlbums();
                observable.subscribeOn(Schedulers.io()).onBackpressureBuffer()
                        .observeOn(AndroidSchedulers.mainThread()).subscribe(downloadedAlbumsOnNext,
                                downloadedAlbumsOnError, downloadedAlbumsOnCompleted);
            }
        });

    }

}

From source file:com.rjfun.cordova.qq.QQPlugin.java

public boolean share(JSONObject args) {
    Log.d(LOGTAG, "share");

    if (!this.inited) {
        this.mTencent = Tencent.createInstance(this.appId, this.getActivity().getApplicationContext());
        this.inited = true;
    }/*www .  j  a  v  a  2s. c o m*/

    String message = args.optString(OPT_MESSAGE);
    String subject = args.optString(OPT_SUBJECT);
    String image = args.optString(OPT_IMAGE);
    String url = args.optString(OPT_URL);

    final boolean qqZone = args.optBoolean(OPT_QQZONE);
    final Bundle params = new Bundle();
    if (qqZone) {
        params.putInt(QzoneShare.SHARE_TO_QZONE_KEY_TYPE, QzoneShare.SHARE_TO_QZONE_TYPE_IMAGE_TEXT);
        params.putString(QzoneShare.SHARE_TO_QQ_TITLE, subject);
        params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, message);
        params.putString(QzoneShare.SHARE_TO_QQ_TARGET_URL, url);
        ArrayList<String> images = new ArrayList<String>();
        images.add(image);
        params.putStringArrayList(QQShare.SHARE_TO_QQ_IMAGE_URL, images);
        params.putString(QzoneShare.SHARE_TO_QQ_APP_NAME, this.appName + "" + this.appId);

    } else {
        params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
        params.putString(QQShare.SHARE_TO_QQ_TITLE, subject);
        params.putString(QQShare.SHARE_TO_QQ_SUMMARY, message);
        params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, url);
        params.putString(QzoneShare.SHARE_TO_QQ_IMAGE_URL, image);
        params.putString(QQShare.SHARE_TO_QQ_APP_NAME, this.appName + "" + this.appId);
        //params.putInt(QQShare.SHARE_TO_QQ_EXT_INT,  0);
    }

    final Activity activity = this.getActivity();
    final IUiListener qqDelegate = this;
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (qqZone) {
                mTencent.shareToQzone(activity, params, qqDelegate);
            } else {
                mTencent.shareToQQ(activity, params, qqDelegate);
            }
        }
    });

    return true;
}

From source file:org.deviceconnect.android.deviceplugin.hue.activity.fragment.HueFragment02.java

/**
 * ??RunnableUI????.// www.  ja  v  a 2 s.c  om
 * @param run ?Runnable
 */
private void runOnUiThread(final Runnable run) {
    final Activity activity = getActivity();
    if (activity != null) {
        activity.runOnUiThread(run);
    }
}

From source file:com.vuze.android.remote.AndroidUtils.java

public static void showDialog(final Activity activity, final CharSequence title, final CharSequence msg) {
    activity.runOnUiThread(new Runnable() {
        public void run() {
            if (activity.isFinishing()) {
                if (DEBUG) {
                    System.out.println("can't display -- finishing");
                }// www.  j a v  a2 s .c  om
                return;
            }
            Builder builder = new AlertDialog.Builder(activity).setMessage(msg).setCancelable(true)
                    .setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    });
            if (title != null) {
                builder.setTitle(title);
            }
            builder.show();
        }
    });

}

From source file:org.gluu.oxpush2.app.ProcessFragment.java

private void runOnUiThread(Runnable runnable) {
    Activity activity = getActivity();
    if (activity != null) {
        activity.runOnUiThread(runnable);
    } else {/*from  ww  w.  j  a va2s. c  o m*/
        if (BuildConfig.DEBUG)
            Log.d(TAG, "Activity is null!");
    }
}