Skip to content

SimpleFunctions provides a collection of utility functions to speed up development for Android.

License

Notifications You must be signed in to change notification settings

isaiahnoelsalazar/SimpleFunctions

Repository files navigation

How to install?

In build.gradle

dependencies {
    // other existing code
    implementation 'com.github.isaiahnoelsalazar:SimpleFunctions:[latest release version]'
}

Note: Remove the brackets for version

In settings.gradle

dependencyResolutionManagement {
    // other existing code
    repositories {
        // other existing code
        maven { url 'https://jitpack.io' }
    }
}

Available methods

Actions

Initialization

Actions action = new Actions();

build

  • sets a runnable for the action
action.build(new Runnable() {
    @Override
    public void run() {
        // do something
    }
});

setArg

  • sets an argument for the action
  • will accept any type of argument
  • returns the action itself
action.setArg("Sample");

// Or

action.setArg(10);

getArg

  • returns the argument of the action
action.getArg();

execute

  • runs the action
action.execute();

executeDelayed

  • runs the action after a specified delay in milliseconds
action.executeDelayed(1000);

Check

hasNumbers

  • will check a String for a number
  • returns a boolean value
Check.hasNumbers("Sample text"); // returns false
Check.hasNumbers("Sample text 1"); // returns true

hasSymbols

  • will check a String for a symbol
  • returns a boolean value
Check.hasSymbols("Sample text"); // returns false
Check.hasSymbols("Sample text!"); // returns true

hasSpaces

  • will check a String for a space
  • returns a boolean value
Check.hasSpaces("Sample_text"); // returns false
Check.hasSpaces("Sample text"); // returns true

howManySecondsLeft

  • will compare two Date objects to see how many seconds are left
  • returns a double value representing the number of seconds
Date now = new Date("2025/01/01");
Date until = new Date("2025/01/02");
Check.howManySecondsLeft(now, until); // returns 86400.0

howManyMinutesLeft

  • will compare two Date objects to see how many minutes are left
  • returns a double value representing the number of minutes
Date now = new Date("2025/01/01");
Date until = new Date("2025/01/02");
Check.howManyMinutesLeft(now, until); // returns 1440.0

howManyHoursLeft

  • will compare two Date objects to see how many hours are left
  • returns a double value representing the number of hours
Date now = new Date("2025/01/01");
Date until = new Date("2025/01/02");
Check.howManyHoursLeft(now, until); // returns 24.0

howManyDaysLeft

  • will compare two Date objects to see how many days are left
  • returns a double value representing the number of days
Date now = new Date("2025/01/01");
Date until = new Date("2025/01/02");
Check.howManyDaysLeft(now, until); // returns 1.0

Email.addValidDomainName

  • adds a valid domain name to the list of valid domain names
Check.Email.addValidDomainName("gmail");

Email.addValidDomainExtension

  • adds a valid domain extension to the list of valid domain extensions
Check.Email.addValidDomainExtension("com");

Email.addValidDomain

  • adds a valid domain to the list of valid domains
Check.Email.addValidDomain("gmail.com");

Email.shouldUseFullDomain

  • sets the checker to use full domains or not
Check.Email.shouldUseFullDomain();

// Or

Check.Email.shouldUseFullDomain(true);

// Or

Check.Email.shouldUseFullDomain(false);

Email.isValid

  • checks a String if it is a valid email or not
  • will return false if the email domain is not listed in the valid domains
Check.Email.isValid("test@gmail.com"); // returns true
Check.Email.isValid("test@outlook.com"); // returns false
Check.Email.isValid("test@asd.com"); // returns false

Cipher

TranspositionCipher

Cipher.TranspositionCipher("Sample text");

Convert

toRealName

  • will capitalize the first character of a given String
  • returns a String
Convert.toRealName("sample text"); // returns "Sample text"

toBase64

  • will convert a String to its Base64 version
  • returns a String
Convert.toBase64("Sample text"); // returns "U2FtcGxlIHRleHQ="

fromBase64

  • will convert a Base64 String to its normal version
  • returns a String
Convert.fromBase64("U2FtcGxlIHRleHQ="); // returns "Sample text"

dateToDDMMYY

  • will convert a Date object to a String in the format of "DD/MM/YY"
  • returns a String
Date now = new Date("2025/01/02");
Convert.dateToDDMMYY(now); // returns "2/1/2025"

dateToMMDDYY

  • will convert a Date object to a String in the format of "MM/DD/YY"
  • returns a String
Date now = new Date("2025/01/02");
Convert.dateToMMDDYY(now); // returns "1/2/2025"

dateToYYMMDD

  • will convert a Date object to a String in the format of "YY/MM/DD"
  • returns a String
Date now = new Date("2025/01/02");
Convert.dateToYYMMDD(now); // returns "2025/1/2"

EasySQL

Initialization

EasySQL easySQL = new EasySQL(this);

createTable

  • creates a table inside a given database
easySQL.createTable("sampleDB", "sampleTABLE", new String[]{"name:text", "age:int"});

clearTable

  • clears a table inside a given database
easySQL.clearTable("sampleDB", "sampleTABLE");

doesTableExist

  • checks if a table inside a given database exists
  • returns a boolean value
easySQL.doesTableExist("sampleDB", "sampleTABLE");

insertToTable

  • inserts a value into a table inside a given database
easySQL.insertToTable("sampleDB", "sampleTABLE", new String[]{"name:Sample", "age:20"});

getTableValues

  • returns a List of all values of each column in a table inside a given database
for (String value : easySQL.getTableValues("sampleDB", "sampleTABLE")){
    System.out.println(value);
}
/*
    returns:
    - name:'Sample'
    - age:20
 */

getTableValuesAsArray

  • returns a List<String[]> of all rows in a table inside a given database
for (String[] value : easySQL.getTableValuesAsArray("sampleDB", "sampleTABLE")){
    System.out.println(java.util.Arrays.toString(value));
}
/*
    returns:
    - [name:'Sample', age:20]
 */

deleteFromTable

  • deletes a value from a table inside a given database using a "column:value" pair String
easySQL.deleteFromTable("sampleDB", "sampleTABLE", "name:Sample");

deleteTable

  • deletes a table inside a given database
easySQL.deleteTable("sampleDB", "sampleTABLE");

FlippableImageView

Initialization

<com.github.isaiahnoelsalazar.simplefunctions.FlippableImageView
     android:id="@+id/sample_flippable_image_view"
     android:layout_width="100dp"
     android:layout_height="100dp" />

or

<com.github.isaiahnoelsalazar.simplefunctions.FlippableImageView
     android:id="@+id/sample_flippable_image_view"
     android:layout_width="100dp"
     android:layout_height="100dp"
     android:src="@drawable/sample_image" />

or

<com.github.isaiahnoelsalazar.simplefunctions.FlippableImageView
     android:id="@+id/sample_flippable_image_view"
     android:layout_width="100dp"
     android:layout_height="100dp"
     android:scaleType="centerCrop"
     android:src="@drawable/sample_image" />
FlippableImageView flippableImageView = findViewById(R.id.sample_flippable_image_view);

setFrontImage

  • set the front image of the flippable image view
flippableImageView.setFrontImage(R.drawable.piece);

setBackImage

  • set the back image of the flippable image view
flippableImageView.setBackImage(R.drawable.piece);

setReverseBackImage

  • reverses back image of the flippable image view
flippableImageView.setReverseBackImage(true);

flip

  • flips the flippable image view
flippableImageView.flip();

instantFlip

  • instantly flips the flippable image view
flippableImageView.instantFlip();

Fullscreen

enable

  • will enable fullscreen viewing on an activity
Fullscreen.enable(this);

disable

  • will disable fullscreen viewing on an activity
Fullscreen.disable(this);

Memory

Initialization

Memory<AnyClassType> memory = new Memory<AnyClassType>();

// Or

Memory<string> memory = new Memory<string>(); // something general like this

Add

  • adds an item to memory
AnyClassType item = new AnyClassType();
memory.Add(item);

// Or

memory.Add("Sample text");

Contains

  • checks if memory contains an item
bool contains = memory.Contains(new AnyClassType());

Remove

  • removes an item from memory
memory.Remove(item); // assuming 'item' already exists in memory

RemoveAt

  • removes an item from memory at a specific index
memory.RemoveAt(1);

Get

  • returns an item from memory at a specific index
AnyClassType item = memory.Get(0);

// Or

string text = memory.Get(0);

Count

  • returns the number of items in memory
int count = memory.Count();

Clear

  • clears all items in memory
memory.Clear();

RoundedAlertDialog

Initialization

RoundedAlertDialog roundedAlertDialog = new RoundedAlertDialog(this);

setTitle

  • set a title for the dialog
roundedAlertDialog.setTitle("Sample title");

setupLeftButton

  • setup the left button for the dialog with a specified text and color
roundedAlertDialog.setupLeftButton("Left button");

// Or

roundedAlertDialog.setupLeftButton("Left button", Color.RED);

setupRightButton

  • setup the right button for the dialog with a specified text and color
roundedAlertDialog.setupRightButton("Right button");

// Or

roundedAlertDialog.setupRightButton("Right button", Color.RED);

setupLeftButtonOnClick

  • setup the OnClick function for the dialog's left button
roundedAlertDialog.setupLeftButtonOnClick(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // do something
    }
});

setupRightButtonOnClick

  • setup the OnClick function for the dialog's right button
roundedAlertDialog.setupRightButtonOnClick(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // do something
    }
});

SimpleList

Initialization

<com.github.isaiahnoelsalazar.simplefunctions.SimpleList
    android:id="@+id/simple_list_id"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
SimpleList simpleList = findViewById(R.id.simple_list_id);

addItem

  • add a String to the list
simpleList.addItem("Sample text 1");

removeItem

  • remove a String from the list using its position
simpleList.removeItem(0);

setOnItemClickListener

  • set the OnItemClickListener for the list
simpleList.setOnItemClickListener(new SimpleList.OnItemClickListener() {
    @Override
    public void onItemClick(int position) {
        // do something
    }
});

setOnItemLongClickListener

  • set the OnItemLongClickListener for the list
simpleList.setOnItemLongClickListener(new SimpleList.OnItemLongClickListener() {
    @Override
    public void onItemLongClick(int position) {
        // do something
    }
});

setPadding

  • set the padding for each item in the list
simpleList.setPadding(16);

setPadding

  • set individual padding for each item in the list
simpleList.setPadding(24, 16, 8, 12); // left, top, right, bottom

Sort

bubbleSort

Sort.bubbleSort(new int[]{ 10, 8, 52, 27, 63, 95, 6, 46 });

URLRequest

Initialization

URLRequest request = new URLRequest();

build

  • sets a runnable for the request
request.build(new Runnable() {
    @Override
    public void run() {
        // do something
    }
});

getDefaultActionArg

  • returns the default argument of the action
request.getDefaultActionArg();

execute

  • runs the request
  • will accept a URL string and a method string
request.execute("https://www.example.com", "GET");

Example

URLRequest request = new URLRequest();
request.build(new Runnable() {
    @Override
    public void run() {
        System.out.println(request.getDefaultActionArg()); // returns the result of the request
        // do something else
    }
});
request.execute("https://www.example.com", "GET"); // replace the URL and method to your liking

About

SimpleFunctions provides a collection of utility functions to speed up development for Android.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages