code
stringlengths
23
201k
docstring
stringlengths
17
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
72
path
stringlengths
11
317
url
stringlengths
57
377
license
stringclasses
7 values
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.save(); canvas.rotate(count, centerX, centerY); for (int i = 0; i < CIRCLE_COUNT; i++) { canvas.drawCircle(centerX + offsetX, centerY, radiusArray[i], paint); canvas.rotate(40, centerX, centerY); } canvas.restore(); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/3/17
onDraw
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlCircleLoadView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlCircleLoadView.java
Apache-2.0
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); exit = false; startAnimation(); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/3/17
onAttachedToWindow
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlCircleLoadView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlCircleLoadView.java
Apache-2.0
@Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); exit = true; handler.removeCallbacksAndMessages(null); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/3/17
onDetachedFromWindow
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlCircleLoadView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlCircleLoadView.java
Apache-2.0
private void startAnimation() { handler.post(new AnimationRunnable(this)); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/3/17
startAnimation
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlCircleLoadView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlCircleLoadView.java
Apache-2.0
private int dip2px(float dpValue) { return (int) (dpValue * getResources().getDisplayMetrics().density + 0.5f); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/3/17
dip2px
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlCircleLoadView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlCircleLoadView.java
Apache-2.0
@Override public void run() { WlCircleLoadView view = viewRef.get(); if (view == null || view.exit) return; view.count = (view.count + 5) % 360; view.invalidate(); view.handler.postDelayed(this, FRAME_DELAY); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/3/17
run
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlCircleLoadView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlCircleLoadView.java
Apache-2.0
public void setBgHeight(int bgheight) { if (bgheight <= 0) { return; } this.w_bg = dip2px(getContext(), bgheight); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/8/18
setBgHeight
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
Apache-2.0
public void setThumbRadius(int radius) { if (radius <= 0) { return; } this.radius = dip2px(getContext(), radius); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/8/18
setThumbRadius
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
Apache-2.0
public void setColorBg(int color) { color_bg = getResources().getColor(color); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/8/18
setColorBg
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
Apache-2.0
public void setColorBuffer(int colorBuffer) { color_buffer = getResources().getColor(colorBuffer); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/8/18
setColorBuffer
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
Apache-2.0
public void setColorProgress(int color) { color_progress = getResources().getColor(color); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/8/18
setColorProgress
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
Apache-2.0
public void setColorThumbNormal(int color) { color_thumb_normal = getResources().getColor(color); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/8/18
setColorThumbNormal
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
Apache-2.0
public void setColorThumbTouch(int color) { color_thumb_touch = getResources().getColor(color); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/8/18
setColorThumbTouch
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
Apache-2.0
public void setOnWlSeekBarChangeListener(OnWlSeekBarChangeListener onWlSeekBarChangeListener) { this.onWlSeekBarChangeListener = onWlSeekBarChangeListener; }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/8/18
setOnWlSeekBarChangeListener
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
Apache-2.0
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); width = getMeasuredWidth(); height = getMeasuredHeight(); top = (height - w_bg) / 2; bottom = (height - w_bg) / 2 + w_bg; cy = height / 2; if (rectF == null) { rectF = new RectF(0, top, width, bottom); } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/8/18
onMeasure
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
Apache-2.0
@Override public boolean onTouchEvent(MotionEvent event) { synchronized (syncAction) { int action = event.getAction(); touch = true; switch (action) { case MotionEvent.ACTION_DOWN: moveX = event.getX(); setProgressInner(moveX / width); if (onWlSeekBarChangeListener != null) { onWlSeekBarChangeListener.onStart(progress); } case MotionEvent.ACTION_MOVE: moveX = event.getX(); setProgressInner(moveX / width); if (onWlSeekBarChangeListener != null) { onWlSeekBarChangeListener.onMove(progress); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: moveX = event.getX(); setProgressInner(moveX / width); if (onWlSeekBarChangeListener != null) { onWlSeekBarChangeListener.onEnd(progress); } touch = false; break; } return true; } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/8/18
onTouchEvent
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
Apache-2.0
public void setRound(boolean isRound) { this.isRound = isRound; invalidate(); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/8/18
setRound
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
Apache-2.0
public void setProgress(double progress) { setProgress(progress, progress_buffer); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/8/18
setProgress
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
Apache-2.0
public void setProgress(double progress, double progress_buffer) { synchronized (syncAction) { if (!touch) { setProgressInner(progress, progress_buffer); } } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/8/18
setProgress
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
Apache-2.0
private void setProgressInner(double progress) { setProgressInner(progress, progress_buffer); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/8/18
setProgressInner
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
Apache-2.0
private synchronized void setProgressInner(double progress, double progress_buffer) { if (progress < 0f) { progress = 0f; } if (progress > 1f) { progress = 1f; } if (progress_buffer < 0f) { progress_buffer = 0f; } if (progress_buffer > 1f) { progress_buffer = 1f; } this.progress_buffer = (float) progress_buffer; this.progress = (float) progress; invalidate(); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/8/18
setProgressInner
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
Apache-2.0
public static int dip2px(Context context, float dipValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dipValue * scale + 0.5f); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/8/18
dip2px
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSeekBar.java
Apache-2.0
public void setWlPlayer(WlPlayer wlPlayer) { this.wlPlayer = wlPlayer; }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/1/24
setWlPlayer
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
Apache-2.0
public void setWlPlayer(WlPlayer wlPlayer, String rgba) { this.wlPlayer = wlPlayer; if (WlColorUtil.isRGBAColor(rgba)) { this.rgba = rgba; } else { this.rgba = "#000000FF"; } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/1/24
setWlPlayer
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
Apache-2.0
public void setAlphaVideoType(WlAlphaVideoType alphaVideoType) { if (wlPlayer == null) { return; } if (alphaVideoType == WlAlphaVideoType.WL_ALPHA_VIDEO_DEFAULT) { setZOrderOnTop(false); } else { setZOrderOnTop(true); } this.wlPlayer.setAlphaVideoType(alphaVideoType); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/1/24
setAlphaVideoType
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
Apache-2.0
public void setVideoScale(WlScaleType scaleType) { if (wlPlayer != null) { wlPlayer.setVideoScale(getUniqueNum(), scaleType); } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/1/24
setVideoScale
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
Apache-2.0
public void setVideoScale(int scaleWidth, int scaleHeight) { if (wlPlayer != null) { wlPlayer.setVideoScale(getUniqueNum(), scaleWidth, scaleHeight); } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/1/24
setVideoScale
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
Apache-2.0
public void setVideoRotate(WlRotateType rotateType) { if (wlPlayer != null) { wlPlayer.setVideoRotate(getUniqueNum(), rotateType); } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/1/24
setVideoRotate
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
Apache-2.0
public void setVideoMirror(WlMirrorType mirrorType) { if (wlPlayer != null) { wlPlayer.setVideoMirror(getUniqueNum(), mirrorType); } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/1/24
setVideoMirror
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
Apache-2.0
public long getUniqueNum() { return hashCode(); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/1/24
getUniqueNum
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
Apache-2.0
public void setClearLastVideoFrame(boolean clear){ if(wlPlayer != null){ wlPlayer.setClearLastVideoFrame(getUniqueNum(), clear); } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/1/24
setClearLastVideoFrame
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
Apache-2.0
public void setOnVideoViewListener(WlOnVideoViewListener onVideoViewListener) { this.wlOnVideoViewListener = onVideoViewListener; }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/1/24
setOnVideoViewListener
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
Apache-2.0
@Override public void surfaceCreated(SurfaceHolder holder) { if (!isInit) { if (wlOnVideoViewListener != null) { isInit = true; wlOnVideoViewListener.initSuccess(); } } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/1/24
surfaceCreated
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
Apache-2.0
@Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { if (wlPlayer != null) { wlPlayer.setSurface(holder.getSurface(), rgba, hashCode()); } if (wlOnVideoViewListener != null) { wlOnVideoViewListener.onSurfaceChange(width, height); } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/1/24
surfaceChanged
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
Apache-2.0
@Override public void surfaceDestroyed(SurfaceHolder holder) { if (wlPlayer != null) { wlPlayer.setSurface(null, rgba, hashCode()); } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/1/24
surfaceDestroyed
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
Apache-2.0
@Override public boolean onTouchEvent(MotionEvent event) { if (wlPlayer == null) { return super.onTouchEvent(event); } int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: isXMoving = false; isMove = false; type = -1; x_down = event.getX(); y_down = event.getY(); break; case MotionEvent.ACTION_MOVE: offset_move_x = event.getX() - x_down; offset_move_y = event.getY() - y_down; if (type == -1) { if (Math.abs(offset_move_x) > Math.abs(startMoveOffsetLength)) { type = MOVE_X; } else if (Math.abs(offset_move_y) > Math.abs(startMoveOffsetLength)) { type = MOVE_Y; } } if (type == MOVE_Y) { if (x_down < getWidth() / 2.0) { if (wlOnVideoViewListener != null) { if (!isMove) { if (offset_move_y > 0) { startMoveOffsetLength = Math.abs(startMoveOffsetLength); } else { startMoveOffsetLength = Math.abs(startMoveOffsetLength) * -1; } wlOnVideoViewListener.moveLeft(-move_offset_percent, MOVE_START); } else { move_offset_percent = (offset_move_y - startMoveOffsetLength) / (getHeight() / 2.0); wlOnVideoViewListener.moveLeft(-move_offset_percent, MOVE_ING); } } } else { if (wlOnVideoViewListener != null) { if (!isMove) { if (offset_move_y > 0) { startMoveOffsetLength = Math.abs(startMoveOffsetLength); } else { startMoveOffsetLength = Math.abs(startMoveOffsetLength) * -1; } wlOnVideoViewListener.moveRight(-move_offset_percent, MOVE_START); } else { move_offset_percent = (offset_move_y - startMoveOffsetLength) / (getHeight() / 2.0); wlOnVideoViewListener.moveRight(-move_offset_percent, MOVE_ING); } } } isMove = true; } else if (type == MOVE_X) { if (wlOnVideoViewListener != null) { if (wlPlayer != null && wlPlayer.getDuration() > 0) { if (!isMove) { if (offset_move_x > 0) { startMoveOffsetLength = Math.abs(startMoveOffsetLength) * -1; } else { startMoveOffsetLength = Math.abs(startMoveOffsetLength); } wlOnVideoViewListener.moveX(seek_time, MOVE_START); } else { move_offset_percent = (offset_move_x + startMoveOffsetLength) / (getWidth() * 3.0); seek_time = wlPlayer.getCurrentTime() + move_offset_percent * wlPlayer.getDuration(); if (seek_time < 0) { seek_time = 0; } if (seek_time > wlPlayer.getDuration()) { seek_time = wlPlayer.getDuration(); } isXMoving = true; wlOnVideoViewListener.moveX(seek_time, MOVE_ING); } } } isMove = true; } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (isMove) { if (type == MOVE_X) { if (wlOnVideoViewListener != null) { if (seek_time < 0) { seek_time = 0; } if (seek_time > wlPlayer.getDuration()) { seek_time = wlPlayer.getDuration(); } if (isXMoving) { wlOnVideoViewListener.moveX(seek_time, MOVE_STOP); } else { wlOnVideoViewListener.moveX(-1, MOVE_STOP); } seek_time = 0; } } else if (type == MOVE_Y) { if (x_down < getWidth() / 2.0) { if (wlOnVideoViewListener != null) { wlOnVideoViewListener.moveLeft(-move_offset_percent, MOVE_STOP); } } else { if (wlOnVideoViewListener != null) { wlOnVideoViewListener.moveRight(-move_offset_percent, MOVE_STOP); } } } } else { clickCount++; handler.postDelayed(runnable, 200); } break; } return true; }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/1/24
onTouchEvent
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
Apache-2.0
@Override public void run() { if (clickCount == 1) { if (wlOnVideoViewListener != null) { wlOnVideoViewListener.onSingleClick(); } } else if (clickCount == 2) { if (wlOnVideoViewListener != null) { wlOnVideoViewListener.onDoubleClick(); } } clickCount = 0; handler.removeCallbacksAndMessages(null); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/1/24
run
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
Apache-2.0
private int dip2px(Context context, float dipValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dipValue * scale + 0.5f); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/1/24
dip2px
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlSurfaceView.java
Apache-2.0
public void setWlPlayer(WlPlayer wlPlayer) { this.wlPlayer = wlPlayer; }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
setWlPlayer
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
public void setWlPlayer(WlPlayer wlPlayer, String rgba) { this.wlPlayer = wlPlayer; if (WlColorUtil.isRGBAColor(rgba)) { this.rgba = rgba; } else { this.rgba = "#000000FF"; } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
setWlPlayer
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
public void setAlphaVideoType(WlAlphaVideoType alphaVideoType) { if (wlPlayer == null) { return; } if (alphaVideoType == WlAlphaVideoType.WL_ALPHA_VIDEO_DEFAULT) { setOpaque(true); } else { setOpaque(false); } this.wlPlayer.setAlphaVideoType(alphaVideoType); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
setAlphaVideoType
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
public void setVideoScale(WlScaleType scaleType) { if (wlPlayer != null) { wlPlayer.setVideoScale(getUniqueNum(), scaleType); } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
setVideoScale
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
public void setVideoScale(int scaleWidth, int scaleHeight) { if (wlPlayer != null) { wlPlayer.setVideoScale(getUniqueNum(), scaleWidth, scaleHeight); } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
setVideoScale
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
public void setVideoRotate(WlRotateType rotateType) { if (wlPlayer != null) { wlPlayer.setVideoRotate(getUniqueNum(), rotateType); } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
setVideoRotate
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
public void setVideoMirror(WlMirrorType mirrorType) { if (wlPlayer != null) { wlPlayer.setVideoMirror(getUniqueNum(), mirrorType); } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
setVideoMirror
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
public long getUniqueNum() { return hashCode(); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
getUniqueNum
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
public void setClearLastVideoFrame(boolean clear) { if (wlPlayer != null) { wlPlayer.setClearLastVideoFrame(getUniqueNum(), clear); } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
setClearLastVideoFrame
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
public void setOnVideoViewListener(WlOnVideoViewListener onVideoViewListener) { this.wlOnVideoViewListener = onVideoViewListener; }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
setOnVideoViewListener
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
@Override public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) { Matrix matrix = new Matrix(); matrix.setScale(1.001f, 1.001f); setTransform(matrix); if (this.surfaceTextur == null) { this.surfaceTextur = surfaceTexture; } else { setSurfaceTexture(this.surfaceTextur); } if (!isInit) { if (surface == null) { surface = new Surface(surfaceTexture); } if (wlPlayer != null) { wlPlayer.setSurface(surface, rgba, getUniqueNum()); } if (wlOnVideoViewListener != null) { isInit = true; wlOnVideoViewListener.initSuccess(); } } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
onSurfaceTextureAvailable
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
@Override public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width, int height) { if (wlPlayer != null) { wlPlayer.setSurface(surface, rgba, getUniqueNum()); } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
onSurfaceTextureSizeChanged
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
@Override public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { if (wlPlayer != null) { wlPlayer.setSurface(null, rgba, getUniqueNum()); } return false; }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
onSurfaceTextureDestroyed
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
@Override public void onSurfaceTextureUpdated(SurfaceTexture surface) { }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
onSurfaceTextureUpdated
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
@Override public boolean onTouchEvent(MotionEvent event) { if (wlPlayer == null) { return super.onTouchEvent(event); } int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: isXMoving = false; isMove = false; type = -1; x_down = event.getX(); y_down = event.getY(); break; case MotionEvent.ACTION_MOVE: offset_move_x = event.getX() - x_down; offset_move_y = event.getY() - y_down; if (type == -1) { if (Math.abs(offset_move_x) > Math.abs(startMoveOffsetLength)) { type = MOVE_X; } else if (Math.abs(offset_move_y) > Math.abs(startMoveOffsetLength)) { type = MOVE_Y; } } if (type == MOVE_Y) { if (x_down < getWidth() / 2.0) { if (wlOnVideoViewListener != null) { if (!isMove) { if (offset_move_y > 0) { startMoveOffsetLength = Math.abs(startMoveOffsetLength); } else { startMoveOffsetLength = Math.abs(startMoveOffsetLength) * -1; } wlOnVideoViewListener.moveLeft(-move_offset_percent, MOVE_START); } else { move_offset_percent = (offset_move_y - startMoveOffsetLength) / (getHeight() / 2.0); wlOnVideoViewListener.moveLeft(-move_offset_percent, MOVE_ING); } } } else { if (wlOnVideoViewListener != null) { if (!isMove) { if (offset_move_y > 0) { startMoveOffsetLength = Math.abs(startMoveOffsetLength); } else { startMoveOffsetLength = Math.abs(startMoveOffsetLength) * -1; } wlOnVideoViewListener.moveRight(-move_offset_percent, MOVE_START); } else { move_offset_percent = (offset_move_y - startMoveOffsetLength) / (getHeight() / 2.0); wlOnVideoViewListener.moveRight(-move_offset_percent, MOVE_ING); } } } isMove = true; } else if (type == MOVE_X) { if (wlOnVideoViewListener != null) { if (wlPlayer != null && wlPlayer.getDuration() > 0) { if (!isMove) { if (offset_move_x > 0) { startMoveOffsetLength = Math.abs(startMoveOffsetLength) * -1; } else { startMoveOffsetLength = Math.abs(startMoveOffsetLength); } wlOnVideoViewListener.moveX(seek_time, MOVE_START); } else { move_offset_percent = (offset_move_x + startMoveOffsetLength) / (getWidth() * 3.0); seek_time = wlPlayer.getCurrentTime() + move_offset_percent * wlPlayer.getDuration(); if (seek_time < 0) { seek_time = 0; } if (seek_time > wlPlayer.getDuration()) { seek_time = wlPlayer.getDuration(); } isXMoving = true; wlOnVideoViewListener.moveX(seek_time, MOVE_ING); } } } isMove = true; } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (isMove) { if (type == MOVE_X) { if (wlOnVideoViewListener != null) { if (seek_time < 0) { seek_time = 0; } if (seek_time > wlPlayer.getDuration()) { seek_time = wlPlayer.getDuration(); } if (isXMoving) { wlOnVideoViewListener.moveX(seek_time, MOVE_STOP); } else { wlOnVideoViewListener.moveX(-1, MOVE_STOP); } seek_time = 0; } } else if (type == MOVE_Y) { if (x_down < getWidth() / 2.0) { if (wlOnVideoViewListener != null) { wlOnVideoViewListener.moveLeft(-move_offset_percent, MOVE_STOP); } } else { if (wlOnVideoViewListener != null) { wlOnVideoViewListener.moveRight(-move_offset_percent, MOVE_STOP); } } } } else { clickCount++; handler.postDelayed(runnable, 200); } break; } return true; }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
onTouchEvent
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
@Override public void run() { if (clickCount == 1) { if (wlOnVideoViewListener != null) { wlOnVideoViewListener.onSingleClick(); } } else if (clickCount == 2) { if (wlOnVideoViewListener != null) { wlOnVideoViewListener.onDoubleClick(); } } clickCount = 0; handler.removeCallbacksAndMessages(null); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
run
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
public void release() { if (surfaceTextur != null) { surfaceTextur.release(); surfaceTextur = null; } if (surface != null) { surface.release(); surface = null; } if (wlPlayer != null) { wlPlayer = null; } }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
release
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
private int dip2px(Context context, float dipValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dipValue * scale + 0.5f); }
author : ywl5320 e-mail : ywl5320@163.com desc : wlmedia date : 2024/5/19
dip2px
java
ywl5320/wlmedia
wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
https://github.com/ywl5320/wlmedia/blob/master/wlmedia_android/wlmedia/src/main/java/com/ywl5320/wlmedia/widget/WlTextureView.java
Apache-2.0
@Override public void onCreate() { super.onCreate(); httpRequestFactory = createRequestFactory(); }
This class offers a {@link SpiceService} that injects a {@link HttpRequestFactory} from Google Http Client into every {@link GoogleHttpClientSpiceRequest} it has to execute. Developpers can override {@link #createRequestFactory()} in addition to the usual {@link #createCacheManager(android.app.Application)} methods to create a {@link HttpRequestFactory} and configure it. @author sni
onCreate
java
stephanenicolas/robospice
extensions/robospice-google-http-client-parent/robospice-google-http-client/src/main/java/com/octo/android/robospice/GoogleHttpClientSpiceService.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-google-http-client-parent/robospice-google-http-client/src/main/java/com/octo/android/robospice/GoogleHttpClientSpiceService.java
Apache-2.0
public static HttpRequestFactory createRequestFactory() { HttpTransport httpTransport = AndroidHttp.newCompatibleTransport(); return httpTransport.createRequestFactory(); }
This class offers a {@link SpiceService} that injects a {@link HttpRequestFactory} from Google Http Client into every {@link GoogleHttpClientSpiceRequest} it has to execute. Developpers can override {@link #createRequestFactory()} in addition to the usual {@link #createCacheManager(android.app.Application)} methods to create a {@link HttpRequestFactory} and configure it. @author sni
createRequestFactory
java
stephanenicolas/robospice
extensions/robospice-google-http-client-parent/robospice-google-http-client/src/main/java/com/octo/android/robospice/GoogleHttpClientSpiceService.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-google-http-client-parent/robospice-google-http-client/src/main/java/com/octo/android/robospice/GoogleHttpClientSpiceService.java
Apache-2.0
@Override public void addRequest(CachedSpiceRequest<?> request, Set<RequestListener<?>> listRequestListener) { if (request.getSpiceRequest() instanceof GoogleHttpClientSpiceRequest) { ((GoogleHttpClientSpiceRequest<?>) request.getSpiceRequest()).setHttpRequestFactory(httpRequestFactory); } super.addRequest(request, listRequestListener); }
This class offers a {@link SpiceService} that injects a {@link HttpRequestFactory} from Google Http Client into every {@link GoogleHttpClientSpiceRequest} it has to execute. Developpers can override {@link #createRequestFactory()} in addition to the usual {@link #createCacheManager(android.app.Application)} methods to create a {@link HttpRequestFactory} and configure it. @author sni
addRequest
java
stephanenicolas/robospice
extensions/robospice-google-http-client-parent/robospice-google-http-client/src/main/java/com/octo/android/robospice/GoogleHttpClientSpiceService.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-google-http-client-parent/robospice-google-http-client/src/main/java/com/octo/android/robospice/GoogleHttpClientSpiceService.java
Apache-2.0
@Override public CacheManager createCacheManager(Application application) throws CacheCreationException { CacheManager cacheManager = new CacheManager(); cacheManager.addPersister(new GsonObjectPersisterFactory(application)); return cacheManager; }
A {@link GoogleHttpClientSpiceService} dedicated to json web services via gson. Provides caching. @author sni
createCacheManager
java
stephanenicolas/robospice
extensions/robospice-google-http-client-parent/robospice-google-http-client/src/main/java/com/octo/android/robospice/GsonGoogleHttpClientSpiceService.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-google-http-client-parent/robospice-google-http-client/src/main/java/com/octo/android/robospice/GsonGoogleHttpClientSpiceService.java
Apache-2.0
@Override public CacheManager createCacheManager(Application application) throws CacheCreationException { CacheManager cacheManager = new CacheManager(); cacheManager.addPersister(new Jackson2ObjectPersisterFactory(application)); return cacheManager; }
A {@link GoogleHttpClientSpiceService} dedicated to json web services via Jackson. Provides caching. @author sni
createCacheManager
java
stephanenicolas/robospice
extensions/robospice-google-http-client-parent/robospice-google-http-client/src/main/java/com/octo/android/robospice/Jackson2GoogleHttpClientSpiceService.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-google-http-client-parent/robospice-google-http-client/src/main/java/com/octo/android/robospice/Jackson2GoogleHttpClientSpiceService.java
Apache-2.0
@Override public CacheManager createCacheManager(Application application) throws CacheCreationException { CacheManager cacheManager = new CacheManager(); cacheManager.addPersister(new JacksonObjectPersisterFactory(application)); return cacheManager; }
A {@link GoogleHttpClientSpiceService} dedicated to json web services via Jackson. Provides caching. @author sni
createCacheManager
java
stephanenicolas/robospice
extensions/robospice-google-http-client-parent/robospice-google-http-client/src/main/java/com/octo/android/robospice/JacksonGoogleHttpClientSpiceService.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-google-http-client-parent/robospice-google-http-client/src/main/java/com/octo/android/robospice/JacksonGoogleHttpClientSpiceService.java
Apache-2.0
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("id=").append(id); sb.append(", ").append("string=").append(string); sb.append(", ").append("millis=").append(millis); SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.S"); sb.append(", ").append("date=").append(dateFormatter.format(date)); sb.append(", ").append("even=").append(even); return sb.toString(); }
A simple demonstration object we are creating and persisting to the database.
toString
java
stephanenicolas/robospice
extensions/robospice-google-http-client-parent/robospice-google-http-client-test/src/main/java/com/octo/android/robospice/googlehttpclient/test/model/SimpleData.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-google-http-client-parent/robospice-google-http-client-test/src/main/java/com/octo/android/robospice/googlehttpclient/test/model/SimpleData.java
Apache-2.0
public void setOkHttpClient(OkHttpClient okHttpClient) { this.okHttpClient = okHttpClient; }
A simplified {@link SpiceRequest} that makes it even easier to use a OkHttpClient. @author SNI @param <T> the result type of this request.
setOkHttpClient
java
stephanenicolas/robospice
extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/OkHttpSpiceRequest.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/OkHttpSpiceRequest.java
Apache-2.0
public OkHttpClient getOkHttpClient() { return okHttpClient; }
A simplified {@link SpiceRequest} that makes it even easier to use a OkHttpClient. @author SNI @param <T> the result type of this request.
getOkHttpClient
java
stephanenicolas/robospice
extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/OkHttpSpiceRequest.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/OkHttpSpiceRequest.java
Apache-2.0
@Override public InputStream processStream(final int contentLength, final InputStream inputStream) throws IOException { OutputStream fileOutputStream = null; try { // touch boolean isTouchedNow = cacheFile.setLastModified(System .currentTimeMillis()); if (!isTouchedNow) { Ln.d( "Modification time of file %s could not be changed normally ", cacheFile.getAbsolutePath()); } fileOutputStream = new FileOutputStream(cacheFile); readBytes(inputStream, new ProgressByteProcessor(this, fileOutputStream, contentLength)); return new FileInputStream(cacheFile); } finally { IOUtils.closeQuietly(fileOutputStream); } }
Creates a OkHttpBigBinaryRequest using its own cache file to prevent any downloaded data to be stored in memory. All file received from the network (via a simple http GET request) will be stored directly in the cache file to prevent memory loss. @param url the url to get the image data from. @param cacheFile a file used to store image data. Developers will have to handle the cache file erasure by themselves. <b>This cache file is not handled by RS caching mechanism in the "normal way". </b>
processStream
java
stephanenicolas/robospice
extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBigBinaryRequest.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBigBinaryRequest.java
Apache-2.0
public File getCacheFile() { return cacheFile; }
Creates a OkHttpBigBinaryRequest using its own cache file to prevent any downloaded data to be stored in memory. All file received from the network (via a simple http GET request) will be stored directly in the cache file to prevent memory loss. @param url the url to get the image data from. @param cacheFile a file used to store image data. Developers will have to handle the cache file erasure by themselves. <b>This cache file is not handled by RS caching mechanism in the "normal way". </b>
getCacheFile
java
stephanenicolas/robospice
extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBigBinaryRequest.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBigBinaryRequest.java
Apache-2.0
@Override public final InputStream loadDataFromNetwork() throws Exception { try { OkUrlFactory urlFactory = new OkUrlFactory(getOkHttpClient()); HttpURLConnection connection = urlFactory.open(new URL(url)); return processStream(connection.getContentLength(), connection.getInputStream()); } catch (final MalformedURLException e) { Ln.e(e, "Unable to create URL"); throw e; } catch (final IOException e) { Ln.e(e, "Unable to download binary"); throw e; } }
Abstract class used to download binaries. See {@link OkHttpSmallBinaryRequest} and {@link OkHttpBigBinaryRequest} @author jva
loadDataFromNetwork
java
stephanenicolas/robospice
extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBinaryRequest.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBinaryRequest.java
Apache-2.0
protected final String getUrl() { return this.url; }
Abstract class used to download binaries. See {@link OkHttpSmallBinaryRequest} and {@link OkHttpBigBinaryRequest} @author jva
getUrl
java
stephanenicolas/robospice
extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBinaryRequest.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBinaryRequest.java
Apache-2.0
protected void readBytes(final InputStream in, final ProgressByteProcessor processor) throws IOException { final byte[] buf = new byte[BUF_SIZE]; try { int amt; do { amt = in.read(buf); if (amt == -1) { break; } } while (processor.processBytes(buf, 0, amt)); } finally { IOUtils.closeQuietly(in); } }
Inspired from Guava com.google.common.io.ByteStreams
readBytes
java
stephanenicolas/robospice
extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBinaryRequest.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBinaryRequest.java
Apache-2.0
@Override public Bitmap loadDataFromNetwork() throws Exception { try { OkUrlFactory urlFactory = new OkUrlFactory(getOkHttpClient()); HttpURLConnection connection = urlFactory.open(new URL(url)); processStream(connection.getContentLength(), connection.getInputStream()); if (width != -1 && height != -1) { this.options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(cacheFile.getAbsolutePath(), options); options.inSampleSize = calculateInSampleSize(options, width, height); options.inJustDecodeBounds = false; options.inPurgeable = true; return BitmapFactory.decodeFile(cacheFile.getAbsolutePath(), options); } else { return BitmapFactory.decodeFile(cacheFile.getAbsolutePath(), options); } } catch (final MalformedURLException e) { Ln.e(e, "Unable to create URL"); throw e; } catch (final IOException e) { Ln.e(e, "Unable to download binary"); throw e; } }
Creates a OkHttpBitmapRequest able to fetch a {@link Bitmap} from the network. @param url the url of the bitmap to fetch. @param width the requested width of the image. @param height the requested height of the image. @param cacheFile a file used to store data during download.
loadDataFromNetwork
java
stephanenicolas/robospice
extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBitmapRequest.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBitmapRequest.java
Apache-2.0
protected final String getUrl() { return this.url; }
Creates a OkHttpBitmapRequest able to fetch a {@link Bitmap} from the network. @param url the url of the bitmap to fetch. @param width the requested width of the image. @param height the requested height of the image. @param cacheFile a file used to store data during download.
getUrl
java
stephanenicolas/robospice
extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBitmapRequest.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBitmapRequest.java
Apache-2.0
@Override public File getCacheFile() { return cacheFile; }
Creates a OkHttpBitmapRequest able to fetch a {@link Bitmap} from the network. @param url the url of the bitmap to fetch. @param width the requested width of the image. @param height the requested height of the image. @param cacheFile a file used to store data during download.
getCacheFile
java
stephanenicolas/robospice
extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBitmapRequest.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBitmapRequest.java
Apache-2.0
public void processStream(int contentLength, final InputStream inputStream) throws IOException { OutputStream fileOutputStream = null; try { // touch boolean isTouchedNow = cacheFile.setLastModified(System.currentTimeMillis()); if (!isTouchedNow) { Ln.d("Modification time of file %s could not be changed normally ", cacheFile.getAbsolutePath()); } fileOutputStream = new FileOutputStream(cacheFile); readBytes(inputStream, new ProgressByteProcessor(this, fileOutputStream, contentLength)); } finally { IOUtils.closeQuietly(fileOutputStream); } }
Creates a OkHttpBitmapRequest able to fetch a {@link Bitmap} from the network. @param url the url of the bitmap to fetch. @param width the requested width of the image. @param height the requested height of the image. @param cacheFile a file used to store data during download.
processStream
java
stephanenicolas/robospice
extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBitmapRequest.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBitmapRequest.java
Apache-2.0
protected void readBytes(final InputStream in, final ProgressByteProcessor processor) throws IOException { final byte[] buf = new byte[BUF_SIZE]; try { int amt; do { amt = in.read(buf); if (amt == -1) { break; } } while (processor.processBytes(buf, 0, amt)); } finally { IOUtils.closeQuietly(in); } }
Inspired from Guava com.google.common.io.ByteStreams
readBytes
java
stephanenicolas/robospice
extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBitmapRequest.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBitmapRequest.java
Apache-2.0
private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (height > reqHeight || width > reqWidth) { if (width > height) { inSampleSize = Math.round((float) height / (float) reqHeight); } else { inSampleSize = Math.round((float) width / (float) reqWidth); } } return inSampleSize; }
Inspired from Guava com.google.common.io.ByteStreams
calculateInSampleSize
java
stephanenicolas/robospice
extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBitmapRequest.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpBitmapRequest.java
Apache-2.0
@Override public InputStream processStream(final int contentLength, final InputStream inputStream) throws IOException { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); readBytes(inputStream, new ProgressByteProcessor(this, bos, contentLength)); final byte[] bytes = bos.toByteArray(); return new ByteArrayInputStream(bytes); }
Downloads small images in size. All data is passed to the listener using memory. This class is meant to help download small images (like thumbnails). If you wish to download bigger documents (or if you don't know the size of your documents), you would be better using {@link OkHttpBigBinaryRequest}. @author sni & jva
processStream
java
stephanenicolas/robospice
extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpSmallBinaryRequest.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-okhttp-parent/robospice-okhttp/src/main/java/com/octo/android/robospice/request/okhttp/simple/OkHttpSmallBinaryRequest.java
Apache-2.0
public static Map<Class<?>, Uri> getContractClasses(List<Class<?>> classList) { Map<Class<?>, Uri> mapHandledClassesToNotificationUri = new HashMap<Class<?>, Uri>(); for (Class<?> clazz : classList) { Uri uri = null; try { Class<?> contractClass = getContractClassForClass(clazz); uri = getContentUri(contractClass); } catch (Exception e) { Ln.v("Contract class not found for " + clazz.getName()); } mapHandledClassesToNotificationUri.put(clazz, uri); } return mapHandledClassesToNotificationUri; }
Helper to get contract class and relevent fields. @author SNI
getContractClasses
java
stephanenicolas/robospice
extensions/robospice-ormlite-content-provider-parent/robospice-ormlite-content-provider/src/main/java/com/octo/android/robospice/persistence/ormlite/ContractHelper.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-content-provider-parent/robospice-ormlite-content-provider/src/main/java/com/octo/android/robospice/persistence/ormlite/ContractHelper.java
Apache-2.0
public static Class<?> getContractClassForClass(Class<?> clazz) throws ClassNotFoundException { String className; if (clazz.isAnnotationPresent(Contract.class)) { className = clazz.getAnnotation(Contract.class).contractClassName(); if (className == null || className.isEmpty()) { className = clazz.getName() + "Contract"; } return Class.forName(className); } else { return null; } }
Helper to get contract class and relevent fields. @author SNI
getContractClassForClass
java
stephanenicolas/robospice
extensions/robospice-ormlite-content-provider-parent/robospice-ormlite-content-provider/src/main/java/com/octo/android/robospice/persistence/ormlite/ContractHelper.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-content-provider-parent/robospice-ormlite-content-provider/src/main/java/com/octo/android/robospice/persistence/ormlite/ContractHelper.java
Apache-2.0
public static Uri getContentUri(Class<?> contractClass) throws IllegalAccessException, NoSuchFieldException { return (Uri) contractClass.getField("CONTENT_URI").get(null); }
Helper to get contract class and relevent fields. @author SNI
getContentUri
java
stephanenicolas/robospice
extensions/robospice-ormlite-content-provider-parent/robospice-ormlite-content-provider/src/main/java/com/octo/android/robospice/persistence/ormlite/ContractHelper.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-content-provider-parent/robospice-ormlite-content-provider/src/main/java/com/octo/android/robospice/persistence/ormlite/ContractHelper.java
Apache-2.0
public static int getContentUriPatternMany(Class<?> contractClass) throws IllegalAccessException, NoSuchFieldException { return contractClass.getField("CONTENT_URI_PATTERN_MANY").getInt(null); }
Helper to get contract class and relevent fields. @author SNI
getContentUriPatternMany
java
stephanenicolas/robospice
extensions/robospice-ormlite-content-provider-parent/robospice-ormlite-content-provider/src/main/java/com/octo/android/robospice/persistence/ormlite/ContractHelper.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-content-provider-parent/robospice-ormlite-content-provider/src/main/java/com/octo/android/robospice/persistence/ormlite/ContractHelper.java
Apache-2.0
public static int getContentUriPatternOne(Class<?> contractClass) throws IllegalAccessException, NoSuchFieldException { return contractClass.getField("CONTENT_URI_PATTERN_ONE").getInt(null); }
Helper to get contract class and relevent fields. @author SNI
getContentUriPatternOne
java
stephanenicolas/robospice
extensions/robospice-ormlite-content-provider-parent/robospice-ormlite-content-provider/src/main/java/com/octo/android/robospice/persistence/ormlite/ContractHelper.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-content-provider-parent/robospice-ormlite-content-provider/src/main/java/com/octo/android/robospice/persistence/ormlite/ContractHelper.java
Apache-2.0
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("id=").append(id); sb.append(", ").append("string=").append(string); sb.append(", ").append("millis=").append(millis); SimpleDateFormat dateFormatter = new SimpleDateFormat( "MM/dd/yyyy HH:mm:ss.S"); sb.append(", ").append("date=").append(dateFormatter.format(date)); sb.append(", ").append("even=").append(even); return sb.toString(); }
A simple demonstration object we are creating and persisting to the database.
toString
java
stephanenicolas/robospice
extensions/robospice-ormlite-content-provider-parent/robospice-ormlite-content-provider-test/src/main/java/com/octo/android/robospice/ormlite/test/model/SimpleData.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-content-provider-parent/robospice-ormlite-content-provider-test/src/main/java/com/octo/android/robospice/ormlite/test/model/SimpleData.java
Apache-2.0
@Override public T loadDataFromCache(Object cacheKey, long maxTimeInCache) throws CacheLoadingException { T result = null; try { CacheEntry cacheEntry = databaseHelper.queryCacheKeyForIdFromDatabase(String.valueOf(cacheKey)); if (cacheEntry == null) { return null; } Object id = cacheEntry.getResultId(); long timeInCache = System.currentTimeMillis() - cacheEntry.getTimestamp(); if (maxTimeInCache == 0 || timeInCache <= maxTimeInCache) { result = databaseHelper.queryForIdFromDatabase(id, getHandledClass()); } } catch (SQLException e) { Ln.e(e, "SQL error"); } return result; }
@param application the android context needed to access android file system or databases to store.
loadDataFromCache
java
stephanenicolas/robospice
extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
Apache-2.0
@Override public T saveDataToCacheAndReturnData(final T data, final Object cacheKey) throws CacheSavingException { try { dao.callBatchTasks(new Callable<Void>() { @Override public Void call() throws Exception { try { databaseHelper.createOrUpdateInDatabase(data, getHandledClass()); saveAllForeignObjectsToCache(data); Object id = getIdField(data.getClass()).extractJavaFieldValue(data); CacheEntry cacheEntry = new CacheEntry(String.valueOf(cacheKey), System.currentTimeMillis(), data.getClass(), id); databaseHelper.createOrUpdateCacheEntryInDatabase(cacheEntry); } catch (Exception e) { Ln.d(e, "Exception occured during saveDataToCacheAndReturnData"); } return null; } }); databaseHelper.refreshFromDatabase(data, getHandledClass()); return data; } catch (Exception e) { Ln.e(e, "SQL Error"); return null; } }
@param application the android context needed to access android file system or databases to store.
saveDataToCacheAndReturnData
java
stephanenicolas/robospice
extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
Apache-2.0
@Override public Void call() throws Exception { try { databaseHelper.createOrUpdateInDatabase(data, getHandledClass()); saveAllForeignObjectsToCache(data); Object id = getIdField(data.getClass()).extractJavaFieldValue(data); CacheEntry cacheEntry = new CacheEntry(String.valueOf(cacheKey), System.currentTimeMillis(), data.getClass(), id); databaseHelper.createOrUpdateCacheEntryInDatabase(cacheEntry); } catch (Exception e) { Ln.d(e, "Exception occured during saveDataToCacheAndReturnData"); } return null; }
@param application the android context needed to access android file system or databases to store.
call
java
stephanenicolas/robospice
extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
Apache-2.0
@Override public boolean isDataInCache(Object cacheKey, long maxTimeInCache) { try { CacheEntry cacheEntry = databaseHelper.queryCacheKeyForIdFromDatabase(String.valueOf(cacheKey)); if (cacheEntry == null) { return false; } long timeInCache = System.currentTimeMillis() - cacheEntry.getTimestamp(); return maxTimeInCache == DurationInMillis.ALWAYS_RETURNED || timeInCache <= maxTimeInCache; } catch (SQLException e) { Ln.e(e, "SQL error"); return false; } }
@param application the android context needed to access android file system or databases to store.
isDataInCache
java
stephanenicolas/robospice
extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
Apache-2.0
@Override public long getCreationDateInCache(Object cacheKey) throws CacheLoadingException { CacheEntry cacheEntry = null; try { cacheEntry = databaseHelper.queryCacheKeyForIdFromDatabase(String.valueOf(cacheKey)); } catch (SQLException e) { throw new CacheLoadingException("Data could not be found in cache for cacheKey=" + cacheKey, e); } if (cacheEntry == null) { throw new CacheLoadingException("Data could not be found in cache for cacheKey=" + cacheKey); } return cacheEntry.getTimestamp(); }
@param application the android context needed to access android file system or databases to store.
getCreationDateInCache
java
stephanenicolas/robospice
extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
Apache-2.0
@SuppressWarnings({ "unchecked", "rawtypes" }) protected <E> void saveAllForeignObjectsToCache(E data) throws SQLException, IllegalAccessException, InvocationTargetException { // copy children on memory // set children to null on parents so that we can save the parent // without cascade Map<Field, Collection<?>> mapFieldToCollection = new HashMap<Field, Collection<?>>(); Class<? extends Object> parentClass = data.getClass(); for (Field field : parentClass.getDeclaredFields()) { ForeignCollectionField annotation = field.getAnnotation(ForeignCollectionField.class); if (annotation != null) { Collection<?> collectionCopy = new ArrayList(); Method getMethod = DatabaseFieldConfig.findGetMethod(field, true); Collection collectionInObject = (Collection<?>) getMethod.invoke(data); if (collectionInObject != null) { collectionCopy.addAll(collectionInObject); } Method setMethod = DatabaseFieldConfig.findSetMethod(field, true); setMethod.invoke(data, (Object) null); mapFieldToCollection.put(field, collectionCopy); } } // save parents without cascade databaseHelper.createOrUpdateInDatabase(data, (Class<E>) parentClass); // get the child from a previous database record databaseHelper.refreshFromDatabase(data, (Class<E>) parentClass); // future hook // delete children obtained from previous database record // we guess the type of children from the parametrized type of the // collection field of the parent for (Field field : parentClass.getDeclaredFields()) { if (field.getAnnotation(ForeignCollectionField.class) != null) { Method getMethod = DatabaseFieldConfig.findGetMethod(field, true); Collection collectionInObject = (Collection<?>) getMethod.invoke(data); // lazy collection are not loaded from database, so we load them if (collectionInObject instanceof LazyForeignCollection) { ((LazyForeignCollection) collectionInObject).refreshCollection(); } ParameterizedType listType = (ParameterizedType) field.getGenericType(); Class<?> itemInListClass = (Class<?>) listType.getActualTypeArguments()[0]; databaseHelper.deleteFromDataBase(collectionInObject, itemInListClass); } } // recursive call on children // we now saved the parent and can fill the foreign key of the children for (Map.Entry<Field, Collection<?>> entry : mapFieldToCollection.entrySet()) { Collection<?> collection = entry.getValue(); // re-set complete children to the parent ConnectionSource connectionSource = databaseHelper.getConnectionSource(); for (Object object : collection) { DatabaseTableConfig childDatabaseTableConfig = DatabaseTableConfig.fromClass(connectionSource, object.getClass()); for (FieldType childFieldType : childDatabaseTableConfig.getFieldTypes(null)) { if (parentClass.equals(childFieldType.getType()) && childFieldType.isForeign()) { childFieldType.assignField(object, data, true, null); } } // save children recursively saveAllForeignObjectsToCache(object); } } //notify if (mapHandledClassesToNotificationUri != null && mapHandledClassesToNotificationUri.containsKey(parentClass)) { Uri notificationUri = mapHandledClassesToNotificationUri.get(parentClass); if (notificationUri != null) { getApplication().getContentResolver().notifyChange(notificationUri, null); Object id = getIdField(data.getClass()).extractJavaFieldValue(data); Uri itemNotificationUri = notificationUri.buildUpon().appendPath(id.toString()).build(); getApplication().getContentResolver().notifyChange(itemNotificationUri, null); } } // future hook }
During this operation, we must save a new POJO (parent) into the database. The problem is that is the POJO contains children POJOs, then saving the parent would not work as the parent must exist in the database prior to saving the children. SO : <ul> <li>we copy the children into memory, <li>put the children to null on parent <li>save the parent to the database <li>if saving filled the parent with previous children, we remove them <li>re inject the children into the parent <li>save the children (as the parent now exists in database). </ul> @param data the parent POJO to save in the database. @throws SQLException @throws IllegalArgumentException @throws IllegalAccessException @throws InvocationTargetException
saveAllForeignObjectsToCache
java
stephanenicolas/robospice
extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
Apache-2.0
@Override public boolean removeDataFromCache(Object cacheKey) { try { String id = cacheKey.toString(); CacheEntry cacheEntry = databaseHelper.queryCacheKeyForIdFromDatabase(id); if (cacheEntry == null) { return false; } Class<?> clazz = Class.forName(cacheEntry.getResultClassName()); databaseHelper.deleteByIdFromDataBase(cacheEntry.getResultId(), clazz); databaseHelper.deleteFromDataBase(cacheEntry, CacheEntry.class); return true; } catch (SQLException e) { Ln.d(e); return false; } catch (ClassNotFoundException e) { Ln.d(e); return false; } }
During this operation, we must save a new POJO (parent) into the database. The problem is that is the POJO contains children POJOs, then saving the parent would not work as the parent must exist in the database prior to saving the children. SO : <ul> <li>we copy the children into memory, <li>put the children to null on parent <li>save the parent to the database <li>if saving filled the parent with previous children, we remove them <li>re inject the children into the parent <li>save the children (as the parent now exists in database). </ul> @param data the parent POJO to save in the database. @throws SQLException @throws IllegalArgumentException @throws IllegalAccessException @throws InvocationTargetException
removeDataFromCache
java
stephanenicolas/robospice
extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
Apache-2.0
@Override public void removeAllDataFromCache() { try { databaseHelper.clearTableFromDataBase(getHandledClass()); databaseHelper.clearTableFromDataBase(CacheEntry.class); } catch (SQLException e) { Ln.d(e, "SQL Error"); } }
During this operation, we must save a new POJO (parent) into the database. The problem is that is the POJO contains children POJOs, then saving the parent would not work as the parent must exist in the database prior to saving the children. SO : <ul> <li>we copy the children into memory, <li>put the children to null on parent <li>save the parent to the database <li>if saving filled the parent with previous children, we remove them <li>re inject the children into the parent <li>save the children (as the parent now exists in database). </ul> @param data the parent POJO to save in the database. @throws SQLException @throws IllegalArgumentException @throws IllegalAccessException @throws InvocationTargetException
removeAllDataFromCache
java
stephanenicolas/robospice
extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
Apache-2.0
@Override public List<T> loadAllDataFromCache() throws CacheLoadingException { try { List<CacheEntry> listCacheEntry = databaseHelper.queryForAllFromDatabase(CacheEntry.class); List<T> listObjectInCache = new ArrayList<T>(); for (CacheEntry cacheEntry : listCacheEntry) { listObjectInCache.add(loadDataFromCache(cacheEntry.getCacheKey(), DurationInMillis.ALWAYS_RETURNED)); } return listObjectInCache; } catch (SQLException e) { Ln.d(e); return null; } }
During this operation, we must save a new POJO (parent) into the database. The problem is that is the POJO contains children POJOs, then saving the parent would not work as the parent must exist in the database prior to saving the children. SO : <ul> <li>we copy the children into memory, <li>put the children to null on parent <li>save the parent to the database <li>if saving filled the parent with previous children, we remove them <li>re inject the children into the parent <li>save the children (as the parent now exists in database). </ul> @param data the parent POJO to save in the database. @throws SQLException @throws IllegalArgumentException @throws IllegalAccessException @throws InvocationTargetException
loadAllDataFromCache
java
stephanenicolas/robospice
extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
Apache-2.0
@Override public List<Object> getAllCacheKeys() { try { List<CacheEntry> listCacheEntry = databaseHelper.queryForAllFromDatabase(CacheEntry.class); List<Object> listCacheKey = new ArrayList<Object>(); for (CacheEntry cacheEntry : listCacheEntry) { listCacheKey.add(cacheEntry.getCacheKey()); } return listCacheKey; } catch (SQLException e) { return null; } }
During this operation, we must save a new POJO (parent) into the database. The problem is that is the POJO contains children POJOs, then saving the parent would not work as the parent must exist in the database prior to saving the children. SO : <ul> <li>we copy the children into memory, <li>put the children to null on parent <li>save the parent to the database <li>if saving filled the parent with previous children, we remove them <li>re inject the children into the parent <li>save the children (as the parent now exists in database). </ul> @param data the parent POJO to save in the database. @throws SQLException @throws IllegalArgumentException @throws IllegalAccessException @throws InvocationTargetException
getAllCacheKeys
java
stephanenicolas/robospice
extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
Apache-2.0
protected FieldType getIdField(Class clazz) throws SQLException { DatabaseTableConfig config = getDatabaseTableConfig(clazz); FieldType[] fieldTypes = config.getFieldTypes(databaseHelper.getConnectionSource().getDatabaseType()); FieldType idFieldType = null; for (FieldType fieldType : fieldTypes) { if (fieldType.isId() || fieldType.isGeneratedId() || fieldType.isGeneratedIdSequence()) { idFieldType = fieldType; } } if (idFieldType == null) { throw new IllegalStateException("Cannot find id field"); } return idFieldType; }
During this operation, we must save a new POJO (parent) into the database. The problem is that is the POJO contains children POJOs, then saving the parent would not work as the parent must exist in the database prior to saving the children. SO : <ul> <li>we copy the children into memory, <li>put the children to null on parent <li>save the parent to the database <li>if saving filled the parent with previous children, we remove them <li>re inject the children into the parent <li>save the children (as the parent now exists in database). </ul> @param data the parent POJO to save in the database. @throws SQLException @throws IllegalArgumentException @throws IllegalAccessException @throws InvocationTargetException
getIdField
java
stephanenicolas/robospice
extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
Apache-2.0
protected DatabaseTableConfig getDatabaseTableConfig(Class clazz) throws SQLException { DatabaseTableConfig config = mTableConfigs.get(clazz); if (config == null) { config = DatabaseTableConfigUtil.fromClass(databaseHelper.getConnectionSource(), clazz); if (config != null) { config.extractFieldTypes(databaseHelper.getConnectionSource()); mTableConfigs.put(clazz, config); } } return config; }
During this operation, we must save a new POJO (parent) into the database. The problem is that is the POJO contains children POJOs, then saving the parent would not work as the parent must exist in the database prior to saving the children. SO : <ul> <li>we copy the children into memory, <li>put the children to null on parent <li>save the parent to the database <li>if saving filled the parent with previous children, we remove them <li>re inject the children into the parent <li>save the children (as the parent now exists in database). </ul> @param data the parent POJO to save in the database. @throws SQLException @throws IllegalArgumentException @throws IllegalAccessException @throws InvocationTargetException
getDatabaseTableConfig
java
stephanenicolas/robospice
extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/InDatabaseObjectPersister.java
Apache-2.0
public static String getCacheKeyForId(String id, Class<?> clazz) { return clazz.getSimpleName() + "_" + id.toString(); }
Helper class which creates/updates our database and provides the DAOs.
getCacheKeyForId
java
stephanenicolas/robospice
extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/RoboSpiceDatabaseHelper.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/RoboSpiceDatabaseHelper.java
Apache-2.0
public static String getIdForCacheKey(String cacheKey) { return cacheKey.substring(cacheKey.indexOf('_') + 1); }
Helper class which creates/updates our database and provides the DAOs.
getIdForCacheKey
java
stephanenicolas/robospice
extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/RoboSpiceDatabaseHelper.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/RoboSpiceDatabaseHelper.java
Apache-2.0
public <T> void updateObjectInDatabase(T modelObject, Class<T> modelObjectClass) throws SQLException { if (modelObject != null) { Dao<T, ?> dao = getDao(modelObjectClass); dao.update(modelObject); } }
Helper class which creates/updates our database and provides the DAOs.
updateObjectInDatabase
java
stephanenicolas/robospice
extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/RoboSpiceDatabaseHelper.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/RoboSpiceDatabaseHelper.java
Apache-2.0
public <T> void refreshFromDatabase(T modelObject, Class<T> modelObjectClass) throws SQLException { if (modelObject != null) { Dao<T, ?> dao = getDao(modelObjectClass); dao.refresh(modelObject); } }
Helper class which creates/updates our database and provides the DAOs.
refreshFromDatabase
java
stephanenicolas/robospice
extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/RoboSpiceDatabaseHelper.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/RoboSpiceDatabaseHelper.java
Apache-2.0
public <T> void createOrUpdateInDatabase(T modelObject, Class<T> modelObjectClass) throws SQLException { if (modelObject != null) { Dao<T, ?> dao = getDao(modelObjectClass); dao.createOrUpdate(modelObject); } }
Helper class which creates/updates our database and provides the DAOs.
createOrUpdateInDatabase
java
stephanenicolas/robospice
extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/RoboSpiceDatabaseHelper.java
https://github.com/stephanenicolas/robospice/blob/master/extensions/robospice-ormlite-parent/robospice-ormlite/src/main/java/com/octo/android/robospice/persistence/ormlite/RoboSpiceDatabaseHelper.java
Apache-2.0