Mercurial > dwindows
comparison android/DWindows.kt @ 2841:3e88b961f801
Android: Rewrite DWContainerRow using RelativeLayout and a LinearLayout stack.
This allows us to replicate the iOS look that I implemented last week.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 16 Sep 2022 01:40:19 +0000 |
parents | 1f0017a07771 |
children | 22dd09e90112 |
comparison
equal
deleted
inserted
replaced
2840:8752d65e2dc0 | 2841:3e88b961f801 |
---|---|
2252 rowdata.clear() | 2252 rowdata.clear() |
2253 rowtitle.clear() | 2253 rowtitle.clear() |
2254 } | 2254 } |
2255 } | 2255 } |
2256 | 2256 |
2257 class DWContainerRow : LinearLayout, Checkable { | 2257 class DWContainerRow : RelativeLayout, Checkable { |
2258 private var mChecked = false | 2258 private var mChecked = false |
2259 private var colorSelection = Color.DKGRAY | 2259 private var colorSelection = Color.DKGRAY |
2260 var imageview: ImageView = ImageView(context) | |
2261 var text: TextView = TextView(context) | |
2262 var stack: LinearLayout = LinearLayout(context) | |
2263 | |
2264 fun setup(context: Context?) { | |
2265 val wrap = RelativeLayout.LayoutParams.WRAP_CONTENT | |
2266 val match = RelativeLayout.LayoutParams.MATCH_PARENT | |
2267 var lp = RelativeLayout.LayoutParams(wrap, wrap) | |
2268 imageview.id = View.generateViewId() | |
2269 this.addView(imageview, lp) | |
2270 lp = RelativeLayout.LayoutParams(match, wrap) | |
2271 text.id = View.generateViewId() | |
2272 lp.addRule(RelativeLayout.RIGHT_OF, imageview.id); | |
2273 this.addView(text, lp) | |
2274 lp = RelativeLayout.LayoutParams(match, wrap) | |
2275 stack.id = View.generateViewId() | |
2276 stack.orientation = LinearLayout.HORIZONTAL | |
2277 lp.addRule(RelativeLayout.BELOW, imageview.id); | |
2278 lp.addRule(RelativeLayout.BELOW, text.id); | |
2279 this.addView(stack, lp) | |
2280 } | |
2260 | 2281 |
2261 constructor(context: Context?) : super(context) { | 2282 constructor(context: Context?) : super(context) { |
2283 setup(context) | |
2262 colorSelection = context?.let { getPlatformSelectionColor(it) }!! | 2284 colorSelection = context?.let { getPlatformSelectionColor(it) }!! |
2263 } | 2285 } |
2264 constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { | 2286 constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { |
2287 setup(context) | |
2265 colorSelection = context?.let { getPlatformSelectionColor(it) }!! | 2288 colorSelection = context?.let { getPlatformSelectionColor(it) }!! |
2266 } | 2289 } |
2267 constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) { | 2290 constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) { |
2291 setup(context) | |
2268 colorSelection = context?.let { getPlatformSelectionColor(it) }!! | 2292 colorSelection = context?.let { getPlatformSelectionColor(it) }!! |
2269 } | 2293 } |
2270 | 2294 |
2271 fun updateBackground() { | 2295 fun updateBackground() { |
2272 if(mChecked) { | 2296 if(mChecked) { |
2337 } | 2361 } |
2338 | 2362 |
2339 // If the view passed in is null we need to create the layout | 2363 // If the view passed in is null we need to create the layout |
2340 if(rowView == null) { | 2364 if(rowView == null) { |
2341 rowView = DWContainerRow(context) | 2365 rowView = DWContainerRow(context) |
2342 rowView.orientation = LinearLayout.HORIZONTAL | |
2343 | 2366 |
2344 // Handle DW_CONTAINER_MODE_MULTI by setting the orientation vertical | 2367 // Handle DW_CONTAINER_MODE_MULTI by setting the orientation vertical |
2345 if(contMode == 2) { | 2368 if(contMode == 2) { |
2346 rowView.orientation = LinearLayout.VERTICAL | 2369 rowView.stack.orientation = LinearLayout.VERTICAL |
2347 rowView.gravity = Gravity.LEFT | 2370 rowView.stack.gravity = Gravity.LEFT |
2348 } | 2371 } |
2349 | 2372 |
2350 for(i in 0 until displayColumns) { | 2373 // If there are extra columns and we are not in default mode... |
2351 val content = model.getRowAndColumn(position, i) | 2374 // Add the columns to the stack (LinearLayout) |
2375 for(i in extraColumns until displayColumns) { | |
2376 var content = model.getRowAndColumn(position, i) | |
2352 | 2377 |
2353 // Image | 2378 // Image |
2354 if((model.getColumnType(i) and 1) != 0) { | 2379 if((model.getColumnType(i) and 1) != 0) { |
2355 val imageview = ImageView(context) | 2380 val imageview = ImageView(context) |
2356 val params = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, | 2381 val params = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, |
2362 imageview.layoutParams = params | 2387 imageview.layoutParams = params |
2363 imageview.id = View.generateViewId() | 2388 imageview.id = View.generateViewId() |
2364 if (content is Drawable) { | 2389 if (content is Drawable) { |
2365 imageview.setImageDrawable(content) | 2390 imageview.setImageDrawable(content) |
2366 } | 2391 } |
2367 rowView.addView(imageview) | 2392 rowView.stack.addView(imageview) |
2368 } else { | 2393 } else { |
2369 // Everything else is displayed as text | 2394 // Everything else is displayed as text |
2370 var textview: TextView? = null | 2395 var textview: TextView? = null |
2371 | 2396 |
2372 // Special case for DW_CONTAINER_MODE_MULTI | 2397 // Special case for DW_CONTAINER_MODE_MULTI |
2373 if(contMode == 2 && i >= extraColumns) { | 2398 if(contMode == 2) { |
2374 // textview will be a text button instead | 2399 // textview will be a text button instead |
2375 textview = Button(context) | 2400 textview = Button(context) |
2376 } else { | 2401 } else { |
2377 textview = TextView(context) | 2402 textview = TextView(context) |
2378 } | 2403 } |
2399 if(isFilesystem) { | 2424 if(isFilesystem) { |
2400 columnClicked = i - 1 | 2425 columnClicked = i - 1 |
2401 } | 2426 } |
2402 eventHandlerInt(parent, DWEvent.COLUMN_CLICK, columnClicked, 0, 0, 0) | 2427 eventHandlerInt(parent, DWEvent.COLUMN_CLICK, columnClicked, 0, 0, 0) |
2403 } | 2428 } |
2404 | 2429 rowView.stack.addView(textview) |
2405 rowView.addView(textview) | |
2406 } | 2430 } |
2407 } | 2431 } |
2408 } else { | 2432 } else { |
2409 // Otherwise we just need to update the existing layout | 2433 // Otherwise we just need to update the existing layout |
2410 | 2434 for(i in extraColumns until displayColumns) { |
2411 for(i in 0 until displayColumns) { | 2435 var content = model.getRowAndColumn(position, i) |
2412 val content = model.getRowAndColumn(position, i) | |
2413 | 2436 |
2414 // Image | 2437 // Image |
2415 if((model.getColumnType(i) and 1) != 0) { | 2438 if((model.getColumnType(i) and 1) != 0) { |
2416 val imageview = rowView.getChildAt(i) | 2439 val imageview = rowView.stack.getChildAt(i - extraColumns) |
2417 | 2440 |
2418 if (imageview is ImageView && content is Drawable) { | 2441 if (imageview is ImageView && content is Drawable) { |
2419 imageview.setImageDrawable(content) | 2442 imageview.setImageDrawable(content) |
2420 } | 2443 } |
2421 } else { | 2444 } else { |
2422 // Text | 2445 // Text |
2423 val textview = rowView.getChildAt(i) | 2446 val textview = rowView.stack.getChildAt(i - extraColumns) |
2424 | 2447 |
2425 if (textview is TextView) { | 2448 if (textview is TextView) { |
2426 if (content is String) { | 2449 if (content is String) { |
2427 textview.text = content | 2450 textview.text = content |
2428 } else if (content is Long || content is Int) { | 2451 } else if (content is Long || content is Int) { |
2433 } | 2456 } |
2434 } | 2457 } |
2435 } | 2458 } |
2436 } | 2459 } |
2437 } | 2460 } |
2461 | |
2462 var content = model.getRowAndColumn(position, 0) | |
2463 | |
2464 // Setup the built-in Image and Text based on if we are fileystem mode or not | |
2465 if(isFilesystem) { | |
2466 if(content is Drawable) { | |
2467 rowView.imageview.setImageDrawable(content) | |
2468 } | |
2469 content = model.getRowAndColumn(position, 1) | |
2470 if (content is String) { | |
2471 rowView.text.text = content | |
2472 } else if(content is Long || content is Int) { | |
2473 rowView.text.text = content.toString() | |
2474 } | |
2475 } else { | |
2476 if(content is Drawable) { | |
2477 rowView.imageview.setImageDrawable(content) | |
2478 } else if (content is String) { | |
2479 rowView.text.text = content | |
2480 } else if(content is Long || content is Int) { | |
2481 rowView.text.text = content.toString() | |
2482 } | |
2483 } | |
2484 | |
2438 // Handle row stripe | 2485 // Handle row stripe |
2439 if (position % 2 == 0) { | 2486 if (position % 2 == 0) { |
2440 if(evenColor != null) { | 2487 if(evenColor != null) { |
2441 rowView.setBackgroundColor(evenColor!!) | 2488 rowView.setBackgroundColor(evenColor!!) |
2442 } else if(backColor != null) { | 2489 } else if(backColor != null) { |