xxxxxxxxxx
FOR ONLINE
https://play.kotlinlang.org/#eyJ2ZXJzaW9uIjoiMS41LjMxIiwicGxhdGZvcm0iOiJqYXZhIiwiYXJncyI6IiIsIm5vbmVNYXJrZXJzIjp0cnVlLCJ0aGVtZSI6ImlkZWEiLCJjb2RlIjoiLyoqXG4gKiBZb3UgY2FuIGVkaXQsIHJ1biwgYW5kIHNoYXJlIHRoaXMgY29kZS4gXG4gKiBwbGF5LmtvdGxpbmxhbmcub3JnIFxuICovXG5cbmZ1biBtYWluKCkge1xuICAgIHByaW50bG4oXCJIZWxsbywgd29ybGQhISFcIilcbn0ifQ==
IN ANDROID STUDIO
"code" -> "Convert Java File to Kotlin File"
xxxxxxxxxx
private fun emitBubbles() {
// It will create a thread and attach it to
// the main thread
Handler().postDelayed({
// Random is used to select random bubble
// size
val size = Random.nextInt(20, 80)
bubbleEmitter.emitBubble(size)
bubbleEmitter.setColors(android.R.color.black,
android.R.color.black,
android.R.color.black);
emitBubbles()
}, Random.nextLong(100, 500))
}
xxxxxxxxxx
private fun emitBubbles() {
// It will create a thread and attach it to
// the main thread
Handler().postDelayed({
// Random is used to select random bubble
// size
val size = Random.nextInt(20, 80)
bubbleEmitter.emitBubble(size)
bubbleEmitter.setColors(android.R.color.black,
android.R.color.black,
android.R.color.black);
emitBubbles()
}, Random.nextLong(100, 500))
}
xxxxxxxxxx
private var imageCapture: ImageCapture? = null
private lateinit var outputDirectory: File
private lateinit var cameraExecutor: ExecutorService
xxxxxxxxxx
private fun startUpdateTimer() {
timer = Timer()
timer?.scheduleAtFixedRate(object : TimerTask() {
override fun run() {
// only the UI thread can edit the activity appearance
this@MainActivity.runOnUiThread {
updateUI()
if (!countdownServiceRunning) {
stopUpdateTimer()
}
}
}
}, 100, 1000)
}
xxxxxxxxxx
private static final String APKLIS_PAID = "paid";
private static final String APKLIS_USER_NAME = "user_name";
public static Pair<Boolean, String> isPurchased(Context context, String packageId) {
boolean paid = false;
String userName = null;
Uri providerURI = Uri.parse(APKLIS_PROVIDER+packageId);
try {
ContentProviderClient contentResolver = context.getContentResolver().acquireContentProviderClient(providerURI);
Cursor cursor = contentResolver.query(providerURI, null, null, null, null);
if (cursor.moveToFirst()) {
paid = cursor.getInt(cursor.getColumnIndex(APKLIS_PAID)) > 0;
userName = cursor.getString(cursor.getColumnIndex(APKLIS_USER_NAME));
}
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
contentResolver.close();
} else {
contentResolver.release();
}
cursor.close();
} catch (RemoteException e) {
e.printStackTrace();
}
return new Pair(paid, userName);
}
}
xxxxxxxxxx
package br.com.treinaweb.springbootapi.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Pessoa
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(nullable = false)
private String nome;
public long getId() {
return id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public void setId(long id) {
this.id = id;
}
}
xxxxxxxxxx
val networkCallback = object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) {
super.onAvailable(network)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// To make sure that requests don't go over mobile data
connectivityManager.bindProcessToNetwork(network)
} else {
connectivityManager.setProcessDefaultNetwork(network)
}
}
override fun onLost(network: Network) {
super.onLost(network)
// This is to stop the looping request for OnePlus & Xiaomi models
connectivityManager.bindProcessToNetwork(null)
connectivityManager.unregisterNetworkCallback(networkCallback)
// Here you can have a fallback option to show a 'Please connect manually' page with an Intent to the Wifi settings
}
}