Messaging: Remove unused code

Change-Id: I8093bb3e305ae323f7069bf42f9e83f8c8647cc7
This commit is contained in:
Michael W
2024-12-26 15:54:37 +01:00
parent 0069df879a
commit e29b158fba
69 changed files with 42 additions and 3228 deletions
@@ -38,19 +38,6 @@ public class AccessibilityUtil {
return accessibilityManager.isTouchExplorationEnabled();
}
public static StringBuilder appendContentDescription(final Context context,
final StringBuilder contentDescription, final String val) {
if (sContentDescriptionDivider == null) {
sContentDescriptionDivider =
context.getResources().getString(R.string.enumeration_comma);
}
if (contentDescription.length() != 0) {
contentDescription.append(sContentDescriptionDivider);
}
contentDescription.append(val);
return contentDescription;
}
public static void announceForAccessibilityCompat(
final View view, @Nullable final AccessibilityManager accessibilityManager,
final int textResourceId) {
@@ -18,8 +18,6 @@ package com.android.messaging.util;
import android.os.Looper;
import java.util.Arrays;
public final class Assert {
public @interface RunsOnMainThread {}
public @interface DoesNotRunOnMainThread {}
@@ -46,17 +44,6 @@ public final class Assert {
setIfEngBuild();
}
/**
* Halt execution if this is not an eng build.
* <p>Intended for use in code paths that should be run only for tests and never on
* a real build.
* <p>Note that this will crash on a user build even though asserts don't normally
* crash on a user build.
*/
public static void isEngBuild() {
isTrueReleaseCheck(sIsEngBuild);
}
/**
* Halt execution if this isn't the case.
*/
@@ -75,15 +62,6 @@ public final class Assert {
}
}
/**
* Halt execution even in release builds if this isn't the case.
*/
public static void isTrueReleaseCheck(final boolean condition) {
if (!condition) {
fail("Expected condition to be true", true);
}
}
public static void equals(final int expected, final int actual) {
if (expected != actual) {
fail("Expected " + expected + " but got " + actual, false);
@@ -103,15 +81,6 @@ public final class Assert {
}
}
public static void oneOf(final int actual, final int ...expected) {
for (int value : expected) {
if (actual == value) {
return;
}
}
fail("Expected value to be one of " + Arrays.toString(expected) + " but was " + actual);
}
public static void inRange(
final int val, final int rangeMinInclusive, final int rangeMaxInclusive) {
if (val < rangeMinInclusive || val > rangeMaxInclusive) {
@@ -16,7 +16,6 @@
*/
package com.android.messaging.util;
import android.graphics.Color;
import android.net.Uri;
import android.net.Uri.Builder;
import androidx.annotation.NonNull;
@@ -85,11 +84,6 @@ public class AvatarUriUtil {
public static final Uri DEFAULT_BACKGROUND_AVATAR = new Uri.Builder().scheme(SCHEME)
.authority(AUTHORITY).appendPath(TYPE_DEFAULT_BACKGROUND_URI).build();
private static final Uri BLANK_SIM_INDICATOR_INCOMING_URI = createSimIconUri("",
false /* selected */, Color.TRANSPARENT, true /* incoming */);
private static final Uri BLANK_SIM_INDICATOR_OUTGOING_URI = createSimIconUri("",
false /* selected */, Color.TRANSPARENT, false /* incoming */);
/**
* Creates an avatar uri based on a list of ParticipantData. The list of participants may not
* be null or empty. Depending on the size of the list either a group avatar uri will be create
@@ -217,10 +211,6 @@ public class AvatarUriUtil {
return builder.build();
}
public static Uri getBlankSimIndicatorUri(final boolean incoming) {
return incoming ? BLANK_SIM_INDICATOR_INCOMING_URI : BLANK_SIM_INDICATOR_OUTGOING_URI;
}
/**
* Creates an avatar uri from the given local resource Uri, followed by a fallback Uri in case
* the local resource one could not be loaded.
@@ -36,8 +36,6 @@ import com.android.messaging.ui.conversationlist.ConversationListActivity;
*/
public class BugleActivityUtil {
private static final int REQUEST_GOOGLE_PLAY_SERVICES = 0;
/**
* Determine if the requirements for the app to run are met. Log any Activity startup
* analytics.
@@ -1,112 +0,0 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS 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.messaging.util;
/**
* Very simple circular array implementation.
*
* @param <E> The element type of this list.
* @LibraryInternal
*/
public class CircularArray<E> {
private int mNextWriter;
private boolean mHasWrapped;
private final int mMaxCount;
Object mList[];
/**
* Constructor for CircularArray.
*
* @param count Max elements to hold in the list.
*/
public CircularArray(int count) {
mMaxCount = count;
clear();
}
/**
* Reset the list.
*/
public void clear() {
mNextWriter = 0;
mHasWrapped = false;
mList = new Object[mMaxCount];
}
/**
* Add an element to the end of the list.
*
* @param object The object to add.
*/
public void add(E object) {
mList[mNextWriter] = object;
++mNextWriter;
if (mNextWriter == mMaxCount) {
mNextWriter = 0;
mHasWrapped = true;
}
}
/**
* Get the number of elements in the list. This will be 0 <= returned count <= max count
*
* @return Elements in the circular list.
*/
public int count() {
if (mHasWrapped) {
return mMaxCount;
} else {
return mNextWriter;
}
}
/**
* Return null if the list hasn't wrapped yet. Otherwise return the next object that would be
* overwritten. Can be useful to avoid extra allocations.
*
* @return
*/
@SuppressWarnings("unchecked")
public E getFree() {
if (!mHasWrapped) {
return null;
} else {
return (E) mList[mNextWriter];
}
}
/**
* Get the object at index. Index 0 is the oldest item inserted into the list. Index (count() -
* 1) is the newest.
*
* @param index Index to retrieve.
* @return Object at index.
*/
@SuppressWarnings("unchecked")
public E get(int index) {
if (mHasWrapped) {
int wrappedIndex = index + mNextWriter;
if (wrappedIndex >= mMaxCount) {
wrappedIndex -= mMaxCount;
}
return (E) mList[wrappedIndex];
} else {
return (E) mList[index];
}
}
}
@@ -45,10 +45,6 @@ public class ConnectivityUtil {
.createForSubscriptionId(subId);
}
public int getCurrentServiceState() {
return mCurrentServiceState;
}
private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
@Override
public void onServiceStateChanged(final ServiceState serviceState) {
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +24,6 @@ import com.android.ex.chips.RecipientEntry;
import com.android.messaging.Factory;
import com.android.messaging.R;
import com.android.messaging.datamodel.BugleRecipientEntry;
import com.android.messaging.datamodel.data.ParticipantData;
/**
* Provides utility methods around creating RecipientEntry instance specific to Bugle's needs.
@@ -105,11 +105,4 @@ public class ContactRecipientEntryUtils {
public static boolean isSendToDestinationContact(final RecipientEntry entry) {
return entry.getContactId() == CONTACT_ID_SENDTO_DESTINATION;
}
/**
* Returns true if the given participant is a special send to number item.
*/
public static boolean isSendToDestinationContact(final ParticipantData participant) {
return participant.getContactId() == CONTACT_ID_SENDTO_DESTINATION;
}
}
@@ -58,30 +58,19 @@ public final class ContentType {
public static final String IMAGE_PNG = "image/png";
public static final String IMAGE_X_MS_BMP = "image/x-ms-bmp";
public static final String AUDIO_UNSPECIFIED = "audio/*";
public static final String AUDIO_AAC = "audio/aac";
public static final String AUDIO_AMR = "audio/amr";
public static final String AUDIO_IMELODY = "audio/imelody";
public static final String AUDIO_MID = "audio/mid";
public static final String AUDIO_MIDI = "audio/midi";
public static final String AUDIO_MP3 = "audio/mp3";
public static final String AUDIO_MPEG3 = "audio/mpeg3";
public static final String AUDIO_MPEG = "audio/mpeg";
public static final String AUDIO_MPG = "audio/mpg";
public static final String AUDIO_MP4 = "audio/mp4";
public static final String AUDIO_MP4_LATM = "audio/mp4-latm";
public static final String AUDIO_X_MID = "audio/x-mid";
public static final String AUDIO_X_MIDI = "audio/x-midi";
public static final String AUDIO_X_MP3 = "audio/x-mp3";
public static final String AUDIO_X_MPEG3 = "audio/x-mpeg3";
public static final String AUDIO_X_MPEG = "audio/x-mpeg";
public static final String AUDIO_X_MPG = "audio/x-mpg";
public static final String AUDIO_3GPP = "audio/3gpp";
public static final String AUDIO_X_WAV = "audio/x-wav";
public static final String AUDIO_OGG = "application/ogg";
public static final String MULTIPART_MIXED = "multipart/mixed";
public static final String VIDEO_UNSPECIFIED = "video/*";
public static final String VIDEO_3GP = "video/3gp";
public static final String VIDEO_3GPP = "video/3gpp";
@@ -95,10 +84,6 @@ public final class ContentType {
public static final String APP_SMIL = "application/smil";
public static final String APP_WAP_XHTML = "application/vnd.wap.xhtml+xml";
public static final String APP_XHTML = "application/xhtml+xml";
public static final String APP_DRM_CONTENT = "application/vnd.oma.drm.content";
public static final String APP_DRM_MESSAGE = "application/vnd.oma.drm.message";
// This class should never be instantiated.
private ContentType() {
@@ -136,16 +121,6 @@ public final class ContentType {
|| contentType.equalsIgnoreCase(TEXT_VCARD));
}
public static boolean isDrmType(final String contentType) {
return (null != contentType)
&& (contentType.equals(APP_DRM_CONTENT)
|| contentType.equals(APP_DRM_MESSAGE));
}
public static boolean isUnspecified(final String contentType) {
return (null != contentType) && contentType.endsWith("*");
}
/**
* If the content type is a type which can be displayed in the conversation list as a preview.
*/
@@ -25,7 +25,6 @@ import android.text.TextUtils;
import com.android.messaging.Factory;
import com.android.messaging.R;
import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
@@ -71,55 +70,6 @@ public class FileUtil {
return getNewFile(directory, fileExtension, fileNameFormat);
}
/** Delete everything below and including root */
public static void removeFileOrDirectory(File root) {
removeFileOrDirectoryExcept(root, null);
}
/** Delete everything below and including root except for the given file */
public static void removeFileOrDirectoryExcept(File root, File exclude) {
if (root.exists()) {
if (root.isDirectory()) {
for (File file : root.listFiles()) {
if (exclude == null || !file.equals(exclude)) {
removeFileOrDirectoryExcept(file, exclude);
}
}
root.delete();
} else if (root.isFile()) {
root.delete();
}
}
}
/**
* Move all files and folders under a directory into the target.
*/
public static void moveAllContentUnderDirectory(File sourceDir, File targetDir) {
if (sourceDir.isDirectory() && targetDir.isDirectory()) {
if (isSameOrSubDirectory(sourceDir, targetDir)) {
LogUtil.e(LogUtil.BUGLE_TAG, "Can't move directory content since the source " +
"directory is a parent of the target");
return;
}
for (File file : sourceDir.listFiles()) {
if (file.isDirectory()) {
final File dirTarget = new File(targetDir, file.getName());
dirTarget.mkdirs();
moveAllContentUnderDirectory(file, dirTarget);
} else {
try {
final File fileTarget = new File(targetDir, file.getName());
Files.move(file, fileTarget);
} catch (IOException e) {
LogUtil.e(LogUtil.BUGLE_TAG, "Failed to move files", e);
// Try proceed with the next file.
}
}
}
}
}
// Checks if the file is in /data, and don't allow any app to send personal information.
// We're told it's possible to create world readable hardlinks to other apps private data
// so we ban all /data file uris.
@@ -35,7 +35,6 @@ import android.net.Uri;
import android.provider.MediaStore;
import androidx.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import com.android.messaging.Factory;
import com.android.messaging.datamodel.MediaScratchFileProvider;
@@ -169,15 +168,6 @@ public class ImageUtils {
}
}
/**
* Sets a drawable to the background of a view. setBackgroundDrawable() is deprecated since
* JB and replaced by setBackground().
*/
@SuppressWarnings("deprecation")
public static void setBackgroundDrawableOnView(final View view, final Drawable drawable) {
view.setBackground(drawable);
}
/**
* Based on the input bitmap bounds given by BitmapFactory.Options, compute the required
* sub-sampling size for loading a scaled down version of the bitmap to the required size
@@ -1,60 +0,0 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS 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.messaging.util;
import androidx.collection.LongSparseArray;
/**
* A space saving set for long values using v4 compat LongSparseArray
*/
public class LongSparseSet {
private static final Object THE_ONLY_VALID_VALUE = new Object();
private final LongSparseArray<Object> mSet = new LongSparseArray<>();
public LongSparseSet() {
}
/**
* @param key The element to check
* @return True if the element is in the set, false otherwise
*/
public boolean contains(long key) {
if (mSet.get(key, null/*default*/) == THE_ONLY_VALID_VALUE) {
return true;
}
return false;
}
/**
* Add an element to the set
*
* @param key The element to add
*/
public void add(long key) {
mSet.put(key, THE_ONLY_VALID_VALUE);
}
/**
* Remove an element from the set
*
* @param key The element to remove
*/
public void remove(long key) {
mSet.delete(key);
}
}
@@ -1,27 +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.messaging.util;
public class MaterialPalette{
public final int mPrimaryColor;
public final int mSecondaryColor;
public MaterialPalette(final int primaryColor, final int secondaryColor) {
mPrimaryColor = primaryColor;
mSecondaryColor = secondaryColor;
}
}
@@ -23,18 +23,4 @@ public class PendingIntentConstants {
public static final int SMS_NOTIFICATION_ID = 0;
public static final int SMS_SECONDARY_USER_NOTIFICATION_ID = 1;
public static final int MSG_SEND_ERROR = 2;
// Request codes
public static final int UPDATE_NOTIFICATIONS_ALARM_ACTION_ID = 100;
public static final int MIN_ASSIGNED_REQUEST_CODE = 1001;
// Logging
private static final String TAG = LogUtil.BUGLE_TAG;
private static final boolean VERBOSE = false;
// Internal Constants
private static final String NOTIFICATION_REQUEST_CODE_PREFS = "notificationRequestCodes.v1";
private static final String REQUEST_CODE_DELIMITER = "|";
private static final String MAX_REQUEST_CODE_KEY = "maxRequestCode";
}
@@ -105,15 +105,6 @@ public class PhoneUtils {
return null;
}
/**
* Get number of SIM slots
*
* @return the SIM slot count
*/
public int getSimSlotCount() {
return mSubscriptionManager.getActiveSubscriptionInfoCountMax();
}
/**
* Get SIM's carrier name
*
@@ -134,15 +125,6 @@ public class PhoneUtils {
return null;
}
/**
* Check if there is SIM inserted on the device
*
* @return true if there is SIM inserted, false otherwise
*/
public boolean hasSim() {
return mSubscriptionManager.getActiveSubscriptionInfoCount() > 0;
}
/**
* Check if the SIM is roaming
*
@@ -168,16 +150,6 @@ public class PhoneUtils {
return new int[]{mcc, mnc};
}
/**
* Get the mcc/mnc string
*
* @return the text of mccmnc string
*/
public String getSimOperatorNumeric() {
// For L_MR1 we return the canonicalized (xxxxxx) string
return getMccMncString(getMccMnc());
}
/**
* Get the SIM's self raw number, i.e. not canonicalized
*
@@ -581,39 +553,6 @@ public class PhoneUtils {
return getCanonicalBySimLocale(selfNumber);
}
/**
* Get the SIM's phone number in NATIONAL format with only digits, used in sending
* as LINE1NOCOUNTRYCODE macro in mms_config
*
* @return all digits national format number of the SIM
*/
public String getSimNumberNoCountryCode() {
String selfNumber = null;
try {
selfNumber = getSelfRawNumber(false/*allowOverride*/);
} catch (IllegalStateException e) {
// continue
}
if (selfNumber == null) {
selfNumber = "";
}
final String country = getSimCountry();
final PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
try {
final PhoneNumber phoneNumber = phoneNumberUtil.parse(selfNumber, country);
if (phoneNumber != null && phoneNumberUtil.isValidNumber(phoneNumber)) {
return phoneNumberUtil
.format(phoneNumber, PhoneNumberFormat.NATIONAL)
.replaceAll("\\D", "");
}
} catch (final NumberParseException e) {
LogUtil.e(TAG, "PhoneUtils.getSimNumberNoCountryCode(): Not able to parse phone number "
+ LogUtil.sanitizePII(selfNumber) + " for country " + country);
}
return selfNumber;
}
/**
* Format a phone number for displaying, using system locale country.
* If the country code matches between the system locale and the input phone number,
@@ -1,129 +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.messaging.util;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import androidx.appcompat.graphics.drawable.DrawableWrapperCompat;
import androidx.appcompat.widget.SwitchCompat;
import android.util.TypedValue;
/* Most methods in this file are copied from
* v7/appcompat/src/androidx.appcompat.internal/widget/TintManager.java. It would be better if
* we could have just extended the TintManager but this is a final class that we do not have
* access to. */
/**
* Util methods for the SwitchCompat widget
*/
public class SwitchCompatUtils {
/**
* Given a color and a SwitchCompat view, updates the SwitchCompat to appear with the appropiate
* color when enabled and checked
*/
public static void updateSwitchCompatColor(SwitchCompat switchCompat, final int color) {
final Context context = switchCompat.getContext();
final TypedValue typedValue = new TypedValue();
switchCompat.setThumbDrawable(getColorTintedDrawable(switchCompat.getThumbDrawable(),
getSwitchThumbColorStateList(context, color, typedValue),
PorterDuff.Mode.MULTIPLY));
switchCompat.setTrackDrawable(getColorTintedDrawable(switchCompat.getTrackDrawable(),
getSwitchTrackColorStateList(context, color, typedValue), PorterDuff.Mode.SRC_IN));
}
private static Drawable getColorTintedDrawable(Drawable oldDrawable,
final ColorStateList colorStateList, final PorterDuff.Mode mode) {
final int[] thumbState = oldDrawable.isStateful() ? oldDrawable.getState() : null;
if (oldDrawable instanceof DrawableWrapperCompat) {
oldDrawable = ((DrawableWrapperCompat) oldDrawable).getDrawable();
}
final Drawable newDrawable = new TintDrawableWrapper(oldDrawable, colorStateList, mode);
if (thumbState != null) {
newDrawable.setState(thumbState);
}
return newDrawable;
}
private static ColorStateList getSwitchThumbColorStateList(final Context context,
final int color, final TypedValue typedValue) {
final int[][] states = new int[3][];
final int[] colors = new int[3];
int i = 0;
// Disabled state
states[i] = new int[] { -android.R.attr.state_enabled };
colors[i] = getColor(Color.parseColor("#ffbdbdbd"), 1f);
i++;
states[i] = new int[] { android.R.attr.state_checked };
colors[i] = color;
i++;
// Default enabled state
states[i] = new int[0];
colors[i] = getThemeAttrColor(context, typedValue,
androidx.appcompat.R.attr.colorSwitchThumbNormal);
i++;
return new ColorStateList(states, colors);
}
private static ColorStateList getSwitchTrackColorStateList(final Context context,
final int color, final TypedValue typedValue) {
final int[][] states = new int[3][];
final int[] colors = new int[3];
int i = 0;
// Disabled state
states[i] = new int[] { -android.R.attr.state_enabled };
colors[i] = getThemeAttrColor(context, typedValue, android.R.attr.colorForeground, 0.1f);
i++;
states[i] = new int[] { android.R.attr.state_checked };
colors[i] = getColor(color, 0.3f);
i++;
// Default enabled state
states[i] = new int[0];
colors[i] = getThemeAttrColor(context, typedValue, android.R.attr.colorForeground, 0.3f);
i++;
return new ColorStateList(states, colors);
}
private static int getThemeAttrColor(final Context context, final TypedValue typedValue,
final int attr) {
if (context.getTheme().resolveAttribute(attr, typedValue, true)) {
if (typedValue.type >= TypedValue.TYPE_FIRST_INT
&& typedValue.type <= TypedValue.TYPE_LAST_INT) {
return typedValue.data;
} else if (typedValue.type == TypedValue.TYPE_STRING) {
return context.getResources().getColor(typedValue.resourceId);
}
}
return 0;
}
private static int getThemeAttrColor(final Context context, final TypedValue typedValue,
final int attr, final float alpha) {
final int color = getThemeAttrColor(context, typedValue, attr);
return getColor(color, alpha);
}
private static int getColor(int color, float alpha) {
final int originalAlpha = Color.alpha(color);
// Return the color, multiplying the original alpha by the disabled value
return (color & 0x00ffffff) | (Math.round(originalAlpha * alpha) << 24);
}
}
+3 -105
View File
@@ -20,22 +20,12 @@ package com.android.messaging.util;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.text.Html;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.style.URLSpan;
import android.view.Gravity;
import android.view.Surface;
import android.view.View;
import android.view.View.OnLayoutChangeListener;
import android.view.animation.Animation;
@@ -45,16 +35,17 @@ import android.view.animation.ScaleAnimation;
import android.widget.RemoteViews;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.messaging.Factory;
import com.android.messaging.R;
import com.android.messaging.ui.SnackBar;
import com.android.messaging.ui.SnackBar.Placement;
import com.android.messaging.ui.conversationlist.ConversationListActivity;
import com.android.messaging.ui.SnackBarInteraction;
import com.android.messaging.ui.SnackBarManager;
import com.android.messaging.ui.UIIntents;
import java.lang.reflect.Field;
import java.util.List;
public class UiUtils {
@@ -62,10 +53,6 @@ public class UiUtils {
public static final int MEDIAPICKER_TRANSITION_DURATION =
getApplicationContext().getResources().getInteger(
R.integer.mediapicker_transition_duration);
/** Short transition duration in ms */
public static final int ASYNCIMAGE_TRANSITION_DURATION =
getApplicationContext().getResources().getInteger(
R.integer.asyncimage_transition_duration);
/** Compose transition duration in ms */
public static final int COMPOSE_TRANSITION_DURATION =
getApplicationContext().getResources().getInteger(
@@ -272,34 +259,6 @@ public class UiUtils {
Color.rgb(blendedRed, blendedGreen, blendedBlue));
}
public static void lockOrientation(final Activity activity) {
final int orientation = activity.getResources().getConfiguration().orientation;
final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
// rotation tracks the rotation of the device from its natural orientation
// orientation tracks whether the screen is landscape or portrait.
// It is possible to have a rotation of 0 (device in its natural orientation) in portrait
// (phone), or in landscape (tablet), so we have to check both values to determine what to
// pass to setRequestedOrientation.
if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) {
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
} else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) {
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
}
}
}
public static void unlockOrientation(final Activity activity) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
public static boolean isRtlMode() {
return Factory.get().getApplicationContext().getResources()
.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
@@ -350,67 +309,6 @@ public class UiUtils {
return phoneUtils.isDefaultSmsApp();
}
/*
* Removes all html markup from the text and replaces links with the the text and a text version
* of the href.
* @param htmlText HTML markup text
* @return Sanitized string with link hrefs inlined
*/
public static String stripHtml(final String htmlText) {
final StringBuilder result = new StringBuilder();
final Spanned markup = Html.fromHtml(htmlText);
final String strippedText = markup.toString();
final URLSpan[] links = markup.getSpans(0, markup.length() - 1, URLSpan.class);
int currentIndex = 0;
for (final URLSpan link : links) {
final int spanStart = markup.getSpanStart(link);
final int spanEnd = markup.getSpanEnd(link);
if (spanStart > currentIndex) {
result.append(strippedText, currentIndex, spanStart);
}
final String displayText = strippedText.substring(spanStart, spanEnd);
final String linkText = link.getURL();
result.append(getApplicationContext().getString(R.string.link_display_format,
displayText, linkText));
currentIndex = spanEnd;
}
if (strippedText.length() > currentIndex) {
result.append(strippedText, currentIndex, strippedText.length());
}
return result.toString();
}
public static void setActionBarShadowVisibility(final AppCompatActivity activity, final boolean visible) {
final ActionBar actionBar = activity.getSupportActionBar();
actionBar.setElevation(visible ?
activity.getResources().getDimensionPixelSize(R.dimen.action_bar_elevation) :
0);
final View actionBarView = activity.getWindow().getDecorView().findViewById(
androidx.appcompat.R.id.decor_content_parent);
if (actionBarView != null) {
// AppCompatActionBar has one drawable Field, which is the shadow for the action bar
// set the alpha on that drawable manually
final Field[] fields = actionBarView.getClass().getDeclaredFields();
try {
for (final Field field : fields) {
if (field.getType().equals(Drawable.class)) {
field.setAccessible(true);
final Drawable shadowDrawable = (Drawable) field.get(actionBarView);
if (shadowDrawable != null) {
shadowDrawable.setAlpha(visible ? 255 : 0);
actionBarView.invalidate();
return;
}
}
}
} catch (final IllegalAccessException ex) {
// Not expected, we should avoid this via field.setAccessible(true) above
LogUtil.e(LogUtil.BUGLE_TAG, "Error setting shadow visibility", ex);
}
}
}
/**
* Get the activity that's hosting the view, typically casting view.getContext() as an Activity
* is sufficient, but sometimes the context is a context wrapper, in which case we need to case