Permalink
Browse files

cling improvements

  • Loading branch information...
Xlythe committed Feb 3, 2013
1 parent 2f26ada commit e841dec8a7efe690fed82e0e0a9f8e3799af52f9
Showing with 23 additions and 18 deletions.
  1. +23 −18 src/com/android2/calculator3/Calculator.java
@@ -69,6 +69,8 @@
private EquationFormatter mEquationFormatter;
+ private boolean clingActive = false;
+
public enum Panel {
GRAPH, FUNCTION, HEX, BASIC, ADVANCED, MATRIX;
@@ -452,19 +454,16 @@ public void onPause() {
@Override
public boolean onKeyDown(int keyCode, KeyEvent keyEvent) {
- if(keyCode == KeyEvent.KEYCODE_BACK && mPulldown.isSliderOpen()) {
+ if(keyCode == KeyEvent.KEYCODE_BACK && mPulldown.isSliderOpen() && !clingActive) {
mPulldown.animateSliderClosed();
return true;
}
- else if(keyCode == KeyEvent.KEYCODE_BACK && mPager != null
- && (getAdvancedVisibility() || getFunctionVisibility() || getGraphVisibility() || getMatrixVisibility() || getHexVisibility())
- && CalculatorSettings.basicPanel(getContext())) {
+ else if(keyCode == KeyEvent.KEYCODE_BACK && mPager != null && !getBasicVisibility() && CalculatorSettings.basicPanel(getContext()) && !clingActive) {
mPager.setCurrentItem(Panel.BASIC.getOrder());
return true;
}
- else if(keyCode == KeyEvent.KEYCODE_BACK && mSmallPager != null && mLargePager != null
- && (getFunctionVisibility() || getGraphVisibility() || getMatrixVisibility() || getHexVisibility())
- && CalculatorSettings.basicPanel(getContext()) && CalculatorSettings.advancedPanel(getContext())) {
+ else if(keyCode == KeyEvent.KEYCODE_BACK && mSmallPager != null && mLargePager != null && !(getAdvancedVisibility() && getBasicVisibility())
+ && CalculatorSettings.basicPanel(getContext()) && CalculatorSettings.advancedPanel(getContext()) && !clingActive) {
mSmallPager.setCurrentItem(SmallPanel.ADVANCED.getOrder());
mLargePager.setCurrentItem(LargePanel.BASIC.getOrder());
return true;
@@ -511,6 +510,11 @@ private boolean isClingsEnabled() {
}
private Cling initCling(int clingId, int[] positionData, float revealRadius, boolean showHand, boolean animate) {
+ if(mPager != null) mPager.setPagingEnabled(false);
+ if(mSmallPager != null) mSmallPager.setPagingEnabled(false);
+ if(mLargePager != null) mLargePager.setPagingEnabled(false);
+ clingActive = true;
+
Cling cling = (Cling) findViewById(clingId);
if(cling != null) {
cling.init(this, positionData, revealRadius, showHand);
@@ -525,13 +529,15 @@ private Cling initCling(int clingId, int[] positionData, float revealRadius, boo
cling.setAlpha(1f);
}
}
- if(mPager != null) mPager.setPagingEnabled(false);
- if(mSmallPager != null) mSmallPager.setPagingEnabled(false);
- if(mLargePager != null) mLargePager.setPagingEnabled(false);
return cling;
}
private void dismissCling(final Cling cling, final String flag, int duration) {
+ if(mPager != null) mPager.setPagingEnabled(true);
+ if(mSmallPager != null) mSmallPager.setPagingEnabled(true);
+ if(mLargePager != null) mLargePager.setPagingEnabled(true);
+ clingActive = false;
+
if(cling != null) {
cling.dismiss();
ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
@@ -545,12 +551,14 @@ public void onAnimationEnd(Animator animation) {
});
anim.start();
}
+ }
+
+ private void removeCling(int id) {
if(mPager != null) mPager.setPagingEnabled(true);
if(mSmallPager != null) mSmallPager.setPagingEnabled(true);
if(mLargePager != null) mLargePager.setPagingEnabled(true);
- }
+ clingActive = false;
- private void removeCling(int id) {
final View cling = findViewById(id);
if(cling != null) {
final ViewGroup parent = (ViewGroup) cling.getParent();
@@ -561,9 +569,6 @@ public void run() {
}
});
}
- if(mPager != null) mPager.setPagingEnabled(true);
- if(mSmallPager != null) mSmallPager.setPagingEnabled(true);
- if(mLargePager != null) mLargePager.setPagingEnabled(true);
}
public void showFirstRunSimpleCling(boolean animate) {
@@ -656,13 +661,13 @@ private void runCling(boolean animate) {
if(getBasicVisibility()) {
showFirstRunSimpleCling(animate);
}
- else if(getMatrixVisibility()) {
+ if(getMatrixVisibility()) {
showFirstRunMatrixCling(animate);
}
- else if(getHexVisibility()) {
+ if(getHexVisibility()) {
showFirstRunHexCling(animate);
}
- else if(getGraphVisibility()) {
+ if(getGraphVisibility()) {
showFirstRunGraphCling(animate);
}
}

0 comments on commit e841dec

Please sign in to comment.