Slide transition in new Android L API - android

I am trying new Android L API in particular transitions. The best experience I have with "Fade" but "Slide.RIGHT" behaves really weird… When screen fly in it brings firstly screen title at the bottom, then title jump to the top of the screen and rest of the screen is appear…
I did not use custom transition, just basic one. Screen I use for testing has just couple of TextView, EditText and button. But even if I change Google ActivitySceneTransitionBasicSample from custom transition to basic Slide.RIGHT it behave the same strange way…
Is somebody managed to implement nice Slide transition? In my case I need to Slide completely different screens. There are no elements I can share.
My code is:
First Activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
Slide transitionEnter = new Slide();
transitionEnter.setSlideEdge(Gravity.RIGHT);
transitionEnter.setDuration(1000);
Window currentW = getWindow();
currentW.setEnterTransition(transitionEnter);
currentW.setExitTransition(transitionEnter);
getWindow().setAllowEnterTransitionOverlap(true);
getWindow().setAllowExitTransitionOverlap(true);
setContentView(R.layout.slide_test_view);
}
public void buttonLAction(View view){
Utils.startActivity(this, SecondSlideTestActivity.class);
}
Second Activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
Slide transitionEnter = new Slide();
transitionEnter.setSlideEdge(Gravity.RIGHT);
transitionEnter.setDuration(1000);
Window currentW = getWindow();
currentW.setEnterTransition(transitionEnter);
currentW.setExitTransition(transitionEnter);
getWindow().setAllowEnterTransitionOverlap(true);
getWindow().setAllowExitTransitionOverlap(true);
setContentView(R.layout.second_slide_test_view);
}

Just a small suggestion, doesn't make it perfect but looks better in my opinion:
Use different edges for enter and exit transition, e.g.:
transitionEnter.setSlideEdge(Gravity.RIGHT);
transitionExit.setSlideEdge(Gravity.LEFT);
I did that and for me it looks kinda okay then. Hope this helps!

Related

Image slide show in Android

I am making an application in android for picture slide show. I have tried the following code:
class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Drawable backgrounds[] = new Drawable[2];
Resources res = getResources();
backgrounds[0] = res.getDrawable(android.R.drawable.btn_star_big_on);
backgrounds[1] = res.getDrawable(android.R.drawable.btn_star_big_off);
TransitionDrawable crossfader = new TransitionDrawable(backgrounds);
ImageView image = (ImageView)findViewById(R.id.image);
image.setImageDrawable(crossfader);
crossfader.startTransition(3000);
}
}
This code successfully bring the new image on top but previous image is not faded out.
Can anyone help me on it?
You need to enable the cross fade on your transition to have both of your images fade. Use the method setCrossFadeEnabled to enable it by setting it tu true.
See documentation here http://developer.android.com/reference/android/graphics/drawable/TransitionDrawable.html#setCrossFadeEnabled(boolean)

Force Main-Layout to Inflate

I'll try another shot. Hopefully now i get the answere i totally Need.
Just imagine:
I have a widget which calls(after onClick) a blank activity with no hardcoded code, just a Relative Layout with some views.(Layout provided by XML-layout-file).
My Activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myLayout);
When i add a for-loop to the onCreate-Method which adds 50 Buttons(take no care about layoutparams, orientation and so on). Just 50 simply Buttons
Like:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myLayout);
for(int i = 0; i<50; i++) {
Button btn = new Button(this);
myLayout.add(btn);
}
I recognize that he only Shows the activity on the Screen until he finished to add all the Buttons.
My Question is: How can i prevent this!? How can i Show up the Activity with the Content from the XML-layout file and then(ONLY then) add one Button after another to the Layout.
Is this possible? If so, do i neew to redraw the whole activity and so on. Please give me advise to my issue.

How to make Only Some Views touchable while making the others (like RelativeLayout) not touchable

Window w = getWindow();
w.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
The above code is to make the whole window not touchable.
However, the button inside this window is also being not Touchable, while I want it to be clickable.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Window w = getWindow();
w.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
b = (Button)findViewById(R.id.button1);
b.setClickable(true);
b.setOnClickListener(this);
}
How can I make on that button touchable?
The other views in your layout shouldnt register onclicks unless you register them to. Whats the behavior you expected from setting the entire window to not be touchable?
EDIT: this code can be used to set any settings on just about any view as long as you want them all the same. For setting a number of views to be non clickable just throw them all into a view[] array and itterate through them like this
TextView a,b,c;
EditText d,e,f;
RelativeLayout g,h,i;
#Override
protected void onCreate(){
//intstatiate and inflate all your views....you should know how to do that
View[] viewHolder = {a,b,c,d,e,f,g,h,i};
for(int i = 0; viewHolder.length>i; i++){
viewHolder[i].setClickable(false);
}
This will do exactly what you want but unless the other views are taking focus you shouldnt have to do that. But it will work.
By using this code:
Window w = getWindow();
w.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
The whole window will be set as not touchable. Alternatively, you can use onClickListener for each View you added in your XML. even layouts can have their own click listener

How to make a page flip like animation when changing between activities?

How can I make a page flip like animation when moving from one activity to other? On some ios applications I saw this, but when I searched for android I could not find any tutorials or code snippets for this.
Please help
Yes it is possible . Please look at this tutorial.
Here's a tutorial on how to add an animation when transistioning between two activities. However, instead of using a translate animation like in the article, you'll want to use a rotate animation.
The flip animation for Activity doesn't exist on Android..sorry!
Here is demo code from sdk:
/**
* <p>Example of using a custom animation when transitioning between activities.</p>
*/
public class Animation extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animation);
// Watch for button clicks.
Button button = (Button)findViewById(R.id.fade_animation);
button.setOnClickListener(mFadeListener);
button = (Button)findViewById(R.id.zoom_animation);
button.setOnClickListener(mZoomListener);
}
private OnClickListener mFadeListener = new OnClickListener() {
public void onClick(View v) {
// Request the next activity transition (here starting a new one).
startActivity(new Intent(Animation.this, Controls1.class));
// Supply a custom animation. This one will just fade the new
// activity on top. Note that we need to also supply an animation
// (here just doing nothing for the same amount of time) for the
// old activity to prevent it from going away too soon.
overridePendingTransition(R.anim.fade, R.anim.hold);
}
};
private OnClickListener mZoomListener = new OnClickListener() {
public void onClick(View v) {
// Request the next activity transition (here starting a new one).
startActivity(new Intent(Animation.this, Controls1.class));
// This is a more complicated animation, involving transformations
// on both this (exit) and the new (enter) activity. Note how for
// the duration of the animation we force the exiting activity
// to be Z-ordered on top (even though it really isn't) to achieve
// the effect we want.
overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
}
};
}
all code is at apidemo/app/ ,:)

Why does my animation freeze when returning to activity containing it?

I'm still sort of new with Android, so forgive me if it's an obvious mistake. In this activity I'm using ViewPager to horizontally scroll through three layouts containing an ImageButton that has an animated background depending on its current state. When the button is pressed, it starts a new activity. However, when I hit the back button to go back to the activity containing the animation from the new activity, sometimes the animation freezes or plays back faster than it should. I wrote a method for starting up the animation that I use in onWindowFocusChanged(), and onRestart(). I'm working in Android 2.1 (API 7).
This is my code:
public class CopyOfWorld extends Activity{
MediaPlayer muzak;
Boolean mSwitch = false;
ImageButton holmes;
AnimationDrawable holmesAnimation;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.world);
Preferencer pp = (Preferencer)getApplicationContext();
ViewPagerAdapter adapter = new ViewPagerAdapter();
ViewPager myPager = (ViewPager) findViewById(R.id.viewpager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(1);
if(pp.getMuzak()){
mSwitch = true;
muzak = MediaPlayer.create(CopyOfWorld.this, R.raw.level1);
muzak.setLooping(true);
muzak.start();
}
}
public void clicker(View v){
Intent myIntent = new Intent(CopyOfWorld.this , Subworld.class);
startActivityForResult(myIntent, 0);
}
#Override
public void onWindowFocusChanged(boolean hasFocus){
super.onWindowFocusChanged(hasFocus);
beginRender();
}
#Override
protected void onPause(){
super.onPause();
if(mSwitch){
muzak.release();
}
}
#Override
protected void onRestart(){
super.onRestart();
Preferencer pp = (Preferencer)getApplicationContext();
if(pp.getMuzak()){
muzak = MediaPlayer.create(CopyOfWorld.this, R.raw.level1);
muzak.setLooping(true);
muzak.start();
}
beginRender();
}
public void beginRender(){
ImageButton holmes = (ImageButton) findViewById(R.id.subworlder);
StateListDrawable background = (StateListDrawable) holmes.getBackground();
Drawable current = background.getCurrent();
if(current instanceof AnimationDrawable){
holmesAnimation = (AnimationDrawable) current;
holmesAnimation.start();
}
}
}
I've tried calling the method beginRender() under ()onResume, but then the app simply crashes.
Could anyone point me in the right direction?
EDIT:
I've been tweaking the code here and there, unfortunately to no avail. But I did notice a pattern in the behavior of the animation. When I press down on the ImageButton or hold it so that it goes from its default animation to its pressed or focused animation then move my finger away from the button so that it doesn't start up the new activity, it sometimes behaves very much as I described at the beginning of this post (i.e. it's supposed to return to its default animation, but instead plays back at twice the rate, chokes up, or doesn't play at all.)
Currently the xml that contains these ImageButtons defines their backgrounds as the animations and have no source (src). But when I change the background to transparent and the src to the animations, the app crashes.
Any clues?

Categories

Resources