Giter VIP home page Giter VIP logo

floatingview's Introduction

FloatingView

[Archived] Use instead: https://developer.android.com/guide/topics/ui/bubbles

The Android project is View to display information such as chat in front. To API Level 14 or higher are supported

Screenshots


Watch YouTube video
SimpleFloating

Requirements

Target Sdk Version : 28
Min Sdk Version : 14

How to use

  1. Add this to your build.gradle.
repositories {
    maven {
        url "https://jitpack.io"
    }
}

dependencies {
  implementation 'com.github.recruit-lifestyle:FloatingView:2.4.4'
}
  1. Implement Service for displaying FloatingView
public class ChatHeadService extends Service {
  ... ...
}
  1. 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(......);
  1. 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();
    }
  1. Add the permission to AndroidManifest
 <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
 <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
  1. Define the Service to AndroidManifest

example)

    <application ...>
        ...
        <!-- Demo -->
        <service
            android:name="jp.co.recruit_lifestyle.sample.service.ChatHeadService"
            android:exported="false"/>
        ...
    </application>
  1. Describe the process to start the Service (run on foreground)

example)

  • FloatingViewControlFragment.java
    final Intent intent = new Intent(activity, ChatHeadService.class);
    ContextCompat.startForegroundService(activity, intent);
  • ChatHeadService.java
public int onStartCommand(Intent intent, int flags, int startId) {
    ...
    startForeground(NOTIFICATION_ID, createNotification(this));
    ...
}
  1. Create notification channel (targetSdkVersion >= 26)

example)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    final String channelId = getString(R.string.default_floatingview_channel_id);
    final String channelName = getString(R.string.default_floatingview_channel_name);
    final NotificationChannel defaultChannel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_MIN);
    final NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    if (manager != null) {
        manager.createNotificationChannel(defaultChannel);
    }
}
  1. Add DisplayCutout process(API Level >= 28)

Call FloatingViewManager.findCutoutSafeArea(activity).
Note: Activity must be portrait oriented.
Note: You must not set windowLayoutInDisplayCutoutMode to never.

example)

  • FloatingViewControlFragment.java
final Intent intent = new Intent(activity, ChatHeadService.class);
intent.putExtra(ChatHeadService.EXTRA_CUTOUT_SAFE_AREA, FloatingViewManager.findCutoutSafeArea(activity));
ContextCompat.startForegroundService(activity, intent);
  • ChatHeadService.java
mFloatingViewManager.setSafeInsetRect((Rect) intent.getParcelableExtra(EXTRA_CUTOUT_SAFE_AREA));

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);
Option Description
shape FloatingViewManager.SHAPE_CIRCLE:Circle(default)
FloatingViewManager.SHAPE_RECTANGLE:Rectangle
overMargin Margin over the edge of the screen (px)
(default) 0
floatingViewX X coordinate of initial display
(default) left side of display
floatingViewY Y coordinate of initial display
(default) top of display
floatingViewWidth FloatingView width
(default) The width of the layout added to FloatingView
floatingViewHeight FloatingView height
(default) The height of the layout added to FloatingView
moveDirection FloatingViewManager.MOVE_DIRECTION_DEFAULT:Left end or right end(default)
FloatingViewManager.MOVE_DIRECTION_LEFT:Left end
FloatingViewManager.MOVE_DIRECTION_RIGHT:Right end
FloatingViewManager.MOVE_DIRECTION_NONE:Not move
FloatingViewManager.MOVE_DIRECTION_NEAREST:Move nearest edge
FloatingViewManager.MOVE_DIRECTION_THROWN:Move in the throwing direction (left end or right end)
usePhysics Use physics-based animation(depends on moveDirection)
(default) true
Info:If MOVE_DIRECTION_NEAREST is set, nothing happens
Info:Can not be used before API 16
animateInitialMove If true, animation when first displayed
(FloatingViewX, floatingViewY) to screen edge
Info: If MOVE_DIRECTION_NONE is set, nothing happens

Dynamic Options

It can be set any time

example)

mFloatingViewManager.setFixedTrashIconImage(R.drawable.ic_trash_fixed);
mFloatingViewManager.setActionTrashIconImage(R.drawable.ic_trash_action);
Option Description
setFixedTrashIconImage It is an icon that does not enlarge when FloatingView overlaps.
setActionTrashIconImage It is an icon that enlarge when FloatingView overlaps.
setDisplayMode FloatingViewManager.DISPLAY_MODE_SHOW_ALWAYS:Always show
FloatingViewManager.DISPLAY_MODE_HIDE_ALWAYS:Always hidden
FloatingViewManager.DISPLAY_MODE_HIDE_FULLSCREEN:It is hidden when in full screen
setTrashViewEnabled If false, the trash icon does not show during dragging.
(default) true

Credits

FloatingView is owned and maintained by RECRUIT LIFESTYLE CO., LTD.

FloatingView was originally created by Yoshihide Sogawa

License

Copyright 2015 RECRUIT LIFESTYLE CO., LTD.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

floatingview's People

Contributors

amyu avatar bullheadandplato avatar geecko86 avatar hannesa2 avatar nicomazz avatar uny avatar y-sogawa avatar ynntk4815 avatar yoshihidesogawa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

floatingview's Issues

Bubble is Invisible

Aright I did download the sample app and that is working fine, But when I add dependency of of FloatingView in my project everything is fine background service is running, I have add permission in manifest check it again and again but whenever I run the app click to button to show bubble but it never shows up mean while service gets started no error in log not at all. just can't see the bubble ...
awesome work btw...

Touch Listener Support

Hello, I would like to get draggable event when the my widget_chathead receive drag, checking the README I see Click Listener.

final LinearLayout iconView = (LinearLayout) inflater.inflate(R.layout.widget_chathead, null);
         iconView.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                //works fine
             }
         });

It's works! but I want get event when user drag the widget, ex:



         iconView.setOnTouchListener(new View.OnTouchListener() {
             @Override
             public boolean onTouch(View v, MotionEvent event) {
                 //not works :(
                 return false;
             }
         });

Someone can help-me? Thank you

Anyway to finish the floatingView?

Calling floatingViewManager.removeAllViewToWindow(); cause IllegalArgumentException.
java.lang.IllegalArgumentException: View=jp.co.recruit_lifestyle.android.floatingview.FloatingView{f72bf3a V.E...... ......I. 0,0-540,303} not attached to window manager
at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:473)
at android.view.WindowManagerGlobal.updateViewLayout(WindowManagerGlobal.java:368)
at android.view.WindowManagerImpl.updateViewLayout(WindowManagerImpl.java:99)
at jp.co.recruit_lifestyle.android.floatingview.FloatingView$FloatingAnimationHandler.handleMessage(FloatingView.java:1051)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

Error when trying to close FloatingView by dragging it to bottom

Hi! First of all thanks for this great library, it's really awesome to use. However, when I try to drag chatHead(Floating view) to bottom(to close it) and after Floating View closes I get the following error:

java.lang.IllegalArgumentException: View=jp.co.recruit_lifestyle.android.floatingview.FloatingView{79038e7 G.E...... ......ID 0,0-78,78} not attached to window manager
                                                                         at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:473)
                                                                         at android.view.WindowManagerGlobal.updateViewLayout(WindowManagerGlobal.java:368)
                                                                         at android.view.WindowManagerImpl.updateViewLayout(WindowManagerImpl.java:101)
                                                                         at jp.co.recruit_lifestyle.android.floatingview.FloatingView.updateViewLayout(FloatingView.java:507)
                                                                         at jp.co.recruit_lifestyle.android.floatingview.FloatingView.onUpdateSystemLayout(FloatingView.java:418)
                                                                         at jp.co.recruit_lifestyle.android.floatingview.FloatingViewManager.onScreenChanged(FloatingViewManager.java:234)
                                                                         at jp.co.recruit_lifestyle.android.floatingview.FullscreenObserverView.onSystemUiVisibilityChange(FullscreenObserverView.java:129)
                                                                         at android.view.View.dispatchSystemUiVisibilityChanged(View.java:20483)
                                                                         at android.view.ViewRootImpl.handleDispatchSystemUiVisibilityChanged(ViewRootImpl.java:5622)
                                                                         at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3674)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                         at android.os.Looper.loop(Looper.java:154)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:6128)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@990cb01 -- permission denied for window type 2038

Hi,

I try to run the sample application of this project.
I am getting following exception:

Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@990cb01 -- permission denied for window type 2038
        at android.view.ViewRootImpl.setView(ViewRootImpl.java:789)
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
        at de.derdoenerdon.ressourcencockpit.library.src.main.java.jp.co.recruit_lifestyle.android.floatingview.FloatingViewManager.addViewToWindow(FloatingViewManager.java:502)
        at de.derdoenerdon.ressourcencockpit.service.ChatHeadService.onStartCommand(ChatHeadService.java:66)
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3474)
        at android.app.ActivityThread.-wrap20(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 

I also set this to my manifest:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

My build.file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "de.derdoenerdon.ressourcencockpit"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'


    implementation 'com.google.firebase:firebase-storage:11.8.0'
    implementation 'com.google.firebase:firebase-auth:11.8.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:27.1.1'

    implementation 'com.github.OPCFoundation:UA-Java:1.03.342.0'

    //added librarys
    //pdf
    implementation 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.5'
    //smiley
    implementation 'com.github.sujithkanna:smileyrating:1.6.8'
    //image picker
    implementation 'com.yanzhenjie:album:2.1.1'
    implementation 'com.github.bumptech.glide:glide:4.7.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
    //MaterialDrawer
    implementation("com.mikepenz:materialdrawer:6.0.7@aar") {
        transitive = true
    }
    //required support lib modules
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:support-annotations:27.1.1'
    implementation 'com.android.support:design:27.1.1'

    implementation "com.mikepenz:crossfader:1.5.2@aar"

    //bubbles
    implementation 'com.github.recruit-lifestyle:FloatingView:2.3.0'

    testImplementation 'junit:junit:4.12'
    testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.7'

}


apply plugin: 'com.google.gms.google-services'

I use this implementation 'com.github.recruit-lifestyle:FloatingView:2.3.0' instead of
implementation 'com.github.recruit-lifestyle:FloatingView:2.3.1', because I get an exception, that I can not resolve the classpaths etc..but with this version, I could.

Also the project and images, how the bubble shall look like, seems to be nice, but the sample is very complicated and also need to include the "library".

I would be happy, if someone can help me to run this sample

Thanks

Implement floatingView for Video streaming

Thanks for your awesome lib. I trying to play VideoView in FloatingService But it's buggy and when trying to show video screen goes to black (I think it's because of SurfaceView I'm not sure)

I also have another problem when I want to switch from current VideoView to your service I don't know how to continue from last position which is played. I Ask a question here But I didn't get answer could you please help me to solve this issue?

http://stackoverflow.com/questions/38615981/implement-floating-view-for-video-streaming

Android O - Crash because of permission handling

07-26 22:53:21.622 4970-4970/jp.co.recruit.floatingview E/AndroidRuntime: FATAL EXCEPTION: main
Process: jp.co.recruit.floatingview, PID: 4970
java.lang.RuntimeException: Unable to start service jp.co.recruit_lifestyle.sample.service.ChatHeadService@e7250e9 with Intent { cmp=jp.co.recruit.floatingview/jp.co.recruit_lifestyle.sample.service.ChatHeadService }: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@fe840cc -- permission denied for window type 2007
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3556)
at android.app.ActivityThread.-wrap20(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1698)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6540)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@fe840cc -- permission denied for window type 2007
at android.view.ViewRootImpl.setView(ViewRootImpl.java:788)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:92)
at jp.co.recruit_lifestyle.android.floatingview.FloatingViewManager.addViewToWindow(FloatingViewManager.java:493)
at jp.co.recruit_lifestyle.sample.service.ChatHeadService.onStartCommand(ChatHeadService.java:68)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3539)
at android.app.ActivityThread.-wrap20(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1698) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6540) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

startObjectAnimation() only updates either X or Y

  1. There should be a mMoveEdgeAnimatorX and a mMoveEdgeAnimatorY, not just one. Currently it only moves horizontally or vertically
  2. the moveTo() method should be public

This is so that developers can move the floatingView themselves and do something like this:

https://giant.gfycat.com/FlickeringVioletFoxterrier.webm

Support Android P

branch
https://github.com/recruit-lifestyle/FloatingView/tree/feature/support_p

Supporting for a complicated view

First of all, i'm sorry for posting here, i can't found your contact.
Can you make it supports a complicated view. I'm using the library, and my view has some buttons, the problem is i can't click on any button. Thanks in advanced.

Free Float?

This seems to have been an option in previous builds. Is there a way to reenable the floating view to be placed anywhere on the screen instead of snapping to an edge? Thanks!

Why service?

Documentation says:
2) Implement Service for displaying FloatingView

Why we have to use service?
I can create instance of FloatingViewManager in Application class, for example.

Adding PopupWindow on onClickListener

Hello,

I tried opening a popupwindow calling the following method in the onclicklistener of the chathead, but I did not manage to show it properly.
Whatever size I define my popup seems to be displayed within the range of the chathead. I would like to display it below the chathead, filling all the display size available below.
I tried also with ListPopupWindow and that is working fine.

This is my code:

`private void displayPopupWindow(View anchorView) {

    LayoutInflater mInflater;
    Context context=this.getApplicationContext();
    mInflater = LayoutInflater.from(context);

    int width;
    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    width = size.x;


    View popupView = mInflater.inflate(R.layout.webview, null);

    PopupWindow popup = new PopupWindow(popupView);

    WebView webView = (WebView) popupView.findViewById(R.id.webView1);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl("http://www.google.com");
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);

            return true;
        }
    });

    popup.setContentView(webView);

    // Set content width and height
    popup.setHeight(500);
    popup.setWidth((int)width);

    // Closes the popup window when touch outside of it - when looses focus
    popup.setOutsideTouchable(true);
    popup.setFocusable(true);
    popup.setBackgroundDrawable(new BitmapDrawable());

    // Show anchored to button
    popup.showAtLocation(anchorView, Gravity.BOTTOM | Gravity.LEFT, 0, -100);
    //popup.showAsDropDown(anchorView, 0, -150);
}`

Can you please help me? Thank you.

Bugs on Galaxy S9+

When move floatingview, position between finger and the floatingview is wrong

permission denied for this window type. ..

It worked fine on old phones. but on marshmallow and nougat it's crashing.
permission denied for this window type. .. on the line
mFloatingViewManager.addViewToWindow(iconView, options);

i guess this will do the job.
params.type = WindowManager.LayoutParams.TYPE_TOAST;

instead of
params.type = WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;

Please kindly update asap.. my app is crashing.

Unable to add window -- token null is not valid; is your activity running?

I'm getting error:

android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:562)

Error happens when i Pass applicationsContext instead of getActivity() into FloatingViewManager.
mFloatingViewManager = new FloatingViewManager(getApplicationContext()

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

in manifest but its not helps.

How to fix it?

Allow EditText editing

Keyboard doesn't show, and text is not able to be selected when using an EditText layout. It's possible with Wei's library, which is now outdated.

Crash on display with oreo 8

Even setting floatingViewWidth/floatingViewHeight when I call the sample code service I repeatedly have it crash with:

01-28 16:04:10.391 12421 12421 E AndroidRuntime: FATAL EXCEPTION: main
01-28 16:04:10.391 12421 12421 E AndroidRuntime: Process: com.android.systemui, PID: 12421
01-28 16:04:10.391 12421 12421 E AndroidRuntime: java.lang.IllegalArgumentException: width and height must be > 0
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.graphics.Bitmap.createBitmap(Bitmap.java:1027)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.graphics.Bitmap.createBitmap(Bitmap.java:994)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.graphics.Bitmap.createBitmap(Bitmap.java:944)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.graphics.Bitmap.createBitmap(Bitmap.java:905)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.graphics.drawable.AdaptiveIconDrawable.updateMaskBoundsInternal(AdaptiveIconDrawable.java:333)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.graphics.drawable.AdaptiveIconDrawable.updateLayerBounds(AdaptiveIconDrawable.java:295)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.graphics.drawable.AdaptiveIconDrawable.onStateChange(AdaptiveIconDrawable.java:782)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.graphics.drawable.Drawable.setState(Drawable.java:775)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.widget.ImageView.drawableStateChanged(ImageView.java:1318)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.view.View.refreshDrawableState(View.java:20028)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.view.View.dispatchAttachedToWindow(View.java:17425)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.view.ViewGroup.addViewInner(ViewGroup.java:4959)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.view.ViewGroup.addView(ViewGroup.java:4750)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at com.android.systemui.statusbar.phone.NotificationIconAreaController.updateIconsForLayout(NotificationIconAreaController.java:247)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at com.android.systemui.statusbar.phone.NotificationIconAreaController.updateNotificationIcons(NotificationIconAreaController.java:155)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at com.android.systemui.statusbar.phone.StatusBar.updateNotificationShade(StatusBar.java:2171)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at com.android.systemui.statusbar.phone.StatusBar.updateNotifications(StatusBar.java:2351)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at com.android.systemui.statusbar.phone.StatusBar.addNotificationViews(StatusBar.java:7352)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at com.android.systemui.statusbar.phone.StatusBar.addEntry(StatusBar.java:1842)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at com.android.systemui.statusbar.phone.StatusBar.onAsyncInflationFinished(StatusBar.java:1859)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at com.android.systemui.statusbar.notification.NotificationInflater$AsyncInflationTask.onAsyncInflationFinished(NotificationInflater.java:641)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at com.android.systemui.statusbar.notification.NotificationInflater.finishIfDone(NotificationInflater.java:460)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at com.android.systemui.statusbar.notification.NotificationInflater.-wrap0(Unknown Source:0)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at com.android.systemui.statusbar.notification.NotificationInflater$6.onViewApplied(NotificationInflater.java:343)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.widget.RemoteViews$AsyncApplyTask.onPostExecute(RemoteViews.java:3424)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.widget.RemoteViews$AsyncApplyTask.onPostExecute(RemoteViews.java:3404)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.os.AsyncTask.finish(AsyncTask.java:695)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.os.AsyncTask.-wrap1(Unknown Source:0)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:105)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:164)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:6592)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
01-28 16:04:10.391 12421 12421 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:769)
01-28 16:04:10.400  1938  1992 I ActivityManager: Showing crash dialog for package com.android.systemui u0

Set initial X and Y and keep move to side feature

Hi @YoshihideSogawa,

I am currently using this library to implement a floating view for my application, however my projects requires two funtionalities:

  1. Initialize position to be at the bottom corner of the screen
  2. If user drags the floating view to the middle of the screen, it will be moved to the closest left/right side instead of letting the view stay in the middle of the application.

What I have come to realize is that if I use:

options.floatingViewX = metrics.widthPixels - sizeOfChatHead;
options.floatingViewY = (int) this.getResources().getDimension(R.dimen.general_padding);

to set the icon to bottom left corner, I lose the second functionality.
If I don't set this option, it works the way I want it but it defaults the position on the top left corner of the screen.

Is there a way around this?

How to avoid this kind of thing?

Seems like including a default layout to be inflated causes this weird behavior, the trash shaded area is jumping... Idk how to solve it, as I really need the message prompted as the image attached.

I'm using the configurations like the sample app (chat heads one), but inflating this layout instead of only the imageview:

<?xml version="1.0" encoding="utf-8"?>
   <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/shape_tin_message"
    android:padding="16dp">

    <RoundedImageView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_gravity="center"
        android:scaleType="centerCrop"
        android:layout_width="20dp"
        android:layout_height="20dp"
        app:oval="true"
        android:src="@drawable/ic_launcher"/>

    <TextView
        android:id="@+id/tin_message"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/white"
        android:textStyle="bold"
        android:textSize="16sp"
        android:layout_gravity="center_vertical"
        android:layout_marginStart="5dp"
        android:textAppearance="?android:textAppearanceMedium"
        tools:text="My TIN # is: 1125198411"/>

</LinearLayout>

image

How to remove view programmatically?

Hi,
I search for method like removeView() to remove floating view from screen.
I found method mFloatingViewManager.removeAllViewToWindow() but seems its not working.

FloatingViewManager.removeAllViewToWindow() causes IllegalArgumentException

I'm Here's the stacktrace.

java.lang.IllegalArgumentException: View=jp.co.recruit_lifestyle.android.floatingview.a{2d7e2db VFE...C.. ......ID 0,0-216,216} not attached to window manager

Caused By:
android.view.WindowManagerGlobal.findViewLocked (WindowManagerGlobal.java:509)
android.view.WindowManagerGlobal.removeView (WindowManagerGlobal.java:399)
android.view.WindowManagerImpl.removeViewImmediate (WindowManagerImpl.java:123)
jp.co.recruit_lifestyle.android.floatingview.FloatingViewManager.removeAllViewToWindow (SourceFile:550)
com.geecko.QuickLyric.services.LyricsOverlayService.onStartCommand (SourceFile:278)
android.app.ActivityThread.handleServiceArgs (ActivityThread.java:3639)
android.app.ActivityThread.-wrap20 (Unknown Source)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1768)
android.os.Handler.dispatchMessage (Handler.java:108)
android.os.Looper.loop (Looper.java:206)
android.app.ActivityThread.main (ActivityThread.java:6749)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:240)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:845)

Have gotten several thousands crash reports like this in the past 30 days.
The Library version that's used here is 2.3.1.
Important to note it only happens with Android 8.

Perhaps you need to use ViewCompat.isAttachedToWindow()?

RelativeLayout with button

I trying to create the RelativeLayout class to replace the iconView

final ImageView iconView = (ImageView) inflater.inflate(R.layout.widget_mail, null, false);

like is

final MapRelativeLayout mapView = new MapRelativeLayout(getApplicationContext());

the mapView can show on screen, but the button OnClickListener is not working,
How can I fix it?

and there is my MapRelativeLayout class

public class MapRelativeLayout extends RelativeLayout {
    LayoutInflater mInflater;
    public MapRelativeLayout(Context context){
        super(context);
        mInflater = LayoutInflater.from(context);
        init();
    }

    public void init()
    {
        View v = mInflater.inflate(R.layout.widget_map_relative_layout, this, true);
       Button btn = findViewById(R.id.button);
        btn.setText("Testing");
        btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d("TEST", "Testing");
            }
        });
    }
}

com.github.recruit-lifestyle:FloatingView:2.2.3 does not compile with Dagger

I have a project built with Dagger 2.0. When i added compile 'com.github.recruit-lifestyle:FloatingView:2.2.3 to build.gradle i got DaggerApplicationComponent can not be resolved error wich means Dagger can not compile together with this library.

I know this error of Dagger and had solved it before but this time the only solution is to remove the FloatingView dependency but i need it !!

Any solution ?

FloatingView not showing Android 4

Hi, first of all, thank you!

I have a problem, i just realized that the floatingview i implemented on my app isn't showing on android 4 devices. And, searching for the problem, I tried the sample you gave us on an android 4 device and it isn't showing too.

I saw another closed issue where it was supposely working on android 4. Is there a workaround that i need to implement for this?

Using DISPLAY_MODE_SHOW_ALWAYS without the floating view jumping position

Hi there

We are trying to use your library with full screen apps like games for example but we noticed that the floating view jumps position when loading a game, i noticed code that adjusts when screen size changes but i want to disable this, so how can i do so?

We need when it starts a particular position it doesn´t move when opening a full screen app.

Any idea how can we achieve this?

Low res icons and trash_fix

screenshot_20160619-132647

screenshot_20160619-133422

As you can see, the drag icon isn't high res. I tried putting a high res pic there but it just appears big in size.
Even the trash icons aren't displayed correctly. Can you direct me how to fix this ?

Cannot make it work, even not the sample

Hi i have been trying to run this for hours, i couldn't make it work. So i downloaded the sample project & tried running/debugging that also. No luck so far. I own a Xiaomi Redmi Note 3 with android lollipop 5.1 installed. The code executes, the service runs till end i got a notification up-top but no floating widget anywhere. Can you help me.

Detect floatingview onmove

I need to remember the last position of the view. There is initial x and y options but how to detect view movement so i can save x and y.

FloatingView appears above the navbar

The window probably has a wrong type. It doesn't look good when the floatingview appears above the navbar. For instance, when you're in landscape mode and you put the floatingview on the same side as the navbar.

This is not the case with Facebook Messenger.

See my screenshots:

test
test2

Crash for the sample project

java.lang.NoSuchMethodError: No static method canDrawOverlays(Landroid/content/Context;)Z in class Landroid/provider/Settings; or its super classes (declaration of 'android.provider.Settings' appears in /system/framework/framework.jar:classes2.dex)
11-03 16:50:16.142 26338-26338/jp.co.recruit.floatingview E/AndroidRuntime:     at jp.co.recruit_lifestyle.sample.fragment.FloatingViewControlFragment.showChatHead(FloatingViewControlFragment.java:165)
11-03 16:50:16.142 26338-26338/jp.co.recruit.floatingview E/AndroidRuntime:     at jp.co.recruit_lifestyle.sample.fragment.FloatingViewControlFragment.access$100(FloatingViewControlFragment.java:26)
11-03 16:50:16.142 26338-26338/jp.co.recruit.floatingview E/AndroidRuntime:     at jp.co.recruit_lifestyle.sample.fragment.FloatingViewControlFragment$2.onClick(FloatingViewControlFragment.java:98)
11-03 16:50:16.142 26338-26338/jp.co.recruit.floatingview E/AndroidRuntime:     at android.view.View.performClick(View.java:4780)
11-03 16:50:16.142 26338-26338/jp.co.recruit.floatingview E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:19866)
11-03 16:50:16.142 26338-26338/jp.co.recruit.floatingview E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:739)
11-03 16:50:16.142 26338-26338/jp.co.recruit.floatingview E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
11-03 16:50:16.142 26338-26338/jp.co.recruit.floatingview E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:135)
11-03 16:50:16.142 26338-26338/jp.co.recruit.floatingview E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5254)
11-03 16:50:16.142 26338-26338/jp.co.recruit.floatingview E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
11-03 16:50:16.142 26338-26338/jp.co.recruit.floatingview E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372)
11-03 16:50:16.142 26338-26338/jp.co.recruit.floatingview E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
11-03 16:50:16.142 26338-26338/jp.co.recruit.floatingview E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

Multiple actions

Would it be possible to implement more than one action while dragging (the X button and something else for example)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.