mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-26 22:31:16 +00:00
Initial replacement of deprecated actionbar tabs with TabLayout.
Still uses default styling.
This commit is contained in:
parent
eb4f633130
commit
8e04ce3afa
4 changed files with 35 additions and 38 deletions
|
@ -27,6 +27,8 @@ repositories {
|
|||
dependencies {
|
||||
compile 'eu.chainfire:libsuperuser:1.0.0.201504231659'
|
||||
compile 'com.android.support:appcompat-v7:22.2.1'
|
||||
compile 'com.android.support:design:22.2.1'
|
||||
compile 'com.android.support:appcompat-v7:22.2.1'
|
||||
compile 'com.android.support:support-v4-preferencefragment:1.0.0@aar'
|
||||
androidTestCompile 'com.squareup.okhttp:mockwebserver:2.4.0'
|
||||
}
|
||||
|
|
|
@ -13,16 +13,13 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBar.Tab;
|
||||
import android.support.v7.app.ActionBar.TabListener;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
|
@ -172,6 +169,17 @@ public class MainActivity extends SyncthingActivity
|
|||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return getResources().getString(R.string.folders_fragment_title);
|
||||
case 1:
|
||||
return getResources().getString(R.string.devices_fragment_title);
|
||||
default:
|
||||
return String.valueOf(position);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private FoldersFragment mFolderFragment;
|
||||
|
@ -182,6 +190,8 @@ public class MainActivity extends SyncthingActivity
|
|||
|
||||
private ViewPager mViewPager;
|
||||
|
||||
private TabLayout mTabLayout;
|
||||
|
||||
private ActionBarDrawerToggle mDrawerToggle;
|
||||
|
||||
private DrawerLayout mDrawerLayout;
|
||||
|
@ -191,41 +201,15 @@ public class MainActivity extends SyncthingActivity
|
|||
*/
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||
setContentView(R.layout.activity_main);
|
||||
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
|
||||
mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
actionBar.setSelectedNavigationItem(position);
|
||||
}
|
||||
});
|
||||
|
||||
TabListener tabListener = new TabListener() {
|
||||
public void onTabSelected(Tab tab, FragmentTransaction ft) {
|
||||
mViewPager.setCurrentItem(tab.getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(Tab tab, FragmentTransaction ft) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
|
||||
}
|
||||
};
|
||||
|
||||
actionBar.addTab(actionBar.newTab()
|
||||
.setText(R.string.folders_fragment_title)
|
||||
.setTabListener(tabListener));
|
||||
actionBar.addTab(actionBar.newTab()
|
||||
.setText(R.string.devices_fragment_title)
|
||||
.setTabListener(tabListener));
|
||||
mTabLayout = (TabLayout) findViewById(R.id.tabContainer);
|
||||
mTabLayout.setupWithViewPager(mViewPager);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
|
|
|
@ -18,7 +18,7 @@ import java.util.LinkedList;
|
|||
/**
|
||||
* Connects to {@link SyncthingService} and provides access to it.
|
||||
*/
|
||||
public class SyncthingActivity extends AppCompatActivity implements ServiceConnection {
|
||||
public abstract class SyncthingActivity extends AppCompatActivity implements ServiceConnection {
|
||||
|
||||
private SyncthingService mSyncthingService;
|
||||
|
||||
|
@ -28,7 +28,7 @@ public class SyncthingActivity extends AppCompatActivity implements ServiceConne
|
|||
* To be used for Fragments.
|
||||
*/
|
||||
public interface OnServiceConnectedListener {
|
||||
public void onServiceConnected();
|
||||
void onServiceConnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,10 +4,21 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/pager"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.design.widget.TabLayout
|
||||
android:id="@+id/tabContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/drawer"
|
||||
|
@ -16,5 +27,5 @@
|
|||
android:layout_gravity="start"
|
||||
android:background="?android:windowBackground"
|
||||
android:clickable="true"
|
||||
android:elevation="16dp"/>
|
||||
android:elevation="16dp" />
|
||||
</android.support.v4.widget.DrawerLayout>
|
||||
|
|
Loading…
Reference in a new issue