Search in sources :

Example 1 with MediaPagerAdapter

use of org.horaapps.leafpic.adapters.MediaPagerAdapter in project LeafPic by HoraApps.

the class SingleMediaActivity method initUI.

private void initUI() {
    setSupportActionBar(toolbar);
    toolbar.bringToFront();
    toolbar.setNavigationIcon(getToolbarIcon(CommunityMaterial.Icon.cmd_arrow_left));
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    setRecentApp(getString(R.string.app_name));
    setupSystemUI();
    getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {

        @Override
        public void onSystemUiVisibilityChange(int visibility) {
            if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
                showSystemUI();
            else
                hideSystemUI();
        }
    });
    adapter = new MediaPagerAdapter(getSupportFragmentManager(), getAlbum().getMedia());
    adapter.setVideoOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (SP.getBoolean("set_internal_player", false)) {
                Intent mpdIntent = new Intent(SingleMediaActivity.this, PlayerActivity.class).setData(getAlbum().getCurrentMedia().getUri());
                startActivity(mpdIntent);
            } else {
                Intent intentOpenWith = new Intent(Intent.ACTION_VIEW);
                intentOpenWith.setDataAndType(getAlbum().getMedia().get(mViewPager.getCurrentItem()).getUri(), getAlbum().getMedia().get(mViewPager.getCurrentItem()).getMimeType());
                startActivity(intentOpenWith);
            }
        }
    });
    getSupportActionBar().setTitle((getAlbum().getCurrentMediaIndex() + 1) + " " + getString(R.string.of) + " " + getAlbum().getMedia().size());
    mViewPager.setAdapter(adapter);
    mViewPager.setCurrentItem(getAlbum().getCurrentMediaIndex());
    mViewPager.setPageTransformer(true, new DepthPageTransformer());
    mViewPager.setOffscreenPageLimit(3);
    mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            getAlbum().setCurrentPhotoIndex(position);
            toolbar.setTitle((position + 1) + " " + getString(R.string.of) + " " + getAlbum().getMedia().size());
            invalidateOptionsMenu();
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    Display aa = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
    if (aa.getRotation() == Surface.ROTATION_90) {
        Configuration configuration = new Configuration();
        configuration.orientation = Configuration.ORIENTATION_LANDSCAPE;
        onConfigurationChanged(configuration);
    }
}
Also used : DepthPageTransformer(org.horaapps.leafpic.animations.DepthPageTransformer) Configuration(android.content.res.Configuration) MediaPagerAdapter(org.horaapps.leafpic.adapters.MediaPagerAdapter) Intent(android.content.Intent) View(android.view.View) HackyViewPager(org.horaapps.leafpic.views.HackyViewPager) ViewPager(android.support.v4.view.ViewPager) WindowManager(android.view.WindowManager) Display(android.view.Display)

Example 2 with MediaPagerAdapter

use of org.horaapps.leafpic.adapters.MediaPagerAdapter in project LeafPic by HoraApps.

the class SingleMediaActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_single_media);
    ButterKnife.bind(this);
    String action = getIntent().getAction();
    if (action != null) {
        switch(action) {
            case ACTION_OPEN_ALBUM:
                loadAlbum(getIntent());
                break;
            case ACTION_OPEN_ALBUM_LAZY:
                loadAlbumsLazy(getIntent());
                break;
            default:
                loadUri(getIntent().getData());
                break;
        }
    }
    if (savedInstanceState != null) {
        mViewPager.setLocked(savedInstanceState.getBoolean(ISLOCKED_ARG, false));
    }
    adapter = new MediaPagerAdapter(getSupportFragmentManager(), media);
    initUi();
}
Also used : MediaPagerAdapter(org.horaapps.leafpic.adapters.MediaPagerAdapter)

Aggregations

MediaPagerAdapter (org.horaapps.leafpic.adapters.MediaPagerAdapter)2 Intent (android.content.Intent)1 Configuration (android.content.res.Configuration)1 ViewPager (android.support.v4.view.ViewPager)1 Display (android.view.Display)1 View (android.view.View)1 WindowManager (android.view.WindowManager)1 DepthPageTransformer (org.horaapps.leafpic.animations.DepthPageTransformer)1 HackyViewPager (org.horaapps.leafpic.views.HackyViewPager)1