-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(android): add Ti.UI.Android.getColorResource(), Ti.UI.Color
Also support passing color resource names to color properties
- Loading branch information
1 parent
9c3321b
commit d852331
Showing
4 changed files
with
192 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
android/titanium/src/java/org/appcelerator/titanium/proxy/ColorProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2020-Present by Axway, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
package org.appcelerator.titanium.proxy; | ||
|
||
import org.appcelerator.kroll.KrollProxy; | ||
import org.appcelerator.kroll.annotations.Kroll; | ||
|
||
import android.graphics.Color; | ||
|
||
import androidx.annotation.ColorInt; | ||
|
||
@Kroll.proxy | ||
/** | ||
* This is a proxy representation of the Android Color type. | ||
* Refer to <a href="https://developer.android.com/reference/android/graphics/Color">Android Color</a> for more details. | ||
*/ | ||
public class ColorProxy extends KrollProxy | ||
{ | ||
private Color color; | ||
|
||
public ColorProxy(@ColorInt int colorInt) | ||
{ | ||
this(Color.valueOf(colorInt)); | ||
} | ||
|
||
public ColorProxy(Color color) | ||
{ | ||
this.color = color; | ||
} | ||
|
||
@Kroll.method | ||
public String toHex() | ||
{ | ||
if (this.color == null) { | ||
return "#000000"; | ||
} | ||
// Padding! If length is less than 8, pad with leading 0s | ||
String hex = Integer.toHexString(this.color.toArgb()); | ||
while (hex.length() < 8) { | ||
hex = "0" + hex; | ||
} | ||
return "#" + hex; | ||
} | ||
|
||
@Override | ||
public void release() | ||
{ | ||
super.release(); | ||
this.color = null; | ||
} | ||
|
||
@Override | ||
public String getApiName() | ||
{ | ||
return "Ti.UI.Color"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters