Compare commits

..

2 Commits

Author SHA1 Message Date
ccfaf87210
Update Intro stuff 2023-06-22 21:03:36 +02:00
5925674826
Move some files 2023-06-22 21:03:21 +02:00
13 changed files with 141 additions and 203 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 {
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);
}
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

@ -1,7 +1,5 @@
package com.cringe_studios.cringe_authenticator;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
@ -9,12 +7,10 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContract;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.biometric.BiometricPrompt;
@ -26,15 +22,14 @@ import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import com.cringe_studios.cringe_authenticator.databinding.ActivityMainBinding;
import com.cringe_studios.cringe_authenticator.databinding.FragmentDynamicBinding;
import com.cringe_studios.cringe_authenticator.fragment.DynamicFragment;
import com.cringe_studios.cringe_authenticator.fragment.HomeFragment;
import com.cringe_studios.cringe_authenticator.fragment.MenuFragment;
import com.cringe_studios.cringe_authenticator.fragment.SettingsFragment;
import com.cringe_studios.cringe_authenticator.scanner.QRScannerActivity;
import com.cringe_studios.cringe_authenticator.scanner.QRScannerContract;
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
import com.cringe_studios.cringe_authenticator.util.SettingsUtil;
import com.cringe_studios.cringe_authenticator_library.OTPType;
import com.google.android.material.color.utilities.DynamicColor;
import java.util.concurrent.Executor;
@ -73,10 +68,16 @@ public class MainActivity extends AppCompatActivity {
launchApp();
startQRCodeScan = registerForActivityResult(new QRScannerContract(), obj -> {
if(obj == null) { // Got some error TODO: show error message
Toast.makeText(this, "Failed to scan code", Toast.LENGTH_LONG).show();
return;
}
Fragment fragment = NavigationUtil.getCurrentFragment(this);
if(fragment instanceof DynamicFragment) {
DynamicFragment frag = (DynamicFragment) fragment;
SettingsUtil.addOTP(getSharedPreferences("groups", 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

@ -3,6 +3,7 @@ package com.cringe_studios.cringe_authenticator.fragment;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@ -13,22 +14,26 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.cringe_studios.cringe_authenticator.OTPData;
import com.cringe_studios.cringe_authenticator.R;
import com.cringe_studios.cringe_authenticator.databinding.AuthenticateTotpBinding;
import com.cringe_studios.cringe_authenticator.databinding.FragmentDynamicBinding;
import com.cringe_studios.cringe_authenticator.databinding.OtpCodeBinding;
import com.cringe_studios.cringe_authenticator.util.FabUtil;
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
import com.cringe_studios.cringe_authenticator.util.SettingsUtil;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.cringe_studios.cringe_authenticator_library.OTP;
import java.util.List;
public class DynamicFragment extends Fragment {
public static final String BUNDLE_GROUP = "group";
private String groupName;
private FragmentDynamicBinding binding;
private Handler handler;
private Runnable refreshCodes;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -39,7 +44,7 @@ public class DynamicFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = FragmentDynamicBinding.inflate(inflater, container, false);
groupName = requireArguments().getString("group");
groupName = requireArguments().getString(DynamicFragment.BUNDLE_GROUP);
/*String[] totps = new String[]{"Code 1", "Code 2", groupName};
for(String totp : totps) {
@ -52,18 +57,31 @@ public class DynamicFragment extends Fragment {
FabUtil.showFabs(getActivity());
refreshCodes = () -> {
for(int i = 0; i < binding.itemList.getChildCount(); i++) {
View v = binding.itemList.getChildAt(i);
OTP otp = (OTP) v.getTag();
otp.getPin();
}
handler.postDelayed(refreshCodes, 1000L);
};
handler.post(refreshCodes);
return binding.getRoot();
}
public void loadOTPs() {
SharedPreferences prefs = getActivity().getSharedPreferences("groups", 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);
binding.itemList.removeAllViews();
for(OTPData otp : data) {
AuthenticateTotpBinding itemBinding = AuthenticateTotpBinding.inflate(getLayoutInflater());
itemBinding.displayName.setText(otp.getName());
itemBinding.totpCode.setText(otp.toOTP().getPin());
OtpCodeBinding itemBinding = OtpCodeBinding.inflate(getLayoutInflater());
itemBinding.label.setText(otp.getName());
itemBinding.otpCode.setText(otp.toOTP().getPin());
itemBinding.getRoot().setTag(otp.toOTP());
binding.itemList.addView(itemBinding.getRoot());
}
}
@ -74,6 +92,12 @@ public class DynamicFragment extends Fragment {
this.binding = null;
}
@Override
public void onDestroy() {
handler.removeCallbacks(refreshCodes);
super.onDestroy();
}
public String getGroupName() {
return groupName;
}

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

@ -29,16 +29,16 @@ public class MenuFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = FragmentMenuBinding.inflate(inflater);
String[] items = {"a", "b"};
SharedPreferences pr = getContext().getSharedPreferences("menu", Context.MODE_PRIVATE);
String[] items = {"a", "b"};
for(String item : items) {
MenuItemBinding itemBinding = MenuItemBinding.inflate(inflater);
itemBinding.button.setText(item);
itemBinding.button.setOnClickListener(view -> {
Bundle bundle = new Bundle();
bundle.putString("tab", item);
bundle.putString(DynamicFragment.BUNDLE_GROUP, item);
NavigationUtil.navigate(this, DynamicFragment.class, bundle);
});
itemBinding.button.setOnLongClickListener(view -> {

View File

@ -1,4 +1,4 @@
package com.cringe_studios.cringe_authenticator;
package com.cringe_studios.cringe_authenticator.scanner;
import android.Manifest;
import android.app.Activity;
@ -24,6 +24,7 @@ import androidx.camera.lifecycle.ProcessCameraProvider;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleOwner;
import com.cringe_studios.cringe_authenticator.OTPData;
import com.cringe_studios.cringe_authenticator.databinding.ActivityQrScannerBinding;
import com.cringe_studios.cringe_authenticator_library.OTP;
import com.cringe_studios.cringe_authenticator_library.OTPAlgorithm;
@ -120,6 +121,8 @@ public class QRScannerActivity extends AppCompatActivity {
}
}
if(code == null) return;
Uri uri = Uri.parse(code.getRawValue());
Log.i("AMOGUS", code.getRawValue());
Log.i("AMOGUS", uri.getHost());
@ -180,7 +183,7 @@ public class QRScannerActivity extends AppCompatActivity {
}
}
private void success(OTPData data) {
private void success(@NonNull OTPData data) {
Intent result = new Intent();
result.putExtra("data", data);
setResult(Activity.RESULT_OK, result);
@ -188,8 +191,7 @@ public class QRScannerActivity extends AppCompatActivity {
}
private void error(String errorMessage) {
Intent result = new Intent();
setResult(Activity.RESULT_CANCELED, result);
setResult(Activity.RESULT_CANCELED, null);
finish();
}

View File

@ -1,4 +1,4 @@
package com.cringe_studios.cringe_authenticator;
package com.cringe_studios.cringe_authenticator.scanner;
import android.app.Activity;
import android.content.Context;
@ -8,6 +8,8 @@ import androidx.activity.result.contract.ActivityResultContract;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.cringe_studios.cringe_authenticator.OTPData;
public class QRScannerContract extends ActivityResultContract<Void, OTPData> {
@NonNull
@ -17,7 +19,7 @@ public class QRScannerContract extends ActivityResultContract<Void, OTPData> {
}
@Override
public OTPData parseResult(int result, @Nullable Intent intent) {
public @Nullable OTPData parseResult(int result, @Nullable Intent intent) {
if(result != Activity.RESULT_OK || intent == null) {
return null;
}

View File

@ -2,6 +2,8 @@ package com.cringe_studios.cringe_authenticator.util;
import android.content.SharedPreferences;
import androidx.annotation.NonNull;
import com.cringe_studios.cringe_authenticator.OTPData;
import com.google.gson.Gson;
@ -11,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) {
@ -18,7 +24,7 @@ public class SettingsUtil {
return Arrays.asList(GSON.fromJson(currentOTPs, OTPData[].class));
}
public static void addOTP(SharedPreferences prefs, String group, OTPData data) {
public static void addOTP(SharedPreferences prefs, String group, @NonNull OTPData data) {
List<OTPData> otps = new ArrayList<>(getOTPs(prefs, group));
otps.add(data);

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

@ -11,15 +11,15 @@
android:padding="5dp"
android:orientation="vertical">
<TextView
android:id="@+id/displayName"
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="My TOTP"
android:text="My OTP"
android:textAlignment="center"
android:textSize="16sp" />
<TextView
android:id="@+id/totpCode"
android:id="@+id/otpCode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="000000"

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>