List of usage examples for android.view ViewGroup getChildAt
public View getChildAt(int index)
From source file:com.facebook.litho.MountState.java
private static void mountViewIncrementally(View view, Rect localVisibleRect) { assertMainThread();//from ww w. ja v a2 s . c om if (view instanceof LithoView) { final LithoView lithoView = (LithoView) view; lithoView.performIncrementalMount(localVisibleRect); } else if (view instanceof ViewGroup) { final ViewGroup viewGroup = (ViewGroup) view; for (int i = 0; i < viewGroup.getChildCount(); i++) { final View childView = viewGroup.getChildAt(i); if (localVisibleRect.intersects(childView.getLeft(), childView.getTop(), childView.getRight(), childView.getBottom())) { final Rect rect = ComponentsPools.acquireRect(); rect.set(Math.max(0, localVisibleRect.left - childView.getLeft()), Math.max(0, localVisibleRect.top - childView.getTop()), childView.getWidth() - Math.max(0, childView.getRight() - localVisibleRect.right), childView.getHeight() - Math.max(0, childView.getBottom() - localVisibleRect.bottom)); mountViewIncrementally(childView, rect); ComponentsPools.release(rect); } } } }
From source file:info.tellmetime.TellmetimeActivity.java
private void resizeClock() { final LinearLayout mClock = (LinearLayout) findViewById(R.id.clock); // Set width of #mClock layout to the screen's shorter edge size, so clock is not // expanded in landscape mode, but has rather somewhat a square shape. RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.CENTER_IN_PARENT); lp.width = mShorterEdge;//from w ww .ja va 2s . co m mClock.setLayoutParams(lp); final float mItemSize = mShorterEdge / mClock.getChildCount(); final int mRowMargin = (int) -(mItemSize / 2.2); // Scale text size according to shorter edge and set spacing between rows. for (int i = 0; i < mClock.getChildCount(); i++) { LinearLayout row = (LinearLayout) mClock.getChildAt(i); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) row.getLayoutParams(); params.bottomMargin = mRowMargin; row.setLayoutParams(params); for (int j = 0; j < row.getChildCount(); j++) ((TextView) row.getChildAt(j)).setTextSize(TypedValue.COMPLEX_UNIT_PX, mItemSize); } LinearLayout lastRow = (LinearLayout) mClock.getChildAt(mClock.getChildCount() - 1); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) lastRow.getLayoutParams(); params.bottomMargin = 0; lastRow.setLayoutParams(params); TextView twenty = (TextView) findViewById(R.id.twenty); params = (LinearLayout.LayoutParams) twenty.getLayoutParams(); params.leftMargin = 0; twenty.setLayoutParams(params); // Inflates minutes indicators and attaches them to main view. FrameLayout minutesLayout = (FrameLayout) findViewById(R.id.minutes_indicators); minutesLayout.removeAllViews(); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); final boolean isLandscape = getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; inflater.inflate(isLandscape ? R.layout.minutes_land : R.layout.minutes_portrait, minutesLayout); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, isLandscape ? FrameLayout.LayoutParams.MATCH_PARENT : FrameLayout.LayoutParams.WRAP_CONTENT); if (!isLandscape) { layoutParams.addRule(RelativeLayout.BELOW, R.id.clock); layoutParams.topMargin = (int) -TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize / 3, getResources().getDisplayMetrics()); } minutesLayout.setLayoutParams(layoutParams); ViewGroup minutesDots = (ViewGroup) findViewById(R.id.minutes_dots); for (int i = 0; i < minutesDots.getChildCount(); i++) ((TextView) minutesDots.getChildAt(i)).setTextSize(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize); }
From source file:com.xnf.henghenghui.ui.view.PagerSlidingTabStrip.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); ViewGroup tabViewGroup = getTabsLayout(); if (tabViewGroup != null) { // ?????//from ww w.ja v a 2 s.co m currentPosition = viewPager != null ? viewPager.getCurrentItem() : 0; // if (!disableViewPager) { // scrollToChild(currentPosition, 0); // ?? // selectedTab(currentPosition); // ?TAB // } // ?tab?Pager for (int w = 0; w < tabViewGroup.getChildCount(); w++) { View itemView = tabViewGroup.getChildAt(w); itemView.setTag(w); itemView.setOnClickListener(this); } } }
From source file:info.tellmetime.TellmetimeActivity.java
/** * Handles changing highlight color via #mSeekBarHighlight. * * @param value indicates exact offset in gradient (SeekBar's max value is equal to #mRainbow width). *//* ww w .jav a 2 s . c o m*/ @Override public void onProgressChanged(SeekBar seekBar, int value, boolean fromUser) { switch (seekBar.getId()) { case R.id.highlightValue: mHighlightColor = mRainbow.getPixel(value, 0); if (((RadioButton) findViewById(R.id.radio_backlight_highlight)).isChecked()) { float[] highlightHSV = new float[3]; Color.colorToHSV(mHighlightColor, highlightHSV); mBacklightColor = Color.HSVToColor(33, highlightHSV); } if (fromUser) mHighlightPosition = (float) value / seekBar.getMax(); mClockAlgorithm.tickTock(); break; case R.id.minutesSize: mMinutesSize = value; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { FrameLayout minutesIndicators = (FrameLayout) findViewById(R.id.minutes_indicators); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) minutesIndicators .getLayoutParams(); params.topMargin = (int) -TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize / 3, getResources().getDisplayMetrics()); minutesIndicators.setLayoutParams(params); } ViewGroup minutesDots = (ViewGroup) findViewById(R.id.minutes_dots); for (int i = 0; i < minutesDots.getChildCount(); i++) { TextView m = (TextView) minutesDots.getChildAt(i); m.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize); } break; } mHider.delayedHide(4000); }
From source file:de.mrapp.android.validation.AbstractValidateableView.java
/** * Adapts the enable state of all children of a specific view group. * * @param viewGroup//from ww w.jav a2 s . c o m * The view group, whose children's enabled states should be adapted, as an instance of * the class {@link ViewGroup}. The view group may not be null * @param enabled * True, if the children should be enabled, false otherwise */ private void setEnabledOnViewGroup(@NonNull final ViewGroup viewGroup, final boolean enabled) { viewGroup.setEnabled(enabled); for (int i = 0; i < viewGroup.getChildCount(); i++) { View child = viewGroup.getChildAt(i); if (child instanceof ViewGroup) { setEnabledOnViewGroup((ViewGroup) child, enabled); } else { child.setEnabled(enabled); } } }
From source file:de.mrapp.android.validation.AbstractValidateableView.java
/** * Adapts the activated state of all children of a specific view group. * * @param viewGroup/* ww w . ja v a2 s.c om*/ * The view group, whose children's activated states should be adapted, as an instance * of the class {@link ViewGroup}. The view group may not be null * @param activated * True, if the children should be activated, false otherwise */ private void setActivatedOnViewGroup(@NonNull final ViewGroup viewGroup, final boolean activated) { viewGroup.setActivated(activated); for (int i = 0; i < viewGroup.getChildCount(); i++) { View child = viewGroup.getChildAt(i); if (child instanceof ViewGroup) { setActivatedOnViewGroup((ViewGroup) child, activated); } else { child.setActivated(activated); } } }
From source file:net.oschina.app.v2.activity.zxing.CaptureActivity.java
private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) { //- ------------------------------------------------------- // String text = rawResult.getText(); if (text != null && StringUtils.isUrl(text)) { if (text.contains("scan_login")) { statusView.setVisibility(View.GONE); viewfinderView.setVisibility(View.GONE); showConfirmLogin(text);/* w ww .j av a 2 s. c om*/ return; } if (text.contains("oschina.net")) { UIHelper.showUrlRedirect(CaptureActivity.this, text); finish(); return; } } try { BarCode2 bc = BarCode2.parse(text); int type = bc.getType(); switch (type) { case BarCode2.SIGN_IN:// handleSignIn(bc); return; default: break; } } catch (JSONException e) { e.printStackTrace(); } //- ------------------------------------------------------- // CharSequence displayContents = resultHandler.getDisplayContents(); if (copyToClipboard && !resultHandler.areContentsSecure()) { ClipboardInterface.setText(displayContents, this); } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (resultHandler.getDefaultButtonID() != null && prefs.getBoolean(PreferencesActivity.KEY_AUTO_OPEN_WEB, false)) { resultHandler.handleButtonPress(resultHandler.getDefaultButtonID()); return; } statusView.setVisibility(View.GONE); viewfinderView.setVisibility(View.GONE); resultView.setVisibility(View.VISIBLE); ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view); if (barcode == null) { barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.app_icon)); } else { barcodeImageView.setImageBitmap(barcode); } TextView formatTextView = (TextView) findViewById(R.id.format_text_view); formatTextView.setText(rawResult.getBarcodeFormat().toString()); TextView typeTextView = (TextView) findViewById(R.id.type_text_view); typeTextView.setText(resultHandler.getType().toString()); DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); TextView timeTextView = (TextView) findViewById(R.id.time_text_view); timeTextView.setText(formatter.format(new Date(rawResult.getTimestamp()))); TextView metaTextView = (TextView) findViewById(R.id.meta_text_view); View metaTextViewLabel = findViewById(R.id.meta_text_view_label); metaTextView.setVisibility(View.GONE); metaTextViewLabel.setVisibility(View.GONE); Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata(); if (metadata != null) { StringBuilder metadataText = new StringBuilder(20); for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) { if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) { metadataText.append(entry.getValue()).append('\n'); } } if (metadataText.length() > 0) { metadataText.setLength(metadataText.length() - 1); metaTextView.setText(metadataText); metaTextView.setVisibility(View.VISIBLE); metaTextViewLabel.setVisibility(View.VISIBLE); } } TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view); contentsTextView.setText(displayContents); int scaledSize = Math.max(22, 32 - displayContents.length() / 4); contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize); TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view); supplementTextView.setText(""); supplementTextView.setOnClickListener(null); if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PreferencesActivity.KEY_SUPPLEMENTAL, true)) { //SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView, // resultHandler.getResult(), // historyManager, // this); } int buttonCount = resultHandler.getButtonCount(); ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view); buttonView.requestFocus(); for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) { TextView button = (TextView) buttonView.getChildAt(x); if (x < buttonCount) { button.setVisibility(View.VISIBLE); button.setText(resultHandler.getButtonText(x)); button.setOnClickListener(new ResultButtonListener(resultHandler, x)); } else { button.setVisibility(View.GONE); } } }
From source file:com.jun.fakeoschina.widget.PagerSlidingTabStrip.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (!allowWidthFull) return;/*from www . j a v a 2s.c o m*/ ViewGroup tabsLayout = getTabsLayout(); // tabsLayout.getMeasuredWidth() ? 528 // getMeasuredWidth() pagerSlidingTabStrip xml720 android:layout_width="match_parent" if (tabsLayout == null || tabsLayout.getMeasuredWidth() >= getMeasuredWidth()) return; if (tabsLayout.getChildCount() <= 0) return; if (tabViews == null) { tabViews = new ArrayList<View>(); } else { tabViews.clear(); } for (int w = 0; w < tabsLayout.getChildCount(); w++) { tabViews.add(tabsLayout.getChildAt(w)); } adjustChildWidthWithParent(tabViews, getMeasuredWidth() - tabsLayout.getPaddingLeft() - tabsLayout.getPaddingRight(), widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec); }
From source file:net.gaast.giggity.ScheduleViewActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); app = (Giggity) getApplication();/*w ww .ja v a 2 s . co m*/ pref = PreferenceManager.getDefaultSharedPreferences(app); curView = getResources() .getIdentifier(pref.getString("default_view", "net.gaast.giggity:id/block_schedule"), null, null); showHidden = pref.getBoolean("show_hidden", false); /* Consider making this a setting, some may find their tablet too small. */ int screen = getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK; tabletView = (screen >= Configuration.SCREENLAYOUT_SIZE_LARGE); setContentView(R.layout.schedule_view_activity); View dl = drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout); drawer = (RelativeLayout) dl.findViewById(R.id.drawer); drawer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // NOOP at least for now just so touches don't fall through to bigScreen. } }); ViewGroup menu = (LinearLayout) dl.findViewById(R.id.menu); menu.getChildCount(); /* Set event handler for all static buttons, going to the option menu code. Dynamic buttons * (from the schedule) have their own handlers. */ for (int i = 0; i < menu.getChildCount(); ++i) { View btn = menu.getChildAt(i); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Not for now as I can't undo it (toggler not calling handlers?) TODO v.setBackground(getResources().getDrawable(R.drawable.menu_gradient)); onOptionsItemSelectedInt(v.getId()); drawerLayout.closeDrawers(); } }); } if (wantDrawer) { /* Hamburger menu! */ /* Should still consider v7-appcompat, depending on how much it, again, affects apk size.. */ getActionBar().setDisplayHomeAsUpEnabled(true); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_menu_white_24dp, R.string.navdrawer_on, R.string.navdrawer_off) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); invalidateOptionsMenu(); /* Looks like this code doesn't actually run BTW. Need to figure that out later. */ updateNavDrawer(); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); invalidateOptionsMenu(); } }; } else { drawerLayout.removeView(drawer); } bigScreen = (LinearLayout) dl.findViewById(R.id.bigScreen); updateOrientation(getResources().getConfiguration().orientation); viewerContainer = (RelativeLayout) dl.findViewById(R.id.viewerContainer); /* TODO: See if I can do this in XML as well? (It's a custom private view.) */ RelativeLayout.LayoutParams lp; lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); days = new DayButtons(this); viewerContainer.addView(days, lp); redraw = false; timer = new Handler(); /* If the OS informs us that the timezone changes, close this activity so the schedule gets reloaded. (This because input is usually TZ-unaware while our objects aren't.) */ tzClose = new BroadcastReceiver() { @Override public void onReceive(Context arg0, Intent arg1) { ScheduleViewActivity.this.finish(); } }; registerReceiver(tzClose, new IntentFilter(Intent.ACTION_TIMEZONE_CHANGED)); if (!getIntent().getAction().equals(Intent.ACTION_VIEW)) return; String url = getIntent().getDataString(); Fetcher.Source fs; if (getIntent().getBooleanExtra("PREFER_CACHED", false)) fs = Fetcher.Source.CACHE_ONLINE; else fs = Fetcher.Source.ONLINE_CACHE; /* I think reminders come in via this activity (instead of straight to itemview) because we may have to reload schedule data? */ if (url.contains("#")) { String parts[] = url.split("#", 2); url = parts[0]; showEventId = parts[1]; } if (app.hasSchedule(url)) { try { sched = app.getSchedule(url, fs); } catch (Exception e) { // Java makes me tired. e.printStackTrace(); } onScheduleLoaded(); } else { loadScheduleAsync(url, fs); } }
From source file:de.grobox.liberario.DirectionsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // remember view for UI changes when fragment is not active mView = inflater.inflate(R.layout.fragment_directions, container, false); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); checkPreferences();/*from www . ja v a2 s . co m*/ setFromUI(); setToUI(); // timeView final Button timeView = (Button) mView.findViewById(R.id.timeView); timeView.setText(DateUtils.getcurrentTime(getActivity())); timeView.setTag(Calendar.getInstance()); timeView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showTimePickerDialog(); } }); // set current time on long click timeView.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View view) { timeView.setText(DateUtils.getcurrentTime(getActivity())); timeView.setTag(Calendar.getInstance()); return true; } }); Button plus10Button = (Button) mView.findViewById(R.id.plus15Button); plus10Button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { addToTime(15); } }); // dateView final Button dateView = (Button) mView.findViewById(R.id.dateView); dateView.setText(DateUtils.getcurrentDate(getActivity())); dateView.setTag(Calendar.getInstance()); dateView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showDatePickerDialog(); } }); // set current date on long click dateView.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View view) { dateView.setText(DateUtils.getcurrentDate(getActivity())); dateView.setTag(Calendar.getInstance()); return true; } }); // Trip Date Type Spinner (departure or arrival) final TextView dateType = (TextView) mView.findViewById(R.id.dateType); dateType.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (dateType.getText().equals(getString(R.string.trip_dep))) { dateType.setText(getString(R.string.trip_arr)); } else { dateType.setText(getString(R.string.trip_dep)); } } }); // Products final ViewGroup productsLayout = (ViewGroup) mView.findViewById(R.id.productsLayout); for (int i = 0; i < productsLayout.getChildCount(); ++i) { final ImageView productView = (ImageView) productsLayout.getChildAt(i); final Product product = Product.fromCode(productView.getTag().toString().charAt(0)); // make inactive products gray if (mProducts.contains(product)) { productView.getDrawable().setColorFilter(null); } else { productView.getDrawable().setColorFilter(getResources().getColor(R.color.highlight), PorterDuff.Mode.SRC_ATOP); } // handle click on product icon productView.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (mProducts.contains(product)) { productView.getDrawable().setColorFilter(getResources().getColor(R.color.highlight), PorterDuff.Mode.SRC_ATOP); mProducts.remove(product); Toast.makeText(v.getContext(), LiberarioUtils.productToString(v.getContext(), product), Toast.LENGTH_SHORT).show(); } else { productView.getDrawable().setColorFilter(null); mProducts.add(product); Toast.makeText(v.getContext(), LiberarioUtils.productToString(v.getContext(), product), Toast.LENGTH_SHORT).show(); } } }); // handle long click on product icon by showing product name productView.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View view) { Toast.makeText(view.getContext(), LiberarioUtils.productToString(view.getContext(), product), Toast.LENGTH_SHORT).show(); return true; } }); } if (!Preferences.getPref(getActivity(), Preferences.SHOW_ADV_DIRECTIONS)) { (mView.findViewById(R.id.productsScrollView)).setVisibility(View.GONE); } Button searchButton = (Button) mView.findViewById(R.id.searchButton); searchButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { NetworkProvider np = NetworkProviderFactory.provider(Preferences.getNetworkId(getActivity())); if (!np.hasCapabilities(NetworkProvider.Capability.TRIPS)) { Toast.makeText(v.getContext(), v.getContext().getString(R.string.error_no_trips_capability), Toast.LENGTH_SHORT).show(); return; } AsyncQueryTripsTask query_trips = new AsyncQueryTripsTask(v.getContext()); // check and set to location if (checkLocation(FavLocation.LOC_TYPE.TO)) { query_trips.setTo(getLocation(FavLocation.LOC_TYPE.TO)); } else { Toast.makeText(getActivity(), getResources().getString(R.string.error_invalid_to), Toast.LENGTH_SHORT).show(); return; } // check and set from location if (mGpsPressed) { if (getLocation(FavLocation.LOC_TYPE.FROM) != null) { query_trips.setFrom(getLocation(FavLocation.LOC_TYPE.FROM)); } else { mAfterGpsTask = query_trips; pd = new ProgressDialog(getActivity()); pd.setMessage(getResources().getString(R.string.stations_searching_position)); pd.setCancelable(false); pd.setIndeterminate(true); pd.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mAfterGpsTask = null; dialog.dismiss(); } }); pd.show(); } } else { if (checkLocation(FavLocation.LOC_TYPE.FROM)) { query_trips.setFrom(getLocation(FavLocation.LOC_TYPE.FROM)); } else { Toast.makeText(getActivity(), getString(R.string.error_invalid_from), Toast.LENGTH_SHORT) .show(); return; } } // remember trip if not from GPS if (!mGpsPressed) { FavDB.updateFavTrip(getActivity(), new FavTrip(getLocation(FavLocation.LOC_TYPE.FROM), getLocation(FavLocation.LOC_TYPE.TO))); } // set date query_trips.setDate(DateUtils.mergeDateTime(getActivity(), dateView.getText(), timeView.getText())); // set departure to true of first item is selected in spinner query_trips.setDeparture(dateType.getText().equals(getString(R.string.trip_dep))); // set products query_trips.setProducts(mProducts); // don't execute if we still have to wait for GPS position if (mAfterGpsTask != null) return; query_trips.execute(); } }); return mView; }