private int getScroll() {
   View c = leftView.getChildAt(0); // this is the first visible row
   int scrollY = -c.getTop();
   listViewItemHeights.put(leftView.getFirstVisiblePosition(), c.getHeight());
   for (int i = 0; i < leftView.getFirstVisiblePosition(); ++i) {
     if (listViewItemHeights.get(i) != null) // (this is a sanity check)
     scrollY += listViewItemHeights.get(i); // add all heights of the views that are gone
   }
   return scrollY;
 }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Refresh the app that was just edited, if it's visible in the list
    ListView list = (ListView) findViewById(R.id.lstApps);
    if (requestCode >= list.getFirstVisiblePosition()
        && requestCode <= list.getLastVisiblePosition()) {
      View v = list.getChildAt(requestCode - list.getFirstVisiblePosition());
      list.getAdapter().getView(requestCode, v, list);
    }
  }
  /**
   * This simple implementation creates a Bitmap copy of the list item currently shown at ListView
   * <code>position</code>.
   */
  @Override
  public View onCreateFloatView(int position) {
    // Guaranteed that this will not be null? I think so. Nope, got
    // a NullPointerException once...
    View v =
        mListView.getChildAt(
            position + mListView.getHeaderViewsCount() - mListView.getFirstVisiblePosition());

    if (v == null) {
      return null;
    }

    v.setPressed(false);

    // Create a copy of the drawing cache so that it does not get
    // recycled by the framework when the list tries to clean up memory
    // v.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
    v.setDrawingCacheEnabled(true);
    mFloatBitmap = Bitmap.createBitmap(v.getDrawingCache());
    v.setDrawingCacheEnabled(false);

    if (mImageView == null) {
      mImageView = new ImageView(mListView.getContext());
    }
    mImageView.setBackgroundColor(mFloatBGColor);
    mImageView.setPadding(0, 0, 0, 0);
    mImageView.setImageBitmap(mFloatBitmap);
    mImageView.setLayoutParams(new ViewGroup.LayoutParams(v.getWidth(), v.getHeight()));

    return mImageView;
  }
Пример #4
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);
  }
Пример #5
0
  @Override
  public void onResume() {
    super.onResume();

    // Format the most recently clicked item upon returning from info page
    if (ListData.indexLastClicked != 99) {
      int idx = ListData.indexLastClicked;
      RelativeLayout lastClicked =
          (RelativeLayout)
              theListView.getChildAt(
                  ListData.indexLastClicked - theListView.getFirstVisiblePosition());
      TextView v = (TextView) lastClicked.getChildAt(0);
      TextView w = (TextView) lastClicked.getChildAt(1);
      boolean completed = ListData.getCompletedList().get(ListData.indexLastClicked);

      if (completed) {
        v.setTextColor(Color.LTGRAY);
        w.setText("DONE!");
        w.setTextColor(Color.parseColor("#73e600"));

      } else {
        v.setTextColor(Color.BLACK);
        w.setText("\u2705");
        w.setTextColor(Color.LTGRAY);
      }
    }
  }
Пример #6
0
  /**
   * Pushes data into list adapter.
   *
   * @param data the data to push
   */
  @UiThread
  protected void updateListView(PaginatedList<Artist> data) {
    if (loadingProgressBar.getVisibility() == View.VISIBLE)
      loadingProgressBar.setVisibility(View.INVISIBLE);

    if (data.getCount() <= 0) {
      Toast.makeText(this, "No singer was found", Toast.LENGTH_LONG).show();
      this.finish();
      return;
    }

    if (artistsFound == null) artistsFound = new PaginatedList<Artist>(data);
    else artistsFound.addItems(data.getItems());

    list = (ListView) findViewById(android.R.id.list);

    // If the adapter doesn't exist, we create one with the initial data.
    // If it exists, we update it.
    int currentPosition = -1;
    if (adapter == null) {
      adapter = new ArtistsListAdapter(this, data.getItems());
    } else {
      currentPosition = list.getFirstVisiblePosition();
      adapter.addItems(data.getItems());
    }
    list.setAdapter(adapter);

    list.setSelectionFromTop(currentPosition + 1, 0);

    if (artistsFound.getPaging().isLast()) list.removeFooterView(loadMoreProgress);

    this.isLoading = false;
  }
Пример #7
0
 private void reset() {
   int begin = mListView.getFirstVisiblePosition();
   int end = mListView.getLastVisiblePosition();
   if (mAdapter.cancelSelection(mListView, begin, end) < 1 && mFromMenu) {
     mActionMode.finish();
   }
 }
  public void startSildingInAnimation(int position) {
    this.selectItemPosition = position;
    arrowView.setY(leftView.getChildAt(position - leftView.getFirstVisiblePosition()).getTop());
    tempScrollY = (int) getScroll();
    if (Math.abs(leftView.getX()) < leftlist_img_width * 0.2) { // 如果leftview大部分都显示出来,就执行动画

      parentViewSliding(
          viewWidth,
          0,
          parentView,
          500l,
          new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
              super.onAnimationEnd(animation);
            }

            @Override
            public void onAnimationStart(Animator animation) {
              super.onAnimationStart(animation);
              parentView.setVisibility(VISIBLE);
            }
          });

      leftViewSliding(0, -(int) leftlist_img_width, leftView, 500l);
    }
  }
  public void loadNextFiveTransactions() {

    index = lv_Transactions.getFirstVisiblePosition();

    View v = lv_Transactions.getChildAt(0);

    top = (v == null) ? 0 : v.getTop();

    FINAL += 5;

    if (FINAL > listOfAllTransactions.size()) {
      FINAL = listOfAllTransactions.size();
      savingsAccountTransactionsListAdapter =
          new SavingsAccountTransactionsListAdapter(
              getActivity(), listOfAllTransactions.subList(INITIAL, FINAL));
      savingsAccountTransactionsListAdapter.notifyDataSetChanged();
      lv_Transactions.setAdapter(savingsAccountTransactionsListAdapter);
      lv_Transactions.setSelectionFromTop(index, top);
      return;
    }

    savingsAccountTransactionsListAdapter =
        new SavingsAccountTransactionsListAdapter(
            getActivity(), listOfAllTransactions.subList(INITIAL, FINAL));
    savingsAccountTransactionsListAdapter.notifyDataSetChanged();
    lv_Transactions.setAdapter(savingsAccountTransactionsListAdapter);
    lv_Transactions.setSelectionFromTop(index, top);
  }
Пример #10
0
 public void onDelete(int accountId) {
   int firstVisiblePos = mListView.getFirstVisiblePosition();
   int removePos = mAdapter.getItemPosition(accountId, firstVisiblePos);
   mToBeRemoved[0] = removePos;
   mRemoveCount = 1;
   animateDeletion();
 }
Пример #11
0
  public View getView(int position, View convertView, ViewGroup parent) {
    AlbumDescriptor albumDescriptor = mData.get(position);
    if (null == convertView || !albumDescriptor.getAlbumId().equals(convertView.getTag())) {
      LayoutInflater inflater = LayoutInflater.from(mContext);
      convertView = (ViewGroup) inflater.inflate(R.layout.album_list_item, parent, false);
      convertView.setTag(albumDescriptor.getAlbumId());
    }

    ListView theListView = null;
    if (parent instanceof ListView) {
      theListView = (ListView) parent;
    }

    final TextView albumText = (TextView) convertView.findViewById(R.id.item_title);
    albumText.setText("" + albumDescriptor.getPhotosCount() + " hot photos");

    final ImageViewProxy imgView = (ImageViewProxy) convertView.findViewById(R.id.album_cover);
    imgView.setImageLink(albumDescriptor.getCoverLinkage());
    imgView.setLoadingIcon(Constants.IMG_LOADING);
    imgView.setImageChangeListener(
        new ImageViewProxy.OnImageChangeListiner() {
          @Override
          public void onImageChanged() {
            Rect rect = imgView.getDrawable().copyBounds();
            Point size = GraphicsUtil.getDisplaySize(imgView.getContext());

            if (0 == rect.width() || 0 == size.x) {
              // wrong, possible 'divided by 0'
              return;
            }

            // TODO HERE TO CALC
            // suppose the image is wider than screen width
            int height =
                rect.height()
                    * imgView.getLayoutParams().width
                    / rect.width(); // size.x is screen width.
            /*
            if(size.x > rect.width()) {
                //TODO HERE TO CALC
                height = (int)(rect.height() * 1.1);
            }


            imgView.setScaleType(ImageView.ScaleType.FIT_CENTER);
            imgView.getLayoutParams().height = height;
            imgView.requestLayout();
            */

          }
        });

    if (position > theListView.getFirstVisiblePosition() - PRE_LOAD_COUNT
        || position < theListView.getLastVisiblePosition() + PRE_LOAD_COUNT) {
      imgView.show();
    }
    albumDescriptor.printInfo();
    return convertView;
  }
Пример #12
0
 @Override
 protected void onPause() {
   // TODO Auto-generated method stub
   /*unregisterReceiver(receiver);*/
   if (receiver != null) {
     unregisterReceiver(receiver);
     receiver = null;
   }
   getPreferences(MODE_PRIVATE)
       .edit()
       .putString("listScroll", listView.getFirstVisiblePosition() + "")
       .commit();
   Log.v("temp on pause", listView.getFirstVisiblePosition() + "");
   super.onPause();
   if ((pDialog != null) && pDialog.isShowing()) pDialog.dismiss();
   pDialog = null;
 }
Пример #13
0
 private void setAllUnselected() {
   for (int i = 0;
       i <= (mListView.getLastVisiblePosition() - mListView.getFirstVisiblePosition());
       i++)
     mListView
         .getChildAt(i)
         .setBackgroundColor(getActivity().getResources().getColor(R.color.non_selected_color));
 }
 private void reprioritizeDownloads() {
   int lastVisibleItem = listView.getLastVisiblePosition();
   if (lastVisibleItem >= 0) {
     int firstVisibleItem = listView.getFirstVisiblePosition();
     adapter.prioritizeViewRange(
         firstVisibleItem, lastVisibleItem, PROFILE_PICTURE_PREFETCH_BUFFER);
   }
 }
Пример #15
0
 public static void ensureVisible(ListView list, int positionToShow) {
   // TODO could be enhanced by using setSelectionFromTop(). setSelection
   // always scrolls the list to the same offset, would prefer to show item
   // at top/bottom depending on direction
   if (positionToShow < list.getFirstVisiblePosition()
       || positionToShow > list.getLastVisiblePosition()) {
     list.setSelection(positionToShow);
   }
 }
Пример #16
0
 public int getScrollY() {
   View c = listView.getChildAt(0);
   if (c == null) {
     return 0;
   }
   int firstVisiblePosition = listView.getFirstVisiblePosition();
   int top = c.getTop();
   return -top + firstVisiblePosition * c.getHeight();
 }
Пример #17
0
  @Override
  public void onSaveInstanceState(Bundle outState) {
    outState.putInt(POSITION_KEY, mListView.getFirstVisiblePosition());
    if (mSelectedPosition != ListView.INVALID_POSITION) {
      outState.putInt(SELECTED_KEY, mSelectedPosition);
    }

    super.onSaveInstanceState(outState);
  }
  /**
   * Highlight current playing item Make the playing item can be seen.
   *
   * @param position
   */
  private void onItemPlay(int position) {
    // Make the the playing item can be seen.
    mMusicListView.smoothScrollToPosition(position);
    int prePlayingPosition = mMusicListAdapter.getPlayingPosition();
    if (prePlayingPosition >= mMusicListView.getFirstVisiblePosition()
        && prePlayingPosition <= mMusicListView.getLastVisiblePosition()) {
      int preItem = prePlayingPosition - mMusicListView.getFirstVisiblePosition();
      ((ViewGroup) mMusicListView.getChildAt(preItem)).getChildAt(0).setVisibility(View.INVISIBLE);
    }

    mMusicListAdapter.setPlayingPosition(position);

    if (mMusicListView.getLastVisiblePosition() < position
        || mMusicListView.getFirstVisiblePosition() > position) return;

    int currentItem = position - mMusicListView.getFirstVisiblePosition();
    ((ViewGroup) mMusicListView.getChildAt(currentItem)).getChildAt(0).setVisibility(View.VISIBLE);
  }
Пример #19
0
 @Override
 protected void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   if (lv != null) {
     // ListViewの位置
     outState.putInt("lvFirstVisiblePosition", lv.getFirstVisiblePosition());
     outState.putInt("lvGetTop", lv.getChildAt(0).getTop());
   }
 }
Пример #20
0
 @Override
 public boolean getIsListViewToTop() {
   View topListView = singleChatLv.getChildAt(singleChatLv.getFirstVisiblePosition());
   if ((topListView == null) || (topListView.getTop() != 0)) {
     return false;
   } else {
     return true;
   }
 }
Пример #21
0
 public void loadImage() {
   int start = mListView.getFirstVisiblePosition();
   int end = mListView.getLastVisiblePosition();
   if (end >= getCount()) {
     end = getCount() - 1;
   }
   syncImageLoader.setLoadLimit(start, end);
   syncImageLoader.unlock();
 }
Пример #22
0
 @Override
 public void onScrollStateChanged(AbsListView view, int scrollState) {
   if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
     View topView = singleChatLv.getChildAt(singleChatLv.getFirstVisiblePosition());
     if ((topView != null) && (topView.getTop() == 0)) {
       mmPullDownView.startTopScroll();
     }
   }
 }
Пример #23
0
  @Override
  public void onRowLongPressed(View view, Object item) {
    extrasMenu.forceHide();

    mMultiSelect.setItemCount(
        mSongAdapter.toggleSelection(
            mListView.getChildAt((Integer) item - mListView.getFirstVisiblePosition()),
            ((Song) mListView.getItemAtPosition((Integer) item))));
  }
Пример #24
0
  @Override
  public void adjustScroll(int scrollHeight, int headerHeight) {
    if (mListView == null) return;

    if (scrollHeight == 0 && mListView.getFirstVisiblePosition() >= 1) {
      return;
    }

    mListView.setSelectionFromTop(1, scrollHeight);
  }
Пример #25
0
 public void deleteView(int position) {
   if (position < 0 || position > list.size()) return;
   int first = mListView.getFirstVisiblePosition();
   View view = mListView.getChildAt(position - first);
   if (view != null) {
     mListView.removeViewAt(position - first);
     return;
   }
   System.out.println("DeviceAdapter 发生了严重的问题....view为NULL");
   System.out.println("position is " + position + " and first is " + first);
 }
  public View getViewByPosition(int pos, ListView listView) {
    final int firstListItemPosition = listView.getFirstVisiblePosition();
    final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;

    if (pos < firstListItemPosition || pos > lastListItemPosition) {
      return listView.getAdapter().getView(pos, null, listView);
    } else {
      final int childIndex = pos - firstListItemPosition;
      return listView.getChildAt(childIndex);
    }
  }
Пример #27
0
 @Override
 protected void onPause() {
   // TODO Auto-generated method stub
   super.onPause();
   StaticMusic.smoothScrollTo = lv.getFirstVisiblePosition();
   try {
     database.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Пример #28
0
  // TODO sync
  public void animateDismiss(final int pos) {
    final int actionPos =
        pos - mListView.getFirstVisiblePosition() + mListView.getHeaderViewsCount();
    final View view = mListView.getChildAt(actionPos);
    final ViewGroup.LayoutParams lp = view.getLayoutParams();
    final int originWidth = view.getWidth();
    final int originHeight = view.getHeight();

    Animator translationXAnim = ObjectAnimator.ofFloat(view, "x", 0, -originWidth);
    Animator alphaAnim = ObjectAnimator.ofFloat(view, "alpha", 1, 0);
    ValueAnimator layoutParamYAnim = ValueAnimator.ofInt(originHeight, 0);
    layoutParamYAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {

          @Override
          public void onAnimationUpdate(ValueAnimator anim) {
            lp.height = (Integer) anim.getAnimatedValue();
            view.setLayoutParams(lp);
          }
        });

    AnimatorSet animSet = new AnimatorSet();
    animSet.setDuration(1000);
    animSet.setTarget(view);
    animSet.setInterpolator(new AccelerateInterpolator());
    animSet.playTogether(translationXAnim, alphaAnim, layoutParamYAnim);
    layoutParamYAnim.setStartDelay(200);
    animSet.addListener(
        new Animator.AnimatorListener() {

          @Override
          public void onAnimationStart(Animator arg0) {}

          @Override
          public void onAnimationRepeat(Animator arg0) {}

          @Override
          public void onAnimationCancel(Animator arg0) {}

          @Override
          public void onAnimationEnd(Animator arg0) {
            // 还原 View 的状态
            lp.height = originHeight;
            view.setLayoutParams(lp);
            ViewHelper.setX(view, 0);
            ViewHelper.setAlpha(view, 1);

            mAdapter.getData().remove(pos);
            mAdapter.notifyDataSetChanged();
          }
        });
    animSet.start();
  }
  public static int getScrollY(ListView lv) {
    View c = lv.getChildAt(0);
    if (c == null) {
      return 0;
    }

    int firstVisiblePosition = lv.getFirstVisiblePosition();
    int top = c.getTop();

    int scrollY = -top + firstVisiblePosition * c.getHeight();
    return scrollY;
  }
 private void holdUserScrollPosition() {
   // Remember the scroll position and offset of the list
   // From: http://stackoverflow.com/a/3035521
   int offset = 0;
   View v = audioFileView.getChildAt(0);
   if (v != null) {
     offset = v.getTop() - audioFileView.getPaddingTop();
   }
   Intent intent = getIntent();
   intent.putExtra(TOP_LIST_ITEM, audioFileView.getFirstVisiblePosition());
   intent.putExtra(TOP_LIST_ITEM_OFFSET, offset);
 }