mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 09:17:44 +00:00
Lint error fixes.
* Old Gingerbread code removed. * Add missing super call.
This commit is contained in:
parent
0a8bbf14a6
commit
0cb2404735
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<Long> getSelfIdentityRawContactIds() {
|
||||
long selfIdentityContactId = getSelfIdentityContactId();
|
||||
|
||||
if (selfIdentityContactId == -1)
|
||||
return null;
|
||||
|
||||
Cursor cursor = null;
|
||||
ArrayList<Long> rawContactIds = new ArrayList<Long>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -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<Long> getSelfIdentityRawContactIds() {
|
||||
List<Long> results = new LinkedList<Long>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user