EditText restricting Copy/Paste when view is being added to WindowManager - android

I am adding a textview to Window using the following code
public static void addViewToWindow(Activity activity, View view, WindowManager.LayoutParams params)
{
WindowManager windowManager = (WindowManager)activity.getSystemService(Context.WINDOW_SERVICE);
windowManager.addView(view, params);
}
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION_PANEL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.OPAQUE);
params.gravity = Gravity.BOTTOM;
params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
addViewToWindow(myActivity, myEditText, params);
But I am not able to long press on the EditText to let the user copy/paste. As soon as I change the orientation of the device to landscape, the EditText covers the entire screen and I am able to copy/paste by long press. I am not able to make out what I am doing wrong.

Related

Android With WindowManager View not move down when soft keyboard hide

I'm working with WindowManager for showing popup (myView) with a Service (I can explain why but it's not the subject)
layoutParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSPARENT);
layoutParams.gravity = Gravity.CENTER;
layoutParams.packageName = context.getPackageName();
layoutParams.buttonBrightness = 1f;
layoutParams.windowAnimations = R.style.DialogAnimation;
layoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
final WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
manager.addView(myView, layoutParams);
In my popup there is an EditText, when it request focus, automatically keyboard move up and the view do the same.
My problem is, when backButton is pressed, automatically keyBoard move down but not my view.
What can I do to make my view back down?

How to get a clickable and moveable imageview just like Facebook messenger?

I want an imageview for my app just like fb messenger chat header which will be shown everywhere when the app is running in background and we are working on another app. I have seen some codes but they just make it visible at a fixed position not movable the code is here and i have just used textview for the time being instead of imageview.
public void onCreate() {
super.onCreate();
//mView = new HUDView(this);
mButton = new Button(this);
mButton.setText("Overlay button");
mButton.setOnTouchListener(new OnTouchListener(){
#Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(getApplicationContext(),"Overlay button event", Toast.LENGTH_SHORT).show();
return false;
}
});
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.RIGHT | Gravity.CENTER;
params.setTitle("Load Average");
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(mButton, params);
}
Any help would be appreciated.
The link of Lalit Poptani is good. You have to use a service for this kind of feature.
Please, look the example form Waza_Be, here: https://stackoverflow.com/a/15980900/5098294

android overlay activity issue

I have an activity that creates a view of type TYPE_SYSTEM_ALERT and I set a touch listener to the view. Is it possible to record the touch but still send the touch event to other views (example: to a widget from my home screen)?
Here is my code:
public class TestGestures extends Activity implements View.OnTouchListener {
/**
* Called when the activity is first created.
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final WindowManager.LayoutParams param=new WindowManager.LayoutParams();
param.flags=WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
final View view=findViewById(R.id.view1);
final ViewGroup parent=(ViewGroup)view.getParent();
if(parent!=null)
parent.removeView(view);
param.format= PixelFormat.RGBA_8888;
param.type=WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
param.gravity= Gravity.TOP|Gravity.LEFT;
param.width=view.getLayoutParams().width;
param.height=view.getLayoutParams().height;
//view.setBackgroundColor(android.R.color.white);
final WindowManager wmgr=(WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.addView(view,param);
view.setOnTouchListener(this);
}
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return false;
}
}
When I'm in the home screen, the touch events are not sent to the widgets
You'll have to play around with the parameters that you're using to setup your WindowManager.LayoutParams. For example, the code below will make the touch events be delivered to the Activity (or View) which is below the view that you just created:
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
On the other hand, if you change TYPE_SYSTEM_OVERLAY to TYPE_SYSTEM_PHONE, the input events will be delivered to the View that is on top of the other ones:
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
So, in your case, since you want the input events to be delivered to the views below, try setting the TYPE_SYSTEM_OVERLAY flag.

How to make a Facebook Messenger-like notification like this in Android

I want to implement notifications like the one in the following image.
Notification appears any time. I think it's of course a background service waiting for new messages from the server then shows this. What I think this is an activity implemented as dialog with this custom UI. Am I correct? And is it a normal startActivity method from the service? And how do I do the transition animation to make it appears slowly from left to right with zooming when show up?
Check out this link http://www.piwai.info/chatheads-basics. He provides information about how to add them on your screen.
The trick is to add a View to the WindowManager like following code
private WindowManager windowManager;
private ImageView chatHead;
public void addView()
{
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
chatHead = new ImageView(this);
chatHead.setImageResource(R.drawable.android_head);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.LEFT;
params.x = 0;
params.y = 100;
windowManager.addView(chatHead, params);
}
Don't forget to add the permission <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

WindowManager get focus?

I have a window manager set up and it has the flag FLAG_NOT_FOCUSABLE which means it will not get the focus of key events. Is there anyway to reverse this upon a click for example? For example, if I click on a button, I want the window to be clickable. How could I do this?
Simply update the window manager with the new parameters.
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//remove FLAG_NOT_FOCUSABLE
params.flags = params.flags & ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
//update the view
windowManager.updateViewLayout(view, params);
}
});

Categories

Resources