List of usage examples for android.widget ImageView getLayoutParams
@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") public ViewGroup.LayoutParams getLayoutParams()
From source file:com.intel.xdk.base.Base.java
public void showSplashScreen() { cordova.getActivity().runOnUiThread(new Runnable() { public void run() { //treat displays larger than 6" as tablets DisplayMetrics dm = new DisplayMetrics(); cordova.getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); double x = Math.pow(dm.widthPixels / dm.xdpi, 2); double y = Math.pow(dm.heightPixels / dm.ydpi, 2); double screenInches = Math.sqrt(x + y); if (screenInches > 6) { isTablet = true;// www. ja va 2s . co m } //used for calculating status bar height int deviceWidth = dm.widthPixels; int deviceHeight = dm.heightPixels; if (deviceWidth > deviceHeight) { deviceWidth = dm.heightPixels; deviceHeight = dm.widthPixels; } //get the splash screen image from asssets Bitmap bm = null; try { if (isTablet) { bm = getBitmapFromAsset("www/intel.xdk.base/android/splash_screen_tablet.jpg"); } else { bm = getBitmapFromAsset("www/intel.xdk.base/android/splash_screen.jpg"); } } catch (IOException ioe) { } //if the splash screen assets are missing, don't try to show the splash screen if (bm == null) { return; } if (Debug.isDebuggerConnected()) Log.i("[intel.xdk]", "splash"); ActivityInfo ai = null; int splashViewId = 0; try { ai = cordova.getActivity().getPackageManager().getActivityInfo( cordova.getActivity().getComponentName(), PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA); if (isTablet) { if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { splashViewId = cordova.getActivity().getResources().getIdentifier("splash_tablet_ls", "layout", cordova.getActivity().getPackageName()); } else { splashViewId = cordova.getActivity().getResources().getIdentifier("splash_tablet", "layout", cordova.getActivity().getPackageName()); } } else { if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { splashViewId = cordova.getActivity().getResources().getIdentifier("splash_ls", "layout", cordova.getActivity().getPackageName()); } else { splashViewId = cordova.getActivity().getResources().getIdentifier("splash", "layout", cordova.getActivity().getPackageName()); } } LayoutInflater inflater = LayoutInflater.from(cordova.getActivity()); splashView = inflater.inflate(splashViewId, null); //set the splash screen image //http://stackoverflow.com/questions/7776445/in-android-can-i-use-image-from-assets-in-layout-xml ImageView backgroundImage = (ImageView) splashView .findViewById(cordova.getActivity().getResources().getIdentifier("background", "id", cordova.getActivity().getPackageName())); backgroundImage.setImageBitmap(bm); ((ViewGroup) root.getParent()).addView(splashView); splashView.bringToFront(); //hack to fix splash screen size when it is smaller than screen ImageView splashImage = (ImageView) cordova.getActivity() .findViewById(cordova.getActivity().getResources().getIdentifier("background", "id", cordova.getActivity().getPackageName())); LayoutParams params = splashImage.getLayoutParams(); Rect imgBounds = splashImage.getDrawable().getBounds(); int splashHeight = params.height; int splashWidth = params.width; //make copies in case we have to switch for landscape - not sure if needed, this is a last minute hack int deviceWidthCopy, deviceHeightCopy; deviceWidthCopy = deviceWidth; deviceHeightCopy = deviceHeight; if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { int temp = deviceWidthCopy; deviceWidthCopy = deviceHeightCopy; deviceHeightCopy = temp; } if (splashHeight < deviceHeightCopy || splashWidth < deviceWidthCopy) { float scaleH = (float) deviceHeightCopy / splashHeight; float scaleW = (float) deviceWidthCopy / splashWidth; float scale = Math.max(scaleH, scaleW); params.height *= scale; params.width *= scale; splashImage.setLayoutParams(params); } cordova.getActivity().setProgressBarIndeterminateVisibility(true); } catch (Exception e) { e.printStackTrace(); } } }); }
From source file:ca.cmput301f13t03.adventure_datetime.view.FragmentView.java
public void setUpView() { if (_fragment == null) return;//from w w w . j av a 2 s . c om /** Layout items **/ _filmLayout = (LinearLayout) _rootView.findViewById(R.id.filmstrip); _filmstrip = (HorizontalScrollView) _rootView.findViewById(R.id.filmstrip_wrapper); _choices = (Button) _rootView.findViewById(R.id.choices); _content = (TextView) _rootView.findViewById(R.id.content); if (_fragment.getStoryMedia() == null) _fragment.setStoryMedia(new ArrayList<Image>()); /* Run on UI Thread for server stuff */ getActivity().runOnUiThread(new Runnable() { @Override public void run() { /** Programmatically set filmstrip height **/ if (_fragment.getStoryMedia().size() > 0) _filmstrip.getLayoutParams().height = FILM_STRIP_SIZE; else _filmstrip.getLayoutParams().height = 0; _content.setText(_fragment.getStoryText()); _filmLayout.removeAllViews(); // 1) Create new ImageView and add to the LinearLayout // 2) Set appropriate Layout Params to ImageView // 3) Give onClickListener for going to fullscreen LinearLayout.LayoutParams lp; //for (int i = 0; i < _fragment.getStoryMedia().size(); i++) { for (int i = 0; i < _fragment.getStoryMedia().size(); i++) { ImageView li = new ImageView(getActivity()); li.setScaleType(ScaleType.CENTER_INSIDE); li.setImageBitmap(_fragment.getStoryMedia().get(i).decodeBitmap()); _filmLayout.addView(li); lp = (LinearLayout.LayoutParams) li.getLayoutParams(); lp.setMargins(10, 10, 10, 10); lp.width = FILM_STRIP_SIZE; lp.height = FILM_STRIP_SIZE; lp.gravity = Gravity.CENTER_VERTICAL; li.setLayoutParams(lp); li.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), FullScreen_Image.class); intent.putExtra(FullScreen_Image.TAG_AUTHOR, false); startActivity(intent); } }); } if (_fragment.getChoices().size() > 0) { /** Choices **/ final List<String> choices = new ArrayList<String>(); for (Choice choice : _fragment.getChoices()) choices.add(choice.getText()); choices.add("I'm feeling lucky."); _choices.setText("Actions"); _choices.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(v.getContext()).setTitle("Actions").setCancelable(true) .setItems(choices.toArray(new String[choices.size()]), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { /** You feeling lucky, punk? **/ if (which == _fragment.getChoices().size()) which = (int) (Math.random() * _fragment.getChoices().size()); Choice choice = _fragment.getChoices().get(which); Toast.makeText(FragmentView.this.getActivity(), choice.getText(), Toast.LENGTH_LONG).show(); Locator.getUserController().MakeChoice(choice); } }) .create().show(); } }); } else { /** End of story **/ Locator.getUserController().deleteBookmark(); _choices.setText("The End"); _choices.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(v.getContext()).setTitle("La Fin").setCancelable(true) .setPositiveButton("Play Again", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Locator.getUserController().StartStory(_fragment.getStoryID()); } }) .setNegativeButton("Change Adventures", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (!_isEditing) getActivity().onBackPressed(); } }).create().show(); } }); } } }); }
From source file:org.ayo.robot.anim.transitioneverywhere.ImageTransformSample.java
@Nullable @Override// ww w . jav a 2s . c o m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_image_transform, container, false); final ViewGroup transitionsContainer = (ViewGroup) view.findViewById(R.id.transitions_container); final ImageView imageView = (ImageView) transitionsContainer.findViewById(R.id.image); imageView.setOnClickListener(new View.OnClickListener() { boolean mExpanded; @Override public void onClick(View v) { mExpanded = !mExpanded; TransitionManager.beginDelayedTransition(transitionsContainer, new TransitionSet() .addTransition(new ChangeBounds()).addTransition(new ChangeImageTransform())); ViewGroup.LayoutParams params = imageView.getLayoutParams(); params.height = mExpanded ? ViewGroup.LayoutParams.MATCH_PARENT : ViewGroup.LayoutParams.WRAP_CONTENT; imageView.setLayoutParams(params); imageView .setScaleType(mExpanded ? ImageView.ScaleType.CENTER_CROP : ImageView.ScaleType.FIT_CENTER); } }); return view; }
From source file:org.openmrs.mobile.activities.DashboardActivity.java
private void bindDrawableResources() { mBitmapCache = new SparseArray<Bitmap>(); ImageView inputFood = (ImageView) findViewById(R.id.findPatientButton); ImageView inputHeight = (ImageView) findViewById(R.id.registryPatientButton); ImageView inputExercise = (ImageView) findViewById(R.id.activeVisitsButton); ImageView captureVitalsImageButton = (ImageView) findViewById(R.id.captureVitalsButton); ImageView syncData = (ImageView) findViewById(R.id.syncData); createImageBitmap(R.drawable.ico_food, inputFood.getLayoutParams()); createImageBitmap(R.drawable.ico_scale, inputHeight.getLayoutParams()); createImageBitmap(R.drawable.ico_exercise, inputExercise.getLayoutParams()); createImageBitmap(R.drawable.ico_vitals, captureVitalsImageButton.getLayoutParams()); createImageBitmap(R.drawable.sync, syncData.getLayoutParams()); inputFood.setImageBitmap(mBitmapCache.get(R.drawable.ico_food)); inputHeight.setImageBitmap(mBitmapCache.get(R.drawable.ico_scale)); inputExercise.setImageBitmap(mBitmapCache.get(R.drawable.ico_exercise)); captureVitalsImageButton.setImageBitmap(mBitmapCache.get(R.drawable.ico_vitals)); syncData.setImageBitmap(mBitmapCache.get(R.drawable.sync)); }
From source file:org.onebusaway.android.ui.TutorialFragment.java
private void updatePagerIndicator(int position, int size) { LinearLayout linear = (LinearLayout) getActivity().findViewById(R.id.pager_indicator); linear.removeAllViewsInLayout();/*ww w . j a v a2s. c om*/ for (int i = 0; i < size; i++) { ImageView iw = new ImageView(getActivity()); if (position == i) { iw.setImageResource(R.drawable.pager_dot_hover); } else { iw.setImageResource(R.drawable.pager_dot); } iw.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) iw.getLayoutParams(); params.setMargins(5, 0, 0, 0); iw.setLayoutParams(params); linear.addView(iw); } }
From source file:de.msal.shoutemo.adapters.NavigationDrawerAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.listrow_navigationdrawer, parent, false);/*w w w . j a v a 2 s .c o m*/ } ImageView ivIcon = (ImageView) convertView.findViewById(R.id.listrow_navigationdrawer__icon); TextView tvText = (TextView) convertView.findViewById(R.id.listrow_navigationdrawer__text); // normal, clickable list entry if (getItem(position) != null) { ivIcon.setImageDrawable(ContextCompat.getDrawable(getContext(), mDrawables[position])); tvText.setText(mEntries[position]); } // separator line else { tvText.setVisibility(View.GONE); ivIcon.setImageDrawable(ContextCompat.getDrawable(getContext(), R.color.autemo_grey_bright)); ViewGroup.LayoutParams layoutParams = ivIcon.getLayoutParams(); layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; layoutParams.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getContext().getResources().getDisplayMetrics()); ivIcon.setLayoutParams(layoutParams); } return convertView; }
From source file:com.wanpaijie.www.http.ImageDownloader.java
/** * Download the specified image from the Internet and binds it to the provided ImageView. The * binding is immediate if the image is found in the cache and will be done asynchronously * otherwise. A null bitmap will be associated to the ImageView if an error occurs. * * @param url The URL of the image to download. * @param imageView The ImageView to bind the downloaded image to. *///from ww w.java2 s .co m public void download(String url, ImageView imageView, Context context) { resetPurgeTimer(); if (url.length() > 0) { url = Http.imageHost + url; } Bitmap bitmap = getBitmapFromCache(url); this.current = context; if (bitmap == null) { forceDownload(url, imageView); } else { cancelPotentialDownload(url, imageView); LayoutParams lp = imageView.getLayoutParams(); lp.height = Util.DiptoPx(this.current, bitmap.getHeight()); lp.width = Util.DiptoPx(this.current, bitmap.getWidth()); imageView.setLayoutParams(lp); imageView.setImageBitmap(bitmap); } }
From source file:com.cachirulop.moneybox.fragment.MoneyboxFragment.java
/** * Create dynamically an android animation for a coin or a bill getting from * the moneybox./*from w w w .j a v a2 s. c om*/ * * @param img * ImageView to receive the animation * @param layout * Layout that paint the image * @return Set of animations to apply to the image */ private AnimationSet createGetAnimation(ImageView img, View layout) { AnimationSet result; result = new AnimationSet(false); result.setFillAfter(true); // get TranslateAnimation get; int bottom; bottom = Math.abs(layout.getHeight() - img.getLayoutParams().height); get = new TranslateAnimation(1.0f, 1.0f, bottom, 1.0f); get.setDuration(1500); result.addAnimation(get); // Fade out AlphaAnimation fadeOut; fadeOut = new AlphaAnimation(1.0f, 0.0f); fadeOut.setDuration(300); fadeOut.setStartOffset(1500); result.addAnimation(fadeOut); return result; }
From source file:com.phicdy.mycuration.ui.TopActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_top); curationFragment = new CurationListFragment(); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.addOnPageChangeListener(new PageChangeListener()); track = (ViewGroup) findViewById(R.id.track); trackScroller = (HorizontalScrollView) findViewById(R.id.track_scroller); indicator = (View) findViewById(R.id.indicator); WindowManager wm = getWindowManager(); Display disp = wm.getDefaultDisplay(); Point size = new Point(); disp.getSize(size);/*from w w w . j a v a 2s .c o m*/ int displayWidth = size.x; LayoutInflater inflater = LayoutInflater.from(this); for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { final int position = i; ImageView ivTab = (ImageView) inflater.inflate(R.layout.tab_item, track, false); ivTab.setImageResource(mSectionsPagerAdapter.getImageResource(position)); ivTab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mViewPager.setCurrentItem(position); } }); final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) ivTab.getLayoutParams(); layoutParams.width = displayWidth / mSectionsPagerAdapter.getCount(); ivTab.setLayoutParams(layoutParams); track.addView(ivTab); } final float density = getResources().getDisplayMetrics().density; indicatorOffset = (int) (INDICATOR_OFFSET_DP * density); setTitle(getString(R.string.home)); dbAdapter = DatabaseAdapter.getInstance(getApplicationContext()); setAlarmManager(); }
From source file:com.dm.wallpaper.board.adapters.LatestAdapter.java
private void resetImageViewHeight(@NonNull ImageView imageView, ImageSize imageSize) { if (imageSize == null) imageSize = new ImageSize(400, 300); int width = WindowHelper.getScreenSize(mContext).x; int spanCount = mContext.getResources().getInteger(R.integer.latest_wallpapers_column_count); if (spanCount > 1) { width = width / spanCount;// ww w . j ava 2 s . c o m } double scaleFactor = (double) width / (double) imageSize.getWidth(); double measuredHeight = (double) imageSize.getHeight() * scaleFactor; imageView.getLayoutParams().height = Double.valueOf(measuredHeight).intValue(); imageView.requestLayout(); }