Android

Hello. I didn’t write for a while. I was studying a very important part how to use existed database in your app. There are several tutorials about this topic. I experimented with some examples all day long. But I could not find a flexible and nice solution that I would like to use in my apps.

At the end I remembered about the Quiz, I checked it and I was laughing for a minute. I found a long time ago the best solution! I have already used it.

So, there is a library Android SQLiteAssetHelper. It is very easy to use it.

First add dependencies inside the build file (Gradle):

dependencies {
    compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
}

Now create a class and that it! Everything works.

public class MyDatabase extends SQLiteAssetHelper {

    private static final String DATABASE_NAME = "northwind.db";
    private static final int DATABASE_VERSION = 1;

    public MyDatabase(Context context) {
	    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
}

There is only one confusing thing, the library was updated four years ago.

Russian words

I have updated the app today. I just added a new activity (it is a tile menu),  the new words and a new category. How to improve my app? I see different ways to improve it.

  1. I am going to put everything in the db
  2. Optimize the audio data
  3. Insert 1000 words (this is my first milestone)

Novita: news

I wrote a simple app to read news. It uses API of https://newsapi.org/, the API is very easy to use.

In this project I used two activities. In first activity there is GridView, where the app loads the news sources. The second activity is a ListView, where I parsed the title, the description and the published date. Now the app is very basic. It is nice to use it. I am going to rewrite it in a few weeks and add a dynamic GridView. The code is very straight. There were only one thing that made me think. I had to convert the date and time from ISO 8601 Javascript format to Java Date. I was looking the solution in internet first and as always I found the solution.

Converting ISO 8601-compliant String to java.util.Date
ISO 8601 date parsing utility
Formatting a calendar date
JSON date to Java date?

screenshot_1

Each news is a link, it opens in a browser.

screenshot_2

Search books

Hello. I have just updated my educational Search books app.

I implemented settings fragment to setup order by setting.

I added setOnKeyListener – if user taps on Enter button, it will work as Search button.

searchEditText.setOnKeyListener(new EditText.OnKeyListener() {
	public boolean onKey(View v, int keyCode, KeyEvent event) {
		// If the event is a key-down event on the "enter" button
		if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
				(keyCode == KeyEvent.KEYCODE_ENTER)) {
			// Perform action on key press
			// Clear the adapter of previous book data
			mAdapter.clear();
			String search = searchEditText.getText().toString();
			loadMore(search);
			return true;
		}
		return false;
	}
});

I added setOnScrollListener to load more data.

// Create an OnScrollListener
bookListView.setOnScrollListener(new AbsListView.OnScrollListener() {

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {
		int threshold = 1;
		int count = bookListView.getCount();

		if (scrollState == SCROLL_STATE_IDLE) {
			if (bookListView.getLastVisiblePosition() >= count - threshold) {
				// loadMore
				String search = searchEditText.getText().toString();
				startIndex += 10;
				loadMore(search);
			}
		}
	}

	@Override
	public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
		//
	}
});

Password reminder

I changed the layout. I added some code that splits hash for the blocks (each block contain 4 letters). The purpose of the app is quite difficult to explain. If you get it you will find it very useful. Actually it doesn’t store any password, it just count the SHA3 hash for the entered data: username and master password. So you can use one master password for any account.

Screenshot_2017-06-13-17-25-26

Search books app

Today I refactored my code and implemented Uri.Builder. It is a useful Helper class for building or manipulating URI references.

I send to here the REQUEST_URL for a query, then I add some parameters and voila we have our nice query!

// make query using Uri.Builder
Uri baseUri = Uri.parse(REQUEST_URL);
Uri.Builder uriBuilder = baseUri.buildUpon();

uriBuilder.appendQueryParameter("maxResults", "10");
uriBuilder.appendQueryParameter("orderby", "newest");
uriBuilder.appendQueryParameter("q", keywords);
requestUrl = uriBuilder.toString();

Reference:
Uri.builder