Git Product home page Git Product logo

Comments (6)

hyuwah avatar hyuwah commented on July 30, 2024

Hi @sianyi

Thanks for trying out this library

First of all, could you explain what kind of behavior you want to achieve?

  1. Is it a simple TextView that floats (and drag-able) inside an Activity / Fragment? Or inside a CustomView? Where does the InitialTextView() being called from?
  2. Then, does the TextView has to be inflated / created programmatically?

If the answer of first question is inside activity or fragment & the second question is true, as far as i know, we have to add the TextView to ViewGroup inside the activity / fragment layout

So, assuming you have this layout and activity code

<!-- activity_example.xml -->
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/root_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- Other View or ViewGroup -->
        
</RelativeLayout>

We have RelativeLayout root with root_view as it's id

// ExampleActivity.java
public class ExampleActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_example);

        InitialTextView();
    }

    private void InitialTextView(){
        TextView floatingLuxView = new TextView(this);
        floatingLuxView.setText("Hi I am a overlay View");
        floatingLuxView.setTextColor(Color.rgb(255, 255, 0));
        floatingLuxView.setTextSize(32f);
        floatingLuxView.setShadowLayer(10, 5, 5, Color.rgb(56, 56, 56));

        DraggableUtils.makeDraggable(floatingLuxView);

        WindowManager windowManager = (WindowManager)getSystemService(WINDOW_SERVICE);

        int LAYOUT_FLAG;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
        } else {
            LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_PHONE;
        }

        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                LAYOUT_FLAG,
                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
                        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);
        params.gravity = Gravity.TOP|Gravity.LEFT;

        // We need to add this floatingLuxView to any ViewGroup on the layout
        // in this case i'm adding it to the root_view
        ViewGroup rootView = findViewById(R.id.root_view);
        rootView.addView(floatingLuxView);
    }
}

We have the InitialTextView() function inside the activity and is being called from onCreate(),
then we just need to add the floatingLuxView to the rootView

Here's the result
draggableview-issue-5

If that's the behavior you'd expect, it would be easier to just write the TextView directly on the xml code, so you don't have to deal with attaching / inflating it to the layout manually.

As for the crash issue, i've tried the code you provide without above modification (adding it to the rootView whatsoever), inside a simple activity, but i can't reproduce the crash.
It runs, the TextView doesn't show up, but it doesn't crash. Could you show me your full code of your implementation?

from draggableview.

sianyi avatar sianyi commented on July 30, 2024

Hi I make a simple app for your reference

https://github.com/sianyi/example_of_floating_lux

I would like to show a floating text view on top of screen and overlay others application.
In addition, I hope it is Draggable.

In the simple APP you can see the red color TextView is inside the main Activity and it works well but the yellow color textView is overlay on other application and will rise Exception when I touch it.

from draggableview.

hyuwah avatar hyuwah commented on July 30, 2024

Hi @sianyi

I updated the library to support the case of overlay draggable view over other app via makeOverlayDraggable(). Can you please check version 0.5.0 out ?

I've also updated the readme regarding it's usage example

Here's the preview on emulator (there's no light sensor on emulator so the value stays 0.0)
draggableview-issue-5-4

On a sidenote, i can't make it work on API 19 (Kitkat) device, the overlay was removed as soon as the activity goes into background. I haven't tried it on a Service though.

from draggableview.

sianyi avatar sianyi commented on July 30, 2024

Thanks!, it is really help.
I will try it.

from draggableview.

hyuwah avatar hyuwah commented on July 30, 2024

It might take a while for the updated version to appear on JitPack (several minutes maybe, but it shouldn't take long)

from draggableview.

sianyi avatar sianyi commented on July 30, 2024

I have tested the new version and it works well on my devices, thank you very much.

from draggableview.

Related Issues (14)

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.