Reputation: 105
When i am using windowmanger in order to display a floating action button and drag it to another button or view, i can't get it to react to "Drag entered", any ideas? i guess it's about the windowmanger but can't figure it out.
it seems like ACTION_DRAG_STARTED is working...
Code :
WindowManager mWindowManager;
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.type = WindowManager.LayoutParams.TYPE_PHONE;
params.format = PixelFormat.TRANSLUCENT;
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.MATCH_PARENT;
params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_LOCAL_FOCUS_MODE;
LinearLayout mLinearLayoutCloseArea = new LinearLayout(this);
mWindowManager = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
mWindowManager.addView(mLinearLayoutCloseArea, params);
LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final FloatingActionButton fab3, fab4;
layoutInflater.inflate(R.layout.close_area_layout, mLinearLayoutCloseArea);
fab3 = (FloatingActionButton) mLinearLayoutCloseArea.findViewById(R.id.floatingActionButton3);
fab4 = (FloatingActionButton) mLinearLayoutCloseArea.findViewById(R.id.floatingActionButton4);
fab3.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
fab3.setVisibility(View.INVISIBLE);
ClipData data = ClipData.newPlainText("", "");
// Shadow For Drag event
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);
// Version check for using Old and new Api
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// New Api
v.startDragAndDrop(data, shadowBuilder, v, 0);
} else
// Old Api
v.startDrag(data, shadowBuilder, v, 0);
return false;
}
});
fab3.setOnDragListener(this);
fab4.setOnDragListener(new View.OnDragListener() {
@Override
public boolean onDrag(View v, DragEvent event) {
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
Log.d("Alive", " \n Action is DragEvent.ACTION_DRAG_STARTED ---- fab4");
break;
case DragEvent.ACTION_DRAG_ENTERED:
Log.d("Alive", "\n\nAction is DragEvent.ACTION_DRAG_ENTERED---- fab4");
break;
}
return false;
}
});
sorry for my English, and thanks in advance.
Upvotes: 0
Views: 538
Reputation: 926
I've had the same problem. Looks like it is expected to send true when receive ACTION_DRAG_STARTED action.
fab4.setOnDragListener(new View.OnDragListener() {
@Override
public boolean onDrag(View v, DragEvent event) {
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
Log.d("Alive", " \n Action is DragEvent.ACTION_DRAG_STARTED ---- fab4");
return true;
case DragEvent.ACTION_DRAG_ENTERED:
Log.d("Alive", "\n\nAction is DragEvent.ACTION_DRAG_ENTERED---- fab4");
return false;
}
}
});
After that all other actions including ACTION_DRAG_ENTERED are successfully trigered.
Upvotes: 2