Example usage for android.widget ListView setDrawSelectorOnTop

List of usage examples for android.widget ListView setDrawSelectorOnTop

Introduction

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

Prototype

public void setDrawSelectorOnTop(boolean onTop) 

Source Link

Document

Controls whether the selection highlight drawable should be drawn on top of the item or behind it.

Usage

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

@Override
public View createView(LayoutInflater inflater) {
    if (fragmentView == null) {
        actionBar.setBackButtonImage(R.drawable.ic_ab_back);
        actionBar.setAllowOverlayTitle(true);
        actionBar.setTitle("My Places");
        actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
            @Override//from  w w  w .j  ava 2s .c  o m
            public void onItemClick(int id) {
                if (id == -1) {
                    finishFragment();
                }
            }
        });

        listAdapter = new ListAdapter(getParentActivity());

        fragmentView = new FrameLayout(getParentActivity());
        FrameLayout frameLayout = (FrameLayout) fragmentView;
        frameLayout.setBackgroundColor(0xfff0f0f0);

        ListView listView = new ListView(getParentActivity());
        listView.setDivider(null);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
        layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP;
        listView.setLayoutParams(layoutParams);
        listView.setAdapter(listAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                if (i == homeRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle("Home");
                    final ViewGroup.LayoutParams lparams = new ViewGroup.LayoutParams(50, 30);
                    final EditText input = new EditText(getParentActivity());
                    input.setHint("Insert city");
                    input.setLayoutParams(lparams);
                    builder.setView(input);
                    builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (input.getText().toString().trim().length() > 0) {
                                String city = input.getText().toString().trim();
                                try {
                                    Bundle locationHome = new getCoordinates().execute(city).get();
                                    String latHome = locationHome.getString("lat");
                                    String lonHome = locationHome.getString("lon");
                                    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext
                                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                                    SharedPreferences.Editor editor = sharedPreferences.edit();
                                    editor.putString("latHome", latHome);
                                    editor.putString("longHome", lonHome);
                                    editor.commit();
                                    Log.i(TAG, "fine! " + lonHome);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                } catch (ExecutionException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT)
                                        .show();
                            }

                        }
                    });
                    builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show();
                        }
                    });
                    showAlertDialog(builder);
                } else if (i == workRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle("Work");
                    final EditText input = new EditText(getParentActivity());
                    input.setHint("Insert city");
                    builder.setView(input);
                    builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (input.getText().toString().trim().length() > 0) {
                                String city = input.getText().toString().trim();
                                try {
                                    Bundle locationWork = new getCoordinates().execute(city).get();
                                    String latWork = locationWork.getString("lat");
                                    String lonWork = locationWork.getString("lon");
                                    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext
                                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                                    SharedPreferences.Editor editor = sharedPreferences.edit();
                                    editor.putString("latWork", latWork);
                                    editor.putString("longWork", lonWork);
                                    editor.commit();
                                    Log.i(TAG, "fine! " + latWork);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                } catch (ExecutionException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT)
                                        .show();
                            }

                        }
                    });
                    builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show();
                        }
                    });
                    showAlertDialog(builder);
                } else if (i == entertainmentRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle("Entertainment");
                    final EditText input = new EditText(getParentActivity());
                    input.setHint("Insert city");
                    builder.setView(input);
                    builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (input.getText().toString().trim().length() > 0) {
                                String city = input.getText().toString().trim();
                                try {
                                    Bundle locationEntertainment = new getCoordinates().execute(city).get();
                                    String latEntertainment = locationEntertainment.getString("lat");
                                    String lonEntertainment = locationEntertainment.getString("lon");
                                    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext
                                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                                    SharedPreferences.Editor editor = sharedPreferences.edit();
                                    editor.putString("latEntertainment", latEntertainment);
                                    editor.putString("longEntertainment", lonEntertainment);
                                    editor.commit();
                                    Log.i(TAG, "fine! " + latEntertainment);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                } catch (ExecutionException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT)
                                        .show();
                            }

                        }
                    });
                    builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show();
                        }
                    });
                    showAlertDialog(builder);
                }
                //TODO find a solution for commuteRow as well!!
            }
        });
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:com.conferenceengineer.android.iosched.ui.AnnouncementsFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final ListView listView = getListView();
    if (!UIUtils.isTablet(getActivity())) {
        view.setBackgroundColor(getResources().getColor(R.color.stream_spacer_color));
    }//w  ww  . j  av  a2s.  c o m

    if (getArguments() != null && getArguments().getBoolean(EXTRA_ADD_VERTICAL_MARGINS, false)) {
        int verticalMargin = getResources().getDimensionPixelSize(R.dimen.social_stream_padding_vertical);
        if (verticalMargin > 0) {
            listView.setClipToPadding(false);
            listView.setPadding(0, verticalMargin, 0, verticalMargin);
        }
    }

    listView.setOnScrollListener(this);
    listView.setDrawSelectorOnTop(true);
    listView.setDivider(getResources().getDrawable(android.R.color.transparent));
    listView.setDividerHeight(getResources().getDimensionPixelSize(R.dimen.page_margin_width));

    TypedValue v = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.activatableItemBackground, v, true);
    listView.setSelector(v.resourceId);

    setListAdapter(mStreamAdapter);
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.AnnouncementsFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final ListView listView = getListView();
    if (!UIUtils.isTablet(getActivity())) {
        view.setBackgroundColor(getResources().getColor(R.color.plus_stream_spacer_color));
    }//w  w w . jav  a  2 s.  c om

    if (getArguments() != null && getArguments().getBoolean(EXTRA_ADD_VERTICAL_MARGINS, false)) {
        int verticalMargin = getResources().getDimensionPixelSize(R.dimen.plus_stream_padding_vertical);
        if (verticalMargin > 0) {
            listView.setClipToPadding(false);
            listView.setPadding(0, verticalMargin, 0, verticalMargin);
        }
    }

    listView.setOnScrollListener(this);
    listView.setDrawSelectorOnTop(true);
    listView.setDivider(getResources().getDrawable(android.R.color.transparent));
    listView.setDividerHeight(getResources().getDimensionPixelSize(R.dimen.page_margin_width));

    TypedValue v = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.activatableItemBackground, v, true);
    listView.setSelector(v.resourceId);

    setListAdapter(mStreamAdapter);
}

From source file:net.abcdroid.devfest12.ui.SocialStreamFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    view.setBackgroundColor(Color.WHITE);

    final ListView listView = getListView();
    listView.setCacheColorHint(Color.WHITE);
    listView.setOnScrollListener(this);
    listView.setDrawSelectorOnTop(true);
    TypedValue v = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.activatableItemBackground, v, true);
    listView.setSelector(v.resourceId);//from ww  w .  j  av a 2s  . com
}

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

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (isGroup) {
        actionBar.setTitle(LocaleController.getString("GroupsAndChannels", R.string.GroupsAndChannels));
    } else {/*from w ww  . j  av a 2 s.  c om*/
        actionBar.setTitle(LocaleController.getString("PrivacyLastSeen", R.string.PrivacyLastSeen));
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (getParentActivity() == null) {
                    return;
                }

                if (currentType != 0 && !isGroup) {
                    final SharedPreferences preferences = ApplicationLoader.applicationContext
                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                    boolean showed = preferences.getBoolean("privacyAlertShowed", false);
                    if (!showed) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                        if (isGroup) {
                            builder.setMessage(
                                    LocaleController.getString("WhoCanAddMeInfo", R.string.WhoCanAddMeInfo));
                        } else {
                            builder.setMessage(LocaleController.getString("CustomHelp", R.string.CustomHelp));
                        }
                        builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int i) {
                                        applyCurrentPrivacySettings();
                                        preferences.edit().putBoolean("privacyAlertShowed", true).commit();
                                    }
                                });
                        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                        showDialog(builder.create());
                        return;
                    }
                }
                applyCurrentPrivacySettings();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
    doneButton.setVisibility(View.GONE);

    listAdapter = new ListAdapter(context);

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

    ListView listView = new ListView(context);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setVerticalScrollBarEnabled(false);
    listView.setDrawSelectorOnTop(true);
    frameLayout.addView(listView);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.gravity = Gravity.TOP;
    listView.setLayoutParams(layoutParams);
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
            if (i == nobodyRow || i == everybodyRow || i == myContactsRow) {
                int newType = currentType;
                if (i == nobodyRow) {
                    newType = 1;
                } else if (i == everybodyRow) {
                    newType = 0;
                } else if (i == myContactsRow) {
                    newType = 2;
                }
                if (newType == currentType) {
                    return;
                }
                enableAnimation = true;
                doneButton.setVisibility(View.VISIBLE);
                lastCheckedType = currentType;
                currentType = newType;
                updateRows();
            } else if (i == neverShareRow || i == alwaysShareRow) {
                ArrayList<Integer> createFromArray;
                if (i == neverShareRow) {
                    createFromArray = currentMinus;
                } else {
                    createFromArray = currentPlus;
                }
                if (createFromArray.isEmpty()) {
                    Bundle args = new Bundle();
                    args.putBoolean(i == neverShareRow ? "isNeverShare" : "isAlwaysShare", true);
                    args.putBoolean("isGroup", isGroup);
                    GroupCreateActivity fragment = new GroupCreateActivity(args);
                    fragment.setDelegate(new GroupCreateActivity.GroupCreateActivityDelegate() {
                        @Override
                        public void didSelectUsers(ArrayList<Integer> ids) {
                            if (i == neverShareRow) {
                                currentMinus = ids;
                                for (int a = 0; a < currentMinus.size(); a++) {
                                    currentPlus.remove(currentMinus.get(a));
                                }
                            } else {
                                currentPlus = ids;
                                for (int a = 0; a < currentPlus.size(); a++) {
                                    currentMinus.remove(currentPlus.get(a));
                                }
                            }
                            doneButton.setVisibility(View.VISIBLE);
                            lastCheckedType = -1;
                            listAdapter.notifyDataSetChanged();
                        }
                    });
                    presentFragment(fragment);
                } else {
                    PrivacyUsersActivity fragment = new PrivacyUsersActivity(createFromArray, isGroup,
                            i == alwaysShareRow);
                    fragment.setDelegate(new PrivacyUsersActivity.PrivacyActivityDelegate() {
                        @Override
                        public void didUpdatedUserList(ArrayList<Integer> ids, boolean added) {
                            if (i == neverShareRow) {
                                currentMinus = ids;
                                if (added) {
                                    for (int a = 0; a < currentMinus.size(); a++) {
                                        currentPlus.remove(currentMinus.get(a));
                                    }
                                }
                            } else {
                                currentPlus = ids;
                                if (added) {
                                    for (int a = 0; a < currentPlus.size(); a++) {
                                        currentMinus.remove(currentPlus.get(a));
                                    }
                                }
                            }
                            doneButton.setVisibility(View.VISIBLE);
                            listAdapter.notifyDataSetChanged();
                        }
                    });
                    presentFragment(fragment);
                }
            }
        }
    });

    return fragmentView;
}

From source file:com.WazaBe.GooglePlusStream.SocialStreamFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    view.setBackgroundColor(Color.WHITE);

    final ListView listView = getListView();
    listView.setCacheColorHint(Color.WHITE);
    listView.setOnScrollListener(this);
    listView.setDrawSelectorOnTop(true);
    // TypedValue v = new TypedValue();
    // getActivity().getTheme().resolveAttribute(R.attr.activatableItemBackground,
    // v, true);/*from  www  .j  a va 2s  .  com*/
    // listView.setSelector(v.resourceId);
}

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));
    }//  ww w  .ja v  a  2s.  co m
    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.telegram.ui.CacheControlActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("CacheSettings", R.string.CacheSettings));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override//from  ww  w . j  a v  a  2 s  .co m
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    listAdapter = new ListAdapter(context);

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

    ListView listView = new ListView(context);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setVerticalScrollBarEnabled(false);
    listView.setDrawSelectorOnTop(true);
    frameLayout.addView(listView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(final AdapterView<?> adapterView, View view, final int i, long l) {
            if (getParentActivity() == null) {
                return;
            }
            if (i == keepMediaRow) {
                BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity());
                builder.setItems(
                        new CharSequence[] { LocaleController.formatPluralString("Weeks", 1),
                                LocaleController.formatPluralString("Months", 1),
                                LocaleController.getString("KeepMediaForever", R.string.KeepMediaForever) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, final int which) {
                                SharedPreferences.Editor editor = ApplicationLoader.applicationContext
                                        .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).edit();
                                editor.putInt("keep_media", which).commit();
                                if (listAdapter != null) {
                                    listAdapter.notifyDataSetChanged();
                                }
                                PendingIntent pintent = PendingIntent.getService(
                                        ApplicationLoader.applicationContext, 0,
                                        new Intent(ApplicationLoader.applicationContext,
                                                ClearCacheService.class),
                                        0);
                                AlarmManager alarmManager = (AlarmManager) ApplicationLoader.applicationContext
                                        .getSystemService(Context.ALARM_SERVICE);
                                if (which == 2) {
                                    alarmManager.cancel(pintent);
                                } else {
                                    alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                                            AlarmManager.INTERVAL_DAY, AlarmManager.INTERVAL_DAY, pintent);
                                }
                            }
                        });
                showDialog(builder.create());
            } else if (i == databaseRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                builder.setMessage(
                        LocaleController.getString("LocalDatabaseClear", R.string.LocalDatabaseClear));
                builder.setPositiveButton(LocaleController.getString("CacheClear", R.string.CacheClear),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                final ProgressDialog progressDialog = new ProgressDialog(getParentActivity());
                                progressDialog
                                        .setMessage(LocaleController.getString("Loading", R.string.Loading));
                                progressDialog.setCanceledOnTouchOutside(false);
                                progressDialog.setCancelable(false);
                                progressDialog.show();
                                MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
                                    @Override
                                    public void run() {
                                        try {
                                            SQLiteDatabase database = MessagesStorage.getInstance()
                                                    .getDatabase();
                                            ArrayList<Long> dialogsToCleanup = new ArrayList<>();
                                            SQLiteCursor cursor = database
                                                    .queryFinalized("SELECT did FROM dialogs WHERE 1");
                                            StringBuilder ids = new StringBuilder();
                                            while (cursor.next()) {
                                                long did = cursor.longValue(0);
                                                int lower_id = (int) did;
                                                int high_id = (int) (did >> 32);
                                                if (lower_id != 0 && high_id != 1) {
                                                    dialogsToCleanup.add(did);
                                                }
                                            }
                                            cursor.dispose();

                                            SQLitePreparedStatement state5 = database
                                                    .executeFast("REPLACE INTO messages_holes VALUES(?, ?, ?)");
                                            SQLitePreparedStatement state6 = database.executeFast(
                                                    "REPLACE INTO media_holes_v2 VALUES(?, ?, ?, ?)");

                                            database.beginTransaction();
                                            for (int a = 0; a < dialogsToCleanup.size(); a++) {
                                                Long did = dialogsToCleanup.get(a);
                                                int messagesCount = 0;
                                                cursor = database.queryFinalized(
                                                        "SELECT COUNT(mid) FROM messages WHERE uid = " + did);
                                                if (cursor.next()) {
                                                    messagesCount = cursor.intValue(0);
                                                }
                                                cursor.dispose();
                                                if (messagesCount <= 2) {
                                                    continue;
                                                }

                                                cursor = database.queryFinalized(
                                                        "SELECT last_mid_i, last_mid FROM dialogs WHERE did = "
                                                                + did);
                                                int messageId = -1;
                                                if (cursor.next()) {
                                                    long last_mid_i = cursor.longValue(0);
                                                    long last_mid = cursor.longValue(1);
                                                    SQLiteCursor cursor2 = database.queryFinalized(
                                                            "SELECT data FROM messages WHERE uid = " + did
                                                                    + " AND mid IN (" + last_mid_i + ","
                                                                    + last_mid + ")");
                                                    try {
                                                        while (cursor2.next()) {
                                                            NativeByteBuffer data = cursor2.byteBufferValue(0);
                                                            if (data != null) {
                                                                TLRPC.Message message = TLRPC.Message
                                                                        .TLdeserialize(data,
                                                                                data.readInt32(false), false);
                                                                data.reuse();
                                                                if (message != null) {
                                                                    messageId = message.id;
                                                                }
                                                            }
                                                        }
                                                    } catch (Exception e) {
                                                        FileLog.e("tmessages", e);
                                                    }
                                                    cursor2.dispose();

                                                    database.executeFast("DELETE FROM messages WHERE uid = "
                                                            + did + " AND mid != " + last_mid_i + " AND mid != "
                                                            + last_mid).stepThis().dispose();
                                                    database.executeFast(
                                                            "DELETE FROM messages_holes WHERE uid = " + did)
                                                            .stepThis().dispose();
                                                    database.executeFast(
                                                            "DELETE FROM bot_keyboard WHERE uid = " + did)
                                                            .stepThis().dispose();
                                                    database.executeFast(
                                                            "DELETE FROM media_counts_v2 WHERE uid = " + did)
                                                            .stepThis().dispose();
                                                    database.executeFast(
                                                            "DELETE FROM media_v2 WHERE uid = " + did)
                                                            .stepThis().dispose();
                                                    database.executeFast(
                                                            "DELETE FROM media_holes_v2 WHERE uid = " + did)
                                                            .stepThis().dispose();
                                                    BotQuery.clearBotKeyboard(did, null);
                                                    if (messageId != -1) {
                                                        MessagesStorage.createFirstHoles(did, state5, state6,
                                                                messageId);
                                                    }
                                                }
                                                cursor.dispose();
                                            }
                                            state5.dispose();
                                            state6.dispose();
                                            database.commitTransaction();
                                            database.executeFast("VACUUM").stepThis().dispose();
                                        } catch (Exception e) {
                                            FileLog.e("tmessages", e);
                                        } finally {
                                            AndroidUtilities.runOnUIThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    try {
                                                        progressDialog.dismiss();
                                                    } catch (Exception e) {
                                                        FileLog.e("tmessages", e);
                                                    }
                                                    if (listAdapter != null) {
                                                        File file = new File(
                                                                ApplicationLoader.getFilesDirFixed(),
                                                                "cache4.db");
                                                        databaseSize = file.length();
                                                        listAdapter.notifyDataSetChanged();
                                                    }
                                                }
                                            });
                                        }
                                    }
                                });
                            }
                        });
                showDialog(builder.create());
            } else if (i == cacheRow) {
                if (totalSize <= 0 || getParentActivity() == null) {
                    return;
                }
                BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity());
                builder.setApplyTopPadding(false);
                builder.setApplyBottomPadding(false);
                LinearLayout linearLayout = new LinearLayout(getParentActivity());
                linearLayout.setOrientation(LinearLayout.VERTICAL);
                for (int a = 0; a < 6; a++) {
                    long size = 0;
                    String name = null;
                    if (a == 0) {
                        size = photoSize;
                        name = LocaleController.getString("LocalPhotoCache", R.string.LocalPhotoCache);
                    } else if (a == 1) {
                        size = videoSize;
                        name = LocaleController.getString("LocalVideoCache", R.string.LocalVideoCache);
                    } else if (a == 2) {
                        size = documentsSize;
                        name = LocaleController.getString("LocalDocumentCache", R.string.LocalDocumentCache);
                    } else if (a == 3) {
                        size = musicSize;
                        name = LocaleController.getString("LocalMusicCache", R.string.LocalMusicCache);
                    } else if (a == 4) {
                        size = audioSize;
                        name = LocaleController.getString("LocalAudioCache", R.string.LocalAudioCache);
                    } else if (a == 5) {
                        size = cacheSize;
                        name = LocaleController.getString("LocalCache", R.string.LocalCache);
                    }
                    if (size > 0) {
                        clear[a] = true;
                        CheckBoxCell checkBoxCell = new CheckBoxCell(getParentActivity());
                        checkBoxCell.setTag(a);
                        checkBoxCell.setBackgroundResource(R.drawable.list_selector);
                        linearLayout.addView(checkBoxCell,
                                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
                        checkBoxCell.setText(name, AndroidUtilities.formatFileSize(size), true, true);
                        checkBoxCell.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                CheckBoxCell cell = (CheckBoxCell) v;
                                int num = (Integer) cell.getTag();
                                clear[num] = !clear[num];
                                cell.setChecked(clear[num], true);
                            }
                        });
                    } else {
                        clear[a] = false;
                    }
                }
                BottomSheet.BottomSheetCell cell = new BottomSheet.BottomSheetCell(getParentActivity(), 1);
                cell.setBackgroundResource(R.drawable.list_selector);
                cell.setTextAndIcon(
                        LocaleController.getString("ClearMediaCache", R.string.ClearMediaCache).toUpperCase(),
                        0);
                cell.setTextColor(Theme.STICKERS_SHEET_REMOVE_TEXT_COLOR);
                cell.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        try {
                            if (visibleDialog != null) {
                                visibleDialog.dismiss();
                            }
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                        cleanupFolders();
                    }
                });
                linearLayout.addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
                builder.setCustomView(linearLayout);
                showDialog(builder.create());
            }
        }
    });

    return fragmentView;
}

From source file:com.conferenceengineer.android.iosched.ui.SocialStreamFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final ListView lv = getListView();
    /*if (!UIUtils.isTablet(getActivity())) {
    view.setBackgroundColor(getResources().getColor(R.color.stream_spacer_color));
    }*//*from  w w  w.  j  a  va 2s.  c o m*/

    // Add some padding if the parent layout is too wide to avoid stretching the items too much
    // emulating the activity_letterboxed_when_large layout behaviour
    if (getArguments() != null && getArguments().getBoolean(EXTRA_ADD_VERTICAL_MARGINS, false)) {

        int verticalMargin = getResources().getDimensionPixelSize(R.dimen.social_stream_padding_vertical);
        if (verticalMargin > 0) {
            lv.setClipToPadding(false);
            lv.setPadding(0, verticalMargin, 0, verticalMargin);
        }
    }

    lv.setOnScrollListener(this);
    lv.setDrawSelectorOnTop(true);
    lv.setDivider(getResources().getDrawable(R.drawable.stream_list_divider));
    lv.setDividerHeight(getResources().getDimensionPixelSize(R.dimen.stream_divider_height));
    //view.setBackgroundColor(getResources().getColor(R.color.stream_list_bg_color));

    setListAdapter(mStreamAdapter);
}

From source file:org.michaelbel.bottomsheet.BottomSheet.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (backgroundColor == 0) {
        backgroundColor = darkTheme ? 0xFF424242 : 0xFFFFFFFF;
    }/*from w ww  .j  a  v a 2  s .  c o  m*/

    if (titleTextColor == 0) {
        titleTextColor = darkTheme ? 0xB3FFFFFF : 0x8A000000;
    }

    if (itemTextColor == 0) {
        itemTextColor = darkTheme ? 0xFFFFFFFF : 0xDE000000;
    }

    if (iconColor == 0) {
        iconColor = darkTheme ? 0xFFFFFFFF : 0x8A000000;
    }

    if (itemSelector == 0) {
        itemSelector = darkTheme ? R.drawable.selectable_dark : R.drawable.selectable_light;
    }

    Window window = getWindow();
    window.setWindowAnimations(R.style.DialogNoAnimation);
    setContentView(container, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    if (containerView == null) {
        containerView = new FrameLayout(getContext()) {
            @Override
            public boolean hasOverlappingRendering() {
                return false;
            }
        };
        if (Build.VERSION.SDK_INT >= 16) {
            containerView.setBackground(shadowDrawable);
        } else {
            containerView.setBackgroundDrawable(shadowDrawable);
        }
        containerView.setPadding(0, backgroundPaddingTop, 0, Utils.dp(getContext(), 8));
    }

    if (Build.VERSION.SDK_INT >= 21) {
        containerView.setFitsSystemWindows(true);
    }

    containerView.setVisibility(View.INVISIBLE);
    containerView.setBackgroundColor(backgroundColor);

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.BOTTOM;

    containerView.setLayoutParams(params);
    container.addView(containerView, 0);

    if (customView != null) {
        if (customView.getParent() != null) {
            ViewGroup viewGroup = (ViewGroup) customView.getParent();
            viewGroup.removeView(customView);
        }

        FrameLayout.LayoutParams params1 = (FrameLayout.LayoutParams) containerView.getLayoutParams();
        params1.width = ViewGroup.LayoutParams.MATCH_PARENT;
        params1.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params1.gravity = Gravity.START | Gravity.TOP;

        containerView.addView(customView, params1);
    } else {
        int topOffset = 0;

        if (titleText != null) {
            TextView titleTextView = new TextView(getContext());
            titleTextView.setLines(1);
            titleTextView.setMaxLines(1);
            titleTextView.setSingleLine(true);
            titleTextView.setText(titleText);
            titleTextView.setTextColor(titleTextColor);
            titleTextView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
            titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
            titleTextView.setGravity(Gravity.CENTER_VERTICAL);

            FrameLayout.LayoutParams params0 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    Utils.dp(getContext(), 56));
            params0.gravity = Gravity.START | Gravity.TOP;
            params0.leftMargin = Utils.dp(getContext(), 16);
            params0.rightMargin = Utils.dp(getContext(), 16);

            titleTextView.setLayoutParams(params0);
            containerView.addView(titleTextView);
            titleTextView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return true;
                }
            });
            topOffset += 56;
        }

        BottomSheetAdapter adapter = new BottomSheetAdapter();

        if (mItems != null || mItemsRes != null) {
            if (contentType == LIST) {
                FrameLayout.LayoutParams params2 = new FrameLayout.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                params2.topMargin = Utils.dp(getContext(), topOffset);

                ListView listView = new ListView(getContext());
                listView.setSelector(itemSelector);
                listView.setDividerHeight(0);
                listView.setAdapter(adapter);
                listView.setDrawSelectorOnTop(true);
                listView.setVerticalScrollBarEnabled(false);
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        dismissWithButtonClick(i);
                    }
                });
                listView.setLayoutParams(params2);
                containerView.addView(listView);
            } else if (contentType == GRID) {
                FrameLayout.LayoutParams params3 = new FrameLayout.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

                GridView gridView = new GridView(getContext());
                gridView.setSelector(itemSelector);
                gridView.setAdapter(adapter);
                gridView.setNumColumns(3);
                gridView.setVerticalScrollBarEnabled(false);
                gridView.setVerticalSpacing(Utils.dp(getContext(), 16));
                gridView.setPadding(Utils.dp(getContext(), 0), Utils.dp(getContext(), topOffset + 8),
                        Utils.dp(getContext(), 0), Utils.dp(getContext(), 16));
                gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        dismissWithButtonClick(i);
                    }
                });
                gridView.setLayoutParams(params3);
                containerView.addView(gridView);
            }

            if (mItems != null) {
                for (int a = 0; a < mItems.length; a++) {
                    items.add(new Item(mItems[a], mIcons != null ? mIcons[a] : 0));
                }
            } else {
                for (int a = 0; a < mItemsRes.length; a++) {
                    items.add(new Item(getContext().getText(mItemsRes[a]), mIcons != null ? mIcons[a] : 0));
                }
            }

            adapter.notifyDataSetChanged();
        }
    }

    WindowManager.LayoutParams params4 = window.getAttributes();
    params4.width = ViewGroup.LayoutParams.MATCH_PARENT;
    params4.gravity = Gravity.TOP | Gravity.START;
    params4.dimAmount = 0;
    params4.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
    if (!focusable) {
        params4.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
    }
    params4.height = ViewGroup.LayoutParams.MATCH_PARENT;
    window.setAttributes(params4);
}