Commit 1cd22e49f2786953b1fa2b99cf542104a5c06929

Authored by Thiago Filipe Soares da Rocha
1 parent 73e36320

Finish Show in Gallery

Assets/Plugins/Android/AndroidManifest.xml
@@ -24,6 +24,6 @@ @@ -24,6 +24,6 @@
24 <category android:name="android.intent.category.LAUNCHER" /> 24 <category android:name="android.intent.category.LAUNCHER" />
25 </intent-filter> 25 </intent-filter>
26 <meta-data android:name="unityplayer.UnityActivity" android:value="true" /> 26 <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
27 - </activity> 27 + </activity>
28 </application> 28 </application>
29 </manifest> 29 </manifest>
30 \ No newline at end of file 30 \ No newline at end of file
Assets/Scenes/Main.unity
@@ -793,7 +793,7 @@ GameObject: @@ -793,7 +793,7 @@ GameObject:
793 m_Icon: {fileID: 0} 793 m_Icon: {fileID: 0}
794 m_NavMeshLayer: 0 794 m_NavMeshLayer: 0
795 m_StaticEditorFlags: 0 795 m_StaticEditorFlags: 0
796 - m_IsActive: 1 796 + m_IsActive: 0
797 --- !u!224 &160532052 797 --- !u!224 &160532052
798 RectTransform: 798 RectTransform:
799 m_ObjectHideFlags: 0 799 m_ObjectHideFlags: 0
@@ -1314,6 +1314,7 @@ MonoBehaviour: @@ -1314,6 +1314,7 @@ MonoBehaviour:
1314 m_Name: 1314 m_Name:
1315 m_EditorClassIdentifier: 1315 m_EditorClassIdentifier:
1316 screenManager: {fileID: 2131993094} 1316 screenManager: {fileID: 2131993094}
  1317 + MediaShareAndroid: {fileID: 1120909430}
1317 --- !u!4 &210788817 1318 --- !u!4 &210788817
1318 Transform: 1319 Transform:
1319 m_ObjectHideFlags: 0 1320 m_ObjectHideFlags: 0
@@ -7721,6 +7722,46 @@ MonoBehaviour: @@ -7721,6 +7722,46 @@ MonoBehaviour:
7721 m_Calls: [] 7722 m_Calls: []
7722 m_TypeName: UnityEngine.UI.ScrollRect+ScrollRectEvent, UnityEngine.UI, Version=1.0.0.0, 7723 m_TypeName: UnityEngine.UI.ScrollRect+ScrollRectEvent, UnityEngine.UI, Version=1.0.0.0,
7723 Culture=neutral, PublicKeyToken=null 7724 Culture=neutral, PublicKeyToken=null
  7725 +--- !u!1 &1120909429
  7726 +GameObject:
  7727 + m_ObjectHideFlags: 0
  7728 + m_PrefabParentObject: {fileID: 0}
  7729 + m_PrefabInternal: {fileID: 0}
  7730 + serializedVersion: 4
  7731 + m_Component:
  7732 + - 4: {fileID: 1120909431}
  7733 + - 114: {fileID: 1120909430}
  7734 + m_Layer: 0
  7735 + m_Name: MediaShareAndroid
  7736 + m_TagString: Untagged
  7737 + m_Icon: {fileID: 0}
  7738 + m_NavMeshLayer: 0
  7739 + m_StaticEditorFlags: 0
  7740 + m_IsActive: 1
  7741 +--- !u!114 &1120909430
  7742 +MonoBehaviour:
  7743 + m_ObjectHideFlags: 0
  7744 + m_PrefabParentObject: {fileID: 0}
  7745 + m_PrefabInternal: {fileID: 0}
  7746 + m_GameObject: {fileID: 1120909429}
  7747 + m_Enabled: 1
  7748 + m_EditorHideFlags: 0
  7749 + m_Script: {fileID: 11500000, guid: fd1b12a178cf08b4284859e93194c7a4, type: 3}
  7750 + m_Name:
  7751 + m_EditorClassIdentifier:
  7752 +--- !u!4 &1120909431
  7753 +Transform:
  7754 + m_ObjectHideFlags: 0
  7755 + m_PrefabParentObject: {fileID: 0}
  7756 + m_PrefabInternal: {fileID: 0}
  7757 + m_GameObject: {fileID: 1120909429}
  7758 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
  7759 + m_LocalPosition: {x: 234.47318, y: 151.18846, z: 0}
  7760 + m_LocalScale: {x: 1, y: 1, z: 1}
  7761 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
  7762 + m_Children: []
  7763 + m_Father: {fileID: 0}
  7764 + m_RootOrder: 8
7724 --- !u!1 &1124983616 7765 --- !u!1 &1124983616
7725 GameObject: 7766 GameObject:
7726 m_ObjectHideFlags: 0 7767 m_ObjectHideFlags: 0
Assets/Scripts/Export Video/AndroidJavaUti.cs
1 -/**********************  
2 -********LAVID**********  
3 -***VLibras Project*****  
4 -*------------------------------------------------------------------------  
5 -*Description:  
6 -*This class is an Android Plugin that gets the current sd card path from  
7 -* Android Device, making available the access to files folder.  
8 -*---------------------------------------------------------------------------  
9 -*Plugin directory:  
10 -* - Assets/Plugins/Android  
11 -*References:  
12 -* - http://docs.unity3d.com/ScriptReference/AndroidJavaClass.html  
13 -*------------------------------------------------------------------------  
14 -*Author: Thiago Filipe  
15 -*thiago.filipe@lavid.ufpb.br  
16 -***********************/  
17 -  
18 -using UnityEngine;  
19 -using System.Collections; 1 +using UnityEngine;
20 using System; 2 using System;
  3 +using System.Collections;
21 4
22 -public class AndroidJavaUti{ 5 +public class AndroidJavaUti : MonoBehaviour {
23 6
24 -  
25 - private static string m_pkgName;  
26 - private static string m_sdCardPath;  
27 - public static AndroidJavaObject Activity 7 + private static string m_pkgName;
  8 + private static string m_sdCardPath;
  9 + public static AndroidJavaObject Activity
  10 + {
  11 + get
28 { 12 {
29 - get  
30 - {  
31 - AndroidJavaClass jcPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");  
32 - return jcPlayer.GetStatic<AndroidJavaObject>("currentActivity");  
33 - } 13 + AndroidJavaClass jcPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  14 + return jcPlayer.GetStatic<AndroidJavaObject>("currentActivity");
34 } 15 }
  16 + }
35 17
36 18
37 - public static string CurrentPkgName 19 + public static string CurrentPkgName
  20 + {
  21 + get
38 { 22 {
39 - get  
40 - {  
41 - if (m_pkgName == null)  
42 - m_pkgName = Activity.Call<string>("getPackageName");  
43 - return m_pkgName;  
44 - } 23 + if (m_pkgName == null)
  24 + m_pkgName = Activity.Call<string>("getPackageName");
  25 + return m_pkgName;
45 } 26 }
46 - public static string CurrentSDCardPath 27 + }
  28 + public static string CurrentSDCardPath
  29 + {
  30 + get
47 { 31 {
48 - get 32 + if (m_sdCardPath == null)
49 { 33 {
50 - if (m_sdCardPath == null)  
51 - {  
52 - AndroidJavaClass jc = new AndroidJavaClass("android.os.Environment");  
53 - IntPtr getExternalStorageDirectoryMethod = AndroidJNI.GetStaticMethodID(jc.GetRawClass(), "getExternalStorageDirectory", "()Ljava/io/File;");  
54 - IntPtr file = AndroidJNI.CallStaticObjectMethod(jc.GetRawClass(), getExternalStorageDirectoryMethod, new jvalue[] { });  
55 - IntPtr getPathMethod = AndroidJNI.GetMethodID(AndroidJNI.GetObjectClass(file), "getPath", "()Ljava/lang/String;");  
56 - IntPtr path = AndroidJNI.CallObjectMethod(file, getPathMethod, new jvalue[] { });  
57 - m_sdCardPath = AndroidJNI.GetStringUTFChars(path);  
58 - AndroidJNI.DeleteLocalRef(file);  
59 - AndroidJNI.DeleteLocalRef(path);  
60 - Debug.Log("m_sdCardPath = " + m_sdCardPath);  
61 - }  
62 - return m_sdCardPath; 34 + AndroidJavaClass jc = new AndroidJavaClass("android.os.Environment");
  35 + IntPtr getExternalStorageDirectoryMethod = AndroidJNI.GetStaticMethodID(jc.GetRawClass(), "getExternalStorageDirectory", "()Ljava/io/File;");
  36 + IntPtr file = AndroidJNI.CallStaticObjectMethod(jc.GetRawClass(), getExternalStorageDirectoryMethod, new jvalue[] { });
  37 + IntPtr getPathMethod = AndroidJNI.GetMethodID(AndroidJNI.GetObjectClass(file), "getPath", "()Ljava/lang/String;");
  38 + IntPtr path = AndroidJNI.CallObjectMethod(file, getPathMethod, new jvalue[] { });
  39 + m_sdCardPath = AndroidJNI.GetStringUTFChars(path);
  40 + AndroidJNI.DeleteLocalRef(file);
  41 + AndroidJNI.DeleteLocalRef(path);
  42 + Debug.Log("m_sdCardPath = " + m_sdCardPath);
63 } 43 }
64 - 44 + return m_sdCardPath;
65 } 45 }
66 -}  
67 46
  47 + }
  48 +}
Assets/Scripts/Export Video/AndroidJavaUti.cs.meta
1 fileFormatVersion: 2 1 fileFormatVersion: 2
2 -guid: 437223d76094ce840a68de8b6ea60fe8  
3 -timeCreated: 1486222942 2 +guid: e79be87b2ce96744e9141cee2058779b
  3 +timeCreated: 1486833877
4 licenseType: Free 4 licenseType: Free
5 MonoImporter: 5 MonoImporter:
6 serializedVersion: 2 6 serializedVersion: 2
Assets/Scripts/Export Video/AndroidPath.cs
@@ -1,63 +0,0 @@ @@ -1,63 +0,0 @@
1 -using UnityEngine;  
2 -using System.Collections;  
3 -using System;  
4 -  
5 -  
6 -public class AndroidPaths : MonoBehaviour {  
7 -  
8 - public static string GetAndroidContextExternalFilesDir  
9 - {  
10 - get  
11 - {  
12 - string path = "";  
13 -  
14 - if (Application.platform == RuntimePlatform.Android)  
15 - {  
16 - try  
17 - {  
18 - using (AndroidJavaClass ajc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))  
19 - {  
20 - using (AndroidJavaObject ajo = ajc.GetStatic<AndroidJavaObject>("currentActivity"))  
21 - {  
22 - path = ajo.Call<AndroidJavaObject>("getExternalFilesDir", null).Call<string>("getAbsolutePath");  
23 - }  
24 - }  
25 - }  
26 - catch (Exception e)  
27 - {  
28 - Debug.LogWarning("Error fetching native Android external storage dir: " + e.Message);  
29 - }  
30 - }  
31 - return path;  
32 - }  
33 - }  
34 -  
35 - public static string GetAndroidContextInternalFilesDir  
36 - {  
37 - get  
38 - {  
39 - string path = "";  
40 -  
41 - if (Application.platform == RuntimePlatform.Android)  
42 - {  
43 - try  
44 - {  
45 - using (AndroidJavaClass ajc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))  
46 - {  
47 - using (AndroidJavaObject ajo = ajc.GetStatic<AndroidJavaObject>("currentActivity"))  
48 - {  
49 - path = ajo.Call<AndroidJavaObject>("getFilesDir").Call<string>("getAbsolutePath");  
50 - }  
51 - }  
52 - }  
53 - catch (Exception e)  
54 - {  
55 - Debug.LogWarning("Error fetching native Android internal storage dir: " + e.Message);  
56 - }  
57 - }  
58 - return path;  
59 - }  
60 - }  
61 -  
62 -  
63 -}  
Assets/Scripts/Export Video/AndroidPath.cs.meta
@@ -1,12 +0,0 @@ @@ -1,12 +0,0 @@
1 -fileFormatVersion: 2  
2 -guid: 71dacb9b6a7d04349b9913751ef87ad4  
3 -timeCreated: 1486607668  
4 -licenseType: Free  
5 -MonoImporter:  
6 - serializedVersion: 2  
7 - defaultReferences: []  
8 - executionOrder: 0  
9 - icon: {instanceID: 0}  
10 - userData:  
11 - assetBundleName:  
12 - assetBundleVariant:  
Assets/Scripts/Export Video/AndroidToast.cs
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 using UnityEngine; 18 using UnityEngine;
19 using System.Collections; 19 using System.Collections;
20 20
21 -public class AndroidToast : MonoBehaviour 21 +public class AndroidToast
22 { 22 {
23 AndroidJavaObject currentActivity; 23 AndroidJavaObject currentActivity;
24 AndroidJavaClass UnityPlayer; 24 AndroidJavaClass UnityPlayer;
Assets/Scripts/Export Video/ExportVideo.cs
@@ -30,12 +30,18 @@ public class ExportVideo : MonoBehaviour { @@ -30,12 +30,18 @@ public class ExportVideo : MonoBehaviour {
30 30
31 31
32 public ScreenManager screenManager; 32 public ScreenManager screenManager;
33 - private MobileNativeDialog nativeDialog; 33 + public MediaShareAndroid MediaShareAndroid;
34 34
  35 + private const string SERVER_URL = "http://150.165.205.57/video/";
  36 +
  37 + /*Strings to Compare glosses*/
35 private static string gloss = "Gloss"; 38 private static string gloss = "Gloss";
36 private string currentGloss = "CurrentGloss"; 39 private string currentGloss = "CurrentGloss";
  40 +
  41 + /* Sharing Current Time - Video Name*/
37 private string currentTime = ""; 42 private string currentTime = "";
38 - private const string SERVER_URL = "http://150.165.205.38/video/"; 43 +
  44 +
39 45
40 /* Strings related to the Android Dialog*/ 46 /* Strings related to the Android Dialog*/
41 private string title = "Download"; 47 private string title = "Download";
@@ -43,13 +49,15 @@ public class ExportVideo : MonoBehaviour { @@ -43,13 +49,15 @@ public class ExportVideo : MonoBehaviour {
43 private string yesOp = "DOWNLOAD"; 49 private string yesOp = "DOWNLOAD";
44 private string noOp = "CANCELAR"; 50 private string noOp = "CANCELAR";
45 51
  52 + /* Data related to the Video*/
46 53
47 - private float videoSize = 0; 54 + private int videoSize = 0;
48 private int bytes = 0; 55 private int bytes = 0;
49 private string videoId = ""; 56 private string videoId = "";
50 private byte[] videoContent = null; 57 private byte[] videoContent = null;
51 58
52 - 59 + /*Coroutine flags */
  60 +
53 private bool videoRequestRunning = false; 61 private bool videoRequestRunning = false;
54 private bool videoDownloadRunning = false; 62 private bool videoDownloadRunning = false;
55 63
@@ -67,12 +75,12 @@ public class ExportVideo : MonoBehaviour { @@ -67,12 +75,12 @@ public class ExportVideo : MonoBehaviour {
67 75
68 public void onClickExport() 76 public void onClickExport()
69 { 77 {
70 -  
71 - Debug.Log("onClickShare pressed"); 78 +
  79 + PlayerLogger.Log("ExportVideo", "OnClickExport", "Starting Export...");
72 screenManager.changeExportStates(ExportLayers.ExportLayer.Export_Layer,false); 80 screenManager.changeExportStates(ExportLayers.ExportLayer.Export_Layer,false);
73 screenManager.changeExportStates(ExportLayers.ExportLayer.Progress_Layer, true); 81 screenManager.changeExportStates(ExportLayers.ExportLayer.Progress_Layer, true);
74 StartCoroutine("requestVideoInfo"); 82 StartCoroutine("requestVideoInfo");
75 - Debug.Log("Hiding export button and showing progress loading"); 83 + PlayerLogger.Log("ExportVideo", "OnClickExport", "Making request to server.");
76 84
77 } 85 }
78 86
@@ -81,10 +89,10 @@ public class ExportVideo : MonoBehaviour { @@ -81,10 +89,10 @@ public class ExportVideo : MonoBehaviour {
81 * button*/ 89 * button*/
82 public void OnFinishGetVideoInfo() 90 public void OnFinishGetVideoInfo()
83 { 91 {
84 - Debug.Log("Video is ready to be downloaded"); 92 + PlayerLogger.Log("ExportVideo","OnFinishGetVideoInfo","Video is ready to be downloaded.");
85 screenManager.changeExportStates(ExportLayers.ExportLayer.Progress_Layer, false); 93 screenManager.changeExportStates(ExportLayers.ExportLayer.Progress_Layer, false);
86 screenManager.changeExportStates(ExportLayers.ExportLayer.Download_Layer, true); 94 screenManager.changeExportStates(ExportLayers.ExportLayer.Download_Layer, true);
87 - Debug.Log("Hiding progress loading and showing download button"); 95 + PlayerLogger.Log("ExportVideo", "OnFinishGetVideoInfo", "Hiding progress loading and showing download button");
88 96
89 } 97 }
90 98
@@ -93,10 +101,12 @@ public class ExportVideo : MonoBehaviour { @@ -93,10 +101,12 @@ public class ExportVideo : MonoBehaviour {
93 101
94 public void onDownloadClick() 102 public void onDownloadClick()
95 { 103 {
96 -  
97 - Debug.Log("Asking for permition to download");  
98 - nativeDialog = new MobileNativeDialog(title, message + ((videoSize/1024f)/1024f).ToString("0.00") + " MB.", yesOp, noOp);  
99 - nativeDialog.OnComplete = OnComplete; 104 + MobileNativeDialog nativeDialog;
  105 +
  106 +
  107 +
  108 + nativeDialog = new MobileNativeDialog(title, message + ((videoSize/1024f)/1024f).ToString("0.00") + " MB.", yesOp, noOp);
  109 + nativeDialog.OnComplete = OnComplete;
100 110
101 } 111 }
102 112
@@ -108,13 +118,13 @@ public class ExportVideo : MonoBehaviour { @@ -108,13 +118,13 @@ public class ExportVideo : MonoBehaviour {
108 { 118 {
109 if(result == MNDialogResult.YES) 119 if(result == MNDialogResult.YES)
110 { 120 {
111 - Debug.Log("User pressed yes"); 121 + PlayerLogger.Log("ExportVideo", "OnDownloadClick", "Starting Video Download...");
112 StartCoroutine("videoDownload"); 122 StartCoroutine("videoDownload");
113 screenManager.changeExportStates(ExportLayers.ExportLayer.Download_Layer, false); 123 screenManager.changeExportStates(ExportLayers.ExportLayer.Download_Layer, false);
114 screenManager.changeExportStates(ExportLayers.ExportLayer.Progress_Download_Layer, true); 124 screenManager.changeExportStates(ExportLayers.ExportLayer.Progress_Download_Layer, true);
115 }else if(result == MNDialogResult.NO) 125 }else if(result == MNDialogResult.NO)
116 { 126 {
117 - Debug.Log("User pressed no"); 127 + PlayerLogger.Log("ExportVideo", "OnDownloadClick", "Resetting states to default...");
118 screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); 128 screenManager.changeExportStates(ExportLayers.ExportLayer.All, true);
119 129
120 } 130 }
@@ -124,7 +134,7 @@ public class ExportVideo : MonoBehaviour { @@ -124,7 +134,7 @@ public class ExportVideo : MonoBehaviour {
124 134
125 public void OnDownloadFinished() 135 public void OnDownloadFinished()
126 { 136 {
127 - Debug.Log("Download has finished. Setting layer to Share Layer"); 137 + PlayerLogger.Log("ExportVideo", "OnDownloadFinished", "Video Downloaded, able to share it.");
128 screenManager.changeExportStates(ExportLayers.ExportLayer.Progress_Download_Layer, false); 138 screenManager.changeExportStates(ExportLayers.ExportLayer.Progress_Download_Layer, false);
129 screenManager.changeExportStates(ExportLayers.ExportLayer.Share_Layer, true); 139 screenManager.changeExportStates(ExportLayers.ExportLayer.Share_Layer, true);
130 } 140 }
@@ -155,75 +165,42 @@ public class ExportVideo : MonoBehaviour { @@ -155,75 +165,42 @@ public class ExportVideo : MonoBehaviour {
155 165
156 public void OnShareVideo() 166 public void OnShareVideo()
157 { 167 {
158 - Debug.Log("Sharing video content");  
159 - if(gloss == currentGloss)  
160 - {  
161 - try  
162 - {  
163 - if (videoContent != null)  
164 - new MediaShareAndroid().ShareActivity(videoContent,bytes, currentTime);  
165 - else  
166 - {  
167 - new AndroidToast().showToast("Erro ao compartilhar vídeo");  
168 - screenManager.changeExportStates(ExportLayers.ExportLayer.All, true);  
169 - }  
170 - }  
171 - catch (Exception e)  
172 - {  
173 - new AndroidToast().showToast(e.Message);  
174 - new AndroidToast().showToast(e.StackTrace);  
175 - }  
176 - 168 + PlayerLogger.Log("ExportVideo", "OnShareVideo", "Sharing Video...");
177 169
  170 + if (gloss == currentGloss) //Checking if user is trying to share the same animation
  171 + {
  172 + Share();
178 } 173 }
179 else 174 else
180 { 175 {
181 currentGloss = gloss; 176 currentGloss = gloss;
182 - currentTime = System.DateTime.Now.ToString("yyyy-MM-dd_HH:mm:ss");  
183 -  
184 - if (videoContent != null)  
185 - new MediaShareAndroid().ShareActivity(videoContent,bytes, currentTime);  
186 - else  
187 - {  
188 - screenManager.changeExportStates(ExportLayers.ExportLayer.All, true);  
189 - new AndroidToast().showToast("Erro ao compartilhar vídeo");  
190 - }  
191 -  
192 - }  
193 - 177 + currentTime = System.DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss");
  178 + Share();
  179 + }
194 } 180 }
195 181
196 - /*Coroutine that downloads the video and update the progress download layer*/  
197 -  
198 - private IEnumerator videoDownload() 182 + private void Share()
199 { 183 {
200 - videoDownloadRunning = true;  
201 - // WWW DownloadVideo = new WWW(SERVER_URL + videoId);  
202 - WWW DownloadVideo = new WWW("http://caiomcg.com/rural.mp4");  
203 - while (!DownloadVideo.isDone)  
204 - {  
205 - screenManager.updateProgressDownloadSprite(DownloadVideo.progress);  
206 - yield return null;  
207 - }  
208 184
209 try 185 try
210 { 186 {
211 - if (DownloadVideo.bytesDownloaded > 0 ) 187 + if (videoContent != null)
212 { 188 {
213 - bytes = DownloadVideo.bytesDownloaded;  
214 - videoContent = DownloadVideo.bytes;  
215 - OnDownloadFinished(); 189 +
  190 + MediaShareAndroid.ShareActivity(videoContent, bytes, currentTime);
216 } 191 }
217 else 192 else
218 { 193 {
219 - GetConnectionStatusError(ExportLayers.ConnectionStatusError.DOWNLOAD_CONNECTION_FAILURE); 194 + new AndroidToast().showToast("Erro ao compartilhar vídeo");
  195 + screenManager.changeExportStates(ExportLayers.ExportLayer.All, true);
220 } 196 }
221 -  
222 -  
223 } 197 }
224 - finally 198 + catch (Exception e)
225 { 199 {
226 - videoDownloadRunning = false; 200 + PlayerLogger.Log("ExportVideo", "Share", "Exception thrown: " + e.Message);
  201 + // new AndroidToast().showToast(e.Message);
  202 + new AndroidToast().showToast("É necessário dá permissão ao aplicativo.");
  203 +
227 } 204 }
228 } 205 }
229 206
@@ -234,11 +211,11 @@ public class ExportVideo : MonoBehaviour { @@ -234,11 +211,11 @@ public class ExportVideo : MonoBehaviour {
234 videoRequestRunning = true; 211 videoRequestRunning = true;
235 WWWForm JsonRequest = new WWWForm(); 212 WWWForm JsonRequest = new WWWForm();
236 JsonRequest.AddField("gloss", gloss); 213 JsonRequest.AddField("gloss", gloss);
237 - WWW videoInfoRequest = new WWW(SERVER_URL,JsonRequest);  
238 - 214 + WWW videoInfoRequest = new WWW(SERVER_URL, JsonRequest);
  215 +
239 PlayerLogger.Log("ExportVideo", "requestVideoInfo", "Request for: " + SERVER_URL); 216 PlayerLogger.Log("ExportVideo", "requestVideoInfo", "Request for: " + SERVER_URL);
240 217
241 - yield return WaitForResponse(videoInfoRequest); 218 + yield return WaitForResponse(videoInfoRequest);
242 219
243 try 220 try
244 { 221 {
@@ -251,7 +228,7 @@ public class ExportVideo : MonoBehaviour { @@ -251,7 +228,7 @@ public class ExportVideo : MonoBehaviour {
251 } 228 }
252 else if (videoInfoRequest.error != null) 229 else if (videoInfoRequest.error != null)
253 { 230 {
254 - 231 +
255 screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); 232 screenManager.changeExportStates(ExportLayers.ExportLayer.All, true);
256 GetConnectionStatusError(ExportLayers.ConnectionStatusError.INTERNET_CONNECTION_FAILURE); 233 GetConnectionStatusError(ExportLayers.ConnectionStatusError.INTERNET_CONNECTION_FAILURE);
257 PlayerLogger.Log("ExportVideo", "requestVideoInfo", "(WWW) Error: " + videoInfoRequest.error); 234 PlayerLogger.Log("ExportVideo", "requestVideoInfo", "(WWW) Error: " + videoInfoRequest.error);
@@ -261,19 +238,19 @@ public class ExportVideo : MonoBehaviour { @@ -261,19 +238,19 @@ public class ExportVideo : MonoBehaviour {
261 PlayerLogger.Log("ExportVideo", "requestVideoInfo", "(WWW) Unsucessful Answer"); 238 PlayerLogger.Log("ExportVideo", "requestVideoInfo", "(WWW) Unsucessful Answer");
262 GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE); 239 GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE);
263 screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); 240 screenManager.changeExportStates(ExportLayers.ExportLayer.All, true);
264 - 241 +
265 } 242 }
266 else if (!videoInfoRequest.responseHeaders["STATUS"].Contains("200")) 243 else if (!videoInfoRequest.responseHeaders["STATUS"].Contains("200"))
267 { 244 {
268 - 245 +
269 PlayerLogger.Log("ExportVideo", "requestVideoInfo", "Unsuccessful answer (" + videoInfoRequest.responseHeaders["STATUS"] + ")."); 246 PlayerLogger.Log("ExportVideo", "requestVideoInfo", "Unsuccessful answer (" + videoInfoRequest.responseHeaders["STATUS"] + ").");
270 GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE); 247 GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE);
271 screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); 248 screenManager.changeExportStates(ExportLayers.ExportLayer.All, true);
272 - 249 +
273 } 250 }
274 else if (String.IsNullOrEmpty(videoInfoRequest.text)) 251 else if (String.IsNullOrEmpty(videoInfoRequest.text))
275 { 252 {
276 - 253 +
277 screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); 254 screenManager.changeExportStates(ExportLayers.ExportLayer.All, true);
278 GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE); 255 GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE);
279 PlayerLogger.Log("ExportVideo", "requestVideoInfo", "Empty answer."); 256 PlayerLogger.Log("ExportVideo", "requestVideoInfo", "Empty answer.");
@@ -285,24 +262,56 @@ public class ExportVideo : MonoBehaviour { @@ -285,24 +262,56 @@ public class ExportVideo : MonoBehaviour {
285 FileContent fileContent = new FileContent(); 262 FileContent fileContent = new FileContent();
286 fileContent = FileContent.CreateFromJSON(videoInfoRequest.text); 263 fileContent = FileContent.CreateFromJSON(videoInfoRequest.text);
287 videoId = fileContent.file; 264 videoId = fileContent.file;
288 - videoSize = float.Parse(fileContent.size); 265 + videoSize = int.Parse(fileContent.size);
289 OnFinishGetVideoInfo(); 266 OnFinishGetVideoInfo();
290 267
291 yield break; 268 yield break;
292 } 269 }
293 270
294 - 271 +
295 } 272 }
296 finally 273 finally
297 { 274 {
298 videoRequestRunning = false; 275 videoRequestRunning = false;
299 276
300 -  
301 - 277 +
  278 +
302 } 279 }
303 } 280 }
304 281
  282 + /*Coroutine that downloads the video and update the progress download layer*/
305 283
  284 + private IEnumerator videoDownload()
  285 + {
  286 + videoDownloadRunning = true;
  287 + WWW DownloadVideo = new WWW(SERVER_URL + videoId);
  288 + // WWW DownloadVideo = new WWW("http://caiomcg.com/rural.mp4");
  289 + while (!DownloadVideo.isDone)
  290 + {
  291 + screenManager.updateProgressDownloadSprite(DownloadVideo.progress);
  292 + yield return null;
  293 + }
  294 +
  295 + try
  296 + {
  297 + if (DownloadVideo.bytesDownloaded > 0 && DownloadVideo.bytesDownloaded<=videoSize)
  298 + {
  299 + bytes = DownloadVideo.bytesDownloaded;
  300 + videoContent = DownloadVideo.bytes;
  301 + OnDownloadFinished();
  302 + }
  303 + else
  304 + {
  305 + GetConnectionStatusError(ExportLayers.ConnectionStatusError.DOWNLOAD_CONNECTION_FAILURE);
  306 + }
  307 +
  308 +
  309 + }
  310 + finally
  311 + {
  312 + videoDownloadRunning = false;
  313 + }
  314 + }
306 315
307 public IEnumerator WaitForResponse(WWW www, Events.RequestSuccess success, Events.RequestError error) 316 public IEnumerator WaitForResponse(WWW www, Events.RequestSuccess success, Events.RequestError error)
308 { 317 {
@@ -315,7 +324,7 @@ public class ExportVideo : MonoBehaviour { @@ -315,7 +324,7 @@ public class ExportVideo : MonoBehaviour {
315 yield return WaitForResponse(www, null, null); 324 yield return WaitForResponse(www, null, null);
316 } 325 }
317 326
318 - public static void GetConnectionStatusError(ExportLayers.ConnectionStatusError error) 327 + private static void GetConnectionStatusError(ExportLayers.ConnectionStatusError error)
319 { 328 {
320 switch (error) 329 switch (error)
321 { 330 {
Assets/Scripts/Export Video/MediaShareAndroid.cs
@@ -26,19 +26,24 @@ public class MediaShareAndroid : MonoBehaviour @@ -26,19 +26,24 @@ public class MediaShareAndroid : MonoBehaviour
26 26
27 private string MediaType = "video/*"; 27 private string MediaType = "video/*";
28 28
29 - private string SubtitleMessage = "VLibras"; 29 + private string SubtitleMessage = "VLibras na Playstore - https://play.google.com/store/apps/details?id=com.lavid.vlibrasdroid&hl=pt_BR";
30 30
31 - private string AndroidPath = AndroidJavaUti.CurrentSDCardPath; 31 + private string AndroidPath;
32 32
33 private string destination = ""; 33 private string destination = "";
34 - private string Vlibras = "VLibras";  
35 - private string FileName = "VLibrasVideo_"; 34 + private string Vlibras = "DCIM/VLibras";
  35 + private string File = "VLibrasVideo_";
36 36
37 private byte[] videoContent; 37 private byte[] videoContent;
38 private int bytes; 38 private int bytes;
39 39
  40 + private void Awake()
  41 + {
  42 + AndroidPath = AndroidJavaUti.CurrentSDCardPath;
  43 + }
  44 +
40 45
41 - /*Makes sure that Vlibras Folder gets created and write the video bytes in it.*/ 46 + /*Makes sure that Vlibras Folder gets created and write the video bytes in it.*/
42 47
43 /* Creates the sharing activity and shows the chooser to the user*/ 48 /* Creates the sharing activity and shows the chooser to the user*/
44 49
@@ -46,61 +51,31 @@ public class MediaShareAndroid : MonoBehaviour @@ -46,61 +51,31 @@ public class MediaShareAndroid : MonoBehaviour
46 { 51 {
47 52
48 #if UNITY_ANDROID 53 #if UNITY_ANDROID
  54 +
49 this.videoContent = videoContent; 55 this.videoContent = videoContent;
50 this.bytes = bytes; 56 this.bytes = bytes;
51 - FileName += CurrentTime + ".mp4";  
52 - ShareIntent();  
53 - /*  
54 - // Create Refernece of AndroidJavaClass class for intent  
55 - AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");  
56 - // Create Refernece of AndroidJavaObject class intent  
57 - AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");  
58 - // Set action for intent  
59 - intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));  
60 - intentObject.Call<AndroidJavaObject>("setType", MediaType);  
61 - //Set Subject of action  
62 - intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), SubtitleMessage);  
63 - //Set title of action or intent  
64 - intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TITLE"), TitleMessage);  
65 -  
66 - /*  
67 - // Set actual data which you want to share  
68 - intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), Media);  
69 - AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");  
70 - AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");  
71 - // Invoke android activity for passing intent to share data  
72 - currentActivity.Call("startActivity", intentObject);  
73 57
74 58
75 - AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");  
76 -  
77 - AndroidJavaObject fileObject = new AndroidJavaObject("java.io.File", Path.Combine(AndroidPath + Vlibras, FileName));// Set Image Path Here  
78 - AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("fromFile", fileObject);  
79 - // string uriPath = uriObject.Call("getPath");  
80 - bool fileExist = fileObject.Call<bool>("exists");  
81 - Debug.Log("File exist : " + fileExist);  
82 - // Attach image to intent  
83 - if (fileExist)  
84 - intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<AndroidJavaObject>("EXTRA_STREAM"), uriObject);  
85 - AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");  
86 - AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");  
87 - currentActivity.Call("startActivity", intentObject);  
88 -  
89 - */ 59 + StartCoroutine(WriteOnAndroid(File + CurrentTime + ".mp4"));
90 60
91 #endif 61 #endif
92 - } 62 + }
93 63
94 - private void ShareIntent() 64 + private IEnumerator WriteOnAndroid(string FileName)
95 { 65 {
96 destination = Path.Combine(AndroidPath, Vlibras); 66 destination = Path.Combine(AndroidPath, Vlibras);
  67 +
  68 + /* Checking if folder Vlibras exists*/
  69 +
97 DirectoryInfo dir = new DirectoryInfo(destination); 70 DirectoryInfo dir = new DirectoryInfo(destination);
98 - new AndroidToast().showToast(destination);  
99 if (!dir.Exists) 71 if (!dir.Exists)
100 { 72 {
101 dir.Create(); 73 dir.Create();
102 } 74 }
103 75
  76 + /*Checking if there's a file with same name - If so, means user's trying
  77 + * to share the same video*/
  78 +
104 dir = new DirectoryInfo(Path.Combine(destination, FileName)); 79 dir = new DirectoryInfo(Path.Combine(destination, FileName));
105 if (!dir.Exists) 80 if (!dir.Exists)
106 { 81 {
@@ -113,28 +88,56 @@ public class MediaShareAndroid : MonoBehaviour @@ -113,28 +88,56 @@ public class MediaShareAndroid : MonoBehaviour
113 } 88 }
114 else 89 else
115 { 90 {
116 - new AndroidToast().showToast("Erro ao escrever arquivo"); 91 + new AndroidToast().showToast("Erro ao compartilhar arquivo.");
117 } 92 }
118 93
119 } 94 }
120 95
121 - 96 + yield return null;
  97 + Refresh(FileName);
  98 +
  99 +
  100 +
  101 +
  102 + }
  103 +
  104 + private void Refresh(string FileName)
  105 + {
  106 +
  107 + AndroidJavaClass jcUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  108 + AndroidJavaObject joActivity = jcUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
  109 + AndroidJavaObject joContext = joActivity.Call<AndroidJavaObject>("getApplicationContext");
  110 + AndroidJavaClass jcMediaScannerConnection = new AndroidJavaClass("android.media.MediaScannerConnection");
  111 + //AndroidJavaClass jcEnvironment = new AndroidJavaClass("android.os.Environment");
  112 + // AndroidJavaObject joExDir = jcEnvironment.CallStatic<AndroidJavaObject>("getExternalStorageDirectory");
  113 + string path = Path.Combine(destination,FileName);
  114 + jcMediaScannerConnection.CallStatic("scanFile", joContext, new string[] { path }, null, null);
  115 + StartCoroutine(ShareIntent(FileName));
  116 +
  117 + }
  118 +
  119 + private IEnumerator ShareIntent(string FileName) {
  120 +
122 // block to open the file and share it ------------START 121 // block to open the file and share it ------------START
123 AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent"); 122 AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
124 AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent"); 123 AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
125 intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND")); 124 intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
  125 +
126 AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri"); 126 AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
127 AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://" + Path.Combine(destination,FileName)); 127 AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://" + Path.Combine(destination,FileName));
  128 +
128 intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject); 129 intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
129 intentObject.Call<AndroidJavaObject>("setType", MediaType); 130 intentObject.Call<AndroidJavaObject>("setType", MediaType);
  131 +
130 //add data to be passed to the other activity i.e., the data to be sent 132 //add data to be passed to the other activity i.e., the data to be sent
131 - intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), SubtitleMessage);  
132 - intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), "Vlibras Video");  
133 - intentObject.Call<AndroidJavaObject>("setType", "video/mp4"); 133 + intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), "VLibras");
  134 + intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), SubtitleMessage);
  135 + intentObject.Call<AndroidJavaObject>("setType", "video/*");
134 AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 136 AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
135 AndroidJavaObject jChooser = intentClass.CallStatic<AndroidJavaObject>("createChooser", intentObject, "Compartilhar via"); 137 AndroidJavaObject jChooser = intentClass.CallStatic<AndroidJavaObject>("createChooser", intentObject, "Compartilhar via");
136 AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity"); 138 AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
137 - currentActivity.Call("startActivity", jChooser); 139 + currentActivity.Call("startActivity", jChooser);
  140 + yield break;
138 141
139 142
140 } 143 }
ProjectSettings/EditorBuildSettings.asset
@@ -7,5 +7,3 @@ EditorBuildSettings: @@ -7,5 +7,3 @@ EditorBuildSettings:
7 m_Scenes: 7 m_Scenes:
8 - enabled: 1 8 - enabled: 1
9 path: Assets/Scenes/Main.unity 9 path: Assets/Scenes/Main.unity
10 - - enabled: 0  
11 - path: Assets/Plugins/StansAssets/Modules/MobileNativePopUps/Example/MobilePopUpsExample.unity