List of usage examples for android.view ViewGroup getWidth
@ViewDebug.ExportedProperty(category = "layout") public final int getWidth()
From source file:de.dreier.mytargets.views.MaterialTapTargetPrompt.java
private void updateFocalCentrePosition() { updateClipBounds();//from www . ja v a 2 s . com if (mTargetView != null) { final int[] viewPosition = new int[2]; mView.getLocationInWindow(viewPosition); final int[] targetPosition = new int[2]; mTargetView.getLocationInWindow(targetPosition); mView.mCentreLeft = mBaseLeft + targetPosition[0] - viewPosition[0] + (mTargetView.getWidth() / 2); mView.mCentreTop = mBaseTop + targetPosition[1] - viewPosition[1] + (mTargetView.getHeight() / 2); } else { mView.mCentreLeft = mBaseLeft; mView.mCentreTop = mBaseTop; } final ViewGroup parent = getParentView(); mTextPositionAbove = mView.mCentreTop > parent.getHeight() / 2; mTextPositionRight = mView.mCentreLeft > parent.getWidth() / 2; updateTextPositioning(); }
From source file:uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.java
void updateFocalCentrePosition() { updateClipBounds();/*from w ww. j a va 2 s . c om*/ if (mTargetView != null) { final int[] viewPosition = new int[2]; mView.getLocationInWindow(viewPosition); final int[] targetPosition = new int[2]; mTargetView.getLocationInWindow(targetPosition); mView.mCentreLeft = mBaseLeft + targetPosition[0] - viewPosition[0] + (mTargetView.getWidth() / 2); mView.mCentreTop = mBaseTop + targetPosition[1] - viewPosition[1] + (mTargetView.getHeight() / 2); } else { mView.mCentreLeft = mBaseLeft; mView.mCentreTop = mBaseTop; } final ViewGroup parent = getParentView(); mTextPositionAbove = mView.mCentreTop > parent.getHeight() / 2; mTextPositionRight = mView.mCentreLeft > parent.getWidth() / 2; updateTextPositioning(); }
From source file:com.zertinteractive.wallpaper.MainActivity.java
@SuppressWarnings("NewApi") private android.animation.Animator animateRevealColorFromCoordinates(ViewGroup viewRoot, @ColorRes int color, int x, int y) { float finalRadius = (float) Math.hypot(viewRoot.getWidth(), viewRoot.getHeight()); android.animation.Animator anim = ViewAnimationUtils.createCircularReveal(viewRoot, x, y, 0, finalRadius); viewRoot.setBackgroundColor(ContextCompat.getColor(this, color)); anim.setDuration(getResources().getInteger(R.integer.anim_duration_long)); anim.setInterpolator(new AccelerateDecelerateInterpolator()); anim.start();//from w ww .j a v a 2 s . c om return anim; }
From source file:android.car.ui.provider.CarDrawerLayout.java
/** * Open the drawer view by animating it into view. *///from ww w . j a va 2 s . com public void openDrawer() { ViewGroup drawerView = (ViewGroup) findDrawerView(); mStartedOpen = false; if (hasWindowFocus()) { int left; LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams(); if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) { left = drawerLp.getMarginStart(); } else { left = drawerLp.getMarginStart() + getWidth() - drawerView.getWidth(); } mDragger.smoothSlideViewTo(drawerView, left, drawerView.getTop()); dispatchOnDrawerOpening(drawerView); } else { final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams(); lp.onScreen = 1.f; dispatchOnDrawerOpened(drawerView); } ViewGroup contentView = (ViewGroup) findContentView(); contentView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); drawerView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); View focusable = drawerView.getChildAt(0); if (focusable != null) { focusable.requestFocus(); } invalidate(); }
From source file:com.thelastcrusade.soundstream.util.MusicListAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { View element = convertView;//from ww w . ja va 2s. c om if (element == null) { LayoutInflater inflater = (LayoutInflater) this.mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); element = inflater.inflate(R.layout.song_item, null); } View userColor = (View) element.findViewById(R.id.user_color); TextView title = (TextView) element.findViewById(R.id.title); TextView album = (TextView) element.findViewById(R.id.album); TextView artist = (TextView) element.findViewById(R.id.artist); ImageButton addButton = (ImageButton) element.findViewById(R.id.btn_add_to_playlist); String macAddress = metadataList.get(position).getMacAddress(); User user = users.getUserByMACAddress(macAddress); if (user != null) { userColor.setBackgroundColor(user.getColor()); } else { Log.wtf(TAG, "User with mac address " + macAddress + " not found. Using default color."); userColor.setBackgroundColor(mContext.getResources().getColor(R.color.transparent)); } //set the default sizes userColor.setMinimumHeight((int) mContext.getResources().getDimension(R.dimen.song_height)); title.setSingleLine(true); artist.setSingleLine(true); album.setSingleLine(true); addButton.setTag(position); addButton.setContentDescription( ContentDescriptionUtils.addToPlaylistAppendSongTitle(metadataList.get(position))); title.setText(metadataList.get(position).getTitle()); artist.setText(metadataList.get(position).getArtist()); album.setText(metadataList.get(position).getAlbum()); artist.setMaxWidth(parent.getWidth() / 2); /* final GestureDetectorCompat songGesture = new GestureDetectorCompat(mContext, new SongGestureListener(element)); element.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return songGesture.onTouchEvent(event); } });*/ return element; }
From source file:android.car.ui.provider.CarDrawerLayout.java
/** * Close the specified drawer view by animating it into view. */// w w w . j a v a2s . c om public void closeDrawer() { ViewGroup drawerView = (ViewGroup) findDrawerView(); if (!isDrawerView(drawerView)) { throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer"); } mStartedOpen = true; // Don't trigger the close drawer animation if drawer is not open. if (hasWindowFocus() && isDrawerOpen()) { int left; LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams(); if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) { left = drawerLp.getMarginStart() - drawerView.getWidth(); } else { left = drawerLp.getMarginStart() + getWidth(); } mDragger.smoothSlideViewTo(drawerView, left, drawerView.getTop()); dispatchOnDrawerClosing(drawerView); } else { final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams(); lp.onScreen = 0.f; dispatchOnDrawerClosed(drawerView); } ViewGroup contentView = (ViewGroup) findContentView(); drawerView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); contentView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); if (!isInTouchMode()) { List<View> focusables = contentView.getFocusables(FOCUS_DOWN); if (focusables.size() > 0) { View candidate = focusables.get(0); candidate.requestFocus(); } } invalidate(); }
From source file:com.juick.android.MainActivity.java
private void setFragmentNeededMetrics() { if (true /* sp.getBoolean("googlePlusNavigation", false) */) { final ViewGroup navigationPanel = (ViewGroup) findViewById(R.id.navigation_panel); if (mf != null && navigationPanel.getWidth() != 0) { mf.setRightScrollBound(navigationPanel.getWidth()); }//from w ww.ja va 2s . com } }
From source file:com.android.incallui.CallCardFragment.java
@Override public void onResume() { super.onResume(); // If the previous launch animation is still running, cancel it so that we don't get // stuck in an intermediate animation state. if (mAnimatorSet != null && mAnimatorSet.isRunning()) { mAnimatorSet.cancel();/*from w w w .j a v a2 s . c om*/ } mIsLandscape = getResources().getBoolean(R.bool.is_layout_landscape); mHasLargePhoto = getResources().getBoolean(R.bool.has_large_photo); final ViewGroup parent = ((ViewGroup) mPrimaryCallCardContainer.getParent()); final ViewTreeObserver observer = parent.getViewTreeObserver(); parent.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { ViewTreeObserver viewTreeObserver = observer; if (!viewTreeObserver.isAlive()) { viewTreeObserver = parent.getViewTreeObserver(); } viewTreeObserver.removeOnGlobalLayoutListener(this); mFloatingActionButtonController.setScreenWidth(parent.getWidth()); updateFabPosition(); } }); updateColors(); }
From source file:com.dk.view.FolderDrawerLayout.java
private boolean createCache() { ViewGroup left = (ViewGroup) findDrawerWithGravity(Gravity.LEFT); if (left.getChildCount() > 0 && !(left.getChildAt(0) instanceof MeshImageView)) { mDrawingCache = drawViewToBitmap(mDrawingCache, left, left.getWidth(), left.getHeight(), 1, new BitmapDrawable()); if (mCoreCalc == null) mCoreCalc = new CoreCalc(left.getWidth(), left.getHeight()); return true; } else {/*w w w. j av a 2 s. c om*/ return false; } }
From source file:cw.kop.autobackground.sources.SourceInfoFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Bundle arguments = getArguments();/* w w w. ja v a 2 s . co m*/ sourcePosition = (Integer) arguments.get("position"); int colorFilterInt = AppSettings.getColorFilterInt(appContext); View view = inflater.inflate(R.layout.source_info_fragment, container, false); headerView = inflater.inflate(R.layout.source_info_header, null, false); settingsContainer = (RelativeLayout) headerView.findViewById(R.id.source_settings_container); sourceImage = (ImageView) headerView.findViewById(R.id.source_image); sourceTitle = (EditText) headerView.findViewById(R.id.source_title); sourcePrefix = (EditText) headerView.findViewById(R.id.source_data_prefix); sourceData = (EditText) headerView.findViewById(R.id.source_data); sourceSuffix = (EditText) headerView.findViewById(R.id.source_data_suffix); sourceNum = (EditText) headerView.findViewById(R.id.source_num); ViewGroup.LayoutParams params = sourceImage.getLayoutParams(); params.height = (int) ((container.getWidth() - 2f * getResources().getDimensionPixelSize(R.dimen.side_margin)) / 16f * 9); sourceImage.setLayoutParams(params); cancelButton = (Button) view.findViewById(R.id.cancel_button); saveButton = (Button) view.findViewById(R.id.save_button); sourcePrefix.setTextColor(colorFilterInt); sourceSuffix.setTextColor(colorFilterInt); cancelButton.setTextColor(colorFilterInt); saveButton.setTextColor(colorFilterInt); // Adjust alpha to get faded hint color from regular text color int hintColor = Color.argb(0x88, Color.red(colorFilterInt), Color.green(colorFilterInt), Color.blue(colorFilterInt)); sourceTitle.setHintTextColor(hintColor); sourceData.setHintTextColor(hintColor); sourceNum.setHintTextColor(hintColor); sourceData.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { switch (type) { case AppSettings.FOLDER: selectSource(getPositionOfType(AppSettings.FOLDER)); break; case AppSettings.GOOGLE_ALBUM: selectSource(getPositionOfType(AppSettings.GOOGLE_ALBUM)); break; } Log.i(TAG, "Data launched folder fragment"); } }); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); saveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { saveSource(); } }); sourceSpinnerText = (TextView) headerView.findViewById(R.id.source_spinner_text); sourceSpinner = (Spinner) headerView.findViewById(R.id.source_spinner); timePref = (CustomSwitchPreference) findPreference("source_time"); timePref.setChecked(arguments.getBoolean("use_time")); timePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (!(Boolean) newValue) { return true; } DialogFactory.TimeDialogListener startTimeListener = new DialogFactory.TimeDialogListener() { @Override public void onTimeSet(TimePicker view, int hour, int minute) { startHour = hour; startMinute = minute; DialogFactory.TimeDialogListener endTimeListener = new DialogFactory.TimeDialogListener() { @Override public void onTimeSet(TimePicker view, int hour, int minute) { endHour = hour; endMinute = minute; timePref.setSummary(String.format("Time active: %02d:%02d - %02d:%02d", startHour, startMinute, endHour, endMinute)); } }; DialogFactory.showTimeDialog(appContext, "End time?", endTimeListener, startHour, startMinute); } }; DialogFactory.showTimeDialog(appContext, "Start time?", startTimeListener, startHour, startMinute); return true; } }); if (savedInstanceState != null) { if (sourcePosition == -1) { sourceSpinner .setSelection(getPositionOfType(savedInstanceState.getString("type", AppSettings.WEBSITE))); } } if (sourcePosition == -1) { sourceImage.setVisibility(View.GONE); sourceSpinnerText.setVisibility(View.VISIBLE); sourceSpinner.setVisibility(View.VISIBLE); SourceSpinnerAdapter adapter = new SourceSpinnerAdapter(appContext, R.layout.spinner_row, Arrays.asList(getResources().getStringArray(R.array.source_menu))); sourceSpinner.setAdapter(adapter); sourceSpinner.setSelection(0); sourceSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { selectSource(position); Log.i(TAG, "Spinner launched folder fragment"); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); type = AppSettings.WEBSITE; hint = "URL"; prefix = ""; suffix = ""; startHour = 0; startMinute = 0; endHour = 0; endMinute = 0; } else { sourceImage.setVisibility(View.VISIBLE); sourceSpinnerText.setVisibility(View.GONE); sourceSpinner.setVisibility(View.GONE); type = arguments.getString("type"); folderData = arguments.getString("data"); String data = folderData; hint = AppSettings.getSourceDataHint(type); prefix = AppSettings.getSourceDataPrefix(type); suffix = ""; switch (type) { case AppSettings.GOOGLE_ALBUM: sourceTitle.setFocusable(false); sourceData.setFocusable(false); sourceNum.setFocusable(false); case AppSettings.FOLDER: data = Arrays.toString(folderData.split(AppSettings.DATA_SPLITTER)); break; case AppSettings.TUMBLR_BLOG: suffix = ".tumblr.com"; break; } sourceTitle.setText(arguments.getString("title")); sourceNum.setText("" + arguments.getInt("num")); sourceData.setText(data); if (imageDrawable != null) { sourceImage.setImageDrawable(imageDrawable); } boolean showPreview = arguments.getBoolean("preview"); if (showPreview) { sourceImage.setVisibility(View.VISIBLE); } ((CustomSwitchPreference) findPreference("source_show_preview")).setChecked(showPreview); String[] timeArray = arguments.getString("time").split(":|[ -]+"); try { startHour = Integer.parseInt(timeArray[0]); startMinute = Integer.parseInt(timeArray[1]); endHour = Integer.parseInt(timeArray[2]); endMinute = Integer.parseInt(timeArray[3]); timePref.setSummary(String.format("Time active: %02d:%02d - %02d:%02d", startHour, startMinute, endHour, endMinute)); } catch (NumberFormatException e) { e.printStackTrace(); startHour = 0; startMinute = 0; endHour = 0; endMinute = 0; } } setDataWrappers(); sourceUse = (Switch) headerView.findViewById(R.id.source_use_switch); sourceUse.setChecked(arguments.getBoolean("use")); if (AppSettings.getTheme().equals(AppSettings.APP_LIGHT_THEME)) { view.setBackgroundColor(getResources().getColor(R.color.LIGHT_THEME_BACKGROUND)); } else { view.setBackgroundColor(getResources().getColor(R.color.DARK_THEME_BACKGROUND)); } ListView listView = (ListView) view.findViewById(android.R.id.list); listView.addHeaderView(headerView); if (savedInstanceState != null) { sourceTitle.setText(savedInstanceState.getString("title", "")); sourceData.setText(savedInstanceState.getString("data", "")); sourceNum.setText(savedInstanceState.getString("num", "")); } return view; }