List of usage examples for android.view ViewGroup getContext
@ViewDebug.CapturedViewProperty public final Context getContext()
From source file:com.frostwire.android.gui.adapters.FileListAdapter.java
protected void initCheckableGridImageView(ViewGroup view, final FileDescriptorItem item) throws Throwable { boolean isChecked = getChecked().contains(item); boolean showFileSize = false; Uri[] uris = getFileItemThumbnailUris(item); MediaPlaybackStatusOverlayView playbackStatusOverlayView = findView(view, R.id.view_my_files_thumbnail_grid_item_playback_overlay_view); MediaPlaybackOverlayPainter.MediaPlaybackState overlayPlaybackState = MediaPlaybackOverlayPainter.MediaPlaybackState.NONE; int thumbnailResizeWidth = (item.fd.fileType == Constants.FILE_TYPE_VIDEOS) ? 512 : 196; if (item.fd.fileType == Constants.FILE_TYPE_VIDEOS && !selectAllMode) { overlayPlaybackState = MediaPlaybackOverlayPainter.MediaPlaybackState.PLAY; showFileSize = true;// w w w. java 2 s .c o m } // TODO: why CheckableImageView needs to exist is hard to explain, I (aldenml) think that // it's better to move the logic to use in place and improve code locality final CheckableImageView checkableView = new CheckableImageView(view.getContext(), view, playbackStatusOverlayView, overlayPlaybackState, thumbnailResizeWidth, // re-sizes while keeping aspect ratio based only on given height 0, uris, isChecked, showFileSize); checkableView.setCheckableMode(selectAllMode); checkableView.loadImages(); if (showFileSize) { checkableView.setFileSize(item.fd.fileSize); } }
From source file:com.xabber.android.ui.adapter.OccupantListAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { final View view; if (convertView == null) { view = activity.getLayoutInflater().inflate(R.layout.item_occupant, parent, false); } else {//from w ww . j a v a 2 s . co m view = convertView; } final Occupant occupant = (Occupant) getItem(position); final ImageView avatarView = (ImageView) view.findViewById(R.id.ivAvatar); avatarView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent; try { intent = ContactActivity.createIntent(activity, account, UserJid.from(JidCreate.domainFullFrom(room.asDomainBareJid(), occupant.getNickname()))); activity.startActivity(intent); } catch (UserJid.UserJidCreateException e) { LogManager.exception(this, e); } } }); final ImageView affilationView = (ImageView) view.findViewById(R.id.affilation); final TextView nameView = (TextView) view.findViewById(R.id.name); final TextView statusTextView = (TextView) view.findViewById(R.id.status); final ImageView statusModeView = (ImageView) view.findViewById(R.id.ivStatus); if (MUCManager.getInstance().getNickname(account, room).equals(occupant.getNickname())) { avatarView.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account)); } else { try { avatarView.setImageDrawable( AvatarManager.getInstance().getUserAvatar(UserJid.from(occupant.getJid()))); } catch (UserJid.UserJidCreateException e) { LogManager.exception(this, e); // set default avatar avatarView.setImageDrawable(ContextCompat.getDrawable(parent.getContext(), R.drawable.ic_avatar_1)); } } affilationView.setImageLevel(occupant.getAffiliation().ordinal()); nameView.setText(occupant.getNickname()); String status; if (occupant.getRole() == MUCRole.moderator) status = activity.getString(R.string.muc_role_moderator); else if (occupant.getRole() == MUCRole.participant) status = activity.getString(R.string.muc_role_participant); else status = activity.getString(R.string.muc_role_visitor); String statusText = occupant.getStatusText(); if (statusText != null && !statusText.isEmpty()) status = status + " " + statusText; statusTextView.setText(status); statusModeView.setImageLevel(occupant.getStatusMode().getStatusLevel()); return view; }
From source file:com.bachhuberdesign.deckbuildergwent.util.FabTransform.java
@Override public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues, final TransitionValues endValues) { if (startValues == null || endValues == null) return null; final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS); final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS); final boolean fromFab = endBounds.width() > startBounds.width(); final View view = endValues.view; final Rect dialogBounds = fromFab ? endBounds : startBounds; final Interpolator fastOutSlowInInterpolator = AnimUtils.getFastOutSlowInInterpolator(); final long duration = getDuration(); final long halfDuration = duration / 2; final long twoThirdsDuration = duration * 2 / 3; if (!fromFab) { // Force measure / layout the dialog back to it's original bounds view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY), makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY)); view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom); }/* w w w . ja v a2s .c o m*/ final int translationX = startBounds.centerX() - endBounds.centerX(); final int translationY = startBounds.centerY() - endBounds.centerY(); if (fromFab) { view.setTranslationX(translationX); view.setTranslationY(translationY); } // Add a color overlay to fake appearance of the FAB final ColorDrawable fabColor = new ColorDrawable(color); fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height()); if (!fromFab) fabColor.setAlpha(0); view.getOverlay().add(fabColor); // Add an icon overlay again to fake the appearance of the FAB final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate(); final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2; final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2; fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(), iconTop + fabIcon.getIntrinsicHeight()); if (!fromFab) fabIcon.setAlpha(0); view.getOverlay().add(fabIcon); // Since the view that's being transition to always seems to be on the top (z-order), we have // to make a copy of the "from" view and put it in the "to" view's overlay, then fade it out. // There has to be another way to do this, right? Drawable dialogView = null; if (!fromFab) { startValues.view.setDrawingCacheEnabled(true); startValues.view.buildDrawingCache(); Bitmap viewBitmap = startValues.view.getDrawingCache(); dialogView = new BitmapDrawable(view.getResources(), viewBitmap); dialogView.setBounds(0, 0, dialogBounds.width(), dialogBounds.height()); view.getOverlay().add(dialogView); } // Circular clip from/to the FAB size final Animator circularReveal; if (fromFab) { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, startBounds.width() / 2, (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2)); circularReveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator()); } else { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2), endBounds.width() / 2); circularReveal.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator()); // Persist the end clip i.e. stay at FAB size after the reveal has run circularReveal.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { final ViewOutlineProvider fabOutlineProvider = view.getOutlineProvider(); view.setOutlineProvider(new ViewOutlineProvider() { boolean hasRun = false; @Override public void getOutline(final View view, Outline outline) { final int left = (view.getWidth() - endBounds.width()) / 2; final int top = (view.getHeight() - endBounds.height()) / 2; outline.setOval(left, top, left + endBounds.width(), top + endBounds.height()); if (!hasRun) { hasRun = true; view.setClipToOutline(true); // We have to remove this as soon as it's laid out so we can get the shadow back view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { if (view.getWidth() == endBounds.width() && view.getHeight() == endBounds.height()) { view.setOutlineProvider(fabOutlineProvider); view.setClipToOutline(false); view.getViewTreeObserver().removeOnPreDrawListener(this); return true; } return true; } }); } } }); } }); } circularReveal.setDuration(duration); // Translate to end position along an arc final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y, fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0) : getPathMotion().getPath(0, 0, -translationX, -translationY)); translate.setDuration(duration); translate.setInterpolator(fastOutSlowInInterpolator); // Fade contents of non-FAB view in/out List<Animator> fadeContents = null; if (view instanceof ViewGroup) { final ViewGroup vg = ((ViewGroup) view); fadeContents = new ArrayList<>(vg.getChildCount()); for (int i = vg.getChildCount() - 1; i >= 0; i--) { final View child = vg.getChildAt(i); final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f); if (fromFab) { child.setAlpha(0f); } fade.setDuration(twoThirdsDuration); fade.setInterpolator(fastOutSlowInInterpolator); fadeContents.add(fade); } } // Fade in/out the fab color & icon overlays final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255); final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255); if (!fromFab) { colorFade.setStartDelay(halfDuration); iconFade.setStartDelay(halfDuration); } colorFade.setDuration(halfDuration); iconFade.setDuration(halfDuration); colorFade.setInterpolator(fastOutSlowInInterpolator); iconFade.setInterpolator(fastOutSlowInInterpolator); // Run all animations together final AnimatorSet transition = new AnimatorSet(); transition.playTogether(circularReveal, translate, colorFade, iconFade); transition.playTogether(fadeContents); if (dialogView != null) { final Animator dialogViewFade = ObjectAnimator.ofInt(dialogView, "alpha", 0) .setDuration(twoThirdsDuration); dialogViewFade.setInterpolator(fastOutSlowInInterpolator); transition.playTogether(dialogViewFade); } transition.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { // Clean up view.getOverlay().clear(); if (!fromFab) { view.setTranslationX(0); view.setTranslationY(0); view.setTranslationZ(0); view.measure(makeMeasureSpec(endBounds.width(), View.MeasureSpec.EXACTLY), makeMeasureSpec(endBounds.height(), View.MeasureSpec.EXACTLY)); view.layout(endBounds.left, endBounds.top, endBounds.right, endBounds.bottom); } } }); return new AnimUtils.NoPauseAnimator(transition); }
From source file:com.github.takahirom.plaidanimation.transition.FabTransform.java
@Override public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues, final TransitionValues endValues) { if (startValues == null || endValues == null) return null; final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS); final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS); final boolean fromFab = endBounds.width() > startBounds.width(); final View view = endValues.view; final Rect dialogBounds = fromFab ? endBounds : startBounds; final Rect fabBounds = fromFab ? startBounds : endBounds; final Interpolator fastOutSlowInInterpolator = new FastOutSlowInInterpolator(); final long duration = getDuration(); final long halfDuration = duration / 2; final long twoThirdsDuration = duration * 2 / 3; if (!fromFab) { // Force measure / layout the dialog back to it's original bounds view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY), makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY)); view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom); }//w ww .ja va2 s . c o m final int translationX = startBounds.centerX() - endBounds.centerX(); final int translationY = startBounds.centerY() - endBounds.centerY(); if (fromFab) { view.setTranslationX(translationX); view.setTranslationY(translationY); } // Add a color overlay to fake appearance of the FAB final ColorDrawable fabColor = new ColorDrawable(color); fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height()); if (!fromFab) fabColor.setAlpha(0); view.getOverlay().add(fabColor); // Add an icon overlay again to fake the appearance of the FAB final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate(); final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2; final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2; fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(), iconTop + fabIcon.getIntrinsicHeight()); if (!fromFab) fabIcon.setAlpha(0); view.getOverlay().add(fabIcon); // Circular clip from/to the FAB size final Animator circularReveal; if (fromFab) { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, startBounds.width() / 2, (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2)); circularReveal.setInterpolator(new FastOutLinearInInterpolator()); } else { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2), endBounds.width() / 2); circularReveal.setInterpolator(new LinearOutSlowInInterpolator()); // Persist the end clip i.e. stay at FAB size after the reveal has run circularReveal.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { view.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { final int left = (view.getWidth() - fabBounds.width()) / 2; final int top = (view.getHeight() - fabBounds.height()) / 2; outline.setOval(left, top, left + fabBounds.width(), top + fabBounds.height()); view.setClipToOutline(true); } }); } }); } circularReveal.setDuration(duration); // Translate to end position along an arc final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y, fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0) : getPathMotion().getPath(0, 0, -translationX, -translationY)); translate.setDuration(duration); translate.setInterpolator(fastOutSlowInInterpolator); // Fade contents of non-FAB view in/out List<Animator> fadeContents = null; if (view instanceof ViewGroup) { final ViewGroup vg = ((ViewGroup) view); fadeContents = new ArrayList<>(vg.getChildCount()); for (int i = vg.getChildCount() - 1; i >= 0; i--) { final View child = vg.getChildAt(i); final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f); if (fromFab) { child.setAlpha(0f); } fade.setDuration(twoThirdsDuration); fade.setInterpolator(fastOutSlowInInterpolator); fadeContents.add(fade); } } // Fade in/out the fab color & icon overlays final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255); final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255); if (!fromFab) { colorFade.setStartDelay(halfDuration); iconFade.setStartDelay(halfDuration); } colorFade.setDuration(halfDuration); iconFade.setDuration(halfDuration); colorFade.setInterpolator(fastOutSlowInInterpolator); iconFade.setInterpolator(fastOutSlowInInterpolator); // Work around issue with elevation shadows. At the end of the return transition the shared // element's shadow is drawn twice (by each activity) which is jarring. This workaround // still causes the shadow to snap, but it's better than seeing it double drawn. Animator elevation = null; if (!fromFab) { elevation = ObjectAnimator.ofFloat(view, View.TRANSLATION_Z, -view.getElevation()); elevation.setDuration(duration); elevation.setInterpolator(fastOutSlowInInterpolator); } // Run all animations together final AnimatorSet transition = new AnimatorSet(); transition.playTogether(circularReveal, translate, colorFade, iconFade); transition.playTogether(fadeContents); if (elevation != null) transition.play(elevation); if (fromFab) { transition.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { // Clean up view.getOverlay().clear(); } }); } return new AnimUtils.NoPauseAnimator(transition); }
From source file:de.dreier.mytargets.utils.transitions.FabTransform.java
@Override public Animator createAnimator(@NonNull final ViewGroup sceneRoot, final TransitionValues startValues, final TransitionValues endValues) { if (startValues == null || endValues == null) { return null; }//from www .j a va2s . co m final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS); final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS); final boolean fromFab = endBounds.width() > startBounds.width(); final View view = endValues.view; final Rect dialogBounds = fromFab ? endBounds : startBounds; final Rect fabBounds = fromFab ? startBounds : endBounds; final Interpolator fastOutSlowInInterpolator = new FastOutSlowInInterpolator(); final long duration = getDuration(); final long halfDuration = duration / 2; final long twoThirdsDuration = duration * 2 / 3; if (!fromFab) { // Force measure / layout the dialog back to it's original bounds view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY), makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY)); view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom); } final int translationX = startBounds.centerX() - endBounds.centerX(); final int translationY = startBounds.centerY() - endBounds.centerY(); if (fromFab) { view.setTranslationX(translationX); view.setTranslationY(translationY); } // Add a color overlay to fake appearance of the FAB final ColorDrawable fabColor = new ColorDrawable(color); fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height()); if (!fromFab) { fabColor.setAlpha(0); } view.getOverlay().add(fabColor); // Add an icon overlay again to fake the appearance of the FAB final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate(); final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2; final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2; fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(), iconTop + fabIcon.getIntrinsicHeight()); if (!fromFab) { fabIcon.setAlpha(0); } view.getOverlay().add(fabIcon); // Circular clip from/to the FAB size final Animator circularReveal; if (fromFab) { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, startBounds.width() / 2, (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2)); circularReveal.setInterpolator(new FastOutLinearInInterpolator()); } else { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2), endBounds.width() / 2); circularReveal.setInterpolator(new LinearOutSlowInInterpolator()); // Persist the end clip i.e. stay at FAB size after the reveal has run circularReveal.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { view.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { final int left = (view.getWidth() - fabBounds.width()) / 2; final int top = (view.getHeight() - fabBounds.height()) / 2; outline.setOval(left, top, left + fabBounds.width(), top + fabBounds.height()); view.setClipToOutline(true); } }); } }); } circularReveal.setDuration(duration); // Translate to end position along an arc final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y, fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0) : getPathMotion().getPath(0, 0, -translationX, -translationY)); translate.setDuration(duration); translate.setInterpolator(fastOutSlowInInterpolator); // Fade contents of non-FAB view in/out List<Animator> fadeContents = null; if (view instanceof ViewGroup) { final ViewGroup vg = ((ViewGroup) view); fadeContents = new ArrayList<>(vg.getChildCount()); for (int i = vg.getChildCount() - 1; i >= 0; i--) { final View child = vg.getChildAt(i); final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f); if (fromFab) { child.setAlpha(0f); } fade.setDuration(twoThirdsDuration); fade.setInterpolator(fastOutSlowInInterpolator); fadeContents.add(fade); } } // Fade in/out the fab color & icon overlays final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255); final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255); if (!fromFab) { colorFade.setStartDelay(halfDuration); iconFade.setStartDelay(halfDuration); } colorFade.setDuration(halfDuration); iconFade.setDuration(halfDuration); colorFade.setInterpolator(fastOutSlowInInterpolator); iconFade.setInterpolator(fastOutSlowInInterpolator); // Work around issue with elevation shadows. At the end of the return transition the shared // element's shadow is drawn twice (by each activity) which is jarring. This workaround // still causes the shadow to snap, but it's better than seeing it double drawn. Animator elevation = null; if (!fromFab) { elevation = ObjectAnimator.ofFloat(view, View.TRANSLATION_Z, -view.getElevation()); elevation.setDuration(duration); elevation.setInterpolator(fastOutSlowInInterpolator); } // Run all animations together final AnimatorSet transition = new AnimatorSet(); transition.playTogether(circularReveal, translate, colorFade, iconFade); transition.playTogether(fadeContents); if (elevation != null) { transition.play(elevation); } if (fromFab) { transition.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { // Clean up view.getOverlay().clear(); } }); } return new NoPauseAnimator(transition); }
From source file:com.umeng.comm.ui.fragments.BaseFeedsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); mRootView = inflater.inflate(ResFinder.getLayout("umeng_comm_feeds_frgm_layout"), container, false); mInputMan = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); // ?//from w w w . j a v a 2s.c o m initViews(); // ?ActionButtonlike?????Dialog View initWidgets(); // ?Feed Adapter initAdapter(); // registerBroadcast(); // cache?? loadFeedsFromDB(); // ? mRefreshLayout.setRefreshing(true); // server?? fetchFeeds(); mSlop = ViewConfiguration.get(container.getContext()).getScaledTouchSlop(); return mRootView; }
From source file:com.android.systemui.qs.QSDragPanel.java
@Override protected void setupViews() { updateResources();//from w w w .j ava 2 s . c om mDetail = LayoutInflater.from(mContext).inflate(R.layout.qs_detail, this, false); mDetailButtons = (ViewGroup) mDetail.findViewById(R.id.buttons); mDetailContent = (ViewGroup) mDetail.findViewById(android.R.id.content); mDetailRemoveButton = (TextView) mDetail.findViewById(android.R.id.button3); mDetailSettingsButton = (TextView) mDetail.findViewById(android.R.id.button2); mDetailDoneButton = (TextView) mDetail.findViewById(android.R.id.button1); updateDetailText(); mDetail.setVisibility(GONE); mDetail.setClickable(true); mQsPanelTop = (QSPanelTopView) LayoutInflater.from(mContext).inflate(R.layout.qs_tile_top, this, false); mBrightnessView = mQsPanelTop.getBrightnessView(); mFooter = new QSFooter(this, mContext); // add target click listener mQsPanelTop.getAddTarget().setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { TilesListAdapter adapter = new TilesListAdapter(mContext, QSDragPanel.this); showDetailAdapter(true, adapter, v.getLocationOnScreen()); mDetail.bringToFront(); } }); mViewPager = new QSViewPager(getContext()); mViewPager.setDragPanel(this); mPageIndicator = new CirclePageIndicator(getContext()); addView(mDetail); addView(mQsPanelTop); addView(mViewPager); addView(mPageIndicator); addView(mFooter.getView()); mClipper = new QSDetailClipper(mDetail); mBrightnessController = new BrightnessController(getContext(), (ImageView) mQsPanelTop.getBrightnessView().findViewById(R.id.brightness_icon), (ToggleSlider) mQsPanelTop.getBrightnessView().findViewById(R.id.brightness_slider)); mDetailDoneButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { announceForAccessibility(mContext.getString(R.string.accessibility_desc_quick_settings)); closeDetail(); } }); mPagerAdapter = new PagerAdapter() { @Override public Object instantiateItem(ViewGroup container, int position) { if (DEBUG_TILES) { Log.d(TAG, "instantiateItem() called with " + "container = [" + container + "], position = [" + position + "]"); } if (mEditing && position == 0) { QSSettings qss = (QSSettings) View.inflate(container.getContext(), R.layout.qs_settings, null); qss.setHost(mHost); container.addView(qss, 0); return qss; } else { final int adjustedPosition = mEditing ? position - 1 : position; QSPage page = mPages.get(adjustedPosition); if (!page.isAttachedToWindow()) { container.addView(page); } return page; } } @Override public void destroyItem(ViewGroup container, int position, Object object) { if (DEBUG_TILES) { Log.d(TAG, "destroyItem() called with " + "container = [" + container + "], position = [" + position + "], object = [" + object + "]"); } if (object instanceof View) { container.removeView((View) object); } } @Override public int getItemPosition(Object object) { if (object instanceof QSPage) { if (mEditing != ((QSPage) object).getAdapterEditingState()) { // position of item changes when we set change the editing mode, // sync it and send the new position ((QSPage) object).setAdapterEditingState(mEditing); // calculate new position int indexOf = ((QSPage) object).getPageIndex(); if (mEditing) return indexOf + 1; else return indexOf; } else if (!mPages.contains(object) && !mDragging) { // only return none if we aren't dragging (object may be removed from // the records array temporarily and we might think we have less pages, // we don't want to prematurely remove this page return POSITION_NONE; } else { return POSITION_UNCHANGED; } } else if (object instanceof QSSettings) { if (((QSSettings) object).getAdapterEditingState() != mEditing) { ((QSSettings) object).setAdapterEditingState(mEditing); if (mEditing) return 0 /* locked at position 0 */; else return POSITION_NONE; } else { return POSITION_UNCHANGED; } } return super.getItemPosition(object); } @Override public int getCount() { final int qsPages = Math.max(getCurrentMaxPageCount(), 1); if (mPages != null && qsPages > mPages.size()) { for (int i = mPages.size(); i < qsPages; i++) { mPages.add(i, new QSPage(mViewPager.getContext(), QSDragPanel.this, i)); } } if (mEditing) return qsPages + 1; return qsPages; } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } }; mViewPager.setAdapter(mPagerAdapter); mPageIndicator.setViewPager(mViewPager); mPageIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (DEBUG_DRAG) { Log.i(TAG, "onPageScrolled() called with " + "position = [" + position + "], positionOffset = [" + positionOffset + "], positionOffsetPixels = [" + positionOffsetPixels + "]"); } if (mEditing) { float targetTranslationX = 0; // targetTranslationX = where it's supposed to be - diff int homeLocation = mViewPager.getMeasuredWidth(); // how far away from homeLocation is the scroll? if (positionOffsetPixels < homeLocation && position == 0) { targetTranslationX = homeLocation - positionOffsetPixels; } mQsPanelTop.setTranslationX(targetTranslationX); } } @Override public void onPageSelected(int position) { if (mDragging && position != mDraggingRecord.page && !mViewPager.isFakeDragging() && !mRestoring) { if (DEBUG_DRAG) { Log.w(TAG, "moving drag record to page: " + position); } // remove it from the previous page and add it here final QSPage sourceP = getPage(mDraggingRecord.page); final QSPage targetP = getPage(position); sourceP.removeView(mDraggingRecord.tileView); mDraggingRecord.page = position; targetP.addView(mDraggingRecord.tileView); // set coords off screen until we're ready to place it mDraggingRecord.tileView.setX(-mDraggingRecord.tileView.getMeasuredWidth()); mDraggingRecord.tileView.setY(-mDraggingRecord.tileView.getMeasuredHeight()); } } @Override public void onPageScrollStateChanged(int state) { } }); mViewPager.setOverScrollMode(OVER_SCROLL_NEVER); setClipChildren(false); mSettingsObserver = new SettingsObserver(new Handler()); mViewPager.setOnDragListener(QSDragPanel.this); mQsPanelTop.setOnDragListener(QSDragPanel.this); mPageIndicator.setOnDragListener(QSDragPanel.this); setOnDragListener(QSDragPanel.this); mViewPager.setOverScrollMode(View.OVER_SCROLL_NEVER); }
From source file:net.openwatch.acluaz.fragment.FormFragment.java
public JSONObject toJson(ViewGroup container, JSONObject json) { String TAG = "FormFragment-ToJSON"; if (container == null) { Log.e(TAG, "null container passed to toJson"); return new JSONObject(); }/* ww w. j a va2 s. c o m*/ if (json == null) json = new JSONObject(); View view; for (int x = 0; x < container.getChildCount(); x++) { view = container.getChildAt(x); if (EditText.class.isInstance(view)) { if (view.getTag() != null) { if (((EditText) view).getText().toString().compareTo("") == 0) continue; // skip blank input try { Log.i(TAG, "Mapping: " + view.getTag().toString() + " value: " + ((EditText) view).getText().toString()); if (view.getTag().toString().compareTo(getString(R.string.zipcode_tag)) == 0) json.put(view.getTag().toString(), Integer.parseInt(((EditText) view).getText().toString())); else json.put(view.getTag().toString(), ((EditText) view).getText().toString()); } catch (JSONException e) { Log.e(TAG, "Error jsonifying text input"); e.printStackTrace(); } } } else if (CompoundButton.class.isAssignableFrom(view.getClass())) { if (view.getTag() != null) { // if location toggle, bundle location if (((String) view.getTag()).compareTo(getString(R.string.device_location_tag)) == 0 && view.getTag(R.id.view_tag) != null) { if (((CompoundButton) view).isChecked()) { try { json.put(getString(R.string.device_lat), ((Location) view.getTag(R.id.view_tag)).getLatitude()); json.put(getString(R.string.device_lon), ((Location) view.getTag(R.id.view_tag)).getLongitude()); } catch (JSONException e) { Log.e(TAG, "Error jsonifying toggle input"); e.printStackTrace(); } } } else if (((String) view.getTag()).compareTo(getString(R.string.device_location_tag)) == 0 && view.getTag(R.id.view_tag) == null) { // no location tagged, get last known LocationManager lm = (LocationManager) container.getContext() .getSystemService(Context.LOCATION_SERVICE); Location last = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); try { json.put(getString(R.string.device_lat), last.getLatitude()); json.put(getString(R.string.device_lon), last.getLongitude()); } catch (JSONException e) { Log.e(TAG, "Error jsonifying last location"); e.printStackTrace(); } catch (NullPointerException e2) { Log.e(TAG, "No current or historical location info on this device"); } } } } // combine date and time fields into a single datetime if (json.has(getString(R.string.date_tag)) && json.has(getString(R.string.time_tag))) { Log.i(TAG, "found date and time tag, let's smush 'em"); try { //TESTING //String datetime = combineDateAndTime(json.getString(getString(R.string.date_tag)), json.getString(getString(R.string.time_tag))); //Log.i(TAG,"datetime: " + datetime); json.put(getString(R.string.date_tag), combineDateAndTime(json.getString(getString(R.string.date_tag)), json.getString(getString(R.string.time_tag)))); Log.i(TAG, json.toString()); //json.remove(getString(R.string.date_tag)); json.remove(getString(R.string.time_tag)); } catch (JSONException e) { Log.e(TAG, "Error creating json datetime field from date and time"); e.printStackTrace(); } } } Log.i(TAG, "toJson: " + json.toString()); return json; }
From source file:com.popdeem.sdk.uikit.fragment.PDUIWalletFragment.java
@Nullable @Override/*from www .j av a 2 s. c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (mView == null) { mView = inflater.inflate(R.layout.fragment_pd_wallet, container, false); mNoItemsInWalletView = mView.findViewById(R.id.pd_wallet_no_items_view); mNoItemsInWalletView.setVisibility(View.GONE); mSwipeRefreshLayout = (PDUISwipeRefreshLayout) mView; mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refreshWallet(); } }); final RecyclerView recyclerView = (RecyclerView) mView.findViewById(R.id.pd_wallet_recycler_view); mAdapter = new PDUIWalletRecyclerViewAdapter(mRewards); mAdapter.setOnItemClickListener(new PDUIWalletRecyclerViewAdapter.OnItemClickListener() { @Override public void onItemClick(View v) { final int position = recyclerView.getChildAdapterPosition(v) - 1; if (mRewards.get(position) instanceof PDReward) { final PDReward reward = (PDReward) mRewards.get(position); if (reward.claimedUsingNetwork(PDReward.PD_SOCIAL_MEDIA_TYPE_INSTAGRAM) && !reward.isInstagramVerified()) { return; } if (reward.getCredit() != null && reward.getCredit().length() > 0) { return; } AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(getActivity(), R.style.AlertDialogCustom)); if (reward.getRewardType().equalsIgnoreCase(PDReward.PD_REWARD_TYPE_SWEEPSTAKE)) { String message = String.format(Locale.getDefault(), "%1s", getString(R.string.pd_redeem_sweepstake_reward_info_message_string)); builder.setTitle(R.string.pd_redeem_sweepstake_reward_info_title_string) .setMessage(message).setPositiveButton(android.R.string.ok, null); builder.create().show(); } else if (!reward.getRewardType().equalsIgnoreCase(PDReward.PD_REWARD_TYPE_CREDIT)) { String message = getString(R.string.pd_wallet_coupon_info_message_text); builder.setTitle(R.string.pd_redeem_reward_info_title_string).setMessage(message) .setNegativeButton(android.R.string.cancel, null) .setPositiveButton(R.string.pd_redeem_button_string, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { redeemReward(reward, position); Intent intent = new Intent(getActivity(), PDUIRedeemActivity.class); intent.putExtra("imageUrl", reward.getCoverImage()); intent.putExtra("reward", reward.getDescription()); intent.putExtra("rules", reward.getRules()); intent.putExtra("isSweepstakes", reward.getRewardType() .equalsIgnoreCase(PDReward.PD_REWARD_TYPE_SWEEPSTAKE)); intent.putExtra("time", reward.getAvailableUntilInSeconds()); intent.putExtra("countdown", reward.getCountdownTimer()); startActivity(intent); } }); builder.create().show(); } } } @Override public void onVerifyClick(int position) { PDReward reward = (PDReward) mRewards.get(position); reward.setVerifying(true); // mAdapter.notifyItemChanged(position); mAdapter.notifyDataSetChanged(); verifyReward(position); } }); // LinearLayoutManager linearLayoutManager = new LinearLayoutManager(container.getContext()); PDUILinearLayoutManager linearLayoutManager = new PDUILinearLayoutManager(container.getContext()); mSwipeRefreshLayout.addLinearLayoutManager(linearLayoutManager); recyclerView.setLayoutManager(linearLayoutManager); // recyclerView.addItemDecoration(new PDUIDividerItemDecoration(getActivity(), R.color.pd_wallet_list_divider_color, false)); recyclerView.setAdapter(mAdapter); // refreshWallet(); } else { container.removeView(mView); } return mView; }