Esempio n. 1
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
      convertView = minflater.inflate(R.layout.fragment_photo_grid_image, null);
      // 获取布局的长宽,并重新设置
      int x = (int) (parent.getWidth() / 3);
      int y = (int) (parent.getWidth() / 3);
      convertView.setLayoutParams(new AbsListView.LayoutParams(x, y));
      holder = new ViewHolder();
      // 初始化finalBitmap
      fb = FinalBitmap.create(context);

      holder.photo_img1 = (ImageView) convertView.findViewById(R.id.photo_img);

      AlbumBackList back = data.get(position);
      //			if(position == 0){
      //				holder.photo_img.setImageResource(R.drawable.add_album);
      //			}else{
      fb.display(holder.photo_img1, "http://61.152.93.162:8380/data/upload/" + back.getSavepath());
      //			}

      convertView.setTag(holder); // 绑定ViewHolder对象

    } else {
      holder = (ViewHolder) convertView.getTag(); // 取出ViewHolder对象
    }

    return convertView;
  }
    public View getView(int position, View convertView, ViewGroup parent) {
      final OneLabelItemView view;
      if (convertView == null) {
        view =
            new OneLabelItemView(
                mActivity,
                mVideoManager,
                parent.getWidth(),
                mFallbackBitmap,
                mList.getSelector(),
                true);
      } else {
        view = (OneLabelItemView) convertView;
      }
      final Actor actor = this.getItem(position);
      view.reset();
      view.position = position;
      view.title = actor.name;

      if (mLoadCovers) {
        if (mVideoManager.coverLoaded(actor, mThumbSize)) {
          view.setCover(mVideoManager.getCoverSync(actor, mThumbSize));
        } else {
          view.setCover(null);
          view.getResponse().load(actor, !mPostScrollLoader.isListIdle());
        }
      }

      return view;
    }
    public View getView(int position, View convertView, ViewGroup parent) {
      final ThreeLabelsItemView view;
      if (convertView == null) {
        view =
            new ThreeLabelsItemView(
                mActivity,
                mMusicManager,
                parent.getWidth(),
                mFallbackBitmap,
                mList.getSelector(),
                false);
      } else {
        view = (ThreeLabelsItemView) convertView;
      }

      final Album album = getItem(position);
      view.reset();
      view.position = position;
      view.title = album.name;
      view.subtitle = album.artist;
      view.subsubtitle = album.year > 0 ? String.valueOf(album.year) : "";
      Log.i(TAG, "isListIdle: " + mPostScrollLoader.isListIdle());
      if (mLoadCovers) {
        if (mMusicManager.coverLoaded(album, mThumbSize)) {
          view.setCover(mMusicManager.getCoverSync(album, mThumbSize));
        } else {
          view.setCover(null);
          view.getResponse().load(album, !mPostScrollLoader.isListIdle());
        }
      }
      return view;
    }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null) {
      convertView =
          LayoutInflater.from(getContext()).inflate(R.layout.list_item_review, parent, false);
    }
    final Item item = getItem(position);
    TextView textView = (TextView) convertView.findViewById(R.id.review_item_view);
    int parentWidth = parent.getWidth();
    if (parentWidth != 0) {
      textView.setWidth(parentWidth);
      if (!mListHeightSizingRequested) {
        mListHeightSizingRequested = true;
        textView.post(
            new Runnable() {
              @Override
              public void run() {
                Utility.setListViewHeightBasedOnItems(mListView);
              }
            });
      }
    }
    textView.setText(item.getReviewStr());

    return convertView;
  }
    @Override
    public void run() {
      final float centerX = vgContainer.getWidth() / 2.0f;
      final float centerY = vgContainer.getHeight() / 2.0f;
      Rotate3dAnimation rotation = null;
      AnimationSet animationSet = null;
      if (mPosition > -1) {
        vFront.setVisibility(View.GONE);
        vBack.setVisibility(View.VISIBLE);
        vBack.requestFocus();
        rotation = new Rotate3dAnimation(-90, 0, centerX, centerY, 310.0f, false, axis);
        animationSet = new AnimationSet(true);
        animationSet.addAnimation(largerAnimation);
        animationSet.addAnimation(rotation);
      } else {
        vFront.setVisibility(View.VISIBLE);
        vBack.setVisibility(View.GONE);
        vFront.requestFocus();
        rotation = new Rotate3dAnimation(90, 0, centerX, centerY, 310.0f, false, axis);
        animationSet = new AnimationSet(true);
        animationSet.addAnimation(rotation);
      }
      rotation.setDuration(500);
      rotation.setFillAfter(true);
      // 动画插入器 减速
      rotation.setInterpolator(new DecelerateInterpolator());

      vgContainer.startAnimation(animationSet);
    }
Esempio n. 6
0
 /**
  * Place the TextView into the specified container.
  *
  * @param container The container in which to place the TextView.
  */
 public void place(PortableContainer container) {
   ViewGroup parent = (ViewGroup) container.getPlatformContainer();
   _textView = new TextView(parent.getContext());
   container.add(_textView);
   _textView.setWidth(parent.getWidth());
   _textView.setWidth(parent.getHeight());
 }
    /**
     * Opens the floating toolbar overflow. This method should not be called if menu items have not
     * been laid out with {@link #layoutMenuItems(java.util.List, MenuItem.OnMenuItemClickListener,
     * int)}.
     *
     * @throws IllegalStateException if called when menu items have not been laid out.
     */
    private void openOverflow() {
      Preconditions.checkState(mMainPanel != null);
      Preconditions.checkState(mOverflowPanel != null);

      mMainPanel.fadeOut(true);
      Size overflowPanelSize = mOverflowPanel.measure();
      final int targetWidth = overflowPanelSize.getWidth();
      final int targetHeight = overflowPanelSize.getHeight();
      final boolean morphUpwards = (mOverflowDirection == OVERFLOW_DIRECTION_UP);
      final int startWidth = mContentContainer.getWidth();
      final int startHeight = mContentContainer.getHeight();
      final float startY = mContentContainer.getY();
      final float right = mContentContainer.getX() + mContentContainer.getWidth();
      Animation widthAnimation =
          new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
              ViewGroup.LayoutParams params = mContentContainer.getLayoutParams();
              int deltaWidth = (int) (interpolatedTime * (targetWidth - startWidth));
              params.width = startWidth + deltaWidth;
              mContentContainer.setLayoutParams(params);
              mContentContainer.setX(right - mContentContainer.getWidth());
            }
          };
      Animation heightAnimation =
          new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
              ViewGroup.LayoutParams params = mContentContainer.getLayoutParams();
              int deltaHeight = (int) (interpolatedTime * (targetHeight - startHeight));
              params.height = startHeight + deltaHeight;
              mContentContainer.setLayoutParams(params);
              if (morphUpwards) {
                float y = startY - (mContentContainer.getHeight() - startHeight);
                mContentContainer.setY(y);
              }
            }
          };
      widthAnimation.setDuration(240);
      heightAnimation.setDuration(180);
      heightAnimation.setStartOffset(60);
      mOpenOverflowAnimation.getAnimations().clear();
      mOpenOverflowAnimation.setAnimationListener(mOnOverflowOpened);
      mOpenOverflowAnimation.addAnimation(widthAnimation);
      mOpenOverflowAnimation.addAnimation(heightAnimation);
      mContentContainer.startAnimation(mOpenOverflowAnimation);
    }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    if (convertView == null) {
      holder = new ViewHolder();

      int w = parent.getWidth() - parent.getPaddingLeft() - parent.getPaddingRight();
      int h = parent.getHeight();

      RelativeLayout itemlayout =
          (RelativeLayout) mInflater.inflate(R.layout.item_weather_weekly, parent, false);
      LayoutParams params = new LayoutParams(w / 5, LayoutParams.MATCH_PARENT);
      itemlayout.setLayoutParams(params);

      int wt = itemlayout.getMeasuredWidth();

      holder.layout = (RelativeLayout) itemlayout.findViewById(R.id.week_item_rl);

      holder.textWeek = (TextView) itemlayout.findViewById(R.id.week_item_week);
      holder.textDate = (TextView) itemlayout.findViewById(R.id.week_item_date);
      holder.textNongli = (TextView) itemlayout.findViewById(R.id.week_item_nongli);
      holder.imgWeather = (ImageView) itemlayout.findViewById(R.id.weather_icon);
      holder.textTemperature = (TextView) itemlayout.findViewById(R.id.week_item_temperature);
      holder.textWeather = (TextView) itemlayout.findViewById(R.id.week_item_weather);
      convertView = itemlayout;
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    if (position < info.size()) {
      WeatherInfo weatherInfo = info.get(position);
      if (position == 0) holder.textWeek.setText(mContext.getString(R.string.today));
      else
        holder.textWeek.setText(
            String.format(mContext.getString(R.string.week), weatherInfo.getWeek()));
      holder.textDate.setText(weatherInfo.getDate());
      holder.textNongli.setText(weatherInfo.getNongli());
      holder.textTemperature.setText(
          String.format(mContext.getString(R.string.temperature), weatherInfo.getTemperatureLow())
              + "/"
              + String.format(
                  mContext.getString(R.string.temperature), weatherInfo.getTemperatureHight()));
      // holder.textWeather.setText(w.weather);
      int length = weatherInfo.getWeather().length();
      if (length > 15 && length <= 18) {
        holder.textWeather.setTextSize(12);
      } else if (length > 18 && length <= 21) {
        holder.textWeather.setTextSize(11);
      } else if (length > 21) {
        holder.textWeather.setTextSize(9);
      }
      holder.textWeather.setText(weatherInfo.getWeather());
      holder.imgWeather.setImageDrawable(
          mContext.getResources().getDrawable(getDrawableID(weatherInfo.getWeatherID())));
    }

    return convertView;
  }
 @Override
 public void prepare(View target) {
   ViewGroup parent = (ViewGroup) target.getParent();
   int distance = parent.getWidth() - target.getLeft();
   getAnimatorAgent()
       .playTogether(
           ObjectAnimator.ofFloat(target, "alpha", 0, 1),
           ObjectAnimator.ofFloat(target, "translationX", -distance, 0));
 }
  @Override
  public void onComputeInternalInsets(ViewTreeObserver.InternalInsetsInfo info) {
    mContentHolder.getLocationOnScreen(mTmpTwoArray);

    info.setTouchableInsets(ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION);
    info.touchableRegion.set(
        mTmpTwoArray[0],
        mTmpTwoArray[1],
        mTmpTwoArray[0] + mContentHolder.getWidth(),
        mTmpTwoArray[1] + mContentHolder.getHeight());
  }
  private void reveal(View sourceView, int colorRes, final AnimatorListener listener) {
    // Make reveal cover the display
    final RevealView revealView = new RevealView(this);
    revealView.setLayoutParams(mLayoutParams);
    revealView.setRevealColor(getResources().getColor(colorRes));
    mDisplayForeground.addView(revealView);

    final SupportAnimator revealAnimator;
    final int[] clearLocation = new int[2];
    if (sourceView != null) {
      sourceView.getLocationInWindow(clearLocation);
      clearLocation[0] += sourceView.getWidth() / 2;
      clearLocation[1] += sourceView.getHeight() / 2;
    } else {
      clearLocation[0] = mDisplayForeground.getWidth() / 2;
      clearLocation[1] = mDisplayForeground.getHeight() / 2;
    }
    final int revealCenterX = clearLocation[0] - revealView.getLeft();
    final int revealCenterY = clearLocation[1] - revealView.getTop();
    final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2);
    final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2);
    final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2);
    final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2));

    revealAnimator =
        ViewAnimationUtils.createCircularReveal(
            revealView, revealCenterX, revealCenterY, 0.0f, revealRadius);
    revealAnimator.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
    revealAnimator.addListener(listener);

    final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    alphaAnimator.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));
    alphaAnimator.addListener(
        new AnimationFinishedListener() {
          @Override
          public void onAnimationFinished() {
            mDisplayForeground.removeView(revealView);
          }
        });

    revealAnimator.addListener(
        new AnimationFinishedListener() {
          @Override
          public void onAnimationFinished() {
            play(alphaAnimator);
          }
        });
    play(revealAnimator);
  }
Esempio n. 12
0
  public void updateInfo() {
    ViewGroup parent = (ViewGroup) mAnchor;
    for (HighLight.ViewPosInfo viewPosInfo : mViewRects) {

      RectF rect = new RectF(ViewUtils.getLocationInView(parent, viewPosInfo.view));
      //            if (!rect.equals(viewPosInfo.rectF))//TODO bug dismissed...fc...
      {
        viewPosInfo.rectF = rect;
        viewPosInfo.onPosCallback.getPos(
            parent.getWidth() - rect.right,
            parent.getHeight() - rect.bottom,
            rect,
            viewPosInfo.marginInfo);
      }
    }
  }
Esempio n. 13
0
  /**
   * Setup a new 3D rotation on the container view.
   *
   * @param position the item that was clicked to show a picture, or -1 to show the list
   * @param start the start angle at which the rotation must begin
   * @param end the end angle of the rotation
   */
  private void applyRotation(int position, float start, float end) {
    // Find the center of the container
    final float centerX = mContainer.getWidth() / 2.0f;
    final float centerY = mContainer.getHeight() / 2.0f;

    // Create a new 3D rotation with the supplied parameter
    // The animation listener is used to trigger the next animation
    final Rotate3dAnimation rotation =
        new Rotate3dAnimation(start, end, centerX, centerY, 310.0f, true);
    rotation.setDuration(500);
    rotation.setFillAfter(true);
    rotation.setInterpolator(new AccelerateInterpolator());
    rotation.setAnimationListener(new DisplayNextView(position));

    mContainer.startAnimation(rotation);
  }
Esempio n. 14
0
 public LoadToast show() {
   if (!mInflated) {
     mShowCalled = true;
     return this;
   }
   mView.show();
   ViewHelper.setTranslationX(mView, (mParentView.getWidth() - mView.getWidth()) / 2);
   ViewHelper.setAlpha(mView, 0f);
   ViewHelper.setTranslationY(mView, -mView.getHeight() + mTranslationY);
   // mView.setVisibility(View.VISIBLE);
   ViewPropertyAnimator.animate(mView)
       .alpha(1f)
       .translationY(25 + mTranslationY)
       .setInterpolator(new DecelerateInterpolator())
       .setDuration(300)
       .setStartDelay(0)
       .start();
   return this;
 }
Esempio n. 15
0
  public HighLight addHighLight(View view, int decorLayoutId, OnPosCallback onPosCallback) {
    ViewGroup parent = (ViewGroup) mAnchor;
    RectF rect = new RectF(ViewUtils.getLocationInView(parent, view));
    ViewPosInfo viewPosInfo = new ViewPosInfo();
    viewPosInfo.layoutId = decorLayoutId;
    viewPosInfo.rectF = rect;
    viewPosInfo.view = view;
    if (onPosCallback == null && decorLayoutId != -1) {
      throw new IllegalArgumentException("onPosCallback can not be null.");
    }
    MarginInfo marginInfo = new MarginInfo();
    onPosCallback.getPos(
        parent.getWidth() - rect.right, parent.getHeight() - rect.bottom, rect, marginInfo);
    viewPosInfo.marginInfo = marginInfo;
    viewPosInfo.onPosCallback = onPosCallback;
    mViewRects.add(viewPosInfo);

    return this;
  }
Esempio n. 16
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    ViewHolder viewHolder = null;
    ImageView imageView;
    if (row == null) {
      // LayoutInflater inflater = ((Activity) getContext()).getLayoutInflater();
      // row = inflater.inflate(R.layout.movie_list_item, parent, false);
      // viewHolder = new ViewHolder(row);
      imageView = new ImageView(mContext);
      GridView gridView = (GridView) parent;
      GridView.LayoutParams params =
          new GridView.LayoutParams(
              GridView.LayoutParams.WRAP_CONTENT, GridView.LayoutParams.WRAP_CONTENT);
      params.width = (parent.getWidth() / gridView.getNumColumns());
      params.height = (int) Math.round(params.width * 1.5);
      imageView.setLayoutParams(params);
      imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
      imageView.setPadding(0, 0, 0, 0);
      // row.setTag(viewHolder);
    } else {
      viewHolder = (ViewHolder) row.getTag();
      imageView = (ImageView) convertView;
    }

    Movie movie = getItem(position);
    StringBuilder posterUrl = new StringBuilder();

    // TODO:
    // Complete the query and jason parsing elsewhere
    // Then move on to creating image and setting parameters if necessary

    if (movie.posterUrl != null) {
      posterUrl.append(baseUrl);
      posterUrl.append(w500);
      posterUrl.append(movie.posterUrl);

      Picasso.with(getContext()).load(posterUrl.toString()).into(imageView);
    }

    return imageView;
  }
  /**
   * Creates or finds a view.
   *
   * <p>The view includes an image, which is provided to the view from the <code>imageCache</code>.
   *
   * @param position the position in the <code>List<T></code>
   * @param convertView the view to be presented
   * @param parent the parent of the view to be presented
   * @return the view to be presented
   */
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    LinearLayout itemView;

    if (convertView == null) {
      itemView = new LinearLayout(context);
      String inflater = Context.LAYOUT_INFLATER_SERVICE;
      LayoutInflater li;
      li = (LayoutInflater) context.getSystemService(inflater);
      li.inflate(resource, itemView, true);

      LinearLayout.LayoutParams linearLayoutParams =
          new LinearLayout.LayoutParams(
              parent.getWidth() / ConstantsHelper.NUMBER_OF_COLUMNS_IN_GRID,
              parent.getWidth() / ConstantsHelper.NUMBER_OF_COLUMNS_IN_GRID);
      itemView.setLayoutParams(new GridView.LayoutParams(linearLayoutParams));
      itemView.setPadding(5, 5, 5, 5);
    } else {
      itemView = (LinearLayout) convertView;
    }

    Advertisement advertisement = getItem(position);

    itemView.setTag(advertisement.id);
    TextView titleView = (TextView) itemView.findViewById(R.id.advertisement_title);
    ImageView imageView = (ImageView) itemView.findViewById(R.id.advertisement_image);

    titleView.setText(advertisement.title);

    String imagePath = advertisement.url;

    if (imagePath.matches("^http.*")) imagePath = "http";

    Bitmap bitmap;
    synchronized (imageCache) {
      bitmap = imageCache.get(imagePath);
    }

    imageView.setImageBitmap(bitmap);
    return itemView;
  }
 public View getView(int position, View convertView, ViewGroup parent) {
   final OneLabelItemView view;
   if (convertView == null) {
     view =
         new OneLabelItemView(
             mActivity, parent.getWidth(), mFallbackBitmap, mList.getSelector(), true);
   } else {
     view = (OneLabelItemView) convertView;
     mItemPositions.remove(view.position);
   }
   final PlaylistItem item = this.getItem(position);
   view.reset();
   view.position = position;
   view.title = item.filename;
   if (position == mCurrentPosition) {
     view.setCover(sPlayingBitmap);
   } else {
     view.setCover(mFallbackBitmap);
   }
   mItemPositions.put(view.position, view);
   return view;
 }
Esempio n. 19
0
  /**
   * 应用旋转动画
   *
   * @param position
   * @param start
   * @param end
   * @param ivFront
   * @param ivBack
   * @param container
   * @param axis
   */
  private void applyRotation(
      int position,
      int start,
      int end,
      ImageView ivFront,
      ImageView ivBack,
      ViewGroup container,
      String axis) {
    final float centerX = container.getWidth() / 2.0f;
    final float centerY = container.getHeight() / 2.0f;

    final Rotate3dAnimation rotate3dAnimation =
        new Rotate3dAnimation(start, end, centerX, centerY, 310.0f, true, Rotate3dAnimation.Y);
    rotate3dAnimation.setDuration(100);
    rotate3dAnimation.setFillAfter(true);
    // 动画插入器,加速
    rotate3dAnimation.setInterpolator(new AccelerateInterpolator());
    rotate3dAnimation.setAnimationListener(
        new DisplayNextView(position, ivFront, ivBack, container, axis));

    container.startAnimation(rotate3dAnimation);
  }
    public View getView(int position, View convertView, ViewGroup parent) {

      final FiveLabelsItemView view;
      if (convertView == null) {
        view =
            new FiveLabelsItemView(
                mActivity,
                mVideoManager,
                parent.getWidth(),
                mFallbackBitmap,
                mList.getSelector(),
                false);
      } else {
        view = (FiveLabelsItemView) convertView;
      }

      final Movie movie = getItem(position);
      view.reset();
      view.position = position;
      view.posterOverlay = movie.numWatched > 0 ? mWatchedBitmap : null;
      view.title = movie.title;
      view.subtitle = movie.genres;
      view.subtitleRight = movie.year > 0 ? String.valueOf(movie.year) : "";
      view.bottomtitle = movie.runtime;
      view.bottomright = String.valueOf(movie.rating);

      if (mLoadCovers) {
        if (mVideoManager.coverLoaded(movie, mThumbSize)) {
          view.setCover(mVideoManager.getCoverSync(movie, mThumbSize));
        } else {
          view.setCover(null);
          view.getResponse().load(movie, !mPostScrollLoader.isListIdle());
        }
      }
      return view;
    }
Esempio n. 21
0
  @SuppressLint("NewApi")
  private static void actionStarActivity(
      final int finishType,
      final Activity thisActivity,
      final Intent intent,
      final Integer requestCode,
      final Bundle bundle,
      final View triggerView,
      int colorOrImageRes,
      long durationMills) {

    // 版本判断,小于5.0则无动画.
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
      startActivityOrFinish(finishType, thisActivity, intent, requestCode, bundle);
      return;
    }

    int[] location = new int[2];
    triggerView.getLocationInWindow(location);
    final int cx = location[0] + triggerView.getWidth() / 2;
    final int cy = location[1] + triggerView.getHeight() / 2;
    final ImageView view = new ImageView(thisActivity);
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageResource(colorOrImageRes);
    final ViewGroup decorView = (ViewGroup) thisActivity.getWindow().getDecorView();
    int w = decorView.getWidth();
    int h = decorView.getHeight();
    decorView.addView(view, w, h);

    // 计算中心点至view边界的最大距离
    int maxW = Math.max(cx, w - cx);
    int maxH = Math.max(cy, h - cy);
    final int finalRadius = (int) Math.sqrt(maxW * maxW + maxH * maxH) + 1;

    Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
    int maxRadius = (int) Math.sqrt(w * w + h * h) + 1;
    // 若使用默认时长,则需要根据水波扩散的距离来计算实际时间
    if (durationMills == PERFECT_MILLS) {
      // 算出实际边距与最大边距的比率
      double rate = 1d * finalRadius / maxRadius;
      // 为了让用户便于感触到水波,速度应随最大边距的变小而越慢,扩散时间应随最大边距的变小而变小,因此比率应在 @rate 与 1 之间。
      durationMills = (long) (PERFECT_MILLS * Math.sqrt(rate));
    }
    final long finalDuration = durationMills;
    // 由于thisActivity.startActivity()会有所停顿,所以进入的水波动画应比退出的水波动画时间短才能保持视觉上的一致。
    anim.setDuration((long) (finalDuration * 0.9));
    anim.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);

            if (requestCode == null) thisActivity.startActivity(intent);
            else if (bundle == null) thisActivity.startActivityForResult(intent, requestCode);
            else thisActivity.startActivityForResult(intent, requestCode, bundle);

            // 默认渐隐过渡动画.
            thisActivity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

            switch (finishType) {
              case FINISH_NONE:
                // 默认显示返回至当前Activity的动画.
                triggerView.postDelayed(
                    new Runnable() {
                      @Override
                      public void run() {
                        Animator anim =
                            ViewAnimationUtils.createCircularReveal(view, cx, cy, finalRadius, 0);
                        anim.setDuration(finalDuration);
                        anim.addListener(
                            new AnimatorListenerAdapter() {
                              @Override
                              public void onAnimationEnd(Animator animation) {
                                super.onAnimationEnd(animation);
                                try {
                                  decorView.removeView(view);
                                } catch (Exception e) {
                                  e.printStackTrace();
                                }
                              }
                            });
                        anim.start();
                      }
                    },
                    1000);
                break;
              case FINISH_SINGLE:
                // finish当前activity
                thisActivity.finish();
                break;
              case FINISH_ALL:
                // finish目标activity外的所有activity
                thisActivity.finishAffinity();
                break;
            }
          }
        });
    anim.start();
  }
Esempio n. 22
0
  protected void setTopControllerDirection(int topControllerDirection, boolean animated) {

    if (getViewControllerContext().isIdleTimerDisabled() && animated && isViewAppeared()) {
      return;
    }

    if (_topControllerDirection != topControllerDirection) {

      getView();

      final ViewGroup contentView = getContentView();

      if (animated && isViewAppeared()) {

        switch (topControllerDirection) {
          case TopControllerDirectionCenter:
            {
              Animation anim = new Animation();

              anim.setDuration(300);
              anim.setListener(
                  new AnimatorListener() {

                    public void onEnd() {

                      IViewController<T> topController = getLeftViewController();

                      if (topController != null) {
                        if (topController.isViewAppeared()) {
                          topController.viewRemoveForSuperView(true);
                        }
                      }

                      topController = getRightViewController();

                      if (topController != null) {
                        if (topController.isViewAppeared()) {
                          topController.viewRemoveForSuperView(true);
                        }
                      }

                      contentView.setEnabled(true);
                      getViewControllerContext().setIdleTimerDisabled(false);
                    }

                    public void onAnimationStart(Animator animation) {}

                    public void onAnimationRepeat(Animator animation) {}

                    public void onAnimationEnd(Animator animation) {
                      onEnd();
                    }

                    public void onAnimationCancel(Animator animation) {
                      onEnd();
                    }
                  });

              IViewController<T> topController = getLeftViewController();

              if (topController != null) {
                if (topController.isViewAppeared()) {
                  anim.alpha(topController.getView(), 1.0f, AlphaValue);
                }
              }

              topController = getCenterViewController();

              if (topController != null) {

                View v = topController.getView();

                anim.translateTo(v, 0, 0);

                if (!topController.isViewAppeared()) {
                  topController.viewAppearToSuperView(contentView, animated);
                }
              }

              topController = getRightViewController();

              if (topController != null) {

                if (topController.isViewAppeared()) {
                  anim.alpha(topController.getView(), 1.0f, AlphaValue);
                }
              }
              contentView.setEnabled(false);
              getViewControllerContext().setIdleTimerDisabled(true);
              anim.submit();
            }
            break;
          case TopControllerDirectionLeft:
            {
              Animation anim = new Animation();

              anim.setDuration(300);
              anim.setListener(
                  new AnimatorListener() {

                    public void onEnd() {

                      IViewController<T> topController = getRightViewController();

                      if (topController != null) {
                        if (topController.isViewAppeared()) {
                          topController.viewRemoveForSuperView(true);
                        }
                      }

                      contentView.setEnabled(true);
                      getViewControllerContext().setIdleTimerDisabled(false);
                    }

                    public void onAnimationStart(Animator animation) {}

                    public void onAnimationRepeat(Animator animation) {}

                    public void onAnimationEnd(Animator animation) {
                      onEnd();
                    }

                    public void onAnimationCancel(Animator animation) {
                      onEnd();
                    }
                  });

              IViewController<T> topController = getLeftViewController();

              if (topController != null) {

                if (!topController.isViewAppeared()) {
                  topController.viewAppearToSuperView(getContentView(), animated, true);
                }

                anim.alpha(topController.getView(), AlphaValue, 1.0f);
              }

              topController = getCenterViewController();

              if (topController != null) {

                View v = topController.getView();

                anim.translateTo(v, contentView.getWidth() - FoldWidth, 0);

                if (!topController.isViewAppeared()) {
                  topController.viewAppearToSuperView(getContentView(), animated);
                }
              }

              topController = getRightViewController();

              if (topController != null) {

                if (topController.isViewAppeared()) {
                  anim.alpha(topController.getView(), 1.0f, AlphaValue);
                }
              }

              contentView.setEnabled(false);
              getViewControllerContext().setIdleTimerDisabled(true);
              anim.submit();
            }
            break;
          case TopControllerDirectionRight:
            {
              Animation anim = new Animation();

              anim.setDuration(300);
              anim.setListener(
                  new AnimatorListener() {

                    public void onEnd() {

                      IViewController<T> topController = getLeftViewController();

                      if (topController != null) {
                        if (topController.isViewAppeared()) {
                          topController.viewRemoveForSuperView(true);
                        }
                      }

                      contentView.setEnabled(true);
                      getViewControllerContext().setIdleTimerDisabled(false);
                    }

                    public void onAnimationStart(Animator animation) {}

                    public void onAnimationRepeat(Animator animation) {}

                    public void onAnimationEnd(Animator animation) {
                      onEnd();
                    }

                    public void onAnimationCancel(Animator animation) {
                      onEnd();
                    }
                  });

              IViewController<T> topController = getLeftViewController();

              if (topController != null) {
                if (topController.isViewAppeared()) {
                  anim.alpha(topController.getView(), 1.0f, AlphaValue);
                }
              }

              topController = getCenterViewController();

              if (topController != null) {

                View v = topController.getView();

                anim.translateTo(v, FoldWidth - contentView.getWidth(), 0);

                if (!topController.isViewAppeared()) {
                  topController.viewAppearToSuperView(contentView, animated);
                }
              }

              topController = getRightViewController();

              if (topController != null) {

                if (!topController.isViewAppeared()) {
                  topController.viewAppearToSuperView(contentView, animated, true);
                }

                anim.alpha(topController.getView(), AlphaValue, 1.0f);
              }

              contentView.setEnabled(false);
              getViewControllerContext().setIdleTimerDisabled(true);
              anim.submit();
            }
            break;
        }

      } else {

        switch (topControllerDirection) {
          case TopControllerDirectionCenter:
            {
              IViewController<T> topController = getLeftViewController();

              if (topController != null) {
                if (topController.isViewAppeared()) {
                  topController.viewRemoveForSuperView(animated);
                }
              }

              topController = getCenterViewController();

              if (topController != null) {

                View v = topController.getView();

                v.setX(0);

                if (isViewAppeared()) {
                  if (!topController.isViewAppeared()) {
                    topController.viewAppearToSuperView(contentView, animated);
                  }
                }
              }

              topController = getRightViewController();

              if (topController != null) {

                if (topController.isViewAppeared()) {
                  topController.viewRemoveForSuperView(animated);
                }
              }
            }
            break;
          case TopControllerDirectionLeft:
            {
              IViewController<T> topController = getLeftViewController();

              if (topController != null) {
                if (isViewAppeared()) {
                  if (!topController.isViewAppeared()) {
                    topController.viewAppearToSuperView(getContentView(), animated, true);
                  }
                }
              }

              topController = getCenterViewController();

              if (topController != null) {

                View v = topController.getView();

                v.setX(contentView.getWidth() - FoldWidth);

                if (isViewAppeared()) {
                  if (!topController.isViewAppeared()) {
                    topController.viewAppearToSuperView(getContentView(), animated);
                  }
                }
              }

              topController = getRightViewController();

              if (topController != null) {

                if (topController.isViewAppeared()) {
                  topController.viewRemoveForSuperView(animated);
                }
              }
            }
            break;
          case TopControllerDirectionRight:
            {
              IViewController<T> topController = getLeftViewController();

              if (topController != null) {
                if (topController.isViewAppeared()) {
                  topController.viewRemoveForSuperView(animated);
                }
              }

              topController = getCenterViewController();

              if (topController != null) {

                View v = topController.getView();

                v.setX(FoldWidth - contentView.getWidth());

                if (isViewAppeared()) {
                  if (!topController.isViewAppeared()) {
                    topController.viewAppearToSuperView(contentView, animated);
                  }
                }
              }

              topController = getRightViewController();

              if (topController != null) {

                if (isViewAppeared()) {
                  if (!topController.isViewAppeared()) {
                    topController.viewAppearToSuperView(contentView, animated, true);
                  }
                }
              }
            }
            break;
        }
      }

      _topControllerDirection = topControllerDirection;
    }
  }
 @Override
 protected Animator getAnimator(final ViewGroup parent, final View view) {
   return ObjectAnimator.ofFloat(view, TRANSLATION_X, 0 - parent.getWidth(), 0);
 }
Esempio n. 24
0
  public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {

    float dx = e2.getX() - _gestureTouchX;

    if (distanceX < 0.0f) {
      _gestureDirection = GestureDirectionRight;
    } else {
      _gestureDirection = GestureDirectionLeft;
    }

    ViewGroup contentView = getContentView();

    if (dx == 0.0f) {

      IViewController<T> controller = getCenterViewController();

      if (controller != null) {
        View v = controller.getView();
        v.setX(dx);
      }

      controller = getLeftViewController();

      if (controller != null) {

        if (controller.isViewAppeared()) {
          controller.viewRemoveForSuperView(false);
        }
      }

      controller = getRightViewController();

      if (controller != null) {

        if (controller.isViewAppeared()) {
          controller.viewRemoveForSuperView(false);
        }
      }
    } else if (dx < 0.0f) {

      IViewController<T> controller = getLeftViewController();

      if (controller != null) {

        if (controller.isViewAppeared()) {
          controller.viewRemoveForSuperView(false);
        }
      }

      controller = getRightViewController();

      if (controller != null) {

        if (!controller.isViewAppeared()) {
          controller.viewAppearToSuperView(contentView, false, true);
        }

        View v = controller.getView();

        float alpha = AlphaValue - (1.0f - AlphaValue) * dx / contentView.getWidth();

        v.setAlpha(alpha);

        controller = getCenterViewController();

        if (controller != null) {
          v = controller.getView();
          v.setX(dx);
        }
      } else {

        controller = getCenterViewController();

        if (controller != null) {
          View v = controller.getView();
          v.setX(0);
        }
      }

    } else {

      IViewController<T> controller = getRightViewController();

      if (controller != null) {

        if (controller.isViewAppeared()) {
          controller.viewRemoveForSuperView(false);
        }
      }

      controller = getLeftViewController();

      if (controller != null) {

        if (!controller.isViewAppeared()) {
          controller.viewAppearToSuperView(contentView, false, true);
        }

        View v = controller.getView();

        float alpha = AlphaValue - (1.0f - AlphaValue) * dx / contentView.getWidth();

        v.setAlpha(alpha);

        controller = getCenterViewController();

        if (controller != null) {
          v = controller.getView();
          v.setX(dx);
        }
      } else {

        controller = getCenterViewController();

        if (controller != null) {
          View v = controller.getView();
          v.setX(0);
        }
      }
    }

    return true;
  }
    /** Override {@link #getChildView(int, int, boolean, View, ViewGroup)} instead. */
    @Override
    public final View getChildView(
        final int groupPosition,
        int childPosition,
        boolean isLastChild,
        View convertView,
        final ViewGroup parent) {
      final GroupInfo info = getGroupInfo(groupPosition);

      if (info.animating) {
        // If this group is animating, return the a DummyView...
        if (convertView instanceof DummyView == false) {
          convertView = new DummyView(parent.getContext());
          convertView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 0));
        }

        if (childPosition < info.firstChildPosition) {
          // The reason why we do this is to support the collapse
          // this group when the group view is not visible but the
          // children of this group are. When notifyDataSetChanged
          // is called, the ExpandableListView tries to keep the
          // list position the same by saving the first visible item
          // and jumping back to that item after the views have been
          // refreshed. Now the problem is, if a group has 2 items
          // and the first visible item is the 2nd child of the group
          // and this group is collapsed, then the dummy view will be
          // used for the group. But now the group only has 1 item
          // which is the dummy view, thus when the ListView is trying
          // to restore the scroll position, it will try to jump to
          // the second item of the group. But this group no longer
          // has a second item, so it is forced to jump to the next
          // group. This will cause a very ugly visual glitch. So
          // the way that we counteract this is by creating as many
          // dummy views as we need to maintain the scroll position
          // of the ListView after notifyDataSetChanged has been
          // called.
          convertView.getLayoutParams().height = 0;
          return convertView;
        }

        final ExpandableListView listView = (ExpandableListView) parent;

        final DummyView dummyView = (DummyView) convertView;

        // Clear the views that the dummy view draws.
        dummyView.clearViews();

        // Set the style of the divider
        dummyView.setDivider(
            listView.getDivider(), parent.getMeasuredWidth(), listView.getDividerHeight());

        // Make measure specs to measure child views
        final int measureSpecW =
            MeasureSpec.makeMeasureSpec(parent.getWidth(), MeasureSpec.EXACTLY);
        final int measureSpecH = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);

        int totalHeight = 0;
        int clipHeight = parent.getHeight();

        final int len = getRealChildrenCount(groupPosition);
        for (int i = info.firstChildPosition; i < len; i++) {
          View childView = getRealChildView(groupPosition, i, (i == len - 1), null, parent);

          LayoutParams p = (LayoutParams) childView.getLayoutParams();
          if (p == null) {
            p = (LayoutParams) generateDefaultLayoutParams();
            childView.setLayoutParams(p);
          }

          int lpHeight = p.height;

          int childHeightSpec;
          if (lpHeight > 0) {
            childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY);
          } else {
            childHeightSpec = measureSpecH;
          }

          childView.measure(measureSpecW, childHeightSpec);
          totalHeight += childView.getMeasuredHeight();

          if (totalHeight < clipHeight) {
            // we only need to draw enough views to fool the user...
            dummyView.addFakeView(childView);
          } else {
            dummyView.addFakeView(childView);

            // if this group has too many views, we don't want to
            // calculate the height of everything... just do a light
            // approximation and break
            int averageHeight = totalHeight / (i + 1);
            totalHeight += (len - i - 1) * averageHeight;
            break;
          }
        }

        Object o;
        int state = (o = dummyView.getTag()) == null ? STATE_IDLE : (Integer) o;

        if (info.expanding && state != STATE_EXPANDING) {
          ExpandAnimation ani = new ExpandAnimation(dummyView, 0, totalHeight, info);
          ani.setDuration(this.parent.getAnimationDuration());
          ani.setAnimationListener(
              new AnimationListener() {

                @Override
                public void onAnimationEnd(Animation animation) {
                  stopAnimation(groupPosition);
                  notifyDataSetChanged();
                  dummyView.setTag(STATE_IDLE);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {}

                @Override
                public void onAnimationStart(Animation animation) {}
              });
          dummyView.startAnimation(ani);
          dummyView.setTag(STATE_EXPANDING);
        } else if (!info.expanding && state != STATE_COLLAPSING) {
          if (info.dummyHeight == -1) {
            info.dummyHeight = totalHeight;
          }

          ExpandAnimation ani = new ExpandAnimation(dummyView, info.dummyHeight, 0, info);
          ani.setDuration(this.parent.getAnimationDuration());
          ani.setAnimationListener(
              new AnimationListener() {

                @Override
                public void onAnimationEnd(Animation animation) {
                  stopAnimation(groupPosition);
                  listView.collapseGroup(groupPosition);
                  notifyDataSetChanged();
                  info.dummyHeight = -1;
                  dummyView.setTag(STATE_IDLE);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {}

                @Override
                public void onAnimationStart(Animation animation) {}
              });
          dummyView.startAnimation(ani);
          dummyView.setTag(STATE_COLLAPSING);
        }

        return convertView;
      } else {
        return getRealChildView(groupPosition, childPosition, isLastChild, convertView, parent);
      }
    }