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:gr.scify.newsum.ui.SearchViewActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if ((getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_NORMAL
            & (getResources().getConfiguration().screenLayout
                    & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_SMALL) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    }//from   ww  w .  j a  v a2s . co m
    SharedPreferences usertheme = getSharedPreferences("theme", 0);
    int newTheme = usertheme.getInt("theme", 2);
    Utils.onActivityCreateSetTheme(this, newTheme);

    SharedPreferences userlang = getSharedPreferences("lang", 0);
    String newlang = userlang.getString("lang", Locale.getDefault().getLanguage());
    Setlanguage.updateLanguage(getApplicationContext(), newlang);

    GestureOverlayView gestureOverlayView = new GestureOverlayView(this);
    View inflate = getLayoutInflater().inflate(R.layout.view, null);
    gestureOverlayView.addView(inflate);
    gestureOverlayView.addOnGesturePerformedListener(this);
    gestureOverlayView.setGestureColor(Color.TRANSPARENT);
    gestureOverlayView.setUncertainGestureColor(Color.TRANSPARENT);
    gestureLib = GestureLibraries.fromRawResource(this, R.raw.gestures);
    if (!gestureLib.load()) {
        finish();
    }
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(gestureOverlayView);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);

    ImageView title_image = (ImageView) findViewById(R.id.title_image);
    title_image.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.scify)));
            startActivity(browse);
        }

    });

    // setContentView(R.layout.view);
    // TODO: Add Loading dialog

    SharedPreferences setvmassage = getSharedPreferences("dialog", 0);
    boolean dialogShown = setvmassage.getBoolean("dialogShown", false);

    if (!dialogShown) {
        // prepare the alert box
        AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
        alertbox.setMessage(R.string.view_massage);
        alertbox.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {

            }
        });
        alertbox.setCancelable(false);
        alertbox.show();

        SharedPreferences.Editor editor = setvmassage.edit();
        editor.putBoolean("dialogShown", true);
        editor.commit();
    }

    // Init waiting dialog
    showWaitingDialog();

    initLayoutAndControls();

}

From source file:com.gaadikey.gaadikey.gaadikey.Fragment_Home.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_home, container, false);

    ImageView thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
    TextView gaadiname_field = (TextView) view.findViewById(R.id.GaadiName);
    TextView gaadimsg_field = (TextView) view.findViewById(R.id.GaadiMsg);
    TextView numberplate_textview = (TextView) view.findViewById(R.id.numberplate);

    numberplate_textview.setOnClickListener(new View.OnClickListener() {
        @Override/*from ww  w  . j a va  2s.  c o m*/
        public void onClick(View view) {

            ((LaunchActivity_NavDrawer) getActivity()).displayView(6); // This opens up numberplate view!
        }
    });

    thumbnail.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            // Open up the settings view when clicked from here!
            ((LaunchActivity_NavDrawer) getActivity()).displayView(8); // The 7th option is settings!
        }
    });

    // Download the Image dynamically, Pinging the Image URL
    // Get the image path URL by rading the persistant storage

    SharedPreferences sharedPref = getActivity().getSharedPreferences("android_shared", Context.MODE_PRIVATE);
    IMAGE_PATH = sharedPref.getString(getString(R.string.KEY_GaadiImage), "default");
    //  IMAGE_PATH = "http://gaadikey.com/images/GaadiKey_bikes/bajaj/bajaj-discover-100m.jpg"; // hARD CODING THE IMAGE url TO CHECK IF 37KB IMAGE LOADING IS THE ISSUE
    GAADI_MSG = sharedPref.getString(getString(R.string.KEY_GaadiMsg), "Set status");
    GAADI_NAME = sharedPref.getString(getString(R.string.KEY_GaadiName), "Your Vehicle Name here");

    gaadimsg_field.setText(GAADI_MSG);
    gaadiname_field.setText(GAADI_NAME);

    Log.e("Retrieved IMAGE_PATH ", IMAGE_PATH);
    Log.e("Retrieved GAADI_MSG ", GAADI_MSG);
    Log.e("Retrieved GAADI NAME ", GAADI_NAME);

    if (!IMAGE_PATH.equals("default")) {

        Picasso.with(getActivity().getBaseContext()).load(IMAGE_PATH).into(thumbnail);

    }

    TextView numberplateText = (TextView) view.findViewById(R.id.numberplate);
    SharedPreferences sharedPref1 = getActivity().getSharedPreferences("android_shared", Context.MODE_PRIVATE);
    String numberplatestring = sharedPref1.getString(getString(R.string.KEY_GaadiKey_Number_Saved),
            "KA50Q7896");
    Log.e("The retreived number plate string is ", numberplatestring);

    numberplateText.setText(numberplatestring); // setting the string obtained from the KEY set by number picker change listener
    Typeface typface = Typeface.createFromAsset(getActivity().getAssets(), "LicensePlate.ttf");
    numberplateText.setTypeface(typface);

    lanes.add("Public Lane");
    lanes.add("Friends Lane");
    lanes.add("Safety Lane");
    lanes.add("Shopping Lane");
    lanes.add("News");

    listview = (ListView) view.findViewById(R.id.list);
    listview.setAdapter(new StickyHomeAdapter(getActivity(), lanes));
    listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {

            SharedPreferences sharedPref4 = getActivity().getSharedPreferences("android_shared",
                    Context.MODE_PRIVATE);
            SharedPreferences.Editor editor_4 = sharedPref4.edit();
            editor_4.putString(getString(R.string.KEY_HomeMenu), "" + position); // Incrementing the position by 1
            editor_4.commit();

            Log.e(" The Item clicked in the list is ", "" + position);
            ((LaunchActivity_NavDrawer) getActivity()).displayView(position + 1);

        }
    });

    // Removing the edittext for now

    //        final EditText edittext = (EditText) view.findViewById(R.id.editText_search);
    //
    //        edittext.setOnEditorActionListener(
    //                new EditText.OnEditorActionListener() {
    //                    @Override
    //                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    //
    //
    //
    //                        if (event != null) {
    //                            // if shift key is down, then we want to insert the '\n' char in the TextView;
    //                            // otherwise, the default action is to send the message.
    //
    //                            if (!event.isShiftPressed())
    //                            {
    //                                Log.e(" Enter is pressed! ", "Yes");
    //                                //return true;
    //                                // Start the activity here
    //
    //                            }
    //                            return false;
    //                        }
    //
    //                        Log.e("here we are ", "Yes");
    //
    //                        Intent i = new Intent(getActivity(), LaunchActivity_NavDrawer.class);
    //                        i.putExtra("searchString",edittext.getText().toString());
    //                        i.putExtra("view", "normal");
    //
    //                        SharedPreferences sharedPref4 = getActivity().getSharedPreferences("android_shared", Context.MODE_PRIVATE);
    //                        SharedPreferences.Editor editor_4 = sharedPref4.edit();
    //                        editor_4.putString(getString(R.string.KEY_HomeMenu), "0" ); // Incrementing the position by 1
    //                        editor_4.commit();
    //                        startActivity(i);
    //
    //                        return true;
    //                    }
    //                });

    return view;
}

From source file:de.uni_weimar.m18.anatomiederstadt.SplashActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    final PathView pathView = (PathView) findViewById(R.id.pathView);
    pathView.useNaturalColors();//from  w w w. j a v  a 2s  .  c  o m

    int pathDelay = 1000;
    int pathDuration = 2500;

    final Animation a = new AlphaAnimation(0.00f, 1.00f);
    a.setStartOffset(3500);
    a.setDuration(1000);

    //pathView.setSvgResource(R.raw.vitruvian_man_weimar_kk3);
    pathView.getPathAnimator().delay(pathDelay).duration(pathDuration)
            .interpolator(new AccelerateDecelerateInterpolator()).start();

    final ImageView logoImage = (ImageView) findViewById(R.id.logoImage);

    a.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            logoImage.setVisibility(View.VISIBLE);

            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    launchMainActivity();
                }
            }, 1500);

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });

    logoImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            launchMainActivity();
        }
    });

    logoImage.startAnimation(a);

}

From source file:com.frostwire.android.gui.adapters.SearchResultListAdapter.java

private void populateThumbnail(View view, SearchResult sr) {
    ImageView fileTypeIcon = findView(view, R.id.view_bittorrent_search_result_list_item_filetype_icon);
    if (sr.getThumbnailUrl() != null) {
        thumbLoader.load(Uri.parse(sr.getThumbnailUrl()), fileTypeIcon, 96, 96, getFileTypeIconId());
    }/*from w w  w.jav  a 2 s .c o m*/

    MediaPlaybackStatusOverlayView overlayView = findView(view,
            R.id.view_bittorrent_search_result_list_item_filetype_icon_media_playback_overlay_view);
    fileTypeIcon.setOnClickListener(previewClickListener);
    if (isAudio(sr) || sr instanceof YouTubePackageSearchResult) {
        fileTypeIcon.setTag(sr);
        overlayView.setTag(sr);
        overlayView.setVisibility(View.VISIBLE);
        overlayView.setPlaybackState(MediaPlaybackOverlayPainter.MediaPlaybackState.PREVIEW);
        overlayView.setOnClickListener(previewClickListener);
    } else {
        fileTypeIcon.setTag(null);
        overlayView.setTag(null);
        overlayView.setVisibility(View.GONE);
        overlayView.setPlaybackState(MediaPlaybackOverlayPainter.MediaPlaybackState.NONE);
    }
}

From source file:com.arlib.floatingsearchview.util.view.MenuView.java

/**
 * Resets the the view to fit into a new
 * available width./*from  ww  w.  j  a v a  2  s  .  com*/
 *
 * <p>This clears and then re-inflates the menu items
 * , removes all of its associated action views, and recreates
 * the menu and action items to fit in the new width.</p>
 *
 * @param availWidth the width available for the menu to use. If
 *                   there is room, menu items that are flagged with
 *                   android:showAsAction="ifRoom" or android:showAsAction="always"
 *                   will show as actions.
 */
public void reset(int availWidth) {

    if (mMenu == -1)
        return;

    //clean view first
    removeAllViews();
    mActionItems.clear();

    //reset menu
    mMenuBuilder.clearAll();
    getMenuInflater().inflate(mMenu, mMenuBuilder);

    int holdAllItemsCount;

    mMenuItems = mMenuBuilder.getActionItems();
    mMenuItems.addAll(mMenuBuilder.getNonActionItems());

    holdAllItemsCount = mMenuItems.size();

    Collections.sort(mMenuItems, new Comparator<MenuItemImpl>() {
        @Override
        public int compare(MenuItemImpl lhs, MenuItemImpl rhs) {
            return ((Integer) lhs.getOrder()).compareTo(rhs.getOrder());
        }
    });

    List<MenuItemImpl> menuItems = filter(mMenuItems, new MenuItemImplPredicate() {
        @Override
        public boolean apply(MenuItemImpl menuItem) {
            return menuItem.requiresActionButton() || menuItem.requestsActionButton();
        }
    });

    int availItemRoom = availWidth / (int) ACTION_DIMENSION_PX;
    boolean addOverflowAtTheEnd = false;
    if (((menuItems.size() < holdAllItemsCount) || availItemRoom < menuItems.size())) {
        addOverflowAtTheEnd = true;
        availItemRoom--;
    }

    ArrayList<Integer> actionMenuItems = new ArrayList<>();

    if (availItemRoom > 0)
        for (int i = 0; i < menuItems.size(); i++) {

            final MenuItemImpl menuItem = menuItems.get(i);

            if (menuItem.getIcon() != null) {

                ImageView action = getActionHolder();
                action.setImageDrawable(Util.setIconColor(menuItem.getIcon(), mActionIconColor));
                addView(action);
                mActionItems.add(menuItem);

                action.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        if (mMenuCallback != null)
                            mMenuCallback.onMenuItemSelected(mMenuBuilder, menuItem);
                    }
                });

                actionMenuItems.add(menuItem.getItemId());

                availItemRoom--;
                if (availItemRoom == 0)
                    break;
            }
        }

    if (addOverflowAtTheEnd) {

        ImageView overflowAction = getOverflowActionHolder();
        overflowAction.setImageDrawable(Util.setIconColor(
                getResources().getDrawable(R.drawable.ic_more_vert_black_24dp), mOverflowIconColor));
        addView(overflowAction);

        overflowAction.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                mMenuPopupHelper.show();
            }
        });

        mMenuBuilder.setCallback(mMenuCallback);

        mHasOverflow = true;
    }

    for (int id : actionMenuItems)
        mMenuBuilder.removeItem(id);

    actionMenuItems.clear();

    if (mOnVisibleWidthChanged != null)
        mOnVisibleWidthChanged.onVisibleWidthChanged(
                ((int) ACTION_DIMENSION_PX * getChildCount()) - (mHasOverflow ? Util.dpToPx(8) : 0));
}

From source file:com.sim2dial.dialer.StatusFragment.java

private void showZRTPDialog(final LinphoneCall call) {
    boolean authVerified = call.isAuthenticationTokenVerified();
    String format = getString(authVerified ? R.string.reset_sas_fmt : R.string.verify_sas_fmt);

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View layout = inflater.inflate(R.layout.zrtp_dialog,
            (ViewGroup) getActivity().findViewById(R.id.toastRoot));

    TextView toastText = (TextView) layout.findViewById(R.id.toastMessage);
    toastText.setText(String.format(format, call.getAuthenticationToken()));

    zrtpToast = new Toast(getActivity());
    zrtpToast.setGravity(Gravity.TOP | Gravity.RIGHT, 0, LinphoneUtils.pixelsToDpi(getResources(), 40));
    zrtpToast.setDuration(Toast.LENGTH_LONG);

    ImageView ok = (ImageView) layout.findViewById(R.id.toastOK);
    ok.setOnClickListener(new OnClickListener() {
        @Override/*  w ww.  ja v  a 2s  .  c o  m*/
        public void onClick(View v) {
            if (call != null) {
                call.setAuthenticationTokenVerified(true);
            }
            if (encryption != null) {
                encryption.setImageResource(R.drawable.security_ok);
            }
            hideZRTPDialog();
        }
    });

    ImageView notOk = (ImageView) layout.findViewById(R.id.toastNotOK);
    notOk.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (call != null) {
                call.setAuthenticationTokenVerified(false);
            }
            if (encryption != null) {
                encryption.setImageResource(R.drawable.security_pending);
            }
            hideZRTPDialog();
        }
    });

    zrtpHack = new CountDownTimer(3000, 1000) {
        public void onTick(long millisUntilFinished) {
            if (!hideZrtpToast) {
                zrtpToast.show();
            }
        }

        public void onFinish() {
            if (!hideZrtpToast) {
                zrtpToast.show();
                zrtpHack.start();
            }
        }

    };

    zrtpToast.setView(layout);
    hideZrtpToast = false;
    zrtpToast.show();
    zrtpHack.start();
}

From source file:com.gh4a.fragment.PullRequestFragment.java

private void fillData() {
    ImageView ivGravatar = (ImageView) mListHeaderView.findViewById(R.id.iv_gravatar);
    AvatarHandler.assignAvatar(ivGravatar, mPullRequest.getUser());
    ivGravatar.setTag(mPullRequest.getUser());
    ivGravatar.setOnClickListener(this);

    TextView tvExtra = (TextView) mListHeaderView.findViewById(R.id.tv_extra);
    tvExtra.setText(mPullRequest.getUser().getLogin());

    TextView tvTimestamp = (TextView) mListHeaderView.findViewById(R.id.tv_timestamp);
    tvTimestamp.setText(StringUtils.formatRelativeTime(getActivity(), mPullRequest.getCreatedAt(), true));

    String body = mPullRequest.getBodyHtml();
    TextView descriptionView = (TextView) mListHeaderView.findViewById(R.id.tv_desc);
    descriptionView.setMovementMethod(UiUtils.CHECKING_LINK_METHOD);
    if (!StringUtils.isBlank(body)) {
        body = HtmlUtils.format(body).toString();
        mImageGetter.bind(descriptionView, body, mPullRequest.getId());
    }/*from   www.j ava  2  s.  c  o m*/

    View milestoneGroup = mListHeaderView.findViewById(R.id.milestone_container);
    if (mPullRequest.getMilestone() != null) {
        TextView tvMilestone = (TextView) mListHeaderView.findViewById(R.id.tv_milestone);
        tvMilestone.setText(mPullRequest.getMilestone().getTitle());
        milestoneGroup.setVisibility(View.VISIBLE);
    } else {
        milestoneGroup.setVisibility(View.GONE);
    }

    View assigneeGroup = mListHeaderView.findViewById(R.id.assignee_container);
    if (mPullRequest.getAssignee() != null) {
        TextView tvAssignee = (TextView) mListHeaderView.findViewById(R.id.tv_assignee);
        tvAssignee.setText(mPullRequest.getAssignee().getLogin());

        ImageView ivAssignee = (ImageView) mListHeaderView.findViewById(R.id.iv_assignee);
        AvatarHandler.assignAvatar(ivAssignee, mPullRequest.getAssignee());
        ivAssignee.setTag(mPullRequest.getAssignee());
        ivAssignee.setOnClickListener(this);
        assigneeGroup.setVisibility(View.VISIBLE);
    } else {
        assigneeGroup.setVisibility(View.GONE);
    }

    if (mPullRequest.isMerged()) {
        setHighlightColors(R.attr.colorPullRequestMerged, R.attr.colorPullRequestMergedDark);
    } else if (Constants.Issue.STATE_CLOSED.equals(mPullRequest.getState())) {
        setHighlightColors(R.attr.colorIssueClosed, R.attr.colorIssueClosedDark);
    } else {
        setHighlightColors(R.attr.colorIssueOpen, R.attr.colorIssueOpenDark);
    }
}

From source file:com.pressurelabs.flowopensource.TheHubActivity.java

/**
 * Generates a Popup Menu with Two Actions Edit and Delete.
 *
 * Deleting the Flow removes the single card from the UI and also notifiers the AppDataManager to
 * delete from file//w w w  . ja  v a 2  s  .co  m
 *
 * Editing launches a renaming process
 *
* @param longClickedFlow Flow represented by cardview longclicked
  * @param cardPosition position of cardview in adapter
 * @param cardViewClicked the cardview view object clicked
 * @return
 */
private boolean showLongClickPopUpMenu(final Flow longClickedFlow, final int cardPosition,
        final View cardViewClicked) {
    LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = layoutInflater.inflate(R.layout.popup_window_longclick, null);

    LinearLayout viewGroup = (LinearLayout) layout.findViewById(R.id.popup_longclick);

    // Creating the PopupWindow
    final PopupWindow popup = new PopupWindow(layout, RecyclerView.LayoutParams.WRAP_CONTENT,
            RecyclerView.LayoutParams.WRAP_CONTENT);

    int dividerMargin = viewGroup.getDividerPadding(); // Top bottom
    int popupPadding = layout.getPaddingBottom();
    int popupDisplayHeight = -(cardViewClicked.getHeight() - dividerMargin - popupPadding);

    // Prevents border

    popup.setBackgroundDrawable(new ColorDrawable());
    popup.setFocusable(true);

    // Getting a reference to Close button, and close the popup when clicked.
    ImageView delete = (ImageView) layout.findViewById(R.id.popup_delete_item);

    delete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            /* Deletes current Flow from file and UI */
            rvContent.remove(cardPosition);
            manager.delete(longClickedFlow.getUuid());
            adapter.notifyItemRemoved(cardPosition);
            adapter.notifyItemRangeChanged(cardPosition, adapter.getItemCount());

            popup.dismiss();

            Snackbar bar = Snackbar.make(cardViewClicked, R.string.snackbar_hub_msg, Snackbar.LENGTH_LONG)
                    .setAction("NO!!!", new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            rvContent.add(cardPosition, longClickedFlow);
                            manager.save(longClickedFlow.getUuid(), longClickedFlow);
                            adapter.notifyItemInserted(cardPosition);
                        }
                    });

            bar.show();
        }
    });

    ImageView edit = (ImageView) layout.findViewById(R.id.popup_edit_item);

    edit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            popup.dismiss();
            renameFlow(cardPosition, cardViewClicked);

        }
    });

    // Displaying the popup at the specified location, + offsets.
    popup.showAsDropDown(cardViewClicked, cardViewClicked.getMeasuredWidth(), popupDisplayHeight, Gravity.TOP);
    longClickPopup = popup;
    return true;
}

From source file:com.doomy.padlock.MainActivity.java

private void openAboutDialog() {
    LayoutInflater mLayoutInflater = LayoutInflater.from(this);
    View mView = mLayoutInflater.inflate(R.layout.view_about, null);

    ImageView mImageViewMrDoomy = (ImageView) mView.findViewById(R.id.imageViewMrDoomy);
    ImageView mImageViewStudio = (ImageView) mView.findViewById(R.id.imageViewStudio);
    ImageView mImageViewGitHub = (ImageView) mView.findViewById(R.id.imageViewGitHub);
    Drawable mMrDoomy = mImageViewMrDoomy.getDrawable();
    Drawable mStudio = mImageViewStudio.getDrawable();
    Drawable mGitHub = mImageViewGitHub.getDrawable();
    mMrDoomy.setColorFilter(getResources().getColor(R.color.orangeDark), PorterDuff.Mode.SRC_ATOP);
    mStudio.setColorFilter(getResources().getColor(R.color.orange), PorterDuff.Mode.SRC_ATOP);
    mGitHub.setColorFilter(getResources().getColor(R.color.greyMaterialDark), PorterDuff.Mode.SRC_ATOP);

    mImageViewGitHub.setOnClickListener(new View.OnClickListener() {
        @Override//  ww  w  .  j  a v a2s. c o m
        public void onClick(View v) {
            Intent mIntent = new Intent();
            mIntent.setAction(Intent.ACTION_VIEW);
            mIntent.addCategory(Intent.CATEGORY_BROWSABLE);
            mIntent.setData(Uri.parse(getString(R.string.url)));
            startActivity(mIntent);
        }
    });

    AlertDialog.Builder mAlertDialog = new AlertDialog.Builder(MainActivity.this, R.style.DialogTheme);

    mAlertDialog.setTitle(getString(R.string.about));
    mAlertDialog.setView(mView);
    mAlertDialog.setPositiveButton(getString(R.string.okay), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    mAlertDialog.show();
}

From source file:com.pressurelabs.flowopensource.TheHubActivity.java

/**
 * Displays a popup window prompting the user to
 *
 * Confirm the changes to the name, saving the new name to file and updating the UI.
 *
 * Cancel the changes, returning the user back to the original state before editing
 *
 * @param newName new name to be used/* w  w w.  j  a  va 2s .c om*/
 * @param cardPosition position of cardview in adapter
 * @param cardViewClicked the cardview view object clicked
 * @param switcher the viewSwitcher object used to rename
 */
private void showEditPopupWindow(final EditText newName, View cardViewClicked, final ViewSwitcher switcher,
        final int cardPosition) {
    LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = layoutInflater.inflate(R.layout.popup_window_editing, null);

    LinearLayout viewGroup = (LinearLayout) layout.findViewById(R.id.popup_editing);

    // Creating the PopupWindow
    final PopupWindow popupEditing = new PopupWindow(layout, RecyclerView.LayoutParams.WRAP_CONTENT,
            RecyclerView.LayoutParams.WRAP_CONTENT);

    int dividerMargin = viewGroup.getDividerPadding(); // Top bottom
    int popupPadding = layout.getPaddingBottom();
    int popupDisplayHeight = -(cardViewClicked.getHeight() - dividerMargin - popupPadding);

    // Prevents border from appearing outside popupwindow
    popupEditing.setBackgroundDrawable(new ColorDrawable());
    popupEditing.setFocusable(false);

    // Getting a reference to Close button, and close the popup when clicked.
    ImageView confirmEdit = (ImageView) layout.findViewById(R.id.popup_confirm_item_changes);

    confirmEdit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Flow toChange = rvContent.get(cardPosition);
            if (newName.getText().toString().equals("")) {
                // Need to optimize this so that the dialog does NOT disappear and just display toast
                Toast.makeText(TheHubActivity.this, "This Flow needs a name!", Toast.LENGTH_LONG).show();
            } else {
                toChange.setName(newName.getText().toString());
                manager.overwrite(toChange.getUuid(), toChange);
                adapter.notifyDataSetChanged();
                switcher.showNext();
                menuState = AppConstants.MENU_ITEMS_NATIVE;
                invalidateOptionsMenu();
                popupEditing.dismiss();
                newName.clearFocus();
            }

        }
    });

    ImageView cancelEdit = (ImageView) layout.findViewById(R.id.popup_cancel_item_changes);

    cancelEdit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switcher.showNext();
            menuState = AppConstants.MENU_ITEMS_NATIVE;
            invalidateOptionsMenu();
            popupEditing.dismiss();
        }
    });

    // Displaying the popup at the specified location, + offsets.
    popupEditing.showAsDropDown(cardViewClicked, cardViewClicked.getMeasuredWidth(), popupDisplayHeight,
            Gravity.TOP);
    editingPopup = popupEditing;
}