Skip to content

Commit

Permalink
test matrix with camera;use translationz to create shadow
Browse files Browse the repository at this point in the history
  • Loading branch information
avenwu committed Jan 27, 2016
1 parent f570a2b commit 6530da2
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 4 deletions.
9 changes: 5 additions & 4 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
applicationId "com.avenwu.deepinandroid"
Expand Down Expand Up @@ -31,7 +31,8 @@ dependencies {
compile 'com.jakewharton:butterknife:6.0.0'
compile 'com.github.avenwu:IndexImageView:1.0.1'
compile 'com.drewnoakes:metadata-extractor:2.7.2'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:percent:23.1.0'
compile 'com.squareup.retrofit:retrofit:1.6.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.avenwu.deepinandroid;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
* Created by aven on 1/20/16.
*/
public class CameraMatrixFragmentDemo extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.camera_matrix_layout, null);
}
}
32 changes: 32 additions & 0 deletions sample/src/main/java/com/avenwu/deepinandroid/StackZFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.avenwu.deepinandroid;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


/**
* Created by aven on 1/27/16.
*/
public class StackZFragment extends Fragment {

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_stack_z, null);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
int count = ((ViewGroup) view).getChildCount();
for (int i = 0; i < count; i++) {
View card = ((ViewGroup) view).getChildAt(i);
ViewCompat.setTranslationZ(card, (i + 1) * 8 * getResources().getDisplayMetrics().density);
}
}
}
12 changes: 12 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@
android:text="Flip 3D"
android:onClick="openFragment"
android:tag="com.avenwu.deepinandroid.FlipFragmentDemo" />
<Button
style="@style/DemoItemStyle"
android:text="Matrix + Camera"
android:onClick="openFragment"
android:tag="com.avenwu.deepinandroid.CameraMatrixFragmentDemo" />

<Button
style="@style/DemoItemStyle"
android:text="Translation Z"
android:onClick="openFragment"
android:tag="com.avenwu.deepinandroid.StackZFragment" />

</LinearLayout>
</ScrollView>

Expand Down
27 changes: 27 additions & 0 deletions sample/src/main/res/layout/camera_matrix_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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"
android:clickable="true"
android:background="#fff">

<net.avenwu.support.widget.MatrixFrameLayout
android:layout_width="300dp"
android:layout_height="450dp"
android:layout_gravity="center"
android:layout_marginTop="30dp">

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/image2" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="This is label"
android:textSize="40sp" />
</net.avenwu.support.widget.MatrixFrameLayout>
</LinearLayout>
64 changes: 64 additions & 0 deletions sample/src/main/res/layout/fragment_stack_z.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:clickable="true">

<TextView
android:id="@+id/tv_card_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#009688"
android:gravity="center"
android:text="Card Label"
android:textColor="@android:color/black"
android:textSize="24sp"
app:layout_heightPercent="40%"
app:layout_marginLeftPercent="5%"
app:layout_marginTopPercent="10%"
app:layout_widthPercent="90%" />

<TextView
android:id="@+id/tv_card_2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4CAF50"
android:gravity="center"
android:text="Card Label"
android:textColor="@android:color/black"
android:textSize="24sp"
app:layout_heightPercent="40%"
app:layout_marginLeftPercent="5%"
app:layout_marginTopPercent="25%"
app:layout_widthPercent="90%" />

<TextView
android:id="@+id/tv_card_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#8BC34A"
android:gravity="center"
android:text="Card Label"
android:textColor="@android:color/black"
android:textSize="24sp"
app:layout_heightPercent="40%"
app:layout_marginLeftPercent="5%"
app:layout_marginTopPercent="40%"
app:layout_widthPercent="90%" />

<TextView
android:id="@+id/tv_card_4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#CDDC39"
android:gravity="center"
android:text="Card Label"
android:textColor="@android:color/black"
android:textSize="24sp"
app:layout_heightPercent="40%"
app:layout_marginLeftPercent="5%"
app:layout_marginTopPercent="55%"
app:layout_widthPercent="90%" />
</android.support.percent.PercentFrameLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package net.avenwu.support.widget;

import android.content.Context;
import android.graphics.Camera;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.util.AttributeSet;
import android.view.animation.Transformation;
import android.widget.FrameLayout;

/**
* Created by aven on 1/20/16.
*/
public class MatrixFrameLayout extends FrameLayout {
Camera mCamera = new Camera();
Transformation mTransformation = new Transformation();
private PaintFlagsDrawFilter mPaintFlagsDrawFilter = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);

public MatrixFrameLayout(Context context) {
this(context, null);
}

public MatrixFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
setWillNotDraw(false);
}

@Override
public void draw(Canvas canvas) {
mTransformation.clear();
mTransformation.setTransformationType(Transformation.TYPE_MATRIX);
Matrix matrix = mTransformation.getMatrix();
float degree = 15;
mCamera.save();
mCamera.rotateY(degree);
mCamera.getMatrix(matrix);
mCamera.restore();

final float centerY = getHeight() / 2f;
matrix.preTranslate(0, -centerY);
matrix.postTranslate(0, centerY);

canvas.save();
canvas.concat(mTransformation.getMatrix());
canvas.setDrawFilter(mPaintFlagsDrawFilter);
super.draw(canvas);
canvas.restore();
}
}

0 comments on commit 6530da2

Please sign in to comment.