Autore Topic: Inviare stringhe infrarosso...ok..ma di continuo? come?  (Letto 739 volte)

Offline smartgatto

  • Utente junior
  • **
  • Post: 96
  • Respect: +3
    • Mostra profilo
  • Dispositivo Android:
    Galaxy S5
  • Sistema operativo:
    Windows 7
Inviare stringhe infrarosso...ok..ma di continuo? come?
« il: 21 Ottobre 2014, 21:01:35 CEST »
0
ciao a tutti...mi spiego meglio:
ho creato un'applicazione per comandare il samsung navibot (robot che aspira automaticamente per terra) tramite infrarossi.
Ok ora funziona bene (devo ancora metterla a punto) però c'è un problema...i tasti "normali" ovvero accensione, ricarica, spot, max, ovvero tutti quei comandi che basta dargli un colpo solo sul telecomando per far partire la funzione vanno benissimo, ma quando si tratta di usare i tasti direzionali per farlo andare dove voglio io (i tasti sono su, sinistra e destra) se tengo schiacciato il tasto voluto, mettiamo "SU" la mia applicazione invia il segnale SU solo quando io mollo il pulsante, così il robot va avanti solo di 1cm, mentre invece la giusta funzione sarebbe che l'applicazione dovrebbe inviare la stessa stringa fino a che non mollo il tasto.
Come posso modificare la mia applicazione?
grazie!!

Codice: [Seleziona]
package com.example.cristina.IRda;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.hardware.ConsumerIrManager;
import android.widget.ImageButton;
import android.widget.Toast;

public class Irda extends Activity {

    ImageButton power;
    ImageButton home;
    ImageButton auto;
    ImageButton max;
    ImageButton spot;
    ImageButton up;
    ImageButton left;
    ImageButton right;
    ImageButton manual;

    ConsumerIrManager mCIR;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_irda);
        mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);
        addListenerOnButton();

    }



    public void addListenerOnButton() {

        power = (ImageButton) findViewById(R.id.power);
        home = (ImageButton) findViewById(R.id.home);
        auto = (ImageButton) findViewById(R.id.auto);
        manual = (ImageButton) findViewById(R.id.manual);
        spot = (ImageButton) findViewById(R.id.spot);
        max = (ImageButton) findViewById(R.id.max);
        up = (ImageButton) findViewById(R.id.up);
        left = (ImageButton) findViewById(R.id.left);
        right = (ImageButton) findViewById(R.id.right);


        power.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Toast.makeText(Irda.this,
                        "Hai cliccato Power", Toast.LENGTH_SHORT).show();
              int[] pattern = {173,170,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,62,23,62,23,62,23,62,23,62,23,62,23,62,23,2500};
                             mCIR.transmit(38000, pattern);

            }

        });


        home.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Toast.makeText(Irda.this,
                        "Hai cliccato Home", Toast.LENGTH_SHORT).show();
                int[] pattern = {173,170,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,19,23,19,23,
                        62,23,62,23,62,23,62,23,62,23,62,23,62,23,2500};
                mCIR.transmit(38000, pattern);

            }

        });

        auto.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Toast.makeText(Irda.this,
                        "Hai cliccato Auto", Toast.LENGTH_SHORT).show();
                int[] pattern = {173,170,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,19,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,
                        19,23,62,23,62,23,62,23,62,23,62,23,62,23,2500

                };
                mCIR.transmit(38000, pattern);

            }

        });

        spot.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Toast.makeText(Irda.this,
                        "Hai cliccato Spot", Toast.LENGTH_SHORT).show();
                int[] pattern = {173,170,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,62,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,19,23,
                        19,23,62,23,62,23,62,23,62,23,62,23,62,23,2500};
                mCIR.transmit(38000, pattern);

            }

        });

        max.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Toast.makeText(Irda.this,
                        "Hai cliccato Max", Toast.LENGTH_SHORT).show();
                int[] pattern = {173,170,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,19,23,19,23,62,23,19,23,19,23,19,23,19,23,19,23,62,23,
                        62,23,19,23,62,23,62,23,62,23,62,23,62,23,2500


                };
                mCIR.transmit(38000, pattern);

            }

        });

        manual.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Toast.makeText(Irda.this,
                        "Hai cliccato Manual", Toast.LENGTH_SHORT).show();
                int[] pattern = {173,170,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,62,23,19,23,19,23,62,23,19,23,19,23,19,23,19,23,19,23,
                        62,23,62,23,19,23,62,23,62,23,62,23,62,23,2500


                };
                mCIR.transmit(38000, pattern);

            }

        });

        up.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Toast.makeText(Irda.this,
                        "Hai cliccato Su", Toast.LENGTH_SHORT).show();
                int[] pattern = {173,170,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,62,23,19,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,
                        62,23,19,23,62,23,62,23,62,23,62,23,62,23,2500


                };
                mCIR.transmit(38000, pattern);

            }

        });

        left.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Toast.makeText(Irda.this,
                        "Hai cliccato Sinistra", Toast.LENGTH_SHORT).show();
                int[] pattern = {173,170,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,19,23,62,23,62,23,19,23,19,23,19,23,19,23,19,23,62,23,
                        19,23,19,23,62,23,62,23,62,23,62,23,62,23,2500


                };
                mCIR.transmit(38000, pattern);

            }

        });

        right.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Toast.makeText(Irda.this,
                        "Hai cliccato Destra", Toast.LENGTH_SHORT).show();
                int[] pattern = {173,170,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,62,23,62,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,
                        19,23,19,23,62,23,62,23,62,23,62,23,62,23,2500


                };
                mCIR.transmit(38000, pattern);

            }

        });
    }


Codice: [Seleziona]
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ff000000"
    android:id="@+id/dd">


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Power"
        android:id="@+id/textView6"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:textColor="#ffffffff"
        android:layout_marginLeft="55dp"
        android:layout_marginTop="35dp" />

    <ImageButton
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:id="@+id/power"
        android:layout_below="@+id/textView6"
        android:layout_alignParentStart="true"
        android:background="@drawable/power"
        android:layout_marginLeft="55dp"
        android:focusableInTouchMode="false" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Home"
        android:id="@+id/textView7"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:textColor="#ffffffff"
        android:layout_marginTop="35dp"
        android:layout_marginRight="55dp" />

    <ImageButton
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:id="@+id/home"
        android:layout_below="@+id/textView7"
        android:layout_alignParentEnd="true"
        android:background="@drawable/home"
        android:layout_marginRight="55dp"
        android:focusableInTouchMode="false" />


    <ImageButton
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:id="@+id/up"
        android:background="@drawable/up"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

    <ImageButton
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:id="@+id/left"
        android:background="@drawable/left"
        android:layout_toEndOf="@+id/auto"
        android:layout_below="@+id/up" />

    <ImageButton
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:id="@+id/right"
        android:background="@drawable/right"
        android:layout_below="@+id/up"
        android:layout_toEndOf="@+id/up" />


    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/power"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="20dp"
        android:id="@+id/linearLayout2">

        <TextView
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Auto"
            android:id="@+id/textView9"
            android:textColor="#ffffffff"
            android:layout_below="@+id/power"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:gravity="center_horizontal" />

        <TextView
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Manual"
            android:id="@+id/textView10"
            android:textColor="#ffffffff"
            android:layout_alignParentStart="false"
            android:layout_alignParentBottom="false"
            android:layout_below="@+id/power"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:gravity="center_horizontal" />

        <TextView
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Spot"
            android:id="@+id/textView11"
            android:textColor="#ffffffff"
            android:layout_below="@+id/power"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:gravity="center_horizontal" />

        <TextView
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Max"
            android:id="@+id/textView8"
            android:textColor="#ffffffff"
            android:layout_below="@+id/power"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:gravity="center_horizontal" />
    </LinearLayout>

    <ImageButton

        android:layout_height="25dp"
        android:id="@+id/auto"
        android:background="@drawable/bottone"
        android:layout_width="50dp"
        android:layout_weight="0"
        android:gravity="center_horizontal"
        android:layout_below="@+id/linearLayout2"
        android:layout_marginLeft="27dp" />

    <ImageButton
        android:layout_height="25dp"
        android:id="@+id/manual"
        android:background="@drawable/bottone"
        android:layout_width="50dp"
        android:layout_weight="0"
        android:gravity="center_horizontal"
        android:layout_alignBottom="@+id/auto"
        android:layout_toEndOf="@+id/power"
        android:layout_marginLeft="8dp" />

    <ImageButton
        android:layout_height="25dp"
        android:id="@+id/spot"
        android:background="@drawable/bottone"
        android:layout_width="50dp"
        android:layout_weight="0"
        android:gravity="center_horizontal"
        android:layout_below="@+id/linearLayout2"
        android:layout_toStartOf="@+id/home"
        android:layout_marginRight="8dp" />

    <ImageButton
        android:layout_height="25dp"
        android:id="@+id/max"
        android:background="@drawable/bottone"
        android:layout_width="50dp"
        android:layout_weight="0"
        android:gravity="center_horizontal"
        android:layout_marginLeft="25dp"
        android:layout_alignBottom="@+id/spot"
        android:layout_alignStart="@+id/textView7" />

    <ImageView
        android:layout_width="187dp"
        android:layout_height="28dp"
        android:id="@+id/imageView"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="50dp"
        android:background="@drawable/samsunglogo" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="by XXXXXXXXxxxxxxxxxxx"
        android:id="@+id/textView"
        android:textColor="#fff9f9f9"
        android:textAlignment="center"
        android:layout_alignParentBottom="true"
        android:layout_alignStart="@+id/manual" />

</RelativeLayout>

Offline eagledeveloper

  • Translate Team
  • Utente senior
  • ****
  • Post: 516
  • Respect: +37
    • Google+
    • 347516210
    • dark_pinz
    • @WandDStudios
    • Mostra profilo
    • W&D Studios
  • Dispositivo Android:
    HTC One X e HTC One
  • Play Store ID:
    W%26D+Studios
  • Sistema operativo:
    Ubuntu / Windows 7
Re:Inviare stringhe infrarosso...ok..ma di continuo? come?
« Risposta #1 il: 22 Ottobre 2014, 13:06:09 CEST »
0
Prova ad usare setOnTouchListener invece che setOnClickListener
I numeri contano molto di più del seme.

Offline smartgatto

  • Utente junior
  • **
  • Post: 96
  • Respect: +3
    • Mostra profilo
  • Dispositivo Android:
    Galaxy S5
  • Sistema operativo:
    Windows 7
Re:Inviare stringhe infrarosso...ok..ma di continuo? come?
« Risposta #2 il: 22 Ottobre 2014, 14:36:17 CEST »
0
Innanzitutto scusate per il crosspost non era mia intenzione..semplicemente avevo trovato una sezione più indicata...

poi...
ho provato a mettere setOnTouchListener così:

Codice: [Seleziona]
power.setOnTouchListener(new OnTouchListener() {

            @Override
            public void onTouch(View arg0) {
                Toast.makeText(Irda.this,
                        "Hai cliccato Power", Toast.LENGTH_SHORT).show();
              int[] pattern = {173,170,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,19,23,19,23,19,23,19,23,19,23,19,23,19,23,19,23,62,23,62,23,62,23,62,23,62,23,62,23,62,23,62,23,2500};
                             mCIR.transmit(38000, pattern);

            }

ma mi da errore:
"class 'anonymous class derived from ontouchlistener' must either be declared etc etc"

e la scritta onTouch (dopo Public void) rimane grigia (method ontouch never used)
« Ultima modifica: 22 Ottobre 2014, 15:08:42 CEST da smartgatto »

Offline eagledeveloper

  • Translate Team
  • Utente senior
  • ****
  • Post: 516
  • Respect: +37
    • Google+
    • 347516210
    • dark_pinz
    • @WandDStudios
    • Mostra profilo
    • W&D Studios
  • Dispositivo Android:
    HTC One X e HTC One
  • Play Store ID:
    W%26D+Studios
  • Sistema operativo:
    Ubuntu / Windows 7
Re:Inviare stringhe infrarosso...ok..ma di continuo? come?
« Risposta #3 il: 22 Ottobre 2014, 15:14:16 CEST »
0
Dove ti da errore?
I numeri contano molto di più del seme.

Offline smartgatto

  • Utente junior
  • **
  • Post: 96
  • Respect: +3
    • Mostra profilo
  • Dispositivo Android:
    Galaxy S5
  • Sistema operativo:
    Windows 7
Re:Inviare stringhe infrarosso...ok..ma di continuo? come?
« Risposta #4 il: 22 Ottobre 2014, 15:16:57 CEST »
0
sulla linea:
power.setOnTouchListener(new OnTouchListener()

mi rimane sottolineato di rosso OnTouchListener() e se ci vado sopra mi da quella scritta "Error:(164, 56) error: <anonymous com.example.cristina.IRda.Irda$9> is not abstract and does not override abstract method onTouch(View,MotionEvent) in OnTouchListener"

Post unito: 22 Ottobre 2014, 15:53:38 CEST
Ho provato a modificare così:
Codice: [Seleziona]
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_irda);
        mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);
        addListenerOnButton();

    }



    public void addListenerOnButton() {

        power = (ImageButton) findViewById(R.id.power);
        home = (ImageButton) findViewById(R.id.home);
        auto = (ImageButton) findViewById(R.id.auto);
        manual = (ImageButton) findViewById(R.id.manual);
        spot = (ImageButton) findViewById(R.id.spot);
        max = (ImageButton) findViewById(R.id.max);
        up = (ImageButton) findViewById(R.id.up);
        left = (ImageButton) findViewById(R.id.left);
        right = (ImageButton) findViewById(R.id.right);


        power.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Toast.makeText(Irda.this, "Hai cliccato Power", Toast.LENGTH_SHORT).show();
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
                mCIR.transmit(38000, pattern);
                return false;

            }

        });


        home.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Toast.makeText(Irda.this, "Hai cliccato Home", Toast.LENGTH_SHORT).show();
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                        62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
                mCIR.transmit(38000, pattern);
                return false;

            }

        });

        auto.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                Toast.makeText(Irda.this, "Hai cliccato Auto", Toast.LENGTH_SHORT).show();
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 19, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23,
                        19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500

                };
                mCIR.transmit(38000, pattern);
                return false;

            }

        });

        spot.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Toast.makeText(Irda.this, "Hai cliccato Spot", Toast.LENGTH_SHORT).show();
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                        19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
                mCIR.transmit(38000, pattern);
                return false;

            }

        });

        max.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Toast.makeText(Irda.this, "Hai cliccato Max", Toast.LENGTH_SHORT).show();
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 19, 23, 19, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23,
                        62, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
                mCIR.transmit(38000, pattern);
                return false;

            }

        });

        manual.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Toast.makeText(Irda.this, "Hai cliccato Manual", Toast.LENGTH_SHORT).show();
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                        62, 23, 62, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
                mCIR.transmit(38000, pattern);
                return false;

            }

        });

        up.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Toast.makeText(Irda.this, "Hai cliccato Su", Toast.LENGTH_SHORT).show();
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                        62, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
                mCIR.transmit(38000, pattern);
                return false;

            }

        });

        left.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Toast.makeText(Irda.this, "Hai cliccato Sinistra", Toast.LENGTH_SHORT).show();
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23,
                        19, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
                mCIR.transmit(38000, pattern);
                return false;
            }

        });

        right.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Toast.makeText(Irda.this, "Hai cliccato Destra", Toast.LENGTH_SHORT).show();
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                        19, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
                mCIR.transmit(38000, pattern);
                return false;

            }

        });

    }

}

Sembra andare meglio ma ancora non ci siamo del tutto...ovvero...adesso se tengo schiacciato qualsiasi button vedo che lampeggia il led blu del mio telefono quindi vuol dire che invia il segnale ma ancora non è un invio lineare (tipo lampeggio continuo) ma a tratti va e poi si ferma per tipo un secondo e poi riprende ad inviare il segnale infrarosso...quindi l'andamento del robot è "tratteggiato"...
« Ultima modifica: 22 Ottobre 2014, 15:53:38 CEST da smartgatto, Reason: Merged DoublePost »

Offline eagledeveloper

  • Translate Team
  • Utente senior
  • ****
  • Post: 516
  • Respect: +37
    • Google+
    • 347516210
    • dark_pinz
    • @WandDStudios
    • Mostra profilo
    • W&D Studios
  • Dispositivo Android:
    HTC One X e HTC One
  • Play Store ID:
    W%26D+Studios
  • Sistema operativo:
    Ubuntu / Windows 7
Re:Inviare stringhe infrarosso...ok..ma di continuo? come?
« Risposta #5 il: 22 Ottobre 2014, 16:49:52 CEST »
0
Devi gestire il MotionEvent event dell'OnTouch.
I numeri contano molto di più del seme.

Offline smartgatto

  • Utente junior
  • **
  • Post: 96
  • Respect: +3
    • Mostra profilo
  • Dispositivo Android:
    Galaxy S5
  • Sistema operativo:
    Windows 7
Re:Inviare stringhe infrarosso...ok..ma di continuo? come?
« Risposta #6 il: 22 Ottobre 2014, 20:45:09 CEST »
0
Dopo varie prove di scrittura del codice ho "partorito" questa versione, usando OnTouch..però il risultato è il medesimo di prima, ovvero invio "non lineare" del segnale...
ma ora però sono riuscito a notare una cosa: se premo su un tasto e mantengo il dito fermo sul pulsante l'invio della stringa è irregolare, mentre se invece premo il dito sul button roteandolo sul button stesso (ovvero senza tenere fermo il dito) l'invio della stringa infrarossa è "lineare" proprio come vorrei io...
come posso risolvere?

Codice: [Seleziona]
package com.example.cristina.IRda;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.hardware.ConsumerIrManager;
import android.widget.ImageButton;

public class Irda extends Activity implements OnTouchListener {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_irda);
        ImageButton power = (ImageButton) findViewById(R.id.power);
        ImageButton home = (ImageButton) findViewById(R.id.home);
        ImageButton auto = (ImageButton) findViewById(R.id.auto);
        ImageButton max = (ImageButton) findViewById(R.id.max);
        ImageButton spot = (ImageButton) findViewById(R.id.spot);
        ImageButton up = (ImageButton) findViewById(R.id.up);
        ImageButton left = (ImageButton) findViewById(R.id.left);
        ImageButton right = (ImageButton) findViewById(R.id.right);
        ImageButton manual = (ImageButton) findViewById(R.id.manual);
        ImageButton pausa = (ImageButton) findViewById(R.id.pausa);

        power.setOnTouchListener(this);
        home.setOnTouchListener(this);
        auto.setOnTouchListener(this);
        max.setOnTouchListener(this);
        spot.setOnTouchListener(this);
        up.setOnTouchListener(this);
        left.setOnTouchListener(this);
        right.setOnTouchListener(this);
        manual.setOnTouchListener(this);
        pausa.setOnTouchListener(this);

    }




    //@Override
    public boolean onTouch(View v, MotionEvent event) {
        if (v.getId() == R.id.power) {
            ConsumerIrManager mCIR;
            mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);

            int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                    19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 19, 23, 19, 23,
                    19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23,
                    62, 23, 62, 23, 2500};
            mCIR.transmit(38000, pattern);

        }

        else

        if (v.getId() == R.id.home) {
            ConsumerIrManager mCIR;
            mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);

            int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                    19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23,
                    19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23,
                    62, 23, 62, 23, 2500};
            mCIR.transmit(38000, pattern);

        }


        else

        if (v.getId() == R.id.auto) {
            ConsumerIrManager mCIR;
            mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);

            int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                    19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 19, 23, 62, 23,
                    19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23,
                    62, 23, 62, 23, 2500};
            mCIR.transmit(38000, pattern);


        }

        else
        if (v.getId() == R.id.max) {
            ConsumerIrManager mCIR;
            mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);

            int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                    19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 19, 23, 19, 23,
                    62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23,
                    62, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
            mCIR.transmit(38000, pattern);


        }

        else
        if (v.getId() == R.id.spot) {
            ConsumerIrManager mCIR;
            mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);

            int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                    19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 62, 23,
                    19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                    19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
            mCIR.transmit(38000, pattern);


        }

        else
        if (v.getId() == R.id.up) {
            ConsumerIrManager mCIR;
            mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);

            int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                    19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23,
                    62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                    62, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
            mCIR.transmit(38000, pattern);

        }

        else
        if (v.getId() == R.id.right) {
            ConsumerIrManager mCIR;
            mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);

            int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19,
                    23, 19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 62,
                    23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                    19, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
            mCIR.transmit(38000, pattern);

        }

        else
        if (v.getId() == R.id.left) {
            ConsumerIrManager mCIR;
            mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);

            int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                    19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 19, 23, 62, 23,
                    62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23,
                    19, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
            mCIR.transmit(38000, pattern);

        }

        else
        if (v.getId() == R.id.manual) {
            ConsumerIrManager mCIR;
            mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);

            int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                    19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23,
                    19, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                    62, 23, 62, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
            mCIR.transmit(38000, pattern);

        }

        else
        if (v.getId() == R.id.pausa) {
            ConsumerIrManager mCIR;
            mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);

            int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19,
                    23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 19, 23, 19, 23, 19,
                    23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 62, 23, 19, 23, 62, 23, 62, 23, 62,
                    23, 62, 23, 2500};
            mCIR.transmit(38000, pattern);

        }
        return false;
    }
}


« Ultima modifica: 22 Ottobre 2014, 22:19:06 CEST da smartgatto »

Offline eagledeveloper

  • Translate Team
  • Utente senior
  • ****
  • Post: 516
  • Respect: +37
    • Google+
    • 347516210
    • dark_pinz
    • @WandDStudios
    • Mostra profilo
    • W&D Studios
  • Dispositivo Android:
    HTC One X e HTC One
  • Play Store ID:
    W%26D+Studios
  • Sistema operativo:
    Ubuntu / Windows 7
Re:Inviare stringhe infrarosso...ok..ma di continuo? come?
« Risposta #7 il: 23 Ottobre 2014, 08:01:46 CEST »
0
Ripeto, documentati sul MotionEvent che hai nell' onTouch.
I numeri contano molto di più del seme.

Offline smartgatto

  • Utente junior
  • **
  • Post: 96
  • Respect: +3
    • Mostra profilo
  • Dispositivo Android:
    Galaxy S5
  • Sistema operativo:
    Windows 7
Re:Inviare stringhe infrarosso...ok..ma di continuo? come?
« Risposta #8 il: 23 Ottobre 2014, 08:58:13 CEST »
0
Ciao..l'avevo scritto ma poi ho editato il mio ultimo post... poiche ho un po di problemi con l'inglese le varie pagine che ho trovato sul motionEvent non sono riuscito a capirle bene..  conosci qualche link in italiano? Grazie infinite!

Offline eagledeveloper

  • Translate Team
  • Utente senior
  • ****
  • Post: 516
  • Respect: +37
    • Google+
    • 347516210
    • dark_pinz
    • @WandDStudios
    • Mostra profilo
    • W&D Studios
  • Dispositivo Android:
    HTC One X e HTC One
  • Play Store ID:
    W%26D+Studios
  • Sistema operativo:
    Ubuntu / Windows 7
I numeri contano molto di più del seme.

Offline smartgatto

  • Utente junior
  • **
  • Post: 96
  • Respect: +3
    • Mostra profilo
  • Dispositivo Android:
    Galaxy S5
  • Sistema operativo:
    Windows 7
Re:Inviare stringhe infrarosso...ok..ma di continuo? come?
« Risposta #10 il: 23 Ottobre 2014, 09:25:38 CEST »
0
Questo pagina l avevo già vista ma non ho capito se ogni button deve avere un motion event..

Mi spiego meglio..
Ok ho capito che l onTouchEvent controlla se lo schermo viene toccato quindi io dovrei dire poi per ogni button se corrisponde al button power per esempio allora invia la stringa power giusto?
« Ultima modifica: 23 Ottobre 2014, 09:32:30 CEST da smartgatto »

Offline eagledeveloper

  • Translate Team
  • Utente senior
  • ****
  • Post: 516
  • Respect: +37
    • Google+
    • 347516210
    • dark_pinz
    • @WandDStudios
    • Mostra profilo
    • W&D Studios
  • Dispositivo Android:
    HTC One X e HTC One
  • Play Store ID:
    W%26D+Studios
  • Sistema operativo:
    Ubuntu / Windows 7
Re:Inviare stringhe infrarosso...ok..ma di continuo? come?
« Risposta #11 il: 23 Ottobre 2014, 09:31:11 CEST »
0
Dipende cosa ti serve, magari ti va bene l'onClick o l'onLongClick su certi bottoni. Mentre dove ti serve sapere se è stato toccato o meno usi l'onTouch e gestisci l'evento.
I numeri contano molto di più del seme.

Offline smartgatto

  • Utente junior
  • **
  • Post: 96
  • Respect: +3
    • Mostra profilo
  • Dispositivo Android:
    Galaxy S5
  • Sistema operativo:
    Windows 7
Re:Inviare stringhe infrarosso...ok..ma di continuo? come?
« Risposta #12 il: 24 Ottobre 2014, 10:39:05 CEST »
0
Niente da fare...
allora ho modificato la mia app come mi hai suggerito tu..
(per fare solo delle prove ho messo solo due semplici button)
ora, usando il motionEvent.Action_Down se premo e mantengo premuto il button1 o 2 mi invia il codice infrarosso una volta sola e basta non "a ciclo continuo" finchè non mollo il button..
dove sbaglio secondo te?
grazie!

Codice: [Seleziona]
package com.example.marco.duetastiprova;

import android.app.Activity;
import android.hardware.ConsumerIrManager;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;



public class MyActivity extends Activity implements View.OnTouchListener {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
        Button button1 = (Button) findViewById(R.id.button1);
        Button button2 = (Button) findViewById(R.id.button2);

        button1.setOnTouchListener(this);
        button2.setOnTouchListener(this);

    }




    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_DOWN) {
            if (v.getId() == R.id.button1) {
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                        19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 19, 23, 19, 23,
                        19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23,
                        62, 23, 62, 23, 2500};
                ConsumerIrManager mCIR;
                mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);
                mCIR.transmit(38000, pattern);

            } else if (v.getId() == R.id.button2) {

                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                        19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23,
                        19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23,
                        62, 23, 62, 23, 2500};
                ConsumerIrManager mCIR;
                mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);
                mCIR.transmit(38000, pattern);
                }
        }

        return false;
    }
}


Offline smartgatto

  • Utente junior
  • **
  • Post: 96
  • Respect: +3
    • Mostra profilo
  • Dispositivo Android:
    Galaxy S5
  • Sistema operativo:
    Windows 7
Re:Inviare stringhe infrarosso...ok..ma di continuo? come?
« Risposta #13 il: 28 Ottobre 2014, 19:53:05 CET »
0
Boh..
ho rimodificato il listato...
ora sono tutti botton clickabili (onClick) tranne quello che effettivamente mi serve, ovvero l'UP.
Così funziona tutto, tranne il solito problema: se premo UP mi invia il segnale a tratti, per farlo andare come dico io devo premere il pulsante UP e muovere il dito (allora si che va spedito) altrimenti no.
E' quasi come se "ascoltasse" i micromovimenti del mio dito e li interpretasse come un ACTION_UP..



Codice: [Seleziona]
package com.example.cristina.IRda;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

import android.hardware.ConsumerIrManager;
import android.widget.ImageButton;

public class Irda extends Activity implements OnTouchListener {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_irda);
        ImageButton power = (ImageButton) findViewById(R.id.power);
        ImageButton home = (ImageButton) findViewById(R.id.home);
        ImageButton auto = (ImageButton) findViewById(R.id.auto);
        ImageButton max = (ImageButton) findViewById(R.id.max);
        ImageButton spot = (ImageButton) findViewById(R.id.spot);
        ImageButton up = (ImageButton) findViewById(R.id.up);
        ImageButton left = (ImageButton) findViewById(R.id.left);
        ImageButton right = (ImageButton) findViewById(R.id.right);
        ImageButton manual = (ImageButton) findViewById(R.id.manual);
        ImageButton pausa = (ImageButton) findViewById(R.id.pausa);

        up.setOnTouchListener(this);


        power.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                ConsumerIrManager mCIR;
                mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                        19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 19, 23, 19, 23,
                        19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23,
                        62, 23, 62, 23, 2500};
                mCIR.transmit(38000, pattern);
                // Perform action on click
            }
        });

        home.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                ConsumerIrManager mCIR;
                mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                        19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23,
                        19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23,
                        62, 23, 62, 23, 2500};
                mCIR.transmit(38000, pattern);
                // Perform action on click
            }
        });

        auto.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                ConsumerIrManager mCIR;
                mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                        19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 19, 23, 62, 23,
                        19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23,
                        62, 23, 62, 23, 2500};
                mCIR.transmit(38000, pattern);
                // Perform action on click
            }
        });

        manual.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                ConsumerIrManager mCIR;
                mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                        19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23,
                        19, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                        62, 23, 62, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
                mCIR.transmit(38000, pattern);
                // Perform action on click
            }
        });

        spot.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                ConsumerIrManager mCIR;
                mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                        19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 62, 23,
                        19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                        19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
                mCIR.transmit(38000, pattern);
                // Perform action on click
            }
        });

        max.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                ConsumerIrManager mCIR;
                mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                        19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 19, 23, 19, 23,
                        62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23,
                        62, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
                mCIR.transmit(38000, pattern);
                // Perform action on click
            }
        });

        left.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                ConsumerIrManager mCIR;
                mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                        19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 19, 23, 62, 23,
                        62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23,
                        19, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
                mCIR.transmit(38000, pattern);
                // Perform action on click
            }
        });

        right.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                ConsumerIrManager mCIR;
                mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19,
                        23, 19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 62,
                        23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                        19, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
                mCIR.transmit(38000, pattern);
                // Perform action on click
            }
        });

        pausa.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                ConsumerIrManager mCIR;
                mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);
                int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19,
                        23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 19, 23, 19, 23, 19,
                        23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 62, 23, 19, 23, 62, 23, 62, 23, 62,
                        23, 62, 23, 2500};
                mCIR.transmit(38000, pattern);
                // Perform action on click
            }
        });
    }


@Override
    public boolean onTouch(View v,MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if (v.getId() == R.id.up) {
                    ConsumerIrManager mCIR;
                    mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);

                    int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                            19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23,
                            62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                            62, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
                    mCIR.transmit(38000, pattern);

                }
                break;

            case MotionEvent.ACTION_MOVE:
                if (v.getId() == R.id.up) {
                    ConsumerIrManager mCIR;
                    mCIR = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);

                    int[] pattern = {173, 170, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                            19, 23, 62, 23, 62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 62, 23, 62, 23, 19, 23,
                            62, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23, 19, 23,
                            62, 23, 19, 23, 62, 23, 62, 23, 62, 23, 62, 23, 62, 23, 2500};
                    mCIR.transmit(38000, pattern);

                }         // finger moves on the screen
                break;

            case MotionEvent.ACTION_UP:
                // finger leaves the screen
                break;
        }

        // tell the system that we handled the event and no further processing is required
        return true;
    }


}



Offline eagledeveloper

  • Translate Team
  • Utente senior
  • ****
  • Post: 516
  • Respect: +37
    • Google+
    • 347516210
    • dark_pinz
    • @WandDStudios
    • Mostra profilo
    • W&D Studios
  • Dispositivo Android:
    HTC One X e HTC One
  • Play Store ID:
    W%26D+Studios
  • Sistema operativo:
    Ubuntu / Windows 7
Re:Inviare stringhe infrarosso...ok..ma di continuo? come?
« Risposta #14 il: 29 Ottobre 2014, 09:15:12 CET »
0
Se premi e non ti muovi c'é un solo evento ACTION_DOWN quindi ti invia il segnare una sola volta.
Se invece muovi il dito viene invocato più volte l'evento ACTION_MOVE.

Io farei qualcosa del genere: quando intercetti l'ACTION_DOWN mandi il segnale continuamente con un intervallo che stabilisci tu e nell'ACTION_UP fermi tutto.

Che ne pensi?
I numeri contano molto di più del seme.