示例#1
0
  @Override
  public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
    final MainActivity mainActivity = (MainActivity) getActivity();
    Animator anim = null;
    if (showTransitionAnim) {
      if (nextAnim != 0) anim = AnimatorInflater.loadAnimator(getActivity(), nextAnim);
      showTransitionAnim = false;
      if (anim != null)
        anim.addListener(
            new Animator.AnimatorListener() {
              @Override
              public void onAnimationEnd(Animator animator) {
                if (mainActivity.drawer instanceof DrawerLayout)
                  ((DrawerLayout) mainActivity.drawer).closeDrawer(mainActivity.drawerView);
                mainActivity.setDrawerListener(true);
              }

              @Override
              public void onAnimationCancel(Animator animator) {}

              @Override
              public void onAnimationStart(Animator animator) {
                mainActivity.setDrawerListener(false);
              }

              @Override
              public void onAnimationRepeat(Animator animator) {}
            });
    } else anim = AnimatorInflater.loadAnimator(getActivity(), R.animator.none);
    return anim;
  }
  private void animateDismiss(final Runnable doAfter) {
    // the animation can only work (and is only worth doing) if this fragment is added
    // reasons it may not be added: fragment is being destroyed, or in the process of being
    // restored
    if (!mFragment.isAdded()) {
      mBackgroundView.setVisibility(View.GONE);
      return;
    }

    UtilsEx.enableHardwareLayer(mBackgroundView);
    final Animator animator =
        AnimatorInflater.loadAnimator(
            mFragment.getActivity().getApplicationContext(), R.anim.fade_out);
    animator.setTarget(mBackgroundView);
    animator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            mBackgroundView.setVisibility(View.GONE);
            mBackgroundView.setLayerType(View.LAYER_TYPE_NONE, null);
            if (doAfter != null) {
              doAfter.run();
            }
          }
        });
    animator.start();
  }
 private static StateListAnimator getRaiseStateListAnimator(Context context) {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
     return AnimatorInflater.loadStateListAnimator(context, R.anim.raise);
   } else {
     return null;
   }
 }
示例#4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow()
        .addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // TODO only if setting says so

    mRideUri = getIntent().getData();

    setContentView(R.layout.display);

    mChkRecord = (CheckableRelativeLayout) findViewById(R.id.chkRecord);
    mChkRecord.setEnabled(false);
    mChkRecordText = (TextView) findViewById(R.id.chkRecord_text);
    mChkRecordTextAnimator = AnimatorInflater.loadAnimator(this, R.animator.blink);
    mChkRecordTextAnimator.setTarget(mChkRecordText);
    mImgGpsStatus = (ImageView) findViewById(R.id.imgGpsStatus);
    ((AnimationDrawable) mImgGpsStatus.getDrawable()).start();
    findViewById(R.id.vieFragmentCycle).setOnTouchListener(mFragmentCycleOnTouchListener);
    mConTabsA = findViewById(R.id.conTabsA);
    mConTabsB = findViewById(R.id.conTabsB);
    mConFragments = findViewById(R.id.conFragments);
    mTxtTitle = (TextView) findViewById(R.id.txtTitle);

    setupFragments(
        savedInstanceState == null
            ? 0
            : savedInstanceState.getInt("mFragmentCycler.currentVisibleIndex"));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
      setupNavigationBarHiding();
    }
    scheduleHideControls();

    setupFragmentContainer();
  }
示例#5
0
 @Override
 public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
   if (enter) {
     AnimatorSet up =
         (AnimatorSet) AnimatorInflater.loadAnimator(getActivity(), R.animator.slide_up);
     up.addListener(
         new AnimatorListenerAdapter() {
           @Override
           public void onAnimationEnd(Animator animation) {
             setOnRiseListener();
           }
         });
     return up;
   } else {
     return AnimatorInflater.loadAnimator(getActivity(), R.animator.slide_down);
   }
 }
  /**
   * Set the state list animator to use when in default mode. If not run on a Lollipop device, this
   * method is a no-op.
   *
   * @param resId A state list animator resource id. Ignored prior to Lollipop.
   */
  public void setDefaultModeStateListAnimator(int resId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      StateListAnimator animator =
          AnimatorInflater.loadStateListAnimator(itemView.getContext(), resId);

      setDefaultModeStateListAnimator(animator);
    }
  }
示例#7
0
  @Override
  public void bindView(View view, Context context, Cursor cursor) {
    RideCursor c = (RideCursor) cursor;

    // Title (name / date)
    TextView txtTitle = ViewHolder.get(view, R.id.txtTitle);
    String name = c.getName();
    long createdDateLong = c.getCreatedDate().getTime();
    String createdDateTimeStr =
        DateUtils.formatDateTime(
            context, createdDateLong, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
    if (name == null) {
      txtTitle.setText(createdDateTimeStr);
    } else {
      txtTitle.setText(name + "\n" + createdDateTimeStr);
    }

    // Summary
    TextView txtSummary = ViewHolder.get(view, R.id.txtSummary);
    CharSequence details = null;
    Animator animator = (Animator) view.getTag(R.id.animator);
    // Cancel the animation / reset the alpha in any case
    if (animator != null) animator.cancel();
    txtSummary.setAlpha(1);
    RideState rideState = c.getState();
    switch (rideState) {
      case CREATED:
        details = context.getString(R.string.ride_list_notStarted);
        txtSummary.setTextColor(mColorDefault);
        txtSummary.setEnabled(false);
        break;

      case ACTIVE:
        details = context.getString(R.string.ride_list_active);
        if (animator == null) {
          animator = AnimatorInflater.loadAnimator(context, R.animator.blink);
          animator.setTarget(txtSummary);
          view.setTag(R.id.animator, animator);
        }
        animator.start();
        txtSummary.setTextColor(mColorActive);
        txtSummary.setEnabled(true);
        break;

      case PAUSED:
        // Distance
        float distance = c.getDistance();
        details = TextUtils.concat(UnitUtil.formatDistance(distance, true, .85f, false), "  -  ");

        // Duration
        long duration = c.getDuration();
        details = TextUtils.concat(details, DateTimeUtil.formatDuration(context, duration));
        txtSummary.setTextColor(mColorDefault);
        txtSummary.setEnabled(true);
        break;
    }
    txtSummary.setText(details);
  }
 @Override
 public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
   if (FragmentUtils.disableAnimations) {
     Animator a = AnimatorInflater.loadAnimator(fa, nextAnim);
     a.setDuration(0);
     return a;
   } else {
     return super.onCreateAnimator(transit, enter, nextAnim);
   }
 }
示例#9
0
  Animator getCancelAnimator() {
    ObjectAnimator backToTransparent1 =
        (ObjectAnimator)
            AnimatorInflater.loadAnimator(view.getContext(), R.animator.pin_background_end);
    ObjectAnimator goDark =
        (ObjectAnimator)
            AnimatorInflater.loadAnimator(view.getContext(), R.animator.pin_background_go_dark);
    ObjectAnimator backToTransparent2 =
        (ObjectAnimator)
            AnimatorInflater.loadAnimator(view.getContext(), R.animator.pin_background_end);

    ViewGroup parent = (ViewGroup) view.getParent();
    ArgbEvaluator evaluator = new ArgbEvaluator();
    for (ObjectAnimator animator : list(backToTransparent1, goDark, backToTransparent2)) {
      animator.setTarget(parent);
      animator.setEvaluator(evaluator);
    }

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setTarget(parent);
    animatorSet.playSequentially(backToTransparent1, goDark, backToTransparent2);
    return animatorSet;
  }
示例#10
0
  @Nullable
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_one, container, false);
    view.findViewById(R.id.txtContainer).setOnClickListener(this);
    view.findViewById(R.id.txtContainer).setOnClickListener(this);
    AnimatorSet animator =
        (AnimatorSet)
            AnimatorInflater.loadAnimator(
                getActivity().getBaseContext(), R.animator.animator_main_in);
    animator.setTarget(view);
    //        animator.setDuration(700);

    AnimatorSet animatorSet =
        (AnimatorSet)
            AnimatorInflater.loadAnimator(
                getActivity().getBaseContext(), R.animator.animator_main_out);
    animatorSet.setTarget(getActivity().findViewById(R.id.customImage));
    animatorSet.start();
    animator.start();
    return view;
  }
  public void inflate(
      Context c, Resources res, XmlPullParser parser, AttributeSet attrs, Theme theme)
      throws XmlPullParserException, IOException {

    int eventType = parser.getEventType();
    float pathErrorScale = 1;
    while (eventType != XmlPullParser.END_DOCUMENT) {
      if (eventType == XmlPullParser.START_TAG) {
        final String tagName = parser.getName();
        if (ANIMATED_VECTOR.equals(tagName)) {
          final TypedArray a =
              obtainAttributes(res, theme, attrs, R.styleable.AnimatedVectorDrawable);
          int drawableRes = a.getResourceId(R.styleable.AnimatedVectorDrawable_android_drawable, 0);
          if (drawableRes != 0) {
            VectorDrawable vectorDrawable =
                (VectorDrawable) VectorDrawable.create(res, drawableRes).mutate();
            vectorDrawable.setAllowCaching(false);
            pathErrorScale = vectorDrawable.getPixelSize();
            mAnimatedVectorState.mVectorDrawable = vectorDrawable;
          }
          a.recycle();
        } else if (TARGET.equals(tagName)) {
          final TypedArray a =
              obtainAttributes(res, theme, attrs, R.styleable.AnimatedVectorDrawableTarget);
          final String target = a.getString(R.styleable.AnimatedVectorDrawableTarget_android_name);

          int id = a.getResourceId(R.styleable.AnimatedVectorDrawableTarget_android_animation, 0);
          if (id != 0) {
            // path animators require separate handling
            Animator objectAnimator;
            if (isPath(target)) {
              objectAnimator = getPathAnimator(c, res, theme, id, pathErrorScale);
            } else {
              objectAnimator = AnimatorInflater.loadAnimator(c, id);
            }
            setupAnimatorsForTarget(target, objectAnimator);
          }
          a.recycle();
        }
      }

      eventType = parser.next();
    }
  }
 @SuppressLint("NewApi")
 private void init(Context context, AttributeSet attributeSet) {
   mVisible = true;
   mColorNormal = getColor(R.color.material_blue_500);
   mColorPressed = darkenColor(mColorNormal);
   mColorRipple = lightenColor(mColorNormal);
   mColorDisabled = getColor(android.R.color.darker_gray);
   mType = TYPE_NORMAL;
   mShadow = true;
   mScrollThreshold = getResources().getDimensionPixelOffset(R.dimen.fab_scroll_threshold);
   mShadowSize = getDimension(R.dimen.fab_shadow_size);
   if (hasLollipopApi()) {
     StateListAnimator stateListAnimator =
         AnimatorInflater.loadStateListAnimator(context, R.anim.fab_press_elevation);
     setStateListAnimator(stateListAnimator);
   }
   if (attributeSet != null) {
     initAttributes(context, attributeSet);
   }
   updateBackground();
 }
示例#13
0
  public void animateYourself() {
    final ViewGroup parent = (ViewGroup) view.getParent();

    if (pinBackgroundAnim != null) {
      pinBackgroundAnim.end();
      pinBackgroundAnim = null;
    }

    pinBackgroundAnim =
        (ObjectAnimator)
            AnimatorInflater.loadAnimator(view.getContext(), R.animator.pin_background_start);

    pinBackgroundAnim.setTarget(parent);
    pinBackgroundAnim.setEvaluator(new ArgbEvaluator());
    pinBackgroundAnim.addListener(
        new AnimatorListener() {

          @Override
          public void onAnimationStart(Animator animation) {
            // NO OP
          }

          @Override
          public void onAnimationRepeat(Animator animation) {}

          @Override
          public void onAnimationEnd(Animator animation) {}

          @Override
          public void onAnimationCancel(Animator animation) {
            endAnimation = getCancelAnimator();
            endAnimation.start();
          }
        });
    pinBackgroundAnim.start();
  }
示例#14
0
 private Animator createAnimator(View v, int resourceId) {
   Animator animator = AnimatorInflater.loadAnimator(v.getContext(), resourceId);
   animator.setTarget(v);
   return animator;
 }
示例#15
0
  public void btnMenu(View view) {
    //        Animation animation = AnimationUtils.loadAnimation(this,R.anim.anim_menu);
    //        ivMenu.startAnimation(animation);
    ivItem1.setVisibility(View.VISIBLE);
    ivItem2.setVisibility(View.VISIBLE);
    ivItem3.setVisibility(View.VISIBLE);
    ivItem4.setVisibility(View.VISIBLE);
    Animator animator = null;

    current++;
    if (current % 2 == 0) {
      // 进来效果
      animator = AnimatorInflater.loadAnimator(this, R.animator.animator_in_menu);
      animator.setTarget(ivMenu);
      animator.start();
      animator = AnimatorInflater.loadAnimator(this, R.animator.animator_in_item1);
      animator.setTarget(ivItem1);
      animator.setInterpolator(new AnticipateOvershootInterpolator());
      animator.start();
      animator = AnimatorInflater.loadAnimator(this, R.animator.animator_in_item2);
      animator.setTarget(ivItem2);
      animator.setInterpolator(new AnticipateOvershootInterpolator());
      animator.start();
      animator = AnimatorInflater.loadAnimator(this, R.animator.animator_in_item3);
      animator.setTarget(ivItem3);
      animator.setInterpolator(new AnticipateOvershootInterpolator());
      animator.start();
      animator = AnimatorInflater.loadAnimator(this, R.animator.animator_in_item4);
      animator.setTarget(ivItem4);
      animator.setInterpolator(new AnticipateOvershootInterpolator());
      animator.start();
    } else {
      // 出去界面效果
      animator = AnimatorInflater.loadAnimator(this, R.animator.animator_menu);
      animator.setTarget(ivMenu);
      animator.start();

      animator = AnimatorInflater.loadAnimator(this, R.animator.animator_item1);
      animator.setInterpolator(new AnticipateOvershootInterpolator());
      animator.setTarget(ivItem1);
      animator.start();

      animator = AnimatorInflater.loadAnimator(this, R.animator.animator_item2);
      animator.setTarget(ivItem2);
      animator.setInterpolator(new AnticipateOvershootInterpolator());
      animator.start();

      animator = AnimatorInflater.loadAnimator(this, R.animator.animator_item3);
      animator.setTarget(ivItem3);
      animator.setInterpolator(new AnticipateOvershootInterpolator());
      animator.start();
      animator = AnimatorInflater.loadAnimator(this, R.animator.animator_item4);
      animator.setTarget(ivItem4);
      animator.setInterpolator(new AnticipateOvershootInterpolator());
      animator.start();
      animator = AnimatorInflater.loadAnimator(this, R.animator.animator_item4);
      animator.setTarget(ivItem4);
      animator.setInterpolator(new AnticipateOvershootInterpolator());
      animator.start();
    }
  }
  @Override
  public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
    Log.d("Explorer animation", "CreateAnimator: " + transit + " " + enter + " " + nextAnim);

    int animationLength = 0;

    if (nextAnim == R.animator.picker_fragment_explorer_welcome_enter) {
      list.setAlpha(0);
      list.post(
          new Runnable() {
            @Override
            public void run() {
              list.setAlpha(1);
              int offsetIncreaseOffset = 0;
              for (int i = 0; i < list.getChildCount(); i++) {
                View searchItemView = list.getChildAt(i);
                AnimationSet slideInAnimation = new AnimationSet(true);
                slideInAnimation.setInterpolator(new MaterialInterpolator());
                slideInAnimation.setDuration(180);
                if (items.get(i) instanceof HeaderItem) {
                  offsetIncreaseOffset += 150;
                  slideInAnimation.setStartOffset(i * 50 + offsetIncreaseOffset);
                  offsetIncreaseOffset += 200;
                } else slideInAnimation.setStartOffset(i * 50 + offsetIncreaseOffset);
                AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
                slideInAnimation.addAnimation(alphaAnimation);
                TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, 150, 0);
                slideInAnimation.addAnimation(translateAnimation);
                searchItemView.startAnimation(slideInAnimation);
              }
            }
          });
      animationLength = list.getChildCount() * 100 + 50;
      Log.d("Explorer animation", "CreateAnimator: enter");
    } else if (nextAnim == R.animator.picker_fragment_explorer_enter) {
      list.setAlpha(0);
      list.post(
          new Runnable() {
            @Override
            public void run() {
              list.setAlpha(1);
              int offsetIncreaseOffset = 0;
              for (int i = 0; i < list.getChildCount(); i++) {
                View searchItemView = list.getChildAt(i);
                AnimationSet slideInAnimation = new AnimationSet(true);
                slideInAnimation.setInterpolator(new MaterialInterpolator());
                slideInAnimation.setDuration(100);
                slideInAnimation.setStartOffset(i * 50 + offsetIncreaseOffset);
                AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
                slideInAnimation.addAnimation(alphaAnimation);
                TranslateAnimation translateAnimation = new TranslateAnimation(100, 0, 0, 0);
                slideInAnimation.addAnimation(translateAnimation);
                searchItemView.startAnimation(slideInAnimation);
              }
            }
          });
      animationLength = list.getChildCount() * 100 + 50;
      Log.d("Explorer animation", "CreateAnimator: enter");
    } else if (nextAnim == R.animator.picker_fragment_explorer_welcome_exit
        || nextAnim == R.animator.picker_fragment_explorer_exit) {
      for (int i = 0; i < list.getChildCount(); i++) {
        View searchItemView = list.getChildAt(i);
        AnimationSet slideInAnimation = new AnimationSet(true);
        slideInAnimation.setInterpolator(new MaterialInterpolator());
        slideInAnimation.setDuration(100);
        slideInAnimation.setStartOffset(i * 50);
        slideInAnimation.setFillAfter(true);
        AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
        alphaAnimation.setFillAfter(true);
        slideInAnimation.addAnimation(alphaAnimation);
        TranslateAnimation translateAnimation = new TranslateAnimation(0, -100, 0, 0);
        slideInAnimation.addAnimation(translateAnimation);
        searchItemView.startAnimation(slideInAnimation);
      }

      animationLength = 0; // list.getChildCount() * 100 + 50;
      Log.d("Explorer animation", "CreateAnimator: exit");
    } else if (nextAnim == R.animator.picker_fragment_explorer_return) {
      list.setAlpha(0);
      list.post(
          new Runnable() {
            @Override
            public void run() {
              list.setAlpha(1);
              for (int i = 0; i < list.getChildCount(); i++) {
                View searchItemView = list.getChildAt(i);
                AnimationSet slideInAnimation = new AnimationSet(true);
                slideInAnimation.setInterpolator(new MaterialInterpolator());
                slideInAnimation.setDuration(100);
                slideInAnimation.setStartOffset(i * 50);
                AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
                slideInAnimation.addAnimation(alphaAnimation);
                TranslateAnimation translateAnimation = new TranslateAnimation(-100, 0, 0, 0);
                slideInAnimation.addAnimation(translateAnimation);
                searchItemView.startAnimation(slideInAnimation);
              }
            }
          });
      animationLength = list.getChildCount() * 100 + 50;
      Log.d("Explorer animation", "CreateAnimator: return");
    } else if (nextAnim == R.animator.picker_fragment_explorer_out) {
      for (int i = 0; i < list.getChildCount(); i++) {
        View searchItemView = list.getChildAt(i);
        AnimationSet slideInAnimation = new AnimationSet(true);
        slideInAnimation.setInterpolator(new MaterialInterpolator());
        slideInAnimation.setDuration(100);
        slideInAnimation.setStartOffset(i * 50);
        slideInAnimation.setFillAfter(true);
        AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
        alphaAnimation.setFillAfter(true);
        slideInAnimation.addAnimation(alphaAnimation);
        TranslateAnimation translateAnimation = new TranslateAnimation(0, 100, 0, 0);
        slideInAnimation.addAnimation(translateAnimation);
        searchItemView.startAnimation(slideInAnimation);
      }
      if (items.size() == 1) {
        AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
        alphaAnimation.setInterpolator(new MaterialInterpolator());
        alphaAnimation.setDuration(100);
        alphaAnimation.setFillAfter(true);
        emptyView.startAnimation(alphaAnimation);
        statusView.startAnimation(alphaAnimation);
        animationLength = 250;
      } // else
      animationLength = 0; // list.getChildCount() * 100 + 50;
      Log.d("Explorer animation", "CreateAnimator: out");
    }

    AnimatorSet animator =
        (AnimatorSet)
            AnimatorInflater.loadAnimator(
                pickerActivity, R.animator.picker_fragment_explorer_enter);
    animator.setDuration(animationLength);

    return animator;
  }