下面列出了怎么用android.view.ViewTreeObserver.OnPreDrawListener的API类实例代码及写法,或者点击链接到github查看源代码。
private void prepareSharedElementTransition(TransitionState state, View sceneRoot, Object sharedElementTransition, Fragment inFragment, Fragment outFragment, boolean isBack, ArrayList<View> sharedElementTargets) {
final View view = sceneRoot;
final Object obj = sharedElementTransition;
final ArrayList<View> arrayList = sharedElementTargets;
final TransitionState transitionState = state;
final boolean z = isBack;
final Fragment fragment = inFragment;
final Fragment fragment2 = outFragment;
sceneRoot.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
public boolean onPreDraw() {
view.getViewTreeObserver().removeOnPreDrawListener(this);
if (obj != null) {
FragmentTransitionCompat21.removeTargets(obj, arrayList);
arrayList.clear();
ArrayMap<String, View> namedViews = BackStackRecord.this.mapSharedElementsIn(transitionState, z, fragment);
FragmentTransitionCompat21.setSharedElementTargets(obj, transitionState.nonExistentView, namedViews, arrayList);
BackStackRecord.this.setEpicenterIn(namedViews, transitionState);
BackStackRecord.this.callSharedElementEnd(transitionState, fragment, fragment2, z, namedViews);
}
return true;
}
});
}
private void load(final ImageView imageView) {
if (imageView.getHeight() == 0) {
// wait for layout, same as glide SizeDeterminer does
imageView.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
@Override public boolean onPreDraw() {
imageView.getViewTreeObserver().removeOnPreDrawListener(this);
load(imageView); // call the same method, but we can be sure now getHeight() is a value
return true;
}
});
} else {
Glide
.with(imageView.getContext())
.load("whatever")
.fitCenter()
.override(Target.SIZE_ORIGINAL, imageView.getHeight())
.into(imageView);
}
}
public void setText(CharSequence charSequence) {
textContent = charSequence;
textView.setText(charSequence.toString());
ViewTreeObserver viewTreeObserver = textView.getViewTreeObserver();
viewTreeObserver.addOnPreDrawListener(new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
if (!isInitTextView) {
return true;
}
textLines = textView.getLineCount();
isExpandNeeded = textLines > expandLines;
isInitTextView = false;
if (isExpandNeeded) {
isShrink = true;
doAnimation(textLines, expandLines, WHAT_ANIMATION_END);
} else {
isShrink = false;
doNotExpand();
}
return true;
}
});
}
/**
*
* @param context
* @param gender
* 性别 0代表女 1代表男
* @param than
* 百分比
*/
public TriangleView(Context context, int gender, int than) {
super(context);
tag = get(lenght);
this.gender = gender;
ratio = than;
this.than = (int) ((100.0f - than) / (100.0f / tag[lenght - 1]));
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
this.getViewTreeObserver().addOnPreDrawListener(
new OnPreDrawListener() {
public boolean onPreDraw() {
init();
getViewTreeObserver().removeOnPreDrawListener(this);
return false;
}
});
}
public void init() {
paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paintWhite = new Paint();
paintWhite.setAntiAlias(true);
paintWhite.setColor(0xffffffff);
paintWhite.setStyle(Paint.Style.FILL_AND_STROKE);
bitmapRefreshPaint = new Paint();
bitmapRefreshPaint.setAntiAlias(true);
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
this.getViewTreeObserver().addOnPreDrawListener(// 绘制完毕
new OnPreDrawListener() {
public boolean onPreDraw() {
Init();
getViewTreeObserver().removeOnPreDrawListener(this);
return false;
}
});
}
/**
*
* @param context
* @param gender
* 性别 0代表女 1代表男
* @param than
* 百分比
*/
public TriangleView(Context context, int gender, int than) {
super(context);
tag = get(lenght);
this.gender = gender;
ratio = than;
this.than = (int) ((100.0f - than) / (100.0f / tag[lenght - 1]));
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
this.getViewTreeObserver().addOnPreDrawListener(
new OnPreDrawListener() {
public boolean onPreDraw() {
init();
getViewTreeObserver().removeOnPreDrawListener(this);
return false;
}
});
}
public void init() {
paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paintWhite = new Paint();
paintWhite.setAntiAlias(true);
paintWhite.setColor(0xffffffff);
paintWhite.setStyle(Paint.Style.FILL_AND_STROKE);
bitmapRefreshPaint = new Paint();
bitmapRefreshPaint.setAntiAlias(true);
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
this.getViewTreeObserver().addOnPreDrawListener(// 绘制完毕
new OnPreDrawListener() {
public boolean onPreDraw() {
Init();
getViewTreeObserver().removeOnPreDrawListener(this);
return false;
}
});
}
public UEFontAwesomeDrawable(Context context, final View view, String text, int color) {
this.text = Html.fromHtml(text).toString();
mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mTextPaint.setTypeface(typeface);
mTextPaint.setDither(true);
mTextPaint.setColor(color);
mTextPaint.setTextAlign(Paint.Align.CENTER);
mTextPaint.measureText(text);
view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
width = view.getWidth();
height = view.getHeight();
mTextPaint.setTextSize(Math.min(width, height));
view.getViewTreeObserver().removeOnPreDrawListener(this);
return false;
}
});
}
@SuppressLint("ClickableViewAccessibility")
private void init(){
setColumnCount(4);
try{
setBackgroundColor(((ColorDrawable) getBackground()).getColor());
}catch(Exception e){
setBackgroundColor(DEFAULT_BACKGROUND);
}
setOnTouchListener(onTouchListener);
getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
int w = getWidth();
int h = getHeight();
cardSize = (Math.min(w, h) - cardDistance)/4;
initCards();
startGame();
getViewTreeObserver().removeOnPreDrawListener(this);
return false;
}
});
}
@SuppressLint("ClickableViewAccessibility")
@SuppressWarnings("deprecation")
public void init(){
setOnTouchListener(this);
HEIGHT = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getHeight();
getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
DP = UEMethod.dp2px(getContext(), 1);
LayoutParams params = getLayoutParams();
if (getHeight() >= HEIGHT - DP * 72) {
params.height = 30 * DP;
}
params.width = (int) (params.height * 2.5);
setLayoutParams(params);
getViewTreeObserver().removeOnPreDrawListener(this);
return false;
}
});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_knobview);
findViewById(R.id.knob1).getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
View v = findViewById(R.id.knob1);
v.getViewTreeObserver().removeOnPreDrawListener(this);
int width = v.getWidth();
int height = v.getHeight();
v.getLayoutParams().width = Math.min(width, height);
v.getLayoutParams().height = Math.min(width, height);
v.requestLayout();
return false;
}
});
}
public void setText(CharSequence charSequence) {
textContent = charSequence;
textView.setText(charSequence.toString());
ViewTreeObserver viewTreeObserver = textView.getViewTreeObserver();
viewTreeObserver.addOnPreDrawListener(new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
if (!isInitTextView) {
return true;
}
textLines = textView.getLineCount();
isExpandNeeded = textLines > expandLines;
isInitTextView = false;
if (isExpandNeeded) {
isShrink = true;
doAnimation(textLines, expandLines, WHAT_ANIMATION_END);
} else {
isShrink = false;
doNotExpand();
}
return true;
}
});
if (!isInitTextView) {
textLines = textView.getLineCount();
}
}
private void applyBlur(final ImageView iv) {
iv.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener(this) {
final /* synthetic */ StarRankActivity this$0;
public boolean onPreDraw() {
iv.getViewTreeObserver().removeOnPreDrawListener(this);
iv.buildDrawingCache();
BlurUtils.star_blur(this.this$0.mContext, iv.getDrawingCache(), this.this$0.mZoomImg);
return true;
}
});
}
private void applyBlur(final ImageView iv) {
iv.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener(this) {
final /* synthetic */ StarActivity this$0;
public boolean onPreDraw() {
iv.getViewTreeObserver().removeOnPreDrawListener(this);
iv.buildDrawingCache();
BlurUtils.star_blur(this.this$0.mContext, iv.getDrawingCache(), this.this$0.mZoomImg);
return true;
}
});
}
private void excludeHiddenFragmentsAfterEnter(View sceneRoot, TransitionState state, int containerId, Object transition) {
final View view = sceneRoot;
final TransitionState transitionState = state;
final int i = containerId;
final Object obj = transition;
sceneRoot.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
public boolean onPreDraw() {
view.getViewTreeObserver().removeOnPreDrawListener(this);
BackStackRecord.this.excludeHiddenFragments(transitionState, i, obj);
return true;
}
});
}
@SuppressLint("ClickableViewAccessibility")
public ClockFaceView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray a =
context.obtainStyledAttributes(attrs, R.styleable.ClockFaceView, defStyleAttr, 0);
Resources res = getResources();
textColor = a.getColor(R.styleable.ClockFaceView_valueTextColor, Color.BLACK);
LayoutInflater.from(context).inflate(R.layout.material_clockface_view, this, true);
clockHandView = findViewById(R.id.material_clock_hand);
clockHandPadding = res.getDimensionPixelSize(R.dimen.material_clock_hand_padding);
int colorOnSurface = MaterialColors.getColor(this, R.attr.colorOnSurface);
int colorOnPrimary = MaterialColors.getColor(this, R.attr.colorOnPrimary);
gradientColors = new int[] {colorOnPrimary, colorOnPrimary, colorOnSurface};
clockHandView.addOnRotateListener(this);
int backgroundColor =
AppCompatResources.getColorStateList(context, R.color.material_timepicker_clockface)
.getDefaultColor();
setBackgroundColor(backgroundColor);
getViewTreeObserver()
.addOnPreDrawListener(
new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
if (!isShown()) {
return true;
}
getViewTreeObserver().removeOnPreDrawListener(this);
int circleRadius =
getHeight() / 2 - clockHandView.getSelectorRadius() - clockHandPadding;
setRadius(circleRadius);
return true;
}
});
a.recycle();
}
@CallSuper
@Override
public boolean onLayoutChild(
@NonNull CoordinatorLayout parent, @NonNull final View child, int layoutDirection) {
if (!ViewCompat.isLaidOut(child)) {
final ExpandableWidget dep = findExpandableWidget(parent, child);
if (dep != null && didStateChange(dep.isExpanded())) {
currentState = dep.isExpanded() ? STATE_EXPANDED : STATE_COLLAPSED;
@State final int expectedState = currentState;
child
.getViewTreeObserver()
.addOnPreDrawListener(
new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
child.getViewTreeObserver().removeOnPreDrawListener(this);
// Proceed only if the state did not change while we're waiting for pre-draw.
if (currentState == expectedState) {
onExpandedStateChange((View) dep, child, dep.isExpanded(), false);
}
return false;
}
});
}
}
return false;
}
/**
* 交换item,并且控制item之间的显示与隐藏效果
*/
private void onSwapItem(int moveX, int moveY) {
// 获取我们手指移动到的那个item的position
final int tempPosition = pointToPosition(moveX, moveY);
// 假如tempPosition 改变了并且tempPosition不等于-1,则进行交换
if (tempPosition != mDragPosition
&& tempPosition != AdapterView.INVALID_POSITION
&& mAnimationEnd) {
mDragAdapter.reorderItems(mDragPosition, tempPosition);
mDragAdapter.setHideItem(tempPosition);
final ViewTreeObserver observer = getViewTreeObserver();
observer.addOnPreDrawListener(new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
observer.removeOnPreDrawListener(this);
animateReorder(mDragPosition, tempPosition);
mDragPosition = tempPosition;
return true;
}
});
}
}
public void setCircle(boolean circle) {
this.mCircle = circle;
if(circle){
getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
setCornerRadius(getWidth()/2);
getViewTreeObserver().removeOnPreDrawListener(this);
return true;
}
});
}
}
private void initViews() {
mBlurView = findViewById(R.id.blurView);
mTextView = (TextView) findViewById(R.id.blurTextView);
mImageView = (ImageView) findViewById(R.id.imageView);
mImageView.getViewTreeObserver().addOnPreDrawListener(
new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
mImageView.getViewTreeObserver()
.removeOnPreDrawListener(this);
// 加载背景图构建Bitmap
mImageView.buildDrawingCache();
// 获取ImageView缓存的Bitmap
Bitmap bmp = mImageView.getDrawingCache();
// 在异步任务中执行模糊
new BlurTask().execute(bmp);
return true;
}
});
// 图片缩放动画
ObjectAnimator imageAnimator = ObjectAnimator.ofFloat(mImageView,
"scaleX", 1.0f, 1.1f).setDuration(2000);
ObjectAnimator imageAnimator1 = ObjectAnimator.ofFloat(mImageView,
"scaleY", 1.0f, 1.1f).setDuration(2000);
imageAnimator.start();
imageAnimator1.start();
imageAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
textAnimation();
}
});
// 由于图片放大相应的模糊的View也需要同样放大
mBlurView.setScaleX(1.1f);
mBlurView.setScaleY(1.1f);
}
/**
* 交换item,并且控制item之间的显示与隐藏效果
*
* @param moveX
* @param moveY
*/
private void onSwapItem(int moveX, int moveY) {
// 获取我们手指移动到的那个item的position
final int tempPosition = pointToPosition(moveX, moveY);
// 假如tempPosition 改变了并且tempPosition不等于-1,则进行交换
if (tempPosition != mDragPosition
&& tempPosition != AdapterView.INVALID_POSITION
&& mAnimationEnd) {
mDragAdapter.reorderItems(mDragPosition, tempPosition);
mDragAdapter.setHideItem(tempPosition);
final ViewTreeObserver observer = getViewTreeObserver();
observer.addOnPreDrawListener(new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
observer.removeOnPreDrawListener(this);
animateReorder(mDragPosition, tempPosition);
mDragPosition = tempPosition;
return true;
}
});
}
}
/**
* Runs provided action after image is drawn for the first time.
*/
private void runAfterImageDraw(final Runnable action) {
image.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
image.getViewTreeObserver().removeOnPreDrawListener(this);
runOnNextFrame(action);
return true;
}
});
image.invalidate();
}
public void init(int score) {
this.score = score;
Resources res = getResources();
tb = res.getDimension(R.dimen.historyscore_tb);
paint_black = new Paint();
paint_black.setAntiAlias(true);
paint_black.setColor(blackColor);
paint_black.setStrokeWidth(tb * 0.2f);
paint_black.setStyle(Style.STROKE);
paint_white = new Paint();
paint_white.setAntiAlias(true);
paint_white.setColor(whiteColor);
paint_white.setTextSize(tb*6.0f);
paint_white.setStrokeWidth(tb * 0.2f);
paint_white.setTextAlign(Align.CENTER);
paint_white.setStyle(Style.STROKE);
rectf = new RectF();
rectf.set(tb * 0.5f, tb * 0.5f, tb * 18.5f, tb * 18.5f);
setLayoutParams(new LayoutParams((int) (tb * 19.5f), (int) (tb * 19.5f)));
this.getViewTreeObserver().addOnPreDrawListener(
new OnPreDrawListener() {
public boolean onPreDraw() {
new thread();
getViewTreeObserver().removeOnPreDrawListener(this);
return false;
}
});
}
public void init(int score) {
this.score = score;
Resources res = getResources();
tb = res.getDimension(R.dimen.historyscore_tb);
paint_black = new Paint();
paint_black.setAntiAlias(true);
paint_black.setColor(blackColor);
paint_black.setStrokeWidth(tb * 0.2f);
paint_black.setStyle(Style.STROKE);
paint_white = new Paint();
paint_white.setAntiAlias(true);
paint_white.setColor(whiteColor);
paint_white.setTextSize(tb*6.0f);
paint_white.setStrokeWidth(tb * 0.2f);
paint_white.setTextAlign(Align.CENTER);
paint_white.setStyle(Style.STROKE);
rectf = new RectF();
rectf.set(tb * 0.5f, tb * 0.5f, tb * 18.5f, tb * 18.5f);
setLayoutParams(new LayoutParams((int) (tb * 19.5f), (int) (tb * 19.5f)));
this.getViewTreeObserver().addOnPreDrawListener(
new OnPreDrawListener() {
public boolean onPreDraw() {
new thread();
getViewTreeObserver().removeOnPreDrawListener(this);
return false;
}
});
}
private void initDatas(){
DP = UEMethod.dp2pxReturnFloat(getContext(), 1);
if (getBackground() != null) {
if (UEDevice.getOSVersionCode() >= 11) {
try {
setStrokeColor(((ColorDrawable)getBackground()).getColor());
super.setBackgroundColor(Color.TRANSPARENT);
} catch (Exception e) {
super.setBackgroundColor(Color.TRANSPARENT);
}
}else {
super.setBackgroundColor(Color.TRANSPARENT);
}
}
super.setPadding(getPaddingLeft() + 10 * (int)DP, getPaddingTop(), (getPaddingRight() + 10 * (int)DP) * 2 + 16 * (int)DP, getPaddingBottom());
super.addTextChangedListener(mTextChangedListener);
super.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
if (heightMode < 0) {
setPadding(getPaddingLeft(), 10 * (int)DP, getPaddingRight(), 10 * (int)DP);
}else {
setPadding(getPaddingLeft(), getPaddingTop() + 7 * (int)DP, getPaddingRight(), getPaddingBottom() + 7 * (int)DP);
}
getViewTreeObserver().removeOnPreDrawListener(this);
return false;
}
});
}
private void initView() {
this.backImageV = (ImageView) findViewById(R.id.common_nav_left);
this.backImageV.setOnClickListener(this);
this.titleTextV = (TextView) findViewById(R.id.common_nav_title);
this.titleTextV.setText(this.mAlbumName);
this.actTextV = (TextView) findViewById(R.id.textv_act);
this.capacityTextV = (TextView) findViewById(R.id.textv_capacity);
this.capacityPBar = (ProgressBar) findViewById(R.id.progressbar_capacity);
this.delBtn = (TextView) findViewById(R.id.btn_del);
this.listView = (ListView) findViewById(R.id.listv);
if (HttpCacheAssistant.getInstanced().isAdmini()) {
this.footView = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.lebox_layout_my_download_foot, null);
this.footView.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
public boolean onPreDraw() {
if (!MyDownloadSubActivity.this.mhasmeasured) {
MyDownloadSubActivity.this.measuredHeight = MyDownloadSubActivity.this.footView.getMeasuredHeight();
int width = MyDownloadSubActivity.this.footView.getMeasuredWidth();
if (NetworkUtil.isNetAvailable()) {
MyDownloadSubActivity.this.footView.setPadding(0, 0, 0, 0);
} else {
MyDownloadSubActivity.this.footView.setPadding(0, -MyDownloadSubActivity.this.measuredHeight, 0, 0);
Logger.d("HYX", "measuredHeight = " + MyDownloadSubActivity.this.measuredHeight);
}
MyDownloadSubActivity.this.mhasmeasured = true;
}
return true;
}
});
this.footView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Logger.d(MyDownloadSubActivity.TAG, ">> mCurrentAid >> " + MyDownloadSubActivity.this.mCurrentAid);
if (NetworkUtil.isNetAvailable()) {
DownloadVideoAlbumPageActivity.launch(MyDownloadSubActivity.this, MyDownloadSubActivity.this.mCurrentAid, 1, 2);
} else {
Util.showToast(R.string.net_error);
}
}
});
this.listView.addHeaderView(this.footView);
}
this.myDownloadFinishSubListAdapter = new MyDownloadFinishSubListAdapter(this.mContext);
this.listView.setAdapter(this.myDownloadFinishSubListAdapter);
this.mDialog = new CustomLoadingDialog(this);
this.mDialog.setCanceledOnTouchOutside(false);
}
private void initView() {
((TextView) findViewById(2131362352)).setText(this.mAlbumName);
this.backImageV = (ImageView) findViewById(2131362351);
this.backImageV.setOnClickListener(this);
this.capacityTextV = (TextView) findViewById(2131361941);
this.capacityPBar = (ProgressBar) findViewById(2131361940);
this.listView = (ListView) findViewById(2131361938);
this.footView = (RelativeLayout) UIsUtils.inflate(this.mContext, R.layout.layout_my_download_foot, null);
this.footView.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener(this) {
final /* synthetic */ MyDownloadSubActivity this$0;
{
if (HotFix.PREVENT_VERIFY) {
System.out.println(VerifyLoad.class);
}
this.this$0 = this$0;
}
public boolean onPreDraw() {
if (!this.this$0.mhasmeasured) {
this.this$0.measuredHeight = this.this$0.footView.getMeasuredHeight();
int width = this.this$0.footView.getMeasuredWidth();
if (NetworkUtils.isNetworkAvailable()) {
this.this$0.footView.setPadding(0, 0, 0, 0);
} else {
this.this$0.footView.setPadding(0, -this.this$0.measuredHeight, 0, 0);
LogInfo.log("HYX", "measuredHeight = " + this.this$0.measuredHeight);
}
this.this$0.mhasmeasured = true;
}
return true;
}
});
this.footView.setOnClickListener(new OnClickListener(this) {
final /* synthetic */ MyDownloadSubActivity this$0;
{
if (HotFix.PREVENT_VERIFY) {
System.out.println(VerifyLoad.class);
}
this.this$0 = this$0;
}
public void onClick(View v) {
LogInfo.log(MyDownloadSubActivity.TAG, ">> mCurrentAid >> " + this.this$0.mCurrentAid);
if (NetworkUtils.isNetworkAvailable()) {
DownloadVideoPageActivity.launch(this.this$0.getActivity(), this.this$0.mCurrentAid, 1, 2);
} else {
UIsUtils.showToast(2131100493);
}
}
});
if (!this.mIsFromRecom) {
this.listView.addHeaderView(this.footView);
}
this.myDownloadFinishSubListAdapter = new MyDownloadFinishSubListAdapter(this, this.mContext, null);
this.listView.setAdapter(this.myDownloadFinishSubListAdapter);
this.mDialog = new CustomLoadingDialog(getActivity());
this.mDialog.setCanceledOnTouchOutside(false);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_main);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(getResources().getColor(R.color.background));
}
mLayoutInflater = LayoutInflater.from(this);
TextView cidView = (TextView) findViewById(R.id.cid);
cidView.setOnClickListener(this);
TextView pwdView = (TextView) findViewById(R.id.pwd);
pwdView.setOnClickListener(this);
TextView statusView = (TextView) findViewById(R.id.logState);
TextView deviceName = (TextView) findViewById(R.id.deviceName);
ImageView barCodeView = (ImageView) findViewById(R.id.barcode);
ImageView menuView = (ImageView) findViewById(R.id.menu);
menuView.setOnClickListener(this);
menu_layout = (LinearLayout) findViewById(R.id.menu_layout);
menu_layout.setOnClickListener(this);
findViewById(R.id.main_layout).setOnClickListener(this);
findViewById(R.id.help).setOnClickListener(this);
findViewById(R.id.feedback).setOnClickListener(this);
findViewById(R.id.about).setOnClickListener(this);
findViewById(R.id.disclaimer).setOnClickListener(this);
findViewById(R.id.avs_title).setOnClickListener(this);
mMyAvsHelper = new MyAvsHelper(getApplicationContext());
mMyAvsHelper.setViews(cidView, pwdView, statusView, deviceName, barCodeView);
mMyAvsHelper.login();
final int[] size = mMyAvsHelper.getVideoSize();
mMediaSurfaceView = (MediaSurfaceView) findViewById(R.id.cameraView);
mMediaSurfaceView.openCamera(mMyAvsHelper);
ViewTreeObserver viewTreeObserver = mMediaSurfaceView.getViewTreeObserver();
viewTreeObserver.addOnPreDrawListener(new OnPreDrawListener(){
@Override
public boolean onPreDraw(){
if (isFirst){
int height = mMediaSurfaceView.getMeasuredHeight();
int width = mMediaSurfaceView.getMeasuredWidth();
float r = (float)height/(float)width;
float r2 = (float)size[1]/(float)size[0];
RelativeLayout.LayoutParams pvLayout = (RelativeLayout.LayoutParams) mMediaSurfaceView.getLayoutParams();
if (r > r2){
pvLayout.height = (int) (width*r2);
}else{
pvLayout.width = (int) (height/r2);
}
isFirst = false;
}
return true;
}
});
mShowChinese = "zh".equals(Locale.getDefault().getLanguage().toLowerCase());
//update
UmengUpdateAgent.setUpdateOnlyWifi(false);
UmengUpdateAgent.update(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_main);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(getResources().getColor(R.color.background));
}
mLayoutInflater = LayoutInflater.from(this);
TextView cidView = (TextView) findViewById(R.id.cid);
cidView.setOnClickListener(this);
TextView pwdView = (TextView) findViewById(R.id.pwd);
pwdView.setOnClickListener(this);
TextView statusView = (TextView) findViewById(R.id.logState);
TextView deviceName = (TextView) findViewById(R.id.deviceName);
ImageView barCodeView = (ImageView) findViewById(R.id.barcode);
ImageView menuView = (ImageView) findViewById(R.id.menu);
menuView.setOnClickListener(this);
menu_layout = (LinearLayout) findViewById(R.id.menu_layout);
menu_layout.setOnClickListener(this);
findViewById(R.id.main_layout).setOnClickListener(this);
findViewById(R.id.help).setOnClickListener(this);
findViewById(R.id.feedback).setOnClickListener(this);
findViewById(R.id.about).setOnClickListener(this);
findViewById(R.id.disclaimer).setOnClickListener(this);
findViewById(R.id.avs_title).setOnClickListener(this);
mMyAvsHelper = new MyAvsHelper(getApplicationContext());
mMyAvsHelper.setViews(cidView, pwdView, statusView, deviceName, barCodeView);
mMyAvsHelper.login();
final int[] size = mMyAvsHelper.getVideoSize();
mMediaSurfaceView = (MediaSurfaceView) findViewById(R.id.cameraView);
mMediaSurfaceView.openCamera(mMyAvsHelper);
ViewTreeObserver viewTreeObserver = mMediaSurfaceView.getViewTreeObserver();
viewTreeObserver.addOnPreDrawListener(new OnPreDrawListener(){
@Override
public boolean onPreDraw(){
if (isFirst){
int height = mMediaSurfaceView.getMeasuredHeight();
int width = mMediaSurfaceView.getMeasuredWidth();
float r = (float)height/(float)width;
float r2 = (float)size[1]/(float)size[0];
RelativeLayout.LayoutParams pvLayout = (RelativeLayout.LayoutParams) mMediaSurfaceView.getLayoutParams();
if (r > r2){
pvLayout.height = (int) (width*r2);
}else{
pvLayout.width = (int) (height/r2);
}
isFirst = false;
}
return true;
}
});
mShowChinese = "zh".equals(Locale.getDefault().getLanguage().toLowerCase());
//update
UmengUpdateAgent.setUpdateOnlyWifi(false);
UmengUpdateAgent.update(this);
}
public void gridviewInit() {
adapter = new GridAdapter(getActivity());
adapter.setSelectedPosition(0);
int size = 0;
if (bmp.size() < 6) {
size = bmp.size() + 1;
} else {
size = bmp.size();
}
LayoutParams params = gridview.getLayoutParams();
final int width = size * (int) (dp * 9.4f);
params.width = width;
gridview.setLayoutParams(params);
gridview.setColumnWidth((int) (dp * 9.4f));
gridview.setStretchMode(GridView.NO_STRETCH);
gridview.setNumColumns(size);
gridview.setAdapter(adapter);
gridview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
/*((InputMethodManager) getActivity().getSystemService(INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(getActivity()
.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);*/
if (arg2 == bmp.size()) {
String sdcardState = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(sdcardState)) {
showDialog();
} else {
Toast.makeText(getActivity(), "sdcard不存在?",
Toast.LENGTH_SHORT).show();
}
} else {
}
}
});
selectimg_horizontalScrollView.getViewTreeObserver()
.addOnPreDrawListener(
new OnPreDrawListener() {
public boolean onPreDraw() {
selectimg_horizontalScrollView.scrollTo(width,
0);
selectimg_horizontalScrollView
.getViewTreeObserver()
.removeOnPreDrawListener(this);
return false;
}
});
}