diff options
author | Jeremy Klein <jlklein@google.com> | 2015-08-24 15:20:02 -0700 |
---|---|---|
committer | Jeremy Klein <jlklein@google.com> | 2015-08-24 15:29:54 -0700 |
commit | a4bd2bdd8fc29be53c8b5642f805a411ee16fada (patch) | |
tree | 6e9bf7ff5e688915187a872471b4f23d405dcbf0 /app/src/main/java/org/connectbot/ConsoleActivity.java | |
parent | 84ac082cbd1e31ac1a5646bc9a733bb305781016 (diff) | |
download | connectbot-a4bd2bdd8fc29be53c8b5642f805a411ee16fada.tar.gz connectbot-a4bd2bdd8fc29be53c8b5642f805a411ee16fada.tar.bz2 connectbot-a4bd2bdd8fc29be53c8b5642f805a411ee16fada.zip |
TabLayout.setupWithViewPager is broken. Implement a fixed version.
This fixes an issue where the tab indicator was disappearing when the
device was rotated. It also avoids a total crash when updating to 22.2.1
design support libraries.
Diffstat (limited to 'app/src/main/java/org/connectbot/ConsoleActivity.java')
-rw-r--r-- | app/src/main/java/org/connectbot/ConsoleActivity.java | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/app/src/main/java/org/connectbot/ConsoleActivity.java b/app/src/main/java/org/connectbot/ConsoleActivity.java index 9ac0c95..0e23979 100644 --- a/app/src/main/java/org/connectbot/ConsoleActivity.java +++ b/app/src/main/java/org/connectbot/ConsoleActivity.java @@ -623,7 +623,7 @@ public class ConsoleActivity extends AppCompatActivity implements BridgeDisconne tabs = (TabLayout) findViewById(R.id.tabs); if (tabs != null) - tabs.setupWithViewPager(pager); + setupTabLayoutWithViewPager(); // detect fling gestures to switch between terminals final GestureDetector detect = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() { @@ -799,6 +799,32 @@ public class ConsoleActivity extends AppCompatActivity implements BridgeDisconne } /** + * Ties the {@link TabLayout} to the {@link ViewPager}. + * + * <p>This method will: + * <ul> + * <li>Add a {@link ViewPager.OnPageChangeListener} that will forward events to + * this TabLayout.</li> + * <li>Populate the TabLayout's tabs from the ViewPager's {@link PagerAdapter}.</li> + * <li>Set our {@link TabLayout.OnTabSelectedListener} which will forward + * selected events to the ViewPager</li> + * </ul> + * </p> + */ + public void setupTabLayoutWithViewPager() { + tabs.setTabsFromPagerAdapter(adapter); + pager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabs)); + tabs.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(pager)); + + if (adapter.getCount() > 0) { + final int curItem = pager.getCurrentItem(); + if (tabs.getSelectedTabPosition() != curItem) { + tabs.getTabAt(curItem).select(); + } + } + } + + /** * */ private void configureOrientation() { |