Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.88 KB | None | 0 0
  1. public class swipableLayout extends LinearLayout {
  2.  
  3. private boolean swiping = false;
  4.  
  5. public static float lastTouchx =0;
  6. public static float lastTouchy =0;
  7. public static float lastPosx =0;
  8. public static float lastPosy =0;
  9. private float initialTouchx =0;
  10. private float initialTouchy =0;
  11. private int initialPositionx=0;
  12. private int initialPositiony=0;
  13. private int height;
  14. private int width;
  15.  
  16. public swipableLayout(Context context){
  17.  
  18. super(context);
  19. }
  20.  
  21. public swipableLayout(Context context, AttributeSet attrs) {
  22. super(context, attrs);
  23.  
  24. }
  25.  
  26. public swipableLayout(Context context, AttributeSet attrs, int defStyle) {
  27. super(context, attrs, defStyle);
  28.  
  29. }
  30.  
  31.  
  32.  
  33. @Override
  34. public boolean onTouchEvent(MotionEvent ev) {
  35.  
  36. final int action = MotionEventCompat.getActionMasked(ev);
  37.  
  38.  
  39.  
  40. switch(action){
  41.  
  42. case MotionEvent.ACTION_DOWN:{
  43. final int pointerIndex = MotionEventCompat.getActionIndex(ev);
  44.  
  45. lastTouchx = ev.getRawX();
  46. lastTouchy = ev.getRawY();
  47. initialTouchx = lastTouchx;
  48. initialTouchy = lastTouchy;
  49.  
  50.  
  51. Log.d("SwipableLayout", "MotionEvent.ACTION_DOWN");
  52. LinearLayout swipableLayout = (LinearLayout) findViewById(R.id.swipableLayout);
  53. height = swipableLayout.getHeight();
  54. width = swipableLayout.getWidth();
  55.  
  56. initialPositionx = swipableLayout.getLeft();
  57. initialPositiony = swipableLayout.getTop();
  58.  
  59.  
  60.  
  61.  
  62. break;
  63.  
  64. }
  65. case MotionEvent.ACTION_MOVE:{
  66.  
  67. final int pointerIndex = MotionEventCompat.getActionIndex(ev);
  68.  
  69. LinearLayout swipableLayout = (LinearLayout) findViewById(R.id.swipableLayout);
  70.  
  71. final float diffX = lastTouchx - ev.getRawX();;
  72. final float diffY = lastTouchy - ev.getRawY();;
  73. /* final float diffX = lastTouchx - MotionEventCompat.getX(ev, pointerIndex);
  74. final float diffY = lastTouchy - MotionEventCompat.getY(ev, pointerIndex);*/
  75. Log.d("layoutInfo", "["
  76. +String.valueOf(swipableLayout.getTop())+","
  77. +String.valueOf(swipableLayout.getLeft())+","
  78. +String.valueOf(swipableLayout.getBottom())+","
  79. +String.valueOf(swipableLayout.getRight())+"]"
  80.  
  81. );
  82.  
  83. lastTouchx = swipableLayout.getLeft();
  84. lastTouchy = swipableLayout.getTop();
  85.  
  86. lastTouchx = ev.getRawX();
  87. lastTouchy = ev.getRawY();
  88.  
  89. float correction = (swipableLayout.getLeft() + swipableLayout.getRight())/2 - width/2f;
  90.  
  91. if(correction>0){
  92.  
  93. swipeActivity.setTickAlpha(correction/width);
  94.  
  95.  
  96.  
  97. }
  98. else swipeActivity.setCrossAlpha(-correction/width);
  99.  
  100.  
  101. /* Log.d("correction/width/touchx", String.valueOf(lastTouchx));
  102. Log.d("correction/width/width", String.valueOf(width));
  103. Log.d("correction/width/2f", String.valueOf(correction));*/
  104.  
  105.  
  106. int newPosx = Math.round ((swipableLayout.getLeft() - (int) diffX));
  107. int newPosy = Math.round ((swipableLayout.getTop() - (int) diffY));
  108.  
  109. swipableLayout.setLeft(newPosx);
  110. swipableLayout.setTop(newPosy);
  111. swipableLayout.setRight(newPosx+width);
  112. swipableLayout.setBottom(newPosy+height);
  113. swipableLayout.setRotation(swipableLayout.getLeft()/20);
  114.  
  115.  
  116. break;
  117.  
  118.  
  119. }
  120. case MotionEvent.ACTION_UP:{
  121.  
  122. swipeActivity.setCrossAlpha(0.0f);
  123. swipeActivity.setTickAlpha(0.0f);
  124.  
  125. Log.d("SwipableLayout", "MotionEvent.ACTION_UP");
  126.  
  127. if(Math.abs(initialTouchx - lastTouchx) > 0){// swipe
  128. LinearLayout swipableLayout = (LinearLayout) findViewById(R.id.swipableLayout);
  129.  
  130. swipableLayout.setLeft(initialPositionx);
  131. swipableLayout.setRight(initialPositionx + width);
  132. swipableLayout.setTop(initialPositiony);
  133. swipableLayout.setBottom(initialPositiony+height);
  134.  
  135. if(Math.abs(swipableLayout.getRotation()) >18)
  136. swipeActivity.instance.moveProfiles();
  137.  
  138.  
  139. swipableLayout.setRotation(0.0f);
  140. }
  141. else { // click
  142. swipeActivity.gotoPetViewer();
  143. }
  144.  
  145. break;
  146.  
  147. }
  148. }
  149.  
  150. return true;
  151. }
  152. }
  153.  
  154. private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
  155. ImageView bmImage;
  156.  
  157. public DownloadImageTask(ImageView bmImage) {
  158.  
  159. this.bmImage = bmImage;
  160. }
  161.  
  162. protected Bitmap doInBackground(String... urls) {
  163. String urldisplay = urls[0];
  164. Bitmap mIcon11 = null;
  165. try {
  166. InputStream in = new java.net.URL(urldisplay).openStream();
  167. mIcon11 = BitmapFactory.decodeStream(in);
  168. } catch (Exception e) {
  169. Log.e("Error", e.getMessage());
  170. e.printStackTrace();
  171. }
  172. return mIcon11;
  173. }
  174.  
  175.  
  176. protected void onPostExecute(Bitmap result) {
  177.  
  178. // HERE IS THE ISSUE!
  179. bmImage.setImageBitmap(result); //<- WHEN I SET THIS BITMAP, THE UPPER
  180. //swipableLayout goes to the initial position
  181.  
  182. imageView9.setTag("adios");
  183. }
  184. }
  185.  
  186. 02-21 01:37:06.330 1061-1061/com.mindfunk.rething D/SwipableLayout: MotionEvent.ACTION_DOWN
  187. 02-21 01:37:06.370 1061-1061/com.mindfunk.rething D/layoutInfo: [20,20,991,700]
  188. 02-21 01:37:06.388 1061-1061/com.mindfunk.rething D/layoutInfo: [20,24,991,704]
  189. 02-21 01:37:06.410 1061-1061/com.mindfunk.rething D/layoutInfo: [20,32,991,712]
  190. 02-21 01:37:06.437 1061-1061/com.mindfunk.rething D/layoutInfo: [20,46,991,726]
  191. 02-21 01:37:06.459 1061-1061/com.mindfunk.rething D/layoutInfo: [18,83,989,763]
  192. 02-21 01:37:06.484 1061-1061/com.mindfunk.rething D/layoutInfo: [18,102,989,782]
  193. 02-21 01:37:06.507 1061-1061/com.mindfunk.rething D/layoutInfo: [18,119,989,799]
  194. 02-21 01:37:06.524 1061-1061/com.mindfunk.rething D/layoutInfo: [18,140,989,820]
  195. 02-21 01:37:06.544 1061-1061/com.mindfunk.rething D/layoutInfo: [18,147,989,827]
  196. 02-21 01:37:06.557 1061-1061/com.mindfunk.rething D/layoutInfo: [18,155,989,835]
  197. 02-21 01:37:06.573 1061-1061/com.mindfunk.rething D/layoutInfo: [18,166,989,846]
  198. 02-21 01:37:06.591 1061-1061/com.mindfunk.rething D/layoutInfo: [18,176,989,856]
  199. 02-21 01:37:06.608 1061-1061/com.mindfunk.rething D/layoutInfo: [18,183,989,863]
  200. 02-21 01:37:06.624 1061-1061/com.mindfunk.rething D/layoutInfo: [18,190,989,870]
  201. 02-21 01:37:06.640 1061-1061/com.mindfunk.rething D/layoutInfo: [18,196,989,876]
  202. 02-21 01:37:06.656 1061-1061/com.mindfunk.rething D/layoutInfo: [18,203,989,883]
  203. 02-21 01:37:06.673 1061-1061/com.mindfunk.rething D/layoutInfo: [18,212,989,892]
  204. 02-21 01:37:06.689 1061-1061/com.mindfunk.rething D/layoutInfo: [18,220,989,900]
  205. 02-21 01:37:06.706 1061-1061/com.mindfunk.rething D/layoutInfo: [19,228,990,908]
  206. 02-21 01:37:06.724 1061-1061/com.mindfunk.rething D/layoutInfo: [20,234,991,914]
  207. 02-21 01:37:06.742 1061-1061/com.mindfunk.rething D/layoutInfo: [22,241,993,921]
  208. 02-21 01:37:06.756 1061-1061/com.mindfunk.rething D/layoutInfo: [23,248,994,928]
  209. 02-21 01:37:06.774 1061-1061/com.mindfunk.rething D/layoutInfo: [26,257,997,937]
  210. 02-21 01:37:06.790 1061-1061/com.mindfunk.rething D/layoutInfo: [29,269,1000,949]
  211. 02-21 01:37:06.808 1061-1061/com.mindfunk.rething D/layoutInfo: [32,277,1003,957]
  212. 02-21 01:37:06.823 1061-1061/com.mindfunk.rething D/layoutInfo: [35,283,1006,963]
  213. 02-21 01:37:06.840 1061-1061/com.mindfunk.rething D/layoutInfo: [37,288,1008,968]
  214. 02-21 01:37:06.854 1061-1061/com.mindfunk.rething D/layoutInfo: [40,294,1011,974]
  215. 02-21 01:37:06.873 1061-1061/com.mindfunk.rething D/layoutInfo: [45,302,1016,982]
  216. 02-21 01:37:06.890 1061-1061/com.mindfunk.rething D/layoutInfo: [48,311,1019,991]
  217. 02-21 01:37:06.904 1061-1061/com.mindfunk.rething D/layoutInfo: [52,319,1023,999]
  218. 02-21 01:37:06.924 1061-1061/com.mindfunk.rething D/layoutInfo: [54,326,1025,1006]
  219. 02-21 01:37:06.944 1061-1061/com.mindfunk.rething D/layoutInfo: [56,331,1027,1011]
  220. 02-21 01:37:06.955 1061-1061/com.mindfunk.rething D/layoutInfo: [57,335,1028,1015]
  221. 02-21 01:37:06.974 1061-1061/com.mindfunk.rething D/layoutInfo: [59,338,1030,1018]
  222. 02-21 01:37:06.990 1061-1061/com.mindfunk.rething D/layoutInfo: [60,341,1031,1021]
  223. 02-21 01:37:07.009 1061-1061/com.mindfunk.rething D/layoutInfo: [60,342,1031,1022]
  224. 02-21 01:37:07.024 1061-1061/com.mindfunk.rething D/layoutInfo: [61,344,1032,1024]
  225. 02-21 01:37:07.038 1061-1061/com.mindfunk.rething D/layoutInfo: [61,344,1032,1024]
  226. 02-21 01:37:07.055 1061-1061/com.mindfunk.rething D/layoutInfo: [63,345,1034,1025]
  227. 02-21 01:37:07.088 1061-1061/com.mindfunk.rething D/layoutInfo: [64,346,1035,1026]
  228. 02-21 01:37:07.105 1061-1061/com.mindfunk.rething D/layoutInfo: [66,348,1037,1028]
  229. 02-21 01:37:07.123 1061-1061/com.mindfunk.rething D/layoutInfo: [66,349,1037,1029]
  230. 02-21 01:37:07.155 1061-1061/com.mindfunk.rething D/layoutInfo: [66,350,1037,1030]
  231. 02-21 01:37:07.172 1061-1061/com.mindfunk.rething D/layoutInfo: [66,351,1037,1031]
  232. 02-21 01:37:07.270 1061-1061/com.mindfunk.rething D/SwipableLayout: MotionEvent.ACTION_UP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement