package com.cc.view;

import com.cc.R;
import com.cc.R.layout;
import com.cc.R.menu; import android.opengl.Visibility;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.util.Log;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.Menu;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView; public class GestureDetectorAty extends Activity { private Button mButton;
private GestureDetector mGestureDetector; private LinearLayout mLayout;
private TextView mCancel; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aty_gesture_detector);
mLayout = (LinearLayout) findViewById(R.id.displayrecord); mCancel = (TextView) findViewById(R.id.tv_cancelrecord); mGestureDetector = new GestureDetector(this, new MyOnGestureListener(
this)); mButton = (Button) findViewById(R.id.btn_textgesture);
mButton.setFocusableInTouchMode(true);
mButton.setOnTouchListener(new OnTouchListener() { @Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
break;
}
case MotionEvent.ACTION_MOVE: { final float p1x = event.getX();
break;
}
case MotionEvent.ACTION_UP: {
mLayout.setVisibility(View.GONE);
mCancel.setVisibility(View.GONE);
break;
}
default:
break;
}
mGestureDetector.onTouchEvent(event);
// 一定要返回true,不然获取不到完整的事件
return true;
} }); } public class MyOnGestureListener extends SimpleOnGestureListener {
private GestureDetectorAty mActivity; public MyOnGestureListener(Context context) {
this.mActivity = (GestureDetectorAty) context;
} @Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
super.onLongPress(e);
} @Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
float p2y = e2.getY();
float p1y = e1.getY();
if (p1y - p2y > ) {
if (e2.getX() - e1.getX() > - | e2.getX() - e1.getX() < ) { }
} // TODO Auto-generated method stub
return super.onFling(e1, e2, velocityX, velocityY);
} // 按住 且为达到onLongPress之前 调用 一旦调用就不会有onSingleTapUp
// 点击了触摸屏,但是没有移动和弹起的动作。onShowPress和onDown的区别在于
// onDown是,一旦触摸屏按下,就马上产生onDown事件,但是onShowPress是onDown事件产生后,
// 一段时间内,如果没有移动鼠标和弹起事件,就认为是onShowPress事件。
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
super.onShowPress(e); } // 按下的时候触发
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
mLayout.setVisibility(View.VISIBLE);
return super.onDown(e);
} // 离开屏幕的一刹那
// 轻击触摸屏后,弹起。如果这个过程中产生了onLongPress、onScroll和onFling事件,就不会
// 产生onSingleTapUp事件。
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
isScroll = true;
mLayout.setVisibility(View.GONE); return super.onSingleTapUp(e);
} @Override
public boolean onSingleTapConfirmed(MotionEvent e) {
// TODO Auto-generated method stub
return super.onSingleTapConfirmed(e);
} private boolean isScroll = true; // 滚动事件,当在触摸屏上迅速的移动,会产生onScroll。由ACTION_MOVE产生
// e1:第1个ACTION_DOWN MotionEvent
// e2:最后一个ACTION_MOVE MotionEvent
// distanceX:距离上次产生onScroll事件后,X抽移动的距离
// distanceY:距离上次产生onScroll事件后,Y抽移动的距离
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
// TODO Auto-generated method stub
if (e1.getY() - e2.getY() > ) {
if (e2.getX() - e1.getX() > - | e2.getX() - e1.getX() < ) {
if (isScroll) {
isScroll = false;
mCancel.setVisibility(View.VISIBLE);
mLayout.setVisibility(View.GONE); }
}
} else if (e1.getY() - e2.getY() < ) {
if (e2.getX() - e1.getX() > - | e2.getX() - e1.getX() < ) {
isScroll = true;
if (isScroll) {
mCancel.setVisibility(View.GONE);
mLayout.setVisibility(View.VISIBLE);
}
}
}
return super.onScroll(e1, e2, distanceX, distanceY);
}
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".GestureDetectorAty" > <Button
android:id="@+id/btn_textgesture"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerInParent="true"
android:text="@string/app_name" /> <LinearLayout
android:id="@+id/displayrecord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btn_textgesture"
android:layout_centerHorizontal="true"
android:layout_marginBottom="50dp"
android:orientation="horizontal"
android:visibility="gone" > <ImageView
android:id="@+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon" /> <TextView
android:id="@+id/tv_displayrecord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开始录制"
android:textColor="@color/green" />
</LinearLayout> <TextView
android:id="@+id/tv_cancelrecord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btn_textgesture"
android:layout_centerHorizontal="true"
android:layout_marginBottom="150dp"
android:background="@color/red"
android:visibility="gone"
android:text="取消录制"
android:textColor="@color/white" /> </RelativeLayout>

android 入门-防微信拍摄视频 按钮事件处理的更多相关文章

  1. Android 自定义View,仿微信视频播放按钮

    闲着,尝试实现了新版微信视频播放按钮,使用的是自定义View,先来个简单的效果图...真的很简单哈. 由于暂时用不到,加上时间原因,加上实在是没意思,加上……,本控件就没有实现自定义属性,有兴趣的朋友 ...

  2. Android防微信首页左右滑动切换

    大家看到微信首页切换效果有没有觉得很炫,滑动切换,点击底部bar瞬间切换,滑动切换渐变效果,线上效果图: 之前也在博客上看到别人的实现,再次基础上,我做了些优化.首先说下实现原理,大神略过,o(╯□╰ ...

  3. Android零基础入门第34节:Android中基于监听的事件处理

    原文:Android零基础入门第34节:Android中基于监听的事件处理 上一期我们学习了Android中的事件处理,也详细学习了Android中基于监听的事件处理,同时学会了匿名内部类形式,那么本 ...

  4. 【详细】Android入门到放弃篇-YES OR NO-》各种UI组件,布局管理器,单元Activity

    问:达叔,你放弃了吗? 答:不,放弃是不可能的,丢了Android,你会心疼吗?如果别人把你丢掉,你是痛苦呢?还是痛苦呢?~ 引导语 有人说,爱上一个人是痛苦的,有人说,喜欢一个人是幸福的. 人与人之 ...

  5. Android:仿微信开场切换界面

    这实例很多人仿做,好实例还是不容错过!最重要是素材容易拿~ 效果: 默认3页面的切换,最后一个页面带按钮,点击进入另外一个页面 思路: 1.准备5个布局页面,1个为主函数布局页面,3个为切换的页面(其 ...

  6. Android入门1:使用VideoView和MediController播放视频

    最近在搞Android,入门曲线还是挺陡峭的,主要还是自己对Java的理解不够深入.前后学习了几天,把最近学习到的一些知识点总结归纳一下,正所谓温故而知新. 目前想搞一个禁播视频站,主要内容都是一些大 ...

  7. 小猪的Android入门之路 Day 4 - part 1

    小猪的Android入门之路 Day 4 - part 1 Android事件处理机制之--基于监听的事件处理机制 本节引言: 在開始本个章节前,我们先回想下,如今我们已经知道了android的一些相 ...

  8. Android入门第一课之Java基础

    通知:由于本周六场地申请没通过,所以本周的培训临时取消. 今天给大家带来的是Android入门的第一课,由于教室申请的不确定性,因此,每次培训的内容都会在博客先提前释放出来.首先Android的APP ...

  9. 前端之Android入门(3):MVC模式(上)

    很多Android的入门书籍,在前面介绍完布局后就会逐个介绍组件,然后开始编写组件使用的例子.每每到此时小伙伴们都可能会有些疑问:是否应该先啃完一本<Java编程思想>学点 Java 知识 ...

随机推荐

  1. python查找并删除相同文件-UNIQ File-script版本

    今天用wxPython做了一个GUI程序,实现查找指定目录内的相同文件,主要原理是计算文件的md5值(计算前先找出文件大小相同的文件,然后计算这些文件的md5值,而不是所有文件都计算,大大减少了md5 ...

  2. 深度分析Linux下双网卡绑定七种模式 多网卡的7种bond模式原理

    http://blog.csdn.net/abc_ii/article/details/9991845多网卡的7种bond模式原理 Linux网卡绑定mode共有七种(~) bond0.bond1.b ...

  3. CentOS 6.4 搭建git 服务器

    CentOS 6.4 搭建git 服务器 (2013-11-22 19:04:09)转载▼ 标签: it 分类: Linux 此文件是依据markdown所编写,更好效果参见本人github的文档ht ...

  4. iOS学习笔记(2)--Xcode6.1创建仅xib文件无storyboard的hello world应用

    http://www.mamicode.com/info-detail-514151.html 由于Xcode6之后,默认创建storyboard而非xib文件,而作为初学,了解xib的加载原理很重要 ...

  5. KVC 与 KVO 理解

    KVC 与 KVO 是 Objective C 的关键概念,个人认为必须理解的东西,下面是实例讲解. Key-Value Coding (KVC) KVC,即是指 NSKeyValueCoding,一 ...

  6. ffmpeg-20160508-git-bin-v2

    ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...

  7. springmvc 文件下传、上载、预览。以二进制形式存放到数据库(转载)

    springmvc 文件上传.下载.预览.以二进制形式存放到数据库.数据库中的关于传入附件的字段我写了2个:一个存放内容accessory,一个存放文件的后缀filetype 上传:首先需要2个必须的 ...

  8. DREAMWEAVER

    女孩儿!!!Coding之路,你没有什么不一样的!!!! 1024,程序员的节日,开会的时候,你对负责人说今天是我们的节日哎~~结果,得到的是负责人冷冰冰的眼神:“你还真把自己当程序员了!?” 一阵愣 ...

  9. 【leetcode】Substring with Concatenation of All Words (hard) ★

    You are given a string, S, and a list of words, L, that are all of the same length. Find all startin ...

  10. CString 操作

    CString Left( int nCount ) const;                   //从左边1开始获取前 nCount 个字符 CString Mid( int nFirst ) ...