List of usage examples for android.view View getParent
public final ViewParent getParent()
From source file:com.numenta.htmit.mobile.notification.NotificationListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); gestureDetector = new GestureDetector(getApplicationContext(), this); setContentView(R.layout.activity_notification_list); setVisible(false);/*from w w w.ja v a 2 s. com*/ listView = (ListView) findViewById(R.id.notification_list_view); dismissButton = (Button) findViewById(R.id.action_dismiss_all_notifications); closeButton = (Button) findViewById(R.id.action_close_notifications); noNotificationsText = (TextView) findViewById(R.id.no_notifications_text); // For the cursor adapter, specify which columns go into which views String[] fromColumns = { "timestamp", "description", "metric_id", "read" }; int[] toViews = { R.id.notification_time, R.id.notification_description, R.id.notification_delete, R.id.notification_unread }; // The TextView in simple_list_item_1 _database = HTMITApplication.getDatabase(); adapter = new SimpleCursorAdapter(this, R.layout.fragment_notification_list_item, null, fromColumns, toViews, 0); new AsyncTask<Void, Void, Cursor>() { @Override protected Cursor doInBackground(Void... params) { unreadNotificationSize = _database.getUnreadNotificationCount(); return _database.getNotificationCursor(); } @Override protected void onPostExecute(Cursor cursor) { setVisible(true); adapter.changeCursor(cursor); notificationSize = cursor.getCount(); updateButtons(); } }.execute(); _notificationsReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (adapter != null) { new AsyncTask<Void, Void, Cursor>() { @Override protected Cursor doInBackground(Void... params) { if (isCancelled()) return null; return _database.getNotificationCursor(); } @Override protected void onPostExecute(Cursor cursor) { adapter.changeCursor(cursor); updateButtons(); } }.execute(); } } }; adapter.setViewBinder(new ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { final int viewId = view.getId(); switch (viewId) { case R.id.notification_time: // Converts the timestamp to a readable time. final int timeIndex = cursor.getColumnIndex("timestamp"); Date date = new Date(cursor.getLong(timeIndex)); ((TextView) view).setText(sdf.format(date)); break; case R.id.notification_unread: // Hides notification icon if already read. if (cursor.getInt(cursor.getColumnIndex("read")) < 1) { view.setVisibility(View.VISIBLE); } else { view.setVisibility(View.INVISIBLE); } break; case R.id.notification_delete: // Adds click handler for notification deletions view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "{TAG:ANDROID.ACTION.NOTIFICATION.DELETE} Delete notification clicked"); View layout = (View) v.getParent(); int position = listView.getPositionForView(layout); NotificationListActivity.this.removeNotificationAt(position); } }); break; default: return false; } return true; } }); listView.setAdapter(adapter); // Clicks on the notifications themselves navigates to the detail view. listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, final View view, int position, long id) { Log.i(TAG, "{TAG:ANDROID.ACTION.NOTIFICATION.SELECT} Notification navigation should occur here to notification " + position); Cursor cursor = (Cursor) adapter.getItem(position); int localIdx = cursor.getColumnIndex("_id"); final int localId = cursor.getInt(localIdx); new AsyncTask<Void, Void, Intent>() { @Override protected Intent doInBackground(Void... v) { // Get the metric necessary for the new intent to view // the metric detail // page. Notification notification = _database.getNotificationByLocalId(localId); if (notification == null) { // The notification or metric was deleted as the // user view the list return null; } Metric metric = _database.getMetric(notification.getMetricId()); if (metric == null) { // the metric was deleted, so nowhere to go _database.deleteNotification(localId); return null; } Intent metricDetail = NotificationUtils .createMetricDetailIntent(NotificationListActivity.this, notification); // Mark the notification as read if (!notification.isRead()) { _database.markNotificationRead(localId); } ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancelAll(); return metricDetail; } @Override protected void onPostExecute(Intent metricDetail) { if (metricDetail == null) { Toast.makeText(NotificationListActivity.this, R.string.notification_expired, Toast.LENGTH_LONG).show(); NotificationListActivity.this.finish(); return; } // Show detail page startActivity(metricDetail); // Hide the 'unread' indication. view.findViewById(R.id.notification_unread).setVisibility(View.INVISIBLE); } }.execute(); } }); // This catches "fling" events on items to delete notifications within // the list. // Defers touch events to a GestureDetector, which isolates fling events // from touch events. listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return gestureDetector.onTouchEvent(event); } }); dismissButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Log.i(TAG, "{TAG:ANDROID.ACTION.NOTIFICATION.DELETE_ALL}"); deleteAllNotifications(); } }); closeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { cancelNotifications(); } }); }
From source file:com.evandroid.musica.fragment.LyricsViewFragment.java
public void update(Lyrics lyrics, View layout, boolean animation) { TextSwitcher textSwitcher = ((TextSwitcher) layout.findViewById(R.id.switcher)); LrcView lrcView = (LrcView) layout.findViewById(R.id.lrc_view); View v = getActivity().findViewById(R.id.tracks_msg); if (v != null) ((ViewGroup) v.getParent()).removeView(v); TextView id3TV = (TextView) layout.findViewById(R.id.id3_tv); RelativeLayout bugLayout = (RelativeLayout) layout.findViewById(R.id.error_msg); this.mLyrics = lyrics; if (SDK_INT >= ICE_CREAM_SANDWICH) beamLyrics(lyrics, this.getActivity()); new PresenceChecker().execute(this, new String[] { lyrics.getArtist(), lyrics.getTrack(), lyrics.getOriginalArtist(), lyrics.getOriginalTrack() }); if (isActiveFragment) ((RefreshIcon) getActivity().findViewById(R.id.refresh_fab)).show(); EditText newLyrics = (EditText) getActivity().findViewById(R.id.edit_lyrics); if (newLyrics != null) newLyrics.setText(""); if (lyrics.getFlag() == Lyrics.POSITIVE_RESULT) { if (!lyrics.isLRC()) { textSwitcher.setVisibility(View.VISIBLE); lrcView.setVisibility(View.GONE); if (animation) textSwitcher.setText(Html.fromHtml(lyrics.getText())); else/* ww w . j a va 2s. c om*/ textSwitcher.setCurrentText(Html.fromHtml(lyrics.getText())); } else { textSwitcher.setVisibility(View.GONE); lrcView.setVisibility(View.VISIBLE); lrcView.setOriginalLyrics(lyrics); lrcView.setSourceLrc(lyrics.getText()); updateLRC(); } bugLayout.setVisibility(View.INVISIBLE); if ("Storage".equals(lyrics.getSource())) id3TV.setVisibility(View.VISIBLE); else id3TV.setVisibility(View.GONE); mScrollView.post(new Runnable() { @Override public void run() { mScrollView.scrollTo(0, 0); //only useful when coming from localLyricsFragment mScrollView.smoothScrollTo(0, 0); } }); } else { textSwitcher.setText(""); textSwitcher.setVisibility(View.INVISIBLE); lrcView.setVisibility(View.INVISIBLE); bugLayout.setVisibility(View.VISIBLE); int message; int whyVisibility; if (lyrics.getFlag() == Lyrics.ERROR || !OnlineAccessVerifier.check(getActivity())) { message = R.string.connection_error; whyVisibility = TextView.GONE; } else { message = R.string.no_results; whyVisibility = TextView.VISIBLE; updateSearchView(false, lyrics.getTrack(), false); } TextView whyTextView = ((TextView) bugLayout.findViewById(R.id.bugtext_why)); ((TextView) bugLayout.findViewById(R.id.bugtext)).setText(message); whyTextView.setVisibility(whyVisibility); whyTextView.setPaintFlags(whyTextView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); id3TV.setVisibility(View.GONE); } stopRefreshAnimation(); getActivity().getIntent().setAction(""); getActivity().invalidateOptionsMenu(); }
From source file:com.example.android.apprestrictionenforcer.AppRestrictionEnforcerFragment.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.item_add: new ItemAddFragment().show(getChildFragmentManager(), "dialog"); break;/*from w ww .j av a 2 s .c o m*/ case R.id.item_remove: String key = (String) v.getTag(); removeItem(key); mLayoutItems.removeView((View) v.getParent()); break; } }
From source file:com.haarman.listviewanimations.itemmanipulation.SwipeDismissListViewTouchListener.java
private Rect getChildViewRect(View parentView, View childView) { final Rect childRect = new Rect(childView.getLeft(), childView.getTop(), childView.getRight(), childView.getBottom());/* w ww .j a va 2 s . co m*/ if (parentView == childView) { return childRect; } ViewGroup parent; while ((parent = (ViewGroup) childView.getParent()) != parentView) { childRect.offset(parent.getLeft(), parent.getTop()); childView = parent; } return childRect; }
From source file:androidx.navigation.fragment.NavHostFragment.java
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); if (!(view instanceof ViewGroup)) { throw new IllegalStateException("created host view " + view + " is not a ViewGroup"); }/* ww w. ja va 2 s. c o m*/ // When added via XML, the parent is null and our view is the root of the NavHostFragment // but when added programmatically, we need to set the NavController on the parent - i.e., // the View that has the ID matching this NavHostFragment. View rootView = view.getParent() != null ? (View) view.getParent() : view; Navigation.setViewNavController(rootView, mNavController); }
From source file:com.example.google.walkway.MainActivity.java
public void onPlaceTypeSelected(View view) { // Get the index of the row that contains the checkbox. // int index = mNavListView.getSelectedItemPosition(); int index = mNavListView.indexOfChild((View) view.getParent()); Place.PlaceType placeType = Place.PlaceType.values()[index]; if (((CheckBox) view).isChecked()) { mSelectedPlaceTypes.add(placeType); } else {//from w w w. j ava 2 s. co m mSelectedPlaceTypes.remove(placeType); } }
From source file:com.doomonafireball.betterpickers.TouchExplorationHelper.java
/** * Computes whether the specified {@link android.graphics.Rect} intersects * with the visible portion of its parent {@link android.view.View}. * Modifies {@code localRect} to contain only the visible portion. * /* www . jav a 2 s .c o m*/ * @param localRect * A rectangle in local (parent) coordinates. * @return Whether the specified {@link android.graphics.Rect} is visible on * the screen. */ @SuppressLint("NewApi") private boolean intersectVisibleToUser(Rect localRect) { // Missing or empty bounds mean this view is not visible. if ((localRect == null) || localRect.isEmpty()) { return false; } // Attached to invisible window means this view is not visible. if (mParentView.getWindowVisibility() != View.VISIBLE) { return false; } // An invisible predecessor or one with alpha zero means // that this view is not visible to the user. Object current = this; while (current instanceof View) { final View view = (View) current; // We have attach info so this view is attached and there is no // need to check whether we reach to ViewRootImpl on the way up. if ((view.getAlpha() <= 0) || (view.getVisibility() != View.VISIBLE)) { return false; } current = view.getParent(); } // If no portion of the parent is visible, this view is not visible. if (!mParentView.getLocalVisibleRect(mTempVisibleRect)) { return false; } // Check if the view intersects the visible portion of the parent. return localRect.intersect(mTempVisibleRect); }
From source file:com.cairoconfessions.MainActivity.java
public void sendShare(View view) { Intent sendIntent = new Intent(); String shareMessage = ((TextView) ((LinearLayout) view.getParent().getParent()) .findViewById(R.id.text_main)).getText().toString(); sendIntent.setAction(Intent.ACTION_SEND); shareMessage = "I would like to share this confession with you:\n\"" + shareMessage + '"'; sendIntent.putExtra(Intent.EXTRA_TEXT, shareMessage); sendIntent.setType("text/plain"); startActivity(sendIntent);// w ww. j a va 2 s . co m }
From source file:com.examples.abelanav2.ui.PicturesFragment.java
@Override public void onPhotoCardClick(View v, final int position) { ((PhotoAdapter) mRecyclerView.getAdapter()).setPosition(position); switch (v.getId()) { case R.id.imageButtonThumbsUp: int vote = 1; CardView card = (CardView) v.getParent().getParent(); card.findViewById(R.id.imageButtonThumbsDown).setSelected(false); if (card.findViewById(R.id.imageButtonThumbsUp).isSelected()) { vote = 0;/*from w w w. ja va 2s. c om*/ card.findViewById(R.id.imageButtonThumbsUp).setSelected(false); } else { card.findViewById(R.id.imageButtonThumbsUp).setSelected(true); } new VoteTask().execute(vote); break; case R.id.imageButtonThumbsDown: vote = -1; card = (CardView) v.getParent().getParent(); card.findViewById(R.id.imageButtonThumbsUp).setSelected(false); if (card.findViewById(R.id.imageButtonThumbsDown).isSelected()) { vote = 0; card.findViewById(R.id.imageButtonThumbsDown).setSelected(false); } else { card.findViewById(R.id.imageButtonThumbsDown).setSelected(true); } new VoteTask().execute(vote); break; case R.id.imageButtonWallpaper: new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.photo_list_wallpaper_title)) .setMessage(getString(R.string.photo_list_wallpaper_message)) .setPositiveButton(R.string.set_wallpaper, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { new WallpaperTask().execute(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // do nothing } }).setIcon(R.drawable.ic_wallpaper).show(); break; case R.id.imageButtonEdit: final EditText editText = new EditText(getActivity().getApplicationContext()); editText.setText(mPhotoAdapter.getPhotoList().get(position).description); editText.setTextColor(getResources().getColor(android.R.color.black)); new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.photo_list_edit_photo_title)) .setMessage(getString(R.string.photo_list_edit_photo_message)).setView(editText) .setPositiveButton(R.string.edit, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { new EditTask().execute(editText.getText().toString()); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // do nothing } }).setIcon(R.drawable.ic_edit).show(); break; case R.id.imageButtonDelete: new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.photo_list_delete_photo_title)) .setMessage(getString(R.string.photo_list_delete_photo_message)) .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { new DeleteTask().execute(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // do nothing } }).setIcon(R.drawable.ic_delete).show(); break; default: break; } }
From source file:android.support.transition.FadePort.java
@Override public Animator onDisappear(ViewGroup sceneRoot, TransitionValues startValues, int startVisibility, TransitionValues endValues, int endVisibility) { if ((mFadingMode & OUT) != OUT) { return null; }/*from w w w .j a va 2 s .c o m*/ View view = null; View startView = (startValues != null) ? startValues.view : null; View endView = (endValues != null) ? endValues.view : null; if (DBG) { Log.d(LOG_TAG, "Fade.onDisappear: startView, startVis, endView, endVis = " + startView + ", " + startVisibility + ", " + endView + ", " + endVisibility); } View overlayView = null; View viewToKeep = null; if (endView == null || endView.getParent() == null) { if (endView != null) { // endView was removed from its parent - add it to the overlay view = overlayView = endView; } else if (startView != null) { // endView does not exist. Use startView only under certain // conditions, because placing a view in an overlay necessitates // it being removed from its current parent if (startView.getParent() == null) { // no parent - safe to use view = overlayView = startView; } else if (startView.getParent() instanceof View && startView.getParent().getParent() == null) { View startParent = (View) startView.getParent(); int id = startParent.getId(); if (id != View.NO_ID && sceneRoot.findViewById(id) != null && mCanRemoveViews) { // no parent, but its parent is unparented but the parent // hierarchy has been replaced by a new hierarchy with the same id // and it is safe to un-parent startView view = overlayView = startView; } } } } else { // visibility change if (endVisibility == View.INVISIBLE) { view = endView; viewToKeep = view; } else { // Becoming GONE if (startView == endView) { view = endView; viewToKeep = view; } else { view = startView; overlayView = view; } } } final int finalVisibility = endVisibility; // TODO: add automatic facility to Visibility superclass for keeping views around if (overlayView != null) { // TODO: Need to do this for general case of adding to overlay int screenX = (Integer) startValues.values.get(PROPNAME_SCREEN_X); int screenY = (Integer) startValues.values.get(PROPNAME_SCREEN_Y); int[] loc = new int[2]; sceneRoot.getLocationOnScreen(loc); ViewCompat.offsetLeftAndRight(overlayView, (screenX - loc[0]) - overlayView.getLeft()); ViewCompat.offsetTopAndBottom(overlayView, (screenY - loc[1]) - overlayView.getTop()); ViewGroupOverlay.createFrom(sceneRoot).add(overlayView); // sceneRoot.getOverlay().add(overlayView); // TODO: add automatic facility to Visibility superclass for keeping views around final float startAlpha = 1; float endAlpha = 0; final View finalView = view; final View finalOverlayView = overlayView; final View finalViewToKeep = viewToKeep; final ViewGroup finalSceneRoot = sceneRoot; final AnimatorListenerAdapter endListener = new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { finalView.setAlpha(startAlpha); // TODO: restore view offset from overlay repositioning if (finalViewToKeep != null) { finalViewToKeep.setVisibility(finalVisibility); } if (finalOverlayView != null) { ViewGroupOverlay.createFrom(finalSceneRoot).remove(finalOverlayView); // finalSceneRoot.getOverlay().remove(finalOverlayView); } } // // @Override // public void onAnimationPause(Animator animation) { // if (finalOverlayView != null) { // finalSceneRoot.getOverlay().remove(finalOverlayView); // } // } // // @Override // public void onAnimationResume(Animator animation) { // if (finalOverlayView != null) { // finalSceneRoot.getOverlay().add(finalOverlayView); // } // } }; return createAnimation(view, startAlpha, endAlpha, endListener); } if (viewToKeep != null) { // TODO: find a different way to do this, like just changing the view to be // VISIBLE for the duration of the transition viewToKeep.setVisibility((View.VISIBLE)); // TODO: add automatic facility to Visibility superclass for keeping views around final float startAlpha = 1; float endAlpha = 0; final View finalView = view; final View finalOverlayView = overlayView; final View finalViewToKeep = viewToKeep; final ViewGroup finalSceneRoot = sceneRoot; final AnimatorListenerAdapter endListener = new AnimatorListenerAdapter() { boolean mCanceled = false; float mPausedAlpha = -1; // @Override // public void onAnimationPause(Animator animation) { // if (finalViewToKeep != null && !mCanceled) { // finalViewToKeep.setVisibility(finalVisibility); // } // mPausedAlpha = finalView.getAlpha(); // finalView.setAlpha(startAlpha); // } // // @Override // public void onAnimationResume(Animator animation) { // if (finalViewToKeep != null && !mCanceled) { // finalViewToKeep.setVisibility(View.VISIBLE); // } // finalView.setAlpha(mPausedAlpha); // } @Override public void onAnimationCancel(Animator animation) { mCanceled = true; if (mPausedAlpha >= 0) { finalView.setAlpha(mPausedAlpha); } } @Override public void onAnimationEnd(Animator animation) { if (!mCanceled) { finalView.setAlpha(startAlpha); } // TODO: restore view offset from overlay repositioning if (finalViewToKeep != null && !mCanceled) { finalViewToKeep.setVisibility(finalVisibility); } if (finalOverlayView != null) { ViewGroupOverlay.createFrom(finalSceneRoot).add(finalOverlayView); // finalSceneRoot.getOverlay().remove(finalOverlayView); } } }; return createAnimation(view, startAlpha, endAlpha, endListener); } return null; }