Ejemplo n.º 1
1
 @Override
 public void handleMessage(Message msg) {
   super.handleMessage(msg);
   int remote_cmd = 0;
   switch (msg.what) {
     case 1:
       Toast.makeText(MainActivity.this, "成功连接到服务器", Toast.LENGTH_SHORT).show();
       break;
     case 2:
       // 提取从服务器发过来的数据,然后发送给蓝牙设备
       remote_cmd = msg.getData().getInt("REMOTE_CMD");
       SendToBluetooth(mConnectThread, remote_cmd);
       break;
     case 3:
       ShowFailedConnectServerDialog(); // 如果连接服务器失败,则显示对话框
       break;
     case 4:
       Toast.makeText(MainActivity.this, "蓝牙设备连接成功", Toast.LENGTH_SHORT).show();
       tvinfo.setText(String.format("已经与蓝牙设备%s建立好连接", deviceName));
       deviceList.clear();
       break;
     default:
       break;
   }
 }
  private void initData(final MasterSlaveReceiver receiver) {
    channelMasterNamesAdapter.clear();
    for (String string : receiver.getMasterNames()) {
      channelMasterNamesAdapter.add(string);
    }
    channelMasterNamesAdapter.notifyDataSetChanged();

    channelSlaveNamesAdapter.clear();
    for (String string : receiver.getSlaveNames()) {
      channelSlaveNamesAdapter.add(string);
    }
    channelSlaveNamesAdapter.notifyDataSetChanged();

    int channelMasterPosition = channelMasterNamesAdapter.getPosition(receiver.getMaster() + "");
    if (channelMasterPosition == -1) {
      channelMasterPosition = 0;
    }
    channelMasterListView.setItemChecked(channelMasterPosition, true);
    channelMasterListView.smoothScrollToPosition(channelMasterPosition);

    int channelSlavePosition = channelSlaveNamesAdapter.getPosition(receiver.getSlave() + "");
    if (channelSlavePosition == -1) {
      channelSlavePosition = 0;
    }
    channelSlaveListView.setItemChecked(channelSlavePosition, true);
    channelSlaveListView.smoothScrollToPosition(channelSlavePosition);
  }
Ejemplo n.º 3
0
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   switch (requestCode) {
     case REQUEST_CONNECT_DEVICE:
       // When DeviceListActivity returns with a device to connect
       if (resultCode == Activity.RESULT_OK) {
         // Get the device MAC address
         String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
         // Get the BLuetoothDevice object
         BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
         // Attempt to connect to the device
         mCommandService.connect(device);
         arrayPlayer.clear();
         arrayAdapter.clear();
         arrayAdapter.notifyDataSetChanged();
       }
       break;
     case REQUEST_ENABLE_BT:
       // When the request to enable Bluetooth returns
       if (resultCode == Activity.RESULT_OK) {
         // Bluetooth is now enabled, so set up a chat session
         setupCommand();
       } else {
         // User did not enable Bluetooth or an error occured
         Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show();
         finish();
       }
   }
 }
Ejemplo n.º 4
0
  /**
   * displays data for different entities
   *
   * @param title
   * @param tablename
   */
  private void displayData(String title, String tablename) {
    //		Log.d(SystemInfo.TIG, TAG + "::displayData()");

    XYPlot plot = (XYPlot) findViewById(R.id.xyplot);
    arrayadapter.clear();
    List<Number> xseries = new ArrayList<Number>();
    List<Number> yseries = new ArrayList<Number>();

    for (int idx = 0; idx < DB_list.size(); ++idx) {
      DB_list.get(idx).generatePlotData(arrayadapter, xseries, yseries);
      this.drawGraph(plot, xseries, yseries, title, DB_list.get(idx).tablename());
    }
    // TODO rm
    /*
    		if( tablename.equals( SystemInfo.DB_TABLENAME_BATTERY) ){
    			DB.generatePlotData( arrayadapter, xseries, yseries );
    			this.drawGraph( plot, xseries, yseries, title, SystemInfo.DB_TABLENAME_BATTERY);
    		}else if( tablename.equals( SystemInfo.DB_TABLENAME_WIFI) ){
    			DB.generatePlotData( arrayadapter, xseries, yseries ); // XXX
    			this.drawGraph( plot, xseries, yseries, title, SystemInfo.DB_TABLENAME_WIFI);
    		}else if( tablename.equals( SystemInfo.DB_TABLENAME_THREEG) ){
    			DB.generatePlotData( arrayadapter, xseries, yseries );
    			this.drawGraph( plot, xseries, yseries, title, SystemInfo.DB_TABLENAME_THREEG);
    		}else if( tablename.equals( SystemInfo.DB_TABLENAME_BLUETOOTH) ){
    			DB.generatePlotData(arrayadapter, xseries, yseries );
    		}
    //*/
  }
 public void setItems(String[] items) {
   _items = items;
   mSelection = new boolean[_items.length];
   simple_adapter.clear();
   simple_adapter.add(_items[0]);
   Arrays.fill(mSelection, false);
 }
 public void setItems(List<String> items) {
   _items = items.toArray(new String[items.size()]);
   mSelection = new boolean[_items.length];
   simple_adapter.clear();
   simple_adapter.add(_items[0]);
   Arrays.fill(mSelection, false);
 }
 /** Sets the menu items to be displayed in the overflow. */
 public void setMenuItems(List<MenuItem> menuItems) {
   ArrayAdapter overflowListViewAdapter = (ArrayAdapter) mListView.getAdapter();
   overflowListViewAdapter.clear();
   overflowListViewAdapter.addAll(menuItems);
   setListViewHeight();
   setOverflowWidth();
 }
Ejemplo n.º 8
0
 /** Method to repopulate the Doctor's array adapter with changes produced in the edit dialog */
 @Override
 public void repopulateAdapter() {
   if (docAdap != null) {
     docAdap.clear();
     docAdap.addAll(MainActivity.drAdapter.getAllDrs());
   }
 }
Ejemplo n.º 9
0
  // Start device discover with the BluetoothAdapter
  private void doDiscovery() {
    if (D) Log.d(TAG, "doDiscovery()");

    // Remove all element from the list
    mPairedDevicesArrayAdapter.clear();

    // If there are paired devices, add each one to the ArrayAdapter
    if (pairedDevices.size() > 0) {
      for (BluetoothDevice device : pairedDevices) {
        mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
      }
    } else {
      String strNoFound = getIntent().getStringExtra("no_devices_found");
      if (strNoFound == null) strNoFound = "No devices found";
      mPairedDevicesArrayAdapter.add(strNoFound);
    }

    // Indicate scanning in the title
    String strScanning = getIntent().getStringExtra("scanning");
    if (strScanning == null) strScanning = "Scanning for devices...";
    setProgressBarIndeterminateVisibility(true);
    setTitle(strScanning);

    // Turn on sub-title for new devices
    // findViewById(R.id.title_new_devices).setVisibility(View.VISIBLE);
    // If we're already discovering, stop it
    if (mBtAdapter.isDiscovering()) {
      mBtAdapter.cancelDiscovery();
    }

    // Request discover from BluetoothAdapter
    mBtAdapter.startDiscovery();
  }
Ejemplo n.º 10
0
  private void doClear() {

    if (mBtAdapter.isDiscovering()) {
      mBtAdapter.cancelDiscovery();
    }
    mNewDevicesArrayAdapter.clear();
  }
  @OnClick(R.id.btn_demo_retrofit_contributors)
  public void onListContributorsClicked() {
    _adapter.clear();

    _subscriptions.add( //
        _api.contributors(_username.getText().toString(), _repo.getText().toString())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(
                new Observer<List<Contributor>>() {
                  @Override
                  public void onCompleted() {
                    Timber.d("Retrofit call 1 completed");
                  }

                  @Override
                  public void onError(Throwable e) {
                    Timber.e(e, "woops we got an error while getting the list of contributors");
                  }

                  @Override
                  public void onNext(List<Contributor> contributors) {
                    for (Contributor c : contributors) {
                      _adapter.add(
                          format(
                              "%s has made %d contributions to %s",
                              c.login, c.contributions, _repo.getText().toString()));

                      Timber.d(
                          "%s has made %d contributions to %s",
                          c.login, c.contributions, _repo.getText().toString());
                    }
                  }
                }));
  }
  @Override
  protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    try {
      loadFile();
      mAdapter.clear();
      for (int i = mFav.length() - 1; i >= 0; i--) {
        long dt = mFav.getJSONObject(i).getJSONObject("datetime").getLong("$date");
        Date datetime = new Date(dt);
        sdf1.setTimeZone(TimeZone.getTimeZone("GMT"));
        String crawlTime = sdf1.format(datetime);
        // String time = getTime(crawlTime);

        mAdapter.add(
            new String[] {
              mFav.getJSONObject(i).getString("from")
                  + " -> "
                  + mFav.getJSONObject(i).getString("to"),
              crawlTime
            });
        // +DateFormat.getDateFormat(GoodResultActivity.this).format(new
        // Date(jArray.getJSONObject(i).getLong("$date"))));
      }
      mAdapter.notifyDataSetChanged();
    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  @Subscribe
  public void onEventListUpdate(SystemEventListUpdateEvent event) {
    List<SystemEvent> newEvents = event.getEvents();
    if (!newEvents.isEmpty()) {
      Log.d(TAG, "Events updated: " + newEvents.size());
      for (SystemEvent e : newEvents) {
        if (!mCachedEvents.contains(e)) {
          mCachedEvents.add(e);
        }
      }

      Collections.sort(mCachedEvents, SyncManager.EVENTS_DESCENDING);
      while (mCachedEvents.size() > MAX_EVENTS) {
        mCachedEvents.remove(mCachedEvents.size() - 1);
      }
      mAdapter.clear();
      mAdapter.addAll(mCachedEvents);
    }

    if (mView != null) {
      if (mCachedEvents.isEmpty()) {
        mView.setVisibility(View.GONE);
      } else {
        mView.setVisibility(View.VISIBLE);
      }
    }
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // handle action bar item clicks
    switch (item.getItemId()) {
      case R.id.action_refresh:
        updateMovieGallery();
        return true;
      case R.id.action_sort_by_release:
        changeOrderBy(RELEASE_DATE_DESC);
        updateMovieGallery();

        return true;
      case R.id.action_sort_by_rating:
        changeOrderBy(VOTE_AVERAGE_DESC);
        updateMovieGallery();
        return true;
      case R.id.action_sort_by_popularity:
        changeOrderBy(POPULARITY_DESC);
        updateMovieGallery();
        return true;
      case R.id.action_get_favorites:
        mMoviesAdapter.clear();
        mMoviesAdapter.addAll(mListOfFavMovies);
      default:
        return super.onOptionsItemSelected(item);
    }
  }
Ejemplo n.º 15
0
  public void searchDevices() {
    currentBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (currentBluetoothAdapter.isDiscovering()) {

      currentBluetoothAdapter.cancelDiscovery();
    } else {
      // limpiamos el adaptador y empezamos a buscar dispositivos
      BTArrayAdapter.clear();
      this.devices.clear();

      /*for(BluetoothDevice device :  currentBluetoothAdapter.getBondedDevices()) {
          this.devices.add(device);


          String discoveryName  = device.getName();
          if (discoveryNameService != null)
          {
              discoveryName = discoveryNameService.foundDevice(device.getAddress(), device.getName());
          }

          BTArrayAdapter.add(discoveryName + "\n" + device.getAddress() );
      } */
      this.displayDiscoveryDialog();
      currentBluetoothAdapter.startDiscovery();
    }
  }
 @Override
 protected void onPostExecute(List<MovieInfo> movieInfos) {
   if (movieInfos != null) {
     associatedAdapter.clear();
     // Min version set to 15. addAll came in 11.
     associatedAdapter.addAll(movieInfos);
   }
 }
        @Override
        public void onLoadFinished(final Loader<List<Peer>> loader, final List<Peer> peers) {
          adapter.clear();

          if (peers != null) for (final Peer peer : peers) adapter.add(peer);

          setEmptyText(WholeStringBuilder.bold(getString(R.string.peer_list_fragment_empty)));
        }
Ejemplo n.º 18
0
        @Override
        public void handleMessage(Message msg) {
          // mConversationArrayAdapter.setNotifyOnChange(false);
          switch (msg.what) {
            case MESSAGE_STATE_CHANGE:
              if (D) Log.i(TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1);
              switch (msg.arg1) {
                case BluetoothThread1.STATE_CONNECTED:
                  mTitle.setText(R.string.title_connected_to);
                  mTitle.append(mConnectedDeviceName);
                  mConversationArrayAdapter.clear();
                  break;
                case BluetoothThread1.STATE_CONNECTING:
                  mTitle.setText(R.string.title_connecting);
                  break;
                case BluetoothThread1.STATE_LISTEN:
                case BluetoothThread1.STATE_NONE:
                  mTitle.setText(R.string.title_not_connected);
                  break;
              }
              break;
            case MESSAGE_WRITE:
              byte[] writeBuf = (byte[]) msg.obj;
              // construct a string from the buffer
              String writeMessage = new String(writeBuf);
              mConversationArrayAdapter.add("Me:  " + writeMessage);
              break;
            case MESSAGE_READ:
              byte[] readBuf = (byte[]) msg.obj;
              // construct a string from the valid bytes in the buffer
              String readMessage = new String(readBuf, 0, msg.arg1);
              // String readMessage = (String) msg.obj;
              // mConversationArrayAdapter.add(mConnectedDeviceName+":  " + readMessage);

              mConversationArrayAdapter.add(System.currentTimeMillis() + ": " + readMessage);
              break;
            case MESSAGE_DEVICE_NAME:
              // save the connected device's name
              mConnectedDeviceName = msg.getData().getString(DEVICE_NAME);
              Toast.makeText(
                      getApplicationContext(),
                      "Connected to " + mConnectedDeviceName,
                      Toast.LENGTH_SHORT)
                  .show();
              break;
            case MESSAGE_TOAST:
              Toast.makeText(
                      getApplicationContext(), msg.getData().getString(TOAST), Toast.LENGTH_SHORT)
                  .show();
              break;
            case MESSAGE_POSTURE_BAD:
              Toast.makeText(
                      getApplicationContext(), msg.getData().getString(TOAST), Toast.LENGTH_SHORT)
                  .show();
              v.vibrate(500);
              break;
          }
        }
 public void clearScreen() {
   this.acompanhamento = new Acompanhamento();
   EditText edtDataReferente = getEditTextDataReferente();
   edtDataReferente.getText().clear();
   clearSubAssuntos();
   assuntosAdapter.clear();
   EditText edtTempoEstudo = getEditTextTempoEstudo();
   edtTempoEstudo.getText().clear();
 }
 public void onClick(DialogInterface dialog, int which, boolean isChecked) {
   if (mSelection != null && which < mSelection.length) {
     mSelection[which] = isChecked;
     simple_adapter.clear();
     simple_adapter.add(buildSelectedItemString());
   } else {
     throw new IllegalArgumentException("Argument 'which' is out of bounds.");
   }
 }
Ejemplo n.º 21
0
 @Override
 public void onRequestSuccess(TagList tags) {
   Log.d("NewPostFragment", "tags: " + tags);
   if (tags != null) {
     mTagsListAdapter.clear();
     mTagsListAdapter.addAll(tags);
     mTagsListAdapter.notifyDataSetChanged();
   }
 }
Ejemplo n.º 22
0
        public void handleMessage(android.os.Message msg) {
          switch (msg.what) {
            case MSG_INIT_OK:
              ArrayAdapter<LogItem> adapter = (ArrayAdapter<LogItem>) getListView().getAdapter();

              adapter.setNotifyOnChange(false);

              adapter.clear();

              ArrayList<LogItem> data = (ArrayList<LogItem>) msg.obj;

              if (data != null) {
                for (int i = 0, size = data.size(); i < size; i++) {
                  adapter.add(data.get(i));
                }
              }

              adapter.notifyDataSetChanged();

              sendEmptyMessage(MSG_DISMISS_PROGRESS);

              if (adapter.getCount() == 0) {
                Util.shortToast(LogViewer.this, R.string.no_log_info);
              } else {
                getListView().setSelection(adapter.getCount() - 1);
              }

              break;
            case MSG_CONTENT_READY:
              sendEmptyMessage(MSG_DISMISS_PROGRESS);

              Util.handleMsgSendContentReady(
                  (String) msg.obj,
                  "Android Device Log - ", //$NON-NLS-1$
                  LogViewer.this,
                  msg.arg2 == 1);

              break;
            case MSG_CHECK_FORCE_COMPRESSION:
              sendEmptyMessage(MSG_DISMISS_PROGRESS);

              Util.checkForceCompression(
                  this, LogViewer.this, (String) msg.obj, msg.arg1, "android_log"); // $NON-NLS-1$

              break;
            case MSG_DISMISS_PROGRESS:
              if (progress != null) {
                progress.dismiss();
                progress = null;
              }
              break;
            case MSG_TOAST:
              Util.shortToast(LogViewer.this, (String) msg.obj);
              break;
          }
        };
Ejemplo n.º 23
0
 /**
  * Sets new list of groups and select specified groups.
  *
  * @param groups
  * @param selected
  */
 void setGroups(Collection<String> groups, Collection<String> selected) {
   ArrayList<String> list = new ArrayList<>(groups);
   Collections.sort(list);
   arrayAdapter.clear();
   for (int position = 0; position < list.size(); position++) {
     String group = list.get(position);
     arrayAdapter.add(group);
     listView.setItemChecked(position + listView.getHeaderViewsCount(), selected.contains(group));
   }
 }
 @Override
 protected void onPostExecute(String[] result) {
   if (result != null && mForecastAdapter != null) {
     mForecastAdapter.clear();
     for (String dayForecastStr : result) {
       mForecastAdapter.add(dayForecastStr);
     }
     // New data is back from the server.  Hooray!
   }
 }
Ejemplo n.º 25
0
 private void updateChannelByAdvancedSetting(int cbw, int dbw, int primCh) {
   if (cbw == 1) { // BW40
     mChannel.remove5GChannels(mChannelAdapter);
     mChannel.insertBw40MChannels(mChannelAdapter);
   } else if (cbw == 2) { // BW80
     // mChannel.remove2dot4GChannels(mChannelAdapter);
     // mChannel.remove5GChannels(mChannelAdapter);
     mChannelAdapter.clear();
     mChannel.insertBw80MChannels(mChannelAdapter);
   }
 }
Ejemplo n.º 26
0
  public void find(View view) {
    if (myBluetoothAdapter.isDiscovering()) {
      // the button is pressed when it discovers, so cancel the discovery
      myBluetoothAdapter.cancelDiscovery();
    } else {
      BTArrayAdapter.clear();
      myBluetoothAdapter.startDiscovery();

      registerReceiver(bReceiver, new IntentFilter(BluetoothDevice.ACTION_FOUND));
    }
  }
Ejemplo n.º 27
0
 @Override
 public void onGetSuggestionResult(SuggestionResult res) {
   if (res == null || res.getAllSuggestions() == null) {
     return;
   }
   sugAdapter.clear();
   for (SuggestionResult.SuggestionInfo info : res.getAllSuggestions()) {
     if (info.key != null) sugAdapter.add(info.key);
   }
   sugAdapter.notifyDataSetChanged();
 }
Ejemplo n.º 28
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.wifi_rx_6620);
    if (WiFi.is11acSupported()) {
      mIsAdvancedMode = true;
    }
    mTvFcs = (TextView) findViewById(R.id.WiFi_FCS_Content);
    mTvRx = (TextView) findViewById(R.id.WiFi_Rx_Content);
    mTvPer = (TextView) findViewById(R.id.WiFi_PER_Content);
    mTvFcs.setText(R.string.wifi_empty);
    mTvRx.setText(R.string.wifi_empty);
    mTvPer.setText(R.string.wifi_empty);
    mBtnGo = (Button) findViewById(R.id.WiFi_Go_Rx);
    mBtnStop = (Button) findViewById(R.id.WiFi_Stop_Rx);
    mBtnGo.setOnClickListener(this);
    mBtnStop.setOnClickListener(this);
    mInitData = new long[2];
    mChannel = new ChannelInfo();
    mChannelSpinner = (Spinner) findViewById(R.id.WiFi_RX_Channel_Spinner);
    mChannelAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
    mChannelAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mChannelAdapter.clear();
    for (int i = 1; i <= ChannelInfo.sChannels[0]; i++) {
      for (String s : mChannel.mFullChannelName) {
        if (s.startsWith("Channel " + ChannelInfo.sChannels[i] + " ")) {
          mChannelAdapter.add(s);
          break;
        }
      }
    }
    mChannelSpinner.setAdapter(mChannelAdapter);
    mChannelSpinner.setOnItemSelectedListener(mSpinnerListener);

    mBandwidthSpinner = (Spinner) findViewById(R.id.WiFi_Bandwidth_Spinner);
    // Bandwidth setings
    ArrayAdapter<String> bwAdapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
    bwAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    if (mIsAdvancedMode) {
      bwAdapter.add(mBandwidth[BW_INDX_ADVANCED]);
    } else {
      for (int i = 0; i < BW_INDX_ADVANCED; i++) {
        bwAdapter.add(mBandwidth[i]);
      }
    }
    mBandwidthSpinner.setAdapter(bwAdapter);
    mBandwidthSpinner.setOnItemSelectedListener(mSpinnerListener);
    mSpBwAdvCbw = (Spinner) findViewById(R.id.wifi_bandwidth_cbw_spn);
    mSpBwAdvDbw = (Spinner) findViewById(R.id.wifi_bandwidth_dbw_spn);
    mSpBwAdvPrimCh = (Spinner) findViewById(R.id.wifi_bandwidth_prim_ch_spn);
    setViewEnabled(true);
    initUiComponent();
  }
  private void loadData() {
    adap.clear();
    adap.addAll(dict.listWords());

    if (tvWordCount != null) {
      tvWordCount.setText(
          getText(R.string.word_count_dict)
              .toString()
              .replace("{{rep}}", dict.getWordCount() + ""));
    }
  }
Ejemplo n.º 30
0
 private void reloadHistoryItems() {
   Iterable<HistoryItem> items = historyManager.buildHistoryItems();
   adapter.clear();
   for (HistoryItem item : items) {
     adapter.add(item);
   }
   setTitle(originalTitle + " (" + adapter.getCount() + ')');
   if (adapter.isEmpty()) {
     adapter.add(new HistoryItem(null, null, null));
   }
 }