diff --git a/.gradle/2.10/taskArtifacts/cache.properties b/.gradle/2.10/taskArtifacts/cache.properties new file mode 100644 index 0000000..a909fed --- /dev/null +++ b/.gradle/2.10/taskArtifacts/cache.properties @@ -0,0 +1 @@ +#Wed Jul 20 13:50:13 BRT 2016 diff --git a/.gradle/2.10/taskArtifacts/cache.properties.lock b/.gradle/2.10/taskArtifacts/cache.properties.lock new file mode 100644 index 0000000..b02f0c5 Binary files /dev/null and b/.gradle/2.10/taskArtifacts/cache.properties.lock differ diff --git a/.gradle/2.10/taskArtifacts/fileHashes.bin b/.gradle/2.10/taskArtifacts/fileHashes.bin new file mode 100644 index 0000000..108dff9 Binary files /dev/null and b/.gradle/2.10/taskArtifacts/fileHashes.bin differ diff --git a/.gradle/2.10/taskArtifacts/fileSnapshots.bin b/.gradle/2.10/taskArtifacts/fileSnapshots.bin new file mode 100644 index 0000000..a3791ae Binary files /dev/null and b/.gradle/2.10/taskArtifacts/fileSnapshots.bin differ diff --git a/.gradle/2.10/taskArtifacts/outputFileStates.bin b/.gradle/2.10/taskArtifacts/outputFileStates.bin new file mode 100644 index 0000000..1a63d7e Binary files /dev/null and b/.gradle/2.10/taskArtifacts/outputFileStates.bin differ diff --git a/.gradle/2.10/taskArtifacts/taskArtifacts.bin b/.gradle/2.10/taskArtifacts/taskArtifacts.bin new file mode 100644 index 0000000..2d4e476 Binary files /dev/null and b/.gradle/2.10/taskArtifacts/taskArtifacts.bin differ diff --git a/.gradle/2.10/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin b/.gradle/2.10/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin new file mode 100644 index 0000000..b02dc8d Binary files /dev/null and b/.gradle/2.10/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin differ diff --git a/.gradle/2.10/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock b/.gradle/2.10/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock new file mode 100644 index 0000000..9f4014c Binary files /dev/null and b/.gradle/2.10/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock differ diff --git a/.gradle/2.10/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin b/.gradle/2.10/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin new file mode 100644 index 0000000..bf9398c Binary files /dev/null and b/.gradle/2.10/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin differ diff --git a/.gradle/2.10/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock b/.gradle/2.10/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock new file mode 100644 index 0000000..d4b6657 Binary files /dev/null and b/.gradle/2.10/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock differ diff --git a/.gradle/2.10/tasks/_app_compileDebugUnitTestJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin b/.gradle/2.10/tasks/_app_compileDebugUnitTestJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin new file mode 100644 index 0000000..444563b Binary files /dev/null and b/.gradle/2.10/tasks/_app_compileDebugUnitTestJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin differ diff --git a/.gradle/2.10/tasks/_app_compileDebugUnitTestJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock b/.gradle/2.10/tasks/_app_compileDebugUnitTestJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock new file mode 100644 index 0000000..46aea40 Binary files /dev/null and b/.gradle/2.10/tasks/_app_compileDebugUnitTestJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock differ diff --git a/.gradle/2.10/tasks/_app_compileDebugUnitTestJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin b/.gradle/2.10/tasks/_app_compileDebugUnitTestJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin new file mode 100644 index 0000000..a7b1b8f Binary files /dev/null and b/.gradle/2.10/tasks/_app_compileDebugUnitTestJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin differ diff --git a/.gradle/2.10/tasks/_app_compileDebugUnitTestJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock b/.gradle/2.10/tasks/_app_compileDebugUnitTestJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock new file mode 100644 index 0000000..bd43394 Binary files /dev/null and b/.gradle/2.10/tasks/_app_compileDebugUnitTestJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock differ diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..5a21c91 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +cine \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..508b3d9 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,23 @@ + + + + + + \ No newline at end of file diff --git a/.idea/libraries/animated_vector_drawable_24_0_0.xml b/.idea/libraries/animated_vector_drawable_24_0_0.xml new file mode 100644 index 0000000..7c5138b --- /dev/null +++ b/.idea/libraries/animated_vector_drawable_24_0_0.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/appcompat_v7_24_0_0.xml b/.idea/libraries/appcompat_v7_24_0_0.xml new file mode 100644 index 0000000..3181dd9 --- /dev/null +++ b/.idea/libraries/appcompat_v7_24_0_0.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/design_24_0_0.xml b/.idea/libraries/design_24_0_0.xml new file mode 100644 index 0000000..1342c13 --- /dev/null +++ b/.idea/libraries/design_24_0_0.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/hamcrest_core_1_3.xml b/.idea/libraries/hamcrest_core_1_3.xml new file mode 100644 index 0000000..157e3f3 --- /dev/null +++ b/.idea/libraries/hamcrest_core_1_3.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/junit_4_12.xml b/.idea/libraries/junit_4_12.xml new file mode 100644 index 0000000..305df30 --- /dev/null +++ b/.idea/libraries/junit_4_12.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/multidex_1_0_1.xml b/.idea/libraries/multidex_1_0_1.xml new file mode 100644 index 0000000..4cb33d0 --- /dev/null +++ b/.idea/libraries/multidex_1_0_1.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/multidex_instrumentation_1_0_1.xml b/.idea/libraries/multidex_instrumentation_1_0_1.xml new file mode 100644 index 0000000..0ff7497 --- /dev/null +++ b/.idea/libraries/multidex_instrumentation_1_0_1.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/play_services_base_9_2_1.xml b/.idea/libraries/play_services_base_9_2_1.xml new file mode 100644 index 0000000..f21c6d7 --- /dev/null +++ b/.idea/libraries/play_services_base_9_2_1.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/play_services_basement_9_2_1.xml b/.idea/libraries/play_services_basement_9_2_1.xml new file mode 100644 index 0000000..6cd70ad --- /dev/null +++ b/.idea/libraries/play_services_basement_9_2_1.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/play_services_tasks_9_2_1.xml b/.idea/libraries/play_services_tasks_9_2_1.xml new file mode 100644 index 0000000..24205cd --- /dev/null +++ b/.idea/libraries/play_services_tasks_9_2_1.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/play_services_vision_9_2_1.xml b/.idea/libraries/play_services_vision_9_2_1.xml new file mode 100644 index 0000000..532c3a2 --- /dev/null +++ b/.idea/libraries/play_services_vision_9_2_1.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/recyclerview_v7_24_0_0.xml b/.idea/libraries/recyclerview_v7_24_0_0.xml new file mode 100644 index 0000000..97c1487 --- /dev/null +++ b/.idea/libraries/recyclerview_v7_24_0_0.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_annotations_24_0_0.xml b/.idea/libraries/support_annotations_24_0_0.xml new file mode 100644 index 0000000..17f57c1 --- /dev/null +++ b/.idea/libraries/support_annotations_24_0_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_v4_24_0_0.xml b/.idea/libraries/support_v4_24_0_0.xml new file mode 100644 index 0000000..5c6ecb1 --- /dev/null +++ b/.idea/libraries/support_v4_24_0_0.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_vector_drawable_24_0_0.xml b/.idea/libraries/support_vector_drawable_24_0_0.xml new file mode 100644 index 0000000..f3d609e --- /dev/null +++ b/.idea/libraries/support_vector_drawable_24_0_0.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/volley_1_0_0.xml b/.idea/libraries/volley_1_0_0.xml new file mode 100644 index 0000000..8e317b7 --- /dev/null +++ b/.idea/libraries/volley_1_0_0.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..cca2cda --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..89b005f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..c3aeb63 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,2949 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1469032158865 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/app-release.apk b/app/app-release.apk new file mode 100644 index 0000000..b1e77fa Binary files /dev/null and b/app/app-release.apk differ diff --git a/app/app.iml b/app/app.iml new file mode 100644 index 0000000..1da3a68 --- /dev/null +++ b/app/app.iml @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..61d237e --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,52 @@ +apply plugin: 'com.android.application' + +def keystorePropertiesFile = rootProject.file("keystore.properties") +def keystoreProperties = new Properties() + +keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) + +android { + compileSdkVersion 24 + buildToolsVersion "24.0.0" + + signingConfigs { + config { + keyAlias 'CineAcessoKey' + keyPassword 'l4v1d-l1v3' + storeFile file('C:/Users/Cinema_2/Desktop/Ademir/cineacesso/cine/cineacesso_key.jks') + storePassword 'l4v1d-l1v3' + } + } + + defaultConfig { + applicationId "lavid.com.cineacesso" + minSdkVersion 16 + targetSdkVersion 24 + versionCode 3 + versionName "1.2" + multiDexEnabled true + jackOptions.enabled = true + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + buildTypes { + release { + minifyEnabled false + shrinkResources true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + signingConfig signingConfigs.config + } + } +} + +dependencies { + compile fileTree(include: ['*.jar'], dir: 'libs') + testCompile 'junit:junit:4.12' + compile 'com.android.support:multidex:1.0.1' + compile 'com.android.support:appcompat-v7:24.0.0' + compile 'com.android.support:design:24.0.0' + compile 'com.google.android.gms:play-services-vision:9.2.1' + compile 'com.android.volley:volley:1.0.0' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..fd9ff95 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,20 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\Ademir\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} +-keep class com.android.volley.** {*;} +-keep class com.android.** +-dontshrink diff --git a/app/src/androidTest/java/lavid/com/cineacesso/ApplicationTest.java b/app/src/androidTest/java/lavid/com/cineacesso/ApplicationTest.java new file mode 100644 index 0000000..e54e271 --- /dev/null +++ b/app/src/androidTest/java/lavid/com/cineacesso/ApplicationTest.java @@ -0,0 +1,13 @@ +package lavid.com.cineacesso; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..f823cc0 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png new file mode 100644 index 0000000..8ff1c6b Binary files /dev/null and b/app/src/main/ic_launcher-web.png differ diff --git a/app/src/main/java/lavid/com/cineacesso/activities/AuxTypeActivity.java b/app/src/main/java/lavid/com/cineacesso/activities/AuxTypeActivity.java new file mode 100644 index 0000000..3585086 --- /dev/null +++ b/app/src/main/java/lavid/com/cineacesso/activities/AuxTypeActivity.java @@ -0,0 +1,178 @@ +package lavid.com.cineacesso.activities; + +import android.app.ProgressDialog; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.net.ConnectivityManager; +import android.os.Bundle; +import android.os.Handler; +import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.widget.Toast; + +import lavid.com.cineacesso.R; +import lavid.com.cineacesso.utils.CineAcessoAPI; +import lavid.com.cineacesso.utils.CineAcessoDB; +import lavid.com.cineacesso.utils.NetworkReceiver; +import lavid.com.cineacesso.utils.RetainedSession; + + +public class AuxTypeActivity extends AppCompatActivity implements View.OnClickListener{ + + //private static final String TAG = AuxTypeActivity.class.getSimpleName(); + + private ProgressDialog mProgressDialog; + private AlertDialog alertDialog; + private String auxType; + + private NetworkReceiver receiver = new NetworkReceiver(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_aux_type); + + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + assert getSupportActionBar() != null; + getSupportActionBar().setDisplayShowTitleEnabled(false); + + alertDialog = new AlertDialog.Builder(this) + .setTitle(getString(R.string.wait)) + .setMessage(getString(R.string.content_unavaliable)) + .setPositiveButton(getString(R.string.ok), (dialogInterface, view) -> dialogInterface.dismiss()) + .create(); + + startTimedLoading(getString(R.string.checking_connection), 3000); + if (!WifiActivity.isValidSSID(this)) { + if (mProgressDialog.isShowing()) { + mProgressDialog.dismiss(); + } + startActivity(new Intent(this, WifiActivity.class)); + } + + IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); + receiver = new NetworkReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + super.onReceive(context, intent); + if (!WifiActivity.isValidSSID(AuxTypeActivity.this)) { + startActivity(new Intent(AuxTypeActivity.this, WifiActivity.class)); + } + } + }; + this.registerReceiver(receiver, filter); + + } + + @Override + protected void onResume() { + super.onResume(); + if (!WifiActivity.isValidSSID(this)) { + startActivity(new Intent(this, WifiActivity.class)); + } + } + + @Override + protected void onDestroy() { + super.onDestroy(); + if (alertDialog != null) { + alertDialog.dismiss(); + } + if (receiver != null) { + this.unregisterReceiver(receiver); + } + } + + @Override + public void onClick(View v) { + + Intent intent = new Intent(this, ContentActivity.class); + + switch (v.getId()) { + + case R.id.btn_libras: + intent.putExtra(CineAcessoDB.CONTENT_TYPE, CineAcessoDB.CONTENT_TYPE_LIBRAS); + auxType = CineAcessoDB.CONTENT_TYPE_LIBRAS; + break; + + case R.id.btn_libras_subtitle: + Toast.makeText(this, getString(R.string.soon), Toast.LENGTH_SHORT).show(); + return; + //intent.putExtra(CineAcessoDB.CONTENT_TYPE, CineAcessoDB.CONTENT_TYPE_LIBRAS_SUB); + //break; + + case R.id.btn_subtitle: + Toast.makeText(this, getString(R.string.soon), Toast.LENGTH_SHORT).show(); + return; + //intent.putExtra(CineAcessoDB.CONTENT_TYPE, CineAcessoDB.CONTENT_TYPE_SUBS); + //break; + + case R.id.btn_audio: + intent.putExtra(CineAcessoDB.CONTENT_TYPE, CineAcessoDB.CONTENT_TYPE_AUDIO); + auxType = CineAcessoDB.CONTENT_TYPE_AUDIO; + break; + } + + startLoading(); + CineAcessoAPI.getServerInfo(this, auxType, (success, map) -> { + + if (!success) { + if (!alertDialog.isShowing() && !isFinishing()) { + alertDialog.show(); + } + } + else { + /*Log.d(TAG, "SERVER_UID = " + map.get(CineAcessoDB.SERVER_UID) + + "\nSERVER_CONTENT = " + map.get(CineAcessoDB.CONTENT) + + "\nSERVER_PTS = " + map.get(CineAcessoDB.PTS) + + "\nSERVER_TITLE = " + map.get(CineAcessoDB.CONTENT_TITLE) + + "\nSERVER_YEAR = " + map.get(CineAcessoDB.CONTENT_YEAR) + + "\nSERVER_AUTHOR = " + map.get(CineAcessoDB.CONTENT_AUTHOR) + + "\nSERVER_IMAGE = " + map.get(CineAcessoDB.CONTENT_IMG));*/ + + String serverUid = map.get(CineAcessoDB.SERVER_UID); + String contentUrl = CineAcessoDB.BASE_URL + map.get(CineAcessoDB.CONTENT); + String imageUrl = CineAcessoDB.BASE_URL + map.get(CineAcessoDB.CONTENT_IMG); + String author = map.get(CineAcessoDB.CONTENT_AUTHOR); + String title = map.get(CineAcessoDB.CONTENT_TITLE) + " (" + map.get(CineAcessoDB.CONTENT_YEAR) + ")"; + + RetainedSession.put(this, CineAcessoDB.CONTENT_TYPE, auxType); + RetainedSession.put(this, CineAcessoDB.SERVER_UID, serverUid); + RetainedSession.put(this, CineAcessoDB.CONTENT_URL, contentUrl); + RetainedSession.put(this, CineAcessoDB.CONTENT_IMG_URL, imageUrl); + RetainedSession.put(this, CineAcessoDB.CONTENT_AUTHOR, author); + RetainedSession.put(this, CineAcessoDB.CONTENT_TITLE, title); + + startActivity(intent); + } + + endLoading(); + }); + } + + private void startLoading() { + mProgressDialog = new ProgressDialog(this); + mProgressDialog.setTitle(getString(R.string.loading)); + mProgressDialog.setCancelable(false); + mProgressDialog.show(); + } + + private void startTimedLoading(String message, long millis) { + mProgressDialog = new ProgressDialog(this); + mProgressDialog.setTitle(getString(R.string.loading)); + mProgressDialog.setCancelable(false); + if (message != null) mProgressDialog.setMessage(message); + mProgressDialog.show(); + new Handler().postDelayed(() -> mProgressDialog.dismiss(), millis); + } + + private void endLoading() { + if (mProgressDialog != null) { + mProgressDialog.cancel(); + } + } +} diff --git a/app/src/main/java/lavid/com/cineacesso/activities/ContentActivity.java b/app/src/main/java/lavid/com/cineacesso/activities/ContentActivity.java new file mode 100644 index 0000000..b3bbd77 --- /dev/null +++ b/app/src/main/java/lavid/com/cineacesso/activities/ContentActivity.java @@ -0,0 +1,90 @@ +package lavid.com.cineacesso.activities; + +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.net.ConnectivityManager; +import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.widget.TextView; + +import com.android.volley.toolbox.NetworkImageView; + +import lavid.com.cineacesso.R; +import lavid.com.cineacesso.utils.CineAcessoDB; +import lavid.com.cineacesso.utils.NetworkReceiver; +import lavid.com.cineacesso.utils.RetainedSession; +import lavid.com.cineacesso.utils.VolleySingleton; + + +public class ContentActivity extends AppCompatActivity { + + private NetworkReceiver receiver = new NetworkReceiver(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_content); + + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + assert getSupportActionBar() != null; + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowTitleEnabled(false); + //toolbar.setNavigationOnClickListener((view -> finish())); + + FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); + assert fab != null; + fab.setOnClickListener(view -> { + startActivity(new Intent(ContentActivity.this, PlayerActivity.class)); + finish(); + }); + + //image + NetworkImageView ivImage = (NetworkImageView) findViewById(R.id.iv_content_image); + ivImage.setDefaultImageResId(R.drawable.content_image_default); + ivImage.setErrorImageResId(R.drawable.content_image_default); + ivImage.setImageUrl(RetainedSession.get(this, CineAcessoDB.CONTENT_IMG_URL), + VolleySingleton.getInstance(this).getImageLoader()); + + //content + TextView tvAuxType = (TextView) findViewById(R.id.tv_aux_type); + assert tvAuxType != null; + String resourceName = getIntent().getStringExtra(CineAcessoDB.CONTENT_TYPE); + int resourceId = getResources().getIdentifier(resourceName, "string", getPackageName()); + tvAuxType.setText(getString(resourceId)); + + //title + TextView textView = (TextView) findViewById(R.id.tv_content_title); + textView.setText(RetainedSession.get(this, CineAcessoDB.CONTENT_TITLE)); + + //author + String text = getString(R.string.direction) + ": " + RetainedSession.get(this, CineAcessoDB.CONTENT_AUTHOR); + textView = (TextView) findViewById(R.id.tv_content_subtitle1); + textView.setText(text); + + IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); + receiver = new NetworkReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + super.onReceive(context, intent); + if (!WifiActivity.isValidSSID(ContentActivity.this)) { + finish(); + startActivity(new Intent(ContentActivity.this, WifiActivity.class)); + } + } + }; + this.registerReceiver(receiver, filter); + + } + + @Override + protected void onDestroy() { + super.onDestroy(); + if (receiver != null) { + unregisterReceiver(receiver); + } + } +} diff --git a/app/src/main/java/lavid/com/cineacesso/activities/PlayerActivity.java b/app/src/main/java/lavid/com/cineacesso/activities/PlayerActivity.java new file mode 100644 index 0000000..cd6f981 --- /dev/null +++ b/app/src/main/java/lavid/com/cineacesso/activities/PlayerActivity.java @@ -0,0 +1,410 @@ +package lavid.com.cineacesso.activities; + +import android.app.AlertDialog; +import android.app.ProgressDialog; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.ServiceConnection; +import android.media.MediaPlayer; +import android.net.ConnectivityManager; +import android.os.Bundle; +import android.os.Handler; +import android.os.IBinder; +import android.os.Message; +import android.support.v7.app.AppCompatActivity; +import android.view.GestureDetector; +import android.view.MotionEvent; +import android.view.SurfaceHolder; +import android.view.SurfaceView; +import android.view.View; +import android.widget.Toast; + +import java.io.IOException; + +import lavid.com.cineacesso.R; +import lavid.com.cineacesso.player.CineAcessoPlayer; +import lavid.com.cineacesso.player.CineAcessoPlayerSynchronizer; +import lavid.com.cineacesso.utils.CineAcessoDB; +import lavid.com.cineacesso.utils.NetworkReceiver; +import lavid.com.cineacesso.utils.RetainedSession; + + +public class PlayerActivity extends AppCompatActivity implements + SurfaceHolder.Callback, + MediaPlayer.OnPreparedListener, + CineAcessoPlayerSynchronizer.OnMessageReceivedListener, + CineAcessoPlayer.OnAudioBecomingNoisyListener { + + //private static final String TAG = PlayerActivity.class.getSimpleName(); + private static final String START = "START"; + private static final String STOP = "STOP"; + private static final String SYNC = "SYNC"; + + private CineAcessoPlayer mPlayer; + private CineAcessoPlayerSynchronizer mSynchronizer; + //private CineAcessoPlayerService mService; + + private NetworkReceiver receiver = new NetworkReceiver(); + + private boolean mBound; + + private AlertDialog alertDialog; + + private boolean startReceived; + private boolean playerPrepared; + + private long startTime; + + private View mDecorView; + private Handler mHideSystemUiHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + hideSystemUI(); + } + }; + + private ServiceConnection mConnection = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName componentName, IBinder iBinder) { + //CineAcessoPlayerService.LocalBinder binder = (CineAcessoPlayerService.LocalBinder) iBinder; + //mService = binder.getService(); + mBound = true; + } + + @Override + public void onServiceDisconnected(ComponentName componentName) { + mBound = false; + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_player); + + //Log.d(TAG, "onCreate()"); + + final GestureDetector clickDetector = new GestureDetector(this, + new GestureDetector.SimpleOnGestureListener() { + @Override + public boolean onSingleTapUp(MotionEvent e) { + boolean visible = (mDecorView.getSystemUiVisibility() + & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; + if (visible) { + hideSystemUI(); + } else { + showSystemUI(); + } + return true; + } + }); + + mDecorView = getWindow().getDecorView(); + mDecorView.setOnTouchListener((view, motionEvent) -> clickDetector.onTouchEvent(motionEvent)); +// { +// mDecorView.setOnSystemUiVisibilityChangeListener(flags -> { +// boolean visible = (flags & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; +// if (controller != null) { +// if (visible && !PlayerActivity.this.isFinishing()) { +// controller.show(); +// } else { +// controller.hide(); +// } +// } +// }); +// } + + SurfaceView surface = (SurfaceView) findViewById(R.id.video_surface); + assert surface != null; + surface.getHolder().addCallback(this); + + IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); + receiver = new NetworkReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + super.onReceive(context, intent); + if (!WifiActivity.isValidSSID(PlayerActivity.this)) { + finish(); + startActivity(new Intent(PlayerActivity.this, WifiActivity.class)); + } + } + }; + this.registerReceiver(receiver, filter); + + } + + @Override + protected void onResume() { + super.onResume(); + //Log.d(TAG, "onResume()"); + mPlayer = CineAcessoPlayer.getInstance(this); + mPlayer.setOnAudioBecomingNoisyListener(this); + mPlayer.setContentType(RetainedSession.get(this, CineAcessoDB.CONTENT_TYPE)); + mPlayer.setOnCompletionListener(mp -> { + finish(); + mSynchronizer.finish(); + }); + mPlayer.setOnPreparedListener(this); + //mPlayer.setOnVideoSizeChangedListener(this); + + if (mSynchronizer == null) { + //Log.d(TAG, "NEW INSTANCE SYNCHRONIZER"); + mSynchronizer = new CineAcessoPlayerSynchronizer(RetainedSession.get(this, CineAcessoDB.SERVER_UID)); + mSynchronizer.setOnMessageReceivedListener(this); + mSynchronizer.start(); + } + } + + @Override + protected void onStop() { + super.onStop(); + //Log.d(TAG, "onStop()"); + if (alertDialog != null) { + alertDialog.dismiss(); + } + mPlayer.release(); + mSynchronizer.finish(); + finish(); +// if (!mPlayer.getContentType().equals(CineAcessoDB.CONTENT_TYPE_AUDIO)) { +// mPlayer.release(); +// mSynchronizer.finish(); +// finish(); +// } +// else { +// NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) +// .setSmallIcon(R.mipmap.ic_launcher) +// .setContentTitle(getString(R.string.app_name)) +// .setContentText(RetainedSession.get(this, CineAcessoDB.CONTENT_TITLE)); +// +// Intent resultIntent = new Intent(this, PlayerActivity.class); +// PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); +// +// mBuilder.setContentIntent(pendingIntent); +// +// NotificationManager mNotfManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); +// mNotfManager.notify(NOTIFICATION_ID, mBuilder.build()); +// } + } + + @Override + protected void onDestroy() { + super.onDestroy(); + //Log.d(TAG, "onDestroy()"); + + if (alertDialog != null) { + alertDialog.dismiss(); + } + + if (!isChangingConfigurations() /*|| !mPlayer.getContentType().equals(CineAcessoDB.CONTENT_TYPE_AUDIO)*/) { + mPlayer.release(); + mSynchronizer.finish(); + } + + if(mBound) { + unbindService(mConnection); + } + if (receiver != null) { + unregisterReceiver(receiver); + } + } + + @Override + public void onWindowFocusChanged(boolean hasFocus) { + super.onWindowFocusChanged(hasFocus); + //Log.d(TAG, "onWindowFocusChanged()"); + if (hasFocus) { + delayedHide(0); + } else { + mHideSystemUiHandler.removeMessages(0); + } + } + + @Override + public void surfaceCreated(SurfaceHolder holder) { + //Log.d(TAG, "surfaceCreated()"); + String url = RetainedSession.get(this, CineAcessoDB.CONTENT_URL); + //Log.d(TAG, "CONTENT URL = " + url); + try { + mPlayer.setup(holder, url); + mPlayer.prepareAsync(); +// if (mPlayer.getContentType().equals(CineAcessoDB.CONTENT_TYPE_AUDIO)) { +// Intent intent = new Intent(this, CineAcessoPlayerService.class); +// bindService(intent, mConnection, Context.BIND_AUTO_CREATE); +// } + } catch (IOException ioe) { + ioe.printStackTrace(); + startActivity(new Intent(this, AuxTypeActivity.class)); + finish(); + Toast.makeText(this, getString(R.string.player_setup_error), Toast.LENGTH_LONG).show(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + @Override + public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { + //Log.d(TAG, "surfaceChanged(): format = " + format + " width = " + width + " height = " + height); + } + + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + //Log.d(TAG, "surfaceDestroyed()"); + } + +// @Override +// public void onVideoSizeChanged(MediaPlayer mediaPlayer, int videoWidth, int videoHeight) { +// if (mediaPlayer != null) { +// DisplayMetrics metrics = new DisplayMetrics(); +// getWindowManager().getDefaultDisplay().getMetrics(metrics); +// +// int screenHeight = metrics.heightPixels; +// int screenWidth = metrics.widthPixels; +// +// ViewGroup.LayoutParams params = surface.getLayoutParams(); +// +// if (videoWidth > videoHeight) { +// params.width = screenWidth; +// params.height = screenWidth * videoHeight / videoWidth; +// } +// else { +// params.width = screenHeight * videoWidth / videoHeight; +// params.height = screenHeight; +// } +// +// surface.setLayoutParams(params); +// } +// Log.d(TAG, "onVideoSizeChanged(): width = " + videoWidth + " height = " + videoHeight); +// } + + @Override + public void onPrepared(MediaPlayer mp) { + playerPrepared = true; + mPlayer.acquireWifiLock(); + if (startReceived) { + long time_buffering = System.currentTimeMillis() - startTime; + mPlayer.start(parseInt(time_buffering)); + } + else { + alertDialog = new ProgressDialog.Builder(this) + .setTitle(getString(R.string.wait_start_title)) + .setMessage(getString(R.string.wait_start_message)) + .setCancelable(true) + .setIcon(R.mipmap.ic_launcher) + .create(); + alertDialog.show(); + + } + + //Log.d(TAG, "prepared()"); + } + + private void showSystemUI() { + mDecorView.setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + ); + } + + private void hideSystemUI() { + mDecorView.setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_FULLSCREEN + ); + } + + private void delayedHide(int delayMillis) { + mHideSystemUiHandler.removeMessages(0); + mHideSystemUiHandler.sendEmptyMessageDelayed(0, delayMillis); + } + + @Override + public void onMessageReceived(String type, long pts) { + + //Log.d(TAG, "[INFO] message " + type + " received"); + + switch (type) { + case START: + startTime = System.currentTimeMillis() + startTime; + if (alertDialog.isShowing()) { + alertDialog.dismiss(); + } + startMedia(); + break; + + case STOP: + stopMedia(); + startActivity(new Intent(this, AuxTypeActivity.class)); + finish(); + break; + + case SYNC: + try { + if (alertDialog != null && alertDialog.isShowing()) { + alertDialog.dismiss(); + } + if (mPlayer.isPlaying()) { + try { + mPlayer.adjustPlayback((int) pts); + } catch (InterruptedException e) { + Toast.makeText(this, getString(R.string.error_occured), Toast.LENGTH_LONG).show(); + finish(); + } + } + else if (!startReceived){ + startTime = System.currentTimeMillis() - pts; + try { + startMedia(parseInt(pts)); + } catch (IllegalArgumentException e) { + finish(); + } + } + } + catch(IllegalStateException ise) { + ise.printStackTrace(); + finish(); + } + break; + } + + } + + private void startMedia() { + if (playerPrepared) { + startReceived = true; + mPlayer.start(); + } + } + + private void startMedia(int offset) { + if (playerPrepared) { + startReceived = true; + mPlayer.start(offset); + } + } + + private void stopMedia() { + mPlayer.release(); + mSynchronizer.finish(); + } + + private int parseInt(long value) { + if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { + throw new IllegalArgumentException("[" + value + "] Cannot be cast to int without changing its value."); + } + return (int) value; + } + + @Override + public void onAudioBecomingNoisy() { + finish(); + } +} + + diff --git a/app/src/main/java/lavid/com/cineacesso/activities/SplashActivity.java b/app/src/main/java/lavid/com/cineacesso/activities/SplashActivity.java new file mode 100644 index 0000000..c8b03fd --- /dev/null +++ b/app/src/main/java/lavid/com/cineacesso/activities/SplashActivity.java @@ -0,0 +1,22 @@ +package lavid.com.cineacesso.activities; + +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.support.v7.app.AppCompatActivity; + + +public class SplashActivity extends AppCompatActivity { + + private static final long SPLASH_VISIBLE_TIME = 2000; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + new Handler().postDelayed(() -> { + startActivity(new Intent(this, AuxTypeActivity.class)); + finish(); + }, SPLASH_VISIBLE_TIME); + } + +} diff --git a/app/src/main/java/lavid/com/cineacesso/activities/WifiActivity.java b/app/src/main/java/lavid/com/cineacesso/activities/WifiActivity.java new file mode 100644 index 0000000..bcf637a --- /dev/null +++ b/app/src/main/java/lavid/com/cineacesso/activities/WifiActivity.java @@ -0,0 +1,110 @@ +package lavid.com.cineacesso.activities; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.net.ConnectivityManager; +import android.net.wifi.WifiManager; +import android.os.Bundle; +import android.provider.Settings; +import android.support.design.widget.FloatingActionButton; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.widget.TextView; + +import java.util.concurrent.ScheduledExecutorService; + +import lavid.com.cineacesso.R; +import lavid.com.cineacesso.utils.CineAcessoDB; +import lavid.com.cineacesso.utils.NetworkReceiver; + + +public class WifiActivity extends AppCompatActivity { + + //private static final String TAG = WifiActivity.class.getSimpleName(); + + private ScheduledExecutorService scheduler; + private NetworkReceiver receiver = new NetworkReceiver(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_wifi); + + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + assert getSupportActionBar() != null; + getSupportActionBar().setDisplayShowTitleEnabled(false); + + TextView tvSSID = (TextView) findViewById(R.id.tv_ssid); + tvSSID.setText(CineAcessoDB.NETWORK_SSID); + + FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab_wifi); + assert fab != null; + fab.setOnClickListener(view -> startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS))); + + IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); + receiver = new NetworkReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + super.onReceive(context, intent); + if (isValidSSID(WifiActivity.this)) { + finish(); + } + } + }; + this.registerReceiver(receiver, filter); + } + + @Override + protected void onResume() { + super.onResume(); + if (isValidSSID(this)) { + finish(); + } + } + + @Override + protected void onPause() { + super.onPause(); + //Log.d(TAG, "onPause()"); + +// if (scheduler == null) { +// scheduler = Executors.newScheduledThreadPool(1); +// +// Runnable ssidValidator = () -> { +// if (isValidSSID(this)) { +// scheduler.shutdown(); +// finish(); +// } +// }; +// +// scheduler.scheduleAtFixedRate(ssidValidator, 0, 2000, TimeUnit.MILLISECONDS); +// } + } + + @Override + protected void onDestroy() { + super.onDestroy(); + //Log.d(TAG, "onDestroy()"); +// try { +// scheduler.shutdown(); +// } catch (NullPointerException npe) { +// npe.printStackTrace(); +// } + if (receiver != null) { + this.unregisterReceiver(receiver); + } + } + + public static boolean isValidSSID(Context ctx) { + + WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); + //Log.d(TAG, "THREAD: " + Thread.currentThread().getId()); + //Log.d(TAG, "NETWORK_SSID: " + wifiManager.getConnectionInfo().getSSID()); + //Log.d(TAG, "INTENT_SSID: " + ssid); + return wifiManager.isWifiEnabled() && wifiManager.getConnectionInfo().getSSID().contains(CineAcessoDB.NETWORK_SSID); + } + +} diff --git a/app/src/main/java/lavid/com/cineacesso/player/CineAcessoPlayer.java b/app/src/main/java/lavid/com/cineacesso/player/CineAcessoPlayer.java new file mode 100644 index 0000000..7f40528 --- /dev/null +++ b/app/src/main/java/lavid/com/cineacesso/player/CineAcessoPlayer.java @@ -0,0 +1,243 @@ +package lavid.com.cineacesso.player; + +import android.content.Context; +import android.media.AudioManager; +import android.media.MediaPlayer; +import android.net.wifi.WifiManager; +import android.os.PowerManager; +import android.util.Log; +import android.view.SurfaceHolder; + +import java.io.IOException; +import java.util.Timer; +import java.util.TimerTask; + + +public class CineAcessoPlayer extends MediaPlayer implements + MediaPlayer.OnErrorListener, + AudioManager.OnAudioFocusChangeListener { + + private static final String TAG = CineAcessoPlayer.class.getSimpleName(); + + private static final int VIDEO_FPS_SYNC_TARGET = 200; + + private boolean synchd = false; + private long startTimeSynchd; + + private OnAudioBecomingNoisyListener onAudioBecomingNoisyListener; + + private static CineAcessoPlayer instance; + private String contentType = ""; + + //private Context context; + private WifiManager.WifiLock wifiLock; + + private class ResumePlayerTask extends TimerTask { + @Override + public void run() { + start(); + } + } + + private Timer currentTimer; + + private CineAcessoPlayer(Context context) { + //this.context = context; + this.wifiLock = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)) + .createWifiLock(WifiManager.WIFI_MODE_FULL, "cineAcessoPlayerLock"); + + setOnErrorListener(this); + +// if (!(contentType = RetainedSession.get(context, CineAcessoDB.AUX_TYPE)) +// .equals(CineAcessoDB.CONTENT_TYPE_AUDIO)) { +// +// setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK); +// setScreenOnWhilePlaying(true); +// } +// else { +// setAudioStreamType(AudioManager.STREAM_MUSIC); +// } + setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK); + setAudioStreamType(AudioManager.STREAM_MUSIC); + } + + public static synchronized CineAcessoPlayer getInstance(Context context) { + if (instance == null) { + instance = new CineAcessoPlayer(context.getApplicationContext()); + } + return instance; + } + + public static synchronized CineAcessoPlayer getInstance() { + return instance; + } + + public void setContentType(String contentType) { + this.contentType = contentType; + } + + public String getContentType() { + return this.contentType; + } + + public void setup(SurfaceHolder sh, String url) throws IOException, IllegalStateException { + try { + setDisplay(sh); + setDataSource(url); + setScreenOnWhilePlaying(true); + } + catch (IllegalStateException e) { + e.printStackTrace(); + //Log.d(TAG, "URL: " + url); + } + } + + public void acquireWifiLock() { + if (wifiLock != null && !wifiLock.isHeld()) { + wifiLock.acquire(); + } + //Log.d(TAG, "prepared()"); + } + + @Override + public void start() throws IllegalStateException { + if (wifiLock != null && !wifiLock.isHeld()) { + wifiLock.acquire(); + } + super.start(); + //Log.d(TAG, "start()"); + } + + public void start(int offset) { + if (wifiLock != null && !wifiLock.isHeld()) { + wifiLock.acquire(); + } + if (offset > 0) { + seekTo(offset + VIDEO_FPS_SYNC_TARGET); + } + super.start(); + //Log.d(TAG, "start()"); + } + + @Override + public void stop() throws IllegalStateException { + + if (wifiLock != null && wifiLock.isHeld()) { + wifiLock.release(); + super.stop(); + } + //Log.d(TAG, "stop()"); + } + + @Override + public void release() { + if (currentTimer != null) { + currentTimer.cancel(); + } + //Log.d(TAG, "RELEASING PLAYER"); + if (instance != null) { + super.release(); + if (wifiLock != null && wifiLock.isHeld()) { + wifiLock.release(); + } + instance = null; + //Log.d(TAG, "release()"); + } + } + + @Override + public boolean onError(MediaPlayer mp, int what, int extra) { + //TODO + // ... react appropriately ... + // The MediaPlayer has moved to the Error state, must be reset! + return false; + } + + //todo use +// private boolean requestAudioFocus() { +// AudioManager audioManager = ( AudioManager ) context.getSystemService(Context.AUDIO_SERVICE); +// int result = audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); +// +// if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { +// Log.i(TAG, "AUDIOFOCUS_REQUEST_GRANTED"); +// return true; +// } +// else { +// Log.i(TAG, "AUDIOFOCUS_REQUEST_FAILED"); +// return false; +// } +// } + + @Override + public void onAudioFocusChange(int focusChange) { + + switch (focusChange) { + case AudioManager.AUDIOFOCUS_GAIN: + // resume playback + //TODO + //Log.d(TAG, "AUDIOFOCUS_GAIN"); + break; + + case AudioManager.AUDIOFOCUS_LOSS: + if (isPlaying()) release(); + //Log.d(TAG, "AUDIOFOCUS_LOSS"); + break; + + case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT: + if (isPlaying()) stop(); + //Log.d(TAG, "AUDIOFOCUS_GAIN_TRANSIENT"); + break; + + case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: + if (isPlaying()) setVolume(0.1f, 0.1f); + //Log.d(TAG, "AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK"); + break; + } + + } + + public void adjustPlayback(int ptsServer) throws InterruptedException { + + int playerCurrentTime = getCurrentPosition(); + + if (!synchd) { + Log.d(TAG, "PLAYER TIME : " + playerCurrentTime + + " SERVER TIME: " + ptsServer); + long driftTime; + if ( (ptsServer - playerCurrentTime) > VIDEO_FPS_SYNC_TARGET ) { + driftTime = (ptsServer - playerCurrentTime) << 1; + Log.d(TAG, "seek()"); + this.seekTo(playerCurrentTime + (int) driftTime); + } + else { + if ( (playerCurrentTime - ptsServer) > VIDEO_FPS_SYNC_TARGET ) { + driftTime = (playerCurrentTime - ptsServer) >> 1; + this.pause(); + Log.d(TAG, "delay()"); + currentTimer = new Timer(); + currentTimer.schedule(new ResumePlayerTask(), driftTime); + } + else { + synchd = true; + startTimeSynchd = ptsServer; + } + } + } + else if ((ptsServer - startTimeSynchd) > VIDEO_FPS_SYNC_TARGET /*1m*/) { + synchd = false; + } + + } + + public void setOnAudioBecomingNoisyListener(OnAudioBecomingNoisyListener listener) { + this.onAudioBecomingNoisyListener = listener; + } + + public OnAudioBecomingNoisyListener getAudioBecomingNoisyListener() { + return this.onAudioBecomingNoisyListener; + } + + public interface OnAudioBecomingNoisyListener { + void onAudioBecomingNoisy(); + } +} diff --git a/app/src/main/java/lavid/com/cineacesso/player/CineAcessoPlayerController.java b/app/src/main/java/lavid/com/cineacesso/player/CineAcessoPlayerController.java new file mode 100644 index 0000000..d5e1d56 --- /dev/null +++ b/app/src/main/java/lavid/com/cineacesso/player/CineAcessoPlayerController.java @@ -0,0 +1,82 @@ +package lavid.com.cineacesso.player; + +import android.content.Context; +import android.media.MediaPlayer; +import android.widget.MediaController; + + +public class CineAcessoPlayerController extends MediaController implements MediaController.MediaPlayerControl{ + + private MediaPlayer player; + + public CineAcessoPlayerController(Context context) { + super(context); + } + + public CineAcessoPlayerController(Context context, MediaPlayer player) { + super(context, false); + this.player = player; + setMediaPlayer(this); + } + + @Override + public void start() { + if (player != null) { + player.start(); + } + } + + @Override + public void pause() { + if (player != null) { + player.pause(); + } + } + + @Override + public int getDuration() { + return player != null ? player.getDuration() : 0; + } + + @Override + public int getCurrentPosition() { + return player != null ? player.getCurrentPosition() : 0; + } + + @Override + public void seekTo(int pos) { + if (player != null) { + player.seekTo(pos); + } + } + + @Override + public boolean isPlaying() { + return player != null && player.isPlaying(); + } + + @Override + public int getBufferPercentage() { + return 0; + } + + @Override + public boolean canPause() { + return true; + } + + @Override + public boolean canSeekBackward() { + return false; + } + + @Override + public boolean canSeekForward() { + return false; + } + + @Override + public int getAudioSessionId() { + return player != null ? player.getAudioSessionId() : 0; + } +} diff --git a/app/src/main/java/lavid/com/cineacesso/player/CineAcessoPlayerService.java b/app/src/main/java/lavid/com/cineacesso/player/CineAcessoPlayerService.java new file mode 100644 index 0000000..5e59de9 --- /dev/null +++ b/app/src/main/java/lavid/com/cineacesso/player/CineAcessoPlayerService.java @@ -0,0 +1,43 @@ +package lavid.com.cineacesso.player; + +import android.app.Service; +import android.content.Intent; +import android.os.Binder; +import android.os.IBinder; +import android.support.annotation.Nullable; + +/** + * Created by Ademir on 24/07/2016. + */ +public class CineAcessoPlayerService extends Service { + + private static final String TAG = CineAcessoPlayerService.class.getSimpleName(); + + private final IBinder mBinder = new LocalBinder(); + + private CineAcessoPlayer mPlayer = CineAcessoPlayer.getInstance(); + + public class LocalBinder extends Binder { + public CineAcessoPlayerService getService() { + return CineAcessoPlayerService.this; + } + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return mBinder; + } + + @Override + public void onCreate() { + super.onCreate(); + //Log.d(TAG, "onCreate()"); + } + + @Override + public void onDestroy() { + super.onDestroy(); + //Log.d(TAG, "onDestroy()"); + } +} diff --git a/app/src/main/java/lavid/com/cineacesso/player/CineAcessoPlayerSynchronizer.java b/app/src/main/java/lavid/com/cineacesso/player/CineAcessoPlayerSynchronizer.java new file mode 100644 index 0000000..5f79a74 --- /dev/null +++ b/app/src/main/java/lavid/com/cineacesso/player/CineAcessoPlayerSynchronizer.java @@ -0,0 +1,118 @@ +package lavid.com.cineacesso.player; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.SocketException; + + +public class CineAcessoPlayerSynchronizer extends Thread { + + private static final String TAG = CineAcessoPlayerSynchronizer.class.getSimpleName(); + + private static final String RESP_MESSAGE_TYPE = "type"; + private static final String RESP_SERVER_UID = "server_uid"; + private static final String RESP_OFFSET = "offset"; + private static final String RESP_PTS = "pts"; + private static final String RESP_MESSAGE_START = "START"; + private static final String RESP_MESSAGE_STOP = "STOP"; + private static final String RESP_MESSAGE_SYNC = "SYNC"; + + private static final int CLIENT_DEFAULT_PORT = 5054; + private static final int BUFFER_LENGTH = 1024; + + private DatagramSocket socket; + private int clientPort; + private boolean socketOpened; + + private String serverUid; + + private OnMessageReceivedListener mOnMessageReceivedListener; + + + public CineAcessoPlayerSynchronizer(String serverUid) { + this(CLIENT_DEFAULT_PORT, serverUid); + } + + private CineAcessoPlayerSynchronizer(int clientPort, String serverUid) { + this.clientPort = clientPort; + this.serverUid = serverUid; + socketOpened = true; + } + + @Override + public void run() { + + try { + socket = new DatagramSocket(clientPort); + byte[] buffer; + DatagramPacket packet; + JSONObject jsonObject; + + while(socketOpened) { + buffer = new byte[BUFFER_LENGTH]; + packet = new DatagramPacket(buffer, buffer.length); + + //Log.d(TAG, "WAITING SERVER MESSAGE"); + socket.receive(packet); + + String message = new String(packet.getData()); + jsonObject = new JSONObject(message); + //Log.d(TAG, "MESSAGE RECEIVED = " + jsonObject.toString()); + + String responseServerUid = jsonObject.has(RESP_SERVER_UID) ? jsonObject.getString(RESP_SERVER_UID) : null; + if (responseServerUid != null && responseServerUid.equals(serverUid) + && jsonObject.has(RESP_MESSAGE_TYPE)) { + + String messageType = jsonObject.getString(RESP_MESSAGE_TYPE); + //Log.d(TAG, "RESP_MESSAGE_" + messageType); + switch (messageType) { + case RESP_MESSAGE_START: + mOnMessageReceivedListener.onMessageReceived(RESP_MESSAGE_START, jsonObject.getLong(RESP_OFFSET)); + break; + + case RESP_MESSAGE_STOP: + mOnMessageReceivedListener.onMessageReceived(RESP_MESSAGE_STOP, -1); + break; + + case RESP_MESSAGE_SYNC: + mOnMessageReceivedListener.onMessageReceived(RESP_MESSAGE_SYNC, jsonObject.getLong(RESP_PTS)); + break; + } + + } + } + + } catch (SocketException se) { + se.printStackTrace(); + //Log.d(TAG, "SOCKET_EXCEPTION"); + } catch (IOException ioe) { + ioe.printStackTrace(); + //Log.d(TAG, "IO_EXCEPTION"); + } catch (JSONException jse) { + jse.printStackTrace(); + //Log.d(TAG, "JSON_EXCEPTION"); + } + + } + + public void finish() { + socketOpened = false; + if (socket != null) { + socket.close(); + socket = null; + } + } + + public void setOnMessageReceivedListener(OnMessageReceivedListener mOnMessageReceivedListener) { + this.mOnMessageReceivedListener = mOnMessageReceivedListener; + } + + public interface OnMessageReceivedListener { + void onMessageReceived(String type, long offset); + } + +} diff --git a/app/src/main/java/lavid/com/cineacesso/utils/BarcodeListener.java b/app/src/main/java/lavid/com/cineacesso/utils/BarcodeListener.java new file mode 100644 index 0000000..019ada5 --- /dev/null +++ b/app/src/main/java/lavid/com/cineacesso/utils/BarcodeListener.java @@ -0,0 +1,10 @@ +package lavid.com.cineacesso.utils; + +import com.google.android.gms.vision.barcode.Barcode; + +/** + * Created by Ademir on 07/07/2016. + */ +public interface BarcodeListener { + void onDetected(Barcode barcode); +} diff --git a/app/src/main/java/lavid/com/cineacesso/utils/BarcodeTrackerFactory.java b/app/src/main/java/lavid/com/cineacesso/utils/BarcodeTrackerFactory.java new file mode 100644 index 0000000..18e9a45 --- /dev/null +++ b/app/src/main/java/lavid/com/cineacesso/utils/BarcodeTrackerFactory.java @@ -0,0 +1,24 @@ +package lavid.com.cineacesso.utils; + +import com.google.android.gms.vision.MultiProcessor; +import com.google.android.gms.vision.Tracker; +import com.google.android.gms.vision.barcode.Barcode; + +/** + * Created by Ademir on 07/07/2016. + */ +public class BarcodeTrackerFactory implements MultiProcessor.Factory { + + private BarcodeListener barcodeListener; + + public BarcodeTrackerFactory(BarcodeListener barcodeListener) { + this.barcodeListener = barcodeListener; + } + + @Override + public synchronized Tracker create(Barcode barcode) { + barcodeListener.onDetected(barcode); + return new Tracker<>(); + } + +} diff --git a/app/src/main/java/lavid/com/cineacesso/utils/CineAcessoAPI.java b/app/src/main/java/lavid/com/cineacesso/utils/CineAcessoAPI.java new file mode 100644 index 0000000..21fddcf --- /dev/null +++ b/app/src/main/java/lavid/com/cineacesso/utils/CineAcessoAPI.java @@ -0,0 +1,104 @@ +package lavid.com.cineacesso.utils; + +import android.content.Context; +import android.net.Uri; + +import com.android.volley.Request; +import com.android.volley.toolbox.JsonObjectRequest; + +import org.json.JSONException; + +import java.util.HashMap; + +import lavid.com.cineacesso.R; + + +public class CineAcessoAPI { + + public static void getServerInfo(final Context context, String auxType, final GetServerInfoCallback cbk) { + + String reqEntry = ""; + switch (auxType) { + case CineAcessoDB.CONTENT_TYPE_LIBRAS: + reqEntry = CineAcessoDB.REQ_ENTRY_DEAF; + break; + + case CineAcessoDB.CONTENT_TYPE_AUDIO: + reqEntry = CineAcessoDB.REQ_ENTRY_BLIND; + break; + + case CineAcessoDB.CONTENT_TYPE_SUBS: + reqEntry = CineAcessoDB.REQ_ENTRY_SUBS; + break; + + } + + String url = Uri.parse(CineAcessoDB.BASE_URL).buildUpon() + .appendEncodedPath(reqEntry).build().toString(); + + JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, url, null, response -> { + + HashMap ret = new HashMap<>(); + try { + ret.put(CineAcessoDB.SERVER_UID, response.getString(CineAcessoDB.UID)); + ret.put(CineAcessoDB.CONTENT, response.getString(CineAcessoDB.CONTENT)); + ret.put(CineAcessoDB.PTS, String.valueOf(response.getInt(CineAcessoDB.PTS))); + if (response.has(CineAcessoDB.CONTENT_AUTHOR)){ + ret.put(CineAcessoDB.CONTENT_AUTHOR, response.getString(CineAcessoDB.CONTENT_AUTHOR)); + } else { + ret.put(CineAcessoDB.CONTENT_AUTHOR, context.getString(R.string.unknown)); + } + if (response.has(CineAcessoDB.CONTENT_YEAR)) { + ret.put(CineAcessoDB.CONTENT_YEAR, response.getString(CineAcessoDB.CONTENT_YEAR)); + } else { + ret.put(CineAcessoDB.CONTENT_YEAR, context.getString(R.string.unknown)); + } + if (response.has(CineAcessoDB.CONTENT_TITLE)) { + ret.put(CineAcessoDB.CONTENT_TITLE, response.getString(CineAcessoDB.CONTENT_TITLE)); + } else { + ret.put(CineAcessoDB.CONTENT_TITLE, context.getString(R.string.unknown)); + } + if (response.has(CineAcessoDB.CONTENT_IMG)) { + ret.put(CineAcessoDB.CONTENT_IMG, response.getString(CineAcessoDB.CONTENT_IMG)); + } else { + ret.put(CineAcessoDB.CONTENT_IMG, null); + } + cbk.run(true, ret); + } catch (JSONException e) { + e.printStackTrace(); + } + }, error -> cbk.run(false, null)); + + VolleySingleton.getInstance(context).addToRequestQueue(jsonObjReq); + } + + +// private static class DefaultErrorListener implements Response.ErrorListener { +// private Context ctx; +// +// public DefaultErrorListener(Context ctx) { +// super(); +// this.ctx = ctx; +// } +// +// @Override +// public void onErrorResponse(VolleyError error) { +// +// if (error instanceof TimeoutError || error instanceof NoConnectionError) { +// //Toast.makeText(ctx, R.string.network_timeout, Toast.LENGTH_LONG).show(); +// } else if (error instanceof AuthFailureError) { +// //Toast.makeText(ctx, R.string.auth_failure, Toast.LENGTH_LONG).show(); +// } else if (error instanceof ServerError) { +// //Toast.makeText(ctx, R.string.server_error, Toast.LENGTH_LONG).show(); +// } else if (error instanceof NetworkError) { +// //Toast.makeText(ctx, R.string.network_error, Toast.LENGTH_LONG).show(); +// } else if (error instanceof ParseError) { +// //Toast.makeText(ctx, R.string.parse_error, Toast.LENGTH_LONG).show(); +// } +// } +// } + + public interface GetServerInfoCallback { + void run(boolean success, HashMap map); + } +} diff --git a/app/src/main/java/lavid/com/cineacesso/utils/CineAcessoDB.java b/app/src/main/java/lavid/com/cineacesso/utils/CineAcessoDB.java new file mode 100644 index 0000000..5052207 --- /dev/null +++ b/app/src/main/java/lavid/com/cineacesso/utils/CineAcessoDB.java @@ -0,0 +1,36 @@ +package lavid.com.cineacesso.utils; + +/** + * Created by Ademir on 12/07/2016. + */ +public class CineAcessoDB { + + public static final String LAST_SESSION = "last_session"; + + public static final String SERVER_UID = "server_uid"; + //public static final String AUX_TYPE = "aux_type"; + public static final String BASE_URL = "http://192.168.0.100:5053"; + public static final String NETWORK_SSID = "CINEACESSO-01"; + + public static final String CONTENT_URL = "content_url"; + public static final String CONTENT_IMG = "img"; + public static final String CONTENT_IMG_URL = "img_url"; + public static final String CONTENT_TITLE = "title"; + public static final String CONTENT_AUTHOR = "author"; + public static final String CONTENT_YEAR = "year"; + public static final String CONTENT_TYPE = "type"; + public static final String CONTENT_TYPE_LIBRAS = "libras"; + //public static final String CONTENT_TYPE_LIBRAS_SUB = "libras_subtitles"; + public static final String CONTENT_TYPE_SUBS = "subtitles"; + public static final String CONTENT_TYPE_AUDIO = "audio"; + + public static final String REQ_ENTRY_DEAF = "api/entry/deaf"; + public static final String REQ_ENTRY_BLIND = "api/entry/blind"; + public static final String REQ_ENTRY_SUBS = "api/entry/subs"; + //public static final String REQ_ENTRY_LIBRAS_SUBS = "api/entry/libras_subs"; + + public static final String UID = "uid"; + public static final String CONTENT = "content"; + public static final String PTS = "pts"; + +} diff --git a/app/src/main/java/lavid/com/cineacesso/utils/IntentReceiver.java b/app/src/main/java/lavid/com/cineacesso/utils/IntentReceiver.java new file mode 100644 index 0000000..c042068 --- /dev/null +++ b/app/src/main/java/lavid/com/cineacesso/utils/IntentReceiver.java @@ -0,0 +1,29 @@ +package lavid.com.cineacesso.utils; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.media.AudioManager; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; + +import lavid.com.cineacesso.activities.WifiActivity; +import lavid.com.cineacesso.player.CineAcessoPlayer; + + +/** + * Created by Ademir on 10/07/2016. + */ +public class IntentReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getAction().equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) { + CineAcessoPlayer player; + if ((player = CineAcessoPlayer.getInstance()) != null) { + if (player.getContentType().equals(CineAcessoDB.CONTENT_TYPE_AUDIO)) { + player.getAudioBecomingNoisyListener().onAudioBecomingNoisy(); + } + } + } + } +} diff --git a/app/src/main/java/lavid/com/cineacesso/utils/NetworkReceiver.java b/app/src/main/java/lavid/com/cineacesso/utils/NetworkReceiver.java new file mode 100644 index 0000000..297af6d --- /dev/null +++ b/app/src/main/java/lavid/com/cineacesso/utils/NetworkReceiver.java @@ -0,0 +1,18 @@ +package lavid.com.cineacesso.utils; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.net.ConnectivityManager; + +import lavid.com.cineacesso.activities.WifiActivity; + +/** + * Created by Cinema_2 on 11/08/2016. + */ +public class NetworkReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + + } +} diff --git a/app/src/main/java/lavid/com/cineacesso/utils/RetainedSession.java b/app/src/main/java/lavid/com/cineacesso/utils/RetainedSession.java new file mode 100644 index 0000000..46f04b9 --- /dev/null +++ b/app/src/main/java/lavid/com/cineacesso/utils/RetainedSession.java @@ -0,0 +1,39 @@ +package lavid.com.cineacesso.utils; + +import android.content.Context; +import android.content.SharedPreferences; + +/** + * Created by Ademir on 15/07/2016. + */ +public class RetainedSession { + + private RetainedSession() { + + } + + public static void put(Context c,String key, String value) { + SharedPreferences prefs = c.getSharedPreferences(CineAcessoDB.LAST_SESSION, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = prefs.edit(); + + editor.putString(key, value).apply(); + } + + public static boolean has(Context c, String key) { + SharedPreferences prefs = c.getSharedPreferences(CineAcessoDB.LAST_SESSION, Context.MODE_PRIVATE); + return prefs.contains(key); + } + + public static String get(Context c, String key) { + SharedPreferences prefs = c.getSharedPreferences(CineAcessoDB.LAST_SESSION, Context.MODE_PRIVATE); + return prefs.getString(key, null); + } + + public static void clear(Context c) { + SharedPreferences prefs = c.getSharedPreferences(CineAcessoDB.LAST_SESSION, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = prefs.edit(); + + editor.clear().apply(); + } + +} diff --git a/app/src/main/java/lavid/com/cineacesso/utils/VolleySingleton.java b/app/src/main/java/lavid/com/cineacesso/utils/VolleySingleton.java new file mode 100644 index 0000000..4213eb5 --- /dev/null +++ b/app/src/main/java/lavid/com/cineacesso/utils/VolleySingleton.java @@ -0,0 +1,68 @@ +package lavid.com.cineacesso.utils; + +import android.content.Context; +import android.graphics.Bitmap; +import android.support.v4.util.LruCache; + +import com.android.volley.DefaultRetryPolicy; +import com.android.volley.Request; +import com.android.volley.RequestQueue; +import com.android.volley.toolbox.ImageLoader; +import com.android.volley.toolbox.Volley; + +/** + * Created by Ademir on 17/07/2016. + */ +public class VolleySingleton { + + private static VolleySingleton mInstance; + private static Context mContext; + private static RequestQueue mRequestQueue; + private static ImageLoader mImageLoader; + + + private VolleySingleton(Context context) { + mContext = context; + mRequestQueue = getRequestQueue(); + mImageLoader = new ImageLoader(mRequestQueue, new ImageLoader.ImageCache() { + private final LruCache cache = new LruCache<>(20); + + @Override + public Bitmap getBitmap(String url) { + return cache.get(url); + } + + @Override + public void putBitmap(String url, Bitmap bitmap) { + cache.put(url, bitmap); + } + }); + } + + public static synchronized VolleySingleton getInstance(Context context) { + if (mInstance == null) { + mInstance = new VolleySingleton(context); + } + return mInstance; + } + + private RequestQueue getRequestQueue() { + if (mRequestQueue == null) { + mRequestQueue = Volley.newRequestQueue(mContext.getApplicationContext()); + } + return mRequestQueue; + } + + public void addToRequestQueue(Request req) { + req.setRetryPolicy(new DefaultRetryPolicy( + 20000, + DefaultRetryPolicy.DEFAULT_MAX_RETRIES, + DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); + getRequestQueue().add(req); + //Log.d("VolleyRequestLog", "url: " + req.getUrl()); + } + + public ImageLoader getImageLoader() { + return mImageLoader; + } +} diff --git a/app/src/main/res/drawable-hdpi/arrow_back.png b/app/src/main/res/drawable-hdpi/arrow_back.png new file mode 100644 index 0000000..f21e4f7 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/arrow_back.png differ diff --git a/app/src/main/res/drawable-hdpi/arrow_back_blue.png b/app/src/main/res/drawable-hdpi/arrow_back_blue.png new file mode 100644 index 0000000..25185db Binary files /dev/null and b/app/src/main/res/drawable-hdpi/arrow_back_blue.png differ diff --git a/app/src/main/res/drawable-hdpi/cineacesso_logo_splash.png b/app/src/main/res/drawable-hdpi/cineacesso_logo_splash.png new file mode 100644 index 0000000..bc15859 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/cineacesso_logo_splash.png differ diff --git a/app/src/main/res/drawable-hdpi/play_shape.png b/app/src/main/res/drawable-hdpi/play_shape.png new file mode 100644 index 0000000..88bb3d7 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/play_shape.png differ diff --git a/app/src/main/res/drawable-hdpi/qr_shape.png b/app/src/main/res/drawable-hdpi/qr_shape.png new file mode 100644 index 0000000..4c50196 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/qr_shape.png differ diff --git a/app/src/main/res/drawable-hdpi/wifi_shape.png b/app/src/main/res/drawable-hdpi/wifi_shape.png new file mode 100644 index 0000000..61906ea Binary files /dev/null and b/app/src/main/res/drawable-hdpi/wifi_shape.png differ diff --git a/app/src/main/res/drawable-mdpi/arrow_back.png b/app/src/main/res/drawable-mdpi/arrow_back.png new file mode 100644 index 0000000..8015860 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/arrow_back.png differ diff --git a/app/src/main/res/drawable-mdpi/arrow_back_blue.png b/app/src/main/res/drawable-mdpi/arrow_back_blue.png new file mode 100644 index 0000000..39e9660 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/arrow_back_blue.png differ diff --git a/app/src/main/res/drawable-mdpi/play_shape.png b/app/src/main/res/drawable-mdpi/play_shape.png new file mode 100644 index 0000000..1655bdb Binary files /dev/null and b/app/src/main/res/drawable-mdpi/play_shape.png differ diff --git a/app/src/main/res/drawable-mdpi/qr_shape.png b/app/src/main/res/drawable-mdpi/qr_shape.png new file mode 100644 index 0000000..1fdbac2 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/qr_shape.png differ diff --git a/app/src/main/res/drawable-mdpi/wifi_shape.png b/app/src/main/res/drawable-mdpi/wifi_shape.png new file mode 100644 index 0000000..3d95a22 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/wifi_shape.png differ diff --git a/app/src/main/res/drawable-xhdpi/arrow_back.png b/app/src/main/res/drawable-xhdpi/arrow_back.png new file mode 100644 index 0000000..b954b7a Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/arrow_back.png differ diff --git a/app/src/main/res/drawable-xhdpi/arrow_back_blue.png b/app/src/main/res/drawable-xhdpi/arrow_back_blue.png new file mode 100644 index 0000000..bfeebec Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/arrow_back_blue.png differ diff --git a/app/src/main/res/drawable-xhdpi/cineacesso_logo_splash.png b/app/src/main/res/drawable-xhdpi/cineacesso_logo_splash.png new file mode 100644 index 0000000..0b23853 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/cineacesso_logo_splash.png differ diff --git a/app/src/main/res/drawable-xhdpi/play_shape.png b/app/src/main/res/drawable-xhdpi/play_shape.png new file mode 100644 index 0000000..bc410c3 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/play_shape.png differ diff --git a/app/src/main/res/drawable-xhdpi/qr_shape.png b/app/src/main/res/drawable-xhdpi/qr_shape.png new file mode 100644 index 0000000..c6ce590 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/qr_shape.png differ diff --git a/app/src/main/res/drawable-xhdpi/wifi_shape.png b/app/src/main/res/drawable-xhdpi/wifi_shape.png new file mode 100644 index 0000000..f9b1541 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/wifi_shape.png differ diff --git a/app/src/main/res/drawable-xxhdpi/arrow_back.png b/app/src/main/res/drawable-xxhdpi/arrow_back.png new file mode 100644 index 0000000..b51035b Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/arrow_back.png differ diff --git a/app/src/main/res/drawable-xxhdpi/arrow_back_blue.png b/app/src/main/res/drawable-xxhdpi/arrow_back_blue.png new file mode 100644 index 0000000..1d5e80f Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/arrow_back_blue.png differ diff --git a/app/src/main/res/drawable-xxhdpi/cineacesso_logo_splash.png b/app/src/main/res/drawable-xxhdpi/cineacesso_logo_splash.png new file mode 100644 index 0000000..3190266 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/cineacesso_logo_splash.png differ diff --git a/app/src/main/res/drawable-xxhdpi/play_shape.png b/app/src/main/res/drawable-xxhdpi/play_shape.png new file mode 100644 index 0000000..c6d762c Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/play_shape.png differ diff --git a/app/src/main/res/drawable-xxhdpi/qr_shape.png b/app/src/main/res/drawable-xxhdpi/qr_shape.png new file mode 100644 index 0000000..bda3492 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/qr_shape.png differ diff --git a/app/src/main/res/drawable-xxhdpi/wifi_shape.png b/app/src/main/res/drawable-xxhdpi/wifi_shape.png new file mode 100644 index 0000000..e829c08 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/wifi_shape.png differ diff --git a/app/src/main/res/drawable/about_govfederal.png b/app/src/main/res/drawable/about_govfederal.png new file mode 100644 index 0000000..1b50407 Binary files /dev/null and b/app/src/main/res/drawable/about_govfederal.png differ diff --git a/app/src/main/res/drawable/about_lavid.png b/app/src/main/res/drawable/about_lavid.png new file mode 100644 index 0000000..4e6c400 Binary files /dev/null and b/app/src/main/res/drawable/about_lavid.png differ diff --git a/app/src/main/res/drawable/about_minc.png b/app/src/main/res/drawable/about_minc.png new file mode 100644 index 0000000..00dffb3 Binary files /dev/null and b/app/src/main/res/drawable/about_minc.png differ diff --git a/app/src/main/res/drawable/about_mjc.png b/app/src/main/res/drawable/about_mjc.png new file mode 100644 index 0000000..de05674 Binary files /dev/null and b/app/src/main/res/drawable/about_mjc.png differ diff --git a/app/src/main/res/drawable/about_mpdg.png b/app/src/main/res/drawable/about_mpdg.png new file mode 100644 index 0000000..58989d6 Binary files /dev/null and b/app/src/main/res/drawable/about_mpdg.png differ diff --git a/app/src/main/res/drawable/about_rnp.png b/app/src/main/res/drawable/about_rnp.png new file mode 100644 index 0000000..dfba71b Binary files /dev/null and b/app/src/main/res/drawable/about_rnp.png differ diff --git a/app/src/main/res/drawable/about_sadv.png b/app/src/main/res/drawable/about_sadv.png new file mode 100644 index 0000000..6f30500 Binary files /dev/null and b/app/src/main/res/drawable/about_sadv.png differ diff --git a/app/src/main/res/drawable/about_sti.png b/app/src/main/res/drawable/about_sti.png new file mode 100644 index 0000000..61e49e0 Binary files /dev/null and b/app/src/main/res/drawable/about_sti.png differ diff --git a/app/src/main/res/drawable/about_ufpb.png b/app/src/main/res/drawable/about_ufpb.png new file mode 100644 index 0000000..11ce13d Binary files /dev/null and b/app/src/main/res/drawable/about_ufpb.png differ diff --git a/app/src/main/res/drawable/aux_audiodesc.png b/app/src/main/res/drawable/aux_audiodesc.png new file mode 100644 index 0000000..a50e43f Binary files /dev/null and b/app/src/main/res/drawable/aux_audiodesc.png differ diff --git a/app/src/main/res/drawable/aux_libras.png b/app/src/main/res/drawable/aux_libras.png new file mode 100644 index 0000000..5768289 Binary files /dev/null and b/app/src/main/res/drawable/aux_libras.png differ diff --git a/app/src/main/res/drawable/aux_libras_subtitles.png b/app/src/main/res/drawable/aux_libras_subtitles.png new file mode 100644 index 0000000..e7b0cac Binary files /dev/null and b/app/src/main/res/drawable/aux_libras_subtitles.png differ diff --git a/app/src/main/res/drawable/aux_subtitles.png b/app/src/main/res/drawable/aux_subtitles.png new file mode 100644 index 0000000..994c0e0 Binary files /dev/null and b/app/src/main/res/drawable/aux_subtitles.png differ diff --git a/app/src/main/res/drawable/by_vlibras.png b/app/src/main/res/drawable/by_vlibras.png new file mode 100644 index 0000000..9d52cf3 Binary files /dev/null and b/app/src/main/res/drawable/by_vlibras.png differ diff --git a/app/src/main/res/drawable/cineacesso_logo.png b/app/src/main/res/drawable/cineacesso_logo.png new file mode 100644 index 0000000..3190266 Binary files /dev/null and b/app/src/main/res/drawable/cineacesso_logo.png differ diff --git a/app/src/main/res/drawable/cineacesso_logo_no_name.png b/app/src/main/res/drawable/cineacesso_logo_no_name.png new file mode 100644 index 0000000..25954fd Binary files /dev/null and b/app/src/main/res/drawable/cineacesso_logo_no_name.png differ diff --git a/app/src/main/res/drawable/cineacesso_name.png b/app/src/main/res/drawable/cineacesso_name.png new file mode 100644 index 0000000..f9565a8 Binary files /dev/null and b/app/src/main/res/drawable/cineacesso_name.png differ diff --git a/app/src/main/res/drawable/content_image_default.png b/app/src/main/res/drawable/content_image_default.png new file mode 100644 index 0000000..6a17202 Binary files /dev/null and b/app/src/main/res/drawable/content_image_default.png differ diff --git a/app/src/main/res/drawable/qr_code_delim.png b/app/src/main/res/drawable/qr_code_delim.png new file mode 100644 index 0000000..bb82971 Binary files /dev/null and b/app/src/main/res/drawable/qr_code_delim.png differ diff --git a/app/src/main/res/drawable/rnp_teste.png b/app/src/main/res/drawable/rnp_teste.png new file mode 100644 index 0000000..9b63bae Binary files /dev/null and b/app/src/main/res/drawable/rnp_teste.png differ diff --git a/app/src/main/res/drawable/splash_screen_bg.xml b/app/src/main/res/drawable/splash_screen_bg.xml new file mode 100644 index 0000000..5702029 --- /dev/null +++ b/app/src/main/res/drawable/splash_screen_bg.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/wifi_shape_big.png b/app/src/main/res/drawable/wifi_shape_big.png new file mode 100644 index 0000000..ca848ec Binary files /dev/null and b/app/src/main/res/drawable/wifi_shape_big.png differ diff --git a/app/src/main/res/layout-v21/activity_content.xml b/app/src/main/res/layout-v21/activity_content.xml new file mode 100644 index 0000000..64a32f6 --- /dev/null +++ b/app/src/main/res/layout-v21/activity_content.xml @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_aux_type.xml b/app/src/main/res/layout/activity_aux_type.xml new file mode 100644 index 0000000..a63391d --- /dev/null +++ b/app/src/main/res/layout/activity_aux_type.xml @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_content.xml b/app/src/main/res/layout/activity_content.xml new file mode 100644 index 0000000..279fa6c --- /dev/null +++ b/app/src/main/res/layout/activity_content.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_player.xml b/app/src/main/res/layout/activity_player.xml new file mode 100644 index 0000000..f520e2d --- /dev/null +++ b/app/src/main/res/layout/activity_player.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/app/src/main/res/layout/activity_wifi.xml b/app/src/main/res/layout/activity_wifi.xml new file mode 100644 index 0000000..0ce7836 --- /dev/null +++ b/app/src/main/res/layout/activity_wifi.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml new file mode 100644 index 0000000..836e594 --- /dev/null +++ b/app/src/main/res/menu/menu_main.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..6094b7b Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c8b7c31 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..c12fab4 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..d9f2450 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..026bc75 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/raw/beep.wav b/app/src/main/res/raw/beep.wav new file mode 100644 index 0000000..015e1f6 Binary files /dev/null and b/app/src/main/res/raw/beep.wav differ diff --git a/app/src/main/res/values-v19/styles.xml b/app/src/main/res/values-v19/styles.xml new file mode 100644 index 0000000..0506460 --- /dev/null +++ b/app/src/main/res/values-v19/styles.xml @@ -0,0 +1,13 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml new file mode 100644 index 0000000..ca9d67c --- /dev/null +++ b/app/src/main/res/values-v21/styles.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..90bf001 --- /dev/null +++ b/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..d114325 --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,15 @@ + + + #3B8CCC + #3B8CCC + #448AFF + + #1F8AC3 + #3D96C3 + #5396B7 + #65A4C3 + + #FFFFFF + #000000 + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..36aad7d --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,4 @@ + + + 16dp + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..678b728 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,63 @@ + + CineAcesso + + Tela de captura do qr code + Tela configuração wifi + Tela principal + Tela informações do conteúdo + + OK + Voltar + Cancelar + + Acesso à camera necessário para detecção + É necessário a permissão de camera. + Permitir uso da camera + + Faça a leitura do QR Code + Escanear código QR + Mire corretamente no QR code e aguarde pela vibração. Você irá automaticamente para o próximo passo. + Você precisa estar conectado na nossa rede Wifi. Conecte em alguma rede com o prefixo: + CINEACESSO-XX + Escolher função + Escolha um dos auxílios abaixo para acompanhar o vídeo ou o filme + Sobre + libras + libras e legendas + legendas + audiodescrição + Desenvolvido por NPE/LAVID\nhttp://lavid.ufpb.br\ncontato@lavid.ufpb.br + Realizadores + Sessão salva! + + Ocorreu um problema ao localizar o vídeo. Tente novamente. + QR Code inválido + O QR Code escaneado é inválido. + Play + Escanear qr Code + Escolher rede sem fio + Aguardando início + Ao iniciar o filme, o conteúdo será reproduzido automaticamente. + + Desconhecido + O conteúdo ainda não está disponível. + Aguarde + Direção + Ocorreu um erro, conecte-se novamente. + A sua ultima sessão ainda não acabou! Aperte OK para voltar ou cancelar para escanear um novo código. + Carregando + Em breve! + Governo federal + Ministério da cultura + Secretaria do audiovisual + Secretaria de tecnologia da informação + Ministério do planejamento, desenvolvimento e gestão + Ministério da justiça e cidadania + Rede nacional de ensino e pesquisa + Laboratório de aplicações de vídeo digital + Universidade federal da paraíba + Você irá acompanhar o filme em: + CineAcesso + Verificando conexão + + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..16912db --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,25 @@ + + + + + + + + +