public class BrowseActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.browser_fragment);

        IO.getInstance();
    }

} public class DetailActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.detail_activity);
    }

} public class OldDetailViewExampleActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail_example);
    }
} public class DialogExampleActivity extends Activity {

    @Override public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#21272A")));

        if (savedInstanceState == null) {
            GuidedStepFragment fragment = new DialogExampleFragment();
            GuidedStepFragment.addAsRoot(this, fragment, android.R.id.content);
        }
    }
} public class VideoExampleActivity extends Activity {

    public static final String TAG = "VideoExampleActivity";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_example);

        FragmentTransaction ft1 = getFragmentManager().beginTransaction();
        ft1.replace(R.id.videoFragment, new VideoSurfaceFragment(), VideoSurfaceFragment.TAG);
        ft1.commit();

        FragmentTransaction ft2 = getFragmentManager().beginTransaction();
        ft2.add(R.id.videoFragment, new VideoConsumptionExampleFragment(), VideoConsumptionExampleFragment.TAG);
        ft2.commit();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        // This part is necessary to ensure that getIntent returns the latest intent when
        // VideoExampleActivity is started. By default, getIntent() returns the initial intent
        // that was set from another activity that started VideoExampleActivity. However, we need
        // to update this intent when for example, user clicks on another video when the currently
        // playing video is in PIP mode, and a new video needs to be started.
        setIntent(intent);
    }

    public static boolean supportsPictureInPicture(Context context) {
        return BuildCompat.isAtLeastN() &&
                context.getPackageManager().hasSystemFeature(
                        PackageManager.FEATURE_PICTURE_IN_PICTURE);
    }

} public class SettingsExampleActivity extends Activity {

    @Override public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings_example);
    }
} public class WizardExampleActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setBackgroundDrawableResource(R.drawable.wizard_background_blackned);

        GuidedStepFragment fragment = new WizardExample1stStepFragment();
        fragment.setArguments(getIntent().getExtras()); // Delegate OldMovie to first step.
        GuidedStepFragment.addAsRoot(this, fragment, android.R.id.content);
    }

    @Override
    public void onBackPressed() {
        if (GuidedStepFragment.getCurrentGuidedStepFragment(getFragmentManager())
                instanceof WizardExample4thStepFragment) {
            // The user 'bought' the product. When he presses 'Back' the Wizard will be closed and
            // he will not be send back to 'Processing Payment...'-Screen.
            finish();
        } else super.onBackPressed();
    }

} public class OldCardPresenterSelector extends PresenterSelector {

    private final Context mContext;
    private final HashMap<OldCard.Type, Presenter> presenters = new HashMap<OldCard.Type, Presenter>();

    public OldCardPresenterSelector(Context context) {
        mContext = context;
    }

    @Override
    public Presenter getPresenter(Object item) {
        if (!(item instanceof OldCard)) throw new RuntimeException(
                String.format("The PresenterSelector only supports data items of type '%s'",
                        OldCard.class.getName()));
        OldCard oldCard = (OldCard) item;
        Presenter presenter = presenters.get(oldCard.getType());
        if (presenter == null) {
            switch (oldCard.getType()) {
                case SINGLE_LINE:
                    presenter = new OldSingleLineCardPresenterOldOld(mContext);
                    break;
                case VIDEO_GRID:
                    presenter = new OldVideoCardViewPresenterOldOld(mContext, R.style.VideoGridCardTheme);
                    break;
                case MOVIE:
                case MOVIE_BASE:
                case MOVIE_COMPLETE:
                case SQUARE_BIG:
                case GRID_SQUARE:
                case GAME: {
                    int themeResId = R.style.MovieCardSimpleTheme;
                    if (oldCard.getType() == OldCard.Type.MOVIE_BASE) {
                        themeResId = R.style.MovieCardBasicTheme;
                    } else if (oldCard.getType() == OldCard.Type.MOVIE_COMPLETE) {
                        themeResId = R.style.MovieCardCompleteTheme;
                    } else if (oldCard.getType() == OldCard.Type.SQUARE_BIG) {
                        themeResId = R.style.SquareBigCardTheme;
                    } else if (oldCard.getType() == OldCard.Type.GRID_SQUARE) {
                        themeResId = R.style.GridCardTheme;
                    } else if (oldCard.getType() == OldCard.Type.GAME) {
                        themeResId = R.style.GameCardTheme;
                    }
                    presenter = new OldImageCardViewPresenterOld(mContext, themeResId);
                    break;
                }
                case SIDE_INFO:
                    presenter = new OldSideInfoCardPresenterOld(mContext);
                    break;
                case TEXT:
                    presenter = new OldTextCardPresenterOld(mContext);
                    break;
                case ICON:
                    presenter = new OldIconCardPresenterOldOld(mContext);
                    break;
                case CHARACTER:
                    presenter = new OldCharacterCardPresenterOld(mContext);
                    break;
                default:
                    presenter = new OldImageCardViewPresenterOld(mContext);
                    break;
            }
        }
        presenters.put(oldCard.getType(), presenter);
        return presenter;
    }

} public class OldCard {

    @SerializedName("title") private String mTitle = "";
    @SerializedName("description") private String mDescription = "";
    @SerializedName("extraText") private String mExtraText = "";
    @SerializedName("card") private String mImageUrl;
    @SerializedName("footerColor") private String mFooterColor = null;
    @SerializedName("selectedColor") private String mSelectedColor = null;
    @SerializedName("localImageResource") private String mLocalImageResource = null;
    @SerializedName("image") private String image = null;
    @SerializedName("footerIconLocalImageResource") private String mFooterResource = null;
    @SerializedName("type") private OldCard.Type mType;
    @SerializedName("id") private int mId;
    @SerializedName("width") private int mWidth;
    @SerializedName("height") private int mHeight;
    @SerializedName("imdbId") private String imdbId;

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getImdbId() {
        return imdbId.substring(2);
    }

    public void setImdbId(String imdbId) {
        this.imdbId = imdbId;
    }

    public String getTitle() {
        return mTitle;
    }

    public void setTitle(String title) {
        mTitle = title;
    }

    public String getLocalImageResource() {
        return mLocalImageResource;
    }

    public void setLocalImageResource(String localImageResource) {
        mLocalImageResource = localImageResource;
    }

    public String getFooterResource() {
        return mFooterResource;
    }

    public void setFooterResource(String footerResource) {
        mFooterResource = footerResource;
    }

    public void setType(Type type) {
        mType = type;
    }

    public void setId(int id) {
        mId = id;
    }

    public void setWidth(int width) {
        mWidth = width;
    }

    public void setHeight(int height) {
        mHeight = height;
    }

    public int getWidth() {
        return mWidth;
    }

    public int getHeight() {
        return mHeight;
    }

    public int getId() {
        return mId;
    }

    public OldCard.Type getType() {
        return mType;
    }

    public String getDescription() {
        return mDescription;
    }

    public void setDescription(String description) {
        mDescription = description;
    }


    public String getExtraText() {
        return mExtraText;
    }

    public void setExtraText(String extraText) {
        mExtraText = extraText;
    }

    public int getFooterColor() {
        if (mFooterColor == null) return -1;
        return Color.parseColor(mFooterColor);
    }

    public void setFooterColor(String footerColor) {
        mFooterColor = footerColor;
    }

    public int getSelectedColor() {
        if (mSelectedColor == null) return -1;
        return Color.parseColor(mSelectedColor);
    }

    public String getImageUrl() {
        return mImageUrl;
    }

    public void setSelectedColor(String selectedColor) {
        mSelectedColor = selectedColor;
    }

    public void setImageUrl(String imageUrl) {
        mImageUrl = imageUrl;
    }

    public URI getImageURI() {
        if (getImageUrl() == null) return null;
        try {
            return new URI(getImageUrl());
        } catch (URISyntaxException e) {
            Log.d("URI exception: ", getImageUrl());
            return null;
        }
    }

    public int getLocalImageResourceId(Context context) {
        return context.getResources().getIdentifier(getLocalImageResourceName(), "drawable",
                                                    context.getPackageName());
    }

    public String getLocalImageResourceName() {
        return mLocalImageResource;
    }

    public String getFooterLocalImageResourceName() {
        return mFooterResource;
    }

    public enum Type {

        MOVIE_COMPLETE,
        MOVIE,
        MOVIE_BASE,
        ICON,
        SQUARE_BIG,
        SINGLE_LINE,
        GAME,
        SQUARE_SMALL,
        DEFAULT,
        SIDE_INFO,
        SIDE_INFO_TEST_1,
        TEXT,
        CHARACTER,
        GRID_SQUARE,
        VIDEO_GRID

    }

} public class OldCardRow {

    // default is a list of cards
    public static final int TYPE_DEFAULT = 0;
    // section header
    public static final int TYPE_SECTION_HEADER = 1;
    // divider
    public static final int TYPE_DIVIDER = 2;

    @SerializedName("type") private int mType = TYPE_DEFAULT;
    // Used to determine whether the row shall use shadows when displaying its cards or not.
    @SerializedName("shadow") private boolean mShadow = true;
    @SerializedName("title") private String mTitle;
    @SerializedName("cards") private List<OldCard> mOldCards;

    public int getType() {
        return mType;
    }

    public String getTitle() {
        return mTitle;
    }

    public boolean useShadow() {
        return mShadow;
    }

    public List<OldCard> getCards() {
        return mOldCards;
    }

} public class OldMovie implements Serializable {

    private static final long serialVersionUID = 133742L;

    @SerializedName("title")
    private String mTitle = "";
    @SerializedName("price_hd")
    private String mPriceHd = "n/a";
    @SerializedName("price_sd")
    private String mPriceSd = "n/a";
    @SerializedName("breadcrump")
    private String mBreadcrump = "";

    public String getTitle() {
        return mTitle;
    }

    public String getBreadcrump() {
        return mBreadcrump;
    }

    public String getPriceHd() {
        return mPriceHd;
    }

    public String getPriceSd() {
        return mPriceSd;
    }

} public class Utils {

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

    /**
     * Will read the content from a given {@link InputStream} and return it as a {@link String}.
     *
     * @param inputStream The {@link InputStream} which should be read.
     * @return Returns <code>null</code> if the the {@link InputStream} could not be read. Else
     * returns the content of the {@link InputStream} as {@link String}.
     */
    public static String inputStreamToString(InputStream inputStream) {
        try {
            byte[] bytes = new byte[inputStream.available()];
            inputStream.read(bytes, 0, bytes.length);
            String json = new String(bytes);
            return json;
        } catch (IOException e) {
            return null;
        }
    }

    public static Uri getResourceUri(Context context, int resID) {
        return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
                                 context.getResources().getResourcePackageName(resID) + '/' +
                                 context.getResources().getResourceTypeName(resID) + '/' +
                                 context.getResources().getResourceEntryName(resID));
    }

    public static boolean hasPermission(final Context context, final String permission) {
        return PackageManager.PERMISSION_GRANTED == context.getPackageManager().checkPermission(
                permission, context.getPackageName());
    }
}
import android.content.Intent;
import android.os.Bundle;
import android.support.v17.leanback.app.BrowseFragment;
import android.support.v17.leanback.streamingapp.R;
import android.support.v17.leanback.streamingapp.app.BrowseActivity;
import android.support.v17.leanback.streamingapp.app.detail.DetailActivity;
import android.support.v17.leanback.streamingapp.old.oldapp.olddetails.OldDetailViewExampleActivity;
import android.support.v17.leanback.streamingapp.old.oldapp.olddialog.DialogExampleActivity;
import android.support.v17.leanback.streamingapp.old.oldapp.oldmedia.VideoExampleActivity;
import android.support.v17.leanback.streamingapp.old.oldapp.oldsettings.SettingsExampleActivity;
import android.support.v17.leanback.streamingapp.old.oldapp.oldwizard.WizardExampleActivity;
import android.support.v17.leanback.streamingapp.old.oldcards.presenters.OldCardPresenterSelector;
import android.support.v17.leanback.streamingapp.old.oldmodels.OldCard;
import android.support.v17.leanback.streamingapp.old.oldmodels.OldCardRow;
import android.support.v17.leanback.streamingapp.old.oldmodels.OldMovie;
import android.support.v17.leanback.streamingapp.utils.Utils;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.ListRow;
import android.support.v17.leanback.widget.ListRowPresenter;
import android.support.v17.leanback.widget.OnItemViewClickedListener;
import android.support.v17.leanback.widget.OnItemViewSelectedListener;
import android.support.v17.leanback.widget.Presenter;
import android.support.v17.leanback.widget.PresenterSelector;
import android.support.v17.leanback.widget.Row;
import android.support.v17.leanback.widget.RowPresenter;
import android.support.v4.app.ActivityOptionsCompat;
import com.google.gson.Gson;
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package android.support.v17.leanback.streamingapp.old.oldapp;




public class OldMainFragment extends BrowseFragment {

    private ArrayObjectAdapter mRowsAdapter;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        setupUIElements();
        setupRowAdapter();
        setupEventListeners();

        this.loadMainPage();
    }

    private void loadMainPage() {
        Intent intent = new Intent(getActivity().getBaseContext(),
//                 BrowseActivity.class);
                DetailActivity.class);
        intent.putExtra("id", "moana-2016");
        if (intent != null) {
            getActivity().startActivityForResult(intent, 1);
        }
    }

    private void setupRowAdapter() {
        mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
        createRows();
        setAdapter(mRowsAdapter);
    }

    private void createRows() {
        String json = Utils
                .inputStreamToString(getResources().openRawResource(R.raw.launcher_cards));
        OldCardRow[] rows = new Gson().fromJson(json, OldCardRow[].class);
        for (OldCardRow row : rows) {
            mRowsAdapter.add(createCardRow(row));
        }
    }

    private ListRow createCardRow(OldCardRow oldCardRow) {
        PresenterSelector presenterSelector = new OldCardPresenterSelector(getActivity());
        ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(presenterSelector);
        for (OldCard oldCard : oldCardRow.getCards()) {
            listRowAdapter.add(oldCard);
        }
        return new ListRow(listRowAdapter);
    }

    private void setupUIElements() {
        setTitle(getString(R.string.browse_title));
        setBadgeDrawable(getResources().getDrawable(R.drawable.title_android_tv, null));
        setHeadersState(HEADERS_DISABLED);
        setHeadersTransitionOnBackEnabled(false);
        setBrandColor(getResources().getColor(R.color.fastlane_background));
    }

    private void setupEventListeners() {
        setOnItemViewClickedListener(new ItemViewClickedListener());
        setOnItemViewSelectedListener(new ItemViewSelectedListener());
    }

    private final class ItemViewClickedListener implements OnItemViewClickedListener {

        @Override
        public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
                                  RowPresenter.ViewHolder rowViewHolder, Row row) {
            Intent intent = null;
            OldCard oldCard = (OldCard) item;
            int id = oldCard.getId();
            switch (id) {
                case 4: {
                    intent = new Intent(getActivity().getBaseContext(),
                            OldDetailViewExampleActivity.class);