Guest User

Untitled

a guest
Oct 19th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. private void setUpResultView() {
  2. try{
  3. resultView = LayoutInflater.from(this).inflate(R.layout.result_layout_surface, null);
  4. final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
  5. WindowManager.LayoutParams.MATCH_PARENT,
  6. WindowManager.LayoutParams.WRAP_CONTENT,
  7. WindowManager.LayoutParams.TYPE_PHONE,
  8. WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
  9. PixelFormat.TRANSLUCENT);
  10.  
  11. params.gravity = Gravity.TOP | Gravity.LEFT;
  12. //params.flags = BIND_ABOVE_CLIENT | BIND_NOT_FOREGROUND;
  13. params.x = 0;
  14. params.y = 0;
  15.  
  16. SwipeLayout swipeLayout = (SwipeLayout)resultView.findViewById(R.id.swipe_layout);
  17.  
  18. //set show mode.
  19. swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
  20.  
  21. //add drag edge.(If the BottomView has 'layout_gravity' attribute, this line is unnecessary)
  22. swipeLayout.addDrag(SwipeLayout.DragEdge.Left, resultView.findViewById(R.id.bottom_wrapper));
  23.  
  24. swipeLayout.addSwipeListener(swipeListener);
  25.  
  26. resultView.setOnTouchListener(onTouchListener);
  27.  
  28. windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
  29. windowManager.addView(resultView, params);
  30.  
  31. }
  32. catch (Exception e) {
  33. e.printStackTrace();
  34. }
  35. }
  36.  
  37. SwipeLayout.SwipeListener swipeListener = new SwipeLayout.SwipeListener() {
  38. @Override
  39. public void onClose(SwipeLayout layout) {
  40. Logger.d("onClose");
  41. }
  42.  
  43. @Override
  44. public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
  45. Logger.d("onUpdate");
  46. }
  47.  
  48. @Override
  49. public void onStartOpen(SwipeLayout layout) {
  50. Logger.d("onStartOpen");
  51. }
  52.  
  53. @Override
  54. public void onOpen(SwipeLayout layout) {
  55. Logger.d("onOpen");//when the BottomView totally show.
  56. }
  57.  
  58. @Override
  59. public void onStartClose(SwipeLayout layout) {
  60. Logger.d("onStartClose");
  61. }
  62.  
  63. @Override
  64. public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
  65. Logger.d("onHandRelease");//when user's hand released.
  66. }
  67. };
  68.  
  69. View.OnTouchListener onTouchListener= new View.OnTouchListener() {
  70. private int lastAction;
  71. private int initialX;
  72. private int initialY;
  73. private float initialTouchX;
  74. private float initialTouchY;
  75.  
  76. @Override
  77. public boolean onTouch(View v, MotionEvent event) {
  78. Logger.d(event.getAction());
  79. switch (event.getAction()) {
  80. case MotionEvent.ACTION_DOWN:
  81. Logger.d("ACTION_DOWN");
  82. return true;
  83. case MotionEvent.ACTION_UP:
  84. Logger.d("ACTION_UP");
  85.  
  86. return true;
  87. case MotionEvent.ACTION_MOVE:
  88. Logger.d("ACTION_MOVE");
  89. return true;
  90. }
  91. return false;
  92. }
  93. };
  94.  
  95. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  96. xmlns:app="http://schemas.android.com/apk/res-auto"
  97. android:layout_width="match_parent"
  98. android:layout_height="wrap_content"
  99. android:focusable="true"
  100. android:focusableInTouchMode="true"
  101. android:orientation="vertical"
  102. app:layout_behavior="@string/AUTO"
  103. app:layout_collapseParallaxMultiplier="1.0">
  104. <com.daimajia.swipe.SwipeLayout
  105. android:id="@+id/swipe_layout"
  106. android:layout_width="match_parent" android:layout_height="180dp">
  107. <!-- Bottom View Start-->
  108. <LinearLayout
  109. android:background="#660011ff"
  110. android:id="@+id/bottom_wrapper"
  111. android:layout_width="160dp"
  112. android:weightSum="1"
  113. android:layout_height="match_parent">
  114. <!--What you want to show-->
  115. </LinearLayout>
  116. <!-- Bottom View End-->
  117.  
  118. <!-- Surface View Start -->
  119. <LinearLayout
  120. android:id="@+id/top_wrapper"
  121. android:padding="10dp"
  122. android:background="#a71919"
  123. android:layout_width="match_parent"
  124. android:layout_height="match_parent">
  125. <!--What you want to show in SurfaceView-->
  126. </LinearLayout>
  127. <!-- Surface View End -->
  128. </com.daimajia.swipe.SwipeLayout>
  129. </LinearLayout>
Add Comment
Please, Sign In to add comment