'Call Method Continuously When button in pressed state
public class MainActivity extends AppCompatActivity {
public ConsumerIrManager consumerIrManager;
public Vibrator v;
public int frequency = 38000;
public int t = 0;
public Handler handler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
consumerIrManager = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);
v=(Vibrator) getSystemService(VIBRATOR_SERVICE);
}
i want to add a event on plus button when i pressed the button it works continuously till i am released button. for Example :- Tv Remote Button when i press volume + button the volume increase continuously till releasing.
public void onClick(View view) {
if(!consumerIrManager.hasIrEmitter()) {
Toast.makeText(getApplicationContext(), "IR Emitter Not Found in Your Device", Toast.LENGTH_LONG).show();
return;
}
switch (view.getId()) {
case R.id.power:
v.vibrate(VibrationEffect.createOneShot(200,VibrationEffect.DEFAULT_AMPLITUDE));
if (t==0) {
Log.i("Button pressed", "Power");
// textt.setText("0");
for(i=0;i<3;i++) {
consumerIrManager.transmit(frequency,btn.power);
}
t=1;
}
else{
Log.i("Button pressed", "Power1");
consumerIrManager.transmit(frequency,btn.power0);
t=0;
}
break;
case R.id.plus:
v.vibrate(VibrationEffect.createOneShot(200,VibrationEffect.DEFAULT_AMPLITUDE));
if (t==0) {
consumerIrManager.transmit(frequency, btn.plus);
Log.i("Button pressed", "Plus");
t=1;
}
else{
consumerIrManager.transmit(frequency, btn.plus0);
strong text Log.i("Button pressed", "Plus1");
t=0;
}
break;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
