Implementing pinch-zoom and pan/drag in an Android view on the canvas
I was trying to get pinch-zoom and panning working on an Android view today. Basically I was trying to implement the same behavior you see when you use Google Maps (for example). You can zoom in and pan around until the edge of the image, but no further. Also, if the image is fully zoomed out, you can’t pan the image. Implementing the pinch-zoom functionality was pretty easy. I found an example on StackOverflow. I then wanted to implement panning (or dragging) as well. However, I wasn’t able to easily find examples and tutorials for this functionality. I started with this example that comes from the third edition of the Hello, Android! book but I didn’t get too far. So I started playing around a little bit with the events and started writing some code from scratch (using the example from Hello, Android!) so that I could have a better idea of what was happening.
As I mentioned before, getting zoom to work was pretty easy. Implementing panning/dragging was the hard part. The major issues I encountered and subsequently fixed were the following:
- Panning continues indefinitely in all directions.
- When you zoom and then pan, stop, and then start again, the view jerks to a new position instead of panning from the existing position.
- Excessive panning towards the left and top can be constrained, but panning towards the right and bottom is not so easily constrained.
Once I fixed all the problems, I figured that it would be nice to document it for future reference, and I also think it would be a useful resource for others who have the same problem. Now a little disclaimer before I go any further: I’m not an Android expert and I’m really not that great with graphics; I just started it learning to program for Android this semester for one of my Masters electives. So there might be a better way of doing all this, and if there is, please let me know! Also, if you want to skip all the explanations and just see the code, you can skip to the last page.
Popularity: 28% [?]
December 4, 2011 Posted by vivin | Android, Java, Operating Systems, Programming and Development, Software | android, canvas, drag, dragging, gestures, java, pan, panning, pinch-zoom, view, zoom, zooming | 17 Comments
vivin.net is back… mostly
So I’m sure you’ve noticed that this website was down for a while. It went down about three weeks ago when one of the (two) hard-drives on my server died due to bad sectors; it was eight years old. I didn’t panic (too much), because my WordPress database was on the main drive, which is still alive. However, my home directory was on the bad drive and I hadn’t backed up in a while (sigh), and so I lost some images that I had uploaded. What baffled me were my WordPress uploads. I was sure that I had installed WordPress on my main drive, but when I went to search for it, I couldn’t find any trace of the install. Due to this, I’ve lost a few images and I’m not sure if I’ll be able to replace them unfortunately. Oh well.
Also, I must bid farewell to a dear and old friend: my webserver enterprise. I set up my webserver almost 10 years ago (running FreeBSD of course), and she has been serving me faithfully for all this time. Over the years I’ve dealt with all kinds of disasters and I’ve been able to keep her running. However, after this latest disaster I’ve realized that I just don’t have the time to maintain and administer a server anymore; it’s hard to do with a full-time job and with a full-load at school (did I mention that I am doing my Masters?). Therefore, I’ve moved my site over to dreamhost. The cool thing is that they also offer shell access too, which in my opinion is absolutely indispensable. It took me a little while to migrate my WordPress installation over (I had to work out a few kinks), but now it looks like everything is running smoothly.
On that note, I’m looking forward to less server-administration and more blogging!
Popularity: 2% [?]
September 19, 2011 Posted by vivin | Computers, FreeBSD, Hardware, Nerdy Stuff | dreamhost, enterprise, freebsd, my website, server, wordpress | Leave a Comment
Rooting the G2
As some of you may already be aware, it appears that the G2 has some sort of “magic restore” (it’s not a rootkit) function that causes all changes to /system to be reverted. This means that you cannot remove any bundled bloatware. Even more troubling, it looks like the phone will perform the restore while it is running (i.e, you don’t need a reset). I haven’t turned on my G2, so this is what I’ve heard from people at XDA Developers. You can get temporary root on the devices, but after a little while (some people say minutes, others say hours; experiences seem to vary) root is lost. So it is possible that something is performing the restore while the phone is running.
Helpful folks on XDA Developers have posted the datasheet to the eMMC and another kind soul (damnoregonian) was able to get the value of the CSD register (the register that seems to control the behavior of the MMC): d00f00320f5903fffffffdff924040c8.
WP_GRP_SIZE[36:32] and WP_GRP_ENABLE[31:31] seem to be the bits that control the write-protect (per the datasheet). Currently these seem to be set to the default values per the data sheet (11111b and 1b). Clearing the bits should (theoretically) turn off the write protection. The value to do that would be d00f00320f5903fffffffde0124040c8. The CSD node is R/O and so you cannot echo to it directly. The only way to do it would be to write a kernel module/driver that writes to the register. Apparently the kernel exports a function called mmc_send_csd, and so one should be able to write to this register.
I’m tempted to write a kernel module that does just that. But since working at Intel I haven’t written any kernel drivers. Also while I did write drivers at Intel, I pretty much made modifications to what others before me had written, and so I never wrote one from scratch. I’m going to see if I can start on something this weekend… wish I was still in college… I had a lot more time then!
If this works (and that’s a big if), there’s still the issue of restores being done while the phone is in operation. That could cause a lot of inconsistency. So this might be a partial solution.
Either way, I’m sure someone will come up with a way to root the phone. But if there’s nothing by next Friday, I’m going to return the phone.
UPDATE
Someone posted updated specs. It looks like those bits are read-only. Bummer. Also, this from T-Mobile’s website:
Bellevue, Wash. — Oct. 7, 2010
As pioneers in Android-powered mobile devices, T-Mobile and HTC strive to support innovation. The T-Mobile G2 is a powerful and highly customizable Android-powered smartphone, which customers can personalize and make their own, from the look of their home screen to adding their favorite applications and more.
The HTC software implementation on the G2 stores some components in read-only memory as a security measure to prevent key operating system software from becoming corrupted and rendering the device inoperable. There is a small subset of highly technical users who may want to modify and re-engineer their devices at the code level, known as “rooting,” but a side effect of HTC’s security measure is that these modifications are temporary and cannot be saved to permanent memory. As a result the original code is restored.
Well, T-Mobile. How about you provide us technical users a way to root our devices? What you’re doing is stupid. You’re going against everything Android stands for. If I can’t root it, I think I will return my phone and get a Vibrant instead. I would have expected this from Apple or Verizon. But not from you. Very disappointing.
Popularity: unranked [?]
October 7, 2010 Posted by vivin | Android, Assembly, C, Computers, Hardware, Nerdy Stuff, Programming and Development, Technology | drivers, emmc, g2, kernel drivers, kernel modules, linux, mmc, modules, root, rooting, xda developers | Leave a Comment
Unboxing my new T-Mobile G2 Android Phone
My wife called me at work today and told me that my new phone just came in the mail
. It’s the new G2 by HTC, which is supposed to be the successor to the G1. The specs on this phone are:
- 3.7 inch WVGA capacitive touch screen
- 5 megapixel camera with auto-focus and flash
- Qualcomm MSM7230 800MHz processor
- 4GB ROM
- 512MB RAM
- GPS/aGPS
- WiFi
- Bluetooth
- Android 2.2
- Runs on T-Mobile’s 4G/HSPA+ network
- Slide-out keyboard
Popularity: 1% [?]
October 6, 2010 Posted by vivin | Android, Hardware, Nerdy Stuff, Technology | android, cell phone, g1, g2, google, htc, mobile phone, mytouch, nexus one, pda, phone, t-mobile, unboxing | Leave a Comment
Downtime and System Upgrade
Sorry for the downtime. My webserver had a failing hard-drive and I figured that while I was replacing the hard-drive, I would upgrade the entire machine as well. The box was a Pentium 4 1.4Ghz with 512MB of RAM that I hadn’t upgraded since I first built it in 2002. Now it’s been upgraded to a Pentium 4 2.4Ghz (hyper-threaded) with 1GB of RAM. Building from source will be a lot faster now! The whole upgrade process took a while because I was also in the process of upgrading another one of my machines and that took for EVER (some issues with shorting). Finally I had to install FreeBSD (version 8.0) on the new hard-drive as well as Apache, PHP, MySQL, WordPress etc. After I have everything set up, I’m going to make sure that I image the hard-drive so that I can restore it from backup easily.
Popularity: unranked [?]
July 24, 2010 Posted by vivin | Computers, FreeBSD, Hardware | computer hardware, freebsd, hard-drives, Hardware, my website, system upgrade, upgrade | Leave a Comment
Download ShapeWriter APK
I tried to install ShapeWriter from the Android Marketplace yesterday and couldn’t find it (I was trying to reinstall it after flashing my phone with Cyanogenmod 5.0.8). After searching the interwebs, I found out that it had been removed from the marketplace on June 20th indefinitely (supposedly for QA issues). Luckily I had backed up the app using MyBackup Pro and still had the APK, so I was able to reinstall it. I’m putting the APK up here for anyone who needs to reinstall ShapeWriter.
Popularity: unranked [?]
June 22, 2010 Posted by vivin | Android, Nerdy Stuff | android, android 2.1, apk, eclair, google, mytouch, shapewriter | 150 Comments
GitHub broke my scp
I set up git on my FreeBSD box so that I can commit my code to GitHub. Today I tried to scp some stuff over and I was met with this rather unhelpful message:
vivin@serenity ~/Projects/code $ scp -r vivin@www.vivin.net:~/code/agnostic . Password: ps: Process environment requires procfs(5) Initializing new SSH agent... vivin@serenity ~/Projects/code $
I fixed the procfs problem by adding the following to my /etc/fstab:
proc /proc procfs rw 0 0 linproc /compat/linux/proc linprocfs rw 0 0
and then running:
vivin@enterprise ~ $ sudo mount /compat/linux/proc vivin@enterprise ~ $ sudo mount /proc
So I try to scp again and I get:
vivin@serenity ~/Projects/code $ scp -r vivin@www.vivin.net:~/code/agnostic . Password: Initializing new SSH agent... vivin@serenity ~/Projects/code $
WTF? Then I remembered making some changes to my .bashrc to be able to commit to github:
function start_agent {
echo "Initializing new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add;
}
# Source SSH settings, if applicable
if [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}" > /dev/null
#ps ${SSH_AGENT_PID} doesn't work under cywgin
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_agent;
}
else
start_agent;
fi
I pulled all that out of my .bashrc and made a separate shell script for it. After I did that, scp started working again. I had no idea that calling scp would actually run .bashrc
Popularity: unranked [?]
March 9, 2010 Posted by vivin | Computers, FreeBSD, Networking, Operating Systems | freebsd, git, github, networking, openssh, scp, ssh | 1 Comment
Trying out ChromeOS from a VMWare image
I was pretty excited when I saw the VMWare image for ChromeOS up for download. I immediately downloaded it to try it out. The zip file I got from gdgt has a vmdk file but no vmx file. I created one from scratch to try ChromeOS out (I’ve made a new zip with the vmdk and the vmx. The link is at the end of this post.). It’s not too bad. The OS boots up really quick. The login screen is pretty spartan (look at the screenshots I have). You login with your Google/Gmail username and password. When you login, it opens up the Chrome browser. I wasn’t able to get anything else running other than the browser. Also, when I first logged in, Chrome complained that the security certificate for Gmail had been revoked. But I was able to login when I typed in the address for Gmail in again. The default tabs seem to be GMail and Google Calendar. I’m assuming that because it’s such an early build, you’re not able to try out the other stuff. Maybe there’s a way; I didn’t play around with it too much. There is a Date and Time settings menu that’s available from the browser, where you can set a few other options, like your proxy, SSL options, home page, and a few other advanced settings.
Read more »
Popularity: unranked [?]
November 20, 2009 Posted by vivin | Chrome OS, Computers, Linux, Operating Systems | chrome, Chrome OS, google, linux, os, vmware | 13 Comments
Flu shot and bizarre network issues
This last weekend I had drill and the medics gave us the seasonal-flu mist-vaccine. It’s the one where they squirt gooey, inactive virus up your nose. I’ve had the vaccine before without any adverse side-effects. Yeah, not this time. I got the shot on Saturday and I was fine on Sunday. Not so on Monday. I woke up a few times in the middle of the night with a bit of a fever, but I figured that it would just go away. Yeah, didn’t happen. On Monday morning I felt like I had been run over by a semi. My throat felt like I had swallowed bits of broken glass. Needless to say, I didn’t go to work. I was bedridden most of the day, but towards the end I felt a little better. I tried to get a little work done but I wasn’t too successful since I had a hard time concentrating.
Read more »
Popularity: unranked [?]
October 27, 2009 Posted by vivin | FreeBSD, Life, Linux, Networking | flu, freebsd, linux, networking, vaccine | 3 Comments
Ubuntu 9.04 (Jaunty Jackalope) and Windows 7 dual-boot
In my previous post I talked about the problems I had while installing Ubuntu and Windows 7 on my Alienware m7700 laptop. It took me about three days of hair-pulling before I was finally able to get it to work. First, I burnt a new copy of the ISO for Ubuntu 9.04. Then, I enabled RAID on my system. I put the disks into stripe mode (the FastTrak Promise 378 does not support JBOD). This time, I got past the COMRESET error (ata3: COMRESET failed (errno=-16)) and was able to boot into the LiveCD. However, my joy was short-lived. The install would terminate (around the 40% mark) with the following message:
[Errno 5] Input/output error
This is often due to a faulty CD/DVD disk or drive, or a faulty hard disk. It may help to clean the CD/DVD, to burn the CD/DVD at a lower speed, to clean the CD/DVD drive lens (cleaning kits are often available from electronics suppliers), to check whether the hard disk is old and in need of replacement, or to move the system to a cooler environment.
Popularity: unranked [?]
October 23, 2009 Posted by vivin | Computers, Linux, Operating Systems, Windows | dual-boot, linux, os, raid, smart, ubuntu, windows 7 | 1 Comment
Search
Blogroll
Links
Popular Posts
Recent Tweets
- Beer http://t.co/ebFRWBAh 3 weeks ago
- @petermolydeux You are a dinosaur. Your task is to get fossilized, discovered by paleontologists, and then be displayed in the Smithsonian. 2012-03-06
- wtf wikipedia! #SOPA #PIPA 2012-01-18
- Twitter realtime search for "WTF wikipedia" is awesome! 2012-01-18
- More updates...
Powered by Twitter Tools
Recent Comments
- dane: Folks, read the defination of Facism above again. It is a near 100 % match for Communism as practiced by the...
- Bobby: @wauter: Could you please provide me active link to grinder-frameworked.py because i can`t find them in git.
- leo: great post! thank you very much
- Terence: Very interesting and useful information.
- Nj2toU: Thank you! I may have to do a factory reset of my Evo due to some kind of memory leak that shows me having...
Recent Trackbacks
- help paying rent: My opinion is ......
- Producing Emerging Media: Color Correcting and Photos in Wordpress
- Rough Book: Maven project for Generic (n-ary) Tree in Java
- Page 2 - Sprint Android Forum: Does Anyone Have a Shapewriter apk?
- JavaFX: LIS 7440
Random Posts
Tag Cloud
ait army army national guard asperger's syndrome asu baghdad camp liberty code cse421 dancing development dsl family fort lee freebsd garba hhb 1/180th inane india indian school al-ghubra iraq isg java Life linux message board my website national guard networking oif oman operation iraqi freedom perl photo album photos pictures programming project roughnecks salsa school vacation war weekend windows xpCategory Cloud
AIT Army Arts Assembly Computers Copyrights Dance Family and Friends FreeBSD Gaming Haiku Hardware Hosting Humor Java Jython Life Linux Love and Marriage Military Movies Music Musings, Ramblings, and Inanities Nerdy Stuff Networking Operating Systems Operation Iraqi Freedom p2p Perl PHP Poetry Politics and Law Programming and Development Projects Prose Python School Sci-Fi Science Software Television Travel Web Windows Work
Meta
Categories
- ►Arts (118)
- ►Art (2)
- ►Books (1)
- ►Concerts (1)
- ►Dance (15)
- ►Movies (6)
- ►Music (40)
- ►Bands (16)
- ►Coldplay (1)
- ►Metallica (3)
- ►Muse (1)
- ►Pink Floyd (1)
- ►Sigur Rös (1)
- ►The Beatles (1)
- ►The Shins (1)
- ►The Strokes (1)
- ►U2 (2)
- ►Coldplay (1)
- ►Genres (10)
- ►Indie (2)
- ►Rock (6)
- ►Alternative (2)
- ►Classic (1)
- ►Psychedelic (1)
- ►Alternative (2)
- ►Indie (2)
- ►Bands (16)
- ►Photography (3)
- ►Poetry (9)
- ►Haiku (4)
- ►Haiku (4)
- ►Prose (5)
- ►Television (5)
- ►Art (2)
- ►Economics (2)
- ►History (1)
- ►Life (537)
- ►Family and Friends (75)
- ►Humor (5)
- ►Love and Marriage (25)
- ►Musings, Ramblings, and Inanities (88)
- ►School (74)
- ►Travel (17)
- ►Work (23)
- ►Family and Friends (75)
- ►Military (198)
- ►Army (126)
- ►AIT (27)
- ►Annual Training (2)
- ►Basic Training (2)
- ►Operation Iraqi Freedom (24)
- ►AIT (27)
- ►Army (126)
- ►Nerdy Stuff (626)
- ►Computers (758)
- ►Hardware (22)
- ►Networking (41)
- ►Operating Systems (109)
- ►Programming and Development (301)
- ►Software (8)
- ►Hardware (22)
- ►DIY (1)
- ►Gaming (13)
- ►Linguistics (3)
- ►Math (1)
- ►Sci-Fi (10)
- ►Science (11)
- ►Technology (3)
- ►Technology (3)
- ►Computers (758)
- ►Politics and Law (39)
- ►Copyrights (10)
- ►DMCA (1)
- ►DMCA (1)
- ►Patents (1)
- ►Copyrights (10)
- ►Arts (118)
Archives
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- July 2011
- June 2011
- May 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- August 2008
- March 2008
- February 2008
- November 2007
- July 2007
- June 2007
- May 2007
- March 2007
- December 2006
- October 2006
- September 2006
- August 2006
- June 2006
- April 2006
- March 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- June 2005
- May 2005
- April 2005
- February 2005
- October 2004
- September 2004
- August 2004
- July 2004
- June 2004
- May 2004
- April 2004
- March 2004
- February 2004
- January 2004
- December 2003
- November 2003
- October 2003
- September 2003
- July 2003
- June 2003
- May 2003
- March 2003
- February 2003
- January 2003
- December 2002
- November 2002
- October 2002
- September 2002
- August 2002
- July 2002
- June 2002
- May 2002
- April 2002
- February 2002
- September 2001
- August 2001
- April 2001
- March 2001
- February 2001
- January 2001
- December 2000
- November 2000
- October 2000
- August 2000
- July 2000
- June 2000
- May 2000
- March 2000
- January 2000
- December 1999
- November 1999
- October 1999
- September 1999