GithubHelp home page GithubHelp logo

tohateam / rundo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ppartisan/rundo

0.0 2.0 0.0 371 KB

Adds Undo/Redo functionality to editable text fields in Android.

License: MIT License

Java 100.00%

rundo's Introduction

RunDo

Banner Image

RunDo adds Undo/Redo functionality to EditText fields in Android.

Releases

Download

Current version is v1.0.5

JavaDoc available at ppartisan.github.io

Implementation

Gradle Dependency

jcenter() & mavenCentral()

Add the following to your module's build.gradle file:

dependencies {
    compile 'com.werdpressed.partisan:rundo:1.0.5'
}
maven

In addition to the dependency above, add:

repositories {
    maven {
        url 'https://dl.bintray.com/ppartisan/maven/'
    }
}

Usage

Recommended usage is via the following method:

RunDo.Factory.getInstance(FragmentManager fm);

To be used in the following way (as an example):

public class MyActivity extends Activity implements Rundo.TextLink, View.OnClickListener {

    private RunDo mRunDo;
    private EditText mEditText;
    private Button mButton;
    
    //...

    mRunDo = RunDo.Factory.getInstance(getFragmentManager());
    mButton.setOnClickListener(this);
    
    //...
    
    @Override
    public void onClick(View v) {
        int id = v.getId();

        switch (id) {
            case R.id.undo_button:
                mRunDo.undo();
                break;
            case R.id.redo_button:
                mRunDo.redo();
                break;
        }

    }

    @Override
    public EditText getEditText() {
        return mEditText;
    }
    
}

See the sample app for a complete example

The getInstance() method requires a FragmentManager (whether android.app.FragmentManager or android.suppoer.v4.app.FragmentManager) argument.

RunDo implementations extend either android.app.Fragment or android.support.v4.app.Fragment.

Calling Undo/Redo

To call Undo or Redo, use the undo() and redo() methods:

mRunDo.undo();
mRunDo.redo();

For example:

@Override
public void onClick(View v) {
    int id = v.getId();
    switch (id) {
        case R.id.undo_button:
            mRunDo.undo();
            break;
        case R.id.redo_button:
            mRunDo.redo();
            break;
    }

}

Tweaking Parameters

There are two ways to customise RunDo objects; setQueueSize(int size) and setTimerLength(long lengthInMillis).

setQueueSize() adjusts the size of the undo and redo queues to hold the specified number of entries, before entries from the opposite end of the queue begin to be removed. The default size is 10. Calling this method will clear all current entries from both queues.

setTimerLength() adjust the countdown between the user's last text entry and the period at which any altered text is saved to the undo queue. The timer is reset if further text is entered during this period. The default value is 2000 milliseconds (2 seconds).

Clearing Queues

Use clearAllQueues() to remove all elements from both undo and redo queues.

Callbacks

Implement RunDo.Callbacks to be notified whenever undo() or redo() is called:

@Override
public void undoCalled() {
}

@Override
public void redoCalled() {
}

rundo's People

Contributors

ppartisan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.