Added material design to closeAllTabs FAB (#1045)

This commit is contained in:
Sonu Sourav 2019-03-31 02:05:53 +05:30 committed by Isaac Hutt
parent 3c8c9d459f
commit 6c07ca4649
7 changed files with 73 additions and 12 deletions

View File

@ -112,6 +112,7 @@ import static android.os.Build.VERSION_CODES;
import static org.kiwix.kiwixmobile.main.TableDrawerAdapter.DocumentSection;
import static org.kiwix.kiwixmobile.main.TableDrawerAdapter.TableClickListener;
import static org.kiwix.kiwixmobile.search.SearchActivity.EXTRA_SEARCH_IN_TEXT;
import static org.kiwix.kiwixmobile.utils.AnimationUtils.rotate;
import static org.kiwix.kiwixmobile.utils.Constants.BOOKMARK_CHOSEN_REQUEST;
import static org.kiwix.kiwixmobile.utils.Constants.EXTRA_CHOSE_X_TITLE;
import static org.kiwix.kiwixmobile.utils.Constants.EXTRA_CHOSE_X_URL;
@ -195,6 +196,8 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
RecyclerView tabRecyclerView;
@BindView(R.id.activity_main_tab_switcher)
View tabSwitcherRoot;
@BindView(R.id.tab_switcher_close_all_tabs)
FloatingActionButton closeAllTabsButton;
private CountDownTimer hideBackToTopTimer = new CountDownTimer(1200, 1200) {
@Override
public void onTick(long millisUntilFinished) {
@ -512,6 +515,8 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
actionBar.setDisplayShowTitleEnabled(true);
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
closeAllTabsButton.setImageDrawable(
ContextCompat.getDrawable(this, R.drawable.ic_close_white_24dp));
tabSwitcherRoot.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE);
contentFrame.setVisibility(View.VISIBLE);
@ -783,17 +788,10 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
updateTabSwitcherIcon();
})
.show();
openDefaultTab();
openHomeScreen();
updateTabSwitcherIcon();
}
private void openDefaultTab() {
new Handler().postDelayed(() -> {
if (webViewList.size() == 0) {
newTab(HOME_URL);
}
}, 100);
}
private void selectTab(int position) {
currentWebViewIndex = position;
tabsAdapter.setSelected(position);
@ -1162,12 +1160,23 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
@OnClick(R.id.tab_switcher_close_all_tabs)
void closeAllTabs() {
rotate(closeAllTabsButton);
webViewList.clear();
tabsAdapter.notifyDataSetChanged();
openDefaultTab();
openHomeScreen();
updateTabSwitcherIcon();
}
//opens home screen when user closes all tabs
private void openHomeScreen() {
new Handler().postDelayed(() -> {
if (webViewList.size() == 0) {
newTab(HOME_URL);
hideTabSwitcher();
}
}, 300);
}
@OnClick(R.id.bottom_toolbar_bookmark)
public void toggleBookmark() {
//Check maybe need refresh

View File

@ -3,7 +3,11 @@ package org.kiwix.kiwixmobile.utils;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.view.animation.Transformation;
import androidx.core.content.ContextCompat;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import org.kiwix.kiwixmobile.R;
public class AnimationUtils {
public static void expand(final View view) {
@ -61,4 +65,29 @@ public class AnimationUtils {
(int) (initialHeight / view.getContext().getResources().getDisplayMetrics().density));
view.startAnimation(animation);
}
//rotate animation for closeAllTabs FAB
public static void rotate(FloatingActionButton v) {
RotateAnimation wheelRotation =
new RotateAnimation(0.0f, 360f, v.getWidth() / 2.0f, v.getHeight() / 2.0f);
wheelRotation.setDuration(200);
wheelRotation.setRepeatCount(0);
wheelRotation.setInterpolator(v.getContext(), android.R.interpolator.cycle);
v.startAnimation(wheelRotation);
wheelRotation.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationEnd(Animation animation) {
v.setImageDrawable(
ContextCompat.getDrawable(v.getContext(), R.drawable.ic_done_white_24dp));
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
v.setImageDrawable(
ContextCompat.getDrawable(v.getContext(), R.drawable.ic_close_white_24dp));
}
});
}
}

View File

@ -1,9 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportHeight="24.0"
android:viewportWidth="24.0"
android:width="24dp">
<path
android:fillColor="#FFFFFF"
android:fillColor="#000000"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:tint="#000000"
android:viewportHeight="24.0"
android:viewportWidth="24.0"
android:width="24dp">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:tint="@color/greenTick"
android:viewportHeight="24.0"
android:viewportWidth="24.0"
android:width="24dp">
<path
android:fillColor="@android:color/white"
android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
</vector>

View File

@ -21,10 +21,10 @@
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:contentDescription="@string/close_all_tabs"
app:backgroundTint="@android:color/black"
app:backgroundTint="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/ic_clear_white_24dp"
app:srcCompat="@drawable/ic_close_white_24dp"
/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -25,6 +25,8 @@
<color name="blueTransparent">#962e7ac4</color>
<color name="actionModeBackground">#4285F4</color>
<color name="titleBar">#000000</color>
<color name="greenTick">#4CAF50</color>
<!-- Dark Text Color for Light Background -->
<color name="textDarkPrimary">#000000</color> <!-- 0% opacity-->
<color name="textDarkSecondary">#DE000000</color> <!--DE for 87% opacity-->