Android Open Source - DVBViewerController Remote Fragment






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  w  w  .j  a  va 2 s .c  om
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import de.bennir.DVBViewerController.service.DVBService;

public class RemoteFragment extends Fragment {
    private static final String TAG = RemoteFragment.class.toString();
    private Context mContext;
    private DVBService mDVBService;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.remote_fragment, container, false);
    }

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

        mContext = getActivity().getApplicationContext();
        mDVBService = DVBService.getInstance(mContext);

        ImageView remote = (ImageView) getActivity().findViewById(
                R.id.remote);

        remote.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    int coords[] = new int[2];
                    v.getLocationOnScreen(coords);

                    int x = (int) event.getRawX() - coords[0];
                    int y = (int) event.getRawY() - coords[1];

                    if (x < 0 || y < 0) {
                        return false;
                    }

                    ImageView img = (ImageView) getActivity().findViewById(
                            R.id.remote_touchmap);
                    Bitmap bitmap = ((BitmapDrawable) img.getDrawable())
                            .getBitmap();

                    double scaleWidthRatio = (double) img.getWidth() / (double) bitmap.getWidth();
                    double scaleHeightRatio = (double) img.getHeight() / (double) bitmap.getHeight();

                    int scaleX = (int) (x / scaleWidthRatio);
                    int scaleY = (int) (y / scaleHeightRatio);

                    if (scaleX > bitmap.getWidth() || scaleY > bitmap.getHeight()) {
                        return false;
                    }

                    int pixel = bitmap.getPixel(scaleX, scaleY);

                    int red = Color.red(pixel);
                    int green = Color.green(pixel);
                    int blue = Color.blue(pixel);

                    /**
                     * Button Events
                     */

                    // Chan+
                    if (red == 119 && blue == 119 && green == 119) {
                        mDVBService.sendCommand("sendUp");
                    }
                    // Chan-
                    if (red == 0 && blue == 0 && green == 0) {
                        mDVBService.sendCommand("sendDown");
                    }
                    // Vol+
                    if (red == 49 && blue == 49 && green == 49) {
                        mDVBService.sendCommand("sendRight");
                    }
                    // Vol-
                    if (red == 204 && blue == 204 && green == 204) {
                        mDVBService.sendCommand("sendLeft");
                    }
                    // Menu
                    if (red == 0 && blue == 255 && green == 255) {
                        mDVBService.sendCommand("sendMenu");
                    }
                    // Ok
                    if (red == 255 && blue == 255 && green == 0) {
                        mDVBService.sendCommand("sendOk");
                    }
                    // Back
                    if (red == 255 && blue == 0 && green == 168) {
                        mDVBService.sendCommand("sendBack");
                    }
                    // Red
                    if (red == 255 && blue == 0 && green == 0) {
                        mDVBService.sendCommand("sendRed");
                    }
                    // Yellow
                    if (red == 255 && blue == 0 && green == 255) {
                        mDVBService.sendCommand("sendYellow");
                    }
                    // Green
                    if (red == 0 && blue == 0 && green == 255) {
                        mDVBService.sendCommand("sendGreen");
                    }
                    // Blue
                    if (red == 0 && blue == 255 && green == 0) {
                        mDVBService.sendCommand("sendBlue");
                    }
                }

                return true;
            }
        });

    }

}




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