【高仿微信系列】微信录制小视频

本帖最后由 ☂上官๑۩۞۩ 于 2015-7-15 17:14 编辑

微信从6.0版本开始推出小视频功能,随着4G网络的出现,视频将会是一个趋势,他能表达出文字所不能表现的东西,增加了微信的黏性。还记得微信小视频这个功能一推出,如同病毒一样席卷朋友圈。

作为爱美的我们,怎么能把我们的窘态暴露给朋友圈的小伙伴呢,必须正能量!美好的!必须美化! So,录制小视频后,加各种滤镜,炫酷MV主题,妈妈再也不担心我的猪窝了…

“小视频”对于微信如此之重要。那么,如何实现呢? 
先看下咱们的实现效果:

            


PS:gif 图片比较大,如果等不及的童鞋,可以点击这里查看视频

OK,先看下,消息列表页面的 下滑显示眼睛动画效果的实现方式: 
自定义ListView:PullDownListView.java 
PullDownListView来自guojunyi的分享, GitHub项目地址:点击这里

  1. package com.example.wechat01.widght;

  2. import android.content.Context;
  3. import android.graphics.Color;
  4. import android.util.AttributeSet;
  5. import android.util.Log;
  6. import android.view.MotionEvent;
  7. import android.view.View;
  8. import android.widget.AbsListView;
  9. import android.widget.AbsListView.OnScrollListener;
  10. import android.widget.ListView;
  11. import android.widget.RelativeLayout;

  12. import com.example.wechat01.R;
  13. import com.nineoldandroids.animation.ValueAnimator;
  14. import com.nineoldandroids.animation.ValueAnimator.AnimatorUpdateListener;

  15. public class PullDownListView extends RelativeLayout implements
  16.                 OnScrollListener {
  17.         static int MAX_PULL_TOP_HEIGHT;
  18.         static int MAX_PULL_BOTTOM_HEIGHT;

  19.         static int REFRESHING_TOP_HEIGHT;
  20.         static int REFRESHING_BOTTOM_HEIGHT;

  21.         private boolean isTop;
  22.         private boolean isBottom;
  23.         private boolean isRefreshing;
  24.         private boolean isAnimation;

  25.         RelativeLayout layoutHeader;
  26.         RelativeLayout layoutFooter;

  27.         private int mCurrentY = 0;
  28.         boolean pullTag = false;
  29.         OnScrollListener mOnScrollListener;
  30.         OnPullHeightChangeListener mOnPullHeightChangeListener;

  31.         public void setOnPullHeightChangeListener(
  32.                         OnPullHeightChangeListener listener) {
  33.                 this.mOnPullHeightChangeListener = listener;
  34.         }

  35.         public void setOnScrollListener(OnScrollListener listener) {
  36.                 mOnScrollListener = listener;
  37.         }

  38.         public PullDownListView(Context context, AttributeSet attrs) {
  39.                 super(context, attrs);
  40.                 // TODO Auto-generated constructor stub
  41.         }

  42.         public boolean isRefreshing() {
  43.                 return this.isRefreshing;
  44.         }

  45.         private ListView mListView = new ListView(getContext()) {

  46.                 int lastY = 0;

  47.                 @Override
  48.                 public boolean onTouchEvent(MotionEvent ev) {
  49.                         if (isAnimation || isRefreshing) {
  50.                                 return super.onTouchEvent(ev);
  51.                         }
  52.                         RelativeLayout parent = (RelativeLayout) mListView.getParent();

  53.                         int currentY = (int) ev.getRawY();
  54.                         switch (ev.getAction()) {
  55.                         case MotionEvent.ACTION_DOWN:
  56.                                 lastY = (int) ev.getRawY();
  57.                                 break;
  58.                         case MotionEvent.ACTION_MOVE: {
  59.                                 boolean isToBottom = currentY - lastY >= 0 ? true : false;

  60.                                 int step = Math.abs(currentY - lastY);
  61.                                 lastY = currentY;

  62.                                 if (isTop && mListView.getTop() >= 0) {

  63.                                         if (isToBottom && mListView.getTop() <= MAX_PULL_TOP_HEIGHT) {
  64.                                                 MotionEvent event = MotionEvent.obtain(ev);
  65.                                                 ev.setAction(MotionEvent.ACTION_UP);
  66.                                                 super.onTouchEvent(ev);
  67.                                                 pullTag = true;

  68.                                                 if (mListView.getTop() > layoutHeader.getHeight()) {
  69.                                                         step = step / 2;
  70.                                                 }
  71.                                                 if ((mListView.getTop() + step) > MAX_PULL_TOP_HEIGHT) {
  72.                                                         mCurrentY = MAX_PULL_TOP_HEIGHT;
  73.                                                         scrollTopTo(mCurrentY);
  74.                                                 } else {
  75.                                                         mCurrentY += step;
  76.                                                         scrollTopTo(mCurrentY);
  77.                                                 }
  78.                                         } else if (!isToBottom && mListView.getTop() > 0) {
  79.                                                 MotionEvent event = MotionEvent.obtain(ev);
  80.                                                 ev.setAction(MotionEvent.ACTION_UP);
  81.                                                 super.onTouchEvent(ev);
  82.                                                 if ((mListView.getTop() - step) < 0) {
  83.                                                         mCurrentY = 0;
  84.                                                         scrollTopTo(mCurrentY);
  85.                                                 } else {
  86.                                                         mCurrentY -= step;
  87.                                                         scrollTopTo(mCurrentY);
  88.                                                 }
  89.                                         } else if (!isToBottom && mListView.getTop() == 0) {
  90.                                                 if (!pullTag) {
  91.                                                         return super.onTouchEvent(ev);
  92.                                                 }

  93.                                         }

  94.                                         return true;
  95.                                 } else if (isBottom
  96.                                                 && mListView.getBottom() <= parent.getHeight()) {
  97.                                         if (!isToBottom
  98.                                                         && (parent.getHeight() - mListView.getBottom()) <= MAX_PULL_BOTTOM_HEIGHT) {
  99.                                                 MotionEvent event = MotionEvent.obtain(ev);
  100.                                                 ev.setAction(MotionEvent.ACTION_UP);
  101.                                                 super.onTouchEvent(ev);
  102.                                                 pullTag = true;
  103.                                                 if (parent.getHeight() - mListView.getBottom() > layoutFooter
  104.                                                                 .getHeight()) {
  105.                                                         step = step / 2;
  106.                                                 }

  107.                                                 if ((mListView.getBottom() - step) < (parent
  108.                                                                 .getHeight() - MAX_PULL_BOTTOM_HEIGHT)) {
  109.                                                         mCurrentY = -MAX_PULL_BOTTOM_HEIGHT;
  110.                                                         scrollBottomTo(mCurrentY);
  111.                                                 } else {
  112.                                                         mCurrentY -= step;
  113.                                                         scrollBottomTo(mCurrentY);
  114.                                                 }
  115.                                         } else if (isToBottom
  116.                                                         && (mListView.getBottom() < parent.getHeight())) {
  117.                                                 if ((mListView.getBottom() + step) > parent.getHeight()) {
  118.                                                         mCurrentY = 0;
  119.                                                         scrollBottomTo(mCurrentY);
  120.                                                 } else {
  121.                                                         mCurrentY += step;
  122.                                                         scrollBottomTo(mCurrentY);
  123.                                                 }
  124.                                         } else if (isToBottom
  125.                                                         && mListView.getBottom() == parent.getHeight()) {
  126.                                                 if (!pullTag) {
  127.                                                         return super.onTouchEvent(ev);
  128.                                                 }
  129.                                         }
  130.                                         return true;
  131.                                 }
  132.                                 break;
  133.                         }
  134.                         case MotionEvent.ACTION_CANCEL:
  135.                         case MotionEvent.ACTION_UP:
  136.                                 pullTag = false;

  137.                                 if (mListView.getTop() > 0) {
  138.                                         if (mListView.getTop() > REFRESHING_TOP_HEIGHT) {
  139.                                                 animateTopTo(layoutHeader.getMeasuredHeight());
  140.                                                 isRefreshing = true;
  141.                                                 if (null != mOnPullHeightChangeListener) {
  142.                                                         mOnPullHeightChangeListener.onRefreshing(true);
  143.                                                 }
  144.                                         } else {
  145.                                                 animateTopTo(0);
  146.                                         }

  147.                                 } else if (mListView.getBottom() < parent.getHeight()) {
  148.                                         if ((parent.getHeight() - mListView.getBottom()) > REFRESHING_BOTTOM_HEIGHT) {
  149.                                                 animateBottomTo(-layoutFooter.getMeasuredHeight());
  150.                                                 isRefreshing = true;
  151.                                                 if (null != mOnPullHeightChangeListener) {
  152.                                                         mOnPullHeightChangeListener.onRefreshing(false);
  153.                                                 }
  154.                                         } else {
  155.                                                 animateBottomTo(0);
  156.                                         }
  157.                                 }

  158.                         }

  159.                         return super.onTouchEvent(ev);
  160.                 }

  161.         };

  162.         public void scrollBottomTo(int y) {
  163.                 mListView.layout(mListView.getLeft(), y, mListView.getRight(),
  164.                                 this.getMeasuredHeight() + y);
  165.                 if (null != mOnPullHeightChangeListener) {
  166.                         mOnPullHeightChangeListener.onBottomHeightChange(
  167.                                         layoutHeader.getHeight(), -y);
  168.                 }
  169.         }

  170.         public void animateBottomTo(final int y) {
  171.                 ValueAnimator animator = ValueAnimator.ofInt(mListView.getBottom()
  172.                                 - this.getMeasuredHeight(), y);
  173.                 animator.setDuration(300);
  174.                 animator.addUpdateListener(new AnimatorUpdateListener() {
  175.                         @Override
  176.                         public void onAnimationUpdate(ValueAnimator animation) {
  177.                                 // TODO Auto-generated method stub
  178.                                 int frameValue = (Integer) animation.getAnimatedValue();
  179.                                 mCurrentY = frameValue;
  180.                                 scrollBottomTo(frameValue);
  181.                                 if (frameValue == y) {
  182.                                         isAnimation = false;
  183.                                 }
  184.                         }
  185.                 });
  186.                 isAnimation = true;
  187.                 animator.start();
  188.         }

  189.         public void scrollTopTo(int y) {
  190.                 mListView.layout(mListView.getLeft(), y, mListView.getRight(),
  191.                                 this.getMeasuredHeight() + y);
  192.                 if (null != mOnPullHeightChangeListener) {
  193.                         mOnPullHeightChangeListener.onTopHeightChange(
  194.                                         layoutHeader.getHeight(), y);
  195.                 }
  196.         }

  197.         public void animateTopTo(final int y) {
  198.                 ValueAnimator animator = ValueAnimator.ofInt(mListView.getTop(), y);
  199.                 animator.setDuration(300);
  200.                 animator.addUpdateListener(new AnimatorUpdateListener() {
  201.                         @Override
  202.                         public void onAnimationUpdate(ValueAnimator animation) {
  203.                                 // TODO Auto-generated method stub
  204.                                 int frameValue = (Integer) animation.getAnimatedValue();
  205.                                 mCurrentY = frameValue;
  206.                                 scrollTopTo(frameValue);
  207.                                 if (frameValue == y) {
  208.                                         isAnimation = false;
  209.                                 }
  210.                         }
  211.                 });
  212.                 isAnimation = true;
  213.                 animator.start();
  214.         }

  215.         @Override
  216.         public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  217.                 super.onMeasure(widthMeasureSpec, heightMeasureSpec);

  218.                 REFRESHING_TOP_HEIGHT = layoutHeader.getMeasuredHeight();
  219.                 REFRESHING_BOTTOM_HEIGHT = layoutFooter.getMeasuredHeight();

  220.                 MAX_PULL_TOP_HEIGHT = this.getMeasuredHeight();
  221.                 MAX_PULL_BOTTOM_HEIGHT = this.getMeasuredHeight();
  222.         }

  223.         @Override
  224.         public void onFinishInflate() {

  225.                 mListView.setBackgroundColor(0xffffffff);
  226.                 mListView.setCacheColorHint(Color.TRANSPARENT);
  227.                 mListView.setVerticalScrollBarEnabled(false);
  228.                 mListView.setLayoutParams(new RelativeLayout.LayoutParams(
  229.                                 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
  230.                 mListView.setOnScrollListener(this);
  231.                 mListView.setDividerHeight(0);
  232.                 this.addView(mListView);

  233.                 layoutHeader = (RelativeLayout) this.findViewById(R.id.layoutHeader);
  234.                 layoutFooter = (RelativeLayout) this.findViewById(R.id.layoutFooter);

  235.                 super.onFinishInflate();
  236.         }

  237.         public ListView getListView() {
  238.                 return this.mListView;
  239.         }

  240.         public void pullUp() {
  241.                 isRefreshing = false;
  242.                 if (mListView.getTop() > 0) {
  243.                         animateTopTo(0);
  244.                 } else if (mListView.getBottom() < this.getHeight()) {
  245.                         animateBottomTo(0);
  246.                 }

  247.         }

  248.         @Override
  249.         public void onScroll(AbsListView view, int firstVisibleItem,
  250.                         int visibleItemCount, int totalItemCount) {
  251.                 // TODO Auto-generated method stub
  252.                 if (null != mOnScrollListener) {
  253.                         mOnScrollListener.onScroll(view, firstVisibleItem,
  254.                                         visibleItemCount, totalItemCount);
  255.                 }
  256.                 if (mListView.getCount() > 0) {
  257.                         if ((firstVisibleItem + visibleItemCount) == totalItemCount) {
  258.                                 View lastItem = (View) mListView
  259.                                                 .getChildAt(visibleItemCount - 1);
  260.                                 if (null != lastItem) {

  261.                                         if (lastItem.getBottom() == mListView.getHeight()) {
  262.                                                 Log.e("my", lastItem.getBottom() + "");
  263.                                                 isBottom = true;
  264.                                         } else {
  265.                                                 isBottom = false;
  266.                                         }
  267.                                 }
  268.                         } else {
  269.                                 isBottom = false;
  270.                         }
  271.                 } else {
  272.                         isBottom = false;
  273.                 }

  274.                 if (mListView.getCount() > 0) {
  275.                         if (firstVisibleItem == 0) {
  276.                                 View firstItem = mListView.getChildAt(0);
  277.                                 if (null != firstItem) {
  278.                                         if (firstItem.getTop() == 0) {
  279.                                                 isTop = true;
  280.                                         } else {
  281.                                                 isTop = false;
  282.                                         }
  283.                                 }
  284.                         } else {
  285.                                 isTop = false;
  286.                         }
  287.                 } else {
  288.                         isTop = true;
  289.                 }

  290.         }

  291.         @Override
  292.         public void onScrollStateChanged(AbsListView view, int scrollState) {
  293.                 // TODO Auto-generated method stub
  294.                 if (null != mOnScrollListener) {
  295.                         mOnScrollListener.onScrollStateChanged(view, scrollState);
  296.                 }
  297.         }

  298.         // listener call back
  299.         public interface OnPullHeightChangeListener {
  300.                 public void onTopHeightChange(int headerHeight, int pullHeight);

  301.                 public void onBottomHeightChange(int footerHeight, int pullHeight);

  302.                 public void onRefreshing(boolean isTop);
  303.         }
  304. }
复制代码

这个Demo比较复杂,具体实现方式请大家去Github研究一下代码吧~ 
另外还有视频录制这块的功能,有些复杂,这块是用的秒拍团队提供的视频录制SDK,感兴趣的可以去官网膜拜~


官网地址: 

OK,项目的完整代码可以去 Github (点击这里) 下载。


Download Apk


Github项目地址:https://github.com/motianhuo/VCameraDemo

文章来自:达达的梦想的博客   http://blog.csdn.net/zhaiyuanjun
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值