Skip to content

Instantly share code, notes, and snippets.

@cameronmcefee
Last active December 11, 2015 11:49
Show Gist options
  • Save cameronmcefee/4596573 to your computer and use it in GitHub Desktop.
Save cameronmcefee/4596573 to your computer and use it in GitHub Desktop.
Here's how I detect Photoshop's skin color and set my assets/colors accordingly
package classes {
public class ApplicationSkin {
import com.adobe.csxs.core.CSXSInterface;
import com.adobe.csxs.types.AppSkinInfo;
public function ApplicationSkin() {}
// The current lightness of the app's background on a scale of 0-1
//
// Returns a Number
static public function appLightness():Number {
return CSXSInterface.instance.getHostEnvironment().data.appSkinInfo.panelBackgroundColor.color.rgb/16777215
}
// The current RGB value of the app's background.
//
// Returns a Number
static public function appColor():Number {
return CSXSInterface.instance.getHostEnvironment().data.appSkinInfo.panelBackgroundColor.color.rgb
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
<mx:Script>
<![CDATA[
import classes.ApplicationSkin;
import com.adobe.csxs.events.*;
private function init():void {
updateUI()
CSXSInterface.getInstance().addEventListener(AppReskinEvent.APPLICATION_RESKIN, function(e:AppReskinEvent):void {
updateUI()
})
CSXSInterface.getInstance().addEventListener(StateChangeEvent.WINDOW_RESIZE, function(e:StateChangeEvent):void {
updateUI()
})
}
private function updateUI():void {
var appUILightness:Number = ApplicationSkin.appLightness()
if(appUILightness>.5){
// Light Mode
} else {
// Dark Mode
}
}
]]>
</mx:Script>
</mx:Canvas>
@cameronmcefee
Copy link
Author

You could take the appLightness test a step further and detect light-dark vs dark-dark etc based on the number value it returns. In my case I'm only testing whether it's light or dark.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment