# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1621736832 0 # Node ID 473eb9ff3f0434026e808c3abb6b0f4d9f21a12a # Parent 68ee9a89e0f01f1d937f477d1719e14f9f977f0f Android: Implement dw_container_set_stripe() and center the images in the rows. Also switch to using jlong (Long) types for passing the colors internally. diff -r 68ee9a89e0f0 -r 473eb9ff3f04 android/DWindows.kt --- a/android/DWindows.kt Sat May 22 23:48:08 2021 +0000 +++ b/android/DWindows.kt Sun May 23 02:27:12 2021 +0000 @@ -621,6 +621,8 @@ var model = DWContainerModel() var selectedItem: Int = -1 var simpleMode: Boolean = true + var oddColor: Int? = null + var evenColor: Int? = null override fun getCount(): Int { return model.numberOfRows() @@ -660,9 +662,11 @@ // Image if((model.getColumnType(i) and 1) != 0) { val imageview = ImageView(context) + val params = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, + LinearLayout.LayoutParams.WRAP_CONTENT) + params.gravity = Gravity.CENTER + imageview.layoutParams = params imageview.id = View.generateViewId() - imageview.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, - LinearLayout.LayoutParams.WRAP_CONTENT) if (content is Drawable) { imageview.setImageDrawable(content) } @@ -670,9 +674,11 @@ } else { // Everything else id displayed as text val textview = TextView(context) + val params = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT) + params.gravity = Gravity.CENTER + textview.layoutParams = params textview.id = View.generateViewId() - textview.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT) if (content is String) { textview.text = content } else if(content is Int) { @@ -709,6 +715,16 @@ } } } + // Handle row stripe + if (position % 2 == 0) { + if(evenColor != null) { + rowView.setBackgroundColor(evenColor!!) + } + } else { + if(oddColor != null) { + rowView.setBackgroundColor(oddColor!!) + } + } return rowView } } @@ -2076,6 +2092,30 @@ return cont } + fun containerSetStripe(cont: ListView, oddcolor: Long, evencolor: Long) + { + waitOnUiThread { + val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter + + if(oddcolor == -1L) { + adapter.oddColor = null + } else if(evencolor == -2L) { + if(darkMode == 1) { + adapter.oddColor = Color.rgb(100, 100, 100) + } else { + adapter.oddColor = Color.rgb(230, 230, 230) + } + } else { + adapter.oddColor = colorFromDW(oddcolor) + } + if(evencolor == -1L || evencolor == -2L) { + adapter.evenColor = null + } else { + adapter.evenColor = colorFromDW(evencolor) + } + } + } + fun containerGetTitleStart(cont: ListView, flags: Int): String? { var retval: String? = null @@ -2808,7 +2848,7 @@ return retval } - fun drawPoint(render: DWRender?, bitmap: Bitmap?, x: Int, y: Int, fgColor: Int, bgColor: Int) + fun drawPoint(render: DWRender?, bitmap: Bitmap?, x: Int, y: Int, fgColor: Long, bgColor: Long) { waitOnUiThread { var canvas: Canvas? = null @@ -2826,7 +2866,7 @@ } } - fun drawLine(render: DWRender?, bitmap: Bitmap?, x1: Int, y1: Int, x2: Int, y2: Int, fgColor: Int, bgColor: Int) + fun drawLine(render: DWRender?, bitmap: Bitmap?, x1: Int, y1: Int, x2: Int, y2: Int, fgColor: Long, bgColor: Long) { waitOnUiThread { var canvas: Canvas? = null @@ -2886,7 +2926,7 @@ } fun drawText(render: DWRender?, bitmap: Bitmap?, x: Int, y: Int, text:String, typeface: Typeface?, - fontsize: Int, window: View?, fgColor: Int, bgColor: Int) + fontsize: Int, window: View?, fgColor: Long, bgColor: Long) { waitOnUiThread { var canvas: Canvas? = null @@ -2943,7 +2983,7 @@ } } - fun drawRect(render: DWRender?, bitmap: Bitmap?, x: Int, y: Int, width: Int, height: Int, fgColor: Int, bgColor: Int) + fun drawRect(render: DWRender?, bitmap: Bitmap?, x: Int, y: Int, width: Int, height: Int, fgColor: Long, bgColor: Long) { waitOnUiThread { var canvas: Canvas? = null @@ -2964,7 +3004,7 @@ } fun drawPolygon(render: DWRender?, bitmap: Bitmap?, flags: Int, npoints: Int, - x: IntArray, y: IntArray, fgColor: Int, bgColor: Int) + x: IntArray, y: IntArray, fgColor: Long, bgColor: Long) { // Create a path with all our points val path = Path() @@ -3003,7 +3043,7 @@ } fun drawArc(render: DWRender?, bitmap: Bitmap?, flags: Int, xorigin: Int, yorigin: Int, - x1: Int, y1: Int, x2: Int, y2: Int, fgColor: Int, bgColor: Int) + x1: Int, y1: Int, x2: Int, y2: Int, fgColor: Long, bgColor: Long) { waitOnUiThread { var canvas: Canvas? = null @@ -3067,39 +3107,23 @@ } } - fun colorSet(alpha: Int, red: Int, green: Int, blue: Int) + fun colorFromDW(color: Long): Int + { + val red: Int = (color and 0x000000FF).toInt() + val green: Int = ((color and 0x0000FF00) shr 8).toInt() + val blue: Int = ((color and 0x00FF0000) shr 16).toInt() + + return Color.rgb(red, green, blue) + } + + fun colorsSet(fgColor: Long, bgColor: Long) { waitOnUiThread { - if(alpha != 0) { - paint.color = Color.argb(alpha, red, green, blue) - } else { - paint.color = Color.rgb(red, green, blue) - } + paint.color = colorFromDW(fgColor) + this.bgcolor = colorFromDW(bgColor) } } - fun bgColorSet(alpha: Int, red: Int, green: Int, blue: Int) - { - if(alpha != 0) { - this.bgcolor = Color.argb(alpha, red, green, blue) - } else { - this.bgcolor = Color.rgb(red, green, blue) - } - } - - fun colorsSet(fgColor: Int, bgColor: Int) - { - val fgRed: Int = (fgColor and 0x000000FF) - val fgGreen: Int = (fgColor and 0x0000FF00) shr 8 - val fgBlue: Int = (fgColor and 0x00FF0000) shr 16 - val bgRed: Int = (bgColor and 0x000000FF) - val bgGreen: Int = (bgColor and 0x0000FF00) shr 8 - val bgBlue: Int = (bgColor and 0x00FF0000) shr 16 - - paint.color = Color.rgb(fgRed, fgGreen, fgBlue) - this.bgcolor = Color.rgb(bgRed, bgGreen, bgBlue) - } - fun timerConnect(interval: Long, sigfunc: Long, data: Long): Timer { // creating timer task, timer diff -r 68ee9a89e0f0 -r 473eb9ff3f04 android/dw.cpp --- a/android/dw.cpp Sat May 22 23:48:08 2021 +0000 +++ b/android/dw.cpp Sun May 23 02:27:12 2021 +0000 @@ -718,11 +718,11 @@ }; /* Return the RGB color regardless if a predefined color was passed */ -unsigned long _dw_get_color(unsigned long thiscolor) +jlong _dw_get_color(unsigned long thiscolor) { if(thiscolor & DW_RGB_COLOR) { - return thiscolor & ~DW_RGB_COLOR; + return ((jlong)thiscolor) & ~DW_RGB_COLOR; } else if(thiscolor < 17) { @@ -2700,16 +2700,16 @@ if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) { - unsigned long fgcolor = (unsigned long)pthread_getspecific(_dw_fgcolor_key); - unsigned long bgcolor = (unsigned long)pthread_getspecific(_dw_bgcolor_key); + jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); + jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); // First get the class that contains the method you need to call jclass clazz = _dw_find_class(env, DW_CLASS_NAME); // Get the method that you want to call jmethodID drawPoint = env->GetMethodID(clazz, "drawPoint", - "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIII)V"); + "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIJJ)V"); // Call the method on the object - env->CallVoidMethod(_dw_obj, drawPoint, handle, pixmap ? pixmap->bitmap : nullptr, x, y, (jint)fgcolor, (jint)bgcolor); + env->CallVoidMethod(_dw_obj, drawPoint, handle, pixmap ? pixmap->bitmap : nullptr, x, y, fgcolor, bgcolor); _dw_jni_check_exception(env); } } @@ -2729,16 +2729,16 @@ if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) { - unsigned long fgcolor = (unsigned long)pthread_getspecific(_dw_fgcolor_key); - unsigned long bgcolor = (unsigned long)pthread_getspecific(_dw_bgcolor_key); + jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); + jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); // First get the class that contains the method you need to call jclass clazz = _dw_find_class(env, DW_CLASS_NAME); // Get the method that you want to call jmethodID drawLine = env->GetMethodID(clazz, "drawLine", - "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIIII)V"); + "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIIJJ)V"); // Call the method on the object - env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, x1, y1, x2, y2, (jint)fgcolor, (jint)bgcolor); + env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, x1, y1, x2, y2, fgcolor, bgcolor); _dw_jni_check_exception(env); } } @@ -2757,8 +2757,8 @@ if((handle || pixmap) && text && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) { - unsigned long fgcolor = (unsigned long)pthread_getspecific(_dw_fgcolor_key); - unsigned long bgcolor = (unsigned long)pthread_getspecific(_dw_bgcolor_key); + jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); + jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); // Construct the string jstring jstr = env->NewStringUTF(text); @@ -2766,11 +2766,11 @@ jclass clazz = _dw_find_class(env, DW_CLASS_NAME); // Get the method that you want to call jmethodID drawLine = env->GetMethodID(clazz, "drawText", - "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IILjava/lang/String;Landroid/graphics/Typeface;ILandroid/view/View;II)V"); + "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IILjava/lang/String;Landroid/graphics/Typeface;ILandroid/view/View;JJ)V"); // Call the method on the object env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, x, y, jstr, pixmap ? pixmap->typeface : nullptr, pixmap ? pixmap->fontsize : 0, - pixmap ? pixmap->handle : nullptr, (jint)fgcolor, (jint)bgcolor); + pixmap ? pixmap->handle : nullptr, fgcolor, bgcolor); _dw_jni_check_exception(env); } } @@ -2829,8 +2829,8 @@ if(jx && jy) { - unsigned long fgcolor = (unsigned long)pthread_getspecific(_dw_fgcolor_key); - unsigned long bgcolor = (unsigned long)pthread_getspecific(_dw_bgcolor_key); + jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); + jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); // Construct the integer arrays env->SetIntArrayRegion(jx, 0, npoints, x); @@ -2839,9 +2839,9 @@ jclass clazz = _dw_find_class(env, DW_CLASS_NAME); // Get the method that you want to call jmethodID drawPolygon = env->GetMethodID(clazz, "drawPolygon", - "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;II[I[III)V"); + "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;II[I[IJJ)V"); // Call the method on the object - env->CallVoidMethod(_dw_obj, drawPolygon, handle, pixmap ? pixmap->bitmap : nullptr, flags, npoints, jx, jy, (jint)fgcolor, (jint)bgcolor); + env->CallVoidMethod(_dw_obj, drawPolygon, handle, pixmap ? pixmap->bitmap : nullptr, flags, npoints, jx, jy, fgcolor, bgcolor); _dw_jni_check_exception(env); } } @@ -2863,16 +2863,16 @@ if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) { - unsigned long fgcolor = (unsigned long)pthread_getspecific(_dw_fgcolor_key); - unsigned long bgcolor = (unsigned long)pthread_getspecific(_dw_bgcolor_key); + jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); + jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); // First get the class that contains the method you need to call jclass clazz = _dw_find_class(env, DW_CLASS_NAME); // Get the method that you want to call jmethodID drawLine = env->GetMethodID(clazz, "drawRect", - "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIIII)V"); + "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIIJJ)V"); // Call the method on the object - env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, x, y, width, height, (jint)fgcolor, (jint)bgcolor); + env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, x, y, width, height, fgcolor, bgcolor); _dw_jni_check_exception(env); } } @@ -2896,16 +2896,16 @@ if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) { - unsigned long fgcolor = (unsigned long)pthread_getspecific(_dw_fgcolor_key); - unsigned long bgcolor = (unsigned long)pthread_getspecific(_dw_bgcolor_key); + jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); + jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); // First get the class that contains the method you need to call jclass clazz = _dw_find_class(env, DW_CLASS_NAME); // Get the method that you want to call jmethodID drawLine = env->GetMethodID(clazz, "drawArc", - "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIIIIIII)V"); + "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIIIIIJJ)V"); // Call the method on the object - env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, flags, xorigin, yorigin, x1, y1, x2, y2, (jint)fgcolor, (jint)bgcolor); + env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, flags, xorigin, yorigin, x1, y1, x2, y2, fgcolor, bgcolor); _dw_jni_check_exception(env); } } @@ -3454,6 +3454,31 @@ */ void API dw_container_set_stripe(HWND handle, unsigned long oddcolor, unsigned long evencolor) { + JNIEnv *env; + + if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + jlong odd = _dw_get_color(oddcolor); + jlong even = _dw_get_color(evencolor); + + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID containerSetStripe = env->GetMethodID(clazz, "containerSetStripe", + "(Landroid/widget/ListView;JJ)V"); + if(oddcolor == DW_RGB_TRANSPARENT) + odd = -1; + else if(oddcolor == DW_CLR_DEFAULT) + odd = -2; + if(evencolor == DW_RGB_TRANSPARENT) + even = -1; + else if(evencolor == DW_CLR_DEFAULT) + even = -2; + + // Call the method on the object + env->CallVoidMethod(_dw_obj, containerSetStripe, handle, odd, even); + _dw_jni_check_exception(env); + } } /*