Example usage for android.widget ImageView setOnClickListener

List of usage examples for android.widget ImageView setOnClickListener

Introduction

In this page you can find the example usage for android.widget ImageView setOnClickListener.

Prototype

public void setOnClickListener(@Nullable OnClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked.

Usage

From source file:com.android.launcher3.Utilities.java

public static void showEditMode(final Activity activity, final ShortcutInfo shortcutInfo) {
    ContextThemeWrapper theme;/*from  w ww.  j  a  va  2s.  c om*/
    final Set<String> setString = new HashSet<String>();
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
        theme = new ContextThemeWrapper(activity, R.style.AlertDialogCustomAPI23);
    } else {
        theme = new ContextThemeWrapper(activity, R.style.AlertDialogCustom);
    }

    AlertDialog.Builder alert = new AlertDialog.Builder(theme);
    LinearLayout layout = new LinearLayout(activity.getApplicationContext());
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setPadding(100, 0, 100, 100);

    final ImageView img = new ImageView(activity.getApplicationContext());
    Drawable icon = null;
    if (Utilities.getAppIconPackageNamePrefEnabled(activity.getApplicationContext()) != null) {
        if (Utilities.getAppIconPackageNamePrefEnabled(activity.getApplicationContext()).equals("NULL")) {
            if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(),
                    shortcutInfo.getTargetComponent().getPackageName()) != null) {
                icon = new BitmapDrawable(activity.getResources(),
                        Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName()));
            } else {
                icon = new BitmapDrawable(activity.getResources(),
                        shortcutInfo.getIcon(new IconCache(activity.getApplicationContext(),
                                Launcher.getLauncher(activity).getDeviceProfile().inv)));
            }
        } else {

            if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(),
                    shortcutInfo.getTargetComponent().getPackageName()) != null) {
                icon = new BitmapDrawable(activity.getResources(),
                        Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName()));
            } else {
                icon = new BitmapDrawable(activity.getResources(),
                        Launcher.getIcons().get(shortcutInfo.getTargetComponent().getPackageName()));
            }
        }
    } else {

        if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(),
                shortcutInfo.getTargetComponent().getPackageName()) != null) {
            icon = new BitmapDrawable(activity.getResources(),
                    Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName()));
        } else {
            icon = new BitmapDrawable(activity.getResources(),
                    shortcutInfo.getIcon(new IconCache(activity.getApplicationContext(),
                            Launcher.getLauncher(Launcher.getLauncherActivity()).getDeviceProfile().inv)));
        }
    }
    img.setImageDrawable(icon);
    img.setPadding(0, 100, 0, 0);

    img.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showIconPack(activity, shortcutInfo);
        }
    });

    final EditText titleBox = new EditText(activity.getApplicationContext());

    try {
        Set<String> title = new HashSet<>(
                Utilities.getTitle(activity, shortcutInfo.getTargetComponent().getPackageName()));
        for (Iterator<String> it = title.iterator(); it.hasNext();) {
            String titleApp = it.next();
            titleBox.setText(titleApp);
        }
    } catch (Exception e) {
        titleBox.setText(shortcutInfo.title);
    }

    titleBox.getBackground().mutate().setColorFilter(
            ContextCompat.getColor(activity.getApplicationContext(), R.color.colorPrimary),
            PorterDuff.Mode.SRC_ATOP);

    layout.addView(img);
    layout.addView(titleBox);

    alert.setTitle(activity.getApplicationContext().getResources().getString(R.string.edit_label));
    alert.setView(layout);

    alert.setPositiveButton(activity.getApplicationContext().getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    for (ItemInfo itemInfo : AllAppsList.data) {
                        if (shortcutInfo.getTargetComponent().getPackageName()
                                .equals(itemInfo.getTargetComponent().getPackageName())) {
                            setString.add(titleBox.getText().toString());
                            getPrefs(activity.getApplicationContext()).edit()
                                    .putStringSet(itemInfo.getTargetComponent().getPackageName(), setString)
                                    .apply();
                            Launcher.getShortcutsCreation().clearAllLayout();
                            applyChange(activity);
                        }
                    }
                }
            });

    alert.setNegativeButton(activity.getApplicationContext().getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    Launcher.getShortcutsCreation().clearAllLayout();
                }
            });
    alert.show();
}

From source file:com.haomee.chat.activity.ChatActivity.java

/**
 * /*from   w  ww.jav  a2  s  . co m*/
 */
private void init_new_emotions(final String path) {
    File file = new File(emotions_base_path);
    File[] files = file.listFiles();// ?
    for (File f : files) {
        if (path == null) {
            return;
        }
        if (f == null) {
            return;
        }
        if (!file.exists() || !file.isDirectory()) {
            return;
        }
        // if (f.listFiles().length == 0) {
        // return;
        // }
        if (path.equals(f.getName())) {// ??
            File[] file_image_list = f.listFiles();
            image_path = new ArrayList<String>();
            image_name = new ArrayList<String>();
            if (file_image_list == null) {
                return;
            }
            for (int j = 0; j < file_image_list.length; j++) {
                File file_image = file_image_list[j];
                try {
                    String newFileName = new String(file_image.getName().getBytes(), "UTF-8");
                    if (newFileName.contains(big_cover_name) || newFileName.contains(simall_cover_name)) {
                        // 
                        final ImageView iv_bottom_emotion = new ImageView(ChatActivity.this);
                        Bitmap decodeFile = BitmapFactory.decodeFile(file_image.getAbsolutePath());
                        iv_bottom_emotion.setImageBitmap(decodeFile);
                        int screen_width = ViewUtil.getScreenWidth(ChatActivity.this);
                        layoutParams.width = screen_width / 8;
                        layoutParams.height = screen_width / 8;
                        iv_bottom_emotion.setLayoutParams(layoutParams);
                        iv_bottom_emotion.setBackgroundResource(R.drawable.grid_line);
                        iv_bottom_emotion.setTag(path);
                        // imag_list.add(iv_bottom_emotion);
                        imag_list.add(0, iv_bottom_emotion);
                        iv_bottom_emotion.setOnClickListener(new OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                // TODO Auto-generated method stub
                                selected_pager = (String) iv_bottom_emotion.getTag();
                                iv_expression_emoji.setBackgroundResource(R.drawable.grid_line);
                                for (ImageView iv : imag_list) {
                                    if (selected_pager.equals(iv.getTag())) {
                                        iv.setBackgroundResource(R.drawable.grid_line_press);
                                    } else {
                                        iv.setBackgroundResource(R.drawable.grid_line);
                                    }
                                }
                                search_selected_emotions((String) iv_bottom_emotion.getTag());
                            }
                        });

                        ll_emotions_content.addView(iv_bottom_emotion);
                        viewpager.setTag(tab_emotions_tag);// ?
                    }
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }

        }
    }
}

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//from   ww w. j  av  a2s  . c o  m
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row = (Cursor) lv.getItemAtPosition(position);
            final String _id = row.getString(row.getColumnIndexOrThrow("_id"));
            final String 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:cm.aptoide.pt.MainActivity.java

private void loadUIEditorsApps() {

    final int[] res_ids = { R.id.central, R.id.topleft, R.id.topright, R.id.bottomleft, R.id.bottomcenter,
            R.id.bottomright };//from   w  w w.j a v  a2s .  c o  m
    final ArrayList<HashMap<String, String>> image_urls = db.getFeaturedGraphics();
    final HashMap<String, String> image_url_highlight = db.getHighLightFeature();

    //        System.out.println(image_url_highlight + "ASDASDASDASD");
    //        System.out.println(image_urls + "ASDASDASDASD");

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (image_url_highlight.size() > 0) {
                a = 1;
                ImageView v = (ImageView) featuredView.findViewById(res_ids[0]);
                // imageLoader.DisplayImage(-1, image_url_highlight.get("url"), v,
                // mContext);
                DisplayImageOptions options = new DisplayImageOptions.Builder()
                        .displayer(new FadeInBitmapDisplayer(1000)).cacheOnDisc().cacheInMemory().build();
                cm.aptoide.com.nostra13.universalimageloader.core.ImageLoader.getInstance()
                        .displayImage(image_url_highlight.get("url"), v, options);
                v.setTag(image_url_highlight.get("id"));
                v.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {

                        Intent i = new Intent(MainActivity.this, ApkInfo.class);
                        i.putExtra("_id", Long.parseLong((String) arg0.getTag()));
                        i.putExtra("top", false);
                        i.putExtra("category", Category.EDITORSCHOICE.ordinal());
                        startActivity(i);

                    }
                });
                // v.setOnClickListener(featuredListener);
            }
        }
    });

    Collections.shuffle(image_urls);
    runOnUiThread(new Runnable() {

        public void run() {

            for (int i = a; i != res_ids.length; i++) {
                try {
                    ImageView v = (ImageView) featuredView.findViewById(res_ids[i]);

                    // imageLoader.DisplayImage(-1,
                    // image_urls.get(i).get("url"), v, mContext);
                    DisplayImageOptions options = new DisplayImageOptions.Builder()
                            .displayer(new FadeInBitmapDisplayer(1000)).cacheOnDisc().cacheInMemory().build();
                    cm.aptoide.com.nostra13.universalimageloader.core.ImageLoader.getInstance()
                            .displayImage(image_urls.get(i - a).get("url"), v, options);

                    v.setTag(image_urls.get(i - a).get("id"));
                    v.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            Intent i = new Intent(MainActivity.this, ApkInfo.class);
                            i.putExtra("_id", Long.parseLong((String) arg0.getTag()));
                            i.putExtra("top", false);
                            i.putExtra("category", Category.EDITORSCHOICE.ordinal());
                            startActivity(i);
                        }
                    });
                    // v.setOnClickListener(featuredListener);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        }
    });
}

From source file:com.zzisoo.toylibrary.adapter.ToyListAdapter.java

@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
    Log.e(TAG, "onBindViewHolder #" + position);

    // Get element from your dataset at this position and replace the contents of the view
    // with that element
    View v = viewHolder.getVh();//from   w ww .j  ava  2s  .  c  o  m
    final ImageView ivToyImage = viewHolder.getIvToyImage();
    final TextView textView = viewHolder.getTvTitle();
    final FlipImageView flipImageView = viewHolder.getFlipImageView();

    View.OnClickListener l = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String strPid = mDataSet.get(position).getStrPid();

            if (mPref.getStringArrayList(SharedPref.PREF_FAVORITE_LIST).contains(strPid)) {
                mPref.removeStringArrayListItem(SharedPref.PREF_FAVORITE_LIST, strPid);
            } else {
                mPref.addStringArrayListItem(SharedPref.PREF_FAVORITE_LIST, strPid);
            }
            flipImageView.toggleFlip();
        }
    };
    textView.setOnClickListener(l);
    flipImageView.setOnClickListener(l);

    viewHolder.getTvLoadingBackground().setBackgroundColor(getPastelRBG());
    viewHolder.getTvLoading().setText("ToyToI");
    if (-1 < position && position < mDataSet.size()) {
        setItemSize(v);

        mFavList = mPref.getStringArrayList(SharedPref.PREF_FAVORITE_LIST);
        if (mFavList.contains(mDataSet.get(position).getStrPid())) {
            flipImageView.setFlipped(true);
        } else {
            flipImageView.setFlipped(false);
        }

        final Toy toy = mDataSet.get(position);

        String bgImage = Config.HOST_SERVER_URL + toy.getImage().replace("..", "");
        String strTitle = toy.getTitle();
        textView.setText(strTitle);//

        ImageLoadingListener fadeImageLoadingListener = new ImageLoadingListener() {

            long ANIM_DURATION = 500;

            @Override
            public void onLoadingStarted(String s, View view) {
                view.clearAnimation();
                ((ImageView) view).setImageResource(R.drawable.alpha_zero);
            }

            @Override
            public void onLoadingFailed(String s, View view, FailReason failReason) {
                Toast.makeText(view.getContext(), "Network Error : " + failReason.getType().toString(),
                        Toast.LENGTH_LONG).show();
                ((TextView) ((FrameLayout) view.getParent()).findViewById(R.id.tvLoading)).setText("Error");
                Log.e(TAG, "onLoadingFailed :" + s);
            }

            @Override
            public void onLoadingComplete(String s, View view, Bitmap bitmap) {
                ((ImageView) view).setImageBitmap(bitmap);
                Animation fadeIn = new AlphaAnimation(0, 1);
                fadeIn.setInterpolator(new DecelerateInterpolator()); // add this
                fadeIn.setDuration(ANIM_DURATION);
                view.clearAnimation();
                view.startAnimation(fadeIn);
            }

            @Override
            public void onLoadingCancelled(String s, View view) {
                if (view != null) {
                    ((TextView) ((FrameLayout) view.getParent()).findViewById(R.id.tvLoading)).setText("Error");
                    Log.e(TAG, "onLoadingCancelled :" + s);
                }
            }
        };

        App.getImageLoader(v.getContext()).displayImage(bgImage, ivToyImage, fadeImageLoadingListener);
        ivToyImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                AsyncHttpClient asyncHttpClient = new AsyncHttpClient();

                asyncHttpClient.get(v.getContext(), Config.URL_DETAIL + mDataSet.get(position).getStrPid(),
                        new AsyncHttpResponseHandler() {

                            @Override
                            public void onSuccess(int i, Header[] headers, byte[] bytes) {
                                String responseStr = new String(bytes);
                                Context context = v.getContext();

                                Bundle bundle = new Bundle();
                                Gson gson = new Gson();
                                Product[] products = gson.fromJson(responseStr, Product[].class);

                                Intent intent = new Intent(context,
                                        FlexibleSpaceWithImageRecyclerViewActivity.class);
                                intent.putExtra("Products", gson.toJson(products));
                                intent.putExtra("title", toy.getTitle());
                                intent.putExtra("image", toy.getImage());
                                intent.putExtra("favorite",
                                        mPref.getStringArrayList(SharedPref.PREF_FAVORITE_LIST)
                                                .contains(toy.getStrPid()));
                                context.startActivity(intent);

                                //changeFragment
                            }

                            private void changeFragment(Bundle bundle) {
                                Fragment fragment = new ProductListViewFragment();
                                fragment.setArguments(bundle);

                                FragmentTransaction transaction = ((FragmentActivity) v.getContext())
                                        .getSupportFragmentManager().beginTransaction();
                                transaction.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.popenter,
                                        R.anim.popexit);
                                transaction.addToBackStack(getClass().getSimpleName());
                                transaction.replace(R.id.toyListViewWraper, fragment);
                                transaction.commit();
                            }

                            @Override
                            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {

                            }
                        });

                Log.d(TAG, "Element " + position + " clicked.");
                mClickedPostion = position;
                //
            }
        });
    }

}

From source file:com.example.android.navigationdrawerexample.Controller.PilihanController.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    /*Fragment fragment = new PlanetFragment();*/
    fragment = null;/*  w ww.ja va2s .c o  m*/
    Bundle args = new Bundle();

    switch (position) {
    case 0:
        fragment = new Fragment() {
            @Override
            public void onResume() {
                super.onResume();
                new GetAllJadwalTask(PilihanController.this).execute(username);
            }

            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                StrictMode.setThreadPolicy(policy);

                View view = inflater.inflate(R.layout.list_jadwal, container, false);
                GetAllJadwalListView = (ExpandableListView) view.findViewById(R.id.GetAllJadwalListView);
                ImageView buat = (ImageView) view.findViewById(R.id.button);
                //Button pilihan = (Button) view.findViewById(R.id.button9);
                if (role == 0)
                    buat.setVisibility(View.GONE);
                else
                    buat.setVisibility(View.VISIBLE);

                new GetAllJadwalTask(PilihanController.this).execute(username);

                GetAllJadwalListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {

                    @Override
                    public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                        GetAllJadwalListView.expandGroup(groupPosition);
                        return true;
                    }
                });

                GetAllJadwalListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

                    @Override
                    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
                            int childPosition, long id) {
                        try {
                            //Toast.makeText(getApplicationContext(), listDataChild2.get(listDataHeader2.get(groupPosition)).get(childPosition).toString(), Toast.LENGTH_LONG).show();
                            int jadwalp = listDataChild2.get(listDataHeader2.get(groupPosition))
                                    .get(childPosition).getInt("Id");
                            int kelasp = listDataChild2.get(listDataHeader2.get(groupPosition))
                                    .get(childPosition).getInt("Id_kelas");
                            ////                                    JSONObject mahasiswaClicked = jsonArray.getJSONObject(groupPosition+childPosition);
                            ////                                    int jadwalp = mahasiswaClicked.getInt("Id");
                            ////                                    int kelasp = mahasiswaClicked.getInt("Id_kelas");
                            Intent showDetails = new Intent(getActivity(), JadwalController.class);
                            showDetails.putExtra("JadwalID", jadwalp);
                            showDetails.putExtra("KelasID", kelasp);
                            showDetails.putExtra("Username", username);
                            showDetails.putExtra("View", "detailJadwal");
                            startActivity(showDetails);

                        } catch (JSONException e) {
                            e.printStackTrace();
                            //Toast.makeText(getApplicationContext(), "lala masuk ex", Toast.LENGTH_LONG).show();
                        }
                        return false;
                    }
                });

                buat.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        Intent showDetails = new Intent(getActivity(), JadwalController.class);
                        //asumsi username gak null
                        showDetails.putExtra("Username", username);
                        showDetails.putExtra("View", "createJadwal");

                        startActivity(showDetails);
                    }
                });
                return view;
            }
        };
        args.putString(FragmentOne.ITEM_NAME, dataList.get(position).getItemName());
        args.putInt(FragmentOne.IMAGE_RESOURCE_ID, dataList.get(position).getImgResID());
        args.putInt("role", 2);
        break;
    case 1:
        fragment = new RoleFragment();
        args.putInt("role", 1);
        break;
    case 2:
        fragment = new Fragment() {
            @Override
            public void onResume() {
                super.onResume();
                new GetAllEnrollTask(PilihanController.this).execute(username);
            }

            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                StrictMode.setThreadPolicy(policy);

                view = inflater.inflate(R.layout.list_enroll, container, false);

                //GetAllEnrollListView = (ListView) view.findViewById(R.id.GetAllJadwalListView);
                ImageView enroll = (ImageView) view.findViewById(R.id.button);
                expListView = (ExpandableListView) view.findViewById(R.id.lvExp);

                new GetAllEnrollTask(PilihanController.this).execute(username);

                expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

                    @Override
                    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
                            int childPosition, long id) {
                        //asumsikan kalo dipencet bisa ngeluarin infromasi asistennya
                        //viewnya di view_profile_personal
                        //kelasnya inten, nah loh pake controller mana nih??
                        //asumsikan gue punya kelas ProfileAsdos.java
                        String userAsdos = listDataChild.get(listDataHeader.get(groupPosition))
                                .get(childPosition);
                        Intent showDetails = new Intent(getActivity(), MenjabatController.class);
                        showDetails.putExtra("Username", userAsdos);
                        startActivity(showDetails);
                        return false;
                    }
                });

                enroll.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        Intent showDetails = new Intent(getActivity(), EnrollController.class);
                        showDetails.putExtra("Username", username);
                        startActivity(showDetails);
                    }
                });
                return view;
            }

        };
        args.putInt("role", 0);
        break;
    case 3:
        fragment = new Fragment() {
            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                StrictMode.setThreadPolicy(policy);

                View view = inflater.inflate(R.layout.choose_forum, container, false);

                Button buttonForumReply = (Button) view.findViewById(R.id.choose_forum_1);
                Button buttonForumForum = (Button) view.findViewById(R.id.choose_forum_2);
                Button buttonForumPolling = (Button) view.findViewById(R.id.choose_forum_3);

                buttonForumReply.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), ForumQA.class);
                        intent.putExtra("Username", username);
                        startActivity(intent);
                    }
                });

                buttonForumForum.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), ForumRequest.class);
                        intent.putExtra("Username", username);
                        startActivity(intent);
                    }
                });

                buttonForumPolling.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), ForumPolling.class);
                        intent.putExtra("Username", username);
                        startActivity(intent);
                    }
                });

                return view;
            }

        };
        args.putInt("role", 3);
        break;
    case 4:
        //ProfileController profileController2 = new ProfileController(username);
        if (role == 2) {
            fragment = new Fragment() {

                @Override
                public View onCreateView(LayoutInflater inflater, ViewGroup container,
                        Bundle savedInstanceState) {
                    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                    StrictMode.setThreadPolicy(policy);

                    view = inflater.inflate(R.layout.admin, container, false);

                    //GetAllEnrollListView = (ListView) view.findViewById(R.id.GetAllJadwalListView);
                    Button kelas = (Button) view.findViewById(R.id.button9);
                    Button role = (Button) view.findViewById(R.id.button10);
                    Button database = (Button) view.findViewById(R.id.button11);
                    Button forum = (Button) view.findViewById(R.id.button12);

                    kelas.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            Intent showDetails = new Intent(getActivity(), KelasController.class);
                            //asumsi username gak null
                            showDetails.putExtra("Username", username);
                            showDetails.putExtra("View", "listKelas");
                            startActivity(showDetails);
                        }
                    });
                    role.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            Intent showDetails = new Intent(getActivity(), RoleController.class);
                            //asumsi username gak null
                            showDetails.putExtra("Username", username);
                            startActivity(showDetails);
                        }
                    });
                    database.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            Intent showDetails = new Intent(getActivity(), Database.class);
                            startActivity(showDetails);
                        }
                    });

                    forum.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            Intent showDetails = new Intent(getActivity(), AdminThread.class);
                            startActivity(showDetails);
                        }
                    });
                    return view;
                }
            };
        } else {
            fragment = new FragmentOne();
            Toast.makeText(getApplicationContext(), "Hei Anda Bukan Admin", Toast.LENGTH_LONG).show();
        }
        args.putInt("role", 4);
        break;
    case 5:
        session.logoutUser();
        finish();
        return;
    }
    /*args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);*/
    fragment.setArguments(args);

    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mPlanetTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:ca.ualberta.cs.drivr.RequestsListAdapter.java

/**
 * Called when the view holder is wants to bind the request at a certain position in the list.
 * @param viewHolder//from   w ww.  ja  v a  2s .  co  m
 * @param position
 */
@Override
public void onBindViewHolder(final RequestsListAdapter.ViewHolder viewHolder, final int position) {
    final Request request = requestsToDisplay.get(position);

    // Get the views to update
    final TextView otherUserNameTextView = viewHolder.otherUserNameTextView;
    final TextView descriptionTextView = viewHolder.descriptionTextView;
    final TextView fareTextView = viewHolder.fareTextView;
    final TextView routeTextView = viewHolder.routeTextView;
    final TextView statusTextView = viewHolder.statusTextView;
    final ImageView callImageView = viewHolder.callImageView;
    final ImageView emailImageView = viewHolder.emailImageView;
    final ImageView checkImageView = viewHolder.checkMarkImageView;
    final ImageView deleteImageView = viewHolder.xMarkImageView;

    // Todo Hide Image Views until correct Request State
    if (request.getRequestState() != RequestState.CONFIRMED) {
        checkImageView.setVisibility(View.INVISIBLE);
    }

    if (request.getRequestState() != RequestState.PENDING) {
        deleteImageView.setVisibility(View.INVISIBLE);
    }

    // Show the other person's name
    final DriversList drivers = request.getDrivers();

    // Get the username of the other user
    if (userManager.getUserMode() == UserMode.RIDER) {
        final String multipleDrivers = "Multiple Drivers Accepted";
        final String driverUsername = drivers.size() == 1 ? drivers.get(0).getUsername() : "No Driver Yet";
        otherUserNameTextView.setText(drivers.size() > 1 ? multipleDrivers : driverUsername);
    } else {
        otherUserNameTextView.setText(request.getRider().getUsername());
    }

    // If the request has a description, show it. Otherwise, hide te description
    if (Strings.isNullOrEmpty(request.getDescription()))
        descriptionTextView.setVisibility(View.GONE);
    else
        descriptionTextView.setText(request.getDescription());

    // Show the fare
    fareTextView.setText("$" + request.getFareString());

    // Show the route
    routeTextView.setText(request.getRoute());

    // Driver User
    otherUserNameTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final String otherUsername = otherUserNameTextView.getText().toString();
            // there exists drivers
            if (otherUsername != "No Driver Yet") {
                if (otherUsername != "Multiple Drivers Accepted") {
                    Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();

                    ElasticSearch elasticSearch = new ElasticSearch(
                            UserManager.getInstance().getConnectivityManager());
                    User user = elasticSearch.loadUser(otherUsername);

                    String driverString = gson.toJson(user, User.class);
                    Intent intent = new Intent(context, DriverProfileActivity.class);
                    intent.putExtra(DriverProfileActivity.DRIVER, driverString);
                    context.startActivity(intent);
                } else {
                    startMultipleDriverIntent(request);
                }
            }
        }
    });

    routeTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();
            String requestString = gson.toJson(request, Request.class);
            Intent intent = new Intent(context, RequestActivity.class);
            intent.putExtra("UniqueID", "From_RequestListActivity");
            intent.putExtra(RequestActivity.EXTRA_REQUEST, requestString);
            context.startActivity(intent);
        }
    });

    // Show the status text
    statusTextView.setText(request.getRequestState().toString());

    // Add a listener to the call image
    callImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (drivers.size() == 0) {
                Toast.makeText(context, "No driver number available at this time", Toast.LENGTH_SHORT).show();

            }
            // Start Dialer
            else if (drivers.size() == 1) {
                Intent intent = new Intent(Intent.ACTION_CALL);
                String number;
                if (UserManager.getInstance().getUserMode().equals(UserMode.RIDER)) {
                    number = drivers.get(0).getPhoneNumber();
                } else {
                    number = request.getRider().getPhoneNumber();
                }
                number = "tel:" + number;
                intent.setData(Uri.parse(number));
                if (ActivityCompat.checkSelfPermission(context,
                        Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

                    return;
                }
                context.startActivity(intent);

            } else {

                startMultipleDriverIntent(request);
            }
        }
    });

    // Add a listener to the email image
    emailImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (drivers.size() == 0) {
                Toast.makeText(context, "No driver email available at this time", Toast.LENGTH_SHORT).show();

            }
            //http://stackoverflow.com/questions/8701634/send-email-intent
            else if (drivers.size() == 1) {

                Intent intent = new Intent();
                ComponentName emailApp = intent.resolveActivity(context.getPackageManager());
                ComponentName unsupportedAction = ComponentName
                        .unflattenFromString("com.android.fallback/.Fallback");
                boolean hasEmailApp = emailApp != null && !emailApp.equals(unsupportedAction);
                String email;

                if (UserManager.getInstance().getUserMode().equals(UserMode.RIDER)) {
                    email = drivers.get(0).getEmail();
                } else {
                    email = request.getRider().getEmail();
                }
                String subject = "Drivr Request: " + request.getId();
                String body = "Drivr user " + drivers.get(0).getUsername();

                if (hasEmailApp) {
                    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + email));
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
                    emailIntent.putExtra(Intent.EXTRA_TEXT, body);
                    context.startActivity(Intent.createChooser(emailIntent, "Chooser Title"));
                } else {
                    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", email, null));
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "");
                    emailIntent.putExtra(Intent.EXTRA_TEXT, "");
                    context.startActivity(Intent.createChooser(emailIntent, "Send email..."));
                }
            } else {
                startMultipleDriverIntent(request);

            }
        }
    });

    // Complete The Request
    checkImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(context, RequestCompletedActivity.class);
            intent.putExtra(RequestCompletedActivity.REQUEST_ID_EXTRA, request.getId());
            context.startActivity(intent);
        }
    });

    deleteImageView.setOnClickListener(new View.OnClickListener() {

        // Todo Delete the Request
        @Override
        public void onClick(View v) {
            v.getContext();
            ElasticSearch elasticSearch = new ElasticSearch(
                    (ConnectivityManager) v.getContext().getSystemService(Context.CONNECTIVITY_SERVICE));
            elasticSearch.deleteRequest(request.getId());
            UserManager userManager = UserManager.getInstance();
            userManager.getRequestsList().removeById(request);
            userManager.notifyObservers();
            requestsToDisplay.remove(request);
            notifyItemRemoved(viewHolder.getAdapterPosition());
        }
    });
}

From source file:android.example.com.animationdemos.ZoomActivity.java

/**
 * "Zooms" in a thumbnail view by assigning the high resolution image to a hidden "zoomed-in"
 * image view and animating its bounds to fit the entire activity content area. More
 * specifically://from   w  w  w  .ja v a2s .co m
 * <p/>
 * <ol>
 * <li>Assign the high-res image to the hidden "zoomed-in" (expanded) image view.</li>
 * <li>Calculate the starting and ending bounds for the expanded view.</li>
 * <li>Animate each of four positioning/sizing properties (X, Y, SCALE_X, SCALE_Y)
 * simultaneously, from the starting bounds to the ending bounds.</li>
 * <li>Zoom back out by running the reverse animation on click.</li>
 * </ol>
 *
 * @param thumbView  The thumbnail view to zoom in.
 * @param imageResId The high-resolution version of the image represented by the thumbnail.
 */
private void zoomImageFromThumb(final View thumbView, int imageResId) {
    // If there's an animation in progress, cancel it immediately and proceed with this one.
    if (mCurrentAnimator != null) {
        mCurrentAnimator.cancel();
    }
    // Load the high-resolution "zoomed-in" image.
    final ImageView expandedImageView = (ImageView) findViewById(R.id.expanded_image);
    expandedImageView.setImageResource(imageResId);
    // Calculate the starting and ending bounds for the zoomed-in image. This step
    // involves lots of math. Yay, math.
    final Rect startBounds = new Rect();
    final Rect finalBounds = new Rect();
    final Point globalOffset = new Point();
    // The start bounds are the global visible rectangle of the thumbnail, and the
    // final bounds are the global visible rectangle of the container view. Also
    // set the container view's offset as the origin for the bounds, since that's
    // the origin for the positioning animation properties (X, Y).
    thumbView.getGlobalVisibleRect(startBounds);
    findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset);
    startBounds.offset(-globalOffset.x, -globalOffset.y);
    finalBounds.offset(-globalOffset.x, -globalOffset.y);
    // Adjust the start bounds to be the same aspect ratio as the final bounds using the
    // "center crop" technique. This prevents undesirable stretching during the animation.
    // Also calculate the start scaling factor (the end scaling factor is always 1.0).
    float startScale;
    if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width()
            / startBounds.height()) {
        // Extend start bounds horizontally
        startScale = (float) startBounds.height() / finalBounds.height();
        float startWidth = startScale * finalBounds.width();
        float deltaWidth = (startWidth - startBounds.width()) / 2;
        startBounds.left -= deltaWidth;
        startBounds.right += deltaWidth;
    } else {
        // Extend start bounds vertically
        startScale = (float) startBounds.width() / finalBounds.width();
        float startHeight = startScale * finalBounds.height();
        float deltaHeight = (startHeight - startBounds.height()) / 2;
        startBounds.top -= deltaHeight;
        startBounds.bottom += deltaHeight;
    }
    // Hide the thumbnail and show the zoomed-in view. When the animation begins,
    // it will position the zoomed-in view in the place of the thumbnail.
    thumbView.setAlpha(0f);
    expandedImageView.setVisibility(View.VISIBLE);
    // Set the pivot point for SCALE_X and SCALE_Y transformations to the top-left corner of
    // the zoomed-in view (the default is the center of the view).
    expandedImageView.setPivotX(0f);
    expandedImageView.setPivotY(0f);
    // Construct and run the parallel animation of the four translation and scale properties
    // (X, Y, SCALE_X, and SCALE_Y).
    AnimatorSet set = new AnimatorSet();
    set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left, finalBounds.left))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, finalBounds.top))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f));
    set.setDuration(mShortAnimationDuration);
    set.setInterpolator(new DecelerateInterpolator());
    set.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCurrentAnimator = null;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            mCurrentAnimator = null;
        }
    });
    set.start();
    mCurrentAnimator = set;
    // Upon clicking the zoomed-in image, it should zoom back down to the original bounds
    // and show the thumbnail instead of the expanded image.
    final float startScaleFinal = startScale;
    expandedImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mCurrentAnimator != null) {
                mCurrentAnimator.cancel();
            }
            // Animate the four positioning/sizing properties in parallel, back to their
            // original values.
            AnimatorSet set = new AnimatorSet();
            set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal));
            set.setDuration(mShortAnimationDuration);
            set.setInterpolator(new DecelerateInterpolator());
            set.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }
            });
            set.start();
            mCurrentAnimator = set;
        }
    });
}

From source file:com.fugueweb.pub.animation.ZoomActivity.java

/**
 * "Zooms" in a thumbnail view by assigning the high resolution image to a hidden "zoomed-in"
 * image view and animating its bounds to fit the entire activity content area. More
 * specifically:/*from  ww  w. ja  va2 s. c o  m*/
 *
 * <ol>
 *   <li>Assign the high-res image to the hidden "zoomed-in" (expanded) image view.</li>
 *   <li>Calculate the starting and ending bounds for the expanded view.</li>
 *   <li>Animate each of four positioning/sizing properties (X, Y, SCALE_X, SCALE_Y)
 *       simultaneously, from the starting bounds to the ending bounds.</li>
 *   <li>Zoom back out by running the reverse animation on click.</li>
 * </ol>
 *
 * @param thumbView  The thumbnail view to zoom in.
 * @param imageResId The high-resolution version of the image represented by the thumbnail.
 */
private void zoomImageFromThumb(final View thumbView, int imageResId) {
    // If there's an animation in progress, cancel it immediately and proceed with this one.
    if (mCurrentAnimator != null) {
        mCurrentAnimator.cancel();
    }

    // Load the high-resolution "zoomed-in" image.
    final ImageView expandedImageView = (ImageView) findViewById(R.id.expanded_image);
    expandedImageView.setImageResource(imageResId);

    // Calculate the starting and ending bounds for the zoomed-in image. This step
    // involves lots of math. Math.
    final Rect startBounds = new Rect();
    final Rect finalBounds = new Rect();
    final Point globalOffset = new Point();

    // The start bounds are the global visible rectangle of the thumbnail, and the
    // final bounds are the global visible rectangle of the container view. Also
    // set the container view's offset as the origin for the bounds, since that's
    // the origin for the positioning animation properties (X, Y).
    thumbView.getGlobalVisibleRect(startBounds);
    findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset);
    startBounds.offset(-globalOffset.x, -globalOffset.y);
    finalBounds.offset(-globalOffset.x, -globalOffset.y);

    // Adjust the start bounds to be the same aspect ratio as the final bounds using the
    // "center crop" technique. This prevents undesirable stretching during the animation.
    // Also calculate the start scaling factor (the end scaling factor is always 1.0).
    float startScale;
    if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width()
            / startBounds.height()) {
        // Extend start bounds horizontally
        startScale = (float) startBounds.height() / finalBounds.height();
        float startWidth = startScale * finalBounds.width();
        float deltaWidth = (startWidth - startBounds.width()) / 2;
        startBounds.left -= deltaWidth;
        startBounds.right += deltaWidth;
    } else {
        // Extend start bounds vertically
        startScale = (float) startBounds.width() / finalBounds.width();
        float startHeight = startScale * finalBounds.height();
        float deltaHeight = (startHeight - startBounds.height()) / 2;
        startBounds.top -= deltaHeight;
        startBounds.bottom += deltaHeight;
    }

    // Hide the thumbnail and show the zoomed-in view. When the animation begins,
    // it will position the zoomed-in view in the place of the thumbnail.
    thumbView.setAlpha(0f);
    expandedImageView.setVisibility(View.VISIBLE);

    // Set the pivot point for SCALE_X and SCALE_Y transformations to the top-left corner of
    // the zoomed-in view (the default is the center of the view).
    expandedImageView.setPivotX(0f);
    expandedImageView.setPivotY(0f);

    // Construct and run the parallel animation of the four translation and scale properties
    // (X, Y, SCALE_X, and SCALE_Y).
    AnimatorSet set = new AnimatorSet();
    set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left, finalBounds.left))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, finalBounds.top))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f));
    set.setDuration(mShortAnimationDuration);
    set.setInterpolator(new DecelerateInterpolator());
    set.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCurrentAnimator = null;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            mCurrentAnimator = null;
        }
    });
    set.start();
    mCurrentAnimator = set;

    // Upon clicking the zoomed-in image, it should zoom back down to the original bounds
    // and show the thumbnail instead of the expanded image.
    final float startScaleFinal = startScale;
    expandedImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mCurrentAnimator != null) {
                mCurrentAnimator.cancel();
            }

            // Animate the four positioning/sizing properties in parallel, back to their
            // original values.
            AnimatorSet set = new AnimatorSet();
            set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal));
            set.setDuration(mShortAnimationDuration);
            set.setInterpolator(new DecelerateInterpolator());
            set.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }
            });
            set.start();
            mCurrentAnimator = set;
        }
    });
}