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
public class LocationManagerService extends ILocationManager.Stub { | |
private Receiver getReceiverLocked(ILocationListener listener, int pid, int uid, | |
String packageName) { | |
IBinder binder = listener.asBinder(); | |
Receiver receiver = mReceivers.get(binder); | |
if (receiver == null) { | |
receiver = new Receiver(listener, null, pid, uid, packageName); | |
mReceivers.put(binder, receiver); | |
try { |
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 Drawable.updateTint(color: Int) { | |
DrawableCompat.wrap(this)?.let { | |
DrawableCompat.setTint(it, color) | |
} | |
} |
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
private fun changeDrawableColor(holder: OutgoingChatViewHolder) { | |
holder.itemView.post { | |
ContextCompat.getDrawable(this, R.drawable.bg_round_corner_outgoing) | |
?.let { incomingBgDrawable -> | |
val color = animatedColor.with(getFloatRange(holder.itemView)) | |
incomingBgDrawable.updateTint(color) | |
holder.itemView.tvOutgoingMessage.background = incomingBgDrawable | |
} | |
} | |
} |
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 android.graphics.Color | |
class AnimatedColor(private val startColor: Int, private val endColor: Int) { | |
private val startHSV: FloatArray | |
private val endHSV: FloatArray | |
private val move = FloatArray(3) | |
init { |
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
private fun getFloatRange(view: View): Float { | |
return 1f - (view.absY() / resources.displayMetrics.heightPixels.toFloat()) | |
} | |
//This function returns the y-cord of the view.. | |
fun View.absY(): Float { | |
val location = IntArray(2) | |
getLocationOnScreen(location) | |
return (location[1].toFloat() - height.toFloat()) | |
} |
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
rvChat.addOnScrollListener(object : RecyclerView.OnScrollListener() { | |
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { | |
super.onScrolled(recyclerView, dx, dy) | |
recyclerView.forEachVisibleHolder { holder: RecyclerView.ViewHolder -> | |
if (holder is OutgoingChatViewHolder) { | |
changeDrawableColor(holder) | |
} | |
} | |
} | |
}) |
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
@SystemService(Context.POWER_SERVICE) | |
public final class PowerManager { | |
final IPowerManager mService; | |
public final class WakeLock { | |
@UnsupportedAppUsage | |
private int mFlags; | |
@UnsupportedAppUsage | |
private String mTag; |
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 android.content.Context | |
import android.os.Bundle | |
import android.os.PowerManager | |
import androidx.appcompat.app.AppCompatActivity | |
class ExampleActivity : AppCompatActivity() { | |
private lateinit var wakeLock: PowerManager.WakeLock |
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
inline fun <reified T : RecyclerView.ViewHolder> RecyclerView.forEachVisibleHolder( | |
action: (T) -> Unit | |
) { | |
for (i in 0 until childCount) { | |
action(getChildViewHolder(getChildAt(i)) as T) | |
} | |
} |
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
rvApps.addOnScrollListener(object : RecyclerView.OnScrollListener() { | |
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { | |
recyclerView.forEachVisibleHolder { holder: AppViewHolder -> | |
holder.rotation | |
// Update the velocity. | |
// The velocity is calculated by the vertical scroll offset. | |
.setStartVelocity(holder.currentVelocity - dx * SCROLL_ROTATION_MAGNITUDE) | |
// Start the animation. This does nothing if the animation is already running. | |
.start() | |
} |
NewerOlder