Страницы

суббота, 30 апреля 2016 г.

MSI X99A SLI PLUS Windows 10 hang issue resolved

I've become a happy owner of MSI X99A Sli Plus mobo. I already read about many issues with asus burninng, msi burning, random Windows hangs due to problems with USB. And I want to say that I encountered nothing of that with my MSI mobo (bios 1.9, recently updated it to 1.B).

But I encountered an annoying hang for which I found a solution, so I want to share it because I don't see it anywhere on the web.

Problem: after unplugging PC from the outlet and plugging back Windows 10 hangs for the first time.
Solution: insert USB stick in one of the USB3.1 slots. You just need to keep 1 USB3.1 slot occupied to not run into that problem

четверг, 7 апреля 2016 г.

C#: Why Dictionary with hashcode as key is dangerous

Recently, I encountered following code:

        private readonly Dictionary<int, View> _listCellsForDisposal;
            if (!_listCellsForDisposal.Contains(view.GetHashCode()))
             {
                _listCellsForDisposal.Add(view.GetHashCode(), view);
             }

The intent of that code is just add item to the list if it doesn't present. But is it doing work well? It doesn't. Let's see why.

At first, let's look at the signature of GetHashCode:

public override int GetHashCode()

So, it returns int. int in c# is platform-dependent. For example int32 takes 4 bytes, it's range is:

-2,147,483,648 to 2,147,483,647

(source: https://msdn.microsoft.com/ru-ru/library/5kzh1b5w.aspx)

But how many objects can we add to the dictionary?

среда, 9 марта 2016 г.

Why static is pain

Bugs, related to static variables may be difficult to understand. I don't think it's worth investigating. As a general practice, just avoid keeping references to objects in static. When using a static reference you allways must ask youself when to free this static and when to use.

Example: keep reference to view in static variable. User closes our app, OS frees memory, so all statics are freed too. When user opens our app again, static gets newly created view. All is well.
Then, time passes and we add background running service in our app. So, when user quits our app OS can't just free memory - static may be accessed from our background service. And reference to view remains. Afterwards user open app again and static has view that was created FOR ALREADY DESTROYED VIEW HIERARCHY. And it is luck if it will work with new one. It is only one example of what can happen when using statics. Using statics is not bad. But statics need more attention from developer. They often must be freed explicitly (for example, recreated at app start). Better keep only primitive data in statics - ints, strings...

Connect to genymotion emulator from another machine via wifi

1. Change NAT to bridge in VirtualBox settings for emulator (network adapter is same used to access network using which you'll connect)
2. download adb wireless by henry (root)
3. enable debugging
4. disable all adb processes started by genymotion for emulator (I choose "use custom sdk" and then renamed adb.exe -> _adb.exe) and restart emulator
5. adb connect ip:5555
done
adb devices should say:
device (not offline)

воскресенье, 14 февраля 2016 г.

Method override in C#

Hi, everyone! Recently, I decided to put all basic info about method overriding in one place. Keeping in mind that method, which is overriden may be virtual or not. Or you may just want to make name hiding (don't know why anybody may want to do that). So, here we go.

Non-virtual methods

class A
{
    void Foo() {}
}

class B: A
{
    void Foo() {} // compiler warning B.Foo() hides A.Foo()
}
To resolve warning:
class B: A
{
    new void Foo() {} // explicitly say to compiler, that hiding is intended using "new" keyword
}

воскресенье, 6 сентября 2015 г.

Making fast performance complex animations in android

Recently, I've ran into a problem with animating item's height inside a list for some devices with poor performance. And I've done a library for that. It animates RecyclerView or ListView item's height, but isn't heavy-bounded to that containers - see on github. That animation is also known as expand-collapse animation. Here I describe main problems and solutions founded so far, which is used in library. Library is finished and I'll be very glad if you find some issues or propose pull requests.

So, let's start. To be more clear, I'll write some straightforward code which does what I'm telling about:

ValueAnimator animator = ValueAnimator.ofInt(100, 300);
animator.setDuration(1000);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
  @Override
  public void onAnimationUpdate(ValueAnimator animation) {
    listViewItem.getLayoutParams().height = (Integer) animation.getAnimatedValue();
    listViewItem.requestLayout();
  }
});
animator.start();
Many libraries, I so before, use this technique. But that is heavy because of requestLayout() - it causes layout and measure steps repeated again each call. From the other side,

суббота, 2 мая 2015 г.

LibGDX: Kotlin setup

In my previous post I wrote how to configure gradle files to increase build and open IDE speed. Those steps needs to be done if you want to configure kotlin in your libGDX project. Otherwise, you'll get really poor IDE responsiveness and even gradle daemon crashes. Assuming, that you've done all instructions from my previous post, here is the magic steps to use Kotlin. It's easy now:

1. Android Studio (AS) / IDEA -> Settings -> find by "plugin" -> Click "Jetbrains" -> find by "kotlin" -> install kotlin and kotlin for android (optional) plugins and click restart IDE to complete install plugin
2. Open core/src/main directory and create "kotlin" directory there. Recreate directories for your package, like they are in "java" directory. If your app's package is com.mycompany.mygame, then create directory com, open it, create mycompany and so on.
3. Return to IDE. You may try tools -> Kotlin -> Configure kotlin in project... or add bold lines to your core/build.gradle: