-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add controller for action panel, add animated show/hide for panel
- Loading branch information
Showing
6 changed files
with
153 additions
and
2 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
app/src/main/java/com/polar/mirror/ActionPanelController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.polar.mirror; | ||
|
||
import android.content.Context; | ||
import android.view.View; | ||
import android.view.animation.Animation; | ||
import android.view.animation.AnimationUtils; | ||
import android.os.Handler; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
|
||
/** | ||
* Controls panel with floating action buttons | ||
*/ | ||
public class ActionPanelController implements View.OnClickListener { | ||
private final View mPanelView; | ||
private final View mOverlayView; | ||
private final Animation mSlideDownAnimation; | ||
private final Animation mSlideUpAnimation; | ||
private boolean mPanelVisible = true; | ||
private Handler mHideHandler; | ||
private Runnable mHideRunnable; | ||
private final int hideMs; | ||
public ActionPanelController(Context context, View panelView, View overlayView){ | ||
mPanelView = panelView; | ||
mOverlayView = overlayView; | ||
mSlideDownAnimation = AnimationUtils.loadAnimation(context, R.anim.slide_down); | ||
mSlideUpAnimation = AnimationUtils.loadAnimation(context, R.anim.slide_up); | ||
hideMs = context.getResources().getInteger(R.integer.autohide_action_panel_ms); | ||
if(hideMs < 0){ | ||
throw new RuntimeException("Bad configuration: negative hideMs"); | ||
} | ||
setupAnimations(); | ||
setupAutoHide(); | ||
} | ||
|
||
private void setupAutoHide(){ | ||
mHideHandler = new Handler(); | ||
mHideRunnable = this::hidePanel; | ||
scheduleHide(); | ||
} | ||
|
||
private void scheduleHide(){ | ||
mHideHandler.postDelayed(mHideRunnable, hideMs); | ||
} | ||
|
||
private void setupAnimations(){ | ||
mSlideDownAnimation.setAnimationListener(new Animation.AnimationListener() { | ||
@Override | ||
public void onAnimationStart(Animation animation) { | ||
/*stub*/ | ||
} | ||
|
||
@Override | ||
public void onAnimationEnd(Animation animation) { | ||
mPanelView.setVisibility(View.GONE); | ||
mOverlayView.setVisibility(View.GONE); | ||
} | ||
|
||
@Override | ||
public void onAnimationRepeat(Animation animation) { | ||
/*stub*/ | ||
} | ||
}); | ||
mSlideUpAnimation.setAnimationListener(new Animation.AnimationListener() { | ||
@Override | ||
public void onAnimationStart(Animation animation) { | ||
mPanelView.setVisibility(View.VISIBLE); | ||
mOverlayView.setVisibility(View.VISIBLE); | ||
} | ||
|
||
@Override | ||
public void onAnimationEnd(Animation animation) { | ||
/*stub*/ | ||
} | ||
|
||
@Override | ||
public void onAnimationRepeat(Animation animation) { | ||
/*stub*/ | ||
} | ||
}); | ||
} | ||
|
||
private void hidePanel(){ | ||
mPanelView.startAnimation(mSlideDownAnimation); | ||
mOverlayView.startAnimation(mSlideDownAnimation); | ||
mPanelVisible = false; | ||
mHideHandler.removeCallbacks(mHideRunnable); | ||
} | ||
|
||
private void showPanel(){ | ||
mPanelView.startAnimation(mSlideUpAnimation); | ||
mOverlayView.startAnimation(mSlideUpAnimation); | ||
mPanelVisible = true; | ||
scheduleHide(); | ||
} | ||
|
||
private void togglePanelVisibility(){ | ||
if(mPanelVisible){ | ||
hidePanel(); | ||
} else { | ||
showPanel(); | ||
} | ||
} | ||
@Override | ||
public void onClick(@NonNull View v) { | ||
final int viewId = v.getId(); | ||
if(viewId == R.id.preview_view || viewId == R.id.stop_view){ | ||
togglePanelVisibility(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<set xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<translate | ||
android:duration="300" | ||
android:fromYDelta="0%" | ||
android:toYDelta="100%" /> | ||
</set> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<set xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<translate | ||
android:duration="300" | ||
android:fromYDelta="100%" | ||
android:toYDelta="0%" /> | ||
</set> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<!--After how many milliseconds we should hide action panel--> | ||
<integer name="autohide_action_panel_ms">15000</integer> | ||
</resources> |