2012-12-06 24 views

回答

0

試試這個..

public class SimpleActivity extends Activity implements SimpleGestureListener{ 

    private SimpleGestureFilter detector; 
    private ImageView imgview; 
    private Bitmap bm; 
    private String image_URL="http://4.bp.blogspot.com/-k8Zxa7NXx5c/UAdrZw92MpI/AAAAAAAAAWI/KZ8n8sziFb4/s1600/Adobe-PDF-Alternative.jpg"; 
    private File file; 
    private File folder; 
    private int no=1; 
    private int totalfiles; 
    private int count; 

     /** Called when the activity is first created. */ 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_main); 
      imgview=(ImageView)findViewById(R.id.imageView1); 

      //Download from URL 
      Downloadfromurl(image_URL); 

      detector = new SimpleGestureFilter(this,this); 
     } 


    public boolean dispatchTouchEvent(MotionEvent me){ 
     this.detector.onTouchEvent(me); 
     return super.dispatchTouchEvent(me); 
    } 


    public void onSwipe(int direction) { 
     String str = ""; 

     switch (direction) { 

     case SimpleGestureFilter.SWIPE_RIGHT : 
      { 
       str = "Swipe Right"; 
       imgfrwd(); 
       break; 
      } 
     case SimpleGestureFilter.SWIPE_LEFT : 
     { 
      str = "Swipe Left"; 
      imgbkwd(); 
      break; 
     } 
     case SimpleGestureFilter.SWIPE_DOWN : 
      { 
       str = "Swipe Down"; 
       imgbkwd(); 
       break; 
      } 
     case SimpleGestureFilter.SWIPE_UP : 
     { 
      str = "Swipe Up"; 
      imgfrwd(); 
      break; 
     } 


     } 
     Toast.makeText(this, str, Toast.LENGTH_SHORT).show(); 
    } 


    public void onDoubleTap() { 
     Toast.makeText(this, "Double Tap", Toast.LENGTH_SHORT).show(); 
    } 


    private Bitmap LoadImage(String URL, BitmapFactory.Options options) 
     {  
     Bitmap bitmap = null; 
     InputStream in = null;  
      try { 
       in = OpenHttpConnection(URL); 
       bitmap = BitmapFactory.decodeStream(in, null, options); 
       in.close(); 
      } catch (IOException e1) { 
      } 
      return bitmap;    
     } 

    private InputStream OpenHttpConnection(String strURL) throws IOException{ 
    InputStream inputStream = null; 
    URL url = new URL(strURL); 
    URLConnection conn = url.openConnection(); 

    try{ 
     HttpURLConnection httpConn = (HttpURLConnection)conn; 
     httpConn.setRequestMethod("GET"); 
     httpConn.connect(); 

     if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) { 
     inputStream = httpConn.getInputStream(); 
     } 
    } 
    catch (Exception ex) 
    { 
    } 
    return inputStream; 
    } 


    void dispimg() 
    { 
      Bitmap bmp = BitmapFactory.decodeFile(folder + "/page"+no+".PNG"); 
      imgview.setImageBitmap(bmp); 

    } 

    void loadfromurl() 
    { 
     BitmapFactory.Options bmOptions; 
      bmOptions = new BitmapFactory.Options(); 
      bmOptions.inSampleSize = 1; 
      bm = LoadImage(image_URL, bmOptions); 
      imgview.setImageBitmap(bm); 
    } 


void imgfrwd() 

{ 

no+=1; 
    count=countfiles(); 
    if(count>=no) 
     dispimg(); 
} 
void imgbkwd() 
{ 

    no-=1; 
    if(no>=0) 
    dispimg(); 
} 

int countfiles() 
{ 
    String[] fileNames = folder.list(); 
    totalfiles = 0; 
    for (int i = 0; i< fileNames.length; i++) 
    { 
     if (fileNames[i].contains(".PNG")) 

      totalfiles++; 

     } 

    return totalfiles; 
} 
} 
+0

它背後的理念,以珠光寶氣的遊戲,用戶觸摸不同顏色的盒子,如果他們匹配的顏色會得到destroy..how可以將此???? –

相關問題