List of usage examples for android.graphics BitmapFactory decodeResource
public static Bitmap decodeResource(Resources res, int id)
From source file:cn.ucai.fulicenter.activity.ChatActivity.java
/** * onActivityResult// w w w . j a v a 2 s . co m */ protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_CODE_EXIT_GROUP) { setResult(RESULT_OK); finish(); return; } if (requestCode == REQUEST_CODE_CONTEXT_MENU) { switch (resultCode) { case RESULT_CODE_COPY: // ?? EMMessage copyMsg = ((EMMessage) adapter.getItem(data.getIntExtra("position", -1))); // clipboard.setText(SmileUtils.getSmiledText(ChatActivity.this, // ((TextMessageBody) copyMsg.getBody()).getMessage())); clipboard.setText(((TextMessageBody) copyMsg.getBody()).getMessage()); break; case RESULT_CODE_DELETE: // ? EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1)); conversation.removeMessage(deleteMsg.getMsgId()); adapter.refreshSeekTo(data.getIntExtra("position", adapter.getCount()) - 1); break; case RESULT_CODE_FORWARD: // ?? EMMessage forwardMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", 0)); Intent intent = new Intent(this, ForwardMessageActivity.class); intent.putExtra("forward_msg_id", forwardMsg.getMsgId()); startActivity(intent); break; default: break; } } if (resultCode == RESULT_OK) { // ? if (requestCode == REQUEST_CODE_EMPTY_HISTORY) { // ? EMChatManager.getInstance().clearConversation(toChatUsername); adapter.refresh(); } else if (requestCode == REQUEST_CODE_CAMERA) { // ?? if (cameraFile != null && cameraFile.exists()) sendPicture(cameraFile.getAbsolutePath()); } else if (requestCode == REQUEST_CODE_SELECT_VIDEO) { // ?? int duration = data.getIntExtra("dur", 0); String videoPath = data.getStringExtra("path"); File file = new File(PathUtil.getInstance().getImagePath(), "thvideo" + System.currentTimeMillis()); Bitmap bitmap = null; FileOutputStream fos = null; try { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, 3); if (bitmap == null) { EMLog.d("chatactivity", "problem load video thumbnail bitmap,use default icon"); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.app_panel_video_icon); } fos = new FileOutputStream(file); bitmap.compress(CompressFormat.JPEG, 100, fos); } catch (Exception e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } fos = null; } if (bitmap != null) { bitmap.recycle(); bitmap = null; } } sendVideo(videoPath, file.getAbsolutePath(), duration / 1000); } else if (requestCode == REQUEST_CODE_LOCAL) { // ?? if (data != null) { Uri selectedImage = data.getData(); if (selectedImage != null) { sendPicByUri(selectedImage); } } } else if (requestCode == REQUEST_CODE_SELECT_FILE) { // ?? if (data != null) { Uri uri = data.getData(); if (uri != null) { sendFile(uri); } } } else if (requestCode == REQUEST_CODE_MAP) { // double latitude = data.getDoubleExtra("latitude", 0); double longitude = data.getDoubleExtra("longitude", 0); String locationAddress = data.getStringExtra("address"); if (locationAddress != null && !locationAddress.equals("")) { toggleMore(more); sendLocationMsg(latitude, longitude, "", locationAddress); } else { String st = getResources().getString(R.string.unable_to_get_loaction); Toast.makeText(this, st, Toast.LENGTH_SHORT).show(); } // ??? } else if (requestCode == REQUEST_CODE_TEXT || requestCode == REQUEST_CODE_VOICE || requestCode == REQUEST_CODE_PICTURE || requestCode == REQUEST_CODE_LOCATION || requestCode == REQUEST_CODE_VIDEO || requestCode == REQUEST_CODE_FILE) { resendMessage(); } else if (requestCode == REQUEST_CODE_COPY_AND_PASTE) { // if (!TextUtils.isEmpty(clipboard.getText())) { String pasteText = clipboard.getText().toString(); if (pasteText.startsWith(COPY_IMAGE)) { // ??path sendPicture(pasteText.replace(COPY_IMAGE, "")); } } } else if (requestCode == REQUEST_CODE_ADD_TO_BLACKLIST) { // ??? EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1)); addUserToBlacklist(deleteMsg.getFrom()); } else if (conversation.getMsgCount() > 0) { adapter.refresh(); setResult(RESULT_OK); } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) { adapter.refresh(); } } }
From source file:es.upv.riromu.arbre.main.MainActivity.java
/***************************************************************/ @Override//from w ww .j av a 2 s . co m protected void onActivityResult(int requestCode, int resultCode, Intent returnedIntent) { super.onActivityResult(requestCode, resultCode, returnedIntent); switch (requestCode) { case PICK_IMAGE: if (resultCode == RESULT_OK) { resetVisibility(PICK_IMAGE); try { state[PICK_IMAGE] = true; state[CROP_IMAGE] = false; state[TREAT_IMAGE] = false; captura = String.valueOf(System.currentTimeMillis() / 1000L); ImageView imv = (ImageView) findViewById(R.id.image_intro); image_uri = returnedIntent.getData(); InputStream is = getContentResolver().openInputStream(returnedIntent.getData()); imv.setImageBitmap(BitmapFactory.decodeStream(is)); is.close(); RangeSeekBar<Integer> seekBar = (RangeSeekBar<Integer>) findViewById(R.id.rangeseekbar); seekBar.setVisibility(View.GONE); } catch (IOException e) { Log.e(TAG, "Error reading from gallery" + e.getMessage()); } catch (Exception e) { Log.e(TAG, "Error reading from gallery" + e.getMessage()); } } break; case CAPTURE_IMAGE: try { if (resultCode == RESULT_OK) { resetVisibility(CAPTURE_IMAGE); captura = String.valueOf(System.currentTimeMillis() / 1000L); state[PICK_IMAGE] = false; state[CROP_IMAGE] = false; state[TREAT_IMAGE] = false; TextView imc = (TextView) findViewById(R.id.textView); imc.setBackgroundColor(Color.rgb(255, 255, 255)); RangeSeekBar<Integer> seekBar = (RangeSeekBar<Integer>) findViewById(R.id.rangeseekbar); seekBar.setVisibility(View.GONE); if (returnedIntent != null) { setPic(); Bundle extras = returnedIntent.getExtras(); setSelectedImage(returnedIntent.getData()); } else { ImageView imv = (ImageView) findViewById(R.id.image_intro); image = Util.decodeSampledBitmapFromUri(image_uri, MAX_SIZE, MAX_SIZE, this); imv.setImageBitmap(image); gpstracker = new GPSTracking(this); if (gpstracker.canGetLocation()) { latitude = String.valueOf(gpstracker.getLatitude()); longitude = String.valueOf(gpstracker.getLongitude()); } else { gpstracker.showSettingsAlert(); } } } } catch (Exception e) { Log.e(TAG, "Error " + e.getMessage()); } break; case CROP_IMAGE: try { if (resultCode == RESULT_OK) { state[CROP_IMAGE] = true; state[TREAT_IMAGE] = false; RangeSeekBar<Integer> seekBar = (RangeSeekBar<Integer>) findViewById(R.id.rangeseekbar); seekBar.setVisibility(View.VISIBLE); ImageTreatment imt = null; Bundle extras = returnedIntent.getExtras(); if (extras != null) { croppedimage_uri = Uri.parse(extras.getString(RETURN_DATA)); // croppedimage=extras.getParcelable(RETURN_DATA_AS_BITMAP); if (croppedimage_uri != null) { InputStream is = getContentResolver().openInputStream(croppedimage_uri); croppedimage = BitmapFactory.decodeStream(is); is.close(); } else { image = BitmapFactory.decodeResource(getResources(), R.drawable.platanus_hispanica); } ImageView imv = (ImageView) findViewById(R.id.image_intro); imv.setImageBitmap(croppedimage); colours[COLOUR_R] = (int) imt.getRedColor(); colours[COLOUR_B] = (int) imt.getBlueColor(); colours[COLOUR_G] = (int) imt.getGreenColor(); } } } catch (OutOfMemoryError e) { Log.e(TAG, "Error " + e.getMessage()); } catch (IOException e) { Log.e(TAG, "Error " + e.getMessage()); } catch (Exception e) { Log.e(TAG, "Error " + e.getMessage()); } } }
From source file:com.app.khclub.base.easeim.activity.ChatActivity.java
/** * onActivityResult//from w w w. jav a 2 s . c o m */ protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_CODE_EXIT_GROUP) { setResult(RESULT_OK); finish(); return; } if (requestCode == REQUEST_CODE_CONTEXT_MENU) { switch (resultCode) { case RESULT_CODE_COPY: // ?? EMMessage copyMsg = ((EMMessage) adapter.getItem(data.getIntExtra("position", -1))); // clipboard.setText(SmileUtils.getSmiledText(ChatActivity.this, // ((TextMessageBody) copyMsg.getBody()).getMessage())); clipboard.setText(((TextMessageBody) copyMsg.getBody()).getMessage()); break; case RESULT_CODE_DELETE: // ? EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1)); conversation.removeMessage(deleteMsg.getMsgId()); adapter.refreshSeekTo(data.getIntExtra("position", adapter.getCount()) - 1); break; case RESULT_CODE_FORWARD: // ?? EMMessage forwardMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", 0)); Intent intent = new Intent(this, ForwardMessageActivity.class); intent.putExtra("forward_msg_id", forwardMsg.getMsgId()); startActivity(intent); break; default: break; } } if (resultCode == RESULT_OK) { // ? LogUtils.i("!!! " + requestCode + " " + resultCode, 1); if (requestCode == REQUEST_CODE_EMPTY_HISTORY) { // ? EMChatManager.getInstance().clearConversation(toChatUsername); adapter.refresh(); } else if (requestCode == REQUEST_CODE_CAMERA) { // ?? if (cameraFile != null && cameraFile.exists()) sendPicture(cameraFile.getAbsolutePath()); } else if (requestCode == REQUEST_CODE_SELECT_VIDEO) { // ?? int duration = data.getIntExtra("dur", 0); String videoPath = data.getStringExtra("path"); File file = new File(PathUtil.getInstance().getImagePath(), "thvideo" + System.currentTimeMillis()); Bitmap bitmap = null; FileOutputStream fos = null; try { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, 3); if (bitmap == null) { EMLog.d("chatactivity", "problem load video thumbnail bitmap,use default icon"); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.app_panel_video_icon); } fos = new FileOutputStream(file); bitmap.compress(CompressFormat.JPEG, 100, fos); } catch (Exception e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } fos = null; } if (bitmap != null) { bitmap.recycle(); bitmap = null; } } sendVideo(videoPath, file.getAbsolutePath(), duration / 1000); } else if (requestCode == REQUEST_CODE_LOCAL) { // ?? if (data != null) { Uri selectedImage = data.getData(); if (selectedImage != null) { sendPicByUri(selectedImage); } } } else if (requestCode == REQUEST_CODE_SELECT_FILE) { // ?? if (data != null) { Uri uri = data.getData(); if (uri != null) { sendFile(uri); } } } else if (requestCode == REQUEST_CODE_MAP) { // double latitude = data.getDoubleExtra("latitude", 0); double longitude = data.getDoubleExtra("longitude", 0); String locationAddress = data.getStringExtra("address"); if (locationAddress != null && !locationAddress.equals("")) { toggleMore(more); sendLocationMsg(latitude, longitude, "", locationAddress); } else { String st = getResources().getString(R.string.unable_to_get_loaction); Toast.makeText(this, st, 0).show(); } // ??? } else if (requestCode == REQUEST_CODE_TEXT || requestCode == REQUEST_CODE_VOICE || requestCode == REQUEST_CODE_PICTURE || requestCode == REQUEST_CODE_LOCATION || requestCode == REQUEST_CODE_VIDEO || requestCode == REQUEST_CODE_FILE) { resendMessage(); } else if (requestCode == REQUEST_CODE_COPY_AND_PASTE) { // if (!TextUtils.isEmpty(clipboard.getText())) { String pasteText = clipboard.getText().toString(); if (pasteText.startsWith(COPY_IMAGE)) { // ??path sendPicture(pasteText.replace(COPY_IMAGE, "")); } } } else if (requestCode == REQUEST_CODE_ADD_TO_BLACKLIST) { // ??? EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1)); addUserToBlacklist(deleteMsg.getFrom()); } else if (conversation.getMsgCount() > 0) { adapter.refresh(); setResult(RESULT_OK); } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) { adapter.refresh(); } if (requestCode == REQUEST_CODE_CARD) { //???? String[] newmembers = data.getStringArrayExtra("newmembers"); LogUtils.i(newmembers.toString(), 1); if (newmembers.length > 0) { sendCard(EMMessage.ChatType.Chat.ordinal(), newmembers[0], ""); } } } }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void makeFavsNotification(ArrayList<String[]> tweets, Context context, boolean toDrawer) { String shortText;/*from w ww. j a v a 2 s .c o m*/ String longText; String title; int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon; Intent resultIntent; if (toDrawer) { resultIntent = new Intent(context, RedirectToDrawer.class); } else { resultIntent = new Intent(context, NotiTweetPager.class); } PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.InboxStyle inbox = null; if (tweets.size() == 1) { title = tweets.get(0)[0]; shortText = tweets.get(0)[1]; longText = shortText; largeIcon = getImage(context, tweets.get(0)[2]); } else { inbox = new NotificationCompat.InboxStyle(); title = context.getResources().getString(R.string.favorite_users); shortText = tweets.size() + " " + context.getResources().getString(R.string.fav_user_tweets); longText = ""; try { inbox.setBigContentTitle(shortText); } catch (Exception e) { } if (tweets.size() <= 5) { for (String[] s : tweets) { inbox.addLine(Html.fromHtml("<b>" + s[0] + ":</b> " + s[1])); } } else { for (int i = 0; i < 5; i++) { inbox.addLine(Html.fromHtml("<b>" + tweets.get(i)[0] + ":</b> " + tweets.get(i)[1])); } inbox.setSummaryText("+" + (tweets.size() - 5) + " " + context.getString(R.string.tweets)); } largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); } NotificationCompat.Builder mBuilder; AppSettings settings = AppSettings.getInstance(context); if (shortText.contains("@" + settings.myScreenName)) { // return because there is a mention notification for this already return; } Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent).setAutoCancel(true) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (inbox == null) { mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText))); } else { mBuilder.setStyle(inbox); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(2, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (context .getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE) .getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, shortText); } // Light Flow notification sendToLightFlow(context, title, shortText); } }
From source file:com.dngames.mobilewebcam.PhotoSettings.java
@Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if (key == "cam_refresh") { int new_refresh = getEditInt(mContext, prefs, "cam_refresh", 60); String msg = "Camera refresh set to " + new_refresh + " seconds!"; if (MobileWebCam.gIsRunning) { if (!mNoToasts && new_refresh != mRefreshDuration) { try { Toast.makeText(mContext.getApplicationContext(), msg, Toast.LENGTH_SHORT).show(); } catch (RuntimeException e) { e.printStackTrace(); }//from w ww . j a v a2 s .com } } else if (new_refresh != mRefreshDuration) { MobileWebCam.LogI(msg); } } // get all preferences for (Field f : getClass().getFields()) { { BooleanPref bp = f.getAnnotation(BooleanPref.class); if (bp != null) { try { f.setBoolean(this, prefs.getBoolean(bp.key(), bp.val())); } catch (Exception e) { Log.e("MobileWebCam", "Exception: " + bp.key() + " <- " + bp.val()); e.printStackTrace(); } } } { EditIntPref ip = f.getAnnotation(EditIntPref.class); if (ip != null) { try { int eval = getEditInt(mContext, prefs, ip.key(), ip.val()) * ip.factor(); if (ip.max() != Integer.MAX_VALUE) eval = Math.min(eval, ip.max()); if (ip.min() != Integer.MIN_VALUE) eval = Math.max(eval, ip.min()); f.setInt(this, eval); } catch (Exception e) { e.printStackTrace(); } } } { IntPref ip = f.getAnnotation(IntPref.class); if (ip != null) { try { int eval = prefs.getInt(ip.key(), ip.val()) * ip.factor(); if (ip.max() != Integer.MAX_VALUE) eval = Math.min(eval, ip.max()); if (ip.min() != Integer.MIN_VALUE) eval = Math.max(eval, ip.min()); f.setInt(this, eval); } catch (Exception e) { // handle wrong set class e.printStackTrace(); Editor edit = prefs.edit(); edit.remove(ip.key()); edit.putInt(ip.key(), ip.val()); edit.commit(); try { f.setInt(this, ip.val()); } catch (IllegalArgumentException e1) { e1.printStackTrace(); } catch (IllegalAccessException e1) { e1.printStackTrace(); } } } } { EditFloatPref fp = f.getAnnotation(EditFloatPref.class); if (fp != null) { try { float eval = getEditFloat(mContext, prefs, fp.key(), fp.val()); if (fp.max() != Float.MAX_VALUE) eval = Math.min(eval, fp.max()); if (fp.min() != Float.MIN_VALUE) eval = Math.max(eval, fp.min()); f.setFloat(this, eval); } catch (Exception e) { e.printStackTrace(); } } } { StringPref sp = f.getAnnotation(StringPref.class); if (sp != null) { try { f.set(this, prefs.getString(sp.key(), getDefaultString(mContext, sp))); } catch (Exception e) { e.printStackTrace(); } } } } mCustomImageScale = Enum.valueOf(ImageScaleMode.class, prefs.getString("custompicscale", "CROP")); mAutoStart = prefs.getBoolean("autostart", false); mCameraStartupEnabled = prefs.getBoolean("cam_autostart", true); mShutterSound = prefs.getBoolean("shutter", true); mDateTimeColor = GetPrefColor(prefs, "datetime_color", "#FFFFFFFF", Color.WHITE); mDateTimeShadowColor = GetPrefColor(prefs, "datetime_shadowcolor", "#FF000000", Color.BLACK); mDateTimeBackgroundColor = GetPrefColor(prefs, "datetime_backcolor", "#80FF0000", Color.argb(0x80, 0xFF, 0x00, 0x00)); mDateTimeBackgroundLine = prefs.getBoolean("datetime_fillline", true); mDateTimeX = prefs.getInt("datetime_x", 98); mDateTimeY = prefs.getInt("datetime_y", 98); mDateTimeAlign = Paint.Align.valueOf(prefs.getString("datetime_imprintalign", "RIGHT")); mDateTimeFontScale = (float) prefs.getInt("datetime_fontsize", 6); mTextColor = GetPrefColor(prefs, "text_color", "#FFFFFFFF", Color.WHITE); mTextShadowColor = GetPrefColor(prefs, "text_shadowcolor", "#FF000000", Color.BLACK); mTextBackgroundColor = GetPrefColor(prefs, "text_backcolor", "#80FF0000", Color.argb(0x80, 0xFF, 0x00, 0x00)); mTextBackgroundLine = prefs.getBoolean("text_fillline", true); mTextX = prefs.getInt("text_x", 2); mTextY = prefs.getInt("text_y", 2); mTextAlign = Paint.Align.valueOf(prefs.getString("text_imprintalign", "LEFT")); mTextFontScale = (float) prefs.getInt("infotext_fontsize", 6); mTextFontname = prefs.getString("infotext_fonttypeface", ""); mStatusInfoColor = GetPrefColor(prefs, "statusinfo_color", "#FFFFFFFF", Color.WHITE); mStatusInfoShadowColor = GetPrefColor(prefs, "statusinfo_shadowcolor", "#FF000000", Color.BLACK); mStatusInfoX = prefs.getInt("statusinfo_x", 2); mStatusInfoY = prefs.getInt("statusinfo_y", 98); mStatusInfoAlign = Paint.Align.valueOf(prefs.getString("statusinfo_imprintalign", "LEFT")); mStatusInfoBackgroundColor = GetPrefColor(prefs, "statusinfo_backcolor", "#00000000", Color.TRANSPARENT); mStatusInfoFontScale = (float) prefs.getInt("statusinfo_fontsize", 6); mStatusInfoBackgroundLine = prefs.getBoolean("statusinfo_fillline", false); mGPSColor = GetPrefColor(prefs, "gps_color", "#FFFFFFFF", Color.WHITE); mGPSShadowColor = GetPrefColor(prefs, "gps_shadowcolor", "#FF000000", Color.BLACK); mGPSX = prefs.getInt("gps_x", 98); mGPSY = prefs.getInt("gps_y", 2); mGPSAlign = Paint.Align.valueOf(prefs.getString("gps_imprintalign", "RIGHT")); mGPSBackgroundColor = GetPrefColor(prefs, "gps_backcolor", "#00000000", Color.TRANSPARENT); mGPSFontScale = (float) prefs.getInt("gps_fontsize", 6); mGPSBackgroundLine = prefs.getBoolean("gps_fillline", false); mImprintPictureX = prefs.getInt("imprint_picture_x", 0); mImprintPictureY = prefs.getInt("imprint_picture_y", 0); mNightAutoConfigEnabled = prefs.getBoolean("night_auto_enabled", false); mSetNightConfiguration = prefs.getBoolean("cam_nightconfiguration", false); // override night camera parameters (read again with postfix) getCurrentNightSettings(); mFilterPicture = false; //***prefs.getBoolean("filter_picture", false); mFilterType = getEditInt(mContext, prefs, "filter_sel", 0); if (mImprintPicture) { if (mImprintPictureURL.length() == 0) { // sdcard image File path = new File(Environment.getExternalStorageDirectory() + "/MobileWebCam/"); if (path.exists()) { synchronized (gImprintBitmapLock) { if (gImprintBitmap != null) gImprintBitmap.recycle(); gImprintBitmap = null; File file = new File(path, "imprint.png"); try { FileInputStream in = new FileInputStream(file); gImprintBitmap = BitmapFactory.decodeStream(in); in.close(); } catch (IOException e) { Toast.makeText(mContext, "Error: unable to read imprint bitmap " + file.getName() + "!", Toast.LENGTH_SHORT).show(); gImprintBitmap = null; } catch (OutOfMemoryError e) { Toast.makeText(mContext, "Error: imprint bitmap " + file.getName() + " too large!", Toast.LENGTH_LONG).show(); gImprintBitmap = null; } } } } else { DownloadImprintBitmap(); } synchronized (gImprintBitmapLock) { if (gImprintBitmap == null) { // last resort: resource default try { gImprintBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.imprint); } catch (OutOfMemoryError e) { Toast.makeText(mContext, "Error: default imprint bitmap too large!", Toast.LENGTH_LONG) .show(); gImprintBitmap = null; } } } } mNoToasts = prefs.getBoolean("no_messages", false); mFullWakeLock = prefs.getBoolean("full_wakelock", true); switch (getEditInt(mContext, prefs, "camera_mode", 1)) { case 0: mMode = Mode.MANUAL; break; case 2: mMode = Mode.HIDDEN; break; case 3: mMode = Mode.BACKGROUND; break; case 1: default: mMode = Mode.NORMAL; break; } }
From source file:com.example.psumaps.MapView.java
private void drawMarker(LatLng point, String str) { // Creating an instance of MarkerOptions MarkerOptions markerOptions = new MarkerOptions(); //IconGenerator tc = new IconGenerator(this); //Bitmap bmp = tc.makeIcon("hello"); Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.bubble_white);// get the image same as your EditText int h = bitmap.getHeight() * 2; int w = bitmap.getWidth() * 2; bitmap = convertToMutable(bitmap);// converting the bitmap to mutable Bitmap incrsize = Bitmap.createScaledBitmap(bitmap, w, h, false); Canvas cs = new Canvas(incrsize); Paint pt = new Paint(); pt.setColor(Color.BLACK);/*from w ww . j av a2 s .c o m*/ //Typeface tf = Typeface.create("Helvetica",Typeface.BOLD); pt.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); String iam = str.toUpperCase(Locale.getDefault()); pt.setTextSize(25); cs.drawText(iam, 0, iam.length(), (h / 2) + 10, (w / 2) / 2, pt); //pt.setColor(Color.RED); //cs.drawText("this is praki", 0, 13, h / 2, w / 3, pt); // Setting latitude and longitude for the marker markerOptions.position(point).title(str).icon(BitmapDescriptorFactory.fromBitmap(incrsize)); // Adding marker on the Google Map map.addMarker(markerOptions); }
From source file:com.android.ex.chips.RecipientEditTextView.java
private void setChipDimensions(final Context context, final AttributeSet attrs) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecipientEditTextView, 0, 0); final Resources r = getContext().getResources(); mChipBackground = a.getDrawable(R.styleable.RecipientEditTextView_chipBackground); if (mChipBackground == null) mChipBackground = ContextCompat.getDrawable(context, R.drawable.circle_background_chips); mChipBackgroundPressed = a.getDrawable(R.styleable.RecipientEditTextView_chipBackgroundPressed); if (mChipBackgroundPressed == null) mChipBackgroundPressed = ContextCompat.getDrawable(context, R.drawable.chip_background_selected); mChipDelete = a.getDrawable(R.styleable.RecipientEditTextView_chipDelete); if (mChipDelete == null) mChipDelete = ContextCompat.getDrawable(context, R.drawable.chip_delete); mChipPadding = a.getDimensionPixelSize(R.styleable.RecipientEditTextView_chipPadding, -1); if (mChipPadding == -1) mChipPadding = (int) r.getDimension(R.dimen.chip_padding); mAlternatesLayout = a.getResourceId(R.styleable.RecipientEditTextView_chipAlternatesLayout, -1); if (mAlternatesLayout == -1) mAlternatesLayout = R.layout.chips_alternate_item; mDefaultContactPhoto = BitmapFactory.decodeResource(r, R.drawable.ic_contact_picture); mMoreItem = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.more_item, null); mChipHeight = a.getDimensionPixelSize(R.styleable.RecipientEditTextView_chipHeight, -1); if (mChipHeight == -1) mChipHeight = r.getDimension(R.dimen.chip_height); mChipFontSize = a.getDimensionPixelSize(R.styleable.RecipientEditTextView_chipFontSize, -1); if (mChipFontSize == -1) mChipFontSize = r.getDimension(R.dimen.chip_text_size); mInvalidChipBackground = a.getDrawable(R.styleable.RecipientEditTextView_invalidChipBackground); if (mInvalidChipBackground == null) mInvalidChipBackground = ContextCompat.getDrawable(context, R.drawable.chip_background_invalid); mLineSpacingExtra = r.getDimension(R.dimen.line_spacing_extra); mMaxLines = r.getInteger(R.integer.chips_max_lines); final TypedValue tv = new TypedValue(); if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()); a.recycle();/* w w w . j a v a2s. co m*/ }
From source file:com.VVTeam.ManHood.Fragment.HistogramFragment.java
private List<PolarPlotData> plotDataForUserWithID(String userID, UsersData _usersData) { Bitmap orgBmp = BitmapFactory.decodeResource(getResources(), R.drawable.g_circle_b); float width = orgBmp.getWidth() * 50.0f / 100.0f; float height = width; PolarPlotData base = new PolarPlotData(0, Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.g_circle_b), (int) width, (int) height, true), _usersData.basePositionOfUserWithID(userID)); PolarPlotData mid = new PolarPlotData(2, Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.g_circle_m), (int) width, (int) height, true), _usersData.midPositionOfUserWithID(userID)); PolarPlotData upper = new PolarPlotData(4, Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.g_circle_s), (int) width, (int) height, true), _usersData.upperPositionOfUserWithID(userID)); PolarPlotData tip = new PolarPlotData(6, Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.g_circle_smaller), (int) width, (int) height, true), _usersData.tipPositionOfUserWithID(userID)); List<PolarPlotData> list = new ArrayList<PolarPlotData>(); list.add(base);/*from w w w .j av a 2s. com*/ list.add(mid); list.add(upper); list.add(tip); return list; }
From source file:com.ieeton.agency.activity.ChatActivity.java
/** * onActivityResult/*w ww . ja va2 s . c o m*/ */ protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Utils.logd("requestCode:" + requestCode); Utils.logd("resultCode:" + resultCode); if (resultCode == RESULT_CODE_EXIT_GROUP) { setResult(RESULT_OK); finish(); return; } if (requestCode == REQUEST_CODE_CONTEXT_MENU) { switch (resultCode) { case RESULT_CODE_COPY: // ?? EMMessage copyMsg = ((EMMessage) adapter.getItem(data.getIntExtra("position", -1))); if (copyMsg.getType() == EMMessage.Type.IMAGE) { ImageMessageBody imageBody = (ImageMessageBody) copyMsg.getBody(); // ??? clipboard.setText(COPY_IMAGE + imageBody.getLocalUrl()); } else { // clipboard.setText(SmileUtils.getSmiledText(ChatActivity.this, // ((TextMessageBody) copyMsg.getBody()).getMessage())); clipboard.setText(((TextMessageBody) copyMsg.getBody()).getMessage()); } break; case RESULT_CODE_DELETE: // ? EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1)); conversation.removeMessage(deleteMsg.getMsgId()); adapter.refresh(); listView.setSelection(data.getIntExtra("position", adapter.getCount()) - 1); break; case RESULT_CODE_FORWARD: // ?? EMMessage forwardMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", 0)); Intent intent = new Intent(this, ForwardMessageActivity.class); intent.putExtra("forward_msg_id", forwardMsg.getMsgId()); startActivity(intent); break; default: break; } } if (resultCode == RESULT_OK) { // ? if (requestCode == REQUEST_CODE_EMPTY_HISTORY) { // ? EMChatManager.getInstance().clearConversation(toChatUsername); adapter.refresh(); } else if (requestCode == REQUEST_CODE_CAMERA) { // ?? if (cameraFile != null && cameraFile.exists()) sendPicture(cameraFile.getAbsolutePath()); } else if (requestCode == REQUEST_CODE_SELECT_VIDEO) { // ?? int duration = data.getIntExtra("dur", 0); String videoPath = data.getStringExtra("path"); File file = new File(PathUtil.getInstance().getImagePath(), "thvideo" + System.currentTimeMillis()); Bitmap bitmap = null; FileOutputStream fos = null; try { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, 3); if (bitmap == null) { EMLog.d("chatactivity", "problem load video thumbnail bitmap,use default icon"); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.app_panel_video_icon); } fos = new FileOutputStream(file); bitmap.compress(CompressFormat.JPEG, 100, fos); } catch (Exception e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } fos = null; } if (bitmap != null) { bitmap.recycle(); bitmap = null; } } sendVideo(videoPath, file.getAbsolutePath(), duration / 1000); } else if (requestCode == REQUEST_CODE_LOCAL) { // ?? if (data != null) { Uri selectedImage = data.getData(); if (selectedImage != null) { sendPicByUri(selectedImage); } } } else if (requestCode == REQUEST_CODE_SELECT_FILE) { // ?? if (data != null) { Uri uri = data.getData(); if (uri != null) { sendFile(uri); } } } else if (requestCode == REQUEST_CODE_MAP) { // double latitude = data.getDoubleExtra("latitude", 0); double longitude = data.getDoubleExtra("longitude", 0); String locationAddress = data.getStringExtra("address"); if (locationAddress != null && !locationAddress.equals("")) { more(more); sendLocationMsg(latitude, longitude, "", locationAddress); } else { Toast.makeText(this, "????", 0).show(); } // ??? } else if (requestCode == REQUEST_CODE_TEXT) { resendMessage(); } else if (requestCode == REQUEST_CODE_VOICE) { resendMessage(); } else if (requestCode == REQUEST_CODE_PICTURE) { resendMessage(); } else if (requestCode == REQUEST_CODE_LOCATION) { resendMessage(); } else if (requestCode == REQUEST_CODE_VIDEO || requestCode == REQUEST_CODE_FILE) { resendMessage(); } else if (requestCode == REQUEST_CODE_COPY_AND_PASTE) { // if (!TextUtils.isEmpty(clipboard.getText())) { String pasteText = clipboard.getText().toString(); if (pasteText.startsWith(COPY_IMAGE)) { // ??path sendPicture(pasteText.replace(COPY_IMAGE, "")); } } } else if (requestCode == REQUEST_CODE_ADD_TO_BLACKLIST) { // ??? EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1)); addUserToBlacklist(deleteMsg.getFrom()); } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) { adapter.refresh(); } else if (requestCode == REQUEST_CODE_QUICK_REPLY) { String content = data.getStringExtra(EXTRA_QUICK_REPLY); Utils.logd("content:" + content); sendText(content); } else if (conversation.getMsgCount() > 0) { adapter.refresh(); setResult(RESULT_OK); } } }
From source file:cn.yunluosoft.tonglou.activity.ChatActivity.java
/** * onActivityResult/* w ww. j a va 2 s . co m*/ */ protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 8226 && resultCode == RESULT_OK) { String s = data.getStringExtra("name"); if (!ToosUtils.isStringEmpty(s)) { messageInfo.receiverNickName = s; toChatUsername = messageInfo.receiverImUserName; // toChatUsername = getIntent().getStringExtra("userId"); ((TextView) findViewById(R.id.title_title)).setText(messageInfo.receiverNickName); } } if (resultCode == RESULT_CODE_EXIT_GROUP) { setResult(RESULT_OK); finish(); return; } if (requestCode == REQUEST_CODE_CONTEXT_MENU) { switch (resultCode) { case RESULT_CODE_COPY: // ?? EMMessage copyMsg = ((EMMessage) adapter.getItem(data.getIntExtra("position", -1))); // clipboard.setText(SmileUtils.getSmiledText(ChatActivity.this, // ((TextMessageBody) copyMsg.getBody()).getMessage())); clipboard.setText(((TextMessageBody) copyMsg.getBody()).getMessage()); break; case RESULT_CODE_DELETE: // ? EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1)); conversation.removeMessage(deleteMsg.getMsgId()); adapter.refreshSeekTo(data.getIntExtra("position", adapter.getCount()) - 1); break; // case RESULT_CODE_FORWARD: // ?? // EMMessage forwardMsg = (EMMessage) adapter.getItem(data // .getIntExtra("position", 0)); // Intent intent = new Intent(this, ForwardMessageActivity.class); // intent.putExtra("forward_msg_id", forwardMsg.getMsgId()); // startActivity(intent); // // break; default: break; } } if (resultCode == RESULT_OK) { // ? if (requestCode == REQUEST_CODE_EMPTY_HISTORY) { // ? EMChatManager.getInstance().clearConversation(toChatUsername); adapter.refresh(); } else if (requestCode == REQUEST_CODE_CAMERA) { // ?? if (cameraFile != null && cameraFile.exists()) sendPicture(cameraFile.getAbsolutePath()); } else if (requestCode == REQUEST_CODE_SELECT_VIDEO) { // ?? int duration = data.getIntExtra("dur", 0); String videoPath = data.getStringExtra("path"); File file = new File(PathUtil.getInstance().getImagePath(), "thvideo" + System.currentTimeMillis()); Bitmap bitmap = null; FileOutputStream fos = null; try { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, 3); if (bitmap == null) { EMLog.d("chatactivity", "problem load video thumbnail bitmap,use default icon"); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.app_panel_video_icon); } fos = new FileOutputStream(file); bitmap.compress(CompressFormat.JPEG, 100, fos); } catch (Exception e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } fos = null; } if (bitmap != null) { bitmap.recycle(); bitmap = null; } } sendVideo(videoPath, file.getAbsolutePath(), duration / 1000); } else if (requestCode == REQUEST_CODE_LOCAL) { // ?? loading(); // if (data != null) { // Uri selectedImage = data.getData(); // if (selectedImage != null) { // sendPicByUri(selectedImage); // } // } } else if (requestCode == REQUEST_CODE_SELECT_FILE) { // ?? if (data != null) { Uri uri = data.getData(); if (uri != null) { sendFile(uri); } } } else if (requestCode == REQUEST_CODE_MAP) { // double latitude = data.getDoubleExtra("latitude", 0); double longitude = data.getDoubleExtra("longitude", 0); String locationAddress = data.getStringExtra("address"); if (locationAddress != null && !locationAddress.equals("")) { toggleMore(more); sendLocationMsg(latitude, longitude, "", locationAddress); } else { String st = getResources().getString(R.string.unable_to_get_loaction); Toast.makeText(this, st, Toast.LENGTH_SHORT).show(); } // ??? } else if (requestCode == REQUEST_CODE_TEXT || requestCode == REQUEST_CODE_VOICE || requestCode == REQUEST_CODE_PICTURE || requestCode == REQUEST_CODE_LOCATION || requestCode == REQUEST_CODE_VIDEO || requestCode == REQUEST_CODE_FILE) { resendMessage(); } else if (requestCode == REQUEST_CODE_COPY_AND_PASTE) { // if (!TextUtils.isEmpty(clipboard.getText())) { String pasteText = clipboard.getText().toString(); if (pasteText.startsWith(COPY_IMAGE)) { // ??path sendPicture(pasteText.replace(COPY_IMAGE, "")); } } } else if (requestCode == REQUEST_CODE_ADD_TO_BLACKLIST) { // ??? EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1)); addUserToBlacklist(deleteMsg.getFrom()); } else if (conversation.getMsgCount() > 0) { adapter.refresh(); setResult(RESULT_OK); } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) { adapter.refresh(); } } }