From 84e6d1b5aa56573a853efff1b68810a95f563017 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 1 Aug 2012 10:46:33 +0200 Subject: [PATCH] Tablet dialer layout + using fragments to fill empty space on tablet --- AndroidManifest.xml | 8 +- .../{background.png => background_alt.png} | Bin res/layout-xlarge-land/dialer.xml | 99 +++++++++++++----- src/org/linphone/ChatFragment.java | 61 ++++++----- src/org/linphone/ContactFragment.java | 44 ++++---- src/org/linphone/HistoryDetailFragment.java | 35 +++++-- src/org/linphone/LinphoneActivity.java | 74 ++++++++----- src/org/linphone/ui/AvatarWithShadow.java | 4 +- 8 files changed, 211 insertions(+), 114 deletions(-) rename res/drawable-xlarge-land/{background.png => background_alt.png} (100%) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 2222af699..c8bf075b1 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -64,7 +64,7 @@ + android:screenOrientation="behind"> @@ -81,12 +81,12 @@ + android:screenOrientation="behind"> + android:screenOrientation="behind"> @@ -94,7 +94,7 @@ + android:screenOrientation="behind"> diff --git a/res/drawable-xlarge-land/background.png b/res/drawable-xlarge-land/background_alt.png similarity index 100% rename from res/drawable-xlarge-land/background.png rename to res/drawable-xlarge-land/background_alt.png diff --git a/res/layout-xlarge-land/dialer.xml b/res/layout-xlarge-land/dialer.xml index ffbccb97a..fc24bd40c 100644 --- a/res/layout-xlarge-land/dialer.xml +++ b/res/layout-xlarge-land/dialer.xml @@ -1,7 +1,7 @@ + android:layout_height="match_parent"> - - - - + - + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/org/linphone/ChatFragment.java b/src/org/linphone/ChatFragment.java index bfd28350e..e76ff7e46 100644 --- a/src/org/linphone/ChatFragment.java +++ b/src/org/linphone/ChatFragment.java @@ -48,8 +48,11 @@ import android.widget.TextView; */ public class ChatFragment extends Fragment implements OnClickListener, LinphoneOnMessageReceivedListener { private LinphoneChatRoom chatRoom; + private View view; private String sipUri; private EditText message; + private TextView contactName; + private AvatarWithShadow contactPicture; private RelativeLayout messagesLayout; private ScrollView messagesScrollView; private int previousMessageID; @@ -59,41 +62,22 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { sipUri = getArguments().getString("SipUri"); - String name = getArguments().getString("DisplayName"); + String displayName = getArguments().getString("DisplayName"); String pictureUri = getArguments().getString("PictureUri"); - View view = inflater.inflate(R.layout.chat, container, false); + view = inflater.inflate(R.layout.chat, container, false); - TextView contactName = (TextView) view.findViewById(R.id.contactName); - if (name == null && getResources().getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) { - contactName.setText(LinphoneUtils.getUsernameFromAddress(sipUri)); - } else if (name == null) { - contactName.setText(sipUri); - } - else { - contactName.setText(name); - } - - AvatarWithShadow contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture); - if (pictureUri != null) { - LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture.getView(), Uri.parse(pictureUri), R.drawable.unknown_small); - } + contactName = (TextView) view.findViewById(R.id.contactName); + contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture); ImageView sendMessage = (ImageView) view.findViewById(R.id.sendMessage); sendMessage.setOnClickListener(this); message = (EditText) view.findViewById(R.id.message); messagesLayout = (RelativeLayout) view.findViewById(R.id.messages); - messagesScrollView = (ScrollView) view.findViewById(R.id.chatScrollView); - messagesScrollView.post(new Runnable() { - @Override - public void run() { - scrollToEnd(); - } - }); - invalidate(); + displayChat(displayName, pictureUri); LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); if (lc != null) @@ -117,6 +101,30 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO scrollToEnd(); } + private void displayChat(String displayName, String pictureUri) { + if (displayName == null && getResources().getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) { + contactName.setText(LinphoneUtils.getUsernameFromAddress(sipUri)); + } else if (displayName == null) { + contactName.setText(sipUri); + } + else { + contactName.setText(displayName); + } + + if (pictureUri != null) { + LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture.getView(), Uri.parse(pictureUri), R.drawable.unknown_small); + } + + messagesScrollView.post(new Runnable() { + @Override + public void run() { + scrollToEnd(); + } + }); + + invalidate(); + } + private void displayMessage(final int id, final String message, final String time, final boolean isIncoming, final RelativeLayout layout) { mHandler.post(new Runnable() { @Override @@ -128,6 +136,11 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO } }); } + + public void changeDisplayedChat(String sipUri, String displayName, String pictureUri) { + this.sipUri = sipUri; + displayChat(displayName, pictureUri); + } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { diff --git a/src/org/linphone/ContactFragment.java b/src/org/linphone/ContactFragment.java index 00c53a810..45b48ec2c 100644 --- a/src/org/linphone/ContactFragment.java +++ b/src/org/linphone/ContactFragment.java @@ -40,9 +40,22 @@ import android.widget.TextView; public class ContactFragment extends Fragment implements OnClickListener { private Contact contact; private ImageView back, editContact, newContact; - private OnClickListener dialListener, chatListener; private LayoutInflater inflater; private View view; + + private OnClickListener dialListener = new OnClickListener() { + @Override + public void onClick(View v) { + LinphoneActivity.instance().setAddresGoToDialerAndCall(v.getTag().toString(), contact.getName(), contact.getPhotoUri()); + } + }; + + private OnClickListener chatListener = new OnClickListener() { + @Override + public void onClick(View v) { + LinphoneActivity.instance().displayChat(v.getTag().toString()); + } + }; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -58,19 +71,22 @@ public class ContactFragment extends Fragment implements OnClickListener { newContact = (ImageView) view.findViewById(R.id.newContact); newContact.setOnClickListener(this); - chatListener = getChatListener(); - dialListener = getDialListener(); - return view; } + public void changeDisplayedContact(Contact newContact) { + contact = newContact; + contact.refresh(getActivity().getContentResolver()); + displayContact(inflater, view); + } + private void displayContact(LayoutInflater inflater, View view) { AvatarWithShadow contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture); if (contact.getPhotoUri() != null) { InputStream input = Compatibility.getContactPictureInputStream(getActivity().getContentResolver(), contact.getID()); contactPicture.setImageBitmap(BitmapFactory.decodeStream(input)); } else { - contactPicture.setBackgroundResource(R.drawable.unknown_small); + contactPicture.setImageResource(R.drawable.unknown_small); } TextView contactName = (TextView) view.findViewById(R.id.contactName); @@ -107,24 +123,6 @@ public class ContactFragment extends Fragment implements OnClickListener { displayContact(inflater, view); } - public OnClickListener getDialListener() { - return new OnClickListener() { - @Override - public void onClick(View v) { - LinphoneActivity.instance().setAddresGoToDialerAndCall(v.getTag().toString(), contact.getName(), contact.getPhotoUri()); - } - }; - } - - public OnClickListener getChatListener() { - return new OnClickListener() { - @Override - public void onClick(View v) { - LinphoneActivity.instance().displayChat(v.getTag().toString()); - } - }; - } - @Override public void onClick(View v) { int id = v.getId(); diff --git a/src/org/linphone/HistoryDetailFragment.java b/src/org/linphone/HistoryDetailFragment.java index c3af4bf65..0701e136e 100644 --- a/src/org/linphone/HistoryDetailFragment.java +++ b/src/org/linphone/HistoryDetailFragment.java @@ -37,6 +37,7 @@ import android.widget.TextView; public class HistoryDetailFragment extends Fragment implements OnClickListener { private ImageView dialBack, chat, addToContacts; private AvatarWithShadow contactPicture; + private View view; private TextView contactName, callDirection, time, date, dialBackUri; private String sipUri, displayName, pictureUri; @@ -50,12 +51,9 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener { String callTime = getArguments().getString("CallTime"); String callDate = getArguments().getString("CallDate"); - View view = inflater.inflate(R.layout.history_detail, container, false); + view = inflater.inflate(R.layout.history_detail, container, false); contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture); - if (pictureUri != null) { - LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture.getView(), Uri.parse(pictureUri), R.drawable.unknown_small); - } dialBack = (ImageView) view.findViewById(R.id.dialBack); dialBack.setOnClickListener(this); @@ -70,23 +68,42 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener { if (displayName == null && getResources().getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) { displayName = LinphoneUtils.getUsernameFromAddress(sipUri); } - contactName.setText(displayName == null ? sipUri : displayName); dialBackUri = (TextView) view.findViewById(R.id.dialBackUri); - dialBackUri.setText(sipUri); callDirection = (TextView) view.findViewById(R.id.callDirection); - callDirection.setText(status); time = (TextView) view.findViewById(R.id.time); - time.setText(callTime == null ? "" : callTime); date = (TextView) view.findViewById(R.id.date); - date.setText(callDate == null ? "" : callDate); + displayHistory(status, callTime, callDate); return view; } + private void displayHistory(String status, String callTime, String callDate) { + if (pictureUri != null) { + LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture.getView(), Uri.parse(pictureUri), R.drawable.unknown_small); + } + + contactName.setText(displayName == null ? sipUri : displayName); + dialBackUri.setText(sipUri); + callDirection.setText(status); + time.setText(callTime == null ? "" : callTime); + date.setText(callDate == null ? "" : callDate); + } + + public void changeDisplayedHistory(String sipUri, String displayName, String pictureUri, String status, String callTime, String callDate) { + if (displayName == null && getResources().getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) { + displayName = LinphoneUtils.getUsernameFromAddress(sipUri); + } + + this.sipUri = sipUri; + this.displayName = displayName; + this.pictureUri = pictureUri; + displayHistory(status, callTime, callDate); + } + @Override public void onResume() { super.onResume(); diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java index 3ff1cb3e8..0870d7063 100644 --- a/src/org/linphone/LinphoneActivity.java +++ b/src/org/linphone/LinphoneActivity.java @@ -45,7 +45,6 @@ import org.linphone.ui.AddressText; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; -import android.content.pm.ActivityInfo; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; @@ -281,16 +280,11 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene } public void displayHistoryDetail(String sipUri, LinphoneCallLog log) { - //TODO Update current fragment if already visible (tablets) LinphoneAddress lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri); Uri uri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(lAddress, getContentResolver()); - Bundle extras = new Bundle(); - extras.putString("SipUri", sipUri); - if (lAddress.getDisplayName() != null) { - extras.putString("DisplayName", lAddress.getDisplayName()); - extras.putString("PictureUri", uri.toString()); - } + String displayName = lAddress.getDisplayName(); + String pictureUri = uri == null ? null : uri.toString(); String status; if (log.getDirection() == CallDirection.Outgoing) { @@ -302,11 +296,27 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene status = "Incoming"; } } - extras.putString("CallStatus", status); - extras.putString("CallTime", secondsToDisplayableString(log.getCallDuration())); - extras.putString("CallDate", log.getStartDate()); - changeCurrentFragment(FragmentsAvailable.HISTORY_DETAIL, extras); + String callTime = secondsToDisplayableString(log.getCallDuration()); + String callDate = log.getStartDate(); + + Fragment fragment2 = getSupportFragmentManager().findFragmentById(R.id.fragmentContainer2); + if (fragment2 != null && fragment2.isVisible() && currentFragment == FragmentsAvailable.HISTORY_DETAIL) { + HistoryDetailFragment historyDetailFragment = (HistoryDetailFragment) fragment2; + historyDetailFragment.changeDisplayedHistory(sipUri, displayName, pictureUri, status, callTime, callDate); + } else { + Bundle extras = new Bundle(); + extras.putString("SipUri", sipUri); + if (displayName != null) { + extras.putString("DisplayName", displayName); + extras.putString("PictureUri", pictureUri); + } + extras.putString("CallStatus", status); + extras.putString("CallTime", callTime); + extras.putString("CallDate", callDate); + + changeCurrentFragment(FragmentsAvailable.HISTORY_DETAIL, extras); + } } private String secondsToDisplayableString(int secs) { @@ -317,10 +327,15 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene } public void displayContact(Contact contact) { - //TODO Update current fragment if already visible (tablets) - Bundle extras = new Bundle(); - extras.putSerializable("Contact", contact); - changeCurrentFragment(FragmentsAvailable.CONTACT, extras); + Fragment fragment2 = getSupportFragmentManager().findFragmentById(R.id.fragmentContainer2); + if (fragment2 != null && fragment2.isVisible() && currentFragment == FragmentsAvailable.CONTACT) { + ContactFragment contactFragment = (ContactFragment) fragment2; + contactFragment.changeDisplayedContact(contact); + } else { + Bundle extras = new Bundle(); + extras.putSerializable("Contact", contact); + changeCurrentFragment(FragmentsAvailable.CONTACT, extras); + } } public void displayContacts() { @@ -328,20 +343,31 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene } public void displayChat(String sipUri) { - //TODO Update current fragment if already visible (tablets) LinphoneAddress lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri); Uri uri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(lAddress, getContentResolver()); + String displayName = lAddress.getDisplayName(); + String pictureUri = uri == null ? null : uri.toString(); - Bundle extras = new Bundle(); - extras.putString("SipUri", sipUri); - if (lAddress.getDisplayName() != null) { - extras.putString("DisplayName", lAddress.getDisplayName()); - extras.putString("PictureUri", uri.toString()); + if (currentFragment == FragmentsAvailable.CHATLIST || currentFragment == FragmentsAvailable.CHAT) { + Fragment fragment2 = getSupportFragmentManager().findFragmentById(R.id.fragmentContainer2); + 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) { + extras.putString("DisplayName", displayName); + extras.putString("PictureUri", pictureUri); + } + changeCurrentFragment(FragmentsAvailable.CHAT, extras); + } + } else { + changeCurrentFragment(FragmentsAvailable.CHATLIST, null); + displayChat(sipUri); } - LinphoneService.instance().resetMessageNotifCount(); LinphoneService.instance().removeMessageNotification(); - changeCurrentFragment(FragmentsAvailable.CHAT, extras); displayMissedChats(getChatStorage().getUnreadMessageCount()); } diff --git a/src/org/linphone/ui/AvatarWithShadow.java b/src/org/linphone/ui/AvatarWithShadow.java index b83d4b557..98e0787e0 100644 --- a/src/org/linphone/ui/AvatarWithShadow.java +++ b/src/org/linphone/ui/AvatarWithShadow.java @@ -54,7 +54,7 @@ public class AvatarWithShadow extends LinearLayout { contactPicture.setImageBitmap(bitmap); } - public void setBackgroundResource(int res) { - contactPicture.setBackgroundResource(res); + public void setImageResource(int res) { + contactPicture.setImageResource(res); } }