Search in sources :

Example 81 with PopupMenu

use of android.support.v7.widget.PopupMenu in project MusicLake by caiyonglong.

the class FolderSongsFragment method listener.

@Override
protected void listener() {
    mAdapter.setOnItemClickListener((adapter, view, position) -> {
        if (view.getId() != R.id.iv_more) {
            PlayManager.setPlayList(musicList);
            PlayManager.play(position);
        }
    });
    mAdapter.setOnItemChildClickListener((adapter, view, position) -> {
        Music music = (Music) adapter.getItem(position);
        PopupMenu popupMenu = new PopupMenu(getContext(), view);
        popupMenu.setOnMenuItemClickListener(item -> {
            switch(item.getItemId()) {
                case R.id.popup_song_play:
                    PlayManager.setPlayList(musicList);
                    PlayManager.play(position);
                    break;
                case R.id.popup_song_detail:
                    ShowDetailDialog.newInstance(musicList.get(position)).show(getChildFragmentManager(), getTag());
                    break;
                case R.id.popup_song_goto_album:
                    Log.e("album", music.toString() + "");
                    NavigateUtil.navigateToAlbum(getActivity(), music.getAlbumId(), music.getAlbum(), null);
                    break;
                case R.id.popup_song_goto_artist:
                    NavigateUtil.navigateToArtist(getActivity(), music.getArtistId(), music.getArtist(), null);
                    break;
                case R.id.popup_song_addto_queue:
                    AddPlaylistDialog.newInstance(music).show(getChildFragmentManager(), "ADD_PLAYLIST");
                    break;
                case R.id.popup_song_delete:
                    new MaterialDialog.Builder(getContext()).title("提示").content("是否移除这首歌曲?").onPositive((dialog, which) -> {
                    }).positiveText("确定").negativeText("取消").show();
                    break;
            }
            return false;
        });
        popupMenu.inflate(R.menu.popup_song);
        popupMenu.show();
    });
}
Also used : LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) R(com.cyl.musiclake.R) FolderSongPresenter(com.cyl.musiclake.ui.music.local.presenter.FolderSongPresenter) ArrayList(java.util.ArrayList) BindView(butterknife.BindView) BaseFragment(com.cyl.musiclake.base.BaseFragment) PopupMenu(android.widget.PopupMenu) View(android.view.View) SongAdapter(com.cyl.musiclake.ui.music.local.adapter.SongAdapter) Log(android.util.Log) PlayManager(com.cyl.musiclake.service.PlayManager) Extras(com.cyl.musiclake.common.Extras) NavigateUtil(com.cyl.musiclake.common.NavigateUtil) Music(com.cyl.musiclake.bean.Music) AddPlaylistDialog(com.cyl.musiclake.ui.music.local.dialog.AddPlaylistDialog) FolderSongsContract(com.cyl.musiclake.ui.music.local.contract.FolderSongsContract) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) AppCompatActivity(android.support.v7.app.AppCompatActivity) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar) ShowDetailDialog(com.cyl.musiclake.ui.music.local.dialog.ShowDetailDialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Music(com.cyl.musiclake.bean.Music) PopupMenu(android.widget.PopupMenu)

Example 82 with PopupMenu

use of android.support.v7.widget.PopupMenu in project memetastic by gsantner.

the class MemeItemAdapter method preparePopupMenu.

private void preparePopupMenu(final ViewHolder holder) {
    final MemeData.Image imageData = (MemeData.Image) holder.imageView.getTag();
    final PopupMenu menu = new PopupMenu(_activity, holder.imageView);
    menu.inflate(R.menu.memeitemadapter__popup_menu);
    ContextUtils.popupMenuEnableIcons(menu);
    menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            switch(menuItem.getItemId()) {
                case R.id.memeitemadapter__popup_menu__action_fav:
                    toggleFavorite(holder);
                    return true;
                case R.id.memeitemadapter__popup_menu__action_hide:
                    int position = holder.getAdapterPosition();
                    toggleHidden(holder, position);
                    ((MainActivity) _activity).updateHiddenNavOption();
                    return true;
                case R.id.memeitemadapter__popup_menu__action_title:
                    MemeData.Image image = (MemeData.Image) holder.imageView.getTag();
                    Toast.makeText(holder.imageView.getContext(), image.conf.getTitle(), Toast.LENGTH_SHORT).show();
                    return true;
            }
            return false;
        }
    });
    View longClickView;
    switch(_itemViewType) {
        case VIEW_TYPE__ROWS_WITH_TITLE:
            {
                longClickView = holder.itemView;
                break;
            }
        case VIEW_TYPE__PICTURE_GRID:
        default:
            {
                longClickView = holder.imageView;
                break;
            }
    }
    longClickView.setOnLongClickListener(new View.OnLongClickListener() {

        public boolean onLongClick(final View v) {
            Menu itemMenu = menu.getMenu();
            boolean isHidden = _app.settings.isHidden(imageData.fullPath.toString());
            boolean isFav = _app.settings.isFavorite(imageData.fullPath.toString());
            boolean isTemplate = imageData.isTemplate;
            itemMenu.findItem(R.id.memeitemadapter__popup_menu__action_hide).setVisible(isTemplate).setTitle(isHidden ? R.string.unhide : R.string.hide);
            itemMenu.findItem(R.id.memeitemadapter__popup_menu__action_fav).setVisible(isTemplate).setTitle(isFav ? R.string.remove_favourite : R.string.favourite);
            menu.show();
            return true;
        }
    });
}
Also used : MemeData(io.github.gsantner.memetastic.data.MemeData) MenuItem(android.view.MenuItem) Menu(android.view.Menu) PopupMenu(android.support.v7.widget.PopupMenu) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) PopupMenu(android.support.v7.widget.PopupMenu)

Example 83 with PopupMenu

use of android.support.v7.widget.PopupMenu in project VirtualApp by asLody.

the class HomeActivity method initMenu.

private void initMenu() {
    mPopupMenu = new PopupMenu(new ContextThemeWrapper(this, R.style.Theme_AppCompat_Light), mMenuView);
    Menu menu = mPopupMenu.getMenu();
    setIconEnable(menu, true);
    menu.add("Accounts").setIcon(R.drawable.ic_account).setOnMenuItemClickListener(item -> {
        List<VUserInfo> users = VUserManager.get().getUsers();
        List<String> names = new ArrayList<>(users.size());
        for (VUserInfo info : users) {
            names.add(info.name);
        }
        CharSequence[] items = new CharSequence[names.size()];
        for (int i = 0; i < names.size(); i++) {
            items[i] = names.get(i);
        }
        new AlertDialog.Builder(this).setTitle("Please select an user").setItems(items, (dialog, which) -> {
            VUserInfo info = users.get(which);
            Intent intent = new Intent(this, ChooseTypeAndAccountActivity.class);
            intent.putExtra(ChooseTypeAndAccountActivity.KEY_USER_ID, info.id);
            startActivity(intent);
        }).show();
        return false;
    });
    menu.add("Virtual Storage").setIcon(R.drawable.ic_vs).setOnMenuItemClickListener(item -> {
        Toast.makeText(this, "The coming", Toast.LENGTH_SHORT).show();
        return false;
    });
    menu.add("Notification").setIcon(R.drawable.ic_notification).setOnMenuItemClickListener(item -> {
        Toast.makeText(this, "The coming", Toast.LENGTH_SHORT).show();
        return false;
    });
    menu.add("Virtual Location").setIcon(R.drawable.ic_notification).setOnMenuItemClickListener(item -> {
        startActivity(new Intent(this, VirtualLocationSettings.class));
        return true;
    });
    menu.add("Settings").setIcon(R.drawable.ic_settings).setOnMenuItemClickListener(item -> {
        Toast.makeText(this, "The coming", Toast.LENGTH_SHORT).show();
        return false;
    });
    mMenuView.setOnClickListener(v -> mPopupMenu.show());
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) VActivity(io.virtualapp.abs.ui.VActivity) Bundle(android.os.Bundle) ChooseTypeAndAccountActivity(com.lody.virtual.client.stub.ChooseTypeAndAccountActivity) PackageAppData(io.virtualapp.home.models.PackageAppData) Animator(android.animation.Animator) LEFT(android.support.v7.widget.helper.ItemTouchHelper.LEFT) END(android.support.v7.widget.helper.ItemTouchHelper.END) OrientationHelper(android.support.v7.widget.OrientationHelper) DOWN(android.support.v7.widget.helper.ItemTouchHelper.DOWN) Handler(android.os.Handler) Looper(android.os.Looper) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) ContextThemeWrapper(android.view.ContextThemeWrapper) View(android.view.View) Canvas(android.graphics.Canvas) EmptyAppData(io.virtualapp.home.models.EmptyAppData) START(android.support.v7.widget.helper.ItemTouchHelper.START) Method(java.lang.reflect.Method) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) ACTION_STATE_DRAG(android.support.v7.widget.helper.ItemTouchHelper.ACTION_STATE_DRAG) ObjectAnimator(android.animation.ObjectAnimator) PopupMenu(android.support.v7.widget.PopupMenu) VCommends(io.virtualapp.VCommends) ViewGroup(android.view.ViewGroup) List(java.util.List) TextView(android.widget.TextView) Nullable(android.support.annotation.Nullable) RIGHT(android.support.v7.widget.helper.ItemTouchHelper.RIGHT) VUserInfo(com.lody.virtual.os.VUserInfo) Context(android.content.Context) VirtualLocationSettings(io.virtualapp.home.location.VirtualLocationSettings) UP(android.support.v7.widget.helper.ItemTouchHelper.UP) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) Intent(android.content.Intent) AppInfoLite(io.virtualapp.home.models.AppInfoLite) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) GmsSupport(com.lody.virtual.GmsSupport) Toast(android.widget.Toast) Menu(android.view.Menu) AddAppButton(io.virtualapp.home.models.AddAppButton) TwoGearsView(io.virtualapp.widgets.TwoGearsView) VUserManager(com.lody.virtual.os.VUserManager) LaunchpadAdapter(io.virtualapp.home.adapters.LaunchpadAdapter) AppData(io.virtualapp.home.models.AppData) ItemOffsetDecoration(io.virtualapp.home.adapters.decorations.ItemOffsetDecoration) Color(android.graphics.Color) RecyclerView(android.support.v7.widget.RecyclerView) AlertDialog(android.support.v7.app.AlertDialog) R(io.virtualapp.R) SmartRecyclerAdapter(io.virtualapp.abs.nestedadapter.SmartRecyclerAdapter) VUiKit(io.virtualapp.abs.ui.VUiKit) ChooseTypeAndAccountActivity(com.lody.virtual.client.stub.ChooseTypeAndAccountActivity) ArrayList(java.util.ArrayList) Intent(android.content.Intent) VirtualLocationSettings(io.virtualapp.home.location.VirtualLocationSettings) SuppressLint(android.annotation.SuppressLint) ContextThemeWrapper(android.view.ContextThemeWrapper) PopupMenu(android.support.v7.widget.PopupMenu) Menu(android.view.Menu) PopupMenu(android.support.v7.widget.PopupMenu) VUserInfo(com.lody.virtual.os.VUserInfo)

Example 84 with PopupMenu

use of android.support.v7.widget.PopupMenu in project HoloEverywhere by Prototik.

the class MenusFragments method onHandleData.

@Override
protected void onHandleData() {
    addItem("PopupMenu", new OnOtherItemClickListener() {

        @Override
        public void onClick(OtherItem otherItem) {
            PopupMenu menu = new PopupMenu(getSupportActivity(), otherItem.lastView);
            mDemoMenuHelper.makeMenu(menu.getMenu(), getMenuInflater());
            menu.show();
        }
    });
    addItem("ContextMenu", mContextMenuListener);
    addItemWithLongClick("ContextMenu (long click)", mContextMenuListener);
}
Also used : PopupMenu(android.support.v7.widget.PopupMenu)

Example 85 with PopupMenu

use of android.support.v7.widget.PopupMenu in project MusicDNA by harjot-oberai.

the class PlayerFragment method onViewCreated.

@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    imgLoader = new ImageLoader(getContext());
    smallPlayer = (RelativeLayout) view.findViewById(R.id.smallPlayer);
    snappyRecyclerView = (SnappyRecyclerView) view.findViewById(R.id.visualizer_recycler);
    bufferingIndicator = (AVLoadingIndicatorView) view.findViewById(R.id.bufferingIndicator);
    currTime = (TextView) view.findViewById(R.id.currTime);
    totalTime = (TextView) view.findViewById(R.id.totalTime);
    repeatController = (ImageView) view.findViewById(R.id.repeat_controller);
    shuffleController = (ImageView) view.findViewById(R.id.shuffle_controller);
    spToolbar = (RelativeLayout) view.findViewById(R.id.smallPlayer_AB);
    overflowMenuAB = (ImageView) view.findViewById(R.id.menuIcon);
    lyricsContainer = (RelativeLayout) view.findViewById(R.id.lyrics_container);
    lyricsIcon = (ImageView) view.findViewById(R.id.lyrics_icon);
    lyricsContent = (TextView) view.findViewById(R.id.lyrics_content);
    lyricsLoadingIndicator = (AVLoadingIndicatorView) view.findViewById(R.id.lyrics_loading_indicator);
    lyricsStatus = (TextView) view.findViewById(R.id.lyrics_status_text);
    lyricsIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!isLyricsVisisble) {
                lyricsIcon.setAlpha(1.0f);
                mVisualizerView.setVisibility(View.GONE);
                lyricsContainer.setVisibility(View.VISIBLE);
                lyricsLoadingIndicator.setVisibility(View.VISIBLE);
                lyricsStatus.setText("Searching Lyrics");
                lyricsStatus.setVisibility(View.VISIBLE);
                if (currentLyrics == null) {
                    downloadThread = new DownloadThread(PlayerFragment.this, false, selected_track_artist.getText().toString(), selected_track_title.getText().toString());
                    downloadThread.start();
                } else {
                    onLyricsDownloaded(currentLyrics);
                }
            } else {
                lyricsIcon.setAlpha(0.5f);
                lyricsContent.setText("");
                lyricsContainer.setVisibility(View.GONE);
                mVisualizerView.setVisibility(View.VISIBLE);
            }
            isLyricsVisisble = !isLyricsVisisble;
        }
    });
    spImgAB = (ImageView) view.findViewById(R.id.selected_track_image_sp_AB);
    spImgAB.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!homeActivity.isPlayerTransitioning && smallPlayer != null) {
                homeActivity.hidePlayer();
                homeActivity.isPlayerVisible = false;
            }
        }
    });
    spTitleAB = (TextView) view.findViewById(R.id.selected_track_title_sp_AB);
    spTitleAB.setSelected(true);
    spArtistAB = (TextView) view.findViewById(R.id.selected_track_artist_sp_AB);
    if (homeActivity.shuffleEnabled) {
        shuffleController.setImageResource(R.drawable.ic_shuffle_filled);
    } else {
        shuffleController.setImageResource(R.drawable.ic_shuffle_alpha);
    }
    if (homeActivity.repeatEnabled) {
        repeatController.setImageResource(R.drawable.ic_repeat_filled);
    } else if (homeActivity.repeatOnceEnabled) {
        repeatController.setImageResource(R.drawable.ic_repeat_once);
    } else {
        repeatController.setImageResource(R.drawable.ic_repeat_alpha);
    }
    repeatController.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (homeActivity.repeatOnceEnabled) {
                homeActivity.repeatOnceEnabled = false;
                repeatController.setImageResource(R.drawable.ic_repeat_alpha);
            } else if (homeActivity.repeatEnabled) {
                homeActivity.repeatEnabled = false;
                homeActivity.repeatOnceEnabled = true;
                repeatController.setImageResource(R.drawable.ic_repeat_once);
            } else {
                homeActivity.repeatEnabled = true;
                repeatController.setImageResource(R.drawable.ic_repeat_filled);
            }
        }
    });
    shuffleController.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (homeActivity.shuffleEnabled) {
                homeActivity.shuffleEnabled = false;
                shuffleController.setImageResource(R.drawable.ic_shuffle_alpha);
                mCallback.onShuffleDisabled();
            } else {
                homeActivity.shuffleEnabled = true;
                shuffleController.setImageResource(R.drawable.ic_shuffle_filled);
                mCallback.onShuffleEnabled();
            }
            snappyRecyclerView.scrollToPosition(HomeActivity.queueCurrentIndex);
            snappyRecyclerView.setCurrentPosition(HomeActivity.queueCurrentIndex);
            customAdapter.notifyDataSetChanged();
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    snappyRecyclerView.setTransparency();
                }
            }, 400);
        }
    });
    equalizerIcon = (ImageView) view.findViewById(R.id.equalizer_icon);
    equalizerIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mCallback.onEqualizerClicked();
        }
    });
    equalizerIcon.setVisibility(View.INVISIBLE);
    saveDNAToggle = (ImageView) view.findViewById(R.id.toggleSaveDNA);
    if (homeActivity.isSaveDNAEnabled) {
        saveDNAToggle.setImageResource(R.drawable.ic_save_filled);
    } else {
        saveDNAToggle.setImageResource(R.drawable.ic_save_alpha);
    }
    saveDNAToggle.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (homeActivity.isSaveDNAEnabled) {
                homeActivity.isSaveDNAEnabled = false;
                saveDNAToggle.setImageResource(R.drawable.ic_save_alpha);
            } else {
                homeActivity.isSaveDNAEnabled = true;
                saveDNAToggle.setImageResource(R.drawable.ic_save_filled);
            }
        }
    });
    mainTrackController = (ImageView) view.findViewById(R.id.controller);
    nextTrackController = (ImageView) view.findViewById(R.id.next);
    previousTrackController = (ImageView) view.findViewById(R.id.previous);
    isFav = false;
    favouriteIcon = (ImageView) view.findViewById(R.id.fav_icon);
    favControllerSp = (ImageView) view.findViewById(R.id.fav_controller_sp);
    if (homeActivity.isFavourite) {
        favouriteIcon.setImageResource(R.drawable.ic_heart_filled_1);
        favControllerSp.setImageResource(R.drawable.ic_heart_filled_1);
        isFav = true;
    } else {
        favouriteIcon.setImageResource(R.drawable.ic_heart_alpha);
        favControllerSp.setImageResource(R.drawable.ic_heart_alpha);
        isFav = false;
    }
    favouriteIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isFav) {
                favouriteIcon.setImageResource(R.drawable.ic_heart_alpha);
                favControllerSp.setImageResource(R.drawable.ic_heart_alpha);
                isFav = false;
                removeFromFavourite();
            } else {
                favouriteIcon.setImageResource(R.drawable.ic_heart_filled_1);
                favControllerSp.setImageResource(R.drawable.ic_heart_filled_1);
                isFav = true;
                addToFavourite();
            }
            new HomeActivity.SaveFavourites().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    });
    favControllerSp.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isFav) {
                favouriteIcon.setImageResource(R.drawable.ic_heart_alpha);
                favControllerSp.setImageResource(R.drawable.ic_heart_alpha);
                isFav = false;
                removeFromFavourite();
            } else {
                favouriteIcon.setImageResource(R.drawable.ic_heart_filled_1);
                favControllerSp.setImageResource(R.drawable.ic_heart_filled_1);
                isFav = true;
                addToFavourite();
            }
            new HomeActivity.SaveFavourites().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    });
    queueIcon = (ImageView) view.findViewById(R.id.queue_icon);
    queueIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mCallback.onQueueClicked();
        }
    });
    selected_track_image = (ImageView) view.findViewById(R.id.selected_track_image_sp);
    selected_track_title = (TextView) view.findViewById(R.id.selected_track_title_sp);
    selected_track_artist = (TextView) view.findViewById(R.id.selected_track_artist_sp);
    player_controller = (ImageView) view.findViewById(R.id.player_control_sp);
    nextControllerSp = (ImageView) view.findViewById(R.id.next_controller_sp);
    nextControllerSp.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mMediaPlayer.pause();
            homeActivity.nextControllerClicked = true;
            mCallback.onComplete();
        }
    });
    bottomContainer = (RelativeLayout) view.findViewById(R.id.mainControllerContainer);
    seekBarContainer = (RelativeLayout) view.findViewById(R.id.seekBarContainer);
    toggleContainer = (RelativeLayout) view.findViewById(R.id.toggleContainer);
    mVisualizerView = (VisualizerView) view.findViewById(R.id.myvisualizerview);
    VisualizerView.w = HomeActivity.screen_width;
    VisualizerView.h = HomeActivity.screen_height;
    VisualizerView.conf = Bitmap.Config.ARGB_8888;
    VisualizerView.bmp = Bitmap.createBitmap(VisualizerView.w, VisualizerView.h, VisualizerView.conf);
    HomeActivity.cacheCanvas = new Canvas(VisualizerView.bmp);
    if (HomeActivity.queue != null) {
        customAdapter = new CustomAdapter(getContext(), snappyRecyclerView, HomeActivity.queue.getQueue());
    } else {
        customAdapter = new CustomAdapter(getContext(), snappyRecyclerView, new ArrayList<UnifiedTrack>());
    }
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
    snappyRecyclerView.setLayoutManager(linearLayoutManager);
    snappyRecyclerView.setItemAnimator(new DefaultItemAnimator());
    snappyRecyclerView.setAdapter(customAdapter);
    snappyRecyclerView.setActivity(homeActivity);
    snappyRecyclerView.addOnItemTouchListener(new ClickItemTouchListener(snappyRecyclerView) {

        @Override
        public boolean onClick(RecyclerView parent, View view, int position, long id) {
            return false;
        }

        @Override
        public boolean onLongClick(RecyclerView parent, View view, int position, long id) {
            if (homeActivity.isFullScreenEnabled) {
                homeActivity.isFullScreenEnabled = false;
                bottomContainer.setVisibility(View.VISIBLE);
                seekBarContainer.setVisibility(View.VISIBLE);
                toggleContainer.setVisibility(View.VISIBLE);
                spToolbar.setVisibility(View.VISIBLE);
                mCallback.onFullScreen();
            } else {
                homeActivity.isFullScreenEnabled = true;
                bottomContainer.setVisibility(View.GONE);
                seekBarContainer.setVisibility(View.GONE);
                toggleContainer.setVisibility(View.GONE);
                spToolbar.setVisibility(View.INVISIBLE);
                mCallback.onFullScreen();
            }
            return true;
        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
        }
    });
    cpb = (CustomProgressBar) view.findViewById(R.id.customProgress);
    smallPlayer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mCallback.onSmallPlayerTouched();
        }
    });
    track = homeActivity.selectedTrack;
    localTrack = homeActivity.localSelectedTrack;
    if (homeActivity.streamSelected) {
        try {
            durationInMilliSec = track.getDuration();
        } catch (Exception e) {
        }
        if (track.getArtworkURL() != null) {
            Picasso.with(getActivity()).load(track.getArtworkURL()).resize(100, 100).into(selected_track_image);
        } else {
            selected_track_image.setImageResource(R.drawable.ic_default);
        }
        try {
            spTitleAB.setText(track.getTitle());
            selected_track_title.setText(track.getTitle());
            selected_track_artist.setText("");
            spArtistAB.setText("");
        } catch (Exception e) {
        }
    } else {
        try {
            durationInMilliSec = (int) localTrack.getDuration();
        } catch (Exception e) {
        }
        try {
            imgLoader.DisplayImage(localTrack.getPath(), selected_track_image);
        } catch (Exception e) {
        }
        try {
            spTitleAB.setText(localTrack.getTitle());
            selected_track_title.setText(localTrack.getTitle());
            selected_track_artist.setText(localTrack.getArtist());
            spArtistAB.setText(localTrack.getArtist());
        } catch (Exception e) {
        }
    }
    temp = getTime(durationInMilliSec);
    totalTime.setText(temp.first + ":" + temp.second);
    homeActivity.mWifi = homeActivity.connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    try {
        if (homeActivity.streamSelected) {
            if ((homeActivity.settings.isStreamOnlyOnWifiEnabled() && homeActivity.mWifi.isConnected()) || !homeActivity.settings.isStreamOnlyOnWifiEnabled()) {
                isPrepared = false;
                mMediaPlayer.reset();
                mMediaPlayer.setDataSource(track.getStreamURL() + "?client_id=" + Config.CLIENT_ID);
                mMediaPlayer.prepareAsync();
            } else {
                mMediaPlayer.pause();
                homeActivity.nextControllerClicked = true;
                mCallback.onComplete();
            }
        } else {
            isPrepared = false;
            mMediaPlayer.reset();
            File f = new File(localTrack.getPath());
            if (f.exists()) {
                mMediaPlayer.setDataSource(localTrack.getPath());
                mMediaPlayer.prepareAsync();
            } else {
                Toast.makeText(getContext(), "Error playing " + localTrack.getTitle() + ". Skipping to next track", Toast.LENGTH_SHORT).show();
                mMediaPlayer.pause();
                homeActivity.nextControllerClicked = true;
                mCallback.onComplete();
            }
        }
        bufferingIndicator.setVisibility(View.VISIBLE);
        mainTrackController.setVisibility(View.GONE);
    } catch (Exception e) {
        e.printStackTrace();
    }
    overflowMenuAB.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PopupMenu popMenu = new PopupMenu(getContext(), overflowMenuAB);
            popMenu.getMenuInflater().inflate(R.menu.player_overflow_menu, popMenu.getMenu());
            popMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    if (item.getTitle().equals("Full Screen")) {
                        if (homeActivity.isFullScreenEnabled) {
                            homeActivity.isFullScreenEnabled = false;
                            bottomContainer.setVisibility(View.VISIBLE);
                            seekBarContainer.setVisibility(View.VISIBLE);
                            toggleContainer.setVisibility(View.VISIBLE);
                            spToolbar.setVisibility(View.VISIBLE);
                            mCallback.onFullScreen();
                        } else {
                            homeActivity.isFullScreenEnabled = true;
                            bottomContainer.setVisibility(View.GONE);
                            seekBarContainer.setVisibility(View.GONE);
                            toggleContainer.setVisibility(View.GONE);
                            spToolbar.setVisibility(View.INVISIBLE);
                            mCallback.onFullScreen();
                        }
                    } else if (item.getTitle().equals("Settings")) {
                        mCallback.onSettingsClicked();
                    } else if (item.getTitle().equals("Add to playlist")) {
                        UnifiedTrack ut = HomeActivity.queue.getQueue().get(HomeActivity.queueCurrentIndex);
                        mCallback.addCurrentSongtoPlaylist(ut);
                    }
                    return true;
                }
            });
            popMenu.show();
        }
    });
    player_controller.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isReplayIconVisible) {
                homeActivity.hasQueueEnded = true;
                mCallback.onComplete();
            } else {
                if (!pauseClicked) {
                    pauseClicked = true;
                }
                togglePlayPause();
            }
        }
    });
    mainTrackController.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isReplayIconVisible) {
                homeActivity.hasQueueEnded = true;
                mCallback.onComplete();
            } else {
                if (!pauseClicked) {
                    pauseClicked = true;
                }
                togglePlayPause();
            }
        }
    });
    nextTrackController.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mMediaPlayer.pause();
            homeActivity.nextControllerClicked = true;
            mCallback.onComplete();
        }
    });
    previousTrackController.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (homeActivity.queueCurrentIndex != 0) {
                mMediaPlayer.pause();
                mCallback.onPreviousTrack();
            }
        }
    });
    progressBar = (SeekBar) view.findViewById(R.id.progressBar);
    progressBar.setMax(durationInMilliSec);
    timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask() {

        public void run() {
            if (isPrepared && !isTracking && getActivity() != null) {
                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        float[] hsv = new float[3];
                        hsv[0] = homeActivity.seekBarColor;
                        hsv[1] = (float) 0.8;
                        hsv[2] = (float) 0.5;
                        progressBar.getProgressDrawable().setColorFilter(new PorterDuffColorFilter(Color.HSVToColor(hsv), PorterDuff.Mode.SRC_IN));
                        cpb.update();
                    }
                });
                try {
                    temp = getTime(mMediaPlayer.getCurrentPosition());
                    getActivity().runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            currTime.setText(temp.first + ":" + temp.second);
                        }
                    });
                    progressBar.setProgress(mMediaPlayer.getCurrentPosition());
                } catch (Exception e) {
                    Log.e("MEDIA", e.getMessage() + ":");
                }
            }
        }
    }, 0, 50);
    progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            temp = getTime(progress);
            getActivity().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    currTime.setText(temp.first + ":" + temp.second);
                }
            });
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            isTracking = true;
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            mMediaPlayer.seekTo(seekBar.getProgress());
            if (mMediaPlayer.isPlaying())
                mMediaPlayer.start();
            isTracking = false;
        }
    });
    final Button mEndButton = new Button(getContext());
    mEndButton.setBackgroundColor(homeActivity.themeColor);
    mEndButton.setTextColor(Color.WHITE);
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            showCase = new ShowcaseView.Builder(getActivity()).blockAllTouches().singleShot(2).setStyle(R.style.CustomShowcaseTheme).useDecorViewAsParent().replaceEndButton(mEndButton).setContentTitlePaint(homeActivity.tp).setTarget(new ViewTarget(mVisualizerView.getId(), getActivity())).setContentTitle("The DNA").setContentText("The DNA of the currently playing song.").build();
            showCase.setButtonText("Next");
            showCase.setButtonPosition(homeActivity.lps);
            showCase.overrideButtonClick(new View.OnClickListener() {

                int count1 = -1;

                @Override
                public void onClick(View v) {
                    count1++;
                    switch(count1) {
                        case 0:
                            showCase.setTarget(new ViewTarget(mVisualizerView.getId(), getActivity()));
                            showCase.setContentTitle("The DNA");
                            showCase.setContentText("Swipe Left or Right to change Song." + "Long Press for fullscreen");
                            showCase.setButtonPosition(homeActivity.lps);
                            showCase.setButtonText("Next");
                            break;
                        case 1:
                            showCase.setTarget(new ViewTarget(R.id.toggleContainer, getActivity()));
                            showCase.setContentTitle("The Controls");
                            showCase.setContentText("Equalizer \n" + "Save DNA toggle\n" + "Add to Favourites \n" + "Queue");
                            showCase.setButtonPosition(homeActivity.lps);
                            showCase.setButtonText("Done");
                            break;
                        case 2:
                            showCase.setTarget(new ViewTarget(R.id.lyrics_icon, getActivity()));
                            showCase.setContentTitle("Lyrics");
                            showCase.setContentText("Get lyrics by tapping this icon");
                            showCase.setButtonPosition(homeActivity.lps);
                            showCase.setButtonText("Done");
                            break;
                        case 3:
                            showCase.hide();
                            break;
                    }
                }
            });
        }
    }, 500);
}
Also used : ArrayList(java.util.ArrayList) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) ViewTarget(com.github.amlcurran.showcaseview.targets.ViewTarget) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) CustomAdapter(com.sdsmdg.harjot.MusicDNA.snappyrecyclerview.CustomAdapter) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) DownloadThread(com.sdsmdg.harjot.MusicDNA.utilities.DownloadThread) TimerTask(java.util.TimerTask) Button(android.widget.Button) ClickItemTouchListener(com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener) SeekBar(android.widget.SeekBar) Canvas(android.graphics.Canvas) Handler(android.os.Handler) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) View(android.view.View) TextView(android.widget.TextView) AVLoadingIndicatorView(com.wang.avi.AVLoadingIndicatorView) VisualizerView(com.sdsmdg.harjot.MusicDNA.visualizers.VisualizerView) RecyclerView(android.support.v7.widget.RecyclerView) SnappyRecyclerView(com.sdsmdg.harjot.MusicDNA.snappyrecyclerview.SnappyRecyclerView) Timer(java.util.Timer) UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack) RecyclerView(android.support.v7.widget.RecyclerView) SnappyRecyclerView(com.sdsmdg.harjot.MusicDNA.snappyrecyclerview.SnappyRecyclerView) ImageLoader(com.sdsmdg.harjot.MusicDNA.imageloader.ImageLoader) File(java.io.File) PopupMenu(android.widget.PopupMenu)

Aggregations

PopupMenu (android.support.v7.widget.PopupMenu)142 MenuItem (android.view.MenuItem)116 View (android.view.View)86 TextView (android.widget.TextView)63 RecyclerView (android.support.v7.widget.RecyclerView)54 ImageView (android.widget.ImageView)40 Intent (android.content.Intent)32 PopupMenu (android.widget.PopupMenu)31 List (java.util.List)27 ArrayList (java.util.ArrayList)26 MenuInflater (android.view.MenuInflater)23 Menu (android.view.Menu)22 Bundle (android.os.Bundle)20 LayoutInflater (android.view.LayoutInflater)20 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)20 Context (android.content.Context)18 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)18 AdapterView (android.widget.AdapterView)17 DialogInterface (android.content.DialogInterface)16 ViewGroup (android.view.ViewGroup)15