List of usage examples for android.view ViewGroup getContext
@ViewDebug.CapturedViewProperty public final Context getContext()
From source file:com.qs.qswlw.view.Mypager.UltraViewPagerAdapter.java
@Override public Object instantiateItem(ViewGroup container, int position) { int realPosition = position; //TODO/*from ww w. j av a 2 s . c om*/ if (enableLoop && adapter.getCount() != 0) { realPosition = position % adapter.getCount(); } Object item = adapter.instantiateItem(container, realPosition); //TODO View childView = null; if (item instanceof View) childView = (View) item; // if (item instanceof RecyclerView.ViewHolder) // childView = ((RecyclerView.ViewHolder) item).itemView; ViewPager viewPager = (ViewPager) container; int childCount = viewPager.getChildCount(); for (int i = 0; i < childCount; i++) { View child = viewPager.getChildAt(i); if (isViewFromObject(child, item)) { viewArray.put(realPosition, child); break; } } if (isEnableMultiScr()) { if (scrWidth == 0) { scrWidth = container.getResources().getDisplayMetrics().widthPixels; } RelativeLayout relativeLayout = new RelativeLayout(container.getContext()); if (childView.getLayoutParams() != null) { RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( (int) (scrWidth * multiScrRatio), ViewGroup.LayoutParams.MATCH_PARENT); layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); childView.setLayoutParams(layoutParams); } container.removeView(childView); relativeLayout.addView(childView); container.addView(relativeLayout); return relativeLayout; } return item; }
From source file:com.commonsware.cwac.crossport.design.widget.BaseTransientBottomBar.java
/** * Constructor for the transient bottom bar. * * @param parent The parent for this transient bottom bar. * @param content The content view for this transient bottom bar. * @param contentViewCallback The content view callback for this transient bottom bar. */// w w w . j av a 2 s . c o m protected BaseTransientBottomBar(@NonNull ViewGroup parent, @NonNull View content, @NonNull ContentViewCallback contentViewCallback) { if (parent == null) { throw new IllegalArgumentException("Transient bottom bar must have non-null parent"); } if (content == null) { throw new IllegalArgumentException("Transient bottom bar must have non-null content"); } if (contentViewCallback == null) { throw new IllegalArgumentException("Transient bottom bar must have non-null callback"); } mTargetParent = parent; mContentViewCallback = contentViewCallback; mContext = parent.getContext(); // ThemeUtils.checkAppCompatTheme(mContext); LayoutInflater inflater = LayoutInflater.from(mContext); // Note that for backwards compatibility reasons we inflate a layout that is defined // in the extending Snackbar class. This is to prevent breakage of apps that have custom // coordinator layout behaviors that depend on that layout. mView = (SnackbarBaseLayout) inflater.inflate(R.layout.design_layout_snackbar, mTargetParent, false); mView.addView(content); ViewCompat.setAccessibilityLiveRegion(mView, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE); ViewCompat.setImportantForAccessibility(mView, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); // Make sure that we fit system windows and have a listener to apply any insets ViewCompat.setFitsSystemWindows(mView, true); ViewCompat.setOnApplyWindowInsetsListener(mView, new android.support.v4.view.OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { // Copy over the bottom inset as padding so that we're displayed // above the navigation bar v.setPadding(v.getPaddingLeft(), v.getPaddingTop(), v.getPaddingRight(), insets.getSystemWindowInsetBottom()); return insets; } }); mAccessibilityManager = (AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE); }
From source file:android.support.v17.leanback.widget.GuidedActionsStylist.java
/** * Constructs a {@link ViewHolder} capable of representing {@link GuidedAction}s. Subclasses * may choose to return a subclass of ViewHolder. * <p>//from ww w . j a v a 2 s .co m * <i>Note: Should not actually add the created view to the parent; the caller will do * this.</i> * @param parent The view group to be used as the parent of the new view. * @param viewType The viewType returned by {@link #getItemViewType(GuidedAction)} * @return The view to be added to the caller's view hierarchy. */ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { if (viewType == VIEW_TYPE_DEFAULT) { return onCreateViewHolder(parent); } LayoutInflater inflater = LayoutInflater.from(parent.getContext()); View v = inflater.inflate(onProvideItemLayoutId(viewType), parent, false); return new ViewHolder(v, parent == mSubActionsGridView); }
From source file:com.mark.quick.ui.view.snackbar.BaseTransientBottomBar.java
/** * Constructor for the transient bottom bar. * * @param parent The parent for this transient bottom bar. * @param content The content view for this transient bottom bar. * @param contentViewCallback The content view callback for this transient bottom bar. *///from w w w . ja v a 2s . c o m protected BaseTransientBottomBar(@NonNull ViewGroup parent, @NonNull View content, @NonNull ContentViewCallback contentViewCallback) { if (parent == null) { throw new IllegalArgumentException("Transient bottom bar must have non-null parent"); } if (content == null) { throw new IllegalArgumentException("Transient bottom bar must have non-null content"); } if (contentViewCallback == null) { throw new IllegalArgumentException("Transient bottom bar must have non-null callback"); } mTargetParent = parent; mContentViewCallback = contentViewCallback; mContext = parent.getContext(); ThemeUtils.checkAppCompatTheme(mContext); LayoutInflater inflater = LayoutInflater.from(mContext); // Note that for backwards compatibility reasons we inflate a layout that is defined // in the extending Snackbar class. This is to prevent breakage of apps that have custom // coordinator layout behaviors that depend on that layout. mView = (SnackbarBaseLayout) inflater.inflate(R.layout.mark_design_layout_snackbar, mTargetParent, false); mView.addView(content); ViewCompat.setAccessibilityLiveRegion(mView, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE); ViewCompat.setImportantForAccessibility(mView, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); // Make sure that we fit system windows and have a listener to apply any insets ViewCompat.setFitsSystemWindows(mView, true); ViewCompat.setOnApplyWindowInsetsListener(mView, new android.support.v4.view.OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { // Copy over the bottom inset as padding so that we're displayed // above the navigation bar v.setPadding(v.getPaddingLeft(), v.getPaddingTop(), v.getPaddingRight(), insets.getSystemWindowInsetBottom()); return insets; } }); mAccessibilityManager = (AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE); }
From source file:com.popdeem.sdk.uikit.fragment.PDUIInboxFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_pd_inbox, container, false); mNoMessagesView = view.findViewById(R.id.pd_inbox_no_items_view); mSwipeRefreshLayout = (PDUISwipeRefreshLayout) view.findViewById(R.id.pd_inbox_swipe_refresh_layout); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override//ww w. j a v a2s . co m public void onRefresh() { refreshMessages(); } }); final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.pd_inbox_recycler_view); mAdapter = new PDUIMessagesRecyclerAdapter(mMessages); mAdapter.setOnItemClickListener(new PDUIMessagesRecyclerAdapter.OnItemClickListener() { @Override public void onClick(View view) { final int position = recyclerView.getChildAdapterPosition(view); PDMessage message = mMessages.get(position); markMessageAsRead(message.getId()); message.setRead(true); mAdapter.notifyItemChanged(position); if (mListener != null) { mListener.itemClicked(message); } } }); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(container.getContext()); mSwipeRefreshLayout.addLinearLayoutManager(linearLayoutManager); recyclerView.setLayoutManager(linearLayoutManager); recyclerView.addItemDecoration( new PDUIDividerItemDecoration(getActivity(), R.color.pd_inbox_list_divider_color)); recyclerView.setAdapter(mAdapter); refreshMessages(); return view; }
From source file:com.juick.android.MainActivity.java
private static void restyleViewGroup(ViewGroup view, ColorsTheme.ColorTheme colorTheme, boolean pressed, boolean selected, boolean dontBackground) { ViewGroup parent = view;//from w ww .ja v a2s . c o m if (parent.getId() == R.id.navigation_panel) return; int childCount = parent.getChildCount(); int background = colorTheme.getBackground(pressed); int foreground = colorTheme.getForeground(pressed); if (selected) { background = calculatePressedBackground(background, foreground); } if (!dontBackground) { boolean skipDraw = false; if ((view instanceof LinearLayout || view instanceof FrameLayout || view instanceof RelativeLayout)) { Context context = view.getContext(); if (context instanceof MainActivity || context instanceof MessagesActivity || context instanceof ThreadActivity) { // no unneeded background in given scrolling activities skipDraw = true; if (view.getBackground() != null) { // but enable for layouts that with color skipDraw = false; } if (!skipDraw && view.getClass().getName().toLowerCase().contains("decorview")) { // given activities manage themselves skipDraw = true; } } } if (!skipDraw) parent.setBackgroundColor(background); } if (view instanceof ListView) dontBackground = true; for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); restyleChildrenOrWidget(child, dontBackground); } }
From source file:com.layer.atlas.AtlasMessagesList.java
public void init(final LayerClient layerClient, final Atlas.ParticipantProvider participantProvider) { if (layerClient == null) throw new IllegalArgumentException("LayerClient cannot be null"); if (participantProvider == null) throw new IllegalArgumentException("ParticipantProvider cannot be null"); this.client = layerClient; LayoutInflater.from(getContext()).inflate(R.layout.atlas_messages_list, this); // --- message view messagesList = (ListView) findViewById(R.id.atlas_messages_list); messagesList.setAdapter(messagesAdapter = new BaseAdapter() { public View getView(int position, View convertView, ViewGroup parent) { final Cell cell = cells.get(position); MessagePart part = cell.messagePart; String userId = part.getMessage().getSender().getUserId(); boolean myMessage = client.getAuthenticatedUserId().equals(userId); if (convertView == null) { convertView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.atlas_view_messages_convert, parent, false); }/*w w w .j a v a2 s . c o m*/ View spacerTop = convertView.findViewById(R.id.atlas_view_messages_convert_spacer_top); spacerTop.setVisibility( cell.clusterItemId == cell.clusterHeadItemId && !cell.timeHeader ? View.VISIBLE : View.GONE); View spacerBottom = convertView.findViewById(R.id.atlas_view_messages_convert_spacer_bottom); spacerBottom.setVisibility(cell.clusterTail ? View.VISIBLE : View.GONE); // format date View timeBar = convertView.findViewById(R.id.atlas_view_messages_convert_timebar); TextView timeBarDay = (TextView) convertView .findViewById(R.id.atlas_view_messages_convert_timebar_day); TextView timeBarTime = (TextView) convertView .findViewById(R.id.atlas_view_messages_convert_timebar_time); if (cell.timeHeader) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); long todayMidnight = cal.getTimeInMillis(); long yesterMidnight = todayMidnight - (24 * 60 * 60 * 1000); // 24h less Date sentAt = cell.messagePart.getMessage().getSentAt(); if (sentAt == null) sentAt = new Date(); String timeBarTimeText = timeFormat.format(sentAt.getTime()); String timeBarDayText = null; if (sentAt.getTime() > todayMidnight) { timeBarDayText = "Today"; } else if (sentAt.getTime() > yesterMidnight) { timeBarDayText = "Yesterday"; } else { timeBarDayText = Tools.sdfDayOfWeek.format(sentAt); } timeBarDay.setText(timeBarDayText); timeBarTime.setText(timeBarTimeText); timeBar.setVisibility(View.VISIBLE); } else { timeBar.setVisibility(View.GONE); } TextView textAvatar = (TextView) convertView .findViewById(R.id.atlas_view_messages_convert_initials); View spacerRight = convertView.findViewById(R.id.atlas_view_messages_convert_spacer_right); if (myMessage) { spacerRight.setVisibility(View.GONE); textAvatar.setVisibility(View.INVISIBLE); } else { spacerRight.setVisibility(View.VISIBLE); Atlas.Participant participant = participantProvider.getParticipant(userId); String displayText = participant != null ? Atlas.getInitials(participant) : ""; textAvatar.setText(displayText); textAvatar.setVisibility(View.VISIBLE); } // mark unsent messages View cellContainer = convertView.findViewById(R.id.atlas_view_messages_cell_container); cellContainer.setAlpha( (myMessage && !cell.messagePart.getMessage().isSent()) ? CELL_CONTAINER_ALPHA_UNSENT : CELL_CONTAINER_ALPHA_SENT); // delivery receipt check TextView receiptView = (TextView) convertView .findViewById(R.id.atlas_view_messages_convert_delivery_receipt); receiptView.setVisibility(View.GONE); if (latestDeliveredMessage != null && latestDeliveredMessage.getId().equals(cell.messagePart.getMessage().getId())) { receiptView.setVisibility(View.VISIBLE); receiptView.setText("Delivered"); } if (latestReadMessage != null && latestReadMessage.getId().equals(cell.messagePart.getMessage().getId())) { receiptView.setVisibility(View.VISIBLE); receiptView.setText("Read"); } // processing cell bindCell(convertView, cell); // mark displayed message as read Message msg = part.getMessage(); if (!msg.getSender().getUserId().equals(client.getAuthenticatedUserId())) { msg.markAsRead(); } timeBarDay.setTextColor(dateTextColor); timeBarTime.setTextColor(dateTextColor); textAvatar.setTextColor(avatarTextColor); ((GradientDrawable) textAvatar.getBackground()).setColor(avatarBackgroundColor); return convertView; } private void bindCell(View convertView, final Cell cell) { ViewGroup cellContainer = (ViewGroup) convertView .findViewById(R.id.atlas_view_messages_cell_container); View cellRootView = cell.onBind(cellContainer); boolean alreadyInContainer = false; // cleanUp container cellRootView.setVisibility(View.VISIBLE); for (int iChild = 0; iChild < cellContainer.getChildCount(); iChild++) { View child = cellContainer.getChildAt(iChild); if (child != cellRootView) { child.setVisibility(View.GONE); } else { alreadyInContainer = true; } } if (!alreadyInContainer) { cellContainer.addView(cellRootView); } } public long getItemId(int position) { return position; } public Object getItem(int position) { return cells.get(position); } public int getCount() { return cells.size(); } }); messagesList.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Cell item = cells.get(position); if (clickListener != null) { clickListener.onItemClick(item); } } }); // --- end of messageView updateValues(); }
From source file:com.near.chimerarevo.fragments.PostsRecyclerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.posts_list_layout, container, false); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) isLandscapeLarge = true;// ww w.j a v a 2 s . co m } else isLandscapeLarge = false; if (!isLandscapeLarge) ((BaseActivity) getActivity()).getToolbar().getBackground().setAlpha(0); mListView = (RecyclerView) v.findViewById(R.id.cardList); mListView.setOverScrollMode(View.OVER_SCROLL_NEVER); mLoadingBar = (ProgressWheel) v.findViewById(R.id.loading_bar); mFab = (FloatingActionButton) v.findViewById(R.id.floating_action); mFab.setEnabled(false); mHeader = v.findViewById(R.id.header); mHeaderText = (TextView) mHeader.findViewById(R.id.header_title); mHeaderImg = (KenBurnsView) mHeader.findViewById(R.id.header_img); mSwipeRefreshLayout = new SwipeRefreshLayout(container.getContext()); mSwipeRefreshLayout.addView(v, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); mSwipeRefreshLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); mSwipeRefreshLayout.setOnRefreshListener(this); mSwipeRefreshLayout.setColorSchemeResources(R.color.blue_light, R.color.red_light, R.color.green_light, R.color.orange_light); return mSwipeRefreshLayout; }
From source file:android.support.transition.TransitionPort.java
/** * Called by TransitionManager to play the transition. This calls * createAnimators() to set things up and create all of the animations and then * runAnimations() to actually start the animations. *//* w w w. j av a 2 s . c om*/ void playTransition(ViewGroup sceneRoot) { ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators(); int numOldAnims = runningAnimators.size(); for (int i = numOldAnims - 1; i >= 0; i--) { Animator anim = runningAnimators.keyAt(i); if (anim != null) { AnimationInfo oldInfo = runningAnimators.get(anim); if (oldInfo != null && oldInfo.view != null && oldInfo.view.getContext() == sceneRoot.getContext()) { boolean cancel = false; TransitionValues oldValues = oldInfo.values; View oldView = oldInfo.view; TransitionValues newValues = mEndValues.viewValues != null ? mEndValues.viewValues.get(oldView) : null; if (newValues == null) { newValues = mEndValues.idValues.get(oldView.getId()); } if (oldValues != null) { // if oldValues null, then transition didn't care to stash values, // and won't get canceled if (newValues != null) { for (String key : oldValues.values.keySet()) { Object oldValue = oldValues.values.get(key); Object newValue = newValues.values.get(key); if (oldValue != null && newValue != null && !oldValue.equals(newValue)) { cancel = true; if (DBG) { Log.d(LOG_TAG, "Transition.playTransition: " + "oldValue != newValue for " + key + ": old, new = " + oldValue + ", " + newValue); } break; } } } } if (cancel) { if (anim.isRunning() || anim.isStarted()) { if (DBG) { Log.d(LOG_TAG, "Canceling anim " + anim); } anim.cancel(); } else { if (DBG) { Log.d(LOG_TAG, "removing anim from info list: " + anim); } runningAnimators.remove(anim); } } } } } createAnimators(sceneRoot, mStartValues, mEndValues); runAnimators(); }
From source file:com.hughes.android.dictionary.DictionaryActivity.java
void onLanguageButtonLongClick(final Context context) { final Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.select_dictionary_dialog); dialog.setTitle(R.string.selectDictionary); final List<DictionaryInfo> installedDicts = application.getDictionariesOnDevice(null); ListView listView = (ListView) dialog.findViewById(android.R.id.list); final Button button = new Button(listView.getContext()); final String name = getString(R.string.dictionaryManager); button.setText(name);//from w ww .jav a 2 s. com final IntentLauncher intentLauncher = new IntentLauncher(listView.getContext(), DictionaryManagerActivity.getLaunchIntent(getApplicationContext())) { @Override protected void onGo() { dialog.dismiss(); DictionaryActivity.this.finish(); } }; button.setOnClickListener(intentLauncher); listView.addHeaderView(button); listView.setAdapter(new BaseAdapter() { @Override public View getView(int position, View convertView, ViewGroup parent) { final DictionaryInfo dictionaryInfo = getItem(position); final LinearLayout result = new LinearLayout(parent.getContext()); for (int i = 0; i < dictionaryInfo.indexInfos.size(); ++i) { final IndexInfo indexInfo = dictionaryInfo.indexInfos.get(i); final View button = application.createButton(parent.getContext(), dictionaryInfo, indexInfo); final IntentLauncher intentLauncher = new IntentLauncher(parent.getContext(), getLaunchIntent(getApplicationContext(), application.getPath(dictionaryInfo.uncompressedFilename), indexInfo.shortName, searchView.getQuery().toString())) { @Override protected void onGo() { dialog.dismiss(); DictionaryActivity.this.finish(); } }; button.setOnClickListener(intentLauncher); if (i == indexIndex && dictFile != null && dictFile.getName().equals(dictionaryInfo.uncompressedFilename)) { button.setPressed(true); } result.addView(button); } final TextView nameView = new TextView(parent.getContext()); final String name = application.getDictionaryName(dictionaryInfo.uncompressedFilename); nameView.setText(name); final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.width = 0; layoutParams.weight = 1.0f; nameView.setLayoutParams(layoutParams); nameView.setGravity(Gravity.CENTER_VERTICAL); result.addView(nameView); return result; } @Override public long getItemId(int position) { return position; } @Override public DictionaryInfo getItem(int position) { return installedDicts.get(position); } @Override public int getCount() { return installedDicts.size(); } }); dialog.show(); }