TakuSemba / Spotlight

Android Library that lights items for tutorials or walk-throughs etc...
Apache License 2.0
3.63k stars 364 forks source link

assign target to view.. #27

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi,

im trying to implement the library, but i cant put target as a view to method setPoint(textview1);

the round is not fit to the view..

any advice would help much.

thanks

ghost commented 6 years ago

SimpleTarget simpleTarget = new SimpleTarget.Builder(this) //location 1 = kiri kanan, location 2 = atas bawah .setPoint(findViewById(R.id.view1)) // position of the Target. setPoint(Point point), setPoint(View view) will work too. .setRadius(200f) // radius of the Target .setTitle(getResources().getString(R.string.preview_step1_title)) .setDescription(getResources().getString(R.string.preview_step1_text)) .setOnSpotlightStartedListener(new OnTargetStateChangedListener() { @Override public void onStarted(SimpleTarget target) { // do something }

                @Override
                public void onEnded(SimpleTarget target) {
                    // do something
                }
            })
            .build();

    Spotlight.with(PreviewActivity.this)
            .setOverlayColor(ContextCompat.getColor(PreviewActivity.this, R.color.background))
            .setDuration(1000L)
            .setAnimation(new DecelerateInterpolator(2f))
            .setTargets(simpleTarget)
            .setClosedOnTouchedOutside(true)
            .setOnSpotlightStartedListener(new OnSpotlightStartedListener() {
                @Override
                public void onStarted() {

                }
            })
            .setOnSpotlightEndedListener(new OnSpotlightEndedListener() {
                @Override
                public void onEnded() {
                    ll1.setVisibility(View.VISIBLE);
                    btnClose1.setVisibility(View.VISIBLE);
                    btnNext1.setVisibility(View.VISIBLE);
                }
            })
            .start();
TakuSemba commented 6 years ago

Can you give me a screenshot of how the spotlight isnt fit.

AndresMorelos commented 6 years ago

I had the same issue, the spotligth isn't fit

Code:

Spotlight.with(this)
                .setOverlayColor(ContextCompat.getColor(this,R.color.background))
                .setDuration(1000L)
                .setAnimation(DecelerateInterpolator(2f))
                .setTargets(
                        SimpleTarget.Builder(this)
                                .setPoint(100f,Intentos.y)
                                .setRadius(100f)
                                .setTitle("Intentos")
                                .setDescription("Este es el contador de los intentos que has realizado,recuerada el maximo es 20!!.")
                                .build()
                ,
                        SimpleTarget.Builder(this)
                                .setPoint(Chronometer.x, Chronometer.y)
                                .setRadius(100f)
                                .setTitle("Cronometro")
                                .setDescription("Tiempo que ha pasado mientras intentas adivinar la palabra.")
                                .build()
                ,
                        SimpleTarget.Builder(this)
                                .setPoint(horizontalScrollView.x , horizontalScrollView.y)
                                .setTitle("Letras")
                                .setDescription("Cada botón representa una letra o caracter, puedes buscar el que necesites pasando el dedo de izquierda a derecha o viceversa")
                                .build()
                )
                .setClosedOnTouchedOutside(true)
                .setOnSpotlightStartedListener {

                }
                .setOnSpotlightEndedListener {

                }
                .start()

Image: whatsapp image 2018-04-27 at 9 22 51 am

TakuSemba commented 6 years ago

Can you try after view is located as I described in Read.me?

view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override public void onGlobalLayout() {
        view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        // show spotlight here
    }
});
AndresMorelos commented 6 years ago
Instrucciones.getViewTreeObserver().addOnGlobalLayoutListener{
            object : ViewTreeObserver.OnGlobalLayoutListener {
                override fun onGlobalLayout() {
                    Instrucciones.viewTreeObserver.removeOnGlobalLayoutListener(this)
                    Spotlight.with(this@instructions)
                            .setOverlayColor(ContextCompat.getColor(this@instructions, R.color.background))
                            .setDuration(1000L)
                            .setAnimation(DecelerateInterpolator(2f))
                            .setTargets(
                                    SimpleTarget.Builder(this@instructions)
                                            .setPoint(Intentos)
                                            .setRadius(100f)
                                            .setTitle("Intentos")
                                            .setDescription("Este es el contador de los intentos que has realizado,recuerada el maximo es 20!!.")
                                            .build()
                                    ,
                                    SimpleTarget.Builder(this@instructions)
                                            .setPoint(Chronometer)
                                            .setRadius(100f)
                                            .setTitle("Cronometro")
                                            .setDescription("Tiempo que ha pasado mientras intentas adivinar la palabra.")
                                            .build()
                                    ,
                                    SimpleTarget.Builder(this@instructions)
                                            .setPoint(horizontalScrollView)
                                            .setTitle("Letras")
                                            .setDescription("Cada botón representa una letra o caracter, puedes buscar el que necesites pasando el dedo de izquierda a derecha o viceversa")
                                            .build()
                            )
                            .setClosedOnTouchedOutside(true)
                            .setOnSpotlightStartedListener {

                            }
                            .setOnSpotlightEndedListener {

                            }
                            .start()
                }

            }

        }

with this code the spotlight doesn't start/show

TakuSemba commented 6 years ago

the code above, is the callback even called? you mean the callback of the onGlobalLayout is called but spotlight doesnt start?

TakuSemba commented 6 years ago

sorry, closing this issue as not seeing your response.