Skip to content

Commit

Permalink
kiwix#1113 Add swipe gesture on the toolbar to switch tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
yashk2000 committed Jan 27, 2020
1 parent 7cb1d8c commit 4fa8ae7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 28 deletions.
Expand Up @@ -319,15 +319,17 @@ public void onSwipeBottom() {
public void onSwipeLeft() {
if (currentWebViewIndex < webViewList.size() - 1) {
View current = getCurrentWebView();
current.setAnimation(transitionLeft());
current.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.transition_left));
selectTab(currentWebViewIndex + 1);
}
}

@Override
public void onSwipeRight() {
if (currentWebViewIndex > 0) {
View current = getCurrentWebView();
current.setAnimation(transitionRight());
current.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.transition_right));
selectTab(currentWebViewIndex - 1);
}
}
});
Expand Down Expand Up @@ -372,32 +374,6 @@ public void onSwipeRight() {
new ItemTouchHelper(tabCallback).attachToRecyclerView(tabRecyclerView);
}

public Animation transitionRight() {
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f
);
inFromRight.setDuration(240);
inFromRight.setInterpolator(new AccelerateInterpolator());
selectTab(currentWebViewIndex - 1);
return inFromRight;
}

public Animation transitionLeft() {
Animation inFromLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f
);
inFromLeft.setDuration(240);
inFromLeft.setInterpolator(new AccelerateInterpolator());
selectTab(currentWebViewIndex + 1);
return inFromLeft;
}

//End of onCreate
private void handleIntentExtras(Intent intent) {

Expand Down
25 changes: 25 additions & 0 deletions core/src/main/res/anim/transition_left.xml
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Kiwix Android
~ Copyright (c) 2020 Kiwix <android.kiwix.org>
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
~
-->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_mediumAnimTime"
android:fromXDelta="0"
android:toXDelta="-100%"/>
</set>
25 changes: 25 additions & 0 deletions core/src/main/res/anim/transition_right.xml
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Kiwix Android
~ Copyright (c) 2020 Kiwix <android.kiwix.org>
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
~
-->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_mediumAnimTime"
android:fromXDelta="-100%"
android:toXDelta="0"/>
</set>

0 comments on commit 4fa8ae7

Please sign in to comment.