🗒️
notes
  • Journal
  • URLs
  • Java Card
    • SCP02
    • Rapid Notes
    • _FIXVALS_
    • Mifare
    • Chain Of Trust
  • Encoding
    • CBEFF
    • Bytes
  • Snippets
    • JNI_OnLoad
  • float to byte[]
  • Protobuf
  • C/C++
    • Containers
    • Basics
    • JNI
    • gcov
    • Castings
  • chess
    • Untitled
  • Compression
    • Untitled
  • Snippets
    • Untitled
  • Build Systems
    • Maven
    • Windows
  • Gradle
  • CMake
  • Java
    • Untitled
    • Certificates
  • Android
    • Mifare
  • Python
    • ctypes
  • WebSub
    • References
  • Spring Boot
    • Form-based Authentication
    • Basic Access Authentication
    • JWT Authentication
  • QR Code
    • Denso QR Code
  • Philosophical Inquiry
    • First
  • XML
    • xmlstarlet
Powered by GitBook
On this page

Was this helpful?

Journal

Dated notes

Sat, Jun 6, 2020 7:30:08 PM

Practicing how to create a ListView in Android. Using default Android resources such as android.R.drawable.presence_online because it has its pair android.R.drawable.presence_offline.

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

</ListView>

The @android:id/list is tricky because I am using ListActivity

I traced via println("*") the optimization benefits of an improved ArrayAdapter implementation decreasing the expensive operations layout inflation and object creation through some sort of caching technique via View::setTag and View::getTag.

There are 20 rows in your list but Android can only display in the ListView 16 rows. When the app is executed, these 16 rows will be inflated. The remaining 4 rows will not be inflated. When you scroll down such that 4 new row appears, there will be an inflation operation for this 4 new rows. It is Android that knows wither new rows appear by calling the getView method of ArrayAdapter. You shall check if the param is null or not. As you scroll back and forth, there will be no more inflation and you retrieved the cached view via getTag call. According to vogella, the avoidance of findViewById improves performance by 15%.

I was surprise when I extend Kotlin's ByteArray to do hex dump when it also became available to ByteBuffer :

fun generateFloat(n:Int) : List<Float>
{
    val maxval = 3 // 0 to 3.0
    var nf = FloatArray(n) {
        nextFloat() * (maxval)
    }.take(n)
    
    return nf
}

fun ByteArray.hexdump(title:String = "",col:Int = 8)
{
    println("[${title}]")

    for (i in 0 until size) {
        if (i != 0 && i % 8 == 0) println()
        var b = String.format("%02X ",this[i])
        print(b)
    }

    println()
}

Some float to hex table:

float

4 bytes representation

0.123

3D FB E7 6D

0.456

3E E9 78 D5

0.789

3F 49 FB E7

3.14159

40 49 0F D0

-1.234

BF 9D F3 B6

If error an Android Studio:

No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android

Then try build.gradle edit using:

classpath 'com.android.tools.build:gradle:3.2.1'

Also, not sure but gradle minimum version is 4.6 !?!

Mon, Jun 8, 2020 3:19:55 PM

Inside CMakeLists.txt, a separate if is better than with chained elseif to be more discreet.

cmake_minimum_required(VERSION 3.10.1)
project(proj)

if (ANDROID)
    message(STATUS "ON_ANDROID")
    add_compile_definitions(ON_ANDROID)
endif()

if (CYGWIN)
    message(STATUS "ON_CYGWIN")
    add_compile_definitions(ON_CYGWIN)
endif()

if (WIN32)
    message(STATUS "ON_WIN32")
    add_compile_definitions(ON_WIN32)
endif()

if (MSVC)
    message(STATUS "ON_MSVC")
    add_compile_definitions(ON_MSVC)
endif()

if (UNIX)
    message(STATUS "ON_UNIX")
    add_compile_definitions(ON_UNIX)
endif()

if(NOT ANDROID AND NOT CYGWIN AND NOT WIN32 AND NOT UNIX AND NOT MSVC)
    message(STATUS "ON_UNKNOWN")
    add_compile_definitions(ON_UNKNOWN)
endif()

For example, in an Android build it is both ON_ANDROID and ON_UNIX. In a cygwin shell, it is both ON_CYGWIN and ON_UNIX. In a Windows git bash shell, it is both ON_WIN32 and ON_MSVC. On Linux shell, it is only ON_UNIX.

Sloppy today. I specified:

tar cvzpf stuff.tar.bz2 stuff/

And combined with circleci settings:

- store_artifacts:
  path: /path/to/stuff.tar.bz2
  destination: android

The artifacts appear as android in contrast to what I expected as android/stuff.tar.bz2 . And then, the file type was gzip format I thought it was circleci doing it. Upon review, it was my z option in my tar command making it into gzip format but with .bz2 extension. Better to skip use of optional destination field so that all outputs are explicit and better tracking.

Got thrown off by ?circle-ci=xxxxx

Wed, Jun 10, 2020 3:01:37 PM

Both sliceArray and copyOfRange have same starting point but they differ in the ending. The sliceArray has inclusive ending whereas copyOfRange means up to but not including end part.

fun testslice()
{
    var buf = sodium.randomBytesBuf(10)
    var buf3_10 = buf.sliceArray(3..9)
    var bufff = buf.copyOfRange(3, 10)

    if (buf3_10.contentEquals(bufff)) {
        println("same content")
    }
}

In the above snippet at line 4, the sliceArray must use 9 otherwise code will crash. Both lines 4 and 5 are doing same thing. Notice also that sliceArray uses .. instead of ,.

So today, I think my Haskell familiarization study paid off a little. I was browsing through a Kotlin tutorial and found this:

package com.zetcode

fun main() {
    
    val nums = intArrayOf(2, 3, 4, 5, 6, 7)

    val total = nums.reduce { product, next -> 
        product * next 
    }

    println(total)
}

So thanks to my Haskell tinkering in the past, this looks like the familiar fold function in the Haskell world. This fold thing really got me into a limbo I remember because it is such an alien construct. I also remember, it has a variant called fold1 and how these two differs. The Kotlin reduce function is the fold1 in Haskell. Change the array by starting with 0 instead of 2 as in the above snippet you will see it will print 0 . The fold1 variant uses the first element as the initial value of the accumulator.

NextURLs

Last updated 4 years ago

Was this helpful?