Search in sources :

Example 1 with WheelView

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();
}
Also used : NotificationManager(android.app.NotificationManager) WheelView(com.lantouzi.wheelview.WheelView) ImageView(android.widget.ImageView) VisualizerView(com.sdsmdg.harjot.MusicDNA.visualizers.VisualizerView) RecyclerView(android.support.v7.widget.RecyclerView) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) WheelView(com.lantouzi.wheelview.WheelView) ListView(android.widget.ListView) TextPaint(android.text.TextPaint) FileNotFoundException(java.io.FileNotFoundException) Button(android.widget.Button) Dialog(android.app.Dialog) CustomLocalBottomSheetDialog(com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomLocalBottomSheetDialog) CustomGeneralBottomSheetDialog(com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomGeneralBottomSheetDialog) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Aggregations

Dialog (android.app.Dialog)1 NotificationManager (android.app.NotificationManager)1 NavigationView (android.support.design.widget.NavigationView)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SearchView (android.support.v7.widget.SearchView)1 TextPaint (android.text.TextPaint)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 ShowcaseView (com.github.amlcurran.showcaseview.ShowcaseView)1 WheelView (com.lantouzi.wheelview.WheelView)1 CustomGeneralBottomSheetDialog (com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomGeneralBottomSheetDialog)1 CustomLocalBottomSheetDialog (com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomLocalBottomSheetDialog)1 VisualizerView (com.sdsmdg.harjot.MusicDNA.visualizers.VisualizerView)1 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)1 FileNotFoundException (java.io.FileNotFoundException)1