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.ant.sunshine.app.ForecastAdapter.java

@Override
public ForecastAdapterViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    if (viewGroup instanceof RecyclerView) {
        int layoutId = -1;
        switch (viewType) {
        case VIEW_TYPE_TODAY: {
            layoutId = R.layout.list_item_forecast_today;
            break;
        }//w ww .  java 2s  . co m
        case VIEW_TYPE_FUTURE_DAY: {
            layoutId = R.layout.list_item_forecast;
            break;
        }
        }
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(layoutId, viewGroup, false);
        view.setFocusable(true);
        return new ForecastAdapterViewHolder(view);
    } else {
        throw new RuntimeException("Not bound to RecyclerView");
    }
}

From source file:com.android.inputmethod.keyboard.emoji.EmojiPalettesAdapter.java

@Override
public Object instantiateItem(final ViewGroup container, final int position) {
    if (DEBUG_PAGER) {
        Log.d(TAG, "instantiate item: " + position);
    }//from   w w w.ja  va2s  .c o m
    final EmojiPageKeyboardView oldKeyboardView = mActiveKeyboardViews.get(position);
    if (oldKeyboardView != null) {
        oldKeyboardView.deallocateMemory();
        // This may be redundant but wanted to be safer..
        mActiveKeyboardViews.remove(position);
    }
    final Keyboard keyboard = mEmojiCategory.getKeyboardFromPagePosition(position);
    final LayoutInflater inflater = LayoutInflater.from(container.getContext());
    final EmojiPageKeyboardView keyboardView = (EmojiPageKeyboardView) inflater
            .inflate(R.layout.emoji_keyboard_page, container, false /* attachToRoot */);
    keyboardView.setKeyboard(keyboard);
    keyboardView.setOnKeyEventListener(mListener);
    container.addView(keyboardView);
    mActiveKeyboardViews.put(position, keyboardView);
    return keyboardView;
}

From source file:at.alladin.rmbt.android.views.ResultGraphView.java

/**
 * //  w  w  w.  j  a  v  a 2 s  . co m
 * @param inflater
 * @return
 */
public View createView(ViewGroup vg) {
    final LayoutInflater inflater = (LayoutInflater) vg.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    try {
        //view = inflater.inflate(R.layout.result_graph, vg, false);
        view = inflater.inflate(R.layout.result_graph, this);

        signalGraph = (CustomizableGraphView) view.findViewById(R.id.graph_signal);
        ulGraph = (CustomizableGraphView) view.findViewById(R.id.graph_upload);
        ulGraph.setShowLog10Lines(false);
        dlGraph = (CustomizableGraphView) view.findViewById(R.id.graph_download);
        dlGraph.setShowLog10Lines(false);

        signalProgress = (ProgressBar) view.findViewById(R.id.signal_progress);
        ulProgress = (ProgressBar) view.findViewById(R.id.upload_progress);
        dlProgress = (ProgressBar) view.findViewById(R.id.download_progress);

    } catch (Exception e) {
        e.printStackTrace();
    }

    return view;
}

From source file:com.pentacog.mctracker.ServerListAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    RelativeLayout serverView = null;/* w  w w. ja va 2  s  . c  o  m*/
    ServerViewHolder holder = null;
    Server server = serverList.get(position);
    server.id = position;
    if (convertView == null) {
        serverView = (RelativeLayout) LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item,
                parent, false);
        holder = new ServerViewHolder((int) getItemId(position), serverView);
        serverView.setTag(holder);
    } else {
        serverView = (RelativeLayout) convertView;
        holder = (ServerViewHolder) serverView.getTag();
        holder.id = (int) getItemId(position);
    }

    //set server name
    holder.serverTitle.setText(server.name);
    //set server IP
    String serverName = server.address.toString();
    if (!serverName.startsWith("/")) {
        int index = serverName.lastIndexOf('/');
        if (index != -1) {
            String tempString;
            tempString = serverName.substring(index + 1);
            serverName = serverName.substring(0, index);
            serverName += " " + tempString;
        }
    } else {
        serverName = serverName.replace("/", "");
    }
    if (server.port != 25565)
        serverName += ":" + server.port;
    holder.serverIp.setText(serverName);

    //set fav icon
    if (server.favorite) {
        holder.favStar.setVisibility(View.VISIBLE);
    } else {
        holder.favStar.setVisibility(View.INVISIBLE);
    }

    if (!server.queried) {
        AlphaAnimation a = new AlphaAnimation(1.0f, 0.2f);
        a.setRepeatCount(Animation.INFINITE);
        a.setRepeatMode(Animation.REVERSE);
        a.setDuration(300);
        holder.statusBar.setBackgroundColor(Color.BLUE);
        holder.statusBar.startAnimation(a);

        //         holder.loading.setVisibility(View.VISIBLE);
        holder.playerCount.setText("" + server.playerCount + "/" + server.maxPlayers);
        holder.serverData.setText(R.string.loading);
        holder.playerCount.setVisibility(View.INVISIBLE);
        holder.ping.setVisibility(View.INVISIBLE);
        new ServerViewUpdater(serverView, server);
    } else {
        setupServerCell(server, holder);
    }

    return serverView;
}

From source file:com.sbhstimetable.sbhs_timetable_android.NoticesFragment.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    if (!ApiAccessor.isLoggedIn()) {
        View v = inflater.inflate(R.layout.fragment_pls2login, container, false);
        TextView t = (TextView) v.findViewById(R.id.textview);
        t.setOnClickListener(new View.OnClickListener() {
            @Override/*from  ww w . ja  va 2  s .co  m*/
            public void onClick(View view) {
                Intent i = new Intent(container.getContext(), LoginActivity.class);
                container.getContext().startActivity(i);
            }
        });
        return v;
    }
    final SwipeRefreshLayout res = (SwipeRefreshLayout) inflater.inflate(R.layout.fragment_notices, container,
            false);
    this.layout = res;
    final ListView v = (ListView) res.findViewById(R.id.notices_listview);
    v.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {
        }

        @Override
        public void onScroll(AbsListView absListView, int i, int i2, int i3) {
            int topRowVerticalPosition = (v == null || v.getChildCount() == 0) ? 0 : v.getChildAt(0).getTop();
            res.setEnabled(topRowVerticalPosition >= 0);
        }
    });
    final Context c = this.getActivity();
    res.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refreshing = true;
            ApiAccessor.getBelltimes(c, false);
            ApiAccessor.getNotices(c, false);
            ApiAccessor.getToday(c, false);
        }
    });
    if (ThemeHelper.isBackgroundDark()) {
        res.setProgressBackgroundColor(R.color.background_floating_material_dark);
    } else {
        res.setProgressBackgroundColor(R.color.background_floating_material_light);
    }
    res.setColorSchemeColors(getResources().getColor(R.color.blue), getResources().getColor(R.color.green),
            getResources().getColor(R.color.yellow), getResources().getColor(R.color.red));
    JsonObject o = StorageCache.getNotices(getActivity(), DateTimeHelper.getDateString(getActivity()));
    NoticesJson n = NoticesJson.getInstance();
    if (o != null) {
        n = new NoticesJson(o);
    }

    if (n != null) {
        NoticesAdapter a = new NoticesAdapter(n);
        this.adapter = a;
        v.setAdapter(a);
    }

    return res;
}

From source file:com.sbhstimetable.sbhs_timetable_android.TimetableFragment.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    if (!ApiAccessor.isLoggedIn()) {
        View v = inflater.inflate(R.layout.fragment_pls2login, container, false);
        TextView t = (TextView) v.findViewById(R.id.textview);
        t.setOnClickListener(new View.OnClickListener() {
            @Override/* www .  j  a v a2 s.co m*/
            public void onClick(View view) {
                Intent i = new Intent(container.getContext(), LoginActivity.class);
                container.getContext().startActivity(i);
            }
        });
        return v;
    }
    final SwipeRefreshLayout v = (SwipeRefreshLayout) inflater.inflate(R.layout.fragment_timetable, container,
            false);
    this.layout = v;

    final Context c = this.getActivity();
    v.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refreshing = true;
            ApiAccessor.getBelltimes(c, false);
            ApiAccessor.getNotices(c, false);
            ApiAccessor.getToday(c, false);
        }
    });
    if (ThemeHelper.isBackgroundDark()) {
        v.setProgressBackgroundColor(R.color.background_floating_material_dark);
    } else {
        v.setProgressBackgroundColor(R.color.background_floating_material_light);
    }
    v.setColorSchemeColors(getResources().getColor(R.color.blue), getResources().getColor(R.color.green),
            getResources().getColor(R.color.yellow), getResources().getColor(R.color.red));

    ListView z = (ListView) this.getActivity().findViewById(R.id.timetable_listview);
    if (z != null) {
        ApiAccessor.getToday(this.getActivity());
    }
    return v;
}

From source file:com.android.launcher3.allapps.AllAppsGridAdapter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    switch (viewType) {
    case SECTION_BREAK_VIEW_TYPE:
        return new ViewHolder(new View(parent.getContext()));
    case ICON_VIEW_TYPE: {
        BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate(R.layout.all_apps_icon, parent, false);
        icon.setOnTouchListener(mTouchListener);
        icon.setOnClickListener(mIconClickListener);
        icon.setOnLongClickListener(mIconLongClickListener);
        icon.setLongPressTimeout(ViewConfiguration.get(parent.getContext()).getLongPressTimeout());
        icon.setFocusable(true);//w w w  .j  a va 2  s  .  c  o m
        return new ViewHolder(icon);
    }
    case PREDICTION_ICON_VIEW_TYPE: {
        BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate(R.layout.all_apps_prediction_bar_icon,
                parent, false);
        icon.setOnTouchListener(mTouchListener);
        icon.setOnClickListener(mIconClickListener);
        icon.setOnLongClickListener(mIconLongClickListener);
        icon.setLongPressTimeout(ViewConfiguration.get(parent.getContext()).getLongPressTimeout());
        icon.setFocusable(true);
        return new ViewHolder(icon);
    }
    case EMPTY_SEARCH_VIEW_TYPE:
        return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_empty_search, parent, false));
    case SEARCH_MARKET_DIVIDER_VIEW_TYPE:
        return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_search_market_divider, parent, false));
    case SEARCH_MARKET_VIEW_TYPE:
        View searchMarketView = mLayoutInflater.inflate(R.layout.all_apps_search_market, parent, false);
        searchMarketView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLauncher.startActivitySafely(v, mMarketSearchIntent, null);
            }
        });
        return new ViewHolder(searchMarketView);
    default:
        throw new RuntimeException("Unexpected view type");
    }
}

From source file:com.lloydtorres.stately.nation.NationCardsRecyclerAdapter.java

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

    switch (viewType) {
    case CARD_OVERVIEW:
        View overviewCard = inflater.inflate(R.layout.card_nation_overview, parent, false);
        viewHolder = new NationOverviewCard(overviewCard);
        break;//from   ww w.  j  a v  a 2 s . c  o m
    case CARD_FREEDOMS:
        View freedomCard = inflater.inflate(R.layout.card_nation_freedom, parent, false);
        viewHolder = new NationFreedomCard(freedomCard);
        break;
    case CARD_GENERIC:
        View genericCard = inflater.inflate(R.layout.card_nation_generic, parent, false);
        viewHolder = new NationGenericCard(genericCard);
        break;
    case CARD_CHART:
        View chartCard = inflater.inflate(R.layout.card_nation_chart, parent, false);
        viewHolder = new NationChartCard(chartCard);
        break;
    }

    return viewHolder;
}

From source file:com.example.demo_dv_fuse.DetailsTab.java

/**
 * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup,
 *      android.os.Bundle)//from w  w  w . j a v a 2  s .  c om
 */
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.details_tab, container, false);

    final String[] choices = { getString(R.string.viewAirportMaps), getString(R.string.viewGoogleMap) };
    final ListView listView = (ListView) view.findViewById(R.id.detailsList);

    final View headerView = inflater.inflate(R.layout.details_list_header, null);
    listView.addHeaderView(headerView, null, false);

    listView.setAdapter(new ArrayAdapter<String>(container.getContext(), R.layout.details_row,
            R.id.details_list_map_row_title, choices));
    listView.setClickable(true);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        /**
         * @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget.AdapterView,
         *      android.view.View, int, long)
         */
        @Override
        public void onItemClick(final AdapterView<?> adapterView, final View parent, final int position,
                final long id) {
            if (position == AIRPORT_MAPS_INDEX) {
                handleViewAirportMapsSelected();
            } else if (position == GOOGLE_MAPS_INDEX) {
                handleViewGoogleMap();
            }
        }
    });

    // departure widgets
    this.departureAirlines = (TextView) view.findViewById(R.id.departure_airlines);
    this.departureAirportCode = (TextView) view.findViewById(R.id.departure_airport_code);
    this.departureFlightNumber = (TextView) view.findViewById(R.id.departure_flight_number);
    this.departureIata = (TextView) view.findViewById(R.id.departure_iata);
    this.departureStatus = (TextView) view.findViewById(R.id.departure_status);
    this.departureTime = (TextView) view.findViewById(R.id.departure_time);

    // arrival widgets
    this.arrivalAirportCode = (TextView) view.findViewById(R.id.arrival_airport_code);
    this.arrivalGate = (TextView) view.findViewById(R.id.arrival_gate);
    this.arrivalTerminal = (TextView) view.findViewById(R.id.arrival_terminal);
    this.arrivalTime = (TextView) view.findViewById(R.id.arrival_time);

    return view;
}

From source file:com.h6ah4i.android.example.advrecyclerview.demo_eds.ExpandableDraggableSwipeableExampleAdapter.java

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