Back to project page android4tv-example2.
The source code is released under:
Apache License
If you think the Android project android4tv-example2 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) 2014 iWedia S.A. 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. *///from ww w . j ava 2s .c o m package com.iwedia.fragments; import android.os.Bundle; import android.os.RemoteException; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ListView; import com.iwedia.activities.EPGActivity; import com.iwedia.adapters.ListViewTimeAdapter; import com.iwedia.custom.TimeLine; import com.iwedia.custom.TimeLineObject; import com.iwedia.dtv.DVBManager; import com.iwedia.epg.R; import java.text.ParseException; /** * This fragment inflates Listview who will show events for one hour. */ public class EPGFragment extends Fragment implements OnItemSelectedListener, OnItemClickListener, OnItemLongClickListener { private final String TAG = "FragmentEPG"; private View mView = null; private ListView mListView = null; private NotifyFragments mNotifyFragments = null; /** * Callback for all fragments when a structure of ListView has changed. */ public interface NotifyFragments { public void listViewChanged(); public boolean showAlertDialog(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (mView == null) { mView = inflater.inflate(R.layout.epg_time_fragment, container, false); mListView = ((ListView) mView.findViewById(R.id.listview_epg)); mListView.setAdapter(new ListViewTimeAdapter(getActivity(), ((EPGActivity) getActivity()).getDVBManager() .getChannelNames(), ((EPGActivity) getActivity()) .getDVBManager().getLoadedEpgEvents(), getArguments().getInt( EPGActivity.FRAGMRENT_ARGUMENT_KEY_TIME))); mListView.setOnItemSelectedListener(this); mListView.setOnItemClickListener(this); mListView.setOnItemLongClickListener(this); mListView.setSelection(((EPGActivity) getActivity()) .getDVBManager().getCurrentChannelNumber()); ((TimeLine) mView.findViewById(R.id.timeline_epg_time)) .setTime(getArguments().getInt( EPGActivity.FRAGMRENT_ARGUMENT_KEY_TIME)); } else { ((ViewGroup) mView.getParent()).removeView(mView); } return mView; } /** * Set position of event and channel list view, positions have to be same. * * @param position * Position of item. */ public void setListViewPosition(int position) { if (mListView != null) { mListView.setSelection(position); ((EPGActivity) getActivity()).getListViewChannels().setSelection( position); } } /** * Get Position of event in listview. * * @return Position of item. */ public int getListViewPosition() { if (mListView != null) { return mListView.getSelectedItemPosition(); } return 0; } /** * Create new adapter with new data. * * @throws RemoteException */ public void reInitializeAdapter() throws RemoteException { /** If Fragment is not shown (initialized) do nothing */ if (mView != null && getActivity() != null) { mListView.setAdapter(new ListViewTimeAdapter(getActivity(), ((EPGActivity) getActivity()).getDVBManager() .getChannelNames(), ((EPGActivity) getActivity()) .getDVBManager().getLoadedEpgEvents(), getArguments().getInt( EPGActivity.FRAGMRENT_ARGUMENT_KEY_TIME))); } } @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { mNotifyFragments.listViewChanged(); } @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ((TimeLineObject) view).showDialogWithEvents(); } @Override public void onNothingSelected(AdapterView<?> arg0) { } /** * Set callback for fragments * * @param notifyFragments * Object of NotifyFragments */ public void setNotifyFragments(NotifyFragments notifyFragments) { mNotifyFragments = notifyFragments; } @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { if (!mNotifyFragments.showAlertDialog()) { ((EPGActivity) getActivity()).getProgressDialog().show(); ((EPGActivity) getActivity()).getDVBManager().reLoadEvents(); } return true; } }