Search in sources :

Example 1 with LocationInfo

use of com.applozic.mobicommons.commons.core.utils.LocationInfo in project Applozic-Android-SDK by AppLozic.

the class AlAttachmentOptions method handleAttachmentOptionsResult.

public static void handleAttachmentOptionsResult(int requestCode, int resultCode, Intent intent, Activity activity, String userId, Integer groupId) {
    try {
        MessageBuilder messageBuilder = new MessageBuilder(activity);
        if (groupId == null && userId != null) {
            messageBuilder.setTo(userId);
        } else if (userId == null && groupId != null) {
            messageBuilder.setGroupId(groupId);
        }
        if ((requestCode == REQUEST_CODE_ATTACH_PHOTO || requestCode == REQUEST_CODE_TAKE_PHOTO) && resultCode == Activity.RESULT_OK) {
            Uri selectedFileUri = (intent == null ? null : intent.getData());
            if (selectedFileUri == null) {
                selectedFileUri = bundle.getParcelable("imageUri");
                String selectedFilePath = bundle.getString("imagePath");
                if (selectedFilePath != null) {
                    messageBuilder.setFilePath(bundle.getString("imagePath")).setContentType(Message.ContentType.ATTACHMENT.getValue()).send();
                    bundle = null;
                }
            }
            String absoluteFilePath = getFilePath(selectedFileUri, activity);
            MediaScannerConnection.scanFile(activity, new String[] { absoluteFilePath }, null, new MediaScannerConnection.OnScanCompletedListener() {

                public void onScanCompleted(String path, Uri uri) {
                }
            });
        }
        if (requestCode == REQUEST_CODE_CONTACT_GROUP_SELECTION && resultCode == Activity.RESULT_OK) {
        // checkForStartNewConversation(intent);
        }
        if (requestCode == REQUEST_CODE_CAPTURE_VIDEO_ACTIVITY && resultCode == Activity.RESULT_OK) {
            String selectedFilePath = bundle.getString("videoPath");
            if (selectedFilePath != null) {
                messageBuilder.setFilePath(bundle.getString("videoPath")).setContentType(Message.ContentType.VIDEO_MSG.getValue()).send();
                bundle = null;
            }
        }
        if (requestCode == REQUEST_MULTI_ATTCAHMENT && resultCode == Activity.RESULT_OK) {
            ArrayList<Uri> attachmentList = intent.getParcelableArrayListExtra(MULTISELECT_SELECTED_FILES);
            String messageText = intent.getStringExtra(MULTISELECT_MESSAGE);
            for (Uri info : attachmentList) {
                messageBuilder.setFilePath(info.toString()).setMessage(messageText).setContentType(Message.ContentType.ATTACHMENT.getValue()).send();
            }
        }
        if (requestCode == MultimediaOptionFragment.REQUEST_CODE_SEND_LOCATION && resultCode == Activity.RESULT_OK) {
            Double latitude = intent.getDoubleExtra("latitude", 0);
            Double longitude = intent.getDoubleExtra("longitude", 0);
            // TODO: put your location(lat/lon ) in constructor.
            LocationInfo info = new LocationInfo(latitude, longitude);
            String locationInfo = GsonUtils.getJsonFromObject(info, LocationInfo.class);
            messageBuilder.setMessage(locationInfo).setContentType(Message.ContentType.LOCATION.getValue()).send();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MessageBuilder(com.applozic.mobicomkit.api.conversation.MessageBuilder) MediaScannerConnection(android.media.MediaScannerConnection) Uri(android.net.Uri) LocationInfo(com.applozic.mobicommons.commons.core.utils.LocationInfo)

Example 2 with LocationInfo

use of com.applozic.mobicommons.commons.core.utils.LocationInfo in project Applozic-Android-SDK by AppLozic.

the class ConversationUIService method onActivityResult.

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    try {
        if ((requestCode == MultimediaOptionFragment.REQUEST_CODE_ATTACH_PHOTO || requestCode == MultimediaOptionFragment.REQUEST_CODE_TAKE_PHOTO) && resultCode == Activity.RESULT_OK) {
            Uri selectedFileUri = (intent == null ? null : intent.getData());
            File file = null;
            if (selectedFileUri == null) {
                file = ((ConversationActivity) fragmentActivity).getFileObject();
                selectedFileUri = ((ConversationActivity) fragmentActivity).getCapturedImageUri();
            }
            if (selectedFileUri != null) {
                selectedFileUri = ((ConversationActivity) fragmentActivity).getCapturedImageUri();
                file = ((ConversationActivity) fragmentActivity).getFileObject();
            }
            MediaScannerConnection.scanFile(fragmentActivity, new String[] { file.getAbsolutePath() }, null, new MediaScannerConnection.OnScanCompletedListener() {

                public void onScanCompleted(String path, Uri uri) {
                }
            });
            if (getConversationFragment() != null) {
                getConversationFragment().loadFileAndSendMessage(selectedFileUri, file, Message.ContentType.ATTACHMENT.getValue());
            }
            Utils.printLog(fragmentActivity, TAG, "File uri: " + selectedFileUri);
        }
        if (requestCode == REQUEST_CODE_CONTACT_GROUP_SELECTION && resultCode == Activity.RESULT_OK) {
            checkForStartNewConversation(intent);
        }
        if (requestCode == MultimediaOptionFragment.REQUEST_CODE_CAPTURE_VIDEO_ACTIVITY && resultCode == Activity.RESULT_OK) {
            Uri selectedFilePath = ((ConversationActivity) fragmentActivity).getVideoFileUri();
            File file = ((ConversationActivity) fragmentActivity).getFileObject();
            if (!(file != null && file.exists())) {
                FileUtils.getLastModifiedFile(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera/").renameTo(file);
            }
            if (selectedFilePath != null && getConversationFragment() != null) {
                getConversationFragment().loadFileAndSendMessage(selectedFilePath, file, Message.ContentType.VIDEO_MSG.getValue());
            }
        }
        if (requestCode == MultimediaOptionFragment.REQUEST_MULTI_ATTCAHMENT && resultCode == Activity.RESULT_OK) {
            ArrayList<Uri> attachmentList = intent.getParcelableArrayListExtra(MobiComAttachmentSelectorActivity.MULTISELECT_SELECTED_FILES);
            String messageText = intent.getStringExtra(MobiComAttachmentSelectorActivity.MULTISELECT_MESSAGE);
            // TODO: check performance, we might need to put in each posting in separate thread.
            List<String> filePaths = new ArrayList<>();
            if (getConversationFragment() != null) {
                for (Uri info : attachmentList) {
                    filePaths.add(info.getPath());
                }
                getConversationFragment().sendMessage(messageText, Message.ContentType.ATTACHMENT.getValue(), filePaths);
            }
        }
        if (requestCode == MultimediaOptionFragment.REQUEST_CODE_SEND_LOCATION && resultCode == Activity.RESULT_OK) {
            Double latitude = intent.getDoubleExtra("latitude", 0);
            Double longitude = intent.getDoubleExtra("longitude", 0);
            // TODO: put your location(lat/lon ) in constructor.
            LocationInfo info = new LocationInfo(latitude, longitude);
            String locationInfo = GsonUtils.getJsonFromObject(info, LocationInfo.class);
            sendLocation(locationInfo);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ConversationActivity(com.applozic.mobicomkit.uiwidgets.conversation.activity.ConversationActivity) MediaScannerConnection(android.media.MediaScannerConnection) ArrayList(java.util.ArrayList) Uri(android.net.Uri) File(java.io.File) LocationInfo(com.applozic.mobicommons.commons.core.utils.LocationInfo)

Aggregations

MediaScannerConnection (android.media.MediaScannerConnection)2 Uri (android.net.Uri)2 LocationInfo (com.applozic.mobicommons.commons.core.utils.LocationInfo)2 MessageBuilder (com.applozic.mobicomkit.api.conversation.MessageBuilder)1 ConversationActivity (com.applozic.mobicomkit.uiwidgets.conversation.activity.ConversationActivity)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1