Eclipse convert to lower or upper case

Let say you have XML and you want to change text case:


<color name="fault_list_history_item_even">#CcCcCc</color>

command+shift+x  -- UPPER CASE

  <color name="fault_list_history_item_even">#CCCCCC</color>

command+shift+y -- LOWER CASE

<color name="fault_list_history_item_even">#cccccc</color>



GIT: working with local branches

LIST ALL LOCAL BRANCHES

@ my_project $ git branch
  clock
* copyright
  copyrights
  develop
  master




CREATE and SWITCH TO NEW branch DND

@ my_project $ git checkout -b DND
Switched to a new branch 'DND'





DELETE LOCAL BRANCH called DND

@ my_project $ git branch -D DND
Deleted branch DND (was 9a59234).

Android: close keyboard

When I am entering text into EditText and then hitting Save Button I want the keyboard to close.


 closeSoftKeyboard(myEditText);
...
}
private void closeSoftKeyboard(View view) {
   InputMethodManager imm = (InputMethodManager)       getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
   imm.hideSoftInputFromWindow(view.getWindowToken(), 0);

}


getActivity() is needed when you use it in Fragment.

Eclipse: increase Java line width wrapping

Java standard line width wrapping is set for 80 which is archaic and unusable with today's screen sizes. Here are instructions how to change it.

1) Go to Eclipse -> Preferences..., search for "Formatter" -> Edit...
2) rename the Active Profile name to something meaningful to you (e.g. company name).
3) open "Line Wrapping" tab
4) Change "maximum line width: from 80 to something like 140 or 160 (for 15 inch macBookPro)
5) Apply, OK
6) format your code (shift+command+F)
7) Export Formatter for other team members.



git: copy file to subfolders


I had a need to copy a file "commit-msg" to git folders called "hooks" while preserving permissions. Since there were a lot of these folders this command helped a lot.

find . -type d -name hooks -exec cp -p commit-msg {} \;

Explanation:

find -type -d :: Unix find command for directory
-name hooks :: name of the folders
cp :: Unix copy command
-p :: preserving permissions
{} :: whatever are the results
\; :: end execution

WARNING: UNPROTECTED PRIVATE KEY FILE!

If you are getting this kind of error the the permissions on your files are modified incorrectly:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0744 for '/home/your_name/.ssh/id_rsa' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: /home/your_name/.ssh/id_rsa





@ .ssh $ ls -alt
..
-rw-r--r--@  1 your_name  staff   222 Nov 26  2012 id_rsa.pub
-rw-r--r--   1 your_name  staff   887 Nov 20  2012 id_rsa
...
@ .ssh $ 

To fix this problem change permissions:

@ .ssh $ chmod 600 id_rsa
@ .ssh $ chmod 600 id_rsa.pub
@ .ssh $ ls -alt
total 80
...
-rw-------@  1 uki  staff   222 Nov 26  2012 id_rsa.pub
-rw-------   1 uki  staff   887 Nov 20  2012 id_rsa_cnh
...
@ .ssh $ 


Android: restarting app (APK) via adb

Often when you work with APK you need to restart it, it is much faster to create a Bash script for that:

echo '*** restart XYZ APK***'
echo 'Continue?'
read input
adb shell am force-stop com.xyz.package;
adb shell am start -n com.xyz.package/.SomeMainActivity

Android: sending commands from computer

I found that often I have to send HOME, or BACK commands to my Android device.

KEYCODE_HOME
adb shell input keyevent 3

KEYCODE_BACK (you might have to execute it few times to get to HOME)
adb shell input keyevent 4

KEYCODE_CALL - opens the Call log
adb shell input keyevent 5

KEYCODE_ENDCALL - if not calling, same as pressing power button (you get choices: Power off, Airplane mode, Silent mode)
adb shell input keyevent 6


KEYCODE_VOLUME_UP - more noise
adb shell input keyevent 24

KEYCODE_POWER - same as pressing power button (you get choices: Power off, Airplane mode, Silent mode)
adb shell input keyevent 26


KEYCODE_CAMERA
adb shell input keyevent 27

KEYCODE_CLEAR
adb shell input keyevent 28


Full list of codes:

0  -  KEYCODE_UNKNOWN
1  -  KEYCODE_MENU
2  -  KEYCODE_SOFT_RIGHT
3  -  KEYCODE_HOME
4  -  KEYCODE_BACK
5  -  KEYCODE_CALL
6  -  KEYCODE_ENDCALL
7  -  KEYCODE_0
8  -  KEYCODE_1
9  -  KEYCODE_2
10  -  KEYCODE_3
11  -  KEYCODE_4
12  -  KEYCODE_5
13  -  KEYCODE_6
14  -  KEYCODE_7
15  -  KEYCODE_8
16  -  KEYCODE_9
17  -  KEYCODE_STAR
18  -  KEYCODE_POUND
19  -  KEYCODE_DPAD_UP
20  -  KEYCODE_DPAD_DOWN
21  -  KEYCODE_DPAD_LEFT
22  -  KEYCODE_DPAD_RIGHT
23  -  KEYCODE_DPAD_CENTER
24  -  KEYCODE_VOLUME_UP
25  -  KEYCODE_VOLUME_DOWN
26  -  KEYCODE_POWER
27  -  KEYCODE_CAMERA
28  -  KEYCODE_CLEAR
29  -  KEYCODE_A
30  -  KEYCODE_B
31  -  KEYCODE_C
32  -  KEYCODE_D
33  -  KEYCODE_E
34  -  KEYCODE_F
35  -  KEYCODE_G
36  -  KEYCODE_H
37  -  KEYCODE_I
38  -  KEYCODE_J
39  -  KEYCODE_K
40  -  KEYCODE_L
41  -  KEYCODE_M
42  -  KEYCODE_N
43  -  KEYCODE_O
44  -  KEYCODE_P
45  -  KEYCODE_Q
46  -  KEYCODE_R
47  -  KEYCODE_S
48  -  KEYCODE_T
49  -  KEYCODE_U
50  -  KEYCODE_V
51  -  KEYCODE_W
52  -  KEYCODE_X
53  -  KEYCODE_Y
54  -  KEYCODE_Z
55  -  KEYCODE_COMMA
56  -  KEYCODE_PERIOD
57  -  KEYCODE_ALT_LEFT
58  -  KEYCODE_ALT_RIGHT
59  -  KEYCODE_SHIFT_LEFT
60  -  KEYCODE_SHIFT_RIGHT
61  -  KEYCODE_TAB
62  -  KEYCODE_SPACE
63  -  KEYCODE_SYM
64  -  KEYCODE_EXPLORER
65  -  KEYCODE_ENVELOPE
66  -  KEYCODE_ENTER
67  -  KEYCODE_DEL
68  -  KEYCODE_GRAVE
69  -  KEYCODE_MINUS
70  -  KEYCODE_EQUALS
71  -  KEYCODE_LEFT_BRACKET
72  -  KEYCODE_RIGHT_BRACKET
73  -  KEYCODE_BACKSLASH
74  -  KEYCODE_SEMICOLON
75  -  KEYCODE_APOSTROPHE
76  -  KEYCODE_SLASH
77  -  KEYCODE_AT
78  -  KEYCODE_NUM
79  -  KEYCODE_HEADSETHOOK
80  -  KEYCODE_FOCUS
81  -  KEYCODE_PLUS
82  -  KEYCODE_MENU
83  -  KEYCODE_NOTIFICATION
84  -  KEYCODE_SEARCH
85  -  TAG_LAST_KEYCODE

Bash: syntax error: unexpected end of file

When you get:

syntax error: unexpected end of file

You should make sure that you don't have problems with end of line characters, however the ERROR in logic of your code (bad command) wil cause that as well.

Sometimes it is easier to comment out all lines with "# your code"and turn on some little-by-little.

Unix: dos2unix on Mac

Removing Windows line ends on Mac:

In Terminal.app

$ cat file1.txt | col -b > file2.txt

Warning: Do not run this with destination of the same file, or it will become empty.

Android: re-installing a bunch of apps with one script

I have a bunch (over a dozen) of APKs that go together on the device as a single solution, to remove them and reinstall all of them would be a time consuming effort, so I have scripts for that.

Do not believe "-r" option in "adb install -r", it does not always re-install the app.

I have a single script with bunch of uninstalls...

adb uninstall com.xyz.x1
$ adb uninstall com.xyz.x2
...
$ cd your_apks
# install all APKs in this folder
$ for i in *.apk; do adb install -r $i; done

UNIX: -bash: xyz.bash: cannot execute binary file

You create your script file but it does not want to execute...

Terminal.app error:

 -bash: xyz.bash: cannot execute binary file


Step 1:

Make sure it has execute permissions

@ scripts $ chmod 777 xyz.bash 

Step 2:

Make sure scrip does not have ERROR inside, special characters that prevent execution.

Starting with Go language by Google

http://golang.org/

1. Download and Install the Go - no configuration needed
2. Add variable:
~@ ~ $ edit ~/.profile


# Go
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin

3. Close and open Terminal

@ ~ $ which go
/usr/local/go/bin/go

4. create a sample program

@ workspaces $ mkdir go_programs
@ workspaces $ touch hello.go
@ workspaces $ edit hello.go 
@ workspaces $

Editor:

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}


Edit PATH again:

# Go
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=~/Documents/workspaces/go_programs
export PATH=$PATH:$GOPATH


5. Run your first program
@ workspaces $  go run hello.go
hello, world

6. Take a tour
http://tour.golang.org/#1

Terminal: set command line prompt and PATH variables in Bash ~/.profile

As a developer you will find yourself using Command Line (Terminal.app) every day, all the time, so it is worthwhile to set it up to behave just right for you...

Open Application > Utilities > Terminal.app (drag it to your toolbar for quick access)

My shell looks like that, it tells me a lot of info just as verification...

Last login: Mon Sep 15 11:56:15 on ttys000
edit ~/.profile
java version "1.8.0_20-ea"
Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b05)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b05, mixed mode)
git version 1.9.0
/Applications/Android/SDK/android-sdk-macosx/platform-tools/adb
uki@ CNH_PROD $ vi ~/.profile


We can use vi editor, but on daily basis I just type "edit ~/.profile"

# ANDROID - updated: Sept 15, 2014
export ANDROID_HOME=/Applications/Android/SDK/android-sdk-macosx
export PATH=${PATH}:${ANDROID_HOME}/build-tools/19.0.3
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
export PATH=${PATH}:${ANDROID_HOME}/tools

echo "edit ~/.profile"
# Adjust prompt.
# \d – Current date
# \t – Current time
# \h – Host name
# \# – Command number
# \u – User name
# \W – Current working directory (ie: Desktop/)
# \w – Current working directory, full path (ie: /Users/Admin/Desktop)
export PS1="\u@ \W $ "
java -version
git version
which adb


To EDIT hit "i" for insert
To Save and Quit you type ESC + :wq + Enter
I have MUCH MORE configurations in there, but it is specific to what you have on your computer.

Getting Info About APK

Often you have apk that you need (e.g. package, version) info for, but you have no documentation about it. This little command gives you a lot of info.

$ aapt dump badging  someapp.apk
package: name='com.someapp.xyz' versionCode='1' versionName='1.1'
sdkVersion:'15'
targetSdkVersion:'17'
application-label:'SomeApp'
application: label='SomeApp' icon=''
application-debuggable
uses-feature:'android.hardware.touchscreen'
uses-implied-feature:'android.hardware.touchscreen','assumed you require a touch screen unless explicitly made optional'
supports-screens: 'small' 'normal' 'large' 'xlarge'
supports-any-density: 'true'
locales: '--_--'
densities: '160' '240' '320'
uki:~ uki$

Android: updating SDK from command line

You may want to create a script "Update Android SDK.bash" that quickly gets you up to speed without starting IDE (e.g. Eclipse) UI.

echo 'Android SDK home ' $ANDROID_HOME
$ANDROID_HOME/tools/android update sdk --no-ui --all --force 



Notice that it will ask you several times to click letter 'y'
Do you accept the license 'android-sdk-license-bcbbd656' [y/n]: y




Installing Archives:
  Preparing to install archives
  Downloading Android SDK Tools, revision 23.0.2
     (15%, 525 KiB/s, 2 minutes left))







Creating Google API key for Map v2

The key will be needed in AndroidManifest.xml like this... 

<meta-data
          android:name="com.google.android.maps.v2.API_KEY"

          android:value="AIz...jshdkfjhdsjkhfkdjsh..bMI"/>

To get the key go to:

https://code.google.com/apis/console/

1) create a NEW app (drop-down on the left Create...)
2) Select "Services" and turn on Maps...

3) API Access "Create new Android Key.." button

4) Terminal:
$ cd .android/
uki$ keytool -list -v -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android 
Alias name: androiddebugkey
Creation date: Nov 23, 2011
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=Android Debug, O=Android, C=US
Issuer: CN=Android Debug, O=Android, C=US
Serial number: 4ecdba20
Valid from: Wed Nov 23 21:29:36 CST 2011 until: Fri Nov 15 21:29:36 CST 2041
Certificate fingerprints:
MD5:  7E:FA:01...fkdjsflkjdlksjflkdsjlfjdsljfljlkdsf....:49:61:36
SHA1: D0:5...sdjkflkdsjflkjsdklfjdsljkdsl....F:A1:43
Signature algorithm name: SHA1withRSA
Version: 3
uki:.android uki$ 


5) Enter the SHA1 key, SEMICOLON; and PACKAGE NAME of your app



6) copy the successfully generated KEY to AndroidManifest.xml

Yay!






Apache Server on Mac OS 10.8

The Apache server is available on Mac by deploying your html pages to:

/Library/WebServer/Documents/

uki:Documents uki$ ls -alt /Library/WebServer/Documents/
total 80
...
-rw-r--r--  1 root  wheel   3726 Aug 24  2012 PoweredByMacOSX.gif
-rw-r--r--  1 root  wheel  31958 Aug 24  2012 PoweredByMacOSXLarge.gif
uki:Documents uki$

You start the Apache server by:
$ sudo apachectl start


Re-deploying your code:
remove old:
$ sudo rm -r /Library/WebServer/Documents/my_project
Make directory:
$ sudo mkdir /Library/WebServer/Documents/my_project
copy new code in:
$ sudo cp -r /Users/uki/Documents/workspaces/.../my_project/* /Library/WebServer/Documents/my_project

you can view your local server at:
http://localhost/

Setting JAVA_HOME variable on Mac

$ edit ~/.profile

add line

export JAVA_HOME=`/usr/libexec/java_home -v 1.7`

SAVE

re-open Terminal

$ echo $JAVA_HOME
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

$

Please note that the most current version (1.6) is loading when 1.7 is missing.

Updating Android JellyBean 4.2

Updating Android JellyBean 4.2 using ClockworkMod CWM & cyanogenmod for Android Developers.

If you are a Mac user you might be frustrated that there is no ODIN3 (Window software).
Actually, it is very easy with adb tool that every Android developer uses.

I am starting with stock Samsung Galaxy Tab 10.1 Android 3.0.1 (from Google I/O).




STEP 1)

Get cyanogenmod for your SPECIFIC device, get most stable version there is:

http://wiki.cyanogenmod.org/w/Devices#vendor=;




Examples:
Galaxy Tab 10.1 Wi-Fi only model
http://wiki.cyanogenmod.org/w/P4wifi_Info
I got cm-10.1-20130522-NIGHTLY-p4wifi.zip

Samsung Galaxy Tab 7 T-Mobile:
http://get.cm/?device=p1
http://download.cyanogenmod.org/?type=stable&device=p1
Stable cm-9.1.0-p1.zip

Motorola Droid2
http://download.cyanogenmod.org/?type=stable&device=droid2
cm-7.2.0-droid2.zip 

STEP 2)

Get Google Apps for your version of above
- cm-10 == Android 4.2.2
- cm-9 == ICS
- cm-7 == Gingerbread

you can easily find by searching "gapps-jb-2013"
http://rapidshare.com/files/3580601868/gapps-jb-20130301-signed.zip



STEP 3)
Get ClockworkMod CWM recovery.img

http://www.clockworkmod.com/rommanager


EXAMPLES:
Samsung Galaxy Tab (T-Mobile)


STEP 4) For Samsung: Inspect if there is no update in Kies (USB Debugging OFF), you can use thier for file transfer, too



STEP 5) Transfer there 2 ZIP files to /sdcard/  (USB Debugging ON)
- gApps
- cm-
Example:
uki:platform-tools uki$ adb push ~/Documents/Android/Samsung_Galaxy_Tab_7_TMobile/cm-9.1.0-p1.zip /sdcard/
3038 KB/s (144260310 bytes in 46.360s)
uki:platform-tools uki$ adb push ~/Documents/Android/Samsung_Galaxy_Tab_7_TMobile/gapps-ics-20120317-signed.zip /sdcard/
3263 KB/s (54485532 bytes in 16.304s)
uki:platform-tools uki$


I am showing 3 zip files because I tried older gApps previously.



STEP 6)
Turn OFF tablet by holding POWER button

STEP )
START device in fast boot mode (USB icon):
- hold VOLUME-DOWN (closer to power button) and press POWER button until device boots,
- select Fastboot, NOT download by pressing volume-down, make selection by pressing VOLUME-UP

STEP )
See if you can see your device
uki:platform-tools uki$ fastboot devices 
288420043805517 fastboot

If you see similar (number) line as above, you are good to proceed.

STEP )
Install ClockworkMod CWM tool

uki:platform-tools uki$ fastboot -u -S 0 flash recovery /Users/uki/Downloads/recovery-clockwork-6.0.3.1-p4wifi.img 
sending 'recovery' (4844 KB)...
OKAY [  0.341s]
writing 'recovery'...
OKAY [  0.605s]
finished. total time: 0.946s
uki:platform-tools uki$


STEP ) 
uki:platform-tools uki$ fastboot reboot
rebooting...

finished. total time: 0.000s

The Tablet should start and be healthy.

STEP )
uki:platform-tools uki$ adb reboot recovery  

The Tablet should start with ClockworkMod Recovery menu. If is does not start it same as bafore (POWER + VOLUME DOWN) and select recovery (icon with box expanding)



STEP )
select  - backup and restore (move with Volume UP, select with pressing Power button)
select  - backup (will take a while, but it is VERY IMPORTANT)
...
Backup complete!
*** Go Back ***

STEP )
wipe data/factory reset

*** Yes...

STEP )
select advanced
select - wipe Dalvik cache

*** Yes
*** Go Back ***

STEP)
select install zip from sdcard
choose..   cm-10.1-2013......-p4wifi.zip from sdcard
*** Yes...


STEP )
install gapps-jb-2013.....zip from sdcard

STEP )
restart, press POWER button for 10 seconds
- unplug,

If it fails recover backup (should not happen)

STEP)
IMPORTANT!!! To enable "USB Debugging" and other {} Developer options:
Settings -> About tablet -> CLICK "Build number" line 6 times!!!!!!

I guess the last one is for the code gurus that spent 6 years in the high mountains writing this, one click per year. :)


STEP )
Update Android SKD Manager to versions 16 & 17


SUCCESS!


KNOWN BUG:

The keyboard closes after first character typed, which makes impossible to use the keyboard. 

To fix it go to: 
settings -> language & input  -> click on settings icon next to "Android Keyboard (AOSP)" -> under TEXT CORRECTION
  • set 'Auto-correction' to 'Off' 
  • set 'Show correction options' to 'Always hide'.
The SWYPE will still work, but it will not show auto-correction words on top, it is a minor setback. When I don't get a correct word in Swype mode, I have to type it character-by-character.



Default Google Account

I have a couple of Google accounts:
- my name @google.com
- my company email which is also done via Google

To change DEFAULT google account I had to sign OUT from all and sign in FIRST with the one I want as default.

For some Google entities I had to do it in reverse as my new email did not work with them.

Animation of 3D mesh in Unity3D


  1. importing the mesh with animation from Maja to Unity3D
  2. setting the position of the mesh
  3. testing the animation and adjusting 

Recommended videos:

Getting Google YouTube API key

You should follow steps in here:
https://developers.google.com/youtube/android/player/register

with small exception since the command returns error:

$ keytool -list -v my-release-key.keystore
keytool error: java.lang.RuntimeException: Usage error, /Users/uki/Documents/Dropbox/Android_Keychains/my-release-key.keystore is not a legal command
java.lang.RuntimeException: Usage error, /Users/uki/Documents/Dropbox/Android_Keychains/my-release-key.keystore is not a legal command
    at sun.security.tools.KeyTool.parseArgs(KeyTool.java:375)
    at sun.security.tools.KeyTool.run(KeyTool.java:171)
    at sun.security.tools.KeyTool.main(KeyTool.java:166)

instead use the following:

$ keytool -list -v -keystore "my-release-key.keystore"
Enter keystore password:  


  • Make sure you use option -v to get both SHA1 and MP5
  • Make sure you quote the file path to your keystore file.