Example usage for android.graphics BitmapFactory decodeByteArray

List of usage examples for android.graphics BitmapFactory decodeByteArray

Introduction

In this page you can find the example usage for android.graphics BitmapFactory decodeByteArray.

Prototype

public static Bitmap decodeByteArray(byte[] data, int offset, int length) 

Source Link

Document

Decode an immutable bitmap from the specified byte array.

Usage

From source file:com.android.xbrowser.BookmarksPageCallbacks.java

static Bitmap getBitmap(Cursor cursor, int columnIndex) {
    byte[] data = cursor.getBlob(columnIndex);
    if (data == null) {
        return null;
    }/*from  w  w w .  j a v  a2  s  . com*/
    return BitmapFactory.decodeByteArray(data, 0, data.length);
}

From source file:com.mobicage.rogerthat.FriendDetailActivity.java

private void initBroadcastReceiver(final IntentFilter filter) {

    T.UI();//from   w  w  w. ja  va2  s. c  om

    mBroadcastReceiver = new SafeBroadcastReceiver() {

        @Override
        public String[] onSafeReceive(final Context context, final Intent intent) {
            T.UI();
            if (mFriend == null) {
                L.bug("FriendDetailActivity received intent but mFriend == null");
                return ALL_RECEIVING_INTENTS;
            }

            String action = intent.getAction();
            if (FriendsPlugin.FRIENDS_LIST_REFRESHED.equals(action)) {

                Friend newFriend = showFriend(intent);
                if (newFriend == null) {
                    // friend does not exist anymore, not interested in any older intent
                    return ALL_RECEIVING_INTENTS;
                }
                mFriend = newFriend;
                return UPDATE_VIEW_INTENTS;

            } else if (BrandingMgr.SERVICE_BRANDING_AVAILABLE_INTENT.equals(action)
                    || BrandingMgr.GENERIC_BRANDING_AVAILABLE_INTENT.equals(action)) {

                if (mFriend != null && mFriend.descriptionBranding != null && mFriend.descriptionBranding
                        .equals(intent.getStringExtra(BrandingMgr.BRANDING_KEY))) {

                    showBrandedDescription(mFriend);
                    return new String[] { BrandingMgr.SERVICE_BRANDING_AVAILABLE_INTENT,
                            BrandingMgr.GENERIC_BRANDING_AVAILABLE_INTENT };
                }

            } else if (mFriend.email.equals(intent.getStringExtra(EMAIL))) {

                // Process friend intents

                if (FriendsPlugin.FRIEND_UPDATE_INTENT.equals(action)
                        || FriendsPlugin.FRIEND_AVATAR_CHANGED_INTENT.equals(action)) {

                    Friend newFriend = showFriend(intent);
                    if (newFriend == null) {
                        // friend does not exist anymore, not interested in any older intent
                        return ALL_RECEIVING_INTENTS;
                    }
                    mFriend = newFriend;
                    return UPDATE_VIEW_INTENTS;

                } else if (FriendsPlugin.FRIEND_REMOVED_INTENT.equals(action)) {

                    L.d("Received intent - FRIEND_REMOVED_INTENT");
                    if (mFriend.existenceStatus != Friend.NOT_FOUND && !isFinishing()) {
                        finish();
                        return ALL_RECEIVING_INTENTS;
                    }

                } else if (FriendsPlugin.FRIEND_QR_CODE_RECEIVED_INTENT.equals(action)) {

                    byte[] image = Base64.decode(intent.getStringExtra("qrcode"));
                    Bitmap bm = BitmapFactory.decodeByteArray(image, 0, image.length);
                    ImageView view = (ImageView) findViewById(R.id.qrcode);
                    view.setImageBitmap(bm);
                    return new String[] { action };

                }
            }
            return null;
        }
    };
    registerReceiver(mBroadcastReceiver, filter);
}

From source file:com.fitforbusiness.nafc.dashboard.DashBoardFragment.java

private void loadIntoListView(List<Session> list) {
    if (list != null && list.size() != 0) {
        LinkedHashMap<String, Object> row;
        if (list != null && list.size() != 0) {
            for (Session session : list) {
                row = new LinkedHashMap<String, Object>();
                row.put("secondLabel", session.getStartTime());
                if (session.getSessionType().equals("1")) {
                    ParseQuery parseQuery = new ParseQuery(Group.class);
                    parseQuery.fromLocalDatastore();
                    parseQuery.whereEqualTo("objectId", session.getGroupClientId());
                    mapgroupList = new ArrayList<Group>();
                    try {
                        mapgroupList = parseQuery.find();
                    } catch (com.parse.ParseException e1) {
                    }/*from  w  ww.  j  a  v  a2s . c o m*/
                    if (mapclientList == null) {
                        ParseQuery parseQuery1 = new ParseQuery(Group.class);
                        parseQuery1.whereEqualTo("objectId", session.getGroupClientId());
                        mapgroupList = new ArrayList<Group>();
                        try {
                            mapgroupList = parseQuery1.find();
                        } catch (com.parse.ParseException e1) {
                        }
                        for (Group group : mapgroupList) {
                            row.put("name", group.getName());
                            if (group.getImageFile() != null) {
                                String fileObjectStr = group.getImageFile();
                                byte[] fileObject = android.util.Base64.decode(fileObjectStr, 1);
                                Bitmap bmp = BitmapFactory.decodeByteArray(fileObject, 0, fileObject.length);
                                row.put("photo", bmp);
                            } else {
                                row.put("photo", null);
                            }
                        }
                    } else {
                        for (Group group : mapgroupList) {
                            row.put("name", group.getName());
                            if (group.getImageFile() != null) {
                                String fileObjectStr = group.getImageFile();
                                byte[] fileObject = android.util.Base64.decode(fileObjectStr, 1);
                                Bitmap bmp = BitmapFactory.decodeByteArray(fileObject, 0, fileObject.length);
                                row.put("photo", bmp);
                            } else {
                                row.put("photo", null);
                            }
                        }
                    }
                } else {
                    ParseQuery parseQuery = new ParseQuery(Client.class);
                    parseQuery.fromLocalDatastore();
                    parseQuery.whereEqualTo("objectId", session.getGroupClientId());
                    mapclientList = new ArrayList<Client>();
                    try {
                        mapclientList = parseQuery.find();
                    } catch (com.parse.ParseException e1) {
                    }
                    if (mapclientList == null) {
                        ParseQuery parseQuery1 = new ParseQuery(Client.class);
                        parseQuery1.whereEqualTo("objectId", session.getGroupClientId());
                        mapclientList = new ArrayList<Client>();
                        try {
                            mapclientList = parseQuery1.find();
                        } catch (com.parse.ParseException e1) {
                        }
                        for (Client client : mapclientList) {
                            row.put("name", client.getFirstName());
                            if (client.getImageFile() != null) {
                                String fileObjectStr = client.getImageFile();
                                byte[] fileObject = android.util.Base64.decode(fileObjectStr, 1);
                                Bitmap bmp = BitmapFactory.decodeByteArray(fileObject, 0, fileObject.length);
                                row.put("photo", bmp);
                            } else {
                                row.put("photo", null);
                            }
                        }
                    } else {
                        for (Client client : mapclientList) {
                            row.put("name", client.getFirstName());
                            if (client.getImageFile() != null) {
                                String fileObjectStr = client.getImageFile();
                                byte[] fileObject = android.util.Base64.decode(fileObjectStr, 1);
                                Bitmap bmp = BitmapFactory.decodeByteArray(fileObject, 0, fileObject.length);
                                row.put("photo", bmp);
                            } else {
                                row.put("photo", null);
                            }
                        }
                    }
                }
                row.put("_id", session.getObjectId());
                //            row.put("secondLabel", session.getSessionType());
                ParseQuery parseQuery = new ParseQuery(Status.class);
                parseQuery.fromLocalDatastore();
                try {
                    mapStatusList = parseQuery.find();
                } catch (com.parse.ParseException e) {
                }
                if (mapStatusList == null || mapStatusList.size() == 0) {
                    ParseQuery parseQuery1 = new ParseQuery(Status.class);
                    parseQuery1.fromLocalDatastore();
                    try {
                        mapStatusList = parseQuery.find();
                    } catch (com.parse.ParseException e) {
                    }
                    if (mapStatusList != null && mapStatusList.size() != 0) {
                        row.put("thirdLabel", mapStatusList.get((int) session.getStatus()).getName());
                    }
                } else {
                    row.put("thirdLabel", mapStatusList.get((int) session.getStatus()).getName());
                }

                row.put("secondLabel", session.getStartTime());
                mapArrayList.add(row);
            }
            if (mapArrayList != null && mapArrayList.size() != 0) {
                CustomAsyncTaskListAdapter adapter = new CustomAsyncTaskListAdapter(getActivity(),
                        R.layout.calendar_day_view_session_row, R.id.ivRowImage, R.id.tvFirstName,
                        R.id.tvSecondLabel, R.id.tvThirdLabel, mapArrayList);
                sessionList.setAdapter(adapter);
            }
        }
    }

}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * ??bitmap//from   w ww . ja v  a  2s.  c om
 * 
 * @param b
 *            Byte
 * @return ?Bitmap
 */
public static Bitmap getBitmapFromBytes(byte[] b) {
    if (b.length != 0) {
        return BitmapFactory.decodeByteArray(b, 0, b.length);
    } else {
        return null;
    }
}

From source file:com.nostra13.universalimageloader.core.decode.ContentImageDecoder.java

private Bitmap makeVideoThumbnailFromMediaMetadataRetriever(MediaMetadataRetriever retriever) {
    if (retriever == null)
        return null;

    Bitmap thumbnail = null;/* w w w .  j  av a 2 s .c o m*/
    byte[] picture = retriever.getEmbeddedPicture();

    if (picture != null) {
        Log8.d();
        thumbnail = BitmapFactory.decodeByteArray(picture, 0, picture.length);
        if (thumbnail != null) {
            Log8.d(thumbnail.getWidth(), thumbnail.getHeight());
        }
    } else {
        Log8.d();
    }

    if (thumbnail == null) {
        Log8.d();
        thumbnail = retriever.getFrameAtTime();
        if (thumbnail != null) {
            Log8.d(thumbnail.getWidth(), thumbnail.getHeight());
        }
    }

    if (thumbnail == null) {
        Log8.d();
        return null;
    }

    return thumbnail;
}

From source file:com.rnd.snapsplit.view.SentRequestFragment.java

@Nullable
@Override/*  w  w w  . ja  va 2s .c om*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    //super.onCreate(savedInstanceState);
    view = inflater.inflate(R.layout.activity_sent_request, container, false);
    activity = getActivity();
    profile = new Profile(getContext());
    ((Toolbar) getActivity().findViewById(R.id.tool_bar_hamburger)).setVisibility(View.VISIBLE);

    mProgressBar = (ProgressBar) view.findViewById(R.id.progressBar);
    mMessageRecyclerView = (RecyclerView) view.findViewById(R.id.messageRecyclerView);
    mLinearLayoutManager = new LinearLayoutManager(getContext());
    //mLinearLayoutManager.setStackFromEnd(true);
    //Raymonds phone number here
    mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference().child("requests");
    mFirebaseAdapter = new FirebaseRecyclerAdapter<PaymentRequest, MessageViewHolder>(PaymentRequest.class,
            R.layout.list_sent_requests, MessageViewHolder.class,
            mFirebaseDatabaseReference.orderByChild("requestEpochDate")) {

        @Override
        protected PaymentRequest parseSnapshot(DataSnapshot snapshot) {
            PaymentRequest pr = super.parseSnapshot(snapshot);
            if (pr != null) {
                pr.setId(snapshot.getKey());
                return pr;
            }
            return null;
        }

        @Override
        protected void populateViewHolder(final MessageViewHolder viewHolder, PaymentRequest pr, int position) {
            mProgressBar.setVisibility(ProgressBar.INVISIBLE);
            if (pr != null && pr.getRequestorPhoneNumber().equals(profile.getPhoneNumber())) {

                if (pr.getStrReceiptPic() != null && !pr.getStrReceiptPic().equals("")) {
                    String encodedReceipt = pr.getStrReceiptPic();
                    byte[] encodeByte = Base64.decode(encodedReceipt, Base64.DEFAULT);
                    Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
                    viewHolder.receiptIcon.setImageBitmap(bitmap);
                }
                viewHolder.pr = pr;
                viewHolder.id = pr.getId();
                viewHolder.description.setText(pr.getDescription());
                viewHolder.toPerson.setText("Request sent to: "
                        + Friend.getFriendByPhoneNumber(getContext(), pr.getReceipientPhoneNo()).getName());
                viewHolder.splitAmount.setText("HKD" + String.format("%.2f", pr.getShareAmount()));
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy' 'HH:mm:ss");
                String date = null;
                Date temp = new Date(Long.parseLong(pr.getRequestEpochDate()) * (-1));
                date = simpleDateFormat.format(temp);
                viewHolder.date.setText(date);
            } else {
                ViewGroup.LayoutParams params = viewHolder.item.getLayoutParams();
                params.height = 0;
                viewHolder.item.setLayoutParams(params);
            }

            // log a view action on it
            //FirebaseUserActions.getInstance().end(getMessageViewAction(fd));
        }

        @Override
        public MessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            MessageViewHolder viewHolder = super.onCreateViewHolder(parent, viewType);
            viewHolder.setOnLongClickListener(new MessageViewHolder.LongClickListener() {
                @Override
                public void onLongClick(View view, int position, String id, PaymentRequest pr) {
                    AlertDialog.Builder ImageDialog = new AlertDialog.Builder(getActivity());
                    ImageDialog.setTitle("Receipt Preview - " + pr.getDescription());
                    ImageView showImage = new ImageView(getActivity());
                    Bitmap bitmap = null;
                    if (pr.getStrReceiptPic() != null && !pr.getStrReceiptPic().equals("")) {
                        String encodedReceipt = pr.getStrReceiptPic();
                        byte[] encodeByte = Base64.decode(encodedReceipt, Base64.DEFAULT);
                        bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
                    }
                    if (bitmap != null) {
                        showImage.setImageBitmap(bitmap);
                    }
                    ImageDialog.setView(showImage);

                    ImageDialog.setNegativeButton("Close Preview", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface arg0, int arg1) {
                        }
                    });
                    ImageDialog.show();
                }
            });
            viewHolder.setOnClickListener(new MessageViewHolder.ClickListener() {
                @Override
                public void onItemClick(View view, int position, String id, PaymentRequest pr) {
                    //Toast.makeText(getActivity(), "Item clicked at " + position, Toast.LENGTH_SHORT).show();

                }

            });
            return viewHolder;
        }

    };

    mFirebaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
        @Override
        public void onItemRangeInserted(int positionStart, int itemCount) {
            super.onItemRangeInserted(positionStart, itemCount);
            int friendlyMessageCount = mFirebaseAdapter.getItemCount();
            int lastVisiblePosition = mLinearLayoutManager.findLastCompletelyVisibleItemPosition();
            // If the recycler view is initially being loaded or the user is at the bottom of the list, scroll
            // to the bottom of the list to show the newly added message.
            if (lastVisiblePosition == -1 || (positionStart >= (friendlyMessageCount - 1)
                    && lastVisiblePosition == (positionStart - 1))) {
                mMessageRecyclerView.scrollToPosition(positionStart);
            }
        }
    });

    mMessageRecyclerView.setLayoutManager(mLinearLayoutManager);
    mMessageRecyclerView.setAdapter(mFirebaseAdapter);

    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());

    return view;

}

From source file:org.zywx.wbpalmstar.plugin.uexiconlist.utils.IconListUtils.java

public static Bitmap downloadNetworkBitmap(String url) {
    byte[] data = downloadImageFromNetwork(url);
    if (data == null || data.length == 0) {
        return null;
    }/*from   www . jav  a2 s  .c  o  m*/
    return BitmapFactory.decodeByteArray(data, 0, data.length);
}

From source file:com.freshplanet.ane.GoogleCloudStorageUpload.tasks.UploadToGoogleCloudStorageAsyncTask.java

private static byte[] resizeImage(byte[] mediaBytes, int maxWidth, int maxHeight) {
    // TODO Auto-generated method stub
    Bitmap image = BitmapFactory.decodeByteArray(mediaBytes, 0, mediaBytes.length);
    Bitmap newImage = resizeImage(image, maxWidth, maxHeight);
    if (image != newImage)
        mediaBytes = getJPEGRepresentationFromBitmap(newImage);
    return mediaBytes;
}

From source file:cn.edu.nju.dapenti.activity.MainActivity.java

private void selectDrawerItem(int position) {
    mCurrentDrawerPos = position;/*  w  ww  .j  a  v  a  2  s  . c o  m*/
    mIcon = null;

    Uri newUri;
    boolean showFeedInfo = true;

    switch (position) {
    case 0:
        newUri = FeedData.EntryColumns.CONTENT_URI;
        break;
    case 1:
        newUri = FeedData.EntryColumns.FAVORITES_CONTENT_URI;
        break;
    default:
        long feedOrGroupId = mDrawerAdapter.getItemId(position);
        if (mDrawerAdapter.isItemAGroup(position)) {
            newUri = FeedData.EntryColumns.ENTRIES_FOR_GROUP_CONTENT_URI(feedOrGroupId);
        } else {
            byte[] iconBytes = mDrawerAdapter.getItemIcon(position);
            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);
                    }

                    mIcon = new BitmapDrawable(getResources(), bitmap);
                }
            }

            newUri = FeedData.EntryColumns.ENTRIES_FOR_FEED_CONTENT_URI(feedOrGroupId);
            showFeedInfo = false;
        }
        mTitle = mDrawerAdapter.getItemName(position);
        break;
    }

    if (!newUri.equals(mEntriesFragment.getUri())) {
        mEntriesFragment.setData(newUri, showFeedInfo);
    }

    mDrawerList.setItemChecked(position, true);

    // First open => we open the drawer for you
    if (PrefUtils.getBoolean(PrefUtils.FIRST_OPEN, true)) {
        PrefUtils.putBoolean(PrefUtils.FIRST_OPEN, false);
        mDrawerLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                mDrawerLayout.openDrawer(mDrawerList);
            }
        }, 500);
    }
}