Change text on shape - android

Hi
is it possible to change the text of a shape? I have:
levelFraction = new Text(0, 300, mFont, "text", HorizontalAlign.CENTER);
then I add it to the scene:
scene.getTopLayer().addEntity(levelFraction);
but I don't see any method to change the text at runtime. Something like:
levelFraction.setText(...);
Is that possible?

if Sheet1.shapes(0).texteffect.text="Go" then
sheet1.shapes(0).texteffect.text="Stop"
else
sheet1.shapes(0).texteffect.text="Go"
end if
You could even call a sub based on the the value of the texteffect.text

I don't know anything about the AndEngine library, so this would just be a wild guess:
Could you perhaps use the ChangeableText (which extends Text) instead of Text? From the name it sounds like you should be able to change the text, and looking at the code it also have a couple of functions to set the text: ChangeableText source

font_texture_golbalValue = new Texture(128,64,TextureOptions.BILINEAR);
font4 = new Font(font_texture_golbalValue, Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD), textSize, true, Color.WHITE);
this.mEngine.getTextureManager().loadTexture(this.font_texture_golbalValue);
this.mEngine.getFontManager().loadFont(this.font4);
scoreval=new ChangeableText(24*CAMERA_WIDTH/100, score_postion, this.font2, ""+scoreValue,"Score##".length());
and You can use scorevalue.SetText();

Related

A Swift/iOS Class Equivalent to Android Dialog?

If I want to create a pop up view in Android, say on clicking a button, a QR code will pop up and things behind will be blurred a bit, I called the Dialog class in Android/Java, which I think is more like a View in iOS.
May I know whether there is a class which is almost equivalent in iOS? I googled around and seems no one mention about that. While some might say I could use AlertController, I would say the experience is completely different. Dialog in Android can contain everything - text, buttons, images, layouts, you name it, while AlertController in iOS is literally just the alert and it does not expect you to do so much customization.
Can anyone illustrate the road ahead for me?
You use UIAlertController in Swift.
Example
DispatchQueue.main.async {
let alertController = UIAlertController(title: "My Title", message: "My Message", preferredStyle: .alert)
alertController.view.tintColor = UIColor.blue //Change this or remove
//Blur Effect
let blurEffect = UIBlurEffect(style: .light)
let blurVisualEffectView = UIVisualEffectView(effect: blurEffect)
blurVisualEffectView.frame = self.view.bounds
self.view.addSubview(blurVisualEffectView) //Add the blur effect to the dialog
//Set Image
var myImage = UIImageView(frame: CGRect(x: 89, y: 35, width: 95, height: 80))
myImage.image = UIImage(named: "MyImage")!
alertController.view.addSubview(myImage)
//Button actions
let cancelAction = UIAlertAction(title: "Cancel", style: .destructive) {_ in
blurVisualEffectView.removeFromSuperview()
}
let okAction = UIAlertAction(title: "OK", style: .default) {_ in
blurVisualEffectView.removeFromSuperview()
}
//Height constraint handler
var height: NSLayoutConstraint = NSLayoutConstraint(
item: alertController.view, attribute:
NSLayoutConstraint.Attribute.height,
relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil,
attribute: NSLayoutConstraint.Attribute.height,
//Change this as desired
multiplier: 1, constant: self.view.frame.height * 0.4)
alertController.view.addConstraint(height) //Set the constraint
alertController.addAction(cancelAction)
alertController.addAction(okAction)
//Display (present) the alertcontroller
self.present(alertController, animated: true, completion: nil)
}
Result
Breaking This Down
Declare the alertController. Set the title to "My Title" and the message.
Set the tintColor. This changes it to custom colors other than the default iOS blue tint.
Add the UIBlurEffect. "Tries" to mimic Androids AlertDialog. :)
Declare and add the UIImageView to the alertController as a sub view
Add the action buttons. cancelAction and okAction. Notice the style: property? This allows you to choose between .destructive, and .default. .destructive makes the button red-tinted, and .default leaves it as the alertController's tintColor.
Add a height constraint. Useful if you want more content visible (like UIImageViews)
Use the alertController.addAction functions to add our buttons, and present it.
Extra note: All of this is contained inside DispatchQueue.main.async {}. This is useful if you want to show your dialog before the parent ViewController is fully loaded. (E.G. You show your dialog in the .viewDidLoad function.

How to override the CellStyle value in excel dart package?

I am using excel dart package to create and edit excel files. I am trying to make my excel file look attractive by giving colors to excel cells.
I read the documentation here and tried to do like this :
CellStyle color1 = CellStyle(
fontColorHex: "#Ffffff",
backgroundColorHex: "#80ff00",
fontFamily: getFontFamily(FontFamily.Calibri),
);
CellStyle color2 = CellStyle(
fontColorHex: "#Ffffff",
backgroundColorHex: "#Ea4a73",
fontFamily: getFontFamily(FontFamily.Calibri),
);
var cell = sheetObject.cell(CellIndex.indexByString("A1"));
//changing cell style to color 1
cell.CellStyle = color1;
//now again changing cell style to color 2
cell.CellStyle = color2;
Problem with this:
When I try to change the cellStyle to color2 it persist the old values of color1. Why this is happening and how can I fix this, Is there any property to remove the cellStyle first and then assigning to new CellStyle. Thanks in advance
The issue I found was that cell.CellStyle should be cell.cellStyle. if that was a mistake while adding code here, Then for your information, the current code works for me without any issue. try to delete the excel file been exported and clean the project and run the code again.

Embedding emoji(emoticons images) to custom softkeyboard android

I have created a custom soft Keyboard(IME) where we can add custom emoji.
Whenever i try to add my emoticons to it. it override the last text entered. i mean it dont append the emoticons unless it override it. how can i add emoji to currentInputConnection
for example
i image write hello image abcimage ///where image represents emoji
it becomes
i image write hello image image
// and i can add image after space easily or i can repeatedly add images easily .
when i add text it appends to emoji but when i add emoji after entering some text it remove the text and then add it self(emoji image).
Just for testing purpose i put emoji code to shift key
Problem code
else if (primaryCode == Keyboard.KEYCODE_SHIFT)
{
// this.handleShift();
//this.mComposing.append(getSmiledText(getApplicationContext(), ":)"));
ImageGetter imageGetter = new ImageGetter()
{
public Drawable getDrawable(String source) {
Drawable d = getResources().getDrawable(R.drawable.e041);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
};
Spanned cs = Html.fromHtml("<img src='" + getResources().getDrawable(R.drawable.e041) + "'/>", imageGetter, null);
// getCurrentInputConnection().commitText(cs, 1);
// this.mComposing.append(cs);
//getCurrentInputConnection().commitText(getSmiledText(getApplicationContext(), ":)"), 1);
getCurrentInputConnection().beginBatchEdit();
getCurrentInputConnection().commitText(cs, 1);
getCurrentInputConnection().endBatchEdit();
//getCurrentInputConnection().setComposingText(cs, 1); // it is giving wrong
}
And tried multiple ways to solve it ,some tried codes are shown in comments
Simple Words : I want to append emoji image to text, but when i add image to text, it remove the written text, how can i solve. full source can't be shown it is lengthy. Ask me if you need any method in my class
Related link :
add custom image as Emoji in android
https://stackoverflow.com/questions/24100615/cannot-add-an-image-to-my-keyboard-service
Implementations of Emoji (Emoticon) View/Keyboard Layouts
Thanks in Advance.
I also tried for the same but always got "obj".Atlast I found a solution try this.
Instead of adding drawables just add emoticons by their uniCodes like this..
getCurrentInputConnection().commitText((CharSequence)"\ud83c\udfb5", 1);
Its working for me perfectly.and also remove beginBatchEdit and endBatchEdit from your code.
Thanks

How can I get the fgcolor attribute to work on recent Android versions?

I used to be able to do this:
<string name="foo">white <font fgcolor="#ff6890a5">blue</font></string>
But now it doesn't work any more. It seems to be a bug in the integer parsing code; see https://code.google.com/p/android/issues/detail?id=58192
Problem is, I'm getting customer complaints now; I can't wait for the bug to be fixed.
Does anybody know a work-around, such as using named resources from color.xml or something like that?
ETA: I've discovered fgcolor="blue" still works, but it's the wrong shade of blue. Is there a list of legal color names somewhere? Maybe I could find one that's close enough. It also works if the color is a number without the high bit set, like #7f6890a5, but of course that's too faint to be useful; I need a solid color, not semi-transparent.
ETA: browsing source code shows these colors:
aqua 0x00FFFF
black 0x000000
blue 0x0000FF
fuchsia 0xFF00FF
green 0x008000
grey 0x808080
lime 0x00FF00
maroon 0x800000
navy 0x000080
olive 0x808000
purple 0x800080
red 0xFF0000
silver 0xC0C0C0
teal 0x008080
white 0xFFFFFF
yellow 0xFFFF00
This doesn't fix my problem, but perhaps other people searching on this question could find this information useful.
How about we leverage the fact that colors without the high bit set still works and just replace it with the correct colors? So you can have a method like this:
private CharSequence fixSpanColor(CharSequence text) {
if (text instanceof Spanned) {
final SpannableString s = new SpannableString(text);
final ForegroundColorSpan[] spans = s.getSpans(0, s.length(), ForegroundColorSpan.class);
for (final ForegroundColorSpan oldSpan : spans) {
final ForegroundColorSpan newSpan = new ForegroundColorSpan(oldSpan.getForegroundColor() | 0xFF000000);
s.setSpan(newSpan, s.getSpanStart(oldSpan), s.getSpanEnd(oldSpan), s.getSpanFlags(oldSpan));
s.removeSpan(oldSpan);
}
return s;
} else {
return text;
}
}
You will then need to pass any text with the required color accent through this method, the simplest example would be modifying all calls like this:
tv.setText(getText(R.string.foo));
To:
tv.setText(fixSpanColor(getText(R.string.foo)));
Hopefully, depending on how your code is structured, there might already a central place where you can add this extra method call.
I have some awful workaround in my client code to manually reset the
ForegroundColorSpans to the proper color, but it would be great not to
have to do so.
I think the workaround that the issue reporter's talking about is the following:
Define the string as:
<string name="foo">white blue</string>
In your activity:
TextView tv = (TextView) findViewById(R.id.textView1);
SpannableString spannableString = new
SpannableString(getResources().getString(R.string.foo));
ForegroundColorSpan fcs = new
ForegroundColorSpan(getResources().getColor(R.color.bluish));
spannableString.setSpan(fcs, spannableString.toString().indexOf(" ") + 1,
spannableString.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
tv.setText(spannableString);
R.color.bluish is defined as <color name="bluish">#ff6890a5</color>.
But, using " " (space) to distinguish and apply the ForegroundColorSpan would only be practical if you have a small number of strings defined.
The following modification might actually be easier for you to carry out:
Define the string as:
<string name="foo_sep_1"><![CDATA[white <font color=\"#6890a5\">blue</font>]]></string>
Or:
<string name="foo_sep_1">white <font color="#6890a5">blue</font></string>
In your activity:
TextView tv2 = (TextView) findViewById(R.id.textView2);
tv2.setText(Html.fromHtml(getResources().getString(R.string.foo_sep_1)));
Be careful about the color code: HTML color codes do not have alpha values (RRGGBB will work, AARRGGBB will not)
Another workaround is using Html.fromHtml(String) directly:
TextView tv3 = (TextView) findViewById(R.id.textView3);
tv3.setText(Html.fromHtml("white <font color='#6890a5'>blue</font>"));
Kudos to TWiStErRob who found a solution that doesn't involve code in https://stackoverflow.com/a/11577658/338479. To quote:
for any color above 7fffffff apply the following: <font
color="#ff6890a5"> put ff6890a5 into a calculator (optionally convert
to decimal first) and flip the sign, then (optionally convert back to
hexa) take the last 8 hexadecimal digits and use <font
color="-#00976F5B">.

Android setting text view color from java code

I have a list and i write a custom adapter for this. And I want to set some text color for this (e.g. Orange color code #F06D2F). I am presenting the code snippet for my getView() method.
TextView text = new TextView(this.context);
// text.setPadding(25, 5, 0, 0);
text.setBackgroundResource(R.drawable.back_horizontal);
// text.setClickable(false);
// text.setFocusable(false);
text.setEllipsize(TruncateAt.END);
text.setSingleLine(true);
// text.setTextColor(R.color.yellow);
text.setTextColor(R.color.Orange);
text.setGravity(Gravity.CENTER_VERTICAL);
helvetica_normal = Typeface.createFromAsset(context.getAssets(), "fonts/helvetica.ttf");
text.setTypeface(helvetica_normal);
// text.setTextColor(R.color.yellow);
text.setText(objects[position]);
LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
manager.addView(text, layoutParams);
The problem is that i can't see the color set to orange. What went wrong?
Note: The context is passed in constructor as well as objects (the string array)
Thanks for your help
try like this , the following worked fine for me
textview.setTextColor(this.getResources().getColor(R.color.orange));
text.setTextColor(Color.parseColor("#FFFFFF"));
You Can also use
text.setTextColor(0xFFF06D2F);
but not just
text.setTextColor(0xF06D2F);
This worked for me, and it is simple. First, import "Color"
import android.graphics.Color;
Then all you have to do is this:
text.setTextColor(Color.RED);
Just discovered this today (9/20/13). You can go ahead and declare a variable like this:
private final int ORANGE = 0xFFFF3300;
Then all you have to do is:
text.setTextColor(ORANGE);
Note that the first two hex characters are for opacity ("FF" means opaque). Then, in the example above, the second "FF" is for red, then "33" is for green, and "00" is for blue. Should be possible to create a great many colors this way.
I am pretty new at this Android programming - this is my first post to this forum. Thanks to all of you for your contributions!
textview.setTextColor(ContextCompat.getColor(context, R.color.your_color));
Yes, You can try this
textview.setTextColor(this.getResources().getColor(R.color.orange));
If you want to change your Text Color and take value from values/colors.xml If statement is holding text color for higher api because else version is depreciated in api23
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
textview_name.setTextColor(getColor(R.color.your_color_name));
}
else
{ textview_name.setTextColor(getResources().getColor(R.color.your_color_name));
}
This is what worked for me.
Import first:
import android.graphics.Color;
Then you can use:
textview.setTextColor(Color.BLUE);
For Kotlin just use holder.text.setTextColor(Color.RED);

Categories

Resources