1private fun loading(view: View, loading: Boolean) {
2 view.takeIf { view is ViewGroup }?.let {
3 for (i in 0 until (view as ViewGroup).childCount) {
4 val childAt = view.getChildAt(i)
5 (childAt as? ISkeletonDrawer)?.let {
6 if (!loading) {
7 it.startLoading()
8 } else {
9 it.stopLoading()
10 }
11 }
12 run { loading(childAt, loading) }
13 }
14 }
15
16 }
1 private fun imageToByteBuffer(image: Image, outputBuffer: ByteArray) {
2 assert(image.format == ImageFormat.YUV_420_888)
3
4 val imageCrop = image.cropRect
5 val imagePlanes = image.planes
6
7 imagePlanes.forEachIndexed { planeIndex, plane ->
1val networkCallback = object : ConnectivityManager.NetworkCallback() {
2 override fun onAvailable(network: Network) {
3 super.onAvailable(network)
4 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
5 // To make sure that requests don't go over mobile data
6 connectivityManager.bindProcessToNetwork(network)
7 } else {
8 connectivityManager.setProcessDefaultNetwork(network)
9 }
10 }
11
12 override fun onLost(network: Network) {
13 super.onLost(network)
14 // This is to stop the looping request for OnePlus & Xiaomi models
15 connectivityManager.bindProcessToNetwork(null)
16 connectivityManager.unregisterNetworkCallback(networkCallback)
17 // Here you can have a fallback option to show a 'Please connect manually' page with an Intent to the Wifi settings
18 }
19}
1 private static final String APKLIS_PAID = "paid";
2 private static final String APKLIS_USER_NAME = "user_name";
3
4 public static Pair<Boolean, String> isPurchased(Context context, String packageId) {
5 boolean paid = false;
6 String userName = null;
7 Uri providerURI = Uri.parse(APKLIS_PROVIDER+packageId);
8 try {
9 ContentProviderClient contentResolver = context.getContentResolver().acquireContentProviderClient(providerURI);
10 Cursor cursor = contentResolver.query(providerURI, null, null, null, null);
11 if (cursor.moveToFirst()) {
12 paid = cursor.getInt(cursor.getColumnIndex(APKLIS_PAID)) > 0;
13 userName = cursor.getString(cursor.getColumnIndex(APKLIS_USER_NAME));
14 }
15 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
16 contentResolver.close();
17 } else {
18 contentResolver.release();
19 }
20 cursor.close();
21 } catch (RemoteException e) {
22 e.printStackTrace();
23 }
24 return new Pair(paid, userName);
25 }
26}
1private fun countWordExtEmbeddedImage(`is`: InputStream?): Int {
2 try {
3 // https://www.baeldung.com/java-microsoft-word-with-apache-poi
4 // 重複的圖片不會計算在內
5 val doc = XWPFDocument(`is`)
6 val pics:List<XWPFPictureData> = doc.getAllPictures()
7 var embed_cnt = 0
8 for (pic in pics) {
9 embed_cnt ++
10 }
11 doc.close()
12 return embed_cnt
13 } catch (ex: Exception) {
14 LOG.error(ex.message)
15 }
16 return -1
17}
1
2
3 private fun emitBubbles() {
4 // It will create a thread and attach it to
5 // the main thread
6 Handler().postDelayed({
7 // Random is used to select random bubble
8 // size
9 val size = Random.nextInt(20, 80)
10 bubbleEmitter.emitBubble(size)
11 bubbleEmitter.setColors(android.R.color.black,
12 android.R.color.black,
13 android.R.color.black);
14 emitBubbles()
15 }, Random.nextLong(100, 500))
16 }
17
1private var imageCapture: ImageCapture? = null
2
3 private lateinit var outputDirectory: File
4 private lateinit var cameraExecutor: ExecutorService
5
1class UserProfileViewModel : ViewModel() {
2 val userId : String = TODO()
3 val user : User = TODO()
4}