List of usage examples for android.graphics BitmapFactory decodeByteArray
public static Bitmap decodeByteArray(byte[] data, int offset, int length)
From source file:LPGoogleFunctions.LPGoogleFunctions.java
/** * The Google Maps Image APIs make it easy to embed a static Google Maps image into your image view. * @param address - The address (such as Chagrin Falls, OH). * @param zoomLevel - (required if markers not present) defines the zoom level of the map, which determines the magnification level of the map. * This parameter takes a numerical value corresponding to the zoom level of the region desired. * @param imageWidth - Specifies width size of the image in pixels. * @param imageHeight - Specifies height size of the image in pixels. * @param imageScale - (optional) affects the number of pixels that are returned. scale=2 returns twice as many pixels as scale=1 while retaining the same coverage area and level of detail (i.e. the contents of the map don't change). * This is useful when developing for high-resolution displays, or when generating a map for printing. The default value is 1. * @param mapType - (optional) defines the type of map to construct. There are several possible maptype values, including roadmap, satellite, hybrid, and terrain. Use LPGoogleMapType. * @param markers - (optional) define one or more markers to attach to the image at specified locations. This parameter takes a single marker definition with parameters separated by the pipe character (|). * Multiple markers may be placed within the same markers parameter as long as they exhibit the same style; you may add additional markers of differing styles by adding additional markers parameters. * Note that if you supply markers for a map, you do not need to specify the (normally required) center and zoom parameters. Use LPMapImageMarker. * @param responseHandler// w ww.j av a 2 s . c o m * @Override public void willLoadStaticMapImage() * @Override public void didLoadStaticMapImage(Bitmap bmp) * @Override public void errorLoadingStaticMapImage(Throwable error) */ public void loadStaticMapImageForAddress(String address, int zoomLevel, int imageWidth, int imageHeight, int imageScale, LPGoogleMapType mapType, ArrayList<LPMapImageMarker> markers, final StaticMapImageListener responseHandler) { if (responseHandler != null) responseHandler.willLoadStaticMapImage(); StringBuilder URL = new StringBuilder(googleAPIStaticMapImageURL); DecimalFormatSymbols separator = new DecimalFormatSymbols(); separator.setDecimalSeparator('.'); DecimalFormat coordinateDecimalFormat = new DecimalFormat("##.######"); coordinateDecimalFormat.setDecimalFormatSymbols(separator); if (address != null) URL.append(String.format("center=%s&", address)); URL.append(String.format("sensor=%s&", this.sensor ? "true" : "false")); URL.append(String.format("zoom=%d&", zoomLevel)); URL.append(String.format("scale=%d&", imageScale)); URL.append(String.format("size=%dx%d&", imageWidth, imageHeight)); URL.append(String.format("maptype=%s&", LPGoogleFunctions.getMapType(mapType))); if (markers != null) { for (int i = 0; i < markers.size(); i++) { LPMapImageMarker marker = markers.get(i); URL.append(String.format("markers=%s&", marker.getMarkerURLString())); } } this.client.get(URL.toString(), new BinaryHttpResponseHandler() { @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { if (responseHandler != null) responseHandler.errorLoadingStaticMapImage(arg3); } @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { try { Bitmap bmp = BitmapFactory.decodeByteArray(arg2, 0, arg2.length); if (responseHandler != null) responseHandler.didLoadStaticMapImage(bmp); } catch (Exception e) { e.printStackTrace(); if (responseHandler != null) responseHandler.errorLoadingStaticMapImage(e.getCause()); } } }); }
From source file:com.vishwa.pinit.MainActivity.java
private void createMarkerAtLocation(final double latitude, final double longitude, final Note note) { if (mReverseNoteStore.get(note.getNoteId()) == null) { Bitmap balloonBackground = BitmapFactory.decodeResource(getResources(), R.drawable.balloon_background); Bitmap userPhoto = null;/*ww w. j av a 2 s . c o m*/ if (note.getNoteCreator().equals(mCurrentUsername)) { balloonBackground = Bitmap.createScaledBitmap(balloonBackground, 87, 94, false); userPhoto = Bitmap.createScaledBitmap(mUserPhotoThumbnail, 75, 71, false); Canvas canvas = new Canvas(balloonBackground); canvas.drawBitmap(balloonBackground, 0, 0, null); canvas.drawBitmap(userPhoto, 6, 6, null); addMarkerToMap(note, balloonBackground, latitude, longitude); } else { if (mMemoryCache.get(note.getNoteCreator()) != null) { balloonBackground = Bitmap.createScaledBitmap(balloonBackground, 87, 94, false); userPhoto = Bitmap.createScaledBitmap(mMemoryCache.get(note.getNoteCreator()), 75, 71, false); Canvas canvas = new Canvas(balloonBackground); canvas.drawBitmap(balloonBackground, 0, 0, null); canvas.drawBitmap(userPhoto, 6, 6, null); addMarkerToMap(note, balloonBackground, latitude, longitude); } else { ParseQuery query = ParseUser.getQuery(); query.whereEqualTo("username", note.getNoteCreator()); query.getFirstInBackground(new GetCallback() { @Override public void done(ParseObject object, ParseException e) { if (e == null) { ParseObject noteCreator = object; if (noteCreator.getBoolean("isDefaultPhoto")) { Bitmap balloonBackground = BitmapFactory.decodeResource(getResources(), R.drawable.balloon_background); Bitmap userPhoto = null; balloonBackground = Bitmap.createScaledBitmap(balloonBackground, 87, 94, false); userPhoto = Bitmap.createScaledBitmap(mMemoryCache.get("defaultPhoto"), 75, 71, false); note.setNoteCreatorHasDefaultPhoto(true); Canvas canvas = new Canvas(balloonBackground); canvas.drawBitmap(balloonBackground, 0, 0, null); canvas.drawBitmap(userPhoto, 6, 6, null); addMarkerToMap(note, balloonBackground, latitude, longitude); } else { ParseFile userPhotoFile = noteCreator.getParseFile("profilePhotoThumbnail"); userPhotoFile.getDataInBackground(new GetDataCallback() { @Override public void done(byte[] data, ParseException e) { if (e == null) { Bitmap balloonBackground = BitmapFactory.decodeResource( getResources(), R.drawable.balloon_background); Bitmap userPhoto = BitmapFactory.decodeByteArray(data, 0, data.length); mMemoryCache.put(note.getNoteCreator(), userPhoto); balloonBackground = Bitmap.createScaledBitmap(balloonBackground, 87, 94, false); userPhoto = Bitmap.createScaledBitmap(userPhoto, 75, 71, false); Canvas canvas = new Canvas(balloonBackground); canvas.drawBitmap(balloonBackground, 0, 0, null); canvas.drawBitmap(userPhoto, 6, 6, null); addMarkerToMap(note, balloonBackground, latitude, longitude); } else { Toast.makeText(getApplicationContext(), "Photo load failed", Toast.LENGTH_LONG).show(); PinItUtils.createAlert("This is embarrassing", "Please log out and login again", MainActivity.this); } } }); } } else { Toast.makeText(getApplicationContext(), note.getNoteCreator(), Toast.LENGTH_LONG) .show(); PinItUtils.createAlert("This is embarrassing", "Please log out and login again", MainActivity.this); } } }); } } } }
From source file:com.xperia64.timidityae.MusicService.java
@SuppressLint("NewApi") public void play() { if (playList != null && currSongNumber >= 0) { shouldAdvance = false;//from w w w.j a v a2s . co m death = true; fullStop = false; stop(); death = false; Globals.shouldRestore = true; while (!death && ((Globals.isPlaying == 0 || JNIHandler.alternativeCheck == 333333))) { try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } } if (!death) { MediaMetadataRetriever mmr = new MediaMetadataRetriever(); String tmpTitle; Globals.currArt = null; final int songIndex; if (shuffleMode == 1) { songIndex = realSongNumber = shuffledIndices.get(currSongNumber); } else { songIndex = realSongNumber = currSongNumber; } try { mmr.setDataSource(playList.get(songIndex)); tmpTitle = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); if (tmpTitle != null) { if (TextUtils.isEmpty(tmpTitle)) tmpTitle = playList.get(songIndex) .substring(playList.get(songIndex).lastIndexOf('/') + 1); } else { tmpTitle = playList.get(songIndex).substring(playList.get(songIndex).lastIndexOf('/') + 1); } } catch (RuntimeException e) { tmpTitle = playList.get(songIndex).substring(playList.get(songIndex).lastIndexOf('/') + 1); } boolean goodart = false; if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) // Please work { try { byte[] art = mmr.getEmbeddedPicture(); if (art != null) { Globals.currArt = BitmapFactory.decodeByteArray(art, 0, art.length); goodart = Globals.currArt != null; } } catch (Exception e) { } } if (!goodart) { String goodPath = playList.get(songIndex).substring(0, playList.get(songIndex).lastIndexOf('/') + 1) + "folder.jpg"; if (new File(goodPath).exists()) { try { Globals.currArt = BitmapFactory.decodeFile(goodPath); } catch (RuntimeException e) { } } else { // Try albumart.jpg goodPath = playList.get(songIndex).substring(0, playList.get(songIndex).lastIndexOf('/') + 1) + "AlbumArt.jpg"; if (new File(goodPath).exists()) { try { Globals.currArt = BitmapFactory.decodeFile(goodPath); } catch (RuntimeException e) { // } } } } if (shouldDoWidget) { Intent intent = new Intent(this, TimidityAEWidgetProvider.class); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); // Use an array and EXTRA_APPWIDGET_IDS instead of AppWidgetManager.EXTRA_APPWIDGET_ID, // since it seems the onUpdate() is only fired on that: ids = AppWidgetManager.getInstance(getApplication()) .getAppWidgetIds(new ComponentName(getApplication(), TimidityAEWidgetProvider.class)); //intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); intent.putExtra("com.xperia64.timidityae.timidityaewidgetprovider.onlyart", true); sendBroadcast(intent); } Intent new_intent = new Intent(); new_intent.setAction(getResources().getString(R.string.ta_rec)); new_intent.putExtra(getResources().getString(R.string.ta_cmd), 6); sendBroadcast(new_intent); currTitle = tmpTitle; shouldAdvance = true; paused = false; final int x = JNIHandler.play(playList.get(songIndex)); if (x != 0) { switch (x) { case -1: handler.post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), getResources().getString(R.string.srv_fnf), Toast.LENGTH_SHORT).show(); } }); break; case -3: handler.post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), "Error initializing AudioTrack. Try decreasing the buffer size.", Toast.LENGTH_LONG).show(); } }); break; case -9: handler.post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), getResources().getString(R.string.srv_loading), Toast.LENGTH_SHORT).show(); } }); break; default: handler.post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), String.format(getResources().getString(R.string.srv_unk), x), Toast.LENGTH_SHORT).show(); } }); break; } Globals.isPlaying = 1; JNIHandler.type = true; shouldAdvance = false; JNIHandler.paused = false; stop(); } else { updateNotification(currTitle, paused); new Thread(new Runnable() { public void run() { while (!death && ((Globals.isPlaying == 1 && shouldAdvance))) { if (JNIHandler.alternativeCheck == 555555) death = true; //System.out.println(String.format("alt check: %d death: %s isplaying: %d shouldAdvance: %s seekBarReady: %s",JNIHandler.alternativeCheck,death?"true":"false",Globals.isPlaying,shouldAdvance?"true":"false",JNIHandler.seekbarReady?"true":"false")); try { Thread.sleep(10); } catch (InterruptedException e) { } } if (!death) { Intent new_intent = new Intent(); new_intent.setAction(getResources().getString(R.string.ta_rec)); new_intent.putExtra(getResources().getString(R.string.ta_cmd), 0); new_intent.putExtra(getResources().getString(R.string.ta_startt), JNIHandler.maxTime); new_intent.putExtra(getResources().getString(R.string.ta_songttl), currTitle); new_intent.putExtra(getResources().getString(R.string.ta_filename), playList.get(songIndex)); new_intent.putExtra("stupidNumber", songIndex); sendBroadcast(new_intent); } if (new File(playList.get(songIndex) + ".def.tcf").exists() || new File(playList.get(songIndex) + ".def.tzf").exists()) { String suffix; if (new File(playList.get(songIndex) + ".def.tcf").exists() && new File(playList.get(songIndex) + ".def.tzf").exists()) { suffix = (Globals.compressCfg ? ".def.tzf" : ".def.tcf"); } else if (new File(playList.get(songIndex) + ".def.tcf").exists()) { suffix = ".def.tcf"; } else { suffix = ".def.tzf"; } JNIHandler.shouldPlayNow = false; JNIHandler.currTime = 0; while (Globals.isPlaying == 0 && !death && shouldAdvance && !JNIHandler.dataWritten) { try { Thread.sleep(25); } catch (InterruptedException e) { e.printStackTrace(); } } Intent new_intent = new Intent(); // silly, but should be done async. I think. new_intent.setAction(getResources().getString(R.string.msrv_rec)); new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 17); new_intent.putExtra(getResources().getString(R.string.msrv_infile), playList.get(songIndex) + suffix); new_intent.putExtra(getResources().getString(R.string.msrv_reset), true); sendBroadcast(new_intent); } while (!death && (((Globals.isPlaying == 0 || JNIHandler.alternativeCheck == 333333) && shouldAdvance))) { try { Thread.sleep(25); } catch (InterruptedException e) { } } if (shouldAdvance && !death) { shouldAdvance = false; new Thread(new Runnable() { public void run() { if (playList.size() > 1 && (((songIndex + 1 < playList.size() && loopMode == 0)) || loopMode == 1)) { next(); } else if (loopMode == 2 || playList.size() == 1) { play(); } else if (loopMode == 0) { Globals.hardStop = true; Intent new_intent = new Intent(); new_intent.setAction(getResources().getString(R.string.ta_rec)); new_intent.putExtra(getResources().getString(R.string.ta_cmd), 5); new_intent.putExtra(getResources().getString(R.string.ta_pause), false); sendBroadcast(new_intent); } } }).start(); } } }).start(); } } } }
From source file:cm.confide.ex.chips.BaseRecipientAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { final RecipientEntry entry = getEntries().get(position); String displayName = entry.getDisplayName(); String destination = entry.getDestination(); if (TextUtils.isEmpty(displayName) || TextUtils.equals(displayName, destination)) { displayName = destination;/* w w w. j av a2 s . co m*/ // We only show the destination for secondary entries, so clear it // only for the first level. if (entry.isFirstLevel()) { destination = null; } } final View itemView = convertView != null ? convertView : mInflater.inflate(getItemLayout(), parent, false); final TextView displayNameView = (TextView) itemView.findViewById(getDisplayNameId()); final TextView destinationView = (TextView) itemView.findViewById(getDestinationId()); final TextView destinationTypeView = (TextView) itemView.findViewById(getDestinationTypeId()); final ImageView imageView = (ImageView) itemView.findViewById(getPhotoId()); displayNameView.setText(displayName); if (!TextUtils.isEmpty(destination)) { destinationView.setText(destination); } else { destinationView.setText(null); } if (destinationTypeView != null) { final CharSequence destinationType = mQuery .getTypeLabel(mContext.getResources(), entry.getDestinationType(), entry.getDestinationLabel()) .toString().toUpperCase(); destinationTypeView.setText(destinationType); } if (entry.isFirstLevel()) { displayNameView.setVisibility(View.VISIBLE); if (imageView != null) { imageView.setVisibility(View.VISIBLE); final byte[] photoBytes = entry.getPhotoBytes(); if (photoBytes != null) { final Bitmap photo = BitmapFactory.decodeByteArray(photoBytes, 0, photoBytes.length); imageView.setImageBitmap(photo); } else { imageView.setImageResource(getDefaultPhotoResource()); } } } else { displayNameView.setVisibility(View.GONE); if (imageView != null) { imageView.setVisibility(View.INVISIBLE); } } return itemView; }
From source file:com.DGSD.Teexter.UI.Recipient.BaseRecipientAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { final RecipientEntry entry = mEntries.get(position); switch (entry.getEntryType()) { case RecipientEntry.ENTRY_TYPE_WAITING_FOR_DIRECTORY_SEARCH: { return convertView != null ? convertView : mInflater.inflate(getWaitingForDirectorySearchLayout(), parent, false); }/*from w ww .ja v a 2s. c om*/ default: { String displayName = entry.getDisplayName(); String destination = entry.getDestination(); if (TextUtils.isEmpty(displayName) || TextUtils.equals(displayName, destination)) { displayName = destination; destination = null; } final View itemView = convertView != null ? convertView : mInflater.inflate(getItemLayout(), parent, false); final TextView displayNameView = (TextView) itemView.findViewById(getDisplayNameId()); final TextView destinationView = (TextView) itemView.findViewById(getDestinationId()); final TextView destinationTypeView = (TextView) itemView.findViewById(getDestinationTypeId()); final ImageView imageView = (ImageView) itemView.findViewById(getPhotoId()); displayNameView.setText(displayName); if (!TextUtils.isEmpty(destination)) { destinationView.setText(destination); } else { destinationView.setText(null); } if (destinationTypeView != null) { final CharSequence destinationType = Email.getTypeLabel(mContext.getResources(), entry.getDestinationType(), entry.getDestinationLabel()).toString().toUpperCase(); destinationTypeView.setText(destinationType); } if (entry.isFirstLevel()) { displayNameView.setVisibility(View.VISIBLE); if (imageView != null) { imageView.setVisibility(View.VISIBLE); final byte[] photoBytes = entry.getPhotoBytes(); if (photoBytes != null && imageView != null) { final Bitmap photo = BitmapFactory.decodeByteArray(photoBytes, 0, photoBytes.length); imageView.setImageBitmap(photo); } else { imageView.setImageResource(getDefaultPhotoResource()); } } } else { displayNameView.setVisibility(View.GONE); if (imageView != null) { imageView.setVisibility(View.INVISIBLE); } } return itemView; } } }
From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java
private void setIconBarContent() { ((MainActivity) activity).actionBar//from ww w . ja v a 2 s .c o m .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray)); ((MainActivity) activity).actionBarTitle.setTextColor(getResources().getColor(R.color.speak_all_gray)); ((MainActivity) activity).actionBarDesc.setTextColor(getResources().getColor(R.color.speak_all_gray)); ((MainActivity) activity).actionBarIconRight.setTextColor(getResources().getColor(R.color.speak_all_red)); ((MainActivity) activity).actionBarIconLeft.setTextColor(getResources().getColor(R.color.speak_all_red)); ((MainActivity) activity).actionBarTitle.setVisibility(View.VISIBLE); ((MainActivity) activity).actionBarTitle.setText(grupo.nombreGrupo); ((MainActivity) activity).actionBarDesc.setVisibility(View.GONE); ((MainActivity) activity).actionBarIconLeft.setVisibility(View.VISIBLE); ((MainActivity) activity).actionBarIconLeft.setText(Finder.STRING.ICN_ARROW_LEFT.toString()); ((MainActivity) activity).actionBarIconRight.setVisibility(View.VISIBLE); ((MainActivity) activity).actionBarLeftFavorites.setVisibility(View.GONE); ((MainActivity) activity).actionBarIconRight.setText(Finder.STRING.ICN_ADJUNT.toString()); ((MainActivity) activity).actionBarIconRightBrowse.setVisibility(View.GONE); ((MainActivity) activity).actionBarRightAll.setVisibility(View.GONE); ((MainActivity) activity).actionBarIconRightDivider.setVisibility(View.GONE); ((MainActivity) activity).actionBarIconPic.setVisibility(View.GONE); ((MainActivity) activity).actionBarCenterLayout.setVisibility(View.VISIBLE); ((MainActivity) activity).actionBarSearchLayout.setVisibility(View.GONE); if (grupo.photo != null) { Bitmap bmp = BitmapFactory.decodeByteArray(grupo.photo, 0, grupo.photo.length); ((MainActivity) activity).actionBarIconPicChat.setImageBitmap(bmp); ((MainActivity) activity).actionBarIconPicChat.setVisibility(View.VISIBLE); ((MainActivity) activity).actionBarIconPicEmpty.setVisibility(View.GONE); } else { ((MainActivity) activity).actionBarIconPicEmpty.setVisibility(View.VISIBLE); ((MainActivity) activity).actionBarIconPicChat.setVisibility(View.GONE); } /*((MainActivity) activity).actionBarTitle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getFragmentManager().popBackStack(); getFragmentManager().beginTransaction().replace(R.id.container, ProfileContactFragment.newInstance(contact)) .addToBackStack(null) .commit(); ((MainActivity) activity).setOnBackPressedListener(null); } });*/ ((MainActivity) activity).actionBarIconLeft.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); MsgGroups mensaje = new Select().from(MsgGroups.class).where("mensajeId = ?", messageSelected) .executeSingle(); if (mensaje.emisor.equals(u.id)) { int status = 0; try { JSONArray contactos = new JSONArray(mensaje.receptores); for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); if (status == 0 || contacto.getInt("status") <= status) { status = contacto.getInt("status"); } } } catch (JSONException e) { e.printStackTrace(); } vista.findViewById(R.id.icn_message_back).setVisibility(View.INVISIBLE); vista.findViewById(R.id.messages_menu_layout).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } else { vista.findViewById(R.id.icn_message_copy).setVisibility(View.INVISIBLE); vista.findViewById(R.id.icn_message_back).setVisibility(View.INVISIBLE); vista.findViewById(R.id.messages_menu_layout).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } else { getFragmentManager().popBackStack(); ((MainActivity) activity).setOnBackPressedListener(null); } } }); ((MainActivity) activity).actionBarIconRight.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { menuAdjunt = !menuAdjunt; if (menuAdjunt) { adjuntLayout.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(adjuntLayout, "alpha", 0, 1)); set.setDuration(200).start(); } else { adjuntLayout.setVisibility(View.GONE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(adjuntLayout, "alpha", 1, 0)); set.setDuration(200).start(); } } }); setted = true; }
From source file:me.ububble.speakall.fragment.ConversationChatFragment.java
public void setIconBarContent() { ((MainActivity) activity).actionBar//from w w w . ja v a 2 s .com .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray)); ((MainActivity) activity).actionBarTitle.setTextColor(getResources().getColor(R.color.speak_all_gray)); ((MainActivity) activity).actionBarDesc.setTextColor(getResources().getColor(R.color.speak_all_gray)); ((MainActivity) activity).actionBarIconRight.setTextColor(getResources().getColor(R.color.speak_all_red)); ((MainActivity) activity).actionBarIconLeft.setTextColor(getResources().getColor(R.color.speak_all_red)); ((MainActivity) activity).actionBarTitle.setVisibility(View.VISIBLE); ((MainActivity) activity).actionBarTitle.setText(contact.fullName); ((MainActivity) activity).actionBarDesc.setVisibility(View.GONE); ((MainActivity) activity).actionBarIconLeft.setVisibility(View.VISIBLE); ((MainActivity) activity).actionBarIconLeft.setText(Finder.STRING.ICN_ARROW_LEFT.toString()); ((MainActivity) activity).actionBarIconRight.setVisibility(View.VISIBLE); ((MainActivity) activity).actionBarLeftFavorites.setVisibility(View.GONE); ((MainActivity) activity).actionBarIconRight.setText(Finder.STRING.ICN_ADJUNT.toString()); ((MainActivity) activity).actionBarIconRightBrowse.setVisibility(View.GONE); ((MainActivity) activity).actionBarRightAll.setVisibility(View.GONE); ((MainActivity) activity).actionBarIconRightDivider.setVisibility(View.GONE); ((MainActivity) activity).actionBarIconPic.setVisibility(View.GONE); ((MainActivity) activity).actionBarCenterLayout.setVisibility(View.VISIBLE); ((MainActivity) activity).actionBarSearchLayout.setVisibility(View.GONE); new Thread(new Runnable() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { if (contact.photo != null) { Bitmap bmp = BitmapFactory.decodeByteArray(contact.photo, 0, contact.photo.length); ((MainActivity) activity).actionBarIconPicChat.setImageBitmap(bmp); ((MainActivity) activity).actionBarIconPicChat.setVisibility(View.VISIBLE); ((MainActivity) activity).actionBarIconPicEmpty.setVisibility(View.GONE); } else { ((MainActivity) activity).actionBarIconPicEmpty.setVisibility(View.VISIBLE); ((MainActivity) activity).actionBarIconPicChat.setVisibility(View.GONE); } } }); } }).start(); ((MainActivity) activity).actionBarTitle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getFragmentManager().beginTransaction() .replace(R.id.container2, ProfileContactFragment.newInstance(contact)).addToBackStack(null) .commit(); ((MainActivity) activity).setOnBackPressedListener(null); } }); ((MainActivity) activity).actionBarIconLeft.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { System.gc(); if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); Message mensaje = new Select().from(Message.class).where("mensajeId = ?", messageSelected) .executeSingle(); if (mensaje.emisor.equals(u.id)) { if (mensaje.status != 4) { vista.findViewById(R.id.icn_message_tempo_divider).setVisibility(View.INVISIBLE); vista.findViewById(R.id.icn_message_tempo).setVisibility(View.INVISIBLE); } else { vista.findViewById(R.id.icn_message_tempo_divider).setVisibility(View.GONE); vista.findViewById(R.id.icn_message_tempo).setVisibility(View.GONE); } vista.findViewById(R.id.icn_message_back).setVisibility(View.INVISIBLE); vista.findViewById(R.id.messages_menu_layout).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } else { vista.findViewById(R.id.icn_message_tempo).setVisibility(View.GONE); vista.findViewById(R.id.icn_message_copy).setVisibility(View.INVISIBLE); vista.findViewById(R.id.icn_message_back).setVisibility(View.INVISIBLE); vista.findViewById(R.id.messages_menu_layout).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } else { getFragmentManager().popBackStack(); ((MainActivity) activity).setOnBackPressedListener(null); } } }); ((MainActivity) activity).actionBarIconRight.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { menuAdjunt = !menuAdjunt; if (menuAdjunt) { adjuntLayout.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(adjuntLayout, "alpha", 0, 1)); set.setDuration(200).start(); } else { adjuntLayout.setVisibility(View.GONE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(adjuntLayout, "alpha", 1, 0)); set.setDuration(200).start(); } } }); setted = true; }
From source file:com.eleybourn.bookcatalogue.utils.Utils.java
/** * Called in the UI thread, will return a cached image OR NULL. * // ww w. j av a 2s .com * @param originalFile File representing original image file * @param destView View to populate * @param cacheId ID of the image in the cache * * @return Bitmap (if cached) or NULL (if not cached) */ public Bitmap fetchCachedImageIntoImageView(final File originalFile, final ImageView destView, final String cacheId) { Bitmap bm = null; // resultant Bitmap (which we will return) // Get the db CoversDbHelper coversDb = getCoversDb(); if (coversDb != null) { byte[] bytes; // Wrap in try/catch. It's possible the SDCard got removed and DB is now inaccessible Date expiry; if (originalFile == null) expiry = new Date(0L); else expiry = new Date(originalFile.lastModified()); try { bytes = coversDb.getFile(cacheId, expiry); } catch (Exception e) { bytes = null; } ; if (bytes != null) { try { bm = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); } catch (Exception e) { bytes = null; } ; } } if (bm != null) { // // Remove any tasks that may be getting the image because they may overwrite anything we do. // Remember: the view may have been re-purposed and have a different associated task which // must be removed from the view and removed from the queue. // if (destView != null) GetThumbnailTask.clearOldTaskFromView(destView); // We found it in cache if (destView != null) destView.setImageBitmap(bm); // Return the image } return bm; }
From source file:com.android.mtkex.chips.BaseRecipientAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { /// M: add view holder to improve performance. DropDownListViewHolder viewHolder;/*from w w w. j av a2s . co m*/ /// M: get view holder from convert view. @{ if (convertView == null) { convertView = mInflater.inflate(getItemLayout(), parent, false); viewHolder = new DropDownListViewHolder(); if (convertView != null) { viewHolder.name = (TextView) convertView.findViewById(getDisplayNameId()); viewHolder.dest = (TextView) convertView.findViewById(getDestinationId()); viewHolder.destType = (TextView) convertView.findViewById(getDestinationTypeId()); viewHolder.img = (ImageView) convertView.findViewById(getPhotoId()); convertView.setTag(viewHolder); } } else { viewHolder = (DropDownListViewHolder) convertView.getTag(); } /// @} final RecipientEntry entry = getEntries().get(position); String displayName = entry.getDisplayName(); String destination = entry.getDestination(); if (TextUtils.isEmpty(displayName) || TextUtils.equals(displayName, destination)) { displayName = destination; // We only show the destination for secondary entries, so clear it // only for the first level. if (entry.isFirstLevel()) { destination = null; } } /// M: get properties from view holder. @{ final View itemView = convertView; final TextView displayNameView = viewHolder.name; final TextView destinationView = viewHolder.dest; final TextView destinationTypeView = viewHolder.destType; final ImageView imageView = viewHolder.img; /// @} displayNameView.setText(displayName); if (!TextUtils.isEmpty(destination)) { destinationView.setText(destination); } else { destinationView.setText(null); } if (destinationTypeView != null) { CharSequence destinationType = null; if (mShowPhoneAndEmail) { /// M: Current query is phone query, but there may exist email results as well. /// Hence, we need to get destinationType of email results by Queries.EMAIL. @{ if (entry.getDestinationKind() == RecipientEntry.ENTRY_KIND_EMAIL) { destinationType = Queries.EMAIL.getTypeLabel(mContext.getResources(), entry.getDestinationType(), entry.getDestinationLabel()).toString().toUpperCase(); } else { destinationType = Queries.PHONE.getTypeLabel(mContext.getResources(), entry.getDestinationType(), entry.getDestinationLabel()).toString().toUpperCase(); } /// @} } else { destinationType = mQuery.getTypeLabel(mContext.getResources(), entry.getDestinationType(), entry.getDestinationLabel()).toString().toUpperCase(); } destinationTypeView.setText(destinationType); } if (entry.isFirstLevel()) { displayNameView.setVisibility(View.VISIBLE); if (imageView != null) { imageView.setVisibility(View.VISIBLE); final byte[] photoBytes = entry.getPhotoBytes(); if (photoBytes != null) { /// M: get bitmap from recipient entry Bitmap photo = entry.getBitmap(); /// M: cache bitmap if unavailable. @{ if (photo == null) { photo = BitmapFactory.decodeByteArray(photoBytes, 0, photoBytes.length); entry.setBitmap(photo); } /// @} imageView.setImageBitmap(photo); } else { imageView.setImageResource(getDefaultPhotoResource()); } } } else { displayNameView.setVisibility(View.GONE); if (imageView != null) { imageView.setVisibility(View.INVISIBLE); } } return itemView; }