Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class swipableLayout extends LinearLayout {
- private boolean swiping = false;
- public static float lastTouchx =0;
- public static float lastTouchy =0;
- public static float lastPosx =0;
- public static float lastPosy =0;
- private float initialTouchx =0;
- private float initialTouchy =0;
- private int initialPositionx=0;
- private int initialPositiony=0;
- private int height;
- private int width;
- public swipableLayout(Context context){
- super(context);
- }
- public swipableLayout(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
- public swipableLayout(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
- @Override
- public boolean onTouchEvent(MotionEvent ev) {
- final int action = MotionEventCompat.getActionMasked(ev);
- switch(action){
- case MotionEvent.ACTION_DOWN:{
- final int pointerIndex = MotionEventCompat.getActionIndex(ev);
- lastTouchx = ev.getRawX();
- lastTouchy = ev.getRawY();
- initialTouchx = lastTouchx;
- initialTouchy = lastTouchy;
- Log.d("SwipableLayout", "MotionEvent.ACTION_DOWN");
- LinearLayout swipableLayout = (LinearLayout) findViewById(R.id.swipableLayout);
- height = swipableLayout.getHeight();
- width = swipableLayout.getWidth();
- initialPositionx = swipableLayout.getLeft();
- initialPositiony = swipableLayout.getTop();
- break;
- }
- case MotionEvent.ACTION_MOVE:{
- final int pointerIndex = MotionEventCompat.getActionIndex(ev);
- LinearLayout swipableLayout = (LinearLayout) findViewById(R.id.swipableLayout);
- final float diffX = lastTouchx - ev.getRawX();;
- final float diffY = lastTouchy - ev.getRawY();;
- /* final float diffX = lastTouchx - MotionEventCompat.getX(ev, pointerIndex);
- final float diffY = lastTouchy - MotionEventCompat.getY(ev, pointerIndex);*/
- Log.d("layoutInfo", "["
- +String.valueOf(swipableLayout.getTop())+","
- +String.valueOf(swipableLayout.getLeft())+","
- +String.valueOf(swipableLayout.getBottom())+","
- +String.valueOf(swipableLayout.getRight())+"]"
- );
- lastTouchx = swipableLayout.getLeft();
- lastTouchy = swipableLayout.getTop();
- lastTouchx = ev.getRawX();
- lastTouchy = ev.getRawY();
- float correction = (swipableLayout.getLeft() + swipableLayout.getRight())/2 - width/2f;
- if(correction>0){
- swipeActivity.setTickAlpha(correction/width);
- }
- else swipeActivity.setCrossAlpha(-correction/width);
- /* Log.d("correction/width/touchx", String.valueOf(lastTouchx));
- Log.d("correction/width/width", String.valueOf(width));
- Log.d("correction/width/2f", String.valueOf(correction));*/
- int newPosx = Math.round ((swipableLayout.getLeft() - (int) diffX));
- int newPosy = Math.round ((swipableLayout.getTop() - (int) diffY));
- swipableLayout.setLeft(newPosx);
- swipableLayout.setTop(newPosy);
- swipableLayout.setRight(newPosx+width);
- swipableLayout.setBottom(newPosy+height);
- swipableLayout.setRotation(swipableLayout.getLeft()/20);
- break;
- }
- case MotionEvent.ACTION_UP:{
- swipeActivity.setCrossAlpha(0.0f);
- swipeActivity.setTickAlpha(0.0f);
- Log.d("SwipableLayout", "MotionEvent.ACTION_UP");
- if(Math.abs(initialTouchx - lastTouchx) > 0){// swipe
- LinearLayout swipableLayout = (LinearLayout) findViewById(R.id.swipableLayout);
- swipableLayout.setLeft(initialPositionx);
- swipableLayout.setRight(initialPositionx + width);
- swipableLayout.setTop(initialPositiony);
- swipableLayout.setBottom(initialPositiony+height);
- if(Math.abs(swipableLayout.getRotation()) >18)
- swipeActivity.instance.moveProfiles();
- swipableLayout.setRotation(0.0f);
- }
- else { // click
- swipeActivity.gotoPetViewer();
- }
- break;
- }
- }
- return true;
- }
- }
- private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
- ImageView bmImage;
- public DownloadImageTask(ImageView bmImage) {
- this.bmImage = bmImage;
- }
- protected Bitmap doInBackground(String... urls) {
- String urldisplay = urls[0];
- Bitmap mIcon11 = null;
- try {
- InputStream in = new java.net.URL(urldisplay).openStream();
- mIcon11 = BitmapFactory.decodeStream(in);
- } catch (Exception e) {
- Log.e("Error", e.getMessage());
- e.printStackTrace();
- }
- return mIcon11;
- }
- protected void onPostExecute(Bitmap result) {
- // HERE IS THE ISSUE!
- bmImage.setImageBitmap(result); //<- WHEN I SET THIS BITMAP, THE UPPER
- //swipableLayout goes to the initial position
- imageView9.setTag("adios");
- }
- }
- 02-21 01:37:06.330 1061-1061/com.mindfunk.rething D/SwipableLayout: MotionEvent.ACTION_DOWN
- 02-21 01:37:06.370 1061-1061/com.mindfunk.rething D/layoutInfo: [20,20,991,700]
- 02-21 01:37:06.388 1061-1061/com.mindfunk.rething D/layoutInfo: [20,24,991,704]
- 02-21 01:37:06.410 1061-1061/com.mindfunk.rething D/layoutInfo: [20,32,991,712]
- 02-21 01:37:06.437 1061-1061/com.mindfunk.rething D/layoutInfo: [20,46,991,726]
- 02-21 01:37:06.459 1061-1061/com.mindfunk.rething D/layoutInfo: [18,83,989,763]
- 02-21 01:37:06.484 1061-1061/com.mindfunk.rething D/layoutInfo: [18,102,989,782]
- 02-21 01:37:06.507 1061-1061/com.mindfunk.rething D/layoutInfo: [18,119,989,799]
- 02-21 01:37:06.524 1061-1061/com.mindfunk.rething D/layoutInfo: [18,140,989,820]
- 02-21 01:37:06.544 1061-1061/com.mindfunk.rething D/layoutInfo: [18,147,989,827]
- 02-21 01:37:06.557 1061-1061/com.mindfunk.rething D/layoutInfo: [18,155,989,835]
- 02-21 01:37:06.573 1061-1061/com.mindfunk.rething D/layoutInfo: [18,166,989,846]
- 02-21 01:37:06.591 1061-1061/com.mindfunk.rething D/layoutInfo: [18,176,989,856]
- 02-21 01:37:06.608 1061-1061/com.mindfunk.rething D/layoutInfo: [18,183,989,863]
- 02-21 01:37:06.624 1061-1061/com.mindfunk.rething D/layoutInfo: [18,190,989,870]
- 02-21 01:37:06.640 1061-1061/com.mindfunk.rething D/layoutInfo: [18,196,989,876]
- 02-21 01:37:06.656 1061-1061/com.mindfunk.rething D/layoutInfo: [18,203,989,883]
- 02-21 01:37:06.673 1061-1061/com.mindfunk.rething D/layoutInfo: [18,212,989,892]
- 02-21 01:37:06.689 1061-1061/com.mindfunk.rething D/layoutInfo: [18,220,989,900]
- 02-21 01:37:06.706 1061-1061/com.mindfunk.rething D/layoutInfo: [19,228,990,908]
- 02-21 01:37:06.724 1061-1061/com.mindfunk.rething D/layoutInfo: [20,234,991,914]
- 02-21 01:37:06.742 1061-1061/com.mindfunk.rething D/layoutInfo: [22,241,993,921]
- 02-21 01:37:06.756 1061-1061/com.mindfunk.rething D/layoutInfo: [23,248,994,928]
- 02-21 01:37:06.774 1061-1061/com.mindfunk.rething D/layoutInfo: [26,257,997,937]
- 02-21 01:37:06.790 1061-1061/com.mindfunk.rething D/layoutInfo: [29,269,1000,949]
- 02-21 01:37:06.808 1061-1061/com.mindfunk.rething D/layoutInfo: [32,277,1003,957]
- 02-21 01:37:06.823 1061-1061/com.mindfunk.rething D/layoutInfo: [35,283,1006,963]
- 02-21 01:37:06.840 1061-1061/com.mindfunk.rething D/layoutInfo: [37,288,1008,968]
- 02-21 01:37:06.854 1061-1061/com.mindfunk.rething D/layoutInfo: [40,294,1011,974]
- 02-21 01:37:06.873 1061-1061/com.mindfunk.rething D/layoutInfo: [45,302,1016,982]
- 02-21 01:37:06.890 1061-1061/com.mindfunk.rething D/layoutInfo: [48,311,1019,991]
- 02-21 01:37:06.904 1061-1061/com.mindfunk.rething D/layoutInfo: [52,319,1023,999]
- 02-21 01:37:06.924 1061-1061/com.mindfunk.rething D/layoutInfo: [54,326,1025,1006]
- 02-21 01:37:06.944 1061-1061/com.mindfunk.rething D/layoutInfo: [56,331,1027,1011]
- 02-21 01:37:06.955 1061-1061/com.mindfunk.rething D/layoutInfo: [57,335,1028,1015]
- 02-21 01:37:06.974 1061-1061/com.mindfunk.rething D/layoutInfo: [59,338,1030,1018]
- 02-21 01:37:06.990 1061-1061/com.mindfunk.rething D/layoutInfo: [60,341,1031,1021]
- 02-21 01:37:07.009 1061-1061/com.mindfunk.rething D/layoutInfo: [60,342,1031,1022]
- 02-21 01:37:07.024 1061-1061/com.mindfunk.rething D/layoutInfo: [61,344,1032,1024]
- 02-21 01:37:07.038 1061-1061/com.mindfunk.rething D/layoutInfo: [61,344,1032,1024]
- 02-21 01:37:07.055 1061-1061/com.mindfunk.rething D/layoutInfo: [63,345,1034,1025]
- 02-21 01:37:07.088 1061-1061/com.mindfunk.rething D/layoutInfo: [64,346,1035,1026]
- 02-21 01:37:07.105 1061-1061/com.mindfunk.rething D/layoutInfo: [66,348,1037,1028]
- 02-21 01:37:07.123 1061-1061/com.mindfunk.rething D/layoutInfo: [66,349,1037,1029]
- 02-21 01:37:07.155 1061-1061/com.mindfunk.rething D/layoutInfo: [66,350,1037,1030]
- 02-21 01:37:07.172 1061-1061/com.mindfunk.rething D/layoutInfo: [66,351,1037,1031]
- 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