Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.preezm.preezm;
- import android.app.Activity;
- import android.content.Intent;
- import android.content.res.AssetFileDescriptor;
- import android.graphics.SurfaceTexture;
- import android.media.MediaPlayer;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.os.Handler;
- import android.text.TextUtils;
- import android.view.Surface;
- import android.view.TextureView;
- import android.view.ViewGroup;
- import com.crashlytics.android.Crashlytics;
- import com.preezm.preezm.model.Country;
- import com.preezm.preezm.model.User;
- import java.io.IOException;
- /**
- * Created by pedja on 1.4.15. 11.19.
- * This class is part of the Preezm
- * Copyright © 2015 ${OWNER}
- */
- public class SplashActivity extends AbsActivity implements Runnable, TextureView.SurfaceTextureListener
- {
- public static final int SPLASH_DELAY = 3000;
- Handler handler;
- private MediaPlayer mMediaPlayer;
- TextureView tvIntro;
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- //debug
- //finish();
- //startActivity(new Intent(this, ContactImportActivity.class));
- //debug end
- setContentView(R.layout.activity_splash);
- handler = new Handler();
- tvIntro = (TextureView) findViewById(R.id.tvIntro);
- tvIntro.setSurfaceTextureListener(this);
- logUsersCountryAsync();
- }
- private void logUsersCountryAsync()
- {
- new AsyncTask<Void, Void, Void>()
- {
- @Override
- protected Void doInBackground(Void... params)
- {
- Country.findUsersCountry();
- return null;
- }
- }.execute();
- }
- @Override
- protected void onResume()
- {
- handler.postDelayed(this, SPLASH_DELAY);
- super.onResume();
- }
- @Override
- protected void onStop()
- {
- super.onStop();
- handler.removeCallbacks(this);
- if(mMediaPlayer != null)
- {
- mMediaPlayer.pause();
- }
- }
- @Override
- public void run()
- {
- continueSignUpProcess(this, false);
- }
- public static void continueSignUpProcess(Activity activity, boolean skipSignup)
- {
- activity.finish();
- //sign-up cases:
- //1. StartActivity - email in user object is null or empty
- //2. DialogVerificationCode - token is null in user object
- //3. ECardEditActivity (personal) - user object doesn't have any ecards
- //4. PreezmIDCreationActivity - user object doesn't have preezm id
- //5. MainActivity - all of the above is if-else, this last case is else. is this ok?
- User user = User.get();
- if(TextUtils.isEmpty(user.getEmail()) && !skipSignup)
- {
- //1.
- activity.startActivity(new Intent(activity, StartActivity.class));
- }
- else if(TextUtils.isEmpty(user.getToken()))
- {
- //2.
- //start sign-up activity and show verification code dialog
- activity.startActivity(new Intent(activity, SignUpActivity.class).setAction(SignUpActivity.INTENT_ACTION_SHOW_VERIFICATION_DIALOG));
- }
- else if(user.getEcards().isEmpty())
- {
- //3.
- ECardEditActivity.start(activity, ECardEditActivity.AFTER_SAVE_ACTION_ADD_PROFESSIONAL, -1, true, -1, false);
- }
- else if(TextUtils.isEmpty(user.getPreezm_id()))
- {
- //4.
- activity.startActivity(new Intent(activity, PreezmIDCreationActivity.class));
- }
- else
- {
- //5.
- MainActivity.start(activity);
- }
- }
- @Override
- public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height)
- {
- Surface surface = new Surface(surfaceTexture);
- try
- {
- AssetFileDescriptor afd = getAssets().openFd("splash_video.mp4");
- mMediaPlayer = new MediaPlayer();
- mMediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
- mMediaPlayer.setSurface(surface);
- mMediaPlayer.setLooping(false);
- mMediaPlayer.prepareAsync();
- // Play video when the media source is ready for playback.
- mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
- {
- @Override
- public void onPrepared(MediaPlayer mediaPlayer)
- {
- int surfaceWidth = tvIntro.getWidth();
- int surfaceHeight = tvIntro.getHeight();
- float videoWidth = mediaPlayer.getVideoWidth();
- float videoHeight = mediaPlayer.getVideoHeight();
- float ratio_width = surfaceWidth / videoWidth;
- float ratio_height = surfaceHeight / videoHeight;
- float aspect = videoWidth / videoHeight;
- ViewGroup.LayoutParams layoutParams = tvIntro.getLayoutParams();
- if (ratio_width < ratio_height)
- {
- layoutParams.width = (int) (surfaceHeight * aspect);
- layoutParams.height = surfaceHeight;
- }
- else
- {
- layoutParams.width = surfaceWidth;
- layoutParams.height = (int) (surfaceWidth / aspect);
- }
- tvIntro.setLayoutParams(layoutParams);
- mediaPlayer.start();
- }
- });
- }
- catch (IOException e)
- {
- if (BuildConfig.DEBUG) e.printStackTrace();
- Crashlytics.logException(e);
- }
- }
- @Override
- public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height)
- {
- }
- @Override
- public boolean onSurfaceTextureDestroyed(SurfaceTexture surface)
- {
- return false;
- }
- @Override
- public void onSurfaceTextureUpdated(SurfaceTexture surface)
- {
- }
- @Override
- protected void onDestroy()
- {
- super.onDestroy();
- if (mMediaPlayer != null)
- {
- mMediaPlayer.stop();
- mMediaPlayer.release();
- mMediaPlayer = null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment