Text chat messages can be copied to clipboard using context menu
This commit is contained in:
parent
43c27b6bf3
commit
e03a2ee2e8
8 changed files with 59 additions and 5 deletions
|
@ -310,6 +310,8 @@
|
||||||
<string name="share_picture_size_large">Grande</string>
|
<string name="share_picture_size_large">Grande</string>
|
||||||
<string name="share_picture_size_real">Taille réelle</string>
|
<string name="share_picture_size_real">Taille réelle</string>
|
||||||
<string name="save_picture">Sauvegarder l\'image</string>
|
<string name="save_picture">Sauvegarder l\'image</string>
|
||||||
|
<string name="copy_text">Copier le texte</string>
|
||||||
|
<string name="text_copied_to_clipboard">Texte copié dans le presse papier</string>
|
||||||
<string name="image_picker_title">Choisissez la source</string>
|
<string name="image_picker_title">Choisissez la source</string>
|
||||||
<string name="image_saved">Image sauvegardée</string>
|
<string name="image_saved">Image sauvegardée</string>
|
||||||
<string name="image_not_saved">Erreur, image non sauvegardée</string>
|
<string name="image_not_saved">Erreur, image non sauvegardée</string>
|
||||||
|
|
|
@ -361,6 +361,8 @@
|
||||||
<string name="share_picture_size_large">Large</string>
|
<string name="share_picture_size_large">Large</string>
|
||||||
<string name="share_picture_size_real">Real size</string>
|
<string name="share_picture_size_real">Real size</string>
|
||||||
<string name="save_picture">Save picture</string>
|
<string name="save_picture">Save picture</string>
|
||||||
|
<string name="text_copied_to_clipboard">Text copied to clipboard</string>
|
||||||
|
<string name="copy_text">Copy text</string>
|
||||||
<string name="image_picker_title">Select source</string>
|
<string name="image_picker_title">Select source</string>
|
||||||
<string name="image_saved">Image saved</string>
|
<string name="image_saved">Image saved</string>
|
||||||
<string name="image_not_saved">Error, image not saved</string>
|
<string name="image_not_saved">Error, image not saved</string>
|
||||||
|
|
|
@ -33,6 +33,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.http.util.ByteArrayBuffer;
|
import org.apache.http.util.ByteArrayBuffer;
|
||||||
|
import org.linphone.compatibility.Compatibility;
|
||||||
import org.linphone.core.LinphoneAddress;
|
import org.linphone.core.LinphoneAddress;
|
||||||
import org.linphone.core.LinphoneChatMessage;
|
import org.linphone.core.LinphoneChatMessage;
|
||||||
import org.linphone.core.LinphoneChatMessage.State;
|
import org.linphone.core.LinphoneChatMessage.State;
|
||||||
|
@ -87,6 +88,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
private static final int MENU_PICTURE_MEDIUM = 3;
|
private static final int MENU_PICTURE_MEDIUM = 3;
|
||||||
private static final int MENU_PICTURE_LARGE = 4;
|
private static final int MENU_PICTURE_LARGE = 4;
|
||||||
private static final int MENU_PICTURE_REAL = 5;
|
private static final int MENU_PICTURE_REAL = 5;
|
||||||
|
private static final int MENU_COPY_TEXT = 6;
|
||||||
private static final int COMPRESSOR_QUALITY = 100;
|
private static final int COMPRESSOR_QUALITY = 100;
|
||||||
private static final int SIZE_SMALL = 500;
|
private static final int SIZE_SMALL = 500;
|
||||||
private static final int SIZE_MEDIUM = 1000;
|
private static final int SIZE_MEDIUM = 1000;
|
||||||
|
@ -309,6 +311,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
ImageView iv = (ImageView) v.findViewById(R.id.image);
|
ImageView iv = (ImageView) v.findViewById(R.id.image);
|
||||||
if (iv != null && iv.getVisibility() == View.VISIBLE) {
|
if (iv != null && iv.getVisibility() == View.VISIBLE) {
|
||||||
menu.add(v.getId(), MENU_SAVE_PICTURE, 0, getString(R.string.save_picture));
|
menu.add(v.getId(), MENU_SAVE_PICTURE, 0, getString(R.string.save_picture));
|
||||||
|
} else {
|
||||||
|
menu.add(v.getId(), MENU_COPY_TEXT, 0, getString(R.string.copy_text));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,6 +327,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
case MENU_SAVE_PICTURE:
|
case MENU_SAVE_PICTURE:
|
||||||
saveImage(item.getGroupId());
|
saveImage(item.getGroupId());
|
||||||
break;
|
break;
|
||||||
|
case MENU_COPY_TEXT:
|
||||||
|
copyText(item.getGroupId());
|
||||||
|
break;
|
||||||
case MENU_PICTURE_SMALL:
|
case MENU_PICTURE_SMALL:
|
||||||
uploadAndSendImage(fileToUploadPath, imageToUpload, ImageSize.SMALL);
|
uploadAndSendImage(fileToUploadPath, imageToUpload, ImageSize.SMALL);
|
||||||
break;
|
break;
|
||||||
|
@ -423,6 +430,14 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void copyText(int id) {
|
||||||
|
String msg = LinphoneActivity.instance().getChatStorage().getTextMessageForId(id);
|
||||||
|
if (msg != null) {
|
||||||
|
Compatibility.copyTextToClipboard(getActivity(), msg);
|
||||||
|
LinphoneActivity.instance().displayCustomToast(getString(R.string.text_copied_to_clipboard), Toast.LENGTH_SHORT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void onMessageReceived(int id, LinphoneAddress from, LinphoneChatMessage message) {
|
public void onMessageReceived(int id, LinphoneAddress from, LinphoneChatMessage message) {
|
||||||
if (from.asStringUriOnly().equals(sipUri)) {
|
if (from.asStringUriOnly().equals(sipUri)) {
|
||||||
|
|
|
@ -187,6 +187,22 @@ public class ChatStorage {
|
||||||
|
|
||||||
return chatMessages;
|
return chatMessages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTextMessageForId(int id) {
|
||||||
|
Cursor c = db.query(TABLE_NAME, null, "id LIKE " + id, null, null, null, null);
|
||||||
|
|
||||||
|
String message = null;
|
||||||
|
if (c.moveToFirst()) {
|
||||||
|
try {
|
||||||
|
message = c.getString(c.getColumnIndex("message"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.close();
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
public void removeDiscussion(String correspondent) {
|
public void removeDiscussion(String correspondent) {
|
||||||
db.delete(TABLE_NAME, "remoteContact LIKE \"" + correspondent + "\"", null);
|
db.delete(TABLE_NAME, "remoteContact LIKE \"" + correspondent + "\"", null);
|
||||||
|
|
|
@ -782,7 +782,7 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
displayMissedCalls(missedCalls);
|
displayMissedCalls(missedCalls);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayCustomToast(final String message, final int duration) {
|
public void displayCustomToast(final String message, final int duration) {
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
|
@ -5,6 +5,8 @@ import org.linphone.R;
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
import android.content.ClipData;
|
||||||
|
import android.content.ClipboardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
|
||||||
|
@ -80,4 +82,10 @@ public class ApiElevenPlus {
|
||||||
Context context, String title, String content, PendingIntent intent) {
|
Context context, String title, String content, PendingIntent intent) {
|
||||||
notif.setLatestEventInfo(context, title, content, intent);
|
notif.setLatestEventInfo(context, title, content, intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void copyTextToClipboard(Context context, String msg) {
|
||||||
|
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
ClipData clip = android.content.ClipData.newPlainText("Message", msg);
|
||||||
|
clipboard.setPrimaryClip(clip);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import android.provider.ContactsContract.CommonDataKinds.SipAddress;
|
||||||
import android.provider.ContactsContract.Contacts;
|
import android.provider.ContactsContract.Contacts;
|
||||||
import android.provider.ContactsContract.Data;
|
import android.provider.ContactsContract.Data;
|
||||||
import android.provider.ContactsContract.Intents.Insert;
|
import android.provider.ContactsContract.Intents.Insert;
|
||||||
|
import android.text.ClipboardManager;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -56,6 +57,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
/**
|
/**
|
||||||
* @author Sylvain Berfini
|
* @author Sylvain Berfini
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@TargetApi(5)
|
@TargetApi(5)
|
||||||
public class ApiFivePlus {
|
public class ApiFivePlus {
|
||||||
public static void overridePendingTransition(Activity activity, int idAnimIn, int idAnimOut) {
|
public static void overridePendingTransition(Activity activity, int idAnimIn, int idAnimOut) {
|
||||||
|
@ -309,12 +311,10 @@ public class ApiFivePlus {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public static int getRotation(Display display) {
|
public static int getRotation(Display display) {
|
||||||
return display.getOrientation();
|
return display.getOrientation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public static Notification createMessageNotification(Context context, String title, String msg, PendingIntent intent) {
|
public static Notification createMessageNotification(Context context, String title, String msg, PendingIntent intent) {
|
||||||
Notification notif = new Notification();
|
Notification notif = new Notification();
|
||||||
notif.icon = R.drawable.chat_icon_over;
|
notif.icon = R.drawable.chat_icon_over;
|
||||||
|
@ -331,7 +331,6 @@ public class ApiFivePlus {
|
||||||
return notif;
|
return notif;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public static Notification createInCallNotification(Context context,
|
public static Notification createInCallNotification(Context context,
|
||||||
String title, String msg, int iconID, PendingIntent intent) {
|
String title, String msg, int iconID, PendingIntent intent) {
|
||||||
Notification notif = new Notification();
|
Notification notif = new Notification();
|
||||||
|
@ -345,7 +344,6 @@ public class ApiFivePlus {
|
||||||
return notif;
|
return notif;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public static void setNotificationLatestEventInfo(Notification notif, Context context, String title, String content, PendingIntent intent) {
|
public static void setNotificationLatestEventInfo(Notification notif, Context context, String title, String content, PendingIntent intent) {
|
||||||
notif.setLatestEventInfo(context, title, content, intent);
|
notif.setLatestEventInfo(context, title, content, intent);
|
||||||
}
|
}
|
||||||
|
@ -357,4 +355,9 @@ public class ApiFivePlus {
|
||||||
public static boolean isPreferenceChecked(Preference preference) {
|
public static boolean isPreferenceChecked(Preference preference) {
|
||||||
return ((CheckBoxPreference) preference).isChecked();
|
return ((CheckBoxPreference) preference).isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void copyTextToClipboard(Context context, String msg) {
|
||||||
|
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
clipboard.setText(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,4 +201,12 @@ public class Compatibility {
|
||||||
ApiEightPlus.initPushNotificationService(context);
|
ApiEightPlus.initPushNotificationService(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void copyTextToClipboard(Context context, String msg) {
|
||||||
|
if(Version.sdkAboveOrEqual(11)) {
|
||||||
|
ApiElevenPlus.copyTextToClipboard(context, msg);
|
||||||
|
} else {
|
||||||
|
ApiFivePlus.copyTextToClipboard(context, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue