How did Facebook Messenger draw chat chat? (Android)

I know that this has already been asked about this many times in StackOverflow, but I'm fond of how Facebook Messenger draws chats.

I followed this tutorial to place ImageView as an overlay. However, dragging it is very sluggish, unlike Chatheads, which exhibits extremely smooth animations.

Enabling the "Show GPU Updates" options in the "Developers" options blinks on the screen while dragging the chat. However, dragging and dropping my ImageView does not cause any flashes.

Here is a small screencast: https://dl.dropboxusercontent.com/u/13595927/temp/TRIM_20140225_134543.mp4

I tried setting the type of layer LAYER_TYPE_SOFTWARE, but didn’t change anything. What else am I missing?

+4
source share
2 answers

my chat like facebook messenger:
https://github.com/henrychuangtw/FB-ChatHead

  • Drag and drop animation
    enter image description here

  • Messenger: show text and send text
    enter image description hereenter image description here


    • Longpressing to stop
      enter image description here
+5
source

here is my simple solution: 1) Create a service (do not forget to add it to Manifest.xml).

2) Add the ImageView (or other view) that you want to draw in your window. You must specify the exact location on the screen using LayoutParams initialization.

3) OnTouchListener , , MotionEvent.ACTION_UP ( ), ( , ).

4) Manifest.xml :

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

5) , onDestroy() :

@Override
public void onDestroy() {
    super.onDestroy();

    // remove views on destroy!
    if (ivCrumpledPaper != null) {
        mWindowManager.removeView(ivCrumpledPaper);
        ivCrumpledPaper = null;
    }

    if (ivRecycleBin != null) {
        mWindowManager.removeView(ivRecycleBin);
        ivRecycleBin = null;
    }
}

6) :

Reject message

7) , -

0

All Articles