creativepsyco's Blog

Trolling you digitally

Set Background That Does Not Resize on Soft Keyboard

| Comments

Problem

Here is an interesting problem. Let’s say you are in a particular view, and you want to be able to set a background. You simple use the View.setBackground(Drawable) or View.setBackgroundDrawable(Drawable) call to do this. However once you do this, you realize that whenever the soft keyboard is opened it pushes your view to the top/resizes it such that your background looks squished.

I encountered this while working on a chatting application. The resulting image looks something like this:

Image

Solution

The solution is quite simple:

  • In your Activity Manifest, declare the activity which houses the view to android:windowSoftInputMode="adjustResize|stateHidden"
  • Then follow this piece of code:
1
2
3
4
5
Bitmap bmImg;
// Load a bitmap into bmImg
BitmapDrawable background = new BitmapDrawable(bmImg);
background.setGravity(Gravity.TOP);
this.setBackgroundDrawable(background);

This will make sure that you set your background with the Gravity.TOP which will ensure it is always aligned with the top of the container view and is not affected by the Soft Keyboard display.

Blogging With Octopress From 2 Computers

| Comments

I use Octopress to blog from multiple computers, work and home computers, sometimes Virtual Machines even. I don’t have a track of where my latest post is going to be written from.

However, recently while deploying I encountered this strange error:

1
2
3
4
5
6
7
8
## Pushing generated _deploy website
To git@github.com:creativepsyco/creativepsyco.github.com.git
 ! [rejected]        master -> master (non-fast-forward)
 error: failed to push some refs to 'git@github.com:creativepsyco/creativepsyco.github.com.git'
 hint: Updates were rejected because the tip of your current branch is behind
 hint: its remote counterpart. Integrate the remote changes (e.g.
 hint: 'git pull ...') before pushing again.
 hint: See the 'Note about fast-forwards' in 'git push --help' for details.

The reason is that Octopress only does a push to the master branch and not a pull. To resolve this, do this:

1
2
3
4
5
6
7
8
9
msk@MathBook Pro ~/Projects/creativepsyco.github.com (source)$ cd _deploy
msk@MathBook Pro ~/Projects/creativepsyco.github.com/_deploy (master)$ git push origin master -f
Counting objects: 1313, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (702/702), done.
Writing objects: 100% (861/861), 99.72 KiB | 0 bytes/s, done.
Total 861 (delta 423), reused 0 (delta 0)
To git@github.com:creativepsyco/creativepsyco.github.com.git
 + 4647e10...aa94c85 master -> master (forced update)

After that all is well:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
msk@MathBook Pro ~/Projects/creativepsyco.github.com/_deploy (master)$ cd ..
msk@MathBook Pro ~/Projects/creativepsyco.github.com (source)$ rake gen_deploy
## Generating Site with Jekyll
unchanged sass/screen.scss
unchanged sass/styles.scss
Configuration from /Users/msk/Projects/creativepsyco.github.com/_config.yml
Building site: source -> public
Configuration from /Users/msk/Projects/creativepsyco.github.com/_config.yml
Configuration from /Users/msk/Projects/creativepsyco.github.com/_config.yml
Configuration from /Users/msk/Projects/creativepsyco.github.com/_config.yml
Configuration from /Users/msk/Projects/creativepsyco.github.com/_config.yml
Successfully generated site: source -> public
## Deploying branch to Github Pages
## Pulling any updates from Github Pages
cd _deploy
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details

    git pull <remote> <branch>

    If you wish to set tracking information for this branch you can do so with:

        git branch --set-upstream-to=origin/<branch> master

        cd -
        rm -rf _deploy/about
        rm -rf _deploy/assets
        rm -rf _deploy/atom.xml
        rm -rf _deploy/blog
        rm -rf _deploy/docs
        rm -rf _deploy/favicon.png
        rm -rf _deploy/font
        rm -rf _deploy/images
        rm -rf _deploy/index.html
        rm -rf _deploy/javascripts
        rm -rf _deploy/portfolio
        rm -rf _deploy/robots.txt
        rm -rf _deploy/sitemap.xml
        rm -rf _deploy/stylesheets
        rm -rf _deploy/super-awesome

## Copying public to _deploy
cp -r public/. _deploy
cd _deploy

## Committing: Site updated at 2014-03-25 16:44:37 UTC
[master 88fada5] Site updated at 2014-03-25 16:44:37 UTC
 36 files changed, 36 insertions(+), 36 deletions(-)

## Pushing generated _deploy website
Counting objects: 166, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (75/75), done.
Writing objects: 100% (75/75), 9.29 KiB | 0 bytes/s, done.
Total 75 (delta 37), reused 0 (delta 0)
To git@github.com:creativepsyco/creativepsyco.github.com.git
   aa94c85..88fada5  master -> master

## Github Pages deploy complete
cd -

Cheers


WebView Vulnerability in Facebook Android SDK: Embedded OAuth

| Comments

Reposting this from my FB feed

TL;DR

Don’t put your FB username and password within mobile apps when you don’t have the native FB app installed!

Today I learnt that the Facebook SDK for Android is very insecure. At first I thought Man in the Middle attacks on the SDK OAuth authentication process is not possible, but if you are embedding someone else’s WebView within your own App via the SDK, you can very well control them, either via Reflection, or just by modifying the SDK code coz FB makes the SDK a public download which you then compile to link in your app. If the SDK does not find the FB app installed on a user’s phone, it resorts to using the fallback mechanism of using an embedded WebView for authentication.

Rooting Samsung Galaxy S3 GT-I9305 With CyanogenMod Jelly Bean 4.2.2

| Comments

After getting the 4.3 update my Samsung Galaxy S3 started having weird battery problems, it was a high I moved to a custom ROM since they were a lot stable than a few years back and offered a much better stock Android experience without any bloated software than device OEMs put inside.

In this post, I shall roughly tell you how I installed a custom on my Samsung Phone.

Warning: Rooting voids the warranty of your device. We and the developers of these files are not responsible if anything happens to your device. Use this rooting guide at your own risk!

Doing a Proper Github Pull Request

| Comments

While there may be different kind of development strategies floating around the merge vs rebase git model, one thing is for sure, you would at the end of the day want a clean merge from the contributors so that it can be tracked tested and cherry-picked if it needs to. This is where pull-requests are so effective.

What is a pull-request?

From the Official Github Guide:

Pull requests let you tell others about changes you’ve pushed to a GitHub repository. Once a pull request is sent, interested parties can review the set of changes, discuss potential modifications, and even push follow-up commits if necessary.

Pull requests are useful in the shared repository model where contributors can work on different topic branches and then file a pull request to be able to initiate discussion about potential changes which does not need to affect the rest of the project.

Example

Here is an example of a pull request I filed for Square’s Wire open source project.

Android Activity: Problem With Posting Runnables

| Comments

A lot of times in Android you end up writing code like this:

1
2
3
4
5
6
7
8
9
10
//---- Normal Code above ---
Runnable runnable  = new Runnable() {
    @Override
    public void run() {
        // Do something stupid
    }
}
// Singleton Handler Manager -- not an instance one, am I smart?
HandlerManager.getInstance().postDelayed(runnable, 20000); // Run this after 20 seconds! Delay processing of data
finish();

That is, cooking up a lot of Runnables and posting them on the Handler to be run after a period of time. It happens.

As our role as developers trying to get a feature done in time, sometimes these Runnnables are the only hope. However, this Runnable introduces a potential memory leak.

Optimizing Google Protocol Buffers With Wire

| Comments

The concept of Protocol Buffers by Google is amazing.

Why should you use it

Protocol Buffers is a serialization strategy, much like XML or JSON. A lot of mobile apps and web services make use of JSON for passing information. However, protocol buffers are inherently compressed formats and not intented for the human eye (readability wise). You should definitely take a look at it if you feel that you are using a lot of the mobile data or if the primary target group of your app is the domain of mobile. It however, makes sense to use them for internal RPC related APIs and communication channels.

Open Source Is an Ideology Not a Verb

| Comments

Extracts From a software about-me page

MyAwesomeSauce is created by @me and open-sourced on Github

Our library has been open-sourced and served under the GPL License v2 to facilitate ease of use among developers

Seriously? Are you trying to market your creation or genuinely serving the interests of the open source community

From Ben Balter:

To say “hey, we’ve got something decent here, let’s take this closed-sourced project and just hit publish” misses the mark. Your motivation can’t be to seek free labor, as in “hey, if developers want to give us their time, great, let’s put this out there and see what happens we have nothing to lose”, or about sporadically seeking to garner good will from a niche community of dedicated fans. Trust me, an open source developer can smell astroturf a mile a way, and that’s exactly how far they’ll stay.

Open source is a philosophy, not something that you get to choose between waterfall, agile or open source (if there is such a thing). Its not about the code you write but rather, the procedure and democracy of how that code was written, reviewed and published.

So save yourself the trouble to say something to be open-source when you actually mean it in terms of the processes and the people involved. Don’t get trapped in the danger zone :–)

Hide Keyboard for Multiple Edit Boxes in a Page

| Comments

How to hide Keyboard in the case of multiple Edit Text

One common problem faced by people working on Android input field forms is that many a times there is a need to show/hide the keyboard when the person touches on some other part of the screen, other than the edit box itself. However, since the focus is retained by the edit box, even if the keyboard is hidden, its hard to actually detect when and where should you be hiding the keyboard.

The Solution

One way to accomplish this to use the dispatchTouchEvent on the parent container. This is the first event that is called whenever there is a touch encountered on the surface. Only after this the rest of the touch listeners are invoked.

We can first dispatch the touch and then check the getCurrentFocus view to see if the focus is retained by the EditText. If it is, then we simply hide the soft keyboard from the screen.

Another thing to make sure is that the parent container view groups are labelled as focusableInTouchMode, clickable and focusable

Here is the gist that does this job from a custom view group that contains multiple EditText instances.

Install Ia32-libs in Saucy Salamander Ubuntu 13.10

| Comments

With the official release of Saucy Salamander 13.10 now available, I found myself installing it cleanly on my machine.

However, when I went ahead to install the ia32-libs package for the Android 32-bit shared libraries supplied with the SDK. I had a shock. I could not install and the terminal returned this error message:

1
2
3
4
5
6
7
8
9
10
11
output$ sudo apt-get install ia32-libs
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package ia32-libs is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  lib32z1 lib32ncurses5 lib32bz2-1.0

E: Package 'ia32-libs' has no installation candidate

Fortunately there is a solution.

According to this thread all you gotta do is use the i386 code behind the package name

So you can install the package as follow:

1
sudo apt-get install ia32-libs:i386

Update

According to Rick below, the above method may not work. In that case, perhaps check out this Link. This should definitely resolve the issue, although it might end up screwing up your package management. But you gotta try what you gotta try, right?

Cheers