1
0
Fork 0
mirror of https://github.com/vanitasvitae/Spherical synced 2024-11-25 05:42:09 +01:00

Make system bars completely transparent

This commit is contained in:
vanitasvitae 2017-09-15 00:56:08 +02:00
parent a497955836
commit 09241253c8
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 42 additions and 28 deletions

View file

@ -3,6 +3,7 @@ package de.trac.spherical;
import android.content.Intent; import android.content.Intent;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.AppBarLayout; import android.support.design.widget.AppBarLayout;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
@ -15,7 +16,10 @@ import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast; import android.widget.Toast;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -38,7 +42,6 @@ public class MainActivity extends AppCompatActivity {
private Renderer renderer; private Renderer renderer;
private FloatingActionButton fab; private FloatingActionButton fab;
private Toolbar toolbar; private Toolbar toolbar;
private AppBarLayout appBarLayout;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -49,10 +52,9 @@ public class MainActivity extends AppCompatActivity {
toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(false);
appBarLayout = (AppBarLayout) findViewById(R.id.lay_toolbar); RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) toolbar.getLayoutParams();
AppBarLayout.LayoutParams lp = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
lp.topMargin += getStatusBarHeight(); lp.topMargin += getStatusBarHeight();
appBarLayout.bringToFront(); toolbar.bringToFront();
fab = (FloatingActionButton) findViewById(R.id.fab); fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() { fab.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -62,6 +64,11 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
// Initialize renderer and setup surface view. // Initialize renderer and setup surface view.
LinearLayout container = (LinearLayout) findViewById(R.id.container); LinearLayout container = (LinearLayout) findViewById(R.id.container);
surfaceView = new SphereSurfaceView(this); surfaceView = new SphereSurfaceView(this);
@ -102,10 +109,10 @@ public class MainActivity extends AppCompatActivity {
private void displayUI(boolean display) { private void displayUI(boolean display) {
if (display) { if (display) {
fab.show(); fab.show();
appBarLayout.setExpanded(true, true); toolbar.setVisibility(View.VISIBLE);
} else { } else {
fab.setVisibility(View.INVISIBLE); fab.setVisibility(View.INVISIBLE);
appBarLayout.setExpanded(false, true); toolbar.setVisibility(View.GONE);
} }
} }
@ -223,6 +230,7 @@ public class MainActivity extends AppCompatActivity {
*/ */
private void displayFlatImage(InputStream inputStream) { private void displayFlatImage(InputStream inputStream) {
Log.d(TAG, "Display Flat Image!"); Log.d(TAG, "Display Flat Image!");
displayPhotoSphere(inputStream, new PhotoSphereMetadata());
} }
public int getStatusBarHeight() { public int getStatusBarHeight() {

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
@ -9,28 +9,18 @@
android:fitsSystemWindows="false" android:fitsSystemWindows="false"
tools:context="de.trac.spherical.MainActivity"> tools:context="de.trac.spherical.MainActivity">
<android.support.design.widget.AppBarLayout <android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/lay_toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="?attr/actionBarSize"
android:fitsSystemWindows="false" android:fitsSystemWindows="true"
android:background="@android:color/transparent" android:background="@android:color/transparent"
app:elevation="0dp"> android:layout_alignParentTop="true"
app:layout_scrollFlags="scroll|enterAlways|snap"
<android.support.v7.widget.Toolbar app:theme="@style/AppTheme.ActionBar"
xmlns:android="http://schemas.android.com/apk/res/android" app:popupTheme="@style/ThemeOverlay.AppCompat" />
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:theme="@style/AppTheme.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat" />
</android.support.design.widget.AppBarLayout>
<LinearLayout <LinearLayout
android:id="@+id/container" android:id="@+id/container"
@ -45,7 +35,9 @@
android:id="@+id/fab" android:id="@+id/fab"
android:src="@drawable/ic_explore_white_48px" android:src="@drawable/ic_explore_white_48px"
app:fabSize="mini" app:fabSize="mini"
android:layout_gravity="bottom|end" android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="64dp" android:layout_marginBottom="64dp"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
@ -54,4 +46,4 @@
app:layout_anchor="@id/container" app:layout_anchor="@id/container"
app:layout_anchorGravity="bottom|right|end" /> app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout> </RelativeLayout>

View file

@ -1,2 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources></resources> <resources>
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="windowActionBarOverlay">false</item>
<item name="android:windowActionBarOverlay">false</item>
<item name="android:fitsSystemWindows">false</item>
</style>
</resources>