List of usage examples for android.view View View
public View(Context context)
From source file:com.commonsware.cwac.masterdetail.MasterDetailHelper.java
/** * Override this if you want something else as the * "empty view" for the detail. This is shown when there * is no detail selected, in dual-pane mode. It is not * used in single-pane mode. The default implementation is * an empty View, and so the detail area is blank when * nothing is selected. You might elect to use this for * instructions, summary information, etc. Note that the * empty view will be sized to fill the detail area. Also * note that the empty view should not have a parent, as * it will be added to a parent by the framework. * // w w w. j a v a2s.co m * @return a View to serve as the "empty view" for the * detail area */ protected View buildDetailEmptyView() { View result = new View(getHost()); // result.setBackgroundColor(Color.MAGENTA); return (result); }
From source file:android.support.design.widget.CollapsingToolbarLayout.java
private void updateDummyView() { if (!mCollapsingTitleEnabled && mDummyView != null) { // If we have a dummy view and we have our title disabled, remove it from its parent final ViewParent parent = mDummyView.getParent(); if (parent instanceof ViewGroup) { ((ViewGroup) parent).removeView(mDummyView); }//from w w w .j ava 2 s . co m } if (mCollapsingTitleEnabled && mToolbar != null) { if (mDummyView == null) { mDummyView = new View(getContext()); } if (mDummyView.getParent() == null) { mToolbar.addView(mDummyView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); } } }
From source file:com.taobao.weex.extend.module.actionsheet.WXActionSheet.java
private View createRoot() { FrameLayout parent = new FrameLayout(getActivity()); parent.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); backgroundLayer = new View(getActivity()); backgroundLayer.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); backgroundLayer.setBackgroundColor(Color.argb(136, 0, 0, 0)); backgroundLayer.setOnClickListener(new View.OnClickListener() { @Override/*from w ww .j av a2 s . co m*/ public void onClick(View v) { dismiss(); if (actionListener != null) { actionListener.onCancel(); } } }); sheetContainer = new LinearLayout(getActivity()); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.gravity = Gravity.BOTTOM; sheetContainer.setLayoutParams(params); sheetContainer.setOrientation(LinearLayout.VERTICAL); sheetContainer.setPadding(dp2px(8), dp2px(8), dp2px(8), dp2px(8)); parent.setPadding(0, 0, 0, getNavBarHeight(getActivity())); parent.addView(backgroundLayer); parent.addView(sheetContainer); return parent; }
From source file:com.commonsware.cwac.masterdetail.MasterDetailHelper.java
/** * Override this if you want something else as the view * shown in the detail area when there are multiple * selections made in the dual-pane mode. You are passed * the positions in your ViewPager/model collection * representing the selected items. This is not used in * single pane mode. The default implementation is an * empty View, so nothing will be shown by default. You * might use this to show aggregate information about the * selected items. Note that the empty view will be sized * to fill the detail area. Also note that the empty view * should not have a parent, as it will be added to a * parent by the framework./*from w w w.j av a 2s .c o m*/ * * @param positions * the items selected by the user * @return the View to show in the detail area for the * multiple selections */ protected View buildDetailMultipleChoiceView(SparseBooleanArray positions) { View result = new View(getHost()); // result.setBackgroundColor(Color.CYAN); return (result); }
From source file:com.marlonjones.voidlauncher.allapps.AllAppsGridAdapter.java
@Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { switch (viewType) { case VIEW_TYPE_SECTION_BREAK: return new ViewHolder(new View(parent.getContext())); case VIEW_TYPE_ICON: /* falls through */ case VIEW_TYPE_PREDICTION_ICON: { BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate(R.layout.all_apps_icon, parent, false); icon.setOnClickListener(mIconClickListener); icon.setOnLongClickListener(mIconLongClickListener); icon.setLongPressTimeout(ViewConfiguration.get(parent.getContext()).getLongPressTimeout()); icon.setOnFocusChangeListener(mIconFocusListener); // Ensure the all apps icon height matches the workspace icons DeviceProfile profile = mLauncher.getDeviceProfile(); Point cellSize = profile.getCellSize(); GridLayoutManager.LayoutParams lp = (GridLayoutManager.LayoutParams) icon.getLayoutParams(); lp.height = cellSize.y;/*from w ww.j a v a2 s .co m*/ icon.setLayoutParams(lp); return new ViewHolder(icon); } case VIEW_TYPE_EMPTY_SEARCH: return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_empty_search, parent, false)); case VIEW_TYPE_SEARCH_MARKET: 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); case VIEW_TYPE_SEARCH_DIVIDER: return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_search_divider, parent, false)); case VIEW_TYPE_PREDICTION_DIVIDER: /* falls through */ case VIEW_TYPE_SEARCH_MARKET_DIVIDER: return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_divider, parent, false)); default: throw new RuntimeException("Unexpected view type"); } }
From source file:com.pitchedapps.primenumbercalculator.Calculator.java
License:asdf
private void reveal(View sourceView, AnimatorListener listener) { final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) getWindow().getDecorView().getOverlay(); final Rect displayRect = new Rect(); mDisplayView.getGlobalVisibleRect(displayRect); // Make reveal cover the display and status bar. final View revealView = new View(this); revealView.setBottom(displayRect.bottom); revealView.setLeft(displayRect.left); revealView.setRight(displayRect.right); revealView.setBackgroundColor(themeClearAccent); groupOverlay.add(revealView);//from ww w . j av a 2s . c o m final int[] clearLocation = new int[2]; sourceView.getLocationInWindow(clearLocation); clearLocation[0] += sourceView.getWidth() / 2; clearLocation[1] += sourceView.getHeight() / 2; final int revealCenterX = clearLocation[0] - revealView.getLeft(); final int revealCenterY = clearLocation[1] - revealView.getTop(); final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2); final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2); final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2); final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2)); final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX, revealCenterY, 0.0f, revealRadius); revealAnimator.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime)); final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); alphaAnimator.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime)); alphaAnimator.addListener(listener); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(revealAnimator).before(alphaAnimator); animatorSet.setInterpolator(new AccelerateDecelerateInterpolator()); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { groupOverlay.remove(revealView); mCurrentAnimator = null; } }); mCurrentAnimator = animatorSet; animatorSet.start(); }
From source file:at.alladin.rmbt.android.adapter.result.RMBTResultPagerAdapter.java
public void addResultListItem(String title, String value, LinearLayout netLayout) { final float scale = activity.getResources().getDisplayMetrics().density; final int leftRightDiv = Helperfunctions.dpToPx(0, scale); final int topBottomDiv = Helperfunctions.dpToPx(0, scale); final int heightDiv = Helperfunctions.dpToPx(1, scale); LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View measurementItemView = inflater.inflate(R.layout.classification_list_item, netLayout, false); final TextView itemTitle = (TextView) measurementItemView.findViewById(R.id.classification_item_title); itemTitle.setText(title);/* ww w .j a v a2s . co m*/ final ImageView itemClassification = (ImageView) measurementItemView .findViewById(R.id.classification_item_color); itemClassification.setImageResource(Helperfunctions.getClassificationColor(-1)); itemClassification.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { activity.showHelp(R.string.url_help_result, false); } }); final TextView itemValue = (TextView) measurementItemView.findViewById(R.id.classification_item_value); itemValue.setText(value); netLayout.addView(measurementItemView); final View divider = new View(activity); divider.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, heightDiv, 1)); divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv); divider.setBackgroundResource(R.drawable.bg_trans_light_10); netLayout.addView(divider); netLayout.invalidate(); }
From source file:org.telegram.ui.Components.ShareAlert.java
public ShareAlert(final Context context, MessageObject messageObject, final String text, boolean publicChannel, final String copyLink) { super(context, true); shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow); linkToCopy = copyLink;/*w w w.ja v a2 s. c om*/ sendingMessageObject = messageObject; searchAdapter = new ShareSearchAdapter(context); isPublicChannel = publicChannel; sendingText = text; if (publicChannel) { loadingLink = true; TLRPC.TL_channels_exportMessageLink req = new TLRPC.TL_channels_exportMessageLink(); req.id = messageObject.getId(); req.channel = MessagesController.getInputChannel(messageObject.messageOwner.to_id.channel_id); ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { if (response != null) { exportedMessageLink = (TLRPC.TL_exportedMessageLink) response; if (copyLinkOnEnd) { copyLink(context); } } loadingLink = false; } }); } }); } containerView = new FrameLayout(context) { private boolean ignoreLayout = false; @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0 && ev.getY() < scrollOffsetY) { dismiss(); return true; } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent e) { return !isDismissed() && super.onTouchEvent(e); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height = MeasureSpec.getSize(heightMeasureSpec); if (Build.VERSION.SDK_INT >= 21) { height -= AndroidUtilities.statusBarHeight; } int size = Math.max(searchAdapter.getItemCount(), listAdapter.getItemCount()); int contentSize = AndroidUtilities.dp(48) + Math.max(3, (int) Math.ceil(size / 4.0f)) * AndroidUtilities.dp(100) + backgroundPaddingTop; int padding = contentSize < height ? 0 : height - (height / 5 * 3) + AndroidUtilities.dp(8); if (gridView.getPaddingTop() != padding) { ignoreLayout = true; gridView.setPadding(0, padding, 0, AndroidUtilities.dp(8)); ignoreLayout = false; } super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(Math.min(contentSize, height), MeasureSpec.EXACTLY)); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); updateLayout(); } @Override public void requestLayout() { if (ignoreLayout) { return; } super.requestLayout(); } @Override protected void onDraw(Canvas canvas) { shadowDrawable.setBounds(0, scrollOffsetY - backgroundPaddingTop, getMeasuredWidth(), getMeasuredHeight()); shadowDrawable.draw(canvas); } }; containerView.setWillNotDraw(false); containerView.setPadding(backgroundPaddingLeft, 0, backgroundPaddingLeft, 0); frameLayout = new FrameLayout(context); frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.background)); frameLayout.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); doneButton = new LinearLayout(context); doneButton.setOrientation(LinearLayout.HORIZONTAL); doneButton.setBackgroundDrawable( Theme.createBarSelectorDrawable(Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, false)); doneButton.setPadding(AndroidUtilities.dp(21), 0, AndroidUtilities.dp(21), 0); frameLayout.addView(doneButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT)); doneButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (selectedDialogs.isEmpty() && (isPublicChannel || linkToCopy != null)) { if (linkToCopy == null && loadingLink) { copyLinkOnEnd = true; Toast.makeText(ShareAlert.this.getContext(), LocaleController.getString("Loading", R.string.Loading), Toast.LENGTH_SHORT).show(); } else { copyLink(ShareAlert.this.getContext()); } dismiss(); } else { if (sendingMessageObject != null) { ArrayList<MessageObject> arrayList = new ArrayList<>(); arrayList.add(sendingMessageObject); for (HashMap.Entry<Long, TLRPC.TL_dialog> entry : selectedDialogs.entrySet()) { SendMessagesHelper.getInstance().sendMessage(arrayList, entry.getKey()); } } else if (sendingText != null) { for (HashMap.Entry<Long, TLRPC.TL_dialog> entry : selectedDialogs.entrySet()) { SendMessagesHelper.getInstance().sendMessage(sendingText, entry.getKey(), null, null, true, null, null, null); } } dismiss(); } } }); doneButtonBadgeTextView = new TextView(context); doneButtonBadgeTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); doneButtonBadgeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13); doneButtonBadgeTextView.setTextColor(Theme.SHARE_SHEET_BADGE_TEXT_COLOR); doneButtonBadgeTextView.setGravity(Gravity.CENTER); doneButtonBadgeTextView.setBackgroundResource(R.drawable.bluecounter); doneButtonBadgeTextView.setMinWidth(AndroidUtilities.dp(23)); doneButtonBadgeTextView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), AndroidUtilities.dp(1)); doneButton.addView(doneButtonBadgeTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 23, Gravity.CENTER_VERTICAL, 0, 0, 10, 0)); doneButtonTextView = new TextView(context); doneButtonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); doneButtonTextView.setGravity(Gravity.CENTER); doneButtonTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8)); doneButtonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); doneButton.addView(doneButtonTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL)); ImageView imageView = new ImageView(context); imageView.setImageResource(R.drawable.search_share); imageView.setScaleType(ImageView.ScaleType.CENTER); imageView.setPadding(0, AndroidUtilities.dp(2), 0, 0); imageView.getDrawable().setTint(Theme.SHARE_SHEET_EDIT_PLACEHOLDER_TEXT_COLOR); frameLayout.addView(imageView, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.CENTER_VERTICAL)); nameTextView = new EditText(context); nameTextView.setHint(LocaleController.getString("ShareSendTo", R.string.ShareSendTo)); nameTextView.setMaxLines(1); nameTextView.setSingleLine(true); nameTextView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); nameTextView.setBackgroundDrawable(null); nameTextView.setHintTextColor(Theme.SHARE_SHEET_EDIT_PLACEHOLDER_TEXT_COLOR); nameTextView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); nameTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); AndroidUtilities.clearCursorDrawable(nameTextView); nameTextView.setTextColor(Theme.SHARE_SHEET_EDIT_TEXT_COLOR); frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 48, 2, 96, 0)); nameTextView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { String text = nameTextView.getText().toString(); if (text.length() != 0) { if (gridView.getAdapter() != searchAdapter) { topBeforeSwitch = getCurrentTop(); gridView.setAdapter(searchAdapter); searchAdapter.notifyDataSetChanged(); } if (searchEmptyView != null) { searchEmptyView.setText(LocaleController.getString("NoResult", R.string.NoResult)); } } else { if (gridView.getAdapter() != listAdapter) { int top = getCurrentTop(); searchEmptyView.setText(LocaleController.getString("NoChats", R.string.NoChats)); gridView.setAdapter(listAdapter); listAdapter.notifyDataSetChanged(); if (top > 0) { layoutManager.scrollToPositionWithOffset(0, -top); } } } if (searchAdapter != null) { searchAdapter.searchDialogs(text); } } }); gridView = new RecyclerListView(context); gridView.setTag(13); gridView.setPadding(0, 0, 0, AndroidUtilities.dp(8)); gridView.setClipToPadding(false); gridView.setLayoutManager(layoutManager = new GridLayoutManager(getContext(), 4)); gridView.setHorizontalScrollBarEnabled(false); gridView.setVerticalScrollBarEnabled(false); gridView.addItemDecoration(new RecyclerView.ItemDecoration() { @Override public void getItemOffsets(android.graphics.Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { Holder holder = (Holder) parent.getChildViewHolder(view); if (holder != null) { int pos = holder.getAdapterPosition(); outRect.left = pos % 4 == 0 ? 0 : AndroidUtilities.dp(4); outRect.right = pos % 4 == 3 ? 0 : AndroidUtilities.dp(4); } else { outRect.left = AndroidUtilities.dp(4); outRect.right = AndroidUtilities.dp(4); } } }); containerView.addView(gridView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0)); gridView.setAdapter(listAdapter = new ShareDialogsAdapter(context)); gridView.setGlowColor(0xfff5f6f7); gridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (position < 0) { return; } TLRPC.TL_dialog dialog; if (gridView.getAdapter() == listAdapter) { dialog = listAdapter.getItem(position); } else { dialog = searchAdapter.getItem(position); } if (dialog == null) { return; } ShareDialogCell cell = (ShareDialogCell) view; if (selectedDialogs.containsKey(dialog.id)) { selectedDialogs.remove(dialog.id); cell.setChecked(false, true); } else { selectedDialogs.put(dialog.id, dialog); cell.setChecked(true, true); } updateSelectedCount(); } }); gridView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { updateLayout(); } }); searchEmptyView = new EmptyTextProgressView(context); searchEmptyView.setShowAtCenter(true); searchEmptyView.showTextView(); searchEmptyView.setText(LocaleController.getString("NoChats", R.string.NoChats)); gridView.setEmptyView(searchEmptyView); containerView.addView(searchEmptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0)); containerView.addView(frameLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP)); shadow = new View(context); shadow.setBackgroundResource(R.drawable.header_shadow); containerView.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0)); updateSelectedCount(); if (!DialogsActivity.dialogsLoaded) { MessagesController.getInstance().loadDialogs(0, 100, true); ContactsController.getInstance().checkInviteText(); DialogsActivity.dialogsLoaded = true; } if (listAdapter.dialogs.isEmpty()) { NotificationCenter.getInstance().addObserver(this, NotificationCenter.dialogsNeedReload); } }
From source file:com.android.mylauncher3.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);/*from w w w . j av a2s.c om*/ 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.startSearchFromAllApps(v, mMarketSearchIntent, mLastSearchQuery); } }); return new ViewHolder(searchMarketView); default: throw new RuntimeException("Unexpected view type"); } }
From source file:org.tomahawk.tomahawk_android.adapters.TomahawkListAdapter.java
/** * This method is being called by the StickyListHeaders library. Get the correct header {@link * View} for the given position.//from w ww . ja v a2 s . c o m * * @param position The position for which to get the correct {@link View} * @param convertView The old {@link View}, which we might be able to recycle * @param parent parental {@link ViewGroup} * @return the correct header {@link View} for the given position. */ @Override public View getHeaderView(int position, View convertView, ViewGroup parent) { TomahawkListItem item = (TomahawkListItem) getItem(position); if (mShowCategoryHeaders && item != null && item != mContentHeaderTomahawkListItem) { View view = null; ViewHolder viewHolder = null; if (convertView != null) { viewHolder = (ViewHolder) convertView.getTag(); view = convertView; } int viewType = R.id.tomahawklistadapter_viewtype_header; if (viewHolder == null || viewHolder.getViewType() != viewType) { view = mLayoutInflater.inflate(R.layout.single_line_list_header, null); viewHolder = new ViewHolder(view, viewType); view.setTag(viewHolder); } if (item instanceof Track || item instanceof Query) { if (mShowQueriesAs == SHOW_QUERIES_AS_TOPHITS) { TomahawkUtils.loadDrawableIntoImageView(mContext, viewHolder.getImageView1(), R.drawable.ic_action_tophits); viewHolder.getTextView1().setText(R.string.tophits_categoryheaders_string); } else if (mShowQueriesAs == SHOW_QUERIES_AS_RECENTLYPLAYED) { TomahawkUtils.loadDrawableIntoImageView(mContext, viewHolder.getImageView1(), R.drawable.ic_action_time); viewHolder.getTextView1().setText(R.string.recentlyplayed_categoryheaders_string); } else { TomahawkUtils.loadDrawableIntoImageView(mContext, viewHolder.getImageView1(), R.drawable.ic_action_track); viewHolder.getTextView1().setText(R.string.tracksfragment_title_string); } } else if (item instanceof Artist) { TomahawkUtils.loadDrawableIntoImageView(mContext, viewHolder.getImageView1(), R.drawable.ic_action_artist); viewHolder.getTextView1().setText(R.string.artistsfragment_title_string); } else if (item instanceof Album) { TomahawkUtils.loadDrawableIntoImageView(mContext, viewHolder.getImageView1(), R.drawable.ic_action_album); viewHolder.getTextView1().setText(R.string.albumsfragment_title_string); } else if (item instanceof UserPlaylist) { TomahawkUtils.loadDrawableIntoImageView(mContext, viewHolder.getImageView1(), R.drawable.ic_action_playlist); if (((UserPlaylist) item).isHatchetPlaylist()) { viewHolder.getTextView1().setText(R.string.hatchet_userplaylists_categoryheaders_string); } else { viewHolder.getTextView1().setText(R.string.userplaylists_categoryheaders_string); } } else if (item instanceof User) { TomahawkUtils.loadDrawableIntoImageView(mContext, viewHolder.getImageView1(), R.drawable.ic_action_friends); viewHolder.getTextView1().setText(R.string.userfragment_title_string); } else if (item instanceof SocialAction) { TomahawkUtils.loadDrawableIntoImageView(mContext, viewHolder.getImageView1(), R.drawable.ic_action_trending); viewHolder.getTextView1().setText(R.string.category_header_activityfeed); } return view; } else { return new View(mContext); } }