List of usage examples for android.graphics BitmapFactory decodeByteArray
public static Bitmap decodeByteArray(byte[] data, int offset, int length)
From source file:com.android.contacts.editor.EditorUiUtils.java
/** Decodes the Bitmap from the photo bytes from the given ValuesDelta. */ public static Bitmap getPhotoBitmap(ValuesDelta valuesDelta) { if (valuesDelta == null) return null; final byte[] bytes = valuesDelta.getAsByteArray(Photo.PHOTO); if (bytes == null) return null; return BitmapFactory.decodeByteArray(bytes, /* offset =*/ 0, bytes.length); }
From source file:com.partypoker.poker.engagement.reach.EngagementReachInteractiveContent.java
/** * Get notification image for in app notifications. For system notification this field corresponds * to the large icon (displayed only on Android 3+). * @return notification image.//from ww w.jav a 2 s . c o m */ public Bitmap getNotificationImage() { /* Decode as bitmap now if not already done */ if (mNotificationImageString != null && mNotificationImage == null) { /* Decode base 64 then decode as a bitmap */ byte[] data = Base64.decode(mNotificationImageString, Base64.DEFAULT); if (data != null) try { mNotificationImage = BitmapFactory.decodeByteArray(data, 0, data.length); } catch (OutOfMemoryError e) { /* Abort */ } /* On any error, don't retry next time */ if (mNotificationImage == null) mNotificationImageString = null; } return mNotificationImage; }
From source file:com.fivehundredpxdemo.android.storage.ImageFetcher.java
public static Bitmap downloadBitmapToMemory(String urlString, String accessToken) { final byte[] bitmapBytes = downloadBitmapToMemory(urlString, MAX_THUMBNAIL_BYTES, accessToken); if (bitmapBytes != null) { // Caution: we don't check the size of the bitmap here, we are relying on the output // of downloadBitmapToMemory to not exceed our memory limits and load a huge bitmap // into memory. return BitmapFactory.decodeByteArray(bitmapBytes, 0, bitmapBytes.length); }//from w w w .ja va 2 s . com return null; }
From source file:com.fivehundredpxdemo.android.storage.ImageFetcher.java
/** * Download a thumbnail sized remote bitmap from a HTTP URL. No HTTP caching is done (the * {@link ImageCache} that this eventually gets passed to will do it's own disk caching. * @param urlString The URL of the image to download * @return The bitmap/*from w ww. j a v a 2 s . com*/ */ private Bitmap processThumbnailBitmap(String urlString) { final byte[] bitmapBytes = downloadBitmapToMemory(urlString, MAX_THUMBNAIL_BYTES, accessToken); if (bitmapBytes != null) { // Caution: we don't check the size of the bitmap here, we are relying on the output // of downloadBitmapToMemory to not exceed our memory limits and load a huge bitmap // into memory. return BitmapFactory.decodeByteArray(bitmapBytes, 0, bitmapBytes.length); } return null; }
From source file:com.aware.ui.Plugins_Manager.java
private void drawUI() { //Clear previous states store_grid.removeAllViews();//w ww. ja v a2 s .co m //Build UI Cursor installed_plugins = getContentResolver().query(Aware_Plugins.CONTENT_URI, null, null, null, Aware_Plugins.PLUGIN_NAME + " ASC"); if (installed_plugins != null && installed_plugins.moveToFirst()) { do { final String package_name = installed_plugins .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_PACKAGE_NAME)); final String name = installed_plugins .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_NAME)); final String description = installed_plugins .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_DESCRIPTION)); final String developer = installed_plugins .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_AUTHOR)); final String version = installed_plugins .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_VERSION)); final int status = installed_plugins .getInt(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_STATUS)); final View pkg_view = inflater.inflate(R.layout.plugins_store_pkg_list_item, null, false); pkg_view.setTag(package_name); //each view has the package name as a tag for easier references try { ImageView pkg_icon = (ImageView) pkg_view.findViewById(R.id.pkg_icon); if (status != PLUGIN_NOT_INSTALLED) { ApplicationInfo appInfo = getPackageManager().getApplicationInfo(package_name, PackageManager.GET_META_DATA); pkg_icon.setImageDrawable(appInfo.loadIcon(getPackageManager())); } else { byte[] img = installed_plugins .getBlob(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_ICON)); if (img != null) pkg_icon.setImageBitmap(BitmapFactory.decodeByteArray(img, 0, img.length)); } TextView pkg_title = (TextView) pkg_view.findViewById(R.id.pkg_title); pkg_title.setText(installed_plugins .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_NAME))); ImageView pkg_state = (ImageView) pkg_view.findViewById(R.id.pkg_state); switch (status) { case PLUGIN_DISABLED: pkg_state.setVisibility(View.INVISIBLE); pkg_view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = getPluginInfoDialog(name, version, description, developer); if (isClassAvailable(package_name, "Settings")) { builder.setNegativeButton("Settings", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Intent open_settings = new Intent(); open_settings.setClassName(package_name, package_name + ".Settings"); startActivity(open_settings); } }); } builder.setPositiveButton("Activate", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Aware.startPlugin(getApplicationContext(), package_name); drawUI(); } }); builder.create().show(); } }); break; case PLUGIN_ACTIVE: pkg_state.setImageResource(R.drawable.ic_pkg_active); pkg_view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = getPluginInfoDialog(name, version, description, developer); if (isClassAvailable(package_name, "Settings")) { builder.setNegativeButton("Settings", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Intent open_settings = new Intent(); open_settings.setClassName(package_name, package_name + ".Settings"); startActivity(open_settings); } }); } builder.setPositiveButton("Deactivate", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Aware.stopPlugin(getApplicationContext(), package_name); drawUI(); } }); builder.create().show(); } }); break; case PLUGIN_UPDATED: pkg_state.setImageResource(R.drawable.ic_pkg_updated); pkg_view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = getPluginInfoDialog(name, version, description, developer); if (isClassAvailable(package_name, "Settings")) { builder.setNegativeButton("Settings", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Intent open_settings = new Intent(); open_settings.setClassName(package_name, package_name + ".Settings"); startActivity(open_settings); } }); } builder.setNeutralButton("Deactivate", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Aware.stopPlugin(getApplicationContext(), package_name); drawUI(); } }); builder.setPositiveButton("Update", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Aware.downloadPlugin(getApplicationContext(), package_name, true); } }); builder.create().show(); } }); break; case PLUGIN_NOT_INSTALLED: pkg_state.setImageResource(R.drawable.ic_pkg_download); pkg_view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = getPluginInfoDialog(name, version, description, developer); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.setPositiveButton("Install", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Aware.downloadPlugin(getApplicationContext(), package_name, false); } }); builder.create().show(); } }); break; } store_grid.addView(pkg_view); } catch (NameNotFoundException e) { e.printStackTrace(); } } while (installed_plugins.moveToNext()); } if (installed_plugins != null && !installed_plugins.isClosed()) installed_plugins.close(); }
From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityAddPickupAndDropoff.java
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); // Getting the selected journey Journey journey = getApp().getSelectedJourney(); // Setting up tabs TabHost tabs = (TabHost) findViewById(R.id.tabhost); tabs.setup();//from w w w.j a v a 2s . c om // Adding Ride tab TabHost.TabSpec specRide = tabs.newTabSpec("tag1"); specRide.setContent(R.id.ride_tab); specRide.setIndicator("Ride"); tabs.addTab(specRide); // Adding Driver tab TabHost.TabSpec specDriver = tabs.newTabSpec("tag2"); specDriver.setContent(R.id.driver_tab); specDriver.setIndicator("Driver"); tabs.addTab(specDriver); // Adding the pickup location address text ((AutoCompleteTextView) findViewById(R.id.pickupText)) .setText(getIntent().getExtras().getString("pickupString")); // Adding the dropoff location address text ((AutoCompleteTextView) findViewById(R.id.dropoffText)) .setText(getIntent().getExtras().getString("dropoffString")); // Drawing the pickup and dropoff locations on the map setPickupLocation(); setDropOffLocation(); // Adding image of the driver User driver = journey.getRoute().getOwner(); picture = (ImageView) findViewById(R.id.mapViewPickupImage); // Create an object for subclass of AsyncTask GetImage task = new GetImage(picture, this); // Execute the task: Get image from url and add it to the ImageView task.execute(driver.getPictureURL()); // Adding the name of the driver ((TextView) findViewById(R.id.mapViewPickupTextViewName)).setText(driver.getFullName()); // Getting the drivers preferences for this ride TripPreferences pref = journey.getTripPreferences(); // Setting the smoking preference if (pref.getSmoking()) { ((ImageView) findViewById(R.id.mapViewPickupImageViewSmokingIcon)) .setImageResource(R.drawable.green_check); } else { ((ImageView) findViewById(R.id.mapViewPickupImageViewSmokingIcon)) .setImageResource(R.drawable.red_cross); } // Setting the animals preference if (pref.getAnimals()) { ((ImageView) findViewById(R.id.mapViewPickupImageViewAnimalsIcon)) .setImageResource(R.drawable.green_check); } else { ((ImageView) findViewById(R.id.mapViewPickupImageViewAnimalsIcon)) .setImageResource(R.drawable.red_cross); } // Setting the breaks preference if (pref.getBreaks()) { ((ImageView) findViewById(R.id.mapViewPickupImageViewBreaksIcon)) .setImageResource(R.drawable.green_check); } else { ((ImageView) findViewById(R.id.mapViewPickupImageViewBreaksIcon)) .setImageResource(R.drawable.red_cross); } // Setting the music preference if (pref.getMusic()) { ((ImageView) findViewById(R.id.mapViewPickupImageViewMusicIcon)) .setImageResource(R.drawable.green_check); } else { ((ImageView) findViewById(R.id.mapViewPickupImageViewMusicIcon)).setImageResource(R.drawable.red_cross); } // Setting the talking preference if (pref.getTalking()) { ((ImageView) findViewById(R.id.mapViewPickupImageViewTalkingIcon)) .setImageResource(R.drawable.green_check); } else { ((ImageView) findViewById(R.id.mapViewPickupImageViewTalkingIcon)) .setImageResource(R.drawable.red_cross); } // Setting the number of available seats ((TextView) findViewById(R.id.mapViewPickupTextViewSeats)) .setText(pref.getSeatsAvailable() + " available seats"); // Setting the age of the driver ((TextView) findViewById(R.id.mapViewPickupTextViewAge)).setText("Age: " + driver.getAge()); // Adding the gender of the driver if (driver.getGender() != null) { if (driver.getGender().equals("m")) { ((ImageView) findViewById(R.id.mapViewPickupImageViewGender)).setImageResource(R.drawable.male); } else if (driver.getGender().equals("f")) { ((ImageView) findViewById(R.id.mapViewPickupImageViewGender)).setImageResource(R.drawable.female); } } // Addring the rating of the driver ((TextView) findViewById(R.id.recommendations)).setText("Recommendations: " + (int) driver.getRating()); // Setting the drivers mobile number ((TextView) findViewById(R.id.mapViewPickupTextViewPhone)).setText("Mobile: " + driver.getPhone()); try { // Getting the car image Car dummyCar = new Car(driver.getCarId(), "Dummy", 0.0); //"Dummy" and 0.0 are dummy vars. getApp() etc sends the current user's carid Request carReq = new CarRequest(RequestType.GET_CAR, getApp().getUser(), dummyCar); CarResponse carRes = (CarResponse) RequestTask.sendRequest(carReq, getApp()); Car car = carRes.getCar(); Bitmap carImage = BitmapFactory.decodeByteArray(car.getPhoto(), 0, car.getPhoto().length); // Setting the car image ((ImageView) findViewById(R.id.mapViewPickupImageViewCar)).setImageBitmap(carImage); // Setting the car name ((TextView) findViewById(R.id.mapViewPickupTextViewCarName)).setText("Car type: " + car.getCarName()); // Setting the comfort ((RatingBar) findViewById(R.id.mapViewPickupAndDropoffComfortStars)) .setRating((float) car.getComfort()); } catch (ClientProtocolException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (ExecutionException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // Adding the date of ride Date d = journey.getStart().getTime(); SimpleDateFormat sdfDate = new SimpleDateFormat("MMM dd yyyy"); SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm zzz"); String dateText = "Date: " + sdfDate.format(d); String timeText = "Time: " + sdfTime.format(d); ((TextView) findViewById(R.id.mapViewPickupTextViewDate)).setText(dateText + "\n" + timeText); //Adding Gender to the driver ImageView iv_image; iv_image = (ImageView) findViewById(R.id.gender); try { if (driver.getGender().equals("Male")) { Drawable male = getResources().getDrawable(R.drawable.male); iv_image.setImageDrawable(male); } else if (driver.getGender().equals("Female")) { Drawable female = getResources().getDrawable(R.drawable.female); iv_image.setImageDrawable(female); } } catch (NullPointerException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // Initializing the two autocomplete textviews pickup and dropoff initAutocomplete(); // Adding onClickListener for the button "Ask for a ride" btnSendRequest = (Button) findViewById(no.ntnu.idi.socialhitchhiking.R.id.mapViewPickupBtnSendRequest); btnSendRequest.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Response res; NotificationRequest req; if (pickupPoint == null || dropoffPoint == null) { //makeToast("You have to choose pickup point and dropoff point."); AlertDialog.Builder ad = new AlertDialog.Builder(MapActivityAddPickupAndDropoff.this); ad.setMessage("You have to choose pickup point and dropoff point."); ad.setTitle("Unable to send request"); ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); ad.show(); return; } inPickupMode = true; String senderID = getApp().getUser().getID(); String recipientID = getApp().getSelectedJourney().getRoute().getOwner().getID(); String senderName = getApp().getUser().getFullName(); String comment = ((EditText) findViewById(R.id.mapViewPickupEtComment)).getText().toString(); int journeyID = getApp().getSelectedJourney().getSerial(); // Creating a new notification to be sendt to the driver Notification n = new Notification(senderID, recipientID, senderName, comment, journeyID, NotificationType.HITCHHIKER_REQUEST, pickupPoint, dropoffPoint, Calendar.getInstance()); req = new NotificationRequest(RequestType.SEND_NOTIFICATION, getApp().getUser(), n); // Sending notification try { res = RequestTask.sendRequest(req, getApp()); if (res instanceof UserResponse) { if (res.getStatus() == ResponseStatus.OK) { makeToast("Ride request sent to driver"); finish(); } if (res.getStatus() == ResponseStatus.FAILED) { if (res.getErrorMessage().contains("no_duplicate_notifications")) { //makeToast("You have already sent a request on this journey"); AlertDialog.Builder ad = new AlertDialog.Builder( MapActivityAddPickupAndDropoff.this); ad.setMessage("You have already sent a request on this ride"); ad.setTitle("Unable to send request"); ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); ad.show(); } else if (res.getErrorMessage().equals("No available seats")) { //makeToast("There are no available seats on this ride"); AlertDialog.Builder ad = new AlertDialog.Builder( MapActivityAddPickupAndDropoff.this); ad.setMessage("There are no available seats on this ride"); ad.setTitle("Unable to send request"); ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); ad.show(); } else if (res.getErrorMessage().equals("User already in journey")) { //makeToast("You have already hitched this ride"); AlertDialog.Builder ad = new AlertDialog.Builder( MapActivityAddPickupAndDropoff.this); ad.setMessage("You have already hitched this ride"); ad.setTitle("Unable to send request"); ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); ad.show(); } else { makeToast("Could not send request"); } } } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); // Adding buttons where you choose between pickup point and dropoff point btnSelectPickupPoint = (Button) findViewById(R.id.mapViewPickupBtnPickup); btnSelectPickupPoint.setBackgroundColor(notSelected); btnSelectDropoffPoint = (Button) findViewById(R.id.mapViewPickupBtnDropoff); btnSelectDropoffPoint.setBackgroundColor(notSelected); // Setting the selected pickup point btnSelectPickupPoint.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { isSelectingDropoffPoint = false; isSelectingPickupPoint = true; btnSelectPickupPoint.setBackgroundColor(selected); btnSelectDropoffPoint.setBackgroundColor(notSelected); makeToast("Press the map to add pickup location"); } }); // Setting the selected dropoff point btnSelectDropoffPoint.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { isSelectingDropoffPoint = true; isSelectingPickupPoint = false; btnSelectPickupPoint.setBackgroundColor(notSelected); btnSelectDropoffPoint.setBackgroundColor(selected); makeToast("Press the map to add dropoff location"); } }); // Adding message to the user makeToast("Please set a pickup and dropoff location."); }
From source file:com.yibu.kuaibu.app.glApplication.java
public Bitmap getBmp(byte[] in) { if (in == null) { return null; }/* w ww .j av a 2 s. co m*/ Bitmap bmpout = BitmapFactory.decodeByteArray(in, 0, in.length); return bmpout; }
From source file:com.android.mms.rcs.FavoriteDetailAdapter.java
private void initVcardMagView(LinearLayout linearLayout) { ImageView imageView = (ImageView) linearLayout.findViewById(R.id.image_view); String fileName = mCursor/* ww w . j av a 2 s. c o m*/ .getString(mCursor.getColumnIndexOrThrow(FavoriteMessageProvider.FavoriteMessage.FILE_NAME)); String vcardFileName = fileName; ArrayList<PropertyNode> propList = RcsMessageOpenUtils.openRcsVcardDetail(mContext, vcardFileName); Bitmap bitmap = null; for (PropertyNode propertyNode : propList) { if ("PHOTO".equals(propertyNode.propName)) { if (propertyNode.propValue_bytes != null) { byte[] bytes = propertyNode.propValue_bytes; bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); bitmap = RcsUtils.decodeInSampleSizeBitmap(bitmap); break; } } } if (bitmap != null) { imageView.setBackgroundDrawable(new BitmapDrawable(bitmap)); } else { imageView.setBackgroundResource(R.drawable.ic_attach_vcard); } }
From source file:net.networksaremadeofstring.rhybudd.ZenossWidgetGraph.java
@SuppressWarnings("unused") private Bitmap RenderLineGraph() { Bitmap emptyBmap = Bitmap.createBitmap(290, 150, Config.ARGB_8888); int width = emptyBmap.getWidth(); int height = emptyBmap.getHeight(); Bitmap charty = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(charty); final int color = 0xff0B0B61; final Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE);//from www . j a v a 2 s . c o m //if(warningEvents > ) canvas.drawText("100", 0, 10, paint); //y canvas.drawLine(25, 0, 25, 289, paint); //x canvas.drawLine(25, 149, 289, 149, paint); int CritArray[] = { 5, 4, 6, 10, 10, 6, 4, 4 }; int curX = 25; int divisor = 148 / 10; paint.setColor(Color.RED); int curY = 148 - (CritArray[0] * divisor); for (int a : CritArray) { canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint); curX += 32; curY = 148 - (a * divisor); } int ErrArray[] = { 1, 2, 2, 2, 4, 2, 1, 0 }; curX = 25; paint.setColor(Color.rgb(255, 102, 0)); curY = 148 - (ErrArray[0] * divisor); for (int a : ErrArray) { canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint); curX += 32; curY = 148 - (a * divisor); } int WarnArray[] = { 0, 2, 4, 8, 10, 4, 2, 2 }; curX = 25; paint.setColor(Color.YELLOW); curY = 148 - (WarnArray[0] * divisor); Path myPath = new Path(); for (int a : WarnArray) { canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint); curX += 32; curY = 148 - (a * divisor); } ByteArrayOutputStream out = new ByteArrayOutputStream(); charty.compress(CompressFormat.PNG, 50, out); return BitmapFactory.decodeByteArray(out.toByteArray(), 0, out.size()); }