Last active
November 24, 2016 05:49
-
-
Save kevalpatel2106/aa7324b22e2273de245eaa6d25df51a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The root element of the collapsed view layout | |
final View collapsedView = mFloatingView.findViewById(R.id.collapse_view); | |
//The root element of the expanded view layout | |
final View expandedView = mFloatingView.findViewById(R.id.expanded_container); | |
//Set the close button | |
ImageView closeButtonCollapsed = (ImageView) mFloatingView.findViewById(R.id.close_btn); | |
closeButtonCollapsed.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
//close the service and remove the from from the window | |
stopSelf(); | |
} | |
}); | |
//Set the view while floating view is expanded. | |
//Set the play button. | |
ImageView playButton = (ImageView) mFloatingView.findViewById(R.id.play_btn); | |
playButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Toast.makeText(FloatingViewService.this, "Playing the song.", Toast.LENGTH_LONG).show(); | |
} | |
}); | |
//Set the next button. | |
ImageView nextButton = (ImageView) mFloatingView.findViewById(R.id.next_btn); | |
nextButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Toast.makeText(FloatingViewService.this, "Playing next song.", Toast.LENGTH_LONG).show(); | |
} | |
}); | |
//Set the pause button. | |
ImageView prevButton = (ImageView) mFloatingView.findViewById(R.id.prev_btn); | |
prevButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Toast.makeText(FloatingViewService.this, "Playing previous song.", Toast.LENGTH_LONG).show(); | |
} | |
}); | |
//Set the close button | |
ImageView closeButton = (ImageView) mFloatingView.findViewById(R.id.close_button); | |
closeButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
collapsedView.setVisibility(View.VISIBLE); | |
expandedView.setVisibility(View.GONE); | |
} | |
}); | |
//Open the application on thi button click | |
ImageView openButton = (ImageView) mFloatingView.findViewById(R.id.open_button); | |
openButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
//Open the application click. | |
Intent intent = new Intent(FloatingViewService.this, MainActivity.class); | |
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
startActivity(intent); | |
//close the service and remove view from the view hierarchy | |
stopSelf(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment