Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View afreakyelf's full-sized avatar
🎯
Focusing

Rajat Mittal afreakyelf

🎯
Focusing
  • AWS
  • Seattle, WA
View GitHub Profile
@afreakyelf
afreakyelf / PinchZoomRecyclerView.kt
Created February 11, 2021 11:17
PinchZoomRecyclerView for android
import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.ScaleGestureDetector
import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener
import androidx.recyclerview.widget.RecyclerView
/**
* Created by Rajat on 11,July,2020
@afreakyelf
afreakyelf / fetchDatafromUrlSpring.java
Last active August 16, 2019 05:16
To fetch data from certain url in Spring
List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
//Add the Jackson Message converter
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
// Note: here we are making this converter to process any kind of response,
// not only application/*json, which is the default behaviour
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.ALL));
messageConverters.add(converter);
RestTemplate restTemplate = new RestTemplate();
@afreakyelf
afreakyelf / isOnline.kt
Created June 21, 2019 17:09
To check internet Connectivity
public boolean isOnline() {
ConnectivityManager cm =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}
@afreakyelf
afreakyelf / runtime_permission.kt
Last active January 23, 2021 16:57
Ask for Runtime Permissions in Android
private val requiredPermissionList = arrayOf(
//list of permissions
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE
)
private fun checkAndRequestPermission(): Boolean {
val permissionsNeeded = ArrayList<String>()
for (permission in requiredPermissionList) {
@afreakyelf
afreakyelf / scrollUpNestedScrollView
Created March 19, 2019 11:59
Scroll Up NestedScrollView
nestedscrollview.fullScroll(View.FOCUS_UP)
@afreakyelf
afreakyelf / Back arrow on toolbar.kt
Last active March 19, 2019 12:30
Back arrow on toolbar
setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
supportActionBar?.setDisplayShowTitleEnabled(false)
//To change the color
<style name="MyToolbarStyle">
<item name="android:minHeight">?actionBarSize</item>
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
@afreakyelf
afreakyelf / captureorpickimage.kt
Last active March 19, 2019 09:24
Capture Image from camera or pick from gallery
import android.Manifest
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.addcare_addphoto_fragment.*
import android.content.Intent
import android.content.pm.PackageManager
@afreakyelf
afreakyelf / recyclerviewtopdetectection
Created March 14, 2019 13:24
Detect when recycler view reaches at the top
if (!recyclerView.canScrollVertically(-1)) {
Log.d("status", "Top reached")
}