Example usage for android.widget ListView setVerticalScrollbarPosition

List of usage examples for android.widget ListView setVerticalScrollbarPosition

Introduction

In this page you can find the example usage for android.widget ListView setVerticalScrollbarPosition.

Prototype

@Override
    public void setVerticalScrollbarPosition(int position) 

Source Link

Usage

From source file:org.telegram.ui.ChannelUsersActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (type == 0) {
        actionBar.setTitle(LocaleController.getString("ChannelBlockedUsers", R.string.ChannelBlockedUsers));
    } else if (type == 1) {
        actionBar.setTitle(LocaleController.getString("ChannelAdministrators", R.string.ChannelAdministrators));
    } else if (type == 2) {
        actionBar.setTitle(LocaleController.getString("ChannelMembers", R.string.ChannelMembers));
    }/*from w w w  . ja  va2 s .  c  om*/
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();

    fragmentView = new FrameLayout(context);
    fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    emptyView = new EmptyTextProgressView(context);
    if (type == 0) {
        if (isMegagroup) {
            emptyView.setText(LocaleController.getString("NoBlockedGroup", R.string.NoBlockedGroup));
        } else {
            emptyView.setText(LocaleController.getString("NoBlocked", R.string.NoBlocked));
        }
    }
    frameLayout.addView(emptyView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    final ListView listView = new ListView(context);
    listView.setEmptyView(emptyView);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setDrawSelectorOnTop(true);
    listView.setAdapter(listViewAdapter = new ListAdapter(context));
    listView.setVerticalScrollbarPosition(
            LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
    frameLayout.addView(listView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (type == 2) {
                if (isAdmin) {
                    if (i == 0) {
                        Bundle args = new Bundle();
                        args.putBoolean("onlyUsers", true);
                        args.putBoolean("destroyAfterSelect", true);
                        args.putBoolean("returnAsResult", true);
                        args.putBoolean("needForwardCount", false);
                        args.putBoolean("allowUsernameSearch", false);
                        args.putString("selectAlertString",
                                LocaleController.getString("ChannelAddTo", R.string.ChannelAddTo));
                        ContactsActivity fragment = new ContactsActivity(args);
                        fragment.setDelegate(new ContactsActivity.ContactsActivityDelegate() {
                            @Override
                            public void didSelectContact(TLRPC.User user, String param) {
                                MessagesController.getInstance().addUserToChat(chatId, user, null,
                                        param != null ? Utilities.parseInt(param) : 0, null,
                                        ChannelUsersActivity.this);
                            }
                        });
                        presentFragment(fragment);
                    } else if (!isPublic && i == 1) {
                        presentFragment(new GroupInviteActivity(chatId));
                    }
                }

            } else if (type == 1) {
                if (isAdmin) {
                    if (isMegagroup && (i == 1 || i == 2)) {
                        TLRPC.Chat chat = MessagesController.getInstance().getChat(chatId);
                        if (chat == null) {
                            return;
                        }
                        boolean changed = false;
                        if (i == 1 && !chat.democracy) {
                            chat.democracy = true;
                            changed = true;
                        } else if (i == 2 && chat.democracy) {
                            chat.democracy = false;
                            changed = true;
                        }
                        if (changed) {
                            MessagesController.getInstance().toogleChannelInvites(chatId, chat.democracy);
                            int count = listView.getChildCount();
                            for (int a = 0; a < count; a++) {
                                View child = listView.getChildAt(a);
                                if (child instanceof RadioCell) {
                                    int num = (Integer) child.getTag();
                                    ((RadioCell) child).setChecked(
                                            num == 0 && chat.democracy || num == 1 && !chat.democracy, true);
                                }
                            }
                        }
                        return;
                    }
                    if (i == participantsStartRow + participants.size()) {
                        Bundle args = new Bundle();
                        args.putBoolean("onlyUsers", true);
                        args.putBoolean("destroyAfterSelect", true);
                        args.putBoolean("returnAsResult", true);
                        args.putBoolean("needForwardCount", false);
                        args.putBoolean("allowUsernameSearch", true);
                        /*if (isMegagroup) {
                        args.putBoolean("allowBots", false);
                        }*/
                        args.putString("selectAlertString", LocaleController
                                .getString("ChannelAddUserAdminAlert", R.string.ChannelAddUserAdminAlert));
                        ContactsActivity fragment = new ContactsActivity(args);
                        fragment.setDelegate(new ContactsActivity.ContactsActivityDelegate() {
                            @Override
                            public void didSelectContact(TLRPC.User user, String param) {
                                setUserChannelRole(user, new TLRPC.TL_channelRoleEditor());
                            }
                        });
                        presentFragment(fragment);
                        return;
                    }
                }
            }
            TLRPC.ChannelParticipant participant = null;
            if (i >= participantsStartRow && i < participants.size() + participantsStartRow) {
                participant = participants.get(i - participantsStartRow);
            }
            if (participant != null) {
                Bundle args = new Bundle();
                args.putInt("user_id", participant.user_id);
                presentFragment(new ProfileActivity(args));
            }
        }
    });

    if (isAdmin || isMegagroup && type == 0) {
        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (getParentActivity() == null) {
                    return false;
                }
                TLRPC.ChannelParticipant participant = null;
                if (i >= participantsStartRow && i < participants.size() + participantsStartRow) {
                    participant = participants.get(i - participantsStartRow);
                }
                if (participant != null) {
                    final TLRPC.ChannelParticipant finalParticipant = participant;
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    CharSequence[] items = null;
                    if (type == 0) {
                        items = new CharSequence[] { LocaleController.getString("Unblock", R.string.Unblock) };
                    } else if (type == 1) {
                        items = new CharSequence[] { LocaleController.getString("ChannelRemoveUserAdmin",
                                R.string.ChannelRemoveUserAdmin) };
                    } else if (type == 2) {
                        items = new CharSequence[] {
                                LocaleController.getString("ChannelRemoveUser", R.string.ChannelRemoveUser) };
                    }
                    builder.setItems(items, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            if (i == 0) {
                                if (type == 0) {
                                    participants.remove(finalParticipant);
                                    listViewAdapter.notifyDataSetChanged();
                                    TLRPC.TL_channels_kickFromChannel req = new TLRPC.TL_channels_kickFromChannel();
                                    req.kicked = false;
                                    req.user_id = MessagesController.getInputUser(finalParticipant.user_id);
                                    req.channel = MessagesController.getInputChannel(chatId);
                                    ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                                        @Override
                                        public void run(TLObject response, TLRPC.TL_error error) {
                                            if (response != null) {
                                                final TLRPC.Updates updates = (TLRPC.Updates) response;
                                                MessagesController.getInstance().processUpdates(updates, false);
                                                if (!updates.chats.isEmpty()) {
                                                    AndroidUtilities.runOnUIThread(new Runnable() {
                                                        @Override
                                                        public void run() {
                                                            TLRPC.Chat chat = updates.chats.get(0);
                                                            MessagesController.getInstance()
                                                                    .loadFullChat(chat.id, 0, true);
                                                        }
                                                    }, 1000);
                                                }
                                            }
                                        }
                                    });
                                } else if (type == 1) {
                                    setUserChannelRole(
                                            MessagesController.getInstance().getUser(finalParticipant.user_id),
                                            new TLRPC.TL_channelRoleEmpty());
                                } else if (type == 2) {
                                    MessagesController.getInstance().deleteUserFromChat(chatId,
                                            MessagesController.getInstance().getUser(finalParticipant.user_id),
                                            null);
                                }
                            }
                        }
                    });
                    showDialog(builder.create());
                    return true;
                } else {
                    return false;
                }
            }
        });
    }

    if (loadingUsers) {
        emptyView.showProgress();
    } else {
        emptyView.showTextView();
    }
    return fragmentView;
}

From source file:org.solovyev.android.messenger.BaseListFragment.java

protected void fillListView(@Nonnull ListView lv, @Nonnull Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
        lv.setScrollbarFadingEnabled(true);
    }//  ww  w. ja v  a2  s  .  c om
    lv.setBackgroundDrawable(null);
    lv.setCacheColorHint(Color.TRANSPARENT);
    ListViewScroller.createAndAttach(lv, this);
    lv.setFastScrollEnabled(true);

    lv.setTextFilterEnabled(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        lv.setOverscrollFooter(null);
    }

    lv.setVerticalFadingEdgeEnabled(false);
    lv.setFocusable(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        lv.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_RIGHT);
    }
    lv.setDivider(new ColorDrawable(Color.LTGRAY));
    lv.setDividerHeight(1);
}