Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.comedia.use;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Timer;
- import java.util.TimerTask;
- import android.app.Activity;
- import android.app.Dialog;
- import android.content.ComponentName;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.DialogInterface.OnKeyListener;
- import android.content.Intent;
- import android.content.ServiceConnection;
- import android.dtv.basic_types.LongHolder;
- import android.dtv.route.DecoderDescriptor;
- import android.dtv.route.DemuxDescriptor;
- import android.dtv.route.FrontendDescriptor;
- import android.dtv.route.MassStorageDescriptor;
- import android.dtv.route.OutputDescriptor;
- import android.dtv.route.RouteErrorCode;
- import android.dtv.service.SERVICE_TYPE;
- import android.dtv.service.Service;
- import android.dtv.service.ServiceInfo;
- import android.dtv.service.ZappingEvent;
- import android.dtv.setup.Conversions;
- import android.dtv.setup.TimeFromStream;
- import android.media.AudioManager;
- import android.net.Uri;
- import android.os.Build;
- import android.os.Bundle;
- import android.os.DeadObjectException;
- import android.os.Handler;
- import android.os.IBinder;
- import android.os.IChannelsCallback;
- import android.os.IDTVManager;
- import android.os.IEventsCallback;
- import android.os.RemoteException;
- import android.util.Log;
- import android.view.KeyEvent;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.Window;
- import android.view.WindowManager;
- import android.view.animation.Animation;
- import android.view.animation.AnimationUtils;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.ListView;
- import android.widget.ProgressBar;
- import android.widget.SeekBar;
- import android.widget.TextView;
- import android.widget.Toast;
- import android.widget.VideoView;
- public class ComediaTestActivity extends Activity {
- private final String LOG_TAG = "ComediaTestActivity";
- private VideoView video;
- private Button btnInitPlayer;
- private Button btnListOfChannels;
- private Button btnChangeChannel;
- private Button btnNext;
- private Button btnPrevious;
- private Button btnScan;
- private Button btnAbortScan;
- private Button btnServiceInformation;
- public static EditText edittextChannelNumber;
- public static Dialog dialogOptions;
- private Intent remoteServiceIntent;
- private BinderServiceConnection conn;
- public static IDTVManager service = null;
- public static Activity activity;
- //Channel Info
- public static Dialog chanellInfo;
- public static Timer channelInforTimer;
- public static Timer channelInfoTimer;
- public static ProgressBar progressBar;
- public static ProgressBar progressBarGoogle, progressBarFace,
- progressBarWiki, progressBarYou;
- public static int mProgressRegister = 0;
- public static int durationRegister = 0;
- public static Animation animShow;
- public static Animation animHide;
- public static Animation menuShow;
- public static Animation menuHide;
- public static LinearLayout popup;
- public static LinearLayout popdown;
- public static Timer popupTimer;
- public static int mProgressStatus = 0;
- public static Integer duration = 0;
- public static Handler mHandler1 = new Handler();
- public static Handler mHandler2 = new Handler();
- public static Handler channelInfoHandler = new Handler();
- public static Handler progressBarHandler = new Handler();
- public static TextView textview_start;
- private static TextView textview_stop;
- public static int broj = 0;
- public static Thread background;
- public static TextView textID, textImeKanala, textNow, textNext,
- textChannelTime, textTeletext, textSubtitle, textAudio, textVideo;
- public static int screenWidth, screenHeight;
- public static int[] location;
- //Channel List
- public static Dialog channelList;
- public static int listNumber;
- public static ListView list;
- TextView naslov;
- public static List<Object> listItems = new ArrayList<Object>();
- public static int lengthCurrentList;
- ListItemsAdapter adapter = null;
- //Volume
- public static Dialog volumeDialog;
- public static SeekBar volumeBar;
- public static Timer volumeTimer = new Timer();
- public static TimerTask volumeTimerTask;
- protected static Handler callbackHandler = new Handler();
- public static long liveRouteID = 0; // route for live TV
- public static long installRouteID = 0; // route for installing services
- public static long recRouteID = 0; // route for using pvr
- public static long playRouteID = 0; // route for using pvr
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
- getWindow().clearFlags(
- WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
- setContentView(R.layout.main);
- initValues();
- initKeyListeners();
- initVideo();
- initChannelList();
- initChannelInfo();
- initVolume();
- connectWithServer();
- }
- @Override
- protected void onPause() {
- super.onPause();
- try {
- activity.unbindService(conn);
- } catch (Exception e) {
- Log.e("unbind on pause", "exception");
- }
- if (service != null) {
- try {
- service.getVideoControl().deinitPlayer(liveRouteID);
- } catch (Exception e) {
- }
- } else {
- Log.e("Java", "deinitPlayer: service is null");
- }
- android.os.Process.killProcess(android.os.Process.myPid());
- }
- private void connectWithServer() {
- remoteServiceIntent = new Intent("com.rtrk.REMOTE_SERVICE_COMEDIA");
- conn = new BinderServiceConnection();
- bindService(remoteServiceIntent, conn, Context.BIND_IMPORTANT);
- }
- class BinderServiceConnection implements ServiceConnection {
- public static final String TAG = "BinderServiceConnection";
- public void onServiceConnected(ComponentName className,
- IBinder boundService) {
- service = IDTVManager.Stub.asInterface((IBinder) boundService);
- try {
- initializeRouteIds();
- } catch (RemoteException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- Log.e(TAG, "onServiceConnected");
- if (service != null) {
- try {
- service.getSetupControl().setEventsCallback(
- eventsCallback.asBinder());
- service.getSetupControl().setChannelsCallback(liveRouteID,
- channelsCallback.asBinder());
- } catch (DeadObjectException ex) {
- Log.e(TAG, "DeadObjectException");
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- } else {
- Log.e("Java", "onServiceConnected: service is null");
- }
- try {
- service.getVideoControl().initPlayer(liveRouteID,1);
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- fillListChannel();
- }
- public void onServiceDisconnected(ComponentName className) {
- service = null;
- Log.d(TAG, "onServiceDisconnected");
- }
- };
- private IChannelsCallback.Stub channelsCallback = new IChannelsCallback.Stub() {
- @Override
- public void signalStrength(int arg0) throws RemoteException {
- // TODO Auto-generated method stub
- }
- @Override
- public void signalQuality(int arg0) throws RemoteException {
- // TODO Auto-generated method stub
- }
- @Override
- public void signalBer(int arg0) throws RemoteException {
- // TODO Auto-generated method stub
- }
- @Override
- public void selectingComponent(boolean arg0) throws RemoteException {
- // TODO Auto-generated method stub
- }
- @Override
- public void scanTunFrequency(int arg0) throws RemoteException {
- // TODO Auto-generated method stub
- }
- @Override
- public void scanProgressChanged(int arg0) throws RemoteException {
- Log.e(LOG_TAG, "scanProgressChanged:" + arg0);
- }
- @Override
- public void scanFinished() throws RemoteException {
- callbackHandler.post(new Runnable() {
- public void run() {
- Toast.makeText(getApplicationContext(), "scan finished",
- Toast.LENGTH_LONG).show();
- }
- });
- service.getVideoControl().initPlayer(liveRouteID, 0);
- }
- @Override
- public void mhegStarted(boolean arg0) throws RemoteException {
- // TODO Auto-generated method stub
- }
- @Override
- public void installServiceTVNumber(int arg0) throws RemoteException {
- // TODO Auto-generated method stub
- }
- @Override
- public void installServiceTVName(String arg0) throws RemoteException {
- Log.e(LOG_TAG, "Installed TV service:" + arg0);
- }
- @Override
- public void installServiceRADIONumber(int arg0) throws RemoteException {
- // TODO Auto-generated method stub
- }
- @Override
- public void installServiceRADIOName(String arg0) throws RemoteException {
- Log.e(LOG_TAG, "Installed radio service:" + arg0);
- }
- @Override
- public void antennaConnected(boolean arg0) throws RemoteException {
- // TODO Auto-generated method stub
- }
- @Override
- public void channelZapping(ZappingEvent arg0) throws RemoteException {
- callbackHandler.post(new Runnable() {
- public void run() {
- long index = 0;
- String scrambled = "";
- try {
- index = service.getServiceLists().getList(0)
- .getCurrentServiceIndex(liveRouteID);
- Service channel = service.getServiceLists().getList(0)
- .getService(liveRouteID, (int) index);
- if (channel.isScrambled()) {
- scrambled = "scrambled";
- } else {
- scrambled = "";
- }
- int indexDisplay = (int) index + 1;
- Toast.makeText(
- getApplicationContext(),
- indexDisplay + ". " + channel.getName() + " "
- + scrambled, Toast.LENGTH_LONG).show();
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- });
- }
- };
- private IEventsCallback.Stub eventsCallback = new IEventsCallback.Stub() {
- @Override
- public void nowNextChanged() throws RemoteException {
- Log.e(LOG_TAG, "Now/next changed");
- }
- @Override
- public void EpgEventsChanged() throws RemoteException {
- callbackHandler.post(new Runnable() {
- public void run() {
- Toast.makeText(getApplicationContext(),
- "Epg events changed", Toast.LENGTH_LONG).show();
- }
- });
- }
- };
- private void initValues() {
- activity = ComediaTestActivity.this;
- dialogOptions = new Dialog(this, R.style.SpecialDialog);
- dialogOptions.setContentView(R.layout.options_menu);
- video = (VideoView) findViewById(R.id.videoView1);
- btnInitPlayer = (Button) dialogOptions
- .findViewById(R.id.buttonInitPlayer);
- btnListOfChannels = (Button) dialogOptions
- .findViewById(R.id.buttonListOfChannels);
- edittextChannelNumber = (EditText) dialogOptions
- .findViewById(R.id.editTextChannelNumber);
- btnChangeChannel = (Button) dialogOptions
- .findViewById(R.id.buttonChangeChannel);
- btnPrevious = (Button) dialogOptions.findViewById(R.id.buttonPrevious);
- btnNext = (Button) dialogOptions.findViewById(R.id.buttonNext);
- btnScan = (Button) dialogOptions.findViewById(R.id.buttonScan);
- btnAbortScan = (Button) dialogOptions.findViewById(R.id.buttonAbort);
- btnServiceInformation = (Button) dialogOptions
- .findViewById(R.id.buttonChannelInformation);
- channelInfoTimer = new Timer();
- screenHeight = getWindowManager().getDefaultDisplay().getHeight();
- screenWidth = getWindowManager().getDefaultDisplay().getWidth();
- }
- private void initKeyListeners() {
- video.setOnKeyListener(new MyOnKeyListener());
- btnInitPlayer.setOnKeyListener(new MyOnKeyListener());
- btnListOfChannels.setOnKeyListener(new MyOnKeyListener());
- btnChangeChannel.setOnKeyListener(new MyOnKeyListener());
- btnAbortScan.setOnKeyListener(new MyOnKeyListener());
- btnPrevious.setOnKeyListener(new MyOnKeyListener());
- btnNext.setOnKeyListener(new MyOnKeyListener());
- btnScan.setOnKeyListener(new MyOnKeyListener());
- btnServiceInformation.setOnKeyListener(new MyOnKeyListener());
- }
- private void initVideo() {
- video.setVideoURI(Uri.parse("mrvl://"));
- video.start();
- video.requestFocus();
- }
- @Override
- public void onBackPressed() {
- super.onBackPressed();
- finish();
- }
- private void initializeRouteIds() throws RemoteException {
- FrontendDescriptor fDescriptor = new FrontendDescriptor();
- RouteErrorCode rError = null;
- rError = service.getRouteControl()
- .GetFrontendDescriptor(0, fDescriptor);
- if (rError != RouteErrorCode.ROUTE_ERRORCODE_NO_ERROR) {
- Log.e("TAG", "GetFrontendDescriptor error");
- return;
- }
- DemuxDescriptor dDescriptor = new DemuxDescriptor();
- rError = null;
- rError = service.getRouteControl().GetDemuxDescriptor(0, dDescriptor);
- if (rError != RouteErrorCode.ROUTE_ERRORCODE_NO_ERROR) {
- Log.e("TAG", "GetDemuxDescriptor error");
- return;
- }
- DecoderDescriptor dDecDescriptor = new DecoderDescriptor();
- rError = null;
- rError = service.getRouteControl().GetDecoderDescriptor(0,
- dDecDescriptor);
- if (rError != RouteErrorCode.ROUTE_ERRORCODE_NO_ERROR) {
- Log.e("TAG", "GetDecoderDescriptor error");
- return;
- }
- OutputDescriptor oDescriptor = new OutputDescriptor();
- rError = null;
- rError = service.getRouteControl().GetOutputDescriptor(0, oDescriptor);
- if (rError != RouteErrorCode.ROUTE_ERRORCODE_NO_ERROR) {
- Log.e("TAG", "GetOutputDescriptor error");
- return;
- }
- MassStorageDescriptor mDescriptor = new MassStorageDescriptor();
- rError = null;
- rError = service.getRouteControl().GetMassStorageDescriptor(0,
- mDescriptor);
- if (rError != RouteErrorCode.ROUTE_ERRORCODE_NO_ERROR) {
- Log.e("TAG", "GetMassStorageDescriptor error");
- // no pvr
- }
- LongHolder route = new LongHolder();
- rError = null;
- rError = service.getRouteControl()
- .GetLiveRoute(fDescriptor.getFrontendId(),
- dDescriptor.getDemuxId(),
- dDecDescriptor.getDecoderId(),
- oDescriptor.getOutputId(), route);
- if (rError != RouteErrorCode.ROUTE_ERRORCODE_NO_ERROR) {
- Log.e("TAG", "GetLiveRoute error");
- return;
- } else {
- liveRouteID = route.getLongValue();
- }
- rError = null;
- rError = service.getRouteControl().GetInstallRoute(
- fDescriptor.getFrontendId(), dDescriptor.getDemuxId(), route);
- if (rError != RouteErrorCode.ROUTE_ERRORCODE_NO_ERROR) {
- Log.e("TAG", "GetInstallRoute error");
- return;
- } else {
- installRouteID = route.getLongValue();
- }
- rError = null;
- rError = service.getRouteControl().GetRecordRoute(
- fDescriptor.getFrontendId(), dDescriptor.getDemuxId(),
- mDescriptor.getMassStorageId(), route);
- if (rError != RouteErrorCode.ROUTE_ERRORCODE_NO_ERROR) {
- Log.e("TAG", "GetRecordRoute error");
- // no pvr
- } else {
- recRouteID = route.getLongValue();
- }
- rError = null;
- rError = service.getRouteControl()
- .GetPlaybackRoute(mDescriptor.getMassStorageId(),
- dDescriptor.getDemuxId(),
- dDecDescriptor.getDecoderId(),
- oDescriptor.getOutputId(), route);
- if (rError != RouteErrorCode.ROUTE_ERRORCODE_NO_ERROR) {
- Log.e("TAG", "GetPlaybackRoute error");
- // no pvr
- } else {
- playRouteID = route.getLongValue();
- }
- }
- public static void initChannelInfo() {
- channelInforTimer = new Timer();
- progressBar = new ProgressBar(activity);
- chanellInfo = new Dialog(activity, com.comedia.use.R.style.SpecialDialog);
- chanellInfo.setContentView(com.comedia.use.R.layout.channel_info);
- chanellInfo.getWindow().getAttributes().width = screenWidth * 4 / 5;
- chanellInfo.getWindow().getAttributes().y = screenHeight / 2;
- progressBar = ((ProgressBar) chanellInfo
- .findViewById(com.comedia.use.R.id.progressBar1));
- textview_start = (TextView) chanellInfo
- .findViewById(com.comedia.use.R.id.textView_start);
- textview_stop = (TextView) chanellInfo
- .findViewById(com.comedia.use.R.id.textView_stop);
- popup = (LinearLayout) chanellInfo
- .findViewById(com.comedia.use.R.id.RelativeLayout1);
- popup.setVisibility(View.GONE);
- channelInforTimer = new Timer();
- popupTimer = new Timer();
- menuShow = AnimationUtils.loadAnimation(activity,
- com.comedia.use.R.anim.menu_show);
- menuHide = AnimationUtils.loadAnimation(activity,
- com.comedia.use.R.anim.menu_hide);
- animShow = AnimationUtils.loadAnimation(activity,
- com.comedia.use.R.anim.popup_show);
- animHide = AnimationUtils.loadAnimation(activity,
- com.comedia.use.R.anim.popup_hide);
- textID = (TextView) chanellInfo.findViewById(com.comedia.use.R.id.textView3);
- textImeKanala = (TextView) chanellInfo
- .findViewById(com.comedia.use.R.id.textView2);
- textNow = (TextView) chanellInfo.findViewById(com.comedia.use.R.id.textView6);
- textNext = (TextView) chanellInfo
- .findViewById(com.comedia.use.R.id.textView7);
- textChannelTime = (TextView) chanellInfo
- .findViewById(com.comedia.use.R.id.textViewChannelTime);
- textTeletext = (TextView) chanellInfo
- .findViewById(com.comedia.use.R.id.textViewTeletext);
- textSubtitle = (TextView) chanellInfo
- .findViewById(com.comedia.use.R.id.textViewSubtitle);
- textAudio = (TextView) chanellInfo
- .findViewById(com.comedia.use.R.id.textViewAudio);
- textVideo = (TextView) chanellInfo
- .findViewById(com.comedia.use.R.id.textViewVideo);
- }
- public static void displayChanellInfo(boolean wait) {
- ServiceInfo currentServiceInfo = null;
- if (wait) {
- try {
- Thread.sleep(4000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- try {
- Service currentService;
- if (service != null) {
- currentService = service
- .getServiceLists()
- .getList(Service.MAIN_LIST_INDEX)
- .getService(
- liveRouteID,
- (int) service.getServiceLists()
- .getList(Service.MAIN_LIST_INDEX)
- .getCurrentServiceIndex(liveRouteID));
- } else {
- currentService = new Service();
- Log.i("Java", "current service: service is null");
- }
- if (service != null) {
- currentServiceInfo = service
- .getServiceLists()
- .getList(Service.MAIN_LIST_INDEX)
- .getServiceInfo(
- (int) service.getServiceLists()
- .getList(Service.MAIN_LIST_INDEX)
- .getCurrentServiceIndex(liveRouteID));
- } else {
- currentServiceInfo = new ServiceInfo();
- Log.i("Java", "current service info: service is null");
- }
- textID.setText("" + (currentService.getIndex() + 1));
- String[] nowStartTime = new String[2];
- nowStartTime = currentServiceInfo.getNow().getStartTime()
- .split(" ");
- textview_start.setText(nowStartTime[0]);
- nowStartTime = currentServiceInfo.getNext().getStartTime()
- .split(" ");
- textview_stop.setText(nowStartTime[0]);
- int audioCount = currentService.getComponentCountAudio();
- int videoCount = currentService.getComponentCountVideo();
- int subtitleCount = currentService.getComponentCountSubtitle();
- int txtCount = currentService.getComponentCountTeletext();
- Log.i("Java", "audio:" + audioCount);
- Log.i("Java", "video:" + videoCount);
- Log.i("Java", "subtitle:" + subtitleCount);
- Log.i("Java", "teletext:" + txtCount);
- if (audioCount > 0) {
- textAudio.setTextColor(activity.getResources().getColor(
- com.comedia.use.R.color.transparent));
- } else {
- textAudio.setTextColor(activity.getResources().getColor(
- com.comedia.use.R.color.serviceComponentDisabled));
- }
- if (subtitleCount > 0) {
- textSubtitle.setTextColor(activity.getResources().getColor(
- com.comedia.use.R.color.transparent));
- } else {
- textSubtitle.setTextColor(activity.getResources().getColor(
- com.comedia.use.R.color.serviceComponentDisabled));
- }
- if (txtCount > 0) {
- textTeletext.setTextColor(activity.getResources().getColor(
- com.comedia.use.R.color.transparent));
- } else {
- textTeletext.setTextColor(activity.getResources().getColor(
- com.comedia.use.R.color.serviceComponentDisabled));
- }
- if (videoCount > 0) {
- textVideo.setTextColor(activity.getResources().getColor(
- com.comedia.use.R.color.transparent));
- } else
- textVideo.setTextColor(activity.getResources().getColor(
- com.comedia.use.R.color.serviceComponentDisabled));
- String[] output = currentService.getName().split(" ");
- if (output.length > 2) {
- textImeKanala.setText(output[0] + " " + output[1] + " ...");
- } else {
- textImeKanala.setText(currentService.getName());
- }
- textNow.setText(currentServiceInfo.getNow().getName());
- textNext.setText(currentServiceInfo.getNext().getName());
- } catch (Exception e) {
- e.printStackTrace();
- }
- String returnValue = new String();
- TimeFromStream time;
- if (service != null) {
- try {
- time = service.getSetupControl().getTimeDateFromStream();
- if (time == null) {
- returnValue = "00:00:00 00/00/0000";
- } else {
- returnValue = time.getHour() + ":" + time.getMin() + ":"
- + time.getSec() + " " + time.getDay() + "/"
- + time.getMonth() + "/" + time.getYear();
- }
- textChannelTime.setText(returnValue);
- } catch (Exception e) {
- // TODO: handle exception
- }
- } else {
- textChannelTime.setText("");
- Log.i("Java", "channel time: service is null");
- }
- final int channelInfoProgressValue = Conversions.getEventPassedPercent(
- currentServiceInfo.getNow().getStartTime(), currentServiceInfo
- .getNow().getEndTime(), returnValue);
- progressBarHandler.post(new Runnable() {
- @Override
- public void run() {
- // TODO Auto-generated method stub
- progressBar.setProgress(channelInfoProgressValue);
- }
- });
- channelInforTimer.cancel();
- popupTimer.cancel();
- /////////////////////POPUP
- chanellInfo.show();
- popup.setVisibility(View.VISIBLE);
- popup.startAnimation(animShow);
- Log.e("TAG", "\n\n\nsetVisibility startAnimation\n\n\n");
- channelInforTimer = new Timer();
- channelInforTimer.schedule(new TimerTask() {
- @Override
- public void run() {
- mHandler1.post(new Runnable() {
- @Override
- public void run() {
- popup.startAnimation(animHide);
- Timer timer = new Timer();
- timer.schedule(new TimerTask() {
- @Override
- public void run() {
- chanellInfo.cancel();
- }
- }, 1300);
- }
- });
- }
- }, 7000);
- }
- void initChannelList()
- {
- channelList = new Dialog(activity, com.comedia.use.R.style.SpecialDialog);
- channelList.requestWindowFeature(Window.FEATURE_NO_TITLE);
- channelList.getWindow().setFlags(
- WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
- WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
- channelList.setContentView(com.comedia.use.R.layout.chanell_list);
- channelList.setCancelable(true);
- channelList.getWindow().getAttributes().width = screenWidth;
- channelList.getWindow().getAttributes().y = screenHeight / 2;
- channelList.getWindow().getAttributes().height = screenHeight * 11 / 12;
- channelList.getWindow().getAttributes().x = -screenWidth / 2;
- listNumber = 0;
- naslov = (TextView) channelList
- .findViewById(com.comedia.use.R.id.SelektovanaOpcija);
- naslov.setText("All channels");
- }
- public void fillListChannel() {
- listItems = new ArrayList<Object>();
- switch (listNumber) {
- case 0: {
- try {
- lengthCurrentList = service.getServiceLists()
- .getList(Service.MAIN_LIST_INDEX).getServiceListCount();
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- break;
- }
- default:
- break;
- }
- try {
- for (int i = 0; i < lengthCurrentList; i++) {
- Object object = new Object();
- listItems.add(object);
- }
- list = (ListView) channelList.findViewById(com.comedia.use.R.id.list);
- list.getBackground().setAlpha(150);
- adapter = new ListItemsAdapter(listItems);
- list.setAdapter(adapter);
- list.setSelection(0);
- list.requestFocus();
- list.setOnItemClickListener(new OnListItemClickListener() {
- });
- } catch (Exception e) {
- Log.d("FillListChannel", "SOMETHING failed");
- }
- }
- public void initVolume() {
- volumeDialog = new Dialog(ComediaTestActivity.this,
- com.comedia.use.R.style.Volume_Dialog);
- volumeDialog.getWindow().getAttributes().y = screenHeight / 2;
- volumeDialog.setContentView(com.comedia.use.R.layout.seekbar);
- volumeDialog.setCancelable(true);
- volumeDialog.setOnKeyListener(new OnKeyListener() {
- @Override
- public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
- if(keyCode == KeyEvent.KEYCODE_VOLUME_UP)
- {
- Log.e("LOG_TAG", "VOLUME UP");
- try {
- double currentVolume = service.getAudioControl().getCurrentVolume(liveRouteID);
- double nextVolume = currentVolume+1;
- if(nextVolume>100)
- {
- nextVolume = 100;
- }
- if(!service.getAudioControl().
- setCurrentVolume(liveRouteID, nextVolume))
- {
- Log.e("LOG_TAG", "Error setting volume");
- }
- 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 = service.getAudioControl().getCurrentVolume(liveRouteID);
- double nextVolume = currentVolume-1;
- if(nextVolume<0)
- {
- nextVolume = 0;
- }
- if(!service.getAudioControl().setCurrentVolume(liveRouteID, nextVolume))
- {
- Log.e("LOG_TAG", "Error setting volume");
- }
- setVolume((int)nextVolume);
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return true;
- }
- return false;
- }
- });
- volumeBar = (SeekBar) volumeDialog
- .findViewById(com.comedia.use.R.id.seek_bar);
- volumeBar.setMax(100);
- volumeBar.setProgress(50);
- volumeBar.setFocusable(false);
- }
- public static void changeChannel(int index) throws RemoteException
- {
- try {
- service
- .getServiceLists()
- .getList(0)
- .setCurrentServiceByIndex(
- liveRouteID,
- index);
- displayChanellInfo(true);
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public static void setVolume(int value)
- {
- if (volumeDialog.isShowing())
- {
- volumeTimerTask.cancel();
- volumeBar.setProgress(value);
- } else
- {
- volumeBar.setProgress(value);
- volumeDialog.show();
- }
- volumeTimerTask = new TimerTask() {
- @Override
- public void run() {
- volumeDialog.cancel();
- }
- };
- volumeTimer.schedule(volumeTimerTask, 1500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement