Example #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    mContext = this;

    setContentView(R.layout.main);

    txTimeDiv = (TextView) findViewById(R.id.txTimeDiv);
    txScaleFactor = (TextView) findViewById(R.id.txScaleFactor);

    btTimeDiv = (Button) findViewById(R.id.btTimeDiv);
    btScaleFactor = (Button) findViewById(R.id.btScaleFactor);

    pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, Globals.TAG);

    fileCreator = new FileCreator("scope-mobile.txt");
    fileCreator.createNewFile();

    // debug file
    fileCreator2 = new FileCreator("scope-mobile-all.txt");
    fileCreator2.createNewFile();

    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    if (mBluetoothAdapter == null) {
      Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
      finish();
      return;
    }
    graphLayout = new GraphLayout(this);
    layout = (LinearLayout) findViewById(R.id.graphView);
    layout.addView(graphLayout.drawGraphSensor());
  }
Example #2
0
        public void handleMessage(android.os.Message msg) {
          switch (msg.what) {
            case Globals.MESSAGE_STATE_CHANGE:
              switch (msg.arg1) {
                case Globals.STATE_CONNECTED:
                  stateConnection = true;
                  break;
                case Globals.STATE_CONNECTING:
                  stateConnection = false;
                  break;
                case Globals.STATE_LISTEN:
                case Globals.STATE_NONE:
                  stateConnection = false;
                  break;
              }
              break;
            case Globals.MESSAGE_READ:
              double[] readBuf = (double[]) msg.obj;
              layout.removeAllViews();
              layout.addView(graphLayout.refreshGraph(readBuf));

              //				byte[] readBuf = (byte[]) msg.obj;
              //                String readMessage = new String(readBuf, 0, msg.arg1);
              //                fileCreator2.AddNewLine(readMessage);
              //                //Log.i(Globals.TAG, "readMessage: "+readMessage);
              //
              //                String readMessageAux = new String(readMessage);
              //
              //                while (readMessageAux.indexOf('%') != -1)
              //                {
              //                	String vAux = aux + readMessageAux.substring(0,
              // readMessageAux.indexOf('%'));
              //                	Log.i(Globals.TAG, "readMessage: "+ vAux); //vector
              //                	aux = "";
              //                	if(readMessageAux.lastIndexOf('%') < readMessageAux.length() - 1)
              //                		readMessageAux =
              // readMessageAux.substring(readMessageAux.indexOf('%') + 1);
              //                	else
              //                		readMessageAux = "";
              //                }
              //
              //                if(readMessageAux.indexOf('%') == -1 && readMessageAux.length() > 0)
              //                {
              //                    aux +=  readMessageAux;
              //                }
              //
              //                try
              //                {
              //                	Double.parseDouble(readMessage);
              //                } catch (NumberFormatException e) {
              //                	Log.i(Globals.TAG, "ERRO");
              //                }
              /*
                int lastPercent = 0;

                if (readMessage.length() > 3)
                {
                	for (int i = 0; i < readMessage.length(); i++)
                	{
                		if (readMessage.charAt(i) == '%')
                		{
                			lastPercent = i;
                		}
                	}
                	if (lastPercent != 0 && readMessage.charAt(0) == '%')
              {
                		Log.i(Globals.TAG, "readMessage: " + readMessage.substring(0, lastPercent));
              	stringBuffer.append(readMessage.substring(0, lastPercent));
              }
                }
                if (stringBuffer.length() > 300)
                {
                	Globals.lock = false;
                	Log.i(Globals.TAG, "CAIU AQUIIIIIIIIIIIIIIIIIIIII (stop)");
                	fileCreator.AddNewLine(stringBuffer.substring(1).toString().replaceAll("%", "\n"));
                	fileCreator.fileToArray();
                	layout.removeAllViews();
                	layout.addView(graphLayout.refreshGraph(fileCreator.getAllIntValuesFromFile()));
                	fileCreator.clearFile();
                	stringBuffer = new StringBuffer();
                	Globals.lock =  true;
                }*/
              break;
          }
        };