destroy fragment completely Android - android-fragments

i have an activity and i want to change fragments depending on the orientation of the device. so here is my code:
FragmentTransaction ft = getFragmentManager().beginTransaction();
if(getFragmentManager().findFragmentById(R.id.calendrier_calendrierhebdomadaire) != null){
Fragment fragment = getFragmentManager().findFragmentById(R.id.calendrier_calendrierhebdomadaire);
ft.remove(fragment);
}
ft = getFragmentManager().beginTransaction();
if(getResources().getConfiguration().orientation == 1){
ft.add(R.id.calendrier_planifications, new Planifications());
}
else if(getResources().getConfiguration().orientation == 2){
ft.add(R.id.calendrier_planifications, new Planifications());
ft.add(R.id.calendrier_calendrierhebdomadaire, new Test());
}
ft.commit();
I am using two different layout files : layout/calendrier.xml containing two LinearLayouts, layout-port/calendrier.xml containing 1 LinearLayout
the problem is when i start my application in the landscape mode (orientation == 2) and switch it to the portrait mode (orientation == 1), i still have methods of my fragment Test executed.
How to completely remove the Test Fragment ?

You have created two transactions, but only committed the second one. Try removing this line:
ft = getFragmentManager().beginTransaction();

Related

ImageCapture cameraX orientation detect when is locked

I want to capture an Image and a Video using the CameraX library. By following the documentation i have no problem implementing the preview and the capture use cases. The code i use is the following.
private fun startCamera() {
cameraProviderFuture = ProcessCameraProvider.getInstance(this)
cameraProviderFuture.addListener({ setUpCamera() }, cameraExecutor)
}
private fun setUpCamera() {
cameraProvider = cameraProviderFuture.get()
bindPreview()
}
private fun bindPreview() {
preview = Preview.Builder().build().also {
it.setSurfaceProvider(binding.cameraPreview.surfaceProvider)
}
imageCapture = ImageCapture.Builder()
.setFlashMode(flashMode)
.setCaptureMode(CAPTURE_MODE_MAXIMIZE_QUALITY)
.build()
videoCapture = ...
bindCamera()
}
private fun bindCamera() {
cameraSelector = selectExternalOrBestCamera()
cameraProvider.unbindAll()
camera = cameraProvider.bindToLifecycle(this, cameraSelector, preview, imageCapture, videoCapture)
Now, let's say that i have locked my device orientation from the menu panel. So if i rotate de device, the applications do not rotate at all. In that case, if a capture an Image, the captured image which i save and i want to send to a Server is rotated by 90 degrees,, which is reasonable since i rotated the device and capture a photo.
As i can see, in other applications (like Whatsapp) the same senario does not happen since they show the preview image correctly rotated after the capture. How can i solve that issue?
So finally i found the solution.
val rotation = display?.rotation ?: Surface.ROTATION_0
val isLandscape = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270
imageCapture = ImageCapture.Builder()
.setFlashMode(flashMode)
.setCaptureMode(CAPTURE_MODE_MAXIMIZE_QUALITY)
.setTargetRotation(rotation)
.setTargetResolution(
if (isLandscape)
Size(1920, 1080)
else
Size(1080, 1920)
)
.build()
That gives me the preview image that i capture in the desired orientation

Click & Drag Mechanism

I need help with GameMaker Studio 2 v2.3.2.556 project.
My clicking & dragging mechanism has two objects: an object called obj_iron that is being dragged, and an object called obj_cursor that is invisible and always follows the mouse. When I use the cursor to drag the iron, nothing happens. How do I make it so I can drag the iron using the cursor?
Code in obj_cursor in the Step Event
//Making the cursor move toward the mouse
global.picked_up_iron = 0
x = mouse_x
y = mouse_y
//Making the cursor small
image_xscale = 0.1
image_yscale = 0.1
//Checking if the cursor collided with obj_iron
if place_meeting(x,y,obj_iron)
{
//Checking if the mouse is held and the cursor is not collided with another obj_iron
if mouse_check_button(mb_left) and (global.picked_up_iron == 0 or global.picked_up_iron == other)
{
//Moving the dragged piece of obj_ironto the obj_cursor's location
var picked_up_iron = other
picked_up_iron.x = x - picked_up_iron.sprite_width / 2
picked_up_iron.y = y - picked_up_iron.sprite_height / 2
//Telling every the object what the dragged piece of obj_iron is
global.picked_up_iron = picked_up_iron
}
}
else if !mouse_check_button(mb_left)
{
//Resetting the value of the current piece of obj_iron
global.picked_up_iron = 0
}
If there are multiple of the same object in the same room, then place_meeting() does not know which kind of object is selected.
Maybe you can try out Instance_Place
var iron = instance_place(x, y, obj_iron);
This way, the iron returns the object the cursor is currently colliding with.

How to get two media stream from one File (for Custom Mixer)

There is one file with two video stream.
I want to mix these two stream to make one output stream.(using media session)
I think we can write the topology as shown below.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms701605(v=vs.85).aspx
IMFActivate *pSinkActivate = NULL;
IMFTopologyNode *pOutputNode = NULL;
pPD->GetStreamDescriptorCount(&cSourceStreams);
// For each stream, create the topology nodes and add them to the topology.
for (DWORD i = 0; i < cSourceStreams; i++)
{
IMFStreamDescriptor *pSD = NULL;
IMFTopologyNode *pSourceNode = NULL;
pPD->GetStreamDescriptorByIndex(i, &fSelected, &pSD);
// Create the media sink activation object.
if (i == 0)
CreateMediaSinkActivate(pSD, hVideoWnd, &pSinkActivate);
// Add a source node for this stream.
AddSourceNode(pTopology, pSource, pPD, pSD, &pSourceNode);
// Create the output node for the renderer.
if (i == 0)
AddOutputNode(pTopology, pSinkActivate, 0, &pOutputNode);
// Connect the source node to the output node.
pSourceNode->ConnectOutput(0, pOutputNode, 0);
SafeRelease(&pSD);
SafeRelease(&pSourceNode);
}
SafeRelease(&pSinkActivate);
SafeRelease(&pOutputNode);
I don't know if I'm doing well.
please help me.
thanks.

ON/OFF button keeps toggling through states on every touch

I don´t know what I´m doing wrong, maybe I'm sitting here way too long on my project. However, I set up a settings menu in my menuScene and I want to create a simple on-off button with a texture with this code:
if ([settingsMenuNode.name isEqualToString:#"checkmark1"]) {
if (self.checkmarkBanner == NO) {
[self.menuCheckmark1 setTexture:[SKTexture textureWithImageNamed:#"menuCheckmark"]];
self.checkmarkBanner = YES;
NSLog(#"YES");
}
if (self.checkmarkBanner == YES) {
[self.menuCheckmark1 setTexture:[SKTexture textureWithImageNamed:#"menuCheckmarkEmpty"]];
self.checkmarkBanner = NO;
NSLog(#"NO");
}
}
every time I touch on the node, I get both logs for ON & OFF at the same time.
can anyone please help me out?
checkmarkBanner is my BOOL just to set whether a banner notification during the game appears or not.
ok, thank you for your quick answers, so i´ve updated my code to this (i added some NSUserDefaults):
//CheckMarkBanner
if ([settingsMenuNode.name isEqualToString:#"checkmarkBanner"]) {
if (self.checkmarkBanner == YES) {
[self.menuCheckmark1 setTexture:[SKTexture textureWithImageNamed:#"menuCheckmarkEmpty"]];
NSString *offString = #"NO";
[[NSUserDefaults standardUserDefaults]setObject:offString forKey:#"checkmark1Banner"];
self.checkmarkBanner = [[[NSUserDefaults standardUserDefaults]stringForKey:#"checkmark1Banner"]boolValue];
NSLog(#"Banner NO");
}
else {
[self.menuCheckmark1 setTexture:[SKTexture textureWithImageNamed:#"menuCheckmark"]];
NSString *onString = #"YES";
[[NSUserDefaults standardUserDefaults]setObject:onString forKey:#"checkmark1Banner"];
self.checkmarkBanner = [[[NSUserDefaults standardUserDefaults]stringForKey:#"checkmark1Banner"]boolValue];
NSLog(#"Banner YES");
}
}

Placing a floating info panel

I'm using Jame Ferreira's Google Script: Enterprise Application Essentials to create a product page (Chapter 5). I've created the app that displays thumbnails of the products all on a page, and then the info panel with more detail that pops up when the user mouses over. It's using CSS to achieve this styling.
Problem comes in when placing the info panel. It pops up in only one location, as opposed to being tied to the thumbnail with which it is associated.
Here's the code related to the info panel. I believe the problem exists in the placement of the last few lines, but have tried everything I can think of:
function onInfo(e){
var app = UiApp.getActiveApplication();
var id = e.parameter.source;
for (var i in productDetails){
if(productDetails[i].id == id){
var r = 50;
var c = 0;
var infoPanel = app.createVerticalPanel().setSize('300px', '300px');
var horzPanel = app.createHorizontalPanel();
var image = app.createImage(productDetails[i].imageUrl).setHeight('100px');
var title = app.createLabel(productDetails[i].title);
horzPanel.add(image);
horzPanel.add(title);
var description = app.createLabel(productDetails[i].description);
infoPanel.add(horzPanel);
infoPanel.add(description);
applyCSS(infoPanel, _infoPanel);
applyCSS(image, _infoImage);
applyCSS(horzPanel, _infoBoxSeparator);
applyCSS(title, _infoTitle);
applyCSS(description, _infoDescription);
app.getElementById('infoGrid').setVisible(true)
.setWidget(0,0, infoPanel);
break;
}
c++
if (c == 3){
c = 0;
r = r+250;
}
switch (c)
{
case 0:
c=250;
break;
case 1:
c=500;
break;
case 2:
c=250;
break;
}
}
var _infoLocation =
{
"top":r+"px",
"left":c+"px",}
applyCSS(infoPanel, _infoLocation);
return app;
}
You may get the position of the mouse using e.parameter.x and e.parameter.y based on which you can position the infoPanel
infoPanel.setStyleAttribute('top',e.parameter.y)
.setStyleAttribute('left',e.parameter.x).setStyleAttribute('zIndex','1')
.setStyleAttribute('position','fixed');
You may add some offset to x and y positions of mouse to display it according to your needs.
Position related parameter which you get in handler function are
e.parameter.x
e.parameter.y
e.parameter.clientX
e.parameter.clientY
e.parameter.screenX
e.parameter.screenY

Resources