Skip to content

Instantly share code, notes, and snippets.

View virendersran01's full-sized avatar
💻
Working from home

Virender Srxn virendersran01

💻
Working from home
  • India
View GitHub Profile
inputProofNumber1.getEditText().addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
Log.d(TAG, "beforeTextChanged: "+s);
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.d(TAG, "onTextChanged: "+s);
}
@virendersran01
virendersran01 / Internet.txt
Created January 5, 2021 04:22
Checking Active Internet Connection
Implementing Internet Connectivity Checker in Android Apps
Amr Salah
Amr Salah
4 days ago·5 min read
Image for post
Photo by Rami Al-zayat on Unsplash
Working on an Android chat app? social media app? or any other internet-based app that you want to check if there is an internet connection in order to continue a process or even notify the user about their network state? This guide comes to the rescue!
You may say: “Hey! There is already an API which gets this job done.”
Yes, there is! Well, although Android SDK provides API that you can use to get network state of user’s device like ConnectivityManager, it does not actually check whether there is an active internet connection. Concretely, try establishing a hotspot from mobile device “A” but do not turn on mobile data or wifi, then connect mobile device “B” to that hotspot of “A”.
@virendersran01
virendersran01 / AutoSlider.txt
Created February 25, 2021 04:15
Android infinite auto image slider using view pager2 and java
Android Infinite Auto Image Slider using View Pager 2 | Android Studio | Java
Golap Gunjan Barman
Golap Gunjan Barman
Feb 13 · 5 min read
Image for post
In this tutorial, we will create an infinite auto image slider using view pager 2. For infinite sliding, we will implement a new technique that saves memory for loading images.
Add the dependency
Before implementation, it adds the dependency for the view pager 2 and rounded image view.
@virendersran01
virendersran01 / TypeWriter.java
Created March 4, 2021 06:12 — forked from Antarix/TypeWriter.java
TextView animation like type writer
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.widget.TextView;
public class TypeWriter extends TextView {
private CharSequence mText;
private int mIndex;
private long mDelay = 150; //Default 150ms delay
@virendersran01
virendersran01 / TextWriterTextView.kt
Created March 4, 2021 06:17 — forked from efimerdlerkravitz/TextWriterTextView.kt
TypeWriter animation effect in Android
package com.example.uicomponents
import android.content.Context
import android.os.Handler
import android.util.AttributeSet
import android.widget.TextView
class TypeWriteTextView(context: Context?, attrs: AttributeSet?) : TextView(context, attrs) {
private var textList: List<String> = emptyList()
@virendersran01
virendersran01 / ArcLayoutManager.kt
Created March 17, 2021 04:17 — forked from OmarKRostom/ArcLayoutManager.kt
Final version of the ArcLayoutManager
package com.omarkrostom.arclayoutmanager
import android.content.Context
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import androidx.recyclerview.widget.RecyclerView
import kotlin.math.*
class ArcLayoutManager(
private val context: Context,
@virendersran01
virendersran01 / ArcLayoutManager.kt
Created March 17, 2021 04:17 — forked from OmarKRostom/ArcLayoutManager.kt
Third step creating an arc layout manager
private fun fill(recycler: RecyclerView.Recycler?, state: RecyclerView.State?) {
detachAndScrapAttachedViews(recycler ?: return)
for (itemIndex in 0 until itemCount) {
val view = recycler.getViewForPosition(itemIndex)
addView(view)
val viewWidth = pxFromDp(context, ITEM_WIDTH)
val viewHeight = pxFromDp(context, ITEM_HEIGHT)
@virendersran01
virendersran01 / ArcLayoutManager.kt
Created March 17, 2021 04:20 — forked from OmarKRostom/ArcLayoutManager.kt
Second step creating an arc layout manager
class ArcLayoutManager(
private val context: Context,
private var horizontalOffset: Int = 0
) : RecyclerView.LayoutManager() {
override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams =
RecyclerView.LayoutParams(MATCH_PARENT, WRAP_CONTENT)
override fun canScrollHorizontally(): Boolean = true
override fun scrollHorizontallyBy(
@virendersran01
virendersran01 / ArcLayoutManager.kt
Created March 17, 2021 04:20 — forked from OmarKRostom/ArcLayoutManager.kt
First step creating an arc layout manager
package com.omarkrostom.arclayoutmanager
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
class ArcLayoutManager: RecyclerView.LayoutManager() {
override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams =
RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
}
@virendersran01
virendersran01 / computeY.kt
Created March 17, 2021 04:20 — forked from OmarKRostom/computeY.kt
ComputeY component for a circular recyclerview
private fun computeYComponent(viewCenterX: Float,
h: Float): Pair<Int, Double> {
val screenWidth = context.resources.displayMetrics.widthPixels
val s = screenWidth.toDouble() / 2
val radius = (h * h + s * s) / (h * 2)
val xScreenFraction = viewCenterX.toDouble() / screenWidth.toDouble()
val beta = acos(s / radius)
val alpha = beta + (xScreenFraction * (Math.PI - (2 * beta)))