Posts

Showing posts with the label UI

Bullets List in Android?

  A much needed, sometimes hidden in the framework, and mimicked with unnecessary WebViews and sort of inner HTML injections to xml resources – a bullet list is much easier to implement then you would expect. When taking the easy solution – using WebViews , you are making the UI hierarchy much heavier then it should be, and when your UI is already rich with layouts and widgets, it seems bad to overload it with heavy WebViews. The Android.text framework gives us – the developers an easy to use API to build special text spans, in the next code snippet we’ll see how a bullet list can be implemented: let’s say we have a simple TextView which we need to hold a text with a bullet at the left hand of it: TextView mTv = (TextView)findViewById(R.id.tv_1); CharSequence cs = getText(R.String.sample_text); SpannableString ss = new SpannableString(cs); ss.setSpan(new BulletSpan(15), 0, cs.length(), 0); mTv.setText(ss);   Explanation: 1. Get a hook on a TextView 2. Construct ...

Introduction to Android native development using Xamarin’s Mono for android.

  It’s been couple of months since I’ve had a chance to post here, but it’s been an amazing time for me in terms of adapting new/old technologies for my development skills, and I have a bag full of new knowledge which has been accumulated and is waiting to be put on the blog, So in the coming weeks I’ll start posting a lot of code samples, architectural guidelines and how-to-do’s. In My professional career as a software developer, the first contact I had with OOP was with C#, back in 2007 as part of a course I took for web development which involved mostly ASP.Net, Windows forms and at the time - the diapers of WPF and Silverlight which were the latest buzz by Microsoft along with c# 3.0 and the 2.5 .Net framework. As time passed, I took on Java in order to acquire the skills which will allow me to program for the Android platform, which is my (Native) passion in the last 3 years or so. Developing for Android in Java is really something all java programmers are able to adapt to as...

Properly save battery Life Throughout App’s lifecycle

On every Google IO, many advocates for the Android platform demonstrate and teach us how to build great apps. The term “Great Apps” consists of many aspects – user experience, performance, saving battery life, not wasting expensive 3G quota and more..in this post i’ll try to demonstrate a simple way to not waste battery life in an Animation oriented activity. Let’s say that after displaying a nifty splash screen, your main activity consists of some animations which act in some sort of an infinite loop, to change pictures, articles, maybe polling data from a web service (asynctask of some sort). needless to say, that all of these processes take a lot of juice from the battery, so why worry about it? well, if we are focused in that activity, there’s not much we can do because it’s in the foreground and the user probably has some interactions with the current activity. but what happens once it’s not focused anymore? all these tasks don’t just stop themselves, it’s in our respons...

Actionbar implementation in earlier Android versions

  The ActionBar was introduced in Android 3.0 (API 11) and enable us to develop applications with a more fluid navigation using Fragments. Ever since, we are using the Action Bar in pretty much every application. The question is, how to be able to implement the Action bar in earlier < 3.0 API’s ? The support library which enables us to use Fragments for devices with API<3 is great and does the work just like we want and need. but what about action bar support? it’s not out of the box even in the support library. the excepted method of implementing Action bar for those earlier versions is actionbarsherlock(or ABS) just to keep things short. The ABS is an open-source expansion of the Android support library and it enables us to write application without having to make a implicit adjustment to out activities in order to support Action bars. The usage is simple: 1. download the project from the ABS website at : http://actionbarsherlock.com/ 2. inside the archive you’ll fi...

Utilizing Http response cache

     A typical mobile application will probably consume some resources from a web server using http requests. This repeated task has some drawbacks: Bandwidth has a cost, polling the same data over and over again results in a waste of user’s quota. the responsiveness and user experience is compromised once the user keeps waiting for data. If the requested data hasn’t changed on the server, then there’s no reason for us to fetch it. Of course, local caching of data is a must, but we also need to be able to refresh the data if it has changed on the server. A simple solution which comes out of the box for API 4+ is http response caching. Http response caching is a mechanism which enables us as developers to save a footprint of the response utilizing the abilities of the Http protocol. Basically, is holds a simple cache of the response which can be defined and enabled in code, and it prevents from fetching unchanged data from the server which was already fetched a...

Design Patterns in Android

       As Android developers or developers in general, we encounter the Design Patterns paradigms pretty much in every job. Most of us as I roughly assume – go over some of the more common design patterns as an integral part in preparing for a job interview.      It is common to assume that software developers should be familiar with what design patterns are and should be able to fire couple of them and explain their usage in modern software architecture. the common patterns that you’ll probably be asked to explain are Singleton, Factory, Strategy and maybe some more exotic ones.      So the question asked, is how do classical Design patterns come handy when planning the  architecture of an android app?      The answer to this somewhat bizarre question can be divided into two mini answers : The platform which we are developing for is not important. In other words, the fact that we are dealin...

How to update UI from a different thread

     Google has set it’s tone on some tough guidelines for developing android apps, basically there aren’t any strict rules but one very easy to misunderstand. there is a single Thread which is called the “main” thread, or “UI thread” on some places. this is the thread which is in charge on the views and interaction with the users gestures. based on the guidelines of any mobile platform at the moment, all the work that shouldn’t be done on the main thread should be done on background thread. this can be achieved in many ways, you can use AsyncTask, Or A Handler, Or a simple thread with an implementation of the   run() method within the declaration of the runnable. ok, so if I’m pulling some server data, or performing long calculations, pulling stuff from or to the Sqlite database I’ll probably use an AsyncTask. but let’s say for instance that I want to simply update the UI once every couple of seconds (update a TextView or an ImageView’s content etc..),...

Testing Android Applications

Android Testing testing in Android application can be really tricky, there’s a lot to test if we want to deliver a proper application which supports as much users as posible, here are a few tips on the what to test and how to test: Testing in Android: · Screen sizes Testing how the app is shown in different screen sizes · OS versions Apps can behave differently or even crush in some OSD versions due to lack of targeting to specific device · Densities Screen densities change from device to device, and from a UI point of view this can be real issues, having apps to look far from the designers aim · Resolutions When not targeting a specific resolution the graphics are used with OS manipulations like stretch and scale, which can be resulting in a disastrous UI and UX for the user · Functionality Basic functionality testing of the app in terms of business logic · Usability The usability angle is very important once we are handling a small device, a lack of attention to the UI and user e...

תכנות לאנדרואיד בקלות פרק 13 – עבודה ברקע – Services

תכנות לאנדרואיד בקלות פרק 13 – עבודה ברקע – Services מהם services? למעשה ניתן לסווג אותם כתהליכים שרצים ברקע, ללא תלות באפליקציה לדוגמא: שעון הוא service, שעון מעורר, מזג אוויר, מד סוללה, כל אלה הם services שאינם "אפליקציות במלוא מובן המילה" ורוב הפעמים גם אין להם ממשק משתמש – UI מדוע אנחנו צריכים services? מכיוון שאנחנו צריכים תהליכים שירוצו ברקע ללא התערבות שלנו, לדוגמא: Facebook, במידה וישנם עדכונים רלוונטים, אני צריך לקבל עדכון, דהיינו יש update service שרץ ברקע ודוגם את השרת כל X שניות/דקות לקבלת מידע חדש, כנ"ל עבור gmail, calendar וכו.. מה אנחנו צריכים בשביל לפתח service? 1. להצהיר עליו ב manifest שלנו, בדיוק כמו שהיינו עושים עם Activity בצורה הבאה: <service android:enabled="true" android:name=".MyService" /> כאשר ה name שלו הוא אותו השם של ה Class אותו נכתוב בסעיף הבא. 2. לכתוב את ה Service עצמו: מדובר ב service שמתחיל לנגן קובץ מדיה כשלוחצים על play, ועוצר כשלוחצים על stop כמו כן, מציג חיווים מתאימים לגבי הstate של ה serv...

תכנות לאנדרואיד בקלות פרק 9 – תפריטים - Menus

Menu באנדרואיד הינו אלמנט מאוד חשוב, כדאי לכלול אותו בכל אפליקציה על מנת לאפשר למשתמש להגדיר את ההגדרות וההעדפות שלו. ישנן 2 דרכים אשר באמצעותן ניתן ליצור menu: 1. ע"י xml 2. ע"י code יצירת menu ע"י XML <? xml version ="1.0" encoding ="utf-8" ? > < menu xmlns:android ="http://schemas.android.com/apk/res/android" > < item android:id ="@+id/new_game" android:icon ="@drawable/ic_new_game" android:title ="@string/new_game" android:showAsAction ="ifRoom" /> < item android:id ="@+id/help" android:icon ="@drawable/ic_help" android:title ="@string/help" /> </ menu > תחת תיקיית res צרו תיקיה בשם menu ובתוכה צרו menu.xml, זה הקובץ אשר מכיל את ההגדרות עבור התפריט בתצורה הבאה: תחת התגית של menu יש ליצור תגיות item אשר כל אחת תכיל: · Id – על מנת שנוכל להחליט בקוד מ...

תכנות לאנרדואיד בקלות פרק 6 – בניית Layouts על ידי code

מבוא בפרק הקודם ראינו כיצד ניתן לבנות layouts (מסכים) שונים ע"י שימוש בשפת markup – XML כפי שאנחנו מכירים מפלטפורמות אחרות כגון WEB/ASP.NET או WPF. ע"פ הנחייה של Google וכל best practice שתפגשו אשר דן בסוגיה (XML או קוד), מומלץ לשתמש ב XML על מנת לבנות layouts, אך בכל זאת כדאי מאוד שנכיר גם את השיטה השניה, בנייה ע"י code. בואו נתחיל: בואו ניזכר במתודה אשר נקראית  setContentView(R.layout.main), זוהי מתודה של המחלקה Activity, אשר בבנאי שלה אנו בעצם שמים reference ל VIEW אשר יופיע לנו בזמן שהActivity הרלוונטי בפוקוס (Forground). במקרה ה XML-י הבנאי קיבל שם קובץ הLayout. כאשר אנו כותבים את כל הממשק בקוד, הוא יקבל View. בואו נראה דוגמא קצרה: נניח שאני רוצה שה VIEW של ה Activity שלי יכיל: Button – עם המלל hit me TextView - עם המלל : “hello world” כמו כן, ארצה ששני הcontrols הללו יופיעו בצורה מאונכת אחד מעל השני, וממורכזים אופקית. הקוד שיבצע את המשימה הנ"ל הינו הקוד הבא: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState...

תכנות לאנרדואיד בקלות פרק 5 – בניית Layouts על ידי xml

Image
בפרק זה אנו נתקין את אופן כתיבת layouts באמצעות XML. בעיקר נתרכז בסוגי controls, ואיך כדאי לגשת לממשקים מעט מורכבים יותר מאשר תבניות סטנדרטיות. בואו ניזכר רגע באפליקציית hello world מפרק 3   < RelativeLayout xmlns:android ="http://schemas.android.com/apk/res/android" xmlns:tools ="http://schemas.android.com/tools" android:layout_width ="match_parent" android:layout_height ="match_parent" > < TextView android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:layout_centerHorizontal ="true" android:layout_centerVertical ="true" android:text ="@string/hello_world" tools:context =".MainActivity" /> </ RelativeLayout > אז מה יש לנו כאן? יש לנו RelativeLayout שהוא בעצם container, נהוג להתחיל כל קובץ layout באיזשהו container שכזה. RelativeLayout בעצם הינו Layout...

best phone for developing?

       So you are an Android developer now? great. you’ll probably start to develop using eclipse and some emulators (probably min 2.2). most of the developers I know are a bit fed up by the fact that the emulator suffers from a “few” cons. like what? You can’t really use an emulator with a mouse and get a real feel the same way you’ll do using your fingers and the various gestures you’ll use on an actual phone – get a real phone if you’re developing an app which includes picture taking/video recording or sound even, then you’ll find yourself guessing – get a real phone Locations – yes, if you’re developing an application which includes locations and maps, you’ll probably want to test it out. yes, the DDMS offers such emulation of Geolocations but it’s not so fun to use – get a real phone pretty much any sensor that you can’t think about needs a real phone in order to develop it the proper way – get a real phone   ok, we got it, you need to get a ph...

Spinner VS AutoCompleteTextView

Image
       We’ve all been in a situation where we needed to show a list of some sort, a list which should be triggered by a user interaction (click, tap, etc..) A list is simple enough, probably even a spinner if we don’t want to spend that much screen real-estate on showing a list which the user clicks once and probably doesn’t need to see it after that. A spinner can be a real bug once there are too much entries for the user to choose from, how much is too much? that’s a good question – probably it differs from user to user, and probably this will have some performance issues with areal large number of entries, you cannot scroll forever to find what you’re looking for. A simple solutions for the problems mentioned above is an AutoCompleteTextView. it’s a control which is basically a combination of a TextView, EditText, and a Spinner all wrapped up in a single easy to use and configurable control. let’s see how it’s done:   first, in the layout file, c...

Boil an egg app - step by step (step 3 – code)

Image
  After reviewing part 2 of the tutorial, it’s time for coding. let’s get started. In the main activity class we’ll have the following things to do: 1. set some private variables to be accessed from different places in the class. 2. bind some variables to views from the xml reviewed in part 2 3. set listeners for the different buttons on the screen 4. handle timer changing and displaying time remained   let’s elaborate on this : 1. initialize some variables in the main class, place those prior to the onCreate() method:     private Button btnSmallEgg,btnMediumEgg,btnLargeEgg;     private Button btnCookAnEggTimer,btnResetTimer;     private TextView btnSoftEgg,btnHardEgg;     private TextView tvTimer,tvTimerLabel;     private TextView tvChooseEggSize,tvChooseEggType,tvIntro ;         long minutes;     long seconds;     long maxTimer=600...

Gradient in XML– easy as pi

  Tired of using solid background colors but you think it’s a bit trouble to use you favorite graphics tool too create interesting backgrounds for you controls or layouts? well, creating gradients in your android app is easy enough, here’s an example: In your drawable folder , create an xml file. the next code creates a gradient which is from top to bottom, with start color of white and end color of somewhat orange, it begins to get a strong fade after 90% of the measure of the container view. <? xml version ="1.0" encoding ="utf-8" ? > < selector xmlns:android ="http://schemas.android.com/apk/res/android" > < item > < shape > < gradient android:angle ="90" android:startColor ="#fff" android:endColor ="#FFA812" android:type ="linear" android:centerY ="0.9" /> </ shape > </ item ...