Add AnimatedTabLayout library to project and use it in the SettingsActivity, the library still needs some improvements to use it correctly on the MainActivity (Board)

This commit is contained in:
Severiano Jaramillo 2018-06-20 17:25:29 -05:00
parent cea9e8faeb
commit c19839a921
5 changed files with 35 additions and 73 deletions

View file

@ -63,6 +63,7 @@ dependencies {
implementation 'com.github.bilthon:graphenej:0.4.6'
implementation 'com.google.zxing:core:3.3.1'
implementation 'me.dm7.barcodescanner:zxing:1.9.8'
implementation 'com.github.sjaramillo10:AnimatedTabLayout:v1.0.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.5.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'

View file

@ -5,15 +5,11 @@ import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.FileObserver;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
@ -30,9 +26,9 @@ import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import com.sjaramillo10.animatedtablayout.AnimatedTabLayout;
import java.io.File;
import java.util.List;
import java.util.Locale;
import butterknife.BindView;
import butterknife.ButterKnife;
@ -53,6 +49,9 @@ import cy.agorise.crystalwallet.viewmodels.CryptoNetBalanceListViewModel;
public class BoardActivity extends AppCompatActivity {
@BindView(R.id.tabLayout)
public TabLayout tabLayout;
@BindView(R.id.pager)
public ViewPager mPager;
@ -123,11 +122,7 @@ public class BoardActivity extends AppCompatActivity {
boardAdapter = new BoardPagerAdapter(getSupportFragmentManager());
mPager.setAdapter(boardAdapter);
TabLayout tabLayout = findViewById(R.id.tabs);
mPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mPager));
tabLayout.setupWithViewPager(mPager);
fabReceive.setOnClickListener(new View.OnClickListener() {
@Override
@ -294,6 +289,9 @@ public class BoardActivity extends AppCompatActivity {
super(fm);
}
// Titles of the tabs
int[] tabTitles = {R.string.balances, R.string.transactions, R.string.contacts};
@Override
public Fragment getItem(int position) {
switch (position){
@ -309,6 +307,11 @@ public class BoardActivity extends AppCompatActivity {
return null; //new OnConstructionFragment();
}
@Override
public CharSequence getPageTitle(int position) {
return getString(tabTitles[position]);
}
@Override
public int getCount() {
return 3;

View file

@ -2,7 +2,6 @@ package cy.agorise.crystalwallet.activities;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
@ -14,15 +13,13 @@ import android.view.SurfaceView;
import android.widget.ImageView;
import android.widget.TextView;
import com.sjaramillo10.animatedtablayout.AnimatedTabLayout;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cy.agorise.crystalwallet.BuildConfig;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.application.CrystalSecurityMonitor;
import cy.agorise.crystalwallet.fragments.AccountsSettingsFragment;
import cy.agorise.crystalwallet.fragments.BackupsSettingsFragment;
import cy.agorise.crystalwallet.fragments.BalanceFragment;
import cy.agorise.crystalwallet.fragments.GeneralSettingsFragment;
import cy.agorise.crystalwallet.fragments.SecuritySettingsFragment;
@ -36,6 +33,9 @@ public class SettingsActivity extends AppCompatActivity{
@BindView(R.id.ivGoBack)
public ImageView ivGoBack;
@BindView(R.id.tabLayout)
public AnimatedTabLayout tabLayout;
@BindView(R.id.pager)
public ViewPager mPager;
@ -80,11 +80,7 @@ public class SettingsActivity extends AppCompatActivity{
settingsPagerAdapter = new SettingsPagerAdapter(getSupportFragmentManager());
mPager.setAdapter(settingsPagerAdapter);
TabLayout tabLayout = findViewById(R.id.tabs);
mPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mPager));
tabLayout.setupWithViewPager(mPager);
}
private class SettingsPagerAdapter extends FragmentStatePagerAdapter {
@ -92,6 +88,9 @@ public class SettingsActivity extends AppCompatActivity{
super(fm);
}
int[] tabTitles = {R.string.general, R.string.security, R.string.backups,
R.string.accounts};
@Override
public Fragment getItem(int position) {
switch (position){
@ -109,6 +108,11 @@ public class SettingsActivity extends AppCompatActivity{
return null; //new OnConstructionFragment();
}
@Override
public CharSequence getPageTitle(int position) {
return getString(tabTitles[position]);
}
@Override
public int getCount() {
return 3;

View file

@ -79,39 +79,13 @@
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
<com.sjaramillo10.animatedtablayout.AnimatedTabLayout
android:id="@+id/tabLayout"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true">
<android.support.design.widget.TabItem
android:id="@+id/tabItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/general" />
<android.support.design.widget.TabItem
android:id="@+id/tabItem2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/security" />
<android.support.design.widget.TabItem
android:id="@+id/tabItem3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/backups" />
<!--<android.support.design.widget.TabItem
android:id="@+id/tabItem4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/accounts"
android:visibility="gone" />-->
</android.support.design.widget.TabLayout>
android:animateLayoutChanges="true"
app:tabMode="fixed" />
</RelativeLayout>

View file

@ -97,32 +97,12 @@
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:id="@+id/tabLayout"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="pin"
android:animateLayoutChanges="true">
<android.support.design.widget.TabItem
android:id="@+id/tabItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/balances" />
<android.support.design.widget.TabItem
android:id="@+id/tabItem2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/transactions" />
<android.support.design.widget.TabItem
android:id="@+id/tabItem3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/contacts" />
</android.support.design.widget.TabLayout>
android:animateLayoutChanges="true" />
</android.support.design.widget.CollapsingToolbarLayout>