Gradle:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.alexsgi:android-utils:VERSION'
}
Run something delayed:
FutureTaskExecutor.runDelayed(final Runnable runnable, int millisInFuture);
FutureTaskExecutor.runDelayed(new Runnable() {
@Override
public void run() {
System.out.println("Message");
}
}, 5000);
FutureTaskExecutor.runDelayed(final Runnable runnable, int millisInFuture, final View view);
view
: if you want to run the runnable on the UI thread, pass a view as a param.
ActivityUtils.setPortraitMode(Activity activity);
ActivityUtils.setLandscapeMode(Activity activity);
ActivityUtils.setAutomaticMode(Activity activity);
int orientation = ActivityUtils.getRequestedOrientation(Activity activity);
Example:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityUtils.setPortraitMode(this);
}
}
Start another activity:
ActivityUtils.startActivity(Activity currentActivity, Class<?> cls); // equal to startActivity(Intent intent)
ActivityUtils.startActivity(Activity currentActivity, Class<?> cls, boolean finishActivity); // (if true: activity.finish() called after intent)
ActivityUtils.startActivity(final Activity currentActivity, final Class<?> cls, int delay); // starts intent with a delay (in ms)
ActivityUtils.startActivity(final Activity currentActivity, final Class<?> cls, boolean finishActivity, int delay); // starts intent with a delay (in ms) and if finishActivity == true: activity.finish() called
Example:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityUtils.setPortraitMode(this);
// ...
ActivityUtils.startActivity(this, AnotherActivity.class, true, 5000);
}
}
Clear text of TextViews and inherits of TextView:
ActivityUtils.clearTextOnViews(View... views);
Example:
ActivityUtils.clearTextOnViews(textView, button, whatEver);
Advanced UI settings:
ActivityUtils.setLightStatusBar(View view, Activity activity);
ActivityUtils.clearLightStatusBar(Activity activity, int color);
Example:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = findViewById(R.id.txt);
ActivityUtils.setLightStatusBar(txt, this);
}
}
Advanced:
BigDecimal bigSum(BigDecimal... summands);
BigDecimal bigDifference(BigDecimal minuend, BigDecimal... subtrahents);
BigDecimal bigProduct(BigDecimal... factors);
BigDecimal bigQuotient(BigDecimal dividend, BigDecimal... divisors);