Search in sources :

Example 51 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project AudioVideo by JimSeker.

the class MainFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View myView = inflater.inflate(R.layout.fragment_main, container, false);
    // deals the screen rotating and keeps the data for the logger.
    // use activity, so it survives the rotation, instead of fragment here.
    mViewModel = new ViewModelProvider(getActivity()).get(LoggerViewModel.class);
    // logger, to display text/info.
    logger = myView.findViewById(R.id.logger);
    logger.setText(mViewModel.GetData());
    // using only intents
    edti = myView.findViewById(R.id.edti);
    scani = myView.findViewById(R.id.scani);
    encodei = myView.findViewById(R.id.encodei);
    Button.OnClickListener mScan = new Button.OnClickListener() {

        public void onClick(View v) {
            Intent intent = new Intent("com.google.zxing.client.android.SCAN");
            // intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
            intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
            startActivityForResult(intent, 0);
        }
    };
    scani.setOnClickListener(mScan);
    Button.OnClickListener mEncode = new Button.OnClickListener() {

        public void onClick(View v) {
            encodeBarcode("TEXT_TYPE", edti.getText().toString());
        }
    };
    encodei.setOnClickListener(mEncode);
    // using the intentintegrator
    scanii = (Button) myView.findViewById(R.id.scanii);
    encodeii = (Button) myView.findViewById(R.id.encodeii);
    Button.OnClickListener scanQRCode = new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            IntentIntegrator integrator = new IntentIntegrator(getActivity());
            integrator.initiateScan(IntentIntegrator.QR_CODE_TYPES);
        }
    };
    scanii.setOnClickListener(scanQRCode);
    Button.OnClickListener mEncodeii = new Button.OnClickListener() {

        public void onClick(View v) {
            encodeBarcode2("TEXT_TYPE", edti.getText().toString());
        }
    };
    encodeii.setOnClickListener(mEncodeii);
    return myView;
}
Also used : Button(android.widget.Button) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 52 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project AudioVideo by JimSeker.

the class PlayFragment method onCreateView.

public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    myViewModel = new ViewModelProvider(getActivity()).get(videoViewModel.class);
    final View myView = inflater.inflate(R.layout.fragment_play, container, false);
    vv = myView.findViewById(R.id.videoView);
    vv.setMediaController(new MediaController(getActivity()));
    myContext = getContext();
    mySpinner = myView.findViewById(R.id.spinner);
    mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Uri videoUri = Uri.parse(mfiles.get(position));
            vv.setVideoURI(videoUri);
            vv.start();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            vv.stopPlayback();
        }
    });
    myViewModel.getfiles().observe(getActivity(), new Observer<List<String>>() {

        @Override
        public void onChanged(List<String> files) {
            mfiles = files;
            adapter = new ArrayAdapter<String>(myContext, android.R.layout.simple_spinner_item, files);
            // set the dropdown layout
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mySpinner.setAdapter(adapter);
        }
    });
    return myView;
}
Also used : MediaController(android.widget.MediaController) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) VideoView(android.widget.VideoView) Uri(android.net.Uri) AdapterView(android.widget.AdapterView) List(java.util.List) ArrayAdapter(android.widget.ArrayAdapter) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 53 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project firebase-android-sdk by firebase.

the class FragmentActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Listening on FragmentManager's FragmentLifeCycleCallbacks
    registerListeners();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fragment);
    Toolbar toolbar = findViewById(R.id.toolbar_fragment_activity);
    setSupportActionBar(toolbar);
    BottomNavigationView navView = findViewById(R.id.nav_view);
    // Passing each menu ID as a set of Ids because each
    // menu should be considered as top level destinations.
    AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications).build();
    NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_fragment);
    // Listening on navigation events using NavController
    navController.addOnDestinationChangedListener((controller, destination, arguments) -> {
        Log.d("Navigation", destination.getLabel().toString() + "Fragment");
    });
    NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
    NavigationUI.setupWithNavController((BottomNavigationView) findViewById(R.id.nav_view), navController);
    model = new ViewModelProvider(this).get(SharedViewModel.class);
}
Also used : BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) NavController(androidx.navigation.NavController) Toolbar(androidx.appcompat.widget.Toolbar) AppBarConfiguration(androidx.navigation.ui.AppBarConfiguration) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 54 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project firebase-android-sdk by firebase.

the class DashboardFragment method onCreateView.

public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    dashboardViewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(DashboardViewModel.class);
    View root = inflater.inflate(R.layout.fragment_dashboard, container, false);
    final TextView textView = root.findViewById(R.id.text_dashboard);
    dashboardViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {

        @Override
        public void onChanged(@Nullable String s) {
            textView.setText(s);
        }
    });
    // Gif loading for testing
    sharedViewModel = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);
    final ImageView imageView = root.findViewById(R.id.img_dashboard);
    sharedViewModel.getImageSrc().observe(getViewLifecycleOwner(), new Observer<String>() {

        @Override
        public void onChanged(String s) {
            Glide.with(requireActivity()).load(s).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).into(imageView);
        }
    });
    return root;
}
Also used : SharedViewModel(com.googletest.firebase.perf.testapp.SharedViewModel) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 55 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project firebase-android-sdk by firebase.

the class NotificationsFragment method onCreateView.

public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    notificationsViewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(NotificationsViewModel.class);
    View root = inflater.inflate(R.layout.fragment_notifications, container, false);
    final TextView textView = root.findViewById(R.id.text_notifications);
    notificationsViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {

        @Override
        public void onChanged(@Nullable String s) {
            textView.setText(s);
        }
    });
    // Gif loading for testing
    sharedViewModel = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);
    final ImageView imageView = root.findViewById(R.id.img_notifications);
    sharedViewModel.getImageSrc().observe(getViewLifecycleOwner(), new Observer<String>() {

        @Override
        public void onChanged(String s) {
            Glide.with(requireActivity()).load(s).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).into(imageView);
        }
    });
    // Recycler View setup
    RecyclerView numbersList = root.findViewById(R.id.rv_fragment_notifications);
    LinearLayoutManager layoutManager = new LinearLayoutManager(requireActivity());
    ListAdapter listAdapter = new ListAdapter(NUM_LIST_ITEMS);
    numbersList.setLayoutManager(layoutManager);
    numbersList.setHasFixedSize(true);
    numbersList.setAdapter(listAdapter);
    return root;
}
Also used : SharedViewModel(com.googletest.firebase.perf.testapp.SharedViewModel) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) RecyclerView(androidx.recyclerview.widget.RecyclerView) ImageView(android.widget.ImageView) ListAdapter(com.googletest.firebase.perf.testapp.ListAdapter) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

ViewModelProvider (androidx.lifecycle.ViewModelProvider)159 View (android.view.View)38 TextView (android.widget.TextView)28 BottomSheetEvent (xyz.zedler.patrick.grocy.model.BottomSheetEvent)25 Intent (android.content.Intent)24 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)24 InfoFullscreenHelper (xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper)23 Nullable (androidx.annotation.Nullable)21 Snackbar (com.google.android.material.snackbar.Snackbar)20 ClickUtil (xyz.zedler.patrick.grocy.util.ClickUtil)20 Bundle (android.os.Bundle)18 RecyclerView (androidx.recyclerview.widget.RecyclerView)18 Toolbar (androidx.appcompat.widget.Toolbar)16 SnackbarMessage (xyz.zedler.patrick.grocy.model.SnackbarMessage)16 Uri (android.net.Uri)10 ViewGroup (android.view.ViewGroup)10 NonNull (androidx.annotation.NonNull)10 Handler (android.os.Handler)9 FirebaseUiException (com.firebase.ui.auth.FirebaseUiException)8 IdpResponse (com.firebase.ui.auth.IdpResponse)8