Java Code Examples for android.view.ViewTreeObserver.OnPreDrawListener

The following examples show how to use android.view.ViewTreeObserver.OnPreDrawListener. These examples are extracted from open source projects.
Example 1
Project: letv   File: BackStackRecord.java    License: Apache License 2.0 6 votes vote down vote up
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;
        }
    });
}
 
Example 2
Project: glide-support   File: TestFragment.java    License: The Unlicense 6 votes vote down vote up
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);
	}
}
 
Example 3
Project: ViewUtils   File: ExpandTextView.java    License: Apache License 2.0 6 votes vote down vote up
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;
        }
    });

}
 
Example 4
Project: UltimateAndroid   File: TriangleView.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @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;
				}
			});
}
 
Example 5
Project: UltimateAndroid   File: RotaryView.java    License: Apache License 2.0 6 votes vote down vote up
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;
				}
			});
}
 
Example 6
Project: UltimateAndroid   File: TriangleView.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @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;
				}
			});
}
 
Example 7
Project: UltimateAndroid   File: RotaryView.java    License: Apache License 2.0 6 votes vote down vote up
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;
				}
			});
}
 
Example 8
Project: Auie   File: UEFontAwesome.java    License: GNU General Public License v2.0 6 votes vote down vote up
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;
		}
	});
}
 
Example 9
Project: Auie   File: UI2048GameView.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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;
		}
	});
}
 
Example 10
Project: Auie   File: UISwitchButton.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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;
		}
	});
}
 
Example 11
Project: WidgyWidgets   File: KnobViewActivity.java    License: Apache License 2.0 6 votes vote down vote up
@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;
		}
	});
}
 
Example 12
Project: qvod   File: TextViewExpandableAnimation.java    License: MIT License 5 votes vote down vote up
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();
        }

    }
 
Example 13
Project: letv   File: StarRankActivity.java    License: Apache License 2.0 5 votes vote down vote up
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;
        }
    });
}
 
Example 14
Project: letv   File: StarActivity.java    License: Apache License 2.0 5 votes vote down vote up
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;
        }
    });
}
 
Example 15
Project: letv   File: BackStackRecord.java    License: Apache License 2.0 5 votes vote down vote up
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;
        }
    });
}
 
Example 16
Project: material-components-android   File: ClockFaceView.java    License: Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 17
Project: material-components-android   File: ExpandableBehavior.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 18
Project: Modularity   File: DragGridView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 交换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;
            }
        });

    }
}
 
Example 19
Project: android-common-utils   File: ExpandNetworkImageView.java    License: Apache License 2.0 5 votes vote down vote up
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;
			}
		});
	}
	
}
 
Example 20
Project: BlurView   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 21
Project: KJFrameForAndroid   File: KJDragGridView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 交换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;
            }
        });

    }
}
 
Example 22
Project: GestureViews   File: FullImageActivity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 23
Project: UltimateAndroid   File: HomeArc.java    License: Apache License 2.0 5 votes vote down vote up
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;
				}
			});
}
 
Example 24
Project: UltimateAndroid   File: HomeArc.java    License: Apache License 2.0 5 votes vote down vote up
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;
				}
			});
}
 
Example 25
Project: Auie   File: UIEditText.java    License: GNU General Public License v2.0 5 votes vote down vote up
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;
		}
	});
}
 
Example 26
Project: letv   File: MyDownloadSubActivity.java    License: Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 27
Project: letv   File: MyDownloadSubActivity.java    License: Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 28
Project: AVS   File: AvsActivity.java    License: Apache License 2.0 4 votes vote down vote up
@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);
	
}
 
Example 29
Project: AVS   File: AvsActivity.java    License: Apache License 2.0 4 votes vote down vote up
@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);
	
}
 
Example 30
Project: WeCenterMobile-Android   File: DetailFragment.java    License: GNU General Public License v2.0 4 votes vote down vote up
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;
						}
					});
}
 
Example 31
Project: WeCenterMobile-Android   File: WriteAnswerActivity.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void gridviewInit() {
	adapter = new GridAdapter(this);
	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(WriteAnswerActivity.this, "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;
						}
					});
}
 
Example 32
Project: FreeFlow   File: FreeFlowContainerTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Tests that changing an attached layout cannot change 
 * the internal map of the item proxies insode a container
 * 
 * @throws InterruptedException
 */
public void testSourceCannotModifyFreeFlowContainerReferences() throws InterruptedException{
	final CountDownLatch lock = new CountDownLatch(1);
	main.runOnUiThread(new Runnable() {
		
		@Override
		public void run() {
			
			final FreeFlowContainer container = new FreeFlowContainer(main);
						
			
			final VLayout vLayout = new VLayout();
			vLayout.setLayoutParams(new VLayout.LayoutParams(300, 200, 10));
			container.setLayout(vLayout);
			
			final DefaultSectionAdapter adapter = new DefaultSectionAdapter(main, 1, 2);
			container.setAdapter(adapter);
			
			
			main.setContentView(container);	
			
			container.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
				@Override
				public boolean onPreDraw() {
					
					int frameCount = container.getFrames().size();
					adapter.setData(5, 10);
					
					// setItems will force new frames to be generated, but not set 
					vLayout.setAdapter(adapter); 
					vLayout.prepareLayout() ;
					
					//assertEquals("Layout frames did not generate as expected", 5*(10+1), vLayout.getAllProxies().size());
					assertEquals("FreeFlowContainer frames changed unexpectedly with data", frameCount, container.getFrames().size());
					
					lock.countDown();
					return false;
				}
			});
		}
	});
	lock.await(5000, TimeUnit.MILLISECONDS);
}
 
Example 33
Project: UltimateAndroid   File: FilckerAnimationListView.java    License: Apache License 2.0 3 votes vote down vote up
private void doAnimation() {
	setEnabled(false);
	animating = true;

	final float durationUnit = (float) MAX_ANIM_DURATION / getHeight();

	animatePreLayout(durationUnit, new AnimatorListenerAdapter() {
		@Override
		public void onAnimationEnd(final Animator animation) {
			adapter.notifyDataSetChanged();

			getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {

				@Override
				public boolean onPreDraw() {
					getViewTreeObserver().removeOnPreDrawListener(this);

					animatePostLayout(durationUnit);

					return true;
				}

			});
		}

	});

}
 
Example 34
Project: UltimateAndroid   File: FilckerAnimationListView.java    License: Apache License 2.0 3 votes vote down vote up
private void doAnimation() {
	setEnabled(false);
	animating = true;

	final float durationUnit = (float) MAX_ANIM_DURATION / getHeight();

	animatePreLayout(durationUnit, new AnimatorListenerAdapter() {
		@Override
		public void onAnimationEnd(final Animator animation) {
			adapter.notifyDataSetChanged();

			getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {

				@Override
				public boolean onPreDraw() {
					getViewTreeObserver().removeOnPreDrawListener(this);

					animatePostLayout(durationUnit);

					return true;
				}

			});
		}

	});

}
 
Example 35
Project: AnimationListView   File: AnimationListView.java    License: Apache License 2.0 3 votes vote down vote up
private void doAnimation() {
	setEnabled(false);
	animating = true;

	final float durationUnit = (float) MAX_ANIM_DURATION / getHeight();

	animatePreLayout(durationUnit, new AnimatorListenerAdapter() {
		@Override
		public void onAnimationEnd(final Animator animation) {
			adapter.notifyDataSetChanged();

			getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {

				@Override
				public boolean onPreDraw() {
					getViewTreeObserver().removeOnPreDrawListener(this);

					animatePostLayout(durationUnit);

					return true;
				}

			});
		}

	});

}