manually including the im.dlg:android-dialer:1.2.5

- avoids using appcompat
- avoids using an artifact without a source repository
This commit is contained in:
Adam Brown 2022-09-15 14:18:11 +01:00
parent 8bfe7b68c3
commit 5058f942af
468 changed files with 2431 additions and 2 deletions

View file

@ -0,0 +1,24 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
compileSdk versions.compileSdk
defaultConfig {
minSdk versions.minSdk
targetSdk versions.targetSdk
}
compileOptions {
sourceCompatibility versions.sourceCompat
targetCompatibility versions.targetCompat
}
kotlinOptions {
jvmTarget = "11"
}
}
dependencies {
implementation "com.android.support:appcompat-v7:28.0.0"
}

View file

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.android.dialer.dialpadview" />

View file

@ -0,0 +1,26 @@
/*
* Copyright (C) 2014 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.dialer.animation;
import android.view.animation.Interpolator;
import com.android.dialer.compat.PathInterpolatorCompat;
public class AnimUtils {
public static final Interpolator EASE_OUT_EASE_IN =
PathInterpolatorCompat.create(0.4f, 0, 0.2f, 1);
}

View file

@ -0,0 +1,120 @@
/*
* 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.dialer.compat;
import android.graphics.Path;
import android.graphics.PathMeasure;
import android.os.Build;
import android.view.animation.Interpolator;
import android.view.animation.PathInterpolator;
public class PathInterpolatorCompat {
public static Interpolator create(
float controlX1, float controlY1, float controlX2, float controlY2) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return new PathInterpolator(controlX1, controlY1, controlX2, controlY2);
}
return new PathInterpolatorBase(controlX1, controlY1, controlX2, controlY2);
}
private static class PathInterpolatorBase implements Interpolator {
/** Governs the accuracy of the approximation of the {@link Path}. */
private static final float PRECISION = 0.002f;
private final float[] mX;
private final float[] mY;
public PathInterpolatorBase(Path path) {
final PathMeasure pathMeasure = new PathMeasure(path, false /* forceClosed */);
final float pathLength = pathMeasure.getLength();
final int numPoints = (int) (pathLength / PRECISION) + 1;
mX = new float[numPoints];
mY = new float[numPoints];
final float[] position = new float[2];
for (int i = 0; i < numPoints; ++i) {
final float distance = (i * pathLength) / (numPoints - 1);
pathMeasure.getPosTan(distance, position, null /* tangent */);
mX[i] = position[0];
mY[i] = position[1];
}
}
public PathInterpolatorBase(float controlX, float controlY) {
this(createQuad(controlX, controlY));
}
public PathInterpolatorBase(
float controlX1, float controlY1, float controlX2, float controlY2) {
this(createCubic(controlX1, controlY1, controlX2, controlY2));
}
private static Path createQuad(float controlX, float controlY) {
final Path path = new Path();
path.moveTo(0.0f, 0.0f);
path.quadTo(controlX, controlY, 1.0f, 1.0f);
return path;
}
private static Path createCubic(
float controlX1, float controlY1, float controlX2, float controlY2) {
final Path path = new Path();
path.moveTo(0.0f, 0.0f);
path.cubicTo(controlX1, controlY1, controlX2, controlY2, 1.0f, 1.0f);
return path;
}
@Override
public float getInterpolation(float t) {
if (t <= 0.0f) {
return 0.0f;
} else if (t >= 1.0f) {
return 1.0f;
}
// Do a binary search for the correct x to interpolate between.
int startIndex = 0;
int endIndex = mX.length - 1;
while (endIndex - startIndex > 1) {
int midIndex = (startIndex + endIndex) / 2;
if (t < mX[midIndex]) {
endIndex = midIndex;
} else {
startIndex = midIndex;
}
}
final float xRange = mX[endIndex] - mX[startIndex];
if (xRange == 0) {
return mY[startIndex];
}
final float tInRange = t - mX[startIndex];
final float fraction = tInRange / xRange;
final float startY = mY[startIndex];
final float endY = mY[endIndex];
return startY + (fraction * (endY - startY));
}
}
}

View file

@ -0,0 +1,231 @@
/*
* 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.dialer.dialpadview;
import android.content.Context;
import android.graphics.RectF;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.FrameLayout;
/**
* Custom class for dialpad buttons.
*
* <p>When touch exploration mode is enabled for accessibility, this class implements the
* lift-to-type interaction model:
*
* <ul>
* <li>Hovering over the button will cause it to gain accessibility focus
* <li>Removing the hover pointer while inside the bounds of the button will perform a click action
* <li>If long-click is supported, hovering over the button for a longer period of time will switch
* to the long-click action
* <li>Moving the hover pointer outside of the bounds of the button will restore to the normal click
* action
* </ul>
*/
public class DialpadKeyButton extends FrameLayout {
/** Timeout before switching to long-click accessibility mode. */
private static final int LONG_HOVER_TIMEOUT = ViewConfiguration.getLongPressTimeout() * 2;
/** Accessibility manager instance used to check touch exploration state. */
private AccessibilityManager mAccessibilityManager;
/** Bounds used to filter HOVER_EXIT events. */
private RectF mHoverBounds = new RectF();
/** Whether this view is currently in the long-hover state. */
private boolean mLongHovered;
/** Alternate content description for long-hover state. */
private CharSequence mLongHoverContentDesc;
/** Backup of standard content description. Used for accessibility. */
private CharSequence mBackupContentDesc;
/** Backup of clickable property. Used for accessibility. */
private boolean mWasClickable;
/** Backup of long-clickable property. Used for accessibility. */
private boolean mWasLongClickable;
/** Runnable used to trigger long-click mode for accessibility. */
private Runnable mLongHoverRunnable;
private OnPressedListener mOnPressedListener;
public DialpadKeyButton(Context context, AttributeSet attrs) {
super(context, attrs);
initForAccessibility(context);
}
public DialpadKeyButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initForAccessibility(context);
}
public void setOnPressedListener(OnPressedListener onPressedListener) {
mOnPressedListener = onPressedListener;
}
private void initForAccessibility(Context context) {
mAccessibilityManager =
(AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
}
public void setLongHoverContentDescription(CharSequence contentDescription) {
mLongHoverContentDesc = contentDescription;
if (mLongHovered) {
super.setContentDescription(mLongHoverContentDesc);
}
}
@Override
public void setContentDescription(CharSequence contentDescription) {
if (mLongHovered) {
mBackupContentDesc = contentDescription;
} else {
super.setContentDescription(contentDescription);
}
}
@Override
public void setPressed(boolean pressed) {
super.setPressed(pressed);
if (mOnPressedListener != null) {
mOnPressedListener.onPressed(this, pressed);
}
}
@Override
public void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mHoverBounds.left = getPaddingLeft();
mHoverBounds.right = w - getPaddingRight();
mHoverBounds.top = getPaddingTop();
mHoverBounds.bottom = h - getPaddingBottom();
}
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
if (action == AccessibilityNodeInfo.ACTION_CLICK) {
simulateClickForAccessibility();
return true;
}
return super.performAccessibilityAction(action, arguments);
}
@Override
public boolean onHoverEvent(MotionEvent event) {
// When touch exploration is turned on, lifting a finger while inside
// the button's hover target bounds should perform a click action.
if (mAccessibilityManager.isEnabled() && mAccessibilityManager.isTouchExplorationEnabled()) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_HOVER_ENTER:
// Lift-to-type temporarily disables double-tap activation.
mWasClickable = isClickable();
mWasLongClickable = isLongClickable();
if (mWasLongClickable && mLongHoverContentDesc != null) {
if (mLongHoverRunnable == null) {
mLongHoverRunnable =
new Runnable() {
@Override
public void run() {
setLongHovered(true);
announceForAccessibility(mLongHoverContentDesc);
}
};
}
postDelayed(mLongHoverRunnable, LONG_HOVER_TIMEOUT);
}
setClickable(false);
setLongClickable(false);
break;
case MotionEvent.ACTION_HOVER_EXIT:
if (mHoverBounds.contains(event.getX(), event.getY())) {
if (mLongHovered) {
performLongClick();
} else {
simulateClickForAccessibility();
}
}
cancelLongHover();
setClickable(mWasClickable);
setLongClickable(mWasLongClickable);
break;
}
}
return super.onHoverEvent(event);
}
/**
* When accessibility is on, simulate press and release to preserve the semantic meaning of
* performClick(). Required for Braille support.
*/
private void simulateClickForAccessibility() {
// Checking the press state prevents double activation.
if (isPressed()) {
return;
}
setPressed(true);
// Stay consistent with performClick() by sending the event after
// setting the pressed state but before performing the action.
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
setPressed(false);
}
private void setLongHovered(boolean enabled) {
if (mLongHovered != enabled) {
mLongHovered = enabled;
// Switch between normal and alternate description, if available.
if (enabled) {
mBackupContentDesc = getContentDescription();
super.setContentDescription(mLongHoverContentDesc);
} else {
super.setContentDescription(mBackupContentDesc);
}
}
}
private void cancelLongHover() {
if (mLongHoverRunnable != null) {
removeCallbacks(mLongHoverRunnable);
}
setLongHovered(false);
}
public interface OnPressedListener {
void onPressed(View view, boolean pressed);
}
}

View file

@ -0,0 +1,73 @@
/*
* Copyright (C) 2014 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.dialer.dialpadview;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;
import androidx.appcompat.widget.AppCompatTextView;
/**
* This is a custom text view intended only for rendering the numerals (and star and pound) on the
* dialpad. TextView has built in top/bottom padding to help account for ascenders/descenders.
*
* <p>Since vertical space is at a premium on the dialpad, particularly if the font size is scaled
* to a larger default, for the dialpad we use this class to more precisely render characters
* according to the precise amount of space they need.
*/
public class DialpadTextView extends AppCompatTextView {
private Rect mTextBounds = new Rect();
private String mTextStr;
public DialpadTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
/** Draw the text to fit within the height/width which have been specified during measurement. */
@Override
public void draw(Canvas canvas) {
Paint paint = getPaint();
// Without this, the draw does not respect the style's specified text color.
paint.setColor(getCurrentTextColor());
// The text bounds values are relative and can be negative,, so rather than specifying a
// standard origin such as 0, 0, we need to use negative of the left/top bounds.
// For example, the bounds may be: Left: 11, Right: 37, Top: -77, Bottom: 0
canvas.drawText(mTextStr, -mTextBounds.left, -mTextBounds.top, paint);
}
/**
* Calculate the pixel-accurate bounds of the text when rendered, and use that to specify the
* height and width.
*/
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
mTextStr = getText().toString();
getPaint().getTextBounds(mTextStr, 0, mTextStr.length(), mTextBounds);
int width = resolveSize(mTextBounds.width(), widthMeasureSpec);
int height = resolveSize(mTextBounds.height(), heightMeasureSpec);
setMeasuredDimension(width, height);
}
}

View file

@ -0,0 +1,455 @@
/*
* Copyright (C) 2014 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.dialer.dialpadview;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.Spannable;
import android.text.TextUtils;
import android.text.style.TtsSpan;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
import android.view.accessibility.AccessibilityManager;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.dialer.animation.AnimUtils;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;
/** View that displays a twelve-key phone dialpad. */
public class DialpadView extends LinearLayout {
private static final String TAG = DialpadView.class.getSimpleName();
private static final double DELAY_MULTIPLIER = 0.66;
private static final double DURATION_MULTIPLIER = 0.8;
// For animation.
private static final int KEY_FRAME_DURATION = 33;
/** {@code True} if the dialpad is in landscape orientation. */
private final boolean mIsLandscape;
/** {@code True} if the dialpad is showing in a right-to-left locale. */
private final boolean mIsRtl;
private final int[] mButtonIds =
new int[] {
R.id.zero,
R.id.one,
R.id.two,
R.id.three,
R.id.four,
R.id.five,
R.id.six,
R.id.seven,
R.id.eight,
R.id.nine,
R.id.star,
R.id.pound
};
private EditText mDigits;
private ImageButton mDelete;
private View mOverflowMenuButton;
private ViewGroup mRateContainer;
private TextView mIldCountry;
private TextView mIldRate;
private boolean mCanDigitsBeEdited;
private int mTranslateDistance;
public DialpadView(Context context) {
this(context, null);
}
public DialpadView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public DialpadView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mTranslateDistance =
getResources().getDimensionPixelSize(R.dimen.dialpad_key_button_translate_y);
mIsLandscape =
getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
mIsRtl = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 &&
TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;
}
@Override
protected void onFinishInflate() {
setupKeypad();
mDigits = (EditText) findViewById(R.id.digits);
mDelete = (ImageButton) findViewById(R.id.deleteButton);
mOverflowMenuButton = findViewById(R.id.dialpad_overflow);
mRateContainer = (ViewGroup) findViewById(R.id.rate_container);
mIldCountry = (TextView) mRateContainer.findViewById(R.id.ild_country);
mIldRate = (TextView) mRateContainer.findViewById(R.id.ild_rate);
AccessibilityManager accessibilityManager =
(AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
if (accessibilityManager.isEnabled()) {
// The text view must be selected to send accessibility events.
mDigits.setSelected(true);
}
}
private void setupKeypad() {
final int[] letterIds =
new int[] {
R.string.dialpad_0_letters,
R.string.dialpad_1_letters,
R.string.dialpad_2_letters,
R.string.dialpad_3_letters,
R.string.dialpad_4_letters,
R.string.dialpad_5_letters,
R.string.dialpad_6_letters,
R.string.dialpad_7_letters,
R.string.dialpad_8_letters,
R.string.dialpad_9_letters,
R.string.dialpad_star_letters,
R.string.dialpad_pound_letters
};
final Resources resources = getContext().getResources();
DialpadKeyButton dialpadKey;
TextView numberView;
TextView lettersView;
final Locale currentLocale = resources.getConfiguration().locale;
final NumberFormat nf;
// We translate dialpad numbers only for "fa" and not any other locale
// ("ar" anybody ?).
if ("fa".equals(currentLocale.getLanguage())) {
nf = DecimalFormat.getInstance(resources.getConfiguration().locale);
} else {
nf = DecimalFormat.getInstance(Locale.ENGLISH);
}
for (int i = 0; i < mButtonIds.length; i++) {
dialpadKey = (DialpadKeyButton) findViewById(mButtonIds[i]);
numberView = (TextView) dialpadKey.findViewById(R.id.dialpad_key_number);
lettersView = (TextView) dialpadKey.findViewById(R.id.dialpad_key_letters);
final String numberString;
final CharSequence numberContentDescription;
if (mButtonIds[i] == R.id.pound) {
numberString = resources.getString(R.string.dialpad_pound_number);
numberContentDescription = numberString;
} else if (mButtonIds[i] == R.id.star) {
numberString = resources.getString(R.string.dialpad_star_number);
numberContentDescription = numberString;
} else {
numberString = nf.format(i);
// The content description is used for Talkback key presses. The number is
// separated by a "," to introduce a slight delay. Convert letters into a verbatim
// span so that they are read as letters instead of as one word.
String letters = resources.getString(letterIds[i]);
Spannable spannable =
Spannable.Factory.getInstance().newSpannable(numberString + "," + letters);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
spannable.setSpan(
(new TtsSpan.VerbatimBuilder(letters)).build(),
numberString.length() + 1,
numberString.length() + 1 + letters.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
numberContentDescription = spannable;
}
numberView.setText(numberString);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
numberView.setElegantTextHeight(false);
}
dialpadKey.setContentDescription(numberContentDescription);
if (lettersView != null) {
lettersView.setText(resources.getString(letterIds[i]));
}
}
final DialpadKeyButton one = (DialpadKeyButton) findViewById(R.id.one);
one.setLongHoverContentDescription(resources.getText(R.string.description_voicemail_button));
final DialpadKeyButton zero = (DialpadKeyButton) findViewById(R.id.zero);
zero.setLongHoverContentDescription(resources.getText(R.string.description_image_button_plus));
}
private Drawable getDrawableCompat(Context context, int id) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return context.getDrawable(id);
} else {
return context.getResources().getDrawable(id);
}
}
public void setShowVoicemailButton(boolean show) {
View view = findViewById(R.id.dialpad_key_voicemail);
if (view != null) {
view.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
}
}
/**
* Whether or not the digits above the dialer can be edited.
*
* @param canBeEdited If true, the backspace button will be shown and the digits EditText will be
* configured to allow text manipulation.
*/
public void setCanDigitsBeEdited(boolean canBeEdited) {
// View deleteButton = findViewById(R.id.deleteButton);
// deleteButton.setVisibility(canBeEdited ? View.VISIBLE : View.INVISIBLE);
// View overflowMenuButton = findViewById(R.id.dialpad_overflow);
// overflowMenuButton.setVisibility(canBeEdited ? View.VISIBLE : View.GONE);
// EditText digits = (EditText) findViewById(R.id.digits);
// digits.setClickable(canBeEdited);
// digits.setLongClickable(canBeEdited);
// digits.setFocusableInTouchMode(canBeEdited);
// digits.setCursorVisible(false);
mCanDigitsBeEdited = canBeEdited;
}
public void setCallRateInformation(String countryName, String displayRate) {
if (TextUtils.isEmpty(countryName) && TextUtils.isEmpty(displayRate)) {
mRateContainer.setVisibility(View.GONE);
return;
}
mRateContainer.setVisibility(View.VISIBLE);
mIldCountry.setText(countryName);
mIldRate.setText(displayRate);
}
public boolean canDigitsBeEdited() {
return mCanDigitsBeEdited;
}
/**
* Always returns true for onHoverEvent callbacks, to fix problems with accessibility due to the
* dialpad overlaying other fragments.
*/
@Override
public boolean onHoverEvent(MotionEvent event) {
return true;
}
public void animateShow() {
// This is a hack; without this, the setTranslationY is delayed in being applied, and the
// numbers appear at their original position (0) momentarily before animating.
final AnimatorListenerAdapter showListener = new AnimatorListenerAdapter() {};
for (int i = 0; i < mButtonIds.length; i++) {
int delay = (int) (getKeyButtonAnimationDelay(mButtonIds[i]) * DELAY_MULTIPLIER);
int duration = (int) (getKeyButtonAnimationDuration(mButtonIds[i]) * DURATION_MULTIPLIER);
final DialpadKeyButton dialpadKey = (DialpadKeyButton) findViewById(mButtonIds[i]);
ViewPropertyAnimator animator = dialpadKey.animate();
if (mIsLandscape) {
// Landscape orientation requires translation along the X axis.
// For RTL locales, ensure we translate negative on the X axis.
dialpadKey.setTranslationX((mIsRtl ? -1 : 1) * mTranslateDistance);
animator.translationX(0);
} else {
// Portrait orientation requires translation along the Y axis.
dialpadKey.setTranslationY(mTranslateDistance);
animator.translationY(0);
}
animator
.setInterpolator(AnimUtils.EASE_OUT_EASE_IN)
.setStartDelay(delay)
.setDuration(duration)
.setListener(showListener)
.start();
}
}
public EditText getDigits() {
return mDigits;
}
public ImageButton getDeleteButton() {
return mDelete;
}
public View getOverflowMenuButton() {
return mOverflowMenuButton;
}
/**
* Get the animation delay for the buttons, taking into account whether the dialpad is in
* landscape left-to-right, landscape right-to-left, or portrait.
*
* @param buttonId The button ID.
* @return The animation delay.
*/
private int getKeyButtonAnimationDelay(int buttonId) {
if (mIsLandscape) {
if (mIsRtl) {
if (buttonId == R.id.three) {
return KEY_FRAME_DURATION * 1;
} else if (buttonId == R.id.six) {
return KEY_FRAME_DURATION * 2;
} else if (buttonId == R.id.nine) {
return KEY_FRAME_DURATION * 3;
} else if (buttonId == R.id.pound) {
return KEY_FRAME_DURATION * 4;
} else if (buttonId == R.id.two) {
return KEY_FRAME_DURATION * 5;
} else if (buttonId == R.id.five) {
return KEY_FRAME_DURATION * 6;
} else if (buttonId == R.id.eight) {
return KEY_FRAME_DURATION * 7;
} else if (buttonId == R.id.zero) {
return KEY_FRAME_DURATION * 8;
} else if (buttonId == R.id.one) {
return KEY_FRAME_DURATION * 9;
} else if (buttonId == R.id.four) {
return KEY_FRAME_DURATION * 10;
} else if (buttonId == R.id.seven || buttonId == R.id.star) {
return KEY_FRAME_DURATION * 11;
}
} else {
if (buttonId == R.id.one) {
return KEY_FRAME_DURATION * 1;
} else if (buttonId == R.id.four) {
return KEY_FRAME_DURATION * 2;
} else if (buttonId == R.id.seven) {
return KEY_FRAME_DURATION * 3;
} else if (buttonId == R.id.star) {
return KEY_FRAME_DURATION * 4;
} else if (buttonId == R.id.two) {
return KEY_FRAME_DURATION * 5;
} else if (buttonId == R.id.five) {
return KEY_FRAME_DURATION * 6;
} else if (buttonId == R.id.eight) {
return KEY_FRAME_DURATION * 7;
} else if (buttonId == R.id.zero) {
return KEY_FRAME_DURATION * 8;
} else if (buttonId == R.id.three) {
return KEY_FRAME_DURATION * 9;
} else if (buttonId == R.id.six) {
return KEY_FRAME_DURATION * 10;
} else if (buttonId == R.id.nine || buttonId == R.id.pound) {
return KEY_FRAME_DURATION * 11;
}
}
} else {
if (buttonId == R.id.one) {
return KEY_FRAME_DURATION * 1;
} else if (buttonId == R.id.two) {
return KEY_FRAME_DURATION * 2;
} else if (buttonId == R.id.three) {
return KEY_FRAME_DURATION * 3;
} else if (buttonId == R.id.four) {
return KEY_FRAME_DURATION * 4;
} else if (buttonId == R.id.five) {
return KEY_FRAME_DURATION * 5;
} else if (buttonId == R.id.six) {
return KEY_FRAME_DURATION * 6;
} else if (buttonId == R.id.seven) {
return KEY_FRAME_DURATION * 7;
} else if (buttonId == R.id.eight) {
return KEY_FRAME_DURATION * 8;
} else if (buttonId == R.id.nine) {
return KEY_FRAME_DURATION * 9;
} else if (buttonId == R.id.star) {
return KEY_FRAME_DURATION * 10;
} else if (buttonId == R.id.zero || buttonId == R.id.pound) {
return KEY_FRAME_DURATION * 11;
}
}
Log.wtf(TAG, "Attempted to get animation delay for invalid key button id.");
return 0;
}
/**
* Get the button animation duration, taking into account whether the dialpad is in landscape
* left-to-right, landscape right-to-left, or portrait.
*
* @param buttonId The button ID.
* @return The animation duration.
*/
private int getKeyButtonAnimationDuration(int buttonId) {
if (mIsLandscape) {
if (mIsRtl) {
if (buttonId == R.id.one
|| buttonId == R.id.four
|| buttonId == R.id.seven
|| buttonId == R.id.star) {
return KEY_FRAME_DURATION * 8;
} else if (buttonId == R.id.two
|| buttonId == R.id.five
|| buttonId == R.id.eight
|| buttonId == R.id.zero) {
return KEY_FRAME_DURATION * 9;
} else if (buttonId == R.id.three
|| buttonId == R.id.six
|| buttonId == R.id.nine
|| buttonId == R.id.pound) {
return KEY_FRAME_DURATION * 10;
}
} else {
if (buttonId == R.id.one
|| buttonId == R.id.four
|| buttonId == R.id.seven
|| buttonId == R.id.star) {
return KEY_FRAME_DURATION * 10;
} else if (buttonId == R.id.two
|| buttonId == R.id.five
|| buttonId == R.id.eight
|| buttonId == R.id.zero) {
return KEY_FRAME_DURATION * 9;
} else if (buttonId == R.id.three
|| buttonId == R.id.six
|| buttonId == R.id.nine
|| buttonId == R.id.pound) {
return KEY_FRAME_DURATION * 8;
}
}
} else {
if (buttonId == R.id.one
|| buttonId == R.id.two
|| buttonId == R.id.three
|| buttonId == R.id.four
|| buttonId == R.id.five
|| buttonId == R.id.six) {
return KEY_FRAME_DURATION * 10;
} else if (buttonId == R.id.seven || buttonId == R.id.eight || buttonId == R.id.nine) {
return KEY_FRAME_DURATION * 9;
} else if (buttonId == R.id.star || buttonId == R.id.zero || buttonId == R.id.pound) {
return KEY_FRAME_DURATION * 8;
}
}
Log.wtf(TAG, "Attempted to get animation duration for invalid key button id.");
return 0;
}
}

View file

@ -0,0 +1,84 @@
/*
* 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.dialer.dialpadview;
import android.content.Context;
import android.graphics.Rect;
import android.text.InputType;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.inputmethod.InputMethodManager;
import com.android.dialer.widget.ResizingTextEditText;
/** EditText which suppresses IME show up. */
public class DigitsEditText extends ResizingTextEditText {
private OnTextContextMenuClickListener mOnTextContextMenuClickListener;
public DigitsEditText(Context context, AttributeSet attrs) {
super(context, attrs);
setInputType(getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
setShowSoftInputOnFocus(false);
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
final InputMethodManager imm =
((InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE));
if (imm != null && imm.isActive(this)) {
imm.hideSoftInputFromWindow(getApplicationWindowToken(), 0);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
final boolean ret = super.onTouchEvent(event);
// Must be done after super.onTouchEvent()
final InputMethodManager imm =
((InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE));
if (imm != null && imm.isActive(this)) {
imm.hideSoftInputFromWindow(getApplicationWindowToken(), 0);
}
return ret;
}
@Override
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
super.onTextChanged(text, start, lengthBefore, lengthAfter);
if (isCursorVisible()) {
setSelection(getText().length());
}
}
@Override
public boolean onTextContextMenuItem(int id) {
boolean value = super.onTextContextMenuItem(id);
if (mOnTextContextMenuClickListener != null) {
mOnTextContextMenuClickListener.onTextContextMenuClickListener(id);
}
return value;
}
public interface OnTextContextMenuClickListener {
void onTextContextMenuClickListener(int id);
}
public void setOnTextContextMenuClickListener(OnTextContextMenuClickListener listener) {
this.mOnTextContextMenuClickListener = listener;
}
}

View file

@ -0,0 +1,41 @@
/*
* 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.dialer.util;
import android.graphics.Paint;
import android.util.TypedValue;
import android.widget.TextView;
/** Provides static functions to work with views */
public class ViewUtil {
private ViewUtil() {}
public static void resizeText(TextView textView, int originalTextSize, int minTextSize) {
final Paint paint = textView.getPaint();
final int width = textView.getWidth();
if (width == 0) {
return;
}
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, originalTextSize);
float ratio = width / paint.measureText(textView.getText().toString());
if (ratio <= 1.0f) {
textView.setTextSize(
TypedValue.COMPLEX_UNIT_PX, Math.max(minTextSize, originalTextSize * ratio));
}
}
}

View file

@ -0,0 +1,55 @@
/*
* Copyright (C) 2014 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.dialer.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.EditText;
import androidx.appcompat.widget.AppCompatEditText;
import com.android.dialer.dialpadview.R;
import com.android.dialer.util.ViewUtil;
/** EditText which resizes dynamically with respect to text length. */
public class ResizingTextEditText extends AppCompatEditText {
private final int mOriginalTextSize;
private final int mMinTextSize;
public ResizingTextEditText(Context context, AttributeSet attrs) {
super(context, attrs);
mOriginalTextSize = (int) getTextSize();
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ResizingText);
mMinTextSize =
(int) a.getDimension(R.styleable.ResizingText_resizing_text_min_size, mOriginalTextSize);
a.recycle();
}
@Override
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
super.onTextChanged(text, start, lengthBefore, lengthAfter);
ViewUtil.resizeText(this, mOriginalTextSize, mMinTextSize);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
ViewUtil.resizeText(this, mOriginalTextSize, mMinTextSize);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 424 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 407 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 549 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 511 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 486 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 261 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 485 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 578 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 261 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 467 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 396 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 445 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 271 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 325 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 571 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 452 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 823 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 B

Some files were not shown because too many files have changed in this diff Show more