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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations