菜谱介绍系统

来源:互联网 发布:单片机布尔变量 编辑:程序博客网 时间:2024/03/28 17:41

1.部分效果图:



2.知识点:

1. gallery

override gallery to left align, process click item event, zoom in/out in gallery item

2. TabActivity

the method to use tab activity, and switch between each tab.

3. multitouch

the method to use multitouch

4. layout move

the method to move layout

5. matrix

zoom in/out  and move image using matrix.

6. singleTask

use singleTask in activity launch mode.

7. play media

the method to play mp4 media.

8. java reflection

read private using java reflection.


3. 源码

Welcome.java:

package com.example.balsfood2;import android.app.Activity;import android.app.AlertDialog;import android.app.KeyguardManager;import android.content.DialogInterface;import android.content.Intent;import android.os.Bundle;import android.view.Display;import android.view.KeyEvent;import android.view.MotionEvent;import android.view.Window;import android.view.WindowManager;public class Welcome extends Activity {float x_d =0;float x_u =0;static int width;static int height; //static boolean bcreate = true ;//boolean bdestroy = false;// static boolean bquit = false; @Overrideprotected void onCreate(Bundle savedInstanceState){// TODO Auto-generated method stubsuper.onCreate(savedInstanceState); System.out.println("oncreate :");//bquit = false;        requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                 WindowManager.LayoutParams.FLAG_FULLSCREEN);         setContentView(R.layout.welcome);/*KeyguardManager manager = (KeyguardManager) getSystemService(this.KEYGUARD_SERVICE);    KeyguardManager.KeyguardLock lock = manager            .newKeyguardLock("KeyguardLock");    lock.disableKeyguard();*/ startService(new Intent(this, ScreenService.class));   Display display = getWindowManager().getDefaultDisplay();             width = display.getWidth();             height = display.getHeight();             System.out.println("width:"+width);             System.out.println("height:"+height);} @Overridepublic boolean dispatchTouchEvent(MotionEvent ev){// TODO Auto-generated method stub//System.out.println("dispatchTouchEvent event:"+ev);switch(ev.getAction()){case MotionEvent.ACTION_DOWN:x_d =ev.getX();break;case MotionEvent.ACTION_UP:x_u =ev.getX();System.out.println("value:"+(x_u - x_d));if(x_u - x_d <-150){//bdestroy = true;Intent intent = new Intent(Welcome.this, Web.class);startActivity(intent); }else if(x_u - x_d >150){popupexit();}     break;}return super.dispatchTouchEvent(ev);} @Overrideprotected void onStart() {// TODO Auto-generated method stubsuper.onStart();//System.out.println("onStart a bquit:"+bquit);//if(bquit)//finish();}@Overrideprotected void onStop(){// TODO Auto-generated method stub//System.out.println("onstop a bcreate:"+bcreate);super.onStop();/*if(bcreate){bcreate = false;System.out.println("onstop b bcreate:"+bcreate);}else{System.out.println("onstop c bcreate:"+bcreate);finish();}*///if(bdestroy)//finish();}@Overrideprotected void onResume(){// TODO Auto-generated method stubsuper.onResume();//bdestroy = false;}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event){// TODO Auto-generated method stubswitch (keyCode){ case KeyEvent.KEYCODE_BACK: return true; } return super.onKeyDown(keyCode, event);} @Overridepublic boolean onKeyUp(int keyCode, KeyEvent event){// TODO Auto-generated method stubswitch (keyCode){ case KeyEvent.KEYCODE_BACK: popupexit();return true; }return super.onKeyUp(keyCode, event);}void popupexit(){new AlertDialog.Builder(this).setTitle("exit").setMessage("exit from annaliza's cook?").setPositiveButton("YES", new DialogInterface.OnClickListener() {              @Override              public void onClick(DialogInterface dialog, int which) {                  // TODO Auto-generated method stub              System.out.println("yes");            //bquit = true;            finish();            }          })        .setNegativeButton("NO", new DialogInterface.OnClickListener() {              @Override              public void onClick(DialogInterface dialog, int which) {                  // TODO Auto-generated method stub              System.out.println("no");                        }          }).show();}}

Web.java:

package com.example.balsfood2;import android.app.Activity;import android.content.Intent;import android.graphics.Color;import android.net.Uri;import android.os.Bundle;import android.view.KeyEvent;import android.view.MotionEvent;import android.view.View;import android.view.Window;import android.view.WindowManager;import android.view.View.OnTouchListener;import android.widget.ImageButton;public class Web extends Activity {ImageButton mImageButton1,mImageButton2;float x_d =0;float x_u =0;boolean bfinish = true;//boolean bdestroy = false;@Overrideprotected void onCreate(Bundle savedInstanceState){// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);        requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                 WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.web);}@Overrideprotected void onResume(){// TODO Auto-generated method stubsuper.onResume();bfinish = true;//bdestroy = false;mImageButton1 = (ImageButton)findViewById(R.id.webbc1);mImageButton1.setOnTouchListener(new OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event){// TODO Auto-generated method stubswitch(event.getAction()){/*case MotionEvent.ACTION_DOWN:x_d =event.getX();mImageButton.setBackgroundColor(Color.rgb(255, 0, 0));mImageButton.invalidate();break;*/case MotionEvent.ACTION_UP:x_u =event.getX(); bfinish = false;Uri uri=Uri.parse("http://www.foodmag.ph");Intent it = new Intent(Intent.ACTION_VIEW,uri);startActivity(it);/*mImageButton.setBackgroundColor(0);mImageButton.invalidate();*/break;}System.out.println("v:"+v);System.out.println("event:"+event);return false;}});mImageButton2 = (ImageButton)findViewById(R.id.webbc2);mImageButton2.setOnTouchListener(new OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event){// TODO Auto-generated method stubswitch(event.getAction()){/*case MotionEvent.ACTION_DOWN:x_d =event.getX();mImageButton.setBackgroundColor(Color.rgb(255, 0, 0));mImageButton.invalidate();break;*/case MotionEvent.ACTION_UP:x_u =event.getX(); bfinish = false;Uri uri=Uri.parse("https://www.facebook.com/pages/Polaroid-Philippines/532370993486603?ref=hl");Intent it = new Intent(Intent.ACTION_VIEW,uri);startActivity(it);/*mImageButton.setBackgroundColor(0);mImageButton.invalidate();*/break;}System.out.println("v:"+v);System.out.println("event:"+event);return false;}});} @Overridepublic boolean dispatchTouchEvent(MotionEvent ev){// TODO Auto-generated method stubswitch(ev.getAction()){case MotionEvent.ACTION_DOWN:x_d =ev.getX();break;case MotionEvent.ACTION_UP:x_u =ev.getX();System.out.println("value:"+(x_u - x_d));if(x_u - x_d <-150){  //bdestroy = true;Intent intent = new Intent(Web.this, Home.class);startActivity(intent);}else if(x_u - x_d >150){//bdestroy = true;Intent intent = new Intent(Web.this, Welcome.class);startActivity(intent);}     break;}return super.dispatchTouchEvent(ev);}@Overrideprotected void onStop(){// TODO Auto-generated method stubsuper.onStop();if(bfinish)finish();}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event){// TODO Auto-generated method stubswitch (keyCode){ case KeyEvent.KEYCODE_BACK: return true; } return super.onKeyDown(keyCode, event);} @Overridepublic boolean onKeyUp(int keyCode, KeyEvent event){// TODO Auto-generated method stubswitch (keyCode){ case KeyEvent.KEYCODE_BACK: Intent intent = new Intent(Web.this, Welcome.class);startActivity(intent);return true; }return super.onKeyUp(keyCode, event);}} 

Home.java:

package com.example.balsfood2; import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.KeyEvent;import android.view.MotionEvent;import android.view.View;import android.view.Window;import android.view.WindowManager;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ImageButton;public class Home extends Activity {ImageButton mImageButton;float x_d =0;float x_u =0;boolean bfinish = true;//boolean bdestroy = false;@Overrideprotected void onCreate(Bundle savedInstanceState){// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);        requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                 WindowManager.LayoutParams.FLAG_FULLSCREEN);         setContentView(R.layout.home);}@Overrideprotected void onResume(){// TODO Auto-generated method stubsuper.onResume();bfinish = true;//bdestroy = false;mImageButton = (ImageButton)findViewById(R.id.Homeck);mImageButton.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v){// TODO Auto-generated method stubbfinish = false;Intent intent = new Intent(Home.this, play.class);startActivity(intent);}});}@Overrideprotected void onStop() {// TODO Auto-generated method stubsuper.onStop();if(bfinish)finish();}@Overridepublic boolean dispatchTouchEvent(MotionEvent ev) {// TODO Auto-generated method stubswitch(ev.getAction()){case MotionEvent.ACTION_DOWN:x_d =ev.getX();break;case MotionEvent.ACTION_UP:x_u =ev.getX();System.out.println("value:"+(x_u - x_d));if(x_u - x_d <-150){//bdestroy = true;Intent intent = new Intent(Home.this, MainActivity.class);startActivity(intent);}else if(x_u - x_d >150){//bdestroy = true;Intent intent = new Intent(Home.this, Web.class);startActivity(intent);}     break;}return super.dispatchTouchEvent(ev);}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event){// TODO Auto-generated method stubswitch (keyCode){ case KeyEvent.KEYCODE_BACK: return true; } return super.onKeyDown(keyCode, event);} @Overridepublic boolean onKeyUp(int keyCode, KeyEvent event){// TODO Auto-generated method stubswitch (keyCode){ case KeyEvent.KEYCODE_BACK: Intent intent = new Intent(Home.this, Web.class);startActivity(intent);return true; }return super.onKeyUp(keyCode, event);}} 

MainActivity.java:

package com.example.balsfood2;import android.os.Bundle;import android.os.Handler;import android.app.TabActivity;import android.content.Intent;import android.graphics.Color;import android.view.KeyEvent;import android.view.MotionEvent;import android.view.View;import android.view.Window;import android.view.WindowManager;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.TabHost;import android.widget.TabWidget;import android.widget.TextView;@SuppressWarnings("deprecation")public class MainActivity extends TabActivity  {static int food_position = 0;static int page_postion = 2; // 1--home, 2--main, 3--snacks, 4--dessertImageView mImageViewSlide;Handler mHander = new Handler();int value = 1;// LinearLayout layout = (LinearLayout) findViewById(R.id.tabs);float x_d = 0;float x_u = 0;float y_d = 0;float y_u = 0;boolean bhide = false;static boolean bigFood = false;static boolean bigFoodInit = false;static boolean bdowning = false;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);System.out.println("------oncreate-------");requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);mHander.postDelayed(slideRunnable, 1000);setContentView(R.layout.tabs);TabHost th = getTabHost();// LayoutInflater.from(this).inflate(R.layout.activity_main,th.getTabContentView(),true);th.addTab(th.newTabSpec("home").setIndicator("HOME").setContent(new Intent(this, page1.class)));th.addTab(th.newTabSpec("main").setIndicator("MAIN DISH").setContent(new Intent(this, page2.class)));th.addTab(th.newTabSpec("snack").setIndicator("SNACKS").setContent(new Intent(this, page3.class)));th.addTab(th.newTabSpec("dessert").setIndicator("DESSERT").setContent(new Intent(this, page4.class)));TabWidget tabWidget = this.getTabWidget();for (int i = 0; i < tabWidget.getChildCount(); i++) {TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);tv.setGravity(BIND_AUTO_CREATE);tv.setPadding(10, 10, 10, 10);tv.setTextSize(16);// 设置字体的大小;tv.setTextColor(Color.RED);// 设置字体的颜色;// 获取tabs图片;}if (page_postion == 2)th.setCurrentTab(1);else if (page_postion == 3)th.setCurrentTab(2);else if (page_postion == 4)th.setCurrentTab(3);elseth.setCurrentTab(1);System.out.println("create main activity");/*TabWidget mTabWidget=(TabWidget)findViewById(R.id.tabs);TabWidget.setOnTouchListener(this);*/// th.addTab(th.newTabSpec("cancel").setIndicator("ccccc").setContent(R.id.TextView03));}@Overridepublic boolean onTouchEvent(MotionEvent event) {// TODO Auto-generated method stub //System.out.println("main touchevent");/* * layout.layout(80, 0, 80 + layout.getWidth(), layout.getHeight()); * layout.postInvalidate(); */// View v =return super.onTouchEvent(event);}@Overridepublic boolean dispatchTouchEvent(MotionEvent ev) {// TODO Auto-generated method stubswitch (ev.getAction()) {case MotionEvent.ACTION_DOWN:System.out.println("mainactivity dispatch down");x_d = ev.getX();y_d = ev.getY();System.out.println("test y_d:"+y_d);System.out.println("test height:"+Welcome.height);System.out.println("test heightb:"+(Welcome.height/2+20));if(y_d < (Welcome.height/2))bdowning = true;elsebdowning = false;{LinearLayout layout = (LinearLayout) findViewById(R.id.tabspopup);layout.setVisibility(View.VISIBLE);if (bhide)layout.setTop((int) (Welcome.height));elselayout.setTop((int) (Welcome.height / 2));}break;case MotionEvent.ACTION_MOVE:System.out.println("luke move");y_u = ev.getY();//System.out.println("value y:" + (y_u - y_d));if (bigFood) {LinearLayout layout = (LinearLayout) findViewById(R.id.tabspopup);if (!bhide){if(bdowning)layout.setTop((int) (Welcome.height / 2 + (y_u - y_d)));}elselayout.setTop((int) (Welcome.height + (y_u - y_d)));layout.postInvalidate();}break;case MotionEvent.ACTION_UP:System.out.println("mainactivity up x_u - x_d: "+(x_u - x_d ));System.out.println("mainactivity up bhide: "+bhide);x_u = ev.getX();y_u = ev.getY();if (bigFood) {if (y_u - y_d > 50) {if(bdowning){LinearLayout layout = (LinearLayout) findViewById(R.id.tabspopup);layout.setTop((int) (Welcome.height));layout.postInvalidate();bhide = true;}} else if (y_u - y_d < -50) {LinearLayout layout = (LinearLayout) findViewById(R.id.tabspopup);layout.setTop((int) (Welcome.height / 2));layout.postInvalidate();bhide = false;} else if ((x_u - x_d < -50) && (bhide)){ System.out.println("jump to food");Intent intent = new Intent(MainActivity.this, food.class);startActivity(intent);}}break;}return super.dispatchTouchEvent(ev);}@Overrideprotected void onStop() {System.out.println("---------onstop-----");if (mHander != null) {mHander.removeCallbacks(slideRunnable);mHander = null;}super.onStop();}Runnable slideRunnable = new Runnable() {public void run() {// System.out.println("run value :" + value);mImageViewSlide = (ImageView) findViewById(R.id.imageViewSlide);if (MainActivity.page_postion == 2) {if (bigFood) {if (bigFoodInit) {bigFoodInit = false;bhide = true;LinearLayout layout = (LinearLayout) findViewById(R.id.tabspopup);layout.setTop((int) (Welcome.height));layout.setVisibility(View.INVISIBLE);mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.null_food));LinearLayout layout2 = (LinearLayout) findViewById(R.id.tabsbk);switch (MainActivity.food_position) {case 201:layout2.setBackgroundResource(R.drawable.main1_b);break;case 202:layout2.setBackgroundResource(R.drawable.main2_b);break;case 203:layout2.setBackgroundResource(R.drawable.main3_b);break;case 204:layout2.setBackgroundResource(R.drawable.main4_b);break;case 205:layout2.setBackgroundResource(R.drawable.main5_b);break;case 206:layout2.setBackgroundResource(R.drawable.main6_b);break;case 207:layout2.setBackgroundResource(R.drawable.main7_b);break;case 208:layout2.setBackgroundResource(R.drawable.main8_b);break;case 209:layout2.setBackgroundResource(R.drawable.main9_b);break;case 210:layout2.setBackgroundResource(R.drawable.main10_b);break;case 211:layout2.setBackgroundResource(R.drawable.main11_b);break;}}mHander.postDelayed(slideRunnable, 2000);return;}switch (value) {case 1:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.main1_s));break;case 2:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.main2_s));break;case 3:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.main3_s));break;case 4:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.main4_s));break;case 5:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.main5_s));break;case 6:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.main6_s));break;case 7:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.main7_s));break;case 8:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.main8_s));break;case 9:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.main9_s));break;case 10:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.main10_s));break;case 11:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.main11_s));break;}value++;if (value > 11)value = 1;} else if (MainActivity.page_postion == 3) {if (bigFood) {if (bigFoodInit) {bigFoodInit = false;bhide = true;LinearLayout layout = (LinearLayout) findViewById(R.id.tabspopup);layout.setTop((int) (Welcome.height));layout.setVisibility(View.INVISIBLE);mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.null_food));LinearLayout layout2 = (LinearLayout) findViewById(R.id.tabsbk);switch (MainActivity.food_position) {case 301:layout2.setBackgroundResource(R.drawable.snacks1_b);break;case 302:layout2.setBackgroundResource(R.drawable.snacks2_b);break;case 303:layout2.setBackgroundResource(R.drawable.snacks3_b);break;case 304:layout2.setBackgroundResource(R.drawable.snacks4_b);break;case 305:layout2.setBackgroundResource(R.drawable.snacks5_b);break;case 306:layout2.setBackgroundResource(R.drawable.snacks6_b);break;case 307:layout2.setBackgroundResource(R.drawable.snacks7_b);break;case 308:layout2.setBackgroundResource(R.drawable.snacks8_b);break;}}mHander.postDelayed(slideRunnable, 2000);return;}switch (value) {case 1:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.snacks1_s));break;case 2:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.snacks2_s));break;case 3:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.snacks3_s));break;case 4:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.snacks4_s));break;case 5:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.snacks5_s));break;case 6:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.snacks6_s));break;case 7:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.snacks7_s));break;case 8:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.snacks8_s));break;}value++;if (value > 8)value = 1;} else if (MainActivity.page_postion == 4) {if (bigFood) {if (bigFoodInit) {bigFoodInit = false;bhide = true;LinearLayout layout = (LinearLayout) findViewById(R.id.tabspopup);layout.setTop((int) (Welcome.height));layout.setVisibility(View.INVISIBLE);mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.null_food));LinearLayout layout2 = (LinearLayout) findViewById(R.id.tabsbk);switch (MainActivity.food_position) {case 401:layout2.setBackgroundResource(R.drawable.dessert1_b);break;case 402:layout2.setBackgroundResource(R.drawable.dessert2_b);break;case 403:layout2.setBackgroundResource(R.drawable.dessert3_b);break;}}mHander.postDelayed(slideRunnable, 2000);return;}switch (value) {case 1:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.dessert1_s));break;case 2:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.dessert2_s));break;case 3:mImageViewSlide.setImageDrawable(getResources().getDrawable(R.drawable.dessert3_s));break;}value++;if (value > 3)value = 1;}mHander.postDelayed(slideRunnable, 2000);}};@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {// TODO Auto-generated method stubswitch (keyCode) {case KeyEvent.KEYCODE_BACK:return true;}return super.onKeyDown(keyCode, event);}@Overridepublic boolean onKeyUp(int keyCode, KeyEvent event) {// TODO Auto-generated method stubswitch (keyCode) {case KeyEvent.KEYCODE_BACK:return true;}return super.onKeyUp(keyCode, event);}}

ImageAdapter.java:

package com.example.balsfood2;import android.app.ActionBar.LayoutParams;import android.content.Context;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.Gallery;import android.widget.ImageView;public class ImageAdapter extends BaseAdapter {// 定义Contextprivate Context mContext;// 定义整型数组 即图片源private Integer[] page2_mImageIds = { R.drawable.main0, R.drawable.main1,R.drawable.main2, R.drawable.main3, R.drawable.main4,R.drawable.main5, R.drawable.main6, R.drawable.main7,R.drawable.main8, R.drawable.main9, R.drawable.main10, R.drawable.main11,};private Integer[] page3_mImageIds = { R.drawable.snacks0,R.drawable.snacks1, R.drawable.snacks2, R.drawable.snacks3,R.drawable.snacks4, R.drawable.snacks5, R.drawable.snacks6,R.drawable.snacks7, R.drawable.snacks8, R.drawable.null_food,R.drawable.null_food, };private Integer[] page4_mImageIds = { R.drawable.dessert0,R.drawable.dessert1, R.drawable.dessert2, R.drawable.dessert3, };// 声明 ImageAdapterpublic ImageAdapter(Context c) {mContext = c;}// 获取图片的个数public int getCount() {if (2 == MainActivity.page_postion)return page2_mImageIds.length;else if (3 == MainActivity.page_postion)return page3_mImageIds.length;else if (4 == MainActivity.page_postion)return page4_mImageIds.length;return page2_mImageIds.length;}// 获取图片在库中的位置public Object getItem(int position) {return position;}// 获取图片IDpublic long getItemId(int position) {//System.out.println("get getItemId position:" + position);return position;}@SuppressWarnings("deprecation")public View getView(int position, View convertView, ViewGroup parent) {ImageView imageview = new ImageView(mContext);// System.out.println("get view position:" + position);// 给ImageView设置资源/*System.out.println("imageadapter :page postion"+ MainActivity.page_postion);*/if (2 == MainActivity.page_postion)imageview.setImageResource(page2_mImageIds[position]);else if (3 == MainActivity.page_postion)imageview.setImageResource(page3_mImageIds[position]);else if (4 == MainActivity.page_postion)imageview.setImageResource(page4_mImageIds[position]);imageview.setAdjustViewBounds(true);imageview.setLayoutParams(new Gallery.LayoutParams((Welcome.width - 10 * 7) / 7,(int) ((Welcome.width - 10 * 7) * 1.2 / 7)));// 设置显示比例类型imageview.setScaleType(ImageView.ScaleType.FIT_XY);return imageview;}}

AlignLeftGallery.java:

package com.example.balsfood2;import java.lang.reflect.Field;   import android.R.attr;import android.content.Context;import android.content.Intent;import android.content.res.TypedArray;import android.graphics.Camera;import android.graphics.Matrix;import android.util.AttributeSet;import android.util.Log;import android.view.GestureDetector;import android.view.MotionEvent;import android.view.View;import android.view.ViewGroup;import android.view.GestureDetector.SimpleOnGestureListener;import android.view.View.OnTouchListener;import android.view.animation.Transformation;import android.widget.Gallery;public class AlignLeftGallery extends Gallery    { private GestureDetector gestureScanner; int downposition=0; static View sview = null;static int zoomdir = 0; //0--no zoom, 1--ready zoom out, 2--zoom out                 //3--ready zoom in , 4--zoom inpublic interface IOnItemClickListener {public void onItemClick(int position,View view);}private static final String TAG = "AlignLeftGallery";    private IOnItemClickListener mListener;        public AlignLeftGallery(Context context, AttributeSet attrs) {            super(context, attrs);                          gestureScanner = new GestureDetector(new MySimpleGesture());    this.setOnTouchListener(new OnTouchListener() {          @Override    public boolean onTouch(View v, MotionEvent event) {         //View view = AlignLeftGallery.this.getSelectedView();         //System.out.println("---zoom ontouch downpostion:"+downposition);View view = AlignLeftGallery.this.getChildAt(downposition);//System.out.println("view:"+view);    int dx =(int)event.getRawX();int dy =(int)event.getRawY();int left = v.getLeft() + dx;int top = v.getTop() + dy;int right = v.getRight() + dx;int bottom = v.getBottom() + dy;    //if (view instanceof MyImageView)    {    //imageView = (MyImageView) view;    if (event.getAction() == MotionEvent.ACTION_DOWN) {        System.out.println("alignleft down v:"+v);    // v.layout(0, 0, right, bottom);    // v.layout(0, (int)120, 1024, 900);    }    if (event.getAction() == MotionEvent.ACTION_MOVE) {         if (event.getPointerCount() == 2)     {    float x = event.getX(0) - event.getX(1);              float y = event.getY(0) - event.getY(1);              float value = (float)Math.sqrt(x * x + y * y);//计算两点的距离                           if(value <150)            {            if(zoomdir == 3)            {            //System.out.println("zoom in position:"+downposition);                         if(downposition >= 7)            downposition -= 6;                        zoomdir = 4;                    View view2 = AlignLeftGallery.this.getChildAt(downposition);                //System.out.println("luke view2 in:"+view2);                                 //System.out.println("luke sview in:"+sview);                                if(sview == null)            System.out.println("sview in null");            else            sview.setLayoutParams(new Gallery.LayoutParams(     (Welcome.width - 10 * 7) / 7,     (int) ((Welcome.width - 10 * 7) * 1.2 / 7)));            }            else if(zoomdir != 2            && zoomdir != 3)            zoomdir = 1;            }            else if(value > 200)            {            if(zoomdir == 1)            {            //System.out.println("zoom out position:"+downposition);                         if(downposition >= 7)            downposition -= 6; //bug here            zoomdir = 2;            View view2 = AlignLeftGallery.this.getChildAt(downposition);            sview = view2;            //System.out.println("luke view2 out:"+view2);            //System.out.println("luke sview out:"+sview);                        if(sview == null)            System.out.println("sview out null");            else            sview.setLayoutParams(new Gallery.LayoutParams(     (Welcome.width - 10 * 5) / 5,     (int) ((Welcome.width - 10 * 5) * 1.2 / 5)));            }            else if(zoomdir == 2)                        zoomdir = 3;            }                                   // System.out.println("value:"+value);    }        }            }         return false;    }    });    }        public void setOnItemClickListener(IOnItemClickListener listener) {    mListener = listener;    }        @Override    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {     //System.out.println("onFling:"+String.valueOf(e2.getX() - e1.getX()));    //super. onFling( e1,  e2,  velocityX,  velocityY) ;        return true;    }         @Overridepublic boolean onDown(MotionEvent e) {// TODO Auto-generated method stubboolean value = super.onDown(e);Field f;try {f = AlignLeftGallery.class.getSuperclass().getDeclaredField("mDownTouchPosition");f.setAccessible(true); try {downposition = f.getInt(this);//System.out.println("ondown downposition:"+downposition);} catch (IllegalArgumentException e1) {// TODO Auto-generated catch blocke1.printStackTrace();} catch (IllegalAccessException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}} catch (NoSuchFieldException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}return value;}@Overridepublic boolean onTouchEvent(MotionEvent event) {// TODO Auto-generated method stub    gestureScanner.onTouchEvent(event);return super.onTouchEvent(event);}@Override    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)     {    //System.out.println("onScroll:"+String.valueOf(e2.getX() - e1.getX()));          return true;    }       @Overridepublic boolean onSingleTapUp(MotionEvent e) {    Log.i(TAG, "onSingleTapUp----------------------");    try {Field f = AlignLeftGallery.class.getSuperclass().getDeclaredField("mDownTouchPosition");f.setAccessible(true);int position = f.getInt(this);//System.out.println("onclick postion:"+position);Field f2 = AlignLeftGallery.class.getSuperclass().getDeclaredField("mDownTouchView");f2.setAccessible(true);View view = (View) f2.get(this);Log.i(TAG, "mDownTouchPosition = " + position);if(null != mListener && position >= 0) {mListener.onItemClick(position,view);}} catch (SecurityException e1) {e1.printStackTrace();} catch (NoSuchFieldException e1) {e1.printStackTrace();} catch (IllegalArgumentException e2) {e2.printStackTrace();} catch (IllegalAccessException e3) {e3.printStackTrace();} return false;}    private class MySimpleGesture extends SimpleOnGestureListener { public boolean onDoubleTap(MotionEvent e) {//System.out.println("ondouble tap");  // return super.onDoubleTap(e);return true;}}}

page1.java:

package com.example.balsfood2;import android.app.Activity;import android.app.AlertDialog;import android.content.DialogInterface;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.KeyEvent;import android.view.View;import android.view.Window;import android.view.WindowManager;import android.view.View.OnClickListener;import android.widget.Button;public class page1 extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState){// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);        requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                 WindowManager.LayoutParams.FLAG_FULLSCREEN);         setContentView(R.layout.page1);}@Overrideprotected void onStop() {super.onStop();finish();}@Overrideprotected void onResume() {MainActivity.page_postion = 1;super.onResume();Intent intent = new Intent(page1.this, Home.class);startActivity(intent);}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event){// TODO Auto-generated method stubswitch (keyCode){ case KeyEvent.KEYCODE_BACK: return true; } return super.onKeyDown(keyCode, event);} @Overridepublic boolean onKeyUp(int keyCode, KeyEvent event){// TODO Auto-generated method stubswitch (keyCode){ case KeyEvent.KEYCODE_BACK: return true; }return super.onKeyUp(keyCode, event);}}

page2.java:

package com.example.balsfood2; import com.example.balsfood2.AlignLeftGallery.IOnItemClickListener;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.KeyEvent;import android.view.MotionEvent;import android.view.View;import android.view.View.OnTouchListener;import android.view.Window;import android.view.WindowManager;import android.view.View.OnClickListener;import android.widget.AdapterView;import android.widget.Button;import android.widget.Gallery;import android.widget.Toast;public class page2 extends Activity /*implements OnTouchListener*/  {AlignLeftGallery mGallery;float x_d =0;float x_u =0;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);setContentView(R.layout.page2);}@Overrideprotected void onResume() {// TODO Auto-generated method stubMainActivity.page_postion = 2;MainActivity.bigFood = false;mGallery = (AlignLeftGallery) findViewById(R.id.Gallery01);mGallery.setAdapter(new ImageAdapter(this));mGallery.setOnItemClickListener(new AlignLeftGallery.IOnItemClickListener() {@Overridepublic void onItemClick(int position,View v)  {// Toast.makeText(page2.this, position + " click!",// Toast.LENGTH_SHORT).show();MainActivity.food_position = 200 + position;            if(position>0){MainActivity.bigFood = true;MainActivity.bigFoodInit = true;/*Intent intent = new Intent(page2.this, foodBig.class);startActivity(intent);*/} }  });mGallery.setSelection(3);super.onResume();}@Overridepublic boolean dispatchTouchEvent(MotionEvent ev) {// TODO Auto-generated method stubswitch(ev.getAction()){case MotionEvent.ACTION_DOWN:x_d =ev.getX();break;case MotionEvent.ACTION_UP:x_u =ev.getX();//System.out.println("ddvalue x:"+(x_u - x_d)); if(x_u - x_d < -150){mGallery.setSelection(10);} else if(x_u - x_d > 150){mGallery.setSelection(3);}    break;}return super.dispatchTouchEvent(ev);}@Overrideprotected void onStop() {// TODO Auto-generated method stubsuper.onStop();//finish();}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {// TODO Auto-generated method stubswitch (keyCode) {case KeyEvent.KEYCODE_BACK:return true;}return super.onKeyDown(keyCode, event);}@Overridepublic boolean onKeyUp(int keyCode, KeyEvent event) {// TODO Auto-generated method stubswitch (keyCode) {case KeyEvent.KEYCODE_BACK:return true;}return super.onKeyUp(keyCode, event);}/*@Overridepublic boolean onTouch(View v, MotionEvent event) {// TODO Auto-generated method stubSystem.out.println("view:"+v);System.out.println("event:"+event);switch (event.getAction() & MotionEvent.ACTION_MASK) {case MotionEvent.ACTION_POINTER_DOWN:// 多点缩放System.out.println("point move");break;case MotionEvent.ACTION_MOVE:System.out.println(" move");break;}return false;}*/}

page3.java:

package com.example.balsfood2;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.KeyEvent;import android.view.MotionEvent;import android.view.View;import android.view.Window;import android.view.WindowManager;import android.view.View.OnClickListener;import android.widget.Button;public class page3 extends Activity {AlignLeftGallery mGallery;float x_d =0;float x_u =0;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);setContentView(R.layout.page3);}@Overrideprotected void onResume() {// TODO Auto-generated method stubMainActivity.page_postion = 3;MainActivity.bigFood = false;mGallery = (AlignLeftGallery) findViewById(R.id.Gallery01);mGallery.setAdapter(new ImageAdapter(this));mGallery.setOnItemClickListener(new AlignLeftGallery.IOnItemClickListener() {@Overridepublic void onItemClick(int position,View v) {// Toast.makeText(page2.this, position + " click!",// Toast.LENGTH_SHORT).show();MainActivity.food_position = 300 + position;if(position>0&& position <=8){MainActivity.bigFood = true;MainActivity.bigFoodInit = true;//Intent intent = new Intent(page3.this, foodBig.class);//startActivity(intent);}}});mGallery.setSelection(3);super.onResume();}@Overridepublic boolean dispatchTouchEvent(MotionEvent ev) {// TODO Auto-generated method stubswitch(ev.getAction()){case MotionEvent.ACTION_DOWN:x_d =ev.getX();break;case MotionEvent.ACTION_UP:x_u =ev.getX();System.out.println("ddvalue x:"+(x_u - x_d)); if(x_u - x_d < -150){mGallery.setSelection(10);} else if(x_u - x_d > 150){mGallery.setSelection(3);}    break;}return super.dispatchTouchEvent(ev);}@Overrideprotected void onStop() {// TODO Auto-generated method stubsuper.onStop();}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {// TODO Auto-generated method stubswitch (keyCode) {case KeyEvent.KEYCODE_BACK:return true;}return super.onKeyDown(keyCode, event);}@Overridepublic boolean onKeyUp(int keyCode, KeyEvent event) {// TODO Auto-generated method stubswitch (keyCode) {case KeyEvent.KEYCODE_BACK:return true;}return super.onKeyUp(keyCode, event);}}

page4.java:

package com.example.balsfood2;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.KeyEvent;import android.view.View;import android.view.Window;import android.view.WindowManager;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;public class page4 extends Activity {AlignLeftGallery mGallery;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);setContentView(R.layout.page4);}@Overrideprotected void onResume() {// TODO Auto-generated method stubMainActivity.page_postion = 4;MainActivity.bigFood = false;mGallery = (AlignLeftGallery) findViewById(R.id.Gallery01);mGallery.setAdapter(new ImageAdapter(this));mGallery.setOnItemClickListener(new AlignLeftGallery.IOnItemClickListener() {@Overridepublic void onItemClick(int position,View view) {// Toast.makeText(page2.this, position + " click!",// Toast.LENGTH_SHORT).show();MainActivity.food_position = 400 + position;System.out.println("page4 postion:"+position);//slideRunnableif(position>0){MainActivity.bigFood = true;MainActivity.bigFoodInit = true;/*Intent intent = new Intent(page4.this, foodBig.class);startActivity(intent);*/}}});mGallery.setSelection(3);super.onResume();}@Overrideprotected void onStop() {// TODO Auto-generated method stubsuper.onStop();}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {// TODO Auto-generated method stubswitch (keyCode) {case KeyEvent.KEYCODE_BACK:return true;}return super.onKeyDown(keyCode, event);}@Overridepublic boolean onKeyUp(int keyCode, KeyEvent event) {// TODO Auto-generated method stubswitch (keyCode) {case KeyEvent.KEYCODE_BACK:return true;}return super.onKeyUp(keyCode, event);}}


play.java:

package com.example.balsfood2;import java.io.IOException;import android.app.Activity;import android.media.MediaPlayer;import android.net.Uri;import android.os.Bundle;import android.view.KeyEvent;import android.view.Window;import android.view.WindowManager;import android.widget.VideoView;public class play extends Activity  { public  VideoView vv; @Overrideprotected void onCreate(Bundle savedInstanceState){ this.requestWindowFeature(Window.FEATURE_NO_TITLE);        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                 WindowManager.LayoutParams.FLAG_FULLSCREEN);                getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);         super.onCreate(savedInstanceState);setContentView(R.layout.play);}  @Overrideprotected void onResume(){// TODO Auto-generated method stubsuper.onResume();playVideo();}void playVideo(){String videoUri = "android.resource://com.example.balsfood2/" + R.raw.welcome;                 vv = (VideoView)findViewById(R.id.videoView);        //vv.setVideoPath("/sdcard/video2.mp4");        vv.setVideoURI(Uri.parse(videoUri));                vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener()        {@Overridepublic void onCompletion(MediaPlayer mp){System.out.println("complete");finish();/*// TODO Auto-generated method stubmp.setLooping(false);try{mp.prepare();} catch (IllegalStateException e){// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e){// TODO Auto-generated catch blocke.printStackTrace();}mp.start();*/}                });                vv.start();       }@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event){// TODO Auto-generated method stubswitch (keyCode){ case KeyEvent.KEYCODE_BACK: return true; } return super.onKeyDown(keyCode, event);} @Overridepublic boolean onKeyUp(int keyCode, KeyEvent event){// TODO Auto-generated method stubswitch (keyCode){ case KeyEvent.KEYCODE_BACK: return true; }return super.onKeyUp(keyCode, event);}}

MultiPointTouchListener.java:

package com.example.balsfood2;import android.graphics.Matrix; import android.graphics.PointF; import android.graphics.Rect;import android.util.DisplayMetrics;import android.util.FloatMath; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.ImageView; public class MulitPointTouchListener implements OnTouchListener {         Matrix matrix = new Matrix();         Matrix savedMatrix = new Matrix();          static final int NONE = 0;         static final int DRAG = 1;         static final int ZOOM = 2;         int mode = NONE;         PointF start = new PointF();         PointF mid = new PointF();         float oldDist = 1f;         float oldscale= 1;                static int zoomtime = 1;        int zoomtype = 0; //0--no zoom, 1--zoom out, 2--zoom in        static boolean mutiup = false;        float scaleold =1;        float scalenew =1;        Matrix matrix2;        float mx = 0;        float msx = 0;float my = 0;float msy = 0;                @Override         public boolean onTouch(View v, MotionEvent event) {         //System.out.println("multi point on touch");                ImageView view = (ImageView) v;                 switch (event.getAction() & MotionEvent.ACTION_MASK) {                 case MotionEvent.ACTION_DOWN:                 mx = 0;               my = 0;            msx = 1; //stupid code            msy = 1;                        matrix.set(view.getImageMatrix());                         savedMatrix.set(matrix);                         start.set(event.getX(), event.getY());                         mode = DRAG;                         matrix2 = food.msImageView.getImageMatrix();                        System.out.println("-------ACTION_DOWN---------");                                                                                               break;                 case MotionEvent.ACTION_POINTER_DOWN:                 zoomtype = 0;                        oldDist = spacing(event);                         if (oldDist > 10f) {                                 savedMatrix.set(matrix);                                 midPoint(mid, event);                                                                   mode = ZOOM;                         }                         break;                 case MotionEvent.ACTION_UP:                 mode = NONE;                mutiup = false;                 System.out.println("zoom up action up:");                break;                case MotionEvent.ACTION_POINTER_UP:                         mode = NONE;                        mutiup = true;                                             //  sysout                        scalenew =scaleold * scalenew;                        System.out.println("scalenew up:"+scalenew);                                                                                               System.out.println("zoom up timea:"+zoomtime);                        if(zoomtype ==1)                        zoomtime++;                        else if(zoomtype ==2)                        zoomtime--;                                                if(zoomtime < 1                        || scalenew < 1)                        {                        scalenew = 1;                        scaleold = 1;                        zoomtime =1;                        }                        System.out.println("zoom up timeb:"+zoomtime);                        break;                 case MotionEvent.ACTION_MOVE:                 System.out.println("--------move st-------");                           if ((mode == DRAG)                        && (zoomtime!=1)) {                                                 Rect rect = food.msImageView.getDrawable().getBounds();                float[] values = new float[9];                matrix2.getValues(values);                float boundx1 = values[2];                float boundy1 = values[5];                float boundx2 = values[2]+rect.width()*values[0];                float boundy2 = values[5]+rect.height()*values[0];                                                /*                    System.out.println("values[0]:"+values[0]);                System.out.println("values[1]:"+values[1]);                System.out.println("values[2]:"+values[2]);                System.out.println("values[3]:"+values[3]);                System.out.println("values[4]:"+values[4]);                System.out.println("values[5]:"+values[5]);                System.out.println("values[6]:"+values[6]);                System.out.println("values[7]:"+values[7]);                System.out.println("values[8]:"+values[8]);*/                                            System.out.println("boundx1:"+values[2]);                System.out.println("boundy1:"+values[5]);                   System.out.println("boundx2:"+(values[2]+rect.width()*values[0]));                System.out.println("boundy2:"+(values[5]+rect.height()*values[0]));                                                                            System.out.println("valuex:"+(event.getX() - start.x));                System.out.println("valuey:"+(event.getY() - start.y));                                if(true)                {                /*matrix.set(savedMatrix);                 matrix.postTranslate(event.getX() - start.x,0);                 break;*/                }                                                               if((boundx1>0                            && ((event.getX() - start.x)>0) )                            ||                            (boundx2 < Welcome.width                            && ((event.getX() - start.x)<0)                             )                             )                            {                            //mode = NONE;                             System.out.println("######################out of range X#####################");                                //mx = 0;                             msx = mx;                                                        }                            else                            {                            System.out.println("--------in of range X--------");                                                           mx = event.getX() - start.x;                            }                                                         if((boundy1>0                            && ((event.getY() - start.y)>0) )                            ||                            (boundy2 < Welcome.height                            && ((event.getY() - start.y)<0) ))                                                    {                            //mode = NONE;                                                         System.out.println("######################out of range Y#####################");                               msy = my;                            // break;                            }                             else                              {                             System.out.println("--------in of range Y--------");                                my = event.getY() - start.y;                             }                                                                                          matrix.set(savedMatrix);                                                                     System.out.println("mx:"+mx);                                 System.out.println("msx:"+msx);                                                                 float tmpx=0,tmpy=0;                                if(msx!=0)                                tmpx = mx;                                else                                tmpx = msx;                                                                if(msy!=0)                                tmpy = my;                                else                                tmpy = msy;                                                                matrix.postTranslate(tmpx,tmpy);                                                                                                                                  System.out.println("--------move end-------");                           } else if (mode == ZOOM) {                                 float newDist = spacing(event);                                 if (newDist > 10f) {                                         matrix.set(savedMatrix);                                         float scale = newDist / oldDist;                                              scaleold = scale;                                                                               // matrix.postScale(scale, scale, mid.x, mid.y); //luke del                                         //luke add st                                        System.out.println("scale:"+scale);                                        System.out.println("scaleold:"+scaleold);                                       if(scale > 1)                                       {                                            zoomtype = 1;                                     //  System.out.println("zoom out time:"+zoomtime);                                       matrix.postScale(scale, scale, mid.x, mid.y);                                     //  matrix.postScale(2, 2, mid.x, mid.y);                                                                                                                               }                                       else                                       {                                                       zoomtype = 2;                                       matrix.postScale(scale, scale, mid.x, mid.y);                                      // System.out.println("zoom in time:"+zoomtime);                                      // if(zoomtime >1)                                    //   matrix.postScale((float) 0.5, (float) 0.5, mid.x, mid.y);                                                                                                                                                 }                                       //ed                                                                                                                                                                                              }                         }                         break;                 }                 view.setImageMatrix(matrix);                 return true;         }                        private float spacing(MotionEvent event) {                 float x = event.getX(0) - event.getX(1);                 float y = event.getY(0) - event.getY(1);                 return FloatMath.sqrt(x * x + y * y);         }                private void midPoint(PointF point, MotionEvent event) {                 float x = event.getX(0) + event.getX(1);                 float y = event.getY(0) + event.getY(1);                 point.set(x / 2, y / 2);         }                 } 


FoodBig.java:

package com.example.balsfood2;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.KeyEvent;import android.view.MotionEvent;import android.view.Window;import android.view.WindowManager;import android.widget.ImageView;public class foodBig extends Activity {ImageView mImageView;float x_d = 0;float x_u = 0;float y_d = 0;float y_u = 0;@Overrideprotected void onCreate(Bundle savedInstanceState){// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);        requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                 WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.foodbig);mImageView = (ImageView) findViewById(R.id.imageViewFood);}@Overrideprotected void onResume(){// TODO Auto-generated method stubsuper.onResume();System.out.println("MainActivity.food_position:"+ MainActivity.food_position);if (MainActivity.food_position == 201)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main1_b));else if (MainActivity.food_position == 202)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main2_b));else if (MainActivity.food_position == 203)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main3_b));else if (MainActivity.food_position == 204)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main4_b));else if (MainActivity.food_position == 205)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main5_b));else if (MainActivity.food_position == 206)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main6_b));else if (MainActivity.food_position == 207)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main7_b));else if (MainActivity.food_position == 208)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main8_b));else if (MainActivity.food_position == 209)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main9_b));else if (MainActivity.food_position == 210)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main10_b));else if (MainActivity.food_position == 211)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main11_b));else if (MainActivity.food_position == 301)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.snacks1_b));else if (MainActivity.food_position == 302)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.snacks2_b));else if (MainActivity.food_position == 303)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.snacks3_b));else if (MainActivity.food_position == 304)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.snacks4_b));else if (MainActivity.food_position == 305)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.snacks5_b));else if (MainActivity.food_position == 306)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.snacks6_b));else if (MainActivity.food_position == 307)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.snacks7_b));else if (MainActivity.food_position == 308)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.snacks8_b));else if (MainActivity.food_position == 401)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.dessert1_b));else if (MainActivity.food_position == 402)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.dessert2_b));else if (MainActivity.food_position == 403)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.dessert3_b));}@Overridepublic boolean dispatchTouchEvent(MotionEvent ev){// TODO Auto-generated method stubswitch (ev.getAction()){case MotionEvent.ACTION_DOWN:x_d = ev.getX();y_d = ev.getY();break;case MotionEvent.ACTION_UP:x_u = ev.getX();y_u = ev.getY();System.out.println("value x:" + (x_u - x_d));System.out.println("value y:" + (y_u - y_d));if (x_u - x_d <- 150){Intent intent = new Intent(foodBig.this,food.class);startActivity(intent);}else if (y_u - y_d < -150){Intent intent = new Intent(foodBig.this,MainActivity.class);startActivity(intent);}break;}return super.dispatchTouchEvent(ev);}@Overrideprotected void onStop(){// TODO Auto-generated method stubsuper.onStop();finish();}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event){// TODO Auto-generated method stubswitch (keyCode){case KeyEvent.KEYCODE_BACK:return true;}return super.onKeyDown(keyCode, event);}@Overridepublic boolean onKeyUp(int keyCode, KeyEvent event){// TODO Auto-generated method stubswitch (keyCode){case KeyEvent.KEYCODE_BACK:return true;}return super.onKeyUp(keyCode, event);}}

food.java:

package com.example.balsfood2; import android.app.Activity;import android.content.Intent;import android.graphics.Matrix;import android.graphics.Rect;import android.os.Bundle;import android.os.Handler;import android.util.DisplayMetrics;import android.view.GestureDetector;import android.view.KeyEvent;import android.view.MotionEvent;import android.view.View;import android.view.ViewGroup.LayoutParams;import android.view.Window;import android.view.WindowManager;import android.view.GestureDetector.SimpleOnGestureListener;import android.view.View.OnTouchListener;import android.widget.ImageView;public class food extends Activity   {ImageView mImageView;static ImageView msImageView;float x_d =0;float x_u =0;     DisplayMetrics dm;    //boolean bdestroy = false;    //Handler mHandertest = new Handler();    @Overrideprotected void onCreate(Bundle savedInstanceState){// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);        requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                 WindowManager.LayoutParams.FLAG_FULLSCREEN);         dm = new DisplayMetrics();        getWindowManager().getDefaultDisplay().getMetrics(dm);// 获取分辨率                        setContentView(R.layout.food);mImageView = (ImageView) findViewById(R.id.imageViewFoodRecipe);}@Overridepublic boolean onTouchEvent(MotionEvent event) {// TODO Auto-generated method stub return super.onTouchEvent(event);}@Overrideprotected void onResume(){// TODO Auto-generated method stubsuper.onResume();//bdestroy = false;if(MainActivity.food_position == 201)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main1_f));else if(MainActivity.food_position == 202)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main2_f));else if(MainActivity.food_position == 203)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main3_f));else if(MainActivity.food_position == 204)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main4_f));else if(MainActivity.food_position == 205)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main5_f));else if(MainActivity.food_position == 206)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main6_f));else if(MainActivity.food_position == 207)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main7_f));else if(MainActivity.food_position == 208)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main8_f));else if(MainActivity.food_position == 209)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main9_f));else if(MainActivity.food_position == 210)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main10_f));else if(MainActivity.food_position == 211)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.main11_f)); //else if(MainActivity.food_position == 301)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.snacks1_f));else if(MainActivity.food_position == 302)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.snacks2_f));else if(MainActivity.food_position == 303)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.snacks3_f));else if(MainActivity.food_position == 304)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.snacks4_f));else if(MainActivity.food_position == 305)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.snacks5_f));else if(MainActivity.food_position == 306)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.snacks6_f));else if(MainActivity.food_position == 307)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.snacks7_f));else if(MainActivity.food_position == 308)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.snacks8_f));else if(MainActivity.food_position == 401)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.dessert1_f));else if(MainActivity.food_position == 402)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.dessert2_f));else if(MainActivity.food_position == 403)mImageView.setImageDrawable(getResources().getDrawable(R.drawable.dessert3_f));msImageView = mImageView;mImageView.setOnTouchListener(new MulitPointTouchListener ()); //mHandertest.postDelayed(imagerun, 1000);/*good way to delay * mImageView.post(new Runnable() {public void run() {float x = mImageView.getLeft();float y = mImageView.getTop();float width = mImageView.getWidth();float height = mImageView.getHeight();float right = mImageView.getRight();float bottom = mImageView.getBottom();System.out.println("^_^ Runnable"+"x = " + x + ", y = " + y + ", width = "+ width + ", height = " + height + ", right = " + right+ ", bottom = " + bottom);}});*/ } /*Runnable imagerun = new Runnable() {public void run() {Matrix matrix = mImageView.getImageMatrix();Rect rect = mImageView.getDrawable().getBounds();float[] values = new float[9];matrix.getValues(values);System.out.println("values2:"+values[2]);System.out.println("values5:"+values[5]);float x = mImageView.getLeft();float y = mImageView.getTop();float width = mImageView.getWidth();float height = mImageView.getHeight();float right = mImageView.getRight();float bottom = mImageView.getBottom();System.out.println("^_^ Runnable"+"x = " + x + ", y = " + y + ", width = "+ width + ", height = " + height + ", right = " + right+ ", bottom = " + bottom);mHandertest.postDelayed(imagerun, 2000);}};*/@Overridepublic boolean dispatchTouchEvent(MotionEvent ev) {switch(ev.getAction()){case MotionEvent.ACTION_DOWN:x_d =ev.getX();mImageView.setScaleType(ImageView.ScaleType.MATRIX);break;case MotionEvent.ACTION_UP:x_u =ev.getX();//System.out.println("ddvalue x:"+(x_u - x_d));if(MulitPointTouchListener.zoomtime ==1)mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER); System.out.println("food up");if((x_u - x_d >150)&& (MulitPointTouchListener.zoomtime == 1)&& (MulitPointTouchListener.mutiup == false)){//bdestroy = true;Intent intent = new Intent(food.this, MainActivity.class);startActivity(intent); }     break;}return super.dispatchTouchEvent(ev);}@Overrideprotected void onStop(){// TODO Auto-generated method stubsuper.onStop();//if(bdestroy)finish();}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event){// TODO Auto-generated method stubswitch (keyCode){ case KeyEvent.KEYCODE_BACK:  return true; } return super.onKeyDown(keyCode, event);} @Overridepublic boolean onKeyUp(int keyCode, KeyEvent event){// TODO Auto-generated method stubswitch (keyCode){ case KeyEvent.KEYCODE_BACK:  /*Intent intent = new Intent(food.this, MainActivity.class);startActivity(intent);*/ return true; }return super.onKeyUp(keyCode, event);}  }

ScreenService.java:(not used)

package com.example.balsfood2;import android.app.Service;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.content.IntentFilter;import android.os.IBinder;public class ScreenService extends Service{private final String ACT_SCREEN_ON = "android.intent.action.SCREEN_ON";public void onReceive(Context arg0, Intent arg1) {// TODO Auto-generated method stub/*System.out.println("onreceive"); Intent i = new Intent(Intent.ACTION_MAIN);     i.setClass(arg0, Welcome.class);     i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);     arg0.startActivity(i);*/}@Overridepublic void onCreate() {// TODO Auto-generated method stubSystem.out.println("screenservice");super.onCreate();IntentFilter intentFilter = new IntentFilter(ACT_SCREEN_ON);      registerReceiver(mScreenBCR, intentFilter);  }private BroadcastReceiver mScreenBCR = new BroadcastReceiver() {        @Override      public void onReceive(Context context, Intent intent) {          // TODO Auto-generated method stub           System.out.println("onReceive  receive intent:"+intent);          System.out.println("act:"+intent.getAction());                    if(intent.getAction().equals(ACT_SCREEN_ON))          {                             System.out.println("SCREEN ON");              try {                  Intent i = new Intent();                  i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);                   i.setClass(context, Welcome.class);                  context.startActivity(i);              } catch (Exception e) {                  // TODO: handle exception                             }          }          //else if(intent.getAction().equals(ACT_TIME_TICK))          {              System.out.println("bb");              //mUpdateTimeListener.updateTime();            }                           }  };  @Overridepublic IBinder onBind(Intent arg0) {// TODO Auto-generated method stubreturn null;}}

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.balsfood2"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk        android:minSdkVersion="11"        android:targetSdkVersion="17" />    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name="com.example.balsfood2.Welcome"            android:label="@string/app_name"            android:launchMode="singleTask"            android:screenOrientation="landscape" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>                <activity            android:name="MainActivity"            android:screenOrientation="landscape" >        </activity>                 <activity            android:name="play"            android:screenOrientation="landscape" >        </activity>          <activity            android:name="Home"            android:screenOrientation="landscape" >        </activity>        <activity            android:name="Web"            android:screenOrientation="landscape" >        </activity>        <activity            android:name="page1"            android:screenOrientation="landscape" >        </activity>        <activity            android:name="page2"            android:screenOrientation="landscape" >        </activity>        <activity            android:name="page3"            android:screenOrientation="landscape" >        </activity>        <activity            android:name="page4"            android:screenOrientation="landscape" >        </activity>        <activity            android:name="food"            android:scaleType="matrix"            android:screenOrientation="landscape" >        </activity>        <activity            android:name="foodBig"            android:screenOrientation="landscape" >        </activity>        <!--         <service android:name="ScreenService">            <intent-filter>                <action android:name="android.intent.action.SCREEN_ON"/>            </intent-filter></service> -->    </application>        <uses-permission   android:name="android.permission.DISABLE_KEYGUARD"/></manifest>

welcome.xml:

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="@drawable/welcome"    android:orientation="vertical" ></FrameLayout>

web.xml:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:background="@drawable/webbk"    android:orientation="horizontal" >    <ImageButton        android:id="@+id/webbc1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="bottom"        android:layout_marginBottom="90dp"        android:background="#0000"        android:src="@drawable/webb1" />    <ImageButton        android:id="@+id/webbc2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="bottom"        android:layout_marginBottom="120dp"        android:layout_marginLeft="20dp"        android:background="#0000"        android:src="@drawable/webb2" /></LinearLayout>

home.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    android:background="@drawable/homebk" >    <ImageButton        android:id="@+id/Homeck"        android:layout_width="95dp"        android:layout_height="81dp"        android:layout_marginLeft="10dp"        android:layout_marginTop="10dp"        android:background="#0000"        android:src="@drawable/homeck" /></LinearLayout>

activity_main.xml:

<LinearLayout 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:orientation="vertical"    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=".MainActivity" >    <ImageView        android:id="@+id/imageView1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:src="@drawable/ic_launcher" />         <TabHost        android:id="@+id/tabhost"        android:layout_width="wrap_content"        android:layout_height="wrap_content">                  <TabWidget android:id="@android:id/tabs"                 android:orientation="horizontal"                android:layout_width="wrap_content"                android:layout_height="wrap_content"               >              </TabWidget>                         <FrameLayout android:id="@android:id/tabcontent"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content">           <TextView android:id="@+id/view1"                          android:layout_width="fill_parent"                          android:layout_height="fill_parent"/>                      <TextView android:id="@+id/view2"                          android:layout_width="fill_parent"                          android:layout_height="fill_parent"/>               </FrameLayout>              </TabHost>         </LinearLayout>

tabs.xml:

<?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android"        android:id="@android:id/tabhost"      android:layout_width="fill_parent"        android:layout_height="fill_parent"    >       <LinearLayout        android:id="@+id/tabsbk"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:orientation="vertical" >        <LinearLayout                            android:layout_width="fill_parent"            android:layout_height="fill_parent"            android:layout_weight="1"            android:orientation="vertical" >                  <ImageView            android:id="@+id/imageViewSlide"            android:layout_width="fill_parent"            android:layout_height="fill_parent"            android:layout_gravity="center_horizontal"            android:scaleType="fitXY"            android:src="@drawable/dessert1_s" />        </LinearLayout>                <LinearLayout            android:id="@+id/tabspopup"            android:clickable="true"            android:layout_width="fill_parent"            android:layout_height="fill_parent"            android:layout_weight="1"            android:background="#ffffff"            android:orientation="vertical" >            <TabWidget                android:id="@android:id/tabs"                android:clickable="true"                android:layout_width="fill_parent"                android:layout_height="wrap_content" >            </TabWidget>            <FrameLayout                android:id="@android:id/tabcontent"                android:layout_width="fill_parent"                android:layout_height="match_parent"                  >            </FrameLayout>        </LinearLayout>        </LinearLayout>     </TabHost>   

play.xml:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >        <VideoView        android:id="@+id/videoView"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:layout_alignParentBottom="true"        android:layout_alignParentLeft="true"        android:layout_alignParentRight="true"        android:layout_alignParentTop="true" ></VideoView></RelativeLayout>

page1.xml:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >       </LinearLayout>

page2.xml:

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="horizontal" >          <com.example.balsfood2.AlignLeftGallery            android:id="@+id/Gallery01"            android:layout_width="fill_parent"            android:layout_height="200dp"                        android:layout_gravity="center_vertical"                        android:gravity="center_vertical"            android:spacing="5dp" /></FrameLayout>

page3.xml:

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="horizontal" >            <com.example.balsfood2.AlignLeftGallery            android:id="@id/Gallery01"            android:layout_width="fill_parent"            android:layout_height="200dp"                        android:layout_gravity="center_vertical"            android:gravity="center_vertical"            android:spacing="5dp" />           <!--  android:background="#55000000" -->                    </FrameLayout>

page4.xml:

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="horizontal" >                <com.example.balsfood2.AlignLeftGallery            android:id="@id/Gallery01"            android:layout_width="fill_parent"            android:layout_height="200dp"             android:layout_gravity="center_vertical"                        android:gravity="center_vertical"            android:spacing="5dp" /></FrameLayout>

 foodBig.xml:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <ImageView        android:id="@+id/imageViewFood"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:src="@drawable/main1_b" /></LinearLayout>


food.xml:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <ImageView        android:id="@+id/imageViewFoodRecipe"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:src="@drawable/main1_f" /></LinearLayout> 


 

原创粉丝点击