Repository: akashandroid90/ImageLetterIcon Branch: master Commit: 1d3bc2249f25 Files: 32 Total size: 83.0 KB Directory structure: gitextract_ff1qdxwa/ ├── .gitignore ├── LICENSE ├── README.md ├── app/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── com/ │ │ └── imagelettericon/ │ │ └── MainActivity.java │ └── res/ │ ├── layout/ │ │ ├── activity_main.xml │ │ └── list_item.xml │ ├── menu/ │ │ └── menu.xml │ ├── values/ │ │ ├── arrays.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── values-w820dp/ │ └── dimens.xml ├── build.gradle ├── gradle.properties ├── gradlew ├── gradlew.bat ├── imageletter/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── com/ │ │ └── github/ │ │ └── akashandroid90/ │ │ └── imageletter/ │ │ ├── MaterialLetterIcon.java │ │ ├── RoundedImageViewWithBorder.java │ │ ├── TintableImageView.java │ │ └── drawable/ │ │ ├── RoundedDrawable.java │ │ └── TextDrawable.java │ └── res/ │ └── values/ │ └── attrs.xml └── settings.gradle ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ .gradle gradle /local.properties .idea /.idea /build *.iml ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README.md ================================================ # ImageLetterIcon Material letter icon with circle background. Also supports for image for user contact. [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-ImageLetterIcon-green.svg?style=true)](https://android-arsenal.com/details/1/2762) [ ![Download](https://api.bintray.com/packages/akashandroid90/maven/image-letter-icon/images/download.svg) ](https://bintray.com/akashandroid90/maven/image-letter-icon/_latestVersion) ![Square Initials](images/one.png) ![Square Initials](images/two.png) ![Alternate Initial Square Image](images/three.png) ![Alternate Initial Circular Image](images/four.png) Gradle ------------------------- ``` dependencies { compile 'com.github.akashandroid90:imageletter:1.8@aar' } ``` ChangeLog ----- bug fixes vector drawable support Usage ----- Declare in XML (see xml attributes below for customization): ```xml ``` Or static initializer (see xml attributes below for customization): ```java MaterialLetterIcon icon = new MaterialLetterIcon.Builder(context) // .shapeColor(getResources().getColor(R.color.circle_color)) .setShapeType(MaterialLetterIcon.SHAPE_CIRCLE) .letter("S") .letterColor(getResources().getColor(R.color.letter_color)) .letterSize(26) .lettersNumber(1) .letterTypeface(yourTypeface) .initials(false) .initialsNumber(2) .create(); ``` Configure using xml attributes or setters in code: ```java app:shape_color="@color/black" // shape color app:shape_type="circle" // shape type app:letter="" // letter or string to get first letter from app:letter_color="@color/white" // letter color app:letter_size="26" // letter size SP app:letters_number="1" // number of letters to get from string app:initials="false" // turn on initials mode app:initials_number="2" // number of initials to be showed app:corner_radius="1dp" // radius of image to make at corner app:is_oval="true" // to make a circular image app:border_width="1dp" // border width around the image app:border_color="@color/black" //border color around image ``` Donations --------- This project needs you! If you would like to support this project's further development, the creator of this project or the continuous maintenance of this project, feel free to donate. Your donation is highly appreciated (and I love food, coffee and beer). Thank you! **PayPal** * **[Donate $5]**: Thank's for creating this project, here's a coffee (or some beer) for you! * **[Donate $10]**: Wow, I am stunned. Let me take you to the movies! * **[Donate $15]**: I really appreciate your work, let's grab some lunch! * **[Donate $25]**: That's some awesome stuff you did right there, dinner is on me! * **[Donate $50]**: I really really want to support this project, great job! * **[Donate $100]**: You are the man! This project saved me hours (if not days) of struggle and hard work, simply awesome! * **[Donate $2799]**: Go buddy, buy Macbook Pro for yourself! Of course, you can also choose what you want to donate, all donations are awesome! Developed By -------------------- Akash Jain [Donate $5]: https://www.paypal.me/akashandroid/5 [Donate $10]: https://www.paypal.me/akashandroid/10 [Donate $15]: https://www.paypal.me/akashandroid/15 [Donate $25]: https://www.paypal.me/akashandroid/25 [Donate $50]: https://www.paypal.me/akashandroid/50 [Donate $100]: https://www.paypal.me/akashandroid/100 [Donate $2799]: https://www.paypal.me/akashandroid/2799 ================================================ FILE: app/.gitignore ================================================ /build ================================================ FILE: app/build.gradle ================================================ apply plugin: 'com.android.application' android { compileSdkVersion compilesdk buildToolsVersion buildtool defaultConfig { applicationId "com.imagelettericon" minSdkVersion minsdk targetSdkVersion targetsdk versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:recyclerview-v7:'+androidlib compile 'com.android.support:design:'+androidlib compile 'com.intuit.sdp:sdp-android:1.0.5' compile project(':imageletter') } ================================================ FILE: app/proguard-rules.pro ================================================ # Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified # in D:\ide\android\Android SDK/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the proguardFiles # directive in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} ================================================ FILE: app/src/main/AndroidManifest.xml ================================================ ================================================ FILE: app/src/main/java/com/imagelettericon/MainActivity.java ================================================ package com.imagelettericon; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Color; import android.net.Uri; import android.os.Bundle; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.RelativeLayout; import android.widget.TextView; import com.github.akashandroid90.imageletter.MaterialLetterIcon; import java.util.Arrays; import java.util.List; import java.util.Random; public class MainActivity extends AppCompatActivity { private static final String[] desuNoto = { "Alane Avey", "Belen Brewster", "Brandon Brochu", "Carli Carrol", "Della Delrio", "Esther Echavarria", "Etha Edinger", "Felipe Flecha", "Ilse Island", "Kecia Keltz", "Lourie Lucas", "Lucille Leachman", "Mandi Mcqueeney", "Murray Matchett", "Nadia Nero", "Nannie Nipp", "Ozella Otis", "Pauletta Poehler", "Roderick Rippy", "Sherril Sager", "Taneka Tenorio", "Treena Trentham", "Ulrike Uhlman", "Virgina Viau", "Willis Wysocki" }; private static final String[] countries = { "Albania", "Australia", "Belgium", "Canada", "China", "Dominica", "Egypt", "Estonia", "Finland", "France", "Germany", "Honduras", "Italy", "Japan", "Madagascar", "Netherlands", "Norway", "Panama", "Portugal", "Romania", "Russia", "Slovakia", "Vatican", "Zimbabwe" }; private static final int CONTACTS = 0; private static final int COUNTRIES = 1; private static final int ALTERNATECOUNTRIES = 2; private static final int ALTERNATECONTACTS = 3; private static final Random RANDOM = new Random(); private RecyclerView recyclerView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recyclerView = (RecyclerView) findViewById(R.id.recyclerview); setupRecyclerView(); } @Override public boolean onCreateOptionsMenu(Menu menu) { final MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); return super.onCreateOptionsMenu(menu); } @Override public void onBackPressed() { showDialog(); } private void showDialog() { new AlertDialog.Builder(this).setMessage("Are you sure want to exit from app?").setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); finish(); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }).setNeutralButton("Rate us", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=com.imagelettericon")); startActivity(intent); } }).create().show(); } @Override public boolean onOptionsItemSelected(MenuItem item) { Intent intent; switch (item.getItemId()) { case R.id.contacts: setContactsAdapter(desuNoto); return true; case R.id.countries: setCountriesAdapter(countries); return true; case R.id.alternate_countries: setAlternateCountriesAdapter(countries); return true; case R.id.alternate_contacts: setAlternateContactsAdapter(countries); return true; case R.id.play_store: intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=com.imagelettericon")); startActivity(intent); return true; case R.id.other_apps: intent= new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://search?q=pub:AkashJain")); startActivity(intent); return true; case R.id.github: intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://github.com/akashandroid90/ImageLetterIcon")); startActivity(intent); return true; case R.id.share: Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Material Icon"); sendIntent.putExtra(Intent.EXTRA_TEXT, "http://play.google.com/store/apps/details?id=com.imagelettericon"); sendIntent.setType("text/plain"); startActivity(sendIntent); return true; } return super.onOptionsItemSelected(item); } private void setupRecyclerView() { recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext())); setContactsAdapter(desuNoto); } private void setContactsAdapter(String[] array) { recyclerView.setAdapter(new SimpleStringRecyclerViewAdapter(this, Arrays.asList(array), CONTACTS)); } private void setCountriesAdapter(String[] array) { recyclerView.setAdapter(new SimpleStringRecyclerViewAdapter(this, Arrays.asList(array), COUNTRIES)); } private void setAlternateCountriesAdapter(String[] array) { recyclerView.setAdapter(new SimpleStringRecyclerViewAdapter(this, Arrays.asList(array), ALTERNATECOUNTRIES)); } private void setAlternateContactsAdapter(String[] array) { recyclerView.setAdapter(new SimpleStringRecyclerViewAdapter(this, Arrays.asList(array), ALTERNATECONTACTS)); } public static class SimpleStringRecyclerViewAdapter extends RecyclerView.Adapter { private final TypedValue mTypedValue = new TypedValue(); private int mBackground; private List mValues; private int[] mMaterialColors; private int[] mImageResource; private int mType; SimpleStringRecyclerViewAdapter(Context context, List items, int type) { context.getTheme().resolveAttribute(R.attr.selectableItemBackground, mTypedValue, true); mMaterialColors = context.getResources().getIntArray(R.array.colors); mImageResource = new int[]{R.drawable.one, R.drawable.two, R.drawable.three, R.drawable.four, R.drawable.five, R.drawable.six, R.drawable.seven, R.drawable.eight, R.drawable.nine}; mBackground = mTypedValue.resourceId; mValues = items; mType = type; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false); view.setBackgroundResource(mBackground); return new ViewHolder(view); } @Override public void onBindViewHolder(final ViewHolder holder, int position) { switch (mType) { case CONTACTS: // holder.mIcon.setImageDrawable(TextDrawable.builder().beginConfig().textColor(Color.WHITE).bold().toUpperCase().endConfig().buildRect("aa",Color.RED)); holder.mIcon.setTextSize(18); holder.mIcon.setOval(false); holder.mIcon.setTextColor(Color.WHITE); holder.mIcon.setBorderColor(Color.BLACK); holder.mIcon.setBorderWidth(1); holder.mIcon.setShapeColor(mMaterialColors[RANDOM.nextInt(mMaterialColors.length)]); holder.mIcon.setText(mValues.get(position)); break; case COUNTRIES: holder.mIcon.setLetterCount(3); holder.mIcon.setTextSize(16); holder.mIcon.setOval(true); holder.mIcon.setText(mValues.get(position)); holder.mIcon.setShapeColor(mMaterialColors[RANDOM.nextInt(mMaterialColors.length)]); break; case ALTERNATECOUNTRIES: if (position % 2 == 0) { holder.mIcon.setOval(true); holder.mIcon.setImageResource(mImageResource[RANDOM.nextInt(mImageResource.length)]); } else { holder.mIcon.setOval(true); holder.mIcon.setShapeColor(mMaterialColors[RANDOM.nextInt(mMaterialColors.length)]); holder.mIcon.setText(mValues.get(position)); holder.mIcon.setLetterCount(2); holder.mIcon.setTextSize(18); } break; case ALTERNATECONTACTS: holder.mIcon.setCornerRadius(holder.itemView.getResources().getDimensionPixelSize(R.dimen._50sdp)); if (position % 2 == 0) { holder.mIcon.setOval(false); holder.mIcon.setImageResource(mImageResource[RANDOM.nextInt(mImageResource.length)]); } else { holder.mIcon.setOval(false); holder.mIcon.setShapeColor(mMaterialColors[RANDOM.nextInt(mMaterialColors.length)]); holder.mIcon.setText(mValues.get(position)); holder.mIcon.setLetterCount(2); holder.mIcon.setTextSize(18); } break; } holder.mBoundString = mValues.get(position); holder.mTextView.setText(mValues.get(position)); } @Override public int getItemCount() { return mValues.size(); } public class ViewHolder extends RecyclerView.ViewHolder { public final View mView; public final MaterialLetterIcon mIcon; public final TextView mTextView; public String mBoundString; public ViewHolder(View view) { super(view); mView = view; mIcon = (MaterialLetterIcon) view.findViewById(R.id.icon); mTextView = (TextView) view.findViewById(android.R.id.text1); } @Override public String toString() { return super.toString() + " '" + mTextView.getText(); } } } } ================================================ FILE: app/src/main/res/layout/activity_main.xml ================================================ ================================================ FILE: app/src/main/res/layout/list_item.xml ================================================ ================================================ FILE: app/src/main/res/menu/menu.xml ================================================ ================================================ FILE: app/src/main/res/values/arrays.xml ================================================ @color/color_1 @color/color_2 @color/color_3 @color/color_4 @color/color_5 @color/color_6 @color/color_7 @color/color_8 @color/color_9 @color/color_10 @color/color_11 ================================================ FILE: app/src/main/res/values/colors.xml ================================================ #3F51B5 #303F9F #FF4081 #DB4437 #E91E63 #FF5722 #EF6C00 #689F38 #0097A7 #4285F4 #039BE5 #3F51B5 #673AB7 #757575 ================================================ FILE: app/src/main/res/values/dimens.xml ================================================ 50dp ================================================ FILE: app/src/main/res/values/strings.xml ================================================ Material Icon Show countries Show alternate countries Show contacts Show alternate contacts ca-app-pub-5883105630361246/1929299012 ca-app-pub-5883105630361246/4184761412 Other Apps Github Play store Share ================================================ FILE: app/src/main/res/values/styles.xml ================================================ ================================================ FILE: app/src/main/res/values-w820dp/dimens.xml ================================================ 64dp ================================================ FILE: build.gradle ================================================ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } ext.buildtool = '26.0.2' ext.compilesdk = 26 ext.targetsdk = 26 ext.minsdk = 14 ext.androidlib = '26.0.0-alpha1' ext.playservicelib = '11.0.4' allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir } ================================================ FILE: gradle.properties ================================================ # Project-wide Gradle settings. # IDE (e.g. Android Studio) users: # Gradle settings configured through the IDE *will override* # any settings specified in this file. # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true ================================================ FILE: gradlew ================================================ #!/usr/bin/env bash ############################################################################## ## ## Gradle start up script for UN*X ## ############################################################################## # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS="" APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" warn ( ) { echo "$*" } die ( ) { echo echo "$*" echo exit 1 } # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false case "`uname`" in CYGWIN* ) cygwin=true ;; Darwin* ) darwin=true ;; MINGW* ) msys=true ;; esac # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" # Need this for relative symlinks. while [ -h "$PRG" ] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; then PRG="$link" else PRG=`dirname "$PRG"`"/$link" fi done SAVED="`pwd`" cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME="`pwd -P`" cd "$SAVED" >/dev/null CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else JAVACMD="java" which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then MAX_FD="$MAX_FD_LIMIT" fi ulimit -n $MAX_FD if [ $? -ne 0 ] ; then warn "Could not set maximum file descriptor limit: $MAX_FD" fi else warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" fi fi # For Darwin, add options to specify how the application appears in the dock if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi # For Cygwin, switch paths to Windows format before running java if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` SEP="" for dir in $ROOTDIRSRAW ; do ROOTDIRS="$ROOTDIRS$SEP$dir" SEP="|" done OURCYGPATTERN="(^($ROOTDIRS))" # Add a user-defined pattern to the cygpath arguments if [ "$GRADLE_CYGPATTERN" != "" ] ; then OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" fi # Now convert the arguments - kludge to limit ourselves to /bin/sh i=0 for arg in "$@" ; do CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` else eval `echo args$i`="\"$arg\"" fi i=$((i+1)) done case $i in (0) set -- ;; (1) set -- "$args0" ;; (2) set -- "$args0" "$args1" ;; (3) set -- "$args0" "$args1" "$args2" ;; (4) set -- "$args0" "$args1" "$args2" "$args3" ;; (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules function splitJvmOpts() { JVM_OPTS=("$@") } eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" ================================================ FILE: gradlew.bat ================================================ @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @rem @rem ########################################################################## @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS= set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if "%ERRORLEVEL%" == "0" goto init echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto init echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :init @rem Get command-line arguments, handling Windowz variants if not "%OS%" == "Windows_NT" goto win9xME_args if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. set CMD_LINE_ARGS= set _SKIP=2 :win9xME_args_slurp if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* goto execute :4NT_args @rem Get arguments from the 4NT Shell from JP Software set CMD_LINE_ARGS=%$ :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% :end @rem End local scope for the variables with windows NT shell if "%ERRORLEVEL%"=="0" goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 exit /b 1 :mainEnd if "%OS%"=="Windows_NT" endlocal :omega ================================================ FILE: imageletter/.gitignore ================================================ /build ================================================ FILE: imageletter/build.gradle ================================================ apply plugin: 'com.android.library' android { compileSdkVersion compilesdk buildToolsVersion buildtool defaultConfig { minSdkVersion minsdk targetSdkVersion targetsdk versionCode 1 versionName '1.13' } buildTypes { release { minifyEnabled false shrinkResources false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } configurations{ compile.exclude module: 'support-media-compat' compile.exclude module: 'support-core-utils' compile.exclude module: 'support-core-ui' compile.exclude module: 'animated-vector-drawable' compile.exclude module: 'support-fragment' } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:appcompat-v7:'+androidlib } ================================================ FILE: imageletter/proguard-rules.pro ================================================ # Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified # in D:\ide\android\Android SDK/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the proguardFiles # directive in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} #-optimizationpasses 5 #-renamesourcefileattribute SourceFile #-optimizations !code/simplification/advanced,code/simplification/* # ##-keep public class * extends View { ##public (android.content.Context); ##public (android.content.Context, android.util.AttributeSet); ##public (android.content.Context, android.util.AttributeSet, int); ##public void set*(...); ##} # #-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } # #-keep class com.github.akashandroid90.imageletter.** { *; } # -keep public class * extends android.view.View { void set*(***); *** get*(); } ================================================ FILE: imageletter/src/main/AndroidManifest.xml ================================================ ================================================ FILE: imageletter/src/main/java/com/github/akashandroid90/imageletter/MaterialLetterIcon.java ================================================ package com.github.akashandroid90.imageletter; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.TypedArray; import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.text.TextUtils; import android.util.AttributeSet; import android.util.TypedValue; import com.github.akashandroid90.imageletter.drawable.TextDrawable; public class MaterialLetterIcon extends RoundedImageViewWithBorder { private TextDrawable.IShapeBuilder mBuilder; private String mText; private int mTextSize; private int mTextColor; private int mShapeColor; private int mLetterCount; private Typeface mTypeface; private boolean bold, uppercase; private boolean mOval; public MaterialLetterIcon(Context context) { this(context, null); } public MaterialLetterIcon(Context context, AttributeSet attrs) { this(context, attrs, 0); } public MaterialLetterIcon(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mBuilder = TextDrawable.builder(); TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.MaterialLetterIcon, defStyle, 0); mLetterCount = attr.getInt(R.styleable.MaterialLetterIcon_text_number, 2); mTextSize = attr.getInt(R.styleable.MaterialLetterIcon_text_size, 26); mTextColor = attr.getColor(R.styleable.MaterialLetterIcon_text_color, Color.WHITE); mShapeColor = attr.getColor(R.styleable.MaterialLetterIcon_shape_color, Color.RED); bold = attr.getBoolean(R.styleable.MaterialLetterIcon_is_bold, false); uppercase = attr.getBoolean(R.styleable.MaterialLetterIcon_is_uppercase, false); computeText(attr.getString(R.styleable.MaterialLetterIcon_text)); attr.recycle(); updateDrawable(); } private int toPx(int dp) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics()); } private void updateDrawable() { if (TextUtils.isEmpty(mText)) { return; } TextDrawable.IConfigBuilder iConfigBuilder = mBuilder.beginConfig().withBorder(getBorderWidth()).textColor(mTextColor).borderColor(getBorderColor()); if (mTypeface != null) iConfigBuilder.useFont(mTypeface); if (mTextSize > 0) iConfigBuilder.fontSize(toPx(mTextSize)); if (isBold()) iConfigBuilder.bold(); if (isUppercase()) iConfigBuilder.toUpperCase(); mBuilder = iConfigBuilder.endConfig(); Drawable mDrawable; if (isOval()) mDrawable = mBuilder.buildRound(mText, mShapeColor); else if (getCornerRadius() > 0) mDrawable = mBuilder.buildRoundRect(mText, mShapeColor, getCornerRadius() / 5); else mDrawable = mBuilder.buildRect(mText, mShapeColor); setImageDrawable(mDrawable); } private void computeText(String text) { if (TextUtils.isEmpty(text)) { return; } String initials[] = text.split("\\s+"); StringBuilder initialsPlain = new StringBuilder(mLetterCount); for (String initial : initials) { initialsPlain.append(initial.substring(0, 1)); } mText = initialsPlain.toString(); mText = mText.substring(0, mLetterCount > mText.length() ? mText.length() : mLetterCount); } public String getText() { return mText; } public void setText(String text) { computeText(text); updateDrawable(); } public int getTextSize() { return mTextSize; } public void setTextSize(int textSize) { mTextSize = textSize; updateDrawable(); } public void setTypeface(Typeface typeface) { mTypeface = typeface; updateDrawable(); } public Typeface getTypeFace() { return mTypeface; } public int getShapeColor() { return mShapeColor; } public void setShapeColor(@ColorInt int color) { mShapeColor = color; updateDrawable(); } public int getTextColor() { return mTextColor; } public void setTextColor(@ColorInt int color) { mTextColor = color; updateDrawable(); } public boolean isBold() { return bold; } public void setBold(boolean bold) { this.bold = bold; } public boolean isUppercase() { return uppercase; } public void setUppercase(boolean uppercase) { this.uppercase = uppercase; } public int getLetterCount() { return mLetterCount; } public void setLetterCount(int mLetterCount) { this.mLetterCount = mLetterCount; } public void setBorderColor(int color) { setBorderColors(ColorStateList.valueOf(color)); } } ================================================ FILE: imageletter/src/main/java/com/github/akashandroid90/imageletter/RoundedImageViewWithBorder.java ================================================ package com.github.akashandroid90.imageletter; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.net.Uri; import android.os.Build; import android.support.v7.content.res.AppCompatResources; import android.util.AttributeSet; import com.github.akashandroid90.imageletter.drawable.RoundedDrawable; import java.io.FileNotFoundException; import java.io.InputStream; public class RoundedImageViewWithBorder extends TintableImageView { public static final int DEFAULT_RADIUS = 0; public static final int DEFAULT_BORDER_WIDTH = 0; private static final ScaleType[] sScaleTypeArray = { ScaleType.MATRIX, ScaleType.FIT_XY, ScaleType.FIT_START, ScaleType.FIT_CENTER, ScaleType.FIT_END, ScaleType.CENTER, ScaleType.CENTER_CROP, ScaleType.CENTER_INSIDE }; private int mCornerRadius = DEFAULT_RADIUS; private int mBorderWidth = DEFAULT_BORDER_WIDTH; private ColorStateList mBorderColor = ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR); private boolean mOval = false; private boolean mRoundBackground = false; private int mResource; private Drawable mDrawable; private Drawable mBackgroundDrawable; private ScaleType mScaleType; public RoundedImageViewWithBorder(Context context) { this(context, null); } public RoundedImageViewWithBorder(Context context, AttributeSet attrs) { this(context, attrs, 0); } public RoundedImageViewWithBorder(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundedImageView, defStyle, 0); int index = a.getInt(R.styleable.RoundedImageView_android_scaleType, -1); if (index >= 0) { setScaleType(sScaleTypeArray[index]); } mCornerRadius = a.getDimensionPixelSize(R.styleable.RoundedImageView_corner_radius, -1); mBorderWidth = a.getDimensionPixelSize(R.styleable.RoundedImageView_border_width, -1); // don't allow negative values for radius and border if (mCornerRadius < 0) { mCornerRadius = DEFAULT_RADIUS; } if (mBorderWidth < 0) { mBorderWidth = DEFAULT_BORDER_WIDTH; } mBorderColor = a.getColorStateList(R.styleable.RoundedImageView_border_color); if (mBorderColor == null) { mBorderColor = ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR); } mRoundBackground = a.getBoolean(R.styleable.RoundedImageView_round_background, false); mOval = a.getBoolean(R.styleable.RoundedImageView_is_oval, false); updateDrawableAttrs(); updateBackgroundDrawableAttrs(); a.recycle(); } @Override protected void drawableStateChanged() { super.drawableStateChanged(); invalidate(); } @Override public ScaleType getScaleType() { return mScaleType; } @Override public void setScaleType(ScaleType scaleType) { if (scaleType == null) { throw new NullPointerException(); } if (mScaleType != scaleType) { mScaleType = scaleType; switch (scaleType) { case CENTER: case CENTER_CROP: case CENTER_INSIDE: case FIT_CENTER: case FIT_START: case FIT_END: case FIT_XY: super.setScaleType(ScaleType.FIT_XY); break; default: super.setScaleType(scaleType); break; } updateDrawableAttrs(); updateBackgroundDrawableAttrs(); invalidate(); } } @Override public void setImageDrawable(Drawable drawable) { mResource = 0; mDrawable = RoundedDrawable.fromDrawable(drawable); updateDrawableAttrs(); super.setImageDrawable(mDrawable); } @Override public void setImageBitmap(Bitmap bm) { mResource = 0; mDrawable = RoundedDrawable.fromBitmap(bm); updateDrawableAttrs(); super.setImageDrawable(mDrawable); } @Override public void setImageURI(Uri uri) { mResource = 0; try { InputStream inputStream = getContext().getContentResolver().openInputStream(uri); mDrawable = Drawable.createFromStream(inputStream, uri.toString()); } catch (FileNotFoundException e) { e.printStackTrace(); } mDrawable = RoundedDrawable.fromDrawable(mDrawable); updateDrawableAttrs(); super.setImageDrawable(mDrawable); } @Override public void setImageResource(int resId) { if (mResource != resId) { mResource = resId; mDrawable = resolveResource(); updateDrawableAttrs(); super.setImageDrawable(mDrawable); } } private Drawable resolveResource() { Drawable d = null; if (mResource != 0) { try { d = AppCompatResources.getDrawable(getContext(), mResource); } catch (Exception e) { mResource = 0; } } return RoundedDrawable.fromDrawable(d); } @Override public void setBackground(Drawable background) { setBackgroundDrawable(background); } private void updateDrawableAttrs() { updateAttrs(mDrawable, false); } private void updateBackgroundDrawableAttrs() { updateAttrs(mBackgroundDrawable, true); } private void updateAttrs(Drawable drawable, boolean background) { if (drawable == null) { return; } if (drawable instanceof RoundedDrawable) { ((RoundedDrawable) drawable) .setScaleType(mScaleType) .setCornerRadius(background && !mRoundBackground ? 0 : mCornerRadius) .setBorderWidth(mBorderWidth) .setBorderColors(mBorderColor) .setOval(mOval); } else if (drawable instanceof LayerDrawable) { // loop through layers to and set drawable attrs LayerDrawable ld = ((LayerDrawable) drawable); int layers = ld.getNumberOfLayers(); for (int i = 0; i < layers; i++) { updateAttrs(ld.getDrawable(i), background); } } } @Override public void setBackgroundDrawable(Drawable background) { mBackgroundDrawable = RoundedDrawable.fromDrawable(background); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) super.setBackground(mBackgroundDrawable); else super.setBackgroundDrawable(mBackgroundDrawable); } public int getCornerRadius() { return mCornerRadius; } public void setCornerRadius(int radius) { if (mCornerRadius == radius) { return; } mCornerRadius = radius; updateDrawableAttrs(); updateBackgroundDrawableAttrs(); } public int getBorderWidth() { return mBorderWidth; } public void setBorderWidth(int width) { if (mBorderWidth == width) { return; } mBorderWidth = width; updateDrawableAttrs(); updateBackgroundDrawableAttrs(); invalidate(); } public int getBorderColor() { if (mBorderColor != null) return mBorderColor.getDefaultColor(); else return RoundedDrawable.DEFAULT_BORDER_COLOR; } public void setBorderColor(int color) { setBorderColors(ColorStateList.valueOf(color)); } public ColorStateList getBorderColors() { return mBorderColor; } public void setBorderColors(ColorStateList colors) { if (mBorderColor.equals(colors)) { return; } mBorderColor = (colors != null) ? colors : ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR); updateDrawableAttrs(); updateBackgroundDrawableAttrs(); if (mBorderWidth > 0) { invalidate(); } } public boolean isOval() { return mOval; } public void setOval(boolean oval) { mOval = oval; updateDrawableAttrs(); updateBackgroundDrawableAttrs(); invalidate(); } public boolean isRoundBackground() { return mRoundBackground; } public void setRoundBackground(boolean roundBackground) { if (mRoundBackground == roundBackground) { return; } mRoundBackground = roundBackground; updateBackgroundDrawableAttrs(); invalidate(); } } ================================================ FILE: imageletter/src/main/java/com/github/akashandroid90/imageletter/TintableImageView.java ================================================ package com.github.akashandroid90.imageletter; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.TypedArray; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.support.v4.content.ContextCompat; import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v7.widget.AppCompatImageView; import android.util.AttributeSet; public class TintableImageView extends AppCompatImageView { private ColorStateList mTint, mBackgroundTint; public TintableImageView(Context context) { super(context); } public TintableImageView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public TintableImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TintableImageView, defStyle, 0); mTint = a.getColorStateList(R.styleable.TintableImageView_image_tint); mBackgroundTint = a.getColorStateList(R.styleable.TintableImageView_background_tint); a.recycle(); } @Override protected void drawableStateChanged() { super.drawableStateChanged(); if (mTint != null) { if (mTint.isStateful()) setColorFilter(mTint.getColorForState(getDrawableState(), 0)); else setColorFilter(mTint); } Drawable drawable = getBackground(); if (mBackgroundTint != null && drawable != null) { Drawable wrap = DrawableCompat.wrap(drawable); wrap = wrap.mutate(); if (mBackgroundTint.isStateful()) DrawableCompat.setTint(wrap, ContextCompat.getColor(getContext(), mBackgroundTint.getColorForState(getDrawableState(), 0))); else DrawableCompat.setTintList(wrap, mBackgroundTint); DrawableCompat.setTintMode(wrap, PorterDuff.Mode.SRC_IN); } } public void removeTint() { mTint = null; clearColorFilter(); } public void setColorFilter(ColorStateList tint) { this.mTint = tint; setColorFilter(tint.getColorForState(getDrawableState(), 0)); } } ================================================ FILE: imageletter/src/main/java/com/github/akashandroid90/imageletter/drawable/RoundedDrawable.java ================================================ package com.github.akashandroid90.imageletter.drawable; import android.content.res.ColorStateList; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.BitmapShader; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Shader; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.widget.ImageView.ScaleType; public class RoundedDrawable extends Drawable { public static final int DEFAULT_BORDER_COLOR = Color.BLACK; private final RectF mBounds = new RectF(); private final RectF mDrawableRect = new RectF(); private final RectF mBitmapRect = new RectF(); private final BitmapShader mBitmapShader; private final Paint mBitmapPaint; private final int mBitmapWidth; private final int mBitmapHeight; private final RectF mBorderRect = new RectF(); private final Paint mBorderPaint; private final Matrix mShaderMatrix = new Matrix(); private ColorStateList mBorderColor = ColorStateList.valueOf(DEFAULT_BORDER_COLOR); private float mCornerRadius = 0; private boolean mOval = false; private float mBorderWidth = 0; private ScaleType mScaleType = ScaleType.FIT_XY; public RoundedDrawable(Bitmap bitmap) { mBitmapWidth = bitmap.getWidth(); mBitmapHeight = bitmap.getHeight(); mBitmapRect.set(0, 0, mBitmapWidth, mBitmapHeight); mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); mBitmapShader.setLocalMatrix(mShaderMatrix); mBitmapPaint = new Paint(); mBitmapPaint.setStyle(Paint.Style.FILL); mBitmapPaint.setAntiAlias(true); mBitmapPaint.setShader(mBitmapShader); mBorderPaint = new Paint(); mBorderPaint.setStyle(Paint.Style.STROKE); if(mBorderColor!=null){ if (mBorderColor.isStateful()) mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR)); else mBorderPaint.setColor(mBorderColor.getDefaultColor()); } else mBorderPaint.setColor(DEFAULT_BORDER_COLOR); mBorderPaint.setStrokeWidth(mBorderWidth); } public static Drawable fromBitmap(Bitmap bitmap) { if (bitmap != null) { return new RoundedDrawable(bitmap); } else { return null; } } public static Drawable fromDrawable(Drawable drawable) { if (drawable != null) { if (drawable instanceof RoundedDrawable) { // just return if it's already a RoundedDrawable return drawable; } else if (drawable instanceof ColorDrawable) { // FIXME we don't support ColorDrawables yet return drawable; } else if (drawable instanceof LayerDrawable) { LayerDrawable ld = (LayerDrawable) drawable; int num = ld.getNumberOfLayers(); // loop through layers to and change to RoundedDrawables if possible for (int i = 0; i < num; i++) { Drawable d = ld.getDrawable(i); ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d)); } return ld; } // try to get a bitmap from the drawable and Bitmap bm = drawableToBitmap(drawable); if (bm != null) { return new RoundedDrawable(bm); } } return drawable; } public static Bitmap drawableToBitmap(Drawable drawable) { if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); } Bitmap bitmap; int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); if (width > 0 && height > 0) { bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); } else { bitmap = null; } return bitmap; } @Override public boolean isStateful() { return mBorderColor.isStateful(); } @Override protected boolean onStateChange(int[] state) { int newColor = mBorderColor.getColorForState(state, 0); if (mBorderPaint.getColor() != newColor) { mBorderPaint.setColor(newColor); return true; } else { return super.onStateChange(state); } } private void updateShaderMatrix() { mBorderRect.set(mBounds); mDrawableRect.set(mBorderWidth, mBorderWidth, mBorderRect.width() - mBorderWidth, mBorderRect.height() - mBorderWidth); float scale; float dx; float dy; switch (mScaleType) { case CENTER: mBorderRect.set(mBounds); mDrawableRect.set(mBorderWidth, mBorderWidth, mBorderRect.width() - mBorderWidth, mBorderRect.height() - mBorderWidth); mShaderMatrix.set(null); mShaderMatrix.setTranslate((int) ((mDrawableRect.width() - mBitmapWidth) * 0.5f + 0.5f), (int) ((mDrawableRect.height() - mBitmapHeight) * 0.5f + 0.5f)); break; case CENTER_CROP: mBorderRect.set(mBounds); mDrawableRect.set(mBorderWidth, mBorderWidth, mBorderRect.width() - mBorderWidth, mBorderRect.height() - mBorderWidth); mShaderMatrix.set(null); dx = 0; dy = 0; if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width() * mBitmapHeight) { scale = mDrawableRect.height() / (float) mBitmapHeight; dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f; } else { scale = mDrawableRect.width() / (float) mBitmapWidth; dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f; } mShaderMatrix.setScale(scale, scale); mShaderMatrix.postTranslate((int) (dx + 0.5f) + mBorderWidth, (int) (dy + 0.5f) + mBorderWidth); break; case CENTER_INSIDE: mShaderMatrix.set(null); if (mBitmapWidth <= mBounds.width() && mBitmapHeight <= mBounds.height()) { scale = 1.0f; } else { scale = Math.min(mBounds.width() / (float) mBitmapWidth, mBounds.height() / (float) mBitmapHeight); } dx = (int) ((mBounds.width() - mBitmapWidth * scale) * 0.5f + 0.5f); dy = (int) ((mBounds.height() - mBitmapHeight * scale) * 0.5f + 0.5f); mShaderMatrix.setScale(scale, scale); mShaderMatrix.postTranslate(dx, dy); mBorderRect.set(mBitmapRect); mShaderMatrix.mapRect(mBorderRect); mDrawableRect.set(mBorderRect.left + mBorderWidth, mBorderRect.top + mBorderWidth, mBorderRect.right - mBorderWidth, mBorderRect.bottom - mBorderWidth); mShaderMatrix.setRectToRect(mBitmapRect, mDrawableRect, Matrix.ScaleToFit.FILL); break; case FIT_CENTER: mBorderRect.set(mBitmapRect); mShaderMatrix.setRectToRect(mBitmapRect, mBounds, Matrix.ScaleToFit.CENTER); mShaderMatrix.mapRect(mBorderRect); mDrawableRect.set(mBorderRect.left + mBorderWidth, mBorderRect.top + mBorderWidth, mBorderRect.right - mBorderWidth, mBorderRect.bottom - mBorderWidth); mShaderMatrix.setRectToRect(mBitmapRect, mDrawableRect, Matrix.ScaleToFit.FILL); break; case FIT_END: mBorderRect.set(mBitmapRect); mShaderMatrix.setRectToRect(mBitmapRect, mBounds, Matrix.ScaleToFit.END); mShaderMatrix.mapRect(mBorderRect); mDrawableRect.set(mBorderRect.left + mBorderWidth, mBorderRect.top + mBorderWidth, mBorderRect.right - mBorderWidth, mBorderRect.bottom - mBorderWidth); mShaderMatrix.setRectToRect(mBitmapRect, mDrawableRect, Matrix.ScaleToFit.FILL); break; case FIT_START: mBorderRect.set(mBitmapRect); mShaderMatrix.setRectToRect(mBitmapRect, mBounds, Matrix.ScaleToFit.START); mShaderMatrix.mapRect(mBorderRect); mDrawableRect.set(mBorderRect.left + mBorderWidth, mBorderRect.top + mBorderWidth, mBorderRect.right - mBorderWidth, mBorderRect.bottom - mBorderWidth); mShaderMatrix.setRectToRect(mBitmapRect, mDrawableRect, Matrix.ScaleToFit.FILL); break; case FIT_XY: default: mBorderRect.set(mBounds); mDrawableRect.set(0 + mBorderWidth, 0 + mBorderWidth, mBorderRect.width() - mBorderWidth, mBorderRect.height() - mBorderWidth); mShaderMatrix.set(null); mShaderMatrix.setRectToRect(mBitmapRect, mDrawableRect, Matrix.ScaleToFit.FILL); break; } mBorderRect.inset(mBorderWidth / 2, mBorderWidth / 2); mBitmapShader.setLocalMatrix(mShaderMatrix); } @Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); mBounds.set(bounds); updateShaderMatrix(); } @Override public void draw(Canvas canvas) { if (mOval) { if (mBorderWidth > 0) { canvas.drawOval(mBorderRect, mBorderPaint); canvas.drawOval(mDrawableRect, mBitmapPaint); } else { canvas.drawOval(mDrawableRect, mBitmapPaint); } } else { if (mBorderWidth > 0) { canvas.drawRoundRect(mBorderRect, mCornerRadius, mCornerRadius, mBorderPaint); canvas.drawRoundRect(mDrawableRect, Math.max(mCornerRadius - mBorderWidth, 0), Math.max(mCornerRadius - mBorderWidth, 0), mBitmapPaint); } else { canvas.drawRoundRect(mDrawableRect, mCornerRadius, mCornerRadius, mBitmapPaint); } } } @Override public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Override public void setAlpha(int alpha) { mBitmapPaint.setAlpha(alpha); invalidateSelf(); } @Override public void setColorFilter(ColorFilter cf) { mBitmapPaint.setColorFilter(cf); invalidateSelf(); } @Override public void setDither(boolean dither) { mBitmapPaint.setDither(dither); invalidateSelf(); } @Override public void setFilterBitmap(boolean filter) { mBitmapPaint.setFilterBitmap(filter); invalidateSelf(); } @Override public int getIntrinsicWidth() { return mBitmapWidth; } @Override public int getIntrinsicHeight() { return mBitmapHeight; } public float getCornerRadius() { return mCornerRadius; } public RoundedDrawable setCornerRadius(float radius) { mCornerRadius = radius; return this; } public float getBorderWidth() { return mBorderWidth; } public RoundedDrawable setBorderWidth(int width) { mBorderWidth = width*5; mBorderPaint.setStrokeWidth(mBorderWidth); return this; } public int getBorderColor() { if(mBorderColor!=null) return mBorderColor.getDefaultColor(); else return DEFAULT_BORDER_COLOR; } public RoundedDrawable setBorderColor(int color) { return setBorderColors(ColorStateList.valueOf(color)); } public ColorStateList getBorderColors() { return mBorderColor; } public RoundedDrawable setBorderColors(ColorStateList colors) { mBorderColor = colors != null ? colors : ColorStateList.valueOf(0); if (mBorderColor.isStateful()) mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR)); else mBorderPaint.setColor(mBorderColor.getDefaultColor()); return this; } public boolean isOval() { return mOval; } public RoundedDrawable setOval(boolean oval) { mOval = oval; return this; } public ScaleType getScaleType() { return mScaleType; } public RoundedDrawable setScaleType(ScaleType scaleType) { if (scaleType == null) { scaleType = ScaleType.FIT_XY; } if (mScaleType != scaleType) { mScaleType = scaleType; updateShaderMatrix(); } return this; } } ================================================ FILE: imageletter/src/main/java/com/github/akashandroid90/imageletter/drawable/TextDrawable.java ================================================ package com.github.akashandroid90.imageletter.drawable; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Typeface; import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.OvalShape; import android.graphics.drawable.shapes.RectShape; import android.graphics.drawable.shapes.RoundRectShape; public class TextDrawable extends ShapeDrawable { private static final float SHADE_FACTOR = 0.9f; private final Paint textPaint; private final Paint borderPaint; private final String text; private final int color; private final int borderColor; private final RectShape shape; private final int height; private final int width; private final int fontSize; private final float radius; private final int borderThickness; private TextDrawable(Builder builder) { super(builder.shape); // shape properties shape = builder.shape; height = builder.height; width = builder.width; radius = builder.radius; // text and color text = builder.toUpperCase ? builder.text.toUpperCase() : builder.text; color = builder.color; borderColor = builder.borderColor; // text paint settings fontSize = builder.fontSize; textPaint = new Paint(); textPaint.setColor(builder.textColor); textPaint.setAntiAlias(true); textPaint.setFakeBoldText(builder.isBold); textPaint.setStyle(Paint.Style.FILL); textPaint.setTypeface(builder.font); textPaint.setTextAlign(Paint.Align.CENTER); textPaint.setStrokeWidth(builder.borderThickness); // border paint settings borderThickness = builder.borderThickness; borderPaint = new Paint(); borderPaint.setColor(borderColor); borderPaint.setStyle(Paint.Style.STROKE); borderPaint.setStrokeWidth(borderThickness); // drawable paint color Paint paint = getPaint(); paint.setColor(color); } private static int getDarkerShade(int color) { return Color.rgb((int) (SHADE_FACTOR * Color.red(color)), (int) (SHADE_FACTOR * Color.green(color)), (int) (SHADE_FACTOR * Color.blue(color))); } public static IShapeBuilder builder() { return new Builder(); } @Override public void draw(Canvas canvas) { super.draw(canvas); Rect r = getBounds(); // draw border if (borderThickness > 0) { drawBorder(canvas); } int count = canvas.save(); canvas.translate(r.left, r.top); // draw text int width = this.width < 0 ? r.width() : this.width; int height = this.height < 0 ? r.height() : this.height; int fontSize = this.fontSize < 0 ? (Math.min(width, height) / 2) : this.fontSize; textPaint.setTextSize(fontSize); canvas.drawText(text, width / 2, height / 2 - ((textPaint.descent() + textPaint.ascent()) / 2), textPaint); canvas.restoreToCount(count); } private void drawBorder(Canvas canvas) { RectF rect = new RectF(getBounds()); rect.inset(borderThickness / 2, borderThickness / 2); if (shape instanceof OvalShape) { canvas.drawOval(rect, borderPaint); } else if (shape instanceof RoundRectShape) { canvas.drawRoundRect(rect, radius, radius, borderPaint); } else { canvas.drawRect(rect, borderPaint); } } @Override public void setAlpha(int alpha) { textPaint.setAlpha(alpha); } @Override public void setColorFilter(ColorFilter cf) { textPaint.setColorFilter(cf); } @Override public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Override public int getIntrinsicWidth() { return width; } @Override public int getIntrinsicHeight() { return height; } public interface IConfigBuilder { IConfigBuilder width(int width); IConfigBuilder height(int height); IConfigBuilder textColor(int color); IConfigBuilder borderColor(int color); IConfigBuilder withBorder(int thickness); IConfigBuilder useFont(Typeface font); IConfigBuilder fontSize(int size); IConfigBuilder bold(); IConfigBuilder toUpperCase(); IShapeBuilder endConfig(); } public interface IBuilder { TextDrawable build(String text, int color); } public interface IShapeBuilder { IConfigBuilder beginConfig(); IBuilder rect(); IBuilder round(); IBuilder roundRect(int radius); TextDrawable buildRect(String text, int color); TextDrawable buildRoundRect(String text, int color, int radius); TextDrawable buildRound(String text, int color); } public static class Builder implements IConfigBuilder, IShapeBuilder, IBuilder { private String text; private int color; private int borderColor; private int borderThickness; private int width; private int height; private Typeface font; private RectShape shape; private int textColor; private int fontSize; private boolean isBold; private boolean toUpperCase; private float radius; private Builder() { text = ""; color = Color.GRAY; borderColor = getDarkerShade(color); textColor = Color.WHITE; borderThickness = 0; width = -1; height = -1; shape = new RectShape(); font = Typeface.DEFAULT; fontSize = -1; isBold = false; toUpperCase = false; } public IConfigBuilder width(int width) { this.width = width; return this; } public IConfigBuilder height(int height) { this.height = height; return this; } public IConfigBuilder textColor(int color) { this.textColor = color; return this; } public IConfigBuilder borderColor(int color) { this.borderColor = color; return this; } public IConfigBuilder withBorder(int thickness) { this.borderThickness = thickness; return this; } public IConfigBuilder useFont(Typeface font) { this.font = font; return this; } public IConfigBuilder fontSize(int size) { this.fontSize = size; return this; } public IConfigBuilder bold() { this.isBold = true; return this; } public IConfigBuilder toUpperCase() { this.toUpperCase = true; return this; } @Override public IConfigBuilder beginConfig() { return this; } @Override public IShapeBuilder endConfig() { return this; } @Override public IBuilder rect() { this.shape = new RectShape(); return this; } @Override public IBuilder round() { this.shape = new OvalShape(); return this; } @Override public IBuilder roundRect(int radius) { this.radius = radius; float[] radii = {radius, radius, radius, radius, radius, radius, radius, radius}; this.shape = new RoundRectShape(radii, null, null); return this; } @Override public TextDrawable buildRect(String text, int color) { rect(); return build(text, color); } @Override public TextDrawable buildRoundRect(String text, int color, int radius) { roundRect(radius); return build(text, color); } @Override public TextDrawable buildRound(String text, int color) { round(); return build(text, color); } @Override public TextDrawable build(String text, int color) { this.color = color; this.text = text; return new TextDrawable(this); } } } ================================================ FILE: imageletter/src/main/res/values/attrs.xml ================================================ ================================================ FILE: settings.gradle ================================================ include ':app', ':imageletter'