android 入门-防微信拍摄视频 按钮事件处理
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 入门-防微信拍摄视频 按钮事件处理的更多相关文章
- Android 自定义View,仿微信视频播放按钮
闲着,尝试实现了新版微信视频播放按钮,使用的是自定义View,先来个简单的效果图...真的很简单哈. 由于暂时用不到,加上时间原因,加上实在是没意思,加上……,本控件就没有实现自定义属性,有兴趣的朋友 ...
- Android防微信首页左右滑动切换
大家看到微信首页切换效果有没有觉得很炫,滑动切换,点击底部bar瞬间切换,滑动切换渐变效果,线上效果图: 之前也在博客上看到别人的实现,再次基础上,我做了些优化.首先说下实现原理,大神略过,o(╯□╰ ...
- Android零基础入门第34节:Android中基于监听的事件处理
原文:Android零基础入门第34节:Android中基于监听的事件处理 上一期我们学习了Android中的事件处理,也详细学习了Android中基于监听的事件处理,同时学会了匿名内部类形式,那么本 ...
- 【详细】Android入门到放弃篇-YES OR NO-》各种UI组件,布局管理器,单元Activity
问:达叔,你放弃了吗? 答:不,放弃是不可能的,丢了Android,你会心疼吗?如果别人把你丢掉,你是痛苦呢?还是痛苦呢?~ 引导语 有人说,爱上一个人是痛苦的,有人说,喜欢一个人是幸福的. 人与人之 ...
- Android:仿微信开场切换界面
这实例很多人仿做,好实例还是不容错过!最重要是素材容易拿~ 效果: 默认3页面的切换,最后一个页面带按钮,点击进入另外一个页面 思路: 1.准备5个布局页面,1个为主函数布局页面,3个为切换的页面(其 ...
- Android入门1:使用VideoView和MediController播放视频
最近在搞Android,入门曲线还是挺陡峭的,主要还是自己对Java的理解不够深入.前后学习了几天,把最近学习到的一些知识点总结归纳一下,正所谓温故而知新. 目前想搞一个禁播视频站,主要内容都是一些大 ...
- 小猪的Android入门之路 Day 4 - part 1
小猪的Android入门之路 Day 4 - part 1 Android事件处理机制之--基于监听的事件处理机制 本节引言: 在開始本个章节前,我们先回想下,如今我们已经知道了android的一些相 ...
- Android入门第一课之Java基础
通知:由于本周六场地申请没通过,所以本周的培训临时取消. 今天给大家带来的是Android入门的第一课,由于教室申请的不确定性,因此,每次培训的内容都会在博客先提前释放出来.首先Android的APP ...
- 前端之Android入门(3):MVC模式(上)
很多Android的入门书籍,在前面介绍完布局后就会逐个介绍组件,然后开始编写组件使用的例子.每每到此时小伙伴们都可能会有些疑问:是否应该先啃完一本<Java编程思想>学点 Java 知识 ...
随机推荐
- silk与opencore-amr音频编码对比
silk与opencore-amr编码对比 在采样率8000 单声道 16位采样精度情况下 silk的压缩率为 1/15 opencore-amr 1/17 对比图 原始的音频编码 opencore- ...
- redis配置文件redis.conf参数说明
redis配置文件redis.conf参数说明 (2013-01-09 21:20:40)转载▼ 标签: redis配置 redis.conf 配置说明 杂谈 分类: nosql # By defau ...
- PHP程序员如何突破成长瓶颈(php开发三到四年)
看了这篇博文,我正好处于这个阶段,也有心要突破自己,呵呵! 作为Web开发中应用最广泛的语言之一,PHP有着大量的粉丝,那么你是一名优秀的程序员吗?在进行自我修炼的同时,你是否想过面对各种各样的问题, ...
- 《oracle每日一练》oralce数据库的导入导出
今天尝试了数据库的导出,直接在命令行里面使用了导出指令: exp uname/pwd@127.0.0.1:1521/orcl file='xx.dmp' 出现的问题: 直接@tnsnames里面配的 ...
- Python之队列queue模块使用 常见问题与用法
python 中,队列是线程间最常用的交换数据的形式.queue模块是提供队列操作的模块,虽然简单易用,但是不小心的话,还是会出现一些意外. 1. 阻塞模式 import queue q = queu ...
- ExpressQuantumGrid4的cxGrid的一些使用方法和经验
使用cxGrid有一些时间了,在这里总结一下使用cxGrid的一些方法,希望给刚开始接触cxGrid的人一些帮助. 1.简单介绍:cxGrid右下方的cxGrid1Level1是表示Grid表的层,c ...
- GNOME启动时激活NumLock(小键盘数字锁定)
首先下载numlockx官方源提供的安装包,解压后进入目录运行终端,切换到root账户执行以下命令: python ./setup.py 然后依次点击GNOME菜单项上的“系统->首选项-> ...
- Divide and conquer:4 Values whose Sum is 0(POJ 2785)
找四个数的和为0 题目大意:给定四个集合,要你每个集合选4个数字,组成和为0 这题是3977的简单版,只要和是0就可以了 #include <iostream> #include < ...
- 100个Github上Android开源库
项目名称 项目简介 1. react-native 这个是 Facebook 在 React.js Conf 2015 大会上推出的基于 JavaScript 的开源框架 React Native, ...
- 【编程题目】求1+2+…+n, 要求不能使用乘除法、for、while、if、else、switch、case和条件语句
看到这个问题,第一个反应是真变态啊. 然后,直觉是不能用循环就只能用递归了.可递归怎么跳出来却遇到了麻烦, 我连goto语句都考虑了也没弄好. 后来想到一个非常NC的方法:查找表. 如果n限定一个比较 ...