Array
(
    [0] => WP_Term Object
        (
            [term_id] => 23
            [name] => Android Ideas
            [slug] => android-ideas
            [term_group] => 0
            [term_taxonomy_id] => 23
            [taxonomy] => category
            [description] => 
            [parent] => 0
            [count] => 20
            [filter] => raw
            [cat_ID] => 23
            [category_count] => 20
            [category_description] => 
            [cat_name] => Android Ideas
            [category_nicename] => android-ideas
            [category_parent] => 0
        )

    [1] => WP_Term Object
        (
            [term_id] => 22
            [name] => Android Library
            [slug] => android-library
            [term_group] => 0
            [term_taxonomy_id] => 22
            [taxonomy] => category
            [description] => 
            [parent] => 0
            [count] => 69
            [filter] => raw
            [cat_ID] => 22
            [category_count] => 69
            [category_description] => 
            [cat_name] => Android Library
            [category_nicename] => android-library
            [category_parent] => 0
        )

    [2] => WP_Term Object
        (
            [term_id] => 85
            [name] => Android Projects
            [slug] => android-projects
            [term_group] => 0
            [term_taxonomy_id] => 85
            [taxonomy] => category
            [description] => 
            [parent] => 0
            [count] => 39
            [filter] => raw
            [cat_ID] => 85
            [category_count] => 39
            [category_description] => 
            [cat_name] => Android Projects
            [category_nicename] => android-projects
            [category_parent] => 0
        )

    [3] => WP_Term Object
        (
            [term_id] => 84
            [name] => Android Source Code
            [slug] => android-source-code
            [term_group] => 0
            [term_taxonomy_id] => 84
            [taxonomy] => category
            [description] => 
            [parent] => 0
            [count] => 40
            [filter] => raw
            [cat_ID] => 84
            [category_count] => 40
            [category_description] => 
            [cat_name] => Android Source Code
            [category_nicename] => android-source-code
            [category_parent] => 0
        )

)
///////////

Android Swipe Dismiss Dialog

0
189

Swipe-To-Dismiss-Dialog

We use some cool dialog with close button in our Android application but why if you can dismiss that dialog by Swipe and that features provide by Swipe Dismiss dialog which is an Android library which can turn any View into a draggable dialog with swipe to dismiss feature.

Demo Example of Swipe Dismiss dialog

Swipe Dismiss Dialog Success
Swipe Dismiss Dialog with Success
Swipe Dismiss Dialog with input
Swipe Dismiss Dialog with input
Swipe Dismiss Dialog with keyboard
Swipe Dismiss Dialog with keyboard

Download

Add this line to the build.gradle of your module:

compile 'com.github.andreilisun:swipedismissdialog:0.1'

Download Sourecode

How to use

Basic

Set View

  • View dialog = LayoutInflater.from(this).inflate(R.layout.dialog_add_user, null);
    new SwipeDismissDialog.Builder(this)
                    .setView(dialog)
                    .build()
                    .show();

From layout resource

  • new SwipeDismissDialog.Builder(this)
                    .setLayoutResId(R.layout.dialog_success_booking)
                    .build()
                    .show();
  • Callbacks

    Listen for the canceled by tap outside/back pressed events:

  • .setOnCancelListener(new OnCancelListener() {
        @Override
        public void onCancel(View view) {
            Toast.makeText(MainActivity.this, "Canceled", Toast.LENGTH_SHORT).show();
        }
    })

Listen for the swipe dismiss event:

.setOnSwipeDismissListener(new OnSwipeDismissListener() {
                    @Override
                    public void onSwipeDismiss(View view, SwipeDismissDirection direction) {
                        Toast.makeText(MainActivity.this, "Swipe dismissed to: " + direction, Toast.LENGTH_SHORT).show();
                    }
                })

Customization

You can set some parameters:

//Set fling gesture velocity. Range [0.0 - 1.0] 
//Default is 0.1f
.setFlingVelocity(0.07f)  
//Set horizontal oscillation. Range[0.0-35.0]
//Default is 35f
//This is the max rotation angle value
.setHorizontalOscillation(35f)
//Set overlay background color. Default is #80444444
.setOverlayColor(Color.parseColor("#80FF0000"))

Ex code

package com.github.andreilisun.sample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.github.andreilisun.swipedismissdialog.SwipeDismissDialog;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        Button addUserButton = (Button) findViewById(R.id.btn_add_user);
        addUserButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showAddUserDialog();
            }
        });

        Button showAlertButton = (Button) findViewById(R.id.btn_show_alert);
        showAlertButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showAlertDialog();
            }
        });
    }

    private void showAddUserDialog() {
        View dialog = LayoutInflater.from(this).inflate(R.layout.dialog_add_user, null);
        final SwipeDismissDialog swipeDismissDialog = new SwipeDismissDialog.Builder(this)
                .setView(dialog)
                .build()
                .show();
        final EditText usernameEditText = (EditText) dialog.findViewById(R.id.et_username);
        Button addButton = (Button) dialog.findViewById(R.id.btn_add);
        addButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                addUserSuccess(usernameEditText.getText().toString());
                swipeDismissDialog.dismiss();
            }
        });
    }

    private void addUserSuccess(String username) {
        Toast.makeText(this, username + " has been added", Toast.LENGTH_SHORT).show();
    }

    private void showAlertDialog() {
        new SwipeDismissDialog.Builder(this)
                .setLayoutResId(R.layout.dialog_success_booking)
                .build()
                .show();
    }
}

 

Share your thoughts

Loading Facebook Comments ...
Loading Disqus Comments ...