use of android.widget.ListPopupWindow in project robolectric by robolectric.
the class ShadowListPopupWindowTest method show_setsLastListPopupWindow.
@Test
public void show_setsLastListPopupWindow() {
Context context = ApplicationProvider.getApplicationContext();
ListPopupWindow popupWindow = new ListPopupWindow(context);
assertThat(ShadowListPopupWindow.getLatestListPopupWindow()).isNull();
popupWindow.setAnchorView(new View(context));
popupWindow.show();
assertThat(ShadowListPopupWindow.getLatestListPopupWindow()).isSameInstanceAs(popupWindow);
}
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));
}
use of android.widget.ListPopupWindow in project FlexibleAdapter by davideas.
the class BottomSheetSectionDialog method createPopUps.
private void createPopUps() {
// Create the Adapter
if (mAdapterReference == null) {
mAdapterItemType = new ArrayAdapter(getContext(), R.layout.reference_spinner_item, new String[] { "Simple Item", "Expandable", "Expandable Section", "Section" });
mAdapterReference = new ArrayAdapter(getContext(), R.layout.reference_spinner_item, getListener().getReferenceList());
}
// Setting up the popups
Log.d(TAG, "Setting up the Popups");
// Item Type
mPopupItemType = new ListPopupWindow(getContext());
mPopupItemType.setAnchorView(mBottomSheetDialog.findViewById(R.id.select_item_type));
mPopupItemType.setModal(true);
mPopupItemType.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
mPopupItemType.setAnimationStyle(android.R.style.Animation_Dialog);
mPopupItemType.setAdapter(mAdapterItemType);
mPopupItemType.setVerticalOffset(-100);
// Header Reference
mPopupReference = new ListPopupWindow(getContext());
mPopupReference.setAnchorView(mBottomSheetDialog.findViewById(R.id.select_reference_button));
mPopupReference.setModal(true);
mPopupReference.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
mPopupReference.setAnimationStyle(android.R.style.Animation_Dialog);
mPopupReference.setAdapter(mAdapterReference);
mPopupReference.setVerticalOffset(-100);
if (mAdapterReference.getCount() > 6)
mPopupReference.setHeight(getResources().getDimensionPixelSize(R.dimen.popup_max_height));
}
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();
}
use of android.widget.ListPopupWindow in project android_frameworks_base by ParanoidAndroid.
the class MenuPopupHelper method tryShow.
public boolean tryShow() {
mPopup = new ListPopupWindow(mContext, null, com.android.internal.R.attr.popupMenuStyle);
mPopup.setOnDismissListener(this);
mPopup.setOnItemClickListener(this);
mAdapter = new MenuAdapter(mMenu);
mPopup.setAdapter(mAdapter);
mPopup.setModal(true);
View anchor = mAnchorView;
if (anchor != null) {
final boolean addGlobalListener = mTreeObserver == null;
// Refresh to latest
mTreeObserver = anchor.getViewTreeObserver();
if (addGlobalListener)
mTreeObserver.addOnGlobalLayoutListener(this);
anchor.addOnAttachStateChangeListener(this);
mPopup.setAnchorView(anchor);
} else {
return false;
}
mPopup.setContentWidth(Math.min(measureContentWidth(mAdapter), mPopupMaxWidth));
mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
mPopup.show();
mPopup.getListView().setOnKeyListener(this);
return true;
}
Aggregations