posted by Full-stack Developer 2011. 10. 25. 09:57
Step 1. Set WebviewClient
 

Webview child = new Webview(this);

...

child.setWebViewClient(new CWebViewClient(this));

Step 2. Using PageLoding Dialog

 public class CWebViewClient extends WebViewClient {
CWebviewLoding dlg;
Context ctx;
public CWebViewClient(Context ctx) {
this.ctx=ctx;
}

@Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }

@Override
public void onPageFinished(WebView view, String url) {
if(dlg!=null && dlg.isShowing()){
dlg.dismiss();
dlg=null;
}
super.onPageFinished(view, url);
}

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
if(dlg==null){
dlg = new CWebviewLoding(ctx);
dlg.show();
}
super.onPageStarted(view, url, favicon);
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
if(dlg!=null && dlg.isShowing()){
dlg.dismiss();
dlg=null;
}
super.onReceivedError(view, errorCode, description, failingUrl);
}
}

Do u wanna  custom indeterminate progressbar?
 
here is  http://codedb.tistory.com/entry/Android-custom-indeterminate-progressbar

 

안녕하세요 ^^
설명을 조금 해보겠습니다. ㅎ
웹뷰에 페이지로딩할때 페이지로딩 시작,마침 시점에 다이얼로그를 삽입해
사용자에게 '아 먼가 돌아가고 있나보군!' 이라는 생각이 들게 만들려고 만든건데요

웹뷰에 setWebViewClient으로 Webviewclient를 세팅해주셔야해요.
그러려면 WebViewClient를 만들어야겠죠?

step2에서 보듯이 만드시면되요 잘보시면 dlg라고 커스텀한 다이얼로그가 있는데요
웹뷰 페이지로딩 시작과 종료시점에 show, dismiss를 해주시면 페이지가 로딩될때
잘 동작하겠죠 혹여나 error가 날때를 대비해서 에러나면 dismiss해주는것도 좋을듯
싶어요.

혹시 가운데 동글동글 돌아가는 다이얼로그가 필요하시나요?
아래 경로로가시면 커스텀한 다이얼로그 예제가 있답니닷!!
http://codedb.tistory.com/entry/Android-custom-indeterminate-progressbar

많은 도움이 되셨기를 빕니다.

즐코딩! 낫빡침!
 

posted by Full-stack Developer 2011. 10. 12. 18:21
Step 1. Create CustomButton.xml
res/drawable/custombtn.xml <- create custombtn.xml

 <?xml version="1.0" encoding="utf-8"?> 
<selector  xmlns:android="http://schemas.android.com/apk/res/android">
<item 
    android:state_pressed="false"
    android:drawable="@drawable/bu4_searchall"/>
<item 
    android:drawable="@drawable/bu4_searchall_o"/>
</selector> 

Step 2. To Use 
-ex)res/layout/main.xml 
...
<ImageView
android:src="@drawable/custombtn"
android:id="@+id/main_pressedimgtest_iv" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
/> 
... 

Step 3. SetOnClickListener
-user source  ex)src/com.xxx.xxx/main.java
...
 ImageView custombtn = (ImageView)findViewById(R.id.main_pressedimgtest_iv);
 custombtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
... 

안녕하세요 ^^
설명을 해드릴까 합니다.

이건 하단 컨트롤바같은 UI를 만들때 사용자가 press할때 이미지를 변경해주는 방법이에요.
사용자에게 터치감을 주기위해서 사용했습니다.

방법은 우선 버튼의 Step1처럼 버튼 누를시 이미지 변경되게 구현하구요
Step2에서 구현한 커스텀UI를 적용해요  Step2에 노란색 부분을 보시면 알수있겠죠?
Step3에서 클릭이벤트를 설정해줘야 press를 하겠죠?

도움되셧길 바랍니다. ㅎ

즐코딩! 낫빡침! 

 
posted by Full-stack Developer 2011. 10. 11. 14:14
TextView customview = new TextView(ctx);
customview.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,                                                                   LayoutParams.WRAP_CONTENT));
Bitmap src = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.and_pop);
src= Bitmap.createScaledBitmap(src, 600, 50,true);
customview.setBackgroundDrawable( new BitmapDrawable(src));

customview.setText(msg.getData().getCharSequence("data"));
customview.setGravity(Gravity.CENTER_VERTICAL);
customview.setPadding(100, 10, 0, 0);

Toast custo = new Toast(ctx);
custo.setView(customview);//insert u r custom view
custo.setGravity(Gravity.CENTER_VERTICAL, 10, 10);
custo.setDuration(Toast.LENGTH_LONG);
custo.show();


안녕하세요 ^^
잠시 설명을 해볼까 합니다.

Toast를 커스텀하는것인데요.
동적으로 원하시는 UI로 구현하시고 혹은 xml로 UI구현하신걸 사용하셔도 무방하구요.
중요한부분은 그렇게 생성한 View를 Toast에 setView를 해주시면 끗!


노란색부분처럼 하시면 되요!

도움되셧길 바랍니다.

즐코딩! 낫빡침! 

 
posted by Full-stack Developer 2011. 10. 5. 17:44
Step 1.create  CustomViewer.java  and custom!

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.Scroller;


public class CustomViewer extends ViewGroup {
private Scroller mScroller;
private VelocityTracker mVelocityTracker;
 private int mScrollX = 0;
private int mCurrentScreen = 0;//현제 창의 위치
 private float mLastMotionX;
 private static final String LOG_TAG = "FlingAndScrollViewer";
 private static final int SNAP_VELOCITY = 1000;//속도
 private final static int TOUCH_STATE_REST = 0;
private final static int TOUCH_STATE_SCROLLING = 1;
 private int mTouchState = TOUCH_STATE_REST;
 private int mTouchSlop = 0;
 public CustomViewer(Context context) {
    super(context);
    mScroller = new Scroller(context);
     mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
     this.setLayoutParams(new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.FILL_PARENT));
}
 public CustomViewer(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = getContext().obtainStyledAttributes(attrs,
            R.styleable.FlingAndScrollViewer);
    mCurrentScreen = a.getInteger(
            R.styleable.FlingAndScrollViewer_default_screen, 0);
     mScroller = new Scroller(context);
     mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
     this.setLayoutParams(new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.FILL_PARENT));
 }
 public void setInitialPosition(int initialPosition){
    mCurrentScreen = initialPosition;
}
 @Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    /*
     * This method JUST determines whether we want to intercept the motion.
     * If we return true, onTouchEvent will be called and we do the actual
     * scrolling there.
     */
     /*
     * Shortcut the most recurring case: the user is in the dragging state
     * and he is moving his finger. We want to intercept this motion.
     */
    final int action = ev.getAction();
    if ((action == MotionEvent.ACTION_MOVE)
            && (mTouchState != TOUCH_STATE_REST)) {
        return true;
    }
     final float x = ev.getX();
     switch (action) {
    case MotionEvent.ACTION_MOVE:
        /*
         * mIsBeingDragged == false, otherwise the shortcut would have
         * caught it. Check whether the user has moved far enough from his
         * original down touch.
         */
         /*
         * Locally do absolute value. mLastMotionX is set to the y value of
         * the down event.
         */
        final int xDiff = (int) Math.abs(x - mLastMotionX);
         boolean xMoved = xDiff > mTouchSlop;
         if (xMoved) {
            // Scroll if the user moved far enough along the X axis
            mTouchState = TOUCH_STATE_SCROLLING;
        }
        break;
     case MotionEvent.ACTION_DOWN:
        // Remember location of down touch
        mLastMotionX = x;
         /*
         * If being flinged and user touches the screen, initiate drag;
         * otherwise don't. mScroller.isFinished should be false when being
         * flinged.
         */
        mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST
                : TOUCH_STATE_SCROLLING;
        break;
     case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        // Release the drag
        mTouchState = TOUCH_STATE_REST;
        break;
    }
     /*
     * The only time we want to intercept motion events is if we are in the
     * drag mode.
     */
    return mTouchState != TOUCH_STATE_REST;
}
 @Override
public boolean onTouchEvent(MotionEvent event) {
     if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(event);
     final int action = event.getAction();
    final float x = event.getX();
     switch (action) {
    case MotionEvent.ACTION_DOWN:
        Log.i(LOG_TAG, "event : down");
        /*
         * If being flinged and user touches, stop the fling. isFinished
         * will be false if being flinged.
         */
        if (!mScroller.isFinished()) {
            mScroller.abortAnimation();
        }
         // Remember where the motion event started
        mLastMotionX = x;
        break;
    case MotionEvent.ACTION_MOVE:
        // Log.i(LOG_TAG,"event : move");
        // if (mTouchState == TOUCH_STATE_SCROLLING) {
        // Scroll to follow the motion event
        final int deltaX = (int) (mLastMotionX - x);
        mLastMotionX = x;
         // Log.i(LOG_TAG, "event : move, deltaX " + deltaX + ", mScrollX " +
        // mScrollX);
         if (deltaX < 0) {
            if (mScrollX > 0) {
                scrollBy(Math.max(-mScrollX, deltaX), 0);
            }
        } else if (deltaX > 0) {
            final int availableToScroll = getChildAt(getChildCount() - 1)
                    .getRight() - mScrollX - getWidth();
            if (availableToScroll > 0) {
                scrollBy(Math.min(availableToScroll, deltaX), 0);
            }
        }
        // }
        break;
    case MotionEvent.ACTION_UP:
        Log.i(LOG_TAG, "event : up");
        // if (mTouchState == TOUCH_STATE_SCROLLING) {
        final VelocityTracker velocityTracker = mVelocityTracker;
        velocityTracker.computeCurrentVelocity(1000);
        int velocityX = (int) velocityTracker.getXVelocity();
         if (velocityX > SNAP_VELOCITY && mCurrentScreen > 0) {
            // Fling hard enough to move left
            snapToScreen(mCurrentScreen - 1);
        } else if (velocityX < -SNAP_VELOCITY
                && mCurrentScreen < getChildCount() - 1) {
            // Fling hard enough to move right
            snapToScreen(mCurrentScreen + 1);
        } else {
            snapToDestination();
        }
         if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        // }
        mTouchState = TOUCH_STATE_REST;
        break;
    case MotionEvent.ACTION_CANCEL:
        Log.i(LOG_TAG, "event : cancel");
        mTouchState = TOUCH_STATE_REST;
    }
    mScrollX = this.getScrollX();
     return true;
}
 private void snapToDestination() {
    final int screenWidth = getWidth();
    final int whichScreen = (mScrollX + (screenWidth / 2)) / screenWidth;
    Log.i(LOG_TAG, "from des");
    snapToScreen(whichScreen);
}
 public void snapToScreen(int whichScreen) {
    Log.i(LOG_TAG, "snap To Screen " + whichScreen);
    mCurrentScreen = whichScreen;
    final int newX = whichScreen * getWidth();
    final int delta = newX - mScrollX;
    mScroller.startScroll(mScrollX, 0, delta, 0, Math.abs(delta) * 2);
    invalidate();
}
 public void setToScreen(int whichScreen) {
    Log.i(LOG_TAG, "set To Screen " + whichScreen);
    mCurrentScreen = whichScreen;
    final int newX = whichScreen * getWidth();
    mScroller.startScroll(newX, 0, 0, 0, 10);
    invalidate();
}
 @Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int childLeft = 0;
     final int count = getChildCount();
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != View.GONE) {
            final int childWidth = child.getMeasuredWidth();
            child.layout(childLeft, 0, childLeft + childWidth,
                    child.getMeasuredHeight());
            childLeft += childWidth;
        }
    }
 }
 @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
     final int width = MeasureSpec.getSize(widthMeasureSpec);
    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    if (widthMode != MeasureSpec.EXACTLY) {
        throw new IllegalStateException("error mode.");
    }
     final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    if (heightMode != MeasureSpec.EXACTLY) {
        throw new IllegalStateException("error mode.");
    }
     // The children are given the same width and height as the workspace
    final int count = getChildCount();
    for (int i = 0; i < count; i++) {
        getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec);
    }
    Log.i(LOG_TAG, "moving to screen " + mCurrentScreen);
    scrollTo(mCurrentScreen * width, 0);
}
 @Override
public void computeScroll() {
    if (mScroller.computeScrollOffset()) {
        mScrollX = mScroller.getCurrX();
        scrollTo(mScrollX, 0);
        postInvalidate();
    }
}
 /**
 * Return the parceable instance to be saved
 */
@Override
protected Parcelable onSaveInstanceState() {
    final SavedState state = new SavedState(super.onSaveInstanceState());
    state.currentScreen = mCurrentScreen;
    return state;
}
 /**
 * Restore the previous saved current screen
 */
@Override
protected void onRestoreInstanceState(Parcelable state) {
    SavedState savedState = (SavedState) state;
    super.onRestoreInstanceState(savedState.getSuperState());
    if (savedState.currentScreen != -1) {
        mCurrentScreen = savedState.currentScreen;
    }
}
 // ========================= INNER CLASSES ==============================
 public interface onViewChangedEvent {
    void onViewChange(int currentViewIndex);
}
 /**
 * A SavedState which save and load the current screen
 */
public static class SavedState extends BaseSavedState {
    int currentScreen = -1;
     /**
     * Internal constructor
     *
     * @param superState
     */
    SavedState(Parcelable superState) {
        super(superState);
    }
     /**
     * Private constructor
     *
     * @param in
     */
    private SavedState(Parcel in) {
        super(in);
        currentScreen = in.readInt();
    }
     /**
     * Save the current screen
     */
    @Override
    public void writeToParcel(Parcel out, int flags) {
        super.writeToParcel(out, flags);
        out.writeInt(currentScreen);
    }
     /**
     * Return a Parcelable creator
     */
    public static final Parcelable.Creator<SavedState> CREATOR = new Parcelable.Creator<SavedState>() {
        public SavedState createFromParcel(Parcel in) {
            return new SavedState(in);
        }
         public SavedState[] newArray(int size) {
            return new SavedState[size];
        }
    };
}

--------------------------------------------------------------------------------
Step 2. Add attrs
add res/values/attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="CustomViewer">
        <attr name="default_screen" format="integer"/>
    </declare-styleable>
</resources> 
--------------------------------------------------------------------------------
Step 3. Use u r layout!
ex)res/layout/main.xml 
<com.xxxx.xxxx.CustomViewer
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:id="@+id/flingScrollViewer"/> 

안녕하세요 ^^
설명을 조금 해보겠습니다.

이 커스텀 UI를 사용하면 폰에서 홈스크린처럼 다음페이지,현제페이지, 전페이지를 스크롤 이동하면 모두보이는 기능입니다. 말이좀 이상한가요?
홈스크린이나 포토 갤러리와 같은 layout이라는 것입니다.

fling할때 가속도와 horizental scroll을 적절히 사용되었습니다.

도움되셧길 바랍니다.

즐코딩! 낫빡침! 

 
posted by Full-stack Developer 2011. 10. 5. 17:18
public class CustomDialog extends Dialog implements android.view.View.OnClickListener{
CustomDialog dlg;
public CustomDialog(Context context) {
super(context);
getWindow().setBackgroundDrawableResource(R.drawable.img_background);
setContentView(R.layout.customdialog);
dlg=this;
Button closeBtn =(Button)findViewById(R.id.customedlg_close_btn);
closeBtn.setOnClickListener(this);
}

@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.customedlg_close_btn:
dlg.dismiss();
break;
}
}

}

안녕하세요 ^^
설명을 해볼까해요 ㅎ
커스텀으로 Dialog를 구현했을 시
배경화면을 변경하고 싶으시겠죠?
그때 위의 노란색 부분과같이 이미지변경을 하시거나
색을 변경하시거나 혹은 투명하게(Colors.TRANSPARENT) 만드실 수 있어요!

도움되셨길 바랍니다.

즐코딩! 낫빡침! 

 
posted by Full-stack Developer 2011. 10. 5. 17:15
1.
<CheckBox
android:id="@+id/setting_idsave_cb"
android:button="@drawable/checkbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="아이디저장"
android:textColor="#9b9d9d"
android:textSize="16px"
android:paddingRight="35px"/>

2.
dir is.. res/drawable/checkbtn.xml

<?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item 
        android:state_checked="true"
        android:drawable="@drawable/img_checked" />
    <item
        android:drawable="@drawable/img_check" />
</selecto 
 

안녕하세요 ^^
설명을 해보겠습니다!

사용방법은 1번과같이 button을 커스텀한 checkbox로 세팅해주시면됩니다.
2과같이 체그될때 이미지, 체크안될을때 이미지를 설정해주시면 끗!

도움되셧길 바랍니다 ㅎ

즐코딩! 낫빡침! 

 
posted by Full-stack Developer 2011. 10. 5. 16:52
1.
<RadioButton
android:id="@+id/setting_p_rb"
android:button="@drawable/radiobtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="개인회원 "
android:textColor="#9b9d9d"
android:textSize="16px"
android:layout_marginBottom="5px"
android:layout_marginTop="2px"
android:paddingRight="47px"/> 

2.
dir is .. res/drawable/radiobtn.xml

<?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item 
        android:state_checked="true"
        android:drawable="@drawable/i_radio_ch" />
    <item
        android:drawable="@drawable/i_radio" />
</selector> 

ch -> checked 

안녕하세요 ^^
설명을 잠시 해보겠어요.
CheckBox와 같은 방식으로 2번처럼 커스텀한 UI 1번처럼 button에 UI를 세팅해주시면 됩니다.

도움되셧길 바랍니다 ㅎ

즐코딩! 낫빡침! 

 
posted by Full-stack Developer 2011. 10. 5. 16:33
1.
<ProgressBar
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:paddingTop="20px"
  android:indeterminateDrawable="@drawable/loadingspin"
  android:animationResolution="1"
  />

 2.
dir is .. res/drawable/loadingspin.xml

<?xml version="1.0" encoding="utf-8"?>
 <layer-list  xmlns:android="http://schemas.android.com/apk/res/android">
 <item>
  <rotate 
  android:drawable="@drawable/loading" ------------------------------↘


  android:pivotX="50%"
  android:pivotY="50%"
  android:fromDegrees="0"
  android:toDegrees="1080"
/>
  </item>
  </layer-list>

 

안녕하세요 ^^
잠시 설명을 해보겟습니다.

2번처럼 UI를 xml를 구현해주세요. drawable에 원하시는 png로 되있는 로딩 이미지를
세팅해주시고
1번처럼 indeterminateDrawable에 구현한 UI를 세팅해주시면 됩니다.

도움되셨으면 좋겠네요 ㅎ

즐코딩! 낫빡침!