This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package penalty; | |
import java.util.Random; | |
public class Player { | |
private String name; | |
private int skills; | |
public Player(String name, int skills) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tailrec fun Context.getActivity(): Activity? = when (this) { | |
is Activity -> this | |
else -> (this as? ContextWrapper)?.baseContext?.getActivity() | |
} | |
/** | |
* Starts the Activity [A], in a more concise way, while still allowing to configure the [Intent] in | |
* the optional [configIntent] lambda. | |
*/ | |
inline fun <reified A : Activity> Context.start(configIntent: Intent.() -> Unit = {}) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun String.fromHtmlToSpanned(): Spanned = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | |
Html.fromHtml(this, Html.FROM_HTML_MODE_LEGACY) | |
} else { | |
HtmlCompat.fromHtml(this, HtmlCompat.FROM_HTML_MODE_LEGACY) | |
} | |
/** turn string into the picture */ | |
fun String.convertToBitmap(textSize: Float, textColor: Int): Bitmap { | |
val paint = Paint(Paint.ANTI_ALIAS_FLAG) | |
paint.textSize = textSize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Spanned.toHtml(): String = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | |
Html.toHtml( this, Html.FROM_HTML_MODE_LEGACY) | |
} else { | |
@Suppress("DEPRECATION") | |
Html.toHtml(this) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:html/parser.dart'; | |
import 'package:http/http.dart'; | |
/// Convenient solution for flutter(dart) to fetch data(preview, title etc.) from provided web link. | |
class FetchPreviewHelper { | |
static final titlePreview = 'title'; | |
static final descriptionPreview = 'description'; | |
static final imagePreview = 'image'; | |
static final favIconPreview = 'favIcon'; | |
static final appleIconPreview = 'appleIcon'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @Description | |
* Checks if device is online or not | |
*/ | |
fun Fragment.isOnline(): Boolean { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | |
val connectivityManager = | |
this.activity?.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
val network = connectivityManager.activeNetwork | |
return if (network != null) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// After 0.5 second after creating, the list will slide down | |
/// to the bottom of the ListView | |
void _animateSlideDown(Model model) { | |
Timer( | |
Duration(milliseconds: 400), | |
() => model.scrollController.animateTo( | |
model.scrollController.position.maxScrollExtent, | |
duration: Duration(milliseconds: 500), | |
curve: Curves.fastOutSlowIn, | |
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BackgroundWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return LayoutBuilder( | |
builder: (BuildContext context, BoxConstraints constraints) { | |
return Align( | |
alignment: AlignmentDirectional.topCenter, | |
child: Container( | |
width: constraints.maxWidth, | |
height: constraints.maxHeight, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T> LiveData<T>.observeOnce(lifecycleOwner: LifecycleOwner,observer: androidx.lifecycle.Observer<T>) { | |
observe(lifecycleOwner, object : androidx.lifecycle.Observer<T> { | |
override fun onChanged(t: T) { | |
observer.onChanged(t) | |
removeObserver(this) | |
} | |
}) | |
} |
OlderNewer