2012년 12월 27일 목요일

current should be >= start and <= end

you must have changed mYear, mMonth, mDay values. months are 0-11. make sure your values are in the range

write label on overlayItem


package kr.co.ht.smartsales.map;

import kr.co.ht.smartsales.R;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.view.View.MeasureSpec;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.OverlayItem;

public class CustomItem extends OverlayItem{
// text we want to overlay on top of our marker
// for trulia this is going to be the price of the property
private String label;

// this is the marker we will send back to the Overlay to use when
// drawing
private StateListDrawable marker = null;

// this framelayout holds the view we will be turning into a drawable
private FrameLayout markerLayout;

// since we are going to use a StateListDrawable we will need to access
// a few of the state values from android
private int stateSelected = android.R.attr.state_selected;
private int statePressed = android.R.attr.state_pressed;
private int stateFocused = android.R.attr.state_focused;

// we need a Context and Resource objects to pull in the marker
// drawables
private Context context;
private Resources res;

// these are the resource ids for the two differnt marker states
private static final int MARKER_DRAWABLE_UNVIEWED = R.drawable.balloon_overlay_unfocused;
private static final int MARKER_DRAWABLE_SELECTED = R.drawable.balloon_overlay_focused;

// Constructor which besides a GeoPoint, laben and snippet also gets
// pass
// our
// marker frame layout as well as the current application context
public CustomItem(GeoPoint pt, String label, String snippet,
FrameLayout markerLayout, Context context) {
super(pt, label, snippet);

// set our class vars
this.markerLayout = markerLayout;
this.label = label;
this.context = context;
this.res = context.getResources();

// now generate the state list drawable
this.marker = generateStateListDrawable();
}

// main function where we create our Drawable by using the marker
// layout,
// adding our string label, then converting to a bitmap drawable
@TargetApi(4)
public Drawable generateMarker(boolean selected) {

Bitmap viewCapture = null;
Drawable drawOverlay = null;

// make sure our marker layout isn't null
if (markerLayout != null) {

// set the text string into the view before we turn it into an
// image
TextView textView = (TextView) markerLayout
.findViewById(R.id.text);
textView.setText(label);

// calling setBackgroundResource seems to overwrite our padding
// in
// the layout;
// the following is a hack i found in this google bug report;
// fixes
// gravity issue as well
// http://code.google.com/p/android/issues/detail?id=17885
int paddingTop = textView.getPaddingTop();
int paddingLeft = textView.getPaddingLeft();
int paddingRight = textView.getPaddingRight();
int paddingBottom = textView.getPaddingBottom();

// set the background bubble image based on whether its selected
// or
// not
if (selected) {
textView.setBackgroundResource(MARKER_DRAWABLE_SELECTED);
} else {
textView.setBackgroundResource(MARKER_DRAWABLE_UNVIEWED);
}

// part of the hack above to reset the padding specified in the
// marker layout
textView.setPadding(paddingLeft, paddingTop, paddingRight,
paddingBottom);

// we need to enable the drawing cache
markerLayout.setDrawingCacheEnabled(true);

// this is the important code
// Without it the view will have a dimension of 0,0 and the
// bitmap
// will be null
markerLayout
.measure(MeasureSpec.makeMeasureSpec(0,
MeasureSpec.UNSPECIFIED), MeasureSpec
.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
markerLayout.layout(0, 0, markerLayout.getMeasuredWidth(),
markerLayout.getMeasuredHeight());

// we need to build our drawing cache
markerLayout.buildDrawingCache(true);

// not null? then we are ready to capture our bitmap image
if (markerLayout.getDrawingCache() != null) {
viewCapture = Bitmap.createBitmap(markerLayout
.getDrawingCache());

// if the view capture is not null we should turn off the
// drawing cache
// and then create our marker drawable with the view capture
if (viewCapture != null) {
markerLayout.setDrawingCacheEnabled(false);
drawOverlay = new BitmapDrawable(viewCapture);
return drawOverlay;
}
} else {

}
}
return null;
}

/*
* (copied from the Google API docs) Sets the state of a drawable to
* match a given state bitset. This is done by converting the state
* bitset bits into a state set of R.attr.state_pressed,
* R.attr.state_selected and R.attr.state_focused attributes, and then
* calling {@link Drawable.setState(int[])}.
*/
// @Override
// public static void setState(final Drawable drawable, final int
// stateBitset) {
// final int[] states = new int[3];
// int index = 0;
// if ((stateBitset & ITEM_STATE_PRESSED_MASK) > 0)
// states[index++] = android.R.attr.state_pressed;
// if ((stateBitset & ITEM_STATE_SELECTED_MASK) > 0)
// states[index++] = android.R.attr.state_selected;
// if ((stateBitset & ITEM_STATE_FOCUSED_MASK) > 0)
// states[index++] = android.R.attr.state_focused;
//
// drawable.setState(states);
// }

@Override
public StateListDrawable getMarker(int stateBitset) {

if (marker == null)
return null;

setState((Drawable) marker, stateBitset);
//원래 코드입니다
//marker.setBounds(0, 0, marker.getIntrinsicWidth(),
// marker.getIntrinsicHeight());

//테스트입니다
int dWidth = marker.getIntrinsicWidth();
int dHeight = marker.getIntrinsicHeight();
marker.setBounds(-dWidth / 2, -dHeight, dWidth / 2, 0);
return (marker);
}

public Drawable getDefaultMarker() {
if (marker == null)
marker = generateStateListDrawable();

return marker;
}

// We create our statelist drawable by setting various states and the
// marker
// to be displayed by that state;
// the generateMarker() function takes in whether the drawable is
// selected
// or not selected
private StateListDrawable generateStateListDrawable() {
StateListDrawable drawables = new StateListDrawable();
drawables.addState(new int[] { stateSelected },
generateMarker(true));
drawables
.addState(new int[] { statePressed }, generateMarker(true));
drawables
.addState(new int[] { stateFocused }, generateMarker(true));
drawables.addState(new int[] {}, generateMarker(false));
return drawables;
}
}

how to to boundCenterBottom with setBounds


int dWidth = drawable.getIntrinsicWidth();
int dHeight = drawable.getIntrinsicHeight();
drawable.setBounds(-dWidth / 2, -dHeight, dWidth / 2, 0);

2012년 12월 19일 수요일

2012년 12월 14일 금요일

if onClick does not be called

You did everythiing, but still onClick does not be called, Try cleaning your project.

2012년 12월 12일 수요일

2012년 12월 11일 화요일

How to shut down window closing a laptop lid


Instructions

    • 1
      Click "Start" and click "Control Panel."
    • 2
      Click "System and Security" (for Windows Vista, this is "System and "Maintenance").
    • 3
      Click "Power Options."
    • 4
      Click "Choose what closing a lid does" in the "Select a power plan" page.
    • 5
      Choose "Do nothing" from the drop-down menu for both "on battery" and "plugged in" options under the "When I close the lid" setting.
    • 6
      Click "Save changes."

nine patch 1 px border visible

Use draw9patch tool in android sdk, not graphic software like Photoshop.

Draw line holding left mouse button, not with control key. Erase line holding right mouse button, not with shift key.

I don't know why a android programmer displayed a confusing message on the top: "Press Shift to erase pixels. Press Control to draw layout bounds".

2012년 12월 6일 목요일

convert double to int


Double max;

.

int tempValue = (int) Math.round(max);


int tempValue = (int) max <-- not working

how to get the max value in arraylist

for(int i=0; i < arrayList.size(); i++) { 
if (arrayList.get(i) > max) { 
max = arrayList.get(i); 

}

how to convert 149 to 200 in java

String testValue = "149";

getMaxValue(testValue);
.
.
.

private static int getMaxValue(String value) {
double maxValue = Double.parseDouble(value);
int digitNumber = value.length();
return (int) ((int) (Math.ceil(maxValue / Math.pow(10, digitNumber-1))) *        Math.pow(10, digitNumber-1));

}

how to get number of digits in a int


int length = String.valueOf(value).length();

2012년 12월 5일 수요일

how to put double in Geopoint as a parameter


GeoPoint gp = new GeoPoint((int)(37.484203*1000000.0),                                      (int)(126.929699*1000000.0));


!! you should multifly 1E6(1000000) !!

split string with substring

String str = "goodmorning-kil-dong"


String s1 = str.substring(12) ; // kil-dong // 시작값만 주어지면 그 위치부터 끝까지 추출
String s2 = str.substring(12,15); //kil // 시작값위치부터 끝값-1 위치까지 추출(끝값위치의 문자는 포함하지않음)

if android device goes offline often when debugging

plug usb cable in other usb port.

2012년 12월 4일 화요일

if korean characters are not shown on GCM

url encode korean characters on server side

how to get screen resolution on android device

DisplayMetrics displayMetrics = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); 
    
int width = displayMetrics.widthPixels; 
int height = displayMetrics.heightPixels;

2012년 12월 3일 월요일

android textview marquee animation


TextView tv = (TextView)findViewById(R.id.someTextView);
tv.setSelected(true);
tv.setEllipsize(TruncateAt.MARQUEE);
tv.setSingleLine(true):

The key must be an application-specific resource id

When I use setTag(int, object), I got the above error. I put integer in the parameter. I defined a string in the strings.xml, and put R.string.<string name>. It worked!!

a field variable and a parameter with same name

They have a same name, but they are totally different. Parameter variable is initialized(int variable is 0) if any value is not passed to it.

how to remove all spaces in front of and behind a string


String temp = " abc " ; 
temp = temp.trim();