Skip to content

Instantly share code, notes, and snippets.

@talosdev
talosdev / Underline text
Created October 9, 2016 18:53
Underline text
addressView.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
@talosdev
talosdev / Activity.java
Last active October 12, 2016 18:02
Change status bar color
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(
ContextCompat.getColor(this, R.color.fandango));
}
@talosdev
talosdev / styles.xml
Created October 12, 2016 11:48
Make an activity statusBar-less
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
@talosdev
talosdev / MainActivity.java
Created October 12, 2016 16:04
Use ARGBEvaluator to gradually change the color of the status bar, app bar and other items
public ArgbEvaluator argbEvaluator = new ArgbEvaluator();
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
if (position < pageAdapter.getCount() - 1) {
Integer evaluate = (Integer) argbEvaluator.evaluate(positionOffset,
ContextCompat.getColor(MainActivity.this, NavigationTabAdapter.TAB_COLORS[position]),
ContextCompat.getColor(MainActivity.this, NavigationTabAdapter.TAB_COLORS[position + 1]));
tabLayout.setBackgroundColor(evaluate);
@talosdev
talosdev / OwnProfileFragment.java
Created October 12, 2016 17:52
Scrolling is not smooth when a recycler with "wrap_content" is included in a scrollview
attendanceCardRecycler.setNestedScrollingEnabled(false);
@talosdev
talosdev / styles.xml
Last active October 17, 2016 20:05
Dialog fragment is not showing the title in api >=23
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- ..... -->
<item name="android:dialogTheme">@style/CustomDialog</item>
</style>
@talosdev
talosdev / GuestListFragment.java
Created October 23, 2016 13:43
Request permissions in a support fragment
@OnClick(R.id.checkin_button)
public void onCheckinClick() {
if (checkinDone) {
return;
}
if (!checkinEnabled) {
if (attendance == null) {
Toast.makeText(context, R.string.checkin_not_possible, Toast.LENGTH_SHORT).show();
} else {
@talosdev
talosdev / ShowPeopleFragment.java
Created October 25, 2016 16:39
Set the width of a dialog fragment
@Override
public void onResume() {
super.onResume();
getDialog().getWindow().setLayout(getResources().getDimensionPixelSize(R.dimen.dialog_fragment_width), ViewGroup.LayoutParams.WRAP_CONTENT);
}
@talosdev
talosdev / Completable to Single<Boolean>
Last active April 10, 2017 19:51
Completable to Single<Boolean>
/**
* Receives a {@link Completable} and returns a {@link Single<Boolean>} that emits <code>true</code>
* if the <code>Completable</code> completes successful, <code>false</code> otherwise.
* An action to be performed in case or error can also be passed through the argument
* <code>exceptionConsumer</code>.
*
* @param completable The input {@link Completable}
* @param exceptionConsumer A consumer to process the exception (eg log it) in case the {@link Completable}
* terminates with an error.
* @return The {@link Single<Boolean>}, as described above.
/**
* Creates an {@link Observable} that emits all lines of a {@link BufferedReader} as {@link String}s.
*
* @param reader The {@link BufferedReader} to read from
* @return An {@link Observable} that emits {@link String}s.
*/
public static Observable<String> fromBufferedReader(BufferedReader reader) {
return Observable.create(e -> {
String line;
while (!e.isDisposed() && (line = reader.readLine()) != null) {