Snippets Collections
@SuppressLint("UnusedMaterialScaffoldPaddingParameter")
    @Preview(showBackground = true)
    @Composable
    fun scaffold() {
        Scaffold(
            topBar = {
                TopAppBar {
                    Text(text = stringResource(id = R.string.app_name))
                }
            },
            bottomBar = {
                BottomAppBar(
                    cutoutShape = MaterialTheme.shapes.small.copy(CornerSize(percent = 50))
                ) {

                }
            },
            floatingActionButton = {
                FloatingActionButton(onClick = { /*TODO*/ }) {
                    Icon(Icons.Filled.Add, contentDescription = "")
                }
            },
            isFloatingActionButtonDocked = true
        ) {
            main()
        }
    }
fun isOnline(context: Context): Boolean {
    val connectivityManager =
        context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
    if (connectivityManager != null) {
        val capabilities =
            connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
        if (capabilities != null) {
            if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
                Log.i("Internet", "NetworkCapabilities.TRANSPORT_CELLULAR")
                return true
            } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
                Log.i("Internet", "NetworkCapabilities.TRANSPORT_WIFI")
                return true
            } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)) {
                Log.i("Internet", "NetworkCapabilities.TRANSPORT_ETHERNET")
                return true
            }
        }
    }
    return false
}
	//retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

    //ViewModal and livedata
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'

    //coroutines
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'

    //navigation
    implementation "androidx.navigation:navigation-fragment-ktx:2.5.3"
    implementation "androidx.navigation:navigation-ui-ktx:2.5.3"

    //scalable unit & text size
    implementation 'com.intuit.ssp:ssp-android:1.0.6'
    implementation 'com.intuit.sdp:sdp-android:1.0.6'

    //custom nav chip
    implementation 'com.github.ismaeldivita:chip-navigation-bar:1.4.0'

    //glide
    implementation 'com.github.bumptech.glide:glide:4.14.2'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2'

	
    //room
    implementation "androidx.room:room-runtime:2.4.3"
    kapt("androidx.room:room-compiler:2.4.3")
    implementation("androidx.room:room-ktx:2.4.3")
Open [yourappfolder]/AndroidManifest.template.xml file
and add the following property:

<application android:persistent="%persistent%" ...
    :
    android:usesCleartextTraffic="true">
    
</application>
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.CallSuper
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
import org.koin.android.ext.android.inject
import se.tv4.analytics.page.ScreenTracker

typealias FragmentInflater<T> = (LayoutInflater, ViewGroup?, Boolean) -> T

/**
 * base fragment to share the common functionality between the fragments in the app
 */
abstract class BaseFragment<T : ViewBinding>(private val inflate: FragmentInflater<T>) : Fragment() {

    private var _binding: T? = null

    /**
     * The view binding for this fragment.
     *
     * [https://developer.android.com/topic/libraries/view-binding]
     *
     * This property is only valid between [onCreateView] and [onDestroyView].
     */
    val binding: T
        get() = _binding ?: throw IllegalStateException("Cannot access view outside onCreateView and onDestroyView")

    @CallSuper
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        _binding = inflate(inflater, container, false)
        return binding.root
    }

    @CallSuper
    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }

}
npx cap open ios #abrir o projecto no xcode

npx cap open android #abrir o projecto no android
<?xml version="1.0" encoding="utf-8"?>
<manifest
  xmlns:android="http://schemas.android.com/apk/res/android"
+  xmlns:tools="http://schemas.android.com/tools" <-- adicionas esta linha não removendo nada e seguindo esta lógica

  package="com.example">

  <application
+    android:hardwareAccelerated="true" <-- adicionas esta linha não removendo nada e seguindo esta lógica
  >
  </application>

+  <uses-permission android:name="android.permission.CAMERA" /><-- adicionas esta linha não removendo nada e seguindo esta lógica

+  <uses-sdk tools:overrideLibrary="com.google.zxing.client.android" /><-- adicionas esta linha não removendo nada e seguindo esta lógica
</manifest>
class KtApp : Application() {

    init {
        instance = this
    }

    companion object{
        private var instance: Application? = null
        fun getInstance(): Application? {
            return instance
        }
    }

    override fun onCreate() {
        super.onCreate()

    }
}
import androidx.preference.PreferenceManager
import com.delfi.area51.ktstart.KtApp

open class PrefUtils {

    companion object {
        private fun getSharePreferences() =
            PreferenceManager.getDefaultSharedPreferences(KtApp.getInstance())

        private fun getEditor() = getSharePreferences().edit()

        fun getString(key: String) = getSharePreferences().getString(key, "")
        fun setString(key: String, value: String) = getEditor().putString(key, value).apply()

        fun getLong(key: String) = getSharePreferences().getLong(key, 0)
        fun setLong(key: String, value: Long) = getEditor().putLong(key, value).apply()

        fun getInt(key: String): Int = getSharePreferences().getInt(key, 0)
        fun setInt(key: String, value: Int) = getEditor().putInt(key, value).apply()
        
        fun getBoolean(key: String): Boolean = getSharePreferences().getBoolean(key, false)
        fun setBoolean(key: String, value: Boolean) = getEditor().putBoolean(key, value).apply()
    }
}
You need to override onSaveInstanceState(Bundle outState).

The method you're overriding only gets called if with the attribute persistableMode is set to persistAcrossReboots in your Manifest.
/html/body/div[2]/dl[6]
<ScrollView
...
android:overScrollMode="never"
... />
RotatedBox(quarterTurns:turns,
  child: AspectRatio(
    aspectRatio: _controller.value.aspectRatio,
    child:  Stack(
      alignment: Alignment.bottomCenter,
      children: [

        VideoPlayer(_controller),
        _ControlsOverlay(controller: _controller,onClickCallback:(){
          setState(() {
            if( turns==0)
              turns=1;
            else turns=0;
          });
        }),
        VideoProgressIndicator(_controller, allowScrubbing: true),

      ],

    ),),
<?xml version="1.0" encoding="utf-8"?>

  <ScrollView

        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:fillViewport="true"
  >

    <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/constraint_layout1"
            >


        <com.google.android.material.textfield.TextInputLayout

                android:layout_width="0dp"
                android:layout_height="wrap_content"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintBottom_toTopOf="@+id/username_input_layout"
                android:padding="16dp"
                app:helperText="Email"
                android:id="@+id/email_input_layout"
                app:layout_constraintVertical_chainStyle="packed"
                app:layout_constraintVertical_bias=".1"

        >

            <TextView

                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/email"
                    android:textColor="#000"
                    android:hint="@string/your_email"
                    android:textSize="20sp"
            />

        </com.google.android.material.textfield.TextInputLayout>


        <com.google.android.material.textfield.TextInputLayout

                android:layout_width="0dp"
                android:layout_height="wrap_content"
                app:layout_constraintTop_toBottomOf="@+id/email_input_layout"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintBottom_toTopOf="@+id/change_password"
                android:padding="16dp"
                app:helperText="Username"
                android:id="@+id/username_input_layout"

        >

            <TextView

                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/username"
                    android:textColor="#000"
                    android:hint="@string/your_username"
                    android:textSize="20sp"

            />

        </com.google.android.material.textfield.TextInputLayout>


        <TextView

                android:layout_width="0dp"
                android:layout_height="wrap_content"
                app:layout_constraintTop_toBottomOf="@+id/username_input_layout"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                android:textSize="18sp"
                android:textColor="@color/link_blue"
                android:text="@string/change_password"
                android:id="@+id/change_password"
                android:gravity="center"

        />

        <Button

                android:id="@+id/logout_button"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                app:layout_constraintTop_toBottomOf="@+id/change_password"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                android:background="@drawable/red_button_drawable"
                android:text="Log out"
                android:textAllCaps="false"
                android:textColor="#fff"
                android:textSize="16sp"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_marginTop="50dp"
                android:layout_marginBottom="30dp"

        />
                  
    </androidx.constraintlayout.widget.ConstraintLayout>


</ScrollView>
// Create an array and instantiate a listview
val myArray : MutableList<BigInteger> = mutableListOf(); val lstView = findViewById<ListView>(R.id.lsvw)

// Create an adapter and link it to the listview
val arrayAdapter : ArrayAdapter<BigInteger> = ArrayAdapter<BigInteger(this, android.R.layout.simple_list_item_1, myArray)
lstView.adapter = arrayAdapter

// Add data to the array and push it to the adapter
myArray.add(<data>)
arrayAdapter.notifyDataSetChanged()
userInput.setOnKeyListener(View.OnKeyListener { v, keyCode, event ->

	if (keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_UP) {

		//code
		return@OnKeyListener true

	}

	false

})
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:focusable="true"
    android:clickable="true"
    card_view:cardCornerRadius="@dimen/card_corner_radius"
    card_view:cardUseCompatPadding="true">

    <LinearLayout
        android:id="@+id/card_item"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:foreground="?android:attr/selectableItemBackground"
        android:padding="@dimen/card_padding">

    </LinearLayout>
</android.support.v7.widget.CardView>
class SleepTrackerViewModelFactory(
       private val dataSource: SleepDatabaseDao,
       private val application: Application) : ViewModelProvider.Factory {
   @Suppress("unchecked_cast")
   override fun <T : ViewModel?> create(modelClass: Class<T>): T {
       if (modelClass.isAssignableFrom(SleepTrackerViewModel::class.java)) {
           return SleepTrackerViewModel(dataSource, application) as T
       }
       throw IllegalArgumentException("Unknown ViewModel class")
   }
}
implementation 'com.squareup.retrofit2:retrofit:2.3.0'  
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'  
implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
// build.gradle (Module: ...)

// Android Studio 4.0
android {
    buildFeatures {
        viewBinding = true
    }
}
// MyFragment.kt

class MyFragment : Fragment(R.layout.fragment_my) {
  
  private var _binding: MyFragmentBinding? = null
  private val binding get() = _binding!!

  override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    
    _binding = MyFragmentBinding.bind(view)
    
    binding.someview.text = "bla bla"
  }

  override fun onDestroyView() {
    super.onDestroyView()
    _binding = null
  }
}
public class ActivityName extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // remove title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
    }
}


// then you need to add new theme
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>


//and then use it AndroidManifest.xml file:
<activity android:name=".ActivityName"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen"/>
keytool -exportcert -list -v \
-alias <your-key-name> -keystore <path-to-production-keystore>
UPDATE TABLE_NAME
SET COL_NAME = REPLACE(COL_NAME, 'OLD_URL/', 'NEW_URL/') where 1
import 'package:flutter/material.dart';

void main() {
  runApp(
    new MaterialApp(
      title: 'Hello World App',
      home: new myApp(),
    )
  );
}

class myApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Hello World App'),
      ),
      body: new Center(
        child: new Text(
          'Hello, world!'
        ),
      ),
    );
  }
}
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:angle="45"
        android:startColor="#ff00ff"
        android:endColor="#000000"/>
</shape>
> More steps
// IntendedActivity - the file you wish to open
// CurrentActivity - the file where this code is placed  

Intent intent = new Intent (this, IntendedActivity.class);
    CurrentActivity.this.startActivity(intent);
public class LocalDatabase extends SQLiteOpenHelper {
         
    private static final String mDatabaseName = "LocalDatabase";
    private static final int mDatabaseVersion = 1;

public LocalDatabase(Context context) {
        super(context, mDatabaseName, null, mDatabaseVersion);
        SQLiteDatabase db = this.getWritableDatabase();
    }      

}
> More steps
public class MainActivity extends AppCompatActivity{ 
    private Button mButton;

   protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mButton = findViewById(R.id.mButton);

       
   }
}
> More steps
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <ImageView
        android:id="@+id/app_icon"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:focusable="false"
        android:clickable="false"
        android:contentDescription="@string/app_name"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="16dp"
        android:paddingBottom="8dp"/>

    <TextView
        android:id="@+id/list_app_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textIsSelectable="false"
        android:textSize="16dp"
        android:textColor="#000000"
        android:layout_toEndOf="@+id/app_icon"
        android:layout_alignTop="@+id/app_icon"
        android:layout_marginStart="16dp"
        android:layout_marginTop="2dp"
        android:text="@string/app_name"/>
    <CheckBox
        android:id="@+id/list_app_checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_marginEnd="12dp"
        android:checked="false"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:clickable="false"
        android:layout_alignTop="@id/list_app_name"

        />

</RelativeLayout>

> More steps
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    android:background="@drawable/backgroundgradient"
    tools:context=".ui.Signup">

    <ImageView
            android:layout_width="130dp"
            android:layout_height="100dp"
            android:layout_centerInParent="true"
            android:src="@drawable/logosp" />

</RelativeLayout>
> More steps
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <ImageView
        android:id="@+id/app_icon"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:focusable="false"
        android:clickable="false"
        android:contentDescription="@string/app_name"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="16dp"
        android:paddingBottom="8dp"/>

    <TextView
        android:id="@+id/list_app_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textIsSelectable="false"
        android:textSize="16dp"
        android:textColor="#000000"
        android:layout_toEndOf="@+id/app_icon"
        android:layout_alignTop="@+id/app_icon"
        android:layout_marginStart="16dp"
        android:layout_marginTop="2dp"
        android:text="@string/app_name"/>
    <CheckBox
        android:id="@+id/list_app_checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_marginEnd="12dp"
        android:checked="false"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:clickable="false"
        android:layout_alignTop="@id/list_app_name"

        />

</RelativeLayout>

> More steps
public class User {

    public String mUsername;

    public User(){
        // Default constructor required for calls to DataSnapshot.getValue(User.class)
    }

    public User( String userName){
        this.mUsername = userName;
    }
}
> More steps
    private ArrayList<String> arrayList;
    ListAdapter listAdapter;

   String[] array = new String[5];
                array[0] = "optn 1";
                array[1] = "optn 2";
                array[2] = "optn 3";
// in on create method

        arrayList = new ArrayList<>();
        listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1 , array);
        mAvailableProfilesList.setAdapter(listAdapter);
        
> More steps
allprojects {
    repositories {
      google()
      jcenter()
    }
  }
> More steps
star

Wed Sep 06 2023 06:33:22 GMT+0000 (Coordinated Universal Time) https://snipsave.com/user/iliyafda/snippet/KuvAIDcTtaKEwg9i5A/

#kotlin #android
star

Thu Nov 10 2022 19:24:05 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/51141970/check-internet-connectivity-android-in-kotlin

#kotlin #android
star

Thu Nov 10 2022 06:44:55 GMT+0000 (Coordinated Universal Time)

#android #kot
star

Mon Aug 29 2022 19:46:59 GMT+0000 (Coordinated Universal Time)

#delphi #android
star

Thu Jul 21 2022 07:33:38 GMT+0000 (Coordinated Universal Time)

#kotlin #android
star

Wed Mar 30 2022 05:06:07 GMT+0000 (Coordinated Universal Time)

#android #kotlin
star

Wed Mar 30 2022 05:05:19 GMT+0000 (Coordinated Universal Time)

#android #kotlin
star

Wed Mar 30 2022 03:55:35 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/33968879/onsaveinstancestate-is-not-called-on-orientation-change-before-ondestroy-to-sa

#android #kotlin
star

Thu Mar 10 2022 08:13:17 GMT+0000 (Coordinated Universal Time) https://www.gnu.org/cgi-bin/estseek.cgi?phrase=Android+12&attr0=&attr1=&attr2=&order=&perpage=10&clip=9&navi=1

#android
star

Fri Dec 17 2021 09:36:11 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/11603267/scrollview-change-the-edge-effect-color-with-holo

#android #xml
star

Tue Sep 14 2021 12:54:07 GMT+0000 (Coordinated Universal Time) https://rrtutors.com/tutorials/how-to-rotate-flutter-widget

#flutter #android
star

Tue May 11 2021 16:05:39 GMT+0000 (Coordinated Universal Time)

#kotlin #android
star

Tue May 11 2021 16:02:40 GMT+0000 (Coordinated Universal Time)

#kotlin #android
star

Tue May 11 2021 15:57:13 GMT+0000 (Coordinated Universal Time)

#kotlin #android
star

Sun Apr 04 2021 03:01:38 GMT+0000 (Coordinated Universal Time)

#android #java
star

Sun Apr 04 2021 03:01:06 GMT+0000 (Coordinated Universal Time) https://www.semicolonworld.com/question/48686/ripple-effect-on-android-lollipop-cardview

#android #java
star

Fri Feb 26 2021 04:53:44 GMT+0000 (Coordinated Universal Time) https://developer.android.com/codelabs/kotlin-android-training-coroutines-and-room

#kotlin #android
star

Fri Feb 05 2021 16:26:52 GMT+0000 (Coordinated Universal Time) https://www.c-sharpcorner.com/article/how-to-use-retrofit-2-with-android-using-kotlin/

#android
star

Wed Feb 03 2021 13:37:35 GMT+0000 (Coordinated Universal Time)

#android #androidstudio #gradle
star

Wed Feb 03 2021 13:29:33 GMT+0000 (Coordinated Universal Time)

#kotlin #android
star

Wed Aug 26 2020 07:41:24 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/2868047/fullscreen-activity-in-android

#android
star

Wed May 27 2020 18:25:34 GMT+0000 (Coordinated Universal Time) https://developers.google.com/android/guides/client-auth

#android
star

Mon Feb 17 2020 07:36:12 GMT+0000 (Coordinated Universal Time)

#android #php
star

Sun Dec 29 2019 19:42:22 GMT+0000 (Coordinated Universal Time) https://kodestat.gitbook.io/flutter/flutter-hello-world

#android #dart #flutter #ios #helloworld

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension