public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_CONNECT_DEVICE_SECURE: // When DeviceListActivity returns with a device to connect if (resultCode == Activity.RESULT_OK) { connectDevice(data, true); } break; case REQUEST_CONNECT_DEVICE_INSECURE: // When DeviceListActivity returns with a device to connect if (resultCode == Activity.RESULT_OK) { connectDevice(data, false); } 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 setupChat(); } else { // User did not enable Bluetooth or an error occurred Log.d(TAG, "BT not enabled"); Toast.makeText(getActivity(), R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show(); getActivity().finish(); } } }
/** * The main processing method. This happens in a background task. In this case we are just * sampling down the bitmap and returning it from a resource. * * @param resId * @return */ private Bitmap processBitmap(int resId) { if (BuildConfig.DEBUG) { Log.d(TAG, "processBitmap - " + resId); } return decodeSampledBitmapFromResource( mResources, resId, mImageWidth, mImageHeight, getImageCache()); }
// BEGIN_INCLUDE(recyclerViewOnBindViewHolder) // Replace the contents of a view (invoked by the layout manager) @Override public void onBindViewHolder(ViewHolder viewHolder, final int position) { Log.d(TAG, "Element " + position + " set."); // Get element from your dataset at this position and replace the contents of the view // with that element // viewHolder.getTextView().setText(mDataSet[position]); if (mViewSet[position].getParent() != null) { ((LinearLayout) mViewSet[position].getParent()).removeAllViews(); } viewHolder.getLinearLayout().removeAllViews(); try { viewHolder.getLinearLayout().addView(mViewSet[position]); } catch (Exception e) { Log.d(TAG, "" + position); } }
/** Set up the UI and background operations for chat. */ private void setupChat() { Log.d(TAG, "setupChat()"); // Initialize the array adapter for the conversation thread mConversationArrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.message); mConversationView.setAdapter(mConversationArrayAdapter); // Initialize the compose field with a listener for the return key mOutEditText.setOnEditorActionListener(mWriteListener); // Initialize the send button with a listener that for click events mSendButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { // Send a message using content of the edit text widget View view = getView(); if (null != view) { TextView textView = (TextView) view.findViewById(R.id.edit_text_out); String message = textView.getText().toString(); sendMessage(message); } } }); mClearGraphButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { graphIndex = 0; graphControl.clearGraph(); } }); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( getActivity(), R.array.chart_spinner_values, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner mGraphSpinner.setAdapter(adapter); mGraphSpinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { graphIndex = 0; graphItemIndex = (int) id; mClearGraphButton.callOnClick(); } @Override public void onNothingSelected(AdapterView<?> parent) { // ? } }); // Initialize the BluetoothChatService to perform bluetooth connections mChatService = new BluetoothChatService(getActivity(), mHandler); mRecordButton.setOnClickListener( new RecordButtonClickListener(getActivity(), mChatService.getTelemetryFileService())); // Initialize the buffer for outgoing messages mOutStringBuffer = new StringBuffer(""); }