summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorcalderwoodra <calderwoodra@google.com>2018-05-04 12:47:03 -0700
committerCopybara-Service <copybara-piper@google.com>2018-05-09 16:46:06 -0700
commitd3844742f236c5c6b838848d226ea9fbcaabab2e (patch)
tree72eeb1a480dc31a3739e58fc8713efca05141fe4 /java
parent12061c870e823f4de4e217540fa686a2040df9f1 (diff)
Replace assert checks with safety checks instead.
Bug: 79239533 Test: tap PiperOrigin-RevId: 195456757 Change-Id: Ief432ae2fbd54d20f8fca198e102b22b169bcb77
Diffstat (limited to 'java')
-rw-r--r--java/com/android/dialer/main/impl/MainSearchController.java62
-rw-r--r--java/com/android/dialer/main/impl/toolbar/MainToolbar.java18
2 files changed, 53 insertions, 27 deletions
diff --git a/java/com/android/dialer/main/impl/MainSearchController.java b/java/com/android/dialer/main/impl/MainSearchController.java
index b9a6654b6..72c46cc7a 100644
--- a/java/com/android/dialer/main/impl/MainSearchController.java
+++ b/java/com/android/dialer/main/impl/MainSearchController.java
@@ -35,7 +35,6 @@ import com.android.contacts.common.dialog.ClearFrequentsDialog;
import com.android.dialer.app.calllog.CallLogActivity;
import com.android.dialer.app.settings.DialerSettingsActivity;
import com.android.dialer.callintent.CallInitiationType;
-import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
import com.android.dialer.constants.ActivityRequestCodes;
import com.android.dialer.dialpadview.DialpadFragment;
@@ -136,7 +135,10 @@ public class MainSearchController implements SearchBarListener {
}
private void showDialpad(boolean animate, boolean fromNewIntent) {
- Assert.checkArgument(!isDialpadVisible());
+ if (isDialpadVisible()) {
+ LogUtil.e("MainSearchController.showDialpad", "Dialpad is already visible.");
+ return;
+ }
Logger.get(activity).logScreenView(ScreenEvent.Type.MAIN_DIALPAD, activity);
@@ -187,14 +189,32 @@ public class MainSearchController implements SearchBarListener {
*/
private void hideDialpad(boolean animate) {
LogUtil.enterBlock("MainSearchController.hideDialpad");
- assertDialpadVisible();
+ DialpadFragment dialpadFragment = getDialpadFragment();
+ if (dialpadFragment == null) {
+ LogUtil.e("MainSearchController.hideDialpad", "Dialpad fragment is null.");
+ return;
+ }
+
+ if (!dialpadFragment.isAdded()) {
+ LogUtil.e("MainSearchController.hideDialpad", "Dialpad fragment is not added.");
+ return;
+ }
+
+ if (dialpadFragment.isHidden()) {
+ LogUtil.e("MainSearchController.hideDialpad", "Dialpad fragment is already hidden.");
+ return;
+ }
+
+ if (!dialpadFragment.isDialpadSlideUp()) {
+ LogUtil.e("MainSearchController.hideDialpad", "Dialpad fragment is already slide down.");
+ return;
+ }
fab.show();
toolbar.slideDown(animate, fragmentContainer);
toolbar.transferQueryFromDialpad(getDialpadFragment().getQuery());
activity.setTitle(R.string.main_activity_label);
- DialpadFragment dialpadFragment = getDialpadFragment();
dialpadFragment.setAnimate(animate);
dialpadFragment.slideDown(
animate,
@@ -295,7 +315,22 @@ public class MainSearchController implements SearchBarListener {
/** Calls {@link #hideDialpad(boolean)}, removes the search fragment and clears the dialpad. */
private void closeSearch(boolean animate) {
LogUtil.enterBlock("MainSearchController.closeSearch");
- assertSearchIsVisible();
+ NewSearchFragment searchFragment = getSearchFragment();
+ if (searchFragment == null) {
+ LogUtil.e("MainSearchController.closeSearch", "Search fragment is null.");
+ return;
+ }
+
+ if (!searchFragment.isAdded()) {
+ LogUtil.e("MainSearchController.closeSearch", "Search fragment isn't added.");
+ return;
+ }
+
+ if (searchFragment.isHidden()) {
+ LogUtil.e("MainSearchController.closeSearch", "Search fragment is already hidden.");
+ return;
+ }
+
if (isDialpadVisible()) {
hideDialpad(animate);
} else if (!fab.isShown()) {
@@ -304,7 +339,7 @@ public class MainSearchController implements SearchBarListener {
showBottomNav();
toolbar.collapse(animate);
toolbarShadow.setVisibility(View.GONE);
- activity.getFragmentManager().beginTransaction().hide(getSearchFragment()).commit();
+ activity.getFragmentManager().beginTransaction().hide(searchFragment).commit();
// Clear the dialpad so the phone number isn't persisted between search sessions.
DialpadFragment dialpadFragment = getDialpadFragment();
@@ -341,26 +376,11 @@ public class MainSearchController implements SearchBarListener {
&& fragment.isDialpadSlideUp();
}
- private void assertDialpadVisible() {
- DialpadFragment fragment = getDialpadFragment();
- Assert.checkArgument(fragment != null, "Dialpad Fragment is null");
- Assert.checkArgument(fragment.isAdded(), "Dialpad Fragment is no added");
- Assert.checkArgument(!fragment.isHidden(), "Dialpad Fragment is hidden");
- Assert.checkArgument(fragment.isDialpadSlideUp(), "Dialpad Fragment is slide down");
- }
-
private boolean isSearchVisible() {
NewSearchFragment fragment = getSearchFragment();
return fragment != null && fragment.isAdded() && !fragment.isHidden();
}
- private void assertSearchIsVisible() {
- NewSearchFragment fragment = getSearchFragment();
- Assert.checkArgument(fragment != null, "Search Fragment is null");
- Assert.checkArgument(fragment.isAdded(), "Search Fragment is not added");
- Assert.checkArgument(!fragment.isHidden(), "Search Fragment is hidden.");
- }
-
/** Returns true if the search UI is visible. */
public boolean isInSearch() {
return isSearchVisible();
diff --git a/java/com/android/dialer/main/impl/toolbar/MainToolbar.java b/java/com/android/dialer/main/impl/toolbar/MainToolbar.java
index 851d7a0b4..475383bd3 100644
--- a/java/com/android/dialer/main/impl/toolbar/MainToolbar.java
+++ b/java/com/android/dialer/main/impl/toolbar/MainToolbar.java
@@ -28,6 +28,7 @@ import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.ImageButton;
import android.widget.PopupMenu;
import com.android.dialer.common.Assert;
+import com.android.dialer.common.LogUtil;
import com.android.dialer.util.ViewUtil;
import com.google.common.base.Optional;
@@ -41,7 +42,6 @@ public final class MainToolbar extends Toolbar implements PopupMenu.OnMenuItemCl
private SearchBarView searchBar;
private SearchBarListener listener;
private MainToolbarMenu overflowMenu;
- private boolean isSlideUp;
private boolean hasGlobalLayoutListener;
public MainToolbar(Context context, AttributeSet attrs) {
@@ -78,7 +78,6 @@ public final class MainToolbar extends Toolbar implements PopupMenu.OnMenuItemCl
return;
}
- Assert.checkArgument(!isSlideUp);
if (getHeight() == 0) {
hasGlobalLayoutListener = true;
ViewUtil.doOnGlobalLayout(
@@ -89,7 +88,12 @@ public final class MainToolbar extends Toolbar implements PopupMenu.OnMenuItemCl
});
return;
}
- isSlideUp = true;
+
+ if (isSlideUp()) {
+ LogUtil.e("MainToolbar.slideDown", "Already slide up.");
+ return;
+ }
+
animate()
.translationY(-getHeight())
.setDuration(animate ? SLIDE_DURATION : 0)
@@ -105,8 +109,10 @@ public final class MainToolbar extends Toolbar implements PopupMenu.OnMenuItemCl
/** Slides the toolbar down and back onto the screen. */
public void slideDown(boolean animate, View container) {
- Assert.checkArgument(isSlideUp);
- isSlideUp = false;
+ if (getTranslationY() == 0) {
+ LogUtil.e("MainToolbar.slideDown", "Already slide down.");
+ return;
+ }
animate()
.translationY(0)
.setDuration(animate ? SLIDE_DURATION : 0)
@@ -131,7 +137,7 @@ public final class MainToolbar extends Toolbar implements PopupMenu.OnMenuItemCl
}
public boolean isSlideUp() {
- return isSlideUp;
+ return getHeight() != 0 && getTranslationY() == -getHeight();
}
public boolean isExpanded() {