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:im.vector.fragments.RoomMembersDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View v = inflater.inflate(R.layout.fragment_dialog_member_list, container, false);
    mListView = ((ListView) v.findViewById(R.id.listView_members));

    final Room room = mSession.getDataHandler().getRoom(mRoomId);

    HashMap<String, String> membershipStrings = new HashMap<String, String>();
    membershipStrings.put(RoomMember.MEMBERSHIP_INVITE, getActivity().getString(R.string.membership_invite));
    membershipStrings.put(RoomMember.MEMBERSHIP_JOIN, getActivity().getString(R.string.membership_join));
    membershipStrings.put(RoomMember.MEMBERSHIP_LEAVE, getActivity().getString(R.string.membership_leave));
    membershipStrings.put(RoomMember.MEMBERSHIP_BAN, getActivity().getString(R.string.membership_ban));

    mAdapter = new ConsoleRoomMembersAdapter(getActivity(), R.layout.adapter_item_room_members,
            room.getLiveState(), getMXMediasCache(), membershipStrings);

    // apply the sort settings
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    mAdapter.sortByLastActivePresence(/* w ww. j a  v  a2s  .co m*/
            preferences.getBoolean(getString(R.string.settings_key_sort_by_last_seen), true));
    mAdapter.displayMembership(
            preferences.getBoolean(getString(R.string.settings_key_display_left_members), false));

    boolean displayLeftMembers = preferences.getBoolean(getString(R.string.settings_key_display_left_members),
            false);

    Collection<RoomMember> members = room.getMembers();
    if (members != null) {
        IMXStore store = mSession.getDataHandler().getStore();

        for (RoomMember m : members) {
            // by default the
            if ((!m.hasLeft()) || displayLeftMembers) {
                mAdapter.add(m);
                mAdapter.saveUser(store.getUser(m.getUserId()));
            }
        }
        mAdapter.sortMembers();
    }

    mAdapter.setPowerLevels(room.getLiveState().getPowerLevels());
    mListView.setAdapter(mAdapter);

    // display the number of members in this room
    // don't update it dynamically
    // assume that the number of members will not be updated
    this.getDialog().setTitle(getString(R.string.members_list) + " (" + mAdapter.getCount() + ")");

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Get the member and display the possible actions for them
            final RoomMember roomMember = mAdapter.getItem(position);
            final Activity activity = VectorApp.getCurrentActivity();

            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Intent startRoomInfoIntent = new Intent(activity, MemberDetailsActivity.class);
                    startRoomInfoIntent.putExtra(MemberDetailsActivity.EXTRA_ROOM_ID, mRoomId);
                    startRoomInfoIntent.putExtra(MemberDetailsActivity.EXTRA_MEMBER_ID, roomMember.getUserId());
                    startRoomInfoIntent.putExtra(MemberDetailsActivity.EXTRA_MATRIX_ID,
                            mSession.getCredentials().userId);
                    startActivity(startRoomInfoIntent);
                }
            });

            // dismiss the member list
            RoomMembersDialogFragment.this.dismiss();
        }
    });

    return v;
}

From source file:org.messic.android.smartphone.activities.main.fragments.playlist.PlaylistFragment.java

private void updatePlaylists() {
    android.app.Activity activity = getActivity();
    if (activity != null) {

        activity.runOnUiThread(new Runnable() {
            @Override/*from w w  w .java 2  s.c o m*/
            public void run() {
                mProgressBar.setVisibility(View.VISIBLE);
                mAdapter.clear();
                Observable<MDMPlaylist> observable = presenter.getPlaylists();
                observable.subscribeOn(Schedulers.io()).onBackpressureBuffer()
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(playlistsOnNext, playlistsOnError, playlistsOnCompleted);
            }
        });
    }

}

From source file:fr.kwiatkowski.apktrack.ui.AppDisplayFragment.java

/**
 * Helper function which runs a given Runnable inside the UI Thread.
 * @param r The Runnable to run./*from  ww w  . j  a  v a 2 s  .c o m*/
 */
private void _run_on_ui_thread(Runnable r) {
    Activity activity = getActivity();
    if (activity != null) {
        activity.runOnUiThread(r);
    }
}

From source file:tv.ouya.sdk.OuyaUnityPlugin.java

public static void getOuyaContentPublished(final String sortMethod) {
    try {//w ww .  j a  v  a 2 s.co  m
        //Log.i(TAG, "getOuyaContentPublished");
        final Activity activity = IOuyaActivity.GetActivity();
        if (null != activity) {
            Runnable runnable = new Runnable() {
                public void run() {
                    OuyaContent ouyaContent = IOuyaActivity.GetOuyaContent();
                    UnityOuyaFacade unityOuyaFacade = IOuyaActivity.GetUnityOuyaFacade();
                    if (null == unityOuyaFacade) {
                        Log.e(TAG, "unityOuyaFacade is null");
                    } else {
                        OuyaContent.SortMethod sort = OuyaContent.SortMethod.valueOf(sortMethod);
                        //Log.i(TAG, "sortMethod="+sortMethod);
                        unityOuyaFacade.getOuyaContentPublished(sort);
                    }
                }
            };
            activity.runOnUiThread(runnable);
        }
    } catch (Exception e) {
        Log.e(TAG, "getOuyaContentPublished: exception=" + e.toString());
    }
}

From source file:com.juick.android.Utils.java

public static void verboseDebugString(final Activity context, final String s) {
    boolean verboseDebug = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("verboseDebug",
            false);//from   w w w.  jav a 2s  . c o  m
    if (verboseDebug) {
        context.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(context, s, Toast.LENGTH_SHORT).show();
            }
        });
    }
}

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

private void runOnUiThread(final Runnable run) {
    final Activity activity = getActivity();
    if (activity != null) {
        activity.runOnUiThread(run);
    }/*ww w  . j a  v a  2 s.  c  o  m*/
}

From source file:org.matrix.console.fragments.RoomMembersDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View v = inflater.inflate(R.layout.fragment_dialog_member_list, container, false);
    mListView = ((ListView) v.findViewById(R.id.listView_members));

    final Room room = mSession.getDataHandler().getRoom(mRoomId);

    HashMap<String, String> membershipStrings = new HashMap<String, String>();
    membershipStrings.put(RoomMember.MEMBERSHIP_INVITE, getActivity().getString(R.string.membership_invite));
    membershipStrings.put(RoomMember.MEMBERSHIP_JOIN, getActivity().getString(R.string.membership_join));
    membershipStrings.put(RoomMember.MEMBERSHIP_LEAVE, getActivity().getString(R.string.membership_leave));
    membershipStrings.put(RoomMember.MEMBERSHIP_BAN, getActivity().getString(R.string.membership_ban));

    mAdapter = new ConsoleRoomMembersAdapter(getActivity(), mSession.getHomeserverConfig(),
            R.layout.adapter_item_room_members, room.getLiveState(), getMXMediasCache(), membershipStrings);

    // apply the sort settings
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    mAdapter.sortByLastActivePresence(/*  w w  w  .  j a  va  2s .  com*/
            preferences.getBoolean(getString(R.string.settings_key_sort_by_last_seen), true));
    mAdapter.displayMembership(
            preferences.getBoolean(getString(R.string.settings_key_display_left_members), false));

    boolean displayLeftMembers = preferences.getBoolean(getString(R.string.settings_key_display_left_members),
            false);

    Collection<RoomMember> members = room.getMembers();
    if (members != null) {
        IMXStore store = mSession.getDataHandler().getStore();

        for (RoomMember m : members) {
            // by default the
            if ((!m.hasLeft()) || displayLeftMembers) {
                mAdapter.add(m);
                mAdapter.saveUser(store.getUser(m.getUserId()));
            }
        }
        mAdapter.sortMembers();
    }

    mAdapter.setPowerLevels(room.getLiveState().getPowerLevels());
    mListView.setAdapter(mAdapter);

    // display the number of members in this room
    // don't update it dynamically
    // assume that the number of members will not be updated
    this.getDialog().setTitle(getString(R.string.members_list) + " (" + mAdapter.getCount() + ")");

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Get the member and display the possible actions for them
            final RoomMember roomMember = mAdapter.getItem(position);
            final Activity activity = ConsoleApplication.getCurrentActivity();

            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Intent startRoomInfoIntent = new Intent(activity, MemberDetailsActivity.class);
                    startRoomInfoIntent.putExtra(MemberDetailsActivity.EXTRA_ROOM_ID, mRoomId);
                    startRoomInfoIntent.putExtra(MemberDetailsActivity.EXTRA_MEMBER_ID, roomMember.getUserId());
                    startRoomInfoIntent.putExtra(MemberDetailsActivity.EXTRA_MATRIX_ID,
                            mSession.getCredentials().userId);
                    startActivity(startRoomInfoIntent);
                }
            });

            // dismiss the member list
            RoomMembersDialogFragment.this.dismiss();
        }
    });

    return v;
}

From source file:org.messic.android.smartphone.activities.main.fragments.search.SearchFragment.java

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

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

/**
 * Wi-Fi???????????./*from w  w w.  j  av a  2s  .  c om*/
 */
private void showWifiNotConnected() {
    final Activity activity = getActivity();
    if (activity != null) {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                new AlertDialog.Builder(getActivity()).setTitle(R.string.hue_dialog_network_error)
                        .setMessage(R.string.hue_dialog_not_connect_wifi)
                        .setPositiveButton(R.string.hue_dialog_ok, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(final DialogInterface dialog, final int which) {
                            }
                        }).setCancelable(false).show();
            }
        });
    }
}

From source file:org.messic.android.smartphone.activities.main.fragments.explore.ExploreFragment.java

private void updateAuthors() {
    android.app.Activity activity = getActivity();
    if (activity != null) {
        activity.runOnUiThread(new Runnable() {
            @Override//from ww  w  .  ja  va 2  s.  co m
            public void run() {
                mProgressBar.setVisibility(View.VISIBLE);
                Observable<MDMAuthor> observable = presenter.getAuthors();
                mAdapter.clear();
                observable.subscribeOn(Schedulers.io()).onBackpressureBuffer()
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(exploreAuthorOnNext, exploreAuthorOnError, exploreAuthorOnCompleted);
            }
        });
    }

}