Example usage for android.view ViewGroup getContext

List of usage examples for android.view ViewGroup getContext

Introduction

In this page you can find the example usage for android.view ViewGroup getContext.

Prototype

@ViewDebug.CapturedViewProperty
public final Context getContext() 

Source Link

Document

Returns the context the view is running in, through which it can access the current theme, resources, etc.

Usage

From source file:com.lloydtorres.stately.wa.ResolutionRecyclerAdapter.java

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    RecyclerView.ViewHolder viewHolder = null;
    LayoutInflater inflater = LayoutInflater.from(parent.getContext());

    switch (viewType) {
    case CARD_HEADER:
        View headerCard = inflater.inflate(R.layout.card_wa_resolution_header, parent, false);
        viewHolder = new ResolutionHeaderCard(headerCard);
        break;//w  ww . j  av a 2 s.com
    case CARD_CONTENT:
        View contentCard = inflater.inflate(R.layout.card_wa_resolution_content, parent, false);
        viewHolder = new ResolutionContentCard(contentCard);
        break;
    case CARD_BREAKDOWN:
        View breakdownCard = inflater.inflate(R.layout.card_wa_resolution_breakdown, parent, false);
        viewHolder = new ResolutionBreakdownCard(breakdownCard);
        break;
    case CARD_HISTORY:
        View historyCard = inflater.inflate(R.layout.card_wa_resolution_history, parent, false);
        viewHolder = new ResolutionHistoryCard(historyCard);
        break;
    }

    return viewHolder;
}

From source file:com.caij.codehub.ui.transitions.MorphFabToDialog.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override/*  w w  w  .j a  v  a  2  s . c o  m*/
public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues,
        final TransitionValues endValues) {
    Animator changeBounds = super.createAnimator(sceneRoot, startValues, endValues);
    if (startValues == null || endValues == null || changeBounds == null) {
        return null;
    }

    Integer startColor = (Integer) startValues.values.get(PROPERTY_COLOR);
    Integer startCornerRadius = (Integer) startValues.values.get(PROPERTY_CORNER_RADIUS);
    Integer endColor = (Integer) endValues.values.get(PROPERTY_COLOR);
    Integer endCornerRadius = (Integer) endValues.values.get(PROPERTY_CORNER_RADIUS);

    if (startColor == null || startCornerRadius == null || endColor == null || endCornerRadius == null) {
        return null;
    }

    MorphDrawable background = new MorphDrawable(startColor, startCornerRadius);
    endValues.view.setBackground(background);

    Animator color = ObjectAnimator.ofArgb(background, background.COLOR, endColor);
    Animator corners = ObjectAnimator.ofFloat(background, background.CORNER_RADIUS, endCornerRadius);

    // ease in the dialog's child views (slide up & fade in)
    if (endValues.view instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) endValues.view;
        float offset = vg.getHeight() / 3;
        for (int i = 0; i < vg.getChildCount(); i++) {
            View v = vg.getChildAt(i);
            v.setTranslationY(offset);
            v.setAlpha(0f);
            v.animate().alpha(1f).translationY(0f).setDuration(150).setStartDelay(150).setInterpolator(
                    AnimationUtils.loadInterpolator(vg.getContext(), android.R.interpolator.fast_out_slow_in));
            offset *= 1.8f;
        }
    }

    AnimatorSet transition = new AnimatorSet();
    transition.playTogether(changeBounds, corners, color);
    transition.setDuration(300);
    transition.setInterpolator(
            AnimationUtils.loadInterpolator(sceneRoot.getContext(), android.R.interpolator.fast_out_slow_in));
    return transition;
}

From source file:com.ryan.ryanreader.fragments.MainMenuFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {

    // TODO load menu position?

    final Context context;

    // /*from  ww w. j a  v a  2 s  .  c o  m*/
    if (container != null) {
        context = container.getContext(); // TODO just use the inflater's
        // context in every case?
    } else {
        context = inflater.getContext();
    }

    // 
    final RedditAccount user = RedditAccountManager.getInstance(context).getDefaultAccount();

    final LinearLayout outer = new LinearLayout(context);

    // 
    outer.setOrientation(LinearLayout.VERTICAL);

    notifications = new LinearLayout(context);
    notifications.setOrientation(LinearLayout.VERTICAL);

    loadingView = new LoadingView(context, R.string.download_waiting, true, true);

    final ListView lv = new ListView(context);
    lv.setDivider(null);

    // listview?
    lv.addFooterView(notifications);

    final int paddingPx = General.dpToPixels(context, 8);
    lv.setPadding(paddingPx, 0, paddingPx, 0);

    adapter = new MainMenuAdapter(context, user, this);
    lv.setAdapter(adapter);

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(final AdapterView<?> adapterView, final View view, final int position,
                final long id) {
            adapter.clickOn(position);
        }
    });

    final AtomicReference<APIResponseHandler.SubredditResponseHandler> accessibleSubredditResponseHandler = new AtomicReference<APIResponseHandler.SubredditResponseHandler>(
            null);

    final APIResponseHandler.SubredditResponseHandler responseHandler = new APIResponseHandler.SubredditResponseHandler(
            context) {

        @Override
        protected void onDownloadNecessary() {
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                public void run() {
                    notifications.addView(loadingView);
                }
            });
        }

        @Override
        protected void onDownloadStarted() {
            loadingView.setIndeterminate(R.string.download_subreddits);
        }

        @Override
        protected void onSuccess(final List<RedditSubreddit> result, final long timestamp) {

            if (result.size() == 0) {
                // Just get the defaults instead
                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    public void run() {
                        notifications.removeView(loadingView);
                        RedditAPI.getUserSubreddits(CacheManager.getInstance(context),
                                accessibleSubredditResponseHandler.get(), RedditAccountManager.getAnon(),
                                force ? CacheRequest.DownloadType.FORCE
                                        : CacheRequest.DownloadType.IF_NECESSARY,
                                force, context);
                    }
                });

            } else {

                adapter.setSubreddits(result);

                if (loadingView != null)
                    loadingView.setDone(R.string.download_done);
            }
        }

        @Override
        protected void onCallbackException(final Throwable t) {
            BugReportActivity.handleGlobalError(context, t);
        }

        @Override
        protected void onFailure(final RequestFailureType type, final Throwable t, final StatusLine status,
                final String readableMessage) {

            if (loadingView != null)
                loadingView.setDone(R.string.download_failed);
            final RRError error = General.getGeneralErrorForFailure(context, type, t, status);

            new Handler(Looper.getMainLooper()).post(new Runnable() {
                public void run() {
                    notifications.addView(new ErrorView(getSupportActivity(), error));
                }
            });
        }

        @Override
        protected void onFailure(final APIFailureType type) {

            if (loadingView != null)
                loadingView.setDone(R.string.download_failed);
            final RRError error = General.getGeneralErrorForFailure(context, type);

            new Handler(Looper.getMainLooper()).post(new Runnable() {
                public void run() {
                    notifications.addView(new ErrorView(getSupportActivity(), error));
                }
            });
        }
    };

    accessibleSubredditResponseHandler.set(responseHandler);

    RedditAPI.getUserSubreddits(CacheManager.getInstance(context), responseHandler, user,
            force ? CacheRequest.DownloadType.FORCE : CacheRequest.DownloadType.IF_NECESSARY, force, context);

    outer.addView(lv);
    lv.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;

    return outer;
}

From source file:com.brightcove.player.samples.offlineplayback.VideoListAdapter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.video_item_view, parent, false);

    return new ViewHolder(view);
}

From source file:com.josecalles.porridge.transitions.MorphFabToDialog.java

@Override
public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues,
        final TransitionValues endValues) {
    Animator changeBounds = super.createAnimator(sceneRoot, startValues, endValues);
    if (startValues == null || endValues == null || changeBounds == null) {
        return null;
    }//from   w w w .  ja  v a 2  s. c o  m

    Integer startColor = (Integer) startValues.values.get(PROPERTY_COLOR);
    Integer startCornerRadius = (Integer) startValues.values.get(PROPERTY_CORNER_RADIUS);
    Integer endColor = (Integer) endValues.values.get(PROPERTY_COLOR);
    Integer endCornerRadius = (Integer) endValues.values.get(PROPERTY_CORNER_RADIUS);

    if (startColor == null || startCornerRadius == null || endColor == null || endCornerRadius == null) {
        return null;
    }

    MorphDrawable background = new MorphDrawable(startColor, startCornerRadius);
    endValues.view.setBackground(background);

    Animator color = ObjectAnimator.ofArgb(background, background.COLOR, endColor);
    Animator corners = ObjectAnimator.ofFloat(background, background.CORNER_RADIUS, endCornerRadius);

    // ease in the dialog's child views (slide up & fade in)
    if (endValues.view instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) endValues.view;
        float offset = vg.getHeight() / 3;
        for (int i = 0; i < vg.getChildCount(); i++) {
            View v = vg.getChildAt(i);
            v.setTranslationY(offset);
            v.setAlpha(0f);
            v.animate().alpha(1f).translationY(0f).setDuration(150).setStartDelay(150).setInterpolator(
                    AnimationUtils.loadInterpolator(vg.getContext(), android.R.interpolator.fast_out_slow_in));
            offset *= 1.8f;
        }
    }

    AnimatorSet transition = new AnimatorSet();
    transition.playTogether(changeBounds, corners, color);
    transition.setDuration(300);
    transition.setInterpolator(
            AnimationUtils.loadInterpolator(sceneRoot.getContext(), android.R.interpolator.fast_out_slow_in));
    return transition;
}

From source file:de.aw.awlib.adapters.AWBaseAdapter.java

@Override
public AWLibViewHolder onCreateViewHolder(ViewGroup viewGroup, int itemType) {
    LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
    View rowView;/*from w  w  w . java2 s  .c  o m*/
    switch (itemType) {
    case UNDODELETEVIEW:
        rowView = inflater.inflate(R.layout.can_undo_view, viewGroup, false);
        break;
    case CHANGEDVIEW:
        rowView = inflater.inflate(mPendingChangeLayout, viewGroup, false);
        break;
    default:
        if (mViewHolderResIDs != null) {
            rowView = inflater.inflate(mViewHolderResIDs[itemType], viewGroup, false);
        } else
            rowView = mBinder.onCreateViewHolder(inflater, viewGroup, itemType);
    }
    AWLibViewHolder holder = createViewHolder(rowView);
    if (holder == null) {
        holder = new AWLibViewHolder(rowView);
    }
    holder.setOnClickListener(this);
    holder.setOnLongClickListener(this);
    return holder;
}

From source file:com.lastsoft.plog.adapter.PlayAdapter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    // Create a new view.
    View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.play_item, viewGroup, false);

    return new ViewHolder(v);
}

From source file:com.pacific.adapter.BasePagerAdapter2.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    H holder;/*from  w  w w .  j  a  v a  2  s.c om*/
    T item = get(position);
    View convertView = cacheViews.poll();
    if (convertView == null) {
        if (inflater == null) {
            inflater = LayoutInflater.from(container.getContext());
        }
        convertView = inflater.inflate(item.getLayout(), container, false);
        holder = createViewHolder(convertView);
        convertView.setTag(R.integer.adapter_holder, holder);
    } else {
        holder = (H) convertView.getTag(R.integer.adapter_holder);
    }
    holder.setCurrentPosition(position);
    holder.setSize(getCount());
    holder.setCurrentItem(item);
    item.bind(holder);
    container.addView(convertView);
    return convertView;
}

From source file:com.ameron32.apps.tapnotes._trial._demo.fragment.expandable.MyExpandableDraggableSwipeableItemAdapter.java

@Override
public MyGroupViewHolder onCreateGroupViewHolder(ViewGroup parent, int viewType) {
    final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    final View v = inflater.inflate(R.layout.arv_list_group_item, parent, false);
    return new MyGroupViewHolder(v);
}

From source file:com.ameron32.apps.tapnotes._trial._demo.fragment.expandable.MyExpandableDraggableSwipeableItemAdapter.java

@Override
public MyChildViewHolder onCreateChildViewHolder(ViewGroup parent, int viewType) {
    final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    final View v = inflater.inflate(R.layout.arv_list_item, parent, false);
    return new MyChildViewHolder(v);
}