android.view.ViewTreeObserver.OnPreDrawListener Java Examples
The following examples show how to use
android.view.ViewTreeObserver.OnPreDrawListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UISwitchButton.java From Auie with GNU General Public License v2.0 | 6 votes |
@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 #2
Source File: TriangleView.java From UltimateAndroid with Apache License 2.0 | 6 votes |
/** * * @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 #3
Source File: RotaryView.java From UltimateAndroid with Apache License 2.0 | 6 votes |
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 #4
Source File: RotaryView.java From UltimateAndroid with Apache License 2.0 | 6 votes |
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 #5
Source File: TriangleView.java From UltimateAndroid with Apache License 2.0 | 6 votes |
/** * * @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 #6
Source File: UEFontAwesome.java From Auie with GNU General Public License v2.0 | 6 votes |
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 #7
Source File: UI2048GameView.java From Auie with GNU General Public License v2.0 | 6 votes |
@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 #8
Source File: ExpandTextView.java From ViewUtils with Apache License 2.0 | 6 votes |
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 #9
Source File: KnobViewActivity.java From WidgyWidgets with Apache License 2.0 | 6 votes |
@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 #10
Source File: TestFragment.java From glide-support with The Unlicense | 6 votes |
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 #11
Source File: BackStackRecord.java From letv with Apache License 2.0 | 6 votes |
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 #12
Source File: ClockFaceView.java From material-components-android with Apache License 2.0 | 5 votes |
@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 #13
Source File: HomeArc.java From UltimateAndroid with Apache License 2.0 | 5 votes |
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 #14
Source File: HomeArc.java From UltimateAndroid with Apache License 2.0 | 5 votes |
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 #15
Source File: StarRankActivity.java From letv with Apache License 2.0 | 5 votes |
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 #16
Source File: StarActivity.java From letv with Apache License 2.0 | 5 votes |
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 #17
Source File: FullImageActivity.java From GestureViews with Apache License 2.0 | 5 votes |
/** * 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 #18
Source File: KJDragGridView.java From KJFrameForAndroid with Apache License 2.0 | 5 votes |
/** * 交换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 #19
Source File: TextViewExpandableAnimation.java From qvod with MIT License | 5 votes |
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 #20
Source File: BackStackRecord.java From letv with Apache License 2.0 | 5 votes |
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 #21
Source File: MainActivity.java From BlurView with Apache License 2.0 | 5 votes |
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 #22
Source File: ExpandNetworkImageView.java From android-common-utils with Apache License 2.0 | 5 votes |
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 #23
Source File: DragGridView.java From Modularity with Apache License 2.0 | 5 votes |
/** * 交换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 #24
Source File: ExpandableBehavior.java From material-components-android with Apache License 2.0 | 5 votes |
@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 #25
Source File: UIEditText.java From Auie with GNU General Public License v2.0 | 5 votes |
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
Source File: WriteAnswerActivity.java From WeCenterMobile-Android with GNU General Public License v2.0 | 4 votes |
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 #27
Source File: FreeFlowContainerTest.java From FreeFlow with Apache License 2.0 | 4 votes |
/** * 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 #28
Source File: DetailFragment.java From WeCenterMobile-Android with GNU General Public License v2.0 | 4 votes |
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 #29
Source File: AvsActivity.java From AVS with Apache License 2.0 | 4 votes |
@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
Source File: AvsActivity.java From AVS with Apache License 2.0 | 4 votes |
@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); }