Yet another Java Developer.

JSF Developer living in Oklahoma City

Gallery

IMGP0171.JPG IMGP0141.JPG 1236913022127.jpg IMGP0318.JPG

Currently browsing android

Scrolling div on Android in webview

Problem

Simple thing as scrolling a div with overflow:auto is currently not possible on the Android platform.
Due to my application requirement I really needed this functionality so here is what I come up with

Challenges

Currently when we call node.offsetHeight we will not get the full height of the div only the content visible
to fix that I change the positioning to absolute and height 100% to get the true height of the div.

Android project with scrollable div can be download here

Code

Code consist of three parts

  • CSS
  • JavaScript
  • HTML markup
.scroller_container{
  	position:relative;  border:1px solid #CCC; overflow:hidden; top:0;left:0
  }
  .scroller{
  	position:relative; float:left; 
  }
 
  .scroller_navigator{
  	float:right;border:1px solid #CCC; height:150px; width:45px;
  }
 
  .scroll_down, .scroll_up{
  	clear:left;padding:8px
  }
 
  .scroller_navigator_spacer{
  	width:10px; height:48px; clear:left;
  }
 /**
		 * WebKit Div Scroller class
		 * @author:Greg Bugaj
		 * Initial release
		 */
		 //Namespace
		var GB=GB || {};
		GB.Scroller=
		{
			SCROLL_INREMENT:5,//Amount to scroll per update
			SCROLL_TIME:75,//Time between update Intervals in  MS	
 
			getElementsByClassName:function(classname, node)  {
				if (!node) {
					node = document.getElementsByTagName('BODY')[0];
				}
				var a = [];
				var re = new RegExp('\\b' + classname + '\\b');
				var els = node.getElementsByTagName("*");
				for(var i=0,j=els.length; i<j; i++){
					if(re.test(els[i].className))a.push(els[i]);
				}				
			    return a;
			},
			//Attached event to the scrollable components
			init:function(){
				var root = document.getElementsByTagName('BODY')[0];
				var containers=GB.Scroller.getElementsByClassName("scroller_container", root);
 
				for(var i=0;i<containers.length;i++){
					var scroller_container = containers[i];
					//Copy old properties
					var old={
						position:scroller_container.style.position, 
						height:scroller_container.style.height, 
						overflow:scroller_container.style.overflow
					};
 
					//Set new props*/
					scroller_container.style.position="absolute";
					scroller_container.style.height="100%";
					scroller_container.style.overflow="none";
 
					var scroller = GB.Scroller.getElementsByClassName("scroller", scroller_container);
						if(scroller==null){
							alert("There is no DIV with class 'scroller'");
						}
						scroller=scroller[0];//There should be only 1 element in the array
 
					var contentHeight = scroller.offsetHeight;   
 
					//Move the element back to it original positon with its original values
					scroller_container.style.position=old.position;
					scroller_container.style.height=old.height;
					scroller_container.style.overflow=old.overflow;
 
					var visibleContentHeight = scroller_container.offsetHeight ;
					var iTimer=0;
						/**
						 * Scroll content layer up/down
						 * @param {Object} e
						 * @param {Object} direction to scroll
						 */
					var scrollContent=function(e, direction){
						var t=parseInt(scroller.style.top);
						var cancelTimer=false;
						/*Scroll text up*/
						if(direction == -1 && ((contentHeight+scroller.offsetTop) < visibleContentHeight)){
							cancelTimer=true;
						}/*Scroll text down*/
						else if(direction == 1/*DOWN*/ && ((contentHeight+scroller.offsetTop) >=  contentHeight)){
							cancelTimer=true;
						}
						if(cancelTimer){
							clearInterval(iTimer);
							return;
						}						
						t+=GB.Scroller.SCROLL_INREMENT*direction;
						scroller.style.top=t+"px";				
					};
 
 
					//Attach events to navigation 
					var tapUP = GB.Scroller.getElementsByClassName("scroll_up", scroller_container);
					if(tapUP==null){
						alert("There is no DIV with class 'scroll_up'");
					}
					tapUP=tapUP[0];//There should be only 1 element in the array
 
					var tapDOWN = GB.Scroller.getElementsByClassName("scroll_down", scroller_container);
					if(tapDOWN==null){
						alert("There is no DIV with class 'scroll_down'");
					}
					tapDOWN=tapDOWN[0];//There should be only 1 element in the array
 
 
					tapUP.addEventListener('touchstart', function(e){
						iTimer=setInterval(function(){ scrollContent(e, -1);}, GB.Scroller.SCROLL_TIME);
					}, false);
 
					tapUP.addEventListener('touchend', function(e){
						clearInterval(iTimer);
					}, false);
 
					tapDOWN.addEventListener('touchstart', function(e){
							iTimer=setInterval(function(){scrollContent(e, 1);}, GB.Scroller.SCROLL_TIME);
					}, false);
 
					tapDOWN.addEventListener('touchend', function(e){
						clearInterval(iTimer);
					}, false);
 
				}//for
			}//function
		};
 
		//Initialize all the scrollable components on the page
		window.addEventListener('load', function(){ GB.Scroller.init(); }, true);
   <div class="scroller_container" style="width:318px; height:150px;">
        <div class="scroller" style="width:205px; top:0;left:0;"> 
            Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec dapibus ipsum in nulla rhoncus a blandit enim lobortis. Mauris scelerisque justo eu purus molestie ut sodales diam laoreet. Integer id volutpat urna. Sed lacinia risus id magna pharetra scelerisque. Proin venenatis blandit sapien vitae pulvinar. Nulla et urna in erat venenatis posuere eu id ipsum. Proin magna mi, congue ultrices malesuada id, sollicitudin a urna. Praesent id lorem leo. Phasellus vestibulum dapibus mattis. Fusce et faucibus risus.  
     Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec dapibus ipsum in nulla rhoncus a blandit enim lobortis. Mauris scelerisque justo eu purus molestie ut sodales diam laoreet. Integer id volutpat urna. Sed lacinia risus id magna pharetra scelerisque. Proin venenatis blandit sapien vitae pulvinar. Nulla et urna in erat venenatis posuere eu id ipsum. Proin magna mi, congue ultrices malesuada id, sollicitudin a urna. Praesent id lorem leo. Phasellus vestibulum dapibus mattis. Fusce et faucibus risus.     </div><!--//scroller-->
 
	<div class="scroller_navigator"><!-- Navigation -->
		<div class="scroll_down" >
			<img src="arrow_up.png" width="32" height="32" alt="Scroll content down" / >
		</div>
		<!-- Spacer between scroll icons  -->
		<div class="scroller_navigator_spacer"> </div>
 
		<div class="scroll_up">
			<img src="arrow_down.png" width="32" height="32" alt="Scroll content up" />
		</div>
	</div>  
 
    </div><!--//scroller_container-->

Feature request/updates

I will add features as I need them or upon request.

Android ImpulseShopper released

About

ImpulseShopper(pre-beta) is application that lets you monitor your favorite daily deals websites like woot.com, 1saleaday.com, dailysteals.com etc…
Includes both widget and full blown application.

  • Engine based
  • Filters
  • Product thumbnails
  • Share via SMS, Email, Twitter
  • Notifications
  • Deployed on Google AppEngine

Screenshots

Android Daily Deals Agent - ImpulseShopper

Update : Beta released

First beta have been unlished on the Android Marketplace. So far so good, some one reported that the program crashes(unknown cause)

Overview

This is idea for my Daily deals agent that will monitor certain sites for daily deals.

Current sites to consider

  • Woot.com - woot | shirt | wine | sellout
  • 1saleaday.com - wireless, watches

Simple yet powerful enough to help me keep tabs on sweet deals.

Screenshots

TabWidget demo project

Sorry it took little longer than expected, run in some issues with cupcake (SDK 1.5)
I have attached a Demo project for all interested with  some screenshots and modified .project for TabWidget Project(fixes cupcake problem ref http://groups.google.com/group/android-developers/browse_thread/thread/5537ae10e4143240) if you use eclipse.

1. My env:
Eclipse Version: 3.4.2
Android SDK 1.5
Windows

2.After you import the TabWidgedDemo project you will probably need to fix your buildpath.
Make sure to add TabWidet as a reference to TabWidgedDemo.

3.In TabWidged project you will need to update the .project file otherwise you will get Verify error when deploying to the device.

If you have any questions let me know, I hope you enjoy the project, more improvements to come

Download tabwidgetdemo for eclipse

Detecting Network Speed and Type on Android (Edge,3G)

For better experience for users of my app I wanted to show them different UI based on their network speed, problem here is that there is no way to know what network we are currently on.

My first instinct was to use android.net.ConnectivityManager getActiveNetworkInfo() which gives us current network information, but the only thing we can find out from this is the connection type TYPE_MOBILE or TYPE_WIFI which is not very useful for my purpose.

So here is a quick tool that will try to determine network type by testing the download speed, I use threshold of 176 kbits/sec as EDGE cut of value.

Downloads

Screenshots

Carme GPS Tracker for Android

My frist Android app, this is simple GPS tracker program that let us record our tracks, store  and share them.

This project uses my custom TabWidget for Android.

Main features

  • Record
  • Playback
  • Share via Email (Google Earth)
  • Share via Twitter  (in progress)
  • Exporting to SD Card
  • Tagging (in progress)

I use icon from http://www.dryicons.com , love their methodology give the little guys an edge by providing free high quality designs.

Screenshots

To Come

Here are some other features that I will implement soon

  • Altitude profiler
  • Photos
  • Profiles

Download Carme source code

Custom Android Tabs

Due to limitation of Android Tab component I created a custom TabWidget that I am using in couple different projects already. The widget allows us to  add custom background and use custom icons, tabs   can be Top/Bottom aligned.

Currently tabs can launch new Activity and  Dialog , when starting new Activity we can use  “startActivityForResult” so our tab will get a notification when other activity have finished.

Read more »

Sidebar3 : Please add some widgets here.