Example usage for android.widget TextView setCompoundDrawablePadding

List of usage examples for android.widget TextView setCompoundDrawablePadding

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:de.baumann.hhsmoodle.data_notes.Notes_Fragment.java

public void setNotesList() {

    if (isFABOpen) {
        closeFABMenu();//  www  . j  a  va  2 s .c om
    }

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "note_title", "note_content", "note_creation" };
    final Cursor row = db.fetchAllData(getActivity());
    adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

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

            switch (note_attachment) {
            case "":
                iv_attachment.setVisibility(View.GONE);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.ic_attachment);
                break;
            }

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

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

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

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

                            return v;
                        }
                    };

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

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

                                public void onClick(DialogInterface dialog, int item) {
                                    if (item == 0) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "3",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "2",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "1",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    }
                                }
                            }).show();
                }
            });
            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    helper_main.openAtt(getActivity(), lv, note_attachment);
                }
            });
            return v;
        }
    };

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

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

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

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

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            final Button attachment;
            final TextView textInput;

            LayoutInflater inflater = getActivity().getLayoutInflater();

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

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

            attachment = (Button) dialogView.findViewById(R.id.button_att);
            if (attName.equals("")) {
                attachment.setVisibility(View.GONE);
            } else {
                attachment.setText(att);
            }

            textInput = (TextView) dialogView.findViewById(R.id.note_text_input);
            if (note_content.isEmpty()) {
                textInput.setVisibility(View.GONE);
            } else {
                textInput.setText(note_content);
                Linkify.addLinks(textInput, Linkify.WEB_URLS);
            }

            attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    helper_main.openAtt(getActivity(), textInput, note_attachment);
                }
            });

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

            File file2 = new File(note_attachment);
            if (!file2.exists()) {
                attachment.setVisibility(View.GONE);
                attImage.setVisibility(View.GONE);
            } else if (note_attachment.contains(".gif") || note_attachment.contains(".bmp")
                    || note_attachment.contains(".tiff") || note_attachment.contains(".png")
                    || note_attachment.contains(".jpg") || note_attachment.contains(".JPG")
                    || note_attachment.contains(".jpeg") || note_attachment.contains(".mpeg")
                    || note_attachment.contains(".mp4") || note_attachment.contains(".3gp")
                    || note_attachment.contains(".3g2") || note_attachment.contains(".avi")
                    || note_attachment.contains(".flv") || note_attachment.contains(".h261")
                    || note_attachment.contains(".h263") || note_attachment.contains(".h264")
                    || note_attachment.contains(".asf") || note_attachment.contains(".wmv")) {
                attImage.setVisibility(View.VISIBLE);

                try {
                    Glide.with(getActivity()).load(note_attachment) // or URI/path
                            .diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).into(attImage); //imageView to set thumbnail to
                } catch (Exception e) {
                    Log.w("HHS_Moodle", "Error load thumbnail", e);
                    attImage.setVisibility(View.GONE);
                }

                attImage.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        helper_main.openAtt(getActivity(), attImage, note_attachment);
                    }
                });
            }

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

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

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

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

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

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            final CharSequence[] options = { getString(R.string.number_edit_entry),
                    getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_share),
                    getString(R.string.todo_menu), getString(R.string.count_create),
                    getString(R.string.bookmark_createEvent) };
            new AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.number_edit_entry))) {
                                Notes_helper.newNote(getActivity(), note_title, note_content, note_icon,
                                        note_attachment, note_creation, _id);
                            }

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

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

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

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

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

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

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

            return true;
        }
    });
}

From source file:com.mk4droid.IMC_Activities.Fragment_Issue_Details.java

/**
 *    OnCreateView/* w  w  w  .java2 s  .  co m*/
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    isVisible = true;

    vfrag_issue_details = inflater.inflate(R.layout.fragment_issue_details, container, false);
    ctx = vfrag_issue_details.getContext();
    resources = setResources();
    mfrag_issue_details = this;

    //========= Image =================
    dbHandler = new DatabaseHandler(ctx);
    imvFull = (ImageView) vfrag_issue_details.findViewById(R.id.imvIssue_Full);

    IssuePic issuepic = dbHandler.getIssuePic(mIssue._id);

    if (issuepic._IssuePicData != null) {
        bmI = My_System_Utils.LowMemBitmapDecoder(issuepic._IssuePicData);
    } else {
        //------- Try to download from internet --------------  
        if (InternetConnCheck.getInstance(ctx).isOnline(ctx) && !mIssue._urlphoto.equals("null")
                && !mIssue._urlphoto.equals("") && mIssue._urlphoto.length() > 0) {

            mIssue._urlphoto = mIssue._urlphoto.replaceFirst("/thumbs", "");
            new ThumbnailTask_IssDetails(mIssue._urlphoto, mIssue._id).execute();
        }
    }

    dbHandler.db.close();

    imvFull.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dialogZoomIm = null;

            if (FActivity_TabHost.IndexGroup == 0)
                dialogZoomIm = new Dialog(ctx, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
            else if (FActivity_TabHost.IndexGroup == 1)
                dialogZoomIm = new Dialog(FActivity_TabHost.ctx,
                        android.R.style.Theme_Black_NoTitleBar_Fullscreen);

            dialogZoomIm.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialogZoomIm.setContentView(R.layout.custom_dialog);
            dialogZoomIm.show();
        }
    });

    // ============ Title and id =========
    tv_id = (TextView) vfrag_issue_details.findViewById(R.id.tv_issuenumber);
    TextView tvTitB = (TextView) vfrag_issue_details.findViewById(R.id.tvTitleIssDetB);

    tv_id.setText(Html.fromHtml("<b><big>#</big></b> " + issueId));
    tv_id.setMovementMethod(new ScrollingMovementMethod());

    tvTitB.setText(mIssue._title);

    //=============== Description ======================
    tvDescription = (TextView) vfrag_issue_details.findViewById(R.id.textViewDescription);
    if (!mIssue._description.equals(""))
        tvDescription.setText(mIssue._description);
    else {
        tvDescription.setVisibility(View.GONE);
    }

    // ============== CATEGORY ===============================
    TextView tvCateg = (TextView) vfrag_issue_details.findViewById(R.id.textViewCategContent);

    int iCateg = 0;
    for (int i = 0; i < Service_Data.mCategL.size(); i++)
        if (Service_Data.mCategL.get(i)._id == mIssue._catid) {
            iCateg = i;
            break;
        }

    tvCateg.setText(Service_Data.mCategL.get(iCateg)._name);

    try {
        bmCateg = My_System_Utils.LowMemBitmapDecoder(Service_Data.mCategL.get(iCateg)._icon);
        BitmapDrawable drCateg = new BitmapDrawable(bmCateg);

        tvCateg.setCompoundDrawablesWithIntrinsicBounds(drCateg, null, null, null);
        tvCateg.setCompoundDrawablePadding(10);
        tvCateg.postInvalidate();
    } catch (Exception e) {

    }

    markerOptions = new MarkerOptions().position(new LatLng(mIssue._latitude, mIssue._longitude))
            .title(mIssue._title).icon(BitmapDescriptorFactory.fromBitmap(bmCateg));

    //================  STATUS ================      
    tvStatus_ack = (TextView) vfrag_issue_details.findViewById(R.id.tv_Status_issuedetails_ack);
    tvStatus_cl = (TextView) vfrag_issue_details.findViewById(R.id.tv_Status_issuedetails_cl);

    vStatus_ack = vfrag_issue_details.findViewById(R.id.v_Status_issuedetails_acknow);
    vStatus_cl = vfrag_issue_details.findViewById(R.id.v_Status_issuedetails_cl);

    int CurrStat = mIssue._currentstatus;

    Colora(CurrStat);

    // ============== Time and Author ================
    TextView tvSubmitted = (TextView) vfrag_issue_details.findViewById(R.id.tvSubmitted);

    String TimeStampRep = mIssue._reported.replace("-", "/");

    tvSubmitted.setText(resources.getString(R.string.Submitted) + " "
            + My_Date_Utils.SubtractDate(TimeStampRep, LangSTR) + " " + resources.getString(R.string.ago) + " "
            + resources.getString(R.string.by) + " " + mIssue._username);

    //============== Votes========================
    TextView tvVotes = (TextView) vfrag_issue_details.findViewById(R.id.textViewVotes);
    tvVotes.setText(Integer.toString(mIssue._votes) + " " + resources.getString(R.string.peoplevoted));

    Button btVote = (Button) vfrag_issue_details.findViewById(R.id.buttonVote);
    //-------- Check if state is Ack or Closed then can not vote ----
    if (CurrStat == 2 || CurrStat == 3)
        btVote.setEnabled(false);

    //-------- Check if Has Voted ----------
    DatabaseHandler dbHandler = new DatabaseHandler(ctx);
    HasVotedSW = dbHandler.CheckIfHasVoted(issueId);

    OwnIssue = false;
    if (UserID_STR.length() > 0)
        OwnIssue = dbHandler.checkIfOwnIssue(Integer.toString(issueId), UserID_STR);

    dbHandler.db.close();

    // if has not voted, it is not his issue, and authenticated then able to vote 
    if (!OwnIssue && !HasVotedSW && AuthFlag) {
        btVote.setEnabled(true);
    }

    if (OwnIssue || HasVotedSW) {
        btVote.setEnabled(false);
        btVote.setText(resources.getString(R.string.AlreadyVoted));
    }

    if (!AuthFlag) {
        btVote.setText(resources.getString(R.string.Vote));
    }

    btVote.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            if (InternetConnCheck.getInstance(ctx).isOnline(ctx) && AuthFlag) {
                new AsynchTaskVote().execute();
            } else if (!InternetConnCheck.getInstance(ctx).isOnline(ctx)) {
                Toast.makeText(ctx, resources.getString(R.string.NoInternet), Toast.LENGTH_SHORT).show();
            } else if (!AuthFlag) {
                Toast.makeText(ctx, resources.getString(R.string.OnlyRegistered), Toast.LENGTH_SHORT).show();
            }
        }
    });

    //============ Address - MapStatic - Button Map dynamic ========================
    TextView tvAddr = (TextView) vfrag_issue_details.findViewById(R.id.textViewAddressContent);
    tvAddr.setText(mIssue._address);

    fmap_issdet = SupportMapFragment.newInstance();

    FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
    fragmentTransaction.add(R.id.lliss_det_map, fmap_issdet);
    fragmentTransaction.commit();

    // ============ COMMENTS ===========================
    Button btCommentsSW = (Button) vfrag_issue_details.findViewById(R.id.btCommentsSW);

    btCommentsSW.setText(resources.getString(R.string.ViewComments));

    btCommentsSW.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (InternetConnCheck.getInstance(ctx).isOnline(ctx)) {
                FragmentTransaction ft2 = getFragmentManager().beginTransaction();

                Fragment_Comments newfrag_comments = new Fragment_Comments(); // Instantiate a new fragment.
                Bundle args = new Bundle();
                args.putInt("issueId", issueId);
                args.putString("issueTitle", mIssue._title);
                newfrag_comments.setArguments(args); // Add the fragment to the activity, pushing this transaction on to the back stack.

                if (FActivity_TabHost.IndexGroup == 0)
                    ft2.add(R.id.flmain, newfrag_comments, "FTAG_COMMENTS");
                else if (FActivity_TabHost.IndexGroup == 1) {
                    ft2.add(R.id.fl_IssuesList_container, newfrag_comments, "FTAG_COMMENTS");
                }

                ft2.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                ft2.addToBackStack(null);
                ft2.commit();
            } else {
                Toast.makeText(ctx, resources.getString(R.string.NoInternet), Toast.LENGTH_SHORT).show();
            }
        }
    });

    return vfrag_issue_details;
}

From source file:de.bahnhoefe.deutschlands.bahnhofsfotos.DetailsActivity.java

private void startNavigation(final Context context) {
    final NavItem[] items = {
            new NavItem("   " + getString(R.string.nav_oepnv), R.drawable.ic_directions_bus_gray_24px),
            new NavItem("   " + getString(R.string.nav_car), R.drawable.ic_directions_car_gray_24px),
            new NavItem("   " + getString(R.string.nav_bike), R.drawable.ic_directions_bike_gray_24px),
            new NavItem("   " + getString(R.string.nav_walk), R.drawable.ic_directions_walk_gray_24px),
            new NavItem("   " + getString(R.string.nav_show), R.drawable.ic_info_gray_24px) };

    ListAdapter adapter = new ArrayAdapter<NavItem>(this, android.R.layout.select_dialog_item,
            android.R.id.text1, items) {
        public View getView(int position, View convertView, 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);

            //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);
            int dp7 = (int) (20 * getResources().getDisplayMetrics().density);
            tv.setCompoundDrawablePadding(dp5);
            tv.setPadding(dp7, 0, 0, 0);

            return v;
        }/*  ww w  . j a v  a2 s.  co  m*/
    };

    AlertDialog.Builder navBuilder = new AlertDialog.Builder(this);
    navBuilder.setIcon(R.mipmap.ic_launcher);
    navBuilder.setTitle(R.string.navMethod);
    navBuilder.setAdapter(adapter, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int navItem) {
            String dlocation = "";
            Intent intent = null;
            switch (navItem) {
            case 0:
                dlocation = String.format("google.navigation:ll=%s,%s&mode=Transit", bahnhof.getLat(),
                        bahnhof.getLon());
                Log.d("findnavigation case 0", dlocation);
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation));
                break;
            case 1:
                dlocation = String.format("google.navigation:ll=%s,%s&mode=d", bahnhof.getLat(),
                        bahnhof.getLon());
                Log.d("findnavigation case 1", dlocation);
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation));
                break;

            case 2:
                dlocation = String.format("google.navigation:ll=%s,%s&mode=b", bahnhof.getLat(),
                        bahnhof.getLon());
                Log.d("findnavigation case 2", dlocation);
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation));
                break;
            case 3:
                dlocation = String.format("google.navigation:ll=%s,%s&mode=w", bahnhof.getLat(),
                        bahnhof.getLon());
                Log.d("findnavigation case 3", dlocation);
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation));
                break;
            case 4:
                dlocation = String.format("geo:0,0?q=%s,%s(%s)", bahnhof.getLat(), bahnhof.getLon(),
                        bahnhof.getTitle());
                Log.d("findnavigation case 4", dlocation);
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation));
                break;

            }
            try {
                startActivity(intent);
            } catch (Exception e) {
                Toast toast = Toast.makeText(context, R.string.activitynotfound, Toast.LENGTH_LONG);
                toast.show();
            }
        }
    }).show();

}

From source file:de.baumann.hhsmoodle.data_bookmarks.Bookmarks_Fragment.java

public void setBookmarksList() {

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "bookmarks_title", "bookmarks_content", "bookmarks_creation" };
    final Cursor row = db.fetchAllData(getActivity());
    adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override/*w w  w  . jav a  2s.c om*/
        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 bookmarks_title = row.getString(row.getColumnIndexOrThrow("bookmarks_title"));
            final String bookmarks_content = row.getString(row.getColumnIndexOrThrow("bookmarks_content"));
            final String bookmarks_icon = row.getString(row.getColumnIndexOrThrow("bookmarks_icon"));
            final String bookmarks_attachment = row
                    .getString(row.getColumnIndexOrThrow("bookmarks_attachment"));
            final String bookmarks_creation = row.getString(row.getColumnIndexOrThrow("bookmarks_creation"));

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

            switch (bookmarks_icon) {
            case "01":
                iv_icon.setImageResource(R.drawable.circle_red);
                break;
            case "02":
                iv_icon.setImageResource(R.drawable.circle_yellow);
                break;
            case "03":
                iv_icon.setImageResource(R.drawable.circle_green);
                break;
            case "04":
                iv_icon.setImageResource(R.drawable.ic_school_grey600_48dp);
                break;
            case "05":
                iv_icon.setImageResource(R.drawable.ic_view_dashboard_grey600_48dp);
                break;
            case "06":
                iv_icon.setImageResource(R.drawable.ic_face_profile_grey600_48dp);
                break;
            case "07":
                iv_icon.setImageResource(R.drawable.ic_calendar_grey600_48dp);
                break;
            case "08":
                iv_icon.setImageResource(R.drawable.ic_chart_areaspline_grey600_48dp);
                break;
            case "09":
                iv_icon.setImageResource(R.drawable.ic_bell_grey600_48dp);
                break;
            case "10":
                iv_icon.setImageResource(R.drawable.ic_settings_grey600_48dp);
                break;
            case "11":
                iv_icon.setImageResource(R.drawable.ic_web_grey600_48dp);
                break;
            case "12":
                iv_icon.setImageResource(R.drawable.ic_magnify_grey600_48dp);
                break;
            case "13":
                iv_icon.setImageResource(R.drawable.ic_pencil_grey600_48dp);
                break;
            case "14":
                iv_icon.setImageResource(R.drawable.ic_check_grey600_48dp);
                break;
            case "15":
                iv_icon.setImageResource(R.drawable.ic_clock_grey600_48dp);
                break;
            case "16":
                iv_icon.setImageResource(R.drawable.ic_bookmark_grey600_48dp);
                break;
            }

            switch (bookmarks_attachment) {
            case "":
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.star_outline);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.star_grey);
                break;
            }

            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    if (bookmarks_attachment.equals("")) {

                        if (db.isExistFav("true")) {
                            Snackbar.make(lv, R.string.bookmark_setFav_not, Snackbar.LENGTH_LONG).show();
                        } else {
                            iv_attachment.setImageResource(R.drawable.star_grey);
                            db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, bookmarks_icon,
                                    "true", bookmarks_creation);
                            setBookmarksList();
                            sharedPref.edit().putString("favoriteURL", bookmarks_content)
                                    .putString("favoriteTitle", bookmarks_title).apply();
                            Snackbar.make(lv, R.string.bookmark_setFav, Snackbar.LENGTH_LONG).show();
                        }
                    } else {
                        iv_attachment.setImageResource(R.drawable.star_outline);
                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, bookmarks_icon, "",
                                bookmarks_creation);
                        setBookmarksList();
                    }
                }
            });

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    final helper_main.Item[] items = {
                            new helper_main.Item(getString(R.string.note_priority_2), R.drawable.circle_red),
                            new helper_main.Item(getString(R.string.note_priority_1), R.drawable.circle_yellow),
                            new helper_main.Item(getString(R.string.note_priority_0), R.drawable.circle_green),
                            new helper_main.Item(getString(R.string.text_tit_11),
                                    R.drawable.ic_school_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_1),
                                    R.drawable.ic_view_dashboard_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_2),
                                    R.drawable.ic_face_profile_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_8),
                                    R.drawable.ic_calendar_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_3),
                                    R.drawable.ic_chart_areaspline_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_4),
                                    R.drawable.ic_bell_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_5),
                                    R.drawable.ic_settings_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_6),
                                    R.drawable.ic_web_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_7),
                                    R.drawable.ic_magnify_grey600_48dp),
                            new helper_main.Item(getString(R.string.title_notes),
                                    R.drawable.ic_pencil_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_9),
                                    R.drawable.ic_check_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_10),
                                    R.drawable.ic_clock_grey600_48dp),
                            new helper_main.Item(getString(R.string.title_bookmarks),
                                    R.drawable.ic_bookmark_grey600_48dp), };

                    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), bookmarks_title, bookmarks_content,
                                                "01", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "02", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "03", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 3) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "04", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 4) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "05", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 5) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "06", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 6) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "07", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 7) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "08", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 8) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "09", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 9) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "10", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 10) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "11", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 11) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "12", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 12) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "13", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 13) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "14", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 14) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "15", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 15) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "16", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    }
                                }
                            }).show();
                }
            });
            return v;
        }
    };

    //display data by filter
    final String note_search = sharedPref.getString("filter_bookmarksBY", "bookmarks_title");
    sharedPref.edit().putString("filter_bookmarksBY", "bookmarks_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 bookmarks_content = row2.getString(row2.getColumnIndexOrThrow("bookmarks_content"));
            sharedPref.edit().putString("load_next", "true").apply();
            sharedPref.edit().putString("loadURL", bookmarks_content).apply();

            ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager);
            viewPager.setCurrentItem(0);

        }
    });

    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 bookmarks_title = row2.getString(row2.getColumnIndexOrThrow("bookmarks_title"));
            final String bookmarks_content = row2.getString(row2.getColumnIndexOrThrow("bookmarks_content"));
            final String bookmarks_icon = row2.getString(row2.getColumnIndexOrThrow("bookmarks_icon"));
            final String bookmarks_attachment = row2
                    .getString(row2.getColumnIndexOrThrow("bookmarks_attachment"));
            final String bookmarks_creation = row2.getString(row2.getColumnIndexOrThrow("bookmarks_creation"));

            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_createShortcut), 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))) {

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

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

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

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                                String inputTag = edit_title.getText().toString().trim();
                                                db.update(Integer.parseInt(_id), inputTag, bookmarks_content,
                                                        bookmarks_icon, bookmarks_attachment,
                                                        bookmarks_creation);
                                                setBookmarksList();
                                                Snackbar.make(lv, R.string.bookmark_added,
                                                        Snackbar.LENGTH_SHORT).show();
                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

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

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

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

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

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

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

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

                            if (options[item].equals(getString(R.string.bookmark_createShortcut))) {
                                Intent i = new Intent();
                                i.setAction(Intent.ACTION_VIEW);
                                i.setData(Uri.parse(bookmarks_content));

                                Intent shortcut = new Intent();
                                shortcut.putExtra("android.intent.extra.shortcut.INTENT", i);
                                shortcut.putExtra("android.intent.extra.shortcut.NAME",
                                        "THE NAME OF SHORTCUT TO BE SHOWN");
                                shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, bookmarks_title);
                                shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                                        Intent.ShortcutIconResource.fromContext(
                                                getActivity().getApplicationContext(), R.mipmap.ic_launcher));
                                shortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
                                getActivity().sendBroadcast(shortcut);
                                Snackbar.make(lv, R.string.toast_shortcut, Snackbar.LENGTH_LONG).show();
                            }

                        }
                    }).show();

            return true;
        }
    });
}

From source file:de.baumann.quitsmoking.fragments.FragmentNotes.java

private void setNotesList() {

    ArrayList<HashMap<String, String>> mapList = new ArrayList<>();

    try {//www.  ja va  2s  .  c  o  m
        Database_Notes db = new Database_Notes(getActivity());
        ArrayList<String[]> bookmarkList = new ArrayList<>();
        db.getBookmarks(bookmarkList, getActivity());
        if (bookmarkList.size() == 0) {
            db.loadInitialData();
            db.getBookmarks(bookmarkList, getActivity());
        }
        db.close();

        for (String[] strAry : bookmarkList) {
            HashMap<String, String> map = new HashMap<>();
            map.put("seqno", strAry[0]);
            map.put("title", strAry[1]);
            map.put("cont", strAry[2]);
            map.put("icon", strAry[3]);
            map.put("attachment", strAry[4]);
            map.put("createDate", strAry[5]);
            mapList.add(map);
        }

        SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), mapList, R.layout.list_item_notes,
                new String[] { "title", "cont", "createDate" },
                new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes }) {
            @Override
            public View getView(final int position, View convertView, ViewGroup parent) {

                @SuppressWarnings("unchecked")
                HashMap<String, String> map = (HashMap<String, String>) listView.getItemAtPosition(position);
                final String title = map.get("title");
                final String cont = map.get("cont");
                final String seqnoStr = map.get("seqno");
                final String icon = map.get("icon");
                final String attachment = map.get("attachment");
                final String create = map.get("createDate");

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

                switch (icon) {
                case "1":
                    i.setImageResource(R.drawable.emoticon_neutral);
                    break;
                case "2":
                    i.setImageResource(R.drawable.emoticon_happy);
                    break;
                case "3":
                    i.setImageResource(R.drawable.emoticon_sad);
                    break;
                case "4":
                    i.setImageResource(R.drawable.emoticon);
                    break;
                case "5":
                    i.setImageResource(R.drawable.emoticon_cool);
                    break;
                case "6":
                    i.setImageResource(R.drawable.emoticon_dead);
                    break;
                case "7":
                    i.setImageResource(R.drawable.emoticon_excited);
                    break;
                case "8":
                    i.setImageResource(R.drawable.emoticon_tongue);
                    break;
                case "9":
                    i.setImageResource(R.drawable.emoticon_devil);
                    break;
                }
                switch (attachment) {
                case "":
                    i2.setVisibility(View.GONE);
                    break;
                default:
                    i2.setVisibility(View.VISIBLE);
                    break;
                }

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

                i.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View arg0) {

                        final FragmentNotes.Item[] items = {
                                new FragmentNotes.Item(getString(R.string.text_tit_1),
                                        R.drawable.emoticon_neutral),
                                new FragmentNotes.Item(getString(R.string.text_tit_2),
                                        R.drawable.emoticon_happy),
                                new FragmentNotes.Item(getString(R.string.text_tit_3), R.drawable.emoticon_sad),
                                new FragmentNotes.Item(getString(R.string.text_tit_4), R.drawable.emoticon),
                                new FragmentNotes.Item(getString(R.string.text_tit_5),
                                        R.drawable.emoticon_cool),
                                new FragmentNotes.Item(getString(R.string.text_tit_6),
                                        R.drawable.emoticon_dead),
                                new FragmentNotes.Item(getString(R.string.text_tit_7),
                                        R.drawable.emoticon_excited),
                                new FragmentNotes.Item(getString(R.string.text_tit_8),
                                        R.drawable.emoticon_tongue),
                                new FragmentNotes.Item(getString(R.string.text_tit_9),
                                        R.drawable.emoticon_devil) };

                        ListAdapter adapter = new ArrayAdapter<FragmentNotes.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.goal_cancel, new DialogInterface.OnClickListener() {

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

                                    public void onClick(DialogInterface dialog, int item) {
                                        if (item == 0) {
                                            changeIcon(seqnoStr, title, cont, "1", attachment, create);
                                        } else if (item == 1) {
                                            changeIcon(seqnoStr, title, cont, "2", attachment, create);
                                        } else if (item == 2) {
                                            changeIcon(seqnoStr, title, cont, "3", attachment, create);
                                        } else if (item == 3) {
                                            changeIcon(seqnoStr, title, cont, "4", attachment, create);
                                        } else if (item == 4) {
                                            changeIcon(seqnoStr, title, cont, "5", attachment, create);
                                        } else if (item == 5) {
                                            changeIcon(seqnoStr, title, cont, "6", attachment, create);
                                        } else if (item == 6) {
                                            changeIcon(seqnoStr, title, cont, "7", attachment, create);
                                        } else if (item == 7) {
                                            changeIcon(seqnoStr, title, cont, "8", attachment, create);
                                        } else if (item == 8) {
                                            changeIcon(seqnoStr, title, cont, "9", attachment, create);
                                        } else if (item == 9) {
                                            changeIcon(seqnoStr, title, cont, "10", attachment, create);
                                        }
                                    }
                                }).show();
                    }
                });
                i2.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        openAtt(attachment);
                    }
                });

                return v;
            }
        };

        listView.setAdapter(simpleAdapter);

    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_screen_notes, container, false);

    PreferenceManager.setDefaultValues(getActivity(), R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());

    ImageView imgHeader = (ImageView) rootView.findViewById(R.id.imageView_header);
    helper_main.setImageHeader(getActivity(), imgHeader);

    RelativeLayout filter_layout = (RelativeLayout) rootView.findViewById(R.id.filter_layout);
    filter_layout.setVisibility(View.GONE);
    lv = (ListView) rootView.findViewById(R.id.listNotes);
    viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager);

    FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override/*from   w w w  .  j a  v a  2  s  . c  o  m*/
        public void onClick(View view) {
            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("");
            teacherInput = (EditText) dialogView.findViewById(R.id.subject_teacher);
            teacherInput.setText("");
            roomInput = (EditText) dialogView.findViewById(R.id.subject_room);
            roomInput.setText("");

            helper_main.showKeyboard(getActivity(), titleInput);

            final ImageButton be = (ImageButton) dialogView.findViewById(R.id.imageButtonPri);
            assert be != null;
            be.setImageResource(R.drawable.circle_grey);
            sharedPref.edit().putString("subject_color", "11").apply();

            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("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", ""),
                                inputRoom, creation);
                        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();
        }
    });

    //calling Notes_DbAdapter
    db = new Subject_DbAdapter(getActivity());
    db.open();

    setSubjectsList();
    setHasOptionsMenu(true);

    return rootView;
}

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;//www  .ja v  a  2s . c  om
    }
    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.geekandroid.sdk.base.BaseFragment.java

public void setDrawablePosition(TextView textView, int left, int top, int right, int bottom) {
    Drawable drawableTop = null;/*from  w  ww .j av a2 s.  c om*/
    Drawable drawableLeft = null;
    Drawable drawableRight = null;
    Drawable drawableBottom = null;

    if (top != 0) {
        drawableTop = getResources().getDrawable(top);
    }
    if (left != 0) {
        drawableLeft = getResources().getDrawable(left);
    }
    if (right != 0) {
        drawableRight = getResources().getDrawable(right);
    }
    if (bottom != 0) {
        drawableBottom = getResources().getDrawable(bottom);
    }
    /// ??,??.
    if (drawableTop != null) {
        drawableTop.setBounds(0, 0, drawableTop.getMinimumWidth(), drawableTop.getMinimumHeight());
    }

    if (drawableLeft != null) {
        int result = convertDp(60);
        drawableLeft.setBounds(0, 0, result, result);
        //            drawableLeft.setBounds(0, 0, drawableLeft.getMinimumWidth(), drawableLeft.getMinimumHeight());
    }
    if (drawableRight != null) {
        int result = convertDp(50);
        drawableRight.setBounds(0, 0, result, result);
        //            drawableRight.setBounds(0, 0, drawableRight.getMinimumWidth(), drawableRight.getMinimumHeight());
    }
    if (drawableBottom != null) {
        drawableBottom.setBounds(0, 0, drawableBottom.getMinimumWidth(), drawableBottom.getMinimumHeight());
    }
    int result = convertDp(10);
    textView.setCompoundDrawablePadding(result);
    textView.setCompoundDrawables(drawableLeft, drawableTop, drawableRight, drawableBottom);
}

From source file:de.baumann.hhsmoodle.data_courses.Courses_Fragment.java

private void setCoursesList() {

    if (isFABOpen) {
        closeFABMenu();/*from ww  w  .  j av a  2s.c om*/
    }

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "courses_title", "courses_content", "courses_creation" };
    final Cursor row = db.fetchAllData();
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

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

            return v;
        }
    };

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

            if (isFABOpen) {
                closeFABMenu();
            }

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

            final CharSequence[] options = { getString(R.string.courseList_todo),
                    getString(R.string.courseList_note), getString(R.string.courseList_random),
                    getString(R.string.courseList_subject), getString(R.string.bookmark_createEvent) };

            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.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(courses_title);

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

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

                                                String inputTitle = edit_title.getText().toString().trim();
                                                String inputCont = edit_cont.getText().toString().trim();

                                                if (db.isExist(inputTitle)) {
                                                    Snackbar.make(edit_title,
                                                            getString(R.string.toast_newTitle),
                                                            Snackbar.LENGTH_LONG).show();
                                                } else {
                                                    db.insert(inputTitle, inputCont, "", "",
                                                            helper_main.createDate());
                                                    dialog2.dismiss();
                                                }
                                            }
                                        });
                                helper_main.showKeyboard(getActivity(), edit_title);
                            }

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

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

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

                                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("");
                                teacherInput = (EditText) dialogView.findViewById(R.id.subject_teacher);
                                teacherInput.setText(courses_title);
                                roomInput = (EditText) dialogView.findViewById(R.id.subject_room);
                                roomInput.setText("");
                                helper_main.showKeyboard(getActivity(), titleInput);

                                final ImageButton be = (ImageButton) dialogView
                                        .findViewById(R.id.imageButtonPri);
                                assert be != null;
                                be.setImageResource(R.drawable.circle_grey);
                                sharedPref.edit().putString("subject_color", "11").apply();

                                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("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(inputTitle)) {
                                                    Snackbar.make(titleInput,
                                                            getString(R.string.toast_newTitle),
                                                            Snackbar.LENGTH_LONG).show();
                                                } else {
                                                    db.insert(inputTitle, inputTeacher,
                                                            sharedPref.getString("subject_color", ""),
                                                            inputRoom, creation);
                                                    dialog.dismiss();
                                                }

                                            }
                                        });
                                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_createEvent))) {
                                helper_main.createCalendarEvent(getActivity(), courses_title, courses_content);
                            }

                        }
                    }).show();
        }
    });

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

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String courses_title = row2.getString(row2.getColumnIndexOrThrow("courses_title"));
            final String courses_content = row2.getString(row2.getColumnIndexOrThrow("courses_content"));
            final String courses_icon = row2.getString(row2.getColumnIndexOrThrow("courses_icon"));
            final String courses_attachment = row2.getString(row2.getColumnIndexOrThrow("courses_attachment"));
            final String courses_creation = row2.getString(row2.getColumnIndexOrThrow("courses_creation"));

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

                                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(courses_title);

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

                                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) {

                                                String inputTitle = edit_title.getText().toString().trim();
                                                String inputCont = edit_cont.getText().toString().trim();
                                                db.update(Integer.parseInt(_id), inputTitle, inputCont,
                                                        courses_icon, courses_attachment, courses_creation);
                                                setCoursesList();
                                                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.app.AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();
                                helper_main.showKeyboard(getActivity(), edit_title);
                            }

                            if (options[item].equals(getString(R.string.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));
                                                setCoursesList();
                                            }
                                        });
                                snackbar.show();
                            }

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

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  w w w .  j av  a2s .  c om
    }

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

}