List of usage examples for android.graphics.drawable GradientDrawable setColor
public void setColor(@Nullable ColorStateList colorStateList)
From source file:com.gumgoose.app.quakebuddy.QuakeAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { // Check if the existing view is being reused, otherwise inflate the view View listItemView = convertView; if (listItemView == null) { listItemView = LayoutInflater.from(getContext()).inflate(R.layout.earthquake_list_item, parent, false); }//from ww w .ja va 2 s.c om // Initiate user's shared preferences for customising the ListView item SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); // Get the Quake object at this position in the list Quake currentEarthquake = getItem(position); // Get the original location String from the Quake object String originalLocation = currentEarthquake.getQuakeLocation(); // If the original location String (i.e. "10km SSW of Basilisa, Philippines") contains // a primary location (i.e. "Basilisa, Philippines") and an offset (i.e. "10km SSW of "), // store the primary location and the offset separately into 2 different Strings String primaryLocation; String locationOffset; // Check whether the originalLocation String contains the " of " text if (originalLocation.contains(LOCATION_SEPARATOR)) { // Split the String into different parts based on the " of " text; // String #1 shows as "10km SSW" and String #2 shows as "Basilisa, Philippines" String[] parts = originalLocation.split(LOCATION_SEPARATOR); // Location offset should be "10km SSW" + " of " --> "10km SSW of " locationOffset = parts[0] + LOCATION_SEPARATOR; // Primary location should be "Basilisa, Philippines" primaryLocation = parts[1]; } else { // No " of " text detected in the originalLocation String, instead display "Near the" locationOffset = getContext().getString(R.string.near_the); // The primary location will be the full location String primaryLocation = originalLocation; } // Find a reference to the list_location_city TextView TextView primaryTextView = (TextView) listItemView.findViewById(R.id.list_location_city); // Populate the primaryTextView with the earthquake's location primaryTextView.setText(primaryLocation); // Find a reference to the list_location_heading TextView TextView secondaryTextView = (TextView) listItemView.findViewById(R.id.list_location_heading); // Change the secondaryTextView color to textColorEarthquakeDetails secondaryTextView.setTextColor(ContextCompat.getColor(getContext(), R.color.textColorEarthquakeDetails)); // Populate the secondaryTextView with the earthquake's location offset secondaryTextView.setText(locationOffset); // Find a reference to the list_magnitude TextView TextView magnitudeView = (TextView) listItemView.findViewById(R.id.list_magnitude); // Format the magnitude to show 1 decimal place String formattedMagnitude = formatMagnitude(currentEarthquake.getQuakeMagnitude()); // Populate the magnitudeView with the earthquake's magnitude magnitudeView.setText(formattedMagnitude); // Find a reference to the list_time TextView TextView thirdView = (TextView) listItemView.findViewById(R.id.list_time); // Find a reference to the list_date TextView TextView fourthView = (TextView) listItemView.findViewById(R.id.list_date); // Obtain user's preference on how to display the earthquake times String timePref = prefs.getString("time_preference", "ago"); if (timePref.equals("ago")) { // Populate the thirdView TextView with the earthquake time in "Ago" format thirdView.setText(getTimeAgo(currentEarthquake.getQuakeUnixTime())); // Empty the fourthView TextView fourthView.setText(""); } else { // Populate the thirdView TextView with the earthquake time thirdView.setText(getStandardTime(currentEarthquake.getQuakeUnixTime())); // Populate the fourthView TextView with the earthquake date fourthView.setText(getDate(currentEarthquake.getQuakeUnixTime())); } // Obtain user's preference on whether to display 'Tsunami Watch' theme String tsunamiPref = prefs.getString("tsunami_watch_theme", "enabled"); // Find a reference to the drawable circle object GradientDrawable magnitudeCircle = (GradientDrawable) magnitudeView.getBackground(); if (tsunamiPref.equals("enabled") && currentEarthquake.getTsunamiWarning() == 1) { // Display current Tsunami watches within the last 24 hours if (DateUtils.isToday(currentEarthquake.getQuakeUnixTime())) { // Change the circle color to black magnitudeCircle.setColor(Color.BLACK); // Change the secondaryTextView color to colorAccent secondaryTextView.setTextColor(ContextCompat.getColor(getContext(), R.color.colorAccent)); // Populate the secondaryTextView to "Check for Tsunamis" secondaryTextView.setText(R.string.tsunami_header); } } else { // Reference the circle color with respect to the magnitude int magnitudeColor = getMagnitudeColor(currentEarthquake.getQuakeMagnitude()); // Change the circle color magnitudeCircle.setColor(magnitudeColor); } // Return the whole list item layout so it can be displayed return listItemView; }
From source file:com.bitants.wally.views.swipeclearlayout.SwipeClearLayout.java
private View generateCircle(Context context, AttributeSet attrs, DisplayMetrics metrics) { ImageView view = new ImageView(context, attrs); GradientDrawable circle = (GradientDrawable) getResources().getDrawable(R.drawable.circle); circle.setColor(CIRCLE_DEFAULT_COLOR); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { view.setBackground(circle);/*from w w w. jav a 2 s .c om*/ } else { view.setBackgroundDrawable(circle); } int size = (int) (metrics.density * CIRCLE_SIZE); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(size, size); view.setLayoutParams(params); view.setImageResource(R.drawable.clip_random); view.setScaleType(ImageView.ScaleType.CENTER_INSIDE); view.setRotation(90.0f); return view; }
From source file:com.amaze.filemanager.adapters.ZipAdapter.java
@Override public void onBindViewHolder(RecyclerView.ViewHolder vholder, final int position1) { final ZipAdapter.ViewHolder holder = ((ZipAdapter.ViewHolder) vholder); if (!this.stoppedAnimation) { animate(holder);// w w w . ja v a 2s .c om } if (position1 == 0) { holder.rl.setMinimumHeight(zipViewer.paddingTop); return; } final ZipObj rowItem = enter.get(position1 - 1); final int p = position1 - 1; GradientDrawable gradientDrawable = (GradientDrawable) holder.imageView.getBackground(); if (rowItem.getEntry() == null) { holder.imageView.setImageResource(R.drawable.abc_ic_ab_back_mtrl_am_alpha); gradientDrawable.setColor(Color.parseColor("#757575")); holder.txtTitle.setText(".."); holder.txtDesc.setText(""); holder.date.setText(R.string.goback); } else { holder.imageView.setImageDrawable( Icons.loadMimeIcon(zipViewer.getActivity(), rowItem.getName(), false, zipViewer.res)); final StringBuilder stringBuilder = new StringBuilder(rowItem.getName()); if (zipViewer.showLastModified) holder.date.setText(new Futils().getdate(rowItem.getTime(), "MMM dd, yyyy", zipViewer.year)); if (rowItem.isDirectory()) { holder.imageView.setImageDrawable(folder); gradientDrawable.setColor(Color.parseColor(zipViewer.iconskin)); if (stringBuilder.toString().length() > 0) { stringBuilder.deleteCharAt(rowItem.getName().length() - 1); try { holder.txtTitle.setText( stringBuilder.toString().substring(stringBuilder.toString().lastIndexOf("/") + 1)); } catch (Exception e) { holder.txtTitle.setText(rowItem.getName().substring(0, rowItem.getName().lastIndexOf("/"))); } } } else { if (zipViewer.showSize) holder.txtDesc.setText(new Futils().readableFileSize(rowItem.getSize())); holder.txtTitle.setText(rowItem.getName().substring(rowItem.getName().lastIndexOf("/") + 1)); if (zipViewer.coloriseIcons) { if (Icons.isVideo(rowItem.getName()) || Icons.isPicture(rowItem.getName())) gradientDrawable.setColor(Color.parseColor("#f06292")); else if (Icons.isAudio(rowItem.getName())) gradientDrawable.setColor(Color.parseColor("#9575cd")); else if (Icons.isPdf(rowItem.getName())) gradientDrawable.setColor(Color.parseColor("#da4336")); else if (Icons.isCode(rowItem.getName())) gradientDrawable.setColor(Color.parseColor("#00bfa5")); else if (Icons.isText(rowItem.getName())) gradientDrawable.setColor(Color.parseColor("#e06055")); else if (Icons.isArchive(rowItem.getName())) gradientDrawable.setColor(Color.parseColor("#f9a825")); else if (Icons.isApk(rowItem.getName())) gradientDrawable.setColor(Color.parseColor("#a4c439")); else if (Icons.isgeneric(rowItem.getName())) gradientDrawable.setColor(Color.parseColor("#9e9e9e")); else gradientDrawable.setColor(Color.parseColor(zipViewer.iconskin)); } else gradientDrawable.setColor(Color.parseColor(zipViewer.iconskin)); } } holder.rl.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { if (rowItem.getEntry() != null) { final Animation animation = AnimationUtils.loadAnimation(zipViewer.getActivity(), R.anim.holder_anim); holder.imageView.setAnimation(animation); toggleChecked(p); } System.out.println("onLongClick"); return true; } }); holder.imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (rowItem.getEntry() != null) { final Animation animation = AnimationUtils.loadAnimation(zipViewer.getActivity(), R.anim.holder_anim); holder.imageView.setAnimation(animation); toggleChecked(p); } } }); Boolean checked = myChecked.get(p); if (checked != null) { if (zipViewer.mainActivity.theme1 == 0) { holder.rl.setBackgroundResource(R.drawable.safr_ripple_white); } else { holder.rl.setBackgroundResource(R.drawable.safr_ripple_black); } holder.rl.setSelected(false); if (checked) { holder.imageView.setImageDrawable( zipViewer.getResources().getDrawable(R.drawable.abc_ic_cab_done_holo_dark)); gradientDrawable.setColor(Color.parseColor("#757575")); holder.rl.setSelected(true); } } holder.rl.setOnClickListener(new View.OnClickListener() { public void onClick(View p1) { if (rowItem.getEntry() == null) zipViewer.goBack(); else { if (zipViewer.selection) { final Animation animation = AnimationUtils.loadAnimation(zipViewer.getActivity(), R.anim.holder_anim); holder.imageView.setAnimation(animation); toggleChecked(p); } else { final StringBuilder stringBuilder = new StringBuilder(rowItem.getName()); if (rowItem.isDirectory()) stringBuilder.deleteCharAt(rowItem.getName().length() - 1); if (rowItem.isDirectory()) { new ZipHelperTask(zipViewer, stringBuilder.toString()).execute(zipViewer.f); } else { String x = rowItem.getName().substring(rowItem.getName().lastIndexOf("/") + 1); File file = new File(c.getCacheDir().getAbsolutePath() + "/" + x); zipViewer.files.clear(); zipViewer.files.add(0, file); try { ZipFile zipFile = new ZipFile(zipViewer.f); new ZipExtractTask(zipFile, c.getCacheDir().getAbsolutePath(), zipViewer.getActivity(), x, true, rowItem.getEntry()).execute(); } catch (IOException e) { e.printStackTrace(); } } } } } }); }
From source file:org.onebusaway.android.ui.ArrivalsListAdapterStyleA.java
@Override protected void initView(View view, ArrivalInfo stopInfo) { final Context context = getContext(); final ObaArrivalInfo arrivalInfo = stopInfo.getInfo(); TextView route = (TextView) view.findViewById(R.id.route); TextView destination = (TextView) view.findViewById(R.id.destination); TextView time = (TextView) view.findViewById(R.id.time); TextView status = (TextView) view.findViewById(R.id.status); TextView etaView = (TextView) view.findViewById(R.id.eta); TextView minView = (TextView) view.findViewById(R.id.eta_min); ViewGroup realtimeView = (ViewGroup) view.findViewById(R.id.eta_realtime_indicator); ImageView moreView = (ImageView) view.findViewById(R.id.more_horizontal); moreView.setColorFilter(context.getResources().getColor(R.color.switch_thumb_normal_material_dark)); ImageView starView = (ImageView) view.findViewById(R.id.route_favorite); starView.setColorFilter(context.getResources().getColor(R.color.navdrawer_icon_tint)); starView.setImageResource(//from ww w. j a v a2 s . com stopInfo.isRouteAndHeadsignFavorite() ? R.drawable.focus_star_on : R.drawable.focus_star_off); route.setText(arrivalInfo.getShortName()); destination.setText(MyTextUtils.toTitleCase(arrivalInfo.getHeadsign())); status.setText(stopInfo.getStatusText()); long eta = stopInfo.getEta(); if (eta == 0) { etaView.setText(R.string.stop_info_eta_now); minView.setVisibility(View.GONE); } else { etaView.setText(String.valueOf(eta)); minView.setVisibility(View.VISIBLE); } status.setBackgroundResource(R.drawable.round_corners_style_b_status); GradientDrawable d = (GradientDrawable) status.getBackground(); Integer colorCode = stopInfo.getColor(); int color = context.getResources().getColor(colorCode); if (stopInfo.getPredicted()) { // Show real-time indicator UIUtils.setRealtimeIndicatorColorByResourceCode(realtimeView, colorCode, android.R.color.transparent); realtimeView.setVisibility(View.VISIBLE); } else { realtimeView.setVisibility(View.INVISIBLE); } etaView.setTextColor(color); minView.setTextColor(color); d.setColor(color); // Set padding on status view int pSides = UIUtils.dpToPixels(context, 5); int pTopBottom = UIUtils.dpToPixels(context, 2); status.setPadding(pSides, pTopBottom, pSides, pTopBottom); time.setText(DateUtils.formatDateTime(context, stopInfo.getDisplayTime(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT)); ContentValues values = null; if (mTripsForStop != null) { values = mTripsForStop.getValues(arrivalInfo.getTripId()); } if (values != null) { String reminderName = values.getAsString(ObaContract.Trips.NAME); TextView reminder = (TextView) view.findViewById(R.id.reminder); if (reminderName.length() == 0) { reminderName = context.getString(R.string.trip_info_noname); } reminder.setText(reminderName); Drawable d2 = reminder.getCompoundDrawables()[0]; d2 = DrawableCompat.wrap(d2); DrawableCompat.setTint(d2.mutate(), view.getResources().getColor(R.color.button_material_dark)); reminder.setCompoundDrawables(d2, null, null, null); reminder.setVisibility(View.VISIBLE); } else { // Explicitly set this to invisible because we might be reusing // this view. View reminder = view.findViewById(R.id.reminder); reminder.setVisibility(View.GONE); } }
From source file:com.coolerfall.uiart.PagerSlidingTabStrip.java
/** get background drawable */ private GradientDrawable createDrawable() { GradientDrawable drawable = new GradientDrawable(); drawable.setCornerRadius(mCornerRadius); drawable.setColor(mNumBackground); return drawable; }
From source file:edu.ptu.navpattern.tooltip.Tooltip.java
private View getContentView(final Builder builder) { GradientDrawable drawable = new GradientDrawable(); drawable.setColor(builder.mBackgroundColor); drawable.setCornerRadius(builder.mCornerRadius); LinearLayout vgContent = new LinearLayout(builder.mContext); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { vgContent.setBackground(drawable); } else {/*from w w w .j a v a 2 s . com*/ //noinspection deprecation vgContent.setBackgroundDrawable(drawable); } int padding = (int) builder.mPadding; vgContent.setPadding(padding, padding, padding, padding); vgContent.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0); textViewParams.gravity = Gravity.CENTER; textViewParams.topMargin = 1; vgContent.setLayoutParams(textViewParams); vgContent.setDividerDrawable(vgContent.getResources().getDrawable(R.drawable.divider_line)); vgContent.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); if (builder.itemText != null && builder.itemText.length > 0) { for (int i = 0; i < builder.itemText.length; i++) { TextView textView = new TextView(builder.mContext); textView.setText(builder.itemText[i]); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 44); textView.setTextColor(0xffffffff); textView.setGravity(Gravity.CENTER_VERTICAL); if (builder.itemLogo != null && builder.itemLogo.length > i) { Drawable drawableLeft = builder.mContext.getResources().getDrawable(builder.itemLogo[i]); /// ??,??. // drawableLeft.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); // textView.setCompoundDrawables(drawableLeft, null, null, null); // textView.setCompoundDrawablePadding(4); // textView.setBackgroundDrawable(drawableLeft); LinearLayout linearLayout = new LinearLayout(builder.mContext); linearLayout.setMinimumHeight((int) dpToPx(44f)); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setGravity(Gravity.CENTER_VERTICAL); ImageView icon = new ImageView(builder.mContext); icon.setImageDrawable(drawableLeft); linearLayout.addView(icon); linearLayout.addView(textView); vgContent.addView(linearLayout); final int position = i; linearLayout.setClickable(false); linearLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (builder.mOnItemClickListener != null) { builder.mOnItemClickListener.onClick(position); } mTouchListener.onTouch(v, MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, v.getLeft() + 5, v.getTop() + 5, 0)); } }); } else { vgContent.addView(textView); final int position = i; textView.setClickable(false); textView.setMinimumHeight((int) dpToPx(44f)); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (builder.mOnItemClickListener != null) { builder.mOnItemClickListener.onClick(position); } mTouchListener.onTouch(v, null); } }); } } } mArrowView = new ImageView(builder.mContext); mArrowView.setImageDrawable(builder.mArrowDrawable); LinearLayout.LayoutParams arrowLayoutParams; if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) { arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowWidth, (int) builder.mArrowHeight, 0); } else { arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowHeight, (int) builder.mArrowWidth, 0); } arrowLayoutParams.gravity = Gravity.CENTER; mArrowView.setLayoutParams(arrowLayoutParams); mContentView = new LinearLayout(builder.mContext); mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); mContentView.setOrientation(mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayout.HORIZONTAL : LinearLayout.VERTICAL); padding = (int) dpToPx(5); switch (mGravity) { case Gravity.START: mContentView.setPadding(0, 0, padding, 0); break; case Gravity.TOP: case Gravity.BOTTOM: mContentView.setPadding(padding, 0, padding, 0); break; case Gravity.END: mContentView.setPadding(padding, 0, 0, 0); break; } if (mGravity == Gravity.TOP || mGravity == Gravity.START) { mContentView.addView(vgContent); mContentView.addView(mArrowView); } else { mContentView.addView(mArrowView); mContentView.addView(vgContent); } if (builder.isCancelable || builder.isDismissOnClick) { mContentView.setOnTouchListener(mTouchListener); } return mContentView; }
From source file:org.zywx.wbpalmstar.plugin.inputtextfieldview.ACEInputTextFieldView.java
private void initKeyboardParams(JSONObject json) { try {/*from w w w . j av a2 s . c o m*/ // EmojiconsXmlPath mEmojiconswgtResXmlPath = json .getString(EInputTextFieldViewUtils.INPUTTEXTFIELDVIEW_PARAMS_JSON_KEY_EMOJICONS); initEmojicons(); mEmojiconsPager.setAdapter(new EmotjiconsPagerAdapter()); // placeHold if (json.has(EInputTextFieldViewUtils.INPUTTEXTFIELDVIEW_PARAMS_JSON_KEY_PLACEHOLD)) { String placehold = json .getString(EInputTextFieldViewUtils.INPUTTEXTFIELDVIEW_PARAMS_JSON_KEY_PLACEHOLD); mEditText.setHint(placehold); } // sendBtn text if (json.has(EInputTextFieldViewUtils.INPUTTEXTFIELDVIEW_PARAMS_JSON_KEY_BTN_TEXT)) { String sendBtnText = json .getString(EInputTextFieldViewUtils.INPUTTEXTFIELDVIEW_PARAMS_JSON_KEY_BTN_TEXT); mBtnSend.setText(sendBtnText); } // sendBtn text size if (json.has(EInputTextFieldViewUtils.INPUTTEXTFIELDVIEW_PARAMS_JSON_KEY_BTN_TEXT_SIZE)) { String sendBtnTextSize = json .getString(EInputTextFieldViewUtils.INPUTTEXTFIELDVIEW_PARAMS_JSON_KEY_BTN_TEXT_SIZE); try { mBtnSend.setTextSize(Float.parseFloat(sendBtnTextSize)); } catch (Exception e) { e.printStackTrace(); } } // sendBtn text color if (json.has(EInputTextFieldViewUtils.INPUTTEXTFIELDVIEW_PARAMS_JSON_KEY_BTN_TEXT_COLOR)) { String btnTextColor = json .getString(EInputTextFieldViewUtils.INPUTTEXTFIELDVIEW_PARAMS_JSON_KEY_BTN_TEXT_COLOR); mBtnSend.setTextColor(BUtility.parseColor(btnTextColor)); } // Selector need StateListDrawable StateListDrawable myGrad = (StateListDrawable) mBtnSend.getBackground(); // sendBtn color normal if (json.has(EInputTextFieldViewUtils.INPUTTEXTFIELDVIEW_PARAMS_JSON_KEY_BTN_COLOR)) { String btnColor = json .getString(EInputTextFieldViewUtils.INPUTTEXTFIELDVIEW_PARAMS_JSON_KEY_BTN_COLOR); if (!TextUtils.isEmpty(btnColor)) { GradientDrawable drawable = (GradientDrawable) myGrad.getCurrent(); drawable.setColor(BUtility.parseColor(btnColor)); } } // sendBtn color pressed if (json.has(EInputTextFieldViewUtils.INPUTTEXTFIELDVIEW_PARAMS_JSON_KEY_BTN_COLOR_DOWN)) { String sendBtnbgColorDown = json .getString(EInputTextFieldViewUtils.INPUTTEXTFIELDVIEW_PARAMS_JSON_KEY_BTN_COLOR_DOWN); if (!TextUtils.isEmpty(sendBtnbgColorDown)) { mBtnSend.setPressed(true); GradientDrawable drawable = (GradientDrawable) myGrad.getCurrent(); drawable.setColor(BUtility.parseColor(sendBtnbgColorDown)); mBtnSend.setPressed(false); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.dat.towerofhanoi.draggablerecyclerview.BoardView.java
public DragItemRecyclerView addColumnList(final DragItemAdapter adapter, final View header, boolean hasFixedItemSize, int color, Drawable drawable) { final DragItemRecyclerView recyclerView = new DragItemRecyclerView(getContext()); recyclerView.setMotionEventSplittingEnabled(false); recyclerView.setDragItem(mDragItem); if (drawable != null) { if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { recyclerView.setBackgroundDrawable(drawable); GradientDrawable gd = (GradientDrawable) recyclerView.getBackground().getCurrent(); gd.setColor(getResources().getColor(R.color.white)); gd.setStroke(2, getResources().getColor(R.color.grey), 0, 0); } else {//from w w w . j av a 2 s . co m recyclerView.setBackground(drawable); } } if (color > 0) { mColumnLayout.setBackgroundColor(color); } //settings for ToH rules recyclerView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext()); linearLayoutManager.setReverseLayout(true); recyclerView.setCanNotDragBelowTopItem(mCanNotDragBelowTopItem); recyclerView.setCanNotDropBelowTopItem(mCanNotDropBelowTopItem); recyclerView.setDragItemCallback(new DragItemRecyclerView.DragItemCallback() { @Override public boolean canDragItemAtPosition(int dragPosition) { return true; } @Override public boolean canDropItemAtPosition(int dropPosition) { if (dropPosition == adapter.getItemCount() - 1) { // Log.d("TAG", "TRUE"); return true; } return false; } }); recyclerView.setLayoutManager(linearLayoutManager); recyclerView.setHasFixedSize(hasFixedItemSize); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setDragItemListener(new DragItemRecyclerView.DragItemListener() { @Override public void onDragStarted(int itemPosition, float x, float y) { mDragStartColumn = getColumnOfList(recyclerView); mDragStartRow = itemPosition; mCurrentRecyclerView = recyclerView; mDragItem.setOffset(((View) mCurrentRecyclerView.getParent()).getX(), mCurrentRecyclerView.getY()); if (mBoardListener != null) { mBoardListener.onItemDragStarted(mDragStartColumn, mDragStartRow); } invalidate(); } @Override public void onDragging(int itemPosition, float x, float y) { } @Override public void onDragEnded(int newItemPosition) { if (mBoardListener != null) { mBoardListener.onItemDragEnded(mDragStartColumn, mDragStartRow, getColumnOfList(recyclerView), newItemPosition); } } }); recyclerView.setAdapter(adapter); recyclerView.setDragEnabled(mDragEnabled); adapter.setDragStartedListener(new DragItemAdapter.DragStartCallback() { @Override public boolean startDrag(View itemView, long itemId) { return recyclerView.startDrag(itemView, itemId, getListTouchX(recyclerView), getListTouchY(recyclerView)); } @Override public boolean isDragging() { return recyclerView.isDragging(); } }); LinearLayout layout = new LinearLayout(getContext()); layout.setOrientation(LinearLayout.VERTICAL); layout.setLayoutParams(new LayoutParams(mColumnWidth, LayoutParams.MATCH_PARENT)); if (header != null) { layout.addView(header); mHeaders.put(mLists.size(), header); } layout.addView(recyclerView); mLists.add(recyclerView); mColumnLayout.addView(layout); return recyclerView; }
From source file:com.tooltip.Tooltip.java
private View getContentView(Builder builder) { GradientDrawable drawable = new GradientDrawable(); drawable.setColor(builder.mBackgroundColor); drawable.setCornerRadius(builder.mCornerRadius); int padding = (int) builder.mPadding; TextView textView = new TextView(builder.mContext); TextViewCompat.setTextAppearance(textView, builder.mTextAppearance); textView.setText(builder.mText);/*from w w w . j a v a 2 s. c o m*/ textView.setPadding(padding, padding, padding, padding); textView.setLineSpacing(builder.mLineSpacingExtra, builder.mLineSpacingMultiplier); textView.setTypeface(builder.mTypeface, builder.mTextStyle); if (builder.mTextSize >= 0) { textView.setTextSize(TypedValue.TYPE_NULL, builder.mTextSize); } if (builder.mTextColor != null) { textView.setTextColor(builder.mTextColor); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { textView.setBackground(drawable); } else { //noinspection deprecation textView.setBackgroundDrawable(drawable); } LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0); textViewParams.gravity = Gravity.CENTER; textView.setLayoutParams(textViewParams); mArrowView = new ImageView(builder.mContext); mArrowView.setImageDrawable(builder.mArrowDrawable); LinearLayout.LayoutParams arrowLayoutParams; if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) { arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowWidth, (int) builder.mArrowHeight, 0); } else { arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowHeight, (int) builder.mArrowWidth, 0); } arrowLayoutParams.gravity = Gravity.CENTER; mArrowView.setLayoutParams(arrowLayoutParams); mContentView = new LinearLayout(builder.mContext); mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); mContentView.setOrientation(mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayout.HORIZONTAL : LinearLayout.VERTICAL); padding = (int) Util.dpToPx(5); switch (mGravity) { case Gravity.START: mContentView.setPadding(0, 0, padding, 0); break; case Gravity.TOP: case Gravity.BOTTOM: mContentView.setPadding(padding, 0, padding, 0); break; case Gravity.END: mContentView.setPadding(padding, 0, 0, 0); break; } if (mGravity == Gravity.TOP || mGravity == Gravity.START) { mContentView.addView(textView); mContentView.addView(mArrowView); } else { mContentView.addView(mArrowView); mContentView.addView(textView); } mContentView.setOnClickListener(mClickListener); mContentView.setOnLongClickListener(mLongClickListener); if (builder.isCancelable || builder.isDismissOnClick) { mContentView.setOnTouchListener(mTouchListener); } return mContentView; }
From source file:com.sonvp.tooltip.Tooltip.java
private View getViewTooltip(Builder builder, int backgroundColor) { View toolTip = null;/*www.j a v a2 s .c om*/ if (builder.viewTooltip == null) { TextView text = new TextView(builder.context); text.setPadding((int) builder.leftPadding, (int) builder.topPadding, (int) builder.rightPadding, (int) builder.bottomPadding); text.setGravity(builder.textGravity); text.setTextColor(builder.textColor); text.setTextSize(TypedValue.COMPLEX_UNIT_PX, builder.textSize); text.setTypeface(builder.typeface, builder.typefaceStyle); int lines = builder.lines; if (lines > 0) { text.setLines(lines); text.setEllipsize(TextUtils.TruncateAt.END); } CharSequence txt = builder.text; if (TextUtils.isEmpty(txt)) { txt = builder.context.getString(builder.textResourceId); } text.setText(txt); toolTip = text; } else { toolTip = builder.viewTooltip; } float radius = builder.radius; if (radius > 0.0F) { GradientDrawable drawable = new GradientDrawable(); drawable.setColor(backgroundColor); drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT); drawable.setCornerRadius(radius); //noinspection deprecation toolTip.setBackgroundDrawable(drawable); } else { toolTip.setBackgroundColor(backgroundColor); } return toolTip; }