summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2018-03-13 02:44:54 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-03-13 02:44:54 +0000
commit61db91fbbae7e4e60831b6d2bd5e476cc7646912 (patch)
tree67ce349c892e04e817c3c96f7210560f49793e07
parentc8039e034838a030848bb040d10997835153427e (diff)
parentf53ba7be0531904a25c15f69c8e1bfdea88be869 (diff)
Merge "Keyboard and search now close when appropriate."
-rw-r--r--java/com/android/dialer/app/DialtactsActivity.java3
-rw-r--r--java/com/android/dialer/main/impl/MainSearchController.java32
-rw-r--r--java/com/android/dialer/main/impl/OldMainActivityPeer.java9
-rw-r--r--java/com/android/dialer/main/impl/toolbar/SearchBarListener.java7
-rw-r--r--java/com/android/dialer/searchfragment/list/NewSearchFragment.java9
5 files changed, 54 insertions, 6 deletions
diff --git a/java/com/android/dialer/app/DialtactsActivity.java b/java/com/android/dialer/app/DialtactsActivity.java
index 37b241bcd..465c57911 100644
--- a/java/com/android/dialer/app/DialtactsActivity.java
+++ b/java/com/android/dialer/app/DialtactsActivity.java
@@ -1727,6 +1727,9 @@ public class DialtactsActivity extends TransactionSafeActivity
clearSearchOnPause = true;
}
+ @Override
+ public void requestingPermission() {}
+
protected int getPreviouslySelectedTabIndex() {
return previouslySelectedTabIndex;
}
diff --git a/java/com/android/dialer/main/impl/MainSearchController.java b/java/com/android/dialer/main/impl/MainSearchController.java
index 7d57f9867..92e5651f8 100644
--- a/java/com/android/dialer/main/impl/MainSearchController.java
+++ b/java/com/android/dialer/main/impl/MainSearchController.java
@@ -86,6 +86,14 @@ public class MainSearchController implements SearchBarListener {
private final List<OnSearchShowListener> onSearchShowListenerList = new ArrayList<>();
+ /**
+ * True when an action happens that closes search (like leaving the app or placing a call). We
+ * want to wait until onPause is called otherwise the transition will look extremely janky.
+ */
+ private boolean closeSearchOnPause;
+
+ private boolean requestingPermission;
+
public MainSearchController(
MainActivity mainActivity,
BottomNavBar bottomNav,
@@ -444,15 +452,35 @@ public class MainSearchController implements SearchBarListener {
}
@Override
+ public void onActivityPause() {
+ if (closeSearchOnPause) {
+ closeSearchOnPause = false;
+ if (isInSearch()) {
+ closeSearch(false);
+ }
+ }
+ }
+
+ @Override
public void onUserLeaveHint() {
if (isInSearch()) {
- closeSearch(false);
+ // Requesting a permission causes this to be called and we want search to remain open when
+ // that happens. Otherwise, close search.
+ closeSearchOnPause = !requestingPermission;
+
+ // Always hide the keyboard when the user leaves dialer (including permission requests)
+ toolbar.hideKeyboard();
}
}
@Override
public void onCallPlacedFromSearch() {
- closeSearch(false);
+ closeSearchOnPause = true;
+ }
+
+ @Override
+ public void requestingPermission() {
+ requestingPermission = true;
}
public void onVoiceResults(int resultCode, Intent data) {
diff --git a/java/com/android/dialer/main/impl/OldMainActivityPeer.java b/java/com/android/dialer/main/impl/OldMainActivityPeer.java
index 3c335b380..b6176464b 100644
--- a/java/com/android/dialer/main/impl/OldMainActivityPeer.java
+++ b/java/com/android/dialer/main/impl/OldMainActivityPeer.java
@@ -447,7 +447,9 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen
}
@Override
- public void onActivityPause() {}
+ public void onActivityPause() {
+ searchController.onActivityPause();
+ }
@Override
public void onActivityStop() {
@@ -676,6 +678,11 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen
// TODO(calderwoodra): logging
searchController.onCallPlacedFromSearch();
}
+
+ @Override
+ public void requestingPermission() {
+ searchController.requestingPermission();
+ }
}
/** @see DialpadFragment.HostInterface */
diff --git a/java/com/android/dialer/main/impl/toolbar/SearchBarListener.java b/java/com/android/dialer/main/impl/toolbar/SearchBarListener.java
index 857c4b9c9..d01fe3a39 100644
--- a/java/com/android/dialer/main/impl/toolbar/SearchBarListener.java
+++ b/java/com/android/dialer/main/impl/toolbar/SearchBarListener.java
@@ -16,6 +16,7 @@
package com.android.dialer.main.impl.toolbar;
+import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
@@ -37,12 +38,18 @@ public interface SearchBarListener {
/** Called when a toolbar menu item is clicked. */
boolean onMenuItemClicked(MenuItem menuItem);
+ /** Called when {@link Activity#onPause()} is called. */
+ void onActivityPause();
+
/** Called when {@link AppCompatActivity#onUserLeaveHint()} is called. */
void onUserLeaveHint();
/** Called when the user places a call from search (regular or dialpad). */
void onCallPlacedFromSearch();
+ /** Called when a permission is about to be requested. */
+ void requestingPermission();
+
/** Interface for returning voice results to the search bar. */
interface VoiceSearchResultCallback {
diff --git a/java/com/android/dialer/searchfragment/list/NewSearchFragment.java b/java/com/android/dialer/searchfragment/list/NewSearchFragment.java
index aff946206..6a60598a7 100644
--- a/java/com/android/dialer/searchfragment/list/NewSearchFragment.java
+++ b/java/com/android/dialer/searchfragment/list/NewSearchFragment.java
@@ -29,7 +29,6 @@ import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
-import android.support.v13.app.FragmentCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.telephony.PhoneNumberUtils;
@@ -342,8 +341,8 @@ public final class NewSearchFragment extends Fragment
LogUtil.i(
"NewSearchFragment.onEmptyViewActionButtonClicked",
"Requesting permissions: " + Arrays.toString(deniedPermissions));
- FragmentCompat.requestPermissions(
- this, deniedPermissions, READ_CONTACTS_PERMISSION_REQUEST_CODE);
+ FragmentUtils.getParentUnsafe(this, SearchFragmentListener.class).requestingPermission();
+ requestPermissions(deniedPermissions, READ_CONTACTS_PERMISSION_REQUEST_CODE);
}
}
@@ -411,6 +410,7 @@ public final class NewSearchFragment extends Fragment
String[] deniedPermissions =
PermissionsUtil.getPermissionsCurrentlyDenied(
getContext(), PermissionsUtil.allLocationGroupPermissionsUsedInDialer);
+ FragmentUtils.getParentUnsafe(this, SearchFragmentListener.class).requestingPermission();
requestPermissions(deniedPermissions, LOCATION_PERMISSION_REQUEST_CODE);
}
@@ -557,5 +557,8 @@ public final class NewSearchFragment extends Fragment
/** Called when a call is placed from the search fragment. */
void onCallPlacedFromSearch();
+
+ /** Called when a permission is about to be requested. */
+ void requestingPermission();
}
}