Friday, 27 September 2013

Special elements like mathematical elements in xml android file

This site: click has list of elements which can be used in xml. Just watch the second (column) element. For example:

    square = &#8730

THen you need to conver it. For example:

    String symbol = Html.fromHtml(square);

Alternative link is here: click you can check similar example

Thursday, 26 September 2013

Android Open Kang Project + How root S3 mini

Okay, here is a deal:
First you should get some stuff:
1 Odin direct click
2 Clock Work Mod direct click
3 Your favourite pack can be found here just select your phone then on the righ click Android Open Kang Project (page will return you 2 options: first is a system, the second is addon google apps)
4 If you want google apps you should also download this addon (if you followed my link from point 3, this gapps pack should be visible after clicking at AOKP distro)




After getting all stuff we should do something with that.. UP

First, run app as administrator Odin exe, click on button PDA and select Clock Work Mod (first unzip it) pack to flash it (file extension should be like tar.md5).



 If you are lucky everything should be finish without errors. Phone should be restarted

Second, put on your phone sdcard 2 files: open kang package in zip and also gapps (if you downloaded it btw).

Third, turn off phone. Click then Vol up + home + power, you should get CWM system on
(power button = enter, vol up/down buttons = arrow up/down).

Find option: wipe data/factory reset and run it, also do the same with wipe cache partition. Then select install zip from sdcard > choose zip from external sdcard. First select your rom (not gapps! it should be installed secondly!!) and install it. Then select gapps and also do the same thing - install.

If everything finish with positive status, select reboot system now (if you cant find it, select +++GO BACK+++ ).

Loading will take some time but not longer than few minutes ~4

Monday, 23 September 2013

Setting background as color in selector

Here is an example of xml file with selector for showing custom color background for specific element

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@color/white" android:state_pressed="true"/>

</selector>

Tuesday, 17 September 2013

Declare many imvageviews in code

If you need declare many views in code without pasting monkey code here is the solution.
The key of solution is TypedArray object.

Let's say we have layout with N imageviews in our layout, each element has own id.

First we need make in res folder file where we will store elements ids in array, it can be arrays.xml
So we write example this:

<array name="avatars_icons">
        <item>@+id/img0</item>
        <item>@+id/img1</item>
        <item>@+id/img2</item>
        <item>@+id/img3</item>
        <item>@+id/img4</item>
        <item>@+id/img5</item>
        <item>@+id/img6</item>
        <item>@+id/img7</item>
        <item>@+id/img8</item>
        <item>@+id/img9</item>
        <item>@+id/img10</item>
        <item>@+id/img11</item>
        <item>@+id/img12</item>
        <item>@+id/img13</item>
        <item>@+id/img14</item>
    </array>

Then we need have array with theirs images

<array name="avatars_male">
        <item>@drawable/m0</item>
        <item>@drawable/m1</item>
        <item>@drawable/m2</item>
        <item>@drawable/m3</item>
        <item>@drawable/m4</item>
        <item>@drawable/m5</item>
        <item>@drawable/m6</item>
        <item>@drawable/m7</item>
        <item>@drawable/m8</item>
        <item>@drawable/m9</item>
        <item>@drawable/m10</item>
        <item>@drawable/m11</item>
        <item>@drawable/m12</item>
        <item>@drawable/m13</item>
        <item>@drawable/m14</item>
    </array>

And in code we do something like that

TypedArray avatarsImageViews = getResources().obtainTypedArray(R.array.avatars_icons);
TypedArray avatarsSex = getResources().obtainTypedArray(R.array.avatars_male);

 for (int i = 0; i < avatarsImageViews.length(); i++) {
            ImageView iv = (ImageView) findViewById(avatarsImageViews.getResourceId(i, 0));
            iv.setImageDrawable(avatarsSex.getDrawable(i));
            //...
            iv.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    //stuff                }
            });
        }

Wednesday, 4 September 2013

Throwing own errors debug infos

Short description:
First argument is just an example (this Object reference)
Most of this code is quite understandable.
We are using error string message from resource by its string id.

private void checkNotNull(Object reference, String name) {
        if (reference == null) {
            throw new NullPointerException(
                    getString(R.string.error_config, name));
        }
    }