Android Open Source - DVBViewerController D V B Viewer Controller Activity






From Project

Back to project page DVBViewerController.

License

The source code is released under:

Apache License

If you think the Android project DVBViewerController 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

package de.bennir.DVBViewerController;
//  w ww.j a  v  a2 s.  co m
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import de.bennir.DVBViewerController.service.DVBServer;
import de.bennir.DVBViewerController.service.DVBService;
import de.keyboardsurfer.android.widget.crouton.Crouton;
import de.keyboardsurfer.android.widget.crouton.Style;

public class DVBViewerControllerActivity extends FragmentActivity {
    private static final String TAG = DVBViewerControllerActivity.class.toString();
    private static final String OPENED_KEY = "OPENED_KEY";
    public static int currentGroup = -1;
    public static de.keyboardsurfer.android.widget.crouton.Configuration croutonInfinite = new de.keyboardsurfer.android.widget.crouton.Configuration.Builder()
            .setDuration(de.keyboardsurfer.android.widget.crouton.Configuration.DURATION_INFINITE)
            .build();
    public DVBService mDVBService;
    public Typeface robotoThin;
    public static Typeface robotoLight;
    public Typeface robotoCondensed;
    public Fragment mContent;
    private ListView mDrawerList;
    private DrawerLayout mDrawerLayout;
    private LinearLayout mDrawer;
    private String mTitle;
    private ActionBarDrawerToggle mDrawerToggle;
    private SharedPreferences prefs = null;
    private Boolean opened = null;
    private Boolean switchToEPG = false;

    @Override
    protected void onDestroy() {
        // Workaround until there's a way to detach the Activity from Crouton while
        // there are still some in the Queue.
        Crouton.clearCroutonsForActivity(this);
        mDVBService.destroy();
        super.onDestroy();
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        if (mDrawerLayout != null && mDrawer != null) {
            for (int i = 0; i < menu.size(); i++) {
                MenuItem item = menu.getItem(i);
                if (item != null) {
                    item.setVisible(!mDrawerLayout.isDrawerOpen(mDrawer));
                }
            }
        }
        return super.onPrepareOptionsMenu(menu);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        mDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mDrawerToggle.onConfigurationChanged(newConfig);
    }

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

        setContentView(R.layout.main);

        initFonts();

        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            DVBServer server = new DVBServer();
            server.host = extras.getString(DVBService.DVBHOST_KEY);
            server.ip = extras.getString(DVBService.DVBIP_KEY);
            server.port = extras.getString(DVBService.DVBPORT_KEY);

            mDVBService = DVBService.getInstance(getApplicationContext(), server);
        } else {
            try {
                throw new Exception("No Bundle");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        mTitle = getString(R.string.remote);

        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setTitle(R.string.remote);

        /**
         * Above View
         */
        if (savedInstanceState != null)
            mContent = getSupportFragmentManager().getFragment(savedInstanceState, "mContent");
        if (mContent == null)
            mContent = new RemoteFragment();

        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.content_frame, mContent)
                .commit();


        /**
         * Behind View
         */
        mDrawerList = (ListView) findViewById(R.id.menu_list);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawer = (LinearLayout) findViewById(R.id.drawer);

        mDrawerToggle = new ActionBarDrawerToggle(
                this,
                mDrawerLayout,
                R.drawable.ic_drawer,
                R.string.open_drawer,
                R.string.close_drawer
        ) {
            /** Called when a drawer has settled in a completely closed state. */
            public void onDrawerClosed(View view) {
                if (view.getId() == mDrawer.getId() && switchToEPG) {
                    // Left Drawer Closed
                    switchToEPG = false;
                    mDrawerLayout.openDrawer(Gravity.END);
                }
                getActionBar().setTitle(mTitle);
                invalidateOptionsMenu();
                if (opened != null && opened == false) {
                    opened = true;
                    if (prefs != null) {
                        SharedPreferences.Editor editor = prefs.edit();
                        editor.putBoolean(OPENED_KEY, true);
                        editor.apply();
                    }
                }
            }

            /** Called when a drawer has settled in a completely open state. */
            public void onDrawerOpened(View drawerView) {
                getActionBar().setTitle(R.string.app_name);
                invalidateOptionsMenu();
            }
        };

        mDrawerLayout.setDrawerListener(mDrawerToggle);
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.END);

        new Thread(new Runnable() {
            @Override
            public void run() {
                prefs = getPreferences(MODE_PRIVATE);
                opened = prefs.getBoolean(OPENED_KEY, false);
                if (opened == false) {
                    mDrawerLayout.openDrawer(mDrawer);
                }
            }
        }).start();

        TextView activeProfile = (TextView) findViewById(R.id.active_profile);
        activeProfile.setTypeface(robotoCondensed);
        if (!mDVBService.getDVBServer().host.equals(DVBService.DEMO_DEVICE)) {
            activeProfile.setText(mDVBService.getDVBServer().host);
        }
        activeProfile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent mIntent = new Intent(getApplicationContext(), DeviceSelectionActivity.class);
                startActivity(mIntent);

                mDVBService.destroy();

                DVBViewerControllerActivity.this.finish();
                overridePendingTransition(R.anim.fadein, R.anim.slide_to_right);
            }
        });

        addMenuItems(getApplicationContext());

        /**
         * Channel Loading
         */
        if (mDVBService.getDVBChannels().isEmpty()) {
            Log.d(TAG, "DVBChannels empty");
            Style st = new Style.Builder()
                    .setConfiguration(DVBViewerControllerActivity.croutonInfinite)
                    .setBackgroundColorValue(Style.holoBlueLight)
                    .setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
                    .build();
            Crouton.makeText(this, R.string.loadingChannels, st).show();
            mDVBService.loadChannels();
        }
    }

    /**
     * Adds Menu Items to NavDrawer
     *
     * @param context Application Context
     */
    private void addMenuItems(Context context) {
        MenuAdapter adapter = new MenuAdapter(context);

        adapter.add(new DVBMenuItem(getString(R.string.remote), R.drawable.ic_action_remote));
        adapter.add(new DVBMenuItem(getString(R.string.channels), R.drawable.ic_action_channels));
        adapter.add(new DVBMenuItem(getString(R.string.epg), R.drawable.ic_action_epg));
        adapter.add(new DVBMenuItem(getString(R.string.timer), R.drawable.ic_action_timers));
        adapter.add(new DVBMenuItem(getString(R.string.settings), R.drawable.ic_action_settings));

        mDrawerList.setAdapter(adapter);
        mDrawerList.setItemChecked(0, true);

        mDrawerList.setOnItemClickListener(new ListView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView adapterView, View view, int position, long id) {
                Fragment newContent = null;
                int titleRes = 0;
                switchToEPG = false;

                switch (position) {
                    case 0:
                        // Remote
                        newContent = new RemoteFragment();
                        titleRes = R.string.remote;
                        break;
                    case 1:
                        // Channels
                        newContent = new ChannelFragment();
                        titleRes = R.string.channels;
                        break;
                    case 2:
                        // EPG
                        newContent = new EPGFragment();
                        titleRes = R.string.epg;
                        switchToEPG = true;
                        break;
                    case 3:
                        // Timers
                        newContent = new TimerFragment();
                        titleRes = R.string.timer;
                        break;
                    case 4:
                        // Settings
                        newContent = new SettingsFragment();
                        titleRes = R.string.settings;
                        break;
                }
                if (newContent != null) {
                    getActionBar().setDisplayShowTitleEnabled(true);
                    getSupportFragmentManager().popBackStackImmediate();
                    mTitle = getString(titleRes);
                    switchContent(newContent, titleRes);
                }

                if (position == 2) {
                    mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.END);
                } else {
                    mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.END);
                }

                mDrawerList.setItemChecked(position, true);
                mDrawerLayout.closeDrawer(mDrawer);
            }
        });
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (mDrawerLayout.isDrawerOpen(Gravity.END)) {
            mDrawerLayout.closeDrawer(Gravity.END);
        } else if (mDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        // Handle your other action bar items...

        return super.onOptionsItemSelected(item);
    }

    private void initFonts() {
        robotoThin = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Thin.ttf");
        robotoLight = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Light.ttf");
        robotoCondensed = Typeface.createFromAsset(getAssets(), "fonts/RobotoCondensed-Bold.ttf");
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == 1)
            mDVBService.loadTimers();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        Log.d(TAG, "onSaveInstanceState");
        super.onSaveInstanceState(outState);

        getSupportFragmentManager().putFragment(outState, "mContent", mContent);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            mDVBService.sendCommand("sendVolDown");
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            mDVBService.sendCommand("sendVolUp");
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            return true;
        }

        return super.onKeyUp(keyCode, event);
    }

    public void switchContent(Fragment fragment, int titleRes) {
        switchContent(fragment, getString(titleRes));
    }

    public void switchContent(Fragment fragment, String title) {
        getActionBar().setTitle(title);
        mContent = fragment;
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.content_frame, fragment)
                .commit();
    }

    public void switchContent(Fragment fragment, String title, boolean addToBackStack) {
        if (addToBackStack) {
            Log.d(TAG, "switchContent addToBackStack");
            getActionBar().setTitle(title);
            mContent = fragment;
            getSupportFragmentManager()
                    .beginTransaction()
                    .replace(R.id.content_frame, fragment)
                    .addToBackStack(null)
                    .commit();
        } else {
            switchContent(fragment, title);
        }
    }

    private class DVBMenuItem {
        public String tag;
        public int iconRes;

        public DVBMenuItem(String tag, int iconRes) {
            this.tag = tag;
            this.iconRes = iconRes;
        }
    }

    private class MenuAdapter extends ArrayAdapter<DVBMenuItem> {

        public MenuAdapter(Context context) {
            super(context, 0);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = LayoutInflater.from(getContext()).inflate(
                        R.layout.menu_list_item, null);
            }

            TextView title = (TextView) convertView
                    .findViewById(R.id.row_title);
            title.setText(getItem(position).tag);
            title.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(getItem(position).iconRes), null, null, null);
            title.setCompoundDrawablePadding(30);

            return convertView;
        }

    }
}




Java Source Code List

com.android.datetimepicker.AccessibleLinearLayout.java
com.android.datetimepicker.AccessibleTextView.java
com.android.datetimepicker.Utils.java
com.android.datetimepicker.date.AccessibleDateAnimator.java
com.android.datetimepicker.date.DatePickerController.java
com.android.datetimepicker.date.DatePickerDialog.java
com.android.datetimepicker.date.DayPickerView.java
com.android.datetimepicker.date.SimpleMonthAdapter.java
com.android.datetimepicker.date.SimpleMonthView.java
com.android.datetimepicker.date.TextViewWithCircularIndicator.java
com.android.datetimepicker.date.YearPickerView.java
com.android.datetimepicker.time.AmPmCirclesView.java
com.android.datetimepicker.time.CircleView.java
com.android.datetimepicker.time.RadialPickerLayout.java
com.android.datetimepicker.time.RadialSelectorView.java
com.android.datetimepicker.time.RadialTextsView.java
com.android.datetimepicker.time.TimePickerDialog.java
com.googlecode.eyesfree.utils.TouchExplorationHelper.java
de.bennir.DVBViewerController.ChannelFragment.java
de.bennir.DVBViewerController.ChannelGroupFragment.java
de.bennir.DVBViewerController.DVBViewerControllerActivity.java
de.bennir.DVBViewerController.DeviceSelectionActivity.java
de.bennir.DVBViewerController.EPGFragment.java
de.bennir.DVBViewerController.RemoteFragment.java
de.bennir.DVBViewerController.SettingsFragment.java
de.bennir.DVBViewerController.TimerFragment.java
de.bennir.DVBViewerController.TimerWizardActivity.java
de.bennir.DVBViewerController.TimerWizardModel.java
de.bennir.DVBViewerController.channels.ChanGroupAdapter.java
de.bennir.DVBViewerController.channels.DVBChannelAdapter.java
de.bennir.DVBViewerController.channels.DVBChannel.java
de.bennir.DVBViewerController.epg.EPGInfoAdapter.java
de.bennir.DVBViewerController.epg.EPGInfo.java
de.bennir.DVBViewerController.service.DVBServer.java
de.bennir.DVBViewerController.service.DVBService.java
de.bennir.DVBViewerController.timers.DVBTimer.java
de.bennir.DVBViewerController.timers.TimerAdapter.java
de.bennir.DVBViewerController.util.DateUtils.java
de.bennir.DVBViewerController.util.ThreadExecutor.java
de.bennir.DVBViewerController.view.QuickReturnListView.java
de.bennir.DVBViewerController.wizard.model.AbstractWizardModel.java
de.bennir.DVBViewerController.wizard.model.BranchPage.java
de.bennir.DVBViewerController.wizard.model.ModelCallbacks.java
de.bennir.DVBViewerController.wizard.model.MultipleFixedChoicePage.java
de.bennir.DVBViewerController.wizard.model.PageList.java
de.bennir.DVBViewerController.wizard.model.PageTreeNode.java
de.bennir.DVBViewerController.wizard.model.Page.java
de.bennir.DVBViewerController.wizard.model.ReviewItem.java
de.bennir.DVBViewerController.wizard.model.SingleFixedChoicePage.java
de.bennir.DVBViewerController.wizard.model.TimerDatePage.java
de.bennir.DVBViewerController.wizard.model.TimerInfoPage.java
de.bennir.DVBViewerController.wizard.ui.MultipleChoiceFragment.java
de.bennir.DVBViewerController.wizard.ui.PageFragmentCallbacks.java
de.bennir.DVBViewerController.wizard.ui.ReviewFragment.java
de.bennir.DVBViewerController.wizard.ui.SingleChoiceFragment.java
de.bennir.DVBViewerController.wizard.ui.StepPagerStrip.java
de.bennir.DVBViewerController.wizard.ui.TimerDateFragment.java
de.bennir.DVBViewerController.wizard.ui.TimerInfoFragment.java