Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1768] Android: KS alerts are not respecting opacity.

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T01:57:07.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.5.0 M03
ComponentsAndroid
Labelsandroid, defect, regression
ReporterThomas Huelbert
AssigneeDon Thorp
Created2011-04-15T03:01:41.000+0000
Updated2011-04-17T01:57:07.000+0000

Description

1.launch KS on device or simulator
2.note the pop ups that show the sdk version and tab info (change tabs to generate more)

results: the windows are not opaque, as per the script they should reflect:

opacity:0.7,

Attachments

FileDateSize
1768_master.diff2011-04-15T03:01:41.000+00002363

Comments

  1. Bill Dawson 2011-04-15

    Here's a sample app.js that shows the problem (so you don't have to build KS):

       /*global Ti, Titanium, alert, JSON */
       Titanium.UI.setBackgroundColor('#000');
       var win = Titanium.UI.createWindow({  
           title:'Test',
           backgroundColor:'#fff',
           fullscreen: true,
           exitOnClose: true
       });
       
       
       var messageView = Titanium.UI.createView({
           top: 0,
           height:30,
           width:250,
           borderRadius:10,
           backgroundColor:'blue',
           opacity:0.7,
           touchEnabled:false
       });
       win.add(messageView);
       
       var v = Titanium.UI.createView({
           top: 50,
           height:30,
           width:250,
           borderRadius:10,
           backgroundColor:'blue',
           touchEnabled:false
       });
       win.add(v);
       win.open();
       

    The top view -- which sets opacity -- should look different than the bottom view, which is otherwise the same. Because of this bug, they look identical.

    What's happening is that because a border property is being set in addition to background, a TiBackgroundDrawable is being used. TiBackgroundDrawable maintains its own copy of a drawable which it draws to the canvas. It doesn't respect any of the alpha stuff being done in TiUIHelper.setDrawableOpacity.

    I can get it to work properly by...

       if (drawable instanceof ColorDrawable) {
            ColorDrawable colorDrawable = (ColorDrawable) drawable;
            colorDrawable.setAlpha(Math.round(opacity * 255));
       ....
       

    ... to ...

       if (drawable instanceof ColorDrawable || drawable instanceof TiBackgroundDrawable) {
            drawable.setAlpha(Math.round(opacity * 255));
       ....
       

    This means, however, that TiBackgroundDrawable doesn't get the color matrix / color filter stuff -- .setColorFilter() is not called on it. I tried overriding .setColorFilter in TiBackgroundDrawable and passing the value to its private 'background' Drawable, but that didn't work at all. Are we sure the color filter / color matrix thing works?

    I haven't committed these changes, as I'm not strong in this area of drawables, color filters, etc. If Don/Marshall wants me to, I can.

  2. Bill Dawson 2011-04-15

    here's a diff patch (based on master) in case you wanna use it.

  3. Marshall Culpepper 2011-04-15

    (from [df00caa5c7758796ef957e3b58eb3b742e271e4a]) merging Bill's original patch for fixing opacity on views with custom background drawables. tested with [#2031] as well to verify [#1768 state:fixed-in-qa] https://github.com/appcelerator/titanium_mobile/commit/df00caa5c7758796ef957e3b58eb3b742e271e4a"> https://github.com/appcelerator/titanium_mobile/commit/df00caa5c775...

  4. Matt Schmulen 2011-04-15

    Failed in 1.6 and 2.1, seems to work fore createImageView, but not createView.
    Titanium SDK version: 1.5.0 (11/22/10 20:42 19a59fd)

    used the test code above

  5. Matt Schmulen 2011-04-15

    passed Android 2.1 Titanium SDK version: 1.5.0 (11/24/10 12:05 c0aff27)
    passed Android 1.6 Titanium SDK version: 1.5.0 (11/24/10 12:05 c0aff27)

JSON Source