Example #1
0
  /**
   * Notifies the menu that the contents of the menu item specified by {@code menuRowId} have
   * changed. This should be called if icons, titles, etc. are changing for a particular menu item
   * while the menu is open.
   *
   * @param menuRowId The id of the menu item to change. This must be a row id and not a child id.
   */
  public void menuItemContentChanged(int menuRowId) {
    // Make sure we have all the valid state objects we need.
    if (mAdapter == null || mMenu == null || mPopup == null || mPopup.getListView() == null) {
      return;
    }

    // Calculate the item index.
    int index = -1;
    int menuSize = mMenu.size();
    for (int i = 0; i < menuSize; i++) {
      if (mMenu.getItem(i).getItemId() == menuRowId) {
        index = i;
        break;
      }
    }
    if (index == -1) return;

    // Check if the item is visible.
    ListView list = mPopup.getListView();
    int startIndex = list.getFirstVisiblePosition();
    int endIndex = list.getLastVisiblePosition();
    if (index < startIndex || index > endIndex) return;

    // Grab the correct View.
    View view = list.getChildAt(index - startIndex);
    if (view == null) return;

    // Cause the Adapter to re-populate the View.
    list.getAdapter().getView(index, view, list);
  }
Example #2
0
  @Override
  public void onPause() {
    // This is called because the lock screen was activated, the window stay
    // active under it and when we unlock the screen, we see the old time for
    // a fraction of a second.
    View v = getView();
    if (v != null) {
      v.setVisibility(View.INVISIBLE);
    }

    if (mState == Stopwatches.STOPWATCH_RUNNING) {
      stopUpdateThread();
    }
    // The stopwatch must keep running even if the user closes the app so save stopwatch state
    // in shared prefs
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    prefs.unregisterOnSharedPreferenceChangeListener(this);
    writeToSharedPref(prefs);
    mTime.writeToSharedPref(prefs, "sw");
    mTimeText.blinkTimeStr(false);
    if (mSharePopup != null) {
      mSharePopup.dismiss();
      mSharePopup = null;
    }
    ((DeskClock) getActivity()).unregisterPageChangedListener(this);
    releaseWakeLock();
    super.onPause();
  }
Example #3
0
  private void setPopupOffset(
      ListPopupWindow popup, int screenRotation, Rect appRect, Rect padding) {
    int[] anchorLocation = new int[2];
    popup.getAnchorView().getLocationInWindow(anchorLocation);
    int anchorHeight = popup.getAnchorView().getHeight();

    // If we have a hardware menu button, locate the app menu closer to the estimated
    // hardware menu button location.
    if (mIsByPermanentButton) {
      int horizontalOffset = -anchorLocation[0];
      switch (screenRotation) {
        case Surface.ROTATION_0:
        case Surface.ROTATION_180:
          horizontalOffset += (appRect.width() - mPopup.getWidth()) / 2;
          break;
        case Surface.ROTATION_90:
          horizontalOffset += appRect.width() - mPopup.getWidth();
          break;
        case Surface.ROTATION_270:
          break;
        default:
          assert false;
          break;
      }
      popup.setHorizontalOffset(horizontalOffset);
      // The menu is displayed above the anchored view, so shift the menu up by the bottom
      // padding of the background.
      popup.setVerticalOffset(-padding.bottom);
    } else {
      // The menu is displayed over and below the anchored view, so shift the menu up by the
      // height of the anchor view.
      popup.setVerticalOffset(-mNegativeSoftwareVerticalOffset - anchorHeight);
    }
  }
  // Initiate Popup Window
  private void initiatePopupWindow(View anchor) {
    try {
      Display display =
          ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
      ListPopupWindow popup = new ListPopupWindow(this);
      popup.setAnchorView(anchor);
      popup.setWidth((int) (display.getWidth() / (1.5)));
      ArrayAdapter<String> arrayAdapter =
          new ArrayAdapter<>(
              this,
              android.R.layout.simple_list_item_1,
              getResources().getStringArray(R.array.test_array));
      popup.setAdapter(arrayAdapter);
      popup.show();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #5
0
 /**
  * Method that shows a popup with the activity main menu.
  *
  * @param anchor The anchor of the popup
  */
 private void showOverflowPopUp(View anchor) {
   SimpleMenuListAdapter adapter = new HighlightedSimpleMenuListAdapter(this, R.menu.history);
   final ListPopupWindow popup = DialogHelper.createListPopupWindow(this, adapter, anchor);
   popup.setOnItemClickListener(
       new OnItemClickListener() {
         @Override
         public void onItemClick(
             final AdapterView<?> parent, final View v, final int position, final long id) {
           final int itemId = (int) id;
           switch (itemId) {
             case R.id.mnu_clear_history:
               popup.dismiss();
               clearHistory();
               break;
           }
         }
       });
   popup.show();
 }
Example #6
0
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
      mWindow.dismiss();

      return true;
    }

    return false;
  }
Example #7
0
  private void setMenuHeight(
      int numMenuItems, Rect appDimensions, int screenHeight, Rect padding, int footerHeight) {
    assert mPopup.getAnchorView() != null;
    View anchorView = mPopup.getAnchorView();
    int[] anchorViewLocation = new int[2];
    anchorView.getLocationOnScreen(anchorViewLocation);
    anchorViewLocation[1] -= appDimensions.top;
    int anchorViewImpactHeight = mIsByPermanentButton ? anchorView.getHeight() : 0;

    // Set appDimensions.height() for abnormal anchorViewLocation.
    if (anchorViewLocation[1] > screenHeight) {
      anchorViewLocation[1] = appDimensions.height();
    }
    int availableScreenSpace =
        Math.max(
            anchorViewLocation[1],
            appDimensions.height() - anchorViewLocation[1] - anchorViewImpactHeight);

    availableScreenSpace -= padding.bottom + footerHeight;
    if (mIsByPermanentButton) availableScreenSpace -= padding.top;

    int numCanFit = availableScreenSpace / (mItemRowHeight + mItemDividerHeight);

    // Fade out the last item if we cannot fit all items.
    if (numCanFit < numMenuItems) {
      int spaceForFullItems = numCanFit * (mItemRowHeight + mItemDividerHeight);
      int spaceForPartialItem = (int) (LAST_ITEM_SHOW_FRACTION * mItemRowHeight);
      // Determine which item needs hiding.
      if (spaceForFullItems + spaceForPartialItem < availableScreenSpace) {
        mPopup.setHeight(spaceForFullItems + spaceForPartialItem + padding.top + padding.bottom);
      } else {
        mPopup.setHeight(
            spaceForFullItems
                - mItemRowHeight
                + spaceForPartialItem
                + padding.top
                + padding.bottom);
      }
    } else {
      mPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    }
  }
Example #8
0
  public static void showPopupWindows(
      final View parent, final ListAdapter adapter, final PopupListener listener) {
    final ListPopupWindow listPopupWindow = new ListPopupWindow(parent.getContext());
    listPopupWindow.setAnchorView(parent);
    listPopupWindow.setModal(true);
    listener.onListenerPop(listPopupWindow);
    parent
        .getViewTreeObserver()
        .addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {
              @Override
              public void onGlobalLayout() {
                listPopupWindow.setWidth(parent.getWidth());
                listPopupWindow.setHeight(ListPopupWindow.WRAP_CONTENT);
                parent.getViewTreeObserver().removeGlobalOnLayoutListener(this);
              }
            });
    listPopupWindow.setAdapter(adapter);
    listPopupWindow.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parents, View view, int position, long id) {
            listener.onListItemClickBack(listPopupWindow, parent, position);
          }
        });
    listPopupWindow.show();
  }
  public void setPersoaneContact(List<BeanPersoanaContact> listPersoane) {

    if (listPersoane.size() > 0) {
      arrayPersoane = new String[listPersoane.size()];
      for (int i = 0; i < listPersoane.size(); i++)
        arrayPersoane[i] = listPersoane.get(i).getNume();

      arrayTelefoane = new String[listPersoane.size()];
      for (int i = 0; i < listPersoane.size(); i++)
        arrayTelefoane[i] = listPersoane.get(i).getTelefon();

      lpw.setAdapter(
          new ArrayAdapter<String>(
              getActivity(), android.R.layout.simple_list_item_1, arrayPersoane));
      lpw.setAnchorView(textPersoana);
      lpw.setModal(true);

      textPersoana.setText(arrayPersoane[0]);

      if (arrayTelefoane.length > 0) textTelefon.setText(arrayTelefoane[0]);
    }
  }
  /** {@inheritDoc} */
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    final Cursor cursor = (Cursor) mAdapter.getItem(position);
    loadTrack(cursor, true);

    if (cursor != null) {
      UIUtils.setLastUsedTrackID(
          getActivity(), cursor.getString(TracksAdapter.TracksQuery.TRACK_ID));
    } else {
      UIUtils.setLastUsedTrackID(getActivity(), ScheduleContract.Tracks.ALL_TRACK_ID);
    }

    if (mListPopupWindow != null) {
      mListPopupWindow.dismiss();
    }
  }
Example #11
0
 /**
  * Constructor for default vertical layout
  *
  * @param context Context
  */
 public PopupMenuNative(Context context, View view) {
   mContext = context;
   mView = view;
   mAdapter = new MenuAdapter(context);
   mMenu = new MenuImpl(mContext, mAdapter);
   mWindow = new ListPopupWindow(context);
   mWindow.setInputMethodMode(INPUT_METHOD_NOT_NEEDED);
   mWindow.setAnchorView(mView);
   mWindow.setWidth(mContext.getResources().getDimensionPixelSize(R.dimen.popup_window_width));
   mWindow.setAdapter(mAdapter);
   mWindow.setOnItemClickListener(this);
   mWindow.setPromptPosition(ListPopupWindow.POSITION_PROMPT_BELOW);
   mWindow.setModal(true);
 }
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.date_livrare_retur_marfa, container, false);

    spinnerDataRetur = (Spinner) v.findViewById(R.id.spinnerDataRetur);
    populateSpinnerDataRetur();
    setListenerSpinnerData();

    spinnerTransport = (Spinner) v.findViewById(R.id.spinnerTranspRetur);
    populateSpinnerTransport();
    setListenerSpinnerTransport();

    spinnerMotivRetur = (Spinner) v.findViewById(R.id.spinnerMotivRetur);
    populateSpinnerMotivRetur();
    setListenerSpinnerRetur();

    spinnerAdresaRetur = (Spinner) v.findViewById(R.id.spinnerAdresaRetur);
    setSpinnerAdresaListener();
    layoutAdresaNoua = (LinearLayout) v.findViewById(R.id.layoutAdresa);
    layoutAdresaNoua.setVisibility(View.GONE);

    spinnerJudet = (Spinner) v.findViewById(R.id.spinnerJudet);
    setSpinnerJudetListener();
    textOras = (EditText) v.findViewById(R.id.textOras);
    setTextOrasListener();
    textStrada = (EditText) v.findViewById(R.id.textStrada);
    setTextStradaListener();

    textPersoana = (EditText) v.findViewById(R.id.textPersoana);
    textPersoana.setOnTouchListener(this);
    setTextPersoanaListener();
    lpw = new ListPopupWindow(getActivity());
    lpw.setOnItemClickListener(this);

    textTelefon = (EditText) v.findViewById(R.id.textTelefon);
    setTextTelefonListener();

    textObservatii = (EditText) v.findViewById(R.id.textObservatii);
    setTextObservatiiListener();

    btnPozitieAdresa = (Button) v.findViewById(R.id.btnPozitieAdresa);
    setListnerBtnPozitieAdresa();

    return v;
  }
        @Override
        public boolean onLongClick(View v) {
          String[] versions = {"Camera", "Laptop", "Watch", "Smartphone", "Television"};
          final ListPopupWindow listPopupWindow = new ListPopupWindow(getActivity());
          listPopupWindow.setAdapter(
              new ArrayAdapter<String>(
                  getActivity(), android.R.layout.simple_dropdown_item_1line, versions));
          listPopupWindow.setAnchorView(mListPopupButton);
          listPopupWindow.setWidth(300);
          listPopupWindow.setHeight(400);

          listPopupWindow.setModal(true);
          listPopupWindow.show();
          return false;
        }
  public boolean onTouch(View v, MotionEvent event) {
    final int DRAWABLE_RIGHT = 2;

    try {

      if (event.getAction() == MotionEvent.ACTION_UP) {
        if (event.getX()
            >= (v.getWidth()
                - ((EditText) v).getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
          lpw.show();
          return true;
        }
      }
    } catch (Exception ex) {

    }
    return false;
  }
  public void reloadFromArguments(Bundle arguments) {
    // Teardown from previous arguments
    if (mListPopupWindow != null) {
      mListPopupWindow.setAdapter(null);
    }
    if (mCursor != null) {
      getActivity().stopManagingCursor(mCursor);
      mCursor = null;
    }
    mHandler.cancelOperation(TracksAdapter.TracksQuery._TOKEN);

    // Load new arguments
    final Intent intent = BaseActivity.fragmentArgumentsToIntent(arguments);
    final Uri tracksUri = intent.getData();
    if (tracksUri == null) {
      return;
    }

    mNextType = intent.getStringExtra(EXTRA_NEXT_TYPE);

    // Filter our tracks query to only include those with valid results
    String[] projection = TracksAdapter.TracksQuery.PROJECTION;
    String selection = null;
    if (TracksFragment.NEXT_TYPE_SESSIONS.equals(mNextType)) {
      // Only show tracks with at least one session
      projection = TracksAdapter.TracksQuery.PROJECTION_WITH_SESSIONS_COUNT;
      selection = ScheduleContract.Tracks.SESSIONS_COUNT + ">0";

    } else if (TracksFragment.NEXT_TYPE_VENDORS.equals(mNextType)) {
      // Only show tracks with at least one vendor
      projection = TracksAdapter.TracksQuery.PROJECTION_WITH_VENDORS_COUNT;
      selection = ScheduleContract.Tracks.VENDORS_COUNT + ">0";
    }

    // Start background query to load tracks
    mHandler.startQuery(
        TracksAdapter.TracksQuery._TOKEN,
        null,
        tracksUri,
        projection,
        selection,
        null,
        ScheduleContract.Tracks.DEFAULT_SORT);
  }
 public void setGroupMetaData(Cursor groupMetaData) {
   this.mGroupMetaData = groupMetaData;
   updateView();
   // Open up the list of groups if a new group was just created.
   if (mCreatedNewGroup) {
     mCreatedNewGroup = false;
     onClick(this); // This causes the popup to open.
     if (mPopup != null) {
       // Ensure that the newly created group is checked.
       int position = mAdapter.getCount() - 2;
       ListView listView = mPopup.getListView();
       if (!listView.isItemChecked(position)) {
         // Newly created group is not checked, so check it.
         listView.setItemChecked(position, true);
         onItemClick(listView, null, position, listView.getItemIdAtPosition(position));
       }
     }
   }
 }
Example #17
0
  @Override
  public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (mPopup == null || mPopup.getListView() == null) return false;

    if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
      if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
        event.startTracking();
        v.getKeyDispatcherState().startTracking(event, this);
        return true;
      } else if (event.getAction() == KeyEvent.ACTION_UP) {
        v.getKeyDispatcherState().handleUpEvent(event);
        if (event.isTracking() && !event.isCanceled()) {
          dismiss();
          return true;
        }
      }
    }
    return false;
  }
  @Override
  public void onClick(View v) {
    if (UiClosables.closeQuietly(mPopup)) {
      return;
    }

    mAdapter =
        new GroupMembershipAdapter<GroupSelectionItem>(
            getContext(), R.layout.group_membership_list_item);

    mGroupMetaData.moveToPosition(-1);
    while (mGroupMetaData.moveToNext()) {
      String accountName = mGroupMetaData.getString(GroupMetaDataLoader.ACCOUNT_NAME);
      String accountType = mGroupMetaData.getString(GroupMetaDataLoader.ACCOUNT_TYPE);
      String dataSet = mGroupMetaData.getString(GroupMetaDataLoader.DATA_SET);
      if (accountName.equals(mAccountName)
          && accountType.equals(mAccountType)
          && Objects.equal(dataSet, mDataSet)) {
        long groupId = mGroupMetaData.getLong(GroupMetaDataLoader.GROUP_ID);
        if (groupId != mFavoritesGroupId && (groupId != mDefaultGroupId || mDefaultGroupVisible)) {
          String title = mGroupMetaData.getString(GroupMetaDataLoader.TITLE);
          boolean checked = hasMembership(groupId);
          mAdapter.add(new GroupSelectionItem(groupId, title, checked));
        }
      }
    }

    mAdapter.add(
        new GroupSelectionItem(
            CREATE_NEW_GROUP_GROUP_ID,
            getContext().getString(R.string.create_group_item_label),
            false));

    mPopup = new ListPopupWindow(getContext(), null);
    mPopup.setAnchorView(mGroupList);
    mPopup.setAdapter(mAdapter);
    mPopup.setModal(true);
    mPopup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
    mPopup.show();

    ListView listView = mPopup.getListView();
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    listView.setOverScrollMode(OVER_SCROLL_ALWAYS);
    int count = mAdapter.getCount();
    for (int i = 0; i < count; i++) {
      listView.setItemChecked(i, mAdapter.getItem(i).isChecked());
    }

    listView.setOnItemClickListener(this);
  }
Example #19
0
  private void runMenuItemEnterAnimations() {
    mMenuItemEnterAnimator = new AnimatorSet();
    AnimatorSet.Builder builder = null;

    ViewGroup list = mPopup.getListView();
    for (int i = 0; i < list.getChildCount(); i++) {
      View view = list.getChildAt(i);
      Object animatorObject = view.getTag(R.id.menu_item_enter_anim_id);
      if (animatorObject != null) {
        if (builder == null) {
          builder = mMenuItemEnterAnimator.play((Animator) animatorObject);
        } else {
          builder.with((Animator) animatorObject);
        }
      }
    }

    mMenuItemEnterAnimator.addListener(mAnimationHistogramRecorder);
    mMenuItemEnterAnimator.start();
  }
Example #20
0
  /**
   * Creates and shows the app menu anchored to the specified view.
   *
   * @param context The context of the AppMenu (ensure the proper theme is set on this context).
   * @param anchorView The anchor {@link View} of the {@link ListPopupWindow}.
   * @param isByPermanentButton Whether or not permanent hardware button triggered it. (oppose to
   *     software button or keyboard).
   * @param screenRotation Current device screen rotation.
   * @param visibleDisplayFrame The display area rect in which AppMenu is supposed to fit in.
   * @param screenHeight Current device screen height.
   * @param footerResourceId The resource id for a view to add to the end of the menu list. Can be 0
   *     if no such view is required.
   */
  void show(
      Context context,
      View anchorView,
      boolean isByPermanentButton,
      int screenRotation,
      Rect visibleDisplayFrame,
      int screenHeight,
      int footerResourceId) {
    mPopup = new ListPopupWindow(context, null, android.R.attr.popupMenuStyle);
    mPopup.setModal(true);
    mPopup.setAnchorView(anchorView);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);

    int footerHeight = 0;
    if (footerResourceId != 0) {
      mPopup.setPromptPosition(ListPopupWindow.POSITION_PROMPT_BELOW);
      View promptView = LayoutInflater.from(context).inflate(footerResourceId, null);
      mPopup.setPromptView(promptView);
      int measureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
      promptView.measure(measureSpec, measureSpec);
      footerHeight = promptView.getMeasuredHeight();
    }
    mPopup.setOnDismissListener(
        new OnDismissListener() {
          @Override
          public void onDismiss() {
            if (mPopup.getAnchorView() instanceof ImageButton) {
              ((ImageButton) mPopup.getAnchorView()).setSelected(false);
            }

            if (mMenuItemEnterAnimator != null) mMenuItemEnterAnimator.cancel();

            mHandler.appMenuDismissed();
            mHandler.onMenuVisibilityChanged(false);
          }
        });

    // Some OEMs don't actually let us change the background... but they still return the
    // padding of the new background, which breaks the menu height.  If we still have a
    // drawable here even though our style says @null we should use this padding instead...
    Drawable originalBgDrawable = mPopup.getBackground();

    // Need to explicitly set the background here.  Relying on it being set in the style caused
    // an incorrectly drawn background.
    if (isByPermanentButton) {
      mPopup.setBackgroundDrawable(
          ApiCompatibilityUtils.getDrawable(context.getResources(), R.drawable.menu_bg));
    } else {
      mPopup.setBackgroundDrawable(
          ApiCompatibilityUtils.getDrawable(context.getResources(), R.drawable.edge_menu_bg));
      mPopup.setAnimationStyle(R.style.OverflowMenuAnim);
    }

    // Turn off window animations for low end devices, and on Android M, which has built-in menu
    // animations.
    if (SysUtils.isLowEndDevice() || Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
      mPopup.setAnimationStyle(0);
    }

    Rect bgPadding = new Rect();
    mPopup.getBackground().getPadding(bgPadding);

    int popupWidth =
        context.getResources().getDimensionPixelSize(R.dimen.menu_width)
            + bgPadding.left
            + bgPadding.right;

    mPopup.setWidth(popupWidth);

    mCurrentScreenRotation = screenRotation;
    mIsByPermanentButton = isByPermanentButton;

    // Extract visible items from the Menu.
    int numItems = mMenu.size();
    List<MenuItem> menuItems = new ArrayList<MenuItem>();
    for (int i = 0; i < numItems; ++i) {
      MenuItem item = mMenu.getItem(i);
      if (item.isVisible()) {
        menuItems.add(item);
      }
    }

    Rect sizingPadding = new Rect(bgPadding);
    if (isByPermanentButton && originalBgDrawable != null) {
      Rect originalPadding = new Rect();
      originalBgDrawable.getPadding(originalPadding);
      sizingPadding.top = originalPadding.top;
      sizingPadding.bottom = originalPadding.bottom;
    }

    // A List adapter for visible items in the Menu. The first row is added as a header to the
    // list view.
    mAdapter = new AppMenuAdapter(this, menuItems, LayoutInflater.from(context));
    mPopup.setAdapter(mAdapter);

    setMenuHeight(menuItems.size(), visibleDisplayFrame, screenHeight, sizingPadding, footerHeight);
    setPopupOffset(mPopup, mCurrentScreenRotation, visibleDisplayFrame, sizingPadding);
    mPopup.setOnItemClickListener(this);
    mPopup.show();
    mPopup.getListView().setItemsCanFocus(true);
    mPopup.getListView().setOnKeyListener(this);

    mHandler.onMenuVisibilityChanged(true);

    if (mVerticalFadeDistance > 0) {
      mPopup.getListView().setVerticalFadingEdgeEnabled(true);
      mPopup.getListView().setFadingEdgeLength(mVerticalFadeDistance);
    }

    // Don't animate the menu items for low end devices.
    if (!SysUtils.isLowEndDevice() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
      mPopup
          .getListView()
          .addOnLayoutChangeListener(
              new View.OnLayoutChangeListener() {
                @Override
                public void onLayoutChange(
                    View v,
                    int left,
                    int top,
                    int right,
                    int bottom,
                    int oldLeft,
                    int oldTop,
                    int oldRight,
                    int oldBottom) {
                  mPopup.getListView().removeOnLayoutChangeListener(this);
                  runMenuItemEnterAnimations();
                }
              });
    }
  }
Example #21
0
  /**
   * Set listener for window dismissed. This listener will only be fired if the quickaction dialog
   * is dismissed by clicking outside the dialog or clicking on sticky item.
   */
  @Override
  public void setOnDismissListener(PopupMenu.OnDismissListener listener) {
    mWindow.setOnDismissListener(listener != null ? this : null);

    mDismissListener = listener;
  }
Example #22
0
 private boolean isPopupWindowShowing() {
   if (mWindow == null) return false;
   return mWindow.isShowing();
 }
  public static ListPopupWindow createPopupMenu(
      Context context, View anchorView, final Listener listener, int mode) {
    // Build choices, depending on the current mode. We assume this Dialog is never called
    // if there are NO choices (e.g. a read-only picture is already super-primary)
    final ArrayList<ChoiceListItem> choices = new ArrayList<ChoiceListItem>(4);
    // Use as Primary
    if (mode == MODE_PHOTO_ALLOW_PRIMARY || mode == MODE_READ_ONLY_ALLOW_PRIMARY) {
      choices.add(
          new ChoiceListItem(
              ChoiceListItem.ID_USE_AS_PRIMARY, context.getString(R.string.use_photo_as_primary)));
    }
    // Remove
    if (mode == MODE_PHOTO_DISALLOW_PRIMARY || mode == MODE_PHOTO_ALLOW_PRIMARY) {
      choices.add(
          new ChoiceListItem(ChoiceListItem.ID_REMOVE, context.getString(R.string.removePhoto)));
    }
    // Take photo (if there is already a photo, it says "Take new photo")
    if (mode == MODE_NO_PHOTO
        || mode == MODE_PHOTO_ALLOW_PRIMARY
        || mode == MODE_PHOTO_DISALLOW_PRIMARY) {
      final int resId = mode == MODE_NO_PHOTO ? R.string.take_photo : R.string.take_new_photo;
      choices.add(new ChoiceListItem(ChoiceListItem.ID_TAKE_PHOTO, context.getString(resId)));
    }
    // Select from Gallery (or "Select new from Gallery")
    if (mode == MODE_NO_PHOTO
        || mode == MODE_PHOTO_ALLOW_PRIMARY
        || mode == MODE_PHOTO_DISALLOW_PRIMARY) {
      final int resId = mode == MODE_NO_PHOTO ? R.string.pick_photo : R.string.pick_new_photo;
      choices.add(new ChoiceListItem(ChoiceListItem.ID_PICK_PHOTO, context.getString(resId)));
    }
    final ListAdapter adapter =
        new ArrayAdapter<ChoiceListItem>(context, R.layout.select_dialog_item, choices);

    final ListPopupWindow listPopupWindow = new ListPopupWindow(context);
    final OnItemClickListener clickListener =
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final ChoiceListItem choice = choices.get(position);
            listPopupWindow.dismiss();

            switch (choice.getId()) {
              case ChoiceListItem.ID_USE_AS_PRIMARY:
                listener.onUseAsPrimaryChosen();
                break;
              case ChoiceListItem.ID_REMOVE:
                listener.onRemovePictureChosen();
                break;
              case ChoiceListItem.ID_TAKE_PHOTO:
                listener.onTakePhotoChosen();
                break;
              case ChoiceListItem.ID_PICK_PHOTO:
                listener.onPickFromGalleryChosen();
                break;
            }
          }
        };

    listPopupWindow.setAnchorView(anchorView);
    listPopupWindow.setAdapter(adapter);
    listPopupWindow.setOnItemClickListener(clickListener);
    listPopupWindow.setWidth(
        context.getResources().getDimensionPixelSize(R.dimen.photo_action_popup_width));
    listPopupWindow.setModal(true);
    listPopupWindow.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
    return listPopupWindow;
  }
Example #24
0
 private void showMenu(Menu menu) {
   mAdapter.setMenu(menu);
   mWindow.show();
 }
Example #25
0
 /** Dismiss the popup window. */
 @Override
 public void dismiss() {
   if (isPopupWindowShowing()) {
     mWindow.dismiss();
   }
 }
Example #26
0
 /** @return Whether the app menu is currently showing. */
 boolean isShowing() {
   if (mPopup == null) {
     return false;
   }
   return mPopup.isShowing();
 }
Example #27
0
 /** Dismisses the app menu and cancels the drag-to-scroll if it is taking place. */
 void dismiss() {
   if (isShowing()) {
     mPopup.dismiss();
   }
 }
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   textPersoana.setText(arrayPersoane[position]);
   textTelefon.setText(arrayTelefoane[position]);
   lpw.dismiss();
 }
Example #29
0
  private void showSharePopup() {
    Intent intent = getShareIntent();

    Activity parent = getActivity();
    PackageManager packageManager = parent.getPackageManager();

    // Get a list of sharable options.
    List<ResolveInfo> shareOptions =
        packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

    if (shareOptions.size() == 0) {
      return;
    }
    ArrayList<CharSequence> shareOptionTitles = new ArrayList<CharSequence>();
    ArrayList<Drawable> shareOptionIcons = new ArrayList<Drawable>();
    ArrayList<CharSequence> shareOptionThreeTitles = new ArrayList<CharSequence>();
    ArrayList<Drawable> shareOptionThreeIcons = new ArrayList<Drawable>();
    ArrayList<String> shareOptionPackageNames = new ArrayList<String>();
    ArrayList<String> shareOptionClassNames = new ArrayList<String>();

    for (int option_i = 0; option_i < shareOptions.size(); option_i++) {
      ResolveInfo option = shareOptions.get(option_i);
      CharSequence label = option.loadLabel(packageManager);
      Drawable icon = option.loadIcon(packageManager);
      shareOptionTitles.add(label);
      shareOptionIcons.add(icon);
      if (shareOptions.size() > 4 && option_i < 3) {
        shareOptionThreeTitles.add(label);
        shareOptionThreeIcons.add(icon);
      }
      shareOptionPackageNames.add(option.activityInfo.packageName);
      shareOptionClassNames.add(option.activityInfo.name);
    }
    if (shareOptionTitles.size() > 4) {
      shareOptionThreeTitles.add(getResources().getString(R.string.see_all));
      shareOptionThreeIcons.add(getResources().getDrawable(android.R.color.transparent));
    }

    if (mSharePopup != null) {
      mSharePopup.dismiss();
      mSharePopup = null;
    }
    mSharePopup = new ListPopupWindow(parent);
    mSharePopup.setAnchorView(mShareButton);
    mSharePopup.setModal(true);
    // This adapter to show the rest will be used to quickly repopulate if "See all..." is hit.
    ImageLabelAdapter showAllAdapter =
        new ImageLabelAdapter(
            parent,
            R.layout.popup_window_item,
            shareOptionTitles,
            shareOptionIcons,
            shareOptionPackageNames,
            shareOptionClassNames);
    if (shareOptionTitles.size() > 4) {
      mSharePopup.setAdapter(
          new ImageLabelAdapter(
              parent,
              R.layout.popup_window_item,
              shareOptionThreeTitles,
              shareOptionThreeIcons,
              shareOptionPackageNames,
              shareOptionClassNames,
              showAllAdapter));
    } else {
      mSharePopup.setAdapter(showAllAdapter);
    }

    mSharePopup.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CharSequence label = ((TextView) view.findViewById(R.id.title)).getText();
            if (label.equals(getResources().getString(R.string.see_all))) {
              mSharePopup.setAdapter(((ImageLabelAdapter) parent.getAdapter()).getShowAllAdapter());
              mSharePopup.show();
              return;
            }

            Intent intent = getShareIntent();
            ImageLabelAdapter adapter = (ImageLabelAdapter) parent.getAdapter();
            String packageName = adapter.getPackageName(position);
            String className = adapter.getClassName(position);
            intent.setClassName(packageName, className);
            startActivity(intent);
          }
        });
    mSharePopup.setOnDismissListener(
        new OnDismissListener() {
          @Override
          public void onDismiss() {
            mSharePopup = null;
          }
        });
    mSharePopup.setWidth((int) getResources().getDimension(R.dimen.popup_window_width));
    mSharePopup.show();
  }