List of usage examples for android.widget ImageView setVisibility
@RemotableViewMethod @Override public void setVisibility(int visibility)
From source file:cn.dev4mob.app.ui.animationsdemo.ZoomActivity.java
/** * "Zooms" in a thumbnail view by assigning the high resolution image to a hidden "zoomed-in" * image view and animating its bounds to fit the entire activity content area. More * specifically:/*w w w. j a v a2 s . c o m*/ * * <ol> * <li>Assign the high-res image to the hidden "zoomed-in" (expanded) image view.</li> * <li>Calculate the starting and ending bounds for the expanded view.</li> * <li>Animate each of four positioning/sizing properties (X, Y, SCALE_X, SCALE_Y) * simultaneously, from the starting bounds to the ending bounds.</li> * <li>Zoom back out by running the reverse animation on click.</li> * </ol> * * @param thumbView The thumbnail view to zoom in. * @param imageResId The high-resolution version of the image represented by the thumbnail. */ private void zoomImageFromThumb(final View thumbView, int imageResId) { // If there's an animation in progress, cancel it immediately and proceed with this one. if (mCurrentAnimator != null) { mCurrentAnimator.cancel(); } // Load the high-resolution "zoomed-in" image. final ImageView expandedImageView = (ImageView) findViewById(R.id.expanded_image); expandedImageView.setImageResource(imageResId); // Calculate the starting and ending bounds for the zoomed-in image. This step // involves lots of math. Yay, math. final Rect startBounds = new Rect(); final Rect finalBounds = new Rect(); final Point globalOffset = new Point(); // The start bounds are the global visible rectangle of the thumbnail, and the // final bounds are the global visible rectangle of the container view. Also // set the container view's offset as the origin for the bounds, since that's // the origin for the positioning animation properties (X, Y). thumbView.getGlobalVisibleRect(startBounds); Timber.d("thumbview startBounds = %s", startBounds); findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset); Timber.d("thumbview finalBoundst = %s", finalBounds); Timber.d("thumbview globalOffset = %s", globalOffset); startBounds.offset(-globalOffset.x, -globalOffset.y); finalBounds.offset(-globalOffset.x, -globalOffset.y); // Adjust the start bounds to be the same aspect ratio as the final bounds using the // "center crop" technique. This prevents undesirable stretching during the animation. // Also calculate the start scaling factor (the end scaling factor is always 1.0). float startScale; if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width() / startBounds.height()) { // Extend start bounds horizontally startScale = (float) startBounds.height() / finalBounds.height(); float startWidth = startScale * finalBounds.width(); float deltaWidth = (startWidth - startBounds.width()) / 2; startBounds.left -= deltaWidth; startBounds.right += deltaWidth; } else { // Extend start bounds vertically startScale = (float) startBounds.width() / finalBounds.width(); Timber.d("startSCale = %f", startScale); float startHeight = startScale * finalBounds.height(); float deltaHeight = (startHeight - startBounds.height()) / 2; startBounds.top -= deltaHeight; startBounds.bottom += deltaHeight; } // Hide the thumbnail and show the zoomed-in view. When the animation begins, // it will position the zoomed-in view in the place of the thumbnail. thumbView.setAlpha(0f); expandedImageView.setVisibility(View.VISIBLE); // Set the pivot point for SCALE_X and SCALE_Y transformations to the top-left corner of // the zoomed-in view (the default is the center of the view). expandedImageView.setPivotX(0f); expandedImageView.setPivotY(0f); // Construct and run the parallel animation of the four translation and scale properties // (X, Y, SCALE_X, and SCALE_Y). AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left, finalBounds.left)) .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, finalBounds.top)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f)); set.setDuration(mShortAnimationDuration); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCurrentAnimator = null; } @Override public void onAnimationCancel(Animator animation) { mCurrentAnimator = null; } }); set.start(); mCurrentAnimator = set; // Upon clicking the zoomed-in image, it should zoom back down to the original bounds // and show the thumbnail instead of the expanded image. final float startScaleFinal = startScale; expandedImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mCurrentAnimator != null) { mCurrentAnimator.cancel(); } // Animate the four positioning/sizing properties in parallel, back to their // original values. AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left)) .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal)); set.setDuration(mShortAnimationDuration); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { thumbView.setAlpha(1f); expandedImageView.setVisibility(View.GONE); mCurrentAnimator = null; } @Override public void onAnimationCancel(Animator animation) { thumbView.setAlpha(1f); expandedImageView.setVisibility(View.GONE); mCurrentAnimator = null; } }); set.start(); mCurrentAnimator = set; } }); }
From source file:ua.mkh.settings.full.MainActivity.java
private void ifest() { if (vk_app == null) { ImageView im9 = (ImageView) findViewById(R.id.ImageView99); im9.setVisibility(View.GONE); if (viber_app == null) { ImageView im91 = (ImageView) findViewById(R.id.ImageView96); im91.setVisibility(View.GONE); if (ok_app == null) { ImageView im92 = (ImageView) findViewById(R.id.ImageView93); im92.setVisibility(View.GONE); if (skype_app == null) { ImageView im93 = (ImageView) findViewById(R.id.ImageView90); im93.setVisibility(View.GONE); if (whatsapp_app == null) { ImageView im94 = (ImageView) findViewById(R.id.ImageView87); im94.setVisibility(View.GONE); if (twitter_app == null) { ImageView im95 = (ImageView) findViewById(R.id.ImageView84); im95.setVisibility(View.GONE); if (facebook_app == null) { ImageView im96 = (ImageView) findViewById(R.id.ImageView31); im96.setVisibility(View.GONE); if (instagram_app == null) { ImageView im1 = (ImageView) findViewById(R.id.ImageView34); ImageView im2 = (ImageView) findViewById(R.id.ImageView82); im1.setVisibility(View.GONE); im2.setVisibility(View.GONE); LinearLayout LinearLayoutSoc = (LinearLayout) findViewById( R.id.LinearLayoutSoc); LinearLayoutSoc.setVisibility(View.GONE); }//from w w w . ja v a2s . c o m } } } } } } } if (music_app == null) { ImageView im1 = (ImageView) findViewById(R.id.ImageView454); im1.setVisibility(View.GONE); if (gamecenter_app == null) { ImageView im2 = (ImageView) findViewById(R.id.ImageView393); im2.setVisibility(View.GONE); if (weather_app == null) { ImageView im5 = (ImageView) findViewById(R.id.ImageView105); im5.setVisibility(View.GONE); if (maps_app == null) { ImageView im7 = (ImageView) findViewById(R.id.ImageView154); im7.setVisibility(View.GONE); if (new1_app == null) { ImageView im8 = (ImageView) findViewById(R.id.ImageView64); im8.setVisibility(View.GONE); if (new2_app == null) { ImageView im9 = (ImageView) findViewById(R.id.ImageView67); im9.setVisibility(View.GONE); if (new3_app == null) { ImageView im10 = (ImageView) findViewById(R.id.ImageView70); im10.setVisibility(View.GONE); if (new4_app == null) { ImageView im3 = (ImageView) findViewById(R.id.ImageView80); ImageView im4 = (ImageView) findViewById(R.id.ImageView102); im3.setVisibility(View.GONE); im4.setVisibility(View.GONE); LinearLayout LinearLayoutAnother = (LinearLayout) findViewById( R.id.LinearLayoutAnother); LinearLayoutAnother.setVisibility(View.GONE); } } } } } } } } if (mail_app == null) { ImageView im7 = (ImageView) findViewById(R.id.ImageView107); im7.setVisibility(View.GONE); if (notes_app == null) { ImageView im8 = (ImageView) findViewById(R.id.ImageView41); im8.setVisibility(View.GONE); if (phone_app == null) { ImageView im9 = (ImageView) findViewById(R.id.ImageView50); im9.setVisibility(View.GONE); if (messages_app == null) { ImageView im10 = (ImageView) findViewById(R.id.ImageView55); im10.setVisibility(View.GONE); if (compass_app == null) { ImageView im11 = (ImageView) findViewById(R.id.ImageView32); im11.setVisibility(View.GONE); if (safari_app == null) { LinearLayout LinearLayout1 = (LinearLayout) findViewById(R.id.LinearLayout1); LinearLayout1.setVisibility(View.GONE); ImageView im5 = (ImageView) findViewById(R.id.ImageView37); ImageView im6 = (ImageView) findViewById(R.id.ImageView106); im5.setVisibility(View.GONE); im6.setVisibility(View.GONE); } } } } } } }
From source file:io.github.trulyfree.easyaspi.MainActivity.java
@Override public boolean setup() { downloadHandler = new DownloadHandler(this); fileHandler = new FileHandler(this); moduleHandler = new ModuleHandler(this); executorService = Executors.newCachedThreadPool(); setContentView(R.layout.activity_main); BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation); navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override//from ww w .ja va2 s . co m public boolean onNavigationItemSelected(@NonNull MenuItem item) { ViewSwitcher viewGroup = (ViewSwitcher) findViewById(R.id.content); int id = item.getItemId(); if ((id == R.id.navigation_home || id == R.id.navigation_modules) && id != currentID) { currentID = item.getItemId(); viewGroup.showNext(); return true; } return false; } }); ViewSwitcher viewSwitcher = (ViewSwitcher) findViewById(R.id.content); Animation in = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left); Animation out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right); viewSwitcher.setInAnimation(in); viewSwitcher.setOutAnimation(out); resetConfigReturned(); Button getNewModule = (Button) findViewById(R.id.new_module_config_confirm); getNewModule.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { EditText editText = (EditText) findViewById(R.id.new_module_config_configurl); final String url = editText.getText().toString(); Toast.makeText(MainActivity.this, "Requested config from: " + url, Toast.LENGTH_SHORT).show(); executorService.submit(new Callable<Boolean>() { @Override public Boolean call() { ModuleConfig config; try { config = moduleHandler.getModuleConfig(url); } catch (MalformedURLException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, "Invalid URL. :(", Toast.LENGTH_LONG).show(); } }); return false; } catch (IOException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, "Failed to get module config. :(", Toast.LENGTH_LONG).show(); } }); return false; } catch (JsonParseException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, "Config loaded was invalid. :(", Toast.LENGTH_LONG).show(); } }); return false; } final ModuleConfig finalConfig = config; final ImageView configResponseBlock = (ImageView) findViewById(R.id.block_module_returned); final int colorFrom = ContextCompat.getColor(MainActivity.this, R.color.colorFillingTint); final int colorTo = ContextCompat.getColor(MainActivity.this, R.color.colorClear); final ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(ANIMATION_DURATION); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { configResponseBlock.setBackgroundColor((Integer) animator.getAnimatedValue()); } }); colorAnimation.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { LinearLayout layout = (LinearLayout) findViewById(R.id.module_returned_config); EditText moduleName = (EditText) findViewById(R.id.module_returned_configname); EditText moduleVersion = (EditText) findViewById( R.id.module_returned_configversion); EditText moduleConfigUrl = (EditText) findViewById(R.id.module_returned_configurl); EditText moduleJarUrl = (EditText) findViewById(R.id.module_returned_jarurl); LinearLayout moduleDependencies = (LinearLayout) findViewById( R.id.module_returned_dependencies); moduleDependencies.removeAllViewsInLayout(); try { configResponseBlock.setVisibility(View.GONE); moduleName.setText(finalConfig.getName()); moduleVersion.setText(finalConfig.getVersion()); moduleConfigUrl.setText(finalConfig.getConfUrl()); moduleJarUrl.setText(finalConfig.getJarUrl()); Config[] dependencies = finalConfig.getDependencies(); for (Config dependency : dependencies) { LinearLayout dependencyLayout = new LinearLayout(MainActivity.this); dependencyLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); dependencyLayout.setOrientation(LinearLayout.HORIZONTAL); EditText name = new EditText(MainActivity.this); EditText jarUrl = new EditText(MainActivity.this); EditText[] loopThrough = { name, jarUrl }; LayoutParams params = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.0f); for (EditText item : loopThrough) { item.setLayoutParams(params); item.setClickable(false); item.setInputType(InputType.TYPE_NULL); item.setCursorVisible(false); item.setFocusable(false); item.setFocusableInTouchMode(false); } name.setText(dependency.getName()); jarUrl.setText(dependency.getJarUrl()); dependencyLayout.addView(name); dependencyLayout.addView(jarUrl); moduleDependencies.addView(dependencyLayout); } layout.setClickable(true); Button validate = (Button) findViewById(R.id.module_returned_validate); Button cancel = (Button) findViewById(R.id.module_returned_cancel); validate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(MainActivity.this, "Requesting jars...", Toast.LENGTH_SHORT).show(); executorService.submit(new Callable<Boolean>() { @Override public Boolean call() { try { boolean success = true, refreshAllModification = true; Button refreshAll = null, getNewModule = (Button) findViewById( R.id.new_module_config_confirm); try { refreshAll = (Button) findViewById(R.id.refresh_all); refreshAll.setClickable(false); } catch (Throwable e) { refreshAllModification = false; } getNewModule.setClickable(false); final TextView stager = (TextView) findViewById( R.id.new_module_config_downloadstage); final ProgressBar progressBar = (ProgressBar) findViewById( R.id.new_module_config_downloadprogress); try { runOnUiThread(new Runnable() { @Override public void run() { resetConfigReturned(); } }); moduleHandler.getNewModule( makeModuleCallback(stager, progressBar), finalConfig, null, true); } catch (IOException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { stager.setText(""); progressBar.setProgress(0); } }); success = false; } getNewModule.setClickable(true); if (refreshAllModification) { refreshAll.setClickable(true); } return success; } catch (Throwable throwable) { throwable.printStackTrace(); return false; } } }); } }); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(MainActivity.this, "Cancelling request...", Toast.LENGTH_SHORT).show(); resetConfigReturned(); } }); } catch (Exception e) { e.printStackTrace(); Toast.makeText(MainActivity.this, "Module config invalid. :(", Toast.LENGTH_LONG).show(); layout.setClickable(false); final int colorFrom = ContextCompat.getColor(MainActivity.this, R.color.colorClear); final int colorTo = ContextCompat.getColor(MainActivity.this, R.color.colorFillingTint); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(ANIMATION_DURATION); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { configResponseBlock .setBackgroundColor((Integer) animator.getAnimatedValue()); } }); } } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); runOnUiThread(new Runnable() { @Override public void run() { colorAnimation.start(); } }); return true; } }); } }); moduleHandler.setup(); refreshFilling(); return true; }
From source file:com.htc.dotdesign.ToolBoxService.java
private void setSelectedColor(ImageView button) { Drawable select = getResources().getDrawable(R.drawable.dot_design_select); select.setColorFilter(getResources().getColor(R.color.overlay_color), Mode.SRC_IN); ImageView selectedIcon = (ImageView) mPalette.findViewById(R.id.selected); selectedIcon.setBackground(select);//from w w w . ja va2 s. c o m Resources res = getResources(); int id = button.getId(); int buttonLeft = button.getLeft(); int buttonTop = button.getTop(); int m1 = res.getDimensionPixelSize(R.dimen.margin_l); int m2 = res.getDimensionPixelSize(R.dimen.margin_m); int colorSize = res.getDimensionPixelSize(R.dimen.hv01); if (id == R.id.btn_color_11 || id == R.id.btn_color_12 || id == R.id.btn_color_13 || id == R.id.btn_color_14) { buttonTop = m2; } else if (id == R.id.btn_color_21 || id == R.id.btn_color_22 || id == R.id.btn_color_23 || id == R.id.btn_color_24) { buttonTop = m2 + colorSize + m1; } else { buttonTop = m2 + 2 * colorSize + 2 * m1; } if (id == R.id.btn_color_11 || id == R.id.btn_color_21 || id == R.id.btn_color_31) { buttonLeft = m2; } else if (id == R.id.btn_color_12 || id == R.id.btn_color_22 || id == R.id.btn_color_32) { buttonLeft = 3 * m2 + colorSize; } else if (id == R.id.btn_color_13 || id == R.id.btn_color_23 || id == R.id.btn_color_33) { buttonLeft = 5 * m2 + 2 * colorSize; } else { buttonLeft = 7 * m2 + 3 * colorSize; } int widthDiff = res.getDimensionPixelSize(R.dimen.select_color_width) - colorSize; int heightDiff = res.getDimensionPixelSize(R.dimen.select_color_height) - colorSize; int marginLeft = buttonLeft - (widthDiff / 2); int marginTop = buttonTop - (heightDiff / 2); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) selectedIcon.getLayoutParams(); params.setMargins(marginLeft, marginTop, 0, 0); selectedIcon.setLayoutParams(params); selectedIcon.setVisibility(View.VISIBLE); }
From source file:org.telegram.ui.Components.ChatAttachAlert.java
public ChatAttachAlert(Context context, final ChatActivity parentFragment) { super(context, false); baseFragment = parentFragment;// w ww . ja v a2 s. c o m setDelegate(this); setUseRevealAnimation(true); checkCamera(false); if (deviceHasGoodCamera) { CameraController.getInstance().initCamera(); } NotificationCenter.getInstance().addObserver(this, NotificationCenter.albumsDidLoaded); NotificationCenter.getInstance().addObserver(this, NotificationCenter.reloadInlineHints); NotificationCenter.getInstance().addObserver(this, NotificationCenter.cameraInitied); shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow); containerView = listView = new RecyclerListView(context) { private int lastWidth; private int lastHeight; @Override public void requestLayout() { if (ignoreLayout) { return; } super.requestLayout(); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (cameraAnimationInProgress) { return true; } else if (cameraOpened) { return processTouchEvent(ev); } else if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0 && ev.getY() < scrollOffsetY) { dismiss(); return true; } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent event) { if (cameraAnimationInProgress) { return true; } else if (cameraOpened) { return processTouchEvent(event); } return !isDismissed() && super.onTouchEvent(event); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height = MeasureSpec.getSize(heightMeasureSpec); if (Build.VERSION.SDK_INT >= 21) { height -= AndroidUtilities.statusBarHeight; } int contentSize = backgroundPaddingTop + AndroidUtilities.dp(294) + (SearchQuery.inlineBots.isEmpty() ? 0 : ((int) Math.ceil(SearchQuery.inlineBots.size() / 4.0f) * AndroidUtilities.dp(100) + AndroidUtilities.dp(12))); int padding = contentSize == AndroidUtilities.dp(294) ? 0 : Math.max(0, (height - AndroidUtilities.dp(294))); if (padding != 0 && contentSize < height) { padding -= (height - contentSize); } if (padding == 0) { padding = backgroundPaddingTop; } if (getPaddingTop() != padding) { ignoreLayout = true; setPadding(backgroundPaddingLeft, padding, backgroundPaddingLeft, 0); ignoreLayout = false; } super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(Math.min(contentSize, height), MeasureSpec.EXACTLY)); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int width = right - left; int height = bottom - top; int newPosition = -1; int newTop = 0; int count = listView.getChildCount(); int lastVisibleItemPosition = -1; int lastVisibleItemPositionTop = 0; if (count > 0) { View child = listView.getChildAt(listView.getChildCount() - 1); Holder holder = (Holder) listView.findContainingViewHolder(child); if (holder != null) { lastVisibleItemPosition = holder.getAdapterPosition(); lastVisibleItemPositionTop = child.getTop(); } } if (lastVisibleItemPosition >= 0 && height - lastHeight != 0) { newPosition = lastVisibleItemPosition; newTop = lastVisibleItemPositionTop + height - lastHeight - getPaddingTop(); } super.onLayout(changed, left, top, right, bottom); if (newPosition != -1) { ignoreLayout = true; layoutManager.scrollToPositionWithOffset(newPosition, newTop); super.onLayout(false, left, top, right, bottom); ignoreLayout = false; } lastHeight = height; lastWidth = width; updateLayout(); checkCameraViewPosition(); } @Override public void onDraw(Canvas canvas) { if (useRevealAnimation && Build.VERSION.SDK_INT <= 19) { canvas.save(); canvas.clipRect(backgroundPaddingLeft, scrollOffsetY, getMeasuredWidth() - backgroundPaddingLeft, getMeasuredHeight()); if (revealAnimationInProgress) { canvas.drawCircle(revealX, revealY, revealRadius, ciclePaint); } else { canvas.drawRect(backgroundPaddingLeft, scrollOffsetY, getMeasuredWidth() - backgroundPaddingLeft, getMeasuredHeight(), ciclePaint); } canvas.restore(); } else { shadowDrawable.setBounds(0, scrollOffsetY - backgroundPaddingTop, getMeasuredWidth(), getMeasuredHeight()); shadowDrawable.draw(canvas); } } @Override public void setTranslationY(float translationY) { super.setTranslationY(translationY); checkCameraViewPosition(); } }; listView.setWillNotDraw(false); listView.setClipToPadding(false); listView.setLayoutManager(layoutManager = new LinearLayoutManager(getContext())); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); listView.setAdapter(adapter = new ListAdapter(context)); listView.setVerticalScrollBarEnabled(false); listView.setEnabled(true); listView.setGlowColor(0xfff5f6f7); listView.addItemDecoration(new RecyclerView.ItemDecoration() { @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { outRect.left = 0; outRect.right = 0; outRect.top = 0; outRect.bottom = 0; } }); listView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { if (listView.getChildCount() <= 0) { return; } if (hintShowed) { if (layoutManager.findLastVisibleItemPosition() > 1) { hideHint(); hintShowed = false; ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).edit() .putBoolean("bothint", true).commit(); } } updateLayout(); checkCameraViewPosition(); } }); containerView.setPadding(backgroundPaddingLeft, 0, backgroundPaddingLeft, 0); attachView = new FrameLayout(context) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(294), MeasureSpec.EXACTLY)); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int width = right - left; int height = bottom - top; int t = AndroidUtilities.dp(8); attachPhotoRecyclerView.layout(0, t, width, t + attachPhotoRecyclerView.getMeasuredHeight()); progressView.layout(0, t, width, t + progressView.getMeasuredHeight()); lineView.layout(0, AndroidUtilities.dp(96), width, AndroidUtilities.dp(96) + lineView.getMeasuredHeight()); hintTextView.layout(width - hintTextView.getMeasuredWidth() - AndroidUtilities.dp(5), height - hintTextView.getMeasuredHeight() - AndroidUtilities.dp(5), width - AndroidUtilities.dp(5), height - AndroidUtilities.dp(5)); int diff = (width - AndroidUtilities.dp(85 * 4 + 20)) / 3; for (int a = 0; a < 8; a++) { int y = AndroidUtilities.dp(105 + 95 * (a / 4)); int x = AndroidUtilities.dp(10) + (a % 4) * (AndroidUtilities.dp(85) + diff); views[a].layout(x, y, x + views[a].getMeasuredWidth(), y + views[a].getMeasuredHeight()); } } }; views[8] = attachPhotoRecyclerView = new RecyclerListView(context); attachPhotoRecyclerView.setVerticalScrollBarEnabled(true); attachPhotoRecyclerView.setAdapter(photoAttachAdapter = new PhotoAttachAdapter(context)); attachPhotoRecyclerView.setClipToPadding(false); attachPhotoRecyclerView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0); attachPhotoRecyclerView.setItemAnimator(null); attachPhotoRecyclerView.setLayoutAnimation(null); attachPhotoRecyclerView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER); attachView.addView(attachPhotoRecyclerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 80)); attachPhotoLayoutManager = new LinearLayoutManager(context) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }; attachPhotoLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); attachPhotoRecyclerView.setLayoutManager(attachPhotoLayoutManager); attachPhotoRecyclerView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @SuppressWarnings("unchecked") @Override public void onItemClick(View view, int position) { if (baseFragment == null || baseFragment.getParentActivity() == null) { return; } if (!deviceHasGoodCamera || position != 0) { if (deviceHasGoodCamera) { position--; } if (MediaController.allPhotosAlbumEntry == null) { return; } ArrayList<Object> arrayList = (ArrayList) MediaController.allPhotosAlbumEntry.photos; if (position < 0 || position >= arrayList.size()) { return; } PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity()); PhotoViewer.getInstance().openPhotoForSelect(arrayList, position, 0, ChatAttachAlert.this, baseFragment); AndroidUtilities.hideKeyboard(baseFragment.getFragmentView().findFocus()); } else { openCamera(); } } }); attachPhotoRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { checkCameraViewPosition(); } }); views[9] = progressView = new EmptyTextProgressView(context); if (Build.VERSION.SDK_INT >= 23 && getContext().checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { progressView.setText(LocaleController.getString("PermissionStorage", R.string.PermissionStorage)); progressView.setTextSize(16); } else { progressView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos)); progressView.setTextSize(20); } attachView.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 80)); attachPhotoRecyclerView.setEmptyView(progressView); views[10] = lineView = new View(getContext()) { @Override public boolean hasOverlappingRendering() { return false; } }; lineView.setBackgroundColor(ContextCompat.getColor(context, R.color.divider)); attachView.addView(lineView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.TOP | Gravity.LEFT)); CharSequence[] items = new CharSequence[] { LocaleController.getString("ChatCamera", R.string.ChatCamera), LocaleController.getString("ChatGallery", R.string.ChatGallery), LocaleController.getString("ChatVideo", R.string.ChatVideo), LocaleController.getString("AttachMusic", R.string.AttachMusic), LocaleController.getString("ChatDocument", R.string.ChatDocument), LocaleController.getString("AttachContact", R.string.AttachContact), LocaleController.getString("ChatLocation", R.string.ChatLocation), "" }; for (int a = 0; a < 8; a++) { AttachButton attachButton = new AttachButton(context); attachButton.setTextAndIcon(items[a], Theme.attachButtonDrawables[a]); attachView.addView(attachButton, LayoutHelper.createFrame(85, 90, Gravity.LEFT | Gravity.TOP)); attachButton.setTag(a); views[a] = attachButton; if (a == 7) { sendPhotosButton = attachButton; sendPhotosButton.imageView.setPadding(0, AndroidUtilities.dp(4), 0, 0); } attachButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { delegate.didPressedButton((Integer) v.getTag()); } }); } hintTextView = new TextView(context); hintTextView.setBackgroundResource(R.drawable.tooltip); hintTextView.setTextColor(Theme.CHAT_GIF_HINT_TEXT_COLOR); hintTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); hintTextView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0); hintTextView.setText(LocaleController.getString("AttachBotsHelp", R.string.AttachBotsHelp)); hintTextView.setGravity(Gravity.CENTER_VERTICAL); hintTextView.setVisibility(View.INVISIBLE); hintTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.scroll_tip, 0, 0, 0); hintTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8)); attachView.addView(hintTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 32, Gravity.RIGHT | Gravity.BOTTOM, 5, 0, 5, 5)); for (int a = 0; a < 8; a++) { viewsCache.add(photoAttachAdapter.createHolder()); } if (loading) { progressView.showProgress(); } else { progressView.showTextView(); } if (Build.VERSION.SDK_INT >= 16) { recordTime = new TextView(context); recordTime.setBackgroundResource(R.drawable.system); recordTime.getBackground() .setColorFilter(new PorterDuffColorFilter(0x66000000, PorterDuff.Mode.MULTIPLY)); recordTime.setText("00:00"); recordTime.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); recordTime.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); recordTime.setAlpha(0.0f); recordTime.setTextColor(0xffffffff); recordTime.setPadding(AndroidUtilities.dp(10), AndroidUtilities.dp(5), AndroidUtilities.dp(10), AndroidUtilities.dp(5)); container.addView(recordTime, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 16, 0, 0)); cameraPanel = new FrameLayout(context) { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int cx = getMeasuredWidth() / 2; int cy = getMeasuredHeight() / 2; int cx2; int cy2; shutterButton.layout(cx - shutterButton.getMeasuredWidth() / 2, cy - shutterButton.getMeasuredHeight() / 2, cx + shutterButton.getMeasuredWidth() / 2, cy + shutterButton.getMeasuredHeight() / 2); if (getMeasuredWidth() == AndroidUtilities.dp(100)) { cx = cx2 = getMeasuredWidth() / 2; cy2 = cy + cy / 2 + AndroidUtilities.dp(17); cy = cy / 2 - AndroidUtilities.dp(17); } else { cx2 = cx + cx / 2 + AndroidUtilities.dp(17); cx = cx / 2 - AndroidUtilities.dp(17); cy = cy2 = getMeasuredHeight() / 2; } switchCameraButton.layout(cx2 - switchCameraButton.getMeasuredWidth() / 2, cy2 - switchCameraButton.getMeasuredHeight() / 2, cx2 + switchCameraButton.getMeasuredWidth() / 2, cy2 + switchCameraButton.getMeasuredHeight() / 2); for (int a = 0; a < 2; a++) { flashModeButton[a].layout(cx - flashModeButton[a].getMeasuredWidth() / 2, cy - flashModeButton[a].getMeasuredHeight() / 2, cx + flashModeButton[a].getMeasuredWidth() / 2, cy + flashModeButton[a].getMeasuredHeight() / 2); } } }; cameraPanel.setVisibility(View.GONE); cameraPanel.setAlpha(0.0f); container.addView(cameraPanel, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 100, Gravity.LEFT | Gravity.BOTTOM)); shutterButton = new ShutterButton(context); cameraPanel.addView(shutterButton, LayoutHelper.createFrame(84, 84, Gravity.CENTER)); shutterButton.setDelegate(new ShutterButton.ShutterButtonDelegate() { @Override public void shutterLongPressed() { if (takingPhoto || baseFragment == null || baseFragment.getParentActivity() == null) { return; } if (Build.VERSION.SDK_INT >= 23) { if (baseFragment.getParentActivity().checkSelfPermission( Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { baseFragment.getParentActivity() .requestPermissions(new String[] { Manifest.permission.RECORD_AUDIO }, 21); return; } } for (int a = 0; a < 2; a++) { flashModeButton[a].setAlpha(0.0f); } switchCameraButton.setAlpha(0.0f); cameraFile = AndroidUtilities.generateVideoPath(); recordTime.setAlpha(1.0f); recordTime.setText("00:00"); videoRecordTime = 0; videoRecordRunnable = new Runnable() { @Override public void run() { if (videoRecordRunnable == null) { return; } videoRecordTime++; recordTime.setText( String.format("%02d:%02d", videoRecordTime / 60, videoRecordTime % 60)); AndroidUtilities.runOnUIThread(videoRecordRunnable, 1000); } }; AndroidUtilities.lockOrientation(parentFragment.getParentActivity()); CameraController.getInstance().recordVideo(cameraView.getCameraSession(), cameraFile, new CameraController.VideoTakeCallback() { @Override public void onFinishVideoRecording(final Bitmap thumb) { if (cameraFile == null || baseFragment == null) { return; } PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity()); cameraPhoto = new ArrayList<>(); cameraPhoto.add(new MediaController.PhotoEntry(0, 0, 0, cameraFile.getAbsolutePath(), 0, true)); PhotoViewer.getInstance().openPhotoForSelect(cameraPhoto, 0, 2, new PhotoViewer.EmptyPhotoViewerProvider() { @Override public Bitmap getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) { return thumb; } @TargetApi(16) @Override public boolean cancelButtonPressed() { if (cameraOpened && cameraView != null && cameraFile != null) { cameraFile.delete(); AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { if (cameraView != null && !isDismissed() && Build.VERSION.SDK_INT >= 21) { cameraView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN); } } }, 1000); CameraController.getInstance() .startPreview(cameraView.getCameraSession()); cameraFile = null; } return true; } @Override public void sendButtonPressed(int index) { if (cameraFile == null) { return; } AndroidUtilities .addMediaToGallery(cameraFile.getAbsolutePath()); baseFragment.sendMedia( (MediaController.PhotoEntry) cameraPhoto.get(0), PhotoViewer.getInstance().isMuteVideo()); closeCamera(false); dismiss(); cameraFile = null; } }, baseFragment); } }); AndroidUtilities.runOnUIThread(videoRecordRunnable, 1000); shutterButton.setState(ShutterButton.State.RECORDING, true); } @Override public void shutterCancel() { cameraFile.delete(); resetRecordState(); CameraController.getInstance().stopVideoRecording(cameraView.getCameraSession(), true); } @Override public void shutterReleased() { if (takingPhoto) { return; } if (shutterButton.getState() == ShutterButton.State.RECORDING) { resetRecordState(); CameraController.getInstance().stopVideoRecording(cameraView.getCameraSession(), false); shutterButton.setState(ShutterButton.State.DEFAULT, true); return; } cameraFile = AndroidUtilities.generatePicturePath(); takingPhoto = CameraController.getInstance().takePicture(cameraFile, cameraView.getCameraSession(), new Runnable() { @Override public void run() { takingPhoto = false; if (cameraFile == null || baseFragment == null) { return; } PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity()); cameraPhoto = new ArrayList<>(); int orientation = 0; try { ExifInterface ei = new ExifInterface(cameraFile.getAbsolutePath()); int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (exif) { case ExifInterface.ORIENTATION_ROTATE_90: orientation = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: orientation = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: orientation = 270; break; } } catch (Exception e) { FileLog.e("tmessages", e); } cameraPhoto.add(new MediaController.PhotoEntry(0, 0, 0, cameraFile.getAbsolutePath(), orientation, false)); PhotoViewer.getInstance().openPhotoForSelect(cameraPhoto, 0, 2, new PhotoViewer.EmptyPhotoViewerProvider() { @TargetApi(16) @Override public boolean cancelButtonPressed() { if (cameraOpened && cameraView != null && cameraFile != null) { cameraFile.delete(); AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { if (cameraView != null && !isDismissed() && Build.VERSION.SDK_INT >= 21) { cameraView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN); } } }, 1000); CameraController.getInstance() .startPreview(cameraView.getCameraSession()); cameraFile = null; } return true; } @Override public void sendButtonPressed(int index) { if (cameraFile == null) { return; } AndroidUtilities .addMediaToGallery(cameraFile.getAbsolutePath()); baseFragment.sendMedia( (MediaController.PhotoEntry) cameraPhoto.get(0), false); closeCamera(false); dismiss(); cameraFile = null; } @Override public boolean scaleToFill() { return true; } }, baseFragment); } }); } }); switchCameraButton = new ImageView(context); switchCameraButton.setScaleType(ImageView.ScaleType.CENTER); cameraPanel.addView(switchCameraButton, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.CENTER_VERTICAL)); switchCameraButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (takingPhoto || cameraView == null || !cameraView.isInitied()) { return; } cameraInitied = false; cameraView.switchCamera(); ObjectAnimator animator = ObjectAnimator.ofFloat(switchCameraButton, "scaleX", 0.0f) .setDuration(100); animator.addListener(new AnimatorListenerAdapterProxy() { @Override public void onAnimationEnd(Animator animator) { switchCameraButton.setImageResource(cameraView.isFrontface() ? R.drawable.camera_revert1 : R.drawable.camera_revert2); ObjectAnimator.ofFloat(switchCameraButton, "scaleX", 1.0f).setDuration(100).start(); } }); animator.start(); } }); for (int a = 0; a < 2; a++) { flashModeButton[a] = new ImageView(context); flashModeButton[a].setScaleType(ImageView.ScaleType.CENTER); flashModeButton[a].setVisibility(View.INVISIBLE); cameraPanel.addView(flashModeButton[a], LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP)); flashModeButton[a].setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View currentImage) { if (flashAnimationInProgress || cameraView == null || !cameraView.isInitied() || !cameraOpened) { return; } String current = cameraView.getCameraSession().getCurrentFlashMode(); String next = cameraView.getCameraSession().getNextFlashMode(); if (current.equals(next)) { return; } cameraView.getCameraSession().setCurrentFlashMode(next); flashAnimationInProgress = true; ImageView nextImage = flashModeButton[0] == currentImage ? flashModeButton[1] : flashModeButton[0]; nextImage.setVisibility(View.VISIBLE); setCameraFlashModeIcon(nextImage, next); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether( ObjectAnimator.ofFloat(currentImage, "translationY", 0, AndroidUtilities.dp(48)), ObjectAnimator.ofFloat(nextImage, "translationY", -AndroidUtilities.dp(48), 0), ObjectAnimator.ofFloat(currentImage, "alpha", 1.0f, 0.0f), ObjectAnimator.ofFloat(nextImage, "alpha", 0.0f, 1.0f)); animatorSet.setDuration(200); animatorSet.addListener(new AnimatorListenerAdapterProxy() { @Override public void onAnimationEnd(Animator animator) { flashAnimationInProgress = false; currentImage.setVisibility(View.INVISIBLE); } }); animatorSet.start(); } }); } } }
From source file:com.android.systemui.statusbar.phone.NavigationBarView.java
public void setMenuVisibility(final boolean show, final boolean force) { if (!force && mShowMenu == show) return;/*from w w w.ja va2 s . c om*/ if ((currentSetting == SHOW_DONT) || mHasBigMenuButton) { return; } mShowMenu = show; boolean localShow = show; ImageView leftButton = (ImageView) getLeftMenuButton(); ImageView rightButton = (ImageView) getRightMenuButton(); switch (currentVisibility) { case VISIBILITY_ALWAYS: localShow = true; case VISIBILITY_SYSTEM: if (mTablet_UI == 1) { rightButton.setImageResource(R.drawable.ic_sysbar_menu_big); leftButton.setImageResource(R.drawable.ic_sysbar_menu_big); } else { rightButton .setImageResource(mVertical ? R.drawable.ic_sysbar_menu_land : R.drawable.ic_sysbar_menu); leftButton.setImageResource(mVertical ? R.drawable.ic_sysbar_menu_land : R.drawable.ic_sysbar_menu); } break; case VISIBILITY_NEVER: leftButton.setImageResource(R.drawable.ic_sysbar_menu_inviz); rightButton.setImageResource(R.drawable.ic_sysbar_menu_inviz); localShow = true; break; case VISIBILITY_SYSTEM_AND_INVIZ: if (localShow) { if (mTablet_UI == 1) { rightButton.setImageResource(R.drawable.ic_sysbar_menu_big); leftButton.setImageResource(R.drawable.ic_sysbar_menu_big); } else { rightButton.setImageResource( mVertical ? R.drawable.ic_sysbar_menu_land : R.drawable.ic_sysbar_menu); leftButton.setImageResource( mVertical ? R.drawable.ic_sysbar_menu_land : R.drawable.ic_sysbar_menu); } } else { localShow = true; leftButton.setImageResource(R.drawable.ic_sysbar_menu_inviz); rightButton.setImageResource(R.drawable.ic_sysbar_menu_inviz); } break; } // do this after just in case show was changed // Tablet menu buttons should not take up space when hidden. switch (currentSetting) { case SHOW_BOTH_MENU: if (mTablet_UI == 1) { leftButton.setVisibility(localShow ? View.VISIBLE : View.GONE); rightButton.setVisibility(localShow ? View.VISIBLE : View.GONE); } else { leftButton.setVisibility(localShow ? View.VISIBLE : View.INVISIBLE); rightButton.setVisibility(localShow ? View.VISIBLE : View.INVISIBLE); } break; case SHOW_LEFT_MENU: if (mTablet_UI == 1) { leftButton.setVisibility(localShow ? View.VISIBLE : View.GONE); } else { leftButton.setVisibility(localShow ? View.VISIBLE : View.INVISIBLE); } rightButton.setVisibility((mTablet_UI == 1) ? View.GONE : View.INVISIBLE); break; default: case SHOW_RIGHT_MENU: leftButton.setVisibility((mTablet_UI == 1) ? View.GONE : View.INVISIBLE); if (mTablet_UI == 1) { rightButton.setVisibility(localShow ? View.VISIBLE : View.GONE); } else { rightButton.setVisibility(localShow ? View.VISIBLE : View.INVISIBLE); } break; } }
From source file:biz.bokhorst.xprivacy.ActivityApp.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final int userId = Util.getUserId(Process.myUid()); // Check privacy service client if (!PrivacyService.checkClient()) return;//from ww w. j av a 2 s .c om // Set layout setContentView(R.layout.restrictionlist); // Get arguments Bundle extras = getIntent().getExtras(); if (extras == null) { finish(); return; } int uid = extras.getInt(cUid); String restrictionName = (extras.containsKey(cRestrictionName) ? extras.getString(cRestrictionName) : null); String methodName = (extras.containsKey(cMethodName) ? extras.getString(cMethodName) : null); // Get app info mAppInfo = new ApplicationInfoEx(this, uid); if (mAppInfo.getPackageName().size() == 0) { finish(); return; } // Set title setTitle(String.format("%s - %s", getString(R.string.app_name), TextUtils.join(", ", mAppInfo.getApplicationName()))); // Handle info click ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo); imgInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Packages can be selected on the web site Util.viewUri(ActivityApp.this, Uri.parse(String.format(ActivityShare.getBaseURL(ActivityApp.this) + "?package_name=%s", mAppInfo.getPackageName().get(0)))); } }); // Display app name TextView tvAppName = (TextView) findViewById(R.id.tvApp); tvAppName.setText(mAppInfo.toString()); // Background color if (mAppInfo.isSystem()) { LinearLayout llInfo = (LinearLayout) findViewById(R.id.llInfo); llInfo.setBackgroundColor(getResources().getColor(getThemed(R.attr.color_dangerous))); } // Display app icon final ImageView imgIcon = (ImageView) findViewById(R.id.imgIcon); imgIcon.setImageDrawable(mAppInfo.getIcon(this)); // Handle icon click imgIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { openContextMenu(imgIcon); } }); // Display on-demand state final ImageView imgCbOnDemand = (ImageView) findViewById(R.id.imgCbOnDemand); if (PrivacyManager.isApplication(mAppInfo.getUid()) && PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true)) { boolean ondemand = PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false); imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox()); imgCbOnDemand.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean ondemand = !PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false); PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, Boolean.toString(ondemand)); imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox()); if (mPrivacyListAdapter != null) mPrivacyListAdapter.notifyDataSetChanged(); } }); } else imgCbOnDemand.setVisibility(View.GONE); // Display restriction state swEnabled = (Switch) findViewById(R.id.swEnable); swEnabled.setChecked( PrivacyManager.getSettingBool(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, true)); swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, Boolean.toString(isChecked)); if (mPrivacyListAdapter != null) mPrivacyListAdapter.notifyDataSetChanged(); imgCbOnDemand.setEnabled(isChecked); } }); imgCbOnDemand.setEnabled(swEnabled.isChecked()); // Add context menu to icon registerForContextMenu(imgIcon); // Check if internet access if (!mAppInfo.hasInternet(this)) { ImageView imgInternet = (ImageView) findViewById(R.id.imgInternet); imgInternet.setVisibility(View.INVISIBLE); } // Check if frozen if (!mAppInfo.isFrozen(this)) { ImageView imgFrozen = (ImageView) findViewById(R.id.imgFrozen); imgFrozen.setVisibility(View.INVISIBLE); } // Display version TextView tvVersion = (TextView) findViewById(R.id.tvVersion); tvVersion.setText(TextUtils.join(", ", mAppInfo.getPackageVersionName(this))); // Display package name TextView tvPackageName = (TextView) findViewById(R.id.tvPackageName); tvPackageName.setText(TextUtils.join(", ", mAppInfo.getPackageName())); // Fill privacy list view adapter final ExpandableListView lvRestriction = (ExpandableListView) findViewById(R.id.elvRestriction); lvRestriction.setGroupIndicator(null); mPrivacyListAdapter = new RestrictionAdapter(R.layout.restrictionentry, mAppInfo, restrictionName, methodName); lvRestriction.setAdapter(mPrivacyListAdapter); if (restrictionName != null) { int groupPosition = new ArrayList<String>(PrivacyManager.getRestrictions(this).values()) .indexOf(restrictionName); lvRestriction.expandGroup(groupPosition); lvRestriction.setSelectedGroup(groupPosition); if (methodName != null) { int childPosition = PrivacyManager.getHooks(restrictionName) .indexOf(new Hook(restrictionName, methodName)); lvRestriction.setSelectedChild(groupPosition, childPosition, true); } } // Listen for package add/remove IntentFilter iff = new IntentFilter(); iff.addAction(Intent.ACTION_PACKAGE_REMOVED); iff.addDataScheme("package"); registerReceiver(mPackageChangeReceiver, iff); mPackageChangeReceiverRegistered = true; // Up navigation getActionBar().setDisplayHomeAsUpEnabled(true); // Tutorial if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialDetails, false)) { ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE); ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE); } View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View view) { ViewParent parent = view.getParent(); while (!parent.getClass().equals(ScrollView.class)) parent = parent.getParent(); ((View) parent).setVisibility(View.GONE); PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialDetails, Boolean.TRUE.toString()); } }; ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener); ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener); // Process actions if (extras.containsKey(cAction)) { NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancel(mAppInfo.getUid()); if (extras.getInt(cAction) == cActionClear) optionClear(); else if (extras.getInt(cAction) == cActionSettings) optionSettings(); } // Annotate Meta.annotate(this); }
From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java
private void addCaveObstacles(int screens) { int totalSlots = screens * SLOTS_PER_SCREEN; for (int i = 0; i < totalSlots;) { // Any given "slot" has a 1 in 3 chance of having an obstacle if (mRandom.nextInt(2) == 0) { View view = mInflater.inflate(R.layout.obstacle_layout, null); ImageView top = (ImageView) view.findViewById(R.id.top_view); ImageView bottom = (ImageView) view.findViewById(R.id.bottom_view); ImageView back = (ImageView) view.findViewById(R.id.back_view); // Which obstacle? int width = 0; if ((mCaveObstacleIndex % 20) == 0) { ObstacleLoadTask task = new ObstacleLoadTask(getResources(), CAVE_OBSTACLES, mCaveObstacles, mCaveObstacleList, mCaveObstacleIndex + 20, 2, mScaleX, mScaleY); task.execute();/*from www .ja v a 2 s . co m*/ } int obstacle = mCaveObstacleList.get(mCaveObstacleIndex++); if (mCaveObstacleIndex >= mCaveObstacleList.size()) { mCaveObstacleIndex = 0; } // int obstacle = mRandom.nextInt((CAVE_OBSTACLES.length/2)); int topIndex = obstacle * 2; int bottomIndex = topIndex + 1; back.setVisibility(View.GONE); int currentObstacle = 0; // Same values as mLastObstacle if (CAVE_OBSTACLES[topIndex] != -1) { currentObstacle |= 1; Bitmap bmp = null; synchronized (mCaveObstacles) { bmp = mCaveObstacles.get(CAVE_OBSTACLES[topIndex]); } while (bmp == null) { synchronized (mCaveObstacles) { bmp = mCaveObstacles.get(CAVE_OBSTACLES[topIndex]); if (bmp == null) { try { mCaveObstacles.wait(); } catch (InterruptedException e) { } } } } width = bmp.getWidth(); top.setImageBitmap(bmp); } else { top.setVisibility(View.GONE); } if (CAVE_OBSTACLES[bottomIndex] != -1) { currentObstacle |= 2; Bitmap bmp = null; synchronized (mCaveObstacles) { bmp = mCaveObstacles.get(CAVE_OBSTACLES[bottomIndex]); } while (bmp == null) { synchronized (mCaveObstacles) { bmp = mCaveObstacles.get(CAVE_OBSTACLES[bottomIndex]); if (bmp == null) { try { mCaveObstacles.wait(); } catch (InterruptedException e) { } } } } if (bmp.getWidth() > width) { width = bmp.getWidth(); } bottom.setImageBitmap(bmp); if (CAVE_OBSTACLES[bottomIndex] == R.drawable.img_mammoth) { // Special case... bottom.setTag(true); } } else { bottom.setVisibility(View.GONE); } int slots = (width / mSlotWidth); slots += 2; // If last obstacle had a top and this is a bottom or vice versa, insert a space if ((mLastObstacle & 0x1) > 0) { if ((currentObstacle & 0x2) > 0) { addSpaceOrPresent(mSlotWidth); i++; } } else if ((mLastObstacle & 0x2) > 0) { if ((currentObstacle & 0x1) > 0) { addSpaceOrPresent(mSlotWidth); i++; } } // If the new obstacle is too wide for the remaining space, skip it and fill spacer instead if ((i + slots) > totalSlots) { addSpaceOrPresent(mSlotWidth * (totalSlots - i)); i = totalSlots; } else { mLastObstacle = currentObstacle; LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(slots * mSlotWidth, LinearLayout.LayoutParams.WRAP_CONTENT); view.setLayoutParams(lp); mObstacleLayout.addView(view); i += slots; } } else { addSpaceOrPresent(mSlotWidth); i++; } } // Account for rounding errors in mSlotWidth int extra = ((screens * mScreenWidth) - (totalSlots * mSlotWidth)); if (extra > 0) { // Add filler to ensure sync with background/foreground scrolls! LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(extra, LinearLayout.LayoutParams.MATCH_PARENT); View view = new View(this); mObstacleLayout.addView(view, lp); } }
From source file:ru.gkpromtech.exhibition.events.EventDetailsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_event_details, container, false); final TextView textHeader = (TextView) view.findViewById(R.id.text_header); final ImageView imageEvent = (ImageView) view.findViewById(R.id.imageEvent); final TextView textDate = (TextView) view.findViewById(R.id.textDate); final TextView textTime = (TextView) view.findViewById(R.id.textTime); final TextView textPlace = (TextView) view.findViewById(R.id.textPlace); final TextView textEvent = (TextView) view.findViewById(R.id.textEvent); final TextView textTags = (TextView) view.findViewById(R.id.tags); final ImageButton imageFlag = (ImageButton) view.findViewById(R.id.imageFlag); final ImageButton imagePlace = (ImageButton) view.findViewById(R.id.imagePlace); textHeader.setText(item.header);//from w w w. ja va 2s .c o m textDate.setText(mDateFormat.format(item.date) + "/"); textTime.setText(mTimeFormat.format(item.date)); EventFavorite fav = EventReader.getInstance(getActivity()).getEventFavorite(item.id); imageFlag.setSelected(fav.favorite != 0); String place = new String(); List<Place> places = EventReader.getInstance(getActivity()).getPlaces(item.id); for (Place p : places) { place = place + p.name + " "; } textPlace.setText(place); textEvent.setText(item.details); String sTags = new String(getResources().getString(R.string.title_tags) + ": "); List<Tag> tags = EventReader.getInstance(getActivity()).getTags(item.id); for (Tag t : tags) { sTags = sTags + t.tag + " "; } textTags.setText(sTags); imageFlag.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { imageFlag.setSelected(!imageFlag.isSelected()); int state = imageFlag.isSelected() ? 1 : 0; mListener.onFavoriteClicked(item.id, state); } }); final HListView previewList = (HListView) view.findViewById(R.id.hListView1); previewList.setHeaderDividersEnabled(true); previewList.setFooterDividersEnabled(true); if (mediaItems.size() <= 1) { previewList.setVisibility(View.INVISIBLE); } else { final HImageListAdapter mAdapter = new HImageListAdapter(getActivity(), R.layout.layout_image_preview, R.id.picture, mediaItems); previewList.setAdapter(mAdapter); previewList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mImagePreviewPosition = position; if (mListener != null) { mListener.onPreviewImageClicked(item, mImagePreviewPosition); } } }); } if (mediaItems.isEmpty()) { imageEvent.setVisibility(ViewGroup.GONE); } else { Media m = mediaItems.get(mImagePreviewPosition); String url = m.url; if (m.type == Media.VIDEO) url = m.preview; imageEvent.setVisibility(ViewGroup.VISIBLE); ImageLoader.load(url, imageEvent); imageEvent.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mListener != null) mListener.onPreviewImageClicked(item, 0); } }); } return view; }
From source file:com.yaniv.online.MainActivity.java
private void updatePrimaryDeckUI() { Log.d(TAG, "updatePrimaryDeckUI()"); int i;/*from w w w . j a v a 2s.com*/ ImageView myCard; ArrayList<Card> peek = primaryDeck.peek(); for (i = 0; i < peek.size(); i++) { int drawable = cardsDrawable.get("" + peek.get(i).getKey()); myCard = (ImageView) findViewById(droppedID[i]); myCard.setImageResource(drawable); myCard.setVisibility(View.VISIBLE); } for (; i < 5; i++) { myCard = (ImageView) findViewById(droppedID[i]); myCard.setVisibility(View.GONE); } updateTurnGUI(); }