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

Java code to work with MillennialMedia, SMAATO and NexAge web advertising APIs

Dec 18, 2010 by

I wrote yesterday about my (mostly) negative experience working with these companies, but some of you might give it a try and maybe your results will be much better or maybe things have actually improved lately. In any case, the code here should get you up to speed covering most of the dirty work of working with these companies’ APIs.

I will post 4 classes here:

  • AdGrabber -  main abstract class to give all other specific grabbers structure and save some repeating code
  • MillenialAdGrabber - MillennialMedia specific grabber
  • NexAgeAdGrabber - right, NexAge specific grabber
  • SomaAdGrabber - the SMAATO ad grabber. Their ad platform is dubbed SOMA, hence the name

If you are using this code, please give an attribution when applicable with a link to this post.

read more