What is the equivalent of !boolean (negative) on Kotlin - android-studio

I have recently decided to switch from Java to Kotlin for Android Development. I don't know what to Google, so I'm asking here.
If we want to get the opposite of a boolean, we put a ! before it. Eg: I want the inside code to run only if the contains() returns false. How to do that?
Example, we do this in Java:
if (!string_text.contains(" "))
How do I write this in Kotlin?

! is the boolean not operator, same as Java.
Check https://kotlinlang.org/docs/reference/keyword-reference.html#operators-and-special-symbols

Try
if (string_text.isNullOrBlank()) {
info oficial kotlin

Related

Where is the setting for the suggestion to wrap incompatible argument for TextView's setText() method using the static method String.valueOf()?

Recently I found out that my Android Studio no longer gives the suggestion to wrap an incompatible argument for the TextView's setText() method using the String.valueOf() method.
I sometimes forget to convert the value/variable that I'm going to pass as argument to String, but Android Studio usually gives me a warning AND suggestions to wrap the value/variable, as long as it is possible. Now, for example, when I do this:
double x = 10.567;
textView.setText(double);
Android Studio will still give me a red error warning, but the only suggestion in there is "Cast parameter to 'int'".
It used to give me the option to automatically insert the String.valueOf() method call, which is very helpful.
Is it just me or this is how it is now? There was an update a few days ago.
Did I mess up some settings in my Android Studio? Can someone tell me how to fix it?
I've looked through the Inspections settings and I haven't found it, if there's even a setting for it.
Maybe the update changes the mechanism, or you can click on the "More actions" in the prompt to see if other options available.
setText() can accept String or int, if you pass in int value, compiler will expect it is String resource ("R.string.xxx"), which is int type. Just memorize this, you don't need to rely on the prompt any more.

Android Studio Kotlin: Extract as Constant

In IntelliJ-based IDEs like Android Studio, in Java source codes, there is an option to extract things as constants when possible (final static). It is in Refactor -> Extract -> Constant and is accessible via Ctrl+Alt+C.
But I can't find it for Kotlin source codes!
Note 1: I can do it manually as you can see about NUMBER in the above screenshot (by defining it as a const val in companion object).
Note 2: The reverse-action is accomplishable by IDE; it means you can inline NUMBER with Ctrl+Alt+N.
Unfortunately, this is a known missing feature for now. It's being tracked on the official issue tracker. You can vote for it there =)

CountreExample generation in KodKod

I have just switched to working with KodKod I am still trying to understand it. I have wrote a program to help me understand I succeeded to see if the solution is SATISFIABLE or UNSATISFIABLE .
I want to be able to see the CountreExample like we normally do in Alloy, I found the Method proof() of the type solution but it always returns null .
I want to know if there is a way to return the CountreExample or not.
Thank you in advance.
Try to look at this examples of Alloy API usages: https://github.com/kaptoxic/alloy/tree/master/src/edu/mit/csail/sdg/alloy4whole

Using NSJSONSerialization with swift on ubuntu/linux

Is it possible to parse JSON using NSJSONSerialization when running swift on ubuntu? Since foundation is available I am assuming it should be?
If not, Is there any other way of serialising and deserialising JSON in swift on linux?
NSJSONSerialization is partly implemented (serialization is not yet implemented)
do it yourself, in accordance with your needs, and you will see, that it is the best investment and great way to understand Swift and its possibilities. you can also use one of the opensource libraries available around. SwiftyJSON is very popular, for an example
As mentioned by Sebastian OsiƄski, unfortunately it use NSJSONSerialization too.
you can check this very simple, but working example swift json. it is far away to be 'perfect', but as an inspiration it could help you, i hope so.
I am using TidyJSON for this, because it combines much of the ease of SwiftyJSON but does not rely on NSJSONSerialization for parsing. It works wherever Swift works, and I'm using it just fine in my current Swift/Ubuntu projects.
If you're using the server side Swift framework "Perfect", You can do something like this to convert "data" (Binary) type to "JSONConvertable" (Swift Arrays etc) object types.
do{
let jsonObject = try String.init(data: jsonData, encoding: .utf8)?.jsonDecode()
print("\(jsonObject as! [String])")
}catch{
response.completed(status: .badRequest)
return
}

Solution for missing std::wstring support in Android NDK?

I have a game which uses std::wstring as its basic string type in thousand of places as well as doing operations with wchar_t and its functions: wcsicmp() wcslen() vsprintf(), etc.
The problem is wstring is not supported in R5c (latest ndk at the time of this writting).
I can't change the code to use std::string because of internationalization and I would be breaking the game engine which is used by many games ...
Which options do I have?
1 - Replace string and wstring with my own string classes
This would give me better platform independency, but it is ridiculous to reimplement the wheel.
I've already started with a COW implementation of strings. I need it to be COW because I use them as keys in hash_maps.
This is of course lots of work and error prone ... but it seems it is something I can do.
2 - Try to fix the NDK recompiling the STLPort with my own implementations of the wide char string functions of the C standart library (wcslen, mbstowcs ... )
This would be the preferable way ... but I have no idea how to do it :(
How do I replace a function (lets say wcslen) in the libstdc++.a or libstlport_static.a? (not sure where they are :()
And as well I'm not sure which functions I need to reimplement, I know wcslen is not working so I guess they should be all ...
3 - Do you have any other idea?
I can't wait for an official fix for this and I will have to go with option #1 if I can't realize how to do #2.
I've read somewhere that if you target 2.3 you can use wstrings, but I ought to target Android 2.1.
PS: Forgot to say I need to use STL of course, but no RTTI and I can live without exceptions.
Thanks in advance!
Try out CrystaX's NDK. It has had stl support long before the official google one. The current version (r5), which is based off the of the official ndk r5, is still beta 3, but it does have wchar_t support.
http://www.crystax.net/android/ndk-r5.php
I'm suffering from the same problem as you, but my only other thought is to load the strings via the JNI (as jstring* in native land), then convert them to UTF characters as necessary. Take a look at the available JNI string functions here:
http://download.oracle.com/javase/1.5.0/docs/guide/jni/spec/functions.html#string_operations
Qt provides an excellent copy-on-write, international-friendly string implementation, QString, that is LGPLed.
You could, in theory extract it from the Qt source and use it in your own project. You will find the QString implementation in src/corelib/tools/qstring.h and .cpp in a Qt source download. You would also need the QChar, QByteArray, QAtomic, and QNamespace includes/classes (all under the corelib folder,) and you should define QT_NO_STL_WCHAR when compiling. (For this I would compile by hand or using my own script/Makefile.) Not simple, but once you get it up and running your life will be a lot simpler. It's better than reinventing the wheel, because it comes with loads of convenience functions and features.
Rather than stripping out just QString, you could also just use the QtCore module as a whole. See the android-lighthouse project for a Qt port to Android. (Also, it might be better to get your sources from there than from the above "vanilla" link, regardless of what you do.)

Resources