How can I implement fragment animation? - android-fragments

I have read the documentation for the Animate transitions between fragments and implemented it into my code. I have seen videos on how to make animations when switching from fragment to another,
but nothing happens.
This is the code in my Main Activity for replacing the fragment by another:
getSupportFragmentManager().beginTransaction().replace(R.id.frag_container, fragment)
.setCustomAnimations(R.anim.slide_in, R.anim.slide_out)
.commit();
I tried to use the addToBackstack() method to see if it has something with the animation, but nothing happens.
The fragment in the code above is made when I press on a BottomNavigationView item.
Here's the XML content for the animation in and out:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#android:integer/config_shortAnimTime"
android:interpolator="#android:anim/decelerate_interpolator"
android:fromXDelta="100%"
android:toXDelta="0%" />
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#android:integer/config_shortAnimTime"
android:interpolator="#android:anim/decelerate_interpolator"
android:fromXDelta="0%"
android:toXDelta="100%" />

The problem was that I replaced the fragment first and then I applied
the animation. It has an order:
getSupportFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.slide_in,R.anim.slide_out)
.replace(R.id.frag_container, fragment)
.comit()

Related

Focusing button by default in android tv

I have an Android tv Layout with two buttons:
Buttons are not focused
I want one button to be focused by default:
Focusing choose a TV button by default.
I have tried a few methods.
In java file
final Buttonspinner spinner = findViewById(R.id.choose_folder);
spinner.requestFocus();
spinner.setFocusable(true);
In xml
android:state_focused="true"
Still, it's not getting focused by default.
How can I achieve this?
In code:
spinner.setFocusableInTouchMode(true);
spinner.setFocusable(true);
spinner.setFocusedByDefault(true);
spinner.requestFocus();
Alternatively in XML:
<Button
android:id="#+id/choose_folder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/choose"
android:focusableInTouchMode="true"
android:focusable="true"
android:focusedByDefault="true">
<requestFocus/>
</Button>
Maybe a bit overkill, but either one of these should cover all bases.

Center text of a Xamarin Forms TabbedPage Title

i have a TabbedPage with multiple Child-Pages, with a title each.
When the title is short enough to be single line the text gets centered perfectly, but as soon as the text needs more than 1 line it is no longer centered.
Can anyone tell me how to fix this?
I think it's impossible to do in common way for all platforms, and you have to do it in platform specific way.
For android project I did it in such way:
In file Styles.xml from folder Resources/values I added style
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomTheme"
parent="#android:style/Theme.Holo">
<item name="android:actionBarTabTextStyle">#style/CustomTab</item>
</style>
<style name="CustomTab"
parent="#android:style/Widget.Holo.ActionBar.TabText">
<item name="android:gravity">center</item>
</style>
</resources>
And in MainActivity.cs I added
[Activity(Theme = "#style/CustomTheme")]
For Windows phone I found this article https://nocture.dk/2014/12/10/xamarin-forms-customizing-tabbed-page-header-title-windows-phone/, but didn't try it.
For iOS i didn't check too http://jfarrell.net/2015/02/25/customizing-the-tab-bar-on-ios-with-xamarin-forms/.

Flex / ActionScript - Click Through An Element To Application Behind Air App

I'm attempting to build a desktop AIR app using flex/Action Script in Flash Builder.
My desired functionality is this:
- transparent background
- semitransparent (alpha 0.5) item/element that ignores all mouse events and "passes clicks through" to the application behind the app
So essentially what I want to have is that the element handles mouse events in exactly the same way a transparent background does - ie. it is like you're clicking on the application behind
Here is a code example of what I have tried. In the below example clicking on the button fires the "window clicked" alert to demonstrate that the click is being ignored by the button and reaching the window with the transparent background. When I remove the click handler though, clicking on the button does not result in the click being passed through to application behind, like a click anywhere else on the transparent background does.
Any ideas?
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
alwaysInFront="true"
creationComplete="maximize();">
<fx:Style>
#namespace s "library://ns.adobe.com/flex/spark";
s|WindowedApplication
{
skinClass:ClassReference("spark.skins.spark.SparkChromeWindowedApplicationSkin");
background-color:#999999;
background-alpha:"0";
}
</fx:Style>
<fx:Script>
import mx.controls.Alert;
public function windowClicked():void{
Alert.show("window clicked");
}
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Window id="mainWindow" height="100%" width="100%" mouseChildren="false" backgroundAlpha="0">
<s:Button label="Click Through Me Please" alpha="0.5"/>
</s:Window>
</s:WindowedApplication>
I made a quick comment to your question but thought I would elaborate in an answer.
Since I'm sure you are going to do more than your example up there, here is how those properties work:
mouseEnabled="false" - this says you can't click me but you can click my children. This works well when you are disabling a single item or want click event to pass through an item to it's children.
mouseChildren="false" - this says you can't click my children. This is useful if you are goin to build complex overlays in your app that might contain 10 display objects and want want the mouse to ignore them all.
Hope this helps!

Widget in Adobe AIR position bottom-right

Thanks in advance.
I'm a graphic designer.
I have to make a widget that shows some icons.
I've made an icon that starts in systemtray, all I need is to make the window application that start at bottom over the icon.
I don't know anything about flex...
I've done this so far in application.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<application xmlns="http://ns.adobe.com/air/application/1.0">
<id>com.widgetStatus.widgetStatus</id>
<filename>widgetStatus</filename>
<name>widgetStatus</name>
<description>Test</description>
<version>0.1a</version>
<initialWindow>
<content>html/index.html</content>
<title>widgetStatus</title>
<systemChrome>none</systemChrome>
<transparent>true</transparent>
<visible>true</visible>
<minimizable>false</minimizable>
<resizable>false</resizable>
<width>400</width>
<height>300</height>
<x>1268</x>
<y>646</y>
</initialWindow>
<icon>
<image128x128>/icons/widget128.png</image128x128>
<image48x48>/icons/widget48.png</image48x48>
<image32x32>/icons/widget32.png</image32x32>
<image16x16>/icons/widget16.png</image16x16>
</icon>
The application starts over the systray but only with my resolution obliuvsly.
Now I need to do something like that:
Positioning Flex/AIR Desktop App Window to the bottom right corner
How can I work with that script in flex? I understand that I can put the code into xml.
Thanks.

Flex: rotating buttons and changing focus

I've got a problem with rotated buttons in Flex. They seem to contaminate other components' focus rectangles.
Take the following source code, which couldn't be much simpler:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:VBox width="100%" height="100%">
<mx:Spacer height="100" />
<mx:Button rotation="10" />
<mx:TextArea rotation="0" />
</mx:VBox>
</mx:WindowedApplication>
Now execute it. Click in the text area, the focus rectangle is correct. Press tab twice, the focus rectangle aroung the TextArea is rotated!
Is there a fix for this, or should I avoid rotating buttons altogether?
I'm using Flex SDK 3.5.
Thanks,
Daniel
I as well recently stumbled upon this bug. Here's a link to suggested fix.
However, I was wondering if there's a more general solution rather then extending each and every component and overriding adjustFocusRect.
I came up with extending FocusManger and overriding the getter for focusPane as follows:
override public function get focusPane():Sprite
{
var fp:Sprite = super.focusPane;
if (fp && fp.numChildren != 0)
fp.getChildAt(0).rotation = 0;
return super.focusPane;
}
and set it as application's focus manager:
private function onPreinitialize():void
{
application.focusManager = new FocusManagerEx(this);
}
This seems to work, though would be nice if some expert could tell if there aren't any pitfalls I'm not aware of.
Seems like a bug in Flex SDK. I see next options:
disable focus rectangles with focusSkin="{null}"
implement your own skin and handle rotations correctly
move to Spark, since 3.5 is the (currently)
last SDK of third generation
try to fix it yourself (I feel it will be
tricky...)
Also, you may file a bug in Adobe's tracker, but they're deep into 4-th generation of Flex.
Update: 3.6 nightly build contains this bug, too.

Resources