Added shadows to contact pictures

This commit is contained in:
Sylvain Berfini 2012-07-23 17:51:35 +02:00
parent 704fefc80a
commit d2325290ef
16 changed files with 147 additions and 49 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:linphone="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
@ -15,7 +16,7 @@
android:id="@+id/contactNameOrNumber" android:id="@+id/contactNameOrNumber"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="0.4" android:layout_weight="0.5"
android:gravity="center_vertical|left" android:gravity="center_vertical|left"
android:paddingLeft="20dp" android:paddingLeft="20dp"
android:textColor="@android:color/white" android:textColor="@android:color/white"
@ -23,8 +24,8 @@
<ImageView <ImageView
android:id="@+id/callStatus" android:id="@+id/callStatus"
android:layout_width="35dp" android:layout_width="40dp"
android:layout_height="35dp" android:layout_height="40dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingLeft="10dp" android:paddingLeft="10dp"
android:paddingRight="10dp" android:paddingRight="10dp"
@ -43,14 +44,12 @@
</LinearLayout> </LinearLayout>
<ImageView <org.linphone.ui.AvatarWithShadow
android:id="@+id/contactPicture" android:id="@+id/contactPicture"
android:layout_width="100dp" android:layout_width="wrap_content"
android:layout_height="100dp" android:layout_height="wrap_content"
linphone:picture="@drawable/unknown_small"
android:layout_gravity="center" android:layout_gravity="center"
android:contentDescription="@string/content_description_contact_picture" android:paddingBottom="10sp" />
android:paddingBottom="10sp"
android:scaleType="fitCenter"
android:src="@drawable/unknown_small" />
</LinearLayout> </LinearLayout>

29
res/layout/avatar.xml Normal file
View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:linphone="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="25dp"
android:layout_height="100dp"
android:scaleType="fitXY"
android:src="@drawable/avatar_shadow_left" />
<ImageView
android:id="@+id/picture"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:contentDescription="@string/content_description_contact_picture"
android:src="@drawable/unknown_small"
android:scaleType="fitCenter" />
<ImageView
android:layout_width="25dp"
android:layout_height="100dp"
android:scaleType="fitXY"
android:src="@drawable/avatar_shadow_right" />
</LinearLayout>

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:background="@drawable/background" android:background="@drawable/background"
@ -15,12 +16,11 @@
android:gravity="center" android:gravity="center"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <org.linphone.ui.AvatarWithShadow
android:contentDescription="@string/content_description_contact_picture"
android:id="@+id/contactPicture" android:id="@+id/contactPicture"
android:layout_width="100dp" android:layout_width="wrap_content"
android:layout_height="100dp" android:layout_height="wrap_content"
android:src="@drawable/unknown_small" /> linphone:picture="@drawable/unknown_small" />
<TextView <TextView
android:id="@+id/contactName" android:id="@+id/contactName"

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:background="@drawable/background" android:background="@drawable/background"
@ -14,12 +15,11 @@
android:gravity="center" android:gravity="center"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <org.linphone.ui.AvatarWithShadow
android:contentDescription="@string/content_description_contact_picture"
android:id="@+id/contactPicture" android:id="@+id/contactPicture"
android:layout_width="100dp" android:layout_width="wrap_content"
android:layout_height="100dp" android:layout_height="wrap_content"
android:src="@drawable/unknown_small" /> linphone:picture="@drawable/unknown_small" />
<TextView <TextView
android:id="@+id/contactName" android:id="@+id/contactName"

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:background="@drawable/background" android:background="@drawable/background"
@ -14,12 +15,11 @@
android:gravity="center" android:gravity="center"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <org.linphone.ui.AvatarWithShadow
android:contentDescription="@string/content_description_contact_picture"
android:id="@+id/contactPicture" android:id="@+id/contactPicture"
android:layout_width="100dp" android:layout_width="wrap_content"
android:layout_height="100dp" android:layout_height="wrap_content"
android:src="@drawable/unknown_small" /> linphone:picture="@drawable/unknown_small" />
<TextView <TextView
android:id="@+id/contactName" android:id="@+id/contactName"

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:background="@drawable/background"> android:background="@drawable/background">
@ -27,12 +28,11 @@
android:orientation="vertical" android:orientation="vertical"
android:paddingTop="30dip"> android:paddingTop="30dip">
<ImageView <org.linphone.ui.AvatarWithShadow
android:contentDescription="@string/content_description_contact_picture"
android:id="@+id/incoming_picture" android:id="@+id/incoming_picture"
android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_gravity="center" android:layout_height="wrap_content"
linphone:picture="@drawable/unknown_small"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:minWidth="128dp" android:minWidth="128dp"
android:minHeight="128dp" android:minHeight="128dp"

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<attr name="direction"> <attr name="direction">
<enum name="rightToLeft" value="0" /> <enum name="rightToLeft" value="0" />
<enum name="bottomToTop" value="1" /> <enum name="bottomToTop" value="1" />
@ -12,4 +13,9 @@
<attr name="content" format="reference" /> <attr name="content" format="reference" />
<attr name="direction" /> <attr name="direction" />
</declare-styleable> </declare-styleable>
<declare-styleable name="AvatarWithShadow">
<attr name="picture" format="reference" />
</declare-styleable>
</resources> </resources>

View file

@ -21,6 +21,7 @@ import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCall; import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCall.State; import org.linphone.core.LinphoneCall.State;
import org.linphone.core.LinphoneCoreFactory; import org.linphone.core.LinphoneCoreFactory;
import org.linphone.ui.AvatarWithShadow;
import android.app.Activity; import android.app.Activity;
import android.content.res.Resources; import android.content.res.Resources;
@ -106,9 +107,9 @@ public class AudioCallFragment extends Fragment {
} }
private void displayOrHideContactPicture(LinearLayout callView, Uri pictureUri, boolean hide) { private void displayOrHideContactPicture(LinearLayout callView, Uri pictureUri, boolean hide) {
ImageView contactPicture = (ImageView) callView.findViewById(R.id.contactPicture); AvatarWithShadow contactPicture = (AvatarWithShadow) callView.findViewById(R.id.contactPicture);
if (pictureUri != null) { if (pictureUri != null) {
LinphoneUtils.setImagePictureFromUri(callView.getContext(), contactPicture, Uri.parse(pictureUri.toString()), R.drawable.unknown_small); LinphoneUtils.setImagePictureFromUri(callView.getContext(), contactPicture.getView(), Uri.parse(pictureUri.toString()), R.drawable.unknown_small);
} }
if (hide) { if (hide) {
contactPicture.setVisibility(View.GONE); contactPicture.setVisibility(View.GONE);

View file

@ -23,6 +23,7 @@ import org.linphone.LinphoneSimpleListener.LinphoneOnMessageReceivedListener;
import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneChatRoom; import org.linphone.core.LinphoneChatRoom;
import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCore;
import org.linphone.ui.AvatarWithShadow;
import org.linphone.ui.BubbleChat; import org.linphone.ui.BubbleChat;
import android.net.Uri; import android.net.Uri;
@ -73,9 +74,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO
contactName.setText(name); contactName.setText(name);
} }
ImageView contactPicture = (ImageView) view.findViewById(R.id.contactPicture); AvatarWithShadow contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);
if (pictureUri != null) { if (pictureUri != null) {
LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture, Uri.parse(pictureUri), R.drawable.unknown_small); LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture.getView(), Uri.parse(pictureUri), R.drawable.unknown_small);
} }
ImageView sendMessage = (ImageView) view.findViewById(R.id.sendMessage); ImageView sendMessage = (ImageView) view.findViewById(R.id.sendMessage);

View file

@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import java.io.InputStream; import java.io.InputStream;
import org.linphone.compatibility.Compatibility; import org.linphone.compatibility.Compatibility;
import org.linphone.ui.AvatarWithShadow;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.os.Bundle; import android.os.Bundle;
@ -28,7 +29,6 @@ import android.view.LayoutInflater;
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.ImageView;
import android.widget.TableLayout; import android.widget.TableLayout;
import android.widget.TextView; import android.widget.TextView;
@ -44,12 +44,12 @@ public class ContactFragment extends Fragment {
contact = (Contact) getArguments().getSerializable("Contact"); contact = (Contact) getArguments().getSerializable("Contact");
View view = inflater.inflate(R.layout.contact, container, false); View view = inflater.inflate(R.layout.contact, container, false);
ImageView contactPicture = (ImageView) view.findViewById(R.id.contactPicture); AvatarWithShadow contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);
if (contact.getPhotoUri() != null) { if (contact.getPhotoUri() != null) {
InputStream input = Compatibility.getContactPictureInputStream(getActivity().getContentResolver(), contact.getID()); InputStream input = Compatibility.getContactPictureInputStream(getActivity().getContentResolver(), contact.getID());
contactPicture.setImageBitmap(BitmapFactory.decodeStream(input)); contactPicture.setImageBitmap(BitmapFactory.decodeStream(input));
} else { } else {
contactPicture.setImageResource(R.drawable.unknown_small); contactPicture.setBackgroundResource(R.drawable.unknown_small);
} }
chatListener = getChatListener(); chatListener = getChatListener();

View file

@ -18,6 +18,7 @@ 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 org.linphone.compatibility.Compatibility; import org.linphone.compatibility.Compatibility;
import org.linphone.ui.AvatarWithShadow;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
@ -34,7 +35,8 @@ import android.widget.TextView;
* @author Sylvain Berfini * @author Sylvain Berfini
*/ */
public class HistoryDetailFragment extends Fragment implements OnClickListener { public class HistoryDetailFragment extends Fragment implements OnClickListener {
private ImageView contactPicture, dialBack, chat, addToContacts; private ImageView dialBack, chat, addToContacts;
private AvatarWithShadow contactPicture;
private TextView contactName, callDirection, time, date, dialBackUri; private TextView contactName, callDirection, time, date, dialBackUri;
private String sipUri, displayName, pictureUri; private String sipUri, displayName, pictureUri;
@ -50,9 +52,9 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
View view = inflater.inflate(R.layout.history_detail, container, false); View view = inflater.inflate(R.layout.history_detail, container, false);
contactPicture = (ImageView) view.findViewById(R.id.contactPicture); contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);
if (pictureUri != null) { if (pictureUri != null) {
LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture, Uri.parse(pictureUri), R.drawable.unknown_small); LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture.getView(), Uri.parse(pictureUri), R.drawable.unknown_small);
} }
dialBack = (ImageView) view.findViewById(R.id.dialBack); dialBack = (ImageView) view.findViewById(R.id.dialBack);

View file

@ -25,6 +25,7 @@ import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCall; import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCall.State; import org.linphone.core.LinphoneCall.State;
import org.linphone.core.Log; import org.linphone.core.Log;
import org.linphone.ui.AvatarWithShadow;
import org.linphone.ui.LinphoneSliders; import org.linphone.ui.LinphoneSliders;
import org.linphone.ui.LinphoneSliders.LinphoneSliderTriggered; import org.linphone.ui.LinphoneSliders.LinphoneSliderTriggered;
@ -33,7 +34,6 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -47,7 +47,7 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat
private TextView mNameView; private TextView mNameView;
private TextView mNumberView; private TextView mNumberView;
private ImageView mPictureView; private AvatarWithShadow mPictureView;
private LinphoneCall mCall; private LinphoneCall mCall;
private LinphoneSliders mIncomingCallWidget; private LinphoneSliders mIncomingCallWidget;
@ -57,7 +57,7 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat
mNameView = (TextView) findViewById(R.id.incoming_caller_name); mNameView = (TextView) findViewById(R.id.incoming_caller_name);
mNumberView = (TextView) findViewById(R.id.incoming_caller_number); mNumberView = (TextView) findViewById(R.id.incoming_caller_number);
mPictureView = (ImageView) findViewById(R.id.incoming_picture); mPictureView = (AvatarWithShadow) findViewById(R.id.incoming_picture);
// set this flag so this activity will stay in front of the keyguard // set this flag so this activity will stay in front of the keyguard
int flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; int flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
@ -93,7 +93,7 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat
LinphoneAddress address = mCall.getRemoteAddress(); LinphoneAddress address = mCall.getRemoteAddress();
// May be greatly sped up using a drawable cache // May be greatly sped up using a drawable cache
Uri uri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(address, getContentResolver()); Uri uri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(address, getContentResolver());
LinphoneUtils.setImagePictureFromUri(this, mPictureView, uri, R.drawable.unknown_small); LinphoneUtils.setImagePictureFromUri(this, mPictureView.getView(), uri, R.drawable.unknown_small);
// To be done after findUriPictureOfContactAndSetDisplayName called // To be done after findUriPictureOfContactAndSetDisplayName called
mNameView.setText(address.getDisplayName()); mNameView.setText(address.getDisplayName());
@ -132,7 +132,7 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat
private void answer() { private void answer() {
if (!LinphoneManager.getInstance().acceptCall(mCall)) { if (!LinphoneManager.getInstance().acceptCall(mCall)) {
// the above method takes care of Samsung Galaxy S // the above method takes care of Samsung Galaxy S
Toast.makeText(this, R.string.couldnt_accept_call, Toast.LENGTH_LONG); Toast.makeText(this, R.string.couldnt_accept_call, Toast.LENGTH_LONG).show();
} else { } else {
if (mCall.getCurrentParamsCopy().getVideoEnabled()) if (mCall.getCurrentParamsCopy().getVideoEnabled())
LinphoneActivity.instance().startVideoActivity(mCall); LinphoneActivity.instance().startVideoActivity(mCall);

View file

@ -0,0 +1,60 @@
package org.linphone.ui;
/*
AvatarWithShadow.java
Copyright (C) 2012 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
import org.linphone.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
/**
* @author Sylvain Berfini
*/
public class AvatarWithShadow extends LinearLayout {
private ImageView contactPicture;
public AvatarWithShadow(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.AvatarWithShadow);
int pictureResId = array.getResourceId(R.styleable.AvatarWithShadow_picture, 0);
array.recycle();
View view = LayoutInflater.from(context).inflate(R.layout.avatar, this);
contactPicture = (ImageView) view.findViewById(R.id.picture);
contactPicture.setImageResource(pictureResId);
}
public ImageView getView() {
return contactPicture;
}
public void setImageBitmap(Bitmap bitmap) {
contactPicture.setImageBitmap(bitmap);
}
public void setBackgroundResource(int res) {
contactPicture.setBackgroundResource(res);
}
}