Added highlight for current item.
This commit is contained in:
parent
e9afc5b6ff
commit
6661bdd631
3 changed files with 50 additions and 3 deletions
4
res/values/colors.xml
Normal file
4
res/values/colors.xml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<color name="currently_playing_background">#BB99CC00</color>
|
||||||
|
</resources>
|
|
@ -53,13 +53,13 @@ import org.teleal.cling.support.model.item.Item;
|
||||||
import org.teleal.cling.support.renderingcontrol.callback.GetVolume;
|
import org.teleal.cling.support.renderingcontrol.callback.GetVolume;
|
||||||
import org.teleal.cling.support.renderingcontrol.callback.SetVolume;
|
import org.teleal.cling.support.renderingcontrol.callback.SetVolume;
|
||||||
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
@ -69,6 +69,8 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AbsListView;
|
||||||
|
import android.widget.AbsListView.OnScrollListener;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
@ -89,7 +91,7 @@ import com.github.nutomic.controldlna.service.PlayServiceBinder;
|
||||||
*/
|
*/
|
||||||
public class RendererFragment extends Fragment implements
|
public class RendererFragment extends Fragment implements
|
||||||
OnBackPressedListener, OnItemClickListener, OnClickListener,
|
OnBackPressedListener, OnItemClickListener, OnClickListener,
|
||||||
OnSeekBarChangeListener {
|
OnSeekBarChangeListener, OnScrollListener {
|
||||||
|
|
||||||
private final String TAG = "RendererFragment";
|
private final String TAG = "RendererFragment";
|
||||||
|
|
||||||
|
@ -103,6 +105,8 @@ public class RendererFragment extends Fragment implements
|
||||||
|
|
||||||
private Device<?, ?, ?> mCurrentRenderer;
|
private Device<?, ?, ?> mCurrentRenderer;
|
||||||
|
|
||||||
|
private View mCurrentTrackView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ListView adapter of media renderers.
|
* ListView adapter of media renderers.
|
||||||
*/
|
*/
|
||||||
|
@ -117,7 +121,6 @@ public class RendererFragment extends Fragment implements
|
||||||
private ServiceConnection mPlayServiceConnection = new ServiceConnection() {
|
private ServiceConnection mPlayServiceConnection = new ServiceConnection() {
|
||||||
|
|
||||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||||
Log.d(TAG, "test");
|
|
||||||
mPlayService = (PlayServiceBinder) service;
|
mPlayService = (PlayServiceBinder) service;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +172,7 @@ public class RendererFragment extends Fragment implements
|
||||||
getActivity(), DeviceArrayAdapter.RENDERER);
|
getActivity(), DeviceArrayAdapter.RENDERER);
|
||||||
mListView.setAdapter(mRendererAdapter);
|
mListView.setAdapter(mRendererAdapter);
|
||||||
mListView.setOnItemClickListener(this);
|
mListView.setOnItemClickListener(this);
|
||||||
|
mListView.setOnScrollListener(this);
|
||||||
mControls = getView().findViewById(R.id.controls);
|
mControls = getView().findViewById(R.id.controls);
|
||||||
mProgressBar = (SeekBar) getView().findViewById(R.id.progressBar);
|
mProgressBar = (SeekBar) getView().findViewById(R.id.progressBar);
|
||||||
mProgressBar.setOnSeekBarChangeListener(this);
|
mProgressBar.setOnSeekBarChangeListener(this);
|
||||||
|
@ -329,6 +333,7 @@ public class RendererFragment extends Fragment implements
|
||||||
mPlayPause.setText(R.string.pause);
|
mPlayPause.setText(R.string.pause);
|
||||||
mPlaying = true;
|
mPlaying = true;
|
||||||
pollTimePosition();
|
pollTimePosition();
|
||||||
|
enableTrackHighlight();
|
||||||
break;
|
break;
|
||||||
case STOPPED:
|
case STOPPED:
|
||||||
// fallthrough
|
// fallthrough
|
||||||
|
@ -367,6 +372,29 @@ public class RendererFragment extends Fragment implements
|
||||||
mListView.setAdapter(mPlaylistAdapter);
|
mListView.setAdapter(mPlaylistAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets colored background on the item that is currently playing.
|
||||||
|
*/
|
||||||
|
private void enableTrackHighlight() {
|
||||||
|
if (mListView.getAdapter() == mRendererAdapter)
|
||||||
|
return;
|
||||||
|
disableTrackHighlight();
|
||||||
|
mCurrentTrackView = mListView.getChildAt(mPlayService.getService()
|
||||||
|
.getCurrentTrack()
|
||||||
|
- mListView.getFirstVisiblePosition() + mListView.getHeaderViewsCount());
|
||||||
|
if (mCurrentTrackView != null)
|
||||||
|
mCurrentTrackView.setBackgroundColor(
|
||||||
|
getResources().getColor(R.color.currently_playing_background));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes highlight from the item that was last highlighted.
|
||||||
|
*/
|
||||||
|
private void disableTrackHighlight() {
|
||||||
|
if (mCurrentTrackView != null)
|
||||||
|
mCurrentTrackView.setBackgroundColor(Color.TRANSPARENT);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unselects current media renderer if one is selected.
|
* Unselects current media renderer if one is selected.
|
||||||
*/
|
*/
|
||||||
|
@ -375,6 +403,7 @@ public class RendererFragment extends Fragment implements
|
||||||
if (mListView.getAdapter() == mPlaylistAdapter) {
|
if (mListView.getAdapter() == mPlaylistAdapter) {
|
||||||
mControls.setVisibility(View.GONE);
|
mControls.setVisibility(View.GONE);
|
||||||
mListView.setAdapter(mRendererAdapter);
|
mListView.setAdapter(mRendererAdapter);
|
||||||
|
disableTrackHighlight();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -474,4 +503,14 @@ public class RendererFragment extends Fragment implements
|
||||||
new ServiceType("schemas-upnp-org", name));
|
new ServiceType("schemas-upnp-org", name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) {
|
||||||
|
enableTrackHighlight();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onScrollStateChanged(AbsListView arg0, int arg1) {
|
||||||
|
enableTrackHighlight();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -355,4 +355,8 @@ public class PlayService extends Service {
|
||||||
return mPlaylist;
|
return mPlaylist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCurrentTrack() {
|
||||||
|
return mCurrentTrack;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue