Skip to content

Instantly share code, notes, and snippets.

View fercarcedo's full-sized avatar

Fernando García Álvarez fercarcedo

View GitHub Profile
@fercarcedo
fercarcedo / MagicSquare
Created December 10, 2014 21:16
Clase MagicSquare (tarea obligatoria seminario IP) - Fernando García Álvarez
import java.util.Random;
/**
* Clase MagicSquare realizada para el ejercicio de seminario de IP
*
* @author Fernando
* @version
*/
public class MagicSquare
{
public static final int MAX_SIZE = 10;
@fercarcedo
fercarcedo / MagicSquareTest
Created December 10, 2014 21:17
Clase MagicSquareTest (tarea obligatoria seminario IP) - Fernando García Álvarez
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* The test class MagicSquareTest.
*
private fun overwriteImages(uris: List<Uri>) {
val pendingIntent = MediaStore.createWriteRequest(contentResolver, uris)
startIntentSenderForResult(pendingIntent.intentSender, REQ_CODE, null, 0, 0, 0)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQ_CODE && resultCode == Activity.RESULT_OK) {
val intent = Intent(this, MyService::class.java)
intent.data = uri
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
startService(intent)
}
}
val imeInsets = view.rootWindowInsets.getInsets(WindowInsets.Type.ime())
if (imeInsets.isVisible()) {
// Move view by the height of the IME
view.translationX = imeInsets.bottom
}
val inputLayoutMarginBottom = inputLayout.marginBottom
val callback = object : WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) {
override fun onProgress(insets: WindowInsets, animations: MutableList<WindowInsetsAnimation>): WindowInsets {
inputLayout.updateLayoutParams<ViewGroup.MarginLayoutParams> {
updateMargins(bottom = inputLayoutMarginBottom +
insets.getInsets(WindowInsets.Type.ime()).bottom)
}
return insets
}
}
val listener = object : WindowInsetsAnimationControlListener {
override fun onCancelled() {
animationController = null
}
override fun onReady(controller: WindowInsetsAnimationController, types: Int) {
animationController = controller
}
}
scrollView.viewTreeObserver.addOnScrollChangedListener {
animationController?.setInsetsAndAlpha(Insets.of(0, 0, 0, scrollView.scrollY), 1f, 0f)
}
view.setOnApplyWindowInsetsListener { view, windowInsets ->
val systemWindowInsets = windowInsets.getInsets(WindowInsets.Type.systemBars())
// It's also possible to use multiple types
val insets = windowInsets.getInsets(
WindowInsets.Type.ime() or
WindowInsets.Type.systemGestures()
)
windowInsets
}
// Old way (now deprecated) of requesting the app to be
// laid out fullscreen and hiding the navigation
view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION