FloatingView
The Android project is View to display information such as chat in front.
To API Level 14 or later are supported
Requirements
Target Sdk Version : 25
Min Sdk Version : 14
How to use
- Add this to your build.gradle.
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
compile 'com.github.recruit-lifestyle:FloatingView:2.2.2'
}
- Implement Service for displaying FloatingView
public class ChatHeadService extends Service {
... ...
}
- You will do the setting of the View to be displayed in the FloatingView(Sample have a set in onStartCommand)
final LayoutInflater inflater = LayoutInflater.from(this);
final ImageView iconView = (ImageView) inflater.inflate(R.layout.widget_chathead, null, false);
iconView.setOnClickListener(......);
- Use the FloatingViewManager, make the setting of FloatingView
mFloatingViewManager = new FloatingViewManager(this, this);
mFloatingViewManager.setFixedTrashIconImage(R.drawable.ic_trash_fixed);
mFloatingViewManager.setActionTrashIconImage(R.drawable.ic_trash_action);
final FloatingViewManager.Options options = new FloatingViewManager.Options();
options.overMargin = (int) (16 * metrics.density);
mFloatingViewManager.addViewToWindow(iconView, options);
The second argument of FloatingViewManager
is FloatingViewListener
Describe the process (onFinishFloatingView
) that is called when you exit the FloatingView
@Override
public void onFinishFloatingView() {
stopSelf();
}
- Add the permission to AndroidManifest
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
- Define the Service to AndroidManifest
example)
<application ...>
...
<!-- Demo -->
<service
android:name="jp.co.recruit_lifestyle.sample.service.ChatHeadService"
android:exported="false"/>
...
</application>
- Describe the process to start the Service (example of Fragment)
final Activity activity = getActivity();
activity.startService(new Intent(activity, ChatHeadService.class));
Static Options
It can be set only when displaying for the first time
example)
final FloatingViewManager.Options options = new FloatingViewManager.Options();
options.overMargin = (int) (16 * metrics.density);
mFloatingViewManager.addViewToWindow(iconView, options);