diff --git a/res/layout-sw600dp-land/main.xml b/res/layout-sw600dp-land/main.xml index eddcc0103..234060977 100644 --- a/res/layout-sw600dp-land/main.xml +++ b/res/layout-sw600dp-land/main.xml @@ -137,7 +137,7 @@ android:id="@+id/dialer" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_weight="0.25" + android:layout_weight="0.24" android:adjustViewBounds="true" android:contentDescription="@string/content_description_dialer" android:scaleType="fitXY" diff --git a/res/layout-sw720dp-land/main.xml b/res/layout-sw720dp-land/main.xml new file mode 100644 index 000000000..84db874be --- /dev/null +++ b/res/layout-sw720dp-land/main.xml @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/org/linphone/ChatFragment.java b/src/org/linphone/ChatFragment.java index eeaf7798d..d8252d752 100644 --- a/src/org/linphone/ChatFragment.java +++ b/src/org/linphone/ChatFragment.java @@ -117,6 +117,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC private Bitmap imageToUpload; private Uri imageToUploadUri; private Thread uploadThread; + private TextWatcher textWatcher; + private OnGlobalLayoutListener keyboardListener; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @@ -174,9 +176,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC } uploadServerUri = getActivity().getResources().getString(R.string.pref_image_sharing_server_key); - addVirtualKeyboardVisiblityListener(); - message.addTextChangedListener(new TextWatcher() { + textWatcher = new TextWatcher() { public void afterTextChanged(Editable arg0) { } @@ -193,13 +194,13 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC sendMessage.setEnabled(true); } } - }); + }; return view; } private void addVirtualKeyboardVisiblityListener() { - view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { + keyboardListener = new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect visibleArea = new Rect(); @@ -212,7 +213,12 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC hideKeyboardVisibleMode(); } } - }); + }; + view.getViewTreeObserver().addOnGlobalLayoutListener(keyboardListener); + } + + private void removeVirtualKeyboardVisiblityListener() { + Compatibility.removeGlobalLayoutListener(view.getViewTreeObserver(), keyboardListener); } public void showKeyboardVisibleMode() { @@ -357,8 +363,11 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC @Override public void onPause() { - super.onPause(); latestImageMessages = null; + message.removeTextChangedListener(textWatcher); + removeVirtualKeyboardVisiblityListener(); + + super.onPause(); if (!message.getText().toString().equals("") && LinphoneActivity.isInstanciated()) { ChatStorage chatStorage = LinphoneActivity.instance().getChatStorage(); @@ -376,6 +385,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC @Override public void onResume() { latestImageMessages = new HashMap(); + message.addTextChangedListener(textWatcher); + addVirtualKeyboardVisiblityListener(); super.onResume(); @@ -643,7 +654,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC Cursor cursor = loader.loadInBackground(); if (cursor != null && cursor.moveToFirst()) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); - return cursor.getString(column_index); + String result = cursor.getString(column_index); + cursor.close(); + return result; } return null; } diff --git a/src/org/linphone/ChatStorage.java b/src/org/linphone/ChatStorage.java index 9e8c04bf8..eec3babf1 100644 --- a/src/org/linphone/ChatStorage.java +++ b/src/org/linphone/ChatStorage.java @@ -251,7 +251,8 @@ public class ChatStorage { c.close(); return rawImage; } - + + c.close(); return null; } diff --git a/src/org/linphone/ContactHelper.java b/src/org/linphone/ContactHelper.java index 0f43a4aec..b9a80a8c9 100644 --- a/src/org/linphone/ContactHelper.java +++ b/src/org/linphone/ContactHelper.java @@ -187,6 +187,7 @@ public final class ContactHelper { boolean valid = checkPhotosUris(resolver, c, android.provider.ContactsContract.Data.CONTACT_ID, android.provider.ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME); + c.close(); if (valid) return true; } @@ -202,6 +203,7 @@ public final class ContactHelper { boolean valid = checkPhotosUris(resolver, c, android.provider.ContactsContract.Data.CONTACT_ID, android.provider.ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME); + c.close(); if (valid) return true; // Finally using phone number @@ -216,7 +218,7 @@ public final class ContactHelper { android.provider.ContactsContract.PhoneLookup.NUMBER, android.provider.ContactsContract.PhoneLookup.DISPLAY_NAME}; c = resolver.query(lookupUri, projection, null, null, null); - while (c.moveToNext()) { + while (c != null && c.moveToNext()) { long id = c.getLong(c.getColumnIndex(android.provider.ContactsContract.PhoneLookup._ID)); String enteredNumber = c.getString(c.getColumnIndex(android.provider.ContactsContract.PhoneLookup.NUMBER)); if (!normalizedNumber.equals(PhoneNumberUtils.getStrippedReversed(enteredNumber))) { diff --git a/src/org/linphone/EditContactFragment.java b/src/org/linphone/EditContactFragment.java index c23d363c0..acdf1b7b3 100644 --- a/src/org/linphone/EditContactFragment.java +++ b/src/org/linphone/EditContactFragment.java @@ -351,8 +351,13 @@ public class EditContactFragment extends Fragment { new String[]{RawContacts._ID}, RawContacts.CONTACT_ID + "=?", new String[]{contactID}, null); - if (c != null && c.moveToFirst()) { - return c.getString(c.getColumnIndex(RawContacts._ID)); + if (c != null) { + String result = null; + if (c.moveToFirst()) { + result = c.getString(c.getColumnIndex(RawContacts._ID)); + } + c.close(); + return result; } return null; } @@ -362,8 +367,13 @@ public class EditContactFragment extends Fragment { new String[]{ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME}, RawContacts.CONTACT_ID + "=?", new String[]{contactID}, null); - if (c != null && c.moveToFirst()) { - return c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME)); + if (c != null) { + String result = null; + if (c.moveToFirst()) { + result = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME)); + } + c.close(); + return result; } return null; } @@ -373,8 +383,13 @@ public class EditContactFragment extends Fragment { new String[]{ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME}, RawContacts.CONTACT_ID + "=?", new String[]{contactID}, null); - if (c != null && c.moveToFirst()) { - return c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME)); + if (c != null) { + String result = null; + if (c.moveToFirst()) { + result = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME)); + } + c.close(); + return result; } return null; } diff --git a/src/org/linphone/compatibility/ApiFivePlus.java b/src/org/linphone/compatibility/ApiFivePlus.java index 6adde17b9..9cd89f3cb 100644 --- a/src/org/linphone/compatibility/ApiFivePlus.java +++ b/src/org/linphone/compatibility/ApiFivePlus.java @@ -36,6 +36,8 @@ import android.provider.ContactsContract.Data; import android.provider.ContactsContract.Intents.Insert; import android.text.ClipboardManager; import android.view.Display; +import android.view.ViewTreeObserver; +import android.view.ViewTreeObserver.OnGlobalLayoutListener; /* ApiFivePlus.java @@ -421,4 +423,8 @@ public class ApiFivePlus { .build() ); } + + public static void removeGlobalLayoutListener(ViewTreeObserver viewTreeObserver, OnGlobalLayoutListener keyboardListener) { + viewTreeObserver.removeGlobalOnLayoutListener(keyboardListener); + } } diff --git a/src/org/linphone/compatibility/ApiSixteenPlus.java b/src/org/linphone/compatibility/ApiSixteenPlus.java index 14d2b8d3f..ec83e5928 100644 --- a/src/org/linphone/compatibility/ApiSixteenPlus.java +++ b/src/org/linphone/compatibility/ApiSixteenPlus.java @@ -7,6 +7,8 @@ import android.app.Notification; import android.app.PendingIntent; import android.content.Context; import android.graphics.Bitmap; +import android.view.ViewTreeObserver; +import android.view.ViewTreeObserver.OnGlobalLayoutListener; /* ApiSixteenPlus.java Copyright (C) 2012 Belledonne Communications, Grenoble, France @@ -76,4 +78,8 @@ public class ApiSixteenPlus { return notif; } + + public static void removeGlobalLayoutListener(ViewTreeObserver viewTreeObserver, OnGlobalLayoutListener keyboardListener) { + viewTreeObserver.removeOnGlobalLayoutListener(keyboardListener); + } } diff --git a/src/org/linphone/compatibility/Compatibility.java b/src/org/linphone/compatibility/Compatibility.java index fef976bb7..9d5f4f416 100644 --- a/src/org/linphone/compatibility/Compatibility.java +++ b/src/org/linphone/compatibility/Compatibility.java @@ -37,6 +37,8 @@ import android.graphics.Bitmap; import android.net.Uri; import android.preference.Preference; import android.view.Display; +import android.view.ViewTreeObserver; +import android.view.ViewTreeObserver.OnGlobalLayoutListener; /** * @author Sylvain Berfini */ @@ -243,4 +245,13 @@ public class Compatibility { ApiFivePlus.deleteSipAddressFromContact(ops, oldSipAddress, contactID); } } + + + public static void removeGlobalLayoutListener(ViewTreeObserver viewTreeObserver, OnGlobalLayoutListener keyboardListener) { + if (Version.sdkAboveOrEqual(16)) { + ApiSixteenPlus.removeGlobalLayoutListener(viewTreeObserver, keyboardListener); + } else { + ApiFivePlus.removeGlobalLayoutListener(viewTreeObserver, keyboardListener); + } + } }