public static Drawable getDefaultContactPhoto(Context context, @Nullable String name) { int targetSize = context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size); if (name != null && !name.isEmpty()) { return TextDrawable.builder() .beginConfig() .width(targetSize) .height(targetSize) .endConfig() .buildRound(String.valueOf(name.charAt(0)), COLOR_GENERATOR.getColor(name)); } synchronized (defaultPhotoLock) { if (defaultContactPhoto == null) defaultContactPhoto = TextDrawable.builder() .beginConfig() .width(targetSize) .height(targetSize) .endConfig() .buildRound("#", UNKNOWN_COLOR); return defaultContactPhoto; } }
// Constructor. public AlumnosAdapter() { mDrawableBuilder = TextDrawable.builder() .beginConfig() .width(100) .height(100) .toUpperCase() .endConfig() .round(); }
private void setLogoImage(ParseFile logoImage) { if (logoImage != null) { mLogoImageButton.setParseFile(logoImage); mLogoImageButton.loadInBackground(); } else { String title = mTitleText.getText().toString(); String firstChar = title.isEmpty() ? "N" : title.substring(0, 1).toUpperCase(); ColorGenerator generator = ColorGenerator.MATERIAL; int alphabetColor = generator.getColor(firstChar); final TextDrawable drawable = TextDrawable.builder().buildRound(firstChar, alphabetColor); mLogoImageButton.setImageDrawable(drawable); } }
public Drawable getDrawable(int position) { final int colorsCount = 16; final int number = (Integer.valueOf(getItem(position).getValue3()) <= colorsCount) ? Integer.valueOf(getItem(position).getValue3()) : Integer.valueOf(getItem(position).getValue0()) % colorsCount; char firstLetter = getItem(position).getValue1().split(" ")[1].charAt(0); TextDrawable drawable = TextDrawable.builder() .beginConfig() .width(60) .height(60) .endConfig() .buildRound(String.valueOf(firstLetter), Common.getColor(number)); return drawable; }
public static Drawable getDefaultGroupPhoto(Context context) { synchronized (defaultGroupPhotoLock) { if (defaultGroupContactPhoto == null) { Drawable background = TextDrawable.builder().buildRound(" ", UNKNOWN_COLOR); RoundedDrawable foreground = (RoundedDrawable) RoundedDrawable.fromDrawable( context.getResources().getDrawable(R.drawable.ic_group_white_24dp)); foreground.setScaleType(ImageView.ScaleType.CENTER); defaultGroupContactPhoto = new ExpandingLayerDrawable(new Drawable[] {background, foreground}); } return defaultGroupContactPhoto; } }
@Override public View getView(int position, View convertView, ViewGroup parent) { final ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = this.inflater.inflate(R.layout.item_tag, null); holder.iv = (ImageView) convertView.findViewById(R.id.tag_view); holder.tv = (TextView) convertView.findViewById(R.id.tag_name); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } String logo = LeetCoderApplication.categories.get(position).size() + ""; TextDrawable drawable = TextDrawable.builder().buildRound(logo, LeetCoderUtil.GetRandomColor()); holder.iv.setImageDrawable(drawable); holder.tv.setText(LeetCoderApplication.categoriesTag.get(position)); return convertView; }
@Override public View getView(int position, View convertView, ViewGroup parent) { View customView = convertView; final SubjectMark mark = arrayList.get(position); final ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); customView = layoutInflater.inflate(R.layout.item_subject_mark, parent, false); holder.mMarkView = (ImageView) customView.findViewById(R.id.image_view); holder.mTypeTextView = (TextView) customView.findViewById(R.id.type); holder.mDateTextView = (TextView) customView.findViewById(R.id.date); customView.setTag(holder); } else { holder = (ViewHolder) customView.getTag(); } holder.mMarkView.setImageDrawable(null); TextDrawable drawable = TextDrawable.builder() .beginConfig() .bold() .useFont(Typeface.DEFAULT) .fontSize(30) .endConfig() .buildRoundRect( String.valueOf(mark.getValue()), CommonFunctions.setMarkColor(context, mark.getValue()), 8); holder.mMarkView.setImageDrawable(drawable); holder.mTypeTextView.setText(mark.getType()); holder.mDateTextView.setText( CommonFunctions.getDate( mark.getDate(), CommonFunctions.FORMAT_YYYY_MM_DD, CommonFunctions.FORMAT_DD_MM_YYYY)); return customView; }
@Override public void init(Bundle savedInstanceState) { map = new HashMap<String, String>(); map.put("google", "Nexus"); map.put("samsung", "Samsung"); map.put("htc", "HTC"); map.put("Sony", "SONY"); map.put("lge", "LG"); map.put("Huawei", "华为"); map.put("nubia", "中兴"); map.put("Xiaomi", "小米"); map.put("Meizu", "魅族"); map.put("ONEPLUS", "一加"); map.put("smartisan", "锤子"); map.put("other", "其他"); AppInfo app = AppInfo.get(this); app.inject(this); Dart.inject(this); container = appContainer.get(this, app); drawer = this; sp = getApplicationContext().getSharedPreferences("dfbrand", Context.MODE_PRIVATE); // set drawer menu width in dp this.setDrawerDPWidth(300); // create HeadItem 1 with menu // create menu com.sspai.navigationdrawer.menu.Menu menu1 = new com.sspai.navigationdrawer.menu.Menu(); brand = sp.getString("brand", "Meizu"); section1 = this.newSection( map.get("google"), TextDrawable.builder().buildRound("", getResources().getColor(R.color.google_color)), HomeFragment.newInstance("google"), false); // set on click listener for section 31 section1.setOnClickListener( new SectionListener() { @Override public void onClick(Section section) { unSelectOldSection(section); switchFragment("google"); } }); Section section2 = this.newSection( map.get("samsung"), TextDrawable.builder().buildRound("", getResources().getColor(R.color.samsung_color)), false); // set on click listener for section 2 section2.setOnClickListener( new SectionListener() { @Override public void onClick(Section section) { unSelectOldSection(section); switchFragment("samsung"); } }); Section section3 = this.newSection( map.get("htc"), TextDrawable.builder().buildRound("", getResources().getColor(R.color.htc_color)), false); // set on click listener for section 2 section3.setOnClickListener( new SectionListener() { @Override public void onClick(Section section) { unSelectOldSection(section); switchFragment("htc"); } }); Section section4 = this.newSection( map.get("Sony"), TextDrawable.builder().buildRound("", getResources().getColor(R.color.sony_color)), false); // set on click listener for section 2 section4.setOnClickListener( new SectionListener() { @Override public void onClick(Section section) { unSelectOldSection(section); switchFragment("Sony"); } }); Section section5 = this.newSection( map.get("lge"), TextDrawable.builder().buildRound("", getResources().getColor(R.color.lge_color)), false); section5.setOnClickListener( new SectionListener() { @Override public void onClick(Section section) { unSelectOldSection(section); switchFragment("lge"); } }); Section section6 = this.newSection( map.get("Huawei"), TextDrawable.builder().buildRound("", getResources().getColor(R.color.huawei_color)), false); section6.setOnClickListener( new SectionListener() { @Override public void onClick(Section section) { unSelectOldSection(section); switchFragment("Huawei"); } }); Section section7 = this.newSection( map.get("nubia"), TextDrawable.builder().buildRound("", getResources().getColor(R.color.nubia_color)), false); section7.setOnClickListener( new SectionListener() { @Override public void onClick(Section section) { unSelectOldSection(section); switchFragment("nubia"); } }); Section section8 = this.newSection( map.get("Xiaomi"), TextDrawable.builder().buildRound("", getResources().getColor(R.color.xiaomi_color)), false); section8.setOnClickListener( new SectionListener() { @Override public void onClick(Section section) { unSelectOldSection(section); switchFragment("Xiaomi"); } }); Section section9 = this.newSection( map.get("Meizu"), TextDrawable.builder().buildRound("", getResources().getColor(R.color.meizu_color)), false); section9.setOnClickListener( new SectionListener() { @Override public void onClick(Section section) { unSelectOldSection(section); switchFragment("Meizu"); } }); Section section10 = this.newSection( map.get("ONEPLUS"), TextDrawable.builder().buildRound("", getResources().getColor(R.color.oneplue_color)), false); section10.setOnClickListener( new SectionListener() { @Override public void onClick(Section section) { unSelectOldSection(section); switchFragment("ONEPLUS"); } }); Section section11 = this.newSection( map.get("smartisan"), TextDrawable.builder().buildRound("", getResources().getColor(R.color.smartisan_color)), false); section11.setOnClickListener( new SectionListener() { @Override public void onClick(Section section) { unSelectOldSection(section); switchFragment("smartisan"); } }); Section section12 = this.newSection( map.get("other"), TextDrawable.builder().buildRound("", getResources().getColor(R.color.other_color)), false); section12.setOnClickListener( new SectionListener() { @Override public void onClick(Section section) { unSelectOldSection(section); switchFragment("other"); } }); // add sections to the menu menu1.getSections().add(section1); menu1.getSections().add(section2); menu1.getSections().add(section3); menu1.getSections().add(section4); menu1.getSections().add(section5); menu1.getSections().add(section6); menu1.getSections().add(section7); menu1.getSections().add(section8); menu1.getSections().add(section9); menu1.getSections().add(section10); menu1.getSections().add(section11); menu1.getSections().add(section12); menu1.getSections().add(new Devisor()); // create headItem1 and add menu1 HeadItem headItem1 = new HeadItem( "少数派出品", "", null, this.getResources().getDrawable(R.drawable.menu_banner), menu1, 0); // add headItem1 to the drawer this.addHeadItem(headItem1); headItem1.setCloseDrawerOnChanged(true); // set this class as onchangedListener this.setOnChangedListener(this); }
private TextDrawable newAvatarDrawable(String text) { String letter = String.valueOf(Character.toUpperCase(text.charAt(0))); return TextDrawable.builder().buildRound(letter, ColorGenerator.MATERIAL.getColor(letter)); }