use of com.lantouzi.wheelview.WheelView in project MusicDNA by harjot-oberai.
the class HomeActivity method showSleepDialog.
public void showSleepDialog() {
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.sleep_timer_dialog);
final WheelView wheelPicker = (WheelView) dialog.findViewById(R.id.wheelPicker);
wheelPicker.setItems(minuteList);
TextView title = (TextView) dialog.findViewById(R.id.sleep_dialog_title_text);
if (SplashActivity.tf4 != null)
title.setTypeface(SplashActivity.tf4);
Button setBtn = (Button) dialog.findViewById(R.id.set_button);
Button cancelBtn = (Button) dialog.findViewById(R.id.cancel_button);
final Button removerBtn = (Button) dialog.findViewById(R.id.remove_timer_button);
final LinearLayout buttonWrapper = (LinearLayout) dialog.findViewById(R.id.button_wrapper);
final TextView timerSetText = (TextView) dialog.findViewById(R.id.timer_set_text);
setBtn.setBackgroundColor(themeColor);
removerBtn.setBackgroundColor(themeColor);
cancelBtn.setBackgroundColor(Color.WHITE);
if (isSleepTimerEnabled) {
wheelPicker.setVisibility(View.GONE);
buttonWrapper.setVisibility(View.GONE);
removerBtn.setVisibility(View.VISIBLE);
timerSetText.setVisibility(View.VISIBLE);
long currentTime = System.currentTimeMillis();
long difference = currentTime - timerSetTime;
int minutesLeft = (int) (timerTimeOutDuration - ((difference / 1000) / 60));
if (minutesLeft > 1) {
timerSetText.setText("Timer set for " + minutesLeft + " minutes from now.");
} else if (minutesLeft == 1) {
timerSetText.setText("Timer set for " + 1 + " minute from now.");
} else {
timerSetText.setText("Music will stop after completion of current song");
}
} else {
wheelPicker.setVisibility(View.VISIBLE);
buttonWrapper.setVisibility(View.VISIBLE);
removerBtn.setVisibility(View.GONE);
timerSetText.setVisibility(View.GONE);
}
removerBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isSleepTimerEnabled = false;
isSleepTimerTimeout = false;
timerTimeOutDuration = 0;
timerSetTime = 0;
sleepHandler.removeCallbacksAndMessages(null);
Toast.makeText(ctx, "Timer removed", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
setBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isSleepTimerEnabled = true;
int minutes = Integer.parseInt(wheelPicker.getItems().get(wheelPicker.getSelectedPosition()));
timerTimeOutDuration = minutes;
timerSetTime = System.currentTimeMillis();
sleepHandler.postDelayed(new Runnable() {
@Override
public void run() {
isSleepTimerTimeout = true;
if (playerFragment.mMediaPlayer == null || !playerFragment.mMediaPlayer.isPlaying()) {
main.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(ctx, "Sleep timer timed out, closing app", Toast.LENGTH_SHORT).show();
if (playerFragment != null && playerFragment.timer != null)
playerFragment.timer.cancel();
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
try {
notificationManager.cancel(1);
} catch (Exception e) {
e.printStackTrace();
} finally {
finish();
}
}
});
}
}
}, minutes * 60 * 1000);
Toast.makeText(ctx, "Timer set for " + minutes + " minutes", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
cancelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isSleepTimerEnabled = false;
isSleepTimerTimeout = false;
dialog.dismiss();
}
});
dialog.show();
}
Aggregations