项目作者: hzw1199

项目描述 :
FloatingView moved by finger supporting OverlaySystem, OverlayActivity, OverlayViewGroup modes
高级语言: Java
项目地址: git://github.com/hzw1199/FloatingView.git
创建时间: 2019-07-16T11:18:08Z
项目社区:https://github.com/hzw1199/FloatingView

开源协议:

下载


FloatingView

Platform
API
License

中文看这里



Features

  • Support three modes: OverlaySystemOverlayActivity and OverlayViewGroup
  • OverlaySystem: Display FloatingView above other apps
  • OverlayActivity: Display FloatingView above certain Activity
  • OverlayViewGroup: Display FloatingView above certain ViewGroup
  • Move FloatingView with finger
  • Scale FloatingView with two fingers (can be disabled)
  • Listen to click and double-click events
  • Define 9 initial position for FloatingView
  • Define initial paddings for FloatingView
  • Hold FloatingView object, so that you can change the content of FloatingView dynamically, and set OnClickListener for each child view of FloatingView

Usage

Step 1

Add it in your build.gradle at the end of repositories:

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url "https://jitpack.io" }
  5. }
  6. }

Add the dependency in the form:

  1. dependencies {
  2. compile 'com.github.hzw1199:FloatingView:1.7.0'
  3. }

Step 2

Configure and display

  • OverlaySystem mode

AndroidManifest.xml:

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

onCreate:

  1. FloatingViewConfig config = new FloatingViewConfig.Builder()
  2. .setPaddingLeft(paddingLeft)
  3. .setPaddingTop(paddingTop)
  4. .setPaddingRight(paddingRight)
  5. .setPaddingBottom(paddingBottom)
  6. .setGravity(gravity)
  7. .build();
  8. floatingView = new FloatingView(OverlaySystemActivity.this, R.layout.view_floating, config);
  9. floatingView.showOverlaySystem();

onDestroy:

  1. if (floatingView != null) {
  2. floatingView.hide();
  3. }
  • OverlayActivity mode

onAttachedToWindow:

  1. FloatingViewConfig config = new FloatingViewConfig.Builder()
  2. .setPaddingLeft(paddingLeft)
  3. .setPaddingTop(paddingTop)
  4. .setPaddingRight(paddingRight)
  5. .setPaddingBottom(paddingBottom)
  6. .setGravity(gravity)
  7. .build();
  8. floatingView = new FloatingView(OverlaySystemActivity.this, R.layout.view_floating, config);
  9. floatingView.showOverlayActivity();

onDetachedFromWindow:

  1. if (floatingView != null) {
  2. floatingView.hide();
  3. }
  • OverlayViewGroup mode

onCreate:

  1. lyViewGroup.post(new Runnable() {
  2. @Override
  3. public void run() {
  4. FloatingViewConfig config = new FloatingViewConfig.Builder()
  5. .setPaddingLeft(paddingLeft)
  6. .setPaddingTop(paddingTop)
  7. .setPaddingRight(paddingRight)
  8. .setPaddingBottom(paddingBottom)
  9. .setGravity(gravity)
  10. .setDisplayWidth(lyViewGroup.getWidth())
  11. .setDisplayHeight(lyViewGroup.getHeight())
  12. .build();
  13. floatingView = new FloatingView(OverlaySystemActivity.this, R.layout.view_floating, config);
  14. floatingView.showOverlayViewGroup(lyViewGroup);
  15. }
  16. });

onDestroy:

  1. if (floatingView != null) {
  2. floatingView.hide();
  3. }

lyViewGroup is the ViewGroup to display FloatingView above

Step 3

Click event

  1. floatingView.setOnClickListener(new View.OnClickListener() {
  2. @Override
  3. public void onClick(View v) {
  4. }
  5. });

Double-click event

  1. floatingView.setOnDoubleClickListener(new View.OnClickListener() {
  2. @Override
  3. public void onClick(View v) {
  4. }
  5. });

Maximize zoom

  1. floatingView.full();

Hold the Floating View object, to change the content logically

demo

  1. LayoutInflater mInflater = LayoutInflater.from(AdvancedControlActivity.this);
  2. View floatingView = mInflater.inflate(R.layout.view_advanced_control, null, false);
  3. floatingView = new FloatingView(AdvancedControlActivity.this, floatingView, config);

Set OnClickListener for subviews of Floating View

demo

  1. LayoutInflater mInflater = LayoutInflater.from(AdvancedControlActivity.this);
  2. View floatingView = mInflater.inflate(R.layout.view_advanced_control, null, false);
  3. floatingView = new FloatingView(AdvancedControlActivity.this, floatingView, config);
  4. final View vTop = floatingView.findViewById(R.id.v_top);
  5. final View vMiddle = floatingView.findViewById(R.id.v_middle);
  6. final View vBottom = floatingView.findViewById(R.id.v_bottom);
  7. final TextView tvTime = floatingView.findViewById(R.id.tv_time);
  8. View.OnClickListener onClickListener = new View.OnClickListener() {
  9. @Override
  10. public void onClick(View v) {
  11. if (v == vTop) {
  12. Toast.makeText(AdvancedControlActivity.this, "Top clicked", Toast.LENGTH_SHORT).show();
  13. } else if (v == vMiddle) {
  14. Toast.makeText(AdvancedControlActivity.this, "Middle clicked", Toast.LENGTH_SHORT).show();
  15. } else if (v == vBottom) {
  16. Toast.makeText(AdvancedControlActivity.this, "Bottom clicked", Toast.LENGTH_SHORT).show();
  17. }
  18. tvTime.setText(String.valueOf(System.currentTimeMillis()));
  19. }
  20. };
  21. vTop.setOnClickListener(onClickListener);
  22. vMiddle.setOnClickListener(onClickListener);
  23. vBottom.setOnClickListener(onClickListener);

Proguard

No need to add more proguard rules, consumerProguardFiles has already handled library proguard rules.

Tip

  • Please check the demo before use.
  • If this project helps you, please star me.

About Me

License

  1. The MIT License (MIT)
  2. Copyright (c) 2019 FloatingView
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.