List of usage examples for android.view ViewGroup getChildCount
public int getChildCount()
From source file:at.ac.uniklu.mobile.sportal.MensaMenuFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); MensaActivity ma = (MensaActivity) getActivity(); if (ma.isDataAvailable()) { final MenuCategory mc = ma.getMenuCategory(mIndex); ViewGroup container = (ViewGroup) getView().findViewById(R.id.menu_items_container); LayoutInflater inflater = getLayoutInflater(getArguments()); container.findViewById(R.id.mensa_website).setOnClickListener(new View.OnClickListener() { @Override//from w ww . j av a 2 s . com public void onClick(View v) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(mc.link))); } }); for (MenuItem mi : mc.menuItems) { View menuItem = inflater.inflate(R.layout.mensa_menu_item, container, false); if (StringUtils.isEmpty(mi.title)) { menuItem.findViewById(R.id.text_title).setVisibility(View.GONE); } else { ((TextView) menuItem.findViewById(R.id.text_title)).setText(mi.title); } ((TextView) menuItem.findViewById(R.id.text_description)).setText(mi.description); if (!StringUtils.isEmpty(mi.description)) { container.addView(menuItem, container.getChildCount() - 1); } } } }
From source file:org.cirdles.chroni.FilePickerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTheme(android.R.style.Theme_Holo); // Set the view to be shown if the list is empty LayoutInflater inflator = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View emptyView = inflator.inflate(R.layout.file_picker_empty_view, null); ((ViewGroup) getListView().getParent()).addView(emptyView); getListView().setEmptyView(emptyView); // adds a RelativeLayout to wrap the listView so that a button can be placed at the bottom RelativeLayout outerLayout = (RelativeLayout) inflator.inflate(R.layout.file_picker_regular_view, null); ((ViewGroup) getListView().getParent()).addView(outerLayout); // sets the margin for the listView so that the bottom item isn't covered FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); params.setMargins(0, 0, 0, 100);//w w w. j av a2 s .c om getListView().setLayoutParams(params); // defines the action for the bottom button Button previousFolderButton = (Button) findViewById(R.id.filePickerPreviousButton); previousFolderButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // moves to the previous directory (if it exists) and refreshes the list of files if (mainDirectory.getParentFile() != null) { mainDirectory = mainDirectory.getParentFile(); refreshFilesList(); // goes through and remo any stubborn delete imageViews ViewGroup list = getListView(); int number = list.getChildCount(); // gets rid of all the delete images for (int i = 0; i < number; i++) { View child = list.getChildAt(i); View checkbox = child.findViewById(R.id.checkBoxFilePicker); checkbox.setVisibility(View.GONE); } // sets the action bar at the top so that it tells the user what the current directory is actionBar = getActionBar(); if (actionBar != null) actionBar.setTitle("/" + mainDirectory.getName()); } // if in delete mode or move mode, resets back to normal mode if (inDeleteMode) toggleDelete(); if (inMovePickMode) toggleMove(false); // pass false, not actually executing the move } }); // defines what happens to a list item on a long press getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, final View view, int position, long id) { // stores the address of the file/folder that has been chosen final File chosenFile = (File) parent.getItemAtPosition(position); if (!choosingDirectory) { // only gives options if the chosen file is NOT a directory if (!chosenFile.isDirectory()) { // brings up a Dialog box and asks the user if they want to copy or delete the file CharSequence[] options = { "Copy", "Move", "Delete" }; // the user's options new AlertDialog.Builder(FilePickerActivity.this) .setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { // copy has been chosen // resets cutFiles if it contains files if (cutFiles != null) cutFiles = null; copiedFile = chosenFile; Toast.makeText(FilePickerActivity.this, "File Copied!", Toast.LENGTH_SHORT).show(); // sets the pasteButton's visibility to visible once the file has been copied Button pasteButton = (Button) findViewById(R.id.filePickerPasteButton); pasteButton.setVisibility(View.VISIBLE); dialog.dismiss(); } else if (which == 1) { // move has been chosen // resets copiedFile if it has a file in it if (copiedFile != null) copiedFile = null; cutFiles = new ArrayList<>(); cutFiles.add(chosenFile); Toast.makeText(FilePickerActivity.this, "File Copied!", Toast.LENGTH_SHORT).show(); // sets the pasteButton's visibility to visible once the file has been copied Button pasteButton = (Button) findViewById(R.id.filePickerPasteButton); pasteButton.setVisibility(View.VISIBLE); dialog.dismiss(); } else if (which == 2) { // delete has been chosen // shows a new dialog asking if the user would like to delete the file or not new AlertDialog.Builder(FilePickerActivity.this) .setMessage("Are you sure you want to delete this file?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // if deleting the currently copied file, un-copy it if (copiedFile != null && chosenFile.equals(copiedFile)) { copiedFile = null; Button pasteButton = (Button) findViewById( R.id.filePickerPasteButton); pasteButton.setVisibility(View.GONE); } // deletes the file and updates the adapter chosenFile.delete(); mAdapter.remove(chosenFile); dialog.dismiss(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); dialog.dismiss(); } } }).show(); } else if (chosenFile.list().length == 0) { // can only delete directory if it's empty // brings up a Dialog box and asks the user if they want to copy or delete the file CharSequence[] options = { "Delete" }; // the user's options new AlertDialog.Builder(FilePickerActivity.this) .setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // shows a new dialog asking if the user would like to delete the file or not new AlertDialog.Builder(FilePickerActivity.this) .setMessage("Are you sure you want to delete this file?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // if deleting a currently copied or cut file, un-copy it if ((copiedFile != null && chosenFile.equals(copiedFile)) || (cutFiles != null && cutFiles.contains(chosenFile))) { // resets the copied/cut file(s) if (copiedFile != null) copiedFile = null; if (cutFiles != null) cutFiles = null; // and gets rid of the paste button on the bottom Button pasteButton = (Button) findViewById( R.id.filePickerPasteButton); pasteButton.setVisibility(View.GONE); } // deletes the file and updates the adapter chosenFile.delete(); mAdapter.remove(chosenFile); Toast.makeText(FilePickerActivity.this, "File Deleted!", Toast.LENGTH_SHORT).show(); dialog.dismiss(); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); } }).show(); } } return true; } }); // Obtain content from the current intent for later use intentContent = getIntent().getStringExtra("Default_Directory"); // Set initial directory if it hasn't been already defined if (mainDirectory == null) { mainDirectory = Environment.getExternalStorageDirectory(); // Takes user to root directory folder // Sets the initial directory based on what file the user is looking for (Aliquot or Report Settings) if (intentContent.contentEquals("Aliquot_Directory") || intentContent.contentEquals("From_Aliquot_Directory")) mainDirectory = new File(mainDirectory + "/CHRONI/Aliquot"); // Takes user to the Aliquot folder // Report Settings Menu if coming from a Dropdown Menu or the Report Settings Menu else if (intentContent.contentEquals("Report_Settings_Directory") || intentContent.contentEquals("From_Report_Directory")) mainDirectory = new File(mainDirectory + "/CHRONI/Report Settings"); else if (intentContent.contentEquals("Parent_Directory")) choosingDirectory = true; // choosing a directory rather than a file // if none of these are true, the directory will be CHRONI's parent directory (externalStorageDirectory) } // sets the action bar at the top so that it tells the user what the current directory is actionBar = getActionBar(); if (actionBar != null) actionBar.setTitle("/" + mainDirectory.getName()); // Initialize the ArrayList mFiles = new ArrayList<>(); // Set the ListAdapter mAdapter = new FilePickerListAdapter(this, mFiles); setListAdapter(mAdapter); // Initialize the extensions array to allow any file extensions acceptedFileExtensions = new String[] {}; // Get intent extras if (getIntent().hasExtra(EXTRA_SHOW_HIDDEN_FILES)) { mShowHiddenFiles = getIntent().getBooleanExtra(EXTRA_SHOW_HIDDEN_FILES, false); } if (getIntent().hasExtra(EXTRA_ACCEPTED_FILE_EXTENSIONS)) { ArrayList<String> collection = getIntent().getStringArrayListExtra(EXTRA_ACCEPTED_FILE_EXTENSIONS); acceptedFileExtensions = collection.toArray(new String[collection.size()]); } // if no file permissions, asks for them if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, 1); } }
From source file:com.nachiket.titan.LibraryActivity.java
private void setSearchBoxVisible(boolean visible) { mSearchBoxVisible = visible;//w w w . j av a 2s . com mSearchBox.setVisibility(visible ? View.VISIBLE : View.GONE); if (mControls != null) { mControls.setVisibility( visible || (mState & PlaybackService.FLAG_NO_MEDIA) != 0 ? View.GONE : View.VISIBLE); } else if (mActionControls != null) { // try to hide the bottom action bar ViewParent parent = mActionControls.getParent(); if (parent != null) parent = parent.getParent(); if (parent != null && parent instanceof ViewGroup) { ViewGroup ab = (ViewGroup) parent; if (ab.getChildCount() == 1) { ab.setVisibility(visible ? View.GONE : View.VISIBLE); } } } if (visible) { mTextFilter.requestFocus(); ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).showSoftInput(mTextFilter, 0); } }
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 ww w . ja va 2 s .c o 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; }
From source file:info.tellmetime.TellmetimeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tellmetime); mDensity = getResources().getDisplayMetrics().density; mScreenWidth = getResources().getDisplayMetrics().widthPixels; mScreenHeight = getResources().getDisplayMetrics().heightPixels; mShorterEdge = Math.min(mScreenWidth, mScreenHeight); mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop(); mBacklightLight = getResources().getColor(R.color.backlight_light); mBacklightDark = getResources().getColor(R.color.backlight_dark); // Restore background and highlight colors from saved values or set defaults. mSettings = getSharedPreferences("PREFS", Context.MODE_PRIVATE); mHighlightColor = mSettings.getInt(HIGHLIGHT, Color.WHITE); mBacklightColor = mSettings.getInt(BACKLIGHT, mBacklightLight); mBackgroundColor = mSettings.getInt(BACKGROUND, getResources().getColor(R.color.background)); mBackgroundMode = mSettings.getInt(BACKGROUND_MODE, MODE_BACKGROUND_SOLID); mHighlightPosition = mSettings.getFloat(POSITION, 0.0f); mMinutesSize = mSettings.getInt(MINUTES_SIZE, 36); isNightMode = mSettings.getBoolean(NIGHTMODE, false); // Dim the navigation bar. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) getWindow().getDecorView().setSystemUiVisibility(isNightMode ? View.SYSTEM_UI_FLAG_LOW_PROFILE : 0); mSurface = (RelativeLayout) findViewById(R.id.surface); mSurface.setBackgroundColor(mBackgroundColor); resizeClock();/* w w w .j a va 2s. c o m*/ Typeface mTypefaceBold = Typeface.createFromAsset(getAssets(), "Roboto-BoldCondensed.ttf"); // Set typeface of all items in the clock to Roboto and dim each one and drop shadow on them. final LinearLayout mClock = (LinearLayout) findViewById(R.id.clock); for (int i = 0; i < mClock.getChildCount(); i++) { LinearLayout row = (LinearLayout) mClock.getChildAt(i); for (int j = 0; j < row.getChildCount(); j++) { TextView tv = (TextView) row.getChildAt(j); tv.setTypeface(mTypefaceBold); tv.setTextColor(mBacklightColor); tv.setShadowLayer(mShorterEdge / 200 * mDensity, 0, 0, mBacklightColor); } } ViewGroup minutesDots = (ViewGroup) findViewById(R.id.minutes_dots); for (int i = 0; i < minutesDots.getChildCount(); i++) { TextView m = (TextView) minutesDots.getChildAt(i); m.setTypeface(mTypefaceBold); m.setTextColor(mBacklightColor); m.setShadowLayer(mShorterEdge / 200 * mDensity, 0, 0, mBacklightColor); } // Set Roboto font on TextView where it isn't default. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { Typeface mTypefaceItalic = Typeface.createFromAsset(getAssets(), "Roboto-CondensedItalic.ttf"); ((TextView) findViewById(R.id.labelBackground)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.info_background)).setTypeface(mTypefaceItalic); ((TextView) findViewById(R.id.info_image)).setTypeface(mTypefaceItalic); ((TextView) findViewById(R.id.labelHighlight)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.labelBackground)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.radio_backlight_light)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.radio_backlight_dark)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.radio_backlight_highlight)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.labelMinutes)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.m1)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.m2)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.m3)).setTypeface(mTypefaceBold); ((TextView) findViewById(R.id.m4)).setTypeface(mTypefaceBold); } FrameLayout mTouchZone = (FrameLayout) findViewById(R.id.touchZone); mTouchZone.setOnTouchListener(this); mTouchZone.setBackgroundColor( getResources().getColor(isNightMode ? R.color.night_mode_overlay : android.R.color.transparent)); mBackgroundImage = (ImageView) findViewById(R.id.background_image); switchBackgroundMode(mBackgroundMode); RelativeLayout mPanel = (RelativeLayout) findViewById(R.id.panel); mPanel.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { mHider.delayedHide(4000); return true; } }); mHider = new PanelHider(mPanel, this); Spinner spinnerBackgroundMode = (Spinner) findViewById(R.id.spinnerBackgroundMode); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.backgrounds_modes, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerBackgroundMode.setAdapter(adapter); spinnerBackgroundMode.setOnItemSelectedListener(this); spinnerBackgroundMode.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { mHider.showNoAutoHide(); return false; } }); spinnerBackgroundMode.setSelection(mBackgroundMode); mSeekBarHighlight = (SeekBar) findViewById(R.id.highlightValue); mSeekBarHighlight.setOnSeekBarChangeListener(this); // Draw rainbow gradient on #mSeekBarHighlight and set position. drawRainbow(); if (mBacklightColor == mBacklightLight) ((RadioButton) findViewById(R.id.radio_backlight_light)).setChecked(true); else if (mBacklightColor == mBacklightDark) ((RadioButton) findViewById(R.id.radio_backlight_dark)).setChecked(true); else ((RadioButton) findViewById(R.id.radio_backlight_highlight)).setChecked(true); SeekBar mSeekBarMinutes = (SeekBar) findViewById(R.id.minutesSize); mSeekBarMinutes.setOnSeekBarChangeListener(this); mSeekBarMinutes.setProgress(mMinutesSize); mHider.hideNow(); Color.colorToHSV(mBackgroundColor, mHSV); mHSV[1] = 1.0f; //Trigger initial tick. mClockAlgorithm.tickTock(); // Schedule the clock algorithm to tick every round minute. Calendar time = Calendar.getInstance(); time.set(Calendar.MILLISECOND, 0); time.set(Calendar.SECOND, 0); time.add(Calendar.MINUTE, 1); Timer timer = new Timer(); timer.schedule(mClockTask, time.getTime(), 60 * 1000); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mSurface.setAlpha(0.0f); mSurface.animate().alpha(1.0f).setDuration(1500); } // If it is first run, hint to user that panel is available. if (!mSettings.contains(HIGHLIGHT)) showToast(R.string.info_first_run); }
From source file:com.aretha.slidemenu.SlideMenu.java
protected final boolean canScroll(View v, int dx, int x, int y) { if (null == mScrollDetector) { return false; }/*from ww w .j ava 2s . co m*/ if (v instanceof ViewGroup) { final ViewGroup viewGroup = (ViewGroup) v; final int scrollX = v.getScrollX(); final int scrollY = v.getScrollY(); final int childCount = viewGroup.getChildCount(); for (int index = 0; index < childCount; index++) { View child = viewGroup.getChildAt(index); final int left = child.getLeft(); final int top = child.getTop(); if (x + scrollX >= left && x + scrollX < child.getRight() && y + scrollY >= top && y + scrollY < child.getBottom() && (mScrollDetector.isScrollable(child, dx, x + scrollX - left, y + scrollY - top) || canScroll(child, dx, x + scrollX - left, y + scrollY - top))) { return true; } } } return ViewCompat.canScrollHorizontally(v, -dx); }
From source file:com.aigo.kt03airdemo.ui.view.ResideLayout.java
private View findViewAtPosition(View parent, int x, int y) { if (parent instanceof ViewPager) { Rect rect = new Rect(); parent.getGlobalVisibleRect(rect); if (rect.contains(x, y)) { return parent; }//from w w w . j av a 2 s .co m } else if (parent instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) parent; final int length = viewGroup.getChildCount(); for (int i = 0; i < length; i++) { View child = viewGroup.getChildAt(i); View viewAtPosition = findViewAtPosition(child, x, y); if (viewAtPosition != null) { return viewAtPosition; } } return null; } return null; }
From source file:com.eleybourn.bookcatalogue.utils.Utils.java
/** * Passed a parent view, add it and all children view (if any) to the passed collection * // w w w.j av a2 s .c o m * @param p Parent View * @param vh Collection */ private static void getViews(View p, Hashtable<Integer, View> vh) { // Get the view ID and add it to collection if not already present. final int id = p.getId(); if (id != View.NO_ID && !vh.containsKey(id)) { vh.put(id, p); } // If it's a ViewGroup, then process children recursively. if (p instanceof ViewGroup) { final ViewGroup g = (ViewGroup) p; final int nChildren = g.getChildCount(); for (int i = 0; i < nChildren; i++) { getViews(g.getChildAt(i), vh); } } }
From source file:com.gdgl.util.SlideMenu.java
/** * Detect whether the views inside content are slidable *//*from w w w . j a va 2 s. co m*/ protected final boolean canScroll(View v, int dx, int x, int y) { if (v instanceof ViewGroup) { final ViewGroup viewGroup = (ViewGroup) v; final int scrollX = v.getScrollX(); final int scrollY = v.getScrollY(); final int childCount = viewGroup.getChildCount(); for (int index = 0; index < childCount; index++) { View child = viewGroup.getChildAt(index); final int left = child.getLeft(); final int top = child.getTop(); if (x + scrollX >= left && x + scrollX < child.getRight() && y + scrollY >= top && y + scrollY < child.getBottom() && View.VISIBLE == child.getVisibility() && (ScrollDetectors.canScrollHorizontal(child, dx) || canScroll(child, dx, x + scrollX - left, y + scrollY - top))) { return true; } } } return ViewCompat.canScrollHorizontally(v, -dx); }
From source file:ca.mymenuapp.ui.widgets.SlidingUpPanelLayout.java
/** * Tests scrollability within child views of v given a delta of dx. * * @param v View to test for horizontal scrollability * @param checkV Whether the view v passed should itself be checked for scrollability (true), * or just its children (false)./* ww w .ja v a2s .c o m*/ * @param dx Delta scrolled in pixels * @param x X coordinate of the active touch point * @param y Y coordinate of the active touch point * @return true if child views of v can be scrolled by delta of dx. */ protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) { if (v instanceof ViewGroup) { final ViewGroup group = (ViewGroup) v; final int scrollX = v.getScrollX(); final int scrollY = v.getScrollY(); final int count = group.getChildCount(); // Count backwards - let topmost views consume scroll distance first. for (int i = count - 1; i >= 0; i--) { final View child = group.getChildAt(i); if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child, true, dx, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } } } return checkV && ViewCompat.canScrollHorizontally(v, -dx); }