use of com.bigyoshi.qrhunt.player.Player in project QRHunt by CMPUT301W22T00.
the class MainActivity method onCreate.
/**
* Sets up screen (toolbar, bottom menu), initializes player if need be
* manages which fragment the app is in and adjusts accordingly, & passes things from
* fragment to fragment
*
* @param savedInstanceState SavedInstanceState
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
db = FirebaseFirestore.getInstance();
Toolbar toolbar = findViewById(R.id.top_navigation_view);
setSupportActionBar(toolbar);
ActionBar actionbar = getSupportActionBar();
actionbar.setDisplayShowTitleEnabled(false);
actionbar.setDisplayShowCustomEnabled(true);
player = new Player(this);
// This will check if the player already has an account
if (!player.getPlayerId().matches("")) {
player.initialize();
}
scoreView = toolbar.findViewById(R.id.top_scanner_score);
updateFirebaseListeners();
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
NavController navController = Navigation.findNavController(this, R.id.main_bottom_navigation_host_fragment);
NavigationUI.setupWithNavController(binding.bottomNavigationView, navController);
navProfile = findViewById(R.id.top_navigation_profile);
navProfile.setOnClickListener(view -> {
binding.bottomNavigationView.setVisibility(View.INVISIBLE);
FragmentProfile profile = new FragmentProfile();
Bundle bundle = new Bundle();
bundle.putSerializable("player", player);
profile.setArguments(bundle);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container, profile, "profile");
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
});
navSearch = findViewById(R.id.top_navigation_search);
navSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
binding.bottomNavigationView.setVisibility(View.INVISIBLE);
actionbar.hide();
FragmentSearch search = new FragmentSearch(player, navController.getCurrentDestination().getId());
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container, search, "search");
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
// determines current fragment so the right button is visible
navController.addOnDestinationChangedListener((navController1, navDestination, bundle) -> {
if (navDestination.getId() == R.id.navigation_map) {
actionbar.show();
navSearch.setVisibility(View.GONE);
// TEMPORARY
navProfile.setVisibility(View.GONE);
}
if (navDestination.getId() == R.id.navigation_scanner) {
actionbar.show();
Bundle result = new Bundle();
result.putSerializable("player", player);
getSupportFragmentManager().setFragmentResult("getPlayer", result);
navSearch.setVisibility(View.VISIBLE);
navProfile.setVisibility(View.VISIBLE);
}
if (navDestination.getId() == R.id.navigation_leaderBoard) {
actionbar.hide();
binding.bottomNavigationView.setVisibility(View.INVISIBLE);
}
});
Intent intent = this.getIntent();
Bundle s = intent.getExtras();
int prevFrag = -1;
if (s != null) {
prevFrag = (int) s.getSerializable("previous");
}
if (prevFrag == R.id.navigation_map) {
actionbar.show();
navSearch.setVisibility(View.GONE);
// Need to figure out how to go to the Map -> currently goes to Scanner (start dest)
// For now I made this invisible
} else if (prevFrag == R.id.navigation_scanner) {
actionbar.show();
navSearch.setVisibility(View.VISIBLE);
}
}
use of com.bigyoshi.qrhunt.player.Player in project QRHunt by CMPUT301W22T00.
the class FragmentScanner method onCreateView.
/**
* Sets up fragment to be loaded in, finds all views, sets onClickListener for buttons
*
* @param inflater Inflater
* @param container Where the fragment is contained
* @param savedInstanceState SavedInstanceState
* @return root
*/
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
getActivity().getSupportFragmentManager().setFragmentResultListener("getPlayer", this, (requestKey, result) -> {
Player player = (Player) result.getSerializable("player");
playerId = player.getPlayerId();
});
// Get permissions first
requestPermissionsIfNecessary(new String[] { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA });
final Activity activity = getActivity();
View root = inflater.inflate(R.layout.fragment_scanner, container, false);
CodeScannerView scannerView = root.findViewById(R.id.scanner_view);
assert activity != null;
codeScanner = new CodeScanner(activity, scannerView);
codeScanner.setCamera(CodeScanner.CAMERA_BACK);
codeScanner.setScanMode(ScanMode.CONTINUOUS);
codeScanner.setAutoFocusMode(AutoFocusMode.SAFE);
codeScanner.setFlashEnabled(false);
codeScanner.setAutoFocusEnabled(true);
codeScanner.setFormats(CodeScanner.ALL_FORMATS);
codeScanner.setDecodeCallback(result -> activity.runOnUiThread(() -> {
camera = new QrCodeProcessor(FragmentScanner.this, result.getText(), playerId);
codeScanner.setScanMode(ScanMode.PREVIEW);
camera.processQRCode();
final Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
@Override
public void run() {
codeScanner.setScanMode(ScanMode.CONTINUOUS);
}
}, 2000);
}));
codeScanner.setErrorCallback(thrown -> Log.e(TAG, "Camera has failed: ", thrown));
return root;
}
Aggregations