Search in sources :

Example 1 with Player

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);
    }
}
Also used : Player(com.bigyoshi.qrhunt.player.Player) Bundle(android.os.Bundle) NavController(androidx.navigation.NavController) Intent(android.content.Intent) FragmentProfile(com.bigyoshi.qrhunt.player.FragmentProfile) View(android.view.View) TextView(android.widget.TextView) FragmentManager(androidx.fragment.app.FragmentManager) FragmentSearch(com.bigyoshi.qrhunt.bottom_navigation.search.FragmentSearch) FragmentTransaction(androidx.fragment.app.FragmentTransaction) ActionBar(androidx.appcompat.app.ActionBar) Toolbar(androidx.appcompat.widget.Toolbar)

Example 2 with Player

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;
}
Also used : Player(com.bigyoshi.qrhunt.player.Player) CodeScanner(com.budiyev.android.codescanner.CodeScanner) CodeScannerView(com.budiyev.android.codescanner.CodeScannerView) Activity(android.app.Activity) Handler(android.os.Handler) CodeScannerView(com.budiyev.android.codescanner.CodeScannerView) View(android.view.View) Nullable(androidx.annotation.Nullable)

Aggregations

View (android.view.View)2 Player (com.bigyoshi.qrhunt.player.Player)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 TextView (android.widget.TextView)1 Nullable (androidx.annotation.Nullable)1 ActionBar (androidx.appcompat.app.ActionBar)1 Toolbar (androidx.appcompat.widget.Toolbar)1 FragmentManager (androidx.fragment.app.FragmentManager)1 FragmentTransaction (androidx.fragment.app.FragmentTransaction)1 NavController (androidx.navigation.NavController)1 FragmentSearch (com.bigyoshi.qrhunt.bottom_navigation.search.FragmentSearch)1 FragmentProfile (com.bigyoshi.qrhunt.player.FragmentProfile)1 CodeScanner (com.budiyev.android.codescanner.CodeScanner)1 CodeScannerView (com.budiyev.android.codescanner.CodeScannerView)1