Running a custom animation between Android Activities - android

So I know you can use your own animation between activities using the overidePendingTransition method. I set up a transition between two activites and it works perfect on my emulator but I see no transition when I flash the app on to my phone. How can this be?
My emulator is running 2.2 as is my phone
Here is my onCreate method
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button button = (Button) findViewById(R.id.close);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(ActivityTransitionActivity.this, ActivityTwo.class);
ActivityTransitionActivity.this.startActivity(myIntent);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
});
}

In your style.xml define your animation
<style name="Animation.CustomAnimation">
<item name="android:activityOpenEnterAnimation">#anim/slide_in_left</item> When opening a new activity, this is the animation that is run on the next activity
<item name="android:activityOpenExitAnimation">#anim/slide_out_right</item>When opening a new activity, this is the animation that is run on the previous activity (which is exiting the screen)
<item name="android:activityCloseEnterAnimation">#anim/slide_in_right</item>When closing the current activity, this is the animation that is run on the next activity (which is entering the screen).
<item name="android:activityCloseExitAnimation">#anim/slide_out_left</item>When closing the current activity, this is the animation that is run on the current activity (which is exiting the screen).
</style>
<style parent="android:style/Theme.Light.NoTitleBar.Fullscreen" name="app_theme">
<item name="android:windowBackground">#drawable/splash</item>
<item name="android:windowAnimationStyle">#style/Animation.CustomAnimation</item>
</style>
<application android:icon="#drawable/icon" android:label="#string/app_name"
android:theme="#style/app_theme">
apply app_theme to your application in android manifest

I had the same problem (on a samsung galaxy s). I found my answer at Activity animation not working in Galaxy Tab
Turns out animations are turned off by default on samsung devices. (It's a setting: Go to Settings -> display -> animations and then turn on the All animations and you will be able to see the animations)

Try this,
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(v.getContext(),
ActivityTwo.class);
startActivityForResult(myIntent, 0);
overridePendingTransition(R.anim.zoomextra, 0);
finish();
}
});

Related

Change theme in Android app [duplicate]

This question already has answers here:
Switching application-wide theme programmatically?
(2 answers)
Closed 7 years ago.
I want dynamically change the theme of my app with buttons, so I implemented this:
sharedPreferences = getSharedPreferences("VALUES",MODE_PRIVATE);
int theme = sharedPreferences.getInt("THEME",2);
switch (theme){
case 1: setTheme(R.style.AppTheme);
break;
case 2: setTheme(R.style.AppTheme_AppBarOverlay);
break;
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tutotial);
And this is the code of the buttons:
tb1 =(Button) findViewById(R.id.button2);
tb1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sharedPreferences.edit().putInt("THEME",1).apply();
Intent intent = new Intent(tutotial.this, tutotial.class);
startActivity(intent);
}
});
tb2 =(Button) findViewById(R.id.button3);
tb2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sharedPreferences.edit().putInt("THEME",2).apply();
Intent intent = new Intent(tutotial.this, tutotial.class);
startActivity(intent);
Intent intent1 = new Intent(tutotial.this, MainActivity.class);
startActivity(intent1);
}
});
The problem is that code just changes the theme of the activity associated and it does not make the change theme in all the app.
There is an open source podcast player called AntennaPod on github. It contains example code that does this.
The way they do it is to call ContextThemeWrapper.setTheme(int) at the beginning of each Activity.onCreate() method.
#Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(UserPreferences.getTheme());
super.onCreate(savedInstanceState);
......
}
This could be done in each activity, or by creating a base activity that does this for you on each subclass.
On closer reading of your question, this is exactly what you are doing. So I would say you are on the right track.
It also seems this has been asked before:
Switching application-wide theme programmatically?
Android - Change app Theme on onClick
I want my users to be able to switch from a dark and light theme for my entire app
All offering the same solution.
You can apply a theme to any activity by including android:theme inside activity inside manifest file.
For example:
<activity android:theme="#android:style/Theme.Dialog">
<activity android:theme="#style/CustomTheme">
And if you want to set theme programatically then use setTheme() before calling setContentView() and super.onCreate() method inside onCreate() method.
You can do this by implementing various themes and on click of button change the themes accordingly, refer this change theme programatically for assistance.

bug on show reapeted background on landscape and portrait

bg_repeat.xml:
<?xml version="1.0" encoding="UTF-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/bg_pattern"
android:tileMode="repeat" />
bg_pattern.jpg:
if i launch app in portrait mode:
and output is okey.
and if launch app in landscape mode,sometimes output(in splashScreen BG and Main BG) is like:
and second problem in this mode(LandS): i change orientation to portrait,and press back button to close app,its refresh current activity(1,2,or even 4 time via each pressing Back btn)(refresh means go back to current activity from current! )
whats wrong? is this a bug?(each two question).
bytheway its my splashScreen.java code:
public class SplashScreen extends Activity {
private int _splashTime = 2000;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
new Handler().postDelayed(new Thread(){
#Override
public void run(){
Intent mainMenu = new Intent(SplashScreen.this, NextAct.class);
SplashScreen.this.startActivity(mainMenu);
SplashScreen.this.finish();
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
}, _splashTime);
}
}
after all i said,i use customTheme.
this is manifest xml code:
<activity android:theme="#style/CustomTheme"
android:label="#string/app_name"
android:name=".SplashScreen">
and this is part of styles.xml code:
<style name="CustomTheme" parent="#android:style/Theme.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#drawable/bg_repeat</item>
</style>
but don't test this new app,that has problem or not.
Not repeating background is a known bug which was partially fixed in ICS and fully in JB. There's a workaround, you have to wrap bitmap in layout and then set repeating in code in onCreate like this :
parent = (RelativeLayout) findViewById(R.id.parent);
Bitmap bg = BitmapFactory.decodeResource(this.getResources(), R.drawable.bg_pattern);
BitmapDrawable patternRepeat = new BitmapDrawable(bg);
patternRepeat.setTileModeX(Shader.TileMode.REPEAT);
patternRepeat.setTileModeY(Shader.TileMode.REPEAT);
parent.setBackgroundDrawable(patternRepeat);

android "state_pressed" works only in second attempt

I've one menu button and a motion class for a longer state_pressed state (0,5 sec.). So long all works fine, but one problem occurs :
I've to press first time on my button, state_pressed doesn't work at this first time then on the second attempt my code works correctly and state_pressed works with 0,5 seconds duration.
How can I make it that it works on the first press? I think tehre is a problem with the hover.xml file and in combination with the setBackgroundDrawable?
Thanks all in advance for ur help!
This is my hover.XML drawable
<?xml version="1.0" encoding="utf-8"?>
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="#drawable/buttonstyle_pressed" />
<item android:drawable="#drawable/buttonstyle" />
And this is my java code
Button menubutton_start;
menubutton_start = (Button) FindViewById(R.id.menustart);
menubutton_start.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
menubutton_start.setBackgroundDrawable(getResources().getDrawable(R.drawable.hover));
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
Intent myIntent = new Intent(GameActivity.this, NextActivity.class);
GameActivity.this.startActivity(myIntent);
}
}, 500); // end of Handler new Runnable()
} // end of OnClick()
}); // end of setOnClickListener
The pressed state will happen automatically if you apply that style to the button.
You shouldn't have to manually set the pressed state in your code at all.

In Android: How do you show layout twice using intent?

Let's pretend this was my Java Class...
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button ScreentwoGameButton = (Button) findViewById(R.id.screentwo);
ScreentwoGameButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent ScreentwoGameIntent = new Intent(Main.this, Screentwo.class);
startActivity(StartGameIntent);
}
});
How do i use this code below but the right way like.
So let's put an example if I click screentwo button the screentwo.xml will show and it will allow me to click inside if any buttons are available. Instead just stare what's in the layout.
I don't want to use the Activity to activity cause the whole point is i'm trying to avoid the flashing looking feel going to another java class.
If you look at the moron test game on Android it says example: press the blue button then red and then green, so if u press the blue button the screen will remain and not flash at all but the image of the blue button will disappear and I'm allowed to click the red and then green.
Hope that helped.
Thanks
Wahid
Button ScreentwoButton = (Button) findViewById(R.id.screentwo);
ScreentwoButton.setOnClickListener(new OnClickListener() {
private Uri Uri;
#Override
public void onClick(View v) {
setContentView(R.layout.Screentwo);
Uri uri=Uri;
Intent i=new Intent(Intent.ACTION_VIEW, uri);
mSoundManager.playSound(1);
}
});
try to use:
setContentView(R.layout.next layout); in your button click.
You could use the viewflipper class and add the different layouts as childs to the viewflipper
and set the active child. Using setcontentView will be trouble some when you use findViewById for a old layout. As findViewById will look in the layout that is specified by setContentView

Right justify text in AlertDialog

I have been trying to alter my AlertDialog so that it will show the text right justified (for Hebrew).
With inazaruk's help here: Right justify text in AlertDialog
I managed to get the dialog showing but it only works correctly in the emulator (Eclipse).
When I move it onto my device (Xpersia X10a) the alert box appears at the top of the screen with the background blocking out everything behind it.
The image on the emulator:
The image on my device:
Code:
public class test extends Activity {
/** Called when the activity is first created. */
public class RightJustifyAlertDialog extends AlertDialog {
public RightJustifyAlertDialog(Context ctx) {
super(ctx, R.style.RightJustifyTheme); } }
#Override
public void onCreate(Bundle savedInstanceState) {
final Context con = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog dialog = new RightJustifyAlertDialog(con);
dialog.setButton("button", new OnClickListener(){
public void onClick(DialogInterface arg0, int arg1)
{
}
});
dialog.setTitle("Some Title");
dialog.setMessage("Some message");
dialog.show();
}
});
}
}
Styles:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="RightJustifyTextView" parent="#android:style/Widget.TextView">
<item name="android:gravity">right|center_vertical</item>
<item name="android:layout_centerVertical">true</item>
</style>
<style name="RightJustifyDialogWindowTitle" parent="#android:style/DialogWindowTitle" >
<item name="android:gravity">right|center_vertical</item>
<item name="android:layout_centerVertical">true</item>
</style>
<style name="RightJustifyTheme" parent="#android:style/Theme.Dialog.Alert">
<item name="android:textViewStyle">#style/RightJustifyTextView</item>
<item name="android:windowTitleStyle">#style/RightJustifyDialogWindowTitle</item>
</style>
</resources>
My device is working with Android 2.1-update1 and the emulator is set to same.
One simple thing to rule out... Check you device's other apps to see if all of them have had their AlertDialog background alpha transparencies removed. You can try deleting something in the default mail application, or other applications that also have a long press delete for items. I wouldn't see the need to change this styling, but you never know what Carriers are going to do these days.

Categories

Resources