diff --git a/src/org/thoughtcrime/securesms/DeviceLinkFragment.java b/src/org/thoughtcrime/securesms/DeviceLinkFragment.java index 21487e2138..a8e5493edb 100644 --- a/src/org/thoughtcrime/securesms/DeviceLinkFragment.java +++ b/src/org/thoughtcrime/securesms/DeviceLinkFragment.java @@ -3,6 +3,7 @@ package org.thoughtcrime.securesms; import android.content.res.Configuration; import android.net.Uri; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; @@ -16,7 +17,7 @@ public class DeviceLinkFragment extends Fragment implements View.OnClickListener private Uri uri; @Override - public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) { + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) { this.container = (LinearLayout) inflater.inflate(R.layout.device_link_fragment, container, false); this.container.findViewById(R.id.link_device).setOnClickListener(this); @@ -31,6 +32,7 @@ public class DeviceLinkFragment extends Fragment implements View.OnClickListener @Override public void onConfigurationChanged(Configuration newConfiguration) { + super.onConfigurationChanged(newConfiguration); if (newConfiguration.orientation == Configuration.ORIENTATION_LANDSCAPE) { container.setOrientation(LinearLayout.HORIZONTAL); } else { @@ -51,6 +53,6 @@ public class DeviceLinkFragment extends Fragment implements View.OnClickListener } public interface LinkClickedListener { - public void onLink(Uri uri); + void onLink(Uri uri); } } diff --git a/src/org/thoughtcrime/securesms/contacts/ContactIdentityManager.java b/src/org/thoughtcrime/securesms/contacts/ContactIdentityManager.java index d829d3be6b..27b9ec8461 100644 --- a/src/org/thoughtcrime/securesms/contacts/ContactIdentityManager.java +++ b/src/org/thoughtcrime/securesms/contacts/ContactIdentityManager.java @@ -2,17 +2,13 @@ package org.thoughtcrime.securesms.contacts; import android.content.Context; import android.net.Uri; -import android.os.Build; import java.util.List; public abstract class ContactIdentityManager { public static ContactIdentityManager getInstance(Context context) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) - return new ContactIdentityManagerICS(context); - else - return new ContactIdentityManagerGingerbread(context); + return new ContactIdentityManagerICS(context); } protected final Context context; diff --git a/src/org/thoughtcrime/securesms/contacts/ContactIdentityManagerGingerbread.java b/src/org/thoughtcrime/securesms/contacts/ContactIdentityManagerGingerbread.java deleted file mode 100644 index fb97ea23b6..0000000000 --- a/src/org/thoughtcrime/securesms/contacts/ContactIdentityManagerGingerbread.java +++ /dev/null @@ -1,134 +0,0 @@ -package org.thoughtcrime.securesms.contacts; - -import android.content.Context; -import android.content.SharedPreferences; -import android.database.Cursor; -import android.net.Uri; -import android.preference.PreferenceManager; -import android.provider.ContactsContract; -import android.provider.ContactsContract.Contacts; -import android.provider.ContactsContract.PhoneLookup; -import android.provider.ContactsContract.RawContacts; -import android.telephony.TelephonyManager; - -import org.thoughtcrime.securesms.ApplicationPreferencesActivity; -import org.thoughtcrime.securesms.util.TextSecurePreferences; - -import java.util.ArrayList; -import java.util.List; - -class ContactIdentityManagerGingerbread extends ContactIdentityManager { - - public ContactIdentityManagerGingerbread(Context context) { - super(context); - } - - @Override - public Uri getSelfIdentityUri() { - String contactUriString = TextSecurePreferences.getIdentityContactUri(context); - - if (hasLocalNumber()) return getContactUriForNumber(getLocalNumber()); - else if (contactUriString != null) return Uri.parse(contactUriString); - - return null; - } - - @Override - public boolean isSelfIdentityAutoDetected() { - return hasLocalNumber() && getContactUriForNumber(getLocalNumber()) != null; - } - - @Override - public List getSelfIdentityRawContactIds() { - long selfIdentityContactId = getSelfIdentityContactId(); - - if (selfIdentityContactId == -1) - return null; - - Cursor cursor = null; - ArrayList rawContactIds = new ArrayList(); - - try { - cursor = context.getContentResolver().query(RawContacts.CONTENT_URI, - new String[] {RawContacts._ID}, - RawContacts.CONTACT_ID + " = ?", - new String[] {selfIdentityContactId+""}, - null); - - if (cursor == null || cursor.getCount() == 0) - return null; - - while (cursor.moveToNext()) { - rawContactIds.add(Long.valueOf(cursor.getLong(0))); - } - - return rawContactIds; - - } finally { - if (cursor != null) - cursor.close(); - } - } - - private Uri getContactUriForNumber(String number) { - String[] PROJECTION = new String[] { - PhoneLookup.DISPLAY_NAME, - PhoneLookup.LOOKUP_KEY, - PhoneLookup._ID, - }; - - Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); - Cursor cursor = null; - - try { - cursor = context.getContentResolver().query(uri, PROJECTION, null, null, null); - - if (cursor != null && cursor.moveToFirst()) { - return Contacts.getLookupUri(cursor.getLong(2), cursor.getString(1)); - } - } finally { - if (cursor != null) - cursor.close(); - } - - return null; - } - - private long getSelfIdentityContactId() { - Uri contactUri = getSelfIdentityUri(); - - if (contactUri == null) - return -1; - - Cursor cursor = null; - - try { - cursor = context.getContentResolver().query(contactUri, - new String[] {ContactsContract.Contacts._ID}, - null, null, null); - - if (cursor != null && cursor.moveToFirst()) { - return cursor.getLong(0); - } else { - return -1; - } - - } finally { - if (cursor != null) - cursor.close(); - } - } - - private String getLocalNumber() { - return ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)) - .getLine1Number(); - } - - private boolean hasLocalNumber() { - String number = getLocalNumber(); - return (number != null) && (number.trim().length() > 0); - } - - - -} diff --git a/src/org/thoughtcrime/securesms/contacts/ContactIdentityManagerICS.java b/src/org/thoughtcrime/securesms/contacts/ContactIdentityManagerICS.java index c06fc47982..c81bacfd6b 100644 --- a/src/org/thoughtcrime/securesms/contacts/ContactIdentityManagerICS.java +++ b/src/org/thoughtcrime/securesms/contacts/ContactIdentityManagerICS.java @@ -1,6 +1,5 @@ package org.thoughtcrime.securesms.contacts; -import android.annotation.SuppressLint; import android.content.Context; import android.database.Cursor; import android.net.Uri; @@ -17,7 +16,6 @@ class ContactIdentityManagerICS extends ContactIdentityManager { super(context); } - @SuppressLint("NewApi") @Override public Uri getSelfIdentityUri() { String[] PROJECTION = new String[] { @@ -48,7 +46,6 @@ class ContactIdentityManagerICS extends ContactIdentityManager { return true; } - @SuppressLint("NewApi") @Override public List getSelfIdentityRawContactIds() { List results = new LinkedList();