Skip to content

Commit

Permalink
示例程序
Browse files Browse the repository at this point in the history
上传示例程序
  • Loading branch information
GcsSloop committed May 9, 2015
1 parent cadfb9e commit 36c493a
Show file tree
Hide file tree
Showing 25 changed files with 8,701 additions and 0 deletions.
Binary file added APK/3D翻转.apk
Binary file not shown.
9 changes: 9 additions & 0 deletions Sample/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
33 changes: 33 additions & 0 deletions Sample/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Sample__3D翻转</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
4 changes: 4 additions & 0 deletions Sample/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.source=1.6
28 changes: 28 additions & 0 deletions Sample/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sloop.fz3d"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="22" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:theme="@android:style/Theme.Holo.Light"
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
1,154 changes: 1,154 additions & 0 deletions Sample/gen/android/support/v7/appcompat/R.java

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Sample/gen/com/sloop/fz3d/BuildConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** Automatically generated file. DO NOT MODIFY */
package com.sloop.fz3d;

public final class BuildConfig {
public final static boolean DEBUG = true;
}
7,147 changes: 7,147 additions & 0 deletions Sample/gen/com/sloop/fz3d/R.java

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions Sample/proguard-project.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
15 changes: 15 additions & 0 deletions Sample/project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-22
android.library.reference.1=../appcompat_v7
Binary file added Sample/res/drawable-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sample/res/drawable-hdpi/sloop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sample/res/drawable-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sample/res/drawable-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sample/res/drawable-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions Sample/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cfcfcf" >

<ImageView
android:layout_marginTop="20dp"
android:layout_centerInParent="true"
android:id="@+id/iv_sloop"
android:layout_width="300dp"
android:layout_height="300dp"
android:src="@drawable/sloop" />

</RelativeLayout>
12 changes: 12 additions & 0 deletions Sample/res/menu/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<menu 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"
tools:context="com.sloop.fz3d.MainActivity" >

<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"/>

</menu>
11 changes: 11 additions & 0 deletions Sample/res/values-v11/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<resources>

<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- API 11 theme customizations can go here. -->
</style>

</resources>
12 changes: 12 additions & 0 deletions Sample/res/values-v14/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<resources>

<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>

</resources>
10 changes: 10 additions & 0 deletions Sample/res/values-w820dp/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<resources>

<!--
Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively).
-->
<dimen name="activity_horizontal_margin">64dp</dimen>

</resources>
7 changes: 7 additions & 0 deletions Sample/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<resources>

<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>

</resources>
8 changes: 8 additions & 0 deletions Sample/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">Sloop__3D翻转</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>

</resources>
20 changes: 20 additions & 0 deletions Sample/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<resources>

<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

</resources>
127 changes: 127 additions & 0 deletions Sample/src/com/sloop/animation/Rotate3dAnimation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/**
* @Title: Rotate3dAnimation.java
* @Package com.sloop.animation
* Copyright: Copyright (c) 2015
*
* @author sloop
* @date 2015年3月10日 上午11:20:10
* @version V1.0
*/

package com.sloop.animation;

import android.graphics.Camera;
import android.graphics.Matrix;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.animation.Animation;
import android.view.animation.Transformation;

/**
* 3D翻转特效
* @ClassName: Rotate3dAnimation
* @author sloop
* @date 2015年3月10日 上午11:20:10
*/

public class Rotate3dAnimation extends Animation {

// 开始角度
private final float mFromDegrees;
// 结束角度
private final float mToDegrees;
// 中心点
private final float mCenterX;
private final float mCenterY;
private final float mDepthZ; //深度
// 是否需要扭曲
private final boolean mReverse;
// 摄像头
private Camera mCamera;
ContextThemeWrapper context;
//新增--像素比例(默认值为1)
float scale = 1;

/**
* 创建一个新的实例 Rotate3dAnimation.
* @param fromDegrees 开始角度
* @param toDegrees 结束角度
* @param centerX 中心点x坐标
* @param centerY 中心点y坐标
* @param depthZ 深度
* @param reverse 是否扭曲
*/
public Rotate3dAnimation(ContextThemeWrapper context, float fromDegrees, float toDegrees, float centerX, float centerY, float depthZ, boolean reverse) {
this.context = context;
mFromDegrees = fromDegrees;
mToDegrees = toDegrees;
mCenterX = centerX;
mCenterY = centerY;
mDepthZ = depthZ;
mReverse = reverse;
//获取手机像素比 (即dp与px的比例)
scale = context.getResources().getDisplayMetrics().density;
Log.e("scale",""+scale);
}

@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {

super.initialize(width, height, parentWidth, parentHeight);
mCamera = new Camera();
}

// 生成Transformation
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
final float fromDegrees = mFromDegrees;
// 生成中间角度
float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);


final float centerX = mCenterX;
final float centerY = mCenterY;
final Camera camera = mCamera;

final Matrix matrix = t.getMatrix();

camera.save();
if (mReverse) {
camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
} else {
camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
}
camera.rotateY(degrees);
// 取得变换后的矩阵
camera.getMatrix(matrix);
camera.restore();

//----------------------------------------------------------------------------
/**
* 修复打脸问题 ( ̄ε(# ̄)☆╰╮( ̄▽ ̄///)
* 简要介绍:
* 原来的3D翻转会由于屏幕像素密度问题而出现效果相差很大
* 例如在屏幕像素比为1,5的手机上显示效果基本正常,
* 而在像素比3,0的手机上面感觉翻转感觉要超出屏幕边缘,
* 有种迎面打脸的感觉、
*
* 解决方案
* 利用屏幕像素密度对变换矩阵进行校正,
* 保证了在所有清晰度的手机上显示的效果基本相同。
*
*/
float[] mValues = {0,0,0,0,0,0,0,0,0};
matrix.getValues(mValues); //获取数值
mValues[6] = mValues[6]/scale; //数值修正
matrix.setValues(mValues); //重新赋值

// Log.e("TAG", "mValues["+0+"]="+mValues[0]+"------------\t"+"mValues["+6+"]="+mValues[6]);
//----------------------------------------------------------------------------

matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}



}
Loading

0 comments on commit 36c493a

Please sign in to comment.