Wednesday, July 1, 2015

Material Design pain in arse

Google lose their own design tutorial. Material design - OK, BUT Y U NOT keep old articles, why you redirect me to new "design concept"? Where is cool tutor from this link: https://developer.android.com/design/patterns/multi-pane-layouts.html? I thought I'm going crazy, cause I could not find it after 2 days I read it. Maybe I remember something wrong, I thought. But you have this link in your own course on Udacity! And now I see this link:
http://developer.android.com/design/patterns/actionbar.html
And it works! But you can't reach this page from anywhere on developer.android.com. And it contains link to App Bar - material design analog. Why not to keep other articles in this way?
Also I remember articles with tablet design strategies - when use multiple panels and when just stretch. Maybe this was on the same page - I'm not sure.
Google, please, please, please, revert you site to previous state and keep material design as additional section. Please, please, please.

Monday, June 8, 2015

My first real-life example of Fragment's reuse.

When you start to learn Android one of the first thing, that course or book trying to put in your head - "use Fragments".
 Why? Because you can put two and more Fragments on one Activity. Ok... But I also can reuse XML code to include needed layout. This was my first thought. But I used fragments in every application. Just because I was taught.
But now I have real example of reusing Fragment for Activities, that contains exactly one Fragment.
We have applications that is simply catalog of  blogs, grouped by categories. So, on my MainActivity I have list of categories and sub-categories. And when you click on category - you get list of blogs from this category. Very simple app.



For showing these lists I use CursorLoader. So, BlogsFragment implements LoaderCallback, from onCreateLoader I return CursorLoader, that query blogs by category. This is common approach.

From screenshots you can see that there are also searching and favorites. By the way, searching implemented using FTS3, but this is theme for other post.
So, when I started to implement search, I used common android practice with searchable activity. So, I created such activity... And on search result I have to show list of blogs. Again. So I used BlogsFragment again. Only thing I have to change - it's query for cursor loader.
The same is for favorite blogs - only new query, all other code is the same.
I understand, that absolutely right approach is to use something like Strategy pattern. But for my goals I added extra flag for intent, that run activities, that use BlogsFragment. So here are some code snippets from blogs fragment:
 public class BlogsFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>  
   public static final String EXTRA_MODE = "extra_mode";  
   public static final int MODE_FROM_CATEGORY = 0;  
   public static final int MODE_FAVOURITES = 1;  
   public static final int MODE_SEARCH = 2;  
 .....  
   @Override  
   public void onActivityCreated(Bundle savedInstanceState) {  
     Intent intent = getActivity().getIntent();  
     if (intent != null) {  
       String title = intent.getStringExtra(EXTRA_CATEGORY_NAME);  
       if (title != null && !title.isEmpty())  
         getActivity().setTitle(title);  
       if (Intent.ACTION_SEARCH.equals(intent.getAction()))  
         currentMode = MODE_SEARCH;  
       else  
         currentMode = intent.getIntExtra(EXTRA_MODE, MODE_FAVOURITES);  
     }  
     initLoader();  
     super.onActivityCreated(savedInstanceState);  
   }  
 .....  
   @Override  
   public Loader<Cursor> onCreateLoader(int id, Bundle args) {  
     Intent intent = getActivity().getIntent();  
     if (intent == null)  
       return null;  
     if (currentMode == MODE_SEARCH) {  
      .....  
       return new CursorLoader(getActivity(), blogsUri, BLOGS_COLUMNS, BlogKeywordsTable.COLUMN_WORDS + " match '"  
           + query.toLowerCase(locale) + "*'", null, BlogTable.COLUMN_PRIORITY + " DESC");  
     } else if (currentMode == MODE_FROM_CATEGORY) {  
      .....   
       return new CursorLoader(getActivity(), blogsUri, BLOGS_COLUMNS, BlogTable.COLUMN_CATEGORY_1_ID + " = "  
           + categoryId, null, BlogTable.COLUMN_PRIORITY + " DESC");  
     } else /* MODE_FAVOURITES */{  
      .....   
       return new CursorLoader(getActivity(), blogsUri, BLOGS_COLUMNS, BlogTable.TABLE_NAME + "." + BlogTable._ID  
           + " in (" + favourites + ")", null, BlogTable.COLUMN_PRIORITY + " DESC");  
     }  
   }  

Thursday, August 28, 2014

Emulator online

Today I have found this awesome site: Manymo


I was trying to launch my game on emulator and failed it. So I start to search alternative. Since I need only to see app on different screens - Manymo is much better, than standard emulator. Because it is much faster - just take apk from bin and upload it. Then you have vast range of screens and apis. Choose what you need, wait 30 sec - enjoy!

Tuesday, August 26, 2014

Game Arts

Check out this arts of my new game project. Yep, I'm just coder :)