Add chat view landscape
This commit is contained in:
parent
e04a5eaaf4
commit
95ae7734a4
10 changed files with 461 additions and 438 deletions
|
@ -108,6 +108,15 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name="org.linphone.ChatActivity"
|
||||||
|
android:theme="@style/NoTitle"
|
||||||
|
android:windowSoftInputMode="adjustPan|adjustResize"
|
||||||
|
android:launchMode="singleTask">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
<activity android:name="org.linphone.setup.SetupActivity"
|
<activity android:name="org.linphone.setup.SetupActivity"
|
||||||
android:theme="@style/NoTitle"
|
android:theme="@style/NoTitle"
|
||||||
android:screenOrientation="nosensor">
|
android:screenOrientation="nosensor">
|
||||||
|
|
BIN
res/drawable-xhdpi/chat_back_default.9.png
Normal file
BIN
res/drawable-xhdpi/chat_back_default.9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
res/drawable-xhdpi/chat_back_over.9.png
Normal file
BIN
res/drawable-xhdpi/chat_back_over.9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
8
res/drawable/chat_back.xml
Normal file
8
res/drawable/chat_back.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:state_pressed="true"
|
||||||
|
android:drawable="@drawable/chat_back_over" />
|
||||||
|
<item
|
||||||
|
android:drawable="@drawable/chat_back_default" />
|
||||||
|
</selector>
|
||||||
|
|
|
@ -3,8 +3,45 @@
|
||||||
xmlns:linphone="http://schemas.android.com/apk/res-auto"
|
xmlns:linphone="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:id="@+id/top_layout"
|
||||||
android:background="@drawable/background" >
|
android:background="@drawable/background" >
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:id="@+id/topbar">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:contentDescription="@string/content_description_back"
|
||||||
|
android:id="@+id/back"
|
||||||
|
android:background="@drawable/chat_back"
|
||||||
|
android:text="@string/button_back"
|
||||||
|
android:gravity="center"
|
||||||
|
android:paddingTop="20dp"
|
||||||
|
android:textColor="@drawable/text_button"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
|
android:layout_weight="1"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:contentDescription="@string/content_description_mark"
|
||||||
|
android:id="@+id/mark"
|
||||||
|
android:background="@drawable/toolsbar_background"
|
||||||
|
android:gravity="center"
|
||||||
|
android:enabled="false"
|
||||||
|
android:paddingTop="20dp"
|
||||||
|
android:textColor="@drawable/text_button"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
|
android:layout_weight="1"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/header"
|
android:id="@+id/header"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -14,7 +51,7 @@
|
||||||
android:paddingRight="10dp"
|
android:paddingRight="10dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_alignParentTop="true"
|
android:layout_below="@+id/topbar"
|
||||||
android:layout_centerHorizontal="true">
|
android:layout_centerHorizontal="true">
|
||||||
|
|
||||||
<org.linphone.ui.AvatarWithShadow
|
<org.linphone.ui.AvatarWithShadow
|
||||||
|
@ -30,7 +67,6 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
android:textColor="@color/text_contrast" />
|
android:textColor="@color/text_contrast" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -74,6 +110,7 @@
|
||||||
android:paddingLeft="10dp" />
|
android:paddingLeft="10dp" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
|
android:imeOptions="flagNoExtractUi"
|
||||||
android:textCursorDrawable="@null"
|
android:textCursorDrawable="@null"
|
||||||
android:id="@+id/message"
|
android:id="@+id/message"
|
||||||
android:inputType="textMultiLine"
|
android:inputType="textMultiLine"
|
||||||
|
|
|
@ -301,6 +301,7 @@
|
||||||
<string name="button_edit">Modifier</string>
|
<string name="button_edit">Modifier</string>
|
||||||
<string name="button_cancel">Annuler</string>
|
<string name="button_cancel">Annuler</string>
|
||||||
<string name="button_ok">Valider</string>
|
<string name="button_ok">Valider</string>
|
||||||
|
<string name="button_back">Retour</string>
|
||||||
<string name="button_all_contacts">Tous</string>
|
<string name="button_all_contacts">Tous</string>
|
||||||
<string name="button_sip_contacts">SIP</string>
|
<string name="button_sip_contacts">SIP</string>
|
||||||
<string name="button_add_contact">+ Contact</string>
|
<string name="button_add_contact">+ Contact</string>
|
||||||
|
|
|
@ -303,6 +303,7 @@
|
||||||
<string name="button_edit">Edit</string>
|
<string name="button_edit">Edit</string>
|
||||||
<string name="button_cancel">Cancel</string>
|
<string name="button_cancel">Cancel</string>
|
||||||
<string name="button_ok">Okay</string>
|
<string name="button_ok">Okay</string>
|
||||||
|
<string name="button_back">Back</string>
|
||||||
<string name="button_all_contacts">All</string>
|
<string name="button_all_contacts">All</string>
|
||||||
<string name="button_sip_contacts">SIP</string>
|
<string name="button_sip_contacts">SIP</string>
|
||||||
<string name="button_add_contact">New contact</string>
|
<string name="button_add_contact">New contact</string>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.linphone;
|
package org.linphone;
|
||||||
/*
|
/*
|
||||||
ChatFragment.java
|
ChatActivity.java
|
||||||
Copyright (C) 2012 Belledonne Communications, Grenoble, France
|
Copyright (C) 2015 Belledonne Communications, Grenoble, France
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
|
@ -17,6 +17,56 @@ You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Matrix;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.media.ExifInterface;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Environment;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
import android.provider.MediaStore;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.support.v4.content.CursorLoader;
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.text.InputType;
|
||||||
|
import android.text.TextWatcher;
|
||||||
|
import android.view.ContextMenu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.widget.BaseAdapter;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.apache.http.util.ByteArrayBuffer;
|
||||||
|
import org.linphone.compatibility.Compatibility;
|
||||||
|
import org.linphone.core.LinphoneAddress;
|
||||||
|
import org.linphone.core.LinphoneChatMessage;
|
||||||
|
import org.linphone.core.LinphoneChatRoom;
|
||||||
|
import org.linphone.core.LinphoneCore;
|
||||||
|
import org.linphone.mediastream.Log;
|
||||||
|
import org.linphone.ui.AvatarWithShadow;
|
||||||
|
import org.linphone.ui.BubbleChat;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
|
@ -32,62 +82,16 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.http.util.ByteArrayBuffer;
|
import org.linphone.core.LinphoneChatMessage.StateListener;
|
||||||
import org.linphone.compatibility.Compatibility;
|
|
||||||
import org.linphone.core.LinphoneAddress;
|
|
||||||
import org.linphone.core.LinphoneChatMessage;
|
|
||||||
import org.linphone.core.LinphoneChatMessage.State;
|
|
||||||
import org.linphone.core.LinphoneChatRoom;
|
|
||||||
import org.linphone.core.LinphoneCore;
|
|
||||||
import org.linphone.core.LinphoneCoreListener.LinphoneComposingListener;
|
import org.linphone.core.LinphoneCoreListener.LinphoneComposingListener;
|
||||||
import org.linphone.mediastream.Log;
|
import org.linphone.core.LinphoneCoreListener.LinphoneMessageListener;
|
||||||
import org.linphone.ui.AvatarWithShadow;
|
|
||||||
import org.linphone.ui.BubbleChat;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Bitmap.CompressFormat;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Matrix;
|
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.media.ExifInterface;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Environment;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.provider.MediaStore;
|
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
import android.support.v4.content.CursorLoader;
|
|
||||||
import android.text.Editable;
|
|
||||||
import android.text.InputType;
|
|
||||||
import android.text.TextWatcher;
|
|
||||||
import android.view.ContextMenu;
|
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
|
||||||
import android.view.inputmethod.InputMethodManager;
|
|
||||||
import android.widget.BaseAdapter;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.ProgressBar;
|
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Sylvain Berfini
|
* @author Margaux Clerc
|
||||||
*/
|
*/
|
||||||
public class ChatFragment extends Fragment implements OnClickListener, LinphoneChatMessage.StateListener, LinphoneComposingListener {
|
public class ChatActivity extends FragmentActivity implements OnClickListener, LinphoneMessageListener, StateListener, LinphoneComposingListener {
|
||||||
|
private static ChatActivity instance;
|
||||||
|
|
||||||
private static final int ADD_PHOTO = 1337;
|
private static final int ADD_PHOTO = 1337;
|
||||||
private static final int MENU_DELETE_MESSAGE = 0;
|
private static final int MENU_DELETE_MESSAGE = 0;
|
||||||
private static final int MENU_SAVE_PICTURE = 1;
|
private static final int MENU_SAVE_PICTURE = 1;
|
||||||
|
@ -103,16 +107,17 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
private static final int SIZE_LARGE = 1500;
|
private static final int SIZE_LARGE = 1500;
|
||||||
|
|
||||||
private LinphoneChatRoom chatRoom;
|
private LinphoneChatRoom chatRoom;
|
||||||
private View view;
|
|
||||||
private String sipUri;
|
private String sipUri;
|
||||||
|
private String displayName;
|
||||||
|
private String pictureUri;
|
||||||
private EditText message;
|
private EditText message;
|
||||||
private ImageView cancelUpload;
|
private ImageView cancelUpload;
|
||||||
private TextView sendImage, sendMessage, contactName, remoteComposing;
|
private LinearLayout topBar;
|
||||||
|
private TextView sendImage, sendMessage, contactName, remoteComposing, back;
|
||||||
private AvatarWithShadow contactPicture;
|
private AvatarWithShadow contactPicture;
|
||||||
private RelativeLayout uploadLayout, textLayout;
|
private RelativeLayout uploadLayout, textLayout;
|
||||||
private List<BubbleChat> lastSentMessagesBubbles;
|
private List<BubbleChat> lastSentMessagesBubbles;
|
||||||
private HashMap<Integer, String> latestImageMessages;
|
private HashMap<Integer, String> latestImageMessages;
|
||||||
private boolean useLinphoneMessageStorage;
|
|
||||||
private ListView messagesList;
|
private ListView messagesList;
|
||||||
private Handler mHandler = new Handler();
|
private Handler mHandler = new Handler();
|
||||||
|
|
||||||
|
@ -124,45 +129,56 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
private Uri imageToUploadUri;
|
private Uri imageToUploadUri;
|
||||||
private Thread uploadThread;
|
private Thread uploadThread;
|
||||||
private TextWatcher textWatcher;
|
private TextWatcher textWatcher;
|
||||||
private OnGlobalLayoutListener keyboardListener;
|
private ViewTreeObserver.OnGlobalLayoutListener keyboardListener;
|
||||||
private ChatMessageAdapter adapter;
|
private ChatMessageAdapter adapter;
|
||||||
|
|
||||||
|
public static boolean isInstanciated() {
|
||||||
|
return instance != null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
sipUri = getArguments().getString("SipUri");
|
super.onCreate(savedInstanceState);
|
||||||
String displayName = getArguments().getString("DisplayName");
|
instance = this;
|
||||||
String pictureUri = getArguments().getString("PictureUri");
|
setContentView(R.layout.chat);
|
||||||
|
|
||||||
view = inflater.inflate(R.layout.chat, container, false);
|
//Retrieve parameter from intent
|
||||||
|
sipUri = getIntent().getStringExtra("SipUri");
|
||||||
|
displayName = getIntent().getStringExtra("DisplayName");
|
||||||
|
pictureUri = getIntent().getStringExtra("PictureUri");
|
||||||
|
|
||||||
useLinphoneMessageStorage = getResources().getBoolean(R.bool.use_linphone_chat_storage);
|
uploadServerUri = LinphonePreferences.instance().getSharingPictureServerUrl();
|
||||||
|
|
||||||
contactName = (TextView) view.findViewById(R.id.contactName);
|
//Initialize UI
|
||||||
contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);
|
contactName = (TextView) findViewById(R.id.contactName);
|
||||||
|
contactPicture = (AvatarWithShadow) findViewById(R.id.contactPicture);
|
||||||
|
messagesList = (ListView) findViewById(R.id.chatMessageList);
|
||||||
|
textLayout = (RelativeLayout) findViewById(R.id.messageLayout);
|
||||||
|
progressBar = (ProgressBar) findViewById(R.id.progressbar);
|
||||||
|
topBar = (LinearLayout) findViewById(R.id.topbar);
|
||||||
|
|
||||||
sendMessage = (TextView) view.findViewById(R.id.sendMessage);
|
sendMessage = (TextView) findViewById(R.id.sendMessage);
|
||||||
sendMessage.setOnClickListener(this);
|
sendMessage.setOnClickListener(this);
|
||||||
|
|
||||||
remoteComposing = (TextView) view.findViewById(R.id.remoteComposing);
|
remoteComposing = (TextView) findViewById(R.id.remoteComposing);
|
||||||
remoteComposing.setVisibility(View.GONE);
|
remoteComposing.setVisibility(View.GONE);
|
||||||
|
|
||||||
messagesList = (ListView) view.findViewById(R.id.chatMessageList);
|
uploadLayout = (RelativeLayout) findViewById(R.id.uploadLayout);
|
||||||
|
uploadLayout.setVisibility(View.GONE);
|
||||||
|
|
||||||
message = (EditText) view.findViewById(R.id.message);
|
displayChatHeader(displayName, pictureUri);
|
||||||
if (!getActivity().getResources().getBoolean(R.bool.allow_chat_multiline)) {
|
|
||||||
|
//Manage multiline
|
||||||
|
message = (EditText) findViewById(R.id.message);
|
||||||
|
if (!getApplicationContext().getResources().getBoolean(R.bool.allow_chat_multiline)) {
|
||||||
message.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
|
message.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
|
||||||
message.setMaxLines(1);
|
message.setMaxLines(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadLayout = (RelativeLayout) view.findViewById(R.id.uploadLayout);
|
sendImage = (TextView) findViewById(R.id.sendPicture);
|
||||||
uploadLayout.setVisibility(View.GONE);
|
|
||||||
textLayout = (RelativeLayout) view.findViewById(R.id.messageLayout);
|
|
||||||
|
|
||||||
progressBar = (ProgressBar) view.findViewById(R.id.progressbar);
|
|
||||||
sendImage = (TextView) view.findViewById(R.id.sendPicture);
|
|
||||||
if (!getResources().getBoolean(R.bool.disable_chat_send_file)) {
|
if (!getResources().getBoolean(R.bool.disable_chat_send_file)) {
|
||||||
registerForContextMenu(sendImage);
|
registerForContextMenu(sendImage);
|
||||||
sendImage.setOnClickListener(new OnClickListener() {
|
sendImage.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
pickImage();
|
pickImage();
|
||||||
|
@ -172,14 +188,24 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
sendImage.setEnabled(false);
|
sendImage.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
cancelUpload = (ImageView) view.findViewById(R.id.cancelUpload);
|
back = (TextView) findViewById(R.id.back);
|
||||||
cancelUpload.setOnClickListener(new OnClickListener() {
|
back.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
cancelUpload = (ImageView) findViewById(R.id.cancelUpload);
|
||||||
|
cancelUpload.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
uploadThread.interrupt();
|
uploadThread.interrupt();
|
||||||
uploadLayout.setVisibility(View.GONE);
|
uploadLayout.setVisibility(View.GONE);
|
||||||
textLayout.setVisibility(View.VISIBLE);
|
textLayout.setVisibility(View.VISIBLE);
|
||||||
progressBar.setProgress(0);
|
progressBar.setProgress(0);
|
||||||
|
fileToUploadPath = null;
|
||||||
|
imageToUpload = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -190,21 +216,12 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
chatRoom.markAsRead();
|
chatRoom.markAsRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
displayChatHeader(displayName, pictureUri);
|
|
||||||
|
|
||||||
uploadServerUri = LinphonePreferences.instance().getSharingPictureServerUrl();
|
|
||||||
|
|
||||||
textWatcher = new TextWatcher() {
|
textWatcher = new TextWatcher() {
|
||||||
public void afterTextChanged(Editable arg0) {
|
public void afterTextChanged(Editable arg0) {}
|
||||||
|
|
||||||
}
|
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}
|
||||||
|
|
||||||
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
|
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
|
|
||||||
{
|
|
||||||
if (message.getText().toString().equals("")) {
|
if (message.getText().toString().equals("")) {
|
||||||
sendMessage.setEnabled(false);
|
sendMessage.setEnabled(false);
|
||||||
} else {
|
} else {
|
||||||
|
@ -216,12 +233,11 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
};
|
};
|
||||||
|
|
||||||
// Force hide keyboard
|
// Force hide keyboard
|
||||||
if (LinphoneActivity.isInstanciated()) {
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
|
||||||
InputMethodManager imm = (InputMethodManager) LinphoneActivity.instance().getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
||||||
imm.hideSoftInputFromWindow(view.getWindowToken(),0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Workaround for SGS3 issue
|
// Workaround for SGS3 issue
|
||||||
|
imageToUpload = getIntent().getParcelableExtra("imageToUpload");
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
fileToUploadPath = savedInstanceState.getString("fileToUploadPath");
|
fileToUploadPath = savedInstanceState.getString("fileToUploadPath");
|
||||||
imageToUpload = savedInstanceState.getParcelable("imageToUpload");
|
imageToUpload = savedInstanceState.getParcelable("imageToUpload");
|
||||||
|
@ -234,8 +250,10 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return view;
|
public static ChatActivity instance() {
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -243,17 +261,18 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
outState.putString("fileToUploadPath", fileToUploadPath);
|
outState.putString("fileToUploadPath", fileToUploadPath);
|
||||||
outState.putParcelable("imageToUpload", imageToUpload);
|
outState.putParcelable("imageToUpload", imageToUpload);
|
||||||
outState.putString("messageDraft", message.getText().toString());
|
outState.putString("messageDraft", message.getText().toString());
|
||||||
|
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addVirtualKeyboardVisiblityListener() {
|
private void addVirtualKeyboardVisiblityListener() {
|
||||||
keyboardListener = new OnGlobalLayoutListener() {
|
keyboardListener = new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onGlobalLayout() {
|
public void onGlobalLayout() {
|
||||||
Rect visibleArea = new Rect();
|
Rect visibleArea = new Rect();
|
||||||
view.getWindowVisibleDisplayFrame(visibleArea);
|
getWindow().getDecorView().getWindowVisibleDisplayFrame(visibleArea);
|
||||||
|
|
||||||
int heightDiff = view.getRootView().getHeight() - (visibleArea.bottom - visibleArea.top);
|
int heightDiff = getWindow().getDecorView().getRootView().getHeight() - (visibleArea.bottom - visibleArea.top);
|
||||||
if (heightDiff > 200) {
|
if (heightDiff > 200) {
|
||||||
showKeyboardVisibleMode();
|
showKeyboardVisibleMode();
|
||||||
} else {
|
} else {
|
||||||
|
@ -261,23 +280,29 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
view.getViewTreeObserver().addOnGlobalLayoutListener(keyboardListener);
|
getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(keyboardListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeVirtualKeyboardVisiblityListener() {
|
private void removeVirtualKeyboardVisiblityListener() {
|
||||||
Compatibility.removeGlobalLayoutListener(view.getViewTreeObserver(), keyboardListener);
|
Compatibility.removeGlobalLayoutListener(getWindow().getDecorView().getViewTreeObserver(), keyboardListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showKeyboardVisibleMode() {
|
public void showKeyboardVisibleMode() {
|
||||||
LinphoneActivity.instance().hideMenu(true);
|
boolean isOrientationLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
|
||||||
|
if (isOrientationLandscape) {
|
||||||
|
topBar.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
contactPicture.setVisibility(View.GONE);
|
contactPicture.setVisibility(View.GONE);
|
||||||
scrollToEnd();
|
scrollToEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideKeyboardVisibleMode() {
|
public void hideKeyboardVisibleMode() {
|
||||||
LinphoneActivity.instance().hideMenu(false);
|
boolean isOrientationLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
|
||||||
contactPicture.setVisibility(View.VISIBLE);
|
contactPicture.setVisibility(View.VISIBLE);
|
||||||
//scrollToEnd();
|
if (isOrientationLandscape) {
|
||||||
|
topBar.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
scrollToEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
class ChatMessageAdapter extends BaseAdapter {
|
class ChatMessageAdapter extends BaseAdapter {
|
||||||
|
@ -318,7 +343,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
bubble = displayImageMessage(msg.getStorageId(), null, msg.getTime(), !msg.isOutgoing(), msg.getStatus(), context, msg.getExternalBodyUrl());
|
bubble = displayImageMessage(msg.getStorageId(), null, msg.getTime(), !msg.isOutgoing(), msg.getStatus(), context, msg.getExternalBodyUrl());
|
||||||
} else {
|
} else {
|
||||||
bubble = displayMessage(msg.getStorageId(), msg.getText(), msg.getTime(), !msg.isOutgoing(), msg.getStatus(), context);
|
bubble = displayMessage(msg.getStorageId(), msg.getText(), msg.getTime(), !msg.isOutgoing(), msg.getStatus(), context);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v = bubble.getView();
|
v = bubble.getView();
|
||||||
|
@ -332,12 +356,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public View getBubble(int position){
|
|
||||||
return messagesList.getChildAt(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dispayMessageList() {
|
public void dispayMessageList() {
|
||||||
adapter = new ChatMessageAdapter(this.getActivity(), chatRoom.getHistory());
|
adapter = new ChatMessageAdapter(this, chatRoom.getHistory());
|
||||||
messagesList.setAdapter(adapter);
|
messagesList.setAdapter(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,7 +371,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pictureUri != null) {
|
if (pictureUri != null) {
|
||||||
LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture.getView(), Uri.parse(pictureUri), R.drawable.unknown_small);
|
LinphoneUtils.setImagePictureFromUri(this, contactPicture.getView(), Uri.parse(pictureUri), R.drawable.unknown_small);
|
||||||
} else {
|
} else {
|
||||||
contactPicture.setImageResource(R.drawable.unknown_small);
|
contactPicture.setImageResource(R.drawable.unknown_small);
|
||||||
}
|
}
|
||||||
|
@ -380,7 +400,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
|
|
||||||
if (url.startsWith("http")) { // Download
|
if (url.startsWith("http")) { // Download
|
||||||
bubble.setShowOrDownloadText(getString(R.string.download_image));
|
bubble.setShowOrDownloadText(getString(R.string.download_image));
|
||||||
bubble.setShowOrDownloadImageButtonListener(new OnClickListener() {
|
bubble.setShowOrDownloadImageButtonListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
v.findViewById(R.id.spinner).setVisibility(View.VISIBLE);
|
v.findViewById(R.id.spinner).setVisibility(View.VISIBLE);
|
||||||
|
@ -389,15 +409,11 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final Bitmap bm = ChatFragment.downloadImage(url);
|
final Bitmap bm = ChatActivity.instance().downloadImage(url);
|
||||||
if (bm != null) {
|
if (bm != null) {
|
||||||
if (useLinphoneMessageStorage) {
|
|
||||||
String newFileUrl = saveImage(bm, finalId, getMessageForId(finalId));
|
String newFileUrl = saveImage(bm, finalId, getMessageForId(finalId));
|
||||||
bubble.updateUrl(newFileUrl);
|
bubble.updateUrl(newFileUrl);
|
||||||
adapter.refreshHistory();
|
adapter.refreshHistory();
|
||||||
} else {
|
|
||||||
LinphoneActivity.instance().getChatStorage().saveImage(finalId, bm);
|
|
||||||
}
|
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -426,7 +442,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
v.findViewById(R.id.image).setVisibility(View.VISIBLE);
|
v.findViewById(R.id.image).setVisibility(View.VISIBLE);
|
||||||
v.findViewById(R.id.download).setVisibility(View.GONE);
|
v.findViewById(R.id.download).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bubble;
|
return bubble;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,7 +470,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||||
if (v.getId() == R.id.sendPicture) {
|
if (v.getId() == R.id.sendPicture) {
|
||||||
menu.add(0, MENU_PICTURE_SMALL, 0, getString(R.string.share_picture_size_small));
|
menu.add(0, MENU_PICTURE_SMALL, 0, getString(R.string.share_picture_size_small));
|
||||||
menu.add(0, MENU_PICTURE_MEDIUM, 0, getString(R.string.share_picture_size_medium));
|
menu.add(0, MENU_PICTURE_MEDIUM, 0, getString(R.string.share_picture_size_medium));
|
||||||
|
@ -465,13 +480,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
} else {
|
} else {
|
||||||
menu.add(v.getId(), MENU_DELETE_MESSAGE, 0, getString(R.string.delete));
|
menu.add(v.getId(), MENU_DELETE_MESSAGE, 0, getString(R.string.delete));
|
||||||
ImageView iv = (ImageView) v.findViewById(R.id.image);
|
ImageView iv = (ImageView) v.findViewById(R.id.image);
|
||||||
if (iv != null && iv.getVisibility() == View.VISIBLE) {
|
|
||||||
if (!useLinphoneMessageStorage) {
|
|
||||||
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));
|
menu.add(v.getId(), MENU_COPY_TEXT, 0, getString(R.string.copy_text));
|
||||||
}
|
|
||||||
|
|
||||||
LinphoneChatMessage msg = getMessageForId(v.getId());
|
LinphoneChatMessage msg = getMessageForId(v.getId());
|
||||||
if (msg != null && msg.getStatus() == LinphoneChatMessage.State.NotDelivered) {
|
if (msg != null && msg.getStatus() == LinphoneChatMessage.State.NotDelivered) {
|
||||||
|
@ -525,9 +534,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
lc.removeListener(this);
|
lc.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getIntent().putExtra("MessageDraft", message.getText());
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
onSaveInstanceState(getArguments());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("UseSparseArrays")
|
@SuppressLint("UseSparseArrays")
|
||||||
|
@ -545,15 +553,13 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LinphoneActivity.isInstanciated()) {
|
if (LinphoneActivity.isInstanciated()) {
|
||||||
LinphoneActivity.instance().selectMenu(FragmentsAvailable.CHAT);
|
|
||||||
LinphoneActivity.instance().updateChatFragment(this);
|
|
||||||
|
|
||||||
if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) {
|
if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) {
|
||||||
LinphoneActivity.instance().hideStatusBar();
|
LinphoneActivity.instance().hideStatusBar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String draft = getArguments().getString("messageDraft");
|
String draft = getIntent().getStringExtra("messageDraft");
|
||||||
message.setText(draft);
|
message.setText(draft);
|
||||||
|
|
||||||
remoteComposing.setVisibility(chatRoom.isRemoteComposing() ? View.VISIBLE : View.GONE);
|
remoteComposing.setVisibility(chatRoom.isRemoteComposing() ? View.VISIBLE : View.GONE);
|
||||||
|
@ -613,13 +619,14 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
newId = chatMessage.getStorageId();
|
newId = chatMessage.getStorageId();
|
||||||
latestImageMessages.put(newId, url);
|
latestImageMessages.put(newId, url);
|
||||||
|
|
||||||
if (useLinphoneMessageStorage)
|
|
||||||
url = saveImage(bitmap, newId, chatMessage);
|
url = saveImage(bitmap, newId, chatMessage);
|
||||||
|
|
||||||
adapter.refreshHistory();
|
adapter.refreshHistory();
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
|
|
||||||
scrollToEnd();
|
scrollToEnd();
|
||||||
|
imageToUpload = null;
|
||||||
|
fileToUploadPath = null;
|
||||||
} else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
|
} else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
|
||||||
LinphoneActivity.instance().displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
|
LinphoneActivity.instance().displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
|
||||||
}
|
}
|
||||||
|
@ -638,7 +645,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -670,12 +676,14 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
private void copyTextMessageToClipboard(int id) {
|
private void copyTextMessageToClipboard(int id) {
|
||||||
String msg = LinphoneActivity.instance().getChatStorage().getTextMessageForId(chatRoom, id);
|
String msg = LinphoneActivity.instance().getChatStorage().getTextMessageForId(chatRoom, id);
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
Compatibility.copyTextToClipboard(getActivity(), msg);
|
Compatibility.copyTextToClipboard(this, msg);
|
||||||
LinphoneActivity.instance().displayCustomToast(getString(R.string.text_copied_to_clipboard), Toast.LENGTH_SHORT);
|
LinphoneActivity.instance().displayCustomToast(getString(R.string.text_copied_to_clipboard), Toast.LENGTH_SHORT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onMessageReceived(LinphoneAddress from, final LinphoneChatMessage message) {
|
@Override
|
||||||
|
public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
|
||||||
|
LinphoneAddress from = cr.getPeerAddress();
|
||||||
if (from.asStringUriOnly().equals(sipUri)) {
|
if (from.asStringUriOnly().equals(sipUri)) {
|
||||||
if (message.getText() != null) {
|
if (message.getText() != null) {
|
||||||
adapter.refreshHistory();
|
adapter.refreshHistory();
|
||||||
|
@ -689,11 +697,11 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void onLinphoneChatMessageStateChanged(LinphoneChatMessage msg, State state) {
|
public synchronized void onLinphoneChatMessageStateChanged(LinphoneChatMessage msg, LinphoneChatMessage.State state) {
|
||||||
final LinphoneChatMessage finalMessage = msg;
|
final LinphoneChatMessage finalMessage = msg;
|
||||||
final String finalImage = finalMessage.getExternalBodyUrl();
|
final String finalImage = finalMessage.getExternalBodyUrl();
|
||||||
final State finalState=state;
|
final LinphoneChatMessage.State finalState = state;
|
||||||
if (LinphoneActivity.isInstanciated() && state != State.InProgress) {
|
if (LinphoneActivity.isInstanciated() && state != LinphoneChatMessage.State.InProgress) {
|
||||||
if (finalMessage != null && !finalMessage.equals("")) {
|
if (finalMessage != null && !finalMessage.equals("")) {
|
||||||
LinphoneActivity.instance().onMessageStateChanged(sipUri, finalMessage.getText(), finalState.toInt());
|
LinphoneActivity.instance().onMessageStateChanged(sipUri, finalMessage.getText(), finalState.toInt());
|
||||||
} else if (finalImage != null && !finalImage.equals("")) {
|
} else if (finalImage != null && !finalImage.equals("")) {
|
||||||
|
@ -774,9 +782,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
byte[] rawImage = LinphoneActivity.instance().getChatStorage().getRawImageFromMessage(id);
|
byte[] rawImage = LinphoneActivity.instance().getChatStorage().getRawImageFromMessage(id);
|
||||||
Bitmap bm = BitmapFactory.decodeByteArray(rawImage, 0, rawImage.length);
|
Bitmap bm = BitmapFactory.decodeByteArray(rawImage, 0, rawImage.length);
|
||||||
if (saveImage(bm, id, null) != null) {
|
if (saveImage(bm, id, null) != null) {
|
||||||
Toast.makeText(getActivity(), getString(R.string.image_saved), Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, getString(R.string.image_saved), Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(getActivity(), getString(R.string.image_not_saved), Toast.LENGTH_LONG).show();
|
Toast.makeText(this, getString(R.string.image_not_saved), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -798,8 +806,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
bm.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
|
bm.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
|
||||||
fOut.flush();
|
fOut.flush();
|
||||||
fOut.close();
|
fOut.close();
|
||||||
|
|
||||||
if (useLinphoneMessageStorage) {
|
|
||||||
//Update url path in liblinphone database
|
//Update url path in liblinphone database
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
LinphoneChatMessage[] history = chatRoom.getHistory();
|
LinphoneChatMessage[] history = chatRoom.getHistory();
|
||||||
|
@ -812,9 +818,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
message.setExternalBodyUrl(path + filename);
|
message.setExternalBodyUrl(path + filename);
|
||||||
chatRoom.updateUrl(message);
|
chatRoom.updateUrl(message);
|
||||||
}
|
|
||||||
|
|
||||||
MediaStore.Images.Media.insertImage(getActivity().getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
|
MediaStore.Images.Media.insertImage(getContentResolver(), file.getAbsolutePath(), file.getName(), file.getName());
|
||||||
return file.getAbsolutePath();
|
return file.getAbsolutePath();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -878,7 +883,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
dos.writeBytes("Content-Type: application/octet-stream" + lineEnd);
|
dos.writeBytes("Content-Type: application/octet-stream" + lineEnd);
|
||||||
dos.writeBytes(lineEnd);
|
dos.writeBytes(lineEnd);
|
||||||
|
|
||||||
file.compress(CompressFormat.JPEG, compressorQuality, dos);
|
file.compress(Bitmap.CompressFormat.JPEG, compressorQuality, dos);
|
||||||
|
|
||||||
dos.writeBytes(lineEnd);
|
dos.writeBytes(lineEnd);
|
||||||
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
|
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
|
||||||
|
@ -912,7 +917,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
|
|
||||||
public String getRealPathFromURI(Uri contentUri) {
|
public String getRealPathFromURI(Uri contentUri) {
|
||||||
String[] proj = {MediaStore.Images.Media.DATA};
|
String[] proj = {MediaStore.Images.Media.DATA};
|
||||||
CursorLoader loader = new CursorLoader(getActivity(), contentUri, proj, null, null, null);
|
CursorLoader loader = new CursorLoader(this, contentUri, proj, null, null, null);
|
||||||
Cursor cursor = loader.loadInBackground();
|
Cursor cursor = loader.loadInBackground();
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
||||||
|
@ -928,7 +933,10 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
imageToUpload = image;
|
imageToUpload = image;
|
||||||
try {
|
try {
|
||||||
sendImage.showContextMenu();
|
sendImage.showContextMenu();
|
||||||
} catch (Exception e) { e.printStackTrace(); };
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uploadAndSendImage(final String filePath, final Bitmap image, final ImageSize size) {
|
private void uploadAndSendImage(final String filePath, final Bitmap image, final ImageSize size) {
|
||||||
|
@ -978,7 +986,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
|
|
||||||
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
||||||
if (bm != null) {
|
if (bm != null) {
|
||||||
bm.compress(CompressFormat.JPEG, COMPRESSOR_QUALITY, outStream);
|
bm.compress(Bitmap.CompressFormat.JPEG, COMPRESSOR_QUALITY, outStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!uploadThread.isInterrupted() && bm != null) {
|
if (!uploadThread.isInterrupted() && bm != null) {
|
||||||
|
@ -999,7 +1007,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
if (furl != null) {
|
if (furl != null) {
|
||||||
sendImageMessage(furl, fbm);
|
sendImageMessage(furl, fbm);
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(getActivity(), getString(R.string.error), Toast.LENGTH_LONG).show();
|
Toast.makeText(ChatActivity.instance(), getString(R.string.error), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1015,16 +1023,13 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
if (data != null && data.getExtras() != null && data.getExtras().get("data") != null) {
|
if (data != null && data.getExtras() != null && data.getExtras().get("data") != null) {
|
||||||
Bitmap bm = (Bitmap) data.getExtras().get("data");
|
Bitmap bm = (Bitmap) data.getExtras().get("data");
|
||||||
showPopupMenuAskingImageSize(null, bm);
|
showPopupMenuAskingImageSize(null, bm);
|
||||||
}
|
} else if (data != null && data.getData() != null) {
|
||||||
else if (data != null && data.getData() != null) {
|
|
||||||
String filePath = getRealPathFromURI(data.getData());
|
String filePath = getRealPathFromURI(data.getData());
|
||||||
showPopupMenuAskingImageSize(filePath, null);
|
showPopupMenuAskingImageSize(filePath, null);
|
||||||
}
|
} else if (imageToUploadUri != null) {
|
||||||
else if (imageToUploadUri != null) {
|
|
||||||
String filePath = imageToUploadUri.getPath();
|
String filePath = imageToUploadUri.getPath();
|
||||||
showPopupMenuAskingImageSize(filePath, null);
|
showPopupMenuAskingImageSize(filePath, null);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name));
|
File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name));
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
imageToUploadUri = Uri.fromFile(file);
|
imageToUploadUri = Uri.fromFile(file);
|
||||||
|
@ -1080,3 +1085,4 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,12 +33,7 @@ public enum FragmentsAvailable {
|
||||||
ABOUT_INSTEAD_OF_CHAT,
|
ABOUT_INSTEAD_OF_CHAT,
|
||||||
ACCOUNT_SETTINGS,
|
ACCOUNT_SETTINGS,
|
||||||
SETTINGS,
|
SETTINGS,
|
||||||
CHATLIST,
|
CHATLIST;
|
||||||
CHAT;
|
|
||||||
|
|
||||||
public boolean shouldAddToBackStack() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean shouldAnimate() {
|
public boolean shouldAnimate() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -68,9 +63,6 @@ public enum FragmentsAvailable {
|
||||||
case CHATLIST:
|
case CHATLIST:
|
||||||
return DIALER.isRightOf(fragment) || fragment == DIALER;
|
return DIALER.isRightOf(fragment) || fragment == DIALER;
|
||||||
|
|
||||||
case CHAT:
|
|
||||||
return CHATLIST.isRightOf(fragment) || fragment == CHATLIST;
|
|
||||||
|
|
||||||
case ABOUT_INSTEAD_OF_SETTINGS:
|
case ABOUT_INSTEAD_OF_SETTINGS:
|
||||||
case SETTINGS:
|
case SETTINGS:
|
||||||
return CHATLIST.isRightOf(fragment) || fragment == CHATLIST || fragment == FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT;
|
return CHATLIST.isRightOf(fragment) || fragment == CHATLIST || fragment == FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT;
|
||||||
|
@ -95,9 +87,6 @@ public enum FragmentsAvailable {
|
||||||
case EDIT_CONTACT:
|
case EDIT_CONTACT:
|
||||||
return fragment == CONTACT || fragment == CONTACTS;
|
return fragment == CONTACT || fragment == CONTACTS;
|
||||||
|
|
||||||
case CHAT:
|
|
||||||
return fragment == CHATLIST;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,7 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
private static final int FIRST_LOGIN_ACTIVITY = 101;
|
private static final int FIRST_LOGIN_ACTIVITY = 101;
|
||||||
private static final int REMOTE_PROVISIONING_LOGIN_ACTIVITY = 102;
|
private static final int REMOTE_PROVISIONING_LOGIN_ACTIVITY = 102;
|
||||||
private static final int CALL_ACTIVITY = 19;
|
private static final int CALL_ACTIVITY = 19;
|
||||||
|
private static final int CHAT_ACTIVITY = 21;
|
||||||
|
|
||||||
private static LinphoneActivity instance;
|
private static LinphoneActivity instance;
|
||||||
|
|
||||||
|
@ -104,7 +105,7 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
private RelativeLayout contacts, history, settings, chat, aboutChat, aboutSettings;
|
private RelativeLayout contacts, history, settings, chat, aboutChat, aboutSettings;
|
||||||
private FragmentsAvailable currentFragment, nextFragment;
|
private FragmentsAvailable currentFragment, nextFragment;
|
||||||
private List<FragmentsAvailable> fragmentsHistory;
|
private List<FragmentsAvailable> fragmentsHistory;
|
||||||
private Fragment dialerFragment, messageListenerFragment, messageListFragment, friendStatusListenerFragment;
|
private Fragment dialerFragment, messageListFragment, friendStatusListenerFragment;
|
||||||
private SavedState dialerSavedState;
|
private SavedState dialerSavedState;
|
||||||
private boolean preferLinphoneContacts = false, isAnimationDisabled = false, isContactPresenceDisabled = true;
|
private boolean preferLinphoneContacts = false, isAnimationDisabled = false, isContactPresenceDisabled = true;
|
||||||
private List<Contact> contactList, sipContactList;
|
private List<Contact> contactList, sipContactList;
|
||||||
|
@ -262,7 +263,7 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
|
|
||||||
@SuppressWarnings("incomplete-switch")
|
@SuppressWarnings("incomplete-switch")
|
||||||
private void changeCurrentFragment(FragmentsAvailable newFragmentType, Bundle extras, boolean withoutAnimation) {
|
private void changeCurrentFragment(FragmentsAvailable newFragmentType, Bundle extras, boolean withoutAnimation) {
|
||||||
if (newFragmentType == currentFragment && newFragmentType != FragmentsAvailable.CHAT) {
|
if (newFragmentType == currentFragment) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nextFragment = newFragmentType;
|
nextFragment = newFragmentType;
|
||||||
|
@ -324,10 +325,6 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
case ABOUT_INSTEAD_OF_SETTINGS:
|
case ABOUT_INSTEAD_OF_SETTINGS:
|
||||||
newFragment = new AboutFragment();
|
newFragment = new AboutFragment();
|
||||||
break;
|
break;
|
||||||
case CHAT:
|
|
||||||
newFragment = new ChatFragment();
|
|
||||||
messageListenerFragment = newFragment;
|
|
||||||
break;
|
|
||||||
case CHATLIST:
|
case CHATLIST:
|
||||||
newFragment = new ChatListFragment();
|
newFragment = new ChatListFragment();
|
||||||
messageListFragment = new Fragment();
|
messageListFragment = new Fragment();
|
||||||
|
@ -378,20 +375,12 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newFragmentType != FragmentsAvailable.DIALER
|
||||||
if (newFragmentType == FragmentsAvailable.DIALER
|
|| newFragmentType != FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT
|
||||||
|| newFragmentType == FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT
|
|| newFragmentType != FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS
|
||||||
|| newFragmentType == FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS
|
|| newFragmentType != FragmentsAvailable.CONTACTS
|
||||||
|| newFragmentType == FragmentsAvailable.SETTINGS
|
|| newFragmentType != FragmentsAvailable.CHATLIST
|
||||||
|| newFragmentType == FragmentsAvailable.CONTACTS
|
|| newFragmentType != FragmentsAvailable.HISTORY) {
|
||||||
|| newFragmentType == FragmentsAvailable.CHATLIST
|
|
||||||
|| newFragmentType == FragmentsAvailable.HISTORY) {
|
|
||||||
try {
|
|
||||||
getSupportFragmentManager().popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
|
||||||
} catch (java.lang.IllegalStateException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
transaction.addToBackStack(newFragmentType.toString());
|
transaction.addToBackStack(newFragmentType.toString());
|
||||||
}
|
}
|
||||||
transaction.replace(R.id.fragmentContainer, newFragment, newFragmentType.toString());
|
transaction.replace(R.id.fragmentContainer, newFragment, newFragmentType.toString());
|
||||||
|
@ -568,24 +557,15 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
String displayName = lAddress.getDisplayName();
|
String displayName = lAddress.getDisplayName();
|
||||||
String pictureUri = uri == null ? null : uri.toString();
|
String pictureUri = uri == null ? null : uri.toString();
|
||||||
|
|
||||||
if (currentFragment == FragmentsAvailable.CHATLIST || currentFragment == FragmentsAvailable.CHAT) {
|
Intent intent = new Intent(this, ChatActivity.class);
|
||||||
Fragment fragment2 = getSupportFragmentManager().findFragmentById(R.id.fragmentContainer2);
|
intent.putExtra("SipUri", sipUri);
|
||||||
if (fragment2 != null && fragment2.isVisible() && currentFragment == FragmentsAvailable.CHAT) {
|
|
||||||
ChatFragment chatFragment = (ChatFragment) fragment2;
|
|
||||||
chatFragment.changeDisplayedChat(sipUri, displayName, pictureUri);
|
|
||||||
} else {
|
|
||||||
Bundle extras = new Bundle();
|
|
||||||
extras.putString("SipUri", sipUri);
|
|
||||||
if (lAddress.getDisplayName() != null) {
|
if (lAddress.getDisplayName() != null) {
|
||||||
extras.putString("DisplayName", displayName);
|
intent.putExtra("DisplayName", displayName);
|
||||||
extras.putString("PictureUri", pictureUri);
|
intent.putExtra("PictureUri", pictureUri);
|
||||||
}
|
|
||||||
changeCurrentFragment(FragmentsAvailable.CHAT, extras);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
changeCurrentFragment(FragmentsAvailable.CHATLIST, null);
|
|
||||||
displayChat(sipUri);
|
|
||||||
}
|
}
|
||||||
|
startOrientationSensor();
|
||||||
|
startActivityForResult(intent, CHAT_ACTIVITY);
|
||||||
|
|
||||||
LinphoneService.instance().resetMessageNotifCount();
|
LinphoneService.instance().resetMessageNotifCount();
|
||||||
LinphoneService.instance().removeMessageNotification();
|
LinphoneService.instance().removeMessageNotification();
|
||||||
displayMissedChats(getChatStorage().getUnreadMessageCount());
|
displayMissedChats(getChatStorage().getUnreadMessageCount());
|
||||||
|
@ -664,7 +644,6 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
case ABOUT_INSTEAD_OF_SETTINGS:
|
case ABOUT_INSTEAD_OF_SETTINGS:
|
||||||
aboutSettings.setSelected(true);
|
aboutSettings.setSelected(true);
|
||||||
break;
|
break;
|
||||||
case CHAT:
|
|
||||||
case CHATLIST:
|
case CHATLIST:
|
||||||
chat.setSelected(true);
|
chat.setSelected(true);
|
||||||
break;
|
break;
|
||||||
|
@ -677,12 +656,6 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateChatFragment(ChatFragment fragment) {
|
|
||||||
messageListenerFragment = fragment;
|
|
||||||
// Hack to maintain soft input flags
|
|
||||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateChatListFragment(ChatListFragment fragment) {
|
public void updateChatListFragment(ChatListFragment fragment) {
|
||||||
messageListFragment = fragment;
|
messageListFragment = fragment;
|
||||||
}
|
}
|
||||||
|
@ -740,17 +713,11 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
|
public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
|
||||||
LinphoneAddress from = cr.getPeerAddress();
|
|
||||||
ChatFragment chatFragment = ((ChatFragment) messageListenerFragment);
|
|
||||||
if (messageListenerFragment != null && messageListenerFragment.isVisible() && chatFragment.getSipUri().equals(from.asStringUriOnly())) {
|
|
||||||
chatFragment.onMessageReceived(from, message);
|
|
||||||
} else if (LinphoneService.isReady()) {
|
|
||||||
displayMissedChats(getChatStorage().getUnreadMessageCount());
|
displayMissedChats(getChatStorage().getUnreadMessageCount());
|
||||||
if (messageListFragment != null && messageListFragment.isVisible()) {
|
if (messageListFragment != null && messageListFragment.isVisible()) {
|
||||||
((ChatListFragment) messageListFragment).refresh();
|
((ChatListFragment) messageListFragment).refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void updateMissedChatCount() {
|
public void updateMissedChatCount() {
|
||||||
displayMissedChats(getChatStorage().getUnreadMessageCount());
|
displayMissedChats(getChatStorage().getUnreadMessageCount());
|
||||||
|
@ -1374,7 +1341,12 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
|
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
if (currentFragment == FragmentsAvailable.DIALER) {
|
if (currentFragment == FragmentsAvailable.DIALER
|
||||||
|
|| currentFragment == FragmentsAvailable.CONTACTS
|
||||||
|
|| currentFragment == FragmentsAvailable.HISTORY
|
||||||
|
|| currentFragment == FragmentsAvailable.CHATLIST
|
||||||
|
|| currentFragment == FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT
|
||||||
|
|| currentFragment == FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS) {
|
||||||
boolean isBackgroundModeActive = LinphonePreferences.instance().isBackgroundModeEnabled();
|
boolean isBackgroundModeActive = LinphonePreferences.instance().isBackgroundModeEnabled();
|
||||||
if (!isBackgroundModeActive) {
|
if (!isBackgroundModeActive) {
|
||||||
stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class));
|
stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class));
|
||||||
|
|
Loading…
Reference in a new issue