この背後にある基本的な考え方は、指を特定の数の画像ビューにスワイプした後、ユーザーの指をスワイプしたときに異なるビューのタッチ イベントを検出することです。
質問する
385 次
1 に答える
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;
}
}
于 2012-12-06T08:05:42.370 に答える