Search in sources :

Example 1 with PlayerFragment

use of com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment in project MusicDNA by harjot-oberai.

the class MediaPlayerService method initMediaSessions.

private void initMediaSessions() {
    if (pFragment != null) {
        pFragment.mCallback7 = this;
        m_objMediaPlayer = pFragment.mMediaPlayer;
        m_objMediaSessionManager = (MediaSessionManager) getSystemService(Context.MEDIA_SESSION_SERVICE);
        m_objMediaSession = new MediaSession(getApplicationContext(), "sample session");
        m_objMediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
        MediaMetadata.Builder metadataBuilder = new MediaMetadata.Builder();
        if (pFragment.localIsPlaying) {
            if (pFragment.localTrack != null) {
                metadataBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, pFragment.localTrack.getTitle());
                metadataBuilder.putString(MediaMetadata.METADATA_KEY_ARTIST, pFragment.localTrack.getArtist());
            }
        } else {
            if (pFragment.track != null) {
                metadataBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, pFragment.track.getTitle());
                metadataBuilder.putString(MediaMetadata.METADATA_KEY_ARTIST, "");
            }
        }
        if (pFragment.selected_track_image != null && pFragment.selected_track_image.getDrawable() != null) {
            if (((BitmapDrawable) pFragment.selected_track_image.getDrawable()).getBitmap() != null) {
                metadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, ((BitmapDrawable) pFragment.selected_track_image.getDrawable()).getBitmap());
            }
        }
        m_objMediaSession.setMetadata(metadataBuilder.build());
        PlaybackState.Builder stateBuilder = new PlaybackState.Builder();
        stateBuilder.setActions(PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS);
        try {
            if (pFragment.mMediaPlayer != null) {
                stateBuilder.setState(!pFragment.mMediaPlayer.isPlaying() ? PlaybackState.STATE_PAUSED : PlaybackState.STATE_PLAYING, PlaybackState.PLAYBACK_POSITION_UNKNOWN, 1.0f);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        m_objMediaSession.setPlaybackState(stateBuilder.build());
        m_objMediaSession.setActive(true);
        m_objMediaController = m_objMediaSession.getController();
        m_objMediaSession.setCallback(new MediaSession.Callback() {

            @Override
            public void onPlay() {
                super.onPlay();
                try {
                    Log.d(Constants.LOG_TAG, "onPlay");
                    PlayerFragment pFrag = pFragment;
                    if (pFrag != null) {
                        if (!pFrag.isStart) {
                            pFrag.togglePlayPause();
                        }
                        pFrag.isStart = false;
                        buildNotification(generateAction(R.drawable.ic_pause_notif, "Pause", Constants.ACTION_PAUSE));
                    }
                } catch (Exception e) {
                }
            }

            @Override
            public void onPause() {
                super.onPause();
                try {
                    PlayerFragment pFrag = pFragment;
                    if (pFrag != null) {
                        pFrag.togglePlayPause();
                        buildNotification(generateAction(R.drawable.ic_play_notif, "Play", Constants.ACTION_PLAY));
                    }
                } catch (Exception e) {
                }
            }

            @Override
            public void onSkipToNext() {
                super.onSkipToNext();
                try {
                    if (pFragment != null) {
                        pFragment.onCallbackCalled(2);
                        final Handler handler = new Handler();
                        handler.postDelayed(new Runnable() {

                            @Override
                            public void run() {
                                buildNotification(generateAction(R.drawable.ic_pause_notif, "Pause", Constants.ACTION_PAUSE));
                            }
                        }, 100);
                    }
                } catch (Exception e) {
                }
            }

            @Override
            public void onSkipToPrevious() {
                super.onSkipToPrevious();
                try {
                    if (pFragment != null) {
                        pFragment.onCallbackCalled(3);
                        final Handler handler = new Handler();
                        handler.postDelayed(new Runnable() {

                            @Override
                            public void run() {
                                buildNotification(generateAction(R.drawable.ic_pause_notif, "Pause", Constants.ACTION_PAUSE));
                            }
                        }, 100);
                    }
                } catch (Exception e) {
                }
            }

            @Override
            public void onFastForward() {
                super.onFastForward();
                Log.d(Constants.LOG_TAG, "onFastForward");
                if (pFragment != null)
                    pFragment.mCallback.onComplete();
                final Handler handler = new Handler();
                handler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        buildNotification(generateAction(R.drawable.ic_pause_notif, "Pause", Constants.ACTION_PAUSE));
                    }
                }, 100);
            }

            @Override
            public void onRewind() {
                super.onRewind();
                Log.d(Constants.LOG_TAG, "onRewind");
                if (pFragment != null)
                    pFragment.mCallback.onPreviousTrack();
                final Handler handler = new Handler();
                handler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        buildNotification(generateAction(R.drawable.ic_pause_notif, "Pause", Constants.ACTION_PAUSE));
                    }
                }, 100);
            }

            @Override
            public void onStop() {
                super.onStop();
            // if (pFragment.mMediaPlayer != null) {
            // if (pFragment.mMediaPlayer.isPlaying()) {
            // buildNotification(generateAction(R.drawable.ic_pause_notif, "Pause", Constants.ACTION_PAUSE));
            // } else {
            // buildNotification(generateAction(R.drawable.ic_play_notif, "Play", Constants.ACTION_PLAY));
            // }
            // }
            }

            @Override
            public void onSeekTo(long pos) {
                super.onSeekTo(pos);
            }

            @Override
            public void onSetRating(Rating rating) {
                super.onSetRating(rating);
            }
        });
    }
}
Also used : Rating(android.media.Rating) Handler(android.os.Handler) MediaSession(android.media.session.MediaSession) MediaMetadata(android.media.MediaMetadata) PlaybackState(android.media.session.PlaybackState) PlayerFragment(com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment)

Example 2 with PlayerFragment

use of com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment in project MusicDNA by harjot-oberai.

the class HomeActivity method onBackPressed.

// //////////////////////////////////////////////////////////////////////////////////////////////
/*
     * Standard Activity methods
     */
@Override
public void onBackPressed() {
    PlayerFragment plFrag = playerFragment;
    LocalMusicViewPagerFragment flmFrag = (LocalMusicViewPagerFragment) fragMan.findFragmentByTag("local");
    LocalMusicFragment lFrag = null;
    if (flmFrag != null) {
        lFrag = (LocalMusicFragment) flmFrag.getFragmentByPosition(0);
    }
    QueueFragment qFrag = (QueueFragment) fragMan.findFragmentByTag("queue");
    EqualizerFragment eqFrag = (EqualizerFragment) fragMan.findFragmentByTag("equalizer");
    ViewSavedDNA vsdFrag = (ViewSavedDNA) fragMan.findFragmentByTag("allSavedDNAs");
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else if (showCase != null && showCase.isShowing()) {
        showCase.hide();
    } else if (plFrag != null && plFrag.isShowcaseVisible()) {
        plFrag.hideShowcase();
    } else if (lFrag != null && lFrag.isShowcaseVisible()) {
        lFrag.hideShowcase();
    } else if (qFrag != null && qFrag.isShowcaseVisible()) {
        qFrag.hideShowcase();
    } else if (eqFrag != null && eqFrag.isShowcaseVisible()) {
        eqFrag.hideShowcase();
    } else if (vsdFrag != null && vsdFrag.isShowcaseVisible()) {
        vsdFrag.hideShowcase();
    } else if (isFullScreenEnabled) {
        isFullScreenEnabled = false;
        plFrag.bottomContainer.setVisibility(View.VISIBLE);
        plFrag.seekBarContainer.setVisibility(View.VISIBLE);
        plFrag.toggleContainer.setVisibility(View.VISIBLE);
        plFrag.spToolbar.setVisibility(View.VISIBLE);
        onFullScreen();
    } else if (isEqualizerVisible) {
        showPlayer2();
    } else if (isQueueVisible) {
        showPlayer3();
    } else if (isPlayerVisible && !isPlayerTransitioning && playerFragment.smallPlayer != null) {
        hidePlayer();
        // showTabs();
        isPlayerVisible = false;
    } else if (isLocalVisible && flmFrag != null && flmFrag.searchBox != null && flmFrag.isSearchboxVisible) {
        flmFrag.searchBox.setText("");
        flmFrag.searchBox.setVisibility(View.INVISIBLE);
        flmFrag.isSearchboxVisible = false;
        InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
        flmFrag.searchIcon.setImageResource(R.drawable.ic_search);
        flmFrag.fragTitle.setVisibility(View.VISIBLE);
    } else if (!searchView.isIconified()) {
        searchView.setQuery("", true);
        searchView.setIconified(true);
        new Thread(new CancelCall()).start();
        if (localRecyclerContainer.getVisibility() == View.VISIBLE || streamRecyclerContainer.getVisibility() == View.VISIBLE) {
            localRecyclerContainer.setVisibility(GONE);
            streamRecyclerContainer.setVisibility(GONE);
        }
    } else if (localRecyclerContainer.getVisibility() == View.VISIBLE || streamRecyclerContainer.getVisibility() == View.VISIBLE) {
        localRecyclerContainer.setVisibility(GONE);
        streamRecyclerContainer.setVisibility(GONE);
    } else {
        if (isEditVisible) {
            hideFragment("Edit");
        } else if (isAlbumVisible) {
            hideFragment("viewAlbum");
        } else if (isArtistVisible) {
            hideFragment("viewArtist");
        } else {
            if (isLocalVisible) {
                hideFragment("local");
                setTitle("Music DNA");
            } else if (isQueueVisible) {
                hideFragment("queue");
                setTitle("Music DNA");
            } else if (isStreamVisible) {
                hideFragment("stream");
                setTitle("Music DNA");
            } else if (isPlaylistVisible) {
                hideFragment("playlist");
                setTitle("Music DNA");
            } else if (isNewPlaylistVisible) {
                hideFragment("newPlaylist");
                setTitle("Music DNA");
            } else if (isEqualizerVisible) {
                finalSelectedTracks.clear();
                hideFragment("equalizer");
                setTitle("Music DNA");
            } else if (isFavouriteVisible) {
                hideFragment("favourite");
                setTitle("Music DNA");
            } else if (isAllPlaylistVisible) {
                hideFragment("allPlaylists");
                setTitle("Music DNA");
            } else if (isFolderContentVisible) {
                hideFragment("folderContent");
                setTitle("Folders");
            } else if (isAllFolderVisible) {
                hideFragment("allFolders");
                setTitle("Music DNA");
            } else if (isAllSavedDnaVisisble) {
                hideFragment("allSavedDNAs");
                setTitle("Music DNA");
            } else if (isSavedDNAVisible) {
                hideFragment("savedDNA");
                setTitle("Music DNA");
            } else if (isRecentVisible) {
                hideFragment("recent");
                setTitle("Music DNA");
            } else if (isAboutVisible) {
                hideFragment("About");
                setTitle("Settings");
            } else if (isSettingsVisible) {
                hideFragment("settings");
                new SaveSettings().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                setTitle("Music DNA");
            } else if (!isPlayerTransitioning) {
                startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));
            }
        }
    }
}
Also used : LocalMusicViewPagerFragment(com.sdsmdg.harjot.MusicDNA.fragments.LocalMusicFragments.LocalMusicViewPagerFragment) LocalMusicFragment(com.sdsmdg.harjot.MusicDNA.fragments.LocalMusicFragments.LocalMusicFragment) InputMethodManager(android.view.inputmethod.InputMethodManager) Intent(android.content.Intent) QueueFragment(com.sdsmdg.harjot.MusicDNA.fragments.QueueFragment.QueueFragment) DrawerLayout(android.support.v4.widget.DrawerLayout) ViewSavedDNA(com.sdsmdg.harjot.MusicDNA.fragments.ViewSavedDNAsFragment.ViewSavedDNA) PlayerFragment(com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment) EqualizerFragment(com.sdsmdg.harjot.MusicDNA.fragments.EqualizerFragment.EqualizerFragment)

Example 3 with PlayerFragment

use of com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment in project MusicDNA by harjot-oberai.

the class HomeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    screen_width = display.getWidth();
    screen_height = display.getHeight();
    ratio = (float) screen_height / (float) 1920;
    ratio2 = (float) screen_width / (float) 1080;
    ratio = Math.min(ratio, ratio2);
    setContentView(R.layout.activity_home);
    headSetReceiver = new HeadSetReceiver();
    IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    registerReceiver(headSetReceiver, filter);
    PackageInfo pInfo;
    try {
        pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        versionName = pInfo.versionName;
        versionCode = pInfo.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    mEndButton = new Button(this);
    mEndButton.setBackgroundColor(themeColor);
    mEndButton.setTextColor(Color.WHITE);
    tp = new TextPaint();
    tp.setColor(themeColor);
    tp.setTextSize(65 * ratio);
    tp.setFakeBoldText(true);
    recentsViewAll = (TextView) findViewById(R.id.recents_view_all);
    recentsViewAll.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showFragment("recent");
        }
    });
    playlistsViewAll = (TextView) findViewById(R.id.playlists_view_all);
    playlistsViewAll.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showFragment("allPlaylists");
        }
    });
    copyrightText = (TextView) findViewById(R.id.copyright_text);
    copyrightText.setText("Music DNA v" + versionName);
    if (SplashActivity.tf4 != null) {
        try {
            copyrightText.setTypeface(SplashActivity.tf4);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    imgLoader = new ImageLoader(this);
    ctx = this;
    initializeHeaderImages();
    hasSoftNavbar = CommonUtils.hasNavBar(this);
    statusBarHeightinDp = CommonUtils.getStatusBarHeight(this);
    navBarHeightSizeinDp = hasSoftNavbar ? CommonUtils.getNavBarHeight(this) : 0;
    serviceConnection = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName className, IBinder service) {
            // cast the IBinder and get MyService instance
            MediaPlayerService.LocalBinder binder = (MediaPlayerService.LocalBinder) service;
            myService = binder.getService();
            bound = true;
            // register
            myService.setCallbacks(HomeActivity.this);
        }

        @Override
        public void onServiceDisconnected(ComponentName arg0) {
            bound = false;
        }
    };
    minuteList = new ArrayList<>();
    for (int i = 1; i < 25; i++) {
        minuteList.add(String.valueOf(i * 5));
    }
    sleepHandler = new Handler();
    lps = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lps.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    lps.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    int margin = ((Number) (getResources().getDisplayMetrics().density * 12)).intValue();
    lps.setMargins(margin, margin, margin, navBarHeightSizeinDp + ((Number) (getResources().getDisplayMetrics().density * 5)).intValue());
    fragMan = getSupportFragmentManager();
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    if (SplashActivity.tf4 != null) {
        collapsingToolbar.setCollapsedTitleTypeface(SplashActivity.tf4);
        collapsingToolbar.setExpandedTitleTypeface(SplashActivity.tf4);
    }
    customLinearGradient = (CustomLinearGradient) findViewById(R.id.custom_linear_gradient);
    customLinearGradient.setAlpha(170);
    customLinearGradient.invalidate();
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null) {
        navigationView.setNavigationItemSelectedListener(this);
    }
    navigationView.setCheckedItem(R.id.nav_home);
    View header = navigationView.getHeaderView(0);
    navImageView = (ImageView) header.findViewById(R.id.nav_image_view);
    if (navImageView != null) {
        navImageView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                PlayerFragment pFrag = getPlayerFragment();
                if (pFrag != null) {
                    if (pFrag.mMediaPlayer != null && pFrag.mMediaPlayer.isPlaying()) {
                        onBackPressed();
                        isPlayerVisible = true;
                        // hideTabs();
                        showPlayer();
                    }
                }
            }
        });
    }
    connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    phoneStateListener = new PhoneStateListener() {

        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            PlayerFragment pFrag = playerFragment;
            if (playerFragment != null) {
                if (state == TelephonyManager.CALL_STATE_RINGING) {
                    // Incoming call: Pause music
                    if (pFrag.mMediaPlayer != null && pFrag.mMediaPlayer.isPlaying()) {
                        wasMediaPlayerPlaying = true;
                        pFrag.togglePlayPause();
                    } else {
                        wasMediaPlayerPlaying = false;
                    }
                } else if (state == TelephonyManager.CALL_STATE_IDLE) {
                    // Not in call: Play music
                    if (pFrag.mMediaPlayer != null && !pFrag.mMediaPlayer.isPlaying() && wasMediaPlayerPlaying) {
                        pFrag.togglePlayPause();
                    }
                } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
                    // A call is dialing, active or on hold
                    if (playerFragment.mMediaPlayer != null && pFrag.mMediaPlayer.isPlaying()) {
                        wasMediaPlayerPlaying = true;
                        pFrag.togglePlayPause();
                    } else {
                        wasMediaPlayerPlaying = false;
                    }
                }
            }
            super.onCallStateChanged(state, incomingNumber);
        }
    };
    TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    if (mgr != null) {
        mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
    }
    mPrefs = getPreferences(MODE_PRIVATE);
    prefsEditor = mPrefs.edit();
    gson = new Gson();
    main = this;
    localBanner = (RelativeLayout) findViewById(R.id.localBanner);
    favBanner = (ImageView) findViewById(R.id.favBanner);
    recentBanner = (ImageView) findViewById(R.id.recentBanner);
    folderBanner = (ImageView) findViewById(R.id.folderBanner);
    savedDNABanner = (ImageView) findViewById(R.id.savedDNABanner);
    localBannerPlayAll = (ImageView) findViewById(R.id.local_banner_play_all);
    localBanner.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showFragment("local");
        }
    });
    favBanner.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showFragment("favourite");
        }
    });
    recentBanner.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showFragment("recent");
        }
    });
    folderBanner.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showFragment("allFolders");
        }
    });
    savedDNABanner.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showFragment("allSavedDNAs");
        }
    });
    localBannerPlayAll.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            queue.getQueue().clear();
            for (int i = 0; i < localTrackList.size(); i++) {
                UnifiedTrack ut = new UnifiedTrack(true, localTrackList.get(i), null);
                queue.getQueue().add(ut);
            }
            if (queue.getQueue().size() > 0) {
                Random r = new Random();
                int tmp = r.nextInt(queue.getQueue().size());
                queueCurrentIndex = tmp;
                LocalTrack track = localTrackList.get(tmp);
                localSelectedTrack = track;
                streamSelected = false;
                localSelected = true;
                queueCall = false;
                isReloaded = false;
                onLocalTrackSelected(-1);
            }
        }
    });
    bottomToolbar = (FrameLayout) findViewById(R.id.bottomMargin);
    spHome = (Toolbar) findViewById(R.id.smallPlayer_home);
    playerControllerHome = (ImageView) findViewById(R.id.player_control_sp_home);
    spImgHome = (CircleImageView) findViewById(R.id.selected_track_image_sp_home);
    spTitleHome = (TextView) findViewById(R.id.selected_track_title_sp_home);
    playerControllerHome.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (queue != null && queue.getQueue().size() > 0) {
                onQueueItemClicked(queueCurrentIndex);
                bottomToolbar.setVisibility(View.INVISIBLE);
            }
        }
    });
    playerControllerHome.setImageResource(R.drawable.ic_play_arrow_white_48dp);
    spHome.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (queue != null && queue.getQueue().size() > 0) {
                onQueueItemClicked(queueCurrentIndex);
                bottomToolbar.setVisibility(View.INVISIBLE);
            }
        }
    });
    localRecyclerContainer = (RelativeLayout) findViewById(R.id.localRecyclerContainer);
    recentsRecyclerContainer = (RelativeLayout) findViewById(R.id.recentsRecyclerContainer);
    streamRecyclerContainer = (RelativeLayout) findViewById(R.id.streamRecyclerContainer);
    playlistRecyclerContainer = (RelativeLayout) findViewById(R.id.playlistRecyclerContainer);
    if (SplashActivity.tf4 != null) {
        try {
            ((TextView) findViewById(R.id.playListRecyclerLabel)).setTypeface(SplashActivity.tf4);
            ((TextView) findViewById(R.id.recentsRecyclerLabel)).setTypeface(SplashActivity.tf4);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    localNothingText = (TextView) findViewById(R.id.localNothingText);
    streamNothingText = (TextView) findViewById(R.id.streamNothingText);
    recentsNothingText = (TextView) findViewById(R.id.recentsNothingText);
    playlistNothingText = (TextView) findViewById(R.id.playlistNothingText);
    localViewAll = (TextView) findViewById(R.id.localViewAll);
    localViewAll.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showFragment("local");
        }
    });
    streamViewAll = (TextView) findViewById(R.id.streamViewAll);
    streamViewAll.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showFragment("stream");
        }
    });
    progress = new Dialog(ctx);
    progress.setCancelable(false);
    progress.requestWindowFeature(Window.FEATURE_NO_TITLE);
    progress.setContentView(R.layout.custom_progress_dialog);
    progress.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    progress.show();
    showCase = new ShowcaseView.Builder(this).blockAllTouches().singleShot(0).setStyle(R.style.CustomShowcaseTheme).useDecorViewAsParent().replaceEndButton(mEndButton).setContentTitlePaint(tp).setTarget(new ViewTarget(R.id.recentsRecyclerLabel, this)).setContentTitle("Recents and Playlists").setContentText("Here all you recent songs and playlists will be listed." + "Long press the cards or playlists for more options \n" + "\n" + "(Press Next to continue / Press back to Hide)").build();
    showCase.setButtonText("Next");
    showCase.setButtonPosition(lps);
    showCase.overrideButtonClick(new View.OnClickListener() {

        int count1 = 0;

        @Override
        public void onClick(View v) {
            count1++;
            switch(count1) {
                case 1:
                    showCase.setTarget(new ViewTarget(R.id.local_banner_alt_showcase, (Activity) ctx));
                    showCase.setContentTitle("Local Songs");
                    showCase.setContentText("See all songs available locally, classified on basis of Artist and Album");
                    showCase.setButtonPosition(lps);
                    showCase.setButtonText("Next");
                    break;
                case 2:
                    showCase.setTarget(new ViewTarget(searchView.getId(), (Activity) ctx));
                    showCase.setContentTitle("Search");
                    showCase.setContentText("Search for songs from local library and SoundCloud™");
                    showCase.setButtonPosition(lps);
                    showCase.setButtonText("Done");
                    break;
                case 3:
                    showCase.hide();
                    break;
            }
        }
    });
    new loadSavedData().execute();
}
Also used : ServiceConnection(android.content.ServiceConnection) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) Gson(com.google.gson.Gson) ViewTarget(com.github.amlcurran.showcaseview.targets.ViewTarget) WindowManager(android.view.WindowManager) IBinder(android.os.IBinder) PackageManager(android.content.pm.PackageManager) Random(java.util.Random) Button(android.widget.Button) TelephonyManager(android.telephony.TelephonyManager) Dialog(android.app.Dialog) CustomLocalBottomSheetDialog(com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomLocalBottomSheetDialog) CustomGeneralBottomSheetDialog(com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomGeneralBottomSheetDialog) PhoneStateListener(android.telephony.PhoneStateListener) HeadSetReceiver(com.sdsmdg.harjot.MusicDNA.headsethandler.HeadSetReceiver) ComponentName(android.content.ComponentName) TextView(android.widget.TextView) MediaPlayerService(com.sdsmdg.harjot.MusicDNA.notificationmanager.MediaPlayerService) PlayerFragment(com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment) IntentFilter(android.content.IntentFilter) PackageInfo(android.content.pm.PackageInfo) Handler(android.os.Handler) LocalTrack(com.sdsmdg.harjot.MusicDNA.models.LocalTrack) 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) FileNotFoundException(java.io.FileNotFoundException) TextPaint(android.text.TextPaint) TextPaint(android.text.TextPaint) ColorDrawable(android.graphics.drawable.ColorDrawable) UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack) RelativeLayout(android.widget.RelativeLayout) ImageLoader(com.sdsmdg.harjot.MusicDNA.imageloader.ImageLoader) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) Display(android.view.Display)

Example 4 with PlayerFragment

use of com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment in project MusicDNA by harjot-oberai.

the class HomeActivity method onComplete.

// //////////////////////////////////////////////////////////////////////////////////////////////
/*
     * PlayerFragment callbacks START
     * onComplete() -> called when a song ends or next button is clicked in player or notification.
     * onPreviousTrack() -> called when previous button is clicked in player or notification.
     * onEqualizerClicked() -> called when equalizer icon is clicked.
     * onQueueCLicked() -> called when queue icon is clicked.
     * onPrepared() -> called when media player prepareAsync() is completed.
     * onSettingsClicked() -> called when settings menu item is selected.
     * onFullScreen() -> called when fullscreen menu item is selected or player is long pressed.
     * onAddedtoFavfromPlayer() -> called when favourite icon is clicked.
     * onShuffleEnabled() / onShuffleEnabled() -> shuffle enebled or disabled.
     * onSmallPlayerTouched() -> called when the down icon at the top of the player ic clicked to hide the player.
     *
     */
@Override
public void onComplete() {
    // Check for sleep timer and whether it has timed out
    if (isSleepTimerEnabled && isSleepTimerTimeout) {
        Toast.makeText(ctx, "Sleep timer timed out, closing app", Toast.LENGTH_SHORT).show();
        if (playerFragment != null && playerFragment.timer != null)
            playerFragment.timer.cancel();
        // Remove the notification
        notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(1);
        // Finish the activity
        finish();
        return;
    }
    // Save the DNA if saving is enabled
    if (isSaveDNAEnabled) {
        new SaveTheDNAs().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
    QueueFragment qFrag = (QueueFragment) fragMan.findFragmentByTag("queue");
    queueCall = true;
    PlayerFragment plFrag = playerFragment;
    if (repeatOnceEnabled && !nextControllerClicked) {
        /*
            * Executed if repeat once is enabled and user did not click the next button from player.
            */
        // Set Progress bar to 0
        plFrag.progressBar.setProgress(0);
        plFrag.progressBar.setSecondaryProgress(0);
        // Get Visualizer and Visualizer View to initial state
        plFrag.mVisualizer.setEnabled(true);
        VisualizerView.w = screen_width;
        VisualizerView.h = screen_height;
        VisualizerView.conf = Bitmap.Config.ARGB_8888;
        VisualizerView.bmp = Bitmap.createBitmap(VisualizerView.w, VisualizerView.h, VisualizerView.conf);
        cacheCanvas = new Canvas(VisualizerView.bmp);
        // Play the song again by seeking media player to 0
        plFrag.mMediaPlayer.seekTo(0);
        // Setup the icons
        plFrag.mainTrackController.setImageResource(R.drawable.ic_pause_white_48dp);
        plFrag.isReplayIconVisible = false;
        plFrag.player_controller.setImageResource(R.drawable.ic_pause_white_48dp);
        // Resume the MediaPlayer
        plFrag.isPrepared = true;
        plFrag.mMediaPlayer.start();
    } else {
        if (queueCurrentIndex < queue.getQueue().size() - 1) {
            queueCurrentIndex++;
            nextControllerClicked = false;
            hasQueueEnded = false;
            if (qFrag != null) {
                qFrag.updateQueueAdapter();
            }
            if (queue.getQueue().get(queueCurrentIndex).getType()) {
                localSelectedTrack = queue.getQueue().get(queueCurrentIndex).getLocalTrack();
                streamSelected = false;
                localSelected = true;
                onLocalTrackSelected(-1);
            } else {
                selectedTrack = queue.getQueue().get(queueCurrentIndex).getStreamTrack();
                streamSelected = true;
                localSelected = false;
                onTrackSelected(-1);
            }
        } else {
            if ((repeatEnabled || repeatOnceEnabled) && (queue.getQueue().size() > 1)) {
                nextControllerClicked = false;
                hasQueueEnded = false;
                queueCurrentIndex = 0;
                if (qFrag != null) {
                    qFrag.updateQueueAdapter();
                }
                onQueueItemClicked(0);
            } else if ((repeatEnabled || repeatOnceEnabled) && (queue.getQueue().size() == 1)) {
                nextControllerClicked = false;
                hasQueueEnded = false;
                plFrag.progressBar.setProgress(0);
                plFrag.progressBar.setSecondaryProgress(0);
                plFrag.mVisualizer.setEnabled(true);
                plFrag.mMediaPlayer.seekTo(0);
                plFrag.mainTrackController.setImageResource(R.drawable.ic_pause_white_48dp);
                plFrag.isReplayIconVisible = false;
                plFrag.player_controller.setImageResource(R.drawable.ic_pause_white_48dp);
                plFrag.isPrepared = true;
                plFrag.mMediaPlayer.start();
            } else {
                if ((nextControllerClicked || hasQueueEnded) && (queue.getQueue().size() > 1)) {
                    nextControllerClicked = false;
                    hasQueueEnded = false;
                    queueCurrentIndex = 0;
                    if (qFrag != null) {
                        qFrag.updateQueueAdapter();
                    }
                    onQueueItemClicked(0);
                } else if ((nextControllerClicked || hasQueueEnded) && (queue.getQueue().size() == 1)) {
                    nextControllerClicked = false;
                    hasQueueEnded = false;
                    plFrag.progressBar.setProgress(0);
                    plFrag.progressBar.setSecondaryProgress(0);
                    if (plFrag.mVisualizer != null)
                        plFrag.mVisualizer.setEnabled(true);
                    plFrag.mMediaPlayer.seekTo(0);
                    plFrag.mainTrackController.setImageResource(R.drawable.ic_pause_white_48dp);
                    plFrag.isReplayIconVisible = false;
                    plFrag.player_controller.setImageResource(R.drawable.ic_pause_white_48dp);
                    plFrag.isPrepared = true;
                    plFrag.mMediaPlayer.start();
                } else {
                // keep queue at last track or you are doomed
                }
            }
        }
    }
}
Also used : Canvas(android.graphics.Canvas) QueueFragment(com.sdsmdg.harjot.MusicDNA.fragments.QueueFragment.QueueFragment) PlayerFragment(com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment)

Example 5 with PlayerFragment

use of com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment in project MusicDNA by harjot-oberai.

the class HomeActivity method onLocalTrackSelected.

public void onLocalTrackSelected(int position) {
    isReloaded = false;
    HideBottomFakeToolbar();
    if (!queueCall) {
        CommonUtils.hideKeyboard(this);
        searchView.setQuery("", true);
        searchView.setIconified(true);
        new Thread(new CancelCall()).start();
        // hideTabs();
        isPlayerVisible = true;
        PlayerFragment frag = playerFragment;
        android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
        PlayerFragment newFragment = new PlayerFragment();
        if (frag == null) {
            playerFragment = newFragment;
            int flag = 0;
            for (int i = 0; i < favouriteTracks.getFavourite().size(); i++) {
                UnifiedTrack ut = favouriteTracks.getFavourite().get(i);
                if (ut.getType() && ut.getLocalTrack().getTitle().equals(localSelectedTrack.getTitle())) {
                    flag = 1;
                    isFavourite = true;
                    break;
                }
            }
            if (flag == 0) {
                isFavourite = false;
            }
            playerFragment.localIsPlaying = true;
            playerFragment.localTrack = localSelectedTrack;
            fm.beginTransaction().setCustomAnimations(R.anim.slide_up, R.anim.slide_down, R.anim.slide_up, R.anim.slide_down).add(R.id.player_frag_container, newFragment, "player").show(newFragment).commitAllowingStateLoss();
        } else {
            if (playerFragment.localTrack != null && playerFragment.localIsPlaying && localSelectedTrack.getTitle() == playerFragment.localTrack.getTitle()) {
            } else {
                int flag = 0;
                for (int i = 0; i < favouriteTracks.getFavourite().size(); i++) {
                    UnifiedTrack ut = favouriteTracks.getFavourite().get(i);
                    if (ut.getType() && ut.getLocalTrack().getTitle().equals(localSelectedTrack.getTitle())) {
                        flag = 1;
                        isFavourite = true;
                        break;
                    }
                }
                if (flag == 0) {
                    isFavourite = false;
                }
                playerFragment.localIsPlaying = true;
                playerFragment.localTrack = localSelectedTrack;
                frag.refresh();
            }
        }
        if (!isQueueVisible)
            showPlayer();
    } else {
        PlayerFragment frag = playerFragment;
        playerFragment.localIsPlaying = true;
        playerFragment.localTrack = localSelectedTrack;
        int flag = 0;
        for (int i = 0; i < favouriteTracks.getFavourite().size(); i++) {
            UnifiedTrack ut = favouriteTracks.getFavourite().get(i);
            if (ut.getType() && ut.getLocalTrack().getTitle().equals(localSelectedTrack.getTitle())) {
                flag = 1;
                isFavourite = true;
                break;
            }
        }
        if (flag == 0) {
            isFavourite = false;
        }
        if (frag != null)
            frag.refresh();
    }
    if (playerFragment != null && playerFragment.snappyRecyclerView != null) {
        playerFragment.snappyRecyclerView.getAdapter().notifyDataSetChanged();
        playerFragment.snappyRecyclerView.setTransparency();
    }
    QueueFragment qFrag = (QueueFragment) fragMan.findFragmentByTag("queue");
    if (qFrag != null) {
        qFrag.updateQueueAdapter();
    }
    UnifiedTrack track = new UnifiedTrack(true, playerFragment.localTrack, null);
    for (int i = 0; i < recentlyPlayed.getRecentlyPlayed().size(); i++) {
        if (recentlyPlayed.getRecentlyPlayed().get(i).getType() && recentlyPlayed.getRecentlyPlayed().get(i).getLocalTrack().getTitle().equals(track.getLocalTrack().getTitle())) {
            recentlyPlayed.getRecentlyPlayed().remove(i);
            // rAdapter.notifyItemRemoved(i);
            break;
        }
    }
    recentlyPlayed.getRecentlyPlayed().add(0, track);
    if (recentlyPlayed.getRecentlyPlayed().size() == 51) {
        recentlyPlayed.getRecentlyPlayed().remove(50);
    }
    recentsRecycler.setVisibility(View.VISIBLE);
    recentsNothingText.setVisibility(View.INVISIBLE);
    continuePlayingList.clear();
    for (int i = 0; i < Math.min(10, recentlyPlayed.getRecentlyPlayed().size()); i++) {
        continuePlayingList.add(recentlyPlayed.getRecentlyPlayed().get(i));
    }
    rAdapter.notifyDataSetChanged();
    refreshHeaderImages();
    RecentsFragment rFrag = (RecentsFragment) fragMan.findFragmentByTag("recent");
    if (rFrag != null && rFrag.rtAdpater != null) {
        rFrag.rtAdpater.notifyDataSetChanged();
    }
}
Also used : UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack) RecentsFragment(com.sdsmdg.harjot.MusicDNA.fragments.RecentsFragment.RecentsFragment) QueueFragment(com.sdsmdg.harjot.MusicDNA.fragments.QueueFragment.QueueFragment) TextPaint(android.text.TextPaint) PlayerFragment(com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment)

Aggregations

PlayerFragment (com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment)7 QueueFragment (com.sdsmdg.harjot.MusicDNA.fragments.QueueFragment.QueueFragment)4 TextPaint (android.text.TextPaint)3 UnifiedTrack (com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack)3 Handler (android.os.Handler)2 Dialog (android.app.Dialog)1 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 ServiceConnection (android.content.ServiceConnection)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 Canvas (android.graphics.Canvas)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 MediaMetadata (android.media.MediaMetadata)1 Rating (android.media.Rating)1 MediaSession (android.media.session.MediaSession)1 PlaybackState (android.media.session.PlaybackState)1 IBinder (android.os.IBinder)1 NavigationView (android.support.design.widget.NavigationView)1