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월 25일 화요일
2012년 12월 23일 일요일
2012년 12월 19일 수요일
to clear activities stack using flag
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
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월 13일 목요일
2012년 12월 12일 수요일
2012년 12월 11일 화요일
How to shut down window closing a laptop lid
Instructions
- 1Click "Start" and click "Control Panel."
- 2Click "System and Security" (for Windows Vista, this is "System and "Maintenance").
- 3Click "Power Options."
- 4Click "Choose what closing a lid does" in the "Select a power plan" page.
- 5Choose "Do nothing" from the drop-down menu for both "on battery" and "plugged in" options under the "When I close the lid" setting.
- 6Click "Save changes."
- 1
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".
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);
}
}
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));
}
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));
}
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 위치까지 추출(끝값위치의 문자는 포함하지않음)
2012년 12월 4일 화요일
how to get screen resolution on android device
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int width = displayMetrics.widthPixels;
int height = displayMetrics.heightPixels;
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();
2012년 11월 29일 목요일
How to add .0 to the end of integer
String pattern = "###.0";
DecimalFormat decimalFormat = new DecimalFormat(pattern);
decimalFormat.format(value);
How to remove day picker section on the DatePickerDialog on Android
public static void displayDatePickerDialogWithoutDaySection( Context context, final TextView datePicker) { // 날짜가 표시합니다 // 오늘 날짜를 가져옵니다 Calendar c = Calendar.getInstance(); final int cyear = c.get(Calendar.YEAR); final int cmonth = c.get(Calendar.MONTH); final int cday = c.get(Calendar.DAY_OF_MONTH); MyDatePickerDialog.OnDateSetListener mDateSetListener = new MyDatePickerDialog.OnDateSetListener() { public void onDateSet(android.widget.DatePicker view, int year, int monthOfYear, int dayOfMonth) { String date_selected = String.valueOf(year) + "-" + String.valueOf(monthOfYear + 1); datePicker.setText(date_selected); } }; MyDatePickerDialog datePickerDialog = new MyDatePickerDialog(context, mDateSetListener, cyear, cmonth, cday); datePickerDialog.show(); DatePicker dp = findDatePicker((ViewGroup) datePickerDialog.getWindow() .getDecorView()); try { Field f[] = dp.getClass().getDeclaredFields(); for (Field field : f) { if (field.getName().equals("mDaySpinner") || field.getName().equals("mDayPicker")) { field.setAccessible(true); Object dayPicker = new Object(); dayPicker = field.get(dp); ((View) dayPicker).setVisibility(View.GONE); } } } catch (SecurityException e) { Log.d("ERROR", e.getMessage()); } catch (IllegalArgumentException e) { Log.d("ERROR", e.getMessage()); } catch (IllegalAccessException e) { Log.d("ERROR", e.getMessage()); } String currentDate = String.valueOf(cyear) + "년 " + String.valueOf(cmonth + 1) + "월"; datePickerDialog.setTitle(currentDate); }
-------------------------------------------------------------------------------
<MyDatePickerDialog.java>
package kr.co.ht.smartsales.utils; import java.util.Calendar; import android.app.DatePickerDialog; import android.content.Context; import android.content.DialogInterface; import android.text.format.DateUtils; import android.widget.DatePicker; public class MyDatePickerDialog extends DatePickerDialog { public MyDatePickerDialog(Context context, OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth) { super(context, callBack, year, monthOfYear, dayOfMonth); // TODO Auto-generated constructor stub } @Override public void onDateChanged(DatePicker view, int year, int month, int day) { view.init(year, month, day, this); updateTitle(year, month, day); } private void updateTitle(int year, int month, int day) { String chosenDate = String.valueOf(year) + "년 " + String.valueOf(month + 1) + "월"; setTitle(chosenDate); } }
Re-installation failed due to different application signatures.
If you don't have the app in your device but still have that error message, remove the app using adb on the terminal.
Open the terminal(window 7) and type "adb uninstall <your app package name>".
Open the terminal(window 7) and type "adb uninstall <your app package name>".
2012년 11월 26일 월요일
No such file or directory - Cygwin
Change \ to /. For example, change "cd C:\cygwin\home\Jeonggyu\workspace\HelloAndroid\bin" to "cd C:/cygwin/home/Jeonggyu/workspace/HelloAndroid\bin" in Cygwin terminal.
NotificationCompat example
Notification noti = new NotificationCompat.Builder(this)
.setContentTitle(message).setContentText("HTSmartSales")
.setSmallIcon(R.drawable.haitai_logo).setContentIntent(pIntent)
.build();
2012년 11월 25일 일요일
stop changing color to black when scroll listView
Add android:cacheColorHint="#00000000" to listview
2012년 11월 22일 목요일
arraylist remove doesn't work
check if you put Integer in the remove method, not int. Arraylist considers Integer as object.
How to sort ArrayList, removing duplicate items
ArrayList arrayList1 = new ArrayList();
//Create a HashSet which allows no duplicates
HashSet hashSet = new HashSet(arrayList1);
//Assign the HashSet to a new ArrayList
ArrayList arrayList2 = new ArrayList(hashSet) ;
//Ensure correct order, since HashSet doesn't
Collections.sort(arrayList2);
for (Object item : arrayList2)
System.out.println(item);
//Create a HashSet which allows no duplicates
HashSet hashSet = new HashSet(arrayList1);
//Assign the HashSet to a new ArrayList
ArrayList arrayList2 = new ArrayList(hashSet) ;
//Ensure correct order, since HashSet doesn't
Collections.sort(arrayList2);
for (Object item : arrayList2)
System.out.println(item);
2012년 11월 21일 수요일
How to disable visual effects and compiz 100%
Type "metacity --replace &" and hit enter on terminal.
Eclipse hangs on loading workbench
Try the following:
- Delete your .eclipse directory in your home directory. Launch eclipse. If that doesn't work,
- Open eclipse under another user account. If it loads, you know the problem is with your account, not your eclipse installation.
- If #2 didn't work your workspace might be screwed up. Delete the .metadata folder in your localworkspace (this is what worked for me). It seems that it contains a .LOCK file that if not properly closed, prevents eclipse from starting properly.
how to install java 1.7 on ubuntu 10.04
Type the following command on terminal.
sudo apt-get install oracle-java7-installer
sudo apt-get install oracle-java7-installer
startActivityForResult
From your
FirstActivity
call the SecondActivity
using startActivityForresult()
method
eg:
Intent i = new Intent(this, SeconActivity.class);
startActivityForResult(i, 1);
In your
SecondActivity
set the data which you want to return back to FirstActivity
, If you don't want to return back don't set any.
eg: In secondActivity if you want to send back data
Intent returnIntent = new Intent();
returnIntent.putExtra("result",result);
setResult(RESULT_OK,returnIntent);
finish();
if you don't want to return data
Intent returnIntent = new Intent();
setResult(RESULT_CANCELED, returnIntent);
finish();
Now in your FirstActivity class write following code for
onActivityResult()
methodprotected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
if(resultCode == RESULT_OK){
String result=data.getStringExtra("result");
}
if (resultCode == RESULT_CANCELED) {
//Write your code on no result return
}
}//onAcrivityResult
Save ArrayList to SharedPreferences
//save the task list to preference
SharedPreferences prefs = getSharedPreferences(SHARED_PREFS_FILE, Context.MODE_PRIVATE);
Editor editor = prefs.edit();
try {
editor.putString(TASKS, ObjectSerializer.serialize(currentTasks));
} catch (IOException e) {
e.printStackTrace();
}
editor.commit();
// load tasks from preference
SharedPreferences prefs = getSharedPreferences(SHARED_PREFS_FILE, Context.MODE_PRIVATE);
try {
currentTasks = (ArrayList<task>) ObjectSerializer.deserialize(prefs.getString(TASKS, ObjectSerializer.serialize(new ArrayList<task>())));
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
You can get ObjectSerializer class from Apache Pig project ObjectSerializer.java
The following is OjectSerializer that I modified.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kr.co.ht.smartsales.utils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import org.apache.commons.logging.Log;
public class ObjectSerializer {
public static String serialize(Serializable obj) throws IOException {
if (obj == null) return "";
try {
ByteArrayOutputStream serialObj = new ByteArrayOutputStream();
ObjectOutputStream objStream = new ObjectOutputStream(serialObj);
objStream.writeObject(obj);
objStream.close();
return encodeBytes(serialObj.toByteArray());
} catch (Exception e) {
}
return null;
}
public static Object deserialize(String str) throws IOException {
if (str == null || str.length() == 0) return null;
try {
ByteArrayInputStream serialObj = new ByteArrayInputStream(decodeBytes(str));
ObjectInputStream objStream = new ObjectInputStream(serialObj);
return objStream.readObject();
} catch (Exception e) {
}
return str;
}
public static String encodeBytes(byte[] bytes) {
StringBuffer strBuf = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
strBuf.append((char) (((bytes[i] >> 4) & 0xF) + ((int) 'a')));
strBuf.append((char) (((bytes[i]) & 0xF) + ((int) 'a')));
}
return strBuf.toString();
}
public static byte[] decodeBytes(String str) {
byte[] bytes = new byte[str.length() / 2];
for (int i = 0; i < str.length(); i+=2) {
char c = str.charAt(i);
bytes[i/2] = (byte) ((c - 'a') << 4);
c = str.charAt(i+1);
bytes[i/2] += (c - 'a');
}
return bytes;
}
}
피드 구독하기:
글 (Atom)