Commit cb8d0442 by wjg

1、添加购物数量动画

parent f6203fad
package com.ihaoin.hooloo.device.component;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.animation.Animation;
import android.view.animation.Transformation;
/**
* An animation that rotates the view on the X,Y,Z axis between two specified angles.
* This animation also adds a translation on the Z axis (depth) to improve the effect.
*/
public class Rotate3dAnimation extends Animation {
public static final Byte ROTATE_X_AXIS = 0x00;
public static final Byte ROTATE_Y_AXIS = 0x01;
public static final Byte ROTATE_Z_AXIS = 0x02;
private final float mFromDegrees;
private final float mToDegrees;
private final float mCenterX;
private final float mCenterY;
private final float mDepthZ;
private final boolean mReverse;
private Camera mCamera;
private Byte mRotateAxis; // 0:X轴 1:Y轴 2:Z轴
/**创建3D旋转动画
* @param fromDegrees the start angle of the 3D rotation
* @param toDegrees the end angle of the 3D rotation
* @param centerX the X center of the 3D rotation
* @param centerY the Y center of the 3D rotation
* @param depthZ the Z depth of the 3D rotation
* @param rotateAxis the rotate axis of the 3D rotation
* @param reverse true if the translation should be reversed, false otherwise
*/
public Rotate3dAnimation(float fromDegrees, float toDegrees,
float centerX, float centerY, float depthZ, Byte rotateAxis, boolean reverse) {
mFromDegrees = fromDegrees;
mToDegrees = toDegrees;
mCenterX = centerX;
mCenterY = centerY;
mDepthZ = depthZ;
mRotateAxis = rotateAxis;
mReverse = reverse;
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
mCamera = new Camera();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
final float fromDegrees = mFromDegrees;
float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
final float centerX = mCenterX;
final float centerY = mCenterY;
final Camera camera = mCamera;
final Matrix matrix = t.getMatrix();
// 将当前的摄像头位置保存下来,以便变换进行完成后恢复成原位
camera.save();
if (mReverse) {
// z的偏移会越来越大。这就会形成这样一个效果,view从近到远
camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
} else {
// z的偏移会越来越小。这就会形成这样一个效果,我们的View从一个很远的地方向我们移过来,越来越近,最终移到了我们的窗口上面
camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
}
// 是给我们的View加上旋转效果,在移动的过程中,视图还会以XYZ轴为中心进行旋转。
if (ROTATE_X_AXIS.equals(mRotateAxis)) {
camera.rotateX(degrees);
} else if (ROTATE_Y_AXIS.equals(mRotateAxis)) {
camera.rotateY(degrees);
} else {
camera.rotateZ(degrees);
}
// 这个是将我们刚才定义的一系列变换应用到变换矩阵上面,调用完这句之后,我们就可以将camera的位置恢复了,以便下一次再使用。
camera.getMatrix(matrix);
// camera位置恢复
camera.restore();
// 下面两句是为了动画是以View中心为旋转点
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}
......@@ -9,6 +9,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.BounceInterpolator;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
......@@ -20,6 +21,7 @@ import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.adapter.TrolleyAdapter;
import com.ihaoin.hooloo.device.component.NetworkHandler;
import com.ihaoin.hooloo.device.component.Rotate3dAnimation;
import com.ihaoin.hooloo.device.config.Base;
import com.ihaoin.hooloo.device.data.TrolleyGoods;
import com.ihaoin.hooloo.device.data.enums.SkuState;
......@@ -176,6 +178,15 @@ public class TrolleyView extends RelativeLayout {
this.txtTotal.setText(Utils.toString(HLApplication.getGoodsCheckedTotal()));
this.setView();
this.measureListHeight();
float centerX = txtCount.getWidth() / 2f;
float centerY = txtCount.getHeight() / 2f;
Animation anim = new Rotate3dAnimation(180f, 360f, centerX, centerY, 0f, Rotate3dAnimation.ROTATE_Y_AXIS, true);
anim.setFillAfter(true); // 设置保持动画最后的状态
anim.setDuration(800); // 设置动画时间
anim.setInterpolator(new BounceInterpolator()); // 设置插入器
txtCount.startAnimation(anim);
}
public Boolean checkGoodsCount() {
......
......@@ -93,6 +93,7 @@
android:layout_alignParentEnd="true"
android:background="@drawable/ic_dot"
android:gravity="center"
android:text="0"
android:textColor="@color/white"
android:textSize="@dimen/ts_trolley_count"
android:textStyle="bold" />
......
<resources>
<dimen name="padding20">20dp</dimen>
<dimen name="padding15">15dp</dimen>
<dimen name="padding10">10dp</dimen>
<dimen name="padding7">7dp</dimen>
<dimen name="padding5">5dp</dimen>
<dimen name="padding3">3dp</dimen>
<dimen name="toast_width">376dp</dimen>
<dimen name="toast_padding_hor">32dp</dimen>
<dimen name="toast_padding_ver">55dp</dimen>
<dimen name="recommend_padding">5dp</dimen>
<dimen name="recommend_image_height_0">794dp</dimen>
<dimen name="recommend_image_height_other">392dp</dimen>
<dimen name="recommend_name_margin_top">82dp</dimen>
<dimen name="recommend_name_margin_left">68dp</dimen>
<dimen name="recommend_desc_margin_top">30dp</dimen>
<dimen name="recommend_desc_margin_left">68dp</dimen>
<dimen name="goods_padding_top">30dp</dimen>
<dimen name="goods_padding_ver">15dp</dimen>
<dimen name="goods_padding_right">38dp</dimen>
<dimen name="goods_last_padding_bottom">200dp</dimen>
<dimen name="goods_thum_size">100dp</dimen>
<dimen name="goods_thum_margin_right">10dp</dimen>
<dimen name="goods_recommend_margin">5dp</dimen>
<dimen name="goods_category_margin_top">10dp</dimen>
<dimen name="goods_tag_margin_top">5dp</dimen>
<dimen name="goods_tag_padding_ver">2dp</dimen>
<dimen name="goods_tag_padding_hor">10dp</dimen>
<dimen name="goods_tag_margin_right">16dp</dimen>
<dimen name="goods_desc_margin_top">5dp</dimen>
<dimen name="goods_butns_margin_top">5dp</dimen>
<dimen name="goods_price_margin">5dp</dimen>
<dimen name="category_padding_ver">20dp</dimen>
<dimen name="category_padding_hor">20dp</dimen>
<dimen name="category_margin">20dp</dimen>
<dimen name="category_divider_padding">0dp</dimen>
<dimen name="tip_margin_top">10dp</dimen>
<dimen name="tip_padding_top">33dp</dimen>
<dimen name="tip_padding_bottom">33dp</dimen>
<dimen name="menu_divider_padding_hor">10dp</dimen>
<dimen name="menu_divider_padding_top">20dp</dimen>
<dimen name="menu_divider_padding_bottom">20dp</dimen>
<dimen name="menu_content_padding_hor">25dp</dimen>
<dimen name="menu_content_padding_top">18dp</dimen>
<dimen name="menu_content_padding_bottom">18dp</dimen>
<dimen name="menu_order_margin_top">23dp</dimen>
<dimen name="menu_spacing_hor">10dp</dimen>
<dimen name="menu_spacing_ver">100dp</dimen>
<dimen name="goods_detail_padding_ver">55dp</dimen>
<dimen name="goods_detail_padding_hor">40dp</dimen>
<dimen name="goods_detail_content_margin_left">40dp</dimen>
<dimen name="goods_detail_image_margin_top">50dp</dimen>
<dimen name="goods_detail_spec_margin_top">25dp</dimen>
<dimen name="goods_detail_rule_width">80dp</dimen>
<dimen name="goods_detail_rule_margin_top">28dp</dimen>
<dimen name="goods_detail_rule_margin_right">16dp</dimen>
<dimen name="goods_detail_rule_padding_hor">60dp</dimen>
<dimen name="goods_detail_rule_padding_ver">10dp</dimen>
<dimen name="goods_detail_layout_rule_margin_top">17dp</dimen>
<dimen name="goods_detail_rec_padding_hor">12dp</dimen>
<dimen name="goods_detail_rec_padding_ver">5dp</dimen>
<dimen name="goods_detail_oper_margin_top">24dp</dimen>
<dimen name="goods_detail_oper_margin_left">55dp</dimen>
<dimen name="goods_detail_oper_margin_bottom">28dp</dimen>
<dimen name="goods_detail_oper_margin_right">35dp</dimen>
<dimen name="goods_detail_price_margin_right">3dp</dimen>
<dimen name="goods_detail_butn_margin_top">28dp</dimen>
<dimen name="goods_detail_butn_padding">23dp</dimen>
<dimen name="goods_detail_count_margin_left">36dp</dimen>
<dimen name="goods_detail_count_margin_right">40dp</dimen>
<dimen name="goods_detail_indicator_margin">20dp</dimen>
<dimen name="dialog_detail_width">600dp</dimen>
<dimen name="dialog_tip_width">600dp</dimen>
<dimen name="dialog_clear_width">715dp</dimen>
<dimen name="dialog_clear_height">385dp</dimen>
<dimen name="dialog_close_margin">35dp</dimen>
<dimen name="clear_butn_height">100dp</dimen>
<dimen name="clear_butn_text">40dp</dimen>
<dimen name="trolley_width">400dp</dimen>
<dimen name="trolley_item_height">100dp</dimen>
<dimen name="trolley_bar_height">60dp</dimen>
<dimen name="trolley_pay_width">150dp</dimen>
<dimen name="trolley_ic_margin_left">80dp</dimen>
<dimen name="trolley_ic_parent_width">110dp</dimen>
<dimen name="trolley_ic_parent_height">120dp</dimen>
<dimen name="trolley_ic_width">92dp</dimen>
<dimen name="trolley_ic_height">110dp</dimen>
<dimen name="trolley_ic_border_size">50dp</dimen>
<dimen name="trolley_count_size">20dp</dimen>
<dimen name="trolley_title_margin_ver">30dp</dimen>
<dimen name="trolley_title_margin_hor">38dp</dimen>
<dimen name="trolley_clear_text_margin_left">8dp</dimen>
<dimen name="trolley_clear_text_margin_right">30dp</dimen>
<dimen name="trolley_line_margin">40dp</dimen>
<dimen name="trolley_thum_size">142dp</dimen>
<dimen name="trolley_thum_margin">40dp</dimen>
<dimen name="trolley_item_padding_top">40dp</dimen>
<dimen name="trolley_item_padding_left">40dp</dimen>
<dimen name="trolley_item_padding_bottom">20dp</dimen>
<dimen name="trolley_item_padding_right">40dp</dimen>
<dimen name="trolley_options_margin_top">16dp</dimen>
<dimen name="trolley_price_margin_top">25dp</dimen>
<dimen name="trolley_price_margin_left">11dp</dimen>
<dimen name="trolley_count_margin">28dp</dimen>
<dimen name="trolley_oper_margin">20dp</dimen>
<dimen name="confirm_order_width">1000dp</dimen>
<dimen name="confirm_order_padding_top">62dp</dimen>
<dimen name="confirm_order_padding_bottom">37dp</dimen>
<dimen name="confirm_order_qr_margin_top">45dp</dimen>
<dimen name="confirm_order_qrcode_size">375dp</dimen>
<dimen name="confirm_order_icon_margin">40dp</dimen>
<dimen name="confirm_order_text_one">62dp</dimen>
<dimen name="confirm_order_text_two">7dp</dimen>
<dimen name="ic_recommend">10dp</dimen>
<dimen name="ic_clear_size">15dp</dimen>
<dimen name="ic_add_size">20dp</dimen>
<dimen name="ic_subtract_size">20dp</dimen>
<dimen name="ic_checkbox">25dp</dimen>
<dimen name="ic_detail_add_size">20dp</dimen>
<dimen name="ic_detail_subtract_size">20dp</dimen>
<dimen name="ic_dialog_close">20dp</dimen>
<dimen name="ic_scan_succ_width">101dp</dimen>
<dimen name="ic_scan_succ_height">97dp</dimen>
<dimen name="ts_toast">28sp</dimen>
<dimen name="ts_trolley_item_price">20sp</dimen>
<dimen name="ts_trolley_item_discount">22sp</dimen>
<dimen name="ts_recommend_name">20sp</dimen>
<dimen name="ts_recommend_desc">20sp</dimen>
<dimen name="ts_category_radio">12sp</dimen>
<dimen name="ts_category_item">18sp</dimen>
<dimen name="ts_goods_item_name">14sp</dimen>
<dimen name="ts_goods_item_intro">12sp</dimen>
<dimen name="ts_goods_item_price">9sp</dimen>
<dimen name="ts_goods_item_discount">12sp</dimen>
<dimen name="ts_goods_item_sellout">12sp</dimen>
<dimen name="ts_goods_item_tag">9sp</dimen>
<dimen name="ts_trolley_item_count">12sp</dimen>
<dimen name="ts_trolley_name">18sp</dimen>
<dimen name="ts_trolley_clear">12sp</dimen>
<dimen name="ts_trolley_total">16sp</dimen>
<dimen name="ts_trolley_count">12sp</dimen>
<dimen name="ts_trolley_pay">16sp</dimen>
<dimen name="ts_tips">9sp</dimen>
<dimen name="ts_detail_name">20sp</dimen>
<dimen name="ts_detail_spec">14sp</dimen>
<dimen name="ts_detail_spec_rec">6sp</dimen>
<dimen name="ts_detail_rule">12sp</dimen>
<dimen name="ts_detail_count">14sp</dimen>
<dimen name="ts_detail_price">12sp</dimen>
<dimen name="ts_detail_discount">14sp</dimen>
<dimen name="ts_detail_add_trolley">14sp</dimen>
<dimen name="ts_detail_buynow">14sp</dimen>
<dimen name="ts_header_text">14sp</dimen>
<dimen name="ts_dialog_title">18sp</dimen>
<dimen name="ts_scan">14sp</dimen>
<dimen name="ts_expire">12sp</dimen>
<dimen name="ts_order_number">12sp</dimen>
<dimen name="ts_menu_title">22sp</dimen>
<dimen name="ts_menu_subtitle">18sp</dimen>
<dimen name="ts_menu_subtitle1">12sp</dimen>
<dimen name="ts_setting_name">16sp</dimen>
<dimen name="ts_setting_desc">14sp</dimen>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment