diff --git a/src/main/java/org/droidupnp/view/ContentDirectoryFragment.java b/src/main/java/org/droidupnp/view/ContentDirectoryFragment.java index a8fdfd5..a183537 100644 --- a/src/main/java/org/droidupnp/view/ContentDirectoryFragment.java +++ b/src/main/java/org/droidupnp/view/ContentDirectoryFragment.java @@ -79,7 +79,11 @@ public void updateSearchVisibility() a.runOnUiThread(new Runnable() { @Override public void run() { - Main.setSearchVisibility(contentDirectoryCommand!=null && contentDirectoryCommand.isSearchAvailable()); + try { + Main.setSearchVisibility(contentDirectoryCommand!=null && contentDirectoryCommand.isSearchAvailable()); + } catch (Exception e) { + e.printStackTrace(); + } } }); } @@ -310,8 +314,12 @@ public Void call() throws java.lang.Exception { a.runOnUiThread(new Runnable() { @Override public void run() { - setListShown(true); - mPullToRefreshLayout.setRefreshComplete(); + try { + setListShown(true); + mPullToRefreshLayout.setRefreshComplete(); + } catch (Exception e) { + e.printStackTrace(); + } } }); } @@ -341,10 +349,14 @@ public Void call() throws java.lang.Exception a.runOnUiThread(new Runnable() { @Override public void run() { - // Empty the list - contentList.clear(); - // Fill the list - contentList.addAll(content); + try { + // Empty the list + contentList.clear(); + // Fill the list + contentList.addAll(content); + } catch (Exception e) { + e.printStackTrace(); + } } }); } @@ -364,9 +376,13 @@ public synchronized void refresh() a.runOnUiThread(new Runnable() { @Override public void run() { - setListShown(false); - mPullToRefreshLayout.setRefreshComplete(); - mPullToRefreshLayout.setRefreshing(true); + try { + setListShown(false); + mPullToRefreshLayout.setRefreshComplete(); + mPullToRefreshLayout.setRefreshing(true); + } catch (Exception e) { + e.printStackTrace(); + } } }); } @@ -488,15 +504,19 @@ private void launchURI(final IDIDLItem uri) a.runOnUiThread(new Runnable(){ @Override public void run() { - RendererDialog rendererDialog = new RendererDialog(); - rendererDialog.setCallback(new Callable() { - @Override - public Void call() throws Exception { - launchURIRenderer(uri); - return null; - } - }); - rendererDialog.show(getActivity().getFragmentManager(), "RendererDialog"); + try { + RendererDialog rendererDialog = new RendererDialog(); + rendererDialog.setCallback(new Callable() { + @Override + public Void call() throws Exception { + launchURIRenderer(uri); + return null; + } + }); + rendererDialog.show(getActivity().getFragmentManager(), "RendererDialog"); + } catch (Exception e) { + e.printStackTrace(); + } } }); } diff --git a/src/main/java/org/droidupnp/view/RendererFragment.java b/src/main/java/org/droidupnp/view/RendererFragment.java index ad4db54..32d3f96 100644 --- a/src/main/java/org/droidupnp/view/RendererFragment.java +++ b/src/main/java/org/droidupnp/view/RendererFragment.java @@ -75,15 +75,21 @@ public RendererFragment() public void hide() { - getActivity().findViewById(R.id.progressBar).setVisibility(View.INVISIBLE); - getActivity().findViewById(R.id.separator).setVisibility(View.INVISIBLE); + Activity a = getActivity(); + if (a==null) + return; + a.findViewById(R.id.progressBar).setVisibility(View.INVISIBLE); + a.findViewById(R.id.separator).setVisibility(View.INVISIBLE); getFragmentManager().beginTransaction().hide(this).commit(); } public void show() { - getActivity().findViewById(R.id.progressBar).setVisibility(View.VISIBLE); - getActivity().findViewById(R.id.separator).setVisibility(View.VISIBLE); + Activity a = getActivity(); + if (a==null) + return; + a.findViewById(R.id.progressBar).setVisibility(View.VISIBLE); + a.findViewById(R.id.separator).setVisibility(View.VISIBLE); getFragmentManager().beginTransaction().show(this).commit(); } @@ -164,7 +170,11 @@ public void startControlPoint() @Override public void run() { - hide(); + try { + hide(); + } catch (Exception e) { + e.printStackTrace(); + } } }); } @@ -209,40 +219,45 @@ public void updateRenderer() @Override public void run() { - show(); + try { + show(); - TextView title = (TextView) a.findViewById(R.id.title); - TextView artist = (TextView) a.findViewById(R.id.artist); - SeekBar seek = (SeekBar) a.findViewById(R.id.progressBar); - SeekBar volume = (SeekBar) a.findViewById(R.id.volume); - TextView durationElapse = (TextView) a.findViewById(R.id.trackDurationElapse); + TextView title = (TextView) a.findViewById(R.id.title); + TextView artist = (TextView) a.findViewById(R.id.artist); + SeekBar seek = (SeekBar) a.findViewById(R.id.progressBar); + SeekBar volume = (SeekBar) a.findViewById(R.id.volume); + TextView durationElapse = (TextView) a.findViewById(R.id.trackDurationElapse); - if (title == null || artist == null || seek == null || duration == null || durationElapse == null) - return; + if (title == null || artist == null || seek == null || duration == null || durationElapse == null) + return; - if (durationRemaining) - duration.setText(rendererState.getRemainingDuration()); - else - duration.setText(rendererState.getDuration()); + if (durationRemaining) + duration.setText(rendererState.getRemainingDuration()); + else + duration.setText(rendererState.getDuration()); - durationElapse.setText(rendererState.getPosition()); + durationElapse.setText(rendererState.getPosition()); - seek.setProgress(rendererState.getElapsedPercent()); + seek.setProgress(rendererState.getElapsedPercent()); - title.setText(rendererState.getTitle()); - artist.setText(rendererState.getArtist()); + title.setText(rendererState.getTitle()); + artist.setText(rendererState.getArtist()); - if (rendererState.getState() == RendererState.State.PLAY) - play_pauseButton.setImageResource(R.drawable.pause); - else - play_pauseButton.setImageResource(R.drawable.play); + if (rendererState.getState() == RendererState.State.PLAY) + play_pauseButton.setImageResource(R.drawable.pause); + else + play_pauseButton.setImageResource(R.drawable.play); - if (rendererState.isMute()) - volumeButton.setImageResource(R.drawable.volume_mute); - else - volumeButton.setImageResource(R.drawable.volume); + if (rendererState.isMute()) + volumeButton.setImageResource(R.drawable.volume_mute); + else + volumeButton.setImageResource(R.drawable.volume); - volume.setProgress(rendererState.getVolume()); + volume.setProgress(rendererState.getVolume()); + + } catch (Exception e) { + e.printStackTrace(); + } } }); diff --git a/src/main/java/org/droidupnp/view/UpnpDeviceListFragment.java b/src/main/java/org/droidupnp/view/UpnpDeviceListFragment.java index b3ca165..2a16d2b 100644 --- a/src/main/java/org/droidupnp/view/UpnpDeviceListFragment.java +++ b/src/main/java/org/droidupnp/view/UpnpDeviceListFragment.java @@ -124,23 +124,27 @@ public void addedDevice(IUpnpDevice device) @Override public void run() { - int position = list.getPosition(d); - if (position >= 0) - { - // Device already in the list, re-set new value at same position - list.remove(d); - list.insert(d, position); - } - else - { - list.add(d); - } - if (isSelected(d.getDevice())) - { - position = list.getPosition(d); - getListView().setItemChecked(position, true); - - Log.i(TAG, d.toString() + " is selected at position " + position); + try { + int position = list.getPosition(d); + if (position >= 0) + { + // Device already in the list, re-set new value at same position + list.remove(d); + list.insert(d, position); + } + else + { + list.add(d); + } + if (isSelected(d.getDevice())) + { + position = list.getPosition(d); + getListView().setItemChecked(position, true); + + Log.i(TAG, d.toString() + " is selected at position " + position); + } + } catch (Exception e) { + e.printStackTrace(); } } }); @@ -158,8 +162,12 @@ public void removedDevice(IUpnpDevice device) @Override public void run() { - // Remove device from list - list.remove(d); + try { + // Remove device from list + list.remove(d); + } catch (Exception e) { + e.printStackTrace(); + } } }); }