Example usage for android.app ActivityOptions makeCustomAnimation

List of usage examples for android.app ActivityOptions makeCustomAnimation

Introduction

In this page you can find the example usage for android.app ActivityOptions makeCustomAnimation.

Prototype

public static ActivityOptions makeCustomAnimation(Context context, int enterResId, int exitResId) 

Source Link

Document

Create an ActivityOptions specifying a custom animation to run when the activity is displayed.

Usage

From source file:samples.piggate.com.piggateCompleteExample.Activity_SingIn.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    _piggate = new Piggate(this, null); //Initialize the Piggate object

    getSupportActionBar().setTitle("Login");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    setContentView(R.layout.activity_login);
    //EditTexts for user email and password
    editEmail = (EditText) findViewById(R.id.editText1);
    editPass = (EditText) findViewById(R.id.editText2);
    Button login = (Button) findViewById(R.id.buttonlogin);

    errorDialog = new AlertDialog.Builder(this).create();
    errorDialog.setTitle("Login error");
    errorDialog.setMessage("There is an error with the login");
    errorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override/*w ww  . j  a v  a2 s .  c om*/
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    networkErrorDialog = new AlertDialog.Builder(this).create();
    networkErrorDialog.setTitle("Network error");
    networkErrorDialog.setMessage("There is an error with the network connection");
    networkErrorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    //OnClick listener for the login button
    //Handles the login request to the server with the email and password fields
    login.setOnClickListener(new View.OnClickListener() {
        @Override
        synchronized public void onClick(View v) {
            String email = editEmail.getText().toString();
            String pass = editPass.getText().toString();

            //If the internet connection is working
            if (checkInternetConnection() == true) {

                if (editEmail.getText().toString().equals("") || editPass.getText().toString().equals("")) {
                    if (editEmail.getText().toString().equals(""))
                        editEmail.setError("Enter your email");
                    if (editPass.getText().toString().equals(""))
                        editPass.setError("Enter your password");
                } else {
                    loadingDialog = ProgressDialog.show(v.getContext(), "Singing In", "Wait a few seconds",
                            true);
                    RequestParams params = new RequestParams();
                    params.put("email", email);
                    params.put("password", pass);

                    //Request of the Piggate object. Handles the login into the application with the user email and password
                    _piggate.RequestOpenSession(params).setListenerRequest(new Piggate.PiggateCallBack() {

                        //Method onComplete for JSONObject
                        //When the request is correct start Activity_Logged activity
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONObject data) {
                            loadingDialog.dismiss();
                            Intent slideactivity = new Intent(Activity_SingIn.this, Activity_Logged.class);
                            slideactivity
                                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            Bundle bndlanimation = ActivityOptions.makeCustomAnimation(getApplicationContext(),
                                    R.anim.slidefromright, R.anim.slidetoleft).toBundle();
                            startActivity(slideactivity, bndlanimation);
                        }

                        //Method onError for JSONObject
                        //If there's an error with the request displays the error message to the user
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONObject data) {
                            loadingDialog.dismiss();
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    errorDialog.show();
                                }
                            });
                        }

                        //Method onComplete for JSONArray
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }

                        //Method onError for JSONArray
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }
                    }).exec();
                }
            } else { //If the internet connection is not working
                networkErrorDialog.show();
            }
        }
    });
}

From source file:samples.piggate.com.piggateCompleteExample.Activity_SingUp.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    _piggate = new Piggate(this, null); //Initialize the Piggate object

    getSupportActionBar().setTitle("Register");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    setContentView(R.layout.activity_register);
    //EditTexts for user email and password
    editEmail = (EditText) findViewById(R.id.editText1);
    editPass = (EditText) findViewById(R.id.editText2);
    Button register = (Button) findViewById(R.id.buttonregister);

    errorDialog = new AlertDialog.Builder(this).create();
    errorDialog.setTitle("Login error");
    errorDialog.setMessage("There is an error with the login");
    errorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override/*from   w  w  w. j  a  v a  2  s  .  com*/
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    networkErrorDialog = new AlertDialog.Builder(this).create();
    networkErrorDialog.setTitle("Network error");
    networkErrorDialog.setMessage("There is an error with the network connection");
    networkErrorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    //OnClick listener for the login button
    //Handles the register request to the server with the email and password fields
    //and the login request if the fields are correct
    register.setOnClickListener(new View.OnClickListener() {
        @Override
        synchronized public void onClick(View v) {
            String email = editEmail.getText().toString();
            String pass = editPass.getText().toString();

            //If the internet connection is working
            if (checkInternetConnection() == true) {

                if (editEmail.getText().toString().equals("") || editPass.getText().toString().equals("")) {
                    if (editEmail.getText().toString().equals(""))
                        editEmail.setError("Enter your email");
                    if (editPass.getText().toString().equals(""))
                        editPass.setError("Enter your password");
                } else {
                    loadingDialog = ProgressDialog.show(v.getContext(), "Singing Up", "Wait a few seconds",
                            true);
                    RequestParams params = new RequestParams();
                    params.put("email", email);
                    params.put("password", pass);

                    //Request of the Piggate object. Handles the register into the application
                    // and the login with the user email and password
                    _piggate.RequestNewUser(params).setListenerRequest(new Piggate.PiggateCallBack() {

                        //Method onComplete for JSONObject
                        //When the request is correct start Activity_Logged activity
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONObject data) {
                            loadingDialog.dismiss();
                            Intent slideactivity = new Intent(Activity_SingUp.this, Activity_Logged.class);
                            slideactivity
                                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            Bundle bndlanimation = ActivityOptions.makeCustomAnimation(getApplicationContext(),
                                    R.anim.slidefromright, R.anim.slidetoleft).toBundle();
                            startActivity(slideactivity, bndlanimation);
                        }

                        //Method onError for JSONObject
                        //If there's an error with the request displays the error message to the user
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONObject data) {
                            loadingDialog.dismiss();
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    errorDialog.show();
                                }
                            });
                        }

                        //Method onComplete for JSONArray
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }

                        //Method onError for JSONArray
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }
                    }).exec();
                }
            } else { //If the internet connection is not working
                networkErrorDialog.show();
            }
        }
    });
}

From source file:samples.piggate.com.piggateInfoDemo.InfoActivity.java

public void backButton() {
    Intent slideactivity = new Intent(InfoActivity.this, Activity_Logged.class);
    slideactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    Bundle bndlanimation = ActivityOptions
            .makeCustomAnimation(getApplicationContext(), R.anim.slidefromleft, R.anim.slidetoright).toBundle();
    startActivity(slideactivity, bndlanimation);
}

From source file:samples.piggate.com.piggateCompleteExample.Activity_Logged.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    _piggate = new Piggate(this, null); //Initialize the Piggate object
    setContentView(R.layout.activity_logged);
    getSupportActionBar().setTitle(PiggateUser.getEmail());

    startService(new Intent(getApplicationContext(), Service_Notify.class)); //Start the service

    //Initialize and set all the left navigation drawer fields
    mDrawer = new Drawer().withActivity(this).withTranslucentStatusBar(false).withHeader(R.layout.drawerheader)
            .addDrawerItems( /* Add drawer items with this method */)
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override// w  w  w  . j  a  v a2s .  c om
                public void onItemClick(AdapterView<?> parent, View view, int position, long id,
                        IDrawerItem drawerItem) {
                    // Open the exchange activity for the selected item
                    Intent slideactivity = new Intent(Activity_Logged.this, Activity_Exchange.class);
                    slideactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

                    //Send the current offer information to the exchange activity
                    slideactivity.putExtra("offerName", exchangeOfferList.get(position).getName().toString());
                    slideactivity.putExtra("offerDescription",
                            exchangeOfferList.get(position).getDescription().toString());
                    slideactivity.putExtra("offerImgURL",
                            exchangeOfferList.get(position).getImgURL().toString());
                    slideactivity.putExtra("exchangeID",
                            exchangeOfferList.get(position).getExchangeID().toString());

                    Bundle bndlanimation = ActivityOptions.makeCustomAnimation(Activity_Logged.this,
                            R.anim.slidefromright, R.anim.slidetoleft).toBundle();
                    startActivity(slideactivity, bndlanimation);
                }
            }).withSliderBackgroundColor(Color.parseColor("#FFFFFF")).withSelectedItem(-1).build();

    //Initialize recycler view
    mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(Activity_Logged.this));
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    newBeaconsLayout = (LinearLayout) findViewById(R.id.newBeaconsLayout);

    //Initialize swipe layout
    mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    mSwipeLayout.setOnRefreshListener(this);

    errorDialog = new AlertDialog.Builder(this).create();
    errorDialog.setTitle("Logout error");
    errorDialog.setMessage("There is an error with the logout");
    errorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    successPaymentDialog = new AlertDialog.Builder(this).create();
    successPaymentDialog.setTitle("Successful payment");
    successPaymentDialog.setMessage("Now you can exchange your purchased product");
    successPaymentDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    errorBuyDialog = new AlertDialog.Builder(this).create();
    errorBuyDialog.setTitle("Payment failed");
    errorBuyDialog.setMessage("There is an error with your payment");
    errorBuyDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    successExchangeDialog = new AlertDialog.Builder(this).create();
    successExchangeDialog.setTitle("Offer successfully exchanged");
    successExchangeDialog.setMessage("The offer has been purchased and exchanged");
    successExchangeDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    errorExchangeDialog = new AlertDialog.Builder(this).create();
    errorExchangeDialog.setTitle("Exchange error");
    errorExchangeDialog.setMessage("There is an error with the exchange");
    errorExchangeDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    networkErrorDialog = new AlertDialog.Builder(this).create();
    networkErrorDialog.setTitle("Network error");
    networkErrorDialog.setMessage("There is an error with the network connection");
    networkErrorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    fadeIn = AnimationUtils.loadAnimation(Activity_Logged.this, R.anim.fadein);
    fadeOut = AnimationUtils.loadAnimation(Activity_Logged.this, R.anim.fadeout);

    //Check if the bluetooth is switched on
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (!mBluetoothAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
    }

    if (getIntent().hasExtra("payment")) {
        if (getIntent().getExtras().getBoolean("payment") == true) {
            successPaymentDialog.show(); //Show success payment dialog
            mDrawer.openDrawer(); //Open the left panel
        } else {
            errorBuyDialog.show(); //Show payment error dialog
        }
    } else if (getIntent().hasExtra("exchanged")) {
        if (getIntent().getExtras().getBoolean("exchanged") == true) {
            successExchangeDialog.show(); //Show exchange success dialog
        } else {
            errorExchangeDialog.show(); //Show exchange error dialog
        }
    }
}

From source file:com.piggate.samples.PiggateLoginApplication.Activity_Logged.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    _piggate = new Piggate(this, null);
    setContentView(R.layout.activity_logged);
    textEmail = (TextView) findViewById(R.id.nametext);
    viewContainer = findViewById(R.id.notificationbar);
    textNotification = (TextView) findViewById(R.id.notification_message);
    Button logout = (Button) findViewById(R.id.buttonlogout);
    final ImageButton return_button = (ImageButton) findViewById(R.id.return1);
    textEmail.setText("Hi, " + PiggateUser.getEmail());

    //Set the onClick listener of the return button
    return_button.setOnClickListener(new View.OnClickListener() {
        @Override/*from  w  w  w.java  2 s.  c  om*/
        public void onClick(View v) {
            onBackPressed();
        }
    });

    //Set the onClick listener of the logout button
    logout.setOnClickListener(new View.OnClickListener() {
        @Override
        synchronized public void onClick(View v) {
            if (!handledClick) {
                handledClick = true;
                Intent slideactivity = new Intent(Activity_Logged.this, Activity_Main.class);
                slideactivity.putExtra("ACTIVITY_MAIN_CREATED_BY_BUTTON_LOGOUT", true);

                Bundle bndlanimation = ActivityOptions
                        .makeCustomAnimation(getApplicationContext(), R.anim.flip1, R.anim.flip2).toBundle();
                startActivity(slideactivity, bndlanimation);

                if (checkInternetConnection() == true) { //If the internet connection is working
                    //Request a session close for the logged user
                    _piggate.RequestCloseSession().setListenerRequest(new Piggate.PiggateCallBack() {

                        //Method onComplete for JSONObject
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONObject data) {
                            Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
                        }

                        //Method onError for JSONObject
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONObject data) {
                            Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
                            _piggate.reload();
                        }

                        //Method onComplete for JSONArray
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }

                        //Method onError for JSONArray
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }
                    }).exec();

                } else { //If internet conexion is not working displays an error message
                    Toast.makeText(getApplicationContext(), "Network is not working", Toast.LENGTH_LONG).show();
                }
            }
        }
    });
}

From source file:com.piggate.samples.PiggateLoginService.Activity_Logged.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    _piggate = new Piggate(this, null);
    setContentView(R.layout.activity_logged);
    textEmail = (TextView) findViewById(R.id.nametext);
    viewContainer = findViewById(R.id.notificationbar);
    textNotification = (TextView) findViewById(R.id.notification_message);
    Button logout = (Button) findViewById(R.id.buttonlogout);
    final ImageButton return_button = (ImageButton) findViewById(R.id.return1);
    textEmail.setText("Hi, " + PiggateUser.getEmail());

    //Set the onClick listener of the return button
    return_button.setOnClickListener(new View.OnClickListener() {
        @Override//from   ww  w  .  ja  va  2  s.c om
        public void onClick(View v) {
            onBackPressed();
        }
    });

    //Set the onClick listener of the logout button
    logout.setOnClickListener(new View.OnClickListener() {
        @Override
        synchronized public void onClick(View v) {
            if (!handledClick) {
                handledClick = true;
                Intent slideactivity = new Intent(Activity_Logged.this, Activity_Main.class);
                slideactivity.putExtra("ACTIVITY_MAIN_CREATED_BY_BUTTON_LOGOUT", true);

                Bundle bndlanimation = ActivityOptions
                        .makeCustomAnimation(getApplicationContext(), R.anim.flip1, R.anim.flip2).toBundle();
                startActivity(slideactivity, bndlanimation);

                if (checkInternetConnection() == true) { //If the internet connection is working
                    //Request a session close for the logged user
                    _piggate.RequestCloseSession().setListenerRequest(new Piggate.PiggateCallBack() {

                        //Method onComplete for JSONObject
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONObject data) {
                            Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
                        }

                        //Method onError for JSONObject
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONObject data) {
                            Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
                            _piggate.reload();
                        }

                        //Method onComplete for JSONArray
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }

                        //Method onError for JSONArray
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }
                    }).exec();

                } else { //If internet conexion is not working displays an error message
                    Toast.makeText(getApplicationContext(), "Network is not working", Toast.LENGTH_LONG).show();
                }
            }
        }
    });

    if (checkInternetConnection() == true) { //If the internet connection is working
        //Get the notification message
        _piggate.RequestGetNotification().setListenerRequest(new Piggate.PiggateCallBack() {
            @Override
            public void onComplete(int statusCode, Header[] headers, String msg, JSONObject data) {
                Service_Notify.notificationMsg = data.optString("message");
            }

            @Override
            public void onError(int statusCode, Header[] headers, String msg, JSONObject data) {
                Service_Notify.notificationMsg = "Click to see the offer"; //Default message if there's an error
            }

            @Override
            public void onComplete(int statusCode, Header[] headers, String msg, JSONArray data) {
                //Unused
            }

            @Override
            public void onError(int statusCode, Header[] headers, String msg, JSONArray data) {
                //Unused
            }
        }).exec();
    } else {
        Service_Notify.notificationMsg = "Click to see the offer"; //Default message if there's a network error
    }
}

From source file:com.collabora.xwperf.notxw_contacts.fragments.MainFragment.java

private void setContactClickListener(ITabScrollHider fragment) {
    fragment.setContactClickListener(new ContactsAdapter.OnItemClickListener() {
        @Override/*from www. j  av  a 2s.  c  o  m*/
        public void onItemClicked(int itemId) {
            Intent intent = new Intent(getActivity(), DetailsActivity_.class);
            intent.putExtra(DetailsActivity.EXTRA_ITEM_ID, itemId);
            if (getResources().getBoolean(R.bool.custom_animations)) {
                ActivityOptions opts = ActivityOptions.makeCustomAnimation(getActivity(),
                        android.R.anim.fade_in, android.R.anim.fade_out);
                getActivity().startActivity(intent, opts.toBundle());
            } else {
                getActivity().startActivity(intent);
            }
        }
    });
}

From source file:io.indy.drone.activity.StrikeDetailActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    ifd("clicked " + item);

    switch (item.getItemId()) {
    case R.id.action_settings:
        ifd("clicked on settings");
        break;//from  w ww . j  a v  a 2 s  . c o  m
    case R.id.action_about:
        Intent intent = new Intent(this, AboutActivity.class);
        startActivity(intent);
        break;
    case android.R.id.home:
        // This ID represents the Home or Up button. In the case of this
        // activity, the Up button is shown. Use NavUtils to allow users
        // to navigate up one level in the application structure. For
        // more details, see the Navigation pattern on Android Design:
        //
        // http://developer.android.com/design/patterns/navigation.html#up-vs-back
        //

        Intent upIntent = new Intent(this, StrikeListActivity.class);
        upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
            startActivity(upIntent);
        } else {
            Bundle translateBundle = ActivityOptions.makeCustomAnimation(StrikeDetailActivity.this,
                    R.anim.slide_in_right, R.anim.slide_out_right).toBundle();
            startActivity(upIntent, translateBundle);
        }

        finish();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.lithiumli.fiction.FictionActivity.java

public void initializeBottomActionBar() {
    View layout = findViewById(R.id.bab_info);
    layout.setOnClickListener(new View.OnClickListener() {
        @Override/*from ww w. j a  va  2  s .  c o m*/
        public void onClick(View v) {
            Intent intent = new Intent(FictionActivity.this, NowPlayingActivity.class);
            ActivityOptions options = ActivityOptions.makeCustomAnimation(FictionActivity.this,
                    R.anim.activity_slide_down, R.anim.activity_slide_up);
            FictionActivity.this.startActivity(intent, options.toBundle());
        }
    });
}

From source file:com.piggate.samples.PiggateLogin.Activity_Logged.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    _piggate = new Piggate(this); //Initialize the Piggate object
    _piggate.setListenerBeacon(new Piggate.PiggateBeaconCallback() { //Set the beacon listener

        //Handle if the device is not compatible
        @Override//from  ww w .java  2 s .c  om
        public void DeviceNotCompatible() {
            //Unused
        }

        //Handle if the bluetooth is not connected
        @Override
        public void BluetoothNotConnect() {
            //Unused
        }

        //Handle the pre - scanning of the beacons
        @Override
        public void PreScanning() {
            //Unused
        }

        //Handle the actions when the listener is ready
        @Override
        public void onReady() {
            //Unused
        }

        //Handle the beacon scanning errors
        @Override
        public void onErrorScanning() {
            //Unused
        }

        //Handle the actions where new beacons are discovered
        @Override
        public void GetNewBeacons(final ArrayList<PiggateBeacon> beacons) {
            //Unused
        }

        //Handles the actions where beacons are detected
        //Add the pending beacons to the server
        @Override
        public void GetBeacons(final ArrayList<PiggateBeacon> beacons) {
            //Unused
        }
    });

    setContentView(R.layout.activity_logged);
    textEmail = (TextView) findViewById(R.id.nametext);
    viewContainer = findViewById(R.id.notificationbar);
    textNotification = (TextView) findViewById(R.id.notification_message);
    Button logout = (Button) findViewById(R.id.buttonlogout);
    final ImageButton return_button = (ImageButton) findViewById(R.id.return1);
    textEmail.setText("Hi, " + PiggateUser.getEmail());

    //Set the onClick listener of the return button
    return_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });

    //Set the onClick listener of the logout button
    logout.setOnClickListener(new View.OnClickListener() {
        @Override
        synchronized public void onClick(View v) {
            if (!handledClick) {
                handledClick = true;
                Intent slideactivity = new Intent(Activity_Logged.this, Activity_Main.class);
                slideactivity.putExtra("ACTIVITY_MAIN_CREATED_BY_BUTTON_LOGOUT", true);

                Bundle bndlanimation = ActivityOptions
                        .makeCustomAnimation(getApplicationContext(), R.anim.flip1, R.anim.flip2).toBundle();
                startActivity(slideactivity, bndlanimation);

                if (checkInternetConnection() == true) { //If the internet connection is working
                    //Request a session close for the logged user
                    _piggate.RequestCloseSession().setListenerRequest(new Piggate.PiggateCallBack() {

                        //Method onComplete for JSONObject
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONObject data) {
                            Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
                        }

                        //Method onError for JSONObject
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONObject data) {
                            Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
                            _piggate.reload();
                        }

                        //Method onComplete for JSONArray
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }

                        //Method onError for JSONArray
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }
                    }).exec();

                } else { //If internet conexion is not working displays an error message
                    Toast.makeText(getApplicationContext(), "Network is not working", Toast.LENGTH_LONG).show();
                }
            }
        }
    });
}