All posts by jb108

Samsung Note and Android 4 upgrade worth it?

Finally Android 4 Ice Cream Sandwich (ICS) is available for the AT&T version of the Samsung Galaxy Note i717 and Galaxy S II. Is it worth the upgrade? I was hesitant to run the upgrade. What if it didn’t work? What if it lost my stuff?

I followed the instructions at: AT&T Cell Phones: How do I update my Samsung Galaxy Note to Android 4.0 Ice Cream Sandwich? Essentially you have to download the Kies application to your PC or Mac and connect your phone to the PC and follow the process. Of course, you should back up your data using the Kies backup system.

My first download of Kies was damaged. So, I downloaded it at a different time period. Then the first use of the backup was extremely slow. I cancelled it. The next day the backup attempt was extremely fast. Hmmm. The Kies app has a lot of critics on the web. Oh well, its free.

But, then you have to update the Kies app on the PC/Mac. Then when you restart Kies, connect the Note to the PC with USB cable (wifi works for upgrade?), you can select the update option for the phone. Of course, this takes long if you watch it. On Windows 7, you have to stick around to respond to the security prompts. Eventually, after very confusing messages on the Kies, your phone will do its thing and be ready.

Of course, some things will change and certain settings will be gone. The above link gives you the list of what changes, for example:
“Application Menu: The application menu sorting, folders and home keys will be reset. Downloaded applications will be preserved.” Fortunately, ICS makes setting the screens so much easier.

Why upgrade?

  • Faster
  • Smoother
  • S Pen lag is gone!
  • Hard to tell, but when playing music, the sound seems better

Yeah, there some productivity suites enhancements and all that. And Android 4 has UI improvements and new features. What I noticed though is the speed. I can scroll web pages so fast it is a a blur. Also, the S Pen is now usable. Well, you could use it before, but on my phone the lag was annoying. Maybe I’m imagining it, but even the Swype keyboard is faster too.

Wikipedia’s list of features in Android 4.0.x Ice Cream Sandwich.

Env:
PC: Windows 7, AMD quad-core
Phone: Model SAMSUNG-SGH-I717
Android: version 4.0.4

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Use Groovy to find path of a file in a directory tree

Find the path of a file according to its name and possible partial path within a directory tree.

I was working on a program that could be executed from a few possible locations in a project. The program had to load a data file. So, there had to be a configured way to locate that file. I had a thought, why not just find it in the project location hierarchy. It would have to search both up and down the tree, and to avoid finding the incorrect file, allow the use of a partial path. That is, you can search for “foo.dat” or “data\foo.dat”, and it would find, for example, “resources\data\foo.dat”.

I used Groovy 2.0 and the Eclipse plugin. Both are great! The static type checker is a very welcome addition to this language.

Notes:

  • This may be a bad idea.
  • Not intended to be a general purpose “Find” as in the the Linux utility of that name.
  • Source also available as a gist:
    git clone git://gist.github.com/3076035.git gist-3076035
import groovy.transform.TypeChecked

/**
 * search file according to its name in directory 
 * and subdirectories
 */
@TypeChecked
class FindFile {
	String basePath; // for unit testing		

	/**
	 * 
	 * Find a file within a hierarchy given a path.
	 * 
	 * @param basePath  which folder to start the search
	 * @param targetPath the name or a sub path
	 * @return the path where the file was found
	 */
	public String find(String basePath, String targetPath){
		def result = ''
		String curPath = basePath + File.separator + targetPath
		
		if(new File(curPath).exists()){
			result = curPath;
		}else{
			result = searchUp(basePath, targetPath)			
			if(!result){
				result = searchDown(basePath, targetPath)				
			}			
		}
		
		result
	}
	
	/**
	 * 
	 * @param targetPath the name or a sub path
	 * @return the path where the file was found
	 */
	public String find(String targetPath){
		def result = ''
		String curDir = getCurrentPath()		
		find(curDir, targetPath)		
	}	
	
	/** depth first recursive search of sub directories */
	def searchDown(String startDir, String targetPath){
		def result = "";
		File curDir = new File("$startDir")
		
		try{
		   curDir.eachDirRecurse { File cur ->				
			def fp = new File(cur.path + 
                                  File.separator + targetPath)				
			if(fp.exists()){
			  result = fp
			  throw BREAK
		        }
		   }
		}catch(BreakClosureException ex){
			// 
		}

		result		
	}
	
	/** Search for path in parent directories  */
	def searchUp(String startDir, String targetPath){
		def result = "";
		
		File lastDir = new File(startDir)
		def up = File.separator + '..'
		File curDir = new File("$startDir$up")
		
		try{
			while(curDir.getCanonicalPath() != 
                          lastDir.getCanonicalPath()){
				def fp = new File(curDir.path + 
                                     File.separator + targetPath)
	
				if(fp.exists()){
					result = fp
					throw BREAK
				}
				
				lastDir = curDir
				curDir =  new File("${curDir.path}$up")				
			}	
		}catch(BreakClosureException ex){
			//
		}

		result
		
	}
	
	protected String getCurrentPath(){
		//return basePath ? basePath : new File(".").path
		new File(".").path
	}	

        // for exit out of closures
	final static BREAK = new BreakClosureException() 	

	static class BreakClosureException extends Throwable {

		public BreakClosureException() {
			super()
		}

	}

}

That wasn’t so bad. Worse was the JUnit test used to create it. I had to use a little Groovy AOP to intercept the SUT’s getCurrentDir() method. But, then I just added the basePath field which made testing much easier. The interception is left in for my future reference on how to do this.

import static org.junit.Assert.*;

import groovy.mock.interceptor.MockFor
import org.junit.Before
import org.junit.After
import org.junit.Test
import static org.hamcrest.CoreMatchers.*

/**
 * 
 * @author jbetancourt
 *
 */
class FindFileTest {
	ProxyMetaClass proxy
	MethodInterceptor theInterceptor = new MethodInterceptor()
	//def BASEPATH = System.properties.get("java.io.tmpdir")
	def BASEPATH = "c:\temp\"
	def hierarchy = "\one\two\three\four"
	
	@Test
	void should_find_in_sub_directory(){
		File tempFile = createTempFile("${BASEPATH}one\two\three\four")
		
		println("Testing:  BASEPATH=$BASEPATH, tempFile=$tempFile, 
                   tempFile name=${tempFile.getName()}")
		def actual = findAtFolder(BASEPATH, tempFile, tempFile.getName())
		def expected = "${BASEPATH}one\two\three\four\${tempFile.name}"			
		assertThat(normalize(actual), is(normalize(expected)))		
	}
	
	@Test
	void should_find_in_higher_level(){
		File tempFile = createTempFile("$BASEPATH\one\")
		
		def actual = findAtFolder("$BASEPATH\one\two\three\four", 
                     tempFile, tempFile.getName())
		def expected = "$BASEPATH\one\${tempFile.name}"			
		assertThat(normalize(actual), is(normalize(expected)))		
	}
	
	@Test
	void should_not_find(){
		def tempFile = new File("$BASEPATH\x.y")
		def actual = findAtFolder("$BASEPATH\one\two\three\four", 
                       tempFile, "$BASEPATH\one\abc.tmp")
		def expected = ""			
		assertThat(normalize(actual), is(normalize(expected)))		
	}
	
	@Test
	void should_find_subpath(){
		File tempFile = createTempFile("$BASEPATH\one\two\three")
		
		def actual = findAtFolder("$BASEPATH\one\two\three\four", 
                        tempFile, "\two\three\" + tempFile.getName())
		def expected = "$BASEPATH\one\two\three\${tempFile.name}"
		assertThat(normalize(actual), is(normalize(expected)))		
	}

	/** test helper */
	private String findAtFolder(String folder, File tempFile, targetSubPath){						
		theInterceptor.basePath = folder		
		def found 
		
		proxy.use {
			def ff = new FindFile()
			found = ff.find(targetSubPath)
		}		
		
		found
	}

	@Before // each test runs
	void setUp(){
		createHierarchy()
		proxy = ProxyMetaClass.getInstance(FindFile.class)
		proxy.interceptor = theInterceptor
	}
	
	@After  // each test runs
	void destroy(){
		if(!deleteHierarchy(BASEPATH, hierarchy)){
			println "Could not delete [$BASEPATH]"
		}			
	} 
	
	/**
	 *  Allow override of getCurrentPath method 
	 * 
	 */
	private class MethodInterceptor implements groovy.lang.Interceptor{
		public basePath

		@Override
		public Object afterInvoke(Object object, String methodName,
				Object[] arguments, Object result) {
			
				if(methodName == "getCurrentPath"){
					result = basePath 
				}
				
				result;
		}
				
		@Override
		public Object beforeInvoke(Object object, String methodName,
				Object[] arguments) {
			
			return null;
		}
	

		@Override
		public boolean doInvoke() {
			return true;
		}
		
	}

	def createHierarchy(){
		def path = "$BASEPATH$hierarchy"		
		
		new File(path.toString()).mkdirs()
	}
	
	/**
	 * 
	 * Can this really be done well.
	 * 
	 * What if there are soft links, etc.
	 * 
	 * @see http://stackoverflow.com/questions/779519/delete-files-recursively-in-java
	 * @see http://commons.apache.org/io/api-release/org/apache/commons/io/FileUtils.html 
	 * 
	 * @param base
	 * @param dest
	 * @return
	 */
	boolean deleteHierarchy(String base, String dest){
		def result
		List list = dest.split("\"+File.separator)
		list = list - [""]
		def f = new File(base + File.separator + list[0])
		result =f.deleteDir()		
		result
	}
	
	String normalize(path){
		return new File(path).getCanonicalPath()
	}

	/** create a temp file at a directory */
	private File createTempFile(String folder) {
		File tempFile =File.createTempFile("xyz",".tmp", 
                         new File(folder))
		tempFile.deleteOnExit()
		return tempFile
	}
	
} // FindFileTest
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

“Switched At Birth” TV series

I finished watching the 22 episodes on Netflix. It might also be available on Hulu and on the show’s web page. This is originally an ABC Family network show.

Excellent show! I couldn’t stop watching it. The actors were awesome. Imagine, the two teen girls learn that they were switched at birth. Not only that, they are from two different socioeconomic sides of the tracks. I also like that one of the “factors” of this show is that one of the teens is deaf, so there is use of ASL and that whole world is given some welcome recognition in media.

“Switched at Birth,” a one-hour scripted drama, tells the story of two teenage girls who discover they were accidentally switched as newborns in the hospital. …. Things come to a dramatic head when both families meet and struggle to learn how to live together for the sake of the girls.*

Recommended.
Links

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Eclipse IDE 4.2 UI is austere

Some people don’t like the new Eclipse Juno release default L&F. Its kind of underwhelming.

I don’t think it is so bad. For use on a large monitor (and what company tortures their developers with small monitors?) the earlier UI is much better. On laptops and smaller monitors, the new UI makes sense.

If you rather have the 3.x appearance go into Window -> Preferences -> General -> Appearance. There you will find a drop down to select the Theme. When I installed the new version the default was “Windows 7″. Change to “Classic”, then restart Eclipse.

The result should be more like Eclipse 3.8.

What is worse is the the changes to UI behavior. For example, I tried to put the Outline view on top of the Navigator view. The UI would attempt to arrange them every which way but stacked. Finally on a guess I dragged a view to the actual tab area, not the view’s work area (as in version 3.8) and it worked.

Further Reading

Eclipse 3.8 vs 4.2

 

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

All The Isms

Isn’t isms such a schism, makes you dizzy like a prism.

Need a doc, a physician, hurts unraveling these positions.

Syllogisms break, split into paroxysms.

Perhaps I don’t get all the mechanisms

Of these organisms, hierarchies of munitions,

Biting, spitting, running, pinching, stabbing me, my inhibitions.

Frenetic pace will not stop; a chasm of malapropisms.

Capitalisms merges corporatism, such a dissum.

Spiritualism takes a back seat to materialisms.

Excuses me’ums I must go and pissisms.

– Josef

Other works

  1. Scattered A short story about the future extremes of …
  2. Poverty
  3. Hero waits A nano-story.
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Swype on Samsung Galaxy Note

I’ve had my Note since Feb 2012, I think.  Love it.  However, even with the large screen I found using keyboard input tedious; I’m just not good with my thumbs like that. 

Finally I retried using the Swype keyboard.  It comes pre-installed on the Samsung Note. Swype is really good!  Takes just a few minutes to get comfortable with it.

The way to get good at it is to not try to be accurate. Coming from the standard keyboards, you always try to tap the correct key. Swype works on gestures, so you can even miss going over the correct keys, it will figure out what your wanted. Plus, it will show you a list of word options too.

The upcoming Swype is even better and available as a demo. The new Swype will have word prediction built in:

Next Word Prediction
Swype’s next word prediction is more intelligent than ever. Imagine your device figuring out what you will type based on the history of how you’ve used specific words in relationship to one another. A cutting edge Advanced Language Model, the latest XT9 algorithms and a robust Dynamic Language Model all work together with a preloaded baseline language database to be able to (almost) read your mind.

That reminds me of something I was working on years ago, Predictive Interface technology. I’ll have to blog about it one day.

iSwipe on iPhone and iPad
Looks like someone is making a Swype-ish app called iSwipe that runs on Apple products. Will require a jail broken phone though. There are other apps that provide Swype type of input. I wonder why the makers of Swype don’t provide an iOS version.

Links

Environment

  • Phone:  Samsung Galaxy Note i717
  • Swype version:  3.26.92….. etc.
  • Android version:  2.3.6

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.