有关oppo蝴蝶解锁的三D技术
oppo手机的界面设计也是很漂亮的。在很多界面中使用了3D技术塑造出了大量华丽的效果。在蝴蝶解锁中使用了两个对称的三D变幻,宛如蝴蝶翅膀上美丽的花纹。在受到用户点击后,随风缓慢上下扇动,充满浪漫的动感色彩。这里只在技术角度做一些探索。
这个效果由两个子view合成,每个各占整个屏幕的一半。左边子view以右边界为旋转中心,手指向右滑动距离转为绕Y轴施转的角度,角度为正。右边子view以左边界为旋转中心,手指向左滑动距离转为绕Y轴旋转的角度,角度为负,这样恰好与x轴方向一致。这种效果经过转为,可以转为像两扇门一样开关,也是很有意思的。为了保证两个view的对称性,我这里使用一张图片,沿中线分割为两个view的背景。
可以使用函数Bitmap.createBitmap实现.
左view的背景,LeftView.java:
package com.magcomm.lockscrenn; import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Camera;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.view.View; class LeftView extends View {
Bitmap leftbm = null;
public int g_r = 0;
private int scr_w = 0, scr_h = 0; public void refrashView(int gr) {
g_r = gr;
invalidate();
}
public LeftView(Context context) {
super(context);
} void setBitmap(Bitmap bm) {
leftbm = bm;
scr_w = bm.getWidth() * 2;
scr_h = bm.getHeight();
} @Override
protected void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
} @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
super.onMeasure(widthMeasureSpec, heightMeasureSpec); } @Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {
// TODO Auto-generated method stub
super.onLayout(changed, left, top, right, bottom);
} @Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
float deg = (g_r * 1.0f / scr_w) * 180;
if (deg >= 90) {
canvas.drawBitmap(leftbm, rotateY((int) deg), null); } else if (deg > 0) {
canvas.drawBitmap(leftbm, rotateY((int) deg), null);
// lv.bringToFront();
} else {
canvas.drawBitmap(leftbm, rotateY((int) 0), null);
}
} private int centerX = 0, centerY = 0;
// 转动的总距离,跟度数比例1:1
private int deltaX = 0, deltaY = 0;
// 图片宽度高度
private int bWidth, bHeight;
// 摄像机
private Camera mCamera = new Camera();
private Matrix mMatrix = new Matrix(); Matrix rotateXY(int degreeX, int degreeY) {
deltaX = degreeX;
deltaY = degreeY;
centerX = scr_w / 2;
centerY = scr_h / 2;
mCamera.save();
mCamera.rotateY(deltaY);
mCamera.rotateX(-deltaX);
mCamera.translate(0, 0, 0);
mCamera.getMatrix(mMatrix);
mCamera.restore();
// 以图片的中心点为旋转中心,如果不加这两句,就是以(0,0)点为旋转中心
mMatrix.preTranslate(-centerX, -centerY);
mMatrix.postTranslate(centerX, centerY);
// mCamera.save(); // postInvalidate();
return mMatrix;
} Matrix rotateY(int degreeY) {
return rotateXY(0, degreeY);
} }
右View的
代码RightView.java:
package com.magcomm.lockscrenn; import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Camera;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.view.View; class RightView extends View {
Bitmap rightbm = null;
public int g_r = 0;
private int scr_w = 0, scr_h = 0; public void refrashView(int gr) {
g_r = gr;
invalidate();
}
public RightView(Context context) {
super(context);
} void setBitmap(Bitmap bm) {
rightbm = bm;
scr_w = bm.getWidth() * 2;
scr_h = bm.getHeight();
} @Override
protected void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
} @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
} @Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {
// TODO Auto-generated method stub
super.onLayout(changed, left, top, right, bottom);
} @Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
float deg = (g_r * 1.0f / scr_w) * 180;
if (deg <= -90) {
canvas.drawBitmap(rightbm, rotateY2((int) deg), null);
} else if (deg < 0) {
canvas.drawBitmap(rightbm, rotateY2((int) deg), null);
// rv.bringToFront(); } else {
canvas.drawBitmap(rightbm, rotateY2(0), null);
}
} // 图片的中心点坐标
private int centerX = 0, centerY = 0;
// 转动的总距离,跟度数比例1:1
private int deltaX = 0, deltaY = 0;
// 图片宽度高度
private int bWidth, bHeight;
// 摄像机
private Camera mCamera = new Camera();
private Matrix mMatrix = new Matrix(); Matrix rotateXY2(int degreeX, int degreeY) {
deltaX = degreeX;
deltaY = degreeY;
centerX = scr_w / 2;
centerY = scr_h / 2;
mCamera.save();
mCamera.rotateY(deltaY);
mCamera.rotateX(-deltaX);
mCamera.translate(scr_w / 2, 0, 0);
mCamera.getMatrix(mMatrix);
mCamera.restore();
// 以图片的中心点为旋转中心,如果不加这两句,就是以(0,0)点为旋转中心
mMatrix.preTranslate(-centerX, -centerY);
mMatrix.postTranslate(centerX, centerY);
// mCamera.save(); // postInvalidate();
return mMatrix;
} Matrix rotateY2(int degreeY) {
return rotateXY2(0, degreeY);
}
}
下面代码是两个view的动画效果,手指放开时出现缓慢的上下的有衰减的扇动效果,宛如蝴蝶颤抖的翅膀。本来自己写了一个弹簧振子的模型,通过滑动距离转化为弹簧的能量波动,进而转化为扇动的初速度,加上弹簧的阻尼运动的衰减系数,使其做带负加速度的圆周运动。但运行效果不太满意,大概需要使用JNI来实现才能满足吧,后来采取了系统自带的动画实现。
int ani_index = 0;
private void applyRotation(float start, float end, final View v) {
// 计算中心点
final float centerX = scr_w / 2.0f;
final float centerY = scr_h / 2.0f;
final Rotate3dAnimation rotation = new Rotate3dAnimation(start, end, 0,
0, 0, 0, 0, 0, centerX, centerY, true);
rotation.setDuration(500);
// rotation.setFillAfter(true);
rotation.setRepeatCount(1);
rotation.setRepeatMode(Animation.REVERSE);
// rotation.setFillAfter(true);
// rotation.setDetachWallpaper(true);
rotation.setInterpolator(new AnticipateInterpolator());
// 设置监听
rotation.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {
}
// 动画结束
public void onAnimationEnd(Animation animation) {
// tv.post(new SwapViews());
startAni(ani_index++);
}
public void onAnimationRepeat(Animation animation) {
}
});
v.startAnimation(rotation);
}
/**
*
* AccelerateDecelerateInterpolator 在动画开始与介绍的地方速率改变比较慢,在中间的时候加速
*
* AccelerateInterpolator 在动画开始的地方速率改变比较慢,然后开始加速
*
* AnticipateInterpolator 开始的时候向后然后向前甩
*
* AnticipateOvershootInterpolator 开始的时候向后然后向前甩一定值后返回最后的值
*
* BounceInterpolator 动画结束的时候弹起
*
* CycleInterpolator 动画循环播放特定的次数,速率改变沿着正弦曲线
*
* DecelerateInterpolator 在动画开始的地方快然后慢
*
* LinearInterpolator 以常量速率改变
*
* OvershootInterpolator 向前甩一定值后再回到原来位置
*
* @param start
* @param end
* @param v
* @param time
*/
private void applyRotation2(float start, float end, final View v, long time) {
// 计算中心点
final float centerX = scr_w / 2.0f;
final float centerY = scr_h / 2.0f;
final Rotate3dAnimation rotation = new Rotate3dAnimation(start, end, 0,
0, 0, 0, 0, 0, centerX, centerY, true);
rotation.setDuration(time);
// rotation.setFillAfter(true);
rotation.setRepeatCount(0);
rotation.setRepeatMode(Animation.REVERSE);
// rotation.setFillAfter(true);
// rotation.setDetachWallpaper(true);
rotation.setInterpolator(new LinearInterpolator());
// 设置监听
rotation.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {
}
// 动画结束
public void onAnimationEnd(Animation animation) {
// tv.post(new SwapViews());
startAni(ani_index++);
}
public void onAnimationRepeat(Animation animation) {
}
});
v.startAnimation(rotation);
}
void startAni(int index) {
// final int ani_deg1[][] = {{60, 0}, {40, 0}, {20, 0}};
// final int ani_deg1[][] = {{0, 60}, {0, 40}, {0, 20}};
final int ani_deg1[][] = { { 0, 80 }, { 80, 0 }, { 0, 60 }, { 60, 0 },
{ 0, 40 }, { 40, 0 } };
// final int ani_deg2[][] = {{-60, 0}, {-40, 0}, {-20, 0}};
final int ani_deg2[][] = { { 0, -80 }, { -80, 0 }, { 0, -60 },
{ -60, 0 }, { 0, -40 }, { -40, 0 } };
final int time[] = { 500, 500, 400, 400, 200, 200 };
if (index > 5) {
ani_index = 0;
} else {
if (u_x <= (scr_w / 2)) {
applyRotation2(ani_deg1[index][0], ani_deg1[index][1], lv,
time[index]);
} else {
applyRotation2(ani_deg2[index][0], ani_deg2[index][1], rv,
time[index]);
}
}
}
在oppo的解锁效果中,view的背面加入了对窗口buffer的特殊处理。使我们能够看到一个打开新窗口的效果,如下图:
需要添加如下函数。这里调用了系统的隐藏函数Surface.screenshot,必须使用系统签名。加入系统app中才能使用。当然,也许你也可以使用反射实现。
publicBitmap getScreenBuffer()
{
DisplaymDisplay;
DisplayMetricsmDisplayMetrics;
MatrixmDisplayMatrix = new Matrix();
WindowManagermWindowManager = (WindowManager) mContext
.getSystemService(Context.WINDOW_SERVICE);
mDisplay= mWindowManager.getDefaultDisplay();
mDisplayMetrics= new DisplayMetrics();
mDisplay.getRealMetrics(mDisplayMetrics);
mDisplay.getRealMetrics(mDisplayMetrics);
float[]dims = { mDisplayMetrics.widthPixels,
mDisplayMetrics.heightPixels};
mlock= Surface.screenshot((int) dims[0], (int) dims[1]);
returnmlock;
}
有关oppo蝴蝶解锁的三D技术的更多相关文章
- 阿里云大数据三次技术突围:Greenplum、Hadoop和“飞天”
阿里云大数据三次技术突围:Greenplum.Hadoop和"飞天" 对于企业来说,到底什么是云计算?相信很多企业都有这样的困惑,让我们一起回到这个原始的起点探讨究竟什么是云 ...
- ASP.NET MVC:多语言的三种技术处理策略
ASP.NET MVC:多语言的三种技术处理策略 背景 本文介绍了多语言的三种技术处理策略,每种策略对应一种场景,这三种场景是: 多语言资源信息只被.NET使用. 多语言资源信息只被Javascrip ...
- 谈谈在DevOps实践中,感觉最重要的这三个技术……
从国内众多DevOps实践中,我们能看到下面三个技术尤其重要和火热: 容器:容器从根本上解决了软件对环境的依懒性,解决了各个环境之间的差异问题:它可以加速部署的速度,提高部署的效率:降低部署的成本.容 ...
- 【转载】目前主流过滤XSS的三种技术
目前主流过滤XSS的三种技术 过滤 过滤,顾名思义,就是将提交上来的数据中的敏感词汇直接过滤掉.例如对"<script>"."<a>". ...
- Java 基础入门随笔(1) JavaSE版——java语言三种技术架构
1.java语言的三种技术架构: J2SE(java 2 Platform Standard Edition):标准版,是为开发普通桌面和商务应用程序提供的解决方案.该技术体系是其他两者的基础,可以完 ...
- ASP、JSP、PHP 三种技术比较
目前,最常用的三种动态网页语言有ASP(Active Server Pages),JSP(JavaServer Pages),PHP (Hypertext Preprocessor). 简 介 : A ...
- Oracle用户解锁的三种办法及默认的用户与密码
ORA-28000: the account is locked-的解决办法 2009-11-11 18:51 ORA-28000: the account is locked 第1步:使用PL/SQ ...
- Docker数据卷Volume实现文件共享、数据迁移备份(三)--技术流ken
前言 前面已经写了两篇关于docker的博文了,在工作中有关docker的基本操作已经基本讲解完了.相信现在大家已经能够熟练配置docker以及使用docker来创建镜像以及容器了.本篇博客将会讲解如 ...
- [华三] IPv6技术白皮书(V1.00)
IPv6技术白皮书(V1.00) http://www.h3c.com/cn/d_200802/605649_30003_0.htm H3C S7500E IPv6技术白皮书 关键词:IPv6,隧道 ...
随机推荐
- python编写工具及配置(notepad++)
学长跟我说老师实验室里用的ide是pycharm,我用了一天,整体还行,就是加载速度太慢,可是第二天用的时候就卡的想让人骂街,cpu占有率趋近100%,电脑配置不高,我寻思不能因为这个就马上换电脑吧, ...
- apt-get 命令详解(中文),以及实例
apt-get 命令详解(中文),以及实例 一,什么的是apt-get 高级包装工具(英语:Advanced Packaging Tools,简称:APT)是Debian及其衍生发行版(如:ubunt ...
- OGNL逻辑标签,UI标签
逻辑标签 public class IndexAction extends BasicAction{ private static final long serialVersionUID = 1L; ...
- MFC的最大化,最小化,关闭
最大化.最小化和关闭按钮是窗口中最主要的元素.首先要说明,说他们是按钮其实是不准确的,按钮是一种窗口,而这三个组件根本就不是窗口,而是一个窗口常见的组成部分.出于习惯的原因,这里还是称呼他们为按钮. ...
- 【转】 随机梯度下降(Stochastic gradient descent)和 批量梯度下降(Batch gradient descent )的公式对比、实现对比
梯度下降(GD)是最小化风险函数.损失函数的一种常用方法,随机梯度下降和批量梯度下降是两种迭代求解思路,下面从公式和实现的角度对两者进行分析,如有哪个方面写的不对,希望网友纠正. 下面的h(x)是要拟 ...
- IllegalArgumentException 介绍
java.lang 类 IllegalArgumentException java.lang.Object java.lang.Throwable java.lang.Exception java.l ...
- swift:打造你自己的折线图
看到苹果Health里的折线图了吗.我们就是要打造一个这样的折线图.没看过的请看下图. 我们的主题在于折线图本身.其他的包括步数.日平均值等描述类的内容这里就不涉及了. 首先观察,这个图种包含些什么组 ...
- javascript实现贪吃蛇
<html> <head> <style> body { background:#444; } .rect { border:1px solid #94F; wid ...
- iOS 开发 Message Digest Algorithm 5(MD5加密)
MD5的全称是Message Digest Algorithm 5(消息摘要算法第五版),是计算机安全领域广泛使用的一种散列函数,用以提供消息的完整性保护.在90年代初由MIT Laboratory ...
- Android面试题整理(1)
1.Activity的生命周期 onCreate(Bundle saveInstanceState):创建activity时调用. onStart():activity可见时调用 ...