Skip to content

Instantly share code, notes, and snippets.

@raxhaxor
raxhaxor / Set startDestination & startDestinationArgs in Navigation component programmatically
Last active March 27, 2021 16:00
Set startDestination & startDestinationArgs in Navigation component programmatically
val finalHost = navHostFragment as NavHostFragment
val navController = finalHost.navController
val graphInflater = navController.navInflater
val navGraph = graphInflater.inflate(R.navigation.my_subscription_nav_graph).apply {
val destination = if (isBeautySubscription) R.id.beautyServiceSubscriptionDetailsFragment else R.id.activeSubscriptionDetailFragment
startDestination = destination
}
navController.setGraph(navGraph, Bundle().apply {
putString("subscriptionId", intent.getStringExtra("subscriptionId"))
// DrwableMaker.kt
class DrawableMaker {
var shape: DrawableShape = DrawableShape.RECTANGLE
@ColorInt
var color: Int = 0
var cornerRadius: Int = 0
var cornerRadii: CornerRadii? = null
var gradientOrientation: GradientDrawable.Orientation = GradientDrawable.Orientation.TOP_BOTTOM
var gradientColors: IntArray? = null
@raxhaxor
raxhaxor / Pause audio and video in android WebView
Created January 5, 2021 14:12
Pause audio and video in android WebView
val audioPauseJavascipt = "function pauseAudioAndVideo(windowA){" +
" for(var i = 0; i < windowA.document.getElementsByTagName('video').length; i++){" +
" var media = windowA.document.getElementsByTagName('video')[i];" +
" media.pause(); " +
" media.currentTime = -1; " +
" media.volume = 0; " +
" }" +
" for(var i = 0; i < windowA.document.getElementsByTagName('audio').length; i++){" +
" var media = windowA.document.getElementsByTagName('audio')[i];" +
" media.pause(); " +
@raxhaxor
raxhaxor / commitAllowingStateLoss on DialogFragment
Created December 31, 2020 06:10
commitAllowingStateLoss on DialogFragment
override fun show(manager: FragmentManager, tag: String?) {
try {
val superClass = this::class.java.superclass
val dismissedField = superClass?.getDeclaredField("mDismissed")
val isShownByMeField = superClass?.getDeclaredField("mShownByMe")
dismissedField?.isAccessible = true
isShownByMeField?.isAccessible = true
dismissedField?.setBoolean(this, false)
isShownByMeField?.setBoolean(this, true)
dismissedField?.isAccessible = false
getWindow().getDecorView().findViewById(android.R.id.content).addView(View(context))
((ViewGroup) overlayLayout.getParent()).removeView(overlayLayout);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_layout);
OverlayLayout overlayLayout = new OverlayLayout(this); // our overlay view
addContentView(overlayLayout, new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT));
}
@Override
public void addContentView(View view, ViewGroup.LayoutParams params) {
if (mContentParent == null) {
installDecor();
}
mContentParent.addView(view, params);
final Callback cb = getCallback();
if (cb != null && !isDestroyed()) {
cb.onContentChanged();
}
private void installDecor() {
if (mDecor == null) {
mDecor = generateDecor();
mDecor.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
mDecor.setIsRootNamespace(true);
}
if (mContentParent == null) {
mContentParent = generateLayout(mDecor);
...
@Override
public void setContentView(int layoutResID) {
if (mContentParent == null) {
installDecor();
} else {
mContentParent.removeAllViews();
}
mLayoutInflater.inflate(layoutResID, mContentParent);
final Callback cb = getCallback();
if (cb != null && !isDestroyed()) {