Add FAB (buggy)

This commit is contained in:
vanitasvitae 2017-09-14 03:06:09 +02:00
parent 64ed8b3d61
commit e54017584c
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
4 changed files with 57 additions and 13 deletions

View File

@ -24,7 +24,7 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
}

View File

@ -3,12 +3,14 @@ package de.trac.spherical;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
import java.io.FileNotFoundException;
@ -30,21 +32,38 @@ public class MainActivity extends AppCompatActivity {
private SphereSurfaceView surfaceView;
private Renderer renderer;
private FloatingActionButton fab;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize renderer and setup surface view.
surfaceView = new SphereSurfaceView(this);
renderer = new Renderer(surfaceView);
setContentView(surfaceView);
((LinearLayout) findViewById(R.id.container)).addView(surfaceView);
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SphereSurfaceView.USE_TOUCH = !SphereSurfaceView.USE_TOUCH;
fab.hide();
}
});
fab.hide();
// Detect gestures like single taps.
final GestureDetector mGesDetect = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapConfirmed(MotionEvent event) {
SphereSurfaceView.USE_TOUCH = !SphereSurfaceView.USE_TOUCH;
if (fab.isShown()) {
fab.hide();
} else {
fab.show();
}
return true;
}
});

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFF"
android:pathData="M12 10.9c-.61 0-1.1 .49 -1.1 1.1s.49 1.1 1.1 1.1c.61 0 1.1-.49
1.1-1.1s-.49-1.1-1.1-1.1zM12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48
10-10S17.52 2 12 2zm2.19 12.19L6 18l3.81-8.19L18 6l-3.81 8.19z" />
<path
android:pathData="M0 0h24v24H0z" />
</vector>

View File

@ -1,19 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="de.trac.spherical.MainActivity">
<TextView
android:id="@+id/hello_world"
<LinearLayout
android:id="@+id/container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="8dp">
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:src="@drawable/ic_explore_white_48px"
app:fabSize="auto"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"/>
<android.opengl.GLSurfaceView
android:id="@+id/surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
app:layout_anchor="@id/container"
app:layout_anchorGravity="bottom|right|end" />
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout>