Android Open Source - Planets-Gradle Video Details Fragment






From Project

Back to project page Planets-Gradle.

License

The source code is released under:

Apache License

If you think the Android project Planets-Gradle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.andrewq.planets.tv;
//  w  w w.j  av  a2 s  .  c  om
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v17.leanback.app.BackgroundManager;
import android.support.v17.leanback.app.DetailsFragment;
import android.support.v17.leanback.widget.Action;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.ClassPresenterSelector;
import android.support.v17.leanback.widget.DetailsOverviewRow;
import android.support.v17.leanback.widget.DetailsOverviewRowPresenter;
import android.support.v17.leanback.widget.HeaderItem;
import android.support.v17.leanback.widget.ListRow;
import android.support.v17.leanback.widget.ListRowPresenter;
import android.support.v17.leanback.widget.OnActionClickedListener;
import android.support.v17.leanback.widget.OnItemClickedListener;
import android.support.v17.leanback.widget.Row;
import android.util.DisplayMetrics;
import android.util.Log;
import android.widget.Toast;

import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;

import java.net.URI;
import java.util.Collections;
import java.util.List;

public class VideoDetailsFragment extends DetailsFragment {
    private static final String TAG = "VideoDetailsFragment";

    private static final int ACTION_WATCH_TRAILER = 1;
    private static final int ACTION_RENT = 2;
    private static final int ACTION_BUY = 3;

    private static final int DETAIL_THUMB_WIDTH = 274;
    private static final int DETAIL_THUMB_HEIGHT = 274;

    private static final int NUM_COLS = 8;

    private static final String MOVIE = "Movie";

    private Planet selectedPlanet;

    private Drawable mDefaultBackground;
    private Target mBackgroundTarget;
    private DisplayMetrics mMetrics;

    public static int dpToPx(int dp, Context ctx) {
        float density = ctx.getResources().getDisplayMetrics().density;
        return Math.round((float) dp * density);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.i(TAG, "onCreate DetailsFragment");
        super.onCreate(savedInstanceState);

        BackgroundManager backgroundManager = BackgroundManager.getInstance(getActivity());
        backgroundManager.attach(getActivity().getWindow());
        mBackgroundTarget = new PicassoBackgroundManagerTarget(backgroundManager);

        mDefaultBackground = getResources().getDrawable(R.drawable.default_background);

        mMetrics = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(mMetrics);

        selectedPlanet = (Planet) getActivity().getIntent().getSerializableExtra(MOVIE);
        new DetailRowBuilderTask().execute(selectedPlanet);

        setOnItemClickedListener(getDefaultItemClickedListener());
        updateBackground(selectedPlanet.getBackgroundImageURI());

    }

    protected OnItemClickedListener getDefaultItemClickedListener() {
        return new OnItemClickedListener() {
            @Override
            public void onItemClicked(Object item, Row row) {
                if (item instanceof Planet) {
                    Planet planet = (Planet) item;
                    Intent intent = new Intent(getActivity(), DetailsActivity.class);
                    intent.putExtra(MOVIE, planet);
                    startActivity(intent);
                }
            }
        };
    }

    protected void updateBackground(URI uri) {
        Log.d(TAG, "uri" + uri);
        Log.d(TAG, "metrics" + mMetrics.toString());
        Picasso.with(getActivity())
                .load(uri.toString())
                .resize(mMetrics.widthPixels, mMetrics.heightPixels)
                .error(mDefaultBackground)
                .centerCrop()
                .into(mBackgroundTarget);
    }

    private class DetailRowBuilderTask extends AsyncTask<Planet, Integer, DetailsOverviewRow> {
        @Override
        protected DetailsOverviewRow doInBackground(Planet... movies) {
            selectedPlanet = movies[0];

            DetailsOverviewRow row = new DetailsOverviewRow(selectedPlanet);
            /*try {
                Bitmap poster = Picasso.with(getActivity())
                        .load(selectedPlanet.getCardImageUrl())
                        .resize(dpToPx(DETAIL_THUMB_WIDTH, getActivity().getApplicationContext()),
                                dpToPx(DETAIL_THUMB_HEIGHT, getActivity().getApplicationContext()))
                        .centerCrop()
                        .get();
                row.setImageBitmap(getActivity(), poster);
            } catch (IOException e) {
            }*/

            //row.addAction(new Action(ACTION_WATCH_TRAILER, "Test!", "Test!"));

            return row;
        }

        @Override
        protected void onPostExecute(DetailsOverviewRow detailRow) {
            ClassPresenterSelector ps = new ClassPresenterSelector();
            DetailsOverviewRowPresenter dorPresenter =
                    new DetailsOverviewRowPresenter(new DetailsDescriptionPresenter());

            SharedPreferences getPrefs2 = PreferenceManager
                    .getDefaultSharedPreferences(getActivity().getBaseContext());

            int theme_chooser = Integer.parseInt(getPrefs2.getString("prefSetTheme", "3"));

            if (theme_chooser == 1)
                dorPresenter.setBackgroundColor(getResources().getColor(R.color.detail_background_red));
            else if (theme_chooser == 2)
                dorPresenter.setBackgroundColor(getResources().getColor(R.color.detail_background_orange));
            else if (theme_chooser == 3)
                dorPresenter.setBackgroundColor(getResources().getColor(R.color.detail_background_blue));
            else if (theme_chooser == 4)
                dorPresenter.setBackgroundColor(getResources().getColor(R.color.detail_background_green));
            else if (theme_chooser == 5)
                dorPresenter.setBackgroundColor(getResources().getColor(R.color.detail_background_purple));
            else if (theme_chooser == 6)
                dorPresenter.setBackgroundColor(getResources().getColor(R.color.detail_background_dark));

            dorPresenter.setStyleLarge(true);
            dorPresenter.setOnActionClickedListener(new OnActionClickedListener() {
                @Override
                public void onActionClicked(Action action) {
                    if (action.getId() == ACTION_WATCH_TRAILER) {

                    }
                    else {
                        Toast.makeText(getActivity(), action.toString(), Toast.LENGTH_SHORT).show();
                    }
                }
            });

            ps.addClassPresenter(DetailsOverviewRow.class, dorPresenter);
            ps.addClassPresenter(ListRow.class,
                    new ListRowPresenter());

            ArrayObjectAdapter adapter = new ArrayObjectAdapter(ps);
            adapter.add(detailRow);

            String subcategories[] = {
                    getString(R.string.related_movies)
            };
            List<Planet> list = PlanetsList.planetList;
            Collections.shuffle(list);
            ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new CardPresenter());

            for (int j = 0; j < NUM_COLS; j++) {
                listRowAdapter.add(list.get(j));
            }

            HeaderItem header = new HeaderItem(0, subcategories[0], null);
            adapter.add(new ListRow(header, listRowAdapter));

            setAdapter(adapter);
        }

    }
}




Java Source Code List

com.andrewq.planets.MainActivity.java
com.andrewq.planets.iab.Base64DecoderException.java
com.andrewq.planets.iab.Base64.java
com.andrewq.planets.iab.IabException.java
com.andrewq.planets.iab.IabHelper.java
com.andrewq.planets.iab.IabResult.java
com.andrewq.planets.iab.Inventory.java
com.andrewq.planets.iab.Purchase.java
com.andrewq.planets.iab.Security.java
com.andrewq.planets.iab.SkuDetails.java
com.andrewq.planets.image_views.DeimosImageView.java
com.andrewq.planets.image_views.EarthImageView.java
com.andrewq.planets.image_views.EuropaImageView.java
com.andrewq.planets.image_views.JupiterImageView.java
com.andrewq.planets.image_views.MarsImageView.java
com.andrewq.planets.image_views.MercuryImageView.java
com.andrewq.planets.image_views.MoonImageView.java
com.andrewq.planets.image_views.NeptuneImageView.java
com.andrewq.planets.image_views.PhobosImageView.java
com.andrewq.planets.image_views.PlutoImageView.java
com.andrewq.planets.image_views.SaturnImageView.java
com.andrewq.planets.image_views.SunImageView.java
com.andrewq.planets.image_views.UranusImageView.java
com.andrewq.planets.image_views.VenusImageView.java
com.andrewq.planets.misc.Settings.java
com.andrewq.planets.moons.DeimosActivity.java
com.andrewq.planets.moons.EuropaActivity.java
com.andrewq.planets.moons.MoonActivity.java
com.andrewq.planets.moons.PhobosActivity.java
com.andrewq.planets.other_bodies.PlutoActivity.java
com.andrewq.planets.other_bodies.SunActivity.java
com.andrewq.planets.planets.EarthActivity.java
com.andrewq.planets.planets.JupiterActivity.java
com.andrewq.planets.planets.MarsActivity.java
com.andrewq.planets.planets.MercuryActivity.java
com.andrewq.planets.planets.NeptuneActivity.java
com.andrewq.planets.planets.SaturnActivity.java
com.andrewq.planets.planets.UranusActivity.java
com.andrewq.planets.planets.VenusActivity.java
com.andrewq.planets.tv.ApplicationTest.java
com.andrewq.planets.tv.CardPresenter.java
com.andrewq.planets.tv.DetailsActivity.java
com.andrewq.planets.tv.DetailsDescriptionPresenter.java
com.andrewq.planets.tv.PicassoBackgroundManagerTarget.java
com.andrewq.planets.tv.Planet.java
com.andrewq.planets.tv.PlanetsFragment.java
com.andrewq.planets.tv.PlanetsList.java
com.andrewq.planets.tv.PlayerActivity.java
com.andrewq.planets.tv.SettingsActivity.java
com.andrewq.planets.tv.TvActivity.java
com.andrewq.planets.tv.Utils.java
com.andrewq.planets.tv.VideoDetailsFragment.java
com.andrewq.planets.util.NotifyingScrollView.java
com.andrewq.planets.util.RowItem.java
com.andrewq.planets.util.SquareImageView.java
com.andrewq.planets.util.ZoomOutPageTransformer.java