Android ICS style buttons for a dialog

Jan 27, 2013 by

This is basically how you create a standart borderless buttons, like the Android ICS ones.


<!-- OK/Cancel buttons.  -->
<LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="vertical"
       android:divider="?android:attr/dividerHorizontal"
       android:showDividers="beginning"
       android:paddingTop="16dip">

    <LinearLayout
           style="?android:attr/buttonBarStyle"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:orientation="horizontal"
           android:measureWithLargestChild="true">

        <LinearLayout android:id="@+id/leftSpacer"
               android:layout_weight="0.25"
               android:layout_width="0dip"
               android:layout_height="wrap_content"
               android:orientation="horizontal"
               android:visibility="gone" />

        <Button android:id="@+id/cancel_button"
               android:layout_width="0dip"
               android:layout_height="wrap_content"
               android:layout_gravity="left"
               android:layout_weight="1"
               android:text="@string/cancel"
               android:maxLines="2"
               style="?android:attr/buttonBarButtonStyle" />

        <Button android:id="@+id/ok_button"
               android:layout_width="0dip"
               android:layout_height="wrap_content"
               android:layout_gravity="right"
               android:layout_weight="1"
               android:text="@string/install"
               android:maxLines="2"
               android:filterTouchesWhenObscured="true"
               style="?android:attr/buttonBarButtonStyle" />

        <LinearLayout android:id="@+id/rightSpacer"
               android:layout_width="0dip"
               android:layout_weight="0.25"
               android:layout_height="wrap_content"
               android:orientation="horizontal"
               android:visibility="gone" />

    </LinearLayout>
</LinearLayout>
read more

Add gestures to your Windows Phone 7 application

Jul 8, 2012 by

As it turns out, it is extremely easy to add gestures to your Windows Phone app. All you need to do is add a reference to the Silverlight Toolkit


xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"

Then add the following code to any UI element (button, textbox etc…) that you want the gesture to be applied to and implement the listeners in your .cs file


<toolkit:GestureService.GestureListener>
     <toolkit:GestureListener 
         DoubleTap="GestureListenerDoubleTap"
         Hold="GestureListenerHold"/>
</toolkit:GestureService.GestureListener>

Last step is the implementation of the listeners:


private void GestureListenerDoubleTap(object sender, GestureEventArgs e)
{
    MessageBox.Show("Double tap gesture");
}

and


private void GestureListenerHold(object sender, GestureEventArgs e)
{
    MessageBox.Show("Hold gesture");
}

That’s it. It is THAT simple

read more

How to determine theme accent color on Windows Phone

Jul 8, 2012 by

That’s how to determine theme accent color on Windows Phone 7


// Determine the accent color.
Color currentAccentColorHex =
    (Color)Application.Current.Resources["PhoneAccentColor"];

switch (currentAccentColorHex.ToString())
{
    case "#FF1BA1E2": currentAccentColor = "blue"; break;

    case "#FFA05000": currentAccentColor = "brown"; break;

    case "#FF339933": currentAccentColor = "green"; break;

    case "#FFE671B8": currentAccentColor = "pink"; break;

    case "#FFA200FF": currentAccentColor = "purple"; break;

    case "#FFE51400": currentAccentColor = "red"; break;

    case "#FF00ABA9": currentAccentColor = "teal (viridian)"; break;

    // Lime changed to #FFA2C139 in Windows Phone OS 7.1.
    case "#FF8CBF26":
    case "#FFA2C139": currentAccentColor = "lime"; break;

    // Magenta changed to # FFD80073 in Windows Phone OS 7.1.
    case "#FFFF0097":
    case "#FFD80073": currentAccentColor = "magenta"; break;

    // #FFF9609 (previously orange) is named mango in Windows Phone OS 7.1.
    case "#FFF09609": currentAccentColor = "mango (orange)"; break;

    // Mobile operator or hardware manufacturer color
    default: currentAccentColor = "custom eleventh color"; break;
}
read more

How to determine theme background color on Windows Phone

Jul 8, 2012 by


// Determine the visibility of the dark background.
Visibility darkBackgroundVisibility =
    (Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"];

// Write the theme background value.
if (darkBackgroundVisibility == Visibility.Visible)
{
    textBlock1.Text = "background = dark";
}
else
{
    textBlock1.Text = "background = light";
}
read more

OTA on BlackBerry – how to detect OS version from the browser user agent

Mar 4, 2011 by

I do an OTA (over the air) distribution for BlackBerry. Some time ago, I wrote here how to setup the mime types for the OTA distribution on Amazon S3. Luckily now, S3 has got a new and very useful web interface, as well as improved mime type detection. They still get the file types not exactly right, but close enough so that the OTA installation for BlackBerry works on “autodetect” settings just fine.

This is however not about S3, this is about detecting the proper OS version of the BlackBerry OS from the user agent of the browser using a few very simple regular expressions.  The code is tailored to PHP, but you can easily adapt it to any language that supports Perl style regular expressions, or you can adapt the reg. expressions as well based on this simple idea:


       $agent = //get user agent raw string

        if (preg_match("/BlackBerry/i", $agent)) {

            if (preg_match("/6\.0\../i", $agent)) {
                $newRelease['os_folder'] = "6.0";                
            }            
            if (preg_match("/5\.0\../i", $agent)) {
                $newRelease['os_folder'] = "5.0";                
            }
            if (preg_match("/4\.7\../i", $agent)) {
                $newRelease['os_folder'] = "4.7";
            }
            if (preg_match("/4\.6\../i", $agent)) {
                $newRelease['os_folder'] = "4.6";
            }
            if (preg_match("/4\.5\../i", $agent)) {
                $newRelease['os_folder'] = "4.5";
            }
            if (preg_match("/4\.3\../i", $agent)) {
                $newRelease['os_folder'] = "4.3";
            }
            if (preg_match("/4\.2\.1/i", $agent)) {
                $newRelease['os_folder'] = "4.2.1";
            }

            //Form your download URL here

        } else {
            //This is not BlackBerry user agent
        }

Nothing complicated, but this should give a start point to any one tying to serve appropriate bundle via OTA.

 

If you were to use S3, then it would basically be:


// The main link to S3
$downloadURL = "https://s3.amazonaws.com/YOUR_BUCKET/releases/" . $newRelease['version_folder'] . "/" . $newRelease['os_folder'] . "/YourAppName.jad";

Post your thoughts/corrections in the comments!

read more

Convert ARGB to int value (Java)

Feb 26, 2011 by

In some Java implementations/SDKs the Color class does not have the

int Color.argb(int, int, int, int)

method.

One SDK that, as far as I know, does not have this method is the BlackBerry SDK.

This code snippet can be used to perform just that:


public final class ColorBB {


    public static int argb(int A, int R, int G, int B){    
        byte[] colorByteArr = { (byte) A, (byte) R, (byte) G, (byte) B };
        return byteArrToInt(colorByteArr);
    }

   
    public static final int byteArrToInt(byte[] colorByteArr) {
        return (colorByteArr[0] << 24) + ((colorByteArr[1] & 0xFF) << 16) + ((colorByteArr[2] & 0xFF) << 8) + (colorByteArr[3] & 0xFF);
    }

}
Let me know in the comments if you have any improvement/modification ideas.

read more