Android Open Source - nxt-remote-controller Old Pad Controller Fragment






From Project

Back to project page nxt-remote-controller.

License

The source code is released under:

MIT License

If you think the Android project nxt-remote-controller 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 git.egatuts.nxtremotecontroller.fragment;
//from  w  w w  .j a  v a  2s .  co  m
import android.bluetooth.BluetoothSocket;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import git.egatuts.nxtremotecontroller.ControllerActivity;
import git.egatuts.nxtremotecontroller.R;
import git.egatuts.nxtremotecontroller.bluetooth.NXTConnector;
import git.egatuts.nxtremotecontroller.bluetooth.threads.ConnectedThread;
import git.egatuts.nxtremotecontroller.device.PairedDevice;

public class OldPadControllerFragment extends BaseFragment {

  private ConnectedThread connected_thread;
  private ControllerActivity activity;
  private PairedDevice device;
  private BluetoothSocket socket;
  private NXTConnector nxt_connector;

  @Override
  public void onResume () {
    super.onResume();
    this.activity = (ControllerActivity) this.getActivity();
    this.device = this.activity.getDevice();
    this.nxt_connector = this.activity.getConnector();
    this.socket = this.nxt_connector.getSocket();
    this.nxt_connector.establishConnection(this.socket, this.device);
  }

  private class DirectionButtonOnTouchListener implements View.OnTouchListener {

    private double lmod;
    private double rmod;

    public DirectionButtonOnTouchListener (double l, double r) {
      lmod = l;
      rmod = r;
    }

    @Override
    public boolean onTouch (View v, MotionEvent event) {
      int action = event.getAction();
      if (action == MotionEvent.ACTION_DOWN) {
        byte power = (byte) 80;
        byte l = (byte) (power * lmod);
        byte r = (byte) (power * rmod);
        OldPadControllerFragment.this.nxt_connector.motors(l, r, true, false);
      } else if ((action == MotionEvent.ACTION_UP) || (action == MotionEvent.ACTION_CANCEL)) {
        OldPadControllerFragment.this.nxt_connector.motors((byte) 0, (byte) 0, false, false);
      }
      return true;
    }
  }

  @Override
  public View onCreateView (LayoutInflater inflater, ViewGroup parent_container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.pad_layout, parent_container, false);
    Button up = (Button) view.findViewById(R.id.up);
    Button left = (Button) view.findViewById(R.id.left);
    Button bottom = (Button) view.findViewById(R.id.bottom);
    Button right = (Button) view.findViewById(R.id.right);
    /*up.setOnTouchListener(new View.OnTouchListener() {
      @Override
      public boolean onTouch (View v, MotionEvent event) {
        int action = event.getAction();
        PadControllerFragment self = PadControllerFragment.this;
        if (action == MotionEvent.ACTION_DOWN) {
          byte power = (byte) 80;
          self.nxt_connector.motors((byte) 80, (byte) 80, true, true);
        } else if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
          self.nxt_connector.motors((byte) 0, (byte) 0, false, true);
        }
        return true;
      }
    });*/
    /*up.setOnTouchListener(new DirectionButtonOnTouchListener(1, 1));
    left.setOnTouchListener(new DirectionButtonOnTouchListener(-0.6, 0.6));
    bottom.setOnTouchListener(new DirectionButtonOnTouchListener(-1, -1));
    right.setOnTouchListener(new DirectionButtonOnTouchListener(0.6, -0.6));
    return view;
  }

  @Override
  public void onDestroy () {
    this.nxt_connector.closeConnections();
    super.onDestroy();
  }

}*/




Java Source Code List

.OldPadControllerFragment.java
com.andexert.library.ApplicationTest.java
com.andexert.library.RippleView.java
com.andexert.rippleeffect.ApplicationTest.java
com.andexert.rippleeffect.CustomAdapter.java
com.andexert.rippleeffect.MainActivity.java
com.andexert.rippleeffect.OnTapListener.java
com.gc.materialdesign.utils.Utils.java
com.gc.materialdesign.views.ButtonFlat.java
com.gc.materialdesign.views.ButtonFloatSmall.java
com.gc.materialdesign.views.ButtonFloat.java
com.gc.materialdesign.views.ButtonIcon.java
com.gc.materialdesign.views.ButtonRectangle.java
com.gc.materialdesign.views.Button.java
com.gc.materialdesign.views.Card.java
com.gc.materialdesign.views.CheckBox.java
com.gc.materialdesign.views.CustomView.java
com.gc.materialdesign.views.LayoutRipple.java
com.gc.materialdesign.views.ProgressBarCircularIndeterminate.java
com.gc.materialdesign.views.ProgressBarDeterminate.java
com.gc.materialdesign.views.ProgressBarIndeterminateDeterminate.java
com.gc.materialdesign.views.ProgressBarIndeterminate.java
com.gc.materialdesign.views.RippleView.java
com.gc.materialdesign.views.ScrollView.java
com.gc.materialdesign.views.Slider.java
com.gc.materialdesign.views.Switch.java
com.gc.materialdesign.widgets.ColorSelector.java
com.gc.materialdesign.widgets.Dialog.java
com.gc.materialdesign.widgets.SnackBar.java
git.egatuts.nxtremotecontroller.ApplicationTest.java
git.egatuts.nxtremotecontroller.GlobalUtils.java
git.egatuts.nxtremotecontroller.activity.ActivityPendingTransition.java
git.egatuts.nxtremotecontroller.activity.BaseActivity.java
git.egatuts.nxtremotecontroller.activity.ControllerActivity.java
git.egatuts.nxtremotecontroller.activity.DefaultActivityPendingTransition.java
git.egatuts.nxtremotecontroller.activity.MainActivity.java
git.egatuts.nxtremotecontroller.activity.SettingsActivity.java
git.egatuts.nxtremotecontroller.bluetooth.BluetoothConstants.java
git.egatuts.nxtremotecontroller.bluetooth.BluetoothUtils.java
git.egatuts.nxtremotecontroller.bluetooth.NXTConnector.java
git.egatuts.nxtremotecontroller.device.PairedDeviceAdapter.java
git.egatuts.nxtremotecontroller.device.PairedDeviceItemClickListener.java
git.egatuts.nxtremotecontroller.device.PairedDeviceViewHolder.java
git.egatuts.nxtremotecontroller.device.PairedDevice.java
git.egatuts.nxtremotecontroller.exception.SocketCreationException.java
git.egatuts.nxtremotecontroller.fragment.ActivityBaseFragment.java
git.egatuts.nxtremotecontroller.fragment.BaseFragment.java
git.egatuts.nxtremotecontroller.fragment.BluetoothFragment.java
git.egatuts.nxtremotecontroller.fragment.ControllerBaseFragment.java
git.egatuts.nxtremotecontroller.fragment.DefaultFragmentPendingTransition.java
git.egatuts.nxtremotecontroller.fragment.FragmentPendingTransition.java
git.egatuts.nxtremotecontroller.fragment.HomeFragment.java
git.egatuts.nxtremotecontroller.fragment.LocalControllerFragment.java
git.egatuts.nxtremotecontroller.fragment.OnlineControllerFragment.java
git.egatuts.nxtremotecontroller.fragment.ScanFragment.java
git.egatuts.nxtremotecontroller.fragment.SettingsFragment.java
git.egatuts.nxtremotecontroller.listener.AnimationEndListener.java
git.egatuts.nxtremotecontroller.listener.AppKillerListener.java
git.egatuts.nxtremotecontroller.listener.BaseListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothDiscoveryListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothEnableListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothPairingListener.java
git.egatuts.nxtremotecontroller.navigation.DrawerItemViewHolder.java
git.egatuts.nxtremotecontroller.navigation.DrawerItem.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerAdapter.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerCallback.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerFragment.java
git.egatuts.nxtremotecontroller.preference.PreferencesUtils.java
git.egatuts.nxtremotecontroller.receiver.AppKillerReceiver.java
git.egatuts.nxtremotecontroller.receiver.BaseReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothDiscoveryReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothEnableReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothPairingReceiver.java
git.egatuts.nxtremotecontroller.thread.BaseThread.java
git.egatuts.nxtremotecontroller.thread.ConnectThread.java
git.egatuts.nxtremotecontroller.thread.ConnectedThread.java
git.egatuts.nxtremotecontroller.views.BaseIndeterminateProgressDialog.java
git.egatuts.nxtremotecontroller.views.BaseProgressDialog.java
git.egatuts.nxtremotecontroller.views.JoystickView.java
git.egatuts.nxtremotecontroller.views.LongIndeterminateProgressDialog.java
git.egatuts.nxtremotecontroller.views.ShortIndeterminateProgressDialog.java