コード例 #1
0
    public static void animateShowing(
        final ViewHolder holder, final ListAdapter adapter, boolean isAnimate) {
      final CheckBox checkBox = holder.checkBox;
      if (checkBox.getVisibility() == View.VISIBLE) {
        return;
      }
      checkBox.setVisibility(View.VISIBLE);
      checkBox.setAlpha(0.0f);
      final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
      final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
      checkBox.measure(widthSpec, heightSpec);
      ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) checkBox.getLayoutParams();
      final long transValue = checkBox.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;

      if (!isAnimate) {
        checkBox.setAlpha(1.0f);
        holder.contentLayout.setTranslationX(transValue);
        return;
      }

      final ObjectAnimator transBodyAnimator = new ObjectAnimator();
      final PropertyValuesHolder trans =
          PropertyValuesHolder.ofFloat("TranslationX", 0.0f, transValue);
      transBodyAnimator.setTarget(holder.contentLayout);
      transBodyAnimator.setValues(trans);
      transBodyAnimator.setDuration(DURATION);

      ObjectAnimator checkBoxAnim = new ObjectAnimator();
      final PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("ScaleX", 0.0f, 1.0f);
      final PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("ScaleY", 0.0f, 1.0f);
      final PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("Alpha", 0.0f, 1.0f);
      checkBoxAnim.setValues(scaleX, scaleY, alpha);
      checkBoxAnim.setTarget(holder.checkBox);
      checkBoxAnim.setDuration(DURATION);
      checkBoxAnim.setInterpolator(new DecelerateInterpolator());
      checkBoxAnim.addListener(
          new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
              checkBox.setTag("animating");
            }

            @Override
            public void onAnimationEnd(Animator animation) {
              // adapter.setCheckBoxAnimator(false);
              checkBox.setTag("animated");
            }
          });
      if (!(checkBox.getTag() != null && "animating".equals(checkBox.getTag()))) {
        // 若正在播放动画,则不继续播放动画
        transBodyAnimator.start();
        checkBoxAnim.start();
      }
    }
コード例 #2
0
    public static void animateHiding(
        final ViewHolder holder, final ListAdapter adapter, boolean isAnimate) {
      final CheckBox checkBox = holder.checkBox;
      final View tansBody = holder.contentLayout;

      if (checkBox.getVisibility() == View.GONE) {
        return;
      }
      ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) checkBox.getLayoutParams();
      final float transValue = checkBox.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;

      if (!isAnimate) {
        checkBox.setVisibility(View.GONE);
        holder.contentLayout.setTranslationX(0.0f);
        return;
      }
      final ObjectAnimator transBodyAnimator = new ObjectAnimator();
      final PropertyValuesHolder trans =
          PropertyValuesHolder.ofFloat("TranslationX", transValue, 0.0f);
      transBodyAnimator.setTarget(tansBody);
      transBodyAnimator.setValues(trans);
      transBodyAnimator.setDuration(DURATION);

      ObjectAnimator checkBoxAnim = new ObjectAnimator();
      final PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("ScaleX", 1.0f, 0.0f);
      final PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("ScaleY", 1.0f, 0.0f);
      final PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("Alpha", 1.0f, 0.0f);
      checkBoxAnim.setValues(scaleX, scaleY, alpha);
      checkBoxAnim.setTarget(checkBox);
      checkBoxAnim.setDuration(DURATION);
      checkBoxAnim.setInterpolator(new AccelerateInterpolator());
      checkBoxAnim.addListener(
          new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
              checkBox.setTag("animating");
            }

            @Override
            public void onAnimationEnd(Animator animation) {
              // adapter.setCheckBoxAnimator(false);
              checkBox.setScaleX(1.0f);
              checkBox.setScaleY(1.0f);
              checkBox.setAlpha(1.0f);
              checkBox.setVisibility(View.GONE);
              checkBox.setTag("animated");
            }
          });
      if (!(checkBox.getTag() != null && "animating".equals(checkBox.getTag()))) {
        transBodyAnimator.start();
        checkBoxAnim.start();
      }
    }
コード例 #3
0
 public void myHandler(View v) {
   CheckBox cb = (CheckBox) v;
   Magazine leMagazine = (Magazine) cb.getTag();
   long id = leMagazine.getId();
   //            int position = Integer.parseInt(cb.getTag(2).toString());
   if (cb.isChecked()) {
     lesIdMagazines.add(id);
   } else {
     lesIdMagazines.remove(id);
   }
 }
コード例 #4
0
 @Override
 public void onClick(View v) {
   if (v.getId() == R.id.checkBox_alarm_active) {
     CheckBox checkBox = (CheckBox) v;
     Alarm alarm = (Alarm) alarmListAdapter.getItem((Integer) checkBox.getTag());
     alarm.setAlarmActive(checkBox.isChecked());
     Database.update(alarm);
     AlarmActivity.this.callMathAlarmScheduleService();
     if (checkBox.isChecked()) {
       Toast.makeText(AlarmActivity.this, alarm.getTimeUntilNextAlarmMessage(), Toast.LENGTH_LONG)
           .show();
     }
   }
 }
コード例 #5
0
 @Override
 public void dismiss() {
   if (outCbx != null && outCbx.isChecked()) {
     int id = radioGroup.getCheckedRadioButtonId();
     RadioButton rbt = (RadioButton) radioGroup.findViewById(id);
     Integer old_tag = (Integer) outCbx.getTag();
     if (old_tag == null) {
       super.dismiss();
       return;
     }
     if (old_tag != id) {
       outCbx.setTag(id);
       outCbx.setText(rbt.getText());
     } else {
       outCbx.setTag(-1);
     }
     outCbx.setChecked(false);
   }
   super.dismiss();
 }