Added context menu for history log, chat threads and chat messages

This commit is contained in:
Sylvain Berfini 2012-07-17 15:24:29 +02:00
parent 9751e6a842
commit 0807e6c5cd
12 changed files with 96 additions and 11 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -2,6 +2,8 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" <item android:state_pressed="true"
android:drawable="@drawable/chat_send_message_over" /> android:drawable="@drawable/chat_send_message_over" />
<item android:state_enabled="false"
android:drawable="@drawable/chat_send_message_disabled" />
<item <item
android:drawable="@drawable/chat_send_message_default" /> android:drawable="@drawable/chat_send_message_default" />
</selector> </selector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View file

@ -3,7 +3,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/background" android:background="@drawable/background"
android:orientation="vertical" > android:orientation="vertical">
<org.linphone.ui.AddressText <org.linphone.ui.AddressText
android:id="@+id/Adress" android:id="@+id/Adress"
@ -19,7 +19,7 @@
android:layout_gravity="center" /> android:layout_gravity="center" />
<org.linphone.ui.Numpad <org.linphone.ui.Numpad
android:id="@+id/Dialer" android:id="@+id/Dialer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="0.15" /> android:layout_weight="0.15" />

View file

@ -254,6 +254,7 @@
<string name="pref_help_username">Example: john if your account is john@sip.linphone.org</string> <string name="pref_help_username">Example: john if your account is john@sip.linphone.org</string>
<string name="pref_help_domain">sip.linphone.org if your account is john@sip.linphone.org</string> <string name="pref_help_domain">sip.linphone.org if your account is john@sip.linphone.org</string>
<string name="delete">Delete</string>
<string name="chat">Chat</string> <string name="chat">Chat</string>
<string name="add_to_contacts">Add to contacts</string> <string name="add_to_contacts">Add to contacts</string>
<string name="status_connected">CONNECTED</string> <string name="status_connected">CONNECTED</string>

View file

@ -29,7 +29,10 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -102,6 +105,18 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO
return view; return view;
} }
private void invalidate() {
messagesLayout.removeAllViews();
List<ChatMessage> messagesList = LinphoneActivity.instance().getChatMessages(sipUri);
previousMessageID = -1;
for (ChatMessage msg : messagesList) {
displayMessage(msg.getId(), msg.getMessage(), msg.getTimestamp(), msg.isIncoming(), messagesLayout);
}
scrollToEnd();
}
private void displayMessage(final int id, final String message, final String time, final boolean isIncoming, final RelativeLayout layout) { private void displayMessage(final int id, final String message, final String time, final boolean isIncoming, final RelativeLayout layout) {
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
@ -109,10 +124,24 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO
BubbleChat bubble = new BubbleChat(layout.getContext(), id, message, time, isIncoming, previousMessageID); BubbleChat bubble = new BubbleChat(layout.getContext(), id, message, time, isIncoming, previousMessageID);
previousMessageID = id; previousMessageID = id;
layout.addView(bubble.getView()); layout.addView(bubble.getView());
registerForContextMenu(bubble.getView());
} }
}); });
} }
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, v.getId(), 0, getString(R.string.delete));
}
@Override
public boolean onContextItemSelected(MenuItem item) {
LinphoneActivity.instance().deleteMessage(item.getItemId());
invalidate();
return true;
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();

View file

@ -24,11 +24,15 @@ import org.linphone.core.LinphoneCoreFactory;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.ImageView; import android.widget.ImageView;
@ -53,6 +57,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
View view = inflater.inflate(R.layout.chatlist, container, false); View view = inflater.inflate(R.layout.chatlist, container, false);
chatList = (ListView) view.findViewById(R.id.chatList); chatList = (ListView) view.findViewById(R.id.chatList);
chatList.setOnItemClickListener(this); chatList.setOnItemClickListener(this);
registerForContextMenu(chatList);
edit = (ImageView) view.findViewById(R.id.edit); edit = (ImageView) view.findViewById(R.id.edit);
edit.setOnClickListener(this); edit.setOnClickListener(this);
@ -74,6 +79,23 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
mConversations = LinphoneActivity.instance().getChatList(); mConversations = LinphoneActivity.instance().getChatList();
chatList.setAdapter(new ChatListAdapter()); chatList.setAdapter(new ChatListAdapter());
} }
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, v.getId(), 0, getString(R.string.delete));
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
String sipUri = (String) info.targetView.getTag();
LinphoneActivity.instance().removeFromChatList(sipUri);
mConversations = LinphoneActivity.instance().getChatList();
chatList.setAdapter(new ChatListAdapter());
return true;
}
@Override @Override
public void onClick(View v) { public void onClick(View v) {

View file

@ -20,6 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.linphone.core.Log;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
@ -103,6 +105,11 @@ public class ChatStorage {
return chatList; return chatList;
} }
public void deleteMessage(int id) {
db.delete(TABLE_NAME, "id LIKE " + id, null);
Log.d("db.delete(TABLE_NAME, \"id LIKE \" + " + id + ", null);");
}
class ChatHelper extends SQLiteOpenHelper { class ChatHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1; private static final int DATABASE_VERSION = 1;

View file

@ -31,11 +31,15 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.ImageView; import android.widget.ImageView;
@ -60,6 +64,7 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnItem
historyList = (ListView) view.findViewById(R.id.historyList); historyList = (ListView) view.findViewById(R.id.historyList);
historyList.setOnItemClickListener(this); historyList.setOnItemClickListener(this);
registerForContextMenu(historyList);
allCalls = (ImageView) view.findViewById(R.id.allCalls); allCalls = (ImageView) view.findViewById(R.id.allCalls);
allCalls.setOnClickListener(this); allCalls.setOnClickListener(this);
@ -85,6 +90,22 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnItem
historyList.setAdapter(new CallHistoryAdapter(getActivity().getApplicationContext())); historyList.setAdapter(new CallHistoryAdapter(getActivity().getApplicationContext()));
} }
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, v.getId(), 0, getString(R.string.delete));
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
LinphoneCallLog log = mLogs.get(info.position);
LinphoneManager.getLc().removeCallLog(log);
mLogs = Arrays.asList(LinphoneManager.getLc().getCallLogs());
historyList.setAdapter(new CallHistoryAdapter(getActivity().getApplicationContext()));
return true;
}
@Override @Override
public void onClick(View v) { public void onClick(View v) {
int id = v.getId(); int id = v.getId();

View file

@ -579,6 +579,14 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
return currentFragment; return currentFragment;
} }
public void deleteMessage(int id) {
if (chatStorage == null) {
return;
}
chatStorage.deleteMessage(id);
}
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_FIRST_USER && requestCode == SETTINGS_ACTIVITY) { if (resultCode == Activity.RESULT_FIRST_USER && requestCode == SETTINGS_ACTIVITY) {

View file

@ -18,7 +18,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
package org.linphone.ui; package org.linphone.ui;
import org.linphone.DialerFragment;
import org.linphone.LinphoneManager; import org.linphone.LinphoneManager;
import org.linphone.LinphoneService; import org.linphone.LinphoneService;
import org.linphone.R; import org.linphone.R;
@ -49,7 +48,9 @@ public class Digit extends Button implements AddressAware {
int after) { int after) {
super.onTextChanged(text, start, before, after); super.onTextChanged(text, start, before, after);
if (text == null || text.length() < 1) return; if (text == null || text.length() < 1) {
return;
}
DialKeyListener lListener = new DialKeyListener(); DialKeyListener lListener = new DialKeyListener();
setOnClickListener(lListener); setOnClickListener(lListener);
@ -57,11 +58,9 @@ public class Digit extends Button implements AddressAware {
if ("0+".equals(text)) { if ("0+".equals(text)) {
setOnLongClickListener(lListener); setOnLongClickListener(lListener);
} }
} }
public Digit(Context context, AttributeSet attrs, int style) { public Digit(Context context, AttributeSet attrs, int style) {
super(context, attrs, style); super(context, attrs, style);
setLongClickable(true); setLongClickable(true);
@ -70,7 +69,6 @@ public class Digit extends Button implements AddressAware {
public Digit(Context context, AttributeSet attrs) { public Digit(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
setLongClickable(true); setLongClickable(true);
} }
public Digit(Context context) { public Digit(Context context) {
@ -78,9 +76,6 @@ public class Digit extends Button implements AddressAware {
setLongClickable(true); setLongClickable(true);
} }
private class DialKeyListener implements OnClickListener, OnTouchListener, OnLongClickListener { private class DialKeyListener implements OnClickListener, OnTouchListener, OnLongClickListener {
final CharSequence mKeyCode; final CharSequence mKeyCode;
boolean mIsDtmfStarted; boolean mIsDtmfStarted;
@ -104,7 +99,7 @@ public class Digit extends Button implements AddressAware {
LinphoneCore lc = LinphoneManager.getLc(); LinphoneCore lc = LinphoneManager.getLc();
lc.stopDtmf(); lc.stopDtmf();
mIsDtmfStarted =false; mIsDtmfStarted =false;
if (lc.isIncall() && !DialerFragment.instance().mVisible) { if (lc.isIncall()) {
lc.sendDtmf(mKeyCode.charAt(0)); lc.sendDtmf(mKeyCode.charAt(0));
} }
} }