diff options
author | Annie Chin <afchin@google.com> | 2017-01-04 15:06:05 -0800 |
---|---|---|
committer | Annie Chin <afchin@google.com> | 2017-01-05 14:09:26 -0800 |
commit | 52eed7ad745fcf38439023d7239651dbbe7b6f14 (patch) | |
tree | 0c60bd62fd045672dbaf7c11805b416befb89142 | |
parent | 7fb470c4a53dfe6969e64c7bee80a3c72fe553b5 (diff) | |
download | android_packages_apps_ExactCalculator-52eed7ad745fcf38439023d7239651dbbe7b6f14.tar.gz android_packages_apps_ExactCalculator-52eed7ad745fcf38439023d7239651dbbe7b6f14.tar.bz2 android_packages_apps_ExactCalculator-52eed7ad745fcf38439023d7239651dbbe7b6f14.zip |
Directly implement CloseCallback/DragCallback.
Test: Verify that dragging history open/closed still works properly.
Fixes: 34079549
Change-Id: I9a53a6631cfc97e40bbfd0dccfe6e28e03792c09
-rw-r--r-- | src/com/android/calculator2/Calculator.java | 86 | ||||
-rw-r--r-- | src/com/android/calculator2/HistoryFragment.java | 69 |
2 files changed, 81 insertions, 74 deletions
diff --git a/src/com/android/calculator2/Calculator.java b/src/com/android/calculator2/Calculator.java index 9af6bc1..27b0e0c 100644 --- a/src/com/android/calculator2/Calculator.java +++ b/src/com/android/calculator2/Calculator.java @@ -87,7 +87,8 @@ import static com.android.calculator2.CalculatorFormula.OnFormulaContextMenuClic public class Calculator extends Activity implements OnTextSizeChangeListener, OnLongClickListener, - AlertDialogFragment.OnClickListener, Evaluator.EvaluationListener /* for main result */ { + AlertDialogFragment.OnClickListener, Evaluator.EvaluationListener /* for main result */, + DragLayout.CloseCallback, DragLayout.DragCallback { private static final String TAG = "Calculator"; /** @@ -243,41 +244,6 @@ public class Calculator extends Activity } }; - private final DragLayout.CloseCallback mCloseCallback = new DragLayout.CloseCallback() { - @Override - public void onClose() { - removeHistoryFragment(); - } - }; - - private final DragLayout.DragCallback mDragCallback = new DragLayout.DragCallback() { - @Override - public void onStartDraggingOpen() { - showHistoryFragment(FragmentTransaction.TRANSIT_NONE); - } - - @Override - public void whileDragging(float yFraction) { - // no-op - } - - @Override - public boolean shouldCaptureView(View view, int x, int y) { - return mDragLayout.isMoving() - || mDragLayout.isOpen() - || mDragLayout.isViewUnder(mDisplayView, x, y); - } - - @Override - public int getDisplayHeight() { - return mDisplayView.getMeasuredHeight(); - } - - public void onLayout(int translation) { - mHistoryFrame.setTranslationY(translation + mDisplayView.getBottom()); - } - }; - private CalculatorState mCurrentState; private Evaluator mEvaluator; @@ -452,9 +418,9 @@ public class Calculator extends Activity }; mDragLayout = (DragLayout) findViewById(R.id.drag_layout); - mDragLayout.removeDragCallback(mDragCallback); - mDragLayout.addDragCallback(mDragCallback); - mDragLayout.setCloseCallback(mCloseCallback); + mDragLayout.removeDragCallback(this); + mDragLayout.addDragCallback(this); + mDragLayout.setCloseCallback(this); mHistoryFrame = (FrameLayout) findViewById(R.id.history_frame); @@ -584,7 +550,7 @@ public class Calculator extends Activity @Override protected void onDestroy() { - mDragLayout.removeDragCallback(mDragCallback); + mDragLayout.removeDragCallback(this); super.onDestroy(); } @@ -1326,6 +1292,46 @@ public class Calculator extends Activity } } + /* Begin override CloseCallback method. */ + + @Override + public void onClose() { + removeHistoryFragment(); + } + + /* End override CloseCallback method. */ + + /* Begin override DragCallback methods */ + + @Override + public void onStartDraggingOpen() { + showHistoryFragment(FragmentTransaction.TRANSIT_NONE); + } + + @Override + public void whileDragging(float yFraction) { + // no-op + } + + @Override + public boolean shouldCaptureView(View view, int x, int y) { + return mDragLayout.isMoving() + || mDragLayout.isOpen() + || mDragLayout.isViewUnder(mDisplayView, x, y); + } + + @Override + public int getDisplayHeight() { + return mDisplayView.getMeasuredHeight(); + } + + @Override + public void onLayout(int translation) { + mHistoryFrame.setTranslationY(translation + mDisplayView.getBottom()); + } + + /* End override DragCallback methods */ + /** * Change evaluation state to one that's friendly to the history fragment. * Return false if that was not easily possible. diff --git a/src/com/android/calculator2/HistoryFragment.java b/src/com/android/calculator2/HistoryFragment.java index 9c9c573..454c47a 100644 --- a/src/com/android/calculator2/HistoryFragment.java +++ b/src/com/android/calculator2/HistoryFragment.java @@ -34,41 +34,11 @@ import java.util.ArrayList; import static android.support.v7.widget.RecyclerView.SCROLL_STATE_DRAGGING; -public class HistoryFragment extends Fragment { +public class HistoryFragment extends Fragment implements DragLayout.DragCallback { public static final String TAG = "HistoryFragment"; public static final String CLEAR_DIALOG_TAG = "clear"; - private final DragLayout.DragCallback mDragCallback = - new DragLayout.DragCallback() { - @Override - public void onStartDraggingOpen() { - // no-op - } - - @Override - public void whileDragging(float yFraction) { - mDragController.animateViews(yFraction, mRecyclerView); - } - - @Override - public boolean shouldCaptureView(View view, int x, int y) { - return view.getId() == R.id.history_frame - && mDragLayout.isViewUnder(view, x, y) - && !mRecyclerView.canScrollVertically(1 /* scrolling down */); - } - - @Override - public int getDisplayHeight() { - return 0; - } - - @Override - public void onLayout(int translation) { - // no-op - } - }; - private final DragController mDragController = new DragController(); private RecyclerView mRecyclerView; @@ -143,8 +113,8 @@ public class HistoryFragment extends Fragment { final boolean isResultLayout = activity.isResultLayout(); mDragLayout = (DragLayout) activity.findViewById(R.id.drag_layout); - mDragLayout.removeDragCallback(mDragCallback); - mDragLayout.addDragCallback(mDragCallback); + mDragLayout.removeDragCallback(this); + mDragLayout.addDragCallback(this); if (mEvaluator != null) { initializeController(isResultLayout); @@ -209,7 +179,7 @@ public class HistoryFragment extends Fragment { public void onDestroyView() { final DragLayout dragLayout = (DragLayout) getActivity().findViewById(R.id.drag_layout); if (dragLayout != null) { - dragLayout.removeDragCallback(mDragCallback); + dragLayout.removeDragCallback(this); } // Note that the view is destroyed when the fragment backstack is popped, so @@ -248,4 +218,35 @@ public class HistoryFragment extends Fragment { } return false; } + + /* Begin override DragCallback methods. */ + + @Override + public void onStartDraggingOpen() { + // no-op + } + + @Override + public void whileDragging(float yFraction) { + mDragController.animateViews(yFraction, mRecyclerView); + } + + @Override + public boolean shouldCaptureView(View view, int x, int y) { + return view.getId() == R.id.history_frame + && mDragLayout.isViewUnder(view, x, y) + && !mRecyclerView.canScrollVertically(1 /* scrolling down */); + } + + @Override + public int getDisplayHeight() { + return 0; + } + + @Override + public void onLayout(int translation) { + // no-op + } + + /* End override DragCallback methods. */ } |