0

I need to create a "Sliding activity" , which will slide when the user swipes it. When the user "swipes" it to the left, the activity should slide to the left, and the new activity will come to the screen from the right side. You can't hold it in middle. The same thing is in Yahoo Mail app. You can see this when you are reading a mail, and swipe the mail to the left to move to the next mail. It is like below.

enter image description here

In the image, you can see the next mail (With the title 'Thank you') is opening from the side. In my case, they are 2 different activities. It is also preferred that we can show a small part of the next activity at the right side of the current activity (like in windows phones) so the user know he has to swipe. That part is now mandatory anyway.

I tried to do it with this answer but it is not what I am seeking for. Any idea please?

NOTE

If I go for Fragments, lot of classes will be changed or be re coded entirely.

UPDATE

Please have a look at the following code. In here, when I swipe on SalesInquiry.java The NewLead.java should be open, with the above explained effects.

DropDownMenu.java

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class DropDownMenu extends Activity {

    private TextView addInquiry, addEvent, additionalInfo, addToContacts;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drop_down_menu);

        //Intializing instance variables
        addInquiry = (TextView)findViewById(R.id.menu_add_inquiry);
        addEvent = (TextView)findViewById(R.id.menu_add_event);
        additionalInfo = (TextView)findViewById(R.id.menu_additional_info);
        addToContacts = (TextView)findViewById(R.id.menu_add_to_contacts);

        //Register the Listeners
        addInquiry.setOnClickListener(new AddInquiryEvent());


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.drop_down_menu, menu);
        return true;
    }

    //Test Button
    private class AddInquiryEvent implements OnClickListener
    {

        @Override
        public void onClick(View arg0) 
        {
            // TODO Auto-generated method stub
            Intent intent = new Intent(DropDownMenu.this,NewLead.class);
            startActivity(intent);

        }

    }

    public void onMenuItemClicked(View view) {
        switch (view.getId()) {
        case R.id.menu_add_inquiry:
            Intent intent = new Intent(DropDownMenu.this,NewLead.class);
            startActivity(intent);
            break;
        default:;
        }
    }

}

SalesInquery.java

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class SalesInqury extends DropDownMenu {

    private ImageView addNewSalesInqury;
    private RelativeLayout salesInquryMainLayout;
    private TextView testEditSales;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.activity_sales_inqury);

        //Intializing instance variables
        addNewSalesInqury = (ImageView)findViewById(R.id.add_new_sales_inqury_btn);
        salesInquryMainLayout = (RelativeLayout)findViewById(R.id.sales_inqury_main_layout);
        testEditSales = (TextView)findViewById(R.id.testWord);


        //Registering Event handlers
        addNewSalesInqury.setOnClickListener(new addNewSalesInquryEvent());
        salesInquryMainLayout.setOnTouchListener(mainLayoutSwiped);
        testEditSales.setOnClickListener(new OpenSalesDemo()); //TESTING DEMO!!!!!
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.sales_inqury, menu);
        return true;
    }

    //Event Handler for Add New Sales Inquery Button
    private class addNewSalesInquryEvent implements OnClickListener
    {

        @Override
        public void onClick(View v) 
        {
            // TODO Auto-generated method stub
            Intent intent = new Intent(SalesInqury.this,NewLead.class);
            startActivity(intent);

        }

    }

    //SWIP LISTENER
    private  OnTouchListener mainLayoutSwiped = new OnSwipeTouchListener()
    {
        public boolean onSwipeLeft() 
         {
             Intent intent = new Intent(SalesInqury.this,NewLead.class);
             startActivity(intent);
            return true;
         }
    };


    //
    //
    // TESTING FUNCTION!!
    //
    //
    //Testing function for sales lead opening
    private class OpenSalesDemo implements OnClickListener
    {

        @Override
        public void onClick(View arg0) 
        {
            // TODO Auto-generated method stub
            Intent intent = new Intent(SalesInqury.this,EditLeads.class);
            startActivity(intent);

        }

    }

}
Community
  • 1
  • 1
PeakGen
  • 21,894
  • 86
  • 261
  • 463

3 Answers3

3
            User GestureDetector and in onFling() method check for the direction of swipe and start the activity accordingly  

            Edited:
    Try this:
            GestureDetector gestureDetector = new GestureDetector(
                    simpleOnGestureListener);

        SimpleOnGestureListener simpleOnGestureListener = new SimpleOnGestureListener() {

                // Move The Background Theme To Select The Theme
                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                        float velocityY) {

                    float sensitvity = 100;

                    if ((e1.getX() - e2.getX()) > sensitvity) {

    //Move right ,start new Activity here
return true;
        }else if ((e2.getX() - e1.getX()) > sensitvity) {
    //Move left ,start new Activity here
return true;
        }else{
return false ;
}
}

@Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
        return (gestureDetector.onTouchEvent(event) || super
                .onTouchEvent(event));
    }
Suhail Mehta
  • 5,514
  • 2
  • 23
  • 37
0

You can use fragments instead of activities

Try viewpager library ,see

http://viewpagerindicator.com/

laalto
  • 150,114
  • 66
  • 286
  • 303
keshav
  • 3,235
  • 1
  • 16
  • 22
  • If I go for Fragments, lot of classes will be changed or be re coded entirely. – PeakGen Nov 25 '13 at 07:49
  • Sorry guys!@ᴀʀᴜnBᴇrtiL But I think at least you are as smart that can find the answer if it's there. Sorry @Artificial_Intelligence But I don't think there is any other way to do this without using fragments. – keshav Nov 26 '13 at 05:05
0

You can simply use Fragments precisely SupportFragment and ViewPager that will allow you to swipe through Different fragements. It is available in android.support.v4 library.

VishalKale
  • 758
  • 7
  • 22