Example usage for android.widget TextView setCompoundDrawablePadding

List of usage examples for android.widget TextView setCompoundDrawablePadding

Introduction

In this page you can find the example usage for android.widget TextView setCompoundDrawablePadding.

Prototype

@android.view.RemotableViewMethod
public void setCompoundDrawablePadding(int pad) 

Source Link

Document

Sets the size of the padding between the compound drawables and the text.

Usage

From source file:com.arcgis.android.samples.localdata.localrasterdata.FileBrowserFragment.java

private void createFileListAdapter() {
    adapter = new ArrayAdapter<Item>(getActivity(), android.R.layout.select_dialog_item, android.R.id.text1,
            fileList) {/*from   w  ww  .j a  v  a2s  .co  m*/
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // creates view
            View view = super.getView(position, convertView, parent);
            TextView textView = (TextView) view.findViewById(android.R.id.text1);
            // put the image on the text view
            int drawableID = 0;
            if (fileList.get(position).icon != -1) {
                // If icon == -1, then directory is empty
                drawableID = fileList.get(position).icon;
            }
            textView.setCompoundDrawablesWithIntrinsicBounds(drawableID, 0, 0, 0);

            textView.setEllipsize(null);

            int dp3 = (int) (3 * getResources().getDisplayMetrics().density + 0.5f);
            textView.setCompoundDrawablePadding(dp3);
            textView.setBackgroundColor(Color.LTGRAY);
            return view;
        }
    };
}

From source file:com.tune.news.fragment.EntriesListFragment.java

@Override
public View inflateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_entry_list, container, true);

    if (mEntriesCursorAdapter != null) {
        setListAdapter(mEntriesCursorAdapter);
    }//from   www  .j  a  v  a2 s  .  c o m

    mListView = (ListView) rootView.findViewById(android.R.id.list);
    mListView.setFastScrollEnabled(true);
    //        mListView.setOnTouchListener(new SwipeGestureListener(mListView.getContext()));

    if (PrefUtils.getBoolean(PrefUtils.DISPLAY_TIP, true)) {
        final TextView header = new TextView(mListView.getContext());
        header.setMinimumHeight(UiUtils.dpToPixel(70));
        int footerPadding = UiUtils.dpToPixel(10);
        header.setPadding(footerPadding, footerPadding, footerPadding, footerPadding);
        header.setText(R.string.tip_sentence);
        header.setGravity(Gravity.CENTER_VERTICAL);
        header.setCompoundDrawablePadding(UiUtils.dpToPixel(5));
        header.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_about, 0,
                R.drawable.ic_action_cancel, 0);
        header.setClickable(true);
        header.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListView.removeHeaderView(header);
                PrefUtils.putBoolean(PrefUtils.DISPLAY_TIP, false);
            }
        });
        mListView.addHeaderView(header);
    }

    UiUtils.addEmptyFooterView(mListView, 90);

    mHideReadButton = (FloatingActionButton) rootView.findViewById(R.id.hide_read_button);
    mHideReadButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            UiUtils.displayHideReadButtonAction(mListView.getContext());
            return true;
        }
    });
    UiUtils.updateHideReadButton(mHideReadButton);

    mRefreshListBtn = (Button) rootView.findViewById(R.id.refreshListBtn);
    mRefreshListBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mNewEntriesNumber = 0;
            mListDisplayDate = new Date().getTime();

            refreshUI();
            if (mUri != null) {
                restartLoaders();
            }
        }
    });

    mSearchView = (SearchView) rootView.findViewById(R.id.searchView);
    if (savedInstanceState != null) {
        refreshUI(); // To hide/show the search bar
    }

    mSearchView.post(new Runnable() { // Do this AFTER the text has been restored from saveInstanceState
        @Override
        public void run() {
            mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String s) {
                    InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
                    return false;
                }

                @Override
                public boolean onQueryTextChange(String s) {
                    setData(EntryColumns.SEARCH_URI(s), true);
                    return false;
                }
            });
        }
    });

    disableSwipe();

    return rootView;
}

From source file:com.viktorrudometkin.burramys.fragment.EntriesListFragment.java

@Override
public View inflateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_entry_list, container, true);

    if (mEntriesCursorAdapter != null) {
        setListAdapter(mEntriesCursorAdapter);
    }//from ww w. j  a  va 2  s .  c  o m

    mListView = (ListView) rootView.findViewById(android.R.id.list);
    mListView.setOnTouchListener(new SwipeGestureListener(mListView.getContext()));

    if (PrefUtils.getBoolean(PrefUtils.DISPLAY_TIP, true)) {
        final TextView header = new TextView(mListView.getContext());
        header.setMinimumHeight(UiUtils.dpToPixel(70));
        int footerPadding = UiUtils.dpToPixel(10);
        header.setPadding(footerPadding, footerPadding, footerPadding, footerPadding);
        header.setText(R.string.tip_sentence);
        header.setGravity(Gravity.CENTER_VERTICAL);
        header.setCompoundDrawablePadding(UiUtils.dpToPixel(5));
        header.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_about, 0,
                R.drawable.ic_action_cancel, 0);
        header.setClickable(true);
        header.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListView.removeHeaderView(header);
                PrefUtils.putBoolean(PrefUtils.DISPLAY_TIP, false);
            }
        });
        mListView.addHeaderView(header);
    }

    UiUtils.addEmptyFooterView(mListView, 90);

    mRefreshListBtn = (Button) rootView.findViewById(R.id.refreshListBtn);
    mRefreshListBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mNewEntriesNumber = 0;
            mListDisplayDate = new Date().getTime();

            refreshUI();
            if (mCurrentUri != null) {
                restartLoaders();
            }
        }
    });

    disableSwipe();

    return rootView;
}

From source file:com.geekandroid.sdk.base.BaseActivity.java

private Drawable getDrawable(TextView textView, int resId, int p, int b) {

    int padding = convertDp(p);
    int bounds = convertDp(b);

    Drawable drawable = getResources().getDrawable(resId);

    if (drawable != null) {
        if (bounds <= 0) {
            Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), resId);
            int height = bitmap.getHeight();
            int width = bitmap.getWidth();
            drawable.setBounds(0, 0, width, height);
        } else {/*w ww.  ja  v  a  2s. co  m*/
            drawable.setBounds(0, 0, bounds, bounds);
        }
    }
    if (padding > 0) {
        textView.setCompoundDrawablePadding(padding);
    }
    return drawable;
}

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

@Override
public void applySelfActionBar() {
    if (parentActivity == null) {
        return;//  w w  w.ja  v  a2  s  .co  m
    }
    ActionBar actionBar = parentActivity.getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setDisplayShowCustomEnabled(false);
    actionBar.setCustomView(null);
    actionBar.setTitle(getStringEntry(R.string.NewGroup));

    TextView title = (TextView) parentActivity.findViewById(R.id.action_bar_title);
    if (title == null) {
        final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android");
        title = (TextView) parentActivity.findViewById(subtitleId);
    }
    if (title != null) {
        title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
        title.setCompoundDrawablePadding(0);
    }
}

From source file:com.github.topbottomsnackbar.TBSnackbar.java

public TBSnackbar setIconPadding(int padding) {
    final TextView tv = mView.getMessageView();
    tv.setCompoundDrawablePadding(padding);
    return this;
}

From source file:com.nttec.everychan.ui.NewTabFragment.java

private void openChansList() {
    final ArrayAdapter<ChanModule> chansAdapter = new ArrayAdapter<ChanModule>(activity, 0) {
        private LayoutInflater inflater = LayoutInflater.from(activity);
        private int drawablePadding = (int) (resources.getDisplayMetrics().density * 5 + 0.5f);

        {/*from   w  w  w  .  ja  v  a2 s  .co  m*/
            for (ChanModule chan : MainApplication.getInstance().chanModulesList)
                add(chan);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ChanModule chan = getItem(position);
            TextView view = (TextView) (convertView == null
                    ? inflater.inflate(android.R.layout.simple_list_item_1, parent, false)
                    : convertView);
            view.setText(chan.getDisplayingName());
            view.setCompoundDrawablesWithIntrinsicBounds(chan.getChanFavicon(), null, null, null);
            view.setCompoundDrawablePadding(drawablePadding);
            return view;
        }
    };

    DialogInterface.OnClickListener onChanSelected = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            ChanModule chan = chansAdapter.getItem(which);
            UrlPageModel model = new UrlPageModel();
            model.chanName = chan.getChanName();
            model.type = UrlPageModel.TYPE_INDEXPAGE;
            openNewTab(chan.buildUrl(model));
        }
    };

    final AlertDialog chansListDialog = new AlertDialog.Builder(activity)
            .setTitle(R.string.newtab_quickaccess_all_boards).setAdapter(chansAdapter, onChanSelected)
            .setNegativeButton(android.R.string.cancel, null).create();

    chansListDialog.getListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
        @Override
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            MenuItem.OnMenuItemClickListener contextMenuHandler = new MenuItem.OnMenuItemClickListener() {
                @SuppressLint("InlinedApi")
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    final ChanModule chan = chansAdapter
                            .getItem(((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position);
                    switch (item.getItemId()) {
                    case R.id.context_menu_favorites_from_fragment:
                        if (MainApplication.getInstance().database.isFavorite(chan.getChanName(), null, null,
                                null)) {
                            MainApplication.getInstance().database.removeFavorite(chan.getChanName(), null,
                                    null, null);
                        } else {
                            try {
                                UrlPageModel indexPage = new UrlPageModel();
                                indexPage.chanName = chan.getChanName();
                                indexPage.type = UrlPageModel.TYPE_INDEXPAGE;
                                MainApplication.getInstance().database.addFavorite(chan.getChanName(), null,
                                        null, null, chan.getChanName(), chan.buildUrl(indexPage));
                            } catch (Exception e) {
                                Logger.e(TAG, e);
                            }
                        }
                        return true;
                    case R.id.context_menu_quickaccess_add:
                        QuickAccess.Entry newEntry = new QuickAccess.Entry();
                        newEntry.chan = chan;
                        list.add(0, newEntry);
                        adapter.notifyDataSetChanged();
                        saveQuickAccessToPreferences();
                        chansListDialog.dismiss();
                        return true;
                    case R.id.context_menu_quickaccess_custom_board:
                        LinearLayout dialogLayout = new LinearLayout(activity);
                        dialogLayout.setOrientation(LinearLayout.VERTICAL);
                        final EditText boardField = new EditText(activity);
                        final EditText descriptionField = new EditText(activity);
                        boardField.setHint(R.string.newtab_quickaccess_addcustom_boardcode);
                        descriptionField.setHint(R.string.newtab_quickaccess_addcustom_boarddesc);
                        LinearLayout.LayoutParams fieldsParams = new LinearLayout.LayoutParams(
                                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                        dialogLayout.addView(boardField, fieldsParams);
                        dialogLayout.addView(descriptionField, fieldsParams);
                        DialogInterface.OnClickListener onOkClicked = new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                String boardName = boardField.getText().toString();
                                for (QuickAccess.Entry entry : list)
                                    if (entry.boardName != null && entry.chan != null)
                                        if (entry.chan.getChanName().equals(chan.getChanName())
                                                && entry.boardName.equals(boardName)) {
                                            Toast.makeText(activity,
                                                    R.string.newtab_quickaccess_addcustom_already_exists,
                                                    Toast.LENGTH_LONG).show();
                                            return;
                                        }

                                try {
                                    if (boardName.trim().length() == 0)
                                        throw new Exception();
                                    UrlPageModel boardPageModel = new UrlPageModel();
                                    boardPageModel.type = UrlPageModel.TYPE_BOARDPAGE;
                                    boardPageModel.chanName = chan.getChanName();
                                    boardPageModel.boardName = boardName;
                                    boardPageModel.boardPage = UrlPageModel.DEFAULT_FIRST_PAGE;
                                    chan.buildUrl(boardPageModel); //,  ??  ?    
                                } catch (Exception e) {
                                    Toast.makeText(activity,
                                            R.string.newtab_quickaccess_addcustom_incorrect_code,
                                            Toast.LENGTH_LONG).show();
                                    return;
                                }

                                QuickAccess.Entry newEntry = new QuickAccess.Entry();
                                newEntry.chan = chan;
                                newEntry.boardName = boardName;
                                newEntry.boardDescription = descriptionField.getText().toString();
                                list.add(0, newEntry);
                                adapter.notifyDataSetChanged();
                                saveQuickAccessToPreferences();
                                chansListDialog.dismiss();
                            }
                        };
                        new AlertDialog.Builder(activity)
                                .setTitle(resources.getString(R.string.newtab_quickaccess_addcustom_title,
                                        chan.getChanName()))
                                .setView(dialogLayout).setPositiveButton(android.R.string.ok, onOkClicked)
                                .setNegativeButton(android.R.string.cancel, null).show();
                        return true;
                    }
                    return false;
                }
            };
            String thisChanName = chansAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position)
                    .getChanName();
            boolean canAddToQuickAccess = true;
            for (QuickAccess.Entry entry : list)
                if (entry.boardName == null && entry.chan != null
                        && entry.chan.getChanName().equals(thisChanName)) {
                    canAddToQuickAccess = false;
                    break;
                }
            menu.add(Menu.NONE, R.id.context_menu_favorites_from_fragment, 1,
                    MainApplication.getInstance().database.isFavorite(thisChanName, null, null, null)
                            ? R.string.context_menu_remove_favorites
                            : R.string.context_menu_add_favorites)
                    .setOnMenuItemClickListener(contextMenuHandler);
            menu.add(Menu.NONE, R.id.context_menu_quickaccess_add, 2, R.string.context_menu_quickaccess_add)
                    .setOnMenuItemClickListener(contextMenuHandler).setVisible(canAddToQuickAccess);
            menu.add(Menu.NONE, R.id.context_menu_quickaccess_custom_board, 3,
                    R.string.context_menu_quickaccess_custom_board)
                    .setOnMenuItemClickListener(contextMenuHandler);
            if (isSingleboardChan(
                    chansAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position)))
                menu.findItem(R.id.context_menu_quickaccess_custom_board).setVisible(false);
        }
    });
    chansListDialog.show();
}

From source file:com.yahala.ui.GroupCreateActivity.java

@Override
public void applySelfActionBar() {
    if (parentActivity == null) {
        return;//w  ww. j a va2s. c  om
    }
    ActionBar actionBar = parentActivity.getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setDisplayShowCustomEnabled(false);
    actionBar.setCustomView(null);
    actionBar.setTitle(LocaleController.getString("NewGroup", R.string.NewGroup));
    actionBar.setSubtitle(String.format("%d/200 %s", selectedContacts.size(),
            LocaleController.getString("Members", R.string.Members)));

    TextView title = (TextView) parentActivity.findViewById(R.id.action_bar_title);
    if (title == null) {
        final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android");
        title = (TextView) parentActivity.findViewById(subtitleId);
    }
    if (title != null) {
        title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
        title.setCompoundDrawablePadding(0);
    }
}

From source file:de.baumann.hhsmoodle.popup.Popup_todo.java

private void setTodoList() {

    PreferenceManager.setDefaultValues(Popup_todo.this, R.xml.user_settings, false);
    final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(Popup_todo.this);

    NotificationManager nMgr = (NotificationManager) Popup_todo.this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    nMgr.cancelAll();/*from   w  w w.j a  v  a 2s  .  com*/

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "todo_title", "todo_content", "todo_creation" };

    final String search = sharedPref.getString("filter_todo_subject", "");
    final Cursor row = db.fetchDataByFilter(search, "todo_title");
    final SimpleCursorAdapter adapter = new SimpleCursorAdapter(Popup_todo.this, layoutstyle, row, column,
            xml_id, 0) {
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

            View v = super.getView(position, convertView, parent);
            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);
            ImageView iv_attachment = (ImageView) v.findViewById(R.id.att_notes);

            switch (todo_icon) {
            case "3":
                iv_icon.setImageResource(R.drawable.circle_green);
                break;
            case "2":
                iv_icon.setImageResource(R.drawable.circle_yellow);
                break;
            case "1":
                iv_icon.setImageResource(R.drawable.circle_red);
                break;
            }

            switch (todo_attachment) {
            case "true":
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.alert_circle);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.alert_circle_red);

                int n = Integer.valueOf(_id);

                android.content.Intent iMain = new android.content.Intent();
                iMain.setAction("shortcutToDo");
                iMain.setClassName(Popup_todo.this, "de.baumann.hhsmoodle.activities.Activity_splash");
                PendingIntent piMain = PendingIntent.getActivity(Popup_todo.this, n, iMain, 0);

                NotificationCompat.Builder builderSummary = new NotificationCompat.Builder(Popup_todo.this)
                        .setSmallIcon(R.drawable.school)
                        .setColor(ContextCompat.getColor(Popup_todo.this, R.color.colorPrimary))
                        .setGroup("HHS_Moodle").setGroupSummary(true).setContentIntent(piMain);

                Notification notification = new NotificationCompat.Builder(Popup_todo.this)
                        .setColor(ContextCompat.getColor(Popup_todo.this, R.color.colorPrimary))
                        .setSmallIcon(R.drawable.school).setContentTitle(todo_title)
                        .setContentText(todo_content).setContentIntent(piMain).setAutoCancel(true)
                        .setGroup("HHS_Moodle")
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(todo_content))
                        .setPriority(Notification.PRIORITY_DEFAULT).setVibrate(new long[0]).build();

                NotificationManager notificationManager = (NotificationManager) Popup_todo.this
                        .getSystemService(NOTIFICATION_SERVICE);
                notificationManager.notify(n, notification);
                notificationManager.notify(0, builderSummary.build());
                break;
            }

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    final Item[] items = {
                            new Item(getString(R.string.note_priority_0), R.drawable.circle_green),
                            new Item(getString(R.string.note_priority_1), R.drawable.circle_yellow),
                            new Item(getString(R.string.note_priority_2), R.drawable.circle_red), };

                    ListAdapter adapter = new ArrayAdapter<Item>(Popup_todo.this,
                            android.R.layout.select_dialog_item, android.R.id.text1, items) {
                        @NonNull
                        public View getView(int position, View convertView, @NonNull ViewGroup parent) {
                            //Use super class to create the View
                            View v = super.getView(position, convertView, parent);
                            TextView tv = (TextView) v.findViewById(android.R.id.text1);
                            tv.setTextSize(18);
                            tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);
                            //Add margin between image and text (support various screen densities)
                            int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f);
                            tv.setCompoundDrawablePadding(dp5);

                            return v;
                        }
                    };

                    new AlertDialog.Builder(Popup_todo.this)
                            .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int whichButton) {
                                    dialog.cancel();
                                }
                            }).setAdapter(adapter, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int item) {
                                    if (item == 0) {
                                        db.update(Integer.parseInt(_id), todo_title, todo_content, "3",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), todo_title, todo_content, "2",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), todo_title, todo_content, "1",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    }
                                }
                            }).show();
                }
            });
            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    switch (todo_attachment) {
                    case "true":
                        db.update(Integer.parseInt(_id), todo_title, todo_content, todo_icon, "",
                                todo_creation);
                        setTodoList();
                        break;
                    default:
                        db.update(Integer.parseInt(_id), todo_title, todo_content, todo_icon, "true",
                                todo_creation);
                        setTodoList();
                        break;
                    }
                }
            });
            return v;
        }
    };

    lv.setAdapter(adapter);
    //onClick function
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

            sharedPref.edit().putString("toDo_title", todo_title).apply();
            sharedPref.edit().putString("toDo_text", todo_content).apply();
            sharedPref.edit().putString("toDo_seqno", _id).apply();
            sharedPref.edit().putString("toDo_icon", todo_icon).apply();
            sharedPref.edit().putString("toDo_create", todo_creation).apply();
            sharedPref.edit().putString("toDo_attachment", todo_attachment).apply();

            helper_main.switchToActivity(Popup_todo.this, Activity_todo.class, false);
        }
    });

    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

            final CharSequence[] options = { getString(R.string.bookmark_edit_title),
                    getString(R.string.todo_share), getString(R.string.bookmark_createNote),
                    getString(R.string.bookmark_createEvent), getString(R.string.bookmark_remove_bookmark) };
            new AlertDialog.Builder(Popup_todo.this)
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.bookmark_edit_title))) {

                                AlertDialog.Builder builder = new AlertDialog.Builder(Popup_todo.this);
                                View dialogView = View.inflate(Popup_todo.this, R.layout.dialog_edit_title,
                                        null);

                                final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
                                edit_title.setHint(R.string.bookmark_edit_title);
                                edit_title.setText(todo_title);

                                builder.setView(dialogView);
                                builder.setTitle(R.string.bookmark_edit_title);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                                String inputTag = edit_title.getText().toString().trim();
                                                db.update(Integer.parseInt(_id), inputTag, todo_content,
                                                        todo_icon, todo_attachment, todo_creation);
                                                setTodoList();
                                                Snackbar.make(lv, R.string.bookmark_added,
                                                        Snackbar.LENGTH_SHORT).show();
                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        });

                                final AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();
                                helper_main.showKeyboard(Popup_todo.this, edit_title);
                            }

                            if (options[item].equals(getString(R.string.todo_share))) {
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("text/plain");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, todo_title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, todo_content);
                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.note_share_2))));
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                Intent calIntent = new Intent(Intent.ACTION_INSERT);
                                calIntent.setType("vnd.android.cursor.item/event");
                                calIntent.putExtra(CalendarContract.Events.TITLE, todo_title);
                                calIntent.putExtra(CalendarContract.Events.DESCRIPTION, todo_content);
                                startActivity(calIntent);
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                Snackbar snackbar = Snackbar
                                        .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setTodoList();
                                            }
                                        });
                                snackbar.show();
                            }

                            if (options[item].equals(getString(R.string.bookmark_createNote))) {
                                sharedPref.edit().putString("handleTextTitle", todo_title)
                                        .putString("handleTextText", todo_content).apply();
                                helper_main.switchToActivity(Popup_todo.this, Activity_EditNote.class, false);
                            }

                        }
                    }).show();

            return true;
        }
    });

    if (lv.getAdapter().getCount() == 0) {
        new android.app.AlertDialog.Builder(this)
                .setMessage(helper_main.textSpannable(getString(R.string.toast_noEntry)))
                .setPositiveButton(this.getString(R.string.toast_yes), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        finish();
                    }
                }).show();
        new Handler().postDelayed(new Runnable() {
            public void run() {
                finish();
            }
        }, 2000);
    }
}

From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java

/**
 * Format appropriately the suggested word in {@link #mWordViews} specified by
 * <code>positionInStrip</code>. When the suggested word doesn't exist, the corresponding
 * {@link TextView} will be disabled and never respond to user interaction. The suggested word
 * may be shrunk or ellipsized to fit in the specified width.
 *
 * The <code>positionInStrip</code> argument is the index in the suggestion strip. The indices
 * increase towards the right for LTR scripts and the left for RTL scripts, starting with 0.
 * The position of the most important suggestion is in {@link #mCenterPositionInStrip}. This
 * usually doesn't match the index in <code>suggedtedWords</code> -- see
 * {@link #getPositionInSuggestionStrip(int,SuggestedWords)}.
 *
 * @param positionInStrip the position in the suggestion strip.
 * @param width the maximum width for layout in pixels.
 * @return the {@link TextView} containing the suggested word appropriately formatted.
 *///ww w.j  a v a2s .c  om
private TextView layoutWord(final int positionInStrip, final int width) {
    final TextView wordView = mWordViews.get(positionInStrip);
    final CharSequence word = wordView.getText();
    if (positionInStrip == mCenterPositionInStrip && mMoreSuggestionsAvailable) {
        // TODO: This "more suggestions hint" should have a nicely designed icon.
        wordView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, mMoreSuggestionsHint);
        // HACK: Align with other TextViews that have no compound drawables.
        wordView.setCompoundDrawablePadding(-mMoreSuggestionsHint.getIntrinsicHeight());
    } else {
        wordView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
    }
    // {@link StyleSpan} in a content description may cause an issue of TTS/TalkBack.
    // Use a simple {@link String} to avoid the issue.
    wordView.setContentDescription(TextUtils.isEmpty(word) ? null : word.toString());
    final CharSequence text = getEllipsizedText(word, width, wordView.getPaint());
    final float scaleX = getTextScaleX(word, width, wordView.getPaint());
    wordView.setText(text); // TextView.setText() resets text scale x to 1.0.
    wordView.setTextScaleX(Math.max(scaleX, MIN_TEXT_XSCALE));
    // A <code>wordView</code> should be disabled when <code>word</code> is empty in order to
    // make it unclickable.
    // With accessibility touch exploration on, <code>wordView</code> should be enabled even
    // when it is empty to avoid announcing as "disabled".
    wordView.setEnabled(
            !TextUtils.isEmpty(word) || AccessibilityUtils.getInstance().isTouchExplorationEnabled());
    return wordView;
}