Archive for the ‘Uncategorized’ Category

Java bitwise operators

December 25, 2011

This is a code snippet found in android.widget.AutoCompleteTextView class:

        // Always turn on the auto complete input type flag, since it
        // makes no sense to use this widget without it.
        int inputType = getInputType();
        if ((inputType&EditorInfo.TYPE_MASK_CLASS)
                == EditorInfo.TYPE_CLASS_TEXT) {
            inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE;
            setRawInputType(inputType);
        }

Here is what I found out: Java Notes: Bitwise Operators

System.out.println("3 & 7 = "+(3 & 7));//3
System.out.println("2 & 4 = "+(2 & 4));//0
System.out.println("2 & 5 = "+(2 & 5));//0
System.out.println("1 & 2 = "+(1 & 2));//0
System.out.println("1 & 0 = "+(1 & 0));//0

System.out.println("3 | 7 = "+(3 | 7));//7
System.out.println("2 | 4 = "+(2 | 4));//6
System.out.println("2 | 5 = "+(2 | 5));//7
System.out.println("1 | 2 = "+(1 | 2));//3
System.out.println("1 | 0 = "+(1 | 0));//1

Advertisements

“There are no active mixer devices…”

May 19, 2010

1. Go to Start –> Run, and type in “services.msc”.

2. Start “Windows Audio”.

Here.

Building mix-up custom Android component/widget using Java class and XML layout

August 27, 2009

A lot of times you would find it convenient to just create “compound components” or what Commons guy called “meta” widgets.These widgets are compositions of other widgets. Most of the work involved would be to layout those compound components, bind data and wire up controls. For the layout part, it’s convenient to just use mixture of a Java class and a corresponding xml layout file, as opposed to using a pure Java class. Here is how:

1. Create the Java class. It usually extends a Layout class such as a LinearLayout or a RelativeLayout.  You have to define a constructor in the flavor of

public MyHomeBrewedComp(Context context, AttributeSet attr)

If you just use "public MyHomeBrewedComp(Context context)“,  you would get an “java.lang.NoSuchMethodException" error from Console and a “android.view.InflateException: Binary XML file line #nnn: Error inflating class com.mh.android.test.MyHomeBrewedComp" from CatLog at runtime.

2. Create the corresponding xml layout file under the package “res/layout” folder.  This is the xml version of your Java class, which means the root node should be the identical class to your Java class.

3. Layout compound widgets in your enclosing widget. If you are doing layout in the xml file, you will then have to inflate the xml in your java file programmatically. You do this by overriding the widget’s onFinishInflate () method.

@Override
protected void onFinishInflate(){
super.onFinishInflate();
((Activity)getContext()).getLayoutInflater().inflate(R.layout.myhomebrewedComp, this);
//other code comes here, such as wiring up controls
...
}

4. TODO: setting up attributes in the custom widget

5.  Using the widget in XML.  First of all you will need a new namespace when you refer to any property/attribute in your widget; second you have to use the full-qualified class name in the xml file. Here is a sample:

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout
xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
xmlns:app=”http://schemas.android.com/apk/res/com.mh.android.test&#8221;
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>

<com.mh.android.test.MyHomeBrewedComp
android:id=”@+id/panel”
app:velocity=”30″
app: friction=”.7f”
android:orientation=”horizontal”
android:layout_width=”fill_parent”
android:layout_height=”75px”
android:layout_alignParentTop=”true”
/>

</RelativeLayout>

Code snippet: clamp value into a range

April 24, 2009

var myVal:Number = Math.max(USER_MIN,  Math.min(USER_MAX, calculateMyDesiredValue());

Inspired by Ely Greenfield. (Note: “Inspired” is an elegent way of saying “copy”.)

firefox shortcut keys

June 24, 2008

firefox shortcut keys

Firefox Keyboard and Mouse Shortcuts

Firefox search box type-suggest/autocomplete

June 23, 2008

Firefox addressbar: “about:config” -> double click “browser.search.suggest.enabled” to toggle the setting

Set Reply-To in pine

March 24, 2008

1.  Main menu->S (Set-up)

2.  C (Config)

3.  Shift-W (Search for “customized-hdrs”)

4. C (to set values. Each field should be separated by comma [,] like this “From: me@somewhere.com, Reply-To:me@here.com”

5. Return to  accept. E to exit.

long/double slash hypen

September 1, 2006

alt-shift-hypen(-) will produce “—”.

Hello world!

April 26, 2006

Welcome to WordPress.com. This is my first post. Edit or delete it and start blogging!