Embed PartCanvasView as part of a layout.

This commit is contained in:
kenkeiras 2017-07-09 10:46:47 -04:00
parent 67e8f7585b
commit a961c55407
7 changed files with 61 additions and 18 deletions

View File

@ -27,4 +27,5 @@ dependencies {
implementation 'com.android.support:appcompat-v7:25.4.0'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:25.4.0'
}

View File

@ -13,8 +13,6 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".TestActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -6,6 +6,7 @@ import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
@ -21,13 +22,9 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
class PartCanvasView extends View {
@ -53,6 +50,15 @@ class PartCanvasView extends View {
public PartCanvasView(Context context) {
super(context);
init();
}
public PartCanvasView(Context context, AttributeSet attr){
super(context, attr);
init();
}
private void init() {
this.setBackgroundColor(Color.rgb(4, 69, 99));
if (!loadState()){

View File

@ -1,9 +1,12 @@
package com.codigoparallevar.minicards;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
public class TestActivity extends AppCompatActivity {
@ -20,8 +23,18 @@ public class TestActivity extends AppCompatActivity {
}
// Use controled canvas
partCanvasView = new PartCanvasView(this);
setContentView(partCanvasView);
setContentView(R.layout.activity_test);
partCanvasView = (PartCanvasView) findViewById(R.id.canvasView);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
@Override

View File

@ -1,18 +1,40 @@
<?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="com.codigoparallevar.minicards.TestActivity">
tools:context="com.codigoparallevar.minicards.parts.buttons.MainActivity">
<TextView
<!--
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
-->
<com.codigoparallevar.minicards.PartCanvasView
android:id="@+id/canvasView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- include layout="@layout/content_main" / -->
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout>

View File

@ -0,0 +1,3 @@
<resources>
<dimen name="fab_margin">16dp</dimen>
</resources>

View File

@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha4'
classpath 'com.android.tools.build:gradle:3.0.0-alpha5'
// NOTE: Do not place your application dependencies here; they belong