Loading src/com/android/calculator2/Calculator.java +12 −6 Original line number Diff line number Diff line Loading @@ -87,6 +87,7 @@ public class Calculator extends Activity implements OnTextSizeChangeListener, OnLongClickListener, AlertDialogFragment.OnClickListener, Evaluator.EvaluationListener /* for main result */ { private static final String TAG = "Calculator"; /** * Constant for an invalid resource id. */ Loading Loading @@ -221,9 +222,16 @@ public class Calculator extends Activity } }; private final DragLayout.CloseCallback mCloseCallback = new DragLayout.CloseCallback() { @Override public void onClose() { popFragmentBackstack(); } }; private final DragLayout.DragCallback mDragCallback = new DragLayout.DragCallback() { @Override public void onStartDragging() { public void onStartDraggingOpen() { showHistoryFragment(FragmentTransaction.TRANSIT_NONE); } Loading @@ -232,11 +240,6 @@ public class Calculator extends Activity // no-op } @Override public void onClosed() { popFragmentBackstack(); } @Override public boolean allowDrag(MotionEvent event) { return isViewTarget(mHistoryFrame, event) || isViewTarget(mDisplayView, event); Loading Loading @@ -414,6 +417,7 @@ public class Calculator extends Activity mDragLayout = (DragLayout) findViewById(R.id.drag_layout); mDragLayout.removeDragCallback(mDragCallback); mDragLayout.addDragCallback(mDragCallback); mDragLayout.setCloseCallback(mCloseCallback); mHistoryFrame = (FrameLayout) findViewById(R.id.history_frame); Loading Loading @@ -701,7 +705,9 @@ public class Calculator extends Activity return; } manager.popBackStack(); manager.executePendingTransactions(); } /** * Switch to INPUT from RESULT state in response to input of the specified button_id. * View.NO_ID is treated as an incomplete function id. Loading src/com/android/calculator2/DragLayout.java +25 −14 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ public class DragLayout extends RelativeLayout { private ViewDragHelper mDragHelper; private final List<DragCallback> mDragCallbacks = new ArrayList<>(); private CloseCallback mCloseCallback; private int mDraggingState = ViewDragHelper.STATE_IDLE; private int mDraggingBorder; Loading Loading @@ -158,7 +159,7 @@ public class DragLayout extends RelativeLayout { private void onStartDragging() { for (DragCallback c : mDragCallbacks) { c.onStartDragging(); c.onStartDraggingOpen(); } mHistoryFrame.setVisibility(VISIBLE); } Loading @@ -174,17 +175,15 @@ public class DragLayout extends RelativeLayout { public void setOpen() { mDragHelper.smoothSlideViewTo(mHistoryFrame, 0, mVerticalRange); mIsOpen = true; mHistoryFrame.setVisibility(VISIBLE); } public void setClosed() { // Scroll the RecyclerView to the bottom. for (DragCallback c : mDragCallbacks) { c.onClosed(); } mDragHelper.smoothSlideViewTo(mHistoryFrame, 0, 0); mIsOpen = false; } public void setCloseCallback(CloseCallback callback) { mCloseCallback = callback; } public void addDragCallback(DragCallback callback) { Loading @@ -195,19 +194,27 @@ public class DragLayout extends RelativeLayout { mDragCallbacks.remove(callback); } /** * Callback when the layout is closed. * We use this to pop the HistoryFragment off the backstack. * We can't use a method in DragCallback because we get ConcurrentModificationExceptions on * mDragCallbacks when executePendingTransactions() is called for popping the fragment off the * backstack. */ public interface CloseCallback { void onClose(); } /** * Callbacks for coordinating with the RecyclerView or HistoryFragment. */ public interface DragCallback { // Callback when a drag in any direction begins. void onStartDragging(); // Callback when a drag to open begins. void onStartDraggingOpen(); // Animate the RecyclerView text. void whileDragging(float yFraction); // Scroll the RecyclerView to the bottom before closing the frame. void onClosed(); // Whether we should allow the drag to happen boolean allowDrag(MotionEvent event); Loading @@ -232,12 +239,16 @@ public class DragLayout extends RelativeLayout { // The view stopped moving. if (mDraggingBorder == 0) { setClosed(); mIsOpen = false; mHistoryFrame.setVisibility(GONE); if (mCloseCallback != null) { mCloseCallback.onClose(); } } else if (mDraggingBorder == mVerticalRange) { setOpen(); mIsOpen = true; } } if (state == ViewDragHelper.STATE_DRAGGING) { } else if (state == ViewDragHelper.STATE_DRAGGING && !mIsOpen) { onStartDragging(); } mDraggingState = state; Loading src/com/android/calculator2/HistoryFragment.java +5 −7 Original line number Diff line number Diff line Loading @@ -38,7 +38,7 @@ public class HistoryFragment extends Fragment { private final DragLayout.DragCallback mDragCallback = new DragLayout.DragCallback() { @Override public void onStartDragging() { public void onStartDraggingOpen() { // no-op } Loading @@ -47,11 +47,6 @@ public class HistoryFragment extends Fragment { mDragController.animateViews(yFraction, mRecyclerView); } @Override public void onClosed() { mEvaluator.cancelNonMain(); } @Override public boolean allowDrag(MotionEvent event) { // Do not allow drag if the recycler view can move down more Loading Loading @@ -200,8 +195,11 @@ public class HistoryFragment extends Fragment { dragLayout.removeDragCallback(mDragCallback); } // Note that the view is destroyed when the fragment backstack is popped, so // these are essentially called when the DragLayout is closed. mEvaluator.cancelNonMain(); super.onDestroy(); super.onDestroyView(); } private void initializeController(boolean isResult) { Loading Loading
src/com/android/calculator2/Calculator.java +12 −6 Original line number Diff line number Diff line Loading @@ -87,6 +87,7 @@ public class Calculator extends Activity implements OnTextSizeChangeListener, OnLongClickListener, AlertDialogFragment.OnClickListener, Evaluator.EvaluationListener /* for main result */ { private static final String TAG = "Calculator"; /** * Constant for an invalid resource id. */ Loading Loading @@ -221,9 +222,16 @@ public class Calculator extends Activity } }; private final DragLayout.CloseCallback mCloseCallback = new DragLayout.CloseCallback() { @Override public void onClose() { popFragmentBackstack(); } }; private final DragLayout.DragCallback mDragCallback = new DragLayout.DragCallback() { @Override public void onStartDragging() { public void onStartDraggingOpen() { showHistoryFragment(FragmentTransaction.TRANSIT_NONE); } Loading @@ -232,11 +240,6 @@ public class Calculator extends Activity // no-op } @Override public void onClosed() { popFragmentBackstack(); } @Override public boolean allowDrag(MotionEvent event) { return isViewTarget(mHistoryFrame, event) || isViewTarget(mDisplayView, event); Loading Loading @@ -414,6 +417,7 @@ public class Calculator extends Activity mDragLayout = (DragLayout) findViewById(R.id.drag_layout); mDragLayout.removeDragCallback(mDragCallback); mDragLayout.addDragCallback(mDragCallback); mDragLayout.setCloseCallback(mCloseCallback); mHistoryFrame = (FrameLayout) findViewById(R.id.history_frame); Loading Loading @@ -701,7 +705,9 @@ public class Calculator extends Activity return; } manager.popBackStack(); manager.executePendingTransactions(); } /** * Switch to INPUT from RESULT state in response to input of the specified button_id. * View.NO_ID is treated as an incomplete function id. Loading
src/com/android/calculator2/DragLayout.java +25 −14 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ public class DragLayout extends RelativeLayout { private ViewDragHelper mDragHelper; private final List<DragCallback> mDragCallbacks = new ArrayList<>(); private CloseCallback mCloseCallback; private int mDraggingState = ViewDragHelper.STATE_IDLE; private int mDraggingBorder; Loading Loading @@ -158,7 +159,7 @@ public class DragLayout extends RelativeLayout { private void onStartDragging() { for (DragCallback c : mDragCallbacks) { c.onStartDragging(); c.onStartDraggingOpen(); } mHistoryFrame.setVisibility(VISIBLE); } Loading @@ -174,17 +175,15 @@ public class DragLayout extends RelativeLayout { public void setOpen() { mDragHelper.smoothSlideViewTo(mHistoryFrame, 0, mVerticalRange); mIsOpen = true; mHistoryFrame.setVisibility(VISIBLE); } public void setClosed() { // Scroll the RecyclerView to the bottom. for (DragCallback c : mDragCallbacks) { c.onClosed(); } mDragHelper.smoothSlideViewTo(mHistoryFrame, 0, 0); mIsOpen = false; } public void setCloseCallback(CloseCallback callback) { mCloseCallback = callback; } public void addDragCallback(DragCallback callback) { Loading @@ -195,19 +194,27 @@ public class DragLayout extends RelativeLayout { mDragCallbacks.remove(callback); } /** * Callback when the layout is closed. * We use this to pop the HistoryFragment off the backstack. * We can't use a method in DragCallback because we get ConcurrentModificationExceptions on * mDragCallbacks when executePendingTransactions() is called for popping the fragment off the * backstack. */ public interface CloseCallback { void onClose(); } /** * Callbacks for coordinating with the RecyclerView or HistoryFragment. */ public interface DragCallback { // Callback when a drag in any direction begins. void onStartDragging(); // Callback when a drag to open begins. void onStartDraggingOpen(); // Animate the RecyclerView text. void whileDragging(float yFraction); // Scroll the RecyclerView to the bottom before closing the frame. void onClosed(); // Whether we should allow the drag to happen boolean allowDrag(MotionEvent event); Loading @@ -232,12 +239,16 @@ public class DragLayout extends RelativeLayout { // The view stopped moving. if (mDraggingBorder == 0) { setClosed(); mIsOpen = false; mHistoryFrame.setVisibility(GONE); if (mCloseCallback != null) { mCloseCallback.onClose(); } } else if (mDraggingBorder == mVerticalRange) { setOpen(); mIsOpen = true; } } if (state == ViewDragHelper.STATE_DRAGGING) { } else if (state == ViewDragHelper.STATE_DRAGGING && !mIsOpen) { onStartDragging(); } mDraggingState = state; Loading
src/com/android/calculator2/HistoryFragment.java +5 −7 Original line number Diff line number Diff line Loading @@ -38,7 +38,7 @@ public class HistoryFragment extends Fragment { private final DragLayout.DragCallback mDragCallback = new DragLayout.DragCallback() { @Override public void onStartDragging() { public void onStartDraggingOpen() { // no-op } Loading @@ -47,11 +47,6 @@ public class HistoryFragment extends Fragment { mDragController.animateViews(yFraction, mRecyclerView); } @Override public void onClosed() { mEvaluator.cancelNonMain(); } @Override public boolean allowDrag(MotionEvent event) { // Do not allow drag if the recycler view can move down more Loading Loading @@ -200,8 +195,11 @@ public class HistoryFragment extends Fragment { dragLayout.removeDragCallback(mDragCallback); } // Note that the view is destroyed when the fragment backstack is popped, so // these are essentially called when the DragLayout is closed. mEvaluator.cancelNonMain(); super.onDestroy(); super.onDestroyView(); } private void initializeController(boolean isResult) { Loading