mirror of
https://github.com/syncthing/syncthing-android.git
synced 2025-01-13 13:35:53 +00:00
Ditched deprecated actionbar APIs and moved to Toolbar.
Also: Corrected styling of the tab layout to match previous implementation. App now follows material convention for side drawer overlapping the app bar.
This commit is contained in:
parent
7a94eb828c
commit
d54e1aa47c
17 changed files with 116 additions and 58 deletions
src/main
java/com/nutomic/syncthingandroid/activities
FolderPickerActivity.javaLogActivity.javaMainActivity.javaRestartActivity.javaSettingsActivity.javaSyncthingActivity.javaToolbarBindingActivity.javaWebGuiActivity.java
res
|
@ -61,8 +61,6 @@ public class FolderPickerActivity extends SyncthingActivity
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
setContentView(R.layout.activity_folder_picker);
|
||||
mListView = (ListView) findViewById(android.R.id.list);
|
||||
mListView.setOnItemClickListener(this);
|
||||
|
|
|
@ -41,7 +41,6 @@ public class LogActivity extends SyncthingActivity {
|
|||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_log);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mSyncthingLog = savedInstanceState.getBoolean("syncthingLog");
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.support.v4.app.FragmentPagerAdapter;
|
|||
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.ActionBarDrawerToggle;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
|
@ -110,9 +111,6 @@ public class MainActivity extends SyncthingActivity
|
|||
mDisabledDialog = null;
|
||||
}
|
||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
|
||||
mDrawerLayout.setDrawerListener(mDrawerToggle);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setHomeButtonEnabled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -190,8 +188,6 @@ public class MainActivity extends SyncthingActivity
|
|||
|
||||
private ViewPager mViewPager;
|
||||
|
||||
private TabLayout mTabLayout;
|
||||
|
||||
private ActionBarDrawerToggle mDrawerToggle;
|
||||
|
||||
private DrawerLayout mDrawerLayout;
|
||||
|
@ -208,8 +204,8 @@ public class MainActivity extends SyncthingActivity
|
|||
mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
|
||||
mTabLayout = (TabLayout) findViewById(R.id.tabContainer);
|
||||
mTabLayout.setupWithViewPager(mViewPager);
|
||||
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabContainer);
|
||||
tabLayout.setupWithViewPager(mViewPager);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
|
@ -231,6 +227,7 @@ public class MainActivity extends SyncthingActivity
|
|||
.replace(R.id.drawer, mDrawerFragment)
|
||||
.commit();
|
||||
mDrawerToggle = new Toggle(this, mDrawerLayout);
|
||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
|
||||
mDrawerLayout.setDrawerListener(mDrawerToggle);
|
||||
}
|
||||
|
||||
|
@ -274,7 +271,13 @@ public class MainActivity extends SyncthingActivity
|
|||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
|
||||
mDrawerToggle.syncState();
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -288,7 +291,6 @@ public class MainActivity extends SyncthingActivity
|
|||
return mDrawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles drawer opened and closed events, toggling option menu state.
|
||||
*/
|
||||
|
@ -301,16 +303,12 @@ public class MainActivity extends SyncthingActivity
|
|||
public void onDrawerOpened(View drawerView) {
|
||||
super.onDrawerOpened(drawerView);
|
||||
mDrawerFragment.onDrawerOpened();
|
||||
mFolderFragment.setHasOptionsMenu(false);
|
||||
mDevicesFragment.setHasOptionsMenu(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawerClosed(View view) {
|
||||
super.onDrawerClosed(view);
|
||||
mDrawerFragment.onDrawerClosed();
|
||||
mFolderFragment.setHasOptionsMenu(true);
|
||||
mDevicesFragment.setHasOptionsMenu(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.nutomic.syncthingandroid.activities;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
|
@ -9,12 +8,9 @@ import android.app.PendingIntent;
|
|||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.nutomic.syncthingandroid.BuildConfig;
|
||||
import com.nutomic.syncthingandroid.R;
|
||||
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
||||
|
||||
|
@ -32,8 +28,6 @@ public class RestartActivity extends SyncthingActivity {
|
|||
@TargetApi(11)
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// Using `<item name="windowActionBar">false</item>` in style causes crash.
|
||||
getSupportActionBar().hide();
|
||||
|
||||
final Intent intent = new Intent(this, SyncthingService.class)
|
||||
.setAction(SyncthingService.ACTION_RESTART);
|
||||
|
|
|
@ -37,7 +37,7 @@ public class SettingsActivity extends SyncthingActivity {
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
setContentView(R.layout.activity_settings);
|
||||
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
if (savedInstanceState != null) {
|
||||
|
@ -71,7 +71,7 @@ public class SettingsActivity extends SyncthingActivity {
|
|||
}
|
||||
|
||||
fm.beginTransaction()
|
||||
.replace(android.R.id.content, mFragment)
|
||||
.replace(R.id.content, mFragment)
|
||||
.commit();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@ import android.content.Intent;
|
|||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
||||
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
||||
|
@ -18,7 +16,7 @@ import java.util.LinkedList;
|
|||
/**
|
||||
* Connects to {@link SyncthingService} and provides access to it.
|
||||
*/
|
||||
public abstract class SyncthingActivity extends AppCompatActivity implements ServiceConnection {
|
||||
public abstract class SyncthingActivity extends ToolbarBindingActivity implements ServiceConnection {
|
||||
|
||||
private SyncthingService mSyncthingService;
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package com.nutomic.syncthingandroid.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
|
||||
import com.nutomic.syncthingandroid.R;
|
||||
|
||||
/**
|
||||
* An activity that onPostCreate will look for a Toolbar in the layout
|
||||
* and bind it as the activity's actionbar with reasonable defaults. <br/>
|
||||
* The Toolbar must exist in the content view and have an id of R.id.toolbar.<br/>
|
||||
* Trying to call getSupportActionBar before this Activity's onPostCreate will cause a crash.
|
||||
*/
|
||||
public class ToolbarBindingActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
if (toolbar != null) {
|
||||
setSupportActionBar(toolbar);
|
||||
//noinspection ConstantConditions
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -104,7 +104,6 @@ public class WebGuiActivity extends SyncthingActivity
|
|||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_web_gui);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
mLoadingView = findViewById(R.id.loading);
|
||||
loadCaCert();
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
<include layout="@layout/widget_toolbar" />
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/empty"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/directory_empty"
|
||||
android:layout_centerInParent="true" />
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</RelativeLayout>
|
||||
<TextView
|
||||
android:id="@android:id/empty"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/directory_empty" />
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<include layout="@layout/widget_toolbar" />
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/scroller"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical"
|
||||
android:fillViewport="true">
|
||||
|
||||
|
@ -16,9 +18,9 @@
|
|||
android:gravity="top"
|
||||
android:textSize="12sp"
|
||||
android:textIsSelectable="true"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
@ -9,10 +10,15 @@
|
|||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include layout="@layout/widget_toolbar" />
|
||||
|
||||
<android.support.design.widget.TabLayout
|
||||
android:id="@+id/tabContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?colorPrimary"
|
||||
android:elevation="@dimen/toolbar_elevation"
|
||||
app:theme="@style/ThemeOverlay.Syncthing.Toolbar" />
|
||||
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/pager"
|
||||
|
@ -28,4 +34,4 @@
|
|||
android:background="?android:windowBackground"
|
||||
android:clickable="true"
|
||||
android:elevation="16dp" />
|
||||
</android.support.v4.widget.DrawerLayout>
|
||||
</android.support.v4.widget.DrawerLayout>
|
13
src/main/res/layout/activity_settings.xml
Normal file
13
src/main/res/layout/activity_settings.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include layout="@layout/widget_toolbar" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
|
@ -1,8 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include layout="@layout/widget_toolbar" />
|
||||
|
||||
<WebView
|
||||
android:id="@+id/webview"
|
||||
|
@ -12,9 +14,8 @@
|
|||
|
||||
<LinearLayout
|
||||
android:id="@+id/loading"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
@ -30,4 +31,4 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:text="@string/web_gui_loading" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
|
|
10
src/main/res/layout/widget_toolbar.xml
Normal file
10
src/main/res/layout/widget_toolbar.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.Toolbar
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:actionBarSize"
|
||||
android:background="?colorPrimary"
|
||||
android:elevation="@dimen/toolbar_elevation"
|
||||
app:theme="@style/ThemeOverlay.Syncthing.Toolbar" />
|
|
@ -1,4 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="material_divider_inset">72dp</dimen>
|
||||
<dimen name="toolbar_elevation">4dp</dimen>
|
||||
</resources>
|
||||
|
|
|
@ -50,6 +50,11 @@
|
|||
<item name="android:minHeight">48dp</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.Syncthing.DrawerArrowToggle" parent="Widget.AppCompat.DrawerArrowToggle">
|
||||
<item name="spinBars">false</item>
|
||||
<item name="color">@android:color/white</item>
|
||||
</style>
|
||||
|
||||
<!-- Text appearances -->
|
||||
<eat-comment />
|
||||
|
||||
|
|
|
@ -4,11 +4,10 @@
|
|||
<!-- Activity themes -->
|
||||
<eat-comment/>
|
||||
|
||||
<style name="Theme.Syncthing.Base" parent="@style/Theme.AppCompat.Light.DarkActionBar">
|
||||
<style name="Theme.Syncthing.Base" parent="@style/Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="colorPrimary">@color/primary</item>
|
||||
<item name="colorPrimaryDark">@color/primary_dark</item>
|
||||
<item name="colorAccent">@color/accent</item>
|
||||
<item name="actionBarTheme">@style/ThemeOverlay.Syncthing.ActionBar</item>
|
||||
|
||||
<item name="textAppearanceListItemPrimary">@style/TextAppearance.Syncthing.ListItemPrimary</item>
|
||||
<item name="textAppearanceListItemSecondary">@style/TextAppearance.Syncthing.ListItemSecondary</item>
|
||||
|
@ -16,12 +15,12 @@
|
|||
|
||||
<item name="android:listViewStyle">@style/Widget.Syncthing.ListView</item>
|
||||
<item name="android:listDivider">@drawable/list_divider_inset</item>
|
||||
<item name="drawerArrowStyle">@style/Widget.Syncthing.DrawerArrowToggle</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Syncthing" parent="Theme.Syncthing.Base"/>
|
||||
|
||||
<style name="Theme.Syncthing.Translucent">
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:colorBackgroundCacheHint">@null</item>
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
|
@ -37,10 +36,10 @@
|
|||
<item name="colorControlActivated">@color/accent</item>
|
||||
</style>
|
||||
|
||||
<!-- ActionBar themes -->
|
||||
<!-- Toolbar themes -->
|
||||
<eat-comment/>
|
||||
|
||||
<style name="ThemeOverlay.Syncthing.ActionBar" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
|
||||
<style name="ThemeOverlay.Syncthing.Toolbar" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
|
||||
<item name="colorAccent">@android:color/white</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue