Update Intro stuff

This commit is contained in:
MrLetsplay 2023-06-22 21:03:36 +02:00
parent 5925674826
commit ccfaf87210
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
9 changed files with 82 additions and 177 deletions

View File

@ -34,13 +34,8 @@
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.CringeAuthenticator">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".QRScannerActivity"
<activity android:name=".scanner.QRScannerActivity"
android:theme="@style/Theme.CringeAuthenticator">
</activity>
</application>

View File

@ -1,17 +1,32 @@
package com.cringe_studios.cringe_authenticator;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.VideoView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.cringe_studios.cringe_authenticator.databinding.ActivityIntroBinding;
public class IntroActivity extends AppCompatActivity {
public static boolean show_logoanimation = false;
private static ActivityIntroBinding binding;
private MediaPlayer mMediaPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -20,21 +35,55 @@ public class IntroActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
if (show_logoanimation) {
setContentView(R.layout.activity_intro);
final Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Do something after 4000ms
Intent m = new Intent(getApplicationContext(), MainActivity.class);
m.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(m);
}
}, 4000);
} else {
}
binding = ActivityIntroBinding.inflate(getLayoutInflater());
Uri uri = Uri.parse(String.format("android.resource://%s/%s", getPackageName(), R.raw.intro));
binding.videoView.setVideoURI(uri);
binding.videoView.start();
binding.videoView.setOnPreparedListener(mediaPlayer -> {
mMediaPlayer = mediaPlayer;
setDimension();
});
binding.videoView.setOnCompletionListener(mp -> openMainActivity());
setContentView(binding.getRoot());
}
public void openMainActivity() {
Intent m = new Intent(getApplicationContext(), MainActivity.class);
m.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(m);
finish();
}
@Override
public void onDestroy() {
super.onDestroy();
// When the Activity is destroyed, release our MediaPlayer and set it to null.
mMediaPlayer.release();
mMediaPlayer = null;
}
private void setDimension() {
float videoProportion = (float) mMediaPlayer.getVideoHeight() / mMediaPlayer.getVideoWidth();
int screenWidth = getResources().getDisplayMetrics().widthPixels;
int screenHeight = getResources().getDisplayMetrics().heightPixels;
float screenProportion = (float) screenHeight / (float) screenWidth;
ViewGroup.LayoutParams lp = binding.videoView.getLayoutParams();
if (videoProportion < screenProportion) {
lp.height= screenHeight;
lp.width = (int) ((float) screenHeight / videoProportion);
} else {
lp.width = screenWidth;
lp.height = (int) ((float) screenWidth * videoProportion);
}
binding.videoView.setLayoutParams(lp);
}

View File

@ -76,7 +76,7 @@ public class MainActivity extends AppCompatActivity {
Fragment fragment = NavigationUtil.getCurrentFragment(this);
if(fragment instanceof DynamicFragment) {
DynamicFragment frag = (DynamicFragment) fragment;
SettingsUtil.addOTP(getSharedPreferences(DynamicFragment.GROUPS_PREFS_NAME, MODE_PRIVATE), frag.getGroupName(), obj);
SettingsUtil.addOTP(getSharedPreferences(SettingsUtil.GROUPS_PREFS_NAME, MODE_PRIVATE), frag.getGroupName(), obj);
frag.loadOTPs();
}
Log.i("AMOGUS", "Actually got something bruh" + obj);

View File

@ -24,9 +24,7 @@ import java.util.List;
public class DynamicFragment extends Fragment {
public static final String
GROUPS_PREFS_NAME = "groups",
BUNDLE_GROUP = "group";
public static final String BUNDLE_GROUP = "group";
private String groupName;
@ -74,7 +72,7 @@ public class DynamicFragment extends Fragment {
}
public void loadOTPs() {
SharedPreferences prefs = getActivity().getSharedPreferences(DynamicFragment.GROUPS_PREFS_NAME, Context.MODE_PRIVATE);
SharedPreferences prefs = getActivity().getSharedPreferences(SettingsUtil.GROUPS_PREFS_NAME, Context.MODE_PRIVATE);
List<OTPData> data = SettingsUtil.getOTPs(prefs, groupName);
Log.i("AMOGUS", "OTPS: " + data);

View File

@ -1,123 +0,0 @@
package com.cringe_studios.cringe_authenticator.fragment;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.VideoView;
import com.cringe_studios.cringe_authenticator.R;
/**
* A simple {@link Fragment} subclass.
* Use the {@link Intro#newInstance} factory method to
* create an instance of this fragment.
*/
public class Intro extends Fragment {
// Create a VideoView variable, a MediaPlayer variable, and an int to hold the current
// video position.
private VideoView videoBG;
MediaPlayer mMediaPlayer;
int mCurrentVideoPosition;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_intro, container, false);
// Hook up the VideoView to our UI.
videoBG = (VideoView) root.findViewById(R.id.videoView);
// Build your video Uri
Uri uri = Uri.parse("android.resource://" // First start with this,
+ requireContext().getPackageName() // then retrieve your package name,
+ "/" // add a slash,
+ R.raw.intro); // and then finally add your video resource. Make sure it is stored
// in the raw folder.
// Set the new Uri to our VideoView
System.out.println(uri);
videoBG.setVideoURI(uri);
// Start the VideoView
videoBG.start();
// Set an OnPreparedListener for our VideoView. For more information about VideoViews,
// check out the Android Docs: https://developer.android.com/reference/android/widget/VideoView.html
videoBG.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
setDimension();
mMediaPlayer = mediaPlayer;
// We want our video to play over and over so we set looping to true.
mMediaPlayer.setLooping(true);
// We then seek to the current position if it has been set and play the video.
if (mCurrentVideoPosition != 0) {
mMediaPlayer.seekTo(mCurrentVideoPosition);
mMediaPlayer.start();
}
}
});
return root;
}
/*================================ Important Section! ================================
We must override onPause(), onResume(), and onDestroy() to properly handle our
VideoView.
*/
@Override
public void onPause() {
super.onPause();
// Capture the current video position and pause the video.
mCurrentVideoPosition = mMediaPlayer.getCurrentPosition();
videoBG.pause();
}
@Override
public void onResume() {
super.onResume();
// Restart the video when resuming the Activity
videoBG.start();
}
@Override
public void onDestroy() {
super.onDestroy();
// When the Activity is destroyed, release our MediaPlayer and set it to null.
mMediaPlayer.release();
mMediaPlayer = null;
}
private void setDimension() {
// Adjust the size of the video
// so it fits on the screen
float videoProportion = getVideoProportion();
int screenWidth = getResources().getDisplayMetrics().widthPixels;
int screenHeight = getResources().getDisplayMetrics().heightPixels;
float screenProportion = (float) screenHeight / (float) screenWidth;
android.view.ViewGroup.LayoutParams lp = videoBG.getLayoutParams();
if (videoProportion < screenProportion) {
lp.height= screenHeight;
lp.width = (int) ((float) screenHeight / videoProportion);
} else {
lp.width = screenWidth;
lp.height = (int) ((float) screenWidth * videoProportion);
}
videoBG.setLayoutParams(lp);
}
// This method gets the proportion of the video that you want to display.
// I already know this ratio since my video is hardcoded, you can get the
// height and width of your video and appropriately generate the proportion
// as :height/width
private float getVideoProportion(){
return 2.22f;
}
}

View File

@ -13,6 +13,10 @@ import java.util.List;
public class SettingsUtil {
public static String
GROUPS_PREFS_NAME = "groups",
GENERAL_PREFS_NAME = "general";
private static final Gson GSON = new Gson();
public static List<OTPData> getOTPs(SharedPreferences prefs, String group) {

View File

@ -1,16 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
android:background="#000000">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment2"
android:name="com.cringe_studios.cringe_authenticator.fragment.Intro"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</androidx.drawerlayout.widget.DrawerLayout>
<VideoView
android:id="@+id/videoView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
tools:context="fragment.Intro">
<VideoView
android:id="@+id/videoView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -43,6 +43,4 @@
libero vel nunc consequat, quis tincidunt nisl eleifend. Cras bibendum enim a justo luctus
vestibulum. Fusce dictum libero quis erat maximus, vitae volutpat diam dignissim.
</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>