forked from organicmaps/organicmaps
[android] Hide expanded search after 5 seconds of inactivity.
This commit is contained in:
parent
252d15ff50
commit
a22938cb8e
2 changed files with 29 additions and 8 deletions
|
@ -16,18 +16,28 @@ import com.mapswithme.maps.R;
|
|||
import com.mapswithme.maps.search.SearchEngine;
|
||||
import com.mapswithme.util.Graphics;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
|
||||
class SearchWheel implements View.OnClickListener
|
||||
{
|
||||
private static String TAG = "TEST";
|
||||
private final View mFrame;
|
||||
|
||||
private final View mSearchLayout;
|
||||
private final ImageView mSearchButton;
|
||||
private final View mTouchInterceptor;
|
||||
|
||||
private boolean mIsExpanded;
|
||||
private SearchOption mCurrentOption;
|
||||
|
||||
private static final long CLOSE_DELAY_MILLIS = 5000L;
|
||||
private Runnable mCloseRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
toggleSearchLayout();
|
||||
}
|
||||
};
|
||||
|
||||
private enum SearchOption
|
||||
{
|
||||
FUEL(R.id.search_fuel, R.drawable.ic_routing_fuel_off, R.drawable.ic_routing_fuel_on, "fuel"),
|
||||
|
@ -77,7 +87,8 @@ class SearchWheel implements View.OnClickListener
|
|||
{
|
||||
mFrame = frame;
|
||||
|
||||
// Search
|
||||
mTouchInterceptor = mFrame.findViewById(R.id.touch_interceptor);
|
||||
mTouchInterceptor.setOnClickListener(this);
|
||||
mSearchButton = (ImageView) mFrame.findViewById(R.id.btn_search);
|
||||
mSearchButton.setOnClickListener(this);
|
||||
mSearchLayout = mFrame.findViewById(R.id.search_frame);
|
||||
|
@ -134,6 +145,7 @@ class SearchWheel implements View.OnClickListener
|
|||
final Animator animator = AnimatorInflater.loadAnimator(mSearchLayout.getContext(), animRes);
|
||||
animator.setTarget(mSearchLayout);
|
||||
animator.start();
|
||||
UiUtils.visibleIf(mIsExpanded, mTouchInterceptor);
|
||||
animator.addListener(new UiUtils.SimpleAnimatorListener()
|
||||
{
|
||||
@Override
|
||||
|
@ -149,7 +161,13 @@ class SearchWheel implements View.OnClickListener
|
|||
for (SearchOption searchOption : SearchOption.values())
|
||||
UiUtils.visibleIf(mIsExpanded, mSearchLayout.findViewById(searchOption.resId));
|
||||
|
||||
UiUtils.visibleIf(mIsExpanded, mSearchLayout);
|
||||
UiUtils.visibleIf(mIsExpanded, mSearchLayout, mTouchInterceptor);
|
||||
|
||||
if (mIsExpanded)
|
||||
{
|
||||
UiThread.cancelDelayedTasks(mCloseRunnable);
|
||||
UiThread.runLater(mCloseRunnable, CLOSE_DELAY_MILLIS);
|
||||
}
|
||||
}
|
||||
|
||||
private void resetSearchButtonImage()
|
||||
|
@ -189,6 +207,9 @@ class SearchWheel implements View.OnClickListener
|
|||
return;
|
||||
}
|
||||
|
||||
toggleSearchLayout();
|
||||
break;
|
||||
case R.id.touch_interceptor:
|
||||
toggleSearchLayout();
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -94,14 +94,14 @@ public class UiThread
|
|||
}
|
||||
|
||||
/**
|
||||
* Executes something on UI thread after a given delay.
|
||||
* Executes something on UI thread after a given delayMillis.
|
||||
*
|
||||
* @param task the code that must be executed on UI thread after given delay.
|
||||
* @param delay The delay (in milliseconds) until the code will be executed.
|
||||
* @param task the code that must be executed on UI thread after given delayMillis.
|
||||
* @param delayMillis The delayMillis until the code will be executed.
|
||||
*/
|
||||
public static void runLater(Runnable task, long delay)
|
||||
public static void runLater(Runnable task, long delayMillis)
|
||||
{
|
||||
sUiHandler.postDelayed(task, delay);
|
||||
sUiHandler.postDelayed(task, delayMillis);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue