List of usage examples for android.graphics BitmapFactory decodeByteArray
public static Bitmap decodeByteArray(byte[] data, int offset, int length)
From source file:ca.hoogit.garagepi.Camera.CameraFragment.java
private void handleUpdatingCameraFeed(String frame) { if (isAdded()) { Log.v(TAG, "handleUpdatingCameraFeed: Updating image view"); byte[] decoded = Base64.decode(frame, Base64.DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(decoded, 0, decoded.length); Drawable drawable = new BitmapDrawable(getResources(), bitmap); mCameraFeed.setImageDrawable(drawable); }//from w w w .j a va 2 s .c o m }
From source file:com.pimp.companionforband.fragments.theme.ThemeFragment.java
@Override public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); imageView = (ImageView) view.findViewById(R.id.selected_me_tile_image_view); SharedPreferences settings = getActivity().getSharedPreferences("MyPrefs", 0); Drawable meTileDrawable = null;//from w ww . j a v a 2 s . com String encoded = settings.getString("me_tile_image", "null"); if (!encoded.equals("null")) { byte[] imageAsBytes = Base64.decode(encoded.getBytes(), Base64.DEFAULT); meTileDrawable = new BitmapDrawable(getResources(), BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length)); } if (meTileDrawable != null) imageView.setImageDrawable(meTileDrawable); Button btnUpdateMe, btnPickMe, btnUpdateTheme, btnGetMeTile, btnGetTheme, btnGetColors; btnPickMe = (Button) view.findViewById(R.id.pick_me_tile_button); btnPickMe.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_PICK); intent.setType("image/*"); startActivityForResult(intent, 9); } }); btnGetMeTile = (Button) view.findViewById(R.id.get_me_tile_button); btnGetMeTile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new getMeTask().execute(); } }); btnUpdateMe = (Button) view.findViewById(R.id.update_me_tile_button); btnUpdateMe.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { bitmapDrawable = (BitmapDrawable) imageView.getDrawable(); new appTask().execute(); } }); SharedPreferences sharedPreferences = getContext().getSharedPreferences("MyPrefs", 0); base = sharedPreferences.getInt("base", -16777216); highlight = sharedPreferences.getInt("highLight", -16777216); lowlight = sharedPreferences.getInt("lowLight", -16777216); secondaryText = sharedPreferences.getInt("secondaryText", -16777216); highContrast = sharedPreferences.getInt("highContrast", -16777216); muted = sharedPreferences.getInt("muted", -16777216); btnGetTheme = (Button) view.findViewById(R.id.get_theme_button); btnGetTheme.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new getThemeTask().execute(view); } }); btnUpdateTheme = (Button) view.findViewById(R.id.update_theme_button); btnUpdateTheme.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new themeTask().execute(); } }); btnBase = (Button) view.findViewById(R.id.base); btnHighlight = (Button) view.findViewById(R.id.highlight); btnLowlight = (Button) view.findViewById(R.id.lowlight); btnSecondaryText = (Button) view.findViewById(R.id.secondaryText); btnHighContrast = (Button) view.findViewById(R.id.highContrast); btnMuted = (Button) view.findViewById(R.id.muted); btnBase.setBackgroundColor(Color.parseColor(String.format("#%06X", (0xFFFFFF & base)))); btnHighlight.setBackgroundColor(Color.parseColor(String.format("#%06X", (0xFFFFFF & highlight)))); btnLowlight.setBackgroundColor(Color.parseColor(String.format("#%06X", (0xFFFFFF & lowlight)))); btnSecondaryText.setBackgroundColor(Color.parseColor(String.format("#%06X", (0xFFFFFF & secondaryText)))); btnHighContrast.setBackgroundColor(Color.parseColor(String.format("#%06X", (0xFFFFFF & highContrast)))); btnMuted.setBackgroundColor(Color.parseColor(String.format("#%06X", (0xFFFFFF & muted)))); btnGetColors = (Button) view.findViewById(R.id.get_colors_button); btnGetColors.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { bitmapDrawable = (BitmapDrawable) imageView.getDrawable(); if (bitmapDrawable.getBitmap() != null && !bitmapDrawable.getBitmap().isRecycled()) { Palette.from(bitmapDrawable.getBitmap()).generate(paletteListener); } } }); }
From source file:co.nerdart.ourss.activity.EntriesListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { UiUtils.setPreferenceTheme(this); super.onCreate(savedInstanceState); ActionBar actionBar = getActionBar(); if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true); Intent intent = getIntent();//from w ww . j a v a 2 s . c om long feedId = intent.getLongExtra(FeedColumns._ID, 0); String title = null; if (feedId > 0) { Cursor cursor = getContentResolver().query(FeedColumns.CONTENT_URI(feedId), FEED_PROJECTION, null, null, null); if (cursor.moveToFirst()) { title = cursor.isNull(0) ? cursor.getString(1) : cursor.getString(0); iconBytes = cursor.getBlob(2); } cursor.close(); } if (title != null) { setTitle(title); } if (savedInstanceState == null) { EntriesListFragment fragment = new EntriesListFragment(); Bundle args = new Bundle(); args.putParcelable(EntriesListFragment.ARG_URI, intent.getData()); fragment.setArguments(args); fragment.setHasOptionsMenu(true); getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment, "fragment").commit(); } if (iconBytes != null && iconBytes.length > 0) { int bitmapSizeInDip = UiUtils.dpToPixel(24); Bitmap bitmap = BitmapFactory.decodeByteArray(iconBytes, 0, iconBytes.length); if (bitmap != null) { if (bitmap.getHeight() != bitmapSizeInDip) { bitmap = Bitmap.createScaledBitmap(bitmap, bitmapSizeInDip, bitmapSizeInDip, false); } getActionBar().setIcon(new BitmapDrawable(getResources(), bitmap)); } } if (MainActivity.mNotificationManager == null) { MainActivity.mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); } }
From source file:jp.iftc.androidasset.db.AssetImage.java
/** * @return assetImageBitmap?? */ public Bitmap getAssetThumBitmap() { return BitmapFactory.decodeByteArray(assetThum, 0, assetThum.length); }
From source file:com.amanmehara.programming.android.adapters.LanguageAdapter.java
private Consumer<String> getLogoResponseCallback(String url, boolean cacheHit, String languageName, ViewHolder viewHolder) {//from w w w . ja va 2 s. c om return response -> { try { if (!cacheHit) { sharedPreferences.edit().putString(url, response).apply(); } JSONObject icon = new JSONObject(response); byte[] imageBlob = Base64.decode(icon.getString("content"), Base64.DEFAULT); int imageBlobLength = imageBlob.length; Bitmap logo = BitmapFactory.decodeByteArray(imageBlob, 0, imageBlobLength); logos.put(languageName, imageBlob); viewHolder.languageImageView.setImageBitmap(logo); } catch (JSONException e) { Log.e(TAG, e.getMessage()); if (cacheHit) { sharedPreferences.edit().remove(url).apply(); } viewHolder.languageImageView.setImageResource(R.drawable.ic_circle_logo); } }; }
From source file:com.HumanDecisionSupportSystemsLaboratory.DD_P2P.SafeProfileFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.safe_profile, container); // retrieve text and image from main activity imgbut = (ImageView) v.findViewById(R.id.profImg); // profile img whoText = (TextView) v.findViewById(R.id.profName); // profile name email = (TextView) v.findViewById(R.id.safe_profile_email); slogan = (TextView) v.findViewById(R.id.safe_profile_slogan); device = (TextView) v.findViewById(R.id.safe_profile_device); Intent i = getActivity().getIntent(); Bundle b = i.getExtras();/* w w w.ja va 2 s . com*/ whoStr = b.getString("who"); safe_gidh = b.getString(Safe.P_SAFE_GIDH); safe_lid = b.getString(Safe.P_SAFE_LID); // safe_id = b.getInt(Safe.P_SAFE_ID) + 1; whoText.setText(whoStr); peer = D_Peer.getPeerByLID(safe_lid, true, false); boolean gotIcon = false; try { byte[] icon = peer.getIcon(); if (icon != null) { Bitmap bmp = BitmapFactory.decodeByteArray(icon, 0, icon.length - 1); imgbut.setImageBitmap(bmp); gotIcon = true; } } catch (Exception e) { e.printStackTrace(); } if (!gotIcon) { int imgPath = Integer.parseInt(b.getString("profImg")); Bitmap bmp = BitmapFactory.decodeResource(getResources(), imgPath); imgbut.setImageBitmap(bmp); } imgbut.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { byte[] icon = peer.getIcon(); if (icon != null) { ImageFragment fragment = ImageFragment.newInstance(icon); FragmentManager fm = getActivity().getSupportFragmentManager(); fragment.show(fm, "icon"); } if (icon == null) { int imgPath = R.drawable.placeholder; Bitmap bmp = BitmapFactory.decodeResource(getResources(), imgPath); icon = PhotoUtil.BitmapToByteArray(bmp, 100); ImageFragment fragment = ImageFragment.newInstance(icon); FragmentManager fm = getActivity().getSupportFragmentManager(); fragment.show(fm, "icon"); } } }); email.setText(peer.getEmail()); slogan.setText(peer.getSlogan()); String instances = null; String contacts_Date = null; String sync_Date = null; for (String _inst : peer._instances.keySet()) { String contact = Encoder.getGeneralizedTime(peer._instances.get(_inst).get_last_contact_date()); String sync = peer._instances.get(_inst).get_last_sync_date_str(); if (contact == null) contact = Util.__("NEVER"); if (sync == null) sync = Util.__("NEVER"); if (instances == null) { instances = _inst; contacts_Date = contact; sync_Date = sync; } else { instances += ", " + _inst; contacts_Date += ", " + contact; sync_Date += ", " + sync; } } device.setText(Util.getStringNonNullUnique(peer.getInstance()) + " / {" + instances + "}"); if (peer.getSK() != null) { ipAddress = (TextView) v.findViewById(R.id.safe_profile_ip); ipAddress.setText("Known Secret Key"); setProfilePhoto = (Button) v.findViewById(R.id.safe_profile_set_profile_photo); setProfilePhoto.setVisibility(View.VISIBLE); setProfilePhoto.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (Build.VERSION.SDK_INT < 19) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(intent, SELECT_PROFILE_PHOTO); } else { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.setType("image/*"); startActivityForResult(intent, SELECT_PPROFILE_PHOTO_KITKAT); } } }); } else { lastContact = (TextView) v.findViewById(R.id.safe_profile_last_contact); lastContact.setText(contacts_Date);//peer.getLastSyncDate(safe_lid)); ipAddress = (TextView) v.findViewById(R.id.safe_profile_ip); ipAddress.setText(sync_Date); /* * hideThisSafe = (Switch) * v.findViewById(R.id.switch_hide_this_safe); * hideThisSafe.setVisibility(View.VISIBLE); * * if (peer.getHidden() == false) hideThisSafe.setChecked(false); * else hideThisSafe.setChecked(true); * * hideThisSafe .setOnCheckedChangeListener(new * OnCheckedChangeListener() { * * @Override public void onCheckedChanged(CompoundButton buttonView, * boolean isChecked) { if (isChecked) { D_Peer.setHidden(peer, * true); peer.storeRequest(); peer.releaseReference(); } else { * D_Peer.setHidden(peer, false); peer.storeRequest(); * peer.releaseReference(); } * * } }); * * resetLastSyncDate = (Button) v * .findViewById(R.id.button_reset_LastSyncDate); * resetLastSyncDate.setVisibility(View.VISIBLE); * resetLastSyncDate.setOnClickListener(new OnClickListener() { * * @Override public void onClick(View v) { peer = * D_Peer.getPeerByPeer_Keep(peer); peer.setLastSyncDate(null); * peer.storeRequest(); peer.releaseReference(); * * for (D_PeerInstance i : peer._instances.values()) { Calendar date * = i.get_last_sync_date(); Log.i("last_sync_date", * "last sync date: " + date); } } }); */ sendMsg = (Button) v.findViewById(R.id.button_send_msg); sendMsg.setVisibility(View.VISIBLE); sendMsg.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent myIntent = new Intent(); myIntent.setClass(getActivity(), Chat.class); // pass data to chat myIntent.putExtra("who", whoStr); // myIntent.putExtra(Safe.P_SAFE_ID, safe_id); myIntent.putExtra(Safe.P_SAFE_LID, safe_lid); myIntent.putExtra(Safe.P_SAFE_GIDH, safe_gidh); myIntent.putExtra("profImg", String.valueOf(R.drawable.placeholder)); startActivity(myIntent); } }); /* * // set up switch access accessIt = (Switch) * v.findViewById(R.id.switch_access); * accessIt.setVisibility(View.VISIBLE); if (peer.getUsed() == true) * accessIt.setChecked(true); if (peer.getUsed() == false) * accessIt.setChecked(false); * * accessIt.setOnCheckedChangeListener(new OnCheckedChangeListener() * { * * @Override public void onCheckedChanged(CompoundButton buttonView, * boolean isChecked) { if (isChecked) { D_Peer.setUsed(peer, true); * } else { D_Peer.setUsed(peer, false); } } }); * * // set up switch block blockIt = (Switch) * v.findViewById(R.id.switch_block); * blockIt.setVisibility(View.VISIBLE); if (peer.getBlocked() == * true) blockIt.setChecked(true); if (peer.getBlocked() == false) * blockIt.setChecked(false); * * blockIt.setOnCheckedChangeListener(new OnCheckedChangeListener() * { * * @Override public void onCheckedChanged(CompoundButton buttonView, * boolean isChecked) { if (isChecked) { D_Peer.setBlocked(peer, * true); } else { D_Peer.setBlocked(peer, false); } } }); * * // set up switch serve serveIt = (Switch) * v.findViewById(R.id.switch_serve); * serveIt.setVisibility(View.VISIBLE); * * if (peer.getUsed() == true) serveIt.setChecked(true); if * (peer.getUsed() == false) serveIt.setChecked(false); * * serveIt.setOnCheckedChangeListener(new OnCheckedChangeListener() * { * * @Override public void onCheckedChanged(CompoundButton buttonView, * boolean isChecked) { if (isChecked) { D_Peer.setUsed(peer, true); * peer.storeRequest(); peer.releaseReference(); } else { * D_Peer.setUsed(peer, false); peer.storeRequest(); * peer.releaseReference(); } } }); */ } return super.onCreateView(inflater, container, savedInstanceState); }
From source file:com.kik.phonegap.plugin.messenger.KikMessengerPlugin.java
@Override public PluginResult execute(String action, JSONArray arg1, String arg2) { // Here we are going to basically going to read the json object and proccess the response Log.d("KikMessangerPlugin", "Plugin Called"); if (action.equals(ACTION)) { try {/*w w w . j a va2 s .c om*/ // The first argument is the string containing the JSONObject // that we will have to parse out String messageString = arg1.getString(0); System.out.println(messageString); JSONObject messageObject = new JSONObject(messageString); String title = messageObject.getString(TITLE); String desription = messageObject.getString(DESCRIPTION); JSONArray gen_urls = messageObject.getJSONArray(GENERICURIS); JSONArray ios_urls = messageObject.getJSONArray(IPHONEURIS); JSONArray android_urls = messageObject.getJSONArray(ANDROIDURIS); String preview = messageObject.getString(PREVIEW); String fileLocation = messageObject.getString(FILELOCATION); String previewURL = messageObject.getString(PREVIEWURL); KikMessage message = new KikMessage(_appID); message.setText(desription); message.setTitle(title); if (fileLocation.length() != 0) { try { File file = new File(fileLocation); message.setFile(file); } catch (IOException e) { return new PluginResult(PluginResult.Status.ERROR, "Error Attaching File"); } } if (preview.length() != 0) { byte[] data_bytes = Base64.decode(preview, 0); message.setImage( new BitmapDrawable(BitmapFactory.decodeByteArray(data_bytes, 0, data_bytes.length))); } else if (previewURL.length() != 0) { BitmapDrawable drawable = new BitmapDrawable(previewURL); message.setImage(drawable); } for (int i = 0; i < ios_urls.length(); i++) { message.setIphoneDownloadUri(ios_urls.getString(i)); } for (int i = 0; i < gen_urls.length(); i++) { message.setFallbackUri(gen_urls.getString(i)); } for (int i = 0; i < android_urls.length(); i++) { message.setAndroidDownloadUri(android_urls.getString(i)); } try { final KikMessage _messageToSend = message; // These will be key value pairs that we will use this.ctx.runOnUiThread(new Runnable() { public void run() { KikClient.sendMessage(ctx, _messageToSend); } }); return new PluginResult(Status.OK); } catch (Exception e) { return new PluginResult(PluginResult.Status.ERROR, "Error passing message to UI thread"); } } catch (JSONException e) { // If there is an issue parsing the JSON object then // we will return a bad result return new PluginResult(PluginResult.Status.ERROR, "Invalid JSON input, expected JSONObject as first item"); } // If we want to initialize the context } else if (action.equals(INIT_ACTION)) { try { String appID = arg1.getString(2); // We just want to take the AppId from this _appID = appID; if (_appID.length() == 0) { return new PluginResult(PluginResult.Status.ERROR, "Invalid App ID"); } else { return new PluginResult(PluginResult.Status.OK); } } catch (JSONException e) { // If there is an issue parsing the JSON object then // we will return a bad result return new PluginResult(PluginResult.Status.ERROR, "Invalid JSON input, expected JSONObject as first item"); } } else if (action.equals(HAS_MESSAGE)) { Intent i = this.ctx.getIntent(); KikData data = KikClient.getDataFromIntent(i); if (data.getType() == KikData.TYPE_PICK || data.getType() == KikData.TYPE_VIEW) { // We will only write back the javascript // if its a valid KikData object String output = "setTimeout(function() { KikAPIClient.message_ready( '" + SerializeKikData(data) + "'); }, 0 );"; super.sendJavascript(output); } return new PluginResult(PluginResult.Status.OK); } // This should not really occur return new PluginResult(PluginResult.Status.INVALID_ACTION, "INVALID COMMAND"); }
From source file:com.cpjd.roblu.ui.images.FullScreenImageGalleryActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed();//from w w w . j a v a 2 s . c om return true; } /* * User wants to delete an image */ else if (item.getItemId() == R.id.delete_image && editable) { Intent result = new Intent(); result.putExtra("position", viewPager.getCurrentItem()); setResult(Constants.IMAGE_DELETED, result); finish(); return true; } /* * User wants to do some drawing! */ else if (item.getItemId() == com.cpjd.roblu.R.id.edit && editable) { Intent intent = new Intent(this, com.cpjd.roblu.ui.images.Drawing.class); intent.putExtra("position", position); startActivityForResult(intent, Constants.GENERAL); return true; } /* * User wants to save the image to the local gallery */ else if (item.getItemId() == com.cpjd.roblu.R.id.save_to_device) { if (EasyPermissions.hasPermissions(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) { byte[] path = ImageGalleryActivity.IMAGES.get(viewPager.getCurrentItem()); Bitmap bitmap = BitmapFactory.decodeByteArray(path, 0, path.length); MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, String.valueOf(System.currentTimeMillis()), ""); Utils.showSnackbar(findViewById(R.id.full_screen_activity), getApplicationContext(), "Saved image to device", false, new IO(getApplicationContext()).loadSettings().getRui().getPrimaryColor()); } else { Utils.showSnackbar(findViewById(R.id.full_screen_activity), getApplicationContext(), "Storage permission is disabled. Please enable it.", true, 0); } return true; } else { return super.onOptionsItemSelected(item); } }
From source file:net.reichholf.dreamdroid.activities.ScreenShotActivity.java
/** * @param bytes/*from w w w .jav a2 s .co m*/ */ private void onScreenshotAvailable(byte[] bytes) { mRawImage = bytes; mImageView.setImageBitmap(BitmapFactory.decodeByteArray(bytes, 0, bytes.length)); setProgressBarIndeterminateVisibility(false); }