Example usage for android.widget TextView setCompoundDrawablesWithIntrinsicBounds

List of usage examples for android.widget TextView setCompoundDrawablesWithIntrinsicBounds

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setCompoundDrawablesWithIntrinsicBounds(@Nullable Drawable left, @Nullable Drawable top,
        @Nullable Drawable right, @Nullable Drawable bottom) 

Source Link

Document

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text.

Usage

From source file:com.example.kjpark.smartclass.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;//w  w w. j av  a 2  s  .  c om
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        tabTitleView.setTextColor(getResources().getColorStateList(R.color.selector));
        tabTitleView.setTextSize(14);

        if (adapter.getPageTitle(i) == "") {
            tabTitleView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_setting, 0, 0, 0);
        } else if (adapter.getPageTitle(i) == "") {
            tabTitleView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_message, 0, 0, 0);
        } else if (adapter.getPageTitle(i) == " ") {
            tabTitleView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_memory, 0, 0, 0);
        } else if (adapter.getPageTitle(i) == "") {
            tabTitleView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_assignment, 0, 0, 0);
        } else if (adapter.getPageTitle(i) == "") {
            tabTitleView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_notice, 0, 0, 0);
        } else {
            tabTitleView.setText(adapter.getPageTitle(i));
        }
        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }

}

From source file:com.investallign.controls.SlidingTabLayout.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@SuppressWarnings("deprecation")
private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;/*  w  ww  .ja v a 2  s .c  om*/
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        String[] split = adapter.getPageTitle(i).toString().split(";");
        title = split[0];
        int iconId = Integer.parseInt(split[1]);

        tabTitleView.setText(title);

        tabTitleView.setCompoundDrawablesWithIntrinsicBounds(0, iconId, 0, 0);
        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }

        if (isFromActivity) {
            tabTitleView.setTextColor(getResources().getColorStateList(R.color.selectorfortextview));
            tabTitleView.setBackground(getResources().getDrawable(R.drawable.selector));

        } else {
            tabTitleView.setTextColor(getResources().getColorStateList(R.color.selector));
            tabTitleView.setBackground(null);
        }

        tabTitleView.setTextSize(14);
    }
}

From source file:de.baumann.hhsmoodle.data_schedule.Schedule_Fragment.java

private void setScheduleList() {

    final int line = sharedPref.getInt("getLine", 1);
    //display data
    final int layoutstyle = R.layout.list_item_schedule;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.att_notes,
            R.id.textView_create_notes };
    String[] column = new String[] { "schedule_title", "schedule_content", "schedule_attachment",
            "schedule_creation" };
    final Cursor row = db.fetchAllData();
    adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override//from   ww w  .j av a2  s.co m
        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 schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title"));
            final String schedule_content = row2.getString(row2.getColumnIndexOrThrow("schedule_content"));
            final String schedule_icon = row2.getString(row2.getColumnIndexOrThrow("schedule_icon"));
            final String schedule_attachment = row2
                    .getString(row2.getColumnIndexOrThrow("schedule_attachment"));
            final String schedule_creation = row2.getString(row2.getColumnIndexOrThrow("schedule_creation"));
            final String schedule_id = row2.getString(row2.getColumnIndexOrThrow("schedule_id"));

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

            if (position == line) {
                v.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorAccent_trans));
            } else {
                v.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.color_trans));
            }

            if (schedule_title.equals(getActivity().getString(R.string.schedule_weekend))
                    || schedule_title.equals(getActivity().getString(R.string.schedule_def_title))) {
                sharedPref.edit().putString("hour_" + schedule_id, "false").apply();
            } else {
                sharedPref.edit().putString("hour_" + schedule_id, "true").apply();
            }

            Subjects_helper.switchIcon(getActivity(), schedule_icon, "schedule_color", iv_icon);

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    final helper_main.Item[] items = {
                            new helper_main.Item(getString(R.string.subjects_color_red), R.drawable.circle_red),
                            new helper_main.Item(getString(R.string.subjects_color_pink),
                                    R.drawable.circle_pink),
                            new helper_main.Item(getString(R.string.subjects_color_purple),
                                    R.drawable.circle_purple),
                            new helper_main.Item(getString(R.string.subjects_color_blue),
                                    R.drawable.circle_blue),
                            new helper_main.Item(getString(R.string.subjects_color_teal),
                                    R.drawable.circle_teal),
                            new helper_main.Item(getString(R.string.subjects_color_green),
                                    R.drawable.circle_green),
                            new helper_main.Item(getString(R.string.subjects_color_lime),
                                    R.drawable.circle_lime),
                            new helper_main.Item(getString(R.string.subjects_color_yellow),
                                    R.drawable.circle_yellow),
                            new helper_main.Item(getString(R.string.subjects_color_orange),
                                    R.drawable.circle_orange),
                            new helper_main.Item(getString(R.string.subjects_color_brown),
                                    R.drawable.circle_brown),
                            new helper_main.Item(getString(R.string.subjects_color_grey),
                                    R.drawable.circle_grey), };

                    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), schedule_title, schedule_content, "1",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "2",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "3",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 3) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "4",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 4) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "5",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 5) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "6",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 6) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "7",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 7) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "8",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 8) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "9",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 9) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "10",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 10) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "11",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    }
                                }
                            }).show();
                }
            });

            return v;
        }
    };

    //display data by filter
    final String note_search = sharedPref.getString("filter_scheduleBY", "schedule_title");
    sharedPref.edit().putString("filter_scheduleBY", "schedule_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) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title"));

            final CharSequence[] options = { getString(R.string.schedule_todo),
                    getString(R.string.schedule_notes) };
            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.schedule_todo))) {
                                sharedPref.edit().putString("filter_todo_subject", schedule_title).apply();
                                new Handler().postDelayed(new Runnable() {
                                    public void run() {
                                        helper_main.switchToActivity(getActivity(), Popup_todo.class, false);
                                    }
                                }, 200);
                            }
                            if (options[item].equals(getString(R.string.schedule_notes))) {
                                sharedPref.edit().putString("filter_note_subject", schedule_title).apply();
                                new Handler().postDelayed(new Runnable() {
                                    public void run() {
                                        helper_main.switchToActivity(getActivity(), Popup_note.class, false);
                                    }
                                }, 200);
                            }
                        }
                    }).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 schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title"));
            final String schedule_content = row2.getString(row2.getColumnIndexOrThrow("schedule_content"));
            final String schedule_icon = row2.getString(row2.getColumnIndexOrThrow("schedule_icon"));
            final String schedule_attachment = row2
                    .getString(row2.getColumnIndexOrThrow("schedule_attachment"));
            final String schedule_creation = row2.getString(row2.getColumnIndexOrThrow("schedule_creation"));
            final String schedule_id = row2.getString(row2.getColumnIndexOrThrow("schedule_id"));

            final CharSequence[] options = { getString(R.string.number_edit_entry),
                    getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_menu),
                    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() {
                        @SuppressWarnings("ConstantConditions")
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.number_edit_entry))) {

                                final CharSequence[] options = { getString(R.string.schedule_fromSubjectList),
                                        getString(R.string.todo_from_new) };
                                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.schedule_fromSubjectList))) {
                                                    sharedPref.edit().putString("edit_yes", "true")
                                                            .putInt("scroll", Integer.parseInt(schedule_id))
                                                            .putString("handleSubjectCreation",
                                                                    schedule_creation)
                                                            .putString("handleSubject_id", schedule_id)
                                                            .putString("handle_id", _id).apply();
                                                    helper_main.switchToActivity(getActivity(),
                                                            Popup_subjects.class, false);
                                                }

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

                                                    LayoutInflater inflater = getActivity().getLayoutInflater();

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

                                                    final EditText titleInput = (EditText) dialogView
                                                            .findViewById(R.id.subject_title_);
                                                    titleInput.setSelection(titleInput.getText().length());
                                                    titleInput.setText(schedule_title);
                                                    final EditText teacherInput = (EditText) dialogView
                                                            .findViewById(R.id.subject_teacher);
                                                    teacherInput.setText(schedule_content);
                                                    final EditText roomInput = (EditText) dialogView
                                                            .findViewById(R.id.subject_room);
                                                    roomInput.setText(schedule_attachment);

                                                    helper_main.showKeyboard(getActivity(), titleInput);

                                                    final ImageButton be = (ImageButton) dialogView
                                                            .findViewById(R.id.imageButtonPri);
                                                    assert be != null;

                                                    Subjects_helper.switchIcon(getActivity(), schedule_icon,
                                                            "schedule_color", be);

                                                    be.setOnClickListener(new View.OnClickListener() {

                                                        @Override
                                                        public void onClick(View arg0) {

                                                            final helper_main.Item[] items = {
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_red),
                                                                            R.drawable.circle_red),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_pink),
                                                                            R.drawable.circle_pink),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_purple),
                                                                            R.drawable.circle_purple),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_blue),
                                                                            R.drawable.circle_blue),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_teal),
                                                                            R.drawable.circle_teal),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_green),
                                                                            R.drawable.circle_green),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_lime),
                                                                            R.drawable.circle_lime),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_yellow),
                                                                            R.drawable.circle_yellow),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_orange),
                                                                            R.drawable.circle_orange),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_brown),
                                                                            R.drawable.circle_brown),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_grey),
                                                                            R.drawable.circle_grey), };

                                                            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
                                                                            * getActivity().getResources()
                                                                                    .getDisplayMetrics().density
                                                                            + 0.5f);
                                                                    tv.setCompoundDrawablePadding(dp5);

                                                                    return v;
                                                                }
                                                            };

                                                            new android.app.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) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_red);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "1")
                                                                                                .apply();
                                                                                    } else if (item == 1) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_pink);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "2")
                                                                                                .apply();
                                                                                    } else if (item == 2) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_purple);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "3")
                                                                                                .apply();
                                                                                    } else if (item == 3) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_blue);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "4")
                                                                                                .apply();
                                                                                    } else if (item == 4) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_teal);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "5")
                                                                                                .apply();
                                                                                    } else if (item == 5) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_green);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "6")
                                                                                                .apply();
                                                                                    } else if (item == 6) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_lime);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "7")
                                                                                                .apply();
                                                                                    } else if (item == 7) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_yellow);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "8")
                                                                                                .apply();
                                                                                    } else if (item == 8) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_orange);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "9")
                                                                                                .apply();
                                                                                    } else if (item == 9) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_brown);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "10")
                                                                                                .apply();
                                                                                    } else if (item == 10) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_grey);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "11")
                                                                                                .apply();
                                                                                    }
                                                                                }
                                                                            })
                                                                    .show();
                                                        }
                                                    });

                                                    android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(
                                                            getActivity());
                                                    builder.setTitle(R.string.subjects_edit);
                                                    builder.setView(dialogView);
                                                    builder.setPositiveButton(R.string.toast_yes,
                                                            new DialogInterface.OnClickListener() {

                                                                public void onClick(DialogInterface dialog,
                                                                        int whichButton) {

                                                                    String inputTitle = titleInput.getText()
                                                                            .toString().trim();
                                                                    String inputTeacher = teacherInput.getText()
                                                                            .toString().trim();
                                                                    String inputRoom = roomInput.getText()
                                                                            .toString().trim();

                                                                    db.update(Integer.parseInt(_id), inputTitle,
                                                                            inputTeacher,
                                                                            sharedPref.getString(
                                                                                    "schedule_color", ""),
                                                                            inputRoom, schedule_creation,
                                                                            schedule_id);
                                                                    dialog.dismiss();
                                                                    setScheduleList();
                                                                    lv.setSelection(
                                                                            Integer.parseInt(schedule_id) - 1);
                                                                    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 android.support.v7.app.AlertDialog dialog2 = builder
                                                            .create();
                                                    dialog2.show();
                                                }

                                            }
                                        }).show();
                            }

                            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.update(Integer.parseInt(_id),
                                                        getString(R.string.schedule_def_teacher),
                                                        getString(R.string.schedule_def_teacher), "11",
                                                        getString(R.string.schedule_def_teacher),
                                                        schedule_creation, schedule_id);
                                                setScheduleList();
                                                lv.setSelection(Integer.parseInt(schedule_id) - 1);
                                            }
                                        });
                                snackbar.show();
                            }

                            if (options[item].equals(getString(R.string.todo_menu))) {
                                Todo_helper.newTodo(getActivity(), schedule_title, schedule_content,
                                        getActivity().getString(R.string.note_content));
                            }

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

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                helper_main.createCalendarEvent(getActivity(), schedule_title,
                                        schedule_content);
                            }

                            if (options[item].equals(getString(R.string.bookmark_createNote))) {
                                Notes_helper.newNote(getActivity(), schedule_title, schedule_content, "", "",
                                        "", "");
                            }

                        }
                    }).show();
            return true;
        }
    });

    scrollToNow();
}

From source file:com.simplealertdialog.SimpleAlertDialog.java

public void setItems(final CharSequence[] items, final int[] iconResIds,
        final AdapterView.OnItemClickListener listener) {
    if (iconResIds == null || items == null) {
        return;/*from   ww  w  .  j  av  a 2s. co  m*/
    }
    final IconListItem[] iconListItems = new IconListItem[Math.min(iconResIds.length, items.length)];
    for (int i = 0; i < iconResIds.length && i < items.length; i++) {
        iconListItems[i] = new IconListItem(iconResIds[i], items[i]);
    }
    mAdapter = new ArrayAdapter<IconListItem>(getContext(), android.R.layout.simple_list_item_1,
            iconListItems) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            if (view != null) {
                TextView tv = (TextView) view.findViewById(android.R.id.text1);
                if (mListItemTextStyle != 0) {
                    tv.setTextAppearance(getContext(), mListItemTextStyle);
                }
                tv.setText(iconListItems[position].text);
                tv.setCompoundDrawablesWithIntrinsicBounds(iconListItems[position].iconResId, 0, 0, 0);
                int padding = (int) (8 * getContext().getResources().getDisplayMetrics().density);
                tv.setCompoundDrawablePadding(padding);
            }
            return view;
        }
    };
    mListItemListener = listener;
}

From source file:com.quaffon.team9.SlidingTabView.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;/*w  w w  .  j  av  a 2s  .c o m*/
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }
        tabTitleView.setCompoundDrawablesWithIntrinsicBounds(ViewPagerAdapter.getDrawableId(i), 0, 0, 0);

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}

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 ww .  j  a  va  2 s.c om*/
            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:org.wheelmap.android.fragment.POIDetailFragment.java

private void startPickPhotoDialog() {

    // user must be logged in
    UserCredentials credentials = new UserCredentials(getActivity());
    if (!credentials.isLoggedIn()) {
        Intent intent = new Intent(getActivity(), ProfileActivity.class);
        startActivityForResult(intent, REQUEST_CODE_LOGIN);
        return;//from   www . j ava  2 s . c  o  m
    }

    final Item[] items = {
            new Item(getString(R.string.photo_upload_picker_gallery), android.R.drawable.ic_menu_gallery),
            new Item(getString(R.string.photo_upload_picker_take_new), android.R.drawable.ic_menu_camera) };

    final ListAdapter adapter = new ArrayAdapter<Item>(this.getActivity(), android.R.layout.select_dialog_item,
            android.R.id.text1, items) {
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = super.getView(position, convertView, parent);
            TextView tv = (TextView) v.findViewById(android.R.id.text1);

            tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);

            int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
            tv.setCompoundDrawablePadding(dp5);

            return v;
        }

    };

    AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());

    builder.setTitle(R.string.photo_upload_picker_title);
    builder.setCancelable(true);

    builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == 0) {
                startGetPhotoFromGalleryIntent();
            } else if (which == 1) {
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                new_photo_file = new File(Environment.getExternalStorageDirectory() + "/DCIM/",
                        "image" + new Date().getTime() + ".png");
                Uri pictureURI = Uri.fromFile(new_photo_file);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, pictureURI);
                startActivityForResult(intent, Request.REQUESTCODE_PHOTO_FROM_CAMERA);
            }

        }
    });
    dialog = builder.create();
    dialog.show();

}

From source file:de.baumann.hhsmoodle.data_subjects.Subjects_Fragment.java

private void setSubjectsList() {

    final helper_main.Item[] items = {
            new helper_main.Item(getString(R.string.subjects_color_red), R.drawable.circle_red),
            new helper_main.Item(getString(R.string.subjects_color_pink), R.drawable.circle_pink),
            new helper_main.Item(getString(R.string.subjects_color_purple), R.drawable.circle_purple),
            new helper_main.Item(getString(R.string.subjects_color_blue), R.drawable.circle_blue),
            new helper_main.Item(getString(R.string.subjects_color_teal), R.drawable.circle_teal),
            new helper_main.Item(getString(R.string.subjects_color_green), R.drawable.circle_green),
            new helper_main.Item(getString(R.string.subjects_color_lime), R.drawable.circle_lime),
            new helper_main.Item(getString(R.string.subjects_color_yellow), R.drawable.circle_yellow),
            new helper_main.Item(getString(R.string.subjects_color_orange), R.drawable.circle_orange),
            new helper_main.Item(getString(R.string.subjects_color_brown), R.drawable.circle_brown),
            new helper_main.Item(getString(R.string.subjects_color_grey), R.drawable.circle_grey), };

    //display data
    final int layoutstyle = R.layout.list_item_schedule;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.att_notes };
    String[] column = new String[] { "subject_title", "subject_content", "subject_attachment" };
    final Cursor row = db.fetchAllData();
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override/* ww  w.ja va 2s  . co m*/
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row = (Cursor) lv.getItemAtPosition(position);
            final String _id = row.getString(row.getColumnIndexOrThrow("_id"));
            final String subject_title = row.getString(row.getColumnIndexOrThrow("subject_title"));
            final String subject_content = row.getString(row.getColumnIndexOrThrow("subject_content"));
            final String subject_icon = row.getString(row.getColumnIndexOrThrow("subject_icon"));
            final String subject_attachment = row.getString(row.getColumnIndexOrThrow("subject_attachment"));
            final String subject_creation = row.getString(row.getColumnIndexOrThrow("subject_creation"));

            View v = super.getView(position, convertView, parent);
            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);
            Subjects_helper.switchIcon(getActivity(), subject_icon, "subject_color", iv_icon);
            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    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), subject_title, subject_content, "1",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "2",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "3",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 3) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "4",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 4) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "5",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 5) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "6",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 6) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "7",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 7) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "8",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 8) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "9",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 9) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "10",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 10) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "11",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    }
                                }
                            }).show();
                }
            });

            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 subject_title = row2.getString(row2.getColumnIndexOrThrow("subject_title"));
            final String subject_content = row2.getString(row2.getColumnIndexOrThrow("subject_content"));

            final CharSequence[] options = { getString(R.string.courseList_todo),
                    getString(R.string.courseList_note), getString(R.string.courseList_random),
                    getString(R.string.courseList_course), 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.courseList_random))) {

                                android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(
                                        getActivity());
                                View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null);

                                final EditText edit_title = (EditText) dialogView
                                        .findViewById(R.id.note_title_input);
                                edit_title.setHint(R.string.title_hint);
                                edit_title.setText(subject_title);

                                final EditText edit_cont = (EditText) dialogView
                                        .findViewById(R.id.note_text_input);
                                edit_cont.setHint(R.string.text_hint);

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

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

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

                                final android.app.AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();

                                dialog2.getButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE)
                                        .setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                //Do stuff, possibly set wantToCloseDialog to true then...
                                                Random_DbAdapter db = new Random_DbAdapter(getActivity());
                                                db.open();

                                                if (db.isExist(subject_title)) {
                                                    Snackbar.make(edit_title,
                                                            getString(R.string.toast_newTitle),
                                                            Snackbar.LENGTH_LONG).show();
                                                } else {
                                                    String inputTitle = edit_title.getText().toString().trim();
                                                    String inputCont = edit_cont.getText().toString().trim();
                                                    db.insert(inputTitle, inputCont, "", "",
                                                            helper_main.createDate());
                                                    dialog2.cancel();
                                                }
                                            }
                                        });
                                helper_main.showKeyboard(getActivity(), edit_title);
                            }

                            if (options[item].equals(getString(R.string.courseList_note))) {
                                Notes_helper.newNote(getActivity(), subject_title, subject_content, "", "", "",
                                        "");
                            }

                            if (options[item].equals(getString(R.string.courseList_todo))) {
                                Todo_helper.newTodo(getActivity(), subject_title, subject_content,
                                        getActivity().getString(R.string.note_content));
                            }

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

                                android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(
                                        getActivity());
                                View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null);

                                final EditText edit_title = (EditText) dialogView
                                        .findViewById(R.id.note_title_input);
                                edit_title.setHint(R.string.title_hint);
                                edit_title.setText(subject_title);

                                final EditText edit_cont = (EditText) dialogView
                                        .findViewById(R.id.note_text_input);
                                edit_cont.setHint(R.string.text_hint);

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

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

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

                                final android.app.AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();

                                dialog2.getButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE)
                                        .setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                //Do stuff, possibly set wantToCloseDialog to true then...
                                                Courses_DbAdapter db = new Courses_DbAdapter(getActivity());
                                                db.open();

                                                if (db.isExist(subject_title)) {
                                                    Snackbar.make(edit_title,
                                                            getString(R.string.toast_newTitle),
                                                            Snackbar.LENGTH_LONG).show();
                                                } else {
                                                    String inputTitle = edit_title.getText().toString().trim();
                                                    String inputCont = edit_cont.getText().toString().trim();
                                                    db.insert(inputTitle, inputCont, "", "",
                                                            helper_main.createDate());
                                                    dialog2.cancel();
                                                }
                                            }
                                        });
                                helper_main.showKeyboard(getActivity(), edit_title);
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                helper_main.createCalendarEvent(getActivity(), subject_title, subject_content);
                            }

                        }
                    }).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 subject_title = row2.getString(row2.getColumnIndexOrThrow("subject_title"));
            final String subject_content = row2.getString(row2.getColumnIndexOrThrow("subject_content"));
            final String subject_icon = row2.getString(row2.getColumnIndexOrThrow("subject_icon"));
            final String subject_attachment = row2.getString(row2.getColumnIndexOrThrow("subject_attachment"));
            final String subject_creation = row2.getString(row2.getColumnIndexOrThrow("subject_creation"));

            final CharSequence[] options = { getString(R.string.number_edit_entry),
                    getString(R.string.subjects_copy), getString(R.string.bookmark_remove_bookmark) };
            new android.app.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))) {

                                LayoutInflater inflater = getActivity().getLayoutInflater();

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

                                titleInput = (EditText) dialogView.findViewById(R.id.subject_title_);
                                titleInput.setSelection(titleInput.getText().length());
                                titleInput.setText(subject_title);
                                teacherInput = (EditText) dialogView.findViewById(R.id.subject_teacher);
                                teacherInput.setText(subject_content);
                                roomInput = (EditText) dialogView.findViewById(R.id.subject_room);
                                roomInput.setText(subject_attachment);

                                helper_main.showKeyboard(getActivity(), titleInput);

                                final ImageButton be = (ImageButton) dialogView
                                        .findViewById(R.id.imageButtonPri);
                                assert be != null;
                                Subjects_helper.switchIcon(getActivity(), subject_icon, "subject_color", be);

                                be.setOnClickListener(new View.OnClickListener() {

                                    @Override
                                    public void onClick(View arg0) {

                                        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 * getActivity().getResources()
                                                        .getDisplayMetrics().density + 0.5f);
                                                tv.setCompoundDrawablePadding(dp5);

                                                return v;
                                            }
                                        };

                                        new android.app.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) {
                                                            be.setImageResource(R.drawable.circle_red);
                                                            sharedPref.edit().putString("subject_color", "1")
                                                                    .apply();
                                                        } else if (item == 1) {
                                                            be.setImageResource(R.drawable.circle_pink);
                                                            sharedPref.edit().putString("subject_color", "2")
                                                                    .apply();
                                                        } else if (item == 2) {
                                                            be.setImageResource(R.drawable.circle_purple);
                                                            sharedPref.edit().putString("subject_color", "3")
                                                                    .apply();
                                                        } else if (item == 3) {
                                                            be.setImageResource(R.drawable.circle_blue);
                                                            sharedPref.edit().putString("subject_color", "4")
                                                                    .apply();
                                                        } else if (item == 4) {
                                                            be.setImageResource(R.drawable.circle_teal);
                                                            sharedPref.edit().putString("subject_color", "5")
                                                                    .apply();
                                                        } else if (item == 5) {
                                                            be.setImageResource(R.drawable.circle_green);
                                                            sharedPref.edit().putString("subject_color", "6")
                                                                    .apply();
                                                        } else if (item == 6) {
                                                            be.setImageResource(R.drawable.circle_lime);
                                                            sharedPref.edit().putString("subject_color", "7")
                                                                    .apply();
                                                        } else if (item == 7) {
                                                            be.setImageResource(R.drawable.circle_yellow);
                                                            sharedPref.edit().putString("subject_color", "8")
                                                                    .apply();
                                                        } else if (item == 8) {
                                                            be.setImageResource(R.drawable.circle_orange);
                                                            sharedPref.edit().putString("subject_color", "9")
                                                                    .apply();
                                                        } else if (item == 9) {
                                                            be.setImageResource(R.drawable.circle_brown);
                                                            sharedPref.edit().putString("subject_color", "10")
                                                                    .apply();
                                                        } else if (item == 10) {
                                                            be.setImageResource(R.drawable.circle_grey);
                                                            sharedPref.edit().putString("subject_color", "11")
                                                                    .apply();
                                                        }
                                                    }
                                                }).show();
                                    }
                                });

                                android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(
                                        getActivity());
                                builder.setTitle(R.string.subjects_edit);
                                builder.setView(dialogView);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                Subject_DbAdapter db = new Subject_DbAdapter(getActivity());
                                                db.open();

                                                String inputTitle = titleInput.getText().toString().trim();
                                                String inputTeacher = teacherInput.getText().toString().trim();
                                                String inputRoom = roomInput.getText().toString().trim();

                                                db.update(Integer.parseInt(_id), inputTitle, inputTeacher,
                                                        sharedPref.getString("subject_color", ""), inputRoom,
                                                        subject_creation);
                                                dialog.dismiss();
                                                setSubjectsList();
                                                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 android.support.v7.app.AlertDialog dialog2 = builder.create();
                                dialog2.show();
                            }

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

                                LayoutInflater inflater = getActivity().getLayoutInflater();

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

                                titleInput = (EditText) dialogView.findViewById(R.id.subject_title_);
                                titleInput.setSelection(titleInput.getText().length());
                                titleInput.setText(subject_title);
                                teacherInput = (EditText) dialogView.findViewById(R.id.subject_teacher);
                                teacherInput.setText(subject_content);
                                roomInput = (EditText) dialogView.findViewById(R.id.subject_room);
                                roomInput.setText(subject_attachment);

                                helper_main.showKeyboard(getActivity(), titleInput);

                                final ImageButton be = (ImageButton) dialogView
                                        .findViewById(R.id.imageButtonPri);
                                Subjects_helper.switchIcon(getActivity(), subject_icon, "subject_color", be);

                                be.setOnClickListener(new View.OnClickListener() {

                                    @Override
                                    public void onClick(View arg0) {

                                        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 * getActivity().getResources()
                                                        .getDisplayMetrics().density + 0.5f);
                                                tv.setCompoundDrawablePadding(dp5);

                                                return v;
                                            }
                                        };

                                        new android.app.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) {
                                                            be.setImageResource(R.drawable.circle_red);
                                                            sharedPref.edit().putString("subject_color", "1")
                                                                    .apply();
                                                        } else if (item == 1) {
                                                            be.setImageResource(R.drawable.circle_pink);
                                                            sharedPref.edit().putString("subject_color", "2")
                                                                    .apply();
                                                        } else if (item == 2) {
                                                            be.setImageResource(R.drawable.circle_purple);
                                                            sharedPref.edit().putString("subject_color", "3")
                                                                    .apply();
                                                        } else if (item == 3) {
                                                            be.setImageResource(R.drawable.circle_blue);
                                                            sharedPref.edit().putString("subject_color", "4")
                                                                    .apply();
                                                        } else if (item == 4) {
                                                            be.setImageResource(R.drawable.circle_teal);
                                                            sharedPref.edit().putString("subject_color", "5")
                                                                    .apply();
                                                        } else if (item == 5) {
                                                            be.setImageResource(R.drawable.circle_green);
                                                            sharedPref.edit().putString("subject_color", "6")
                                                                    .apply();
                                                        } else if (item == 6) {
                                                            be.setImageResource(R.drawable.circle_lime);
                                                            sharedPref.edit().putString("subject_color", "7")
                                                                    .apply();
                                                        } else if (item == 7) {
                                                            be.setImageResource(R.drawable.circle_yellow);
                                                            sharedPref.edit().putString("subject_color", "8")
                                                                    .apply();
                                                        } else if (item == 8) {
                                                            be.setImageResource(R.drawable.circle_orange);
                                                            sharedPref.edit().putString("subject_color", "9")
                                                                    .apply();
                                                        } else if (item == 9) {
                                                            be.setImageResource(R.drawable.circle_brown);
                                                            sharedPref.edit().putString("subject_color", "10")
                                                                    .apply();
                                                        } else if (item == 10) {
                                                            be.setImageResource(R.drawable.circle_grey);
                                                            sharedPref.edit().putString("subject_color", "11")
                                                                    .apply();
                                                        }
                                                    }
                                                }).show();
                                    }
                                });

                                android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(
                                        getActivity());
                                builder.setTitle(R.string.subjects_edit);
                                builder.setView(dialogView);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                Subject_DbAdapter db = new Subject_DbAdapter(getActivity());
                                                db.open();

                                                String inputTitle = titleInput.getText().toString().trim();
                                                String inputTeacher = teacherInput.getText().toString().trim();
                                                String inputRoom = roomInput.getText().toString().trim();

                                                Date date = new Date();
                                                DateFormat dateFormat = new SimpleDateFormat(
                                                        "yy-MM-dd_HH-mm-ss", Locale.getDefault());
                                                String creation = dateFormat.format(date);

                                                if (db.isExist(creation)) {
                                                    Snackbar.make(titleInput,
                                                            getString(R.string.toast_newTitle),
                                                            Snackbar.LENGTH_LONG).show();
                                                } else {
                                                    db.insert(inputTitle, inputTeacher,
                                                            sharedPref.getString("subject_color", creation),
                                                            inputRoom, helper_main.createDate());
                                                    dialog.dismiss();
                                                    setSubjectsList();
                                                }

                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

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

                                final android.support.v7.app.AlertDialog dialog2 = builder.create();
                                dialog2.show();
                            }

                            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));
                                                setSubjectsList();
                                            }
                                        });
                                snackbar.show();
                            }

                        }
                    }).show();

            return true;
        }
    });
}

From source file:org.nla.tarotdroid.lib.ui.GameSetHistoryActivity.java

/**
 * Manage click on GameSet.//  w ww . j a  va 2 s .  c om
 * 
 * @param pos
 */
private void onListItemClick(final int pos) {
    final GameSet gameSet = (GameSet) getListAdapter().getItem(pos);

    final Item[] items = AppContext.getApplication().isAppLimited() ? limitedItems : allItems;

    ListAdapter adapter = new ArrayAdapter<Item>(this, android.R.layout.select_dialog_item, android.R.id.text1,
            items) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // User super class to create the View
            View v = super.getView(position, convertView, parent);
            TextView tv = (TextView) v.findViewById(android.R.id.text1);

            // Put the image on the TextView
            tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);

            // Add margin between image and text (support various screen
            // densities)
            int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
            tv.setCompoundDrawablePadding(dp5);

            return v;
        }
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(String.format(this.getString(R.string.lblGameSetHistoryActivityMenuTitle),
            new SimpleDateFormat("dd/MM/yy").format(gameSet.getCreationTs())));

    builder.setAdapter(adapter, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int itemIndex) {

            Item item = items[itemIndex];

            if (item.itemType == Item.ItemTypes.publishOnFacebook) {

                // check for active internet connexion first
                // see post
                // http://stackoverflow.com/questions/2789612/how-can-i-check-whether-an-android-device-is-connected-to-the-web
                ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
                        Context.CONNECTIVITY_SERVICE);
                NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

                if (networkInfo != null && networkInfo.isConnected()) {

                    if (gameSet.getGameCount() == 0) {
                        Toast.makeText(GameSetHistoryActivity.this,
                                R.string.lblFacebookImpossibleToPublishGamesetWithNoGame, Toast.LENGTH_SHORT)
                                .show();
                    }

                    else if (!AppContext.getApplication().getNotificationIds().isEmpty()) {
                        Toast.makeText(GameSetHistoryActivity.this, R.string.lblFacebookGamesetBeingPublished,
                                Toast.LENGTH_SHORT).show();
                    }

                    else {
                        tempGameSet = gameSet;

                        // // TODO Improve in later version
                        // ShortenUrlTask shortenUrlTask = new
                        // ShortenUrlTask(FacebookHelper.buildGameSetUrl(tempGameSet));
                        // shortenUrlTask.setCallback(urlShortenedCallback);
                        // shortenUrlTask.execute();

                        startPostProcess();
                    }
                } else {
                    Toast.makeText(GameSetHistoryActivity.this,
                            getString(R.string.titleInternetConnexionNecessary), Toast.LENGTH_LONG).show();
                }
            } else if (item.itemType == Item.ItemTypes.publishOnTwitter) {
                Toast.makeText(GameSetHistoryActivity.this, "TODO: Publish on twitter", Toast.LENGTH_LONG)
                        .show();

                Intent intent = new Intent(GameSetHistoryActivity.this, TwitterConnectActivity.class);
                startActivity(intent);
            } else if (item.itemType == Item.ItemTypes.remove) {
                RemoveGameSetDialogClickListener removeGameSetDialogClickListener = new RemoveGameSetDialogClickListener(
                        gameSet);
                AlertDialog.Builder builder = new AlertDialog.Builder(GameSetHistoryActivity.this);
                builder.setTitle(GameSetHistoryActivity.this.getString(R.string.titleRemoveGameSetYesNo));
                builder.setMessage(Html.fromHtml(
                        GameSetHistoryActivity.this.getText(R.string.msgRemoveGameSetYesNo).toString()));
                builder.setPositiveButton(GameSetHistoryActivity.this.getString(R.string.btnOk),
                        removeGameSetDialogClickListener);
                builder.setNegativeButton(GameSetHistoryActivity.this.getString(R.string.btnCancel),
                        removeGameSetDialogClickListener).show();
                builder.setIcon(android.R.drawable.ic_dialog_alert);
            } else if (item.itemType == Item.ItemTypes.transferOverBluetooth) {
                if (!GameSetHistoryActivity.this.bluetoothHelper.isBluetoothEnabled()) {
                    Toast.makeText(GameSetHistoryActivity.this,
                            GameSetHistoryActivity.this.getString(R.string.msgActivateBluetooth),
                            Toast.LENGTH_LONG).show();
                }

                try {
                    // make sure at least one device was discovered
                    if (GameSetHistoryActivity.this.bluetoothHelper.getBluetoothDeviceCount() == 0) {
                        Toast.makeText(GameSetHistoryActivity.this,
                                GameSetHistoryActivity.this.getString(R.string.msgRunDiscoverDevicesFirst),
                                Toast.LENGTH_LONG).show();
                    }

                    // display devices and download
                    final String[] items = GameSetHistoryActivity.this.bluetoothHelper
                            .getBluetoothDeviceNames();

                    AlertDialog.Builder builder = new AlertDialog.Builder(GameSetHistoryActivity.this);
                    builder.setTitle(GameSetHistoryActivity.this.getString(R.string.lblSelectBluetoothDevice));
                    builder.setItems(items, new BluetoothDeviceClickListener(gameSet, items));
                    AlertDialog alert = builder.create();
                    alert.show();
                } catch (Exception e) {
                    AuditHelper.auditError(ErrorTypes.gameSetHistoryActivityError, e,
                            GameSetHistoryActivity.this);
                }
            } else if (item.itemType == Item.ItemTypes.exportToExcel) {
                try {
                    if (!AppContext.getApplication().isAppLimited()) {

                        ExportToExcelTask task = new ExportToExcelTask(GameSetHistoryActivity.this,
                                progressDialog);
                        task.setCallback(excelExportCallback);
                        task.execute(gameSet);
                    }
                } catch (Exception e) {
                    Toast.makeText(
                            GameSetHistoryActivity.this, AppContext.getApplication().getResources()
                                    .getText(R.string.msgGameSetExportError).toString() + e.getMessage(),
                            Toast.LENGTH_LONG).show();
                    AuditHelper.auditError(ErrorTypes.excelFileStorage, e);
                }
            } else if (item.itemType == Item.ItemTypes.edit) {
                // SharedPreferences preferences =
                // PreferenceManager.getDefaultSharedPreferences(GameSetHistoryActivity.this);

                // set selected gameset as session gameset
                // AppContext.getApplication().getBizService().setGameSet(gameSet);

                // // Get non DAL stored parameters property from shared
                // preferences
                // UIHelper.fillNonComputationPreferences(gameSet.getGameSetParameters(),
                // preferences);

                // start tab gameset activity
                Intent intent = new Intent(GameSetHistoryActivity.this, TabGameSetActivity.class);
                intent.putExtra(ActivityParams.PARAM_GAMESET_ID, gameSet.getId());
                GameSetHistoryActivity.this.startActivityForResult(intent, RequestCodes.DISPLAY_WITH_FACEBOOK);
            }
        }
    });
    AlertDialog alert = builder.create();
    alert.show();

}

From source file:org.alfresco.mobile.android.application.fragments.properties.DetailsFragment.java

private void display(Node refreshedNode, LayoutInflater inflater) {
    node = refreshedNode;//  w ww .j  a va2s .co  m

    // Detect if restrictable
    isRestrictable = node.hasAspect(ContentModel.ASPECT_RESTRICTABLE);

    renditionManager = ApplicationManager.getInstance(getActivity()).getRenditionManager(getActivity());

    // Header
    TextView tv = (TextView) vRoot.findViewById(R.id.title);
    tv.setText(node.getName());
    tv = (TextView) vRoot.findViewById(R.id.details);
    tv.setText(Formatter.createContentBottomText(getActivity(), node, true));

    if (isRestrictable) {
        tv.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_encrypt, 0);
    }

    // Preview + Thumbnail
    displayIcon(node, R.drawable.mime_folder, (ImageView) vRoot.findViewById(R.id.icon), false);
    displayIcon(node, R.drawable.mime_256_folder, (ImageView) vRoot.findViewById(R.id.preview), true);

    // Description
    Integer generalPropertyTitle = null;
    tv = (TextView) vRoot.findViewById(R.id.description);
    List<String> filter = new ArrayList<String>();
    if (node.getDescription() != null && node.getDescription().length() > 0
            && vRoot.findViewById(R.id.description_group) != null) {
        vRoot.findViewById(R.id.description_group).setVisibility(View.VISIBLE);
        tv.setText(node.getDescription());
        generalPropertyTitle = -1;
        ((TextView) vRoot.findViewById(R.id.prop_name_value)).setText(node.getName());
        filter.add(ContentModel.PROP_NAME);
    } else if (vRoot.findViewById(R.id.description_group) != null) {
        vRoot.findViewById(R.id.description_group).setVisibility(View.GONE);
        generalPropertyTitle = R.string.metadata;
    }

    mTabHost = (TabHost) vRoot.findViewById(android.R.id.tabhost);
    setupTabs();

    if (mTabHost == null) {
        grouprootview = (ViewGroup) vRoot.findViewById(R.id.metadata);
        createPropertiesPanel(inflater, generalPropertyTitle, filter);
    }

    // BUTTONS
    ImageView b = (ImageView) vRoot.findViewById(R.id.action_openin);
    if (node.isDocument() && ((DocumentImpl) node).hasAllowableAction(Action.CAN_GET_CONTENT_STREAM.value())
            && ((Document) node).getContentStreamLength() > 0 && !isRestrictable) {
        b.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                openin();
            }
        });
    } else {
        b.setVisibility(View.GONE);
    }

    b = (ImageView) vRoot.findViewById(R.id.action_geolocation);
    if (node.isDocument() && node.hasAspect(ContentModel.ASPECT_GEOGRAPHIC)) {
        b.setVisibility(View.VISIBLE);
        b.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (node == null) {
                    return;
                }
                String latitude = (node.getProperty(ContentModel.PROP_LATITUDE).getValue() != null)
                        ? node.getProperty(ContentModel.PROP_LATITUDE).getValue().toString()
                        : "";
                String longitude = (node.getProperty(ContentModel.PROP_LONGITUDE).getValue() != null)
                        ? node.getProperty(ContentModel.PROP_LONGITUDE).getValue().toString()
                        : "";
                ActionManager.actionShowMap(DetailsFragment.this, node.getName(), latitude, longitude);
            }
        });
    } else {
        b.setVisibility(View.GONE);
    }

    b = (ImageView) vRoot.findViewById(R.id.like);
    if (alfSession != null && alfSession.getRepositoryInfo() != null
            && alfSession.getRepositoryInfo().getCapabilities() != null
            && alfSession.getRepositoryInfo().getCapabilities().doesSupportLikingNodes()) {
        IsLikedLoaderCallBack lcb = new IsLikedLoaderCallBack(alfSession, getActivity(), node);
        lcb.setImageButton(b);
        lcb.setProgressView(vRoot.findViewById(R.id.like_progress));
        lcb.execute(false);

        b.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                like(v);
            }
        });
    } else {
        b.setVisibility(View.GONE);
        if (vRoot.findViewById(R.id.like_progress) != null) {
            vRoot.findViewById(R.id.like_progress).setVisibility(View.GONE);
        }
    }

    // BUTTONS
    b = (ImageView) vRoot.findViewById(R.id.action_favorite);
    if (!isRestrictable) {
        IsFavoriteLoaderCallBack lcb = new IsFavoriteLoaderCallBack(alfSession, this, node);
        lcb.setImageButton(b);
        lcb.setProgressView(vRoot.findViewById(R.id.favorite_progress));
        lcb.execute(false);
        b.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                favorite(v);
            }
        });
    } else {
        b.setVisibility(View.GONE);
        vRoot.findViewById(R.id.favorite_progress).setVisibility(View.GONE);
    }

    b = (ImageView) vRoot.findViewById(R.id.action_share);
    if (node.isDocument() && !isRestrictable) {
        b.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                share();
            }
        });
    } else {
        b.setVisibility(View.GONE);
    }
}