Advertisement
kernel_memory_dump

MyOnKeyListener-Leon

May 9th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.09 KB | None | 0 0
  1. package com.comedia.use;
  2.  
  3.  
  4.  
  5. import android.dtv.service.Service;
  6.  
  7. import android.dtv.service.ServiceInfo;
  8.  
  9. import android.os.RemoteException;
  10.  
  11. import android.util.Log;
  12.  
  13. import android.view.KeyEvent;
  14.  
  15. import android.view.View;
  16.  
  17. import android.view.View.OnKeyListener;
  18.  
  19. import android.widget.Toast;
  20.  
  21.  
  22.  
  23. public class MyOnKeyListener implements OnKeyListener {
  24.  
  25.  
  26.  
  27.     private ServiceInfo currentServiceInfo;
  28.  
  29.     private final String LOG_TAG = "ComediaTestActivity";
  30.  
  31.  
  32.  
  33.     // If your signal is SATTELITE use SIGNAL_TYPE.SATTELITE instead of
  34.  
  35.     // SIGNAL_TYPE.TERRESTRIAL
  36.  
  37. //  SIGNAL_TYPE signalType = SIGNAL_TYPE.TERRESTRIAL;
  38.  
  39.  
  40.  
  41.     private Service currentService;
  42.  
  43.  
  44.  
  45.     public boolean onKey(View v, int keyCode, KeyEvent event) {
  46.  
  47.         Log.e("LOG_TAG", "COMEDIA TEST KEY CODE: " + Integer.toString(keyCode));
  48.  
  49.         if (event.getAction() == KeyEvent.ACTION_DOWN)
  50.  
  51.         {
  52.  
  53.            
  54.  
  55.             if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
  56.  
  57.                 try {
  58.  
  59.                     switch (v.getId()) {
  60.  
  61.  
  62.  
  63.                     // Init player
  64.  
  65.                     case R.id.buttonInitPlayer: {
  66.  
  67.                         Log.e(LOG_TAG, "Init player");
  68.  
  69.                         ComediaTestActivity.service.getVideoControl()
  70.  
  71.                                 .initPlayer(ComediaTestActivity.liveRouteID, 0);
  72.  
  73.                         break;
  74.  
  75.                     }
  76.  
  77.                     case R.id.videoView1: {
  78.  
  79.  
  80.  
  81.                         //ComediaTestActivity.dialogOptions.show();
  82.  
  83.                         break;
  84.  
  85.                     }
  86.  
  87.  
  88.  
  89.                     // Get channel list
  90.  
  91.                     case R.id.buttonListOfChannels: {
  92.  
  93.                         final int numberOfServices = ComediaTestActivity.service
  94.  
  95.                                 .getServiceLists().getList(0)
  96.  
  97.                                 .getServiceListCount();
  98.  
  99.  
  100.  
  101.                         Thread thread = new Thread(new Runnable() {
  102.  
  103.  
  104.  
  105.                             public void run() {
  106.  
  107.                                 for (int i = 0; i < numberOfServices; i++) {
  108.  
  109.  
  110.  
  111.                                     try {
  112.  
  113.  
  114.  
  115.                                         Log.e(LOG_TAG,
  116.  
  117.                                                 i
  118.  
  119.                                                         + 1
  120.  
  121.                                                         + "."
  122.  
  123.                                                         + ComediaTestActivity.service
  124.  
  125.                                                                 .getServiceLists()
  126.  
  127.                                                                 .getList(0)
  128.  
  129.                                                                 .getService(
  130.  
  131.                                                                         ComediaTestActivity.liveRouteID,
  132.  
  133.                                                                         i)
  134.  
  135.                                                                 .getName());
  136.  
  137.                                     } catch (RemoteException e) {
  138.  
  139.                                         e.printStackTrace();
  140.  
  141.                                     }
  142.  
  143.                                 }
  144.  
  145.                             }
  146.  
  147.                         });
  148.  
  149.                         thread.start();
  150.  
  151.                         break;
  152.  
  153.                     }
  154.  
  155.  
  156.  
  157.                     // Change channel
  158.  
  159.                     case R.id.buttonChangeChannel: {
  160.  
  161.                         Log.e("LOG_TAG", "changing channel");
  162.  
  163.  
  164.  
  165.                         try {
  166.  
  167.  
  168.  
  169.                             // Get channel number from edit text
  170.  
  171.                             int channelNumber = Integer
  172.  
  173.                                     .parseInt(ComediaTestActivity.edittextChannelNumber
  174.  
  175.                                             .getEditableText().toString());
  176.  
  177.  
  178.  
  179.                             Log.e(LOG_TAG + " channelNumber:", ""
  180.  
  181.                                     + channelNumber);
  182.  
  183.                             ComediaTestActivity.service
  184.  
  185.                                     .getServiceLists()
  186.  
  187.                                     .getList(0)
  188.  
  189.                                     .setCurrentServiceByIndex(
  190.  
  191.                                             ComediaTestActivity.liveRouteID,
  192.  
  193.                                             channelNumber - 1);
  194.  
  195.  
  196.  
  197.                         } catch (Exception e) {
  198.  
  199.                             e.printStackTrace();
  200.  
  201.                         }
  202.  
  203.                         ComediaTestActivity.edittextChannelNumber.setText("");
  204.  
  205.                         break;
  206.  
  207.                     }
  208.  
  209.  
  210.  
  211.                     // Channel up
  212.  
  213.                     case R.id.buttonNext: {
  214.  
  215.                         long currentServiceIndex = ComediaTestActivity.service
  216.  
  217.                                 .getServiceLists()
  218.  
  219.                                 .getList(0)
  220.  
  221.                                 .getCurrentServiceIndex(
  222.  
  223.                                         ComediaTestActivity.liveRouteID);
  224.  
  225.  
  226.  
  227.                         final int numberOfServices = ComediaTestActivity.service
  228.  
  229.                                 .getServiceLists().getList(0)
  230.  
  231.                                 .getServiceListCount();
  232.  
  233.  
  234.  
  235.                         ComediaTestActivity.service
  236.  
  237.                                 .getServiceLists()
  238.  
  239.                                 .getList(0)
  240.  
  241.                                 .setCurrentServiceByIndex(
  242.  
  243.                                         ComediaTestActivity.liveRouteID,
  244.  
  245.                                         ((int) currentServiceIndex + 1)
  246.  
  247.                                                 % numberOfServices);
  248.  
  249.                         break;
  250.  
  251.                     }
  252.  
  253.  
  254.  
  255.                     // Channel down
  256.  
  257.                     case R.id.buttonPrevious: {
  258.  
  259.                         long currentServiceIndex = ComediaTestActivity.service
  260.  
  261.                                 .getServiceLists()
  262.  
  263.                                 .getList(0)
  264.  
  265.                                 .getCurrentServiceIndex(
  266.  
  267.                                         ComediaTestActivity.liveRouteID);
  268.  
  269.  
  270.  
  271.                         final int numberOfServices = ComediaTestActivity.service
  272.  
  273.                                 .getServiceLists().getList(0)
  274.  
  275.                                 .getServiceListCount();
  276.  
  277.  
  278.  
  279.                         if (currentServiceIndex == 0)
  280.  
  281.                             currentServiceIndex = numberOfServices;
  282.  
  283.  
  284.  
  285.                         ComediaTestActivity.service
  286.  
  287.                                 .getServiceLists()
  288.  
  289.                                 .getList(0)
  290.  
  291.                                 .setCurrentServiceByIndex(
  292.  
  293.                                         ComediaTestActivity.liveRouteID,
  294.  
  295.                                         (int) currentServiceIndex - 1);
  296.  
  297.                         break;
  298.  
  299.                     }
  300.  
  301.  
  302.  
  303.                     // Scan
  304.  
  305.                     case R.id.buttonScan: {
  306.  
  307.                         ComediaTestActivity.service.getScanControl().scanAll(
  308.  
  309.                                 ComediaTestActivity.installRouteID);
  310.  
  311.  
  312.  
  313.                         break;
  314.  
  315.                     }
  316.  
  317.  
  318.  
  319.                     // Abort scan
  320.  
  321.                     case R.id.buttonAbort: {
  322.  
  323.                         ComediaTestActivity.service.getScanControl().abortScan(
  324.  
  325.                                 ComediaTestActivity.installRouteID);
  326.  
  327.                         break;
  328.  
  329.                     }
  330.  
  331.  
  332.  
  333.                     // Channel information
  334.  
  335.                     case R.id.buttonChannelInformation: {
  336.  
  337.  
  338.  
  339.                         currentService = null;
  340.  
  341.                         long currentServiceIndex = ComediaTestActivity.service
  342.  
  343.                                 .getServiceLists()
  344.  
  345.                                 .getList(0)
  346.  
  347.                                 .getCurrentServiceIndex(
  348.  
  349.                                         ComediaTestActivity.liveRouteID);
  350.  
  351.                         if (ComediaTestActivity.service != null) {
  352.  
  353.                             currentService = ComediaTestActivity.service
  354.  
  355.                                     .getServiceLists()
  356.  
  357.                                     .getList(0)
  358.  
  359.                                     .getService(
  360.  
  361.                                             ComediaTestActivity.liveRouteID,
  362.  
  363.                                             (int) currentServiceIndex);
  364.  
  365.                         }
  366.  
  367.                         if (ComediaTestActivity.service != null) {
  368.  
  369.                             currentServiceInfo = ComediaTestActivity.service
  370.  
  371.                                     .getServiceLists().getList(0)
  372.  
  373.                                     .getServiceInfo((int) currentServiceIndex);
  374.  
  375.                         }
  376.  
  377.                         Log.e(LOG_TAG + " Channel index:",
  378.  
  379.                                 "" + (currentService.getIndex() + 1));
  380.  
  381.  
  382.  
  383.                         String[] nowStartTime = new String[2];
  384.  
  385.                         nowStartTime = currentServiceInfo.getNow()
  386.  
  387.                                 .getStartTime().split(" ");
  388.  
  389.  
  390.  
  391.                         Log.e(LOG_TAG + " Now event: start time:",
  392.  
  393.                                 nowStartTime[0]);
  394.  
  395.  
  396.  
  397.                         nowStartTime = currentServiceInfo.getNext()
  398.  
  399.                                 .getStartTime().split(" ");
  400.  
  401.  
  402.  
  403.                         Log.e(LOG_TAG + " Next event: stop time:",
  404.  
  405.                                 nowStartTime[0]);
  406.  
  407.  
  408.  
  409.                         // if()
  410.  
  411.                         int audioCount = currentService
  412.  
  413.                                 .getComponentCountAudio();
  414.  
  415.                         int videoCount = currentService
  416.  
  417.                                 .getComponentCountVideo();
  418.  
  419.                         int subtitleCount = currentService
  420.  
  421.                                 .getComponentCountSubtitle();
  422.  
  423.                         int txtCount = currentService
  424.  
  425.                                 .getComponentCountTeletext();
  426.  
  427.                         Log.e("Components", "audio:" + audioCount);
  428.  
  429.                         Log.e("Components", "video:" + videoCount);
  430.  
  431.                         Log.e("Components", "subtitle:" + subtitleCount);
  432.  
  433.                         Log.e("Components", "teletext:" + txtCount);
  434.  
  435.  
  436.  
  437.                         String[] output = currentService.getName().split(" ");
  438.  
  439.                         if (output.length > 2) {
  440.  
  441.                             Log.e("Channel name:", output[0] + " " + output[1]
  442.  
  443.                                     + " ...");
  444.  
  445.                         } else {
  446.  
  447.                             Log.e("Channel name:", currentService.getName());
  448.  
  449.                         }
  450.  
  451.  
  452.  
  453.                         Log.e("Now event - name:", currentServiceInfo.getNow()
  454.  
  455.                                 .getName());
  456.  
  457.                         Log.e("Next event - name:", currentServiceInfo
  458.  
  459.                                 .getNext().getName());
  460.  
  461.                         break;
  462.  
  463.                     }
  464.  
  465.  
  466.  
  467.                     }
  468.  
  469.                 } catch (Exception e) {
  470.  
  471.                 }
  472.  
  473.                 return true;
  474.  
  475.             }else if(keyCode == 134)
  476.  
  477.             {
  478.  
  479.                 Log.e("LOG_TAG", "CHANNEL UP");
  480.  
  481.                 try {
  482.  
  483.                     long currentServiceIndex = ComediaTestActivity.service
  484.  
  485.                             .getServiceLists()
  486.  
  487.                             .getList(0)
  488.  
  489.                             .getCurrentServiceIndex(
  490.  
  491.                                     ComediaTestActivity.liveRouteID);
  492.  
  493.    
  494.  
  495.                     final int numberOfServices = ComediaTestActivity.service
  496.  
  497.                             .getServiceLists().getList(0)
  498.  
  499.                             .getServiceListCount();
  500.  
  501.    
  502.  
  503.                     ComediaTestActivity.changeChannel(((int) currentServiceIndex + 1)
  504.  
  505.                                             % numberOfServices);
  506.  
  507.                 } catch (Exception e) {
  508.  
  509.                     e.printStackTrace();
  510.  
  511.                 }
  512.  
  513.                 return true;
  514.  
  515.             }else if(keyCode == 133)
  516.  
  517.             {
  518.  
  519.                 Log.e("LOG_TAG", "CHANNEL DOWN");
  520.  
  521.                 try{
  522.  
  523.                     long currentServiceIndex = ComediaTestActivity.service
  524.  
  525.                             .getServiceLists()
  526.  
  527.                             .getList(0)
  528.  
  529.                             .getCurrentServiceIndex(
  530.  
  531.                                     ComediaTestActivity.liveRouteID);
  532.  
  533.    
  534.  
  535.                     final int numberOfServices = ComediaTestActivity.service
  536.  
  537.                             .getServiceLists().getList(0)
  538.  
  539.                             .getServiceListCount();
  540.  
  541.    
  542.  
  543.                     if (currentServiceIndex == 0)
  544.  
  545.                         currentServiceIndex = numberOfServices;
  546.  
  547.    
  548.  
  549.                     ComediaTestActivity.changeChannel((int)(currentServiceIndex - 1));
  550.  
  551.                 } catch (Exception e) {
  552.  
  553.                     e.printStackTrace();
  554.  
  555.                 }
  556.  
  557.                 return true;
  558.  
  559.             }else if(keyCode == KeyEvent.KEYCODE_VOLUME_UP)
  560.  
  561.             {
  562.  
  563.                 Log.e("LOG_TAG", "VOLUME UP");
  564.  
  565.                 try {
  566.  
  567.                     double currentVolume = ComediaTestActivity.service.getAudioControl().getCurrentVolume(ComediaTestActivity.liveRouteID);
  568.  
  569.                     double nextVolume = currentVolume+1;
  570.  
  571.                     if(nextVolume>100)
  572.  
  573.                     {
  574.  
  575.                         nextVolume = 100;
  576.  
  577.                     }
  578.  
  579.                     if(!ComediaTestActivity.service.getAudioControl().
  580.  
  581.                             setCurrentVolume(ComediaTestActivity.liveRouteID, nextVolume))
  582.  
  583.                     {
  584.  
  585.                         Log.e("LOG_TAG", "Error setting volume");
  586.  
  587.                     }
  588.  
  589.                     ComediaTestActivity.setVolume((int)nextVolume);
  590.  
  591.                 } catch (RemoteException e) {
  592.  
  593.                     // TODO Auto-generated catch block
  594.  
  595.                     e.printStackTrace();
  596.  
  597.                 }
  598.  
  599.                 return true;
  600.  
  601.             }else if(keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
  602.  
  603.             {
  604.  
  605.                 Log.e("LOG_TAG", "VOLUME DOWN");
  606.  
  607.                 try {
  608.  
  609.                     double currentVolume = ComediaTestActivity.service.getAudioControl().getCurrentVolume(ComediaTestActivity.liveRouteID);
  610.  
  611.                     double nextVolume = currentVolume-1;
  612.  
  613.                     if(nextVolume<0)
  614.  
  615.                     {
  616.  
  617.                         nextVolume = 0;
  618.  
  619.                     }
  620.  
  621.                     if(!ComediaTestActivity.service.getAudioControl().setCurrentVolume(ComediaTestActivity.liveRouteID, nextVolume))
  622.  
  623.                     {
  624.  
  625.                         Log.e("LOG_TAG", "Error setting volume");
  626.  
  627.                     }
  628.  
  629.                     ComediaTestActivity.setVolume((int)nextVolume);
  630.  
  631.                 } catch (RemoteException e) {
  632.  
  633.                     // TODO Auto-generated catch block
  634.  
  635.                     e.printStackTrace();
  636.  
  637.                 }
  638.  
  639.                 return true;
  640.  
  641.             }else if(keyCode == KeyEvent.KEYCODE_INFO)
  642.  
  643.             {
  644.  
  645.                 Log.e("LOG_TAG", "CHANNEL_INFO");
  646.  
  647.                 ComediaTestActivity.displayChanellInfo(false);
  648.  
  649.                 return true;
  650.  
  651.             }else if(keyCode == KeyEvent.KEYCODE_MENU)
  652.  
  653.             {
  654.  
  655.                 ComediaTestActivity.channelList.show();
  656.  
  657.             }else if (keyCode == 91)
  658.  
  659.             {
  660.  
  661.                 try {
  662.  
  663.                     if (ComediaTestActivity.service.getAudioControl().isMute(ComediaTestActivity.liveRouteID))
  664.  
  665.                     {
  666.  
  667.                         ComediaTestActivity.service.getAudioControl().muteAudio(ComediaTestActivity.liveRouteID, false);
  668.  
  669.                         double currentVolume = ComediaTestActivity.service.getAudioControl().getCurrentVolume(ComediaTestActivity.liveRouteID);
  670.  
  671.                         ComediaTestActivity.setVolume((int) currentVolume);
  672.  
  673.                     }
  674.  
  675.                     else
  676.  
  677.                     {
  678.  
  679.                         ComediaTestActivity.service.getAudioControl().muteAudio(ComediaTestActivity.liveRouteID, true);
  680.  
  681.                         ComediaTestActivity.setVolume(0);
  682.  
  683.                     }
  684.  
  685.                 } catch (RemoteException e) {
  686.  
  687.                     // TODO Auto-generated catch block
  688.  
  689.                     e.printStackTrace();
  690.  
  691.                 }
  692.  
  693.             }else
  694.  
  695.             {
  696.  
  697.                 Log.e("LOG_TAG", "\n\nUNKNOWN KEYCODE " + keyCode + "\n\n");
  698.  
  699.             }
  700.  
  701.         }
  702.  
  703.         return false;
  704.  
  705.     }
  706.  
  707. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement