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; } }