List of usage examples for android.widget Toast setGravity
public void setGravity(int gravity, int xOffset, int yOffset)
From source file:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java
public void imageSharing(Intent data, String type) { // Get the Uri of the selected file Uri uri = data.getData();/*from w w w . j a va 2s . com*/ Log.d("imageSharing - type", type + " @"); Log.d("File Uri: ", uri.toString() + " #"); // Get the path String path = null; try { path = getPath(this, uri); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.d("File Path: ", path + " #"); if (path != null) { String userNum = prefs.getString(stored_user_country_code, "") + prefs.getString(stored_user_mobile_no, ""); String fileName = System.currentTimeMillis() + getFileFormat(path); String msg; if (type.equals("video")) { msg = "VID-" + userNum + "-" + fileName; } else if (type.equals("audio")) { msg = "AUD-" + userNum + "-" + fileName; } else { msg = "IMG-" + userNum + "-" + fileName; } String numb = prefs.getString(stored_chatuserNumber, ""); Log.d("nnumb", numb + " #"); String savefileuri = saveImage(path, fileName, stripNumber(numb)); if (savefileuri.equals(FILE_SIZE_ERROR + "")) { Toast toast = Toast.makeText(getApplicationContext(), "you upload file size is exceed to 30 MB", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } else if (!savefileuri.equals("")) { Log.d("msg1", msg + " !"); sendInitmsg(msg, numb); new AsyncTaskUploadFile(savefileuri, msg).execute(); } else { Toast.makeText(getApplicationContext(), "File not found", Toast.LENGTH_SHORT).show(); } } }
From source file:com.ccxt.whl.activity.ChatActivity.java
/** * ?uri??//ww w . j a v a 2 s . c om * * @param selectedImage */ private void sendPicByUri(Uri selectedImage) { // String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage, null, null, null, null); if (cursor != null) { cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex("_data"); String picturePath = cursor.getString(columnIndex); cursor.close(); cursor = null; if (picturePath == null || picturePath.equals("null")) { Toast toast = Toast.makeText(this, "?", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return; } sendPicture(picturePath); } else { File file = new File(selectedImage.getPath()); if (!file.exists()) { Toast toast = Toast.makeText(this, "?", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return; } sendPicture(file.getAbsolutePath()); } }
From source file:com.nbplus.vbroadlauncher.fragment.LauncherFragment.java
public void handleMessage(Message msg) { if (msg == null) { return;/*from w ww.j a v a 2s. c o m*/ } switch (msg.what) { case HANDLER_MESSAGE_CONNECTIVITY_CHANGED: Log.d(TAG, "HANDLER_MESSAGE_CONNECTIVITY_CHANGED received !!!"); final boolean networkStatus = NetworkUtils.isConnected(getActivity()); if (mLastNetworkStatus == networkStatus) { Log.d(TAG, ">> current and previous are same status. ignore it..."); return; } mLastNetworkStatus = networkStatus; mWeatherView.onNetworkConnected(mLastNetworkStatus); if (mLastNetworkStatus) { // start push agent service VBroadcastServer serverInfo = LauncherSettings.getInstance(getActivity()).getServerInformation(); if (serverInfo != null && StringUtils.isEmptyString(serverInfo.getPushInterfaceServer()) == false) { Intent intent = new Intent(getActivity(), PushService.class); intent.setAction(PushConstants.ACTION_START_SERVICE); intent.putExtra(PushConstants.EXTRA_START_SERVICE_IFADDRESS, serverInfo.getPushInterfaceServer()); getActivity().startService(intent); } } break; case Constants.HANDLER_MESSAGE_PUSH_STATUS_CHANGED: int status = msg.arg1; Log.d(TAG, "HANDLER_MESSAGE_PUSH_STATUS_CHANGED received. status = " + status); if (status == PushConstants.PUSH_STATUS_VALUE_CONNECTED) { mPushServiceStatus.setImageResource(R.drawable.ic_nav_wifi_on); } else { mPushServiceStatus.setImageResource(R.drawable.ic_nav_wifi_off); } // int what = msg.arg2; // if (what == PushConstants.PUSH_STATUS_WHAT_NETORSERVER) { // new AlertDialog.Builder(getActivity()).setMessage("? ? ? ? ? ?? ? ?.") // //.setTitle(R.string.alert_network_title) // .setCancelable(true) // .setPositiveButton(R.string.alert_ok, // new DialogInterface.OnClickListener() { // public void onClick(DialogInterface dialog, int whichButton) { // dialog.dismiss(); // } // }) // .show(); // } break; case Constants.HANDLER_MESSAGE_PUSH_MESAGE_RECEIVED: PushPayloadData payloadData = (PushPayloadData) msg.obj; if (payloadData == null) { Log.d(TAG, "empty push message string !!"); return; } Log.d(TAG, "HANDLER_MESSAGE_PUSH_MESAGE_RECEIVED received = " + payloadData.getServiceType()); String type = payloadData.getServiceType(); switch (type) { // case Constants.PUSH_PAYLOAD_TYPE_REALTIME_BROADCAST: case Constants.PUSH_PAYLOAD_TYPE_NORMAL_BROADCAST: case Constants.PUSH_PAYLOAD_TYPE_TEXT_BROADCAST: { // , ?? ?, ? ?? .. // . View btnShortcut = null; for (int i = 0; i < mPushNotifiableShorcuts.size(); i++) { ShortcutData shortcut = mPushNotifiableShorcuts.get(i); String[] pushType = shortcut.getPushType(); if (pushType != null && pushType.length > 0 && Arrays.asList(pushType).indexOf(type) >= 0) { btnShortcut = shortcut.getLauncherButton(); break; } } // push notification badge . if (btnShortcut != null) { TextView badgeView = (TextView) btnShortcut.findViewById(R.id.launcher_menu_badge); if (badgeView != null) { badgeView.setVisibility(View.VISIBLE); } } break; } // case Constants.PUSH_PAYLOAD_TYPE_EMERGENCY_CALL: break; // case Constants.PUSH_PAYLOAD_TYPE_INHABITANTS_POLL: // ? case Constants.PUSH_PAYLOAD_TYPE_COOPERATIVE_BUYING: { View btnShortcut = null; for (int i = 0; i < mPushNotifiableShorcuts.size(); i++) { ShortcutData shortcut = mPushNotifiableShorcuts.get(i); String[] pushType = shortcut.getPushType(); if (pushType != null && pushType.length > 0 && Arrays.asList(pushType).indexOf(type) >= 0) { btnShortcut = shortcut.getLauncherButton(); break; } } // push notification badge . if (btnShortcut != null) { TextView badgeView = (TextView) btnShortcut.findViewById(R.id.launcher_menu_badge); if (badgeView != null) { badgeView.setVisibility(View.VISIBLE); } } break; } default: Log.d(TAG, "Unknown push payload type !!!"); break; } break; case Constants.HANDLER_MESSAGE_SEND_EMERGENCY_CALL_COMPLETE_TASK: { BaseApiResult result = (BaseApiResult) msg.obj; Toast toast; dismissProgressDialog(); if (result != null) { Log.d(TAG, ">> EMERGENCY CALL result code = " + result.getResultCode() + ", message = " + result.getResultMessage()); if (Constants.RESULT_OK.equals(result.getResultCode())) { toast = Toast.makeText(getActivity(), R.string.emergency_call_success_message, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } else { toast = Toast.makeText(getActivity(), result.getResultMessage(), Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } } else { toast = Toast.makeText(getActivity(), R.string.emergency_call_fail_message, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } break; } case HANDLER_MESSAGE_SET_VILLAGE_NAME: if (mVillageName != null) { mVillageName.setText(LauncherSettings.getInstance(getActivity()).getVillageName()); } if (mWeatherView != null) { mWeatherView.onChangedVillageName(); } break; // ?? ? case HANDLER_IOT_DATA_SYNC_COMPLETED: { if (!mIsProcessingIoTDataSync) { return; } mIsProcessingIoTDataSync = false; mHandler.postDelayed(new Runnable() { @Override public void run() { dismissProgressDialog(); } }, 1000); Toast toast; toast = Toast.makeText(getActivity(), R.string.toast_iot_data_sync, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); mIoTDataSyncText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_cached_white, 0, 0, 0); mIoTDataSyncText.setTextColor(getResources().getColor(R.color.white)); break; } case HANDLER_IOT_SERVICE_STATUS_CHANGED: { Bundle extras = msg.getData(); if (extras == null) { return; } boolean serviceStatus = extras.getBoolean(IoTConstants.EXTRA_SERVICE_STATUS); if (serviceStatus) { mIoTDataSyncText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_cached_white, 0, 0, 0); mIoTDataSyncText.setTextColor(getResources().getColor(R.color.white)); mIoTDataSync.setOnClickListener(mIoTSyncClickListener); mIoTDataSync.setClickable(true); mIoTDataSync.setEnabled(true); } else { mIoTDataSyncText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_cached_grey600, 0, 0, 0); mIoTDataSyncText.setTextColor(getResources().getColor(R.color.btn_color_absentia_off)); mIoTDataSync.setOnClickListener(null); mIoTDataSync.setClickable(false); mIoTDataSync.setEnabled(false); } } } }
From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java
private Toast createToastShort(String text) { Toast toast = new Toast(this); TextView tv = new TextView(this); tv.setText(text);/*from ww w. j ava 2 s.c om*/ tv.setTextColor(ContextCompat.getColor(this, R.color.colorAccent)); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, TOAST_TEXT_SIZE); // int pixel = (int)mWindowDensity * 56; int toastMargin = getResources().getDimensionPixelSize(R.dimen.toast_margin_top_bottom); tv.setPadding(0, toastMargin, 0, toastMargin); toast.setView(tv); toast.setGravity(mToastPosition, 0, 0); toast.setDuration(Toast.LENGTH_SHORT); return toast; }
From source file:co.taqat.call.CallActivity.java
public void displayCustomToast(final String message, final int duration) { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toastRoot)); TextView toastText = (TextView) layout.findViewById(R.id.toastMessage); toastText.setText(message);// w w w . j a va 2 s .co m final Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.CENTER, 0, 0); toast.setDuration(duration); toast.setView(layout); toast.show(); }
From source file:com.interestfriend.activity.ChatActivity.java
/** * uri/*from ww w. ja va 2s. c o m*/ * * @param selectedImage */ private void sendPicByUri(Uri selectedImage) { // String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage, null, null, null, null); if (cursor != null) { cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex("_data"); String picturePath = cursor.getString(columnIndex); cursor.close(); cursor = null; if (picturePath == null || picturePath.equals("null")) { Toast toast = Toast.makeText(this, "", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return; } sendPicture(picturePath); } else { File file = new File(selectedImage.getPath()); if (!file.exists()) { Toast toast = Toast.makeText(this, "", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return; } sendPicture(file.getAbsolutePath()); } }
From source file:com.devwang.logcabin.LogCabinMainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Intent serverIntent = null;/*w w w. j ava2s . com*/ Toast toast = Toast.makeText(LogCabinMainActivity.this, "", Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); switch (item.getItemId()) { case R.id.secure_connect_scan:// // Launch the DeviceListActivity to see devices and do scan serverIntent = new Intent(this, DeviceListActivity.class); startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_SECURE); return true; case R.id.insecure_connect_scan:// // Launch the DeviceListActivity to see devices and do scan serverIntent = new Intent(this, DeviceListActivity.class); startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_INSECURE); return true; case R.id.app_developer: toastDisplay(LogCabinMainActivity.this, ": \n\nQQ:1120341494\n:dongleixiaxue314\n :http://www.devwang.com", Gravity.CENTER, R.drawable.hutview, Toast.LENGTH_SHORT); return true; case R.id.app_cmd_what: case R.id.app_voice_what: toast.setText( "\n\n\n\n..."); toast.show(); return true; case R.id.app_college: toast.setText(R.string.str_college); toast.show(); return true; case R.id.app_web_url: toastDisplay(LogCabinMainActivity.this, getString(R.string.http_devwang_sinaapp_com_logcabin_logcabin_web_php), Gravity.CENTER, 0, Toast.LENGTH_SHORT); return true; case R.id.app_update: android.app.AlertDialog.Builder dialog = new AlertDialog.Builder(LogCabinMainActivity.this); LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.dialogview_appupdate, null); dialog.setView(layout); appUpdateEditText = (EditText) layout.findViewById(R.id.et_appupdate); dialog.setPositiveButton(R.string.str_app_update_sure, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String appUpdateEditTextString = appUpdateEditText.getText().toString(); if ("devwang".equals(appUpdateEditTextString.toString())) { AppUpdate = true; Toast.makeText(getApplicationContext(), R.string.str_app_update_pass_toast, Toast.LENGTH_SHORT).show(); } } }); dialog.show(); return true; } return false; }
From source file:flex.android.magiccube.activity.ActivityBattleMode.java
public void SaveReplay() { // TODO Auto-generated method stub if (dbHelper == null) { dbHelper = new DBHelper(this); }/* ww w. j a v a2 s . c om*/ dbHelper.create(TableName, TableContent); ContentValues values = new ContentValues(); values.put("cmdstrbefore", this.GetCmdStrBefore()); values.put("cmdstrafter", this.GetCmdStrAfter()); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); String datestr = dateFormat.format(date); values.put("savetime", datestr); values.put("movetimes", this.GetMoveTimes()); dbHelper.insert(TableName, values); Toast toast; if (State == OnStateListener.WIN) { toast = Toast.makeText(getApplicationContext(), "" + datestr, Toast.LENGTH_LONG); } else { toast = Toast.makeText(getApplicationContext(), "" + datestr, Toast.LENGTH_LONG); } toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); }
From source file:io.puzzlebox.bloom.ui.MakerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View v = inflater.inflate(R.layout.fragment_maker, container, false); // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // setContentView(R.layout.main); // getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title); progressBarRange = (ProgressBar) v.findViewById(R.id.progressBarRange); //// ShapeDrawable progressBarRangeDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null,null)); // ShapeDrawable progressBarRangeDrawable = new ShapeDrawable(); //// String progressBarRangeColor = "#FF00FF"; // String progressBarRangeColor = "#990099"; // progressBarRangeDrawable.getPaint().setColor(Color.parseColor(progressBarRangeColor)); // ClipDrawable progressRange = new ClipDrawable(progressBarRangeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); // progressBarRange.setProgressDrawable(progressRange); // progressBarRange.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal)); // progressBarRange.setMax(128 + 127); progressBarRange.setMax(bloomRangeMax); // imageViewStatus = (ImageView) v.findViewById(R.id.imageViewStatus); servoSeekBar = (SeekBar) v.findViewById(R.id.ServoSeekBar); servoSeekBar.setEnabled(false);// www . java 2 s . com // servoSeekBar.setMax(180); servoSeekBar.setMax(100); servoSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { byte[] buf = new byte[] { (byte) 0x03, (byte) 0x00, (byte) 0x00 }; buf[1] = (byte) servoSeekBar.getProgress(); BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); // rssiValue = (TextView) v.findViewById(R.id.rssiValue); connectBloom = (Button) v.findViewById(R.id.connectBloom); connectBloom.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { if (!BloomSingleton.getInstance().scanFlag) { scanLeDevice(); Timer mTimer = new Timer(); mTimer.schedule(new TimerTask() { @Override public void run() { if ((BloomSingleton.getInstance().mDevice != null) && (BloomSingleton.getInstance().mDevice.getAddress() != null) && (BloomSingleton.getInstance().mBluetoothLeService != null)) { BloomSingleton .getInstance().mDeviceAddress = BloomSingleton.getInstance().mDevice .getAddress(); if (BloomSingleton.getInstance().mDeviceAddress != null) BloomSingleton.getInstance().mBluetoothLeService .connect(BloomSingleton.getInstance().mDeviceAddress); else { Toast toast = Toast.makeText(getActivity(), "Error connecting to Puzzlebox Bloom", Toast.LENGTH_SHORT); toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM); toast.show(); } BloomSingleton.getInstance().scanFlag = true; } else { getActivity().runOnUiThread(new Runnable() { public void run() { Toast toast = Toast.makeText(getActivity(), "Error connecting to Puzzlebox Bloom", Toast.LENGTH_SHORT); toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM); toast.show(); } }); } } }, BloomSingleton.getInstance().SCAN_PERIOD); } } catch (Exception e) { Log.e(TAG, "Exception connecting to Bloom: " + e); Toast toast = Toast.makeText(getActivity(), "Exception connecting to Puzzlebox Bloom", Toast.LENGTH_SHORT); toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM); toast.show(); } System.out.println(BloomSingleton.getInstance().connState); // Log.e(TAG, connState); // if (connState == false) { if (!BloomSingleton.getInstance().connState && BloomSingleton.getInstance().mDeviceAddress != null) { BloomSingleton.getInstance().mBluetoothLeService .connect(BloomSingleton.getInstance().mDeviceAddress); } else { if (BloomSingleton.getInstance().mBluetoothLeService != null) { setBloomRGBOff(); BloomSingleton.getInstance().mBluetoothLeService.disconnect(); BloomSingleton.getInstance().mBluetoothLeService.close(); setButtonDisable(); } } } }); redSeekBar = (SeekBar) v.findViewById(R.id.seekBarRed); redSeekBar.setEnabled(false); redSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { bloomColorRed = redSeekBar.getProgress(); byte[] buf = new byte[] { (byte) 0x0A, (byte) 0x00, (byte) bloomColorRed }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); greenSeekBar = (SeekBar) v.findViewById(R.id.seekBarGreen); greenSeekBar.setEnabled(false); greenSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { bloomColorGreen = greenSeekBar.getProgress(); byte[] buf = new byte[] { (byte) 0x0A, (byte) 0x01, (byte) bloomColorGreen }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); blueSeekBar = (SeekBar) v.findViewById(R.id.seekBarBlue); blueSeekBar.setEnabled(false); blueSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { bloomColorBlue = blueSeekBar.getProgress(); byte[] buf = new byte[] { (byte) 0x0A, (byte) 0x02, (byte) bloomColorBlue }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); buttonOpen = (Button) v.findViewById(R.id.buttonOpen); buttonOpen.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { byte[] buf = new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00 }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); buttonClose = (Button) v.findViewById(R.id.buttonClose); buttonClose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { byte[] buf = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00 }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); buttonCycleServo = (Button) v.findViewById(R.id.buttonDemoServo); buttonCycleServo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { byte[] buf = new byte[] { (byte) 0x03, (byte) 0x00, (byte) 0x00 }; // Cycle // byte[] buf = new byte[] { (byte) 0x04, (byte) 0x00, (byte) 0x00 }; // CycleSlow BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); buttonCycleRGB = (Button) v.findViewById(R.id.buttonDemoRGB); buttonCycleRGB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { byte[] buf = new byte[] { (byte) 0x06, (byte) 0x00, (byte) 0x00 }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); updateBloomRGB(); } }); buttonDemo = (Button) v.findViewById(R.id.buttonDemo); buttonDemo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { byte[] buf = new byte[] { (byte) 0x05, (byte) 0x00, (byte) 0x00 }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); // buttonDemo = (Button) v.findViewById(R.id.buttonDemo); // buttonDemo.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // byte[] buf; //// if (! BloomSingleton.getInstance().demoActive) { // BloomSingleton.getInstance().demoActive = true; // // // bloomOpen() //// buf = new byte[]{(byte) 0x01, (byte) 0x00, (byte) 0x00}; //// BloomSingleton.getInstance().characteristicTx.setValue(buf); //// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // // // loopRGB() // buf = new byte[]{(byte) 0x06, (byte) 0x00, (byte) 0x00}; // BloomSingleton.getInstance().characteristicTx.setValue(buf); // BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // // // Set Red to 0 // buf = new byte[]{(byte) 0x0A, (byte) 0x00, (byte) 0x00}; // R = 0 // BloomSingleton.getInstance().characteristicTx.setValue(buf); // BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // // // bloomClose() //// buf = new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00}; //// BloomSingleton.getInstance().characteristicTx.setValue(buf); //// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // // //// } else { //// BloomSingleton.getInstance().demoActive = false; ////// buf = new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00}; ////// BloomSingleton.getInstance().characteristicTx.setValue(buf); ////// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); //// buf = new byte[]{(byte) 0x0A, (byte) 0x00, (byte) 0x00}; // R = 0 //// BloomSingleton.getInstance().characteristicTx.setValue(buf); //// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); ////// buf = new byte[]{(byte) 0x0A, (byte) 0x01, (byte) 0x00}; // G = 0 ////// BloomSingleton.getInstance().characteristicTx.setValue(buf); ////// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); ////// buf = new byte[]{(byte) 0x0A, (byte) 0x02, (byte) 0x00}; // B = 0 ////// BloomSingleton.getInstance().characteristicTx.setValue(buf); ////// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); //// } // } // }); if (!getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(getActivity(), "Bluetooth LE not supported", Toast.LENGTH_SHORT).show(); getActivity().finish(); } final BluetoothManager mBluetoothManager = (BluetoothManager) getActivity() .getSystemService(Context.BLUETOOTH_SERVICE); BloomSingleton.getInstance().mBluetoothAdapter = mBluetoothManager.getAdapter(); if (BloomSingleton.getInstance().mBluetoothAdapter == null) { Toast.makeText(getActivity(), "Bluetooth LE not supported", Toast.LENGTH_SHORT).show(); getActivity().finish(); return v; } Intent gattServiceIntent = new Intent(getActivity(), RBLService.class); // bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE); getActivity().bindService(gattServiceIntent, mServiceConnection, getActivity().BIND_AUTO_CREATE); /** * Update settings according to default UI */ updateScreenLayout(); // updatePowerThresholds(); // updatePower(); if (BloomSingleton.getInstance().connState) { setButtonEnable(); updateBloomRGB(); } return v; }
From source file:cn.kangeqiu.kq.activity.ChatActivity.java
/** * ?uri??//www . ja v a 2 s.co m * * @param selectedImage */ private void sendPicByUri(Uri selectedImage) { // String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage, null, null, null, null); String st8 = getResources().getString(R.string.cant_find_pictures); if (cursor != null) { cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex("_data"); String picturePath = cursor.getString(columnIndex); cursor.close(); cursor = null; if (picturePath == null || picturePath.equals("null")) { Toast toast = Toast.makeText(this, st8, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return; } sendPicture(picturePath); } else { File file = new File(selectedImage.getPath()); if (!file.exists()) { Toast toast = Toast.makeText(this, st8, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return; } sendPicture(file.getAbsolutePath()); } }