kandi background
Explore Kits

RoundedImageView | fast ImageView that supports rounded corners | Computer Vision library

 by   vinc3m1 Java Version: v2.3.0 License: Non-SPDX

 by   vinc3m1 Java Version: v2.3.0 License: Non-SPDX

Download this library from

kandi X-RAY | RoundedImageView Summary

RoundedImageView is a Java library typically used in Artificial Intelligence, Computer Vision applications. RoundedImageView has no bugs, it has no vulnerabilities, it has build file available and it has medium support. However RoundedImageView has a Non-SPDX License. You can download it from GitHub, Maven.
A fast ImageView (and Drawable) that supports rounded corners (and ovals or circles) based on the original example from Romain Guy. It supports many additional features including ovals, rounded rectangles, ScaleTypes and TileModes.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • RoundedImageView has a medium active ecosystem.
  • It has 6203 star(s) with 1239 fork(s). There are 225 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 26 open issues and 191 have been closed. On average issues are closed in 87 days. There are 9 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of RoundedImageView is v2.3.0
RoundedImageView Support
Best in #Computer Vision
Average in #Computer Vision
RoundedImageView Support
Best in #Computer Vision
Average in #Computer Vision

quality kandi Quality

  • RoundedImageView has 0 bugs and 0 code smells.
RoundedImageView Quality
Best in #Computer Vision
Average in #Computer Vision
RoundedImageView Quality
Best in #Computer Vision
Average in #Computer Vision

securitySecurity

  • RoundedImageView has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • RoundedImageView code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
RoundedImageView Security
Best in #Computer Vision
Average in #Computer Vision
RoundedImageView Security
Best in #Computer Vision
Average in #Computer Vision

license License

  • RoundedImageView has a Non-SPDX License.
  • Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.
RoundedImageView License
Best in #Computer Vision
Average in #Computer Vision
RoundedImageView License
Best in #Computer Vision
Average in #Computer Vision

buildReuse

  • RoundedImageView releases are available to install and integrate.
  • Deployable package is available in Maven.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
RoundedImageView Reuse
Best in #Computer Vision
Average in #Computer Vision
RoundedImageView Reuse
Best in #Computer Vision
Average in #Computer Vision
Top functions reviewed by kandi - BETA

kandi has reviewed RoundedImageView and discovered the below as its top functions. This is intended to give you an instant insight into RoundedImageView implemented functionality, and help decide if they suit your requirements.

  • Updates the shader matrix .
  • Draws this image .
  • from adapter
  • Returns the view which is created when the view is created .
  • update the attributes of the drawable
  • Sets the scale type .
  • Builds a transformation .
  • Set the example type .
  • Returns a new instance of the bounded fragment .
  • Set corner radius .

RoundedImageView Key Features

does not create a copy of the original bitmap

does not use a clipPath which is not hardware accelerated and not anti-aliased.

does not use setXfermode to clip the bitmap and draw twice to the canvas.

Borders (with Colors and ColorStateLists)

Ovals and Circles

All ScaleTypes Borders are drawn at view edge, not bitmap edge Except on edges where the bitmap is smaller than the view Borders are not scaled up/down with the image (correct width and radius are maintained)

Anti-aliasing

Transparent backgrounds

Hardware acceleration

Support for LayerDrawables (including TransitionDrawables)

TileModes for repeating drawables

Gradle

copy iconCopydownload iconDownload
repositories {
    mavenCentral()
}

dependencies {
    implementation 'com.makeramen:roundedimageview:2.3.0'
}

Usage

copy iconCopydownload iconDownload
<com.makeramen.roundedimageview.RoundedImageView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/imageView1"
        android:src="@drawable/photo1"
        android:scaleType="fitCenter"
        app:riv_corner_radius="30dip"
        app:riv_border_width="2dip"
        app:riv_border_color="#333333"
        app:riv_mutate_background="true"
        app:riv_tile_mode="repeat"
        app:riv_oval="true" />

Picasso

copy iconCopydownload iconDownload
Transformation transformation = new RoundedTransformationBuilder()
          .borderColor(Color.BLACK)
          .borderWidthDp(3)
          .cornerRadiusDp(30)
          .oval(false)
          .build();

Picasso.with(context)
    .load(url)
    .fit()
    .transform(transformation)
    .into(imageView);

License

copy iconCopydownload iconDownload
Copyright 2017 Vincent Mi

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Image doesn't send for other side Android Studio java

copy iconCopydownload iconDownload
private void sendMessage(String encodedImage) {
        Map<String, Object> message = new HashMap<>();
        message.put(Constants.KEY_SENDER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
        message.put(Constants.KEY_RECEIVER_ID, user.getId());
        message.put(Constants.KEY_MESSAGE, binding.inputMessage.getText().toString());
        message.put(Constants.KEY_IMAGE_MESSAGE, encodedImage);
        message.put(Constants.KEY_TIMESTAMP, new Date());
        db.collection(Constants.KEY_COLLECTION_CHAT).add(message);
        if (conversionId != null) {
            updateConversion(binding.inputMessage.getText().toString());
        } else {
            Map<String, Object> conversion = new HashMap<>();
            conversion.put(Constants.KEY_SENDER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
            conversion.put(Constants.KEY_SENDER_NAME, preferenceManager.getString(Constants.KEY_NAME));
            conversion.put(Constants.KEY_SENDER_IMAGE, preferenceManager.getString(Constants.KEY_IMAGE));

            conversion.put(Constants.KEY_RECEIVER_ID, user.getId());
            conversion.put(Constants.KEY_RECEIVER_NAME, user.getName());
            conversion.put(Constants.KEY_RECEIVER_IMAGE, user.getImage());
            conversion.put(Constants.KEY_LAST_MESSAGE, binding.inputMessage.getText().toString());
            conversion.put(Constants.KEY_TIMESTAMP, new Date());
            addConversion(conversion);
        }
        if (!isReceiverAvaible) {
            try {
                JSONArray tokens = new JSONArray();
                tokens.put(user.getToken());

                JSONObject data = new JSONObject();
                data.put(Constants.KEY_USER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
                data.put(Constants.KEY_NAME, preferenceManager.getString(Constants.KEY_NAME));
                data.put(Constants.KEY_FCM_TOKEN, preferenceManager.getString(Constants.KEY_FCM_TOKEN));
                data.put(Constants.KEY_MESSAGE, binding.inputMessage.getText().toString());

                JSONObject body = new JSONObject();
                body.put(Constants.REMOTE_MSG_DATA, data);
                body.put(Constants.REMOTE_MSG_REGISTRATION_IDS, tokens);

                sendNotification(body.toString());

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        binding.inputMessage.setText(null);
    }
private final EventListener<QuerySnapshot> eventListener = (value, error) -> {
        if (error != null) {
            return;
        }
        if (value != null) {
            int count = messages.size();
            for (DocumentChange documentChange : value.getDocumentChanges()) {
                if (documentChange.getType() == DocumentChange.Type.ADDED) {
                    ChatMessage chatMessage = new ChatMessage(
                            documentChange.getDocument().getString(Constants.KEY_SENDER_ID),
                            documentChange.getDocument().getString(Constants.KEY_RECEIVER_ID),
                            documentChange.getDocument().getString(Constants.KEY_MESSAGE),
                            getReadableDateTime(documentChange.getDocument().getDate(Constants.KEY_TIMESTAMP)),
                            documentChange.getDocument().getDate(Constants.KEY_TIMESTAMP)
                    );
                    if (documentChange.getDocument().getString(Constants.KEY_IMAGE_MESSAGE) != null && !documentChange.getDocument().getString(Constants.KEY_IMAGE_MESSAGE).isEmpty()) {
                        byte[] decodedString = Base64.decode((documentChange.getDocument().getString(Constants.KEY_IMAGE_MESSAGE, Base64.DEFAULT);
                        Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
                        chatMessage.setImage(decodedByte);
                    }
                    messages.add(chatMessage);
                }
            }
            Collections.sort(messages, Comparator.comparing(ChatMessage::getDate));
            if (count == 0) {
                chatAdapter.notifyDataSetChanged();
            } else {
                chatAdapter.notifyItemRangeInserted(messages.size(), messages.size());
                binding.chatRecyclerView.smoothScrollToPosition(messages.size() - 1);
            }
            binding.chatRecyclerView.setVisibility(View.VISIBLE);
        }
        binding.progressBar.setVisibility(View.GONE);
        if (conversionId == null) checkForConversion();
    };
private final ActivityResultLauncher<Intent> pickImage = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
        if (result.getResultCode() != RESULT_OK) return;
        if (result.getData() == null) return;
        Uri imageUri = result.getData().getData();

        try {
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
            sendMessage(encodeImage(bitmap));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    });
private String encodeImage(Bitmap bitmap) {
        int previewWidth = 300;
        int previewHeight = bitmap.getHeight() * previewWidth / bitmap.getWidth();
        Bitmap previewBitmap = Bitmap.createScaledBitmap(bitmap, previewWidth, previewHeight, false);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        previewBitmap.compress(Bitmap.CompressFormat.JPEG, 50, byteArrayOutputStream);
        String str = Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.DEFAULT);
        return str == null ? "" : str;
    }
-----------------------
private void sendMessage(String encodedImage) {
        Map<String, Object> message = new HashMap<>();
        message.put(Constants.KEY_SENDER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
        message.put(Constants.KEY_RECEIVER_ID, user.getId());
        message.put(Constants.KEY_MESSAGE, binding.inputMessage.getText().toString());
        message.put(Constants.KEY_IMAGE_MESSAGE, encodedImage);
        message.put(Constants.KEY_TIMESTAMP, new Date());
        db.collection(Constants.KEY_COLLECTION_CHAT).add(message);
        if (conversionId != null) {
            updateConversion(binding.inputMessage.getText().toString());
        } else {
            Map<String, Object> conversion = new HashMap<>();
            conversion.put(Constants.KEY_SENDER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
            conversion.put(Constants.KEY_SENDER_NAME, preferenceManager.getString(Constants.KEY_NAME));
            conversion.put(Constants.KEY_SENDER_IMAGE, preferenceManager.getString(Constants.KEY_IMAGE));

            conversion.put(Constants.KEY_RECEIVER_ID, user.getId());
            conversion.put(Constants.KEY_RECEIVER_NAME, user.getName());
            conversion.put(Constants.KEY_RECEIVER_IMAGE, user.getImage());
            conversion.put(Constants.KEY_LAST_MESSAGE, binding.inputMessage.getText().toString());
            conversion.put(Constants.KEY_TIMESTAMP, new Date());
            addConversion(conversion);
        }
        if (!isReceiverAvaible) {
            try {
                JSONArray tokens = new JSONArray();
                tokens.put(user.getToken());

                JSONObject data = new JSONObject();
                data.put(Constants.KEY_USER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
                data.put(Constants.KEY_NAME, preferenceManager.getString(Constants.KEY_NAME));
                data.put(Constants.KEY_FCM_TOKEN, preferenceManager.getString(Constants.KEY_FCM_TOKEN));
                data.put(Constants.KEY_MESSAGE, binding.inputMessage.getText().toString());

                JSONObject body = new JSONObject();
                body.put(Constants.REMOTE_MSG_DATA, data);
                body.put(Constants.REMOTE_MSG_REGISTRATION_IDS, tokens);

                sendNotification(body.toString());

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        binding.inputMessage.setText(null);
    }
private final EventListener<QuerySnapshot> eventListener = (value, error) -> {
        if (error != null) {
            return;
        }
        if (value != null) {
            int count = messages.size();
            for (DocumentChange documentChange : value.getDocumentChanges()) {
                if (documentChange.getType() == DocumentChange.Type.ADDED) {
                    ChatMessage chatMessage = new ChatMessage(
                            documentChange.getDocument().getString(Constants.KEY_SENDER_ID),
                            documentChange.getDocument().getString(Constants.KEY_RECEIVER_ID),
                            documentChange.getDocument().getString(Constants.KEY_MESSAGE),
                            getReadableDateTime(documentChange.getDocument().getDate(Constants.KEY_TIMESTAMP)),
                            documentChange.getDocument().getDate(Constants.KEY_TIMESTAMP)
                    );
                    if (documentChange.getDocument().getString(Constants.KEY_IMAGE_MESSAGE) != null && !documentChange.getDocument().getString(Constants.KEY_IMAGE_MESSAGE).isEmpty()) {
                        byte[] decodedString = Base64.decode((documentChange.getDocument().getString(Constants.KEY_IMAGE_MESSAGE, Base64.DEFAULT);
                        Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
                        chatMessage.setImage(decodedByte);
                    }
                    messages.add(chatMessage);
                }
            }
            Collections.sort(messages, Comparator.comparing(ChatMessage::getDate));
            if (count == 0) {
                chatAdapter.notifyDataSetChanged();
            } else {
                chatAdapter.notifyItemRangeInserted(messages.size(), messages.size());
                binding.chatRecyclerView.smoothScrollToPosition(messages.size() - 1);
            }
            binding.chatRecyclerView.setVisibility(View.VISIBLE);
        }
        binding.progressBar.setVisibility(View.GONE);
        if (conversionId == null) checkForConversion();
    };
private final ActivityResultLauncher<Intent> pickImage = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
        if (result.getResultCode() != RESULT_OK) return;
        if (result.getData() == null) return;
        Uri imageUri = result.getData().getData();

        try {
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
            sendMessage(encodeImage(bitmap));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    });
private String encodeImage(Bitmap bitmap) {
        int previewWidth = 300;
        int previewHeight = bitmap.getHeight() * previewWidth / bitmap.getWidth();
        Bitmap previewBitmap = Bitmap.createScaledBitmap(bitmap, previewWidth, previewHeight, false);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        previewBitmap.compress(Bitmap.CompressFormat.JPEG, 50, byteArrayOutputStream);
        String str = Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.DEFAULT);
        return str == null ? "" : str;
    }
-----------------------
private void sendMessage(String encodedImage) {
        Map<String, Object> message = new HashMap<>();
        message.put(Constants.KEY_SENDER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
        message.put(Constants.KEY_RECEIVER_ID, user.getId());
        message.put(Constants.KEY_MESSAGE, binding.inputMessage.getText().toString());
        message.put(Constants.KEY_IMAGE_MESSAGE, encodedImage);
        message.put(Constants.KEY_TIMESTAMP, new Date());
        db.collection(Constants.KEY_COLLECTION_CHAT).add(message);
        if (conversionId != null) {
            updateConversion(binding.inputMessage.getText().toString());
        } else {
            Map<String, Object> conversion = new HashMap<>();
            conversion.put(Constants.KEY_SENDER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
            conversion.put(Constants.KEY_SENDER_NAME, preferenceManager.getString(Constants.KEY_NAME));
            conversion.put(Constants.KEY_SENDER_IMAGE, preferenceManager.getString(Constants.KEY_IMAGE));

            conversion.put(Constants.KEY_RECEIVER_ID, user.getId());
            conversion.put(Constants.KEY_RECEIVER_NAME, user.getName());
            conversion.put(Constants.KEY_RECEIVER_IMAGE, user.getImage());
            conversion.put(Constants.KEY_LAST_MESSAGE, binding.inputMessage.getText().toString());
            conversion.put(Constants.KEY_TIMESTAMP, new Date());
            addConversion(conversion);
        }
        if (!isReceiverAvaible) {
            try {
                JSONArray tokens = new JSONArray();
                tokens.put(user.getToken());

                JSONObject data = new JSONObject();
                data.put(Constants.KEY_USER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
                data.put(Constants.KEY_NAME, preferenceManager.getString(Constants.KEY_NAME));
                data.put(Constants.KEY_FCM_TOKEN, preferenceManager.getString(Constants.KEY_FCM_TOKEN));
                data.put(Constants.KEY_MESSAGE, binding.inputMessage.getText().toString());

                JSONObject body = new JSONObject();
                body.put(Constants.REMOTE_MSG_DATA, data);
                body.put(Constants.REMOTE_MSG_REGISTRATION_IDS, tokens);

                sendNotification(body.toString());

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        binding.inputMessage.setText(null);
    }
private final EventListener<QuerySnapshot> eventListener = (value, error) -> {
        if (error != null) {
            return;
        }
        if (value != null) {
            int count = messages.size();
            for (DocumentChange documentChange : value.getDocumentChanges()) {
                if (documentChange.getType() == DocumentChange.Type.ADDED) {
                    ChatMessage chatMessage = new ChatMessage(
                            documentChange.getDocument().getString(Constants.KEY_SENDER_ID),
                            documentChange.getDocument().getString(Constants.KEY_RECEIVER_ID),
                            documentChange.getDocument().getString(Constants.KEY_MESSAGE),
                            getReadableDateTime(documentChange.getDocument().getDate(Constants.KEY_TIMESTAMP)),
                            documentChange.getDocument().getDate(Constants.KEY_TIMESTAMP)
                    );
                    if (documentChange.getDocument().getString(Constants.KEY_IMAGE_MESSAGE) != null && !documentChange.getDocument().getString(Constants.KEY_IMAGE_MESSAGE).isEmpty()) {
                        byte[] decodedString = Base64.decode((documentChange.getDocument().getString(Constants.KEY_IMAGE_MESSAGE, Base64.DEFAULT);
                        Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
                        chatMessage.setImage(decodedByte);
                    }
                    messages.add(chatMessage);
                }
            }
            Collections.sort(messages, Comparator.comparing(ChatMessage::getDate));
            if (count == 0) {
                chatAdapter.notifyDataSetChanged();
            } else {
                chatAdapter.notifyItemRangeInserted(messages.size(), messages.size());
                binding.chatRecyclerView.smoothScrollToPosition(messages.size() - 1);
            }
            binding.chatRecyclerView.setVisibility(View.VISIBLE);
        }
        binding.progressBar.setVisibility(View.GONE);
        if (conversionId == null) checkForConversion();
    };
private final ActivityResultLauncher<Intent> pickImage = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
        if (result.getResultCode() != RESULT_OK) return;
        if (result.getData() == null) return;
        Uri imageUri = result.getData().getData();

        try {
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
            sendMessage(encodeImage(bitmap));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    });
private String encodeImage(Bitmap bitmap) {
        int previewWidth = 300;
        int previewHeight = bitmap.getHeight() * previewWidth / bitmap.getWidth();
        Bitmap previewBitmap = Bitmap.createScaledBitmap(bitmap, previewWidth, previewHeight, false);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        previewBitmap.compress(Bitmap.CompressFormat.JPEG, 50, byteArrayOutputStream);
        String str = Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.DEFAULT);
        return str == null ? "" : str;
    }
-----------------------
private void sendMessage(String encodedImage) {
        Map<String, Object> message = new HashMap<>();
        message.put(Constants.KEY_SENDER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
        message.put(Constants.KEY_RECEIVER_ID, user.getId());
        message.put(Constants.KEY_MESSAGE, binding.inputMessage.getText().toString());
        message.put(Constants.KEY_IMAGE_MESSAGE, encodedImage);
        message.put(Constants.KEY_TIMESTAMP, new Date());
        db.collection(Constants.KEY_COLLECTION_CHAT).add(message);
        if (conversionId != null) {
            updateConversion(binding.inputMessage.getText().toString());
        } else {
            Map<String, Object> conversion = new HashMap<>();
            conversion.put(Constants.KEY_SENDER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
            conversion.put(Constants.KEY_SENDER_NAME, preferenceManager.getString(Constants.KEY_NAME));
            conversion.put(Constants.KEY_SENDER_IMAGE, preferenceManager.getString(Constants.KEY_IMAGE));

            conversion.put(Constants.KEY_RECEIVER_ID, user.getId());
            conversion.put(Constants.KEY_RECEIVER_NAME, user.getName());
            conversion.put(Constants.KEY_RECEIVER_IMAGE, user.getImage());
            conversion.put(Constants.KEY_LAST_MESSAGE, binding.inputMessage.getText().toString());
            conversion.put(Constants.KEY_TIMESTAMP, new Date());
            addConversion(conversion);
        }
        if (!isReceiverAvaible) {
            try {
                JSONArray tokens = new JSONArray();
                tokens.put(user.getToken());

                JSONObject data = new JSONObject();
                data.put(Constants.KEY_USER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
                data.put(Constants.KEY_NAME, preferenceManager.getString(Constants.KEY_NAME));
                data.put(Constants.KEY_FCM_TOKEN, preferenceManager.getString(Constants.KEY_FCM_TOKEN));
                data.put(Constants.KEY_MESSAGE, binding.inputMessage.getText().toString());

                JSONObject body = new JSONObject();
                body.put(Constants.REMOTE_MSG_DATA, data);
                body.put(Constants.REMOTE_MSG_REGISTRATION_IDS, tokens);

                sendNotification(body.toString());

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        binding.inputMessage.setText(null);
    }
private final EventListener<QuerySnapshot> eventListener = (value, error) -> {
        if (error != null) {
            return;
        }
        if (value != null) {
            int count = messages.size();
            for (DocumentChange documentChange : value.getDocumentChanges()) {
                if (documentChange.getType() == DocumentChange.Type.ADDED) {
                    ChatMessage chatMessage = new ChatMessage(
                            documentChange.getDocument().getString(Constants.KEY_SENDER_ID),
                            documentChange.getDocument().getString(Constants.KEY_RECEIVER_ID),
                            documentChange.getDocument().getString(Constants.KEY_MESSAGE),
                            getReadableDateTime(documentChange.getDocument().getDate(Constants.KEY_TIMESTAMP)),
                            documentChange.getDocument().getDate(Constants.KEY_TIMESTAMP)
                    );
                    if (documentChange.getDocument().getString(Constants.KEY_IMAGE_MESSAGE) != null && !documentChange.getDocument().getString(Constants.KEY_IMAGE_MESSAGE).isEmpty()) {
                        byte[] decodedString = Base64.decode((documentChange.getDocument().getString(Constants.KEY_IMAGE_MESSAGE, Base64.DEFAULT);
                        Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
                        chatMessage.setImage(decodedByte);
                    }
                    messages.add(chatMessage);
                }
            }
            Collections.sort(messages, Comparator.comparing(ChatMessage::getDate));
            if (count == 0) {
                chatAdapter.notifyDataSetChanged();
            } else {
                chatAdapter.notifyItemRangeInserted(messages.size(), messages.size());
                binding.chatRecyclerView.smoothScrollToPosition(messages.size() - 1);
            }
            binding.chatRecyclerView.setVisibility(View.VISIBLE);
        }
        binding.progressBar.setVisibility(View.GONE);
        if (conversionId == null) checkForConversion();
    };
private final ActivityResultLauncher<Intent> pickImage = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
        if (result.getResultCode() != RESULT_OK) return;
        if (result.getData() == null) return;
        Uri imageUri = result.getData().getData();

        try {
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
            sendMessage(encodeImage(bitmap));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    });
private String encodeImage(Bitmap bitmap) {
        int previewWidth = 300;
        int previewHeight = bitmap.getHeight() * previewWidth / bitmap.getWidth();
        Bitmap previewBitmap = Bitmap.createScaledBitmap(bitmap, previewWidth, previewHeight, false);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        previewBitmap.compress(Bitmap.CompressFormat.JPEG, 50, byteArrayOutputStream);
        String str = Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.DEFAULT);
        return str == null ? "" : str;
    }

Cardview shows twice when dynamically generated

copy iconCopydownload iconDownload
    TextView nameWorker = card.findViewById(R.id.nameWorker);
    RatingBar RatingBar = card.findViewById(R.id.ratingBar);
    Button submitButton = card.findViewById(R.id.submitButton);

android:exported needs to be explicitly specified for &lt;activity&gt;. Apps targeting Android 12 and higher are required to specify

copy iconCopydownload iconDownload
<receiver android:name="<name_of_the_entry>"
                android:exported="false or true"
                tools:node="merge" />
-----------------------
     <activity
                android:name="<activity which is giving error>"
                android:exported="true"
                tools:node="merge" />
-----------------------
<activity android:name="name_of_the_activity_inside_library>"
    android:exported="false|true"
    tools:node="merge" />
-----------------------
debugImplementation "androidx.fragment:fragment-testing:<version>"
androidTestImplementation "androidx.fragment:fragment-testing:<version>"
-----------------------
debugImplementation "androidx.fragment:fragment-testing:<version>"
androidTestImplementation "androidx.fragment:fragment-testing:<version>"
-----------------------
 android:exported="true"
-----------------------
androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.0.4"
-----------------------
> java.util.concurrent.ExecutionException: com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/xxxxx.tmp/base.apk (at Binary XML file line #129): YOUR.FULLY.QUALIFIED.NAME.FAILING.ACTIVITY: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present
-----------------------
<activity android:name="androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity"
android:exported="true"
tools:node="merge"/>

<activity android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity"
android:exported="true"
tools:node="merge"/>

<activity android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity"
android:exported="true"
tools:node="merge"/>
-----------------------
 <activity
        android:name="com.test.activity.SplashActivity"
        android:clearTaskOnLaunch="true"
        android:label="@string/app_name"
        android:launchMode="singleTop"
        android:noHistory="true"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar"
        android:exported="true">
   <receiver
        android:name="com.test.receiver.ShareReceiver"
        android:exported="true">
        <intent-filter>
            <action android:name="com.test.fcm.android.action.broadcast" />
        </intent-filter>
    </receiver>

   <service
        android:name="com.google.android.gms.tagmanager.InstallReferrerService"
        android:exported="true" />
testImplementation 'junit:junit:4.13.2' 
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.razorpay:checkout:1.6.15'
-----------------------
 <activity
        android:name="com.test.activity.SplashActivity"
        android:clearTaskOnLaunch="true"
        android:label="@string/app_name"
        android:launchMode="singleTop"
        android:noHistory="true"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar"
        android:exported="true">
   <receiver
        android:name="com.test.receiver.ShareReceiver"
        android:exported="true">
        <intent-filter>
            <action android:name="com.test.fcm.android.action.broadcast" />
        </intent-filter>
    </receiver>

   <service
        android:name="com.google.android.gms.tagmanager.InstallReferrerService"
        android:exported="true" />
testImplementation 'junit:junit:4.13.2' 
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.razorpay:checkout:1.6.15'
-----------------------
 <activity
        android:name="com.test.activity.SplashActivity"
        android:clearTaskOnLaunch="true"
        android:label="@string/app_name"
        android:launchMode="singleTop"
        android:noHistory="true"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar"
        android:exported="true">
   <receiver
        android:name="com.test.receiver.ShareReceiver"
        android:exported="true">
        <intent-filter>
            <action android:name="com.test.fcm.android.action.broadcast" />
        </intent-filter>
    </receiver>

   <service
        android:name="com.google.android.gms.tagmanager.InstallReferrerService"
        android:exported="true" />
testImplementation 'junit:junit:4.13.2' 
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.razorpay:checkout:1.6.15'
-----------------------
"com.google.dagger:hilt-android:2.38.1"
"com.google.dagger:hilt-android-gradle-plugin:2.38.1"
"com.google.dagger:hilt-android-compiler:2.38.1"
"com.google.dagger:hilt-android-testing:2.38.1"
"com.google.dagger:hilt-android:2.40.5"
"com.google.dagger:hilt-android-gradle-plugin:2.40.5"
"com.google.dagger:hilt-android-compiler:2.40.5"
"com.google.dagger:hilt-android-testing:2.40.5" 
-----------------------
"com.google.dagger:hilt-android:2.38.1"
"com.google.dagger:hilt-android-gradle-plugin:2.38.1"
"com.google.dagger:hilt-android-compiler:2.38.1"
"com.google.dagger:hilt-android-testing:2.38.1"
"com.google.dagger:hilt-android:2.40.5"
"com.google.dagger:hilt-android-gradle-plugin:2.40.5"
"com.google.dagger:hilt-android-compiler:2.40.5"
"com.google.dagger:hilt-android-testing:2.40.5" 
-----------------------
<receiver
    android:name="com.razorpay.RzpTokenReceiver"
    android:exported="false">
    <intent-filter>
        <action android:name="rzp.device_token.share" />
    </intent-filter>
</receiver>

<activity
    android:name="com.razorpay.CheckoutActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:exported="true"
    android:theme="@style/CheckoutTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <data
            android:host="rzp.io"
            android:scheme="io.rzp" />
    </intent-filter>
</activity>
-----------------------
android:exported="true" <!-- or false as required -->
-----------------------
<activity
     android:name=".MainActivity"
     android:exported="true" <** add this line on AndroidManifest.xml**
     android:launchMode="singleTop"
     android:theme="@style/LaunchTheme"
 </activity>

Kotlin :Execution failed for task ':app:checkDebugAarMetadata'

copy iconCopydownload iconDownload
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
        implementation 'com.github.AsynctaskCoffee:TinderLikeCardStack:1.0'
}
<dependency>
    <groupId>com.github.AsynctaskCoffee</groupId>
    <artifactId>TinderLikeCardStack</artifactId>
    <version>1.0</version>
</dependency>


<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
-----------------------
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
        implementation 'com.github.AsynctaskCoffee:TinderLikeCardStack:1.0'
}
<dependency>
    <groupId>com.github.AsynctaskCoffee</groupId>
    <artifactId>TinderLikeCardStack</artifactId>
    <version>1.0</version>
</dependency>


<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Why does exoplayer 2.13.3 get downloaded, when I have included a dependency for exoplayer 2.8.4?

copy iconCopydownload iconDownload
implementation('com.google.android.exoplayer:exoplayer') {
    version {
        strictly '2.8.4'
    }
}

how to edit view of layout in parent when use RecyclerView?

copy iconCopydownload iconDownload
val tvName = findViewById<TextView>(R.id.tv_item_user);
tvName.Visibility = View.VISIBLE; // View.GONE, View.INVISIBLE are available too.

android studio: center ProgressPar on top of RoundedImageView

copy iconCopydownload iconDownload
    <ProgressBar
    android:id="@+id/pb"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_alignStart="@+id/imageIV"
    android:layout_alignBottom="@+id/imageIV"
    android:layout_alignEnd="@+id/imageIV"
    android:layout_alignTop="@+id/imageIV" />
    <ProgressBar
    android:id="@+id/pb"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_alignStart="@+id/imageIV"
    android:layout_alignBottom="@+id/imageIV"
    android:layout_alignTop="@+id/imageIV"
    android:layout_alignEnd="@+id/imageIV"
    />
-----------------------
    <ProgressBar
    android:id="@+id/pb"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_alignStart="@+id/imageIV"
    android:layout_alignBottom="@+id/imageIV"
    android:layout_alignEnd="@+id/imageIV"
    android:layout_alignTop="@+id/imageIV" />
    <ProgressBar
    android:id="@+id/pb"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_alignStart="@+id/imageIV"
    android:layout_alignBottom="@+id/imageIV"
    android:layout_alignTop="@+id/imageIV"
    android:layout_alignEnd="@+id/imageIV"
    />

handle clickevent in appbar in fragments android studio

copy iconCopydownload iconDownload
public class ProfileFragment extends Fragment {
    

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        Toolbar toolbar = view.findViewById(R.id.my_toolbar);
        toolbar.inflateMenu(R.menu.your_menu);
        toolbar.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.delete:
                        //handle click
                        return true;
                    case R.id.new_pic:
                        // handle here
                        return true;
                    default:
                        return false;
                }
            }
        });

    }
}

Not able to set background of imageview using databinding

copy iconCopydownload iconDownload
@BindingAdapter("imageName")
fun setImageFromURls(view: @BindingAdapter("imageName")
fun setImageFromURls(view: ShapeableImageView, fileName: String) {
    Glide.with(view.context)
            .load(fileName)
            .into(view)
}

Images not showing in recyclerview from firebase

copy iconCopydownload iconDownload
Picasso.get()
         .load(uploadCurrent.getmImageUrl())
         .fit()
         .transform(transformation)
         .into(holder.postImageView);
Picasso.with(holder.postImageView)//or context
        .load(uploadCurrent.getmImageUrl())
        .fit()
        .transform(transformation)
        .into(holder.postImageView);
-----------------------
Picasso.get()
         .load(uploadCurrent.getmImageUrl())
         .fit()
         .transform(transformation)
         .into(holder.postImageView);
Picasso.with(holder.postImageView)//or context
        .load(uploadCurrent.getmImageUrl())
        .fit()
        .transform(transformation)
        .into(holder.postImageView);

Community Discussions

Trending Discussions on RoundedImageView
  • Image doesn't send for other side Android Studio java
  • Cardview shows twice when dynamically generated
  • android:exported needs to be explicitly specified for &lt;activity&gt;. Apps targeting Android 12 and higher are required to specify
  • Kotlin :Execution failed for task ':app:checkDebugAarMetadata'
  • Why does exoplayer 2.13.3 get downloaded, when I have included a dependency for exoplayer 2.8.4?
  • how to edit view of layout in parent when use RecyclerView?
  • android studio: center ProgressPar on top of RoundedImageView
  • handle clickevent in appbar in fragments android studio
  • Not able to set background of imageview using databinding
  • Images not showing in recyclerview from firebase
Trending Discussions on RoundedImageView

QUESTION

Image doesn't send for other side Android Studio java

Asked 2022-Mar-24 at 16:00

I have problem, because I can't send images for other side, it duplicates or sends empty message, but normal messages work fine. I've tried many tutorials and changing some classes, but nothing really worked

here's my recycler view class:

public final class ChatAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private final List<ChatMessage> messages;
    private Bitmap profileImage;
    private final String senderId;

    private static final int VIEW_TYPE_SENT = 1;
    private static final int VIEW_TYPE_RECEIVED = 2;

    public void setReceiverProfileImage(Bitmap bitmap) {
        this.profileImage = bitmap;
    }

    public ChatAdapter(List<ChatMessage> messages, Bitmap profileImage, String senderId) {
        this.messages = messages;
        this.profileImage = profileImage;
        this.senderId = senderId;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return (viewType == VIEW_TYPE_SENT ? new SentMessageViewHolder(
                ItemContainerSentMessageBinding.inflate(
                        LayoutInflater.from(parent.getContext()),
                        parent,
                        false)
        ) : new ReceivedMessageViewHolder(
                ItemContainerReceivedMessageBinding.inflate(
                        LayoutInflater.from(parent.getContext()),
                        parent,
                        false)
        ));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (getItemViewType(position) == VIEW_TYPE_SENT) {
            ((SentMessageViewHolder) holder).setData(messages.get(position));
        } else {
            ((ReceivedMessageViewHolder) holder).setData(messages.get(position), profileImage);
        }

    }

    @Override
    public int getItemCount() {
        return messages.size();
    }

    @Override
    public int getItemViewType(int position) {
        return (messages.get(position).getSenderId().equals(senderId) ? VIEW_TYPE_SENT : VIEW_TYPE_RECEIVED);
    }

    public static class SentMessageViewHolder extends RecyclerView.ViewHolder {

        private final ItemContainerSentMessageBinding binding;

        public SentMessageViewHolder(ItemContainerSentMessageBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }

        void setData(ChatMessage message) {
            binding.textMessage.setText(message.getMessage());
            binding.textDateTime.setText(message.getDateTime());
            binding.image.setImageBitmap(message.getImage());
        }
    }

    public static class ReceivedMessageViewHolder extends RecyclerView.ViewHolder {

        private final ItemContainerReceivedMessageBinding binding;

        public ReceivedMessageViewHolder(ItemContainerReceivedMessageBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }

        void setData(ChatMessage message, Bitmap bitmap) {
            binding.textMessage.setText(message.getMessage());
            binding.textDateTime.setText(message.getDateTime());
            if (bitmap != null) {
                binding.imageProfile.setImageBitmap(bitmap);
            }
            binding.image.setImageBitmap(message.getImage());
        }
    }
}

Here's received message:

<com.makeramen.roundedimageview.RoundedImageView
        android:id="@+id/imageProfile"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:background="@drawable/background_image"
        android:scaleType="centerCrop"
        app:layout_constraintBottom_toBottomOf="@id/textMessage"
        app:layout_constraintStart_toStartOf="parent"
        app:riv_oval="true"/>

    <TextView
        android:id="@+id/textMessage"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="4dp"
        android:layout_marginLeft="4dp"
        android:background="@drawable/background_received_message"
        android:paddingStart="12dp"
        android:paddingEnd="12dp"
        android:paddingTop="8dp"
        android:paddingBottom="8dp"
        app:layout_constraintWidth_max="wrap"
        android:textColor="@color/white"
        android:textSize="13sp"
        app:layout_constraintStart_toEndOf="@id/imageProfile"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_percent="0.75"/>

    <ImageView
        android:id="@+id/image"
        android:background="@drawable/background_sent_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:layout_marginStart="4dp"
        android:maxWidth="250dp"
        android:maxHeight="250dp"
        app:layout_constraintStart_toEndOf="@id/imageProfile"
        app:layout_constraintTop_toTopOf="parent"/>

    <TextView
        android:id="@+id/textDateTime"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dp"
        android:textColor="@color/secondary_text"
        android:textSize="8sp"
        app:layout_constraintStart_toStartOf="@id/textMessage"
        app:layout_constraintTop_toBottomOf="@id/textMessage"/>

and picking image activity:

    private final ActivityResultLauncher<Intent> pickImage = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
        if (result.getResultCode() != RESULT_OK) return;
        if (result.getData() == null) return;
        Uri imageUri = result.getData().getData();

        try {
            InputStream inputStream = getContentResolver().openInputStream(imageUri);
            Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
            this.encodingImage = encodeImage(bitmap);
            sendMessage();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    });

and here create ChatMessage object (eventListener):

    private final EventListener<QuerySnapshot> eventListener = (value, error) -> {
        if (error != null) {
            return;
        }
        if (value != null) {
            int count = messages.size();
            for (DocumentChange documentChange : value.getDocumentChanges()) {
                if (documentChange.getType() == DocumentChange.Type.ADDED) {
                    ChatMessage chatMessage = new ChatMessage(
                            documentChange.getDocument().getString(Constants.KEY_SENDER_ID),
                            documentChange.getDocument().getString(Constants.KEY_RECEIVER_ID),
                            documentChange.getDocument().getString(Constants.KEY_MESSAGE),
                            getReadableDateTime(documentChange.getDocument().getDate(Constants.KEY_TIMESTAMP)),
                            documentChange.getDocument().getDate(Constants.KEY_TIMESTAMP)
                    );
                    if (!encodingImage.isEmpty()) {
                        byte[] decodedString = Base64.decode(encodingImage, Base64.DEFAULT);
                        Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
                        chatMessage.setImage(decodedByte);
                    }
                    messages.add(chatMessage);
                }
            }
            Collections.sort(messages, Comparator.comparing(ChatMessage::getDate));
            if (count == 0) {
                chatAdapter.notifyDataSetChanged();
            } else {
                chatAdapter.notifyItemRangeInserted(messages.size(), messages.size());
                binding.chatRecyclerView.smoothScrollToPosition(messages.size() - 1);
            }
            binding.chatRecyclerView.setVisibility(View.VISIBLE);
        }
        binding.progressBar.setVisibility(View.GONE);
        if (conversionId == null) checkForConversion();
    };

sendMessage method:

    private void sendMessage() {
        Map<String, Object> message = new HashMap<>();
        message.put(Constants.KEY_SENDER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
        message.put(Constants.KEY_RECEIVER_ID, user.getId());
        message.put(Constants.KEY_MESSAGE, binding.inputMessage.getText().toString());
        if (!encodingImage.isEmpty()) {
            message.put(Constants.KEY_IMAGE_MESSAGE, encodingImage);
        }
        message.put(Constants.KEY_TIMESTAMP, new Date());
        db.collection(Constants.KEY_COLLECTION_CHAT).add(message);
        if (conversionId != null) {
            updateConversion(binding.inputMessage.getText().toString());
        } else {
            Map<String, Object> conversion = new HashMap<>();
            conversion.put(Constants.KEY_SENDER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
            conversion.put(Constants.KEY_SENDER_NAME, preferenceManager.getString(Constants.KEY_NAME));
            conversion.put(Constants.KEY_SENDER_IMAGE, preferenceManager.getString(Constants.KEY_IMAGE));

            conversion.put(Constants.KEY_RECEIVER_ID, user.getId());
            conversion.put(Constants.KEY_RECEIVER_NAME, user.getName());
            conversion.put(Constants.KEY_RECEIVER_IMAGE, user.getImage());
            conversion.put(Constants.KEY_LAST_MESSAGE, binding.inputMessage.getText().toString());
            conversion.put(Constants.KEY_TIMESTAMP, new Date());
            addConversion(conversion);
        }
        if (!isReceiverAvaible) {
            try {
                JSONArray tokens = new JSONArray();
                tokens.put(user.getToken());

                JSONObject data = new JSONObject();
                data.put(Constants.KEY_USER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
                data.put(Constants.KEY_NAME, preferenceManager.getString(Constants.KEY_NAME));
                data.put(Constants.KEY_FCM_TOKEN, preferenceManager.getString(Constants.KEY_FCM_TOKEN));
                data.put(Constants.KEY_MESSAGE, binding.inputMessage.getText().toString());

                JSONObject body = new JSONObject();
                body.put(Constants.REMOTE_MSG_DATA, data);
                body.put(Constants.REMOTE_MSG_REGISTRATION_IDS, tokens);

                sendNotification(body.toString());

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        binding.inputMessage.setText(null);
    }

listenMessages method:

    private void listenMessages() {
        db.collection(Constants.KEY_COLLECTION_CHAT)
                .whereEqualTo(Constants.KEY_SENDER_ID, preferenceManager.getString(Constants.KEY_USER_ID))
                .whereEqualTo(Constants.KEY_RECEIVER_ID, user.getId())
                .addSnapshotListener(eventListener);
        db.collection(Constants.KEY_COLLECTION_CHAT)
                .whereEqualTo(Constants.KEY_SENDER_ID, user.getId())
                .whereEqualTo(Constants.KEY_RECEIVER_ID, preferenceManager.getString(Constants.KEY_USER_ID))
                .addSnapshotListener(eventListener);
    }
    private String encodeImage(Bitmap bitmap) {
        int previewWidth = 300;
        int previewHeight = bitmap.getHeight() * previewWidth / bitmap.getWidth();
        Bitmap previewBitmap = Bitmap.createScaledBitmap(bitmap, previewWidth, previewHeight, false);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        previewBitmap.compress(Bitmap.CompressFormat.JPEG, 50, byteArrayOutputStream);
        return Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.DEFAULT);
    }

Please help and thanks!

ANSWER

Answered 2022-Mar-24 at 16:00

The issue


You are actually providing the adapter the encodingImage which was just created and that is why you get repeated or no image at all.

The solution

There are 2 parts in this solution:

  1. Reformat the methods and their parameters
  2. Change the code to pick image for sending image

Let's start !

1. Reformat the methods and their parameters

First of all, you need to add 1 parameter to the sendMessage() method. It will look something like this:

private void sendMessage(String encodedImage) {
        Map<String, Object> message = new HashMap<>();
        message.put(Constants.KEY_SENDER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
        message.put(Constants.KEY_RECEIVER_ID, user.getId());
        message.put(Constants.KEY_MESSAGE, binding.inputMessage.getText().toString());
        message.put(Constants.KEY_IMAGE_MESSAGE, encodedImage);
        message.put(Constants.KEY_TIMESTAMP, new Date());
        db.collection(Constants.KEY_COLLECTION_CHAT).add(message);
        if (conversionId != null) {
            updateConversion(binding.inputMessage.getText().toString());
        } else {
            Map<String, Object> conversion = new HashMap<>();
            conversion.put(Constants.KEY_SENDER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
            conversion.put(Constants.KEY_SENDER_NAME, preferenceManager.getString(Constants.KEY_NAME));
            conversion.put(Constants.KEY_SENDER_IMAGE, preferenceManager.getString(Constants.KEY_IMAGE));

            conversion.put(Constants.KEY_RECEIVER_ID, user.getId());
            conversion.put(Constants.KEY_RECEIVER_NAME, user.getName());
            conversion.put(Constants.KEY_RECEIVER_IMAGE, user.getImage());
            conversion.put(Constants.KEY_LAST_MESSAGE, binding.inputMessage.getText().toString());
            conversion.put(Constants.KEY_TIMESTAMP, new Date());
            addConversion(conversion);
        }
        if (!isReceiverAvaible) {
            try {
                JSONArray tokens = new JSONArray();
                tokens.put(user.getToken());

                JSONObject data = new JSONObject();
                data.put(Constants.KEY_USER_ID, preferenceManager.getString(Constants.KEY_USER_ID));
                data.put(Constants.KEY_NAME, preferenceManager.getString(Constants.KEY_NAME));
                data.put(Constants.KEY_FCM_TOKEN, preferenceManager.getString(Constants.KEY_FCM_TOKEN));
                data.put(Constants.KEY_MESSAGE, binding.inputMessage.getText().toString());

                JSONObject body = new JSONObject();
                body.put(Constants.REMOTE_MSG_DATA, data);
                body.put(Constants.REMOTE_MSG_REGISTRATION_IDS, tokens);

                sendNotification(body.toString());

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        binding.inputMessage.setText(null);
    }

Now after this, you need to change the eventListener object. It will look like this:

private final EventListener<QuerySnapshot> eventListener = (value, error) -> {
        if (error != null) {
            return;
        }
        if (value != null) {
            int count = messages.size();
            for (DocumentChange documentChange : value.getDocumentChanges()) {
                if (documentChange.getType() == DocumentChange.Type.ADDED) {
                    ChatMessage chatMessage = new ChatMessage(
                            documentChange.getDocument().getString(Constants.KEY_SENDER_ID),
                            documentChange.getDocument().getString(Constants.KEY_RECEIVER_ID),
                            documentChange.getDocument().getString(Constants.KEY_MESSAGE),
                            getReadableDateTime(documentChange.getDocument().getDate(Constants.KEY_TIMESTAMP)),
                            documentChange.getDocument().getDate(Constants.KEY_TIMESTAMP)
                    );
                    if (documentChange.getDocument().getString(Constants.KEY_IMAGE_MESSAGE) != null && !documentChange.getDocument().getString(Constants.KEY_IMAGE_MESSAGE).isEmpty()) {
                        byte[] decodedString = Base64.decode((documentChange.getDocument().getString(Constants.KEY_IMAGE_MESSAGE, Base64.DEFAULT);
                        Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
                        chatMessage.setImage(decodedByte);
                    }
                    messages.add(chatMessage);
                }
            }
            Collections.sort(messages, Comparator.comparing(ChatMessage::getDate));
            if (count == 0) {
                chatAdapter.notifyDataSetChanged();
            } else {
                chatAdapter.notifyItemRangeInserted(messages.size(), messages.size());
                binding.chatRecyclerView.smoothScrollToPosition(messages.size() - 1);
            }
            binding.chatRecyclerView.setVisibility(View.VISIBLE);
        }
        binding.progressBar.setVisibility(View.GONE);
        if (conversionId == null) checkForConversion();
    };

2. Change the code to pick image for sending image

Now you are doing a very very wrong thing while trying to send an image method. This issue start's from the place where you are picking the image. To solve it, replace that with this code:

private final ActivityResultLauncher<Intent> pickImage = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
        if (result.getResultCode() != RESULT_OK) return;
        if (result.getData() == null) return;
        Uri imageUri = result.getData().getData();

        try {
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
            sendMessage(encodeImage(bitmap));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    });

Also you need to change the encodeImage method now!:

private String encodeImage(Bitmap bitmap) {
        int previewWidth = 300;
        int previewHeight = bitmap.getHeight() * previewWidth / bitmap.getWidth();
        Bitmap previewBitmap = Bitmap.createScaledBitmap(bitmap, previewWidth, previewHeight, false);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        previewBitmap.compress(Bitmap.CompressFormat.JPEG, 50, byteArrayOutputStream);
        String str = Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.DEFAULT);
        return str == null ? "" : str;
    }

Tada! This must work now. If not, pls inform me!

Source https://stackoverflow.com/questions/71590120

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install RoundedImageView

You can download it from GitHub, Maven.
You can use RoundedImageView like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the RoundedImageView component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Compare Computer Vision Libraries with Highest Support
Compare Computer Vision Libraries with Highest Security
Compare Computer Vision Libraries with Permissive License
Compare Computer Vision Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.