[FileSharing] fix download file + clean up
This commit is contained in:
parent
c13dcd0768
commit
acbf4de7df
8 changed files with 292 additions and 42 deletions
BIN
res/drawable-xhdpi/chat_attachment.png
Normal file
BIN
res/drawable-xhdpi/chat_attachment.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
|
@ -77,13 +77,53 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<ImageView
|
<RelativeLayout
|
||||||
android:id="@+id/image"
|
android:layout_width="wrap_content"
|
||||||
android:visibility="gone"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="150dp"
|
android:gravity="center"
|
||||||
android:layout_height="150dp"
|
android:layout_gravity="center">
|
||||||
android:scaleType="centerInside"/>
|
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/relativeLayoutCentered"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_gravity="center">
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/image"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:scaleType="centerInside"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:layout_marginBottom="12dp"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/file_extension"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:maxLines="1"
|
||||||
|
style="@style/font25"
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="FILE"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/file_name"
|
||||||
|
android:layout_below="@+id/relativeLayoutCentered"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:maxLines="1"
|
||||||
|
style="@style/font24"
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text=""/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/file_transfer_layout"
|
android:id="@+id/file_transfer_layout"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
|
|
|
@ -146,4 +146,15 @@
|
||||||
<item name="android:textStyle">italic</item>
|
<item name="android:textStyle">italic</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="font24" parent="@android:style/TextAppearance.Small">
|
||||||
|
<item name="android:textColor">@color/colorB</item>
|
||||||
|
<item name="android:textSize">13sp</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="font25" parent="@android:style/TextAppearance.Small">
|
||||||
|
<item name="android:textColor">@color/colorH</item>
|
||||||
|
<item name="android:textSize">21sp</item>
|
||||||
|
<item name="android:textStyle">bold</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
|
@ -893,7 +893,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
|
|
||||||
//File transfer
|
//File transfer
|
||||||
private void pickImage() {
|
private void pickImage() {
|
||||||
//TODO : update to use with any file types
|
|
||||||
List<Intent> cameraIntents = new ArrayList<Intent>();
|
List<Intent> cameraIntents = new ArrayList<Intent>();
|
||||||
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||||
File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis())));
|
File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis())));
|
||||||
|
@ -902,7 +901,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
cameraIntents.add(captureIntent);
|
cameraIntents.add(captureIntent);
|
||||||
|
|
||||||
Intent galleryIntent = new Intent();
|
Intent galleryIntent = new Intent();
|
||||||
//galleryIntent.setType("image/*");
|
|
||||||
galleryIntent.setType("*/*");
|
galleryIntent.setType("*/*");
|
||||||
galleryIntent.setAction(Intent.ACTION_PICK);
|
galleryIntent.setAction(Intent.ACTION_PICK);
|
||||||
|
|
||||||
|
@ -1048,9 +1046,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
@Override
|
@Override
|
||||||
protected byte[] doInBackground(File... params) {
|
protected byte[] doInBackground(File... params) {
|
||||||
File file = params[0];
|
File file = params[0];
|
||||||
//FileInputStream fileInputStream = null;
|
|
||||||
//ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
|
||||||
//String extension = LinphoneUtils.getExtensionFromFileName(path);
|
|
||||||
|
|
||||||
byte[] byteArray = new byte[(int) file.length()];
|
byte[] byteArray = new byte[(int) file.length()];
|
||||||
FileInputStream fis = null;
|
FileInputStream fis = null;
|
||||||
|
@ -1096,9 +1091,13 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
String fileToUploadPath = null;
|
String fileToUploadPath = null;
|
||||||
if (data != null && data.getData() != null) {
|
if (data != null && data.getData() != null) {
|
||||||
fileToUploadPath = getRealPathFromURI(data.getData());
|
fileToUploadPath = getRealPathFromURI(data.getData());
|
||||||
|
if(fileToUploadPath == null)
|
||||||
|
fileToUploadPath = data.getData().toString();
|
||||||
} else if (imageToUploadUri != null) {
|
} else if (imageToUploadUri != null) {
|
||||||
fileToUploadPath = imageToUploadUri.getPath();
|
fileToUploadPath = imageToUploadUri.getPath();
|
||||||
}
|
}
|
||||||
|
sendImageMessage(fileToUploadPath, 0);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
@ -1123,7 +1122,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
newChatConversation = false;
|
newChatConversation = false;
|
||||||
initChatRoom(sipUri);
|
initChatRoom(sipUri);
|
||||||
|
|
||||||
//TODO :
|
|
||||||
if(fileSharedUri != null){
|
if(fileSharedUri != null){
|
||||||
//save SipUri into bundle
|
//save SipUri into bundle
|
||||||
onSaveInstanceState(getArguments());
|
onSaveInstanceState(getArguments());
|
||||||
|
@ -1215,6 +1213,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
public LinearLayout imdmLayout;
|
public LinearLayout imdmLayout;
|
||||||
public ImageView imdmIcon;
|
public ImageView imdmIcon;
|
||||||
public TextView imdmLabel;
|
public TextView imdmLabel;
|
||||||
|
public TextView fileExtensionLabel;
|
||||||
|
public TextView fileNameLabel;
|
||||||
|
|
||||||
public ViewHolder(View view) {
|
public ViewHolder(View view) {
|
||||||
id = view.getId();
|
id = view.getId();
|
||||||
|
@ -1234,6 +1234,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
imdmLayout = (LinearLayout) view.findViewById(R.id.imdmLayout);
|
imdmLayout = (LinearLayout) view.findViewById(R.id.imdmLayout);
|
||||||
imdmIcon = (ImageView) view.findViewById(R.id.imdmIcon);
|
imdmIcon = (ImageView) view.findViewById(R.id.imdmIcon);
|
||||||
imdmLabel = (TextView) view.findViewById(R.id.imdmText);
|
imdmLabel = (TextView) view.findViewById(R.id.imdmText);
|
||||||
|
fileExtensionLabel = (TextView) view.findViewById(R.id.file_extension);
|
||||||
|
fileNameLabel = (TextView) view.findViewById(R.id.file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1356,6 +1358,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
holder.delete.setVisibility(View.GONE);
|
holder.delete.setVisibility(View.GONE);
|
||||||
holder.messageText.setVisibility(View.GONE);
|
holder.messageText.setVisibility(View.GONE);
|
||||||
holder.messageImage.setVisibility(View.GONE);
|
holder.messageImage.setVisibility(View.GONE);
|
||||||
|
holder.fileExtensionLabel.setVisibility(View.GONE);
|
||||||
|
holder.fileNameLabel.setVisibility(View.GONE);
|
||||||
holder.fileTransferLayout.setVisibility(View.GONE);
|
holder.fileTransferLayout.setVisibility(View.GONE);
|
||||||
holder.fileTransferProgressBar.setProgress(0);
|
holder.fileTransferProgressBar.setProgress(0);
|
||||||
holder.fileTransferAction.setEnabled(true);
|
holder.fileTransferAction.setEnabled(true);
|
||||||
|
@ -1415,9 +1419,14 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
holder.imdmLayout.setVisibility(View.INVISIBLE);
|
holder.imdmLayout.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (externalBodyUrl != null || fileTransferContent != null) {
|
if (externalBodyUrl != null || fileTransferContent != null) {
|
||||||
String appData = message.getAppData();
|
String appData = message.getAppData();
|
||||||
|
|
||||||
|
|
||||||
if (message.isOutgoing() && appData != null) {
|
if (message.isOutgoing() && appData != null) {
|
||||||
holder.messageImage.setVisibility(View.VISIBLE);
|
holder.messageImage.setVisibility(View.VISIBLE);
|
||||||
if (!sameMessage) {
|
if (!sameMessage) {
|
||||||
|
@ -1457,6 +1466,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
loadBitmap(appData, holder.messageImage);
|
loadBitmap(appData, holder.messageImage);
|
||||||
holder.messageImage.setTag(message.getAppData());
|
holder.messageImage.setTag(message.getAppData());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1494,10 +1504,10 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (context.getPackageManager().checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context.getPackageName()) == PackageManager.PERMISSION_GRANTED) {
|
if (context.getPackageManager().checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context.getPackageName()) == PackageManager.PERMISSION_GRANTED) {
|
||||||
v.setEnabled(false);
|
v.setEnabled(false);
|
||||||
String extension = message.getFileTransferInformation().getSubtype();
|
String filename = message.getFileTransferInformation().getName();
|
||||||
String filename = context.getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis())) + "." + extension;
|
String filename2 = context.getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis())) ; //+ "." + extension;
|
||||||
File file = new File(Environment.getExternalStorageDirectory(), filename);
|
File file = new File(Environment.getExternalStorageDirectory(), filename);
|
||||||
message.setAppData(filename);
|
message.setAppData(file.getPath());
|
||||||
LinphoneManager.getInstance().addDownloadMessagePending(message);
|
LinphoneManager.getInstance().addDownloadMessagePending(message);
|
||||||
message.setListener(LinphoneManager.getInstance());
|
message.setListener(LinphoneManager.getInstance());
|
||||||
message.setFileTransferFilepath(file.getPath());
|
message.setFileTransferFilepath(file.getPath());
|
||||||
|
@ -1536,6 +1546,51 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
holder.bubbleLayout.setLayoutParams(layoutParams);
|
holder.bubbleLayout.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
|
if(message.getAppData() != null && holder.fileTransferLayout.getVisibility() != View.VISIBLE){
|
||||||
|
if(LinphoneUtils.isExtensionImage(message.getAppData())){
|
||||||
|
holder.fileExtensionLabel.setVisibility(View.GONE);
|
||||||
|
holder.fileNameLabel.setVisibility(View.GONE);
|
||||||
|
}else {
|
||||||
|
String extension = (LinphoneUtils.getExtensionFromFileName(message.getAppData()));
|
||||||
|
if(extension != null)
|
||||||
|
extension = extension.toUpperCase();
|
||||||
|
else
|
||||||
|
extension = "FILE";
|
||||||
|
|
||||||
|
if (extension.length() > 4)
|
||||||
|
extension = extension.substring(0, 3);
|
||||||
|
|
||||||
|
//holder.messageImage.setImageResource(R.drawable.chat_attachment);
|
||||||
|
holder.fileExtensionLabel.setText(extension);
|
||||||
|
holder.fileExtensionLabel.setVisibility(View.VISIBLE);
|
||||||
|
//holder.fileExtensionLabel.setTag(message.getAppData());
|
||||||
|
holder.fileNameLabel.setText(LinphoneUtils.getNameFromFilePath(message.getAppData()));
|
||||||
|
holder.fileNameLabel.setVisibility(View.VISIBLE);
|
||||||
|
holder.fileExtensionLabel.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
|
File file = null;
|
||||||
|
Uri contentUri = null;
|
||||||
|
String imageUri = (String)holder.messageImage.getTag();
|
||||||
|
if (imageUri.startsWith("file://")) {
|
||||||
|
imageUri = imageUri.substring("file://".length());
|
||||||
|
file = new File(imageUri);
|
||||||
|
contentUri = FileProvider.getUriForFile(getActivity(), "org.linphone.provider", file);
|
||||||
|
} else if (imageUri.startsWith("content://")) {
|
||||||
|
contentUri = Uri.parse(imageUri);
|
||||||
|
} else {
|
||||||
|
file = new File(imageUri);
|
||||||
|
contentUri = FileProvider.getUriForFile(getActivity(), "org.linphone.provider", file);
|
||||||
|
}
|
||||||
|
intent.setDataAndType(contentUri, "*/*");
|
||||||
|
intent.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isEditMode) {
|
if (isEditMode) {
|
||||||
holder.delete.setVisibility(View.VISIBLE);
|
holder.delete.setVisibility(View.VISIBLE);
|
||||||
holder.delete.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
holder.delete.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@ -1635,7 +1690,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
if(LinphoneUtils.isExtensionImage(path))
|
if(LinphoneUtils.isExtensionImage(path))
|
||||||
defaultBitmap = BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.chat_picture_over);
|
defaultBitmap = BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.chat_picture_over);
|
||||||
else
|
else
|
||||||
defaultBitmap = BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.chat_attachment_over);
|
defaultBitmap = BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.chat_attachment);
|
||||||
|
|
||||||
BitmapWorkerTask task = new BitmapWorkerTask(imageView);
|
BitmapWorkerTask task = new BitmapWorkerTask(imageView);
|
||||||
final AsyncBitmap asyncBitmap = new AsyncBitmap(context.getResources(), defaultBitmap, task);
|
final AsyncBitmap asyncBitmap = new AsyncBitmap(context.getResources(), defaultBitmap, task);
|
||||||
|
@ -1660,7 +1715,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
path = params[0];
|
path = params[0];
|
||||||
Bitmap bm = null;
|
Bitmap bm = null;
|
||||||
Bitmap thumbnail = null;
|
Bitmap thumbnail = null;
|
||||||
|
|
||||||
if(LinphoneUtils.isExtensionImage(path)) {
|
if(LinphoneUtils.isExtensionImage(path)) {
|
||||||
if (path.startsWith("content")) {
|
if (path.startsWith("content")) {
|
||||||
try {
|
try {
|
||||||
|
@ -1723,17 +1777,17 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
|
File file = null;
|
||||||
Uri contentUri = null;
|
Uri contentUri = null;
|
||||||
String imageUri = (String)v.getTag();
|
String imageUri = (String)v.getTag();
|
||||||
if (imageUri.startsWith("file://")) {
|
if (imageUri.startsWith("file://")) {
|
||||||
imageUri = imageUri.substring("file://".length());
|
imageUri = imageUri.substring("file://".length());
|
||||||
File file = new File(imageUri);
|
file = new File(imageUri);
|
||||||
contentUri = FileProvider.getUriForFile(getActivity(), "org.linphone.provider", file);
|
contentUri = FileProvider.getUriForFile(getActivity(), "org.linphone.provider", file);
|
||||||
} else if (imageUri.startsWith("content://")) {
|
} else if (imageUri.startsWith("content://")) {
|
||||||
contentUri = Uri.parse(imageUri);
|
contentUri = Uri.parse(imageUri);
|
||||||
} else {
|
} else {
|
||||||
File file = new File(imageUri);
|
file = new File(imageUri);
|
||||||
contentUri = FileProvider.getUriForFile(getActivity(), "org.linphone.provider", file);
|
contentUri = FileProvider.getUriForFile(getActivity(), "org.linphone.provider", file);
|
||||||
}
|
}
|
||||||
intent.setDataAndType(contentUri, "*/*");
|
intent.setDataAndType(contentUri, "*/*");
|
||||||
|
|
|
@ -299,7 +299,6 @@ public class ContactsManager extends ContentObserver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.e(" =====>>>> ContacsManager - fetchContactsSync Ended");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long timeElapsed = (new Date()).getTime() - contactsTime.getTime();
|
long timeElapsed = (new Date()).getTime() - contactsTime.getTime();
|
||||||
|
|
|
@ -647,14 +647,12 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.e(" ===>>> displayChat : message = "+message+" - fileUri = "+fileUri);
|
|
||||||
String pictureUri = null;
|
String pictureUri = null;
|
||||||
String thumbnailUri = null;
|
String thumbnailUri = null;
|
||||||
String displayName = null;
|
String displayName = null;
|
||||||
|
|
||||||
LinphoneAddress lAddress = null;
|
LinphoneAddress lAddress = null;
|
||||||
if(sipUri != null) {
|
if(sipUri != null) {
|
||||||
Log.e(" ===>>> displayChat : sipUri = "+ sipUri);
|
|
||||||
try {
|
try {
|
||||||
lAddress = LinphoneManager.getLc().interpretUrl(sipUri);
|
lAddress = LinphoneManager.getLc().interpretUrl(sipUri);
|
||||||
} catch (LinphoneCoreException e) {
|
} catch (LinphoneCoreException e) {
|
||||||
|
@ -692,7 +690,6 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
changeCurrentFragment(FragmentsAvailable.CHAT, extras);
|
changeCurrentFragment(FragmentsAvailable.CHAT, extras);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e(" ===>>> displayChat : currentFragment != Chat");
|
|
||||||
if(isTablet()){
|
if(isTablet()){
|
||||||
changeCurrentFragment(FragmentsAvailable.CHAT_LIST, null);
|
changeCurrentFragment(FragmentsAvailable.CHAT_LIST, null);
|
||||||
//displayChat(sipUri, message, fileUri);
|
//displayChat(sipUri, message, fileUri);
|
||||||
|
@ -1326,7 +1323,6 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
} else {
|
} else {
|
||||||
if (!ContactsManager.getInstance().contactsFetchedOnce()) {
|
if (!ContactsManager.getInstance().contactsFetchedOnce()) {
|
||||||
ContactsManager.getInstance().enableContactsAccess();
|
ContactsManager.getInstance().enableContactsAccess();
|
||||||
Log.e(" ====>>>> LinphoneActivity - ContactsManager.getInstance().fetchContactsAsync() 2 !!!");
|
|
||||||
ContactsManager.getInstance().fetchContactsAsync();
|
ContactsManager.getInstance().fetchContactsAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,14 +19,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
package org.linphone;
|
package org.linphone;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.CursorLoader;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.database.Cursor;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.provider.MediaStore;
|
|
||||||
|
|
||||||
import org.linphone.assistant.RemoteProvisioningActivity;
|
import org.linphone.assistant.RemoteProvisioningActivity;
|
||||||
import org.linphone.mediastream.Log;
|
import org.linphone.mediastream.Log;
|
||||||
|
@ -127,9 +124,13 @@ public class LinphoneLauncherActivity extends Activity {
|
||||||
stringFileShared = intent.getStringExtra(Intent.EXTRA_STREAM);
|
stringFileShared = intent.getStringExtra(Intent.EXTRA_STREAM);
|
||||||
}else {
|
}else {
|
||||||
fileUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
fileUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||||
stringFileShared = getRealPathFromURI(fileUri);
|
stringFileShared = LinphoneUtils.getRealPathFromURI(getBaseContext(), fileUri);
|
||||||
if(stringFileShared == null)
|
if(stringFileShared == null)
|
||||||
stringFileShared = fileUri.getPath();
|
if(fileUri.getPath().contains("/0/1/mediakey:/local"))
|
||||||
|
stringFileShared = LinphoneUtils.getFilePath(getBaseContext(), fileUri);
|
||||||
|
else
|
||||||
|
stringFileShared = fileUri.getPath();
|
||||||
|
|
||||||
}
|
}
|
||||||
newIntent.putExtra("fileShared", stringFileShared);
|
newIntent.putExtra("fileShared", stringFileShared);
|
||||||
}
|
}
|
||||||
|
@ -160,18 +161,7 @@ public class LinphoneLauncherActivity extends Activity {
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRealPathFromURI(Uri contentUri) {
|
|
||||||
String[] proj = {MediaStore.Images.Media.DATA};
|
|
||||||
CursorLoader loader = new CursorLoader(this, contentUri, proj, null, null, null);
|
|
||||||
Cursor cursor = loader.loadInBackground();
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
|
||||||
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
|
||||||
String result = cursor.getString(column_index);
|
|
||||||
cursor.close();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ServiceWaitThread extends Thread {
|
private class ServiceWaitThread extends Thread {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
|
@ -23,8 +23,10 @@ import android.app.AlertDialog;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.CursorLoader;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.database.Cursor;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
@ -32,9 +34,11 @@ import android.net.NetworkInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.provider.MediaStore.Images;
|
import android.provider.MediaStore.Images;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -60,6 +64,8 @@ import org.linphone.mediastream.video.capture.hwconf.Hacks;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileDescriptor;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -73,6 +79,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
|
@ -472,6 +479,16 @@ public final class LinphoneUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getNameFromFilePath(String filePath) {
|
||||||
|
String name = filePath;
|
||||||
|
int i = filePath.lastIndexOf('/');
|
||||||
|
if (i > 0) {
|
||||||
|
name = filePath.substring(i+1);
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String getExtensionFromFileName(String fileName) {
|
public static String getExtensionFromFileName(String fileName) {
|
||||||
String extension = null;
|
String extension = null;
|
||||||
int i = fileName.lastIndexOf('.');
|
int i = fileName.lastIndexOf('.');
|
||||||
|
@ -713,5 +730,148 @@ public final class LinphoneUtils {
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************************************************************
|
||||||
|
* Picasa/Photos management workaround *
|
||||||
|
************************************************************************************************/
|
||||||
|
|
||||||
|
public static String getFilePath(final Context context, final Uri uri) {
|
||||||
|
|
||||||
|
// Google photo uri example
|
||||||
|
// content://com.google.android.apps.photos.contentprovider/0/1/mediakey%3A%2FAF1QipMObgoK_wDY66gu0QkMAi/ORIGINAL/NONE/114919
|
||||||
|
|
||||||
|
if ("content".equalsIgnoreCase(uri.getScheme())) {
|
||||||
|
String result = getDataColumn(context, uri, null, null); //
|
||||||
|
if (TextUtils.isEmpty(result))
|
||||||
|
if (uri.getAuthority().contains("com.google.android")) {
|
||||||
|
try {
|
||||||
|
File localFile = createImageFile(context, null);
|
||||||
|
FileInputStream remoteFile = getSourceStream(context, uri);
|
||||||
|
if(copyToFile(remoteFile, localFile))
|
||||||
|
result = localFile.getAbsolutePath();
|
||||||
|
remoteFile.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
// File
|
||||||
|
else if ("file".equalsIgnoreCase(uri.getScheme())) {
|
||||||
|
return uri.getPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy data from a source stream to destFile.
|
||||||
|
* Return true if succeed, return false if failed.
|
||||||
|
*/
|
||||||
|
private static boolean copyToFile(InputStream inputStream, File destFile) {
|
||||||
|
if (inputStream == null || destFile == null) return false;
|
||||||
|
try {
|
||||||
|
OutputStream out = new FileOutputStream(destFile);
|
||||||
|
try {
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = inputStream.read(buffer)) >= 0) {
|
||||||
|
out.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTimestamp() {
|
||||||
|
try {
|
||||||
|
return new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.ROOT).format(new Date());
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
return new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File createImageFile(Context context, String imageFileName) throws IOException {
|
||||||
|
if (TextUtils.isEmpty(imageFileName))
|
||||||
|
imageFileName = getTimestamp()+".JPEG"; // make random filename if you want.
|
||||||
|
|
||||||
|
final File root;
|
||||||
|
imageFileName = imageFileName;
|
||||||
|
root = context.getExternalCacheDir();
|
||||||
|
|
||||||
|
if (root != null && !root.exists())
|
||||||
|
root.mkdirs();
|
||||||
|
return new File(root, imageFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static FileInputStream getSourceStream(Context context, Uri u) throws FileNotFoundException {
|
||||||
|
FileInputStream out = null;
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
|
ParcelFileDescriptor parcelFileDescriptor =
|
||||||
|
context.getContentResolver().openFileDescriptor(u, "r");
|
||||||
|
FileDescriptor fileDescriptor = null;
|
||||||
|
if (parcelFileDescriptor != null) {
|
||||||
|
fileDescriptor = parcelFileDescriptor.getFileDescriptor();
|
||||||
|
out = new FileInputStream(fileDescriptor);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out = (FileInputStream) context.getContentResolver().openInputStream(u);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of the data column for this Uri. This is useful for
|
||||||
|
* MediaStore Uris, and other file-based ContentProviders.
|
||||||
|
*
|
||||||
|
* @param context The context.
|
||||||
|
* @param uri The Uri to query.
|
||||||
|
* @param selection (Optional) Filter used in the query.
|
||||||
|
* @param selectionArgs (Optional) Selection arguments used in the query.
|
||||||
|
* @return The value of the _data column, which is typically a file path.
|
||||||
|
*/
|
||||||
|
static String getDataColumn(Context context, Uri uri, String selection,
|
||||||
|
String[] selectionArgs) {
|
||||||
|
|
||||||
|
Cursor cursor = null;
|
||||||
|
final String column = "_data";
|
||||||
|
final String[] projection = {
|
||||||
|
column
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
|
||||||
|
null);
|
||||||
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
final int column_index = cursor.getColumnIndexOrThrow(column);
|
||||||
|
return cursor.getString(column_index);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (cursor != null)
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getRealPathFromURI(Context context, Uri contentUri) {
|
||||||
|
String[] proj = {MediaStore.Images.Media.DATA};
|
||||||
|
CursorLoader loader = new CursorLoader(context, contentUri, proj, null, null, null);
|
||||||
|
Cursor cursor = loader.loadInBackground();
|
||||||
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
||||||
|
String result = cursor.getString(column_index);
|
||||||
|
cursor.close();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue