More lint fixes

This commit is contained in:
l3d00m
2015-08-23 21:12:30 +02:00
parent e9743b616a
commit 48b936d7b7
30 changed files with 173 additions and 167 deletions
@@ -2,13 +2,11 @@ package com.moez.QKSMS.common.utils;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.test.AndroidTestCase; import android.test.AndroidTestCase;
import android.util.Log;
import com.moez.QKSMS.ui.MainActivity; import com.moez.QKSMS.ui.MainActivity;
import com.moez.QKSMS.ui.settings.SettingsFragment; import com.moez.QKSMS.ui.settings.SettingsFragment;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Locale;
public class DateFormatterTest extends AndroidTestCase { public class DateFormatterTest extends AndroidTestCase {
protected void setUp() throws Exception { protected void setUp() throws Exception {
@@ -17,9 +15,9 @@ public class DateFormatterTest extends AndroidTestCase {
public void test24Hours(){ public void test24Hours(){
SharedPreferences prefs = MainActivity.getPrefs(getContext()); SharedPreferences prefs = MainActivity.getPrefs(getContext());
prefs.edit().putBoolean(SettingsFragment.TIMESTAMPS_24H, true).commit(); prefs.edit().putBoolean(SettingsFragment.TIMESTAMPS_24H, true).apply();
assertTrue(DateFormatter.accountFor24HourTime(getContext(), new SimpleDateFormat("h:mm a")).equals(new SimpleDateFormat("H:mm"))); assertTrue(DateFormatter.accountFor24HourTime(getContext(), new SimpleDateFormat("h:mm a")).equals(new SimpleDateFormat("H:mm")));
prefs.edit().putBoolean(SettingsFragment.TIMESTAMPS_24H, false).commit(); prefs.edit().putBoolean(SettingsFragment.TIMESTAMPS_24H, false).apply();
} }
public void testDateSymbolsAPI(){ public void testDateSymbolsAPI(){
@@ -29,7 +29,7 @@ import java.lang.annotation.Target;
@Target({ElementType.FIELD}) @Target({ElementType.FIELD})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface SdkConstant { public @interface SdkConstant {
public static enum SdkConstantType { public enum SdkConstantType {
ACTIVITY_INTENT_ACTION, BROADCAST_INTENT_ACTION, SERVICE_ACTION, INTENT_CATEGORY, FEATURE ACTIVITY_INTENT_ACTION, BROADCAST_INTENT_ACTION, SERVICE_ACTION, INTENT_CATEGORY, FEATURE
} }
@@ -90,7 +90,7 @@ public class CountryDetector {
*/ */
public CountryDetector(ICountryDetector service) { public CountryDetector(ICountryDetector service) {
mService = service; mService = service;
mListeners = new HashMap<CountryListener, ListenerTransport>(); mListeners = new HashMap<>();
} }
/** /**
@@ -53,7 +53,7 @@ public class DhcpInfoInternal {
private Collection<RouteInfo> mRoutes; private Collection<RouteInfo> mRoutes;
public DhcpInfoInternal() { public DhcpInfoInternal() {
mRoutes = new ArrayList<RouteInfo>(); mRoutes = new ArrayList<>();
} }
public void addRoute(RouteInfo routeInfo) { public void addRoute(RouteInfo routeInfo) {
@@ -1387,7 +1387,7 @@ public interface IConnectivityManager extends android.os.IInterface {
} }
} }
static final int TRANSACTION_setNetworkPreference = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0); static final int TRANSACTION_setNetworkPreference = (android.os.IBinder.FIRST_CALL_TRANSACTION);
static final int TRANSACTION_getNetworkPreference = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1); static final int TRANSACTION_getNetworkPreference = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
static final int TRANSACTION_getActiveNetworkInfo = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2); static final int TRANSACTION_getActiveNetworkInfo = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2);
static final int TRANSACTION_getActiveNetworkInfoForUid = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3); static final int TRANSACTION_getActiveNetworkInfoForUid = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3);
@@ -125,7 +125,7 @@ public interface INetworkPolicyListener extends android.os.IInterface {
} }
} }
static final int TRANSACTION_onUidRulesChanged = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0); static final int TRANSACTION_onUidRulesChanged = (android.os.IBinder.FIRST_CALL_TRANSACTION);
static final int TRANSACTION_onMeteredIfacesChanged = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1); static final int TRANSACTION_onMeteredIfacesChanged = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
static final int TRANSACTION_onRestrictBackgroundChanged = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2); static final int TRANSACTION_onRestrictBackgroundChanged = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2);
} }
@@ -439,7 +439,7 @@ public interface INetworkPolicyManager extends android.os.IInterface {
} }
} }
static final int TRANSACTION_setUidPolicy = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0); static final int TRANSACTION_setUidPolicy = (android.os.IBinder.FIRST_CALL_TRANSACTION);
static final int TRANSACTION_getUidPolicy = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1); static final int TRANSACTION_getUidPolicy = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
static final int TRANSACTION_getUidsWithPolicy = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2); static final int TRANSACTION_getUidsWithPolicy = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2);
static final int TRANSACTION_isUidForeground = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3); static final int TRANSACTION_isUidForeground = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3);
@@ -199,7 +199,7 @@ public class LinkCapabilities implements Parcelable {
* Constructor * Constructor
*/ */
public LinkCapabilities() { public LinkCapabilities() {
mCapabilities = new HashMap<Integer, String>(); mCapabilities = new HashMap<>();
} }
/** /**
@@ -209,9 +209,9 @@ public class LinkCapabilities implements Parcelable {
*/ */
public LinkCapabilities(LinkCapabilities source) { public LinkCapabilities(LinkCapabilities source) {
if (source != null) { if (source != null) {
mCapabilities = new HashMap<Integer, String>(source.mCapabilities); mCapabilities = new HashMap<>(source.mCapabilities);
} else { } else {
mCapabilities = new HashMap<Integer, String>(); mCapabilities = new HashMap<>();
} }
} }
@@ -356,7 +356,7 @@ public class LinkCapabilities implements Parcelable {
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mCapabilities.size()); dest.writeInt(mCapabilities.size());
for (Entry<Integer, String> entry : mCapabilities.entrySet()) { for (Entry<Integer, String> entry : mCapabilities.entrySet()) {
dest.writeInt(entry.getKey().intValue()); dest.writeInt(entry.getKey());
dest.writeString(entry.getValue()); dest.writeString(entry.getValue());
} }
} }
@@ -52,14 +52,14 @@ import java.util.Collections;
public class LinkProperties implements Parcelable { public class LinkProperties implements Parcelable {
String mIfaceName; String mIfaceName;
private Collection<LinkAddress> mLinkAddresses = new ArrayList<LinkAddress>(); private Collection<LinkAddress> mLinkAddresses = new ArrayList<>();
private Collection<InetAddress> mDnses = new ArrayList<InetAddress>(); private Collection<InetAddress> mDnses = new ArrayList<>();
private Collection<RouteInfo> mRoutes = new ArrayList<RouteInfo>(); private Collection<RouteInfo> mRoutes = new ArrayList<>();
private ProxyProperties mHttpProxy; private ProxyProperties mHttpProxy;
public static class CompareResult<T> { public static class CompareResult<T> {
public Collection<T> removed = new ArrayList<T>(); public Collection<T> removed = new ArrayList<>();
public Collection<T> added = new ArrayList<T>(); public Collection<T> added = new ArrayList<>();
@Override @Override
public String toString() { public String toString() {
@@ -97,7 +97,7 @@ public class LinkProperties implements Parcelable {
} }
public Collection<InetAddress> getAddresses() { public Collection<InetAddress> getAddresses() {
Collection<InetAddress> addresses = new ArrayList<InetAddress>(); Collection<InetAddress> addresses = new ArrayList<>();
for (LinkAddress linkAddress : mLinkAddresses) { for (LinkAddress linkAddress : mLinkAddresses) {
addresses.add(linkAddress.getAddress()); addresses.add(linkAddress.getAddress());
} }
@@ -192,8 +192,7 @@ public class LinkProperties implements Parcelable {
public boolean isIdenticalAddresses(LinkProperties target) { public boolean isIdenticalAddresses(LinkProperties target) {
Collection<InetAddress> targetAddresses = target.getAddresses(); Collection<InetAddress> targetAddresses = target.getAddresses();
Collection<InetAddress> sourceAddresses = getAddresses(); Collection<InetAddress> sourceAddresses = getAddresses();
return (sourceAddresses.size() == targetAddresses.size()) ? return (sourceAddresses.size() == targetAddresses.size()) && sourceAddresses.containsAll(targetAddresses);
sourceAddresses.containsAll(targetAddresses) : false;
} }
/** /**
@@ -275,8 +274,8 @@ public class LinkProperties implements Parcelable {
* are in target but not in mLinkAddresses are placed in the * are in target but not in mLinkAddresses are placed in the
* addedAddresses. * addedAddresses.
*/ */
CompareResult<LinkAddress> result = new CompareResult<LinkAddress>(); CompareResult<LinkAddress> result = new CompareResult<>();
result.removed = new ArrayList<LinkAddress>(mLinkAddresses); result.removed = new ArrayList<>(mLinkAddresses);
result.added.clear(); result.added.clear();
if (target != null) { if (target != null) {
for (LinkAddress newAddress : target.getLinkAddresses()) { for (LinkAddress newAddress : target.getLinkAddresses()) {
@@ -305,9 +304,9 @@ public class LinkProperties implements Parcelable {
* are in target but not in mDnses are placed in the * are in target but not in mDnses are placed in the
* addedAddresses. * addedAddresses.
*/ */
CompareResult<InetAddress> result = new CompareResult<InetAddress>(); CompareResult<InetAddress> result = new CompareResult<>();
result.removed = new ArrayList<InetAddress>(mDnses); result.removed = new ArrayList<>(mDnses);
result.added.clear(); result.added.clear();
if (target != null) { if (target != null) {
for (InetAddress newAddress : target.getDnses()) { for (InetAddress newAddress : target.getDnses()) {
@@ -335,9 +334,9 @@ public class LinkProperties implements Parcelable {
* leaving the routes that are different. And route address which * leaving the routes that are different. And route address which
* are in target but not in mRoutes are placed in added. * are in target but not in mRoutes are placed in added.
*/ */
CompareResult<RouteInfo> result = new CompareResult<RouteInfo>(); CompareResult<RouteInfo> result = new CompareResult<>();
result.removed = new ArrayList<RouteInfo>(mRoutes); result.removed = new ArrayList<>(mRoutes);
result.added.clear(); result.added.clear();
if (target != null) { if (target != null) {
for (RouteInfo r : target.getRoutes()) { for (RouteInfo r : target.getRoutes()) {
@@ -168,17 +168,7 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
@Override @Override
public String toString() { public String toString() {
final StringBuilder builder = new StringBuilder("NetworkPolicy"); return "NetworkPolicy" + "[" + template + "]:" + " cycleDay=" + cycleDay + ", cycleTimezone=" + cycleTimezone + ", warningBytes=" + warningBytes + ", limitBytes=" + limitBytes + ", lastWarningSnooze=" + lastWarningSnooze + ", lastLimitSnooze=" + lastLimitSnooze + ", metered=" + metered + ", inferred=" + inferred;
builder.append("[").append(template).append("]:");
builder.append(" cycleDay=").append(cycleDay);
builder.append(", cycleTimezone=").append(cycleTimezone);
builder.append(", warningBytes=").append(warningBytes);
builder.append(", limitBytes=").append(limitBytes);
builder.append(", lastWarningSnooze=").append(lastWarningSnooze);
builder.append(", lastLimitSnooze=").append(lastLimitSnooze);
builder.append(", metered=").append(metered);
builder.append(", inferred=").append(inferred);
return builder.toString();
} }
public static final Creator<NetworkPolicy> CREATOR = new Creator<NetworkPolicy>() { public static final Creator<NetworkPolicy> CREATOR = new Creator<NetworkPolicy>() {
@@ -153,8 +153,7 @@ public class ProxyProperties implements Parcelable {
return false; return false;
} }
if (mHost != null && p.mHost == null) return false; if (mHost != null && p.mHost == null) return false;
if (mHost == null && p.mHost != null) return false; return !(mHost == null && p.mHost != null) && mPort == p.mPort;
return mPort == p.mPort;
} }
/** /**
@@ -72,11 +72,11 @@ public abstract class ElementTimeImpl implements ElementTime {
String[] beginTimeStringList = mSmilElement.getAttribute("begin").split(";"); String[] beginTimeStringList = mSmilElement.getAttribute("begin").split(";");
// TODO: Check other constraints on parsed values, e.g., "single, non-negative offset values // TODO: Check other constraints on parsed values, e.g., "single, non-negative offset values
ArrayList<Time> beginTimeList = new ArrayList<Time>(); ArrayList<Time> beginTimeList = new ArrayList<>();
// Initialize Time instances and add them to Vector // Initialize Time instances and add them to Vector
for (int i = 0; i < beginTimeStringList.length; i++) { for (String aBeginTimeStringList : beginTimeStringList) {
try { try {
beginTimeList.add(new TimeImpl(beginTimeStringList[i], getBeginConstraints())); beginTimeList.add(new TimeImpl(aBeginTimeStringList, getBeginConstraints()));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// Ignore badly formatted times // Ignore badly formatted times
} }
@@ -121,15 +121,15 @@ public abstract class ElementTimeImpl implements ElementTime {
} }
public TimeList getEnd() { public TimeList getEnd() {
ArrayList<Time> endTimeList = new ArrayList<Time>(); ArrayList<Time> endTimeList = new ArrayList<>();
String[] endTimeStringList = mSmilElement.getAttribute("end").split(";"); String[] endTimeStringList = mSmilElement.getAttribute("end").split(";");
int len = endTimeStringList.length; int len = endTimeStringList.length;
if (!((len == 1) && (endTimeStringList[0].length() == 0))) { // Ensure the end field is set. if (!((len == 1) && (endTimeStringList[0].length() == 0))) { // Ensure the end field is set.
// Initialize Time instances and add them to Vector // Initialize Time instances and add them to Vector
for (int i = 0; i < len; i++) { for (String anEndTimeStringList : endTimeStringList) {
try { try {
endTimeList.add(new TimeImpl(endTimeStringList[i], endTimeList.add(new TimeImpl(anEndTimeStringList,
getEndConstraints())); getEndConstraints()));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// Ignore badly formatted times // Ignore badly formatted times
@@ -245,7 +245,7 @@ public abstract class ElementTimeImpl implements ElementTime {
*/ */
return FILL_AUTO; return FILL_AUTO;
} else { } else {
return ((ElementTimeImpl) parent).getFillDefault(); return parent.getFillDefault();
} }
} }
} }
@@ -156,28 +156,29 @@ public class SmilDocumentImpl extends DocumentImpl implements SMILDocument, Docu
public Element createElement(String tagName) throws DOMException { public Element createElement(String tagName) throws DOMException {
// Find the appropriate class for this element // Find the appropriate class for this element
tagName = tagName.toLowerCase(); tagName = tagName.toLowerCase();
if (tagName.equals("text") || switch (tagName) {
tagName.equals("img") || case "text":
tagName.equals("video")) { case "img":
return new SmilRegionMediaElementImpl(this, tagName); case "video":
} else if (tagName.equals("audio")) { return new SmilRegionMediaElementImpl(this, tagName);
return new SmilMediaElementImpl(this, tagName); case "audio":
} else if (tagName.equals("layout")) { return new SmilMediaElementImpl(this, tagName);
return new SmilLayoutElementImpl(this, tagName); case "layout":
} else if (tagName.equals("root-layout")) { return new SmilLayoutElementImpl(this, tagName);
return new SmilRootLayoutElementImpl(this, tagName); case "root-layout":
} else if (tagName.equals("region")) { return new SmilRootLayoutElementImpl(this, tagName);
return new SmilRegionElementImpl(this, tagName); case "region":
} else if (tagName.equals("ref")) { return new SmilRegionElementImpl(this, tagName);
return new SmilRefElementImpl(this, tagName); case "ref":
} else if (tagName.equals("par")) { return new SmilRefElementImpl(this, tagName);
return new SmilParElementImpl(this, tagName); case "par":
} else if (tagName.equals("vcard")) { return new SmilParElementImpl(this, tagName);
return new SmilRegionMediaElementImpl(this, tagName); case "vcard":
} else { return new SmilRegionMediaElementImpl(this, tagName);
// This includes also the structural nodes SMIL, default:
// HEAD, BODY, for which no specific types are defined. // This includes also the structural nodes SMIL,
return new SmilElementImpl(this, tagName); // HEAD, BODY, for which no specific types are defined.
return new SmilElementImpl(this, tagName);
} }
} }
@@ -44,7 +44,7 @@ public class SmilParElementImpl extends SmilElementImpl implements SMILParElemen
*/ */
TimeList beginTimeList = super.getBegin(); TimeList beginTimeList = super.getBegin();
if (beginTimeList.getLength() > 1) { if (beginTimeList.getLength() > 1) {
ArrayList<Time> singleTimeContainer = new ArrayList<Time>(); ArrayList<Time> singleTimeContainer = new ArrayList<>();
singleTimeContainer.add(beginTimeList.item(0)); singleTimeContainer.add(beginTimeList.item(0));
beginTimeList = new TimeListImpl(singleTimeContainer); beginTimeList = new TimeListImpl(singleTimeContainer);
} }
@@ -46,7 +46,7 @@ public class SmilPlayer implements Runnable {
private static final boolean LOCAL_LOGV = false; private static final boolean LOCAL_LOGV = false;
private static final int TIMESLICE = 200; private static final int TIMESLICE = 200;
private static enum SmilPlayerState { private enum SmilPlayerState {
INITIALIZED, INITIALIZED,
PLAYING, PLAYING,
PLAYED, PLAYED,
@@ -54,7 +54,7 @@ public class SmilPlayer implements Runnable {
STOPPED, STOPPED,
} }
private static enum SmilPlayerAction { private enum SmilPlayerAction {
NO_ACTIVE_ACTION, NO_ACTIVE_ACTION,
RELOAD, RELOAD,
STOP, STOP,
@@ -88,7 +88,7 @@ public class SmilPlayer implements Runnable {
private static ArrayList<TimelineEntry> getParTimeline( private static ArrayList<TimelineEntry> getParTimeline(
ElementParallelTimeContainer par, double offset, double maxOffset) { ElementParallelTimeContainer par, double offset, double maxOffset) {
ArrayList<TimelineEntry> timeline = new ArrayList<TimelineEntry>(); ArrayList<TimelineEntry> timeline = new ArrayList<>();
// Set my begin at first // Set my begin at first
TimeList myBeginList = par.getBegin(); TimeList myBeginList = par.getBegin();
@@ -145,7 +145,7 @@ public class SmilPlayer implements Runnable {
private static ArrayList<TimelineEntry> getSeqTimeline( private static ArrayList<TimelineEntry> getSeqTimeline(
ElementSequentialTimeContainer seq, double offset, double maxOffset) { ElementSequentialTimeContainer seq, double offset, double maxOffset) {
ArrayList<TimelineEntry> timeline = new ArrayList<TimelineEntry>(); ArrayList<TimelineEntry> timeline = new ArrayList<>();
double orgOffset = offset; double orgOffset = offset;
// Set my begin at first // Set my begin at first
@@ -211,7 +211,7 @@ public class SmilPlayer implements Runnable {
return getSeqTimeline((ElementSequentialTimeContainer) element, offset, maxOffset); return getSeqTimeline((ElementSequentialTimeContainer) element, offset, maxOffset);
} else { } else {
// Not ElementTimeContainer here // Not ElementTimeContainer here
ArrayList<TimelineEntry> timeline = new ArrayList<TimelineEntry>(); ArrayList<TimelineEntry> timeline = new ArrayList<>();
TimeList beginList = element.getBegin(); TimeList beginList = element.getBegin();
for (int i = 0; i < beginList.getLength(); ++i) { for (int i = 0; i < beginList.getLength(); ++i) {
@@ -301,7 +301,7 @@ public class SmilPlayer implements Runnable {
mAllEntries = getTimeline(mRoot, 0, Long.MAX_VALUE); mAllEntries = getTimeline(mRoot, 0, Long.MAX_VALUE);
mMediaTimeUpdatedEvent = ((DocumentEvent) mRoot).createEvent("Event"); mMediaTimeUpdatedEvent = ((DocumentEvent) mRoot).createEvent("Event");
mMediaTimeUpdatedEvent.initEvent(MEDIA_TIME_UPDATED_EVENT, false, false); mMediaTimeUpdatedEvent.initEvent(MEDIA_TIME_UPDATED_EVENT, false, false);
mActiveElements = new ArrayList<ElementTime>(); mActiveElements = new ArrayList<>();
} }
public synchronized void play() { public synchronized void play() {
@@ -529,7 +529,7 @@ public class SmilPlayer implements Runnable {
} }
private void stopCurrentSlide() { private void stopCurrentSlide() {
HashSet<TimelineEntry> skippedEntries = new HashSet<TimelineEntry>(); HashSet<TimelineEntry> skippedEntries = new HashSet<>();
int totalEntries = mAllEntries.size(); int totalEntries = mAllEntries.size();
for (int i = mCurrentElement; i < totalEntries; i++) { for (int i = mCurrentElement; i < totalEntries; i++) {
// Stop any started entries, and skip the not started entries until // Stop any started entries, and skip the not started entries until
@@ -64,7 +64,7 @@ public class EndlessJabberInterface {
editor.putString("InterfaceClass", concreteImplementation.getName()); editor.putString("InterfaceClass", concreteImplementation.getName());
editor.putBoolean("SendSMS", sendSMS); editor.putBoolean("SendSMS", sendSMS);
editor.putBoolean("SendMMS", sendMMS); editor.putBoolean("SendMMS", sendMMS);
editor.commit(); editor.apply();
SendInfoToEndlessJabber(context); SendInfoToEndlessJabber(context);
} }
@@ -74,7 +74,7 @@ public class EndlessJabberInterface {
public static void DisableIntegration(Context context, Class nameOfImplementation) { public static void DisableIntegration(Context context, Class nameOfImplementation) {
SharedPreferences.Editor editor = context.getSharedPreferences("EndlessJabberSDK", Context.MODE_PRIVATE).edit(); SharedPreferences.Editor editor = context.getSharedPreferences("EndlessJabberSDK", Context.MODE_PRIVATE).edit();
editor.clear(); editor.clear();
editor.commit(); editor.apply();
SendInfoToEndlessJabber(context); SendInfoToEndlessJabber(context);
} }
@@ -73,7 +73,7 @@ public class CacheManager {
// ignore. // ignore.
} }
if (n != 0) return; if (n != 0) return;
pref.edit().putInt(KEY_CACHE_UP_TO_DATE, 1).commit(); pref.edit().putInt(KEY_CACHE_UP_TO_DATE, 1).apply();
clear(context); clear(context);
} }
@@ -137,8 +137,8 @@ public class ImageCacheService {
public static final long crc64Long(byte[] buffer) { public static final long crc64Long(byte[] buffer) {
long crc = INITIALCRC; long crc = INITIALCRC;
for (int k = 0, n = buffer.length; k < n; ++k) { for (byte aBuffer : buffer) {
crc = sCrcTable[(((int) crc) ^ buffer[k]) & 0xff] ^ (crc >> 8); crc = sCrcTable[(((int) crc) ^ aBuffer) & 0xff] ^ (crc >> 8);
} }
return crc; return crc;
} }
@@ -81,7 +81,7 @@ public class ThumbnailManager extends BackgroundLoaderManager {
public ThumbnailManager(final Context context) { public ThumbnailManager(final Context context) {
super(context); super(context);
mThumbnailCache = new SimpleCache<Uri, Bitmap>(8, 16, 0.75f, true); mThumbnailCache = new SimpleCache<>(8, 16, 0.75f, true);
mContext = context; mContext = context;
mEmptyImageBitmap = BitmapFactory.decodeResource(context.getResources(), mEmptyImageBitmap = BitmapFactory.decodeResource(context.getResources(),
@@ -1247,7 +1247,7 @@ public class ExifInterface {
if (l == null || l.length <= 0) { if (l == null || l.length <= 0) {
return null; return null;
} }
return new Long(l[0]); return Long.valueOf(l[0]);
} }
/** /**
@@ -1266,7 +1266,7 @@ public class ExifInterface {
if (l == null || l.length <= 0) { if (l == null || l.length <= 0) {
return null; return null;
} }
return new Integer(l[0]); return Integer.valueOf(l[0]);
} }
/** /**
@@ -1285,7 +1285,7 @@ public class ExifInterface {
if (l == null || l.length <= 0) { if (l == null || l.length <= 0) {
return null; return null;
} }
return new Byte(l[0]); return Byte.valueOf(l[0]);
} }
/** /**
@@ -95,7 +95,7 @@ public class DeliveryReportHelper {
public List<DeliveryReportItem> getListItems() { public List<DeliveryReportItem> getListItems() {
List<DeliveryReportItem> items = getReportItems(); List<DeliveryReportItem> items = getReportItems();
if (items == null) { if (items == null) {
items = new ArrayList<DeliveryReportItem>(1); items = new ArrayList<>(1);
items.add(new DeliveryReportItem("", mContext.getString(R.string.status_none), null)); items.add(new DeliveryReportItem("", mContext.getString(R.string.status_none), null));
Log.w(LOG_TAG, "cursor == null"); Log.w(LOG_TAG, "cursor == null");
} }
@@ -123,7 +123,7 @@ public class DeliveryReportHelper {
return null; return null;
} }
List<DeliveryReportItem> items = new ArrayList<DeliveryReportItem>(); List<DeliveryReportItem> items = new ArrayList<>();
while (c.moveToNext()) { while (c.moveToNext()) {
// For sent messages with delivery reports, we stick the delivery time in the // For sent messages with delivery reports, we stick the delivery time in the
// date_sent column (see MessageStatusReceiver). // date_sent column (see MessageStatusReceiver).
@@ -191,15 +191,12 @@ public class DeliveryReportHelper {
private static MmsReportStatus queryStatusByRecipient( private static MmsReportStatus queryStatusByRecipient(
Map<String, MmsReportStatus> status, String recipient) { Map<String, MmsReportStatus> status, String recipient) {
Set<String> recipientSet = status.keySet(); Set<String> recipientSet = status.keySet();
Iterator<String> iterator = recipientSet.iterator(); for (String r : recipientSet) {
while (iterator.hasNext()) {
String r = iterator.next();
if (SmsHelper.isEmailAddress(recipient)) { if (SmsHelper.isEmailAddress(recipient)) {
if (TextUtils.equals(r, recipient)) { if (TextUtils.equals(r, recipient)) {
return status.get(r); return status.get(r);
} }
} } else if (PhoneNumberUtils.compare(r, recipient)) {
else if (PhoneNumberUtils.compare(r, recipient)) {
return status.get(r); return status.get(r);
} }
} }
@@ -237,7 +234,7 @@ public class DeliveryReportHelper {
try { try {
Map<String, MmsReportStatus> statusMap = Map<String, MmsReportStatus> statusMap =
new HashMap<String, MmsReportStatus>(); new HashMap<>();
while (c.moveToNext()) { while (c.moveToNext()) {
String recipient = c.getString(COLUMN_RECIPIENT); String recipient = c.getString(COLUMN_RECIPIENT);
@@ -270,7 +267,7 @@ public class DeliveryReportHelper {
return null; return null;
} }
List<MmsReportRequest> reqList = new ArrayList<MmsReportRequest>(); List<MmsReportRequest> reqList = new ArrayList<>();
while (c.moveToNext()) { while (c.moveToNext()) {
reqList.add(new MmsReportRequest( reqList.add(new MmsReportRequest(
c.getString(COLUMN_RECIPIENT), c.getString(COLUMN_RECIPIENT),
@@ -235,7 +235,7 @@ public class QKDialog extends DialogFragment {
} }
public QKDialog buildMenu(final OnItemClickListener onItemClickListener) { public QKDialog buildMenu(final OnItemClickListener onItemClickListener) {
ArrayAdapter adapter = new ArrayAdapter<String>(mContext, R.layout.list_item_simple, mMenuItems); ArrayAdapter adapter = new ArrayAdapter<>(mContext, R.layout.list_item_simple, mMenuItems);
ListView listView = new ListView(mContext); ListView listView = new ListView(mContext);
listView.setAdapter(adapter); listView.setAdapter(adapter);
listView.setDivider(null); listView.setDivider(null);
@@ -256,7 +256,7 @@ public class QKDialog extends DialogFragment {
} }
public QKDialog setItems(String[] items, final OnItemClickListener onClickListener) { public QKDialog setItems(String[] items, final OnItemClickListener onClickListener) {
ArrayAdapter adapter = new ArrayAdapter<String>(mContext, R.layout.list_item_simple, items); ArrayAdapter adapter = new ArrayAdapter<>(mContext, R.layout.list_item_simple, items);
ListView listView = new ListView(mContext); ListView listView = new ListView(mContext);
listView.setAdapter(adapter); listView.setAdapter(adapter);
listView.setDivider(null); listView.setDivider(null);
@@ -301,7 +301,7 @@ public class QKDialogFragment extends DialogFragment {
} }
public QKDialogFragment setItems(String[] items) { public QKDialogFragment setItems(String[] items) {
ArrayAdapter adapter = new ArrayAdapter<String>(mContext, R.layout.list_item_simple, items); ArrayAdapter adapter = new ArrayAdapter<>(mContext, R.layout.list_item_simple, items);
ListView listView = new ListView(mContext); ListView listView = new ListView(mContext);
listView.setAdapter(adapter); listView.setAdapter(adapter);
listView.setDivider(null); listView.setDivider(null);
@@ -383,7 +383,7 @@ public class MessageItem {
// Use constant string for outgoing messages // Use constant string for outgoing messages
mContact = mAddress = mContact = mAddress =
mContext.getString(R.string.messagelist_sender_self); mContext.getString(R.string.messagelist_sender_self);
timestamp = msg == null ? 0 : ((SendReq) msg).getDate() * 1000L; timestamp = msg == null ? 0 : msg.getDate() * 1000L;
} }
SlideModel slide = mSlideshow == null ? null : mSlideshow.get(0); SlideModel slide = mSlideshow == null ? null : mSlideshow.get(0);
@@ -1277,7 +1277,7 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa
protected void onQueryComplete(int token, Object cookie, Cursor cursor) { protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
switch (token) { switch (token) {
case MainActivity.HAVE_LOCKED_MESSAGES_TOKEN: case MainActivity.HAVE_LOCKED_MESSAGES_TOKEN:
if (((MainActivity) mContext).isFinishing()) { if (mContext.isFinishing()) {
Log.w(TAG, "ComposeMessageActivity is finished, do nothing "); Log.w(TAG, "ComposeMessageActivity is finished, do nothing ");
if (cursor != null) { if (cursor != null) {
cursor.close(); cursor.close();
@@ -1316,7 +1316,7 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa
} }
// The last message in this converation was just deleted. Send the user // The last message in this converation was just deleted. Send the user
// to the conversation list. // to the conversation list.
((MainActivity) mContext).showMenu(); mContext.showMenu();
} }
cursor.close(); cursor.close();
} }
@@ -150,7 +150,7 @@ public class SlideshowActivity extends QKActivity implements EventListener {
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
// Play slide-show in full-screen mode. // Play slide-show in full-screen mode.
requestWindowFeature(Window.FEATURE_NO_TITLE); supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(icicle); super.onCreate(icicle);
mHandler = new Handler(); mHandler = new Handler();
@@ -32,7 +32,7 @@ public class SearchFragment extends QKContentFragment implements RecyclerCursorA
// Track which TextView's show which Contact objects so that we can update // Track which TextView's show which Contact objects so that we can update
// appropriately when the Contact gets fully loaded. // appropriately when the Contact gets fully loaded.
private HashMap<Contact, QKTextView> mContactMap = new HashMap<Contact, QKTextView>(); private HashMap<Contact, QKTextView> mContactMap = new HashMap<>();
private Context mContext; private Context mContext;
private SharedPreferences mPrefs; private SharedPreferences mPrefs;
@@ -220,7 +220,7 @@ public class SettingsFragment extends PreferenceFragment implements
// If this is a preference category, make sure to go through all the subpreferences as // If this is a preference category, make sure to go through all the subpreferences as
// well. // well.
if (pref instanceof PreferenceCategory) { if (pref instanceof PreferenceCategory) {
Stack<PreferenceCategory> stack = new Stack<PreferenceCategory>(); Stack<PreferenceCategory> stack = new Stack<>();
stack.push((PreferenceCategory) pref); stack.push((PreferenceCategory) pref);
do { do {
@@ -406,66 +406,88 @@ public class SettingsFragment extends PreferenceFragment implements
valueString valueString
); );
if (key.equals(BACKGROUND)) { switch (key) {
ThemeManager.setTheme(ThemeManager.Theme.fromString((String) newValue)); case BACKGROUND:
} else if (key.equals(STATUS_TINT)) { ThemeManager.setTheme(ThemeManager.Theme.fromString((String) newValue));
ThemeManager.setStatusBarTintEnabled((Boolean) newValue); break;
} else if (key.equals(FONT_FAMILY)) { case STATUS_TINT:
preference.setSummary(mFontFamilies[Integer.parseInt("" + newValue)]); ThemeManager.setStatusBarTintEnabled((Boolean) newValue);
} else if (key.equals(FONT_SIZE)) { break;
preference.setSummary(mFontSizes[Integer.parseInt("" + newValue)]); case FONT_FAMILY:
} else if (key.equals(FONT_WEIGHT)) { preference.setSummary(mFontFamilies[Integer.parseInt("" + newValue)]);
int i = Integer.parseInt("" + newValue); break;
preference.setSummary(mFontWeights[i == 2 ? 0 : 1]); case FONT_SIZE:
} else if (key.equals(COLOUR_SENT)) { preference.setSummary(mFontSizes[Integer.parseInt("" + newValue)]);
ThemeManager.setSentBubbleColored((Boolean) newValue); break;
} else if (key.equals(COLOUR_RECEIVED)) { case FONT_WEIGHT:
ThemeManager.setReceivedBubbleColored((Boolean) newValue); int i = Integer.parseInt("" + newValue);
} else if (key.equals(NIGHT_AUTO)) { preference.setSummary(mFontWeights[i == 2 ? 0 : 1]);
updateAlarmManager(mContext, (Boolean) newValue); break;
} else if (key.equals(DAY_START) || key.equals(NIGHT_START)) { case COLOUR_SENT:
updateAlarmManager(mContext, true); ThemeManager.setSentBubbleColored((Boolean) newValue);
} else if (key.equals(SLIDING_TAB)) { break;
mContext.setSlidingTabEnabled((Boolean) newValue); case COLOUR_RECEIVED:
} else if (key.equals(YAPPY)) { ThemeManager.setReceivedBubbleColored((Boolean) newValue);
if ((Boolean) newValue) { break;
case NIGHT_AUTO:
updateAlarmManager(mContext, (Boolean) newValue);
break;
case DAY_START:
case NIGHT_START:
updateAlarmManager(mContext, true);
break;
case SLIDING_TAB:
mContext.setSlidingTabEnabled((Boolean) newValue);
break;
case YAPPY:
if ((Boolean) newValue) {
try {
EndlessJabberInterface.EnableIntegration(mContext, EndlessJabber.class, true, false);
} catch (Exception e) {
e.printStackTrace();
}
if (!EndlessJabberInterface.IsInstalled(mContext)) {
EndlessJabberInterface.OpenGooglePlayLink(mContext);
}
} else {
try {
EndlessJabberInterface.DisableIntegration(mContext, EndlessJabber.class);
} catch (Exception e) {
e.printStackTrace();
}
}
break;
case QUICKCOMPOSE:
NotificationManager.initQuickCompose(getActivity(), (Boolean) newValue, !(Boolean) newValue);
break;
case MMSC_URL:
case MMS_PROXY:
case MMS_PORT:
preference.setSummary(newValue.toString());
break;
case MAX_MMS_ATTACHMENT_SIZE:
// Update the summary in the list preference
ListPreference listpref = (ListPreference) preference;
int index = listpref.findIndexOfValue((String) newValue);
preference.setSummary(mMaxMmsAttachmentSizes[index]);
// Update the SMS helper static class with the new option
SmsHelper.setMaxAttachmentSizeSetting(mContext, (String) newValue);
break;
case SYSTEM_BAR_FLAT:
ThemeManager.setSystemBarFlatEnabled((Boolean) newValue);
break;
case STATUS_COMPAT:
ThemeManager.setStatusBarTintCompat((Boolean) newValue);
break;
case DELAY_DURATION:
try { try {
EndlessJabberInterface.EnableIntegration(mContext, EndlessJabber.class, true, false); int duration = Integer.parseInt((String) newValue);
if (duration < 1 || duration > 30)
throw new Exception("Duration out of bounds");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); Toast.makeText(mContext, R.string.delayed_duration_bounds_error, Toast.LENGTH_SHORT).show();
} }
if (!EndlessJabberInterface.IsInstalled(mContext)) { break;
EndlessJabberInterface.OpenGooglePlayLink(mContext);
}
} else {
try {
EndlessJabberInterface.DisableIntegration(mContext, EndlessJabber.class);
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (key.equals(QUICKCOMPOSE)) {
NotificationManager.initQuickCompose(getActivity(), (Boolean) newValue, !(Boolean) newValue);
} else if (key.equals(MMSC_URL) || key.equals(MMS_PROXY) || key.equals(MMS_PORT)) {
preference.setSummary(newValue.toString());
} else if (key.equals(MAX_MMS_ATTACHMENT_SIZE)) {
// Update the summary in the list preference
ListPreference listpref = (ListPreference) preference;
int index = listpref.findIndexOfValue((String) newValue);
preference.setSummary(mMaxMmsAttachmentSizes[index]);
// Update the SMS helper static class with the new option
SmsHelper.setMaxAttachmentSizeSetting(mContext, (String) newValue);
} else if (key.equals(SYSTEM_BAR_FLAT)) {
ThemeManager.setSystemBarFlatEnabled((Boolean) newValue);
} else if (key.equals(STATUS_COMPAT)) {
ThemeManager.setStatusBarTintCompat((Boolean) newValue);
} else if (key.equals(DELAY_DURATION)) {
try {
int duration = Integer.parseInt((String) newValue);
if (duration < 1 || duration > 30) throw new Exception("Duration out of bounds");
} catch (Exception e) {
Toast.makeText(mContext, R.string.delayed_duration_bounds_error, Toast.LENGTH_SHORT).show();
}
} }
return true; return true;
@@ -599,7 +621,7 @@ public class SettingsFragment extends PreferenceFragment implements
Set<String> defaultResponses = new HashSet<>(Arrays.asList(mContext.getResources().getStringArray(R.array.qk_responses))); Set<String> defaultResponses = new HashSet<>(Arrays.asList(mContext.getResources().getStringArray(R.array.qk_responses)));
Set<String> responseSet = mPrefs.getStringSet(SettingsFragment.QK_RESPONSES, defaultResponses); Set<String> responseSet = mPrefs.getStringSet(SettingsFragment.QK_RESPONSES, defaultResponses);
ArrayList<String> responses = new ArrayList<String>(); ArrayList<String> responses = new ArrayList<>();
responses.addAll(responseSet); responses.addAll(responseSet);
Collections.sort(responses); Collections.sort(responses);
for (int i = responses.size(); i < 12; i++) { for (int i = responses.size(); i < 12; i++) {
@@ -50,10 +50,10 @@ public class DemoConversationCursorLoader extends Loader<Cursor> {
// First, build a list of all results. Then, filter the results using mSelection and return // First, build a list of all results. Then, filter the results using mSelection and return
// that list. // that list.
ArrayList<MessageData> candidates = new ArrayList<MessageData>(); ArrayList<MessageData> candidates = new ArrayList<>();
if (THREAD_ID_WELCOME_SCREEN == mThreadId) { if (THREAD_ID_WELCOME_SCREEN == mThreadId) {
candidates = new ArrayList<MessageData>(); candidates = new ArrayList<>();
long time = System.currentTimeMillis() - 50000; long time = System.currentTimeMillis() - 50000;
candidates.add(new MessageData( candidates.add(new MessageData(
"sms", 0, mThreadId, "QKSMS", "sms", 0, mThreadId, "QKSMS",
@@ -70,7 +70,7 @@ public class DemoConversationCursorLoader extends Loader<Cursor> {
} }
// Build the actual list based on the selection. // Build the actual list based on the selection.
ArrayList<MessageData> data = new ArrayList<MessageData>(); ArrayList<MessageData> data = new ArrayList<>();
for (MessageData m : candidates) { for (MessageData m : candidates) {
if (!SmsHelper.UNREAD_SELECTION.equals(mSelection) || m.read == 0) { if (!SmsHelper.UNREAD_SELECTION.equals(mSelection) || m.read == 0) {
data.add(m); data.add(m);
@@ -176,6 +176,6 @@ public class WelcomeActivity extends QKActivity implements ViewPager.OnPageChang
SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(this).edit(); SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(this).edit();
prefs.putBoolean(SettingsFragment.WELCOME_SEEN, true); prefs.putBoolean(SettingsFragment.WELCOME_SEEN, true);
prefs.commit(); prefs.apply();
} }
} }