Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View siscofran999's full-sized avatar
🌴
Sans Boy

Fransisco siscofran999

🌴
Sans Boy
  • Jakarta, Indonesia
View GitHub Profile
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val progress = findViewById<ProgressBar>(R.id.progress)
val txvProgress = findViewById<TextView>(R.id.txvProgress)
val img = findViewById<AppCompatImageView>(R.id.img)
val animator = ObjectAnimator.ofInt(progress, "progress", 1, 100)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="ring"
android:thicknessRatio="16"
android:useLevel="false">
<solid android:color="#d0d0d0" />
</shape>
</item>
@siscofran999
siscofran999 / View.xml
Created June 18, 2022 16:51
view pada tutorial medium
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
tools:context=".MainActivity">
<androidx.appcompat.widget.AppCompatImageView
@siscofran999
siscofran999 / NetworkConnection.kt
Created October 22, 2021 09:48
CheckRealtimeNetwork
class NetworkConnection(private val context: Context) : LiveData<Boolean>() {
private var connectivityManager: ConnectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
private var networkCallback: ConnectivityManager.NetworkCallback? = null
override fun onActive() {
super.onActive()
updateConnection()
when{
Build.VERSION.SDK_INT >= Build.VERSION_CODES.N -> {
@siscofran999
siscofran999 / SampleMoveAnimation.kt
Created July 19, 2021 16:40
sample class implement move animation
class MainActivity2 : AppCompatActivity(), Animation.AnimationListener {
private lateinit var binding: ActivityMain2Binding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMain2Binding.inflate(layoutInflater)
setContentView(binding.root)
binding.img.setOnClickListener {
@siscofran999
siscofran999 / move_top.xml
Created July 19, 2021 16:13
Moving Top Animation
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromYDelta="0%p"
android:toYDelta="-100%p"
android:duration="1500" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity2">
<ImageView
android:id="@+id/img"
fun getImageUri(inContext: Context, inImage: Bitmap): Uri {
val path: String = MediaStore.Images.Media.insertImage(
inContext.contentResolver,
inImage,
"Title",
null
)
Log.i("TAG", "getImageUri: $path")
return Uri.parse(path)
}
fun getPath(context: Context, uri: Uri?): String? {
var cursor: Cursor? = null
return try {
val proj = arrayOf(MediaStore.Images.Media.DATA)
cursor = uri?.let { context.contentResolver.query(it, proj, null, null, null) }
val column_index = cursor!!.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)
cursor.moveToFirst()
cursor.getString(column_index)
} catch (e: Exception) {
loge("getRealPathFromURI Exception : $e")
@Throws(IOException::class)
fun saveImage(context: Context, bitmap: Bitmap, folderName: String, fileName: String): Uri? {
val fos: OutputStream?
var imageFile: File? = null
var imageUri: Uri? = null
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val resolver = context.contentResolver
val contentValues = ContentValues()
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, fileName)
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg")