Android Open Source - android4tv-example2 E P G Fragment






From Project

Back to project page android4tv-example2.

License

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.

Java Source Code

/*
 * 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;
    }
}




Java Source Code List

com.iwedia.activities.ChannelListDialog.java
com.iwedia.activities.CustomTimePickerDialog.java
com.iwedia.activities.DTVActivity.java
com.iwedia.activities.EPGActivity.java
com.iwedia.activities.ListDialog.java
com.iwedia.activities.ManualPvrRecordDialog.java
com.iwedia.activities.ManualReminderDialog.java
com.iwedia.activities.ManualSetDialog.java
com.iwedia.activities.MediaMountedReceiver.java
com.iwedia.activities.ReminderListDialog.java
com.iwedia.activities.ScheduledRecordListDialog.java
com.iwedia.activities.SoftwareVersionDialog.java
com.iwedia.activities.TVActivity.java
com.iwedia.adapters.ChannelListAdapter.java
com.iwedia.adapters.FragmentTabAdapter.java
com.iwedia.adapters.ListViewChannelsAdapter.java
com.iwedia.adapters.ListViewTimeAdapter.java
com.iwedia.callback.EPGCallBack.java
com.iwedia.callback.PvrCallback.java
com.iwedia.callback.ReminderCallback.java
com.iwedia.custom.TimeLineObject.java
com.iwedia.custom.TimeLine.java
com.iwedia.dtv.ChannelInfo.java
com.iwedia.dtv.DVBManager.java
com.iwedia.dtv.IPService.java
com.iwedia.dtv.PvrManager.java
com.iwedia.dtv.ReminderManager.java
com.iwedia.dtv.TimeEventHolder.java
com.iwedia.dtv.TimeEvent.java
com.iwedia.fragments.EPGFragment.java