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:de.baumann.hhsmoodle.popup.Popup_note.java

private void setNotesList() {

    //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[] { "note_title", "note_content", "note_creation" };
    final String search = sharedPref.getString("filter_note_subject", "");
    final Cursor row = db.fetchDataByFilter(search, "note_title");

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(Popup_note.this, layoutstyle, row, column, xml_id,
            0) {//  w  ww . j av a  2 s. co  m
        @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 note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_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 (note_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 (note_attachment) {
            case "":
                iv_attachment.setVisibility(View.GONE);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.ic_attachment);
                break;
            }

            File file = new File(note_attachment);
            if (!file.exists()) {
                iv_attachment.setVisibility(View.GONE);
            }

            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_note.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_note.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), note_title, note_content, "3",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "2",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "1",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    }
                                }
                            }).show();
                }
            });
            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    helper_main.openAtt(Popup_note.this, lv, note_attachment);
                }
            });
            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 note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            final Button attachment2;
            final TextView textInput;

            LayoutInflater inflater = Popup_note.this.getLayoutInflater();

            final ViewGroup nullParent = null;
            final View dialogView = inflater.inflate(R.layout.dialog_note_show, nullParent);

            final String attName = note_attachment.substring(note_attachment.lastIndexOf("/") + 1);
            final String att = getString(R.string.app_att) + ": " + attName;

            attachment2 = (Button) dialogView.findViewById(R.id.button_att);
            if (attName.equals("")) {
                attachment2.setVisibility(View.GONE);
            } else {
                attachment2.setText(att);
            }
            File file2 = new File(note_attachment);
            if (!file2.exists()) {
                attachment2.setVisibility(View.GONE);
            }

            textInput = (TextView) dialogView.findViewById(R.id.note_text_input);
            textInput.setText(note_content);
            Linkify.addLinks(textInput, Linkify.WEB_URLS);

            attachment2.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    helper_main.openAtt(Popup_note.this, lv, note_attachment);
                }
            });

            final ImageView be = (ImageView) dialogView.findViewById(R.id.imageButtonPri);

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

            android.app.AlertDialog.Builder dialog = new android.app.AlertDialog.Builder(Popup_note.this)
                    .setTitle(note_title).setView(dialogView)
                    .setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setNegativeButton(R.string.note_edit, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            sharedPref.edit().putString("handleTextTitle", note_title)
                                    .putString("handleTextText", note_content)
                                    .putString("handleTextIcon", note_icon).putString("handleTextSeqno", _id)
                                    .putString("handleTextAttachment", note_attachment)
                                    .putString("handleTextCreate", note_creation).apply();
                            helper_main.switchToActivity(Popup_note.this, Activity_EditNote.class, false);
                        }
                    });
            dialog.show();
        }
    });

    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 note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            final CharSequence[] options = { getString(R.string.note_edit), getString(R.string.note_share),
                    getString(R.string.todo_menu), getString(R.string.bookmark_createEvent),
                    getString(R.string.note_remove_note) };
            new AlertDialog.Builder(Popup_note.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.note_edit))) {
                                sharedPref.edit().putString("handleTextTitle", note_title)
                                        .putString("handleTextText", note_content)
                                        .putString("handleTextIcon", note_icon)
                                        .putString("handleTextSeqno", _id)
                                        .putString("handleTextAttachment", note_attachment)
                                        .putString("handleTextCreate", note_creation).apply();
                                helper_main.switchToActivity(Popup_note.this, Activity_EditNote.class, false);
                            }

                            if (options[item].equals(getString(R.string.note_share))) {
                                File attachment = new File(note_attachment);
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("text/plain");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, note_title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, note_content);

                                if (attachment.exists()) {
                                    Uri bmpUri = Uri.fromFile(attachment);
                                    sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
                                }

                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.note_share_2))));
                            }

                            if (options[item].equals(getString(R.string.todo_menu))) {

                                Todo_DbAdapter db = new Todo_DbAdapter(Popup_note.this);
                                db.open();
                                if (db.isExist(note_title)) {
                                    Snackbar.make(lv, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG)
                                            .show();
                                } else {
                                    db.insert(note_title, note_content, "3", "true", helper_main.createDate());
                                    ViewPager viewPager = (ViewPager) Popup_note.this
                                            .findViewById(R.id.viewpager);
                                    viewPager.setCurrentItem(2);
                                    Popup_note.this.setTitle(R.string.todo_title);
                                    dialog.dismiss();
                                }
                            }

                            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, note_title);
                                calIntent.putExtra(CalendarContract.Events.DESCRIPTION, note_content);
                                startActivity(calIntent);
                            }

                            if (options[item].equals(getString(R.string.note_remove_note))) {
                                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));
                                                setNotesList();
                                            }
                                        });
                                snackbar.show();
                            }
                        }
                    }).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.mobiletin.inputmethod.indic.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.
 *//*from www  .j a  v  a  2s .c o m*/
private TextView layoutWord(final int positionInStrip, final int width) {

    //    final TextView wordView = mWordViews.get(positionInStrip);

    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;
}

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

@Override
public void applySelfActionBar() {
    if (parentActivity == null) {
        return;/*www . j  ava  2s .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.GroupInfo));
    actionBar.setSubtitle(null);

    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);
    }
    ((ApplicationActivity) parentActivity).fixBackButton();
}

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

@Override
public void applySelfActionBar() {
    if (parentActivity == null) {
        return;//from w  ww .  ja  v  a 2s. c o  m
    }
    final ActionBar actionBar = parentActivity.getSupportActionBar();
    if (onlySelect) {
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayUseLogoEnabled(false);
        actionBar.setDisplayShowCustomEnabled(false);
        actionBar.setSubtitle(null);
        actionBar.setCustomView(null);
        actionBar.setTitle(getStringEntry(R.string.SelectChat));
        ((ApplicationActivity) parentActivity).fixBackButton();
    } else {
        ImageView view = (ImageView) parentActivity.findViewById(16908332);
        if (view == null) {
            view = (ImageView) parentActivity.findViewById(R.id.home);
        }
        if (view != null) {
            view.setPadding(Utilities.dp(6), 0, Utilities.dp(6), 0);
        }
        actionBar.setHomeButtonEnabled(false);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(false);
        actionBar.setDisplayUseLogoEnabled(true);
        actionBar.setDisplayShowCustomEnabled(false);
        actionBar.setCustomView(null);
        actionBar.setSubtitle(null);
        actionBar.setTitle(getStringEntry(R.string.AppName));
    }

    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.nttec.everychan.ui.NewTabFragment.java

private void openLocal() {
    if (!CompatibilityUtils.hasAccessStorage(activity))
        return;//w ww  .  jav a2 s.  co  m
    final ListAdapter savedThreadsAdapter = new ArrayAdapter<Object>(activity, 0) {
        private static final int HEAD_ITEM = 0;
        private static final int NORMAL_ITEM = 1;

        private LayoutInflater inflater = LayoutInflater.from(activity);
        private int drawablePadding = (int) (resources.getDisplayMetrics().density * 5 + 0.5f);

        {
            add(new Object());
            for (Database.SavedThreadEntry entity : MainApplication.getInstance().database.getSavedThreads()) {
                File file = new File(entity.filepath);
                if (file.exists())
                    add(entity);
            }
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v;
            if (position == 0) {
                v = convertView == null ? inflater.inflate(android.R.layout.simple_list_item_1, parent, false)
                        : convertView;
                TextView tv = (TextView) v.findViewById(android.R.id.text1);
                tv.setText(R.string.newtab_select_local_file);
            } else {
                Database.SavedThreadEntry item = (Database.SavedThreadEntry) getItem(position);
                v = convertView == null ? inflater.inflate(android.R.layout.simple_list_item_2, parent, false)
                        : convertView;
                TextView t1 = (TextView) v.findViewById(android.R.id.text1);
                TextView t2 = (TextView) v.findViewById(android.R.id.text2);
                t1.setSingleLine();
                t2.setSingleLine();
                t1.setEllipsize(TextUtils.TruncateAt.END);
                t2.setEllipsize(TextUtils.TruncateAt.START);
                t1.setText(item.title);
                t2.setText(item.filepath);
                ChanModule chan = MainApplication.getInstance().getChanModule(item.chan);
                if (chan != null) {
                    t1.setCompoundDrawablesWithIntrinsicBounds(chan.getChanFavicon(), null, null, null);
                    t1.setCompoundDrawablePadding(drawablePadding);
                }
            }
            return v;
        }

        @Override
        public int getViewTypeCount() {
            return 2;
        }

        @Override
        public int getItemViewType(int position) {
            return position == 0 ? HEAD_ITEM : NORMAL_ITEM;
        }
    };

    if (savedThreadsAdapter.getCount() == 1) {
        selectFile();
        return;
    }
    DialogInterface.OnClickListener listListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == 0) {
                selectFile();
            } else {
                Database.SavedThreadEntry item = (Database.SavedThreadEntry) savedThreadsAdapter.getItem(which);
                LocalHandler.open(item.filepath, activity);
            }
        }
    };
    new AlertDialog.Builder(activity).setTitle(R.string.newtab_saved_threads_title)
            .setAdapter(savedThreadsAdapter, listListener).setNegativeButton(android.R.string.cancel, null)
            .show();
}

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

@Override
public void applySelfActionBar() {
    if (parentActivity == null) {
        return;//from ww w .  jav  a2 s .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.setSubtitle(null);

    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);
    }

    if (destroyAfterSelect) {
        actionBar.setTitle(getStringEntry(R.string.SelectContact));
    } else {
        actionBar.setTitle(getStringEntry(R.string.Contacts));
    }

    ((ApplicationActivity) parentActivity).fixBackButton();
}

From source file:org.telegram.ui.ActionBar.ActionBarMenuItem.java

public TextView addSubItem(int id, String text, int icon) {
    if (popupLayout == null) {
        rect = new Rect();
        location = new int[2];
        popupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getContext());
        popupLayout.setOnTouchListener(new OnTouchListener() {
            @Override/*from   w w w  .j  ava 2 s .c  o m*/
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                    if (popupWindow != null && popupWindow.isShowing()) {
                        v.getHitRect(rect);
                        if (!rect.contains((int) event.getX(), (int) event.getY())) {
                            popupWindow.dismiss();
                        }
                    }
                }
                return false;
            }
        });
        popupLayout.setDispatchKeyEventListener(new ActionBarPopupWindow.OnDispatchKeyEventListener() {
            @Override
            public void onDispatchKeyEvent(KeyEvent keyEvent) {
                if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0
                        && popupWindow != null && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                }
            }
        });
    }
    TextView textView = new TextView(getContext());
    textView.setTextColor(ContextCompat.getColor(getContext(), R.color.primary_text));
    textView.setBackgroundResource(R.drawable.list_selector);
    if (!LocaleController.isRTL) {
        textView.setGravity(Gravity.CENTER_VERTICAL);
    } else {
        textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
    }
    textView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    textView.setMinWidth(AndroidUtilities.dp(196));
    textView.setTag(id);
    textView.setText(text);
    if (icon != 0) {
        textView.setCompoundDrawablePadding(AndroidUtilities.dp(12));
        if (!LocaleController.isRTL) {
            textView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(icon), null, null,
                    null);
        } else {
            textView.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(icon),
                    null);
        }
    }
    popupLayout.setShowedFromBotton(showFromBottom);
    popupLayout.addView(textView);
    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams();
    if (LocaleController.isRTL) {
        layoutParams.gravity = Gravity.RIGHT;
    }
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(48);
    textView.setLayoutParams(layoutParams);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (popupWindow != null && popupWindow.isShowing()) {
                if (processedPopupClick) {
                    return;
                }
                processedPopupClick = true;
                popupWindow.dismiss(allowCloseAnimation);
            }
            if (parentMenu != null) {
                parentMenu.onItemClick((Integer) view.getTag());
            } else if (delegate != null) {
                delegate.onItemClick((Integer) view.getTag());
            }
        }
    });
    menuHeight += layoutParams.height;
    return textView;
}

From source file:com.secbro.qark.filebrowser.FileBrowserFragment.java

private void createFileListAdapter() {
    adapter = new ArrayAdapter<Item>(getActivity(), android.R.layout.select_dialog_item, android.R.id.text1,
            fileList) {/*from w  w w  . j a va  2 s.  c  om*/
        @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);

            // add margin between image and text (support various screen
            // densities)
            // int dp5 = (int) (5 *
            // getResources().getDisplayMetrics().density + 0.5f);
            int dp3 = (int) (3 * getResources().getDisplayMetrics().density + 0.5f);
            // TODO: change next line for empty directory, so text will be
            // centered
            textView.setCompoundDrawablePadding(dp3);
            textView.setBackgroundColor(Color.LTGRAY);
            return view;
        }// public View getView(int position, View convertView, ViewGroup
    };// adapter = new ArrayAdapter<Item>(this,
}

From source file:de.baumann.hhsmoodle.data_todo.Todo_Fragment.java

public void setTodoList() {

    if (isFABOpen) {
        closeFABMenu();//from   w w w.j av  a  2  s . c  o  m
    }

    NotificationManager nMgr = (NotificationManager) getActivity()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    nMgr.cancelAll();

    //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 Cursor row = db.fetchAllData(getActivity());
    adapter = new SimpleCursorAdapter(getActivity(), 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);
            helper_main.switchIcon(getActivity(), todo_icon, "todo_icon", iv_icon);

            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(getActivity(), "de.baumann.hhsmoodle.activities.Activity_splash");
                PendingIntent piMain = PendingIntent.getActivity(getActivity(), n, iMain, 0);

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

                Notification notification = new NotificationCompat.Builder(getActivity())
                        .setColor(ContextCompat.getColor(getActivity(), 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) getActivity()
                        .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 helper_main.Item[] items = {
                            new helper_main.Item(getString(R.string.note_priority_0), R.drawable.circle_green),
                            new helper_main.Item(getString(R.string.note_priority_1), R.drawable.circle_yellow),
                            new helper_main.Item(getString(R.string.note_priority_2), R.drawable.circle_red), };

                    ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(),
                            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(getActivity())
                            .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;
        }
    };

    //display data by filter
    final String note_search = sharedPref.getString("filter_todoBY", "note_title");
    sharedPref.edit().putString("filter_todoBY", "note_title").apply();
    filter.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s.toString());
        }
    });
    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            return db.fetchDataByFilter(constraint.toString(), note_search);
        }
    });

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

            if (isFABOpen) {
                closeFABMenu();
            }

            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(getActivity(), Activity_todo.class, false);
        }
    });

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

            if (isFABOpen) {
                closeFABMenu();
            }

            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.number_edit_entry),
                    getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_share),
                    getString(R.string.bookmark_createNote), getString(R.string.count_create),
                    getString(R.string.bookmark_createEvent) };
            new AlertDialog.Builder(getActivity())
                    .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.number_edit_entry))) {

                                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                                View dialogView = View.inflate(getActivity(), 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(getActivity(), 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))) {
                                helper_main.createCalendarEvent(getActivity(), todo_title, todo_content);
                            }

                            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))) {
                                Notes_helper.newNote(getActivity(), todo_title, todo_content, "", "", "", "");
                            }

                            if (options[item].equals(getString(R.string.count_create))) {
                                Count_helper.newCount(getActivity(), todo_title, todo_content,
                                        getActivity().getString(R.string.note_content), false);
                            }

                        }
                    }).show();

            return true;
        }
    });
}

From source file:pageslidingtabstrip.ConsumingPagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {
    if (!isDoubleTab) {
        View v = View.inflate(getContext(), R.layout.tab_desc, null);
        TextView text = (TextView) v.findViewById(R.id.text);
        if (iconShowDirection != -1 && positions != null && iconIds != null
                && positions.length == iconIds.length) {
            for (int index : positions) {
                if (index == position) {
                    if (iconShowDirection == LEFT) {
                        text.setCompoundDrawablesWithIntrinsicBounds(iconIds[index], 0, 0, 0);
                    } else {
                        text.setCompoundDrawablesWithIntrinsicBounds(0, 0, iconIds[index], 0);
                    }// w ww . ja va2 s  .c o  m
                    text.setCompoundDrawablePadding(CommonTools.dip2px(context, 5));
                    break;
                }
            }
        }
        text.setText(title);
        addTab(position, v);
    } else {
        View view = View.inflate(getContext(), R.layout.layout_text_tab, null);
        TextView classname = (TextView) view.findViewById(R.id.classname);
        TextView schoolname = (TextView) view.findViewById(R.id.schoolname);
        if (title.contains(";")) {
            String[] strs = title.split(";");
            schoolname.setText(strs[0]);
            classname.setText(strs[1]);
            addTab(position, view);
        } else {
            classname.setText(title.substring(0, title.indexOf("(")));
            schoolname.setText(title.substring(title.indexOf("(") + 1, title.indexOf(")")));
            addTab(position, view);
        }
    }

}