From ecf792a7fe29098e406e7751c3c698096fe69fd7 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 9 Aug 2016 14:40:15 +0200 Subject: [PATCH] Use compatibility method for setTextAppearance --- src/org/linphone/ChatFragment.java | 8 ++-- .../linphone/compatibility/ApiElevenPlus.java | 6 +++ .../compatibility/ApiTwentyThreePlus.java | 48 +++++++++++++++++++ .../linphone/compatibility/Compatibility.java | 10 ++++ 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 src/org/linphone/compatibility/ApiTwentyThreePlus.java diff --git a/src/org/linphone/ChatFragment.java b/src/org/linphone/ChatFragment.java index 5dfdadc77..77d160176 100644 --- a/src/org/linphone/ChatFragment.java +++ b/src/org/linphone/ChatFragment.java @@ -1187,8 +1187,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); layoutParams.setMargins(100, 10, 10, 10); holder.background.setBackgroundResource(R.drawable.resizable_chat_bubble_outgoing); - holder.contactName.setTextAppearance(R.style.font3); - holder.fileTransferAction.setTextAppearance(R.style.font15); + Compatibility.setTextAppearance(holder.contactName, getActivity(), R.style.font3); + Compatibility.setTextAppearance(holder.fileTransferAction, getActivity(), R.style.font15); holder.fileTransferAction.setBackgroundResource(R.drawable.resizable_confirm_delete_button); } else { if (isEditMode) { @@ -1199,8 +1199,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC layoutParams.setMargins(10, 10, 100, 10); } holder.background.setBackgroundResource(R.drawable.resizable_chat_bubble_incoming); - holder.contactName.setTextAppearance(R.style.font9); - holder.fileTransferAction.setTextAppearance(R.style.font8); + Compatibility.setTextAppearance(holder.contactName, getActivity(), R.style.font9); + Compatibility.setTextAppearance(holder.fileTransferAction, getActivity(), R.style.font8); holder.fileTransferAction.setBackgroundResource(R.drawable.resizable_assistant_button); } holder.bubbleLayout.setLayoutParams(layoutParams); diff --git a/src/org/linphone/compatibility/ApiElevenPlus.java b/src/org/linphone/compatibility/ApiElevenPlus.java index 7b30e5581..ba7711204 100644 --- a/src/org/linphone/compatibility/ApiElevenPlus.java +++ b/src/org/linphone/compatibility/ApiElevenPlus.java @@ -17,6 +17,7 @@ import android.provider.ContactsContract; import android.provider.ContactsContract.CommonDataKinds.SipAddress; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Intents.Insert; +import android.widget.TextView; /* ApiElevenPlus.java @@ -162,4 +163,9 @@ public class ApiElevenPlus { return notif; } + + @SuppressWarnings("deprecation") + public static void setTextAppearance(TextView textview, Context context, int style) { + textview.setTextAppearance(context, style); + } } diff --git a/src/org/linphone/compatibility/ApiTwentyThreePlus.java b/src/org/linphone/compatibility/ApiTwentyThreePlus.java new file mode 100644 index 000000000..8efdfccfe --- /dev/null +++ b/src/org/linphone/compatibility/ApiTwentyThreePlus.java @@ -0,0 +1,48 @@ +package org.linphone.compatibility; + +import java.util.ArrayList; + +import org.linphone.R; + +import android.annotation.TargetApi; +import android.app.Notification; +import android.app.PendingIntent; +import android.content.ContentUris; +import android.content.ContentValues; +import android.content.Context; +import android.content.Intent; +import android.graphics.Bitmap; +import android.net.Uri; +import android.provider.ContactsContract; +import android.provider.ContactsContract.CommonDataKinds.SipAddress; +import android.provider.ContactsContract.Contacts; +import android.provider.ContactsContract.Intents.Insert; +import android.widget.TextView; + +/* +ApiTwentyThreePlus.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +/** + * @author Sylvain Berfini + */ +@TargetApi(23) +public class ApiTwentyThreePlus { + public static void setTextAppearance(TextView textview, int style) { + textview.setTextAppearance(style); + } +} diff --git a/src/org/linphone/compatibility/Compatibility.java b/src/org/linphone/compatibility/Compatibility.java index cad5a21a0..9fac817b5 100644 --- a/src/org/linphone/compatibility/Compatibility.java +++ b/src/org/linphone/compatibility/Compatibility.java @@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import org.linphone.mediastream.Version; +import android.app.Activity; import android.app.Notification; import android.app.PendingIntent; import android.content.Context; @@ -29,6 +30,7 @@ import android.text.Html; import android.text.Spanned; import android.view.ViewTreeObserver; import android.view.ViewTreeObserver.OnGlobalLayoutListener; +import android.widget.TextView; /** * @author Sylvain Berfini */ @@ -120,4 +122,12 @@ public class Compatibility { }*/ return Html.fromHtml(text); } + + public static void setTextAppearance(TextView textview, Context context, int style) { + if (Version.sdkAboveOrEqual(Version.API23_MARSHMALLOW_60)) { + ApiTwentyThreePlus.setTextAppearance(textview, style); + } else { + ApiElevenPlus.setTextAppearance(textview, context, style); + } + } }