Could not find com.android.tools.build:gradle:2.2.0 -here is the solution

In case You had problem with:

Error:Could not find com.android.tools.build:gradle:2.2.0.
Searched in the following locations:
    https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.0/gradle-2.2.0.pom
    https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.0/gradle-2.2.0.jar
Required by:
    :YOUR_PROJECT:unspecified

Don’t forget modify root build.gradle and add

jcenter()

It would look like this:

buildscript {
    repositories {

jcenter()

        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

Simple pulling database sqlite to desktop and preview it

All what we need is to make few steps:

  1. Add in our project this line to output in log current path to database
    Log.d(TAG, "onCreate db: " +  context.getDatabasePath("mydatabase.db"));
  2. Create simple batch command to pull database (afik root is no needed)
    adb pull "/data/data/com.example.app/databases/mydatabase.db" mydatabase_%date%.db.sqlite
  3. Download SQLiteManager to firefox, run it, open our sqlite database

 

Zrzut ekranu 2016-02-16 12.15.38

 

 

 

Good luck!

Notepad++ with regex, re-using match variables

Here is an simple example how to use regex in notepad++ with reusing selected match variables.

For example we have special code for simulating gcm notifications. We would like to see it in pretty style.
To achieve this we must to move all elements with minus to the new lines. How to do it? Here is the solution.

We have this string:
adb shell am broadcast -a com.google.android.c2dm.intent.RECEIVE -c com.example.android.debug -n com.example.android.google.debug/com.example.android.gcm.GcmBroadcastReceiver --es "aaa" "123" --es "mmm" "bla bla bla" --es "sss" "321" --es "from" "111" --es "type" "yesterday" --es "collapse_key" "do_not_collapse"

By using bellow command in notepad++:

Searching text:

\-[a-z]{0,2}\s

Replace with:

\n($0)

We get the quite pretty result:

adb shell am broadcast
-a com.google.android.c2dm.intent.RECEIVE
-c com.example.android.debug
-n com.example.android.google.debug/com.example.android.gcm.GcmBroadcastReceiver
--es "aaa" "123"
--es "mmm" "bla bla bla"
--es "sss" "321"
--es "from" "111"
--es "type" "yesterday"
--es "collapse_key" "do_not_collapse"

Ignoring some logs in Logcat filter – Android Studio – solution

Here is a little help to remove from our logcat some logs we don’t want like: dalvikvm or OpenGL
All what you need is to click in top right corner of logcat, select our package name and click Edit Filter Configuration

2015-04-28_11h04_27

Then in the field called Log Tag regex You need insert this
^((?!(?:dalvikvm|OpenGLRenderer)).)*$ which means you don’t want any log which contains dalvivm or OpenGLRenderer. If You want add another word to ignore list just insert inside of regex

|word

For example:
^((?!(?:dalvikvm|OpenGLRenderer|Word)).)*$

Working example of setting alarm with repeating stuff, checking if alarm was set with pendingIntent

Here is short and quite (imho) understanding part of code:

//starting #1
AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(getActivity(), MyReceiver.class);
intent.setAction(MyReceiver.ACTION_ALARM_RECEIVER);//my custom string action name
PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity(), 1001, intent, PendingIntent.FLAG_CANCEL_CURRENT);//used unique ID as 1001
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), aroundInterval, pendingIntent);//first start will start asap

#1 – first we are getting alarm service. We create own intention and setting own action to it to be able handle in onReceive(), in our receiver class. Then the intention is putting into pendingIntent. The complete pendingIntent is used by alarmManager for a start.
I used System.currentTimeMillis() because I wanted start repeating asap.
I used flag PendingIntent.FLAG_CANCEL_CURRENT for pendingIntent but it might be also PendingIntent.FLAG_UPDATE_CURRENT. It is important to use the same flag everywhere, but when you want stop it, you use PendingIntent.FLAG_NO_CREATE. I will write about it later.
Number 1001 in pendingIntent was used just to be know that our intention has unique ID.

Continue reading “Working example of setting alarm with repeating stuff, checking if alarm was set with pendingIntent”

Smaller ratingboard with clickable area

During my one day project for a client I had to use (I hate it) android’s ratingbar component. One of the pointed task in project was to use a bit smaller object with 5 stars than it is as default. What is more it had to be place it in every item in listview.
So what’s the problem? “All you have to do is to use param

style="?"

” – I thought. But it has not been the final solution yet..

Continue reading “Smaller ratingboard with clickable area”

Clearing items in MultiSelectListPreference – solution

Hi, today I was working on MultiSelectListPreference in PreferenceFragment screen. I was going to have multi select list where user would be able select items. Each selected item would be describing specific shortcut from my app to OP desktop.
After about half an hour I found out how to restore MultiSelectListPreference with all default items.

Continue reading “Clearing items in MultiSelectListPreference – solution”

Android NavigationDrawer not handling setOnItemClickListener- nothing happens – solution

During my graduation work I had to use navigation drawer for menu list. What is more, I also needed pull to refresh layout. Both items are very sensitive and its order matters where to put them. You might be in situation where you think which one should be in which one. So during rebuilding layout with that two items first I moved pull to refresh layout up, to be a root layout. This showed me unpredictable result.
I was able swipe down to refresh even when I had already opened drawer…

Continue reading “Android NavigationDrawer not handling setOnItemClickListener- nothing happens – solution”

Pull to refresh in project, disabling refresh when we want to scroll down

I have been working for my graduation work on layout `pull to refresh`, called now.. SwipeRefreshLayout. It was connected with NavigationDrawerFragment.
During tests over that two things I discovered I was not able to scroll down my list without calling refresh. I found very interesting solution on stackoverflow. Answer was posted by @Cabezas. Thank You!

Continue reading “Pull to refresh in project, disabling refresh when we want to scroll down”