Advertisement
Guest User

alagarta

a guest
Jan 15th, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.07 KB | None | 0 0
  1. import android.view.MotionEvent;
  2. import ketai.ui.*;
  3.  
  4. boolean firstRun = false;
  5. aLagarta mag = new aLagarta();
  6. int numImage = 0;
  7. int numPage = 1;
  8. PImage background;
  9. KetaiGesture gesture;
  10. boolean reading = false;
  11. boolean zoom = false;
  12. boolean isDone = false;
  13. int numberOfEdition;
  14. PImage topLogo;
  15. float sizeWidth;
  16. float sizeHeight;
  17. float drawX;
  18. float drawY;
  19. SimpleThread thread1;
  20.  
  21. void setup() {
  22.   size(displayWidth, displayHeight);
  23.   orientation(LANDSCAPE);
  24.   //println(displayWidth+"   "+displayHeight);
  25.   smooth();
  26.   gesture = new KetaiGesture(this);
  27.   sizeWidth = width;
  28.   sizeHeight = height;
  29.   drawX = width/2;
  30.   drawY = height/2;
  31.   thread1 = new SimpleThread(10, "loading");
  32.   thread1.start();
  33. }
  34.  
  35. void draw() {
  36.   if (isDone == true) {
  37.     thread1.quit();
  38.     thread1.stop();
  39.   }
  40.   if (reading == false) {
  41.     if (firstRun == false) {
  42.       mag.update();
  43.       firstRun = true;
  44.     }
  45.     imageMode(CENTER);
  46.     image(background, 394, 260);
  47.     image(topLogo, displayWidth/2, 44);
  48.     imageMode(CENTER);
  49.     if (mag.thumbs.get(numImage).width == 0) {
  50.     }
  51.     else {
  52.       image(mag.thumbs.get(numImage), width/2, height*0.55, round(mag.thumbs.get(numImage).width*0.55), round(mag.thumbs.get(numImage).height*0.55));
  53.     }
  54.   }
  55.   if (reading == true /*&& mag.editionPages.size() != 0*/) {
  56.     imageMode(CENTER);
  57.     if (mag.readingPage.width != 0 && mag.readingPage.width !=-1) {
  58.       image(mag.readingPage, drawX, drawY, round(sizeWidth), round(sizeHeight));
  59.     }
  60.   }
  61.   //delay(1000);
  62. }
  63.  
  64. void onFlick(float x, float y, float px, float py, float v) {
  65.   if (!reading) {
  66.     if (x-px > 0) {
  67.       if (numImage != 0)
  68.         numImage--;
  69.     }
  70.     else if (x-px < 0) {
  71.       if (numImage != mag.thumbs.size()-1)
  72.         numImage++;
  73.     }
  74.   }
  75.   if (reading) {
  76.     if (!zoom) {
  77.       if (x-px > 0) {
  78.         if (numPage != 1) {
  79.           numPage--;
  80.           mag.getPage(numberOfEdition, numPage);
  81.         }
  82.         /*if (mag.editionPages.get(numPage-1) == null)
  83.          mag.getPage(numberOfEdition, numPage);*/
  84.       }
  85.       else if (x-px < 0) {
  86.         numPage++;
  87.         mag.getPage(numberOfEdition, numPage);
  88.       }
  89.     }
  90.     if (zoom) {
  91.       drawX = x-px;
  92.       drawY = y-py;
  93.     }
  94.   }
  95. }
  96.  
  97. void onDoubleTap(float x, float y) {
  98.   if (!reading) {
  99.     if (mag.thumbs.get(numImage).width == 0) {
  100.     }
  101.     else {
  102.       reading = true;
  103.       numberOfEdition = numImage+1;
  104.       mag.getPage(numberOfEdition, 1);
  105.     }
  106.   }
  107.   if (reading) {
  108.     sizeHeight = height;
  109.     sizeWidth = width;
  110.     drawX = width/2;
  111.     drawY = height/2;
  112.     zoom = false;
  113.   }
  114. }
  115.  
  116. void onPinch(float x, float y, float d)
  117. {
  118.   sizeWidth = constrain(sizeWidth+d, mag.readingPage.width, 1.5*mag.readingPage.width);
  119.   sizeHeight = constrain(sizeHeight+d, mag.readingPage.height, 1.5*mag.readingPage.height);
  120.   zoom = true;
  121. }
  122.  
  123. public boolean surfaceTouchEvent(MotionEvent event) {
  124.  
  125.   //call to keep mouseX, mouseY, etc updated
  126.   super.surfaceTouchEvent(event);
  127.  
  128.   //forward event to class for processing
  129.   return gesture.surfaceTouchEvent(event);
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement