SlindingMenu slowing toggle - android

I want to display for few seconds part of the sliding menu, Here is how I'm doin it:
#Override
public void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
showMenu();
}
}, 500);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
showContent();
}
}, 600);
}
However, the menu is displaying and disapeared quickly, is there a way to slow down the toggle so that the user can see part of the menu while it's appearing and disapearing slowly?

I made mViewAbove public in SlidingMenu.java, then used scrollBy(int, int):
#Override
public void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
final View viewAbove = getSlidingMenu().mViewAbove;
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
viewAbove.scrollBy(-60, 0);
}
}, 500);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
viewAbove.scrollBy(60, 0);
}
}, 2000);
}

Is there a way to slow down the toggle so that the user can see part of the menu while it's > appearing and disapearing slowly?
You would have to change the animation-changing-rate of the Interpolator of the Scroller here, if you want it to scroll slower. Maybe create a setter for the Interpolator, if you want it to scroll slow only temporary (I assume you only want to show to the user, that there is a SlidingMenu inside your app, right?), after that you could reset the rate of the Interpolator to the default.

Related

Unlock device and swich to other screen

I am trying to write a simple code to switch activity when unlock the device (if app is open) for that I have to switch another activity I have tried this code.But even that code it shows the current screen for a fraction of second. what should I do.
#Override
protected void onResume() {
// This is the second main Layout after main layout (which has
// background image)
mainLayout.setVisibility(View.INVISIBLE);
super.onResume();
checkActivity();
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
SimpleChatMainActivity.this.runOnUiThread(new Runnable() {
#Override
public void run() {
//Visible after 1 second
mainLayout.setVisibility(View.VISIBLE);
}
});
}
}, 1000);
// Some code
}

How make a button invisible for 1 or 2 second on another button click

In my app I want to make a button invisible for a few seconds after another button has been pressed and then it should become visible again.
How it is possible?
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
btn.setVisibility(View.INVISIBLE);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
btn.setVisibility(View.VISIBLE);
}
}, 1000); // where 1000 is equal to 1 sec (1 * 1000)
}
});
You can do somthing like this:
firstBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
secondBtn.setVisibility(View.INVISIBLE);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
secondBtn.setVisibility(View.VISIBLE);
}
}, 2000); //change it for the time you need in milliseconds
}
});
must make buttonView invisible then use btnView.postDelayed
Just inside onClick of second button just do
secondButtonView.setVisibility(View.INVISIBLE);
secondButtonView.postDelayed(new Runnable() {
#Override
public void run() {
secondButtonView.setVisibility(View.VISIBLE);
}
}, 2000);
View.postDelayed() simply calls Handler.postDelayed(). It's a
convenient method that helps avoid creating Handler instances.
This quote is from Romain Guy Android framework engineer https://groups.google.com/forum/#!topic/android-developers/IuG3HgKx89Q
//my button invisible
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
// Do something after 5s = 5000ms
//my button visible
}
}, 5000);
U can use handler for it
also u can use Timer and TimerTask
//First button invisible
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
// Second visible
// after some MS
}
}, 2000);
Suppose you have two buttons Button button1,button2 properly inflated and displayed in view. You can change visibility of button2 on click of button1 by:
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
button2.setVisibility(View.INVISIBLE);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
button2.setVisibility(View.VISIBLE);
}
}, 2 * 1000);//number of seconds *1000
}
});
try this,
write following code on another button's click event.
continuebutton.setVisibility(View.INVISIBLE);
continuebutton.postDelayed(new Runnable() {
public void run() {
continuebutton.setVisibility(View.VISIBLE);
}
}, 2000);

Android: Animation doesn't work

I am working o na Android app. This app has tutorial screens. In this tutorial user has to slide right and left to complete the tutorial. When it launches the app it shows first fragment called SwipeLeftFragment. When user swipes left it shows second fragment called SwipeRightFragment. When user swipes right it shows third fragment called CompletedTutorialFragment.
Currently It works fine but animation doesn't work.
Following is my code:
public class TutorialActivity extends FragmentActivity {
#Override
protected void onStart() {
super.onStart();
final swipeLeftFragment swipeLeftFragment = new SwipeLeftFragment();
addFragmentToBottom(swipeLeftFragment);
swipeLeftFragment.getView().setOnTouchListener(new OnSwipeListener(TutorialActivity.this) {
#Override
public void onSwipeRight() {
}
#Override
public void onSwipeLeft() {
TranslateAnimation animation = new TranslateAnimation(0, -swipeLeftFragment.getView().getWidth(), 0, 0);
animation.setDuration(5000);
swipeLeftFragment.getView().startAnimation(animation);
swipeLeftFragment.getView().setVisibility(View.GONE);
final SwipeRightFragment swipeRightFragment = new SwipeRightFragment();
addFragmentToBottom(swipeRightFragment);
swipeRightFragment.getView().setOnTouchListener(new OnSwipeListener(TutorialActivity.this) {
#Override
public void onSwipeRight() {
TranslateAnimation animation = new TranslateAnimation(0, +swipeRightFragment.getView().getWidth(), 0, 0);
animation.setDuration(5000);
swipeRightFragment.getView().startAnimation(animation);
swipeRightFragment.getView().setVisibility(View.GONE);
final CompletedTutorialFragment completedTutorialFragment = new CompletedTutorialFragment();
addFragmentToBottom(completedTutorialFragment);
startSignupActivity();
}
#Override
public void onSwipeLeft() {
}
});
}
});
}
private void startSignupActivity() {
Handler mHandler = new Handler();
mHandler.postDelayed(new Runnable() {
#Override
public void run() {
startActivity(new Intent(TutorialActivity.this, SignUpActivity.class));
}
}, 2000L);
}
}
Can someone tell me whats wrong with my code?
this is the
OnTouchListener I am using

how to check if an application is killed during an animation in android

i have to make an application in which it starts with an animation and if we click the back button then it should return back to application manager.But what i have made in it if u click back button during that animation then it goes to application manager but after a second or two the first page(the one after this animation comes up).
Can anyone help??
This is the animation..
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.load);
im = (ImageView) findViewById(R.id.load_icon);
rotate = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.load_page);
rotate.setInterpolator(new LinearInterpolator());
im.startAnimation(rotate);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent nextPageIntent = new Intent(getApplicationContext(),
P1.class);
startActivity(nextPageIntent);
}
}, 3000);
}
The first page opens because you have added
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent nextPageIntent = new Intent(getApplicationContext(),
P1.class);
startActivity(nextPageIntent);
}
}, 3000);
This launches the activity.For knowing if the animation has stopped use AnimationListener. More details here about animation listener
Android, How to set animation listener for view group?
You just added animation to one image view thats all, you do not doing anything with animation. The problem is, you started one thread to start activity P1 after 3 seconds. That thread only starting P1 activity. Try this and try to avoid killProcess(),
public class LauncherActivity extends Activity {
private Handler mHandler;
private Runnable mRunnable;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
mHandler = new Handler();
mRunnable = new Runnable() {
#Override
public void run() {
Intent nextPageIntent = new Intent(getApplicationContext(),
XmlParserActivity.class);
startActivity(nextPageIntent);
}
};
mHandler.postDelayed(mRunnable, 3000);
}
/* #Override
public void onBackPressed() {
super.onBackPressed();
mHandler.removeCallbacks(mRunnable);
}*/
#Override
protected void onDestroy() {
super.onDestroy();
mHandler.removeCallbacks(mRunnable);
}
}
public void onBackPressed() {
android.os.Process.killProcess(android.os.Process.myPid());
}
This is the answer

Hide and make visible button every 5 second interval

Can it possible to make a button on screen which automatically visible and gone every 5sec interval?
By using this
b.setVisibility(View.VISIBLE);
we can visible and
b.setVisibility(View.GONE);
we can hide it.But I can't manage to make it by usin the time interval.
Any idea?please share.
There are a few different ways, one is a Handler and Runnable:
public class Example extends Activity {
private Handler mHandler = new Handler();
private Runnable alternate = new Runnable() {
public void run() {
// Alternate visible and not
mHandler.postDelayed(alternate, 5000);
}
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mHandler.postDelayed(alternate, 5000);
}
}
Use this
new CountDownTimer(9000000, 5000) {
public void onTick(long millisUntilFinished) {
if(b.getVisibility() == View.GONE)
b.setVisibility(View.VISIBLE);
else
b.setVisibility(View.GONE);
}
public void onFinish() {
//Restart timer if you want.
}
}.start();

Categories

Resources