animation on layout with change activity - java

What I want, when I click on the login button of the first activity the yellow part slides down and the next activity opens. when I click on the signup button of the second screen(login screen) the yellow part of the second screen slides up and the first activity (sign up Activity)opens. I have used slide-down animation on the linear layout on the first screen it works but not working smoothly. Any help??
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
mSignUpButton = findViewById(R.id.btnSigUp);
linearLayout=findViewById(R.id.linearLayout1);
mGotoLoginActivityButton=findViewById(R.id.btnLoginSignUpActivity);
slideDown= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide_down);
//listener for Login button
mGotoLoginActivityButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//setValidation();
Intent intent = new Intent(SignupActivity.this, LoginActivity.class);
startActivity(intent);
linearLayout.startAnimation(slideDown);
}
});
}

you shouldn't use two separated Activities for this purpose, use one and login and create account views should be packed into Fragments. this way will be way easier to animate between two views/fragments in on Activity, but if you really must use Activity then use Transitions (probably with shared elements), not animations, as these are working in one Activity during its runtime when visible (and you are currently running new Activity, which cover old one)

Related

Camera activity return make button behaviour lost

I'm a total beginner in Android and I tried to make an app that exploit the camera.
In this application a FloatingActionButton is the button that triggered the camera (code below).
This button is hide if the bottomsheet is expand and show if it's collapse.
All of it work perfectly the first time I use the button.
Indeed, once the picture is taken and the mainactivity is back, the button doesn't work anymore and furthermore is behavior is "lost" too (which means that the FloatingActionButton is always shown).
I don't understand what is the source of this bug.
You'll find next to this post 2 screen, one before the button is clicked and one after and the code called in my fragment that make the onclick listener of the button :
The button is hidden when the bottomsheet is expanded (before camera was used):
The button is shown, even if the bottomsheet is expanded (after camera was used):
#Override
public void onStart() {
super.onStart();
mMapsHandler = new MapsHandler(getActivity());
mBottomSheetHandler = new BottomSheetHandler(getActivity());
FloatingActionButton button = (FloatingActionButton) getActivity().findViewById(R.id.cameraButton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivity(intent); //On change d'activite
}
});

Call a Method from another Method Android

I am not sure this workaround is the correct way to achieve my goal of having a prompt text in a spinner. What happens with this application is the spinner navigates to another Activity via an Intent and when the user navigates back to the Main Activity with the spinner they have two ways back. One with a Button and a click event the other by clicking the device BACK button. I am trying to call the code in the click event from the method that manages the device BACK button
I do not know how to call the click event from the device BACK button Method
#Override
public void onBackPressed() {
Toast.makeText(getApplicationContext(),"Use BACK BUTTON\n\n"+"On the Screen",Toast.LENGTH_LONG).show();
// I want to call goBack(View view) from here
// +++++++++++++++++++++++++++++++++++++++++++
}
public void goBack(View view){
Intent i = new Intent( PageTwo.this, MainActivity.class );
startActivity( i );
}
The reason I use this Intent to navigate BACK to the Main Activity is it reloads the variables in the Spinner
It looks like goBack(View) is most likely from an onClick setup in your layout XML. Since you aren't using the view, just pass null:
#Override public void onBackPressed() {
goBack(null);
}
I don't know if I get you right, if you just want to go back to the activity which started another activity, you can just call finish() method of Activity class:
#Override
public void onBackPressed() {
finish();
}
finish() reference

Stop the sliding screen at the middle

HomeActivity.java
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
Button btnopen = (Button)findViewById(R.id.btnWindowAnimation);
btnopen.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent slideactivity = new Intent(HomeActivity.this, CartActivity.class);
Bundle bndlanimation =
ActivityOptions.makeCustomAnimation(getApplicationContext(), R.anim.animation,R.anim.animation2).toBundle();
startActivity(slideactivity, bndlanimation);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.layout.home, menu);
return true;
}
HomeActivity has a button and it will help to slide the 1st screen and bring the second screen.
animation.xml
android:fromXDelta="100%p"
android:toXDelta="25%p"
android:duration="5000"
This animation code is helping me to slide my screen after pressing the button. As shown in this video
https://www.youtube.com/watch?v=EzgGGWpRES0
I want to stop the new screen at the middle without covering the 1st screen completely.
Any suggestions? I have used another activity called cart( i haven't used fragments here)
Sounds like you want a NavigationDrawer.
You can find out more information on the Android developer site:
https://developer.android.com/design/patterns/navigation-drawer.html
https://developer.android.com/training/implementing-navigation/nav-drawer.htmlA
Your Requirement is to partially Display an Overlapping Activity on an Existing Activity. This is Possible with Sliding Menu Library (Which does not mean to technically create a floating Activity, but to create a Floating View integrated within the Sliding Menu that will be displayed partially on top on an Activity).
In case, if you are regarding this as some sort of Default Menu then please take a look at this Image
If this is your actual Requirement, then here are the details for you.
Sliding Menu Library is an OpenSource Library, you can use it for displaying a partially visible Sliding Menu on top of an Activity.
Here is the link of Sliding Menu Lib :
https://github.com/jfeinstein10/SlidingMenu
You can navigate to the example directory present in this Project for the demonstration of it's Usage.
I hope thie helps :)

Android app shows screen before LoginActivity

I am making an Android app with authentication. The startup activity is MainActivity, but when a user is not logged in I start a new activity called LoginActivity.
My problem is that if a user is not logged in and starts the app, he see's a default android app screen (title bar and empty content area) for a split second before the LoginActivity launches.
How can I fix this?
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(!userIsLoggedIn())
{
Intent LoginActivity = new Intent(getApplicationContext(), LoginActivity.class);
LoginActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(LoginActivity);
finish();
}
}
}
You can make your MainActivity translucent by setting the activity theme android:style/Theme.Translucent. Which makes the activity transparent so you won't see any thing till other activity starts.
But this has drawbacks. The animation that accours when you click to the application icon, you won't see that anymore and If your userIsLoggedIn() takes more than it should, it will look like the phone is froze for a second to the user.
For such situations, best practice is to have a splash screen activity or welcome screen activity appear as first screen for few seconds (1 or 2 sec). This screen is generally contains your company logo/image, like Facebook app. In this activity you put the logic to decide which activity to call next.
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
if(alreadyLoggedIn)
startActivity(new Intent(SplashScreenActivity.this,MainActivity.class));
else
startActivity(new Intent(SplashScreenActivity.this,LoginActivity.class));
finish();
}
}, 1000);

Show information based on what button that was pressed

I'm making a information app for Android and I can't figure out how to change a button depending on which button was pressed in a previous class.
I made this picture that shows how the app works:
After clicking the first button you get to a new class with 2 new buttons that sends you to the same class but the 3 buttons there is supposed to change depending on which one of the two buttons you pressed, the three buttons you get sent to sends you to the same class but there is a TextView that changes text depending on what button you pressed.
So I need to add some kind of information to the button (an intent?) so it knows what you pressed earlier.
I'm kinda new to Java and Android so I'm sorry if I explained in a weird way.
Thanks in advance
Each time you start a new Activity, but some extras in that intent telling the next activity what the buttons should display. In the next activity, read the extras from the intent you got, and programatically set your buttons' text accordingly.
Here's some psuedo code.
public class FirstActivity extends Activity{
//setup button 1 and two first, then set their onClickLiseners like so
View.OnClickListener clickListener = new View.OnClickListener(){
public void onClick(View view){
Intent newActivity = new Intent(FirstActivity.this, SecondActivity.class);
if(view == button1){
//add extra to intent indicating button1 was clicked
}
else{
//add extra to intent indicating button2 was clicked
}
startActivity(newActivity);
}
};
// other stuff in your activity
}
public class SecondActivity extends Activity{
protected void onCreate(Bundle icicle){
Intent startedBy = getIntent();
if(started by has the extra indicating button 1 was clicked){
//do button1 stuff
}
else{
//do button2 stuff
}
}
}
}

Categories

Resources