Ejemplo n.º 1
0
  @Override
  public void run() {
    int i, len;
    double ondo1;

    // [FTDriver] Create Read Buffer
    byte[] rbuf = new byte[128]; // 1byte <--slow-- [Transfer Speed] --fast--> 4096 byte
    while (mLooper != null) {
      // [FTDriver] Read from USB Serial
      len = mSerial.read(rbuf);
      String str1 = new String(rbuf);
      // String new_str1 = str1.substring(43, 45);
      if (len > 0) {
        if (SHOW_LOGCAT) {
          Log.i(TAG, "Read  Length : " + len + ",buf: " + str1);
        }
        // Message msg = new Message(); //非推奨
        Message msg = Message.obtain(); // 推奨
        // Message msg = mHandler.obtainMessage(); //推奨
        msg.obj = str1;

        // ハンドラへのメッセージ送信
        mHandler.sendMessage(msg);

        //                    //@todo mText1 = (String) mY.getText();
        //                    try { //エラーが出そうな処理
        //                        //String x;
        //                        //int a;
        //                        //x = new_str1.toLowerCase(Locale.ENGLISH);
        //                        //a = Integer.parseInt(x, 16);
        //                    for (i = 0; i < len; ++i) {
        //                        if (SHOW_LOGCAT) {
        //                            Log.i(TAG, "Read  Data[" + i + "] : " + rbuf[i]);
        //                        }
        //
        //                            if (rbuf[i] == 0x0A) {
        //                                if (!(new_str1.equals("FF"))) {
        //                                    ondo1 = ((Integer.parseInt(new_str1, 16)) * 16);
        //                                    ondo1 = (ondo1 / 10) - 60;
        //                                    if (ondo1 > 0) {
        //                                        //@todo mText1 = "" + String.format("%.1f", ondo1)
        // + "\n";
        //                                    }
        //                                }
        //
        //                            }
        //
        //                        }
        //                    } catch (NumberFormatException nfe) {
        //
        //                    }
        //                mHandler.post(new Runnable() {
        //                    public void run() {
        ////                            TextView dateText = (TextView) findViewById(R.id.date_id);
        ////                            Time time = new Time("Asia/Tokyo");
        ////                            time.setToNow();
        ////                            String date = time.year + "年" + (time.month + 1) + "月" +
        // time.monthDay + "日 "
        ////                                    + time.hour + "時" + time.minute + "分" + time.second
        // + "秒";
        ////                            dateText.setText(date);
        //                        //mX.setText(String.valueOf(time.second));
        //                        //@todo mY.setText(mText1);
        //                    }
        //                });
      }
      try {
        Thread.sleep(50);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      if (mStop) {
        mRunningMainLoop = false;
        return;
      }
    }
  };
Ejemplo n.º 2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ezydine);

    // [FTDriver] setPermissionIntent() before begin()
    mSerial = new FTDriver((UsbManager) getSystemService(Context.USB_SERVICE));

    // [FTDriver] setPermissionIntent() before begin()
    PendingIntent permissionIntent =
        PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
    mSerial.setPermissionIntent(permissionIntent);

    if (mSerial.begin(SERIAL_BAUDRATE)) {
      //   mainloop();
    }

    // リソースに準備した画像ファイルからBitmapを作成しておく
    image_amber = BitmapFactory.decodeResource(getResources(), R.drawable.amber_32);
    image_black = BitmapFactory.decodeResource(getResources(), R.drawable.black_32);
    image_green = BitmapFactory.decodeResource(getResources(), R.drawable.green_32);
    image_red = BitmapFactory.decodeResource(getResources(), R.drawable.red_32);
    image_white = BitmapFactory.decodeResource(getResources(), R.drawable.white_32);
    image_blue = BitmapFactory.decodeResource(getResources(), R.drawable.blue_32);
    image_gray = BitmapFactory.decodeResource(getResources(), R.drawable.gray_32);

    // データの作成
    List<CustomData> objects = new ArrayList<CustomData>();

    item1 = new CustomData();
    item2 = new CustomData();
    item3 = new CustomData();
    item4 = new CustomData();
    item5 = new CustomData();
    item6 = new CustomData();
    item7 = new CustomData();
    item8 = new CustomData();
    item9 = new CustomData();
    item10 = new CustomData();

    initView();
    objects.add(item1);
    objects.add(item2);
    objects.add(item3);
    objects.add(item4);
    objects.add(item5);
    objects.add(item6);
    objects.add(item7);
    objects.add(item8);
    objects.add(item9);
    objects.add(item10);

    item1.setImagaData(image_green);
    item9.setImagaData(image_blue);
    item1.setTextColor(true);
    item10.setImagaData(image_red);

    CustomAdapter customAdapater = new CustomAdapter(this, 0, objects);

    ListView listView = (ListView) findViewById(R.id.list);
    listView.setAdapter(customAdapater);

    // リスト項目がクリックされた時の処理
    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ListView listView = (ListView) parent;
            Log.d(TAG, "onItemClick: " + position);
            //                String item = (String) listView.getItemAtPosition(position);
            //                Toast.makeText(getApplicationContext(), item + " clicked",
            //                        Toast.LENGTH_LONG).show();
          }
        });

    listView.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          // リスト項目が選択された時の処理
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ListView listView = (ListView) parent;
            Log.d(TAG, "onItemSelected: " + position);
            //                String item = (String) listView.getItemAtPosition(position);
            //                Toast.makeText(getApplicationContext(), item + " selected",
            //                        Toast.LENGTH_LONG).show();
          }

          // リスト項目がなにも選択されていない時の処理
          @Override
          public void onNothingSelected(AdapterView<?> parent) {
            Log.d(TAG, "onNothingSelected");
            //                Toast.makeText(getApplicationContext(), "no item selected",
            //                        Toast.LENGTH_LONG).show();
          }
        });

    // リスト項目が長押しされた時の処理
    listView.setOnItemLongClickListener(
        new AdapterView.OnItemLongClickListener() {
          @Override
          public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            ListView listView = (ListView) parent;
            Log.d(TAG, "onItemLongClick: " + position);
            //                String item = (String) listView.getItemAtPosition(position);
            //                Toast.makeText(getApplicationContext(), item + " long clicked",
            //                        Toast.LENGTH_LONG).show();
            return false;
          }
        });
    mHandler =
        new Handler() {
          // メッセージ受信
          public void handleMessage(Message message) {
            // メッセージの表示
            textView = (TextView) findViewById(R.id.textView);
            textView.setText((String) message.obj);
            Log.d(TAG, "mag: " + (String) message.obj);
            // メッセージの種類に応じてswitch文で制御すれば
            // イベント制御に利用できます
          };
        };
  }