Vote count:
0
Im trying to make a task manager app. A simple swipe right from the left side of the screen should bring up the task manager, and a swipe left should hide the task manager. How would i accomplish this? I have two views, h an b. When i swipe h to the right, view b should pop up. When i swipe h left, view b should dissapear. For right now when you swipe left view b dissapears. However when you swipe right, view b does not pop back up. package wei.mark.example;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.Toast;
import wei.mark.standout.StandOutWindow;
import wei.mark.standout.constants.StandOutFlags;
import wei.mark.standout.ui.Window;
public class SimpleWindow extends StandOutWindow {
private View h, b, tex1;
//private TextView tex1;
private float x1, x2;
private int x = 300;
private int y = 1920;
static final int MIN_DISTANCE = 150;
@Override
public String getAppName() {
return "SimpleWindow";
}
@Override
public int getAppIcon() {
return android.R.drawable.ic_menu_close_clear_cancel;
}
@Override
public void createAndAttachView(int id, FrameLayout frame) {
// create a new layout from body.xml
tex1 = frame.findViewById(R.id.textView1);
b = frame.findViewById(R.id.bruh);
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.simple, frame, true);
h = frame.findViewById(R.id.touchwiz);
h.setOnTouchListener(new OnSwipeTouchListener(this){
public void onSwipeTop() {
Toast.makeText(SimpleWindow.this, "top", Toast.LENGTH_SHORT).show();
}
public void onSwipeRight() {
Toast.makeText(SimpleWindow.this, "right", Toast.LENGTH_SHORT).show();
b.setVisibility(View.VISIBLE);
}
public void onSwipeLeft() {
Toast.makeText(SimpleWindow.this, "left", Toast.LENGTH_SHORT).show();
/ /Hide view b
b.setVisibility(View.INVISIBLE);
}
public void onSwipeBottom() {
Toast.makeText(SimpleWindow.this, "bottom", Toast.LENGTH_SHORT).show();
}
public boolean onTouch(View v, MotionEvent event){
return gestureDetector.onTouchEvent(event);
}
});
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
x1 = event.getX();
break;
case MotionEvent.ACTION_UP:
x2 = event.getX();
float deltaX = x2 - x1;
if (Math.abs(deltaX) > MIN_DISTANCE)
{
Toast.makeText(this, "left2right swipe", Toast.LENGTH_SHORT).show ();
}
else
{
// consider as something else - a screen tap for example
}
break;
}
return super.onTouchEvent(event);
}
// the window will be centered
@Override
public StandOutLayoutParams getParams(int id, Window window) {
return new StandOutLayoutParams(id, x, y,
StandOutLayoutParams.LEFT, StandOutLayoutParams.CENTER);
}
// move the window by dragging the view
@Override
public int getFlags(int id) {
return super.getFlags(id)
| StandOutFlags.FLAG_WINDOW_FOCUSABLE_DISABLE | StandOutFlags.FL;
}
@Override
public String getPersistentNotificationMessage(int id) {
return "Click to close the SimpleWindow";
}
@Override
public Intent getPersistentNotificationIntent(int id) {
return StandOutWindow.getCloseIntent(this, SimpleWindow.class, id);
}
}
asked 1 min ago
Android bringing a layout on and off the screen
Aucun commentaire:
Enregistrer un commentaire