VirtualBox Ubuntu: setup for development

I need a Linux box for work development (Mac Unix does not suffice) so I downloaded VirtualBox and Ubuntu. To start developing I needed a bunch of installed.



Download the package lists from the repositories. This is not update of tools, just the available directory. Upgrade existing packages.

sudo apt-get update&&sudo apt-get dist-upgrade


Install Guest Additions
Top menu > Devices > Insert Guest Additions CD...

cd /media/uki/VBOXADDITIONS_4.3.16_95972/
sudo ./VBoxLinuxAdditions.run


Installing Java JDK

$ sudo apt-get -y install default-jdk
$ java -version
java version "1.7.0_65"


Install ANT

sudo apt-get -u install ant
$ ant -v
Apache Ant(TM) version 1.9.3 compiled on April 8 2014


Install GIT

sudo apt-get install git
$ git version
git version 1.9.1


Installing Misc tools

sudo apt-get install build-essential
sudo apt-get -y install autoconf automake
apt-get -y install curl
apt-get -y install libtool




As an Amazon Associate I earn from qualifying purchases.

VItrualBox Ubuntu on Mac: up/down/delete keys act weird typing letters

When I try to navigate in vi editor the characters are being typed instead.

You can get by you alternating fn and control while using up/down and delete buttons, but that is very frustrating and hard to remember.

Solution:

in Terminal >

vi ~/.vimrc

add following line:

set nocompatible


Note: In case you don't remember how to use vi:
- hit "i" for INSERT mode
- hit "esc" ":wq"and "enter" to save
- hit "esc" ":q!" to leave without saving


As an Amazon Associate I earn from qualifying purchases.

Eclipse: hiding files in Package Explorer

It is very important to have your Eclipse IDE as optimized as possible. It is essential for me to see all "hidden" files and directories such as .gitmodules, .project, .classpath, but I do not want to see .DS_store as it is useless to me.


Solution:
In your Eclipse > Package Explorer > click a small triangle drop-down > Filters..
Add ".DS_store" and any other file patterns comma separated.
Press OK to save.




As an Amazon Associate I earn from qualifying purchases.

GIT: remove last (few) commits

You should commit often, however sometimes I do a NEW commit instead making an amend to previous, that is especially important when working with tools like Gerit (online code review) when you can have only 1 commit, sometimes for a very long time.
This recipe works only if you did NOT PUSH.

Remove recent X (~1) commits without destroying your local changes:

git log
git reset --soft HEAD~1

at this time you can squash your multiple commits and commit with --amend flag.


$ git status
$ git add --all
$ git commit --amend



As an Amazon Associate I earn from qualifying purchases.

GIT: update ALL REPOS in current directory

If you have a ZILLION GIT repositories in your current workspace you may benefit from a Bash shell command that does operations on all of them at one swoop.







function git_all_REPOS_in_current_directory() {
    WORKING_DIR=$PWD
   
    for DIRECTORY in ls -d */
    do
        #echo "directory: $DIRECTORY"
        cd $WORKING_DIR/$DIRECTORY
        pwd
        git fetch
        # do more as need like git rebase, etc. I prefer to do it MANUALLY
        # get modules up to date
        git submodule foreach git fetch
        git submodule foreach git rebase
    done
}



As an Amazon Associate I earn from qualifying purchases.

Eclipse: converting Android to plain Java project

When you are switching between Android and plain Java projects (or libraries) occasionally you may end up with a Java project that is complaining: AndroidManifest.xml is missing!
This tutorial shows the steps to fix that.



Step 1) Open .properties and remove line with AndroidNature


<natures><nature>com.android.ide.eclipse.adt.AndroidNature</nature><nature>org.eclipse.jdt.core.javanature</nature></natures>




Step 2) remove Android specific buildSpec

<buildSpec><buildCommand><name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name><arguments></arguments></buildCommand><buildCommand><name>com.android.ide.eclipse.adt.PreCompilerBuilder</name><arguments></arguments></buildCommand><buildCommand><name>org.eclipse.jdt.core.javabuilder</name><arguments></arguments></buildCommand><buildCommand><name>com.android.ide.eclipse.adt.ApkBuilder</name><arguments></arguments></buildCommand></buildSpec>



Step 3) Open .classpath and remove android references


<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>


Step 3) Open  project.properties (auto-generated) and remove Android references



android.library=true
# Project target.
target=android-17

Step 4)  Open .settings/org.eclipse.jdk.core.pref the file should look like that


eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

Step 4) Clean and rebuild the project






As an Amazon Associate I earn from qualifying purchases.

5b. Android: formatting numbers based on LOCALE

This example shows you how to format a number based on user's language and region setting (LOCALE)




    /**
     * This method updates the UI with LOCALE specific format
     * e.g. US 1,234.99
     * e.g. Europe 1 234,99
     * @param resultingValue - calculated value to be displayed
     */
   private void updateResult(double resultingValue) {
      NumberFormat nf = NumberFormat.getInstance();
      nf.setMaximumFractionDigits(2);
      nf.setMinimumFractionDigits(0);
      resultingValueTextView.setText(nf.format(resultingValue));
   }


As an Amazon Associate I earn from qualifying purchases.

Android Studio: Reveal in Finder

Very often you need to open the file or a directory in Finder (or Terminal), to do so you right-click on the file or directory and selected Reveal In Finder.







As an Amazon Associate I earn from qualifying purchases.

5a. Android Studio: create new Java CONSTANTS class

Sometimes is worth to extract a bunch of code to a separate class to keep the original short and sweet (readable and maintainable).




In our Activity class I had a lot of constants:

   private final static double CONVERSION_METERS_TO_YARDS = 1.093613298;
   private final static double CONVERSION_KILOMETERS_TO_MILES = 0.621371192;


One way to maintain them was to move them to a new Java class ConversionConstants






















  • Make sure you write the JavaDoc /** my description */ for each class you create
  • constants are public - available form any other class
  • constants are final - the value cannot be changed by the code
  • constants are static - indicate that the constant will belong to class and not the instance, you don't have to have an instance to get it e.g. ConversionConstants.METERS_TO_YARDS

package com.chicagoandroid.cit299.calc;
/**
* This class will contain hundreds of possible conversion constants.
*/
public class ConversionConstants {
    public final static double METERS_TO_YARDS = 1.093613298;
    public final static double KILOMETERS_TO_MILES = 0.621371192;
}


Now I can access these constants from any other class and use them in my calculations:





Note: I am not providing the source code on purpose because copy-and-paste is not a good learning experience.



As an Amazon Associate I earn from qualifying purchases.

Eclipse: starting from bash command line

I start Eclipse from Bash command line (in Terminal.app) to make sure it reads all Bash Enviroment settings.


function eclipse () {
nohup bash -ic /Eclipse_Luna_4_4/Eclipse.app/Contents/MacOS/eclipse &
echo "disown PID -- prevent eclipse from closing when you close Terminal"
}


As an Amazon Associate I earn from qualifying purchases.

4i. Android: 9patch

If you want to provide a reach UI you will be using images, it is not possible to create image for every device size, therefore they will be stretching. Android 9patch is a way to control what can stretch in the image to preserve quality of that image.

Examples of using 9patch:





Finding draw9patch tool 



In the browser search for square icon




  • top - stretch horizontally
  • left - stretch vertically
  • right - content area
  • bottom - content area





Actual look of the 9patch:



Copy your 9patch  pop_up_background_82x82.9.png to drawable folder:

conventer/src/main/res/drawable-mdpi/pop_up_background.9.png


    <TextView
            android:id="@+id/resultingValue"
            android:text="..."
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="60"
            android:background="@drawable/pop_up_background" />




As an Amazon Associate I earn from qualifying purchases.

4h. Android: Activity lifecycle methods

There are few concepts that you will have to get familiar with:

  • activity stack - LIFO (last in, first out )
  • active activity - running activity that is visible and interactive
  • paused activity - running activity that is visible, but obstructed
  • stopped activity - completely obstructed
  • inactivate activity - app has been killed by Android, or the user 





/**
* Activity starts but it is not visible yet, open necessary connections
*/
protected void onCreate(Bundle savedInstanceState) {
super.onStart();
// your code
}
/**
* Activity starts but it is not visible yet, open necessary connections
*/
protected void onStart() {
super.onStart();
// your code
}
/**
* activity was completely hidden by another Activity, or another app, but not killed
* check if you need refresh time-sensitive content (facebook wall update)
*/
protected void onRestart() {
super.onRestart();
// your code
}
/**
* Activity is now visible to the user, resume updating the views
*/
protected void onResume() {
super.onResume();
// your code
}


/** Activity is obstructed, stop updating the views */
protected void onPause() {
super.onPause();
// your code
}
/**
* Activity was obstructed, release resources, or it may get killed
*/
protected void onStop() {
super.onStop();
// your code
}
/**
* Activity is being killed by Android, close network and database connections
*/
protected void onDestroy() {
super.onDestroy();
// your code
}


There is a description available on from Google's Android Developers site:
http://developer.android.com/reference/android/app/Activity.html




It takes time and effort to create tutorials, please support my efforts with a couple-dollar donation, any amount will be greatly appreciated and highly motivating!



As an Amazon Associate I earn from qualifying purchases.

Android: language locale

Android allows us to write applications that are specific to languages and regions.


  • create locale specific layouts if language has different layout than default (i.e. Chinese)
  • create local specific res/values/strings.xml for each language you want to support
  • create local specific res/values/dimens.xml if language requires some minor length adjustments (e.g. German)






































Don't forget to provide translations for regional varieties of the language!

<resources>
    <string name="app_name">Converter Mate!</string>
    <string name="select_conversion">Select Conversion  Mate!:</string>
    <string name="enter_value">Enter Value  Mate!</string>
    <string name="action_settings">Settings  Mate!</string>
    <string name="resulting_value">Resulting Value Mate!:</string>






As an Amazon Associate I earn from qualifying purchases.

Android: switch case conditional

At some point, each application will have to perform some logic based on different cases.

  • extract your CONSTANTS
  • extract your logic into a separate method so it can be called from several places
  • use switch case instead of if else
  • use try catch statement when data types may vary





   private final static double CONVERSION_METERS_TO_YARDS = 1.093613298;
   private final static double CONVERSION_KILOMETERS_TO_MILES = 0.621371192;

   private void calculateResult() {
      Double valueEntered = 0.0;
      try {
         valueEntered = Double.valueOf(valueEnteredEditText.getText().toString());
         showToast("afterTextChanged " + valueEntered);
      }
      catch (NumberFormatException e) {
         resultingValueTextView.setText("");
         return;
      }

      switch (selectedConversion) {
      case 0:
         resultingValueTextView.setText("" + valueEntered * CONVERSION_METERS_TO_YARDS);
         break;
      case 1:
         resultingValueTextView.setText("" + valueEntered * CONVERSION_KILOMETERS_TO_MILES);
         break;
      }
   }


As an Amazon Associate I earn from qualifying purchases.

Android: LinearLayout


I like to work with combination of LinearLayout, especially when creating forms.


<LinearLayout 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"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <LinearLayout
        android:id="@+id/spinnerLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/select_conversion"
            android:layout_weight="40" />
        <Spinner
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/conversionSelectorSpinner"
            android:layout_weight="60" />
    </LinearLayout>
    <LinearLayout
        android:layout_marginTop="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:text="@string/enter_value"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="40" />
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="8"
            android:id="@+id/valueEntered"
            android:onClick="onClickEnterValue"
            android:text=""
            android:layout_gravity="center_vertical"
            android:layout_weight="60" />
    </LinearLayout>
    <LinearLayout
        android:layout_marginTop="30dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:text="@string/resulting_value"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="40" />
        <TextView
            android:id="@+id/resultingValue"
            android:text="..."
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="60" />
    </LinearLayout>
</LinearLayout>




As an Amazon Associate I earn from qualifying purchases.

Android: handling input fo TextEdit and updating TextView

Some of the simplest, but very useful apps, can contain forms that that you have to read and fill out. You can do most of that work with TextEdit (input) and TextView (output).

Step 1) Define your layout, name your widgets very well.


Step 2) Define class members for each of the fields that will be used multiple times

public class MainActivity extends ActionBarActivity {
   //during the life-span of the app we will access these fields many times
   private EditText valueEnteredEditText;
   private TextView resultingValueTextView;


Step 3) Find the right layout items by ID and inflate them.

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);


      valueEnteredEditText = (EditText) findViewById(R.id.valueEntered);
      resultingValueTextView = (TextView) findViewById(R.id.resultingValue);


       addListenerToValueEnteredEditText();
       createConversionSelectorSpinner();
   }



Step 4) Add a listener that will react to a value entered

   private void addListenerToValueEnteredEditText() {


      valueEnteredEditText.addTextChangedListener(new TextWatcher() {
         public void onTextChanged(CharSequence s, int start, int before, int count) {
            showToast("onTextChanged ");
         }
         public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            showToast("beforeTextChanged ");
         }
         public void afterTextChanged(Editable s) {
            calculateResult();
         }
      });
   }





As an Amazon Associate I earn from qualifying purchases.

Android Studio: switching between Project and Structure views

If you have a lot of methods in a given class you may want to see the Structure view.

Step 1) Select "monitor" icon in the bottom-left corner
Step 2) Select "Structure" view
Step 3) Open view settings "gear" icon
Step 4) Sort Alphabetically
Step 5) Autoscroll to Source - if you select any method on the left, the right source will show
Step 6) Autoscroll from Source - if you select in the source, the method on the left will be selected




As an Amazon Associate I earn from qualifying purchases.

Android: adding a Spinner (drop-down or pick-list widget)


You start by adding Spinner UI to your res/layout/activity_xyz.xml
Make sure to give it a meaningful ID, especially if you have multiple Spinner items.

        <Spinner
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/conversionSelectorSpinner" />


If your spinner will have a pre-defined list of items that will need to be translated to another language then you probably should use string-array in res/values/strings.xml

    <string-array name="conversionTypeArray">
        <item>meters to yards</item>
        <item>kilometers to miles</item>
    </string-array>


In your Activity class you have to add your Spinner in onCreate() method.

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
     
      //set up the conversion choices using a Spinner
      Spinner conversionSelectorSpinner = (Spinner) findViewById(R.id.conversionSelectorSpinner);
     
      // create adapter from the res/values/strings.xml/string-array
      // simple_spinner_item is a TextView
      ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.conversionTypeArray, android.R.layout.simple_spinner_item);
     
     // simple_spinner_dropdown_item is basically a single line TextView that serves as header of a Spinner
      adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
     
       // set array adapter to populate the spinner
      conversionSelectorSpinner.setAdapter(adapter);



Now if you build  the APK we will have a Spinner, but we will have to make it work for us.

We will need a variable that will hold our selection, we will make it a class member to be used in various methods.

public class MainActivity extends ActionBarActivity {
   private int selectedConversion = 0;


We will need a programmatic access to the string-array we defined, we will add that line inside our onCreate() method.


 final String conversionTypeArray[] = getResources().getStringArray(R.array.conversionTypeArray);

Finally, we will have to add a event listener to our Spinner.



      // add listener that will react when an item was selected
      conversionSelectorSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
         @Override
         public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
            // assign selected item to the class member to be used later
            selectedConversion = position;
            // if you change conversion type, it is natural that the result will be different
            calculateResult();
            // we would not have debug toasts in production version, for edu purposes only
            showToast("onItemSelected in position: " + position + " id: " + id + " selected name: " + conversionTypeArray[position]);
         }
         @Override
         public void onNothingSelected(AdapterView<?> parentView) {
            // onNothingSelected is a Callback method to be invoked when the selection disappears from this view.
            // The selection can disappear for instance when touch is activated or when the adapter becomes empty.
            showToast("onNothingSelected");
         }
      });












As an Amazon Associate I earn from qualifying purchases.

Android apps now can run on every OS in a Chrome browser

Android apps can now run on every OS in a Chrome browser, or at least this can be shown to be possible. Tested on OS X, Windows and Ubuntu.

"ARChon runtime lets you run unlimited number of Android APKs created with chromeos-apk on Chrome OS and across any desktop platform that supports Chrome."

VIDEO DEMO

On personal note, the author of the hack, Mr. vladikoff001, is our developer hero of the mega proportions. Congratulations.


Yes, this is still a buggy hack, but it definitely opens doors for bigger and better future for this Android developer.


As an Amazon Associate I earn from qualifying purchases.

Android Studio: Eclipse shortcuts and formatter

If you are switching between Eclipse (at work) and Android Studio (home, teaching) then you will run into a problem of remembering the keyboard shortcuts and formatting the code consistently.



In Android Studio you have an option to add "Eclipse Code Formatter" and specify the xml formatter you exported from Eclipse (for your whole team).



You also have an option of using keymaps (keyboard shortcuts) from Mac Eclipse.







As an Amazon Associate I earn from qualifying purchases.

GIT: submodules

In this tutorial you will see examples of how to work with modules in GTI. It is a good practice for multiple projects to re-use common libraries of code, for example model library, APIs, utility classes, etc.

List Submodules



$ git submodule



Add submodule to an existing project

Before I start, I like to check what is the repository URL of the PARENT project, your submodules will likely have similar URL:

$ git config --get remote.origin.url

ssh://git@xyz.repositoryhosting.com/xyz/parent_project_name.git


In your (parent) project clone another project as submodule..

git submodule add --force ssh://git@xyz.repositoryhosting.com/xyz/submodule_name.git module/submodule_name
Cloning into 'module/submodule_name'...
remote: Counting objects: 47, done.
remote: Compressing objects: 100% (30/30), done.
remote: Total 47 (delta 6), reused 47 (delta 6)
Receiving objects: 100% (47/47), 1.85 MiB | 715.00 KiB/s, done.
Resolving deltas: 100% (6/6), done.
Checking connectivity... done.


If you checked out a base project and your submodule is empty, you need to initialize your submodules. The command below will bring the remote code to your local folders recursively for each submodule you have.

$ git submodule update -f --init --recursive


If the code you want in the submodule is in different branch then you have to checkout that branch

git submodule foreach git checkout develop


Finally you can do your normal PULL, or FETCH and REBASE 

$ git submodule foreach git pull


Remove submodule

List currently registered submodules


$ git submodule

$ git submodule deinit -f module/myOldModule
$ git rm -rf module/myOldModule
$ rm -rf 'module/myOldModule'








As an Amazon Associate I earn from qualifying purchases.

Eclipse: show hidden files

It is common that you need to edit hidden .* files, for example if you work with GIT you may want to edit .gitignore file.

In Eclipse > Package Explorer > select drop-down arrow "View Menu" > Filters ...



Then unselect ".* resources" and the .gitignore .gitmodules, etc. should be showing. 





As an Amazon Associate I earn from qualifying purchases.

Eclipse not reading ANT env variables

Sometimes you have ANT build.xml that works perfectly from command line but does not execute in Eclipse:

BUILD FAILED
Execute failed: java.io.IOException: Cannot run program "${env.THRIFT_TOOL}": error=2, No such file or directory

When you inspect your build.xml you should have (true for any executable):

<property environment="env"/><property name="thrift.compiler" value="${env.THRIFT_TOOL}"/>


If you inspect your env variable setting, on OSX ~/.profile you should have:

# Thrift tool  - updated: Sept 16, 2014
export THRIFT_TOOL=/usr/local/bin/thrift
export PATH=${THRIFT_TOOL}:${PATH}


Yet Eclipse is not running Ant correctly!

Starting Eclipse from COMMAND LINE fixes the issue:

$ bash -ic /Applications/../Eclipse.app/Contents/MacOS/eclipse 



As an Amazon Associate I earn from qualifying purchases.

Thrift: building from source

I was required to build Thrift from sources (to adjust it to generate Parcelable Android model classes)

uki@ thrift $ .git clone https://github.com/apache/thrift.git
uki@ thrift $ cd thrift
uki@ thrift $ .git checkout 0.9.1
uki@ thrift $ ./cleanup.sh
uki@ thrift $ ./bootstrap.sh
uki@ thrift $ ./configure
uki@ thrift $ sudo make
uki@ thrift $ sudo make install

I get an error on my Mac:

./src/thrift/cxxfunctional.h:93:18: error: no member named 'bind' in namespace 'std'; did you mean 'find'?



Attempted solution 1:

I found a post on http://blog.evernote.com/
change file:
thrift/compiler/cpp/src/thriftl.ll
line 51 to #include "thrifty.hh"

src/thriftl.ll:51:10: fatal error: 'thrifty.hh' file not found
#include "thrifty.hh"
THIS SOLUTION CLEARLY DOES NOT WORK

Attempted solution 2:

As I was reading up I found that the version of my C++ might be wrong:

"libc++, the default C++ standard library in 10.9, doesn't include the experimental TR1 headers - just their standardized C++11 versions"

Checking the existing version of C++ on Mac:

 $ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)



Installed newest C++ from brew

$ brew install gcc49


in my ~/.profile I added these 2 lines:

# C++ HOME - updated: Sept 16, 2014
export CPP_HOME=/usr/local/Cellar/gcc/4.9.1/bin/
export PATH=${PATH}:${CPP_HOME}
alias g++="/usr/local/Cellar/gcc/4.9.1/bin/cpp-4.9"
alias gcc="/usr/local/Cellar/gcc/4.9.1/bin/cpp-4.9"


now in the Terminal I can verify this:

uki@ thrift $ gcc --version
cpp-4.9 (Homebrew gcc 4.9.1) 4.9.1



The exercise is not complete yet, so I was not able to verify if this is a fix.




As an Amazon Associate I earn from qualifying purchases.

Eclipse: Thrift plugin

If you are editing Thrift files you will need this plugin.




In Eclipse open Help > Install New Software ... > Work With: enter this URL, click Add..

http://thrift4eclipse.sourceforge.net/updatesite/















and follow the installation steps.


As an Amazon Associate I earn from qualifying purchases.

GIT: installation on Mac

General GIT installation page:

http://git-scm.com/book/en/v2/Getting-Started-Installing-Git

 

Mac Specific:

Install Brew - Mac package installer

This "brew" tool will be useful for many other things...

$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Check existing version of git

$ git --version
git version 1.8.5.2 (Apple Git-48)

We can see that I had not the newest GIT (1.8.5), but I want to latest and greatest...

Install the latest and greatest git version

$ brew install git
/usr/local/Cellar/git/1.9.0: 1322 files, 30M

At this point the new GIT is installed, however the old GIT is still being used..

$ git --version
git version 1.8.5.2 (Apple Git-48)

Checking the NEW GIT at different location...

uki@ bin $ /usr/local/Cellar/git/1.9.0/bin/git --version
git version 1.9.0


Edit the PATH so he new GIT tool is found first

Open Applications > Utilities > Terminal.app
We will be editing .profile file located in your home folder (~), this file may not be showing in your Finder, so you might need to do it in vi editor.

edit ~/.profile
export GIT_TOOL=/usr/local/Cellar/git/1.9.0/
export PATH=${GIT_TOOL}/bin:${PATH}
$ git --version
git version 1.9.0




As an Amazon Associate I earn from qualifying purchases.

CyberFit - Founder's story

Uki D. Lucas is a technology entrepreneur, public speaker, book author and UX expert specializing in mobile application development. He has been working with technology start-up companies since 1999 job at RollingStone magazine. Plus to all the tech experience Uki is an active sport guy, and after some gym workouts with a trainer the idea of the fitness app CyberFit was obvious.

I have talked to a gym buff who said,
- I know my exercises, why do I need a new app?
    - How do you track your exercises?
- Spreadsheet.
    - This is exactly why we created this app!
              ~ Uki D. Lucas, CyberFit app.
File 32668
Over the past 6 months, his mobile development company CyberWalkAbout.com has worked to develop the CyberFit  application (http://bit.ly/CyberFit),a new revolutionary fitness tracking app. His creation has been already released to the App Store and proven to be very unique, as we are working with the best trainers with various approaches, so user can find just the right "fit" for him/her. Each trainer should be able to create a program, post their videos, keep track of the clients' progress, make money. Training buddies should be able to share their progress and schedules. It's like a new fitness social network!

CyberFit is a video-based set of programs that are customized to user's goals, in addition the application includes all expected features like:

- complete set of body measurements
- front, side and back over time photo comparison
- schedule of workout sessions with notifications
- exercise history with progress indication
- heart rate monitor support
File 40457 File 40458
File 40459 File 40460
To move this app to the next level Uki is currently looking for additional funding that will cover the marketing efforts and other app improvements.


As an Amazon Associate I earn from qualifying purchases.

Android Class - Table of Contents

Note: content of this page is being migrated to the right margin.

Session 1

GIT: cheat sheet

http://ukitech.blogspot.com/2014/06/git-cheat-sheet.html

UNIX commands review


Session 2 - review

Android SDK: set-up in IDE

http://ukitech.blogspot.com/2014/09/android-sdk-set-up-in-ide.html

 Android Studio - creating Android Virtual Device AVD

http://ukitech.blogspot.com/2014/09/android-studio-creating-android-virtual.html

Android Studio - changing the app name

http://ukitech.blogspot.com/2014/09/android-studio-changing-app-name.html

Android Studio - creating new Module (app)

Android Studio - Failure [INSTALL_FAILED_OLDER_SDK]

http://ukitech.blogspot.com/2014/09/android-studio-failure.html

Android Studio - Error:compileSdkVersion android-L requires compiling with JDK 7

http://ukitech.blogspot.com/2014/09/android-studio-errorcompilesdkversion.html


Session 3

Android Tutorial - creating calc converter app




As an Amazon Associate I earn from qualifying purchases.

Android Tutorial - creating GUI - converter app

Step 1: Open src > main > res > activity-main.xml


  • Use "Design" view to bring desired Views
  • Use "Text" view to edit XML

Read about Spinner:



Read about Toast:



As an Amazon Associate I earn from qualifying purchases.

Android: creating new module - calc converter app

Objective

In this short tutorial you will create a new Android Studio project.

Step 1. In Android Studio create a new Module





  • Android Application
  • Application Name: Unit Conventer
  • Module Name: unit_conventer
  • edu.clcillinois.cit299.calc
  • Min. required SDK: API 10
  • Target SDK:  API 19 (Kitkat)
  • Compile with: APK 19  (Kitkat)
  • Java: 1.6
  • Theme: Holo Light


Step 2. Search on Google images and/or create an icon for the app



search terms: calculator converter icon


Step 3: Chose the selected app icon




Step 4: Create "Blank Activity" with ActionBar


Step 5: Create "MainActivity" and "activity_main" layout





Step 6: Deploy the app to a device

If you get an error

Failure [INSTALL_FAILED_OLDER_SDK]
see fix here: 










As an Amazon Associate I earn from qualifying purchases.

Android Studio - creating new app icon

You can set a new app icon at any time, but if you have the asset already created the best time is to set it when you create the new app (new Module).




As an Amazon Associate I earn from qualifying purchases.

Android Studio - Error:compileSdkVersion android-L requires compiling with JDK 7



Error:compileSdkVersion android-L requires compiling with JDK 7
Open SDK Settings

Problem Description:

The default java 1.6 on Mac is located at
/Library/Java/Home
You need Java 1.7 to compile android-L

Solution:

Download the newest Java from Oracle site.
$ java -version

java version "1.8.0_20-ea"

Set location of Java JDK to newest Java you have installed


/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home


As an Amazon Associate I earn from qualifying purchases.

Android Studio - Failure [INSTALL_FAILED_OLDER_SDK]

Problem Description:


When trying to install a newly created app the error appears in Run window and the app fails to install.

Failure [INSTALL_FAILED_OLDER_SDK]

Additional info:


This bug occurs when styles.xml contain:

<style name="AppTheme" parent="Theme.AppCompat.Light">

Fix:


Open build.gradle

Change from:


android {
    compileSdkVersion 'android-L'
    buildToolsVersion "20.0.0"

Change to:


    compileSdkVersion 20
    buildToolsVersion "20.0.0"

Re-run the project and it will work OK.


As an Amazon Associate I earn from qualifying purchases.

Android Studio - creating new Module (app)

Android Studio Project e.g. CIT_299 can contain multiple Modules, or apps.

Create a new Module - App

  • Application name 
  • module name




As an Amazon Associate I earn from qualifying purchases.

Android Studio: changing the app name

The app name is normally saved in string name="app_name"

To change the app name you should navigate:


CIT_299/week03/src/main/res/values/strings.xml

Where: 
  • CIT_299 - is your project name
  • week03 - is your app folder
  • main/res - is how Android Studio places resources folder
  • values - is you DEFAULT LANGUAGE values folder




Make sure you change any other language you want to support e.g. values-es for Spanish


Next, you should rename the DIRECTORY and MODULE name:


Finally, make sure settings.gradle include the newly named module

include: ':converter', ':week2'






As an Amazon Associate I earn from qualifying purchases.

Android Studio: creating Android Virtual Device AVD

Why do we need AVD?

To be honest most of my Android testing happens on the real devices, however sometimes you need to test on a device with different screen size, different resolution (dpi) or limited memory or network bandwidth.

Example AVD Settings


One of my favorite emulator settings is the 10.1 inch tablet with mdpi resolution, it it relatively light weight and works pretty well.  



Starting AVD with the correct scale for your screen size.

It is essential that when you start the emulator of e.g. 10.1 inch tablet, it is actually 10.1 inch (diagonally) on your screen - you should measure it with a ruler. If the screen is too small you will design all the elements too big, if the emulator is too big, the UI will be too small on the real device.





As an Amazon Associate I earn from qualifying purchases.

Android SDK: set-up in IDE

It is a good practice to maintain a Stand Alone version of Android SDK (also called ADT for Eclipse) that is residing on your file system independently of your IDE (Eclipse, or Android Studio).

Getting Android SDK


Open:
http://developer.android.com/sdk/index.html


Download:
http://developer.android.com/sdk/index.html#download

Once you download the SDK (ADT) put it in a convenient location, I keep it on my Mac here:


/Applications/Android/SDK/android-sdk-macosx

The reason for this location is that it is being backed up with all Apps and moved to another Mac when upgrading. We aware that after you download all kinds of versions this folder will grow, mine is about 13 Gb most of that are system-images -- and I don't even have all previous versions of Android downloaded. You will need every version you are building for, so for example I am currently using API 17 and 19.

Setting SDK in Eclipse (Luna):




Setting Android SDK in Android Studio









As an Amazon Associate I earn from qualifying purchases.

My favorite quotations..


“A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.”  by Robert A. Heinlein

"We are but habits and memories we chose to carry along." ~ Uki D. Lucas


Popular Recent Articles