Posts

Showing posts from March, 2013

GUI like Evernote Menu

Image
In previous post I tried to make a GUI like Google Keep.
In this post I tried to clone Evernote Menu layout.
As always,do not take this code too seriously, it is just an example.


We start with ActionBar.
With Android Action Bar Style Generator (by Jeff Gilfelt) we choose a background and generate our zip code. We take only the part that interests us and integrate it. For our Activity we choose a RelativeLayout, and we put it under ActionBar.
Then we start with first component. We put a ScrollWiew.
.............. Inside the scrollView we put a LinearLayout that will contain all components.
The first box will contain Account info. We use a LinearLayout with a ImageView and a TextView.
.... Then we put a divider, a box with 2x2 buttons and another divider.
We can do it in many ways, with a GridView for example. I choose to use this layout:

..... ....... It is very important android:layout_weig…

GUI like Google Keep

Image
Google Keep has a very nice UI.

First of all, I'm not a designer, but tonight I enjoyed trying to clone it.
Do not take this code too seriously, it is just an example.


We start with ActionBar. Window and ActionBar have same background color.

With Android Action Bar Style Generator (by Jeff Gilfelt) we choose a background and generate our zip code. We take only the part that interests us and integrate it. For our Activity we choose a RelativeLayout, and we put it under ActionBar. Then we try to draw first box with title and icons.

We choose a FrameLayout and we adjust margins.
We want a white rectangle with a light bottom shadow. We can do it with a 9 patch image.
In this case I choose a xml file with a layer-list. Then we fill the box with title, a divider and 4 images.
....... For the buttons background we use: We should add something like this: but I should create images...

In landscape mode, we change something in layout:

Change Credentials in EGit

Image
It can be useful to someone.

I have changed my credentials on GitHub.
Now accessing my git repository aborts with Invalid username/password.

If you want clear previous credentials you can do:
Open Git repositories view, open Remotes > origin > your push url > right click and "Change Credentials..."

Snippet: Google Picker Account

Image
If we want to show a picker with Google accounts, it has become extremely simple with Google Play Services.

Until a few months ago, we would have had to use something like this:
AccountManager manager = (AccountManager) getSystemService(ACCOUNT_SERVICE); Account[] list = manager.getAccounts(); for(Account account: list) { if(account.type.equalsIgnoreCase("com.google")) { //Do something } } To use this code we need the following permission in your manifest:

Now we can use new AccountPicker.newChooseAccountIntent() method.

First of all, we need to make sure the Google Play Services client library is being included in the Android's project build path.

Select Project > Properties > Java Build Path > Libraries from the Eclipse menu.Click Add External JARs.Browse to android-sdk-folder/extras/google/google_play_services/libproject/google-play-services_lib/libs, select google-play-services.jar and click OK.In the Order and Export tab, make sure th…

Antipattern: freezing the UI with a Service and an IntentService

Image
The worst thing that can happen to your app's responsiveness is an "Application Not Responding" (ANR) dialog.

In my previous posts I described how to freeze the UI with a Broadcast Receiver and with a Async Task.

In this post I'll freeze the UI with a Service and with an IntentService.

A Service is an application component that can perform long-running operations in the background.
We should read official doc very carefully.
A Service is not a separate process. The Service object itself does not imply it is running in its own processA Service is not a thread. It is not a means itself to do work off of the main thread (to avoid Application Not Responding errors) It should be simple...if you do use a service, it still runs in the main thread of its hosting by default, so you should still create a new thread within the service if it performs intensive or blocking operations.
The standard pattern for implementing a Service is to create and run a new Thread from onStartCom…

Snippet: Android Plurals form

Image
Android supports Plurals. Plurals are XML based resources which allow to handle different quantities.
Here you can find a simple implemetation.
Plurals can be placed in any xml-file in the values directory, but usually, it will be placed in strings.xml. No booksOne bookTwo booksFew booksMany books%d books To get the plurals from code, you can use the getQuantityString(int id, int quantity). Resources res = getResources(); String book = res.getQuantityString(R.plurals.books, count, count); The call to getQuantityString() takes the id of the plural, the quantity used to select the appropriate plural, and optionally any arguments used for substitution in the display string.
If your plural strings do not include string formatting, you don't need to pass the third parameter.

Here a simple code: public class PluralFormsActivity extends SherlockActivity { private void retrivePlurals() { TextView tw = (TextView) findViewById(R.id.text_xml); if (tw != null) { …