summaryrefslogtreecommitdiff
path: root/java/com/android/contacts/common/util
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/contacts/common/util')
-rw-r--r--java/com/android/contacts/common/util/AccountFilterUtil.java42
-rw-r--r--java/com/android/contacts/common/util/BitmapUtil.java167
-rw-r--r--java/com/android/contacts/common/util/ContactDisplayUtils.java12
-rw-r--r--java/com/android/contacts/common/util/DateUtils.java241
-rw-r--r--java/com/android/contacts/common/util/MaterialColorMapUtils.java8
-rw-r--r--java/com/android/contacts/common/util/NameConverter.java242
-rw-r--r--java/com/android/contacts/common/util/StopWatch.java28
-rw-r--r--java/com/android/contacts/common/util/TelephonyManagerUtils.java9
-rw-r--r--java/com/android/contacts/common/util/TrafficStatsTags.java22
-rw-r--r--java/com/android/contacts/common/util/UriUtils.java90
10 files changed, 7 insertions, 854 deletions
diff --git a/java/com/android/contacts/common/util/AccountFilterUtil.java b/java/com/android/contacts/common/util/AccountFilterUtil.java
index 18743c65e..25f937c5e 100644
--- a/java/com/android/contacts/common/util/AccountFilterUtil.java
+++ b/java/com/android/contacts/common/util/AccountFilterUtil.java
@@ -16,35 +16,15 @@
package com.android.contacts.common.util;
-import android.app.Activity;
import android.content.Context;
-import android.content.Intent;
-import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.android.contacts.common.R;
import com.android.contacts.common.list.ContactListFilter;
-import com.android.contacts.common.list.ContactListFilterController;
/** Utility class for account filter manipulation. */
public class AccountFilterUtil {
- public static final String EXTRA_CONTACT_LIST_FILTER = "contactListFilter";
- private static final String TAG = AccountFilterUtil.class.getSimpleName();
-
- /**
- * Find TextView with the id "account_filter_header" and set correct text for the account filter
- * header.
- *
- * @param filterContainer View containing TextView with id "account_filter_header"
- * @return true when header text is set in the call. You may use this for conditionally showing or
- * hiding this entire view.
- */
- public static boolean updateAccountFilterTitleForPeople(
- View filterContainer, ContactListFilter filter, boolean showTitleForAllAccounts) {
- return updateAccountFilterTitle(filterContainer, filter, showTitleForAllAccounts, false);
- }
-
/**
* Similar to {@link #updateAccountFilterTitleForPeople(View, ContactListFilter, boolean,
* boolean)}, but for Phone UI.
@@ -78,8 +58,6 @@ public class AccountFilterUtil {
} else if (filter.filterType == ContactListFilter.FILTER_TYPE_CUSTOM) {
headerTextView.setText(R.string.listCustomView);
textWasSet = true;
- } else {
- Log.w(TAG, "Filter type \"" + filter.filterType + "\" isn't expected.");
}
} else {
if (filter.filterType == ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS) {
@@ -97,29 +75,9 @@ public class AccountFilterUtil {
} else if (filter.filterType == ContactListFilter.FILTER_TYPE_SINGLE_CONTACT) {
headerTextView.setText(R.string.listSingleContact);
textWasSet = true;
- } else {
- Log.w(TAG, "Filter type \"" + filter.filterType + "\" isn't expected.");
}
}
- } else {
- Log.w(TAG, "Filter is null.");
}
return textWasSet;
}
-
- /** This will update filter via a given ContactListFilterController. */
- public static void handleAccountFilterResult(
- ContactListFilterController filterController, int resultCode, Intent data) {
- if (resultCode == Activity.RESULT_OK) {
- final ContactListFilter filter = data.getParcelableExtra(EXTRA_CONTACT_LIST_FILTER);
- if (filter == null) {
- return;
- }
- if (filter.filterType == ContactListFilter.FILTER_TYPE_CUSTOM) {
- filterController.selectCustomFilter();
- } else {
- filterController.setContactListFilter(filter, true);
- }
- }
- }
}
diff --git a/java/com/android/contacts/common/util/BitmapUtil.java b/java/com/android/contacts/common/util/BitmapUtil.java
deleted file mode 100644
index 20f916a3f..000000000
--- a/java/com/android/contacts/common/util/BitmapUtil.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.contacts.common.util;
-
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PorterDuff.Mode;
-import android.graphics.PorterDuffXfermode;
-import android.graphics.Rect;
-import android.graphics.RectF;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
-
-/** Provides static functions to decode bitmaps at the optimal size */
-public class BitmapUtil {
-
- private BitmapUtil() {}
-
- /**
- * Returns Width or Height of the picture, depending on which size is smaller. Doesn't actually
- * decode the picture, so it is pretty efficient to run.
- */
- public static int getSmallerExtentFromBytes(byte[] bytes) {
- final BitmapFactory.Options options = new BitmapFactory.Options();
-
- // don't actually decode the picture, just return its bounds
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
-
- // test what the best sample size is
- return Math.min(options.outWidth, options.outHeight);
- }
-
- /**
- * Finds the optimal sampleSize for loading the picture
- *
- * @param originalSmallerExtent Width or height of the picture, whichever is smaller
- * @param targetExtent Width or height of the target view, whichever is bigger.
- * <p>If either one of the parameters is 0 or smaller, no sampling is applied
- */
- public static int findOptimalSampleSize(int originalSmallerExtent, int targetExtent) {
- // If we don't know sizes, we can't do sampling.
- if (targetExtent < 1) {
- return 1;
- }
- if (originalSmallerExtent < 1) {
- return 1;
- }
-
- // Test what the best sample size is. To do that, we find the sample size that gives us
- // the best trade-off between resulting image size and memory requirement. We allow
- // the down-sampled image to be 20% smaller than the target size. That way we can get around
- // unfortunate cases where e.g. a 720 picture is requested for 362 and not down-sampled at
- // all. Why 20%? Why not. Prove me wrong.
- int extent = originalSmallerExtent;
- int sampleSize = 1;
- while ((extent >> 1) >= targetExtent * 0.8f) {
- sampleSize <<= 1;
- extent >>= 1;
- }
-
- return sampleSize;
- }
-
- /** Decodes the bitmap with the given sample size */
- public static Bitmap decodeBitmapFromBytes(byte[] bytes, int sampleSize) {
- final BitmapFactory.Options options;
- if (sampleSize <= 1) {
- options = null;
- } else {
- options = new BitmapFactory.Options();
- options.inSampleSize = sampleSize;
- }
- return BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
- }
-
- /**
- * Retrieves a copy of the specified drawable resource, rotated by a specified angle.
- *
- * @param resources The current resources.
- * @param resourceId The resource ID of the drawable to rotate.
- * @param angle The angle of rotation.
- * @return Rotated drawable.
- */
- public static Drawable getRotatedDrawable(
- android.content.res.Resources resources, int resourceId, float angle) {
-
- // Get the original drawable and make a copy which will be rotated.
- Bitmap original = BitmapFactory.decodeResource(resources, resourceId);
- Bitmap rotated =
- Bitmap.createBitmap(original.getWidth(), original.getHeight(), Bitmap.Config.ARGB_8888);
-
- // Perform the rotation.
- Canvas tempCanvas = new Canvas(rotated);
- tempCanvas.rotate(angle, original.getWidth() / 2, original.getHeight() / 2);
- tempCanvas.drawBitmap(original, 0, 0, null);
-
- return new BitmapDrawable(resources, rotated);
- }
-
- /**
- * Given an input bitmap, scales it to the given width/height and makes it round.
- *
- * @param input {@link Bitmap} to scale and crop
- * @param targetWidth desired output width
- * @param targetHeight desired output height
- * @return output bitmap scaled to the target width/height and cropped to an oval. The cropping
- * algorithm will try to fit as much of the input into the output as possible, while
- * preserving the target width/height ratio.
- */
- public static Bitmap getRoundedBitmap(Bitmap input, int targetWidth, int targetHeight) {
- if (input == null) {
- return null;
- }
- final Bitmap.Config inputConfig = input.getConfig();
- final Bitmap result =
- Bitmap.createBitmap(
- targetWidth, targetHeight, inputConfig != null ? inputConfig : Bitmap.Config.ARGB_8888);
- final Canvas canvas = new Canvas(result);
- final Paint paint = new Paint();
- canvas.drawARGB(0, 0, 0, 0);
- paint.setAntiAlias(true);
- final RectF dst = new RectF(0, 0, targetWidth, targetHeight);
- canvas.drawOval(dst, paint);
-
- // Specifies that only pixels present in the destination (i.e. the drawn oval) should
- // be overwritten with pixels from the input bitmap.
- paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
-
- final int inputWidth = input.getWidth();
- final int inputHeight = input.getHeight();
-
- // Choose the largest scale factor that will fit inside the dimensions of the
- // input bitmap.
- final float scaleBy =
- Math.min((float) inputWidth / targetWidth, (float) inputHeight / targetHeight);
-
- final int xCropAmountHalved = (int) (scaleBy * targetWidth / 2);
- final int yCropAmountHalved = (int) (scaleBy * targetHeight / 2);
-
- final Rect src =
- new Rect(
- inputWidth / 2 - xCropAmountHalved,
- inputHeight / 2 - yCropAmountHalved,
- inputWidth / 2 + xCropAmountHalved,
- inputHeight / 2 + yCropAmountHalved);
-
- canvas.drawBitmap(input, src, dst, paint);
- return result;
- }
-}
diff --git a/java/com/android/contacts/common/util/ContactDisplayUtils.java b/java/com/android/contacts/common/util/ContactDisplayUtils.java
index 1586784db..ff22f2880 100644
--- a/java/com/android/contacts/common/util/ContactDisplayUtils.java
+++ b/java/com/android/contacts/common/util/ContactDisplayUtils.java
@@ -16,21 +16,20 @@
package com.android.contacts.common.util;
-import static android.provider.ContactsContract.CommonDataKinds.Phone;
-
import android.content.Context;
import android.content.res.Resources;
+import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.TtsSpan;
-import android.util.Log;
import android.util.Patterns;
import com.android.contacts.common.R;
import com.android.contacts.common.compat.PhoneNumberUtilsCompat;
import com.android.contacts.common.preference.ContactsPreferences;
+import com.android.dialer.common.LogUtil;
import java.util.Objects;
/** Methods for handling various contact data labels. */
@@ -38,7 +37,6 @@ public class ContactDisplayUtils {
public static final int INTERACTION_CALL = 1;
public static final int INTERACTION_SMS = 2;
- private static final String TAG = ContactDisplayUtils.class.getSimpleName();
/**
* Checks if the given data type is a custom type.
@@ -74,9 +72,9 @@ public class ContactDisplayUtils {
} else {
resId = getPhoneLabelResourceId(type);
if (interactionType != INTERACTION_CALL) {
- Log.e(
- TAG,
- "Un-recognized interaction type: "
+ LogUtil.e(
+ "ContactDisplayUtils.getLabelForCallOrSms",
+ "un-recognized interaction type: "
+ interactionType
+ ". Defaulting to ContactDisplayUtils.INTERACTION_CALL.");
}
diff --git a/java/com/android/contacts/common/util/DateUtils.java b/java/com/android/contacts/common/util/DateUtils.java
index 1935d727a..09d52bce8 100644
--- a/java/com/android/contacts/common/util/DateUtils.java
+++ b/java/com/android/contacts/common/util/DateUtils.java
@@ -16,252 +16,11 @@
package com.android.contacts.common.util;
-import android.content.Context;
-import android.text.format.DateFormat;
import android.text.format.Time;
-import java.text.ParsePosition;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.Locale;
-import java.util.TimeZone;
/** Utility methods for processing dates. */
public class DateUtils {
- public static final TimeZone UTC_TIMEZONE = TimeZone.getTimeZone("UTC");
-
- /**
- * When parsing a date without a year, the system assumes 1970, which wasn't a leap-year. Let's
- * add a one-off hack for that day of the year
- */
- public static final String NO_YEAR_DATE_FEB29TH = "--02-29";
-
- // Variations of ISO 8601 date format. Do not change the order - it does affect the
- // result in ambiguous cases.
- private static final SimpleDateFormat[] DATE_FORMATS = {
- CommonDateUtils.FULL_DATE_FORMAT,
- CommonDateUtils.DATE_AND_TIME_FORMAT,
- new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'", Locale.US),
- new SimpleDateFormat("yyyyMMdd", Locale.US),
- new SimpleDateFormat("yyyyMMdd'T'HHmmssSSS'Z'", Locale.US),
- new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.US),
- new SimpleDateFormat("yyyyMMdd'T'HHmm'Z'", Locale.US),
- };
-
- static {
- for (SimpleDateFormat format : DATE_FORMATS) {
- format.setLenient(true);
- format.setTimeZone(UTC_TIMEZONE);
- }
- CommonDateUtils.NO_YEAR_DATE_FORMAT.setTimeZone(UTC_TIMEZONE);
- }
-
- /**
- * Parses the supplied string to see if it looks like a date.
- *
- * @param string The string representation of the provided date
- * @param mustContainYear If true, the string is parsed as a date containing a year. If false, the
- * string is parsed into a valid date even if the year field is missing.
- * @return A Calendar object corresponding to the date if the string is successfully parsed. If
- * not, null is returned.
- */
- public static Calendar parseDate(String string, boolean mustContainYear) {
- ParsePosition parsePosition = new ParsePosition(0);
- Date date;
- if (!mustContainYear) {
- final boolean noYearParsed;
- // Unfortunately, we can't parse Feb 29th correctly, so let's handle this day seperately
- if (NO_YEAR_DATE_FEB29TH.equals(string)) {
- return getUtcDate(0, Calendar.FEBRUARY, 29);
- } else {
- synchronized (CommonDateUtils.NO_YEAR_DATE_FORMAT) {
- date = CommonDateUtils.NO_YEAR_DATE_FORMAT.parse(string, parsePosition);
- }
- noYearParsed = parsePosition.getIndex() == string.length();
- }
-
- if (noYearParsed) {
- return getUtcDate(date, true);
- }
- }
- for (int i = 0; i < DATE_FORMATS.length; i++) {
- SimpleDateFormat f = DATE_FORMATS[i];
- synchronized (f) {
- parsePosition.setIndex(0);
- date = f.parse(string, parsePosition);
- if (parsePosition.getIndex() == string.length()) {
- return getUtcDate(date, false);
- }
- }
- }
- return null;
- }
-
- private static final Calendar getUtcDate(Date date, boolean noYear) {
- final Calendar calendar = Calendar.getInstance(UTC_TIMEZONE, Locale.US);
- calendar.setTime(date);
- if (noYear) {
- calendar.set(Calendar.YEAR, 0);
- }
- return calendar;
- }
-
- private static final Calendar getUtcDate(int year, int month, int dayOfMonth) {
- final Calendar calendar = Calendar.getInstance(UTC_TIMEZONE, Locale.US);
- calendar.clear();
- calendar.set(Calendar.YEAR, year);
- calendar.set(Calendar.MONTH, month);
- calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
- return calendar;
- }
-
- public static boolean isYearSet(Calendar cal) {
- // use the Calendar.YEAR field to track whether or not the year is set instead of
- // Calendar.isSet() because doing Calendar.get() causes Calendar.isSet() to become
- // true irregardless of what the previous value was
- return cal.get(Calendar.YEAR) > 1;
- }
-
- /**
- * Same as {@link #formatDate(Context context, String string, boolean longForm)}, with longForm
- * set to {@code true} by default.
- *
- * @param context Valid context
- * @param string String representation of a date to parse
- * @return Returns the same date in a cleaned up format. If the supplied string does not look like
- * a date, return it unchanged.
- */
- public static String formatDate(Context context, String string) {
- return formatDate(context, string, true);
- }
-
- /**
- * Parses the supplied string to see if it looks like a date.
- *
- * @param context Valid context
- * @param string String representation of a date to parse
- * @param longForm If true, return the date formatted into its long string representation. If
- * false, return the date formatted using its short form representation (i.e. 12/11/2012)
- * @return Returns the same date in a cleaned up format. If the supplied string does not look like
- * a date, return it unchanged.
- */
- public static String formatDate(Context context, String string, boolean longForm) {
- if (string == null) {
- return null;
- }
-
- string = string.trim();
- if (string.length() == 0) {
- return string;
- }
- final Calendar cal = parseDate(string, false);
-
- // we weren't able to parse the string successfully so just return it unchanged
- if (cal == null) {
- return string;
- }
-
- final boolean isYearSet = isYearSet(cal);
- final java.text.DateFormat outFormat;
- if (!isYearSet) {
- outFormat = getLocalizedDateFormatWithoutYear(context);
- } else {
- outFormat =
- longForm ? DateFormat.getLongDateFormat(context) : DateFormat.getDateFormat(context);
- }
- synchronized (outFormat) {
- outFormat.setTimeZone(UTC_TIMEZONE);
- return outFormat.format(cal.getTime());
- }
- }
-
- public static boolean isMonthBeforeDay(Context context) {
- char[] dateFormatOrder = DateFormat.getDateFormatOrder(context);
- for (int i = 0; i < dateFormatOrder.length; i++) {
- if (dateFormatOrder[i] == 'd') {
- return false;
- }
- if (dateFormatOrder[i] == 'M') {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Returns a SimpleDateFormat object without the year fields by using a regular expression to
- * eliminate the year in the string pattern. In the rare occurence that the resulting pattern
- * cannot be reconverted into a SimpleDateFormat, it uses the provided context to determine
- * whether the month field should be displayed before the day field, and returns either "MMMM dd"
- * or "dd MMMM" converted into a SimpleDateFormat.
- */
- public static java.text.DateFormat getLocalizedDateFormatWithoutYear(Context context) {
- final String pattern =
- ((SimpleDateFormat) SimpleDateFormat.getDateInstance(java.text.DateFormat.LONG))
- .toPattern();
- // Determine the correct regex pattern for year.
- // Special case handling for Spanish locale by checking for "de"
- final String yearPattern =
- pattern.contains("de") ? "[^Mm]*[Yy]+[^Mm]*" : "[^DdMm]*[Yy]+[^DdMm]*";
- try {
- // Eliminate the substring in pattern that matches the format for that of year
- return new SimpleDateFormat(pattern.replaceAll(yearPattern, ""));
- } catch (IllegalArgumentException e) {
- return new SimpleDateFormat(DateUtils.isMonthBeforeDay(context) ? "MMMM dd" : "dd MMMM");
- }
- }
-
- /**
- * Given a calendar (possibly containing only a day of the year), returns the earliest possible
- * anniversary of the date that is equal to or after the current point in time if the date does
- * not contain a year, or the date converted to the local time zone (if the date contains a year.
- *
- * @param target The date we wish to convert(in the UTC time zone).
- * @return If date does not contain a year (year < 1900), returns the next earliest anniversary
- * that is after the current point in time (in the local time zone). Otherwise, returns the
- * adjusted Date in the local time zone.
- */
- public static Date getNextAnnualDate(Calendar target) {
- final Calendar today = Calendar.getInstance();
- today.setTime(new Date());
-
- // Round the current time to the exact start of today so that when we compare
- // today against the target date, both dates are set to exactly 0000H.
- today.set(Calendar.HOUR_OF_DAY, 0);
- today.set(Calendar.MINUTE, 0);
- today.set(Calendar.SECOND, 0);
- today.set(Calendar.MILLISECOND, 0);
-
- final boolean isYearSet = isYearSet(target);
- final int targetYear = target.get(Calendar.YEAR);
- final int targetMonth = target.get(Calendar.MONTH);
- final int targetDay = target.get(Calendar.DAY_OF_MONTH);
- final boolean isFeb29 = (targetMonth == Calendar.FEBRUARY && targetDay == 29);
- final GregorianCalendar anniversary = new GregorianCalendar();
- // Convert from the UTC date to the local date. Set the year to today's year if the
- // there is no provided year (targetYear < 1900)
- anniversary.set(!isYearSet ? today.get(Calendar.YEAR) : targetYear, targetMonth, targetDay);
- // If the anniversary's date is before the start of today and there is no year set,
- // increment the year by 1 so that the returned date is always equal to or greater than
- // today. If the day is a leap year, keep going until we get the next leap year anniversary
- // Otherwise if there is already a year set, simply return the exact date.
- if (!isYearSet) {
- int anniversaryYear = today.get(Calendar.YEAR);
- if (anniversary.before(today) || (isFeb29 && !anniversary.isLeapYear(anniversaryYear))) {
- // If the target date is not Feb 29, then set the anniversary to the next year.
- // Otherwise, keep going until we find the next leap year (this is not guaranteed
- // to be in 4 years time).
- do {
- anniversaryYear += 1;
- } while (isFeb29 && !anniversary.isLeapYear(anniversaryYear));
- anniversary.set(anniversaryYear, targetMonth, targetDay);
- }
- }
- return anniversary.getTime();
- }
-
/**
* Determine the difference, in days between two dates. Uses similar logic as the {@link
* android.text.format.DateUtils.getRelativeTimeSpanString} method.
diff --git a/java/com/android/contacts/common/util/MaterialColorMapUtils.java b/java/com/android/contacts/common/util/MaterialColorMapUtils.java
index a2d9847ec..bd32faa51 100644
--- a/java/com/android/contacts/common/util/MaterialColorMapUtils.java
+++ b/java/com/android/contacts/common/util/MaterialColorMapUtils.java
@@ -21,7 +21,6 @@ import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Trace;
-import com.android.contacts.common.R;
public class MaterialColorMapUtils {
@@ -35,13 +34,6 @@ public class MaterialColorMapUtils {
resources.obtainTypedArray(com.android.contacts.common.R.array.letter_tile_colors_dark);
}
- public static MaterialPalette getDefaultPrimaryAndSecondaryColors(Resources resources) {
- final int primaryColor = resources.getColor(R.color.quickcontact_default_photo_tint_color);
- final int secondaryColor =
- resources.getColor(R.color.quickcontact_default_photo_tint_color_dark);
- return new MaterialPalette(primaryColor, secondaryColor);
- }
-
/**
* Returns the hue component of a color int.
*
diff --git a/java/com/android/contacts/common/util/NameConverter.java b/java/com/android/contacts/common/util/NameConverter.java
deleted file mode 100644
index ae3275d14..000000000
--- a/java/com/android/contacts/common/util/NameConverter.java
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.contacts.common.util;
-
-import android.content.ContentValues;
-import android.content.Context;
-import android.database.Cursor;
-import android.net.Uri;
-import android.net.Uri.Builder;
-import android.provider.ContactsContract;
-import android.provider.ContactsContract.CommonDataKinds.StructuredName;
-import android.text.TextUtils;
-import com.android.contacts.common.model.dataitem.StructuredNameDataItem;
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- * Utility class for converting between a display name and structured name (and vice-versa), via
- * calls to the contact provider.
- */
-public class NameConverter {
-
- /** The array of fields that comprise a structured name. */
- public static final String[] STRUCTURED_NAME_FIELDS =
- new String[] {
- StructuredName.PREFIX,
- StructuredName.GIVEN_NAME,
- StructuredName.MIDDLE_NAME,
- StructuredName.FAMILY_NAME,
- StructuredName.SUFFIX
- };
-
- /**
- * Converts the given structured name (provided as a map from {@link StructuredName} fields to
- * corresponding values) into a display name string.
- *
- * <p>Note that this operates via a call back to the ContactProvider, but it does not access the
- * database, so it should be safe to call from the UI thread. See ContactsProvider2.completeName()
- * for the underlying method call.
- *
- * @param context Activity context.
- * @param structuredName The structured name map to convert.
- * @return The display name computed from the structured name map.
- */
- public static String structuredNameToDisplayName(
- Context context, Map<String, String> structuredName) {
- Builder builder = ContactsContract.AUTHORITY_URI.buildUpon().appendPath("complete_name");
- for (String key : STRUCTURED_NAME_FIELDS) {
- if (structuredName.containsKey(key)) {
- appendQueryParameter(builder, key, structuredName.get(key));
- }
- }
- return fetchDisplayName(context, builder.build());
- }
-
- /**
- * Converts the given structured name (provided as ContentValues) into a display name string.
- *
- * @param context Activity context.
- * @param values The content values containing values comprising the structured name.
- */
- public static String structuredNameToDisplayName(Context context, ContentValues values) {
- Builder builder = ContactsContract.AUTHORITY_URI.buildUpon().appendPath("complete_name");
- for (String key : STRUCTURED_NAME_FIELDS) {
- if (values.containsKey(key)) {
- appendQueryParameter(builder, key, values.getAsString(key));
- }
- }
- return fetchDisplayName(context, builder.build());
- }
-
- /** Helper method for fetching the display name via the given URI. */
- private static String fetchDisplayName(Context context, Uri uri) {
- String displayName = null;
- Cursor cursor =
- context
- .getContentResolver()
- .query(
- uri,
- new String[] {
- StructuredName.DISPLAY_NAME,
- },
- null,
- null,
- null);
-
- if (cursor != null) {
- try {
- if (cursor.moveToFirst()) {
- displayName = cursor.getString(0);
- }
- } finally {
- cursor.close();
- }
- }
- return displayName;
- }
-
- /**
- * Converts the given display name string into a structured name (as a map from {@link
- * StructuredName} fields to corresponding values).
- *
- * <p>Note that this operates via a call back to the ContactProvider, but it does not access the
- * database, so it should be safe to call from the UI thread.
- *
- * @param context Activity context.
- * @param displayName The display name to convert.
- * @return The structured name map computed from the display name.
- */
- public static Map<String, String> displayNameToStructuredName(
- Context context, String displayName) {
- Map<String, String> structuredName = new TreeMap<String, String>();
- Builder builder = ContactsContract.AUTHORITY_URI.buildUpon().appendPath("complete_name");
-
- appendQueryParameter(builder, StructuredName.DISPLAY_NAME, displayName);
- Cursor cursor =
- context
- .getContentResolver()
- .query(builder.build(), STRUCTURED_NAME_FIELDS, null, null, null);
-
- if (cursor != null) {
- try {
- if (cursor.moveToFirst()) {
- for (int i = 0; i < STRUCTURED_NAME_FIELDS.length; i++) {
- structuredName.put(STRUCTURED_NAME_FIELDS[i], cursor.getString(i));
- }
- }
- } finally {
- cursor.close();
- }
- }
- return structuredName;
- }
-
- /**
- * Converts the given display name string into a structured name (inserting the structured values
- * into a new or existing ContentValues object).
- *
- * <p>Note that this operates via a call back to the ContactProvider, but it does not access the
- * database, so it should be safe to call from the UI thread.
- *
- * @param context Activity context.
- * @param displayName The display name to convert.
- * @param contentValues The content values object to place the structured name values into. If
- * null, a new one will be created and returned.
- * @return The ContentValues object containing the structured name fields derived from the display
- * name.
- */
- public static ContentValues displayNameToStructuredName(
- Context context, String displayName, ContentValues contentValues) {
- if (contentValues == null) {
- contentValues = new ContentValues();
- }
- Map<String, String> mapValues = displayNameToStructuredName(context, displayName);
- for (String key : mapValues.keySet()) {
- contentValues.put(key, mapValues.get(key));
- }
- return contentValues;
- }
-
- private static void appendQueryParameter(Builder builder, String field, String value) {
- if (!TextUtils.isEmpty(value)) {
- builder.appendQueryParameter(field, value);
- }
- }
-
- /**
- * Parses phonetic name and returns parsed data (family, middle, given) as ContentValues. Parsed
- * data should be {@link StructuredName#PHONETIC_FAMILY_NAME}, {@link
- * StructuredName#PHONETIC_MIDDLE_NAME}, and {@link StructuredName#PHONETIC_GIVEN_NAME}. If this
- * method cannot parse given phoneticName, null values will be stored.
- *
- * @param phoneticName Phonetic name to be parsed
- * @param values ContentValues to be used for storing data. If null, new instance will be created.
- * @return ContentValues with parsed data. Those data can be null.
- */
- public static StructuredNameDataItem parsePhoneticName(
- String phoneticName, StructuredNameDataItem item) {
- String family = null;
- String middle = null;
- String given = null;
-
- if (!TextUtils.isEmpty(phoneticName)) {
- String[] strings = phoneticName.split(" ", 3);
- switch (strings.length) {
- case 1:
- family = strings[0];
- break;
- case 2:
- family = strings[0];
- given = strings[1];
- break;
- case 3:
- family = strings[0];
- middle = strings[1];
- given = strings[2];
- break;
- }
- }
-
- if (item == null) {
- item = new StructuredNameDataItem();
- }
- item.setPhoneticFamilyName(family);
- item.setPhoneticMiddleName(middle);
- item.setPhoneticGivenName(given);
- return item;
- }
-
- /** Constructs and returns a phonetic full name from given parts. */
- public static String buildPhoneticName(String family, String middle, String given) {
- if (!TextUtils.isEmpty(family) || !TextUtils.isEmpty(middle) || !TextUtils.isEmpty(given)) {
- StringBuilder sb = new StringBuilder();
- if (!TextUtils.isEmpty(family)) {
- sb.append(family.trim()).append(' ');
- }
- if (!TextUtils.isEmpty(middle)) {
- sb.append(middle.trim()).append(' ');
- }
- if (!TextUtils.isEmpty(given)) {
- sb.append(given.trim()).append(' ');
- }
- sb.setLength(sb.length() - 1); // Yank the last space
- return sb.toString();
- } else {
- return null;
- }
- }
-}
diff --git a/java/com/android/contacts/common/util/StopWatch.java b/java/com/android/contacts/common/util/StopWatch.java
index b944b9867..7986d1081 100644
--- a/java/com/android/contacts/common/util/StopWatch.java
+++ b/java/com/android/contacts/common/util/StopWatch.java
@@ -16,7 +16,7 @@
package com.android.contacts.common.util;
-import android.util.Log;
+import com.android.dialer.common.LogUtil;
import java.util.ArrayList;
/** A {@link StopWatch} records start, laps and stop, and print them to logcat. */
@@ -37,11 +37,6 @@ public class StopWatch {
return new StopWatch(label);
}
- /** Return a dummy instance that does no operations. */
- public static StopWatch getNullStopWatch() {
- return NullStopWatch.INSTANCE;
- }
-
/** Record a lap. */
public void lap(String lapLabel) {
mTimes.add(System.currentTimeMillis());
@@ -76,25 +71,6 @@ public class StopWatch {
sb.append(" ");
last = current;
}
- Log.v(TAG, sb.toString());
- }
-
- private static class NullStopWatch extends StopWatch {
-
- public static final NullStopWatch INSTANCE = new NullStopWatch();
-
- public NullStopWatch() {
- super(null);
- }
-
- @Override
- public void lap(String lapLabel) {
- // noop
- }
-
- @Override
- public void stopAndLog(String TAG, int timeThresholdToLog) {
- // noop
- }
+ LogUtil.v(TAG, sb.toString());
}
}
diff --git a/java/com/android/contacts/common/util/TelephonyManagerUtils.java b/java/com/android/contacts/common/util/TelephonyManagerUtils.java
index b664268ca..e4c2c6373 100644
--- a/java/com/android/contacts/common/util/TelephonyManagerUtils.java
+++ b/java/com/android/contacts/common/util/TelephonyManagerUtils.java
@@ -33,13 +33,4 @@ public class TelephonyManagerUtils {
final String voiceMailLabel = telephonyManager.getVoiceMailAlphaTag();
return voiceMailLabel;
}
-
- /**
- * @param context Current application context.
- * @return True if there is a subscription which supports video calls. False otherwise.
- */
- public static boolean hasVideoCallSubscription(Context context) {
- // TODO: Check the telephony manager's subscriptions to see if any support video calls.
- return true;
- }
}
diff --git a/java/com/android/contacts/common/util/TrafficStatsTags.java b/java/com/android/contacts/common/util/TrafficStatsTags.java
deleted file mode 100644
index b0e7fb583..000000000
--- a/java/com/android/contacts/common/util/TrafficStatsTags.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.contacts.common.util;
-
-public class TrafficStatsTags {
-
- public static final int CONTACT_PHOTO_DOWNLOAD_TAG = 0x0001;
- public static final int TAG_MAX = 0x9999;
-}
diff --git a/java/com/android/contacts/common/util/UriUtils.java b/java/com/android/contacts/common/util/UriUtils.java
deleted file mode 100644
index 4690942ba..000000000
--- a/java/com/android/contacts/common/util/UriUtils.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.contacts.common.util;
-
-import android.net.Uri;
-import android.provider.ContactsContract;
-import java.util.List;
-
-/** Utility methods for dealing with URIs. */
-public class UriUtils {
-
- /** Static helper, not instantiable. */
- private UriUtils() {}
-
- /** Checks whether two URI are equal, taking care of the case where either is null. */
- public static boolean areEqual(Uri uri1, Uri uri2) {
- if (uri1 == null && uri2 == null) {
- return true;
- }
- if (uri1 == null || uri2 == null) {
- return false;
- }
- return uri1.equals(uri2);
- }
-
- /** Parses a string into a URI and returns null if the given string is null. */
- public static Uri parseUriOrNull(String uriString) {
- if (uriString == null) {
- return null;
- }
- return Uri.parse(uriString);
- }
-
- /** Converts a URI into a string, returns null if the given URI is null. */
- public static String uriToString(Uri uri) {
- return uri == null ? null : uri.toString();
- }
-
- public static boolean isEncodedContactUri(Uri uri) {
- if (uri == null) {
- return false;
- }
- final String lastPathSegment = uri.getLastPathSegment();
- if (lastPathSegment == null) {
- return false;
- }
- return lastPathSegment.equals(Constants.LOOKUP_URI_ENCODED);
- }
-
- /**
- * @return {@code uri} as-is if the authority is of contacts provider. Otherwise or {@code uri} is
- * null, return null otherwise
- */
- public static Uri nullForNonContactsUri(Uri uri) {
- if (uri == null) {
- return null;
- }
- return ContactsContract.AUTHORITY.equals(uri.getAuthority()) ? uri : null;
- }
-
- /** Parses the given URI to determine the original lookup key of the contact. */
- public static String getLookupKeyFromUri(Uri lookupUri) {
- // Would be nice to be able to persist the lookup key somehow to avoid having to parse
- // the uri entirely just to retrieve the lookup key, but every uri is already parsed
- // once anyway to check if it is an encoded JSON uri, so this has negligible effect
- // on performance.
- if (lookupUri != null && !UriUtils.isEncodedContactUri(lookupUri)) {
- final List<String> segments = lookupUri.getPathSegments();
- // This returns the third path segment of the uri, where the lookup key is located.
- // See {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}.
- return (segments.size() < 3) ? null : Uri.encode(segments.get(2));
- } else {
- return null;
- }
- }
-}