博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android小代码
阅读量:6378 次
发布时间:2019-06-23

本文共 6710 字,大约阅读时间需要 22 分钟。

hot3.png

public class ContactActivity extends Activity {

 
private int mCenterX = 0; 
private int mCenterY = 0; 
private ViewGroup leftLayout; 
private ViewGroup rightLayout; 
public static final String ACTION_3D = "action_3d"; 
private RoateRecever roateRecever; 
private ViewGroup currentLayout; 
public void onCreate(Bundle savedInstanceState) {
 
super.onCreate(savedInstanceState); 
requestWindowFeature(Window.FEATURE_NO_TITLE); 
mCenterX = getWindowManager().getDefaultDisplay().getWidth()/2; 
setContentView(R.layout.contact); 
leftLayout = (ViewGroup) findViewById(R.id.contact_layout); 
currentLayout = leftLayout; 
registerReceiver(); 
@Override 
protected void onDestroy() {
 
super.onDestroy(); 
if (roateRecever!=null) {
 
unregisterReceiver(roateRecever); 
roateRecever =null; 
} } 
public void jumpToRight(Rotate3d rightAnimation,String module) {
 
if("contact".equals(module)){
 
setContentView(R.layout.contact); 
rightLayout = (ViewGroup) findViewById(R.id.contact_layout); 
else if ("im".equals(module)) {
 
setContentView(R.layout.im); 
rightLayout = (ViewGroup) findViewById(R.id.im_layout); 
else if ("call".equals(module)) {
 
setContentView(R.layout.call); 
rightLayout = (ViewGroup) findViewById(R.id.call_layout); 
else if ("message".equals(module)) {
 
setContentView(R.layout.message); 
rightLayout = (ViewGroup) findViewById(R.id.message_layout); 
else if ("usage".equals(module)) {
 
setContentView(R.layout.usage); 
rightLayout = (ViewGroup) findViewById(R.id.usage_layout); 
else if ("money".equals(module)) {
 
setContentView(R.layout.money); 
rightLayout = (ViewGroup) findViewById(R.id.money_layout); 
else if ("sns".equals(module)) {
 
setContentView(R.layout.sns); 
rightLayout = (ViewGroup) findViewById(R.id.sns_layout); 
else if ("more".equals(module)) {
 
setContentView(R.layout.more); 
rightLayout = (ViewGroup) findViewById(R.id.more_layout); 
currentLayout = rightLayout; 
// rightLayout.startAnimation(rightAnimation); 
public void leftMoveHandle(String module) {
 
int mID = currentLayout.getId(); 
String currentModule = matchModule(mID); 
if(module.equals(currentModule))return; 
Rotate3d leftAnimation = new Rotate3d(0, -90, 0, 0, mCenterX, mCenterY); 
Rotate3d rightAnimation = new Rotate3d(90, 0, 0.0f, 0.0f, mCenterX, mCenterY); 
leftAnimation.setFillAfter(true); 
leftAnimation.setDuration(800); 
rightAnimation.setFillAfter(true); 
rightAnimation.setDuration(800);
// currentLayout.startAnimation(leftAnimation); 
jumpToRight(rightAnimation,module); 
public void rightMoveHandle(String module) {
 
int mID = currentLayout.getId(); 
String currentModule = matchModule(mID); 
if(module.equals(currentModule))return; 
Rotate3d leftAnimation = new Rotate3d(-90, 0, 0, 0, mCenterX, mCenterY); 
Rotate3d rightAnimation = new Rotate3d(0, 90, 0.0f, 0.0f, mCenterX, mCenterY); 
leftAnimation.setFillAfter(true); 
leftAnimation.setDuration(800); 
rightAnimation.setFillAfter(true); 
rightAnimation.setDuration(800); 
// currentLayout.startAnimation(rightAnimation); 
jumpToLeft(leftAnimation,module); 
public void jumpToLeft(Rotate3d leftAnimation, String module) {
 
if("contact".equals(module)){
 
setContentView(R.layout.contact); 
leftLayout = (ViewGroup) findViewById(R.id.contact_layout); 
else if ("im".equals(module)) {
 
setContentView(R.layout.im); 
leftLayout = (ViewGroup) findViewById(R.id.im_layout); 
else if ("call".equals(module)) {
 
setContentView(R.layout.call); 
leftLayout = (ViewGroup) findViewById(R.id.call_layout); 
else if ("message".equals(module)) {
 
setContentView(R.layout.message); 
leftLayout = (ViewGroup) findViewById(R.id.message_layout); 
else if ("usage".equals(module)) {
 
setContentView(R.layout.usage); 
leftLayout = (ViewGroup) findViewById(R.id.usage_layout); 
else if ("money".equals(module)) {
 
setContentView(R.layout.money); 
leftLayout = (ViewGroup) findViewById(R.id.money_layout); 
else if ("sns".equals(module)) {
 
setContentView(R.layout.sns); 
leftLayout = (ViewGroup) findViewById(R.id.sns_layout); 
else if ("more".equals(module)) {
 
setContentView(R.layout.more); 
leftLayout = (ViewGroup) findViewById(R.id.more_layout); 
currentLayout = leftLayout; 
// leftLayout.startAnimation(leftAnimation); 
private String matchModule(int mID) {
 
String currentModule = null; 
switch (mID) {
 
case R.id.contact_layout: 
currentModule = "contact"; 
break; 
case R.id.im_layout: 
currentModule = "im"; 
break; 
case R.id.call_layout: 
currentModule = "call"; 
break; 
case R.id.message_layout: 
currentModule = "message"; 
break; 
case R.id.usage_layout: 
currentModule = "usage"; 
break; 
case R.id.money_layout: 
currentModule = "money"; 
break; 
case R.id.sns_layout: 
currentModule = "sns"; 
break; 
case R.id.more_layout: 
currentModule = "more"; 
break; 
default: 
break; } 
return currentModule; } 
public class RoateRecever extends BroadcastReceiver{
 
@Override 
public void onReceive(Context context, Intent intent) {
 
System.out.println("RoateRecever"); 
int orientation = intent.getIntExtra("orientation", -1); 
String module = intent.getStringExtra("module"); 
if (1 == orientation) {
 
rightMoveHandle(module); 
}else if (2 == orientation) {
 
leftMoveHandle(module); } } } 
/** 
* 注册广播 
*/ 
public void registerReceiver() {
 
IntentFilter filter = new IntentFilter(ACTION_3D); 
roateRecever = new RoateRecever(); 
registerReceiver(roateRecever, filter); } } 

public class ImageUtil {
 
/** 
* @Title: resizeImage 
* @Description: 对位图缩放 
* bitmap 传进来位图 
* @param w 长 
* @param h 宽 
* @return bitmap 
*/ 
public static Bitmap resizeImage(Bitmap bitmap, int w, int h) {
 
// 原来的图片 
Bitmap BitmapOrg = bitmap; 
int width = BitmapOrg.getWidth(); 
int height = BitmapOrg.getHeight(); 
int newWidth = w; 
int newHeight = h; 
// 计算缩放 
float scaleWidth = ((float) newWidth) / width; 
float scaleHeight = ((float) newHeight) / height; 
// 创建一个矩阵操纵 
Matrix matrix = new Matrix(); 
// 调整位图 
matrix.postScale(scaleWidth, scaleHeight); 
// if you want to rotate the Bitmap 
// matrix.postRotate(45); 
// 调整新位图 
Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width, height, matrix, true); 
return resizedBitmap; 
// make a Drawable from Bitmap to allow to set the Bitmap 
// to the ImageView, ImageButton or what ever 
// return new BitmapDrawable(resizedBitmap); } 
/** 
* 图片去色,返回灰度图片 
* @param bmpOriginal 
* 传入的图片 
* @return 去色后的图片 
*/ 
public static Bitmap toGrayscale(Bitmap bmpOriginal) {
 
int width, height; 
height = bmpOriginal.getHeight(); 
width = bmpOriginal.getWidth(); 
Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); 
Canvas c = new Canvas(bmpGrayscale); 
Paint paint = new Paint(); 
ColorMatrix cm = new ColorMatrix(); 
cm.setSaturation(0); 
ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); 
paint.setColorFilter(f); 
c.drawBitmap(bmpOriginal, 0, 0, paint); 
return bmpGrayscale; } } 

转载于:https://my.oschina.net/u/1994482/blog/401897

你可能感兴趣的文章
上传一张照片,让算法告诉你是否患有抑郁症
查看>>
VR厂商唯晶科技获2800万C+轮融资,曾开发过游戏《圣女之歌》
查看>>
Countly 19.02.1 发布,实时移动和 web 分析报告平台
查看>>
TCP连接中time_wait在开发中的影响-搜人以鱼不如授之以渔
查看>>
Oracle数据库机出新帮助不同规模企业迈向云端
查看>>
前端通信:ajax设计方案(六)--- 全局配置、请求格式拓展和优化、请求二进制类型、浏览器错误搜集以及npm打包发布...
查看>>
微服务分布式企业框架 Springmvc+mybatis+shiro+Dubbo+ZooKeeper+Redis+KafKa
查看>>
被《时代周刊》选为年度最佳发明,PS VR靠的竟然是价格
查看>>
通用唯一标识码UUID的介绍及使用。
查看>>
spring笔记--依赖注入之针对不同类型变量的几种注入方式
查看>>
Java爬虫——网易云热评爬取
查看>>
Ajax的简单学习
查看>>
无华为,不智慧:智慧城市建设为何少不了华为?
查看>>
高性能网络通信框架Netty-基础概念篇
查看>>
为npm配置taobao源
查看>>
zookeeper初探三 java客户端连接
查看>>
管理邮件用户
查看>>
如何查看linux版本
查看>>
导出DC数据以便以介质方式安装另一台域控制器
查看>>
Hibernate学习(八):检索方式
查看>>