Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.comedia.use;
- import android.dtv.service.Service;
- import android.dtv.service.ServiceInfo;
- import android.os.RemoteException;
- import android.util.Log;
- import android.view.KeyEvent;
- import android.view.View;
- import android.view.View.OnKeyListener;
- import android.widget.Toast;
- public class MyOnKeyListener implements OnKeyListener {
- private ServiceInfo currentServiceInfo;
- private final String LOG_TAG = "ComediaTestActivity";
- // If your signal is SATTELITE use SIGNAL_TYPE.SATTELITE instead of
- // SIGNAL_TYPE.TERRESTRIAL
- // SIGNAL_TYPE signalType = SIGNAL_TYPE.TERRESTRIAL;
- private Service currentService;
- public boolean onKey(View v, int keyCode, KeyEvent event) {
- Log.e("LOG_TAG", "COMEDIA TEST KEY CODE: " + Integer.toString(keyCode));
- if (event.getAction() == KeyEvent.ACTION_DOWN)
- {
- if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
- try {
- switch (v.getId()) {
- // Init player
- case R.id.buttonInitPlayer: {
- Log.e(LOG_TAG, "Init player");
- ComediaTestActivity.service.getVideoControl()
- .initPlayer(ComediaTestActivity.liveRouteID, 0);
- break;
- }
- case R.id.videoView1: {
- //ComediaTestActivity.dialogOptions.show();
- break;
- }
- // Get channel list
- case R.id.buttonListOfChannels: {
- final int numberOfServices = ComediaTestActivity.service
- .getServiceLists().getList(0)
- .getServiceListCount();
- Thread thread = new Thread(new Runnable() {
- public void run() {
- for (int i = 0; i < numberOfServices; i++) {
- try {
- Log.e(LOG_TAG,
- i
- + 1
- + "."
- + ComediaTestActivity.service
- .getServiceLists()
- .getList(0)
- .getService(
- ComediaTestActivity.liveRouteID,
- i)
- .getName());
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
- }
- });
- thread.start();
- break;
- }
- // Change channel
- case R.id.buttonChangeChannel: {
- Log.e("LOG_TAG", "changing channel");
- try {
- // Get channel number from edit text
- int channelNumber = Integer
- .parseInt(ComediaTestActivity.edittextChannelNumber
- .getEditableText().toString());
- Log.e(LOG_TAG + " channelNumber:", ""
- + channelNumber);
- ComediaTestActivity.service
- .getServiceLists()
- .getList(0)
- .setCurrentServiceByIndex(
- ComediaTestActivity.liveRouteID,
- channelNumber - 1);
- } catch (Exception e) {
- e.printStackTrace();
- }
- ComediaTestActivity.edittextChannelNumber.setText("");
- break;
- }
- // Channel up
- case R.id.buttonNext: {
- long currentServiceIndex = ComediaTestActivity.service
- .getServiceLists()
- .getList(0)
- .getCurrentServiceIndex(
- ComediaTestActivity.liveRouteID);
- final int numberOfServices = ComediaTestActivity.service
- .getServiceLists().getList(0)
- .getServiceListCount();
- ComediaTestActivity.service
- .getServiceLists()
- .getList(0)
- .setCurrentServiceByIndex(
- ComediaTestActivity.liveRouteID,
- ((int) currentServiceIndex + 1)
- % numberOfServices);
- break;
- }
- // Channel down
- case R.id.buttonPrevious: {
- long currentServiceIndex = ComediaTestActivity.service
- .getServiceLists()
- .getList(0)
- .getCurrentServiceIndex(
- ComediaTestActivity.liveRouteID);
- final int numberOfServices = ComediaTestActivity.service
- .getServiceLists().getList(0)
- .getServiceListCount();
- if (currentServiceIndex == 0)
- currentServiceIndex = numberOfServices;
- ComediaTestActivity.service
- .getServiceLists()
- .getList(0)
- .setCurrentServiceByIndex(
- ComediaTestActivity.liveRouteID,
- (int) currentServiceIndex - 1);
- break;
- }
- // Scan
- case R.id.buttonScan: {
- ComediaTestActivity.service.getScanControl().scanAll(
- ComediaTestActivity.installRouteID);
- break;
- }
- // Abort scan
- case R.id.buttonAbort: {
- ComediaTestActivity.service.getScanControl().abortScan(
- ComediaTestActivity.installRouteID);
- break;
- }
- // Channel information
- case R.id.buttonChannelInformation: {
- currentService = null;
- long currentServiceIndex = ComediaTestActivity.service
- .getServiceLists()
- .getList(0)
- .getCurrentServiceIndex(
- ComediaTestActivity.liveRouteID);
- if (ComediaTestActivity.service != null) {
- currentService = ComediaTestActivity.service
- .getServiceLists()
- .getList(0)
- .getService(
- ComediaTestActivity.liveRouteID,
- (int) currentServiceIndex);
- }
- if (ComediaTestActivity.service != null) {
- currentServiceInfo = ComediaTestActivity.service
- .getServiceLists().getList(0)
- .getServiceInfo((int) currentServiceIndex);
- }
- Log.e(LOG_TAG + " Channel index:",
- "" + (currentService.getIndex() + 1));
- String[] nowStartTime = new String[2];
- nowStartTime = currentServiceInfo.getNow()
- .getStartTime().split(" ");
- Log.e(LOG_TAG + " Now event: start time:",
- nowStartTime[0]);
- nowStartTime = currentServiceInfo.getNext()
- .getStartTime().split(" ");
- Log.e(LOG_TAG + " Next event: stop time:",
- nowStartTime[0]);
- // if()
- int audioCount = currentService
- .getComponentCountAudio();
- int videoCount = currentService
- .getComponentCountVideo();
- int subtitleCount = currentService
- .getComponentCountSubtitle();
- int txtCount = currentService
- .getComponentCountTeletext();
- Log.e("Components", "audio:" + audioCount);
- Log.e("Components", "video:" + videoCount);
- Log.e("Components", "subtitle:" + subtitleCount);
- Log.e("Components", "teletext:" + txtCount);
- String[] output = currentService.getName().split(" ");
- if (output.length > 2) {
- Log.e("Channel name:", output[0] + " " + output[1]
- + " ...");
- } else {
- Log.e("Channel name:", currentService.getName());
- }
- Log.e("Now event - name:", currentServiceInfo.getNow()
- .getName());
- Log.e("Next event - name:", currentServiceInfo
- .getNext().getName());
- break;
- }
- }
- } catch (Exception e) {
- }
- return true;
- }else if(keyCode == 134)
- {
- Log.e("LOG_TAG", "CHANNEL UP");
- try {
- long currentServiceIndex = ComediaTestActivity.service
- .getServiceLists()
- .getList(0)
- .getCurrentServiceIndex(
- ComediaTestActivity.liveRouteID);
- final int numberOfServices = ComediaTestActivity.service
- .getServiceLists().getList(0)
- .getServiceListCount();
- ComediaTestActivity.changeChannel(((int) currentServiceIndex + 1)
- % numberOfServices);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return true;
- }else if(keyCode == 133)
- {
- Log.e("LOG_TAG", "CHANNEL DOWN");
- try{
- long currentServiceIndex = ComediaTestActivity.service
- .getServiceLists()
- .getList(0)
- .getCurrentServiceIndex(
- ComediaTestActivity.liveRouteID);
- final int numberOfServices = ComediaTestActivity.service
- .getServiceLists().getList(0)
- .getServiceListCount();
- if (currentServiceIndex == 0)
- currentServiceIndex = numberOfServices;
- ComediaTestActivity.changeChannel((int)(currentServiceIndex - 1));
- } catch (Exception e) {
- e.printStackTrace();
- }
- return true;
- }else if(keyCode == KeyEvent.KEYCODE_VOLUME_UP)
- {
- Log.e("LOG_TAG", "VOLUME UP");
- try {
- double currentVolume = ComediaTestActivity.service.getAudioControl().getCurrentVolume(ComediaTestActivity.liveRouteID);
- double nextVolume = currentVolume+1;
- if(nextVolume>100)
- {
- nextVolume = 100;
- }
- if(!ComediaTestActivity.service.getAudioControl().
- setCurrentVolume(ComediaTestActivity.liveRouteID, nextVolume))
- {
- Log.e("LOG_TAG", "Error setting volume");
- }
- ComediaTestActivity.setVolume((int)nextVolume);
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return true;
- }else if(keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
- {
- Log.e("LOG_TAG", "VOLUME DOWN");
- try {
- double currentVolume = ComediaTestActivity.service.getAudioControl().getCurrentVolume(ComediaTestActivity.liveRouteID);
- double nextVolume = currentVolume-1;
- if(nextVolume<0)
- {
- nextVolume = 0;
- }
- if(!ComediaTestActivity.service.getAudioControl().setCurrentVolume(ComediaTestActivity.liveRouteID, nextVolume))
- {
- Log.e("LOG_TAG", "Error setting volume");
- }
- ComediaTestActivity.setVolume((int)nextVolume);
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return true;
- }else if(keyCode == KeyEvent.KEYCODE_INFO)
- {
- Log.e("LOG_TAG", "CHANNEL_INFO");
- ComediaTestActivity.displayChanellInfo(false);
- return true;
- }else if(keyCode == KeyEvent.KEYCODE_MENU)
- {
- ComediaTestActivity.channelList.show();
- }else if (keyCode == 91)
- {
- try {
- if (ComediaTestActivity.service.getAudioControl().isMute(ComediaTestActivity.liveRouteID))
- {
- ComediaTestActivity.service.getAudioControl().muteAudio(ComediaTestActivity.liveRouteID, false);
- double currentVolume = ComediaTestActivity.service.getAudioControl().getCurrentVolume(ComediaTestActivity.liveRouteID);
- ComediaTestActivity.setVolume((int) currentVolume);
- }
- else
- {
- ComediaTestActivity.service.getAudioControl().muteAudio(ComediaTestActivity.liveRouteID, true);
- ComediaTestActivity.setVolume(0);
- }
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }else
- {
- Log.e("LOG_TAG", "\n\nUNKNOWN KEYCODE " + keyCode + "\n\n");
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement