Search in sources :

Example 6 with ListPopupWindow

use of android.widget.ListPopupWindow in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class EditUserPhotoController method showUpdatePhotoPopup.

private void showUpdatePhotoPopup() {
    final boolean canTakePhoto = canTakePhoto();
    final boolean canChoosePhoto = canChoosePhoto();
    if (!canTakePhoto && !canChoosePhoto) {
        return;
    }
    final Context context = mImageView.getContext();
    final List<EditUserPhotoController.RestrictedMenuItem> items = new ArrayList<>();
    if (canTakePhoto) {
        final String title = context.getString(R.string.user_image_take_photo);
        final Runnable action = new Runnable() {

            @Override
            public void run() {
                takePhoto();
            }
        };
        items.add(new RestrictedMenuItem(context, title, UserManager.DISALLOW_SET_USER_ICON, action));
    }
    if (canChoosePhoto) {
        final String title = context.getString(R.string.user_image_choose_photo);
        final Runnable action = new Runnable() {

            @Override
            public void run() {
                choosePhoto();
            }
        };
        items.add(new RestrictedMenuItem(context, title, UserManager.DISALLOW_SET_USER_ICON, action));
    }
    final ListPopupWindow listPopupWindow = new ListPopupWindow(context);
    listPopupWindow.setAnchorView(mImageView);
    listPopupWindow.setModal(true);
    listPopupWindow.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
    listPopupWindow.setAdapter(new RestrictedPopupMenuAdapter(context, items));
    final int width = Math.max(mImageView.getWidth(), context.getResources().getDimensionPixelSize(R.dimen.update_user_photo_popup_min_width));
    listPopupWindow.setWidth(width);
    listPopupWindow.setDropDownGravity(Gravity.START);
    listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            listPopupWindow.dismiss();
            final RestrictedMenuItem item = (RestrictedMenuItem) parent.getAdapter().getItem(position);
            item.doAction();
        }
    });
    listPopupWindow.show();
}
Also used : Context(android.content.Context) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) Paint(android.graphics.Paint) ListPopupWindow(android.widget.ListPopupWindow) AdapterView(android.widget.AdapterView)

Example 7 with ListPopupWindow

use of android.widget.ListPopupWindow in project AndroidChromium by JackyAndroid.

the class BookmarkRow method showMenu.

/**
     * Show drop-down menu after user click on more-info icon
     * @param view The anchor view for the menu
     */
private void showMenu(View view) {
    if (mPopupMenu == null) {
        mPopupMenu = new ListPopupWindow(getContext(), null, 0, R.style.BookmarkMenuStyle);
        mPopupMenu.setAdapter(new ArrayAdapter<String>(getContext(), R.layout.bookmark_popup_item, new String[] { getContext().getString(R.string.bookmark_item_select), getContext().getString(R.string.bookmark_item_edit), getContext().getString(R.string.bookmark_item_move), getContext().getString(R.string.bookmark_item_delete) }) {

            private static final int MOVE_POSITION = 2;

            @Override
            public boolean areAllItemsEnabled() {
                return false;
            }

            @Override
            public boolean isEnabled(int position) {
                // activity is killed (crbug.com/594213), so null check here.
                if (mDelegate == null || mDelegate.getModel() == null)
                    return false;
                if (position == MOVE_POSITION) {
                    BookmarkItem bookmark = mDelegate.getModel().getBookmarkById(mBookmarkId);
                    if (bookmark == null)
                        return false;
                    return bookmark.isMovable();
                }
                return true;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View view = super.getView(position, convertView, parent);
                view.setEnabled(isEnabled(position));
                return view;
            }
        });
        mPopupMenu.setAnchorView(view);
        mPopupMenu.setWidth(getResources().getDimensionPixelSize(R.dimen.bookmark_item_popup_width));
        mPopupMenu.setVerticalOffset(-view.getHeight());
        mPopupMenu.setModal(true);
        mPopupMenu.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position == 0) {
                    setChecked(mDelegate.getSelectionDelegate().toggleSelectionForItem(mBookmarkId));
                } else if (position == 1) {
                    BookmarkItem item = mDelegate.getModel().getBookmarkById(mBookmarkId);
                    if (item.isFolder()) {
                        BookmarkAddEditFolderActivity.startEditFolderActivity(getContext(), item.getId());
                    } else {
                        BookmarkUtils.startEditActivity(getContext(), item.getId());
                    }
                } else if (position == 2) {
                    BookmarkFolderSelectActivity.startFolderSelectActivity(getContext(), mBookmarkId);
                } else if (position == 3) {
                    if (mDelegate != null && mDelegate.getModel() != null) {
                        mDelegate.getModel().deleteBookmarks(mBookmarkId);
                    }
                }
                // http://crbug.com/600642
                if (mPopupMenu != null)
                    mPopupMenu.dismiss();
            }
        });
    }
    mPopupMenu.show();
    mPopupMenu.getListView().setDivider(null);
}
Also used : ListPopupWindow(android.widget.ListPopupWindow) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) ViewGroup(android.view.ViewGroup) BookmarkItem(org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem) ImageView(android.widget.ImageView) TextView(android.widget.TextView) SelectableItemView(org.chromium.chrome.browser.widget.selection.SelectableItemView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 8 with ListPopupWindow

use of android.widget.ListPopupWindow in project android_frameworks_base by ParanoidAndroid.

the class AutoCompletePopup method ensurePopup.

private void ensurePopup() {
    if (mPopup == null) {
        mPopup = new ListPopupWindow(mWebView.getContext());
        mAnchor = new AnchorView(mWebView.getContext());
        mWebView.getWebView().addView(mAnchor);
        mPopup.setOnItemClickListener(this);
        mPopup.setAnchorView(mAnchor);
        mPopup.setPromptPosition(ListPopupWindow.POSITION_PROMPT_BELOW);
    } else if (mWebView.getWebView().indexOfChild(mAnchor) < 0) {
        mWebView.getWebView().addView(mAnchor);
    }
}
Also used : ListPopupWindow(android.widget.ListPopupWindow)

Example 9 with ListPopupWindow

use of android.widget.ListPopupWindow in project Talon-for-Twitter by klinker24.

the class NewScheduledTweet method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    settings = AppSettings.getInstance(this);
    Utils.setUpTheme(this, settings);
    countHandler = new Handler();
    setContentView(R.layout.scheduled_new_tweet_activity);
    Intent intent = getIntent();
    sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
    context = this;
    mEditText = (EditText) findViewById(R.id.tweet_content);
    counter = (TextView) findViewById(R.id.char_remaining);
    emojiButton = (ImageButton) findViewById(R.id.emojiButton);
    emojiKeyboard = (EmojiKeyboard) findViewById(R.id.emojiKeyboard);
    // if they are coming from the compose window with text, then display it
    if (getIntent().getBooleanExtra("has_text", false)) {
        mEditText.setText(getIntent().getStringExtra("text"));
        mEditText.setSelection(mEditText.getText().length());
    }
    final ListPopupWindow autocomplete = new ListPopupWindow(context);
    autocomplete.setAnchorView(mEditText);
    autocomplete.setHeight(Utils.toDP(100, context));
    autocomplete.setWidth(Utils.toDP(275, context));
    try {
        autocomplete.setAdapter(new AutoCompletePeopleAdapter(context, FollowersDataSource.getInstance(context).getCursor(settings.currentAccount, mEditText.getText().toString()), mEditText));
    } catch (Exception e) {
    // not really sure why
    }
    autocomplete.setPromptPosition(ListPopupWindow.POSITION_PROMPT_ABOVE);
    autocomplete.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            autocomplete.dismiss();
        }
    });
    mEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            String searchText = mEditText.getText().toString();
            try {
                if (searchText.substring(searchText.length() - 1, searchText.length()).equals("@")) {
                    autocomplete.show();
                } else if (searchText.substring(searchText.length() - 1, searchText.length()).equals(" ")) {
                    autocomplete.dismiss();
                } else if (autocomplete.isShowing()) {
                    String[] split = mEditText.getText().toString().split(" ");
                    String adapterText;
                    if (split.length > 1) {
                        adapterText = split[split.length - 1];
                    } else {
                        adapterText = split[0];
                    }
                    adapterText = adapterText.replace("@", "");
                    autocomplete.setAdapter(new AutoCompletePeopleAdapter(context, FollowersDataSource.getInstance(context).getCursor(settings.currentAccount, adapterText), mEditText));
                }
            } catch (Exception e) {
                // there is no text
                try {
                    autocomplete.dismiss();
                } catch (Exception x) {
                // something went really wrong i guess haha
                }
            }
            countHandler.removeCallbacks(getCount);
            countHandler.postDelayed(getCount, 300);
        }
    });
    if (!sharedPrefs.getBoolean("keyboard_type", true)) {
        mEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
        mEditText.setImeOptions(EditorInfo.IME_ACTION_NONE);
    }
    startDate = intent.getStringExtra(ViewScheduledTweets.EXTRA_TIME);
    startMessage = intent.getStringExtra(ViewScheduledTweets.EXTRA_TEXT);
    if (TextUtils.isEmpty(startDate)) {
        startDate = "";
    }
    if (TextUtils.isEmpty(startMessage)) {
        startMessage = "";
    }
    final Calendar c = Calendar.getInstance();
    currentYear = c.get(Calendar.YEAR);
    currentMonth = c.get(Calendar.MONTH);
    currentDay = c.get(Calendar.DAY_OF_MONTH);
    currentHour = c.get(Calendar.HOUR_OF_DAY);
    currentMinute = c.get(Calendar.MINUTE);
    currentDate = new Date(currentYear, currentMonth, currentDay, currentHour, currentMinute);
    timeDisplay = (TextView) findViewById(R.id.currentTime);
    dateDisplay = (TextView) findViewById(R.id.currentDate);
    btDate = (Button) findViewById(R.id.setDate);
    btTime = (Button) findViewById(R.id.setTime);
    if (!startDate.equals("") && !startDate.equals("null")) {
        setDate = new Date(Long.parseLong(startDate));
        timeDone = true;
        btTime.setEnabled(true);
    } else {
        btTime.setEnabled(false);
    }
    if (mEditText.getText().toString().isEmpty()) {
        mEditText.setText(startMessage);
    }
    if (!startDate.equals("")) {
        Date startDateObj = new Date(Long.parseLong(startDate));
        if (sharedPrefs.getBoolean("hour_format", false)) {
            timeDisplay.setText(DateFormat.getTimeInstance(DateFormat.SHORT, Locale.GERMAN).format(startDateObj));
        } else {
            timeDisplay.setText(DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US).format(startDateObj));
        }
        if (sharedPrefs.getBoolean("hour_format", false)) {
            dateDisplay.setText(DateFormat.getDateInstance(DateFormat.MEDIUM).format(startDateObj));
        } else {
            dateDisplay.setText(DateFormat.getDateInstance(DateFormat.MEDIUM).format(startDateObj));
        }
    }
    if (!settings.useEmoji) {
        emojiButton.setVisibility(View.GONE);
    } else {
        emojiKeyboard.setAttached((HoloEditText) mEditText);
        mEditText.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (emojiKeyboard.isShowing()) {
                    emojiKeyboard.setVisibility(false);
                }
            }
        });
        emojiButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
                emojiKeyboard.toggleVisibility();
                RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) emojiKeyboard.getLayoutParams();
                params.topMargin = mEditText.getHeight();
                emojiKeyboard.setLayoutParams(params);
            }
        });
    }
    // sets the date button listener to call the dialog
    btDate.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            com.android.datetimepicker.date.DatePickerDialog.newInstance(reservationDate, currentYear, currentMonth, currentDay, settings.theme != AppSettings.THEME_LIGHT).show(getFragmentManager(), "date_picker");
            btTime.setEnabled(true);
        }
    });
    // sets the time button listener to call the dialog
    btTime.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            com.android.datetimepicker.time.TimePickerDialog dialog = com.android.datetimepicker.time.TimePickerDialog.newInstance(timeDate, currentHour, currentMinute, settings.militaryTime);
            if (settings.theme != AppSettings.THEME_LIGHT) {
                dialog.setThemeDark(true);
            }
            dialog.show(getFragmentManager(), "time_picker");
        }
    });
    // Inflate a "Done/Discard" custom action bar view.
    LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext().getSystemService(LAYOUT_INFLATER_SERVICE);
    final View customActionBarView = inflater.inflate(R.layout.actionbar_done_discard, null);
    FrameLayout done = (FrameLayout) customActionBarView.findViewById(R.id.actionbar_done);
    ((TextView) done.findViewById(R.id.done)).setText(R.string.done_label);
    done.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            doneClick();
        }
    });
    FrameLayout discard = (FrameLayout) customActionBarView.findViewById(R.id.actionbar_discard);
    if (!TextUtils.isEmpty(getIntent().getStringExtra(ViewScheduledTweets.EXTRA_TIME))) {
        ((TextView) discard.findViewById(R.id.discard)).setText(R.string.delete);
    }
    discard.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            discardClick();
        }
    });
    // Show the custom action bar view and hide the normal Home icon and title.
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
Also used : InputMethodManager(android.view.inputmethod.InputMethodManager) ListPopupWindow(android.widget.ListPopupWindow) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) HoloTextView(com.klinker.android.twitter.views.text.HoloTextView) ActionBar(android.app.ActionBar) Calendar(java.util.Calendar) Handler(android.os.Handler) Intent(android.content.Intent) AutoCompletePeopleAdapter(com.klinker.android.twitter.adapters.AutoCompletePeopleAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) HoloTextView(com.klinker.android.twitter.views.text.HoloTextView) Date(java.util.Date) LayoutInflater(android.view.LayoutInflater) FrameLayout(android.widget.FrameLayout) RelativeLayout(android.widget.RelativeLayout) AdapterView(android.widget.AdapterView)

Example 10 with ListPopupWindow

use of android.widget.ListPopupWindow in project xabber-android by redsolution.

the class CustomMessageMenu method showMenu.

public static void showMenu(Context context, View anchor, List<HashMap<String, String>> items, final AdapterView.OnItemClickListener itemClickListener, PopupWindow.OnDismissListener dismissListener) {
    // build popup
    final ListPopupWindow popup = new ListPopupWindow(context);
    CustomMessageMenuAdapter adapter = new CustomMessageMenuAdapter(context, items);
    popup.setAdapter(adapter);
    popup.setAnchorView(anchor);
    popup.setModal(true);
    popup.setSoftInputMode(SOFT_INPUT_ADJUST_NOTHING);
    popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            itemClickListener.onItemClick(parent, view, position, id);
            popup.dismiss();
        }
    });
    popup.setOnDismissListener(dismissListener);
    // measure content dimens
    ViewGroup mMeasureParent = null;
    int height = 0;
    int maxWidth = 0;
    View itemView = null;
    int itemType = 0;
    final int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    final int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    final int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        final int positionType = adapter.getItemViewType(i);
        if (positionType != itemType) {
            itemType = positionType;
            itemView = null;
        }
        if (mMeasureParent == null) {
            mMeasureParent = new FrameLayout(context);
        }
        itemView = adapter.getView(i, itemView, mMeasureParent);
        itemView.measure(widthMeasureSpec, heightMeasureSpec);
        final int itemHeight = itemView.getMeasuredHeight();
        final int itemWidth = itemView.getMeasuredWidth();
        if (itemWidth > maxWidth) {
            maxWidth = itemWidth;
        }
        height += itemHeight;
    }
    // set dimens and show
    popup.setWidth(maxWidth);
    popup.setHeight(height);
    popup.show();
}
Also used : CustomMessageMenuAdapter(com.xabber.android.ui.adapter.CustomMessageMenuAdapter) ListPopupWindow(android.widget.ListPopupWindow) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout) AdapterView(android.widget.AdapterView) View(android.view.View) AdapterView(android.widget.AdapterView)

Aggregations

ListPopupWindow (android.widget.ListPopupWindow)15 View (android.view.View)12 AdapterView (android.widget.AdapterView)11 TextView (android.widget.TextView)6 ImageView (android.widget.ImageView)4 ImageButton (android.widget.ImageButton)3 Context (android.content.Context)2 Intent (android.content.Intent)2 Paint (android.graphics.Paint)2 Point (android.graphics.Point)2 Handler (android.os.Handler)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 ViewGroup (android.view.ViewGroup)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 ArrayAdapter (android.widget.ArrayAdapter)2 FrameLayout (android.widget.FrameLayout)2 AutoCompletePeopleAdapter (com.klinker.android.twitter.adapters.AutoCompletePeopleAdapter)2 ArrayList (java.util.ArrayList)2 ActionBar (android.app.ActionBar)1