├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── study │ │ └── xuan │ │ └── vrshow │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ ├── BelleBook_Big.stl │ │ ├── andes1.jpg │ │ ├── bai.stl │ │ └── bb.jpg │ ├── java │ │ └── com │ │ │ └── study │ │ │ └── xuan │ │ │ └── vrshow │ │ │ ├── GifActivity.java │ │ │ ├── GoogleActivity.java │ │ │ ├── MainActivity.java │ │ │ └── STLActivity.java │ └── res │ │ ├── drawable │ │ └── demo.gif │ │ ├── layout │ │ ├── activity_gif.xml │ │ ├── activity_google.xml │ │ ├── activity_main.xml │ │ ├── activity_stl.xml │ │ └── main_layout.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── study │ └── xuan │ └── vrshow │ └── ExampleUnitTest.java ├── build.gradle ├── gif ├── book.gif ├── gifdemo.gif └── googlefinal.gif ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── study │ │ └── xuan │ │ └── gifshow │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── study │ │ │ └── xuan │ │ │ └── gifshow │ │ │ ├── gif │ │ │ └── VrGifView.java │ │ │ ├── util │ │ │ └── ScreenUtil.java │ │ │ └── widget │ │ │ └── stlview │ │ │ ├── callback │ │ │ ├── OnReadCallBack.java │ │ │ └── OnReadListener.java │ │ │ ├── model │ │ │ └── STLModel.java │ │ │ ├── operate │ │ │ ├── ISTLReader.java │ │ │ ├── ReaderHandler.java │ │ │ └── STLReader.java │ │ │ ├── util │ │ │ ├── IOUtils.java │ │ │ ├── STLUtils.java │ │ │ └── ScreenUtil.java │ │ │ └── widget │ │ │ ├── STLRenderer.java │ │ │ ├── STLView.java │ │ │ └── STLViewBuilder.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── study │ └── xuan │ └── gifshow │ └── ExampleUnitTest.java ├── settings.gradle └── stlshow ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src ├── androidTest └── java │ └── com │ └── study │ └── xuan │ └── stlshow │ └── ExampleInstrumentedTest.java ├── main ├── AndroidManifest.xml └── res │ └── values │ └── strings.xml └── test └── java └── com └── study └── xuan └── stlshow └── ExampleUnitTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VRShow 2 | VR全景图+Opengl3D模型展示 3 | **使用方式:** 4 | 1.Add it in your root build.gradle at the end of repositories: 5 | 6 | allprojects { 7 | repositories { 8 | ... 9 | maven { url 'https://jitpack.io' } 10 | } 11 | } 12 | Step 2. Add the dependency 13 | 14 | dependencies { 15 | compile 'com.github.sdfdzx:VRShow:v1.0.2' 16 | } 17 | ### 1.全景360°GIF图 18 | ![全景360°GIF图](https://github.com/sdfdzx/VRShow/blob/master/gif/gifdemo.gif) 19 | 20 | **功能:** 21 | >1.支持单指拖拽 22 | >2.支持双指缩放 23 | >3.支持触摸响应速度模式:LOW,NORMAL,FAST 24 | 25 | **使用方式:** 26 | Step 1. XML and Java 27 | ``` 28 | 34 | 35 | public class GifActivity extends AppCompatActivity { 36 | private VrGifView mGif; 37 | @Override 38 | protected void onCreate(Bundle savedInstanceState) { 39 | super.onCreate(savedInstanceState); 40 | setContentView(R.layout.activity_gif); 41 | mGif = (VrGifView) findViewById(R.id.gif); 42 | mGif.setTouch(true);//是否 可触摸 43 | mGif.setDrag(true);//是否可拖拽 44 | mGif.setScale(false);//是否可伸缩 45 | mGif.setMoveMode(VrGifView.MODE_FAST);//触摸响应速度 46 | } 47 | } 48 | ``` 49 | ### 2.3D模型展示 50 | ![3D模型展示](https://github.com/sdfdzx/VRShow/blob/master/gif/book.gif) 51 | 52 | **功能:** 53 | >1.异步读取STL格式的3D文件 54 | >2.支持进度回调 55 | >3.支持单指拖动 56 | >4.支持双指缩放 57 | >5.支持陀螺仪传感器 58 | 59 | **使用方式:** 60 | Step 1. XML and Java 61 | ``` 62 | 66 | 67 | 68 | STLViewBuilder.init(mStl).Assets(this, "bai.stl").build(); 69 | mStl.setTouch(true); 70 | mStl.setScale(true); 71 | mStl.setRotate(true); 72 | mStl.setSensor(true); 73 | mStl.setOnReadCallBack(new OnReadCallBack() { 74 | @Override 75 | public void onStart() {} 76 | @Override 77 | public void onReading(int cur, int total) {} 78 | @Override 79 | public void onFinish() {} 80 | }); 81 | ``` 82 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion "27.0.0" 6 | defaultConfig { 7 | applicationId "com.study.xuan.vrshow" 8 | minSdkVersion 19 9 | targetSdkVersion 26 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile project(':library') 28 | compile 'com.android.support:appcompat-v7:26.+' 29 | compile 'com.google.vr:sdk-panowidget:1.101.0' 30 | testCompile 'junit:junit:4.12' 31 | } 32 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\Program\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/study/xuan/vrshow/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.vrshow; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.study.xuan.vrshow", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /app/src/main/assets/andes1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/app/src/main/assets/andes1.jpg -------------------------------------------------------------------------------- /app/src/main/assets/bai.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/app/src/main/assets/bai.stl -------------------------------------------------------------------------------- /app/src/main/assets/bb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/app/src/main/assets/bb.jpg -------------------------------------------------------------------------------- /app/src/main/java/com/study/xuan/vrshow/GifActivity.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.vrshow; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | import com.study.xuan.gifshow.gif.VrGifView; 7 | 8 | public class GifActivity extends AppCompatActivity { 9 | private VrGifView mGif; 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_gif); 14 | mGif = (VrGifView) findViewById(R.id.gif); 15 | mGif.setTouch(true); 16 | mGif.setDrag(true); 17 | mGif.setScale(false); 18 | mGif.setMoveMode(VrGifView.MODE_FAST); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/study/xuan/vrshow/GoogleActivity.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.vrshow; 2 | 3 | import android.content.Intent; 4 | import android.content.res.AssetManager; 5 | import android.graphics.BitmapFactory; 6 | import android.net.Uri; 7 | import android.os.AsyncTask; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.os.Bundle; 10 | import android.text.Html; 11 | import android.text.method.LinkMovementMethod; 12 | import android.util.Log; 13 | import android.util.Pair; 14 | import android.widget.TextView; 15 | import android.widget.Toast; 16 | 17 | 18 | import com.google.vr.sdk.widgets.pano.VrPanoramaEventListener; 19 | import com.google.vr.sdk.widgets.pano.VrPanoramaView; 20 | 21 | import java.io.File; 22 | import java.io.FileInputStream; 23 | import java.io.IOException; 24 | import java.io.InputStream; 25 | 26 | public class GoogleActivity extends AppCompatActivity { 27 | private static final String TAG = GoogleActivity.class.getSimpleName(); 28 | /** Actual panorama widget. **/ 29 | private VrPanoramaView panoWidgetView; 30 | /** 31 | * Arbitrary variable to track load status. In this example, this variable should only be accessed 32 | * on the UI thread. In a real app, this variable would be code that performs some UI actions when 33 | * the panorama is fully loaded. 34 | */ 35 | public boolean loadImageSuccessful; 36 | /** Tracks the file to be loaded across the lifetime of this app. **/ 37 | private Uri fileUri; 38 | /** Configuration information for the panorama. **/ 39 | private VrPanoramaView.Options panoOptions = new VrPanoramaView.Options(); 40 | private ImageLoaderTask backgroundImageLoaderTask; 41 | 42 | /** 43 | * Called when the app is launched via the app icon or an intent using the adb command above. This 44 | * initializes the app and loads the image to render. 45 | */ 46 | @Override 47 | protected void onCreate(Bundle savedInstanceState) { 48 | super.onCreate(savedInstanceState); 49 | setContentView(R.layout.main_layout); 50 | 51 | // Make the source link clickable. 52 | TextView sourceText = (TextView) findViewById(R.id.source); 53 | sourceText.setText(Html.fromHtml(getString(R.string.source))); 54 | sourceText.setMovementMethod(LinkMovementMethod.getInstance()); 55 | 56 | panoWidgetView = (VrPanoramaView) findViewById(R.id.pano_view); 57 | panoWidgetView.setEventListener(new ActivityEventListener()); 58 | //panoWidgetView.setTouchTrackingEnabled(true); 59 | 60 | // Initial launch of the app or an Activity recreation due to rotation. 61 | handleIntent(getIntent()); 62 | } 63 | 64 | /** 65 | * Called when the Activity is already running and it's given a new intent. 66 | */ 67 | @Override 68 | protected void onNewIntent(Intent intent) { 69 | Log.i(TAG, this.hashCode() + ".onNewIntent()"); 70 | // Save the intent. This allows the getIntent() call in onCreate() to use this new Intent during 71 | // future invocations. 72 | setIntent(intent); 73 | // Load the new image. 74 | handleIntent(intent); 75 | } 76 | 77 | /** 78 | * Load custom images based on the Intent or load the default image. See the Javadoc for this 79 | * class for information on generating a custom intent via adb. 80 | */ 81 | private void handleIntent(Intent intent) { 82 | // Determine if the Intent contains a file to load. 83 | if (Intent.ACTION_VIEW.equals(intent.getAction())) { 84 | Log.i(TAG, "ACTION_VIEW Intent recieved"); 85 | 86 | fileUri = intent.getData(); 87 | if (fileUri == null) { 88 | Log.w(TAG, "No data uri specified. Use \"-d /path/filename\"."); 89 | } else { 90 | Log.i(TAG, "Using file " + fileUri.toString()); 91 | } 92 | 93 | panoOptions.inputType = intent.getIntExtra("inputType", VrPanoramaView.Options.TYPE_MONO); 94 | Log.i(TAG, "Options.inputType = " + panoOptions.inputType); 95 | } else { 96 | Log.i(TAG, "Intent is not ACTION_VIEW. Using default pano image."); 97 | fileUri = null; 98 | panoOptions.inputType = VrPanoramaView.Options.TYPE_MONO; 99 | } 100 | 101 | // Load the bitmap in a background thread to avoid blocking the UI thread. This operation can 102 | // take 100s of milliseconds. 103 | if (backgroundImageLoaderTask != null) { 104 | // Cancel any task from a previous intent sent to this activity. 105 | backgroundImageLoaderTask.cancel(true); 106 | } 107 | backgroundImageLoaderTask = new ImageLoaderTask(); 108 | backgroundImageLoaderTask.execute(Pair.create(fileUri, panoOptions)); 109 | } 110 | 111 | @Override 112 | protected void onPause() { 113 | panoWidgetView.pauseRendering(); 114 | super.onPause(); 115 | } 116 | 117 | @Override 118 | protected void onResume() { 119 | super.onResume(); 120 | panoWidgetView.resumeRendering(); 121 | } 122 | 123 | @Override 124 | protected void onDestroy() { 125 | // Destroy the widget and free memory. 126 | panoWidgetView.shutdown(); 127 | 128 | // The background task has a 5 second timeout so it can potentially stay alive for 5 seconds 129 | // after the activity is destroyed unless it is explicitly cancelled. 130 | if (backgroundImageLoaderTask != null) { 131 | backgroundImageLoaderTask.cancel(true); 132 | } 133 | super.onDestroy(); 134 | } 135 | 136 | /** 137 | * Helper class to manage threading. 138 | */ 139 | class ImageLoaderTask extends AsyncTask, Void, Boolean> { 140 | 141 | /** 142 | * Reads the bitmap from disk in the background and waits until it's loaded by pano widget. 143 | */ 144 | @Override 145 | protected Boolean doInBackground(Pair... fileInformation) { 146 | VrPanoramaView.Options panoOptions = null; // It's safe to use null VrPanoramaView.Options. 147 | InputStream istr = null; 148 | if (fileInformation == null || fileInformation.length < 1 149 | || fileInformation[0] == null || fileInformation[0].first == null) { 150 | AssetManager assetManager = getAssets(); 151 | try { 152 | istr = assetManager.open("bb.jpg"); 153 | panoOptions = new VrPanoramaView.Options(); 154 | panoOptions.inputType = VrPanoramaView.Options.TYPE_MONO; 155 | } catch (IOException e) { 156 | Log.e(TAG, "Could not decode default bitmap: " + e); 157 | return false; 158 | } 159 | } else { 160 | try { 161 | istr = new FileInputStream(new File(fileInformation[0].first.getPath())); 162 | panoOptions = fileInformation[0].second; 163 | } catch (IOException e) { 164 | Log.e(TAG, "Could not load file: " + e); 165 | return false; 166 | } 167 | } 168 | 169 | panoWidgetView.loadImageFromBitmap(BitmapFactory.decodeStream(istr), panoOptions); 170 | try { 171 | istr.close(); 172 | } catch (IOException e) { 173 | Log.e(TAG, "Could not close input stream: " + e); 174 | } 175 | 176 | return true; 177 | } 178 | } 179 | 180 | /** 181 | * Listen to the important events from widget. 182 | */ 183 | private class ActivityEventListener extends VrPanoramaEventListener { 184 | /** 185 | * Called by pano widget on the UI thread when it's done loading the image. 186 | */ 187 | @Override 188 | public void onLoadSuccess() { 189 | loadImageSuccessful = true; 190 | } 191 | 192 | /** 193 | * Called by pano widget on the UI thread on any asynchronous error. 194 | */ 195 | @Override 196 | public void onLoadError(String errorMessage) { 197 | loadImageSuccessful = false; 198 | Toast.makeText( 199 | GoogleActivity.this, "Error loading pano: " + errorMessage, Toast.LENGTH_LONG) 200 | .show(); 201 | Log.e(TAG, "Error loading pano: " + errorMessage); 202 | } 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /app/src/main/java/com/study/xuan/vrshow/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.vrshow; 2 | 3 | import android.app.ActivityManager; 4 | import android.content.Intent; 5 | import android.content.pm.ConfigurationInfo; 6 | import android.os.Build; 7 | import android.os.Bundle; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.view.View; 10 | import android.widget.TextView; 11 | 12 | 13 | public class MainActivity extends AppCompatActivity{ 14 | private boolean supportsEs2; 15 | private TextView mTvGif; 16 | private TextView mTvStl; 17 | private TextView mTvGoogle; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.activity_main); 23 | initView(); 24 | initEvent(); 25 | /*checkSupported(); 26 | if (supportsEs2) { 27 | setContentView(R.layout.activity_main); 28 | } else { 29 | setContentView(R.layout.activity_main); 30 | Toast.makeText(this, "当前设备不支持OpenGL ES 2.0!", Toast.LENGTH_SHORT).show(); 31 | }*/ 32 | 33 | } 34 | 35 | private void initView() { 36 | mTvGif = (TextView) findViewById(R.id.gif); 37 | mTvStl = (TextView) findViewById(R.id.stl); 38 | mTvGoogle = (TextView) findViewById(R.id.google); 39 | } 40 | 41 | private void initEvent() { 42 | mTvGif.setOnClickListener(new View.OnClickListener() { 43 | @Override 44 | public void onClick(View v) { 45 | Intent intent = new Intent(MainActivity.this, GifActivity.class); 46 | startActivity(intent); 47 | } 48 | }); 49 | 50 | mTvStl.setOnClickListener(new View.OnClickListener() { 51 | @Override 52 | public void onClick(View v) { 53 | Intent intent = new Intent(MainActivity.this, STLActivity.class); 54 | startActivity(intent); 55 | } 56 | }); 57 | 58 | mTvGoogle.setOnClickListener(new View.OnClickListener() { 59 | @Override 60 | public void onClick(View v) { 61 | Intent intent = new Intent(MainActivity.this, GoogleActivity.class); 62 | startActivity(intent); 63 | } 64 | }); 65 | /*stlView.setRotate(true); 66 | stlView.setScale(true); 67 | stlView.setSensor(true); 68 | stlView.setOnReadCallBack(new OnReadCallBack() { 69 | @Override 70 | public void onStart() { 71 | mTvProgress.setText("开始解析!"); 72 | } 73 | 74 | @Override 75 | public void onReading(int cur, int total) { 76 | bundle.putInt("cur", cur); 77 | bundle.putInt("total", total); 78 | Message msg = new Message(); 79 | msg.setData(bundle); 80 | handler.sendMessage(msg); 81 | } 82 | 83 | @Override 84 | public void onFinish() { 85 | mTvProgress.setText("解析完成!"); 86 | } 87 | });*/ 88 | } 89 | 90 | 91 | /*private onReadListener readListener = new onReadListener() { 92 | @Override 93 | public void onstart() { 94 | mTvProgress.setText("开始解析!"); 95 | } 96 | 97 | @Override 98 | public void onLoading(int cur, int total) { 99 | bundle.putInt("cur", cur); 100 | bundle.putInt("total", total); 101 | Message msg = new Message(); 102 | msg.setData(bundle); 103 | handler.sendMessage(msg); 104 | } 105 | 106 | @Override 107 | public void onFinished(STLModel model) { 108 | mTvProgress.setText("解析完成!"); 109 | if (model != null) { 110 | if (stlView == null) { 111 | stlView = new STLView(MainActivity.this,model); 112 | container.addView(stlView); 113 | } else { 114 | stlView.setNewSTLObject(model); 115 | } 116 | } 117 | } 118 | 119 | @Override 120 | public void onFailure(Exception e) { 121 | 122 | } 123 | };*/ 124 | 125 | 126 | private void checkSupported() { 127 | ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); 128 | ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); 129 | supportsEs2 = configurationInfo.reqGlEsVersion >= 0x2000; 130 | 131 | boolean isEmulator = Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1 132 | && (Build.FINGERPRINT.startsWith("generic") 133 | || Build.FINGERPRINT.startsWith("unknown") 134 | || Build.MODEL.contains("google_sdk") 135 | || Build.MODEL.contains("Emulator") 136 | || Build.MODEL.contains("Android SDK built for x86")); 137 | 138 | supportsEs2 = supportsEs2 || isEmulator; 139 | } 140 | 141 | @Override 142 | protected void onPause() { 143 | super.onPause(); 144 | /*if (stlView != null) { 145 | stlView.onPause(); 146 | }*/ 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /app/src/main/java/com/study/xuan/vrshow/STLActivity.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.vrshow; 2 | 3 | import android.app.ProgressDialog; 4 | import android.content.Context; 5 | import android.os.Bundle; 6 | import android.os.Handler; 7 | import android.os.Message; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.util.Log; 10 | import android.widget.Toast; 11 | 12 | import com.study.xuan.gifshow.widget.stlview.callback.OnReadCallBack; 13 | import com.study.xuan.gifshow.widget.stlview.widget.STLView; 14 | import com.study.xuan.gifshow.widget.stlview.widget.STLViewBuilder; 15 | 16 | public class STLActivity extends AppCompatActivity { 17 | private STLView mStl; 18 | private Context mContext; 19 | private ProgressDialog mBar; 20 | private Bundle bundle = new Bundle(); 21 | private Handler handler = new Handler(){ 22 | @Override 23 | public void handleMessage(Message msg) { 24 | Bundle bundle = msg.getData(); 25 | float cur = bundle.getFloat("cur"); 26 | float total = bundle.getFloat("total"); 27 | float progress = cur / total; 28 | Log.i("Progress", progress + ""); 29 | mBar.setProgress((int) (progress * 100.0f)); 30 | } 31 | }; 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_stl); 36 | mContext = this; 37 | mStl = (STLView) findViewById(R.id.stl); 38 | mBar = prepareProgressDialog(mContext); 39 | mStl.setOnReadCallBack(new OnReadCallBack() { 40 | @Override 41 | public void onStart() { 42 | Toast.makeText(mContext, "开始解析!", Toast.LENGTH_LONG).show(); 43 | mBar.show(); 44 | } 45 | 46 | @Override 47 | public void onReading(int cur, int total) { 48 | bundle.putFloat("cur", cur); 49 | bundle.putFloat("total", total); 50 | Message msg = new Message(); 51 | msg.setData(bundle); 52 | handler.sendMessage(msg); 53 | } 54 | 55 | @Override 56 | public void onFinish() { 57 | mBar.dismiss(); 58 | } 59 | }); 60 | STLViewBuilder.init(mStl).Assets(this, "bai.stl").build(); 61 | mStl.setTouch(true); 62 | mStl.setScale(true); 63 | mStl.setRotate(true); 64 | mStl.setSensor(true); 65 | } 66 | 67 | private ProgressDialog prepareProgressDialog(Context context) { 68 | ProgressDialog progressDialog = new ProgressDialog(context); 69 | progressDialog.setTitle(R.string.stl_load_progress_title); 70 | progressDialog.setMax(100); 71 | progressDialog.setMessage(context.getString(R.string.stl_load_progress_message)); 72 | progressDialog.setIndeterminate(false); 73 | progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 74 | progressDialog.setCancelable(false); 75 | return progressDialog; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/app/src/main/res/drawable/demo.gif -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_gif.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_google.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 22 | 34 | 46 | 47 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_stl.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/main_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 21 | 22 | 28 | 29 | 35 | 36 | 42 | 43 | 49 | 50 | 56 | 57 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #222 7 | #555 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 24dip 4 | 12dip 5 | 15dip 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | VRShow 3 | 4 | 5 | 请等一会. 6 | STL 文件加载中... 7 | STL 文件解析失败. 8 | 文件过大,解析失败! 9 | 关闭对话框 10 | 父目录 11 | 选择STL文件 12 | 13 | 14 | 15 | 移动 16 | 旋转 17 | 18 | 19 | STL展示界面的配置 20 | 21 | 绿 22 | 23 | 透明度 24 | 模型颜色: 25 | 展示坐标和网格: 26 | 网格: 27 | 坐标: 28 | 重置默认值. 29 | 保存 & 关闭 30 | 31 | 32 | Machu Picchu\nWorld Heritage Site 33 | The world-famous citadel of the Andes 34 | Machu Picchu is an Incan citadel set high in the Andes Mountains in 35 | Peru, above the Urubamba River valley. 36 | 37 | A 360 panoramic view of Machu Picchu 38 | 39 | It is situated on a mountain ridge above the Sacred Valley which is 80 40 | kilometres (50 mi) northwest of Cuzco and through which the Urubamba River flows. 41 | Most archaeologists believe that Machu Picchu was built as an estate for the Inca emperor 42 | Pachacuti (1438–1472). Often mistakenly referred to as the Lost City of the Incas, 43 | it is the most familiar icon of Inca civilization. 44 | 45 | \n\nThe Incas built the estate around 1450, but abandoned it a century later at the time of the 46 | Spanish Conquest. Although known locally, it was not known to the Spanish during the colonial 47 | period and remained unknown to the outside world before being brought to international attention 48 | in 1911 by the American historian Hiram Bingham. Most of the outlying buildings have been 49 | reconstructed in order to give tourists a better idea of what the structures originally 50 | looked like. By 1976, 30% of Machu Picchu had been restored; restoration continues today. 51 | 52 | \n\nMachu Picchu was declared a Peruvian Historical Sanctuary in 1981 and a UNESCO World Heritage 53 | Site in 1983. In 2007, Machu Picchu was voted one of the New Seven Wonders of the World in a 54 | worldwide Internet poll. 55 | 56 | 57 | Source <a href="https://en.wikipedia.org/wiki/Machu_Picchu">Wikipedia</a> 58 | 59 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/test/java/com/study/xuan/vrshow/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.vrshow; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.3.2' 9 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // Add this line 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gif/book.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/gif/book.gif -------------------------------------------------------------------------------- /gif/gifdemo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/gif/gifdemo.gif -------------------------------------------------------------------------------- /gif/googlefinal.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/gif/googlefinal.gif -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrownCoder/VRShow/ad4eea9bf2ca08e6629380c7b11e1f7271611027/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Nov 29 12:18:12 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | group='com.github.sdfdzx' 5 | android { 6 | compileSdkVersion 26 7 | buildToolsVersion "27.0.0" 8 | 9 | defaultConfig { 10 | minSdkVersion 15 11 | targetSdkVersion 26 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | compile fileTree(dir: 'libs', include: ['*.jar']) 28 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 29 | exclude group: 'com.android.support', module: 'support-annotations' 30 | }) 31 | compile 'com.android.support:appcompat-v7:26.+' 32 | compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.8' 33 | testCompile 'junit:junit:4.12' 34 | } 35 | -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\Program\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /library/src/androidTest/java/com/study/xuan/gifshow/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.gifshow; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.study.xuan.gifshow.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /library/src/main/java/com/study/xuan/gifshow/gif/VrGifView.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.gifshow.gif; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ObjectAnimator; 5 | import android.content.Context; 6 | import android.util.AttributeSet; 7 | import android.view.MotionEvent; 8 | 9 | import com.study.xuan.gifshow.util.ScreenUtil; 10 | 11 | import pl.droidsonroids.gif.GifDrawable; 12 | import pl.droidsonroids.gif.GifImageView; 13 | 14 | /** 15 | * Author : xuan. 16 | * Date : 2017/12/16. 17 | * Description :利用3d展示的gif控制播放进度 18 | */ 19 | 20 | public class VrGifView extends GifImageView { 21 | //触摸响应速度 22 | public static final int MODE_FAST = 1; 23 | public static final int MODE_NORMAL = 2; 24 | public static final int MODE_LOW = 3; 25 | private int SPEED_FAST = 100; 26 | private int SPEED_NORMAL = 250; 27 | private int SPEED_LOW = 500; 28 | 29 | private Context mContext; 30 | private GifDrawable gifDrawable; 31 | private int gifLength; 32 | //单指旋转 33 | private float lastX; 34 | private float downTime; 35 | private int curPos; 36 | private float moveX; 37 | private float moveDis; 38 | //手指拖动距离和播放位置的映射 39 | private float PX_TO_POS; 40 | private int moveMode; 41 | private int moveSpeed; 42 | //双指缩放 43 | private float pinchScale = 1.0f; 44 | private float pinchStartDistance = 0.0f; 45 | private ObjectAnimator scaleAnimator; 46 | private boolean isUp; 47 | private Animator.AnimatorListener listener; 48 | //当前缩放量 49 | private float scale_now = 1.0f; 50 | //触摸模式 51 | private static final int TOUCH_NONE = 0; 52 | private static final int TOUCH_DRAG = 1; 53 | private static final int TOUCH_ZOOM = 2; 54 | private int touchMode = TOUCH_NONE; 55 | //感应开关 56 | private boolean isTouch; 57 | private boolean isScale; 58 | private boolean isDrag; 59 | private boolean canAnim; 60 | 61 | public VrGifView(Context context) { 62 | this(context, null); 63 | } 64 | 65 | public VrGifView(Context context, AttributeSet attrs) { 66 | this(context, attrs, 0); 67 | } 68 | 69 | public VrGifView(Context context, AttributeSet attrs, int defStyle) { 70 | super(context, attrs, defStyle); 71 | this.mContext = context; 72 | init(); 73 | } 74 | 75 | private void init() { 76 | if (gifDrawable == null) { 77 | gifDrawable = (GifDrawable) getDrawable(); 78 | } 79 | if (gifDrawable == null) { 80 | return; 81 | } 82 | gifLength = gifDrawable.getDuration(); 83 | moveMode = MODE_FAST; 84 | moveSpeed = SPEED_FAST; 85 | canAnim = true; 86 | PX_TO_POS = gifLength / ScreenUtil.getWindowDisplay(mContext).getWidth(); 87 | setImageDrawable(gifDrawable); 88 | } 89 | 90 | public void setTouch(boolean touch) { 91 | isTouch = touch; 92 | } 93 | 94 | public void setScale(boolean scale) { 95 | isScale = scale; 96 | if (isScale) { 97 | listener = new Animator.AnimatorListener() { 98 | @Override 99 | public void onAnimationStart(Animator animation) { 100 | canAnim = false; 101 | } 102 | 103 | @Override 104 | public void onAnimationEnd(Animator animation) { 105 | canAnim = true; 106 | } 107 | 108 | @Override 109 | public void onAnimationCancel(Animator animation) { 110 | 111 | } 112 | 113 | @Override 114 | public void onAnimationRepeat(Animator animation) { 115 | 116 | } 117 | }; 118 | } 119 | } 120 | 121 | public void setDrag(boolean drag) { 122 | isDrag = drag; 123 | } 124 | 125 | /** 126 | * 设置触摸触发响应速度 127 | */ 128 | public void setMoveMode(int mode) { 129 | switch (mode) { 130 | case MODE_FAST: 131 | moveMode = MODE_FAST; 132 | moveSpeed = SPEED_FAST; 133 | break; 134 | case MODE_NORMAL: 135 | moveMode = MODE_NORMAL; 136 | moveSpeed = SPEED_NORMAL; 137 | break; 138 | case MODE_LOW: 139 | moveMode = MODE_LOW; 140 | moveSpeed = SPEED_LOW; 141 | break; 142 | default: 143 | moveMode = MODE_NORMAL; 144 | moveSpeed = SPEED_NORMAL; 145 | break; 146 | } 147 | } 148 | 149 | /** 150 | * 设置gif图 151 | */ 152 | public void setGifDrawable(GifDrawable gifDrawable) { 153 | this.gifDrawable = gifDrawable; 154 | } 155 | 156 | @Override 157 | public boolean onTouchEvent(MotionEvent event) { 158 | if (!isTouch) { 159 | return true; 160 | } 161 | //双指缩放 162 | if (isScale) { 163 | zoomScale(event); 164 | } 165 | //单指旋转 166 | if (isDrag) { 167 | rotateModel(event); 168 | } 169 | return true; 170 | } 171 | 172 | private void rotateModel(MotionEvent event) { 173 | switch (event.getAction() & MotionEvent.ACTION_MASK) { 174 | case MotionEvent.ACTION_DOWN: 175 | if (touchMode == TOUCH_NONE && event.getPointerCount() == 1) { 176 | touchMode = TOUCH_DRAG; 177 | gifDrawable.stop(); 178 | lastX = event.getX(); 179 | downTime = event.getDownTime(); 180 | } 181 | break; 182 | case MotionEvent.ACTION_MOVE: 183 | if (touchMode == TOUCH_DRAG) { 184 | if ((event.getEventTime() - downTime) > moveSpeed) { 185 | moveX = event.getX(); 186 | moveDis = moveX - lastX; 187 | lastX = moveX; 188 | curPos = gifDrawable.getCurrentPosition(); 189 | if ((curPos + moveDis * PX_TO_POS) < 0) { 190 | curPos += moveDis * PX_TO_POS + gifLength; 191 | } else { 192 | curPos += moveDis * PX_TO_POS; 193 | } 194 | if (curPos < 0) { 195 | curPos = 0; 196 | } 197 | gifDrawable.seekTo(curPos); 198 | downTime = event.getEventTime(); 199 | } 200 | } 201 | break; 202 | case MotionEvent.ACTION_UP: 203 | if (touchMode == TOUCH_DRAG) { 204 | touchMode = TOUCH_NONE; 205 | } 206 | gifDrawable.start(); 207 | break; 208 | } 209 | } 210 | 211 | private void zoomScale(MotionEvent event) { 212 | switch (event.getAction() & MotionEvent.ACTION_MASK) { 213 | // starts pinch 214 | case MotionEvent.ACTION_POINTER_DOWN: 215 | if (event.getPointerCount() >= 2) { 216 | pinchStartDistance = getPinchDistance(event); 217 | downTime = event.getDownTime(); 218 | if (pinchStartDistance > 50f) { 219 | touchMode = TOUCH_ZOOM; 220 | } 221 | } 222 | break; 223 | 224 | case MotionEvent.ACTION_MOVE: 225 | if (touchMode == TOUCH_ZOOM && pinchStartDistance > 0) { 226 | // on pinch 227 | if ((event.getEventTime() - downTime) > moveSpeed) { 228 | if (getPinchDistance(event) > pinchStartDistance) { 229 | //递增 230 | isUp = true; 231 | } else { 232 | isUp = false; 233 | } 234 | pinchScale = getPinchDistance(event) / pinchStartDistance; 235 | if (checkScale(pinchScale)) { 236 | changeScale(pinchScale); 237 | } 238 | } 239 | } 240 | break; 241 | 242 | // end pinch 243 | case MotionEvent.ACTION_UP: 244 | case MotionEvent.ACTION_POINTER_UP: 245 | pinchScale = 0; 246 | if (touchMode == TOUCH_ZOOM) { 247 | touchMode = TOUCH_NONE; 248 | } 249 | break; 250 | } 251 | } 252 | 253 | private boolean checkScale(float pinchScale) { 254 | if (canAnim) { 255 | if (isUp) { 256 | if (pinchScale > 1) { 257 | return true; 258 | } 259 | } else { 260 | if (pinchScale < 1) { 261 | return true; 262 | } 263 | } 264 | } 265 | return false; 266 | } 267 | 268 | private void changeScale(float pinchScale) { 269 | scaleAnimator = ObjectAnimator.ofFloat(this, "scale", scale_now, scale_now * pinchScale); 270 | scale_now = scale_now * pinchScale; 271 | scaleAnimator.setDuration(50); 272 | if (listener != null) { 273 | scaleAnimator.addListener(listener); 274 | } 275 | scaleAnimator.start(); 276 | } 277 | 278 | private float getPinchDistance(MotionEvent event) { 279 | float x = 0; 280 | float y = 0; 281 | try { 282 | x = event.getX(0) - event.getX(1); 283 | y = event.getY(0) - event.getY(1); 284 | } catch (IllegalArgumentException e) { 285 | e.printStackTrace(); 286 | } 287 | return (float) Math.sqrt(x * x + y * y); 288 | } 289 | 290 | /** 291 | * 动画反射需要 292 | */ 293 | public void setScale(float value) { 294 | setScaleX(value); 295 | setScaleY(value); 296 | } 297 | } 298 | -------------------------------------------------------------------------------- /library/src/main/java/com/study/xuan/gifshow/util/ScreenUtil.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.gifshow.util; 2 | 3 | import android.content.Context; 4 | import android.view.Display; 5 | import android.view.WindowManager; 6 | 7 | /** 8 | * Author : xuan. 9 | * Date : 2017/11/30. 10 | * Description :input the description of this file. 11 | */ 12 | 13 | public class ScreenUtil { 14 | /** 15 | * 获得屏幕宽高 16 | * 调用getWidth(),getHeight() 17 | */ 18 | public static Display getWindowDisplay(Context context) { 19 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 20 | return wm.getDefaultDisplay(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /library/src/main/java/com/study/xuan/gifshow/widget/stlview/callback/OnReadCallBack.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.gifshow.widget.stlview.callback; 2 | 3 | /** 4 | * Author : xuan. 5 | * Date : 2017/12/12. 6 | * Description :抽象类回调 7 | */ 8 | 9 | public abstract class OnReadCallBack { 10 | public void onStart() { 11 | 12 | } 13 | 14 | public void onReading(int cur, int total) { 15 | 16 | } 17 | 18 | public void onFinish() { 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /library/src/main/java/com/study/xuan/gifshow/widget/stlview/callback/OnReadListener.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.gifshow.widget.stlview.callback; 2 | 3 | import com.study.xuan.gifshow.widget.stlview.model.STLModel; 4 | 5 | public interface OnReadListener { 6 | void onstart(); 7 | 8 | void onLoading(int cur, int total); 9 | 10 | void onFinished(STLModel model); 11 | 12 | void onFailure(Exception e); 13 | } -------------------------------------------------------------------------------- /library/src/main/java/com/study/xuan/gifshow/widget/stlview/model/STLModel.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.gifshow.widget.stlview.model; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import com.study.xuan.gifshow.widget.stlview.util.STLUtils; 7 | 8 | import java.nio.FloatBuffer; 9 | import javax.microedition.khronos.opengles.GL10; 10 | 11 | 12 | /** 13 | * Author : xuan. 14 | * Date : 2017/12/14. 15 | * Description : stl文件对应转换的3d模型数据 16 | */ 17 | 18 | public class STLModel implements Parcelable { 19 | FloatBuffer triangleBuffer; 20 | FloatBuffer normalBuffer; 21 | 22 | public float maxX; 23 | public float maxY; 24 | public float maxZ; 25 | public float minX; 26 | public float minY; 27 | public float minZ; 28 | 29 | //优化使用的数组 30 | public float[] normal_array=null; 31 | public float[] vertex_array=null; 32 | private int vertext_size=0; 33 | 34 | public STLModel() { 35 | } 36 | 37 | public STLModel(Parcel source) { 38 | maxX = source.readFloat(); 39 | maxY = source.readFloat(); 40 | maxZ = source.readFloat(); 41 | minX = source.readFloat(); 42 | minY = source.readFloat(); 43 | minZ = source.readFloat(); 44 | vertext_size = source.readInt(); 45 | source.readFloatArray(normal_array); 46 | source.readFloatArray(vertex_array); 47 | setVnorms(normal_array); 48 | setVnorms(vertex_array); 49 | } 50 | 51 | public void draw(GL10 gl) { 52 | if (triangleBuffer == null) { 53 | return; 54 | } 55 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 56 | gl.glEnableClientState(GL10.GL_NORMAL_ARRAY); 57 | //gl.glFrontFace(GL10.GL_CCW); 58 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, triangleBuffer); 59 | gl.glNormalPointer(GL10.GL_FLOAT,0, normalBuffer); 60 | gl.glDrawArrays(GL10.GL_TRIANGLES, 0, vertext_size*3); 61 | gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); 62 | gl.glDisableClientState(GL10.GL_NORMAL_ARRAY); 63 | } 64 | 65 | public void setMax(float maxX, float maxY, float maxZ) { 66 | this.maxX = maxX; 67 | this.maxY = maxY; 68 | this.maxZ = maxZ; 69 | } 70 | 71 | public void setMin(float minX, float minY, float minZ) { 72 | this.minX = minX; 73 | this.minY = minY; 74 | this.minZ = minZ; 75 | } 76 | 77 | public void setSize(int size) { 78 | this.vertext_size = size; 79 | } 80 | 81 | public void delete (){ 82 | } 83 | 84 | public void setVerts(float[] verts) { 85 | this.vertex_array = verts; 86 | this.triangleBuffer = STLUtils.floatToBuffer(vertex_array); 87 | } 88 | 89 | public void setVnorms(float[] vnorms) { 90 | this.normal_array = vnorms; 91 | this.normalBuffer = STLUtils.floatToBuffer(normal_array); 92 | } 93 | 94 | @Override 95 | public int describeContents() { 96 | return 0; 97 | } 98 | 99 | @Override 100 | public void writeToParcel(Parcel dest, int flags) { 101 | dest.writeFloat(maxX); 102 | dest.writeFloat(maxY); 103 | dest.writeFloat(maxZ); 104 | dest.writeFloat(minX); 105 | dest.writeFloat(minY); 106 | dest.writeFloat(minZ); 107 | dest.writeInt(vertext_size); 108 | dest.writeFloatArray(normal_array); 109 | dest.writeFloatArray(vertex_array); 110 | } 111 | 112 | public static final Creator CREATOR = new Creator() { 113 | @Override 114 | public STLModel createFromParcel(Parcel source) { 115 | return new STLModel(source); 116 | } 117 | 118 | @Override 119 | public STLModel[] newArray(int size) { 120 | return new STLModel[size]; 121 | } 122 | }; 123 | } 124 | -------------------------------------------------------------------------------- /library/src/main/java/com/study/xuan/gifshow/widget/stlview/operate/ISTLReader.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.gifshow.widget.stlview.operate; 2 | 3 | 4 | import com.study.xuan.gifshow.widget.stlview.callback.OnReadListener; 5 | import com.study.xuan.gifshow.widget.stlview.model.STLModel; 6 | 7 | /** 8 | * Author : xuan. 9 | * Date : 2017/12/10. 10 | * Description : interface of stlreader 11 | */ 12 | 13 | public interface ISTLReader { 14 | public STLModel parserBinStl(byte[] bytes); 15 | 16 | public STLModel parserAsciiStl(byte[] bytes); 17 | 18 | public void setCallBack(OnReadListener listener); 19 | } 20 | -------------------------------------------------------------------------------- /library/src/main/java/com/study/xuan/gifshow/widget/stlview/operate/ReaderHandler.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.gifshow.widget.stlview.operate; 2 | 3 | import android.os.AsyncTask; 4 | 5 | import com.study.xuan.gifshow.widget.stlview.callback.OnReadListener; 6 | import com.study.xuan.gifshow.widget.stlview.model.STLModel; 7 | import com.study.xuan.gifshow.widget.stlview.util.STLUtils; 8 | 9 | /** 10 | * Author : xuan. 11 | * Date : 2017/12/10. 12 | * Description : 异步加载Stl文件 13 | */ 14 | public class ReaderHandler { 15 | private ISTLReader reader; 16 | private ReaderTask backWorker; 17 | private OnReadListener listener; 18 | 19 | public ReaderHandler(ISTLReader reader, OnReadListener listener) { 20 | this.reader = reader; 21 | this.listener = listener; 22 | backWorker = new ReaderTask(); 23 | } 24 | 25 | 26 | public void read(byte[] stlBytes) { 27 | try { 28 | backWorker.execute(stlBytes); 29 | } catch (Exception e) { 30 | listener.onFailure(e); 31 | } 32 | } 33 | 34 | private class ReaderTask extends AsyncTask { 35 | @Override 36 | protected void onPreExecute() { 37 | listener.onstart(); 38 | } 39 | 40 | @Override 41 | protected STLModel doInBackground(Object... source) { 42 | STLModel model = null; 43 | model = parserByte((byte[]) source[0]); 44 | return model; 45 | } 46 | 47 | private STLModel parserByte(byte[] bytes) { 48 | if (STLUtils.isAscii(bytes)) { 49 | //parser ascii code 50 | return reader.parserAsciiStl(bytes); 51 | } else { 52 | // parser bin code 53 | return reader.parserBinStl(bytes); 54 | } 55 | } 56 | 57 | @Override 58 | protected void onPostExecute(STLModel model) { 59 | listener.onFinished(model); 60 | } 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /library/src/main/java/com/study/xuan/gifshow/widget/stlview/operate/STLReader.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.gifshow.widget.stlview.operate; 2 | 3 | import com.study.xuan.gifshow.widget.stlview.callback.OnReadListener; 4 | import com.study.xuan.gifshow.widget.stlview.model.STLModel; 5 | 6 | 7 | /** 8 | * Author : xuan. 9 | * Date : 2017/12/14. 10 | * Description : STL文件解析器 11 | */ 12 | 13 | 14 | public class STLReader implements ISTLReader { 15 | private OnReadListener listener; 16 | public float maxX = Float.MIN_VALUE; 17 | public float maxY = Float.MIN_VALUE; 18 | public float maxZ = Float.MIN_VALUE; 19 | public float minX = Float.MAX_VALUE; 20 | public float minY = Float.MAX_VALUE; 21 | public float minZ = Float.MAX_VALUE; 22 | //优化使用的数组 23 | private float[] normal_array = null; 24 | private float[] vertex_array = null; 25 | private int vertext_size = 0; 26 | 27 | /** 28 | * 解析二进制格式的STL文件 29 | */ 30 | public STLModel parserBinStl(byte[] stlBytes) { 31 | STLModel model = new STLModel(); 32 | vertext_size = getIntWithLittleEndian(stlBytes, 80); 33 | ; 34 | vertex_array = new float[vertext_size * 9]; 35 | normal_array = new float[vertext_size * 9]; 36 | 37 | for (int i = 0; i < vertext_size; i++) { 38 | for (int n = 0; n < 3; n++) { 39 | normal_array[i * 9 + n * 3] = Float.intBitsToFloat(getIntWithLittleEndian 40 | (stlBytes, 84 + i * 50)); 41 | normal_array[i * 9 + n * 3 + 1] = Float.intBitsToFloat(getIntWithLittleEndian 42 | (stlBytes, 84 + i * 50 + 4)); 43 | normal_array[i * 9 + n * 3 + 2] = Float.intBitsToFloat(getIntWithLittleEndian 44 | (stlBytes, 84 + i * 50 + 8)); 45 | } 46 | float x = Float.intBitsToFloat(getIntWithLittleEndian(stlBytes, 84 + i * 50 + 12)); 47 | float y = Float.intBitsToFloat(getIntWithLittleEndian(stlBytes, 84 + i * 50 + 16)); 48 | float z = Float.intBitsToFloat(getIntWithLittleEndian(stlBytes, 84 + i * 50 + 20)); 49 | adjustMaxMin(x, y, z); 50 | vertex_array[i * 9] = x; 51 | vertex_array[i * 9 + 1] = y; 52 | vertex_array[i * 9 + 2] = z; 53 | 54 | x = Float.intBitsToFloat(getIntWithLittleEndian(stlBytes, 84 + i * 50 + 24)); 55 | y = Float.intBitsToFloat(getIntWithLittleEndian(stlBytes, 84 + i * 50 + 28)); 56 | z = Float.intBitsToFloat(getIntWithLittleEndian(stlBytes, 84 + i * 50 + 32)); 57 | adjustMaxMin(x, y, z); 58 | vertex_array[i * 9 + 3] = x; 59 | vertex_array[i * 9 + 4] = y; 60 | vertex_array[i * 9 + 5] = z; 61 | 62 | x = Float.intBitsToFloat(getIntWithLittleEndian(stlBytes, 84 + i * 50 + 36)); 63 | y = Float.intBitsToFloat(getIntWithLittleEndian(stlBytes, 84 + i * 50 + 40)); 64 | z = Float.intBitsToFloat(getIntWithLittleEndian(stlBytes, 84 + i * 50 + 44)); 65 | adjustMaxMin(x, y, z); 66 | vertex_array[i * 9 + 6] = x; 67 | vertex_array[i * 9 + 7] = y; 68 | vertex_array[i * 9 + 8] = z; 69 | 70 | if (i % (vertext_size / 50) == 0) { 71 | listener.onLoading(i, vertext_size); 72 | } 73 | } 74 | //将读取的数据设置到STLModel对象中 75 | //=================矫正中心店坐标======================== 76 | float center_x = (maxX + minX) / 2; 77 | float center_y = (maxY + minY) / 2; 78 | float center_z = (maxZ + minZ) / 2; 79 | 80 | for (int i = 0; i < vertext_size * 3; i++) { 81 | adjust_coordinate(vertex_array, i * 3, center_x); 82 | adjust_coordinate(vertex_array, i * 3 + 1, center_y); 83 | adjust_coordinate(vertex_array, i * 3 + 2, center_z); 84 | } 85 | 86 | model.setMax(maxX, maxY, maxZ); 87 | model.setMin(minX, minY, minZ); 88 | model.setSize(vertext_size); 89 | model.setVerts(vertex_array); 90 | model.setVnorms(normal_array); 91 | return model; 92 | } 93 | 94 | private int getIntWithLittleEndian(byte[] bytes, int offset) { 95 | return (0xff & bytes[offset]) | ((0xff & bytes[offset + 1]) << 8) | ((0xff & bytes[offset 96 | + 2]) << 16) | ((0xff & bytes[offset + 3]) << 24); 97 | } 98 | 99 | private void adjustMaxMin(float x, float y, float z) { 100 | if (x > maxX) { 101 | maxX = x; 102 | } 103 | if (y > maxY) { 104 | maxY = y; 105 | } 106 | if (z > maxZ) { 107 | maxZ = z; 108 | } 109 | if (x < minX) { 110 | minX = x; 111 | } 112 | if (y < minY) { 113 | minY = y; 114 | } 115 | if (z < minZ) { 116 | minZ = z; 117 | } 118 | } 119 | 120 | 121 | /** 122 | * 解析ASCII格式的STL文件 123 | */ 124 | @Override 125 | public STLModel parserAsciiStl(byte[] bytes) { 126 | int max = 0; 127 | STLModel model = new STLModel(); 128 | String stlText = new String(bytes); 129 | 130 | String[] stlLines = stlText.split("\n"); 131 | vertext_size = (stlLines.length - 2) / 7; 132 | vertex_array = new float[vertext_size * 9]; 133 | normal_array = new float[vertext_size * 9]; 134 | max = stlLines.length; 135 | 136 | int normal_num = 0; 137 | int vertex_num = 0; 138 | for (int i = 0; i < stlLines.length; i++) { 139 | String string = stlLines[i].trim(); 140 | if (string.startsWith("facet normal ")) { 141 | string = string.replaceFirst("facet normal ", ""); 142 | String[] normalValue = string.split(" "); 143 | for (int n = 0; n < 3; n++) { 144 | normal_array[normal_num++] = Float.parseFloat(normalValue[0]); 145 | normal_array[normal_num++] = Float.parseFloat(normalValue[1]); 146 | normal_array[normal_num++] = Float.parseFloat(normalValue[2]); 147 | } 148 | } 149 | if (string.startsWith("vertex ")) { 150 | string = string.replaceFirst("vertex ", ""); 151 | String[] vertexValue = string.split(" "); 152 | float x = Float.parseFloat(vertexValue[0]); 153 | float y = Float.parseFloat(vertexValue[1]); 154 | float z = Float.parseFloat(vertexValue[2]); 155 | adjustMaxMin(x, y, z); 156 | vertex_array[vertex_num++] = x; 157 | vertex_array[vertex_num++] = y; 158 | vertex_array[vertex_num++] = z; 159 | } 160 | 161 | if (i % (stlLines.length / 50) == 0) { 162 | listener.onLoading(i, max); 163 | } 164 | } 165 | //将读取的数据设置到STLModel对象中 166 | //=================矫正中心店坐标======================== 167 | float center_x = (maxX + minX) / 2; 168 | float center_y = (maxY + minY) / 2; 169 | float center_z = (maxZ + minZ) / 2; 170 | 171 | for (int i = 0; i < vertext_size * 3; i++) { 172 | adjust_coordinate(vertex_array, i * 3, center_x); 173 | adjust_coordinate(vertex_array, i * 3 + 1, center_y); 174 | adjust_coordinate(vertex_array, i * 3 + 2, center_z); 175 | } 176 | model.setMax(maxX, maxY, maxZ); 177 | model.setMin(minX, minY, minZ); 178 | model.setSize(vertext_size); 179 | model.setVerts(vertex_array); 180 | model.setVnorms(normal_array); 181 | return model; 182 | } 183 | 184 | /** 185 | * 矫正坐标 坐标圆心移动 186 | * 187 | * @param 188 | * @param postion 189 | */ 190 | private void adjust_coordinate(float[] vertex_array, int postion, float adjust) { 191 | this.vertex_array[postion] -= adjust; 192 | } 193 | 194 | @Override 195 | public void setCallBack(OnReadListener listener) { 196 | this.listener = listener; 197 | } 198 | 199 | } 200 | -------------------------------------------------------------------------------- /library/src/main/java/com/study/xuan/gifshow/widget/stlview/util/IOUtils.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.gifshow.widget.stlview.util; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.Closeable; 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.io.OutputStream; 10 | 11 | /** 12 | * Author : xuan. 13 | * Date : 2017/12/8. 14 | * Description :input the description of this file. 15 | */ 16 | 17 | public class IOUtils { 18 | private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; 19 | 20 | /** 21 | * Convert input stream into byte[]. 22 | * 23 | * @param input 24 | * @return Array of Byte 25 | * @throws IOException 26 | */ 27 | public static byte[] toByteArray(InputStream input) throws IOException { 28 | ByteArrayOutputStream output = new ByteArrayOutputStream(); 29 | copy(input, output); 30 | return output.toByteArray(); 31 | } 32 | 33 | /** 34 | * Copy length size of input stream to output stream. 35 | * This method will NOT close input and output stream. 36 | * 37 | * @param input 38 | * @param output 39 | * @return long copied length 40 | * @throws IOException 41 | */ 42 | private static long copy(InputStream input, OutputStream output) throws IOException { 43 | byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; 44 | long count = 0; 45 | int n = 0; 46 | while ((n = input.read(buffer)) != -1) { 47 | output.write(buffer, 0, n); 48 | count += n; 49 | } 50 | return count; 51 | } 52 | 53 | /** 54 | * Copy length size of input stream to output stream. 55 | * 56 | * @param input 57 | * @param output 58 | * @return long copied length 59 | * @throws IOException 60 | */ 61 | public static long copy(InputStream input, OutputStream output, int length) throws IOException { 62 | byte[] buffer = new byte[length]; 63 | int count = 0; 64 | int n = 0; 65 | int max = length; 66 | while ((n = input.read(buffer, 0, max)) != -1) { 67 | output.write(buffer, 0, n); 68 | count += n; 69 | if (count > length) { 70 | break; 71 | } 72 | 73 | max -= n; 74 | if (max <= 0) { 75 | break; 76 | } 77 | } 78 | return count; 79 | } 80 | 81 | /** 82 | * Close closeable quietly. 83 | * 84 | * @param closeable 85 | */ 86 | public static void closeQuietly(Closeable closeable) { 87 | if (closeable == null) { 88 | return; 89 | } 90 | 91 | try { 92 | closeable.close(); 93 | } catch (Throwable e) { 94 | System.out.println("文件关闭失败"); 95 | } 96 | } 97 | public static String File2String(File file) { 98 | Long fileLengthLong = file.length(); 99 | byte[] fileContent = new byte[fileLengthLong.intValue()]; 100 | try { 101 | FileInputStream inputStream = new FileInputStream(file); 102 | inputStream.read(fileContent); 103 | inputStream.close(); 104 | } catch (Exception e) { 105 | // TODO: handle exception 106 | } 107 | return new String(fileContent); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /library/src/main/java/com/study/xuan/gifshow/widget/stlview/util/STLUtils.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.gifshow.widget.stlview.util; 2 | 3 | import android.app.ActivityManager; 4 | import android.content.Context; 5 | import android.content.pm.ConfigurationInfo; 6 | import android.os.Build; 7 | 8 | import java.io.ByteArrayOutputStream; 9 | import java.io.Closeable; 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.io.OutputStream; 13 | import java.nio.ByteBuffer; 14 | import java.nio.ByteOrder; 15 | import java.nio.FloatBuffer; 16 | 17 | import static android.content.Context.ACTIVITY_SERVICE; 18 | 19 | /** 20 | * Author : xuan. 21 | * Date : 2017/12/10. 22 | * Description : STL文件相关工具类 23 | */ 24 | public class STLUtils { 25 | /** 26 | * 判断STL文件格式是否是Ascii格式 27 | */ 28 | public static boolean isAscii(byte[] bytes) { 29 | for (byte b : bytes) { 30 | if (b == 0x0a || b == 0x0d || b == 0x09) { 31 | continue; 32 | } 33 | if (b < 0x20 || (0xff & b) >= 0x80) { 34 | return false; 35 | } 36 | } 37 | return true; 38 | } 39 | 40 | public static FloatBuffer floatToBuffer(float[] a) { 41 | //先初始化buffer,数组的长度*4,因为一个float占4个字节 42 | ByteBuffer bb = ByteBuffer.allocateDirect(a.length * 4); 43 | //数组排序用nativeOrder 44 | bb.order(ByteOrder.nativeOrder()); 45 | FloatBuffer buffer = bb.asFloatBuffer(); 46 | buffer.put(a); 47 | buffer.position(0); 48 | return buffer; 49 | } 50 | 51 | /** 52 | * 检验机器是否支持OpenGl ES2 53 | */ 54 | public static boolean checkSupported(Context context) { 55 | boolean supportsEs2; 56 | ActivityManager activityManager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); 57 | ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); 58 | supportsEs2 = configurationInfo.reqGlEsVersion >= 0x2000; 59 | 60 | boolean isEmulator = Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1 61 | && (Build.FINGERPRINT.startsWith("generic") 62 | || Build.FINGERPRINT.startsWith("unknown") 63 | || Build.MODEL.contains("google_sdk") 64 | || Build.MODEL.contains("Emulator") 65 | || Build.MODEL.contains("Android SDK built for x86")); 66 | 67 | supportsEs2 = supportsEs2 || isEmulator; 68 | return supportsEs2; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /library/src/main/java/com/study/xuan/gifshow/widget/stlview/util/ScreenUtil.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.gifshow.widget.stlview.util; 2 | 3 | import android.content.Context; 4 | import android.view.Display; 5 | import android.view.WindowManager; 6 | 7 | /** 8 | * Author : xuan. 9 | * Date : 2017/11/30. 10 | * Description :input the description of this file. 11 | */ 12 | 13 | public class ScreenUtil { 14 | /** 15 | * 获得屏幕宽高 16 | * 调用getWidth(),getHeight() 17 | */ 18 | public static Display getWindowDisplay(Context context) { 19 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 20 | return wm.getDefaultDisplay(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /library/src/main/java/com/study/xuan/gifshow/widget/stlview/widget/STLRenderer.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.gifshow.widget.stlview.widget; 2 | 3 | import android.opengl.GLSurfaceView.Renderer; 4 | import android.opengl.GLU; 5 | import android.util.Log; 6 | 7 | import com.study.xuan.gifshow.widget.stlview.model.STLModel; 8 | 9 | import java.nio.ByteBuffer; 10 | import java.nio.ByteOrder; 11 | import java.nio.FloatBuffer; 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | import javax.microedition.khronos.egl.EGLConfig; 16 | import javax.microedition.khronos.opengles.GL10; 17 | 18 | /** 19 | * Author : xuan. 20 | * Date : 2017/12/14. 21 | * Description : 渲染器 22 | */ 23 | 24 | 25 | public class STLRenderer implements Renderer { 26 | public static final int FRAME_BUFFER_COUNT = 5; 27 | public float angleX; 28 | public float angleY; 29 | public float positionX = 0f; 30 | public float positionY = 0f; 31 | //scale 32 | //外部控制 33 | public float scale = 1.0f; 34 | //当前展示 35 | private float scale_rember = 1.0f; 36 | //当前固定 37 | private float scale_now = 1.0f; 38 | private boolean scaleRange; 39 | private float SCALE_MAX; 40 | private float SCALE_MIN; 41 | public float translation_z; 42 | 43 | public static float red; 44 | public static float green; 45 | public static float blue; 46 | public static float alpha; 47 | public static boolean displayAxes = false; 48 | public static boolean displayGrids = false; 49 | private static int bufferCounter = FRAME_BUFFER_COUNT; 50 | 51 | private STLModel stlObject; 52 | 53 | public STLRenderer(STLModel stlObject) { 54 | this.stlObject = stlObject; 55 | setTransLation_Z(); 56 | } 57 | 58 | /** 59 | * 简单重绘(适用于旋转等) 60 | */ 61 | public void requestRedraw() { 62 | bufferCounter = FRAME_BUFFER_COUNT; 63 | } 64 | 65 | /** 66 | * 复杂重绘 (适用于更换文件) 67 | * 68 | * @param stlObject 69 | */ 70 | public void requestRedraw(STLModel stlObject) { 71 | 72 | this.stlObject = stlObject; 73 | setTransLation_Z(); 74 | bufferCounter = FRAME_BUFFER_COUNT; 75 | } 76 | 77 | public void checkScaleRange(boolean scaleRange) { 78 | this.scaleRange = scaleRange; 79 | } 80 | 81 | public void setScaleRange(float max, float min) { 82 | this.SCALE_MAX = max; 83 | this.SCALE_MIN = min; 84 | } 85 | 86 | @Override 87 | public void onDrawFrame(GL10 gl) { 88 | if (stlObject == null) { 89 | return; 90 | } 91 | if (bufferCounter < 1) { 92 | return; 93 | } 94 | bufferCounter--; 95 | gl.glLoadIdentity(); 96 | gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); 97 | gl.glTranslatef(positionX, -positionY, 0); 98 | // rotation and apply Z-axis 99 | gl.glTranslatef(0, 0, translation_z); 100 | gl.glRotatef(angleX, 0, 1, 0); 101 | gl.glRotatef(angleY, 1, 0, 0); 102 | gl.glPopMatrix(); 103 | Log.i("angle", "angleX" + angleX + "angleY" + angleY); 104 | 105 | scale_rember = scale_now * scale; 106 | if (scaleRange) { 107 | if (scale_rember > SCALE_MAX) { 108 | scale_rember = SCALE_MAX; 109 | } 110 | if (scale_rember < SCALE_MIN) { 111 | scale_rember = SCALE_MIN; 112 | } 113 | } 114 | gl.glScalef(scale_rember, scale_rember, scale_rember); 115 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 116 | 117 | gl.glMatrixMode(GL10.GL_MODELVIEW); 118 | // draw X-Y field 119 | if (displayGrids) { 120 | drawGrids(gl); 121 | } 122 | if (displayAxes) { 123 | drawLines(gl); 124 | } 125 | 126 | // draw axis 127 | if (displayAxes) { 128 | gl.glLineWidth(3f); 129 | float[] vertexArray = {-100, 0, 0, 100, 0, 0, 0, -100, 0, 0, 100, 0, 0, 0, -100, 0, 0, 100}; 130 | FloatBuffer lineBuffer = getFloatBufferFromArray(vertexArray); 131 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, lineBuffer); 132 | 133 | // X : red 134 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, new float[]{1.0f, 0f, 0f, 0.75f}, 0); 135 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, new float[]{1.0f, 0f, 0f, 0.5f}, 0); 136 | gl.glDrawArrays(GL10.GL_LINES, 0, 2); 137 | 138 | // Y : blue 139 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, new float[]{0f, 0f, 1.0f, 0.75f}, 0); 140 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, new float[]{0f, 0f, 1.0f, 0.5f}, 0); 141 | gl.glDrawArrays(GL10.GL_LINES, 2, 2); 142 | 143 | // Z : green 144 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, new float[]{0f, 1.0f, 0f, 0.75f}, 0); 145 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, new float[]{0f, 1.0f, 0f, 0.5f}, 0); 146 | gl.glDrawArrays(GL10.GL_LINES, 4, 2); 147 | } 148 | 149 | // draw object 150 | if (stlObject != null) { 151 | // FIXME transparency applying does not correctly 152 | gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_AMBIENT, new float[]{0.75f, 0.75f, 0.75f, 1.0f}, 0); 153 | 154 | gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_DIFFUSE, new float[]{0.75f, 0.75f, 0.75f, 1.0f}, 0); 155 | 156 | gl.glEnable(GL10.GL_COLOR_MATERIAL); 157 | gl.glPushMatrix(); 158 | gl.glColor4f(red, green, blue, 1.0f); 159 | stlObject.draw(gl); 160 | gl.glPopMatrix(); 161 | gl.glDisable(GL10.GL_COLOR_MATERIAL); 162 | } 163 | } 164 | 165 | private FloatBuffer getFloatBufferFromArray(float[] vertexArray) { 166 | ByteBuffer vbb = ByteBuffer.allocateDirect(vertexArray.length * 4); 167 | vbb.order(ByteOrder.nativeOrder()); 168 | FloatBuffer triangleBuffer = vbb.asFloatBuffer(); 169 | triangleBuffer.put(vertexArray); 170 | triangleBuffer.position(0); 171 | return triangleBuffer; 172 | } 173 | 174 | private FloatBuffer getFloatBufferFromList(List vertexList) { 175 | ByteBuffer vbb = ByteBuffer.allocateDirect(vertexList.size() * 4); 176 | vbb.order(ByteOrder.nativeOrder()); 177 | FloatBuffer triangleBuffer = vbb.asFloatBuffer(); 178 | float[] array = new float[vertexList.size()]; 179 | for (int i = 0; i < vertexList.size(); i++) { 180 | array[i] = vertexList.get(i); 181 | } 182 | triangleBuffer.put(array); 183 | triangleBuffer.position(0); 184 | return triangleBuffer; 185 | } 186 | 187 | @Override 188 | public void onSurfaceChanged(GL10 gl, int width, int height) { 189 | if (stlObject == null) { 190 | return; 191 | } 192 | float aspectRatio = (float) width / height; 193 | 194 | gl.glViewport(0, 0, width, height); 195 | 196 | gl.glLoadIdentity(); 197 | gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); 198 | 199 | GLU.gluPerspective(gl, 45f, aspectRatio, 1f, 5000f);// (stlObject.maxZ - stlObject.minZ) * 10f + 100f); 200 | 201 | gl.glMatrixMode(GL10.GL_MODELVIEW); 202 | GLU.gluLookAt(gl, 0, 0, 100f, 0, 0, 0, 0, 1f, 0); 203 | } 204 | 205 | @Override 206 | public void onSurfaceCreated(GL10 gl, EGLConfig config) { 207 | if (stlObject == null) { 208 | return; 209 | } 210 | // gl.glClearColor(0f, 0f, 0f, 0.5f); 211 | 212 | 213 | //gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); 214 | gl.glEnable(GL10.GL_BLEND); 215 | // gl.glEnable(GL10.GL_TEXTURE_2D); 216 | // gl.glBlendFunc(GL10.GL_ONE, GL10.GL_SRC_COLOR); 217 | // FIXME This line seems not to be needed? 218 | gl.glClearDepthf(1.0f); 219 | gl.glEnable(GL10.GL_DEPTH_TEST); 220 | gl.glDepthFunc(GL10.GL_LEQUAL); 221 | gl.glHint(3152, 4354); 222 | gl.glEnable(GL10.GL_NORMALIZE); 223 | gl.glShadeModel(GL10.GL_SMOOTH); 224 | 225 | gl.glMatrixMode(GL10.GL_PROJECTION); 226 | 227 | // Lighting 228 | gl.glEnable(GL10.GL_LIGHTING); 229 | gl.glLightModelfv(GL10.GL_LIGHT_MODEL_AMBIENT, getFloatBufferFromArray(new float[]{0.5f, 0.5f, 0.5f, 1.0f}));// 全局环境光 230 | gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT_AND_DIFFUSE, new float[]{0.3f, 0.3f, 0.3f, 1.0f}, 0); 231 | gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, new float[]{0f, 0f, 1000f, 1.0f}, 0); 232 | gl.glEnable(GL10.GL_LIGHT0); 233 | 234 | } 235 | 236 | /** 237 | * 画网格 238 | * 239 | * @param gl 240 | */ 241 | private void drawGrids(GL10 gl) { 242 | List lineList = new ArrayList(); 243 | 244 | for (int x = -100; x <= 100; x += 5) { 245 | lineList.add((float) x); 246 | lineList.add(-100f); 247 | lineList.add(0f); 248 | lineList.add((float) x); 249 | lineList.add(100f); 250 | lineList.add(0f); 251 | } 252 | for (int y = -100; y <= 100; y += 5) { 253 | lineList.add(-100f); 254 | lineList.add((float) y); 255 | lineList.add(0f); 256 | lineList.add(100f); 257 | lineList.add((float) y); 258 | lineList.add(0f); 259 | } 260 | 261 | FloatBuffer lineBuffer = getFloatBufferFromList(lineList); 262 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, lineBuffer); 263 | 264 | gl.glLineWidth(1f); 265 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, new float[]{0.5f, 0.5f, 0.5f, 1.0f}, 0); 266 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, new float[]{0.5f, 0.5f, 0.5f, 1.0f}, 0); 267 | gl.glDrawArrays(GL10.GL_LINES, 0, lineList.size() / 3); 268 | } 269 | 270 | /** 271 | * 画坐标 272 | * 273 | * @param gl 274 | */ 275 | private void drawLines(GL10 gl) { 276 | gl.glLineWidth(3f); 277 | float[] vertexArray = {-100, 0, 0, 100, 0, 0, 0, -100, 0, 0, 100, 0, 0, 0, -100, 0, 0, 100}; 278 | FloatBuffer lineBuffer = getFloatBufferFromArray(vertexArray); 279 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, lineBuffer); 280 | 281 | // X : red 282 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, new float[]{1.0f, 0f, 0f, 0.75f}, 0); 283 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, new float[]{1.0f, 0f, 0f, 0.5f}, 0); 284 | gl.glDrawArrays(GL10.GL_LINES, 0, 2); 285 | 286 | // Y : blue 287 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, new float[]{0f, 0f, 1.0f, 0.75f}, 0); 288 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, new float[]{0f, 0f, 1.0f, 0.5f}, 0); 289 | gl.glDrawArrays(GL10.GL_LINES, 2, 2); 290 | 291 | // Z : green 292 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, new float[]{0f, 1.0f, 0f, 0.75f}, 0); 293 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, new float[]{0f, 1.0f, 0f, 0.5f}, 0); 294 | gl.glDrawArrays(GL10.GL_LINES, 4, 2); 295 | } 296 | 297 | /** 298 | * 调整Z轴平移位置 (目的式为了模型展示大小适中) 299 | */ 300 | private void setTransLation_Z() { 301 | //算x、y轴差值 302 | float distance_x = stlObject.maxX - stlObject.minX; 303 | float distance_y = stlObject.maxY - stlObject.minY; 304 | float distance_z = stlObject.maxZ - stlObject.minZ; 305 | translation_z = distance_x; 306 | if (translation_z < distance_y) { 307 | translation_z = distance_y; 308 | } 309 | if (translation_z < distance_z) { 310 | translation_z = distance_z; 311 | } 312 | translation_z *= -2; 313 | } 314 | 315 | public void delete() { 316 | stlObject.delete(); 317 | stlObject = null; 318 | } 319 | 320 | /** 321 | * 固定缩放比例 322 | */ 323 | public void setsclae() { 324 | scale_now = scale_rember; 325 | scale_rember = 1.0f; 326 | scale = 1.0f; 327 | } 328 | } 329 | -------------------------------------------------------------------------------- /library/src/main/java/com/study/xuan/gifshow/widget/stlview/widget/STLView.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.gifshow.widget.stlview.widget; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.SharedPreferences; 6 | import android.graphics.PointF; 7 | import android.hardware.Sensor; 8 | import android.hardware.SensorEvent; 9 | import android.hardware.SensorEventListener; 10 | import android.hardware.SensorManager; 11 | import android.opengl.GLSurfaceView; 12 | import android.os.Bundle; 13 | import android.os.Parcelable; 14 | import android.util.AttributeSet; 15 | import android.util.Log; 16 | import android.view.MotionEvent; 17 | 18 | import com.study.xuan.gifshow.widget.stlview.callback.OnReadCallBack; 19 | import com.study.xuan.gifshow.widget.stlview.callback.OnReadListener; 20 | import com.study.xuan.gifshow.widget.stlview.model.STLModel; 21 | import com.study.xuan.gifshow.widget.stlview.util.STLUtils; 22 | 23 | /** 24 | * Author : xuan. 25 | * Date : 2017/12/10. 26 | * Description : 自定义展示器 27 | */ 28 | 29 | public class STLView extends GLSurfaceView { 30 | private STLRenderer stlRenderer; 31 | private Context mContext; 32 | private OnReadCallBack onReadCallBack; 33 | //双指缩放 34 | //这里将偏移数值降低 35 | private final float TOUCH_SCALE_FACTOR = 180.0f / 1080 / 2; 36 | private float previousX; 37 | private float previousY; 38 | // zoom rate (larger > 1.0f > smaller) 39 | private float pinchScale = 1.0f; 40 | private PointF pinchStartPoint = new PointF(); 41 | private float pinchStartZ = 0.0f; 42 | private float pinchStartDistance = 0.0f; 43 | private float pinchMoveX = 0.0f; 44 | private float pinchMoveY = 0.0f; 45 | 46 | // for touch event handling 47 | private static final int TOUCH_NONE = 0; 48 | private static final int TOUCH_DRAG = 1; 49 | private static final int TOUCH_ZOOM = 2; 50 | private int touchMode = TOUCH_NONE; 51 | //传感器 52 | private float timestamp; 53 | // 创建常量,把纳秒转换为秒。 54 | private static final float NS2S = 1.0f / 1000000000.0f; 55 | private SensorManager sensorManager; 56 | private Sensor gyroscopeSensor; 57 | private SensorEventListener sensorEventListener; 58 | //感应开关 59 | private boolean isSensor; 60 | private boolean isTouch; 61 | private boolean isRotate; 62 | private boolean isScale; 63 | 64 | private STLModel modelData; 65 | 66 | 67 | public STLView(Context context) { 68 | this(context, null); 69 | } 70 | 71 | public STLView(Context context, AttributeSet attrs) { 72 | super(context, attrs); 73 | this.mContext = context; 74 | if (STLUtils.checkSupported(mContext)) { 75 | init(); 76 | }else{ 77 | Log.e("ERROR", "the phone can't support OpenGl ES2!"); 78 | } 79 | } 80 | 81 | private void init() { 82 | SharedPreferences colorConfig = mContext.getSharedPreferences("colors", Activity.MODE_PRIVATE); 83 | STLRenderer.red = colorConfig.getFloat("red", 0.75f); 84 | STLRenderer.green = colorConfig.getFloat("green", 0.75f); 85 | STLRenderer.blue = colorConfig.getFloat("blue", 0.75f); 86 | STLRenderer.alpha = colorConfig.getFloat("alpha", 0.5f); 87 | stlRenderer = new STLRenderer(new STLModel()); 88 | setRenderer(stlRenderer); 89 | } 90 | 91 | public void setOnReadCallBack(OnReadCallBack onReadCallBack) { 92 | this.onReadCallBack = onReadCallBack; 93 | } 94 | 95 | public OnReadListener getReadListener() { 96 | return readListener; 97 | } 98 | 99 | private final OnReadListener readListener = new OnReadListener() { 100 | @Override 101 | public void onstart() { 102 | if (onReadCallBack != null) { 103 | onReadCallBack.onStart(); 104 | } 105 | } 106 | 107 | @Override 108 | public void onLoading(int cur, int total) { 109 | if (onReadCallBack != null) { 110 | onReadCallBack.onReading(cur, total); 111 | } 112 | } 113 | 114 | @Override 115 | public void onFinished(STLModel model) { 116 | modelData = model; 117 | if (isSensor) { 118 | initSensor(); 119 | } 120 | if (onReadCallBack != null) { 121 | onReadCallBack.onFinish(); 122 | } 123 | stlRenderer.requestRedraw(model); 124 | } 125 | 126 | @Override 127 | public void onFailure(Exception e) { 128 | 129 | } 130 | }; 131 | 132 | private void changeDistance(float scale) { 133 | stlRenderer.scale = scale; 134 | } 135 | 136 | @Override 137 | public boolean onTouchEvent(MotionEvent event) { 138 | if (!isTouch) { 139 | return true; 140 | } 141 | //双指缩放 142 | if (isScale) { 143 | zoomScale(event); 144 | } 145 | //单指旋转 146 | if (isRotate) { 147 | rotateModel(event); 148 | } 149 | return true; 150 | } 151 | 152 | /** 153 | * 单指旋转model 154 | */ 155 | private void rotateModel(MotionEvent event) { 156 | switch (event.getAction() & MotionEvent.ACTION_MASK) { 157 | // start drag 158 | case MotionEvent.ACTION_DOWN: 159 | registerSensor(false); 160 | if (touchMode == TOUCH_NONE && event.getPointerCount() == 1) { 161 | touchMode = TOUCH_DRAG; 162 | previousX = event.getX(); 163 | previousY = event.getY(); 164 | } 165 | break; 166 | 167 | case MotionEvent.ACTION_MOVE: 168 | if (touchMode == TOUCH_DRAG) { 169 | float x = event.getX(); 170 | float y = event.getY(); 171 | 172 | float dx = x - previousX; 173 | float dy = y - previousY; 174 | //一次只移动一个方向 175 | previousX = x; 176 | previousY = y; 177 | 178 | if (isRotate) { 179 | if (Math.abs(dx) > Math.abs(dy)) { 180 | stlRenderer.angleX = (stlRenderer.angleX + dx * TOUCH_SCALE_FACTOR) % 181 | 360.0f; 182 | } else { 183 | stlRenderer.angleY = (stlRenderer.angleY + dy * TOUCH_SCALE_FACTOR) % 184 | 360.0f; 185 | } 186 | } else { 187 | // change view point 188 | stlRenderer.positionX += dx * TOUCH_SCALE_FACTOR / 5; 189 | stlRenderer.positionY += dy * TOUCH_SCALE_FACTOR / 5; 190 | } 191 | stlRenderer.requestRedraw(); 192 | requestRender(); 193 | } 194 | break; 195 | 196 | // end drag 197 | case MotionEvent.ACTION_UP: 198 | registerSensor(true); 199 | if (touchMode == TOUCH_DRAG) { 200 | touchMode = TOUCH_NONE; 201 | break; 202 | } 203 | stlRenderer.setsclae(); 204 | } 205 | } 206 | 207 | /** 208 | * 双指缩放大小 209 | */ 210 | private void zoomScale(MotionEvent event) { 211 | switch (event.getAction() & MotionEvent.ACTION_MASK) { 212 | // starts pinch 213 | case MotionEvent.ACTION_POINTER_DOWN: 214 | registerSensor(false); 215 | if (event.getPointerCount() >= 2) { 216 | pinchStartDistance = getPinchDistance(event); 217 | //pinchStartZ = pinchStartDistance; 218 | if (pinchStartDistance > 50f) { 219 | getPinchCenterPoint(event, pinchStartPoint); 220 | previousX = pinchStartPoint.x; 221 | previousY = pinchStartPoint.y; 222 | touchMode = TOUCH_ZOOM; 223 | } 224 | } 225 | break; 226 | 227 | case MotionEvent.ACTION_MOVE: 228 | if (touchMode == TOUCH_ZOOM && pinchStartDistance > 0) { 229 | // on pinch 230 | PointF pt = new PointF(); 231 | 232 | getPinchCenterPoint(event, pt); 233 | pinchMoveX = pt.x - previousX; 234 | pinchMoveY = pt.y - previousY; 235 | float dx = pinchMoveX; 236 | float dy = pinchMoveY; 237 | previousX = pt.x; 238 | previousY = pt.y; 239 | 240 | if (isRotate) { 241 | stlRenderer.angleX += dx * TOUCH_SCALE_FACTOR; 242 | stlRenderer.angleY += dy * TOUCH_SCALE_FACTOR; 243 | } else { 244 | // change view point 245 | stlRenderer.positionX += dx * TOUCH_SCALE_FACTOR / 5; 246 | stlRenderer.positionY += dy * TOUCH_SCALE_FACTOR / 5; 247 | } 248 | 249 | pinchScale = getPinchDistance(event) / pinchStartDistance; 250 | changeDistance(pinchScale); 251 | stlRenderer.requestRedraw(); 252 | invalidate(); 253 | } 254 | break; 255 | 256 | // end pinch 257 | case MotionEvent.ACTION_UP: 258 | case MotionEvent.ACTION_POINTER_UP: 259 | registerSensor(true); 260 | pinchScale = 0; 261 | pinchStartZ = 0; 262 | if (touchMode == TOUCH_ZOOM) { 263 | touchMode = TOUCH_NONE; 264 | 265 | pinchMoveX = 0.0f; 266 | pinchMoveY = 0.0f; 267 | pinchScale = 1.0f; 268 | pinchStartPoint.x = 0.0f; 269 | pinchStartPoint.y = 0.0f; 270 | invalidate(); 271 | } 272 | break; 273 | } 274 | } 275 | 276 | /** 277 | * 传感器注册事件 278 | */ 279 | private void registerSensor(boolean register) { 280 | if (sensorManager != null) { 281 | if (register) { 282 | sensorManager.registerListener(sensorEventListener, gyroscopeSensor, SensorManager 283 | .SENSOR_DELAY_GAME); 284 | } else { 285 | sensorManager.unregisterListener(sensorEventListener); 286 | } 287 | } 288 | } 289 | 290 | /** 291 | * @param event 292 | * @return pinched distance 293 | */ 294 | private float getPinchDistance(MotionEvent event) { 295 | float x = 0; 296 | float y = 0; 297 | try { 298 | x = event.getX(0) - event.getX(1); 299 | y = event.getY(0) - event.getY(1); 300 | } catch (IllegalArgumentException e) { 301 | // TODO Auto-generated catch block 302 | e.printStackTrace(); 303 | } 304 | return (float) Math.sqrt(x * x + y * y); 305 | } 306 | 307 | private void initSensor() { 308 | sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); 309 | gyroscopeSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); 310 | sensorEventListener = new SensorEventListener() { 311 | @Override 312 | public void onSensorChanged(SensorEvent sensorEvent) { 313 | if (sensorEvent.sensor.getType() == Sensor.TYPE_GYROSCOPE) { 314 | if (timestamp != 0) { 315 | final float dT = (sensorEvent.timestamp - timestamp) * NS2S; 316 | stlRenderer.angleX += sensorEvent.values[0] * dT * 180.0f % 360.0f; 317 | stlRenderer.angleY += sensorEvent.values[1] * dT * 180.0f % 360.0f; 318 | stlRenderer.requestRedraw(); 319 | requestRender(); 320 | } 321 | timestamp = sensorEvent.timestamp; 322 | } 323 | } 324 | 325 | @Override 326 | public void onAccuracyChanged(Sensor sensor, int accuracy) { 327 | 328 | } 329 | }; 330 | sensorManager.registerListener(sensorEventListener, gyroscopeSensor, SensorManager 331 | .SENSOR_DELAY_GAME); 332 | } 333 | 334 | public void setSensor(boolean sensor) { 335 | isSensor = sensor; 336 | } 337 | 338 | public void setTouch(boolean touch) { 339 | isTouch = touch; 340 | } 341 | 342 | public void setRotate(boolean rotate) { 343 | isTouch = true; 344 | isRotate = rotate; 345 | } 346 | 347 | public void setScale(boolean scale) { 348 | isTouch = true; 349 | isScale = scale; 350 | } 351 | 352 | /** 353 | * @param event 354 | * @param pt pinched point 355 | */ 356 | private void getPinchCenterPoint(MotionEvent event, PointF pt) { 357 | pt.x = (event.getX(0) + event.getX(1)) * 0.5f; 358 | pt.y = (event.getY(0) + event.getY(1)) * 0.5f; 359 | } 360 | 361 | @Override 362 | protected Parcelable onSaveInstanceState() { 363 | Bundle bundle = new Bundle(); 364 | bundle.putParcelable("super_state", super.onSaveInstanceState()); 365 | bundle.putParcelable("model", modelData); 366 | bundle.putBoolean("isRotate", isRotate); 367 | bundle.putBoolean("isScale", isScale); 368 | bundle.putBoolean("isSensor", isSensor); 369 | bundle.putBoolean("isTouch", isTouch); 370 | return bundle; 371 | } 372 | 373 | @Override 374 | protected void onRestoreInstanceState(Parcelable state) { 375 | if (state instanceof Bundle) { 376 | Bundle bundle = (Bundle) state; 377 | setTouch(bundle.getBoolean("isTouch")); 378 | setRotate(bundle.getBoolean("isRotate")); 379 | setScale(bundle.getBoolean("isScale")); 380 | setSensor(bundle.getBoolean("isSensor")); 381 | setNewSTLObject((STLModel) bundle.getParcelable("model")); 382 | super.onRestoreInstanceState(bundle.getParcelable("super_state")); 383 | return; 384 | } 385 | super.onRestoreInstanceState(state); 386 | } 387 | 388 | /** 389 | * 更新object 刷新界面 390 | * 391 | * @param stlObject 392 | */ 393 | public void setNewSTLObject(STLModel stlObject) { 394 | this.modelData = stlObject; 395 | stlRenderer.requestRedraw(stlObject); 396 | } 397 | 398 | /** 399 | * 刷新界面 400 | */ 401 | public void requestRedraw() { 402 | stlRenderer.requestRedraw(); 403 | } 404 | 405 | public void delete() { 406 | stlRenderer.delete(); 407 | } 408 | } 409 | -------------------------------------------------------------------------------- /library/src/main/java/com/study/xuan/gifshow/widget/stlview/widget/STLViewBuilder.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.gifshow.widget.stlview.widget; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | 6 | import com.study.xuan.gifshow.widget.stlview.callback.OnReadListener; 7 | import com.study.xuan.gifshow.widget.stlview.operate.ISTLReader; 8 | import com.study.xuan.gifshow.widget.stlview.operate.ReaderHandler; 9 | import com.study.xuan.gifshow.widget.stlview.operate.STLReader; 10 | import com.study.xuan.gifshow.widget.stlview.util.IOUtils; 11 | 12 | import java.io.File; 13 | import java.io.FileInputStream; 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | 17 | /** 18 | * Author : xuan. 19 | * Date : 2017/12/14. 20 | * Description :3dView 构造器 21 | */ 22 | 23 | public class STLViewBuilder { 24 | private STLView stlView; 25 | private static final int TYPE_FILE = 0; 26 | private static final int TYPE_BYTE = 1; 27 | private static final int TYPE_STREAM = 2; 28 | private ReaderHandler handler; 29 | private OnReadListener listener; 30 | private File file; 31 | private byte[] bytes; 32 | private InputStream is; 33 | private ISTLReader reader; 34 | private boolean hasSource; 35 | private int type; 36 | private Object obj; 37 | 38 | public STLViewBuilder(STLView stlView) { 39 | this.stlView = stlView; 40 | this.listener = stlView.getReadListener(); 41 | } 42 | 43 | public static STLViewBuilder init(STLView stlView) { 44 | return new STLViewBuilder(stlView); 45 | } 46 | 47 | public STLViewBuilder Reader(ISTLReader reader) { 48 | this.reader = reader; 49 | this.reader.setCallBack(this.listener); 50 | return this; 51 | } 52 | 53 | public STLViewBuilder Byte(byte[] bytes) { 54 | hasSource = true; 55 | type = TYPE_BYTE; 56 | this.bytes = bytes; 57 | return this; 58 | } 59 | 60 | public STLViewBuilder File(File file) { 61 | type = TYPE_FILE; 62 | hasSource = true; 63 | this.file = file; 64 | return this; 65 | } 66 | 67 | public STLViewBuilder Assets(Context context, String fileName) { 68 | try { 69 | return InputStream(context.getAssets().open(fileName)); 70 | } catch (IOException e) { 71 | e.printStackTrace(); 72 | } 73 | return this; 74 | } 75 | 76 | public STLViewBuilder InputStream(InputStream inputStream) { 77 | type = TYPE_STREAM; 78 | hasSource = true; 79 | this.is = inputStream; 80 | return this; 81 | } 82 | 83 | public STLViewBuilder build() { 84 | if (!hasSource) { 85 | Log.e("VRShow", "has not set the source file!"); 86 | return this; 87 | } 88 | if (reader == null) { 89 | reader = new STLReader(); 90 | reader.setCallBack(this.listener); 91 | } 92 | handler = new ReaderHandler(reader, listener); 93 | try { 94 | switch (type) { 95 | case TYPE_BYTE: 96 | handler.read(bytes); 97 | break; 98 | case TYPE_FILE: 99 | handler.read(IOUtils.toByteArray(new FileInputStream(file))); 100 | break; 101 | case TYPE_STREAM: 102 | handler.read(IOUtils.toByteArray(is)); 103 | break; 104 | } 105 | } catch (IOException e) { 106 | e.printStackTrace(); 107 | } 108 | return this; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | gifshow 3 | 4 | -------------------------------------------------------------------------------- /library/src/test/java/com/study/xuan/gifshow/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.gifshow; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':library' 2 | -------------------------------------------------------------------------------- /stlshow/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /stlshow/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | group='com.github.sdfdzx' 5 | android { 6 | compileSdkVersion 26 7 | buildToolsVersion "27.0.0" 8 | 9 | defaultConfig { 10 | minSdkVersion 19 11 | targetSdkVersion 26 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | compile fileTree(dir: 'libs', include: ['*.jar']) 28 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 29 | exclude group: 'com.android.support', module: 'support-annotations' 30 | }) 31 | compile 'com.android.support:appcompat-v7:26.+' 32 | testCompile 'junit:junit:4.12' 33 | compile 'com.google.vr:sdk-panowidget:1.101.0' 34 | } 35 | -------------------------------------------------------------------------------- /stlshow/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\Program\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /stlshow/src/androidTest/java/com/study/xuan/stlshow/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.stlshow; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.study.xuan.stlshow.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /stlshow/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /stlshow/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | STLShow 3 | 4 | -------------------------------------------------------------------------------- /stlshow/src/test/java/com/study/xuan/stlshow/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.study.xuan.stlshow; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } --------------------------------------------------------------------------------