Android Open Source - android4tv-example2 Scheduled Record List Dialog






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  w  ww .  j a v a2s .  c om*/
package com.iwedia.activities;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.widget.ArrayAdapter;

import com.iwedia.dtv.DVBManager;
import com.iwedia.dtv.pvr.OnTouchInfo;
import com.iwedia.dtv.pvr.PvrSortMode;
import com.iwedia.dtv.pvr.PvrSortOrder;
import com.iwedia.dtv.pvr.SmartInfo;
import com.iwedia.dtv.pvr.TimerInfo;
import com.iwedia.dtv.types.InternalException;

import java.util.ArrayList;
import java.util.Date;
import java.util.TimeZone;

/**
 * Dialog that contains list of PVR records.
 */
public class ScheduledRecordListDialog extends ListDialog {
    /** List of scheduled records. */
    private ArrayList<Object> mRecords;

    public ScheduledRecordListDialog(Context context) {
        super(context);
    }

    /**
     * Create alert dialog with entries
     * 
     * @param title
     * @param arrayAdapter
     * @param listClickListener
     */
    protected void createAlertDIalog(final int indexOfRecord) {
        AlertDialog.Builder builderSingle = new AlertDialog.Builder(mContext);
        builderSingle.setTitle("Delete record?");
        builderSingle.setPositiveButton("Yes",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            DVBManager.getInstance().getPvrManager()
                                    .deleteScheduledRecord(indexOfRecord);
                        } catch (InternalException e) {
                            e.printStackTrace();
                        }
                        updateRecords();
                        dialog.dismiss();
                    }
                });
        builderSingle.setNegativeButton("No",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
        builderSingle.show();
    }

    /**
     * Refresh records list.
     */
    public void updateRecords() {
        try {
            mRecords = DVBManager.getInstance().getPvrManager()
                    .getPvrScheduledRecords();
        } catch (InternalException e) {
            e.printStackTrace();
        }
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(mContext,
                android.R.layout.simple_list_item_1);
        for (int i = 0; i < mRecords.size(); i++) {
            Object record = mRecords.get(i);
            if (record instanceof SmartInfo) {
                SmartInfo smartInfo = (SmartInfo) record;
                arrayAdapter.add(smartInfo.getTitle());
            } else if (record instanceof TimerInfo) {
                TimerInfo timerInfo = (TimerInfo) record;
                arrayAdapter.add(timerInfo.getTitle());
            } else if (record instanceof OnTouchInfo) {
                OnTouchInfo onTouchInfo = (OnTouchInfo) record;
                arrayAdapter.add(onTouchInfo.getTitle());
            }
        }
        mListViewRecords.setAdapter(arrayAdapter);
        if (arrayAdapter.getCount() == 0) {
            nothingSelected();
        }
    }

    /**
     * Convert mega bytes to human readable format.
     * 
     * @param mb
     *        Number of mega bytes.
     * @param si
     * @return Human readable format
     */
    public static String humanReadableByteCount(long mb, boolean si) {
        long bytes = mb * 1024 * 1024;
        int unit = si ? 1000 : 1024;
        if (bytes < unit)
            return bytes + " B";
        int exp = (int) (Math.log(bytes) / Math.log(unit));
        String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1)
                + (si ? "" : "i");
        return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
    }

    @Override
    protected void itemSelected(int index) {
        Object record = mRecords.get(index);
        if (record instanceof SmartInfo) {
            SmartInfo smartInfo = (SmartInfo) record;
            mTitle.setText(smartInfo.getTitle());
            mDescription
                    .setText(smartInfo.getDescription().equals("") ? "No information available"
                            : smartInfo.getDescription());
            mStartTime.setText(sFormatDate.format(smartInfo.getStartTime()
                    .getCalendar().getTime()));
            sFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
            mDuration.setText(sFormat.format(new Date(smartInfo.getEndTime()
                    .getCalendar().getTime().getTime()
                    - smartInfo.getStartTime().getCalendar().getTime()
                            .getTime())));
            mSize.setText("No information available");
        } else if (record instanceof TimerInfo) {
            TimerInfo timerInfo = (TimerInfo) record;
            mTitle.setText(timerInfo.getTitle());
            mDescription
                    .setText(timerInfo.getDescription().equals("") ? "No information available"
                            : timerInfo.getDescription());
            mStartTime.setText(sFormatDate.format(timerInfo.getStartTime()
                    .getCalendar().getTime()));
            sFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
            mDuration.setText(sFormat.format(new Date(timerInfo.getEndTime()
                    .getCalendar().getTime().getTime()
                    - timerInfo.getStartTime().getCalendar().getTime()
                            .getTime())));
            mSize.setText("No information available");
        } else if (record instanceof OnTouchInfo) {
            OnTouchInfo onTouchInfo = (OnTouchInfo) record;
            mTitle.setText(onTouchInfo.getTitle());
            mDescription
                    .setText(onTouchInfo.getDescription().equals("") ? "No information available"
                            : onTouchInfo.getDescription());
            mStartTime.setText(sFormatDate.format(onTouchInfo.getStartTime()
                    .getCalendar().getTime()));
            mDuration.setText("No information available");
            mSize.setText("No information available");
        }
    }

    @Override
    protected void nothingSelected() {
        mTitle.setText("");
        mDescription.setText("");
        mStartTime.setText("");
        mDuration.setText("");
        mSize.setText("");
    }

    @Override
    protected void buttonSortByDateAscClicked() {
        try {
            DVBManager.getInstance().getPvrManager()
                    .setScheduledSortMode(PvrSortMode.SORT_BY_DATE);
            DVBManager.getInstance().getPvrManager()
                    .setScheduledSortOrder(PvrSortOrder.SORT_ASCENDING);
        } catch (InternalException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void buttonSortByDateDescClicked() {
        try {
            DVBManager.getInstance().getPvrManager()
                    .setScheduledSortMode(PvrSortMode.SORT_BY_DATE);
            DVBManager.getInstance().getPvrManager()
                    .setScheduledSortOrder(PvrSortOrder.SORT_DESCENDING);
        } catch (InternalException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void buttonSortByDurationAscClicked() {
        try {
            DVBManager.getInstance().getPvrManager()
                    .setScheduledSortMode(PvrSortMode.SORT_BY_DURATION);
            DVBManager.getInstance().getPvrManager()
                    .setScheduledSortOrder(PvrSortOrder.SORT_ASCENDING);
        } catch (InternalException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void buttonSortByDurationDescClicked() {
        try {
            DVBManager.getInstance().getPvrManager()
                    .setScheduledSortMode(PvrSortMode.SORT_BY_DURATION);
            DVBManager.getInstance().getPvrManager()
                    .setScheduledSortOrder(PvrSortOrder.SORT_DESCENDING);
        } catch (InternalException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void buttonSortByNameAscClicked() {
        try {
            DVBManager.getInstance().getPvrManager()
                    .setScheduledSortMode(PvrSortMode.SORT_BY_NAME);
            DVBManager.getInstance().getPvrManager()
                    .setScheduledSortOrder(PvrSortOrder.SORT_ASCENDING);
        } catch (InternalException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void buttonSortByNameDescClicked() {
        try {
            DVBManager.getInstance().getPvrManager()
                    .setScheduledSortMode(PvrSortMode.SORT_BY_NAME);
            DVBManager.getInstance().getPvrManager()
                    .setScheduledSortOrder(PvrSortOrder.SORT_DESCENDING);
        } catch (InternalException e) {
            e.printStackTrace();
        }
    }
}




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