Back to project page CastVideos-android.
The source code is released under:
Apache License
If you think the Android project CastVideos-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Copyright (C) 2013 Google Inc. All Rights Reserved. *// w w w . j a v a 2 s . c o m * 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 com.google.sample.cast.refplayer.browser; import com.google.android.gms.cast.MediaInfo; import com.google.sample.cast.refplayer.R; import com.google.sample.cast.refplayer.mediaplayer.LocalPlayerActivity; import com.google.sample.castcompanionlibrary.utils.Utils; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; import android.view.View; import android.widget.ListView; import java.util.List; public class VideoBrowserListFragment extends ListFragment implements LoaderManager.LoaderCallbacks<List<MediaInfo>> { private static final String TAG = "VideoBrowserListFragment"; private static final String CATALOG_URL = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/d.json"; private VideoListAdapter mAdapter; /* * (non-Javadoc) * @see android.support.v4.app.Fragment#onActivityCreated(android.os.Bundle) */ @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); getListView().setFastScrollEnabled(true); mAdapter = new VideoListAdapter(getActivity()); setEmptyText(getString(R.string.no_video_found)); setListAdapter(mAdapter); setListShown(false); getLoaderManager().initLoader(0, null, this); } /* * (non-Javadoc) * @see android.support.v4.app.LoaderManager.LoaderCallbacks#onLoadFinished(android * .support.v4.content.Loader, java.lang.Object) */ @Override public void onLoadFinished(Loader<List<MediaInfo>> arg0, List<MediaInfo> data) { mAdapter.setData(data); if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } } /* * (non-Javadoc) * @see android.support.v4.app.LoaderManager.LoaderCallbacks#onLoaderReset(android * .support.v4.content.Loader) */ @Override public void onLoaderReset(Loader<List<MediaInfo>> arg0) { mAdapter.setData(null); } @Override public void onListItemClick(ListView l, View v, int position, long id) { MediaInfo selectedMedia = mAdapter.getItem(position); handleNavigation(selectedMedia, false); } private void handleNavigation(MediaInfo info, boolean autoStart) { Intent intent = new Intent(getActivity(), LocalPlayerActivity.class); intent.putExtra("media", Utils.fromMediaInfo(info)); intent.putExtra("shouldStart", autoStart); getActivity().startActivity(intent); } /* * (non-Javadoc) * @see android.support.v4.app.LoaderManager.LoaderCallbacks#onCreateLoader(int, * android.os.Bundle) */ @Override public Loader<List<MediaInfo>> onCreateLoader(int arg0, Bundle arg1) { return new VideoItemLoader(getActivity(), CATALOG_URL); } public static VideoBrowserListFragment newInstance() { VideoBrowserListFragment f = new VideoBrowserListFragment(); Bundle b = new Bundle(); f.setArguments(b); return f; } public static VideoBrowserListFragment newInstance(Bundle b) { VideoBrowserListFragment f = new VideoBrowserListFragment(); f.setArguments(b); return f; } }