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.example.echoprint.AudioFingerprinter.java

private void didFailWithException(final Exception e) {
    if (listener == null)
        return;//  ww  w. jav a 2  s.c  o m

    if (listener instanceof Activity) {
        Activity activity = (Activity) listener;
        activity.runOnUiThread(new Runnable() {
            public void run() {
                listener.didFailWithException(e);
            }
        });
    } else
        listener.didFailWithException(e);
}

From source file:org.deviceconnect.android.deviceplugin.uvc.fragment.UVCDeviceListFragment.java

/**
 * Added the view at ListView./*from w  w  w.j  a  v  a 2s  . c  o  m*/
 */
private void addFooterView() {
    final Activity activity = getActivity();
    if (activity == null) {
        return;
    }
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            UVCDeviceManager mgr = getManager();
            if (mgr == null) {
                return;
            }
            LayoutInflater inflater = activity.getLayoutInflater();
            if (mFooterView != null) {
                mListView.removeFooterView(mFooterView);
            }
            if (mgr.getDeviceList().size() == 0) {
                mFooterView = inflater.inflate(R.layout.item_uvc_error, null);
                mListView.addFooterView(mFooterView);
            }
        }
    });
}

From source file:com.digitalvotingpass.camera.CameraFragment.java

/**
 * Shows a {@link Toast} on the UI thread.
 *
 * @param text The message to show/*www . j  ava 2  s  . c o  m*/
 */
public void showToast(final String text) {
    final Activity activity = getActivity();
    if (activity != null) {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(activity, text, Toast.LENGTH_SHORT).show();
            }
        });
    }
}

From source file:com.grarak.kerneladiutor.fragments.tools.BuildpropFragment.java

private void load(final List<RecyclerViewItem> items) {
    if (mProps == null)
        return;/* w  w w  . java2 s  .  c o m*/
    String[] titles = mProps.keySet().toArray(new String[mProps.size()]);
    for (int i = 0; i < mProps.size(); i++) {
        final String title = titles[i];
        final String value = mProps.values().toArray(new String[mProps.size()])[i];
        if ((mKeyText != null && !title.contains(mKeyText)
                || (mValueText != null && !value.contains(mValueText)))) {
            continue;
        }

        int color = ViewUtils.getThemeAccentColor(getActivity());
        String colorCode = "#" + Integer.toHexString(Color.red(color)) + Integer.toHexString(Color.green(color))
                + Integer.toHexString(Color.blue(color));

        DescriptionView descriptionView = new DescriptionView();
        if (mKeyText != null && !mKeyText.isEmpty()) {
            descriptionView.setTitle(Utils.htmlFrom(title.replace(mKeyText,
                    "<b><font color=\"" + colorCode + "\">" + mKeyText + "</font></b>")));
        } else {
            descriptionView.setTitle(title);
        }
        if (mValueText != null && !mValueText.isEmpty()) {
            descriptionView.setSummary(Utils.htmlFrom(value.replace(mValueText,
                    "<b><font color=\"" + colorCode + "\">" + mKeyText + "</font></b>")));
        } else {
            descriptionView.setSummary(value);
        }
        descriptionView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {
            @Override
            public void onClick(RecyclerViewItem item) {
                mItemOptionsDialog = new Dialog(getActivity())
                        .setItems(getResources().getStringArray(R.array.build_prop_item_options),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int i) {
                                        switch (i) {
                                        case 0:
                                            modify(title, value);
                                            break;
                                        case 1:
                                            delete(title, value);
                                            break;
                                        }
                                    }
                                })
                        .setOnDismissListener(new DialogInterface.OnDismissListener() {
                            @Override
                            public void onDismiss(DialogInterface dialogInterface) {
                                mItemOptionsDialog = null;
                            }
                        });
                mItemOptionsDialog.show();
            }
        });

        items.add(descriptionView);
    }

    Activity activity;
    if (mSearchFragment != null && (activity = getActivity()) != null) {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (isAdded()) {
                    mSearchFragment.setCount(items.size());
                }
            }
        });
    }
}

From source file:com.sitewhere.android.example.ExampleFragment.java

/**
 * Sends most recent location and measurements to SiteWhere.
 *//*from   ww  w .java2s . c o m*/
protected void onSendDataToSiteWhere() {
    SiteWhereMessageClient messageClient = SiteWhereMessageClient.getInstance();
    try {
        if (lastLocation != null) {
            messageClient.sendDeviceLocation(messageClient.getUniqueDeviceId(), lastLocation.getLatitude(),
                    lastLocation.getLongitude(), lastLocation.getAltitude(), null);

            Activity activity = getActivity();

            if (activity != null) {
                activity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        //                            Toast.makeText(getActivity(), "Sent Location to SiteWhere", Toast.LENGTH_SHORT)
                        //                                    .show();
                    }
                });
            }
            Map<String, Double> measurements = new HashMap<>();
            measurements.put("x.rotation", new Double(lastRotation[0]));
            measurements.put("y.rotation", new Double(lastRotation[1]));
            measurements.put("z.rotation", new Double(lastRotation[2]));
            messageClient.sendDeviceMeasurements(messageClient.getUniqueDeviceId(), measurements, new Date());
        }
    } catch (Throwable e) {
        Log.e(TAG, "Unable to send location to SiteWhere.", e);
    }
}

From source file:at.ac.tuwien.detlef.fragments.EpisodeListFragment.java

private void filterByPodcastOnUiThread() {
    Activity activity = getActivity();
    if (activity == null) {
        return;//from  www .j a  va  2s.  c  o  m
    }

    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            filterByPodcast();
        }
    });
}

From source file:at.ac.tuwien.detlef.fragments.EpisodeListFragment.java

/**
 * Updates the displayed list based on the current model contents. Ensures
 * that UI methods are called on the UI thread.
 *//*from   ww  w .  ja  v a2s.  com*/
private void updateEpisodeList() {
    Activity activity = getActivity();
    if (activity == null) {
        return;
    }

    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            adapter.notifyDataSetChanged();
        }
    });
}

From source file:at.ac.tuwien.detlef.fragments.EpisodeListFragment.java

@Override
public void onEpisodeAdded(final Episode episode) {
    Activity activity = getActivity();
    if (activity == null) {
        return;/*from w  w  w .  j  a v  a  2s  .  co m*/
    }

    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            model.addEpisode(episode);
        }
    });
    filterByPodcastOnUiThread();
}

From source file:at.ac.tuwien.detlef.fragments.EpisodeListFragment.java

@Override
public void onEpisodeDeleted(final Episode episode) {
    Activity activity = getActivity();
    if (activity == null) {
        return;//from  w w  w. j a va  2s. c  o  m
    }

    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            model.removeEpisode(episode);
            adapter.notifyDataSetChanged();
        }
    });
}

From source file:com.macadamian.blinkup.BlinkUpPlugin.java

private boolean clearBlinkupData(final Activity activity, final BlinkupController controller) {
    PreferencesHelper.setPlanId(activity, null);
    sClearCache = true;/*from ww  w  . j  a  va2 s  .  c o  m*/
    controller.intentClearComplete = new Intent(activity, ClearCompleteActivity.class);

    // default is to run on WebCore thread, clearing shows UI so needs UI thread
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            controller.clearDevice(activity);
        }
    });
    return true;
}