Sunday, 29 December 2013

How get rid off annoying bin gen folders from git repository - intellij / android studio

There two ways to get rid off it:
Case 1: you have just created new project and didn't commit first changes:
It's better because you have clean plate and you can define what should be ignored.

I'm using this text which is saved in .gitignore file placed in main project, but if you are using another libraries you can put .gitignore also there.

 ### Android ###  
 # built application files  
 # files for the dex VM  
 # Java class files  
 # generated files  
 # Local configuration file (sdk path, etc)  
 # Eclipse project files  
 # Proguard folder generated by Eclipse  
 # Intellij project files  

I know there are sometimes problems with gitignore files, please try save file by notepad++ and it should be good solution for windows users.

Case 2:
You have commited some changes and forgot to put .gitignore

Well this is the hard part because even you commited own .gitignore file - not all filles will be ignored anyway... You might think it doesn't work but this is how it works: all filles which were commited goes to "checking file list" and if you change them, they will be also raported as changed..

What to do then? In few steps:

for example with bin folder (it was commited and you forgot to ignore it)
0. Put own .gitignore file by placing it in proper main project folder and commit changes
1. Remove or move out of project bin folder (just make sure bin is gone while doing this operation, intellij tends to autogenerate bin and gen folders, so make sure intellij is closed)
2. if you write now git status inconsole, you will see bin folder was deleted
3. Commit changes - bin will be removed so there will be no checking this folder/files in future
4. Put bin folder back or let intellij generate new bin folder
5. Check if git found bin folder by writting in console git status, if there is no any information about bin folder, it means it is now ignored by git:)

Friday, 27 December 2013

Intellij regular expressions samples

Will be here bunch of samples what to write to find what you want:

  • Find declaration of anonymous AsyncTask starting by new AsyncTask
  •  (?<=\t)new AsyncTask

Wednesday, 25 December 2013

HoloEverywhere Library - dialog layout is wrong on Sony devices Android 2.3.x

Few days ago I posted short question/topic on about problems with holoeverywhere and sony phone family. There is probably problem with linear layouts and measuring heights. So far the main developer and owner of this library didn't responded on my issue answer .

Actually what can you do is just replace linear layouts to relative in places where it is major.
So to be sure if your app works fine just try it on devices from sony family with android lower than 4, mainly it happens on android 2.3.x.

Wednesday, 11 December 2013

Noobrom Apk Latest Addition - announcement

Hi, temporary I don't have time to fix problem with high end devices like Nexus 5 (there were also rumors with S3). Problem is connected with large heap because I need to parse so much elements (above > ~2k items). I will back to this project asap. So please be patient and stop rating 1 :D At least please wait with commening in few/several days. I will appreciate this.

I am planning store datas in databases as remote cloud place for speed up loading releases. But this is still in planning.


Thursday, 5 December 2013

Adb multiple devices - how to connect

In few example words...

1. Command "adb devices -l"

C:\Users\XXX>adb devices -l
List of devices attached
HT1AWVZ11641           device
01e010f522900141       device product:occam model:Nexus_4 device:mako

2. Command "adb -s <serial number> shell"

C:\Users\XXX>adb -s 01e010f522900141 shell
shell@mako:/ $

Monday, 2 December 2013

Clickable text in TextView + text bold + text color (ClickableSpan + Span bold color)

Here is short example how to use spannables.
My TextView was named "text_terms_link", so you should use your own view or rename like mine.

 ClickableSpan cs = new ClickableSpan() {  
   public void onClick(View view) {  
     //action stuff here  
 //getting text from xml = "Terms and Conditions"  
 String text_terms_string = getResources().getString(R.string.register_terms_text);  
 SpannableString ss = new SpannableString(text_terms_string);  
 //we need find oud position of "Terms" text: first index and the last  
 int termStart = text_terms_string.indexOf("Terms");  
 int termStop = termStart + "term".length();  
 //we set here clickable our text  
 ss.setSpan(cs, termStart, termStop, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  
 //we set here our color i.e. #cccccc in this example I take color from xml  
 ss.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.aquaBlue)),  
 //we set here text to be bolded    
 ss.setSpan(new StyleSpan(Typeface.BOLD),termStart,termStop,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  
 //I set here spannable text to my previous declared TextView  
 //We set here clickable text, this is important !!  

Wednesday, 27 November 2013

Adb shell - opening/copying files by selecting as wildcard

Let's say we have very long app and we do not want rewrite it because it takes too much time or we sense that the percentage of wrong misspelling will be occured.. here is the solution

We know that:
ls - list files
| - is a pipe for i.e. grep
grep <text> - filters text and returns text which is accepted with our filter

Problem: we need to open directory which is too long, we need use example wildcard:
cd $(ls|grep App_Back) - we need just few letters of directory which we want to open

shell@mako:/storage/emulated/legacy $ ls
shell@mako:/storage/emulated/legacy $ cd $(ls|grep App_Backup)
cd $(ls|grep App_Backup)
shell@mako:/storage/emulated/legacy/App_Backup_Restore $

Tuesday, 26 November 2013

Working example - check if word exist - using wiki url for checking

Here is working example how check if our word real exist.
We will use for it wikipedia url. If we put to url our wolrd and if page opens it, it will means word exist.
However If we do it by in example firefox we will see text "we do not have much information about this, do you want add some for it?" or something like that.

If we use it by writting in code, response would be quite different. We would get responseCode which is very helpful.

 * Created with IntelliJ IDEA.
 * User: Michall
 * Date: 23.11.13
 * Time: 17:58
 * To change this template use File | Settings | File Templates.
public class WikiBig {

    private int cc = 0;

    public static void main(String[] args) {
        new WikiBig().doStuff();

     * We set path to words to check if any from the list exist
    private void doStuff() {
        CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));

        //word per line like (in polish language) example:
        //13921hx9x1 <- this will not exist so wiki will return us 400 and text will not be appendted to list of real words
        File file = new File("C:\\temp\\words.txt");


     * Unused but it converts con.getInputstream to string
     * @param is
     * @return
    static String convertStreamToString( is) {
        java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
        return s.hasNext() ? : "";

     * for every word we take from file we add it to url
     * if wiki returns us 200 it means word exists
     * if not 400
     * If we find existing word we will append it to new file with words existing
     * @param path
    private void loadTextFromFIle(String path) {
        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(
                    path), "cp1250"));

            String strLine;
            // Read File Line By Line
            while (((strLine = br.readLine()) != null)) {

        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.

     * save text to list of existing words (to file of course)
     * @param strLine
    private void askWordWiki(final String strLine) {
        if (cc > 12229)
            try {

                String wordWithUrl = "" + strLine;
                URL obj = null;

                obj = new URL(wordWithUrl);

                HttpURLConnection con = (HttpURLConnection) obj.openConnection();
                int responseCode = con.getResponseCode();
                if (responseCode == 200) {
            } catch (MalformedURLException e) {
                askWordWiki(strLine);//prevent from timeout
            } catch (ProtocolException e) {
                askWordWiki(strLine);//prevent from timeout
            } catch (IOException e) {
                askWordWiki(strLine);//prevent from timeout

    private void writeAppendToFile(String strLine) throws IOException {

        BufferedWriter bw = new BufferedWriter(new FileWriter("C:\\temp\\foundwords.txt", true));

Working example with jsoup - parse from site actors and top of best movies

Here is an example how to use jsoup to parse some text from site.
This site has also small "security bridge". To get what we want we must have first cookie.

So first we will take cooke from home page, and then we will parse some text.

I used in string something like this %1$s < percentage with number tells about number of argument, dolar with s means that this will be a string (d if for decimal and etc.)
So after this move i can reuse string and putting into additional string element

 * Created with IntelliJ IDEA.
 * Date: 10.11.13
 * Time: 21:44
 * To change this template use File | Settings | File Templates.
public class Seriale {
    private static boolean writeOut = true;
    private static String start = "";
    private static String series = "";
    private static String actors = "$s";
    private static URL obj;
    private static HttpURLConnection con;
    private static int responseCode;

    public static void main(String[] args) throws IOException {

        CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));

        //we need first cookie, if we won't get it we will see annoying advertistment



    private static void initStart() throws IOException {
        obj = new URL(start);
        con = (HttpURLConnection) obj.openConnection();
        responseCode = con.getResponseCode();

    private static void getSeries() throws IOException {
        obj = new URL(series);
        con = (HttpURLConnection) obj.openConnection();
        responseCode = con.getResponseCode();

        String str = convertStreamToString(con.getInputStream());
        Document doc = Jsoup.parse(str);
        Element awt ="table.awT.rankingTable").get(0);

        Elements filmPoster ="div.ohidden");
        for (Element el : filmPoster) {

    private static void getActors() throws IOException {
        for (int i = 0; i < 5; i++) {
            obj = new URL(String.format(actors, i));
            con = (HttpURLConnection) obj.openConnection();
            responseCode = con.getResponseCode();

            String str = convertStreamToString(con.getInputStream());
            Document doc = Jsoup.parse(str);
            Elements awt ="div.hitDescWrapper>h3");

            for (Element el : awt) {

    static String convertStreamToString( is) {
        java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
        return s.hasNext() ? : "";

Working example for grasemonkey - show me only elements where post has >= 1k shares

Here is short example.
Few weeks ago I started learning javascript. This language is great it is very useful for websites where you want make little autobot or any part-site remover.
Here is an working example on real site, it is very easy.

// ==UserScript==
// @name        kwejk low rate remover
// @namespace  
// @include*
// @version     1
// @grant       none
// ==/UserScript==

//window.onload = function(){
    var elements = document.getElementsByClassName("mediaPair");
    for(var i=0;i<elements.length;i++)
        var fbc = elements[i].getElementsByClassName("fb_share_ab")[0]
        //alert("["+fbc+"]" + " " +fbc.length);

            //alert(i + "/" + elements.length + " votes " + fbc + " isNumber? " + isNumber(fbc) + " " + (Number(fbc) < 1000));
                if(Number(fbc) < 1000)
                    elements[i].outerHTML = "";

function isNumber (o) {
  return ! isNaN (o-0) && o !== null && o !== "" && o !== false;

Sunday, 17 November 2013

Noobroom another changes

I've changed some things in apk. I added list menu with categories to be able check list ordered by last date, by IMDB rating or release date.
There are some things to fix like: make data to load faster or handle wrong parsing.
Part of them will be fixed today before 8 PM GMT+01:00)
I'm glad people like my app and it is still useful. :)

I've found on Google services quite interesting trend diagram for noobroom. Here is the diagram showing from where (only USA) people are search Noobroom.

Wednesday, 13 November 2013

Sunday, 3 November 2013

Noobroom Latest Additions fix

Today I've fixed my app which you can find here Google Play
Now it should be working.
Please feel free pm/mail me for any problems.
Sometimes I do not have so much time to take car of my app but I'll try fix all problems asap.

Nothing much was changed except problem with logging.
I've added new information about problems with app :)

Tuesday, 29 October 2013

Battlefield 3 for free - legal

Aktywując klucz G433-XWLD-ZBW8-JWUC-JDSW dostajemy na Originie darmowego Battlefielda 3. Kod zadziała każdemu, nie jest jednorazowy.

Use this key till midnight and you will get legal BC3.
Reference to this info: link

Thursday, 10 October 2013

Excercise question for DEV Android, are you able solve the problem?

John created own lazyAdapter. His constructor had 3 arguments, first is for activity and the last two are for storing data. John decided add new elments by on his own.

John wanted first clear lazyAdapter's data and then add by his addItem method new items.

After compilation he noticed that something gone wrong. Images loaded correctly but somehow titles were not right.

Fields: images are storing urls in String, titles are storing titles of something in String.

Q:Can you figure out what was in title's text?

Q:What was causing the problem?

Q:How many elements will be in adapter in array titles after calling getView?

Picture #1

Picture #2

Monday, 7 October 2013

System UI has stopped working - probably solution for CyanogenMod

Here is one of the most topics about this bug LINK
I'm using S3 mini, I changed base wallpaper to another my own without any features. Just simple wallpapaper which was just screenshot of my phone. Seems it fixed the problem so far...
Just make sure you made reboot just for in case.

Thursday, 3 October 2013

Noobroom Latest Additions apk for Android

Here is my private project. I'm planing add to apk ability like watching movies.
This app can checks what was added recently and shows it with poster preview.

Loading can take quite long to parse, but it works. Sorry for that.
This long loading is because the app parses titles every time you run it.
Images are loaded once. When each of them is downloaded, it will be loaded only from cache then.
In this way server won't be too much overloaded.

Wednesday, 2 October 2013

Parsing html elements to readable string

Lets say we have title in html page : Big &amp; small
Our target is get this result in textView: Big & small
Solution is to use: Html.fromHtml(String string)
Example: Html.fromHtml("Big &amp; small")
In any problem you can cast .toString() after but I think it is not urgent.

Android 2.x.x not showing hint text in edittext

Here is the solution, add to xml:

OnBackPressed for fragments

Here is one of most common problems which is connected with onBackPressedFunction - how to implement onBackPressed() in Android Fragments?

And here is also my solution by using listeners to handle custom onBackPressed

According to @HaMMeRed answer here is pseudocode how should it works.
Lets say that your main activity is called BaseActivity (like in SlidingMenu example).
Here are the steps:

First we need create interface and class which implements its interface to have generic method

-1. Create class interface OnBackPressedListener

 public interface OnBackPressedListener {  
   public void doBack();  

0. Create class which implements skills of OnBackPressedListener

 public class BaseBackPressedListener implements OnBackPressedListener {  
   private final FragmentActivity activity;  
   public BaseBackPressedListener(FragmentActivity activity) {  
     this.activity = activity;  
   public void doBack() {  
     activity.getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);  

Since now, we will work on our code BaseActivity and its fragments..

1. Create private listener on top of your class
 protected OnBackPressedListener onBackPressedListener;  

2. Create method to set listener

 public void setOnBackPressedListener(OnBackPressedListener onBackPressedListener) {  
   this.onBackPressedListener = onBackPressedListener;  

3. In Override onBackPressed implement something like that

 public void onBackPressed() {  
   if (onBackPressedListener != null)  

4. in your fragment in onCreateView you should add our listener

 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {  
   activity = getActivity();  
   ((BaseActivity)activity).setOnBackPressedListener(new BaseBackPressedListener(activity));  
   View view = ... ;  
 //stuff with view  
   return view;  

Now if you click back button listener should find custom class with custom onBackPressed reaction

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="">

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


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">

Then we need have array with theirs images

<array name="avatars_male">

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.setOnClickListener(new OnClickListener() {

                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));

Sunday, 11 August 2013

Set all except first to false

for(int i = 0; i < options.length; i++) {
        options[i] = false;
        found = options[i];

Friday, 2 August 2013

PullToRefresh loading indeterminate progress bar doesn't hide, goes on and on

If your application using asynctask and you call
it is possible that time between setOnRefreshListener and onRefreshComplete will be relative small. This can create problem with not hiding loading bar.

To fix it try put in handler you function with hiding loading header bar for example like this:

 //my function which I call on asynctask finish  
 public void updateListView()  
   handler = new Handler();  
   handler.postDelayed(runnable, DELAY_MILLIS);  
And here is the runnable field:

 Runnable runnable = new Runnable() {  
   public void run() {  
       Log.d("xxx", "trying to hide refresh");  
       handler.postDelayed(this, DELAY_MILLIS);  
Handler will rerun itself and tries to hide loading header.

Monday, 29 July 2013

Styling and formatting in xml android file like quotes

Most information about styling and formating text can be found in android doc page:
Formatting and Styling

Escaping apostrophes and quotes
<string name="good_example">"This'll work"</string>
<string name="good_example_2">This\'ll also work</string>
<string name="bad_example">This doesn't work</string>
<string name="bad_example_2">XML encodings don&apos;t work</string>

Formatting strings

In code:

String string = String.format(getString(R.string.welcome_messages), "Mike", 2);

In resources:
<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>

Friday, 26 July 2013

Noobroom acc invitation close in 11 days

Noobroom is going close free access to theirs site. In 11 days site will be available only for registered users.

I'm open to send invitation to NoobRoom
PM me for it.

My android app for NoobRoom (shows latest additions) can be found here: Google Play

Thursday, 25 July 2013

Get rid off Failure [INSTALL_FAILED_OLDER_SDK] by gradle

It means your phone/emulator uses older sdk than project.
To fix go to file build.gradle and change min sdk to lower.

 buildscript {  
   repositories {  
   dependencies {  
     classpath ''  
 apply plugin: 'android'  
 dependencies {  
   compile files('libs/android-support-v4.jar')  
 android {  
   compileSdkVersion 17  
   buildToolsVersion "17.0.0"  
   defaultConfig {  
     minSdkVersion 15  
     targetSdkVersion 17  

SimpleDateFormat - How get specific date format from calendar

//Thursday, 25 July
public List<HashMap<String, String>> getCalendarsFormats() {
    Calendar calendar = Calendar.getInstance();
    List<HashMap<String, String>> dates = new ArrayList<HashMap<String, String>>();

    for (int i = 0; i < 4; i++) {
        Calendar tempCalendar = (Calendar) calendar.clone();
        tempCalendar.add(Calendar.DAY_OF_WEEK_IN_MONTH, i);

        HashMap<String, String> tempHash = new HashMap<String, String>();

        SimpleDateFormat formatter1 = new SimpleDateFormat("dd-MM-yyyy");
        String format1 = formatter1.format(tempCalendar.getTime());
        tempHash.put("format1", format1);
        SimpleDateFormat formatter2 = new SimpleDateFormat("EEEE, dd MMMM");
        String format2 = formatter2.format(tempCalendar.getTime());
        tempHash.put("format2", format2);


    return dates;

How listen incoming sms in service

Wednesday, 24 July 2013

How capitalize first letter in string

char[] stringArray = myString.toCharArray();
stringArray[0] = Character.toUpperCase(stringArray[0]);
myString = new String(stringArray);

Obtaining resources by numer of index instead resource id by TypedArray

While using resources as items in you listview or adapter, try store and load it from <_array> tag. You will avoid exceptions in case where apk in specific language has new items and in other not.

Now you can take resource by index, not by specific id.
arr = mCtx.getResources().obtainTypedArray( R.array.art_sounds_url);
mAudioRes = arr.getResourceId( resArrPosition, -1 );