├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── dictionaries │ └── Adil.xml ├── encodings.xml ├── gradle.xml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── markdown-navigator.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── MaterialPickerDialog ├── bintray.gradle ├── build.gradle ├── install.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── adil │ │ └── dev │ │ └── lib │ │ └── materialnumberpicker │ │ ├── adapter │ │ ├── GenderAdapter.java │ │ └── NumberPickerAdapter.java │ │ ├── dialog │ │ ├── GenderPickerDialog.java │ │ └── NumberPickerDialog.java │ │ └── model │ │ ├── GenderModel.java │ │ └── IntervalModel.java │ └── res │ ├── drawable │ ├── ic_round_shape_selected.xml │ └── ic_round_shape_unselected.xml │ ├── layout │ ├── gender_picker_dialog.xml │ ├── interval_picker_dialog.xml │ └── picker_item.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ └── strings.xml ├── README.md ├── app ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── adil │ │ └── dev │ │ └── lib │ │ └── material_number_picker │ │ └── MainActivity.java │ └── res │ ├── layout │ └── activity_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshot_1.png ├── screenshot_2.png └── settings.gradle /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/dictionaries/Adil.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1097 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 33 | 34 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Abstraction issuesJava 39 | 40 | 41 | Android > Lint > Correctness 42 | 43 | 44 | Android > Lint > Internationalization > Bidirectional Text 45 | 46 | 47 | Android > Lint > Performance 48 | 49 | 50 | Android > Lint > Security 51 | 52 | 53 | Android > Lint > Usability 54 | 55 | 56 | Android Lint for Kotlin 57 | 58 | 59 | Assignment issuesGroovy 60 | 61 | 62 | Assignment issuesJava 63 | 64 | 65 | Class structureJava 66 | 67 | 68 | Cloning issuesJava 69 | 70 | 71 | Code style issuesJava 72 | 73 | 74 | Concurrency annotation issuesJava 75 | 76 | 77 | Control FlowGroovy 78 | 79 | 80 | Control flow issuesJava 81 | 82 | 83 | Declaration redundancyJava 84 | 85 | 86 | Dependency issuesJava 87 | 88 | 89 | Encapsulation issuesJava 90 | 91 | 92 | Error handlingGroovy 93 | 94 | 95 | Error handlingJava 96 | 97 | 98 | General 99 | 100 | 101 | Groovy 102 | 103 | 104 | Inheritance issuesJava 105 | 106 | 107 | Initialization issuesJava 108 | 109 | 110 | Internationalization issuesJava 111 | 112 | 113 | JUnit issuesJava 114 | 115 | 116 | Java 117 | 118 | 119 | Memory issuesJava 120 | 121 | 122 | Method MetricsGroovy 123 | 124 | 125 | Naming ConventionsGroovy 126 | 127 | 128 | Naming conventionsJava 129 | 130 | 131 | Numeric issuesJava 132 | 133 | 134 | Pattern Validation 135 | 136 | 137 | Performance issuesJava 138 | 139 | 140 | Potentially confusing code constructsGroovy 141 | 142 | 143 | Probable bugsGroovy 144 | 145 | 146 | Probable bugsJava 147 | 148 | 149 | Resource management issuesJava 150 | 151 | 152 | Security issuesJava 153 | 154 | 155 | Serialization issuesJava 156 | 157 | 158 | TestNGJava 159 | 160 | 161 | Threading issuesGroovy 162 | 163 | 164 | Threading issuesJava 165 | 166 | 167 | Visibility issuesJava 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 189 | 190 | 191 | 192 | 193 | 1.8 194 | 195 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 211 | 212 | 213 | 214 | 215 | 216 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /MaterialPickerDialog/bintray.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.jfrog.bintray' 2 | 3 | version = '0.0.1' 4 | 5 | if (project.hasProperty("android")) { // Android libraries 6 | task sourcesJar(type: Jar) { 7 | classifier = 'sources' 8 | from android.sourceSets.main.java.srcDirs 9 | } 10 | 11 | task javadoc(type: Javadoc) { 12 | source = android.sourceSets.main.java.srcDirs 13 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 14 | } 15 | } else { // Java libraries 16 | task sourcesJar(type: Jar, dependsOn: classes) { 17 | classifier = 'sources' 18 | from sourceSets.main.allSource 19 | } 20 | } 21 | 22 | task javadocJar(type: Jar, dependsOn: javadoc) { 23 | classifier = 'javadoc' 24 | from javadoc.destinationDir 25 | } 26 | 27 | artifacts { 28 | archives javadocJar 29 | archives sourcesJar 30 | } 31 | 32 | // Bintray 33 | Properties properties = new Properties() 34 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 35 | 36 | bintray { 37 | user = properties.getProperty("bintray.user") 38 | key = properties.getProperty("bintray.apikey") 39 | 40 | configurations = ['archives'] 41 | pkg { 42 | repo = 'maven' 43 | name = 'AndroidMaterialPickerDialog' 44 | desc = 'Simple Material Picker Dialog Library which offer developers different kind of material dialogs like, gender picker, number picker.' 45 | websiteUrl = 'https://github.com/ch-muhammad-adil/Android-Material-Picker-Dialog' 46 | issueTrackerUrl = websiteUrl+'/issues' 47 | vcsUrl = 'https://github.com/ch-muhammad-adil/Android-Material-Picker-Dialog.git' 48 | licenses = ["Apache-2.0"] 49 | githubRepo = 'https://github.com/ch-muhammad-adil/Android-Material-Picker-Dialog' //Optional Github repository 50 | githubReleaseNotesFile = 'README.md' //Optional Github readme file 51 | publish = true 52 | publicDownloadNumbers = true 53 | version { 54 | desc = 'Simple Material Picker Dialog Library which offer developers different kind of material dialogs like, gender picker, number picker.' 55 | gpg { 56 | sign = true //Determines whether to GPG sign the files. The default is false 57 | passphrase = properties.getProperty("bintray.gpg.password") 58 | //Optional. The passphrase for GPG signing' 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /MaterialPickerDialog/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | apply plugin: "com.jfrog.bintray" 4 | 5 | // This is the library version used when deploying the artifact 6 | version = "1.0.3" 7 | //./gradlew bintrayUpload 8 | android { 9 | compileSdkVersion 25 10 | buildToolsVersion "25.0.2" 11 | 12 | defaultConfig { 13 | minSdkVersion 14 14 | targetSdkVersion 25 15 | versionCode 1 16 | versionName "1.0" 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | compile fileTree(dir: 'libs', include: ['*.jar']) 28 | compile 'com.android.support:appcompat-v7:25.1.1' 29 | compile 'com.android.support:design:25.1.1' 30 | compile 'com.android.support:cardview-v7:25.1.1' 31 | compile 'com.android.support:recyclerview-v7:25.1.1' 32 | 33 | } 34 | 35 | def siteUrl = 'https://github.com/ch-muhammad-adil/Android-Material-Picker-Dialog' // Homepage URL of the library 36 | def gitUrl = 'https://github.com/ch-muhammad-adil/Android-Material-Picker-Dialog.git' // Git repository URL 37 | group = "com.github.ch-muhammad-adil" 38 | 39 | install { 40 | repositories.mavenInstaller { 41 | // This generates POM.xml with proper parameters 42 | pom { 43 | project { 44 | packaging 'aar' 45 | 46 | // Add your description here 47 | name 'com.github.ch-muhammad-adil:mpd' 48 | description = 'Simple Material Picker Dialog Library which offer developers different kind of material dialogs like, gender picker, number picker.' 49 | url siteUrl 50 | 51 | // Set your license 52 | licenses { 53 | license { 54 | name 'The Apache Software License, Version 2.0' 55 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 56 | } 57 | } 58 | developers { 59 | developer { 60 | id 'ch-muhammad-adil' 61 | name 'Muhammad Adil' 62 | email 'chmuhammadadil7@gmail.com' 63 | } 64 | } 65 | scm { 66 | connection gitUrl 67 | developerConnection gitUrl 68 | url siteUrl 69 | } 70 | } 71 | } 72 | } 73 | } 74 | 75 | task sourcesJar(type: Jar) { 76 | from android.sourceSets.main.java.srcDirs 77 | classifier = 'sources' 78 | } 79 | 80 | task javadoc(type: Javadoc) { 81 | source = android.sourceSets.main.java.srcDirs 82 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 83 | } 84 | 85 | task javadocJar(type: Jar, dependsOn: javadoc) { 86 | classifier = 'javadoc' 87 | from javadoc.destinationDir 88 | } 89 | artifacts { 90 | archives javadocJar 91 | archives sourcesJar 92 | } 93 | 94 | Properties properties = new Properties() 95 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 96 | 97 | // https://github.com/bintray/gradle-bintray-plugin 98 | bintray { 99 | user = properties.getProperty("bintray.user") 100 | key = properties.getProperty("bintray.apikey") 101 | 102 | configurations = ['archives'] 103 | pkg { 104 | repo = "maven" 105 | // it is the name that appears in bintray when logged 106 | name = "MaterialPickerDialog" 107 | websiteUrl = siteUrl 108 | vcsUrl = gitUrl 109 | licenses = ["Apache-2.0"] 110 | 111 | publish = true 112 | version { 113 | gpg { 114 | sign = true //Determines whether to GPG sign the files. The default is false 115 | passphrase = properties.getProperty("bintray.gpg.password") //Optional. The passphrase for GPG signing' 116 | } 117 | } 118 | } 119 | } 120 | 121 | 122 | -------------------------------------------------------------------------------- /MaterialPickerDialog/install.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.github.dcendents.android-maven' 2 | 3 | group = 'com.github.ch-muhammad-adil' 4 | 5 | install { 6 | repositories.mavenInstaller { 7 | pom { 8 | project { 9 | packaging 'aar' 10 | groupId 'com.github.ch-muhammad-adil' 11 | artifactId 'MPD' 12 | 13 | name 'MaterialPickerDialog' 14 | description 'Simple Material Picker Dialog Library which offer developers different kind of material dialogs like, gender picker, number picker.' 15 | url 'https://github.com/ch-muhammad-adil/Android-Material-Picker-Dialog' 16 | 17 | licenses { 18 | license { 19 | name 'The Apache Software License, Version 2.0' 20 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 21 | } 22 | } 23 | developers { 24 | developer { 25 | id 'ch-muhammad-adil' 26 | name 'Muhammad Adil' 27 | email 'chmuhammadadil7@gmail.com' 28 | } 29 | } 30 | scm { 31 | connection 'https://github.com/ch-muhammad-adil/Android-Material-Picker-Dialog.git' 32 | developerConnection 'https://github.com/ch-muhammad-adil/Android-Material-Picker-Dialog.git' 33 | url 'https://github.com/ch-muhammad-adil/Android-Material-Picker-Dialog' 34 | 35 | } 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /MaterialPickerDialog/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/Adil/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /MaterialPickerDialog/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /MaterialPickerDialog/src/main/java/adil/dev/lib/materialnumberpicker/adapter/GenderAdapter.java: -------------------------------------------------------------------------------- 1 | package adil.dev.lib.materialnumberpicker.adapter; 2 | 3 | import android.content.Context; 4 | import android.os.Vibrator; 5 | import android.support.v4.content.ContextCompat; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.FrameLayout; 11 | import android.widget.TextView; 12 | 13 | import java.util.ArrayList; 14 | 15 | import adil.dev.lib.materialnumberpicker.R; 16 | import adil.dev.lib.materialnumberpicker.model.GenderModel; 17 | 18 | 19 | /** 20 | * Created by Adil on 08/01/2016. 21 | */ 22 | public class GenderAdapter extends RecyclerView.Adapter { 23 | 24 | Context mContext; 25 | LayoutInflater inflater; 26 | ArrayList dataList = new ArrayList<>(); 27 | ItemClickCallBack itemClickCallBack; 28 | 29 | public GenderAdapter(Context context) { 30 | this.mContext = context; 31 | inflater = LayoutInflater.from(context); 32 | initList(); 33 | } 34 | 35 | public void setOnItemClickCallBack(ItemClickCallBack onItemClickCallBack) { 36 | this.itemClickCallBack = onItemClickCallBack; 37 | } 38 | 39 | @Override 40 | public DialogViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 41 | return new DialogViewHolder(inflater.inflate(R.layout.picker_item, parent, false)); 42 | } 43 | 44 | @Override 45 | public void onBindViewHolder(DialogViewHolder holder, int position) { 46 | holder.number.setText(dataList.get(position).getGender()); 47 | if (dataList.get(position).isHasFocus()) { 48 | holder.number.setBackgroundResource(R.drawable.ic_round_shape_selected); 49 | holder.number.setTextColor(ContextCompat.getColor(mContext,R.color.MPD_pickerItemTextColorSelected)); 50 | } else { 51 | holder.number.setBackgroundResource(R.drawable.ic_round_shape_unselected); 52 | holder.number.setTextColor(ContextCompat.getColor(mContext,R.color.MPD_pickerItemTextColorUnSelected)); 53 | } 54 | } 55 | 56 | private void initList() { 57 | 58 | dataList.add(new GenderModel(mContext.getString(R.string.MPD_male), true)); 59 | dataList.add(new GenderModel(mContext.getString(R.string.MPD_female), false)); 60 | 61 | } 62 | 63 | @Override 64 | public int getItemCount() { 65 | return dataList.size(); 66 | } 67 | 68 | int focusedItem = 0; 69 | 70 | class DialogViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 71 | TextView number; 72 | FrameLayout itemParent; 73 | 74 | 75 | public DialogViewHolder(View itemView) { 76 | super(itemView); 77 | number = (TextView) itemView.findViewById(R.id.text_number); 78 | itemParent = (FrameLayout) itemView.findViewById(R.id.item_parent); 79 | itemParent.setOnClickListener(this); 80 | 81 | } 82 | 83 | 84 | @Override 85 | public void onClick(View v) { 86 | Vibrator vb = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); 87 | vb.vibrate(30); 88 | if (v.getId() == R.id.item_parent) { 89 | if (focusedItem <= -1) { 90 | focusedItem = getLayoutPosition(); 91 | dataList.get(getLayoutPosition()).setHasFocus(true); 92 | notifyItemChanged(getLayoutPosition()); 93 | } else { 94 | dataList.get(focusedItem).setHasFocus(false); 95 | notifyItemChanged(focusedItem); 96 | focusedItem = getLayoutPosition(); 97 | dataList.get(getLayoutPosition()).setHasFocus(true); 98 | notifyItemChanged(getLayoutPosition()); 99 | } 100 | itemClickCallBack.onItemClicked(dataList.get(getLayoutPosition()).getGender()); 101 | } 102 | } 103 | } 104 | 105 | public interface ItemClickCallBack { 106 | public void onItemClicked(String gender); 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /MaterialPickerDialog/src/main/java/adil/dev/lib/materialnumberpicker/adapter/NumberPickerAdapter.java: -------------------------------------------------------------------------------- 1 | package adil.dev.lib.materialnumberpicker.adapter; 2 | 3 | import android.content.Context; 4 | import android.os.Vibrator; 5 | import android.support.v4.content.ContextCompat; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.FrameLayout; 11 | import android.widget.TextView; 12 | 13 | import java.util.ArrayList; 14 | 15 | import adil.dev.lib.materialnumberpicker.R; 16 | import adil.dev.lib.materialnumberpicker.model.IntervalModel; 17 | 18 | 19 | /** 20 | * Created by Adil on 26/11/2015. 21 | */ 22 | public class NumberPickerAdapter extends RecyclerView.Adapter { 23 | 24 | Context mContext; 25 | LayoutInflater inflater; 26 | ArrayList dataList = new ArrayList<>(); 27 | ItemClickCallBack itemClickCallBack; 28 | ValueAvailableListener valueAvailableListener; 29 | NumberPickerAdapter instance; 30 | 31 | public NumberPickerAdapter(Context context, ItemClickCallBack itemClickCallBack,ValueAvailableListener valueAvailableListener, int start, int last) { 32 | this.mContext = context; 33 | inflater = LayoutInflater.from(context); 34 | this.itemClickCallBack = itemClickCallBack; 35 | this.valueAvailableListener=valueAvailableListener; 36 | initList(start,last); 37 | instance = this; 38 | } 39 | 40 | @Override 41 | public DialogViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 42 | return new DialogViewHolder(inflater.inflate(R.layout.picker_item, parent, false)); 43 | } 44 | 45 | public void findForItemToShow(int value){ 46 | int position=-1; 47 | for(int i=0;ilast){ 38 | throw new IllegalStateException("Start value must be smaller than last value"); 39 | } 40 | this.callBack = callBack; 41 | this.mContext = context; 42 | this.selectNumber = start; 43 | this.start = start; 44 | this.last = last; 45 | } 46 | 47 | public static NumberPickerDialog getInstance() { 48 | return instance; 49 | } 50 | 51 | @Override 52 | protected void onCreate(Bundle savedInstanceState) { 53 | super.onCreate(savedInstanceState); 54 | requestWindowFeature(Window.FEATURE_NO_TITLE); 55 | setContentView(R.layout.interval_picker_dialog); 56 | getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); 57 | instance = this; 58 | initViews(); 59 | initValues(); 60 | initValuesInViews(); 61 | setOnClickListener(); 62 | } 63 | 64 | RecyclerView recyclerView; 65 | TextView okView, cancelView; 66 | EditText selectedTextView; 67 | 68 | private void initViews() { 69 | recyclerView = (RecyclerView) findViewById(R.id.recyclerView); 70 | okView = (TextView) findViewById(R.id.ok); 71 | cancelView = (TextView) findViewById(R.id.cancel); 72 | selectedTextView = (EditText) findViewById(R.id.dialog_selected_value); 73 | } 74 | 75 | private void initValues() { 76 | 77 | } 78 | 79 | LinearLayoutManager linearLayoutManager; 80 | 81 | private void initValuesInViews() { 82 | linearLayoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false); 83 | recyclerView.setLayoutManager(linearLayoutManager); 84 | recyclerView.setItemAnimator(new DefaultItemAnimator()); 85 | if (last - start <= -1) 86 | recyclerView.setItemViewCacheSize(100000); 87 | else 88 | recyclerView.setItemViewCacheSize(last - start); 89 | selectedTextView.setText(String.valueOf(start)); 90 | selectNumber = start; 91 | 92 | SnapHelper snapHelper = new LinearSnapHelper(); 93 | snapHelper.attachToRecyclerView(recyclerView); 94 | 95 | recyclerView.setAdapter(new NumberPickerAdapter(mContext, this, this, start, last)); 96 | } 97 | 98 | private void setOnClickListener() { 99 | 100 | 101 | selectedTextView.addTextChangedListener(new TextWatcher() { 102 | @Override 103 | public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { 104 | 105 | } 106 | 107 | @Override 108 | public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { 109 | Vibrator vb = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); 110 | try { 111 | int value = Integer.parseInt(charSequence.toString()); 112 | 113 | if (value >= start && value <= last) { 114 | ((NumberPickerAdapter) recyclerView.getAdapter()).findForItemToShow(value); 115 | } else if (value < start) { 116 | selectNumber = value; 117 | // selectedTextView.setError("value can not be lower than " + start); 118 | vb.vibrate(50); 119 | } else if (value > last) { 120 | selectNumber = value; 121 | // selectedTextView.setError("value can not be higher than " + last); 122 | vb.vibrate(50); 123 | } 124 | } catch (NumberFormatException e) { 125 | selectedTextView.setError(mContext.getString(R.string.MPD_empty_message)); 126 | } 127 | } 128 | 129 | @Override 130 | public void afterTextChanged(Editable editable) { 131 | 132 | } 133 | }); 134 | 135 | cancelView.setOnClickListener(new View.OnClickListener() { 136 | @Override 137 | public void onClick(View v) { 138 | dismiss(); 139 | } 140 | }); 141 | okView.setOnClickListener(new View.OnClickListener() { 142 | @Override 143 | public void onClick(View v) { 144 | if (selectedTextView.getText().toString().isEmpty()||selectedTextView.getText().toString().equals("-")) { 145 | selectedTextView.setError(mContext.getString(R.string.MPD_empty_message)); 146 | } else if (selectNumber < start || selectNumber > last) { 147 | selectedTextView.setError(mContext.getString(R.string.MPD_incorrect_message)); 148 | } else { 149 | callBack.onSelectingValue(selectNumber); 150 | dismiss(); 151 | } 152 | } 153 | }); 154 | } 155 | 156 | @Override 157 | public void onItemClicked(int selectedNumber, int position) { 158 | this.selectNumber = selectedNumber; 159 | selectedTextView.setText(String.valueOf(selectedNumber)); 160 | selectedTextView.setError(null); 161 | linearLayoutManager.scrollToPositionWithOffset(position, 0); 162 | } 163 | 164 | @Override 165 | public void onValueAvailable(int value, int position) { 166 | this.selectNumber = value; 167 | linearLayoutManager.scrollToPositionWithOffset(position, 0); 168 | } 169 | 170 | public interface NumberPickerCallBack { 171 | public void onSelectingValue(int value); 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /MaterialPickerDialog/src/main/java/adil/dev/lib/materialnumberpicker/model/GenderModel.java: -------------------------------------------------------------------------------- 1 | package adil.dev.lib.materialnumberpicker.model; 2 | 3 | /** 4 | * Created by Adil on 08/01/2016. 5 | */ 6 | public class GenderModel { 7 | String gender; 8 | boolean hasFocus; 9 | 10 | public GenderModel(String gender, boolean hasFocus) { 11 | this.gender = gender; 12 | this.hasFocus = hasFocus; 13 | } 14 | 15 | public String getGender() { 16 | return gender; 17 | } 18 | 19 | public void setGender(String gender) { 20 | this.gender = gender; 21 | } 22 | 23 | public boolean isHasFocus() { 24 | return hasFocus; 25 | } 26 | 27 | public void setHasFocus(boolean hasFocus) { 28 | this.hasFocus = hasFocus; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /MaterialPickerDialog/src/main/java/adil/dev/lib/materialnumberpicker/model/IntervalModel.java: -------------------------------------------------------------------------------- 1 | package adil.dev.lib.materialnumberpicker.model; 2 | 3 | /** 4 | * Created by Adil on 03/12/2015. 5 | */ 6 | public class IntervalModel { 7 | int value; 8 | boolean hasFocus; 9 | 10 | public IntervalModel(int value, boolean hasFocus) { 11 | this.value = value; 12 | this.hasFocus = hasFocus; 13 | } 14 | 15 | public int getValue() { 16 | return value; 17 | } 18 | 19 | public void setValue(int value) { 20 | this.value = value; 21 | } 22 | 23 | public boolean isHasFocus() { 24 | return hasFocus; 25 | } 26 | 27 | public void setHasFocus(boolean hasFocus) { 28 | this.hasFocus = hasFocus; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /MaterialPickerDialog/src/main/res/drawable/ic_round_shape_selected.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 7 | 10 | -------------------------------------------------------------------------------- /MaterialPickerDialog/src/main/res/drawable/ic_round_shape_unselected.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 7 | 10 | -------------------------------------------------------------------------------- /MaterialPickerDialog/src/main/res/layout/gender_picker_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 18 | 19 | 27 | 28 | 38 | 39 | 40 | 41 | 47 | 48 | 55 | 56 | 57 | 62 | 63 | 72 | 73 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /MaterialPickerDialog/src/main/res/layout/interval_picker_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 18 | 19 | 27 | 28 | 44 | 45 | 46 | 47 | 53 | 54 | 63 | 64 | 65 | 70 | 71 | 80 | 81 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /MaterialPickerDialog/src/main/res/layout/picker_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 22 | -------------------------------------------------------------------------------- /MaterialPickerDialog/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #C5CAE9 4 | #3F51B5 5 | #303F9F 6 | #FF4081 7 | #33FF4081 8 | 9 | 10 | #3F51B5 11 | #C5CAE9 12 | #FFF 13 | #FFF 14 | #00FFFFFF 15 | @color/MPD_primaryColor 16 | #444 17 | #ccffffff 18 | -------------------------------------------------------------------------------- /MaterialPickerDialog/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 80dp 4 | 80dp 5 | 80dp 6 | 5dp 7 | -------------------------------------------------------------------------------- /MaterialPickerDialog/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | MaterialNumberPicker 3 | 4 | done 5 | cancel 6 | Male 7 | Female 8 | value can not be empty 9 | please select correct value 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android Material Picker Dialog 2 | This Library provides a very simple implementation of some android material picker's dialogs which were not available as open source library. 3 | It includes android **Number/Interval picker** which can 4 | be used as **Year picker**, **Month picker** and **any time duration Picker**. 5 | It also includes **Material Gender Picker Dialog** which was much required. 6 | 7 | #Screenshots 8 | ![pickers](https://github.com/ch-muhammad-adil/Android-Material-Picker-Dialog/blob/master/screenshot_1.png?raw=true)![pickers](https://github.com/ch-muhammad-adil/Android-Material-Picker-Dialog/blob/master/screenshot_2.png?raw=true) 9 | 10 | 11 | ##Compile Library jCenter 12 | ```groovy 13 | dependencies { 14 | .... 15 | compile 'com.github.ch-muhammad-adil:MaterialPickerDialog:1.0.3' 16 | .... 17 | } 18 | ``` 19 | 20 | ##Compile Library maven 21 | 22 | ```groovy 23 | dependencies { 24 | repositories { 25 | mavenCentral() 26 | } 27 | compile 'com.github.ch-muhammad-adil:MaterialPickerDialog:1.0.3' 28 | } 29 | ``` 30 | 31 | 32 | ##Simple Code for Number Picker 33 | 34 | ```java 35 | 36 | ////Using NumberPicker as an interval 37 | 38 | NumberPickerDialog dialog=new NumberPickerDialog(MainActivity.this, -50, 50, new NumberPickerDialog.NumberPickerCallBack() { 39 | @Override 40 | public void onSelectingValue(int value) { 41 | Toast.makeText(MainActivity.this, "Selected "+String.valueOf(value), Toast.LENGTH_SHORT).show(); 42 | } 43 | }); 44 | dialog.show(); 45 | 46 | ////Using number picker as year interval 47 | 48 | NumberPickerDialog dialog=new NumberPickerDialog(MainActivity.this, 1992, 2017, new NumberPickerDialog.NumberPickerCallBack() { 49 | @Override 50 | public void onSelectingValue(int value) { 51 | Toast.makeText(MainActivity.this, "Selected Year "+String.valueOf(value), Toast.LENGTH_SHORT).show(); 52 | } 53 | }); 54 | dialog.show(); 55 | 56 | ``` 57 | 58 | 59 | ##Simple Code for Gender Picker 60 | 61 | ```java 62 | 63 | ////Using gender picker 64 | 65 | GenderPickerDialog dialog=new GenderPickerDialog(MainActivity.this); 66 | dialog.setOnSelectingGender(new GenderPickerDialog.OnGenderSelectListener() { 67 | @Override 68 | public void onSelectingGender(String value) { 69 | Toast.makeText(MainActivity.this, "Selected "+value, Toast.LENGTH_SHORT).show(); 70 | } 71 | }); 72 | dialog.show(); 73 | 74 | ``` 75 | ##Do Add permissions for vibration in your menifest file. 76 | 77 | ```xml 78 | 79 | ``` 80 | 81 | ##Color Attributes of Material Picker Dialog 82 | 83 | If you override these attributes in your _**colors.xml**_ file under _**res/values**_ 84 | you can customize your **material picker dialog** 85 | ```xml 86 | 87 | 88 | 89 | @color/primaryColor 90 | #C5CAE9 91 | #FFF 92 | #00FFFFFF 93 | @color/MPD_primaryColor 94 | #444 95 | #bbffffff 96 | #FFF 97 | 98 | 99 | ``` 100 | 101 | 102 | ##Localization Attributes 103 | You can update any text and message or you can add localization using these attributes. You just need to override these **string attributes** in your **_strings.xml_** file under **_res/values_**. 104 | 105 | ```xml 106 | 107 | done 108 | cancel 109 | Male 110 | Female 111 | value can not be empty 112 | please select correct value 113 | 114 | ``` 115 | 116 | ##TODO 117 | * Number Picker Requires support for reverse ordering 118 | * Orientation change control is not handled yet in case if user changes orientation and dialog is open 119 | * Need to add horizontal movement of number picker items 120 | 121 | This is my first implementation of any open source library so your suggestions will be really helpful" 122 | 123 | ### Licence 124 | 125 | > Licensed under the Apache License, Version 2.0 (the "License"); 126 | > you may not use this work except in compliance with the License. 127 | > You may obtain a copy of the License in the LICENSE file, or at: 128 | > 129 | > [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0) 130 | > 131 | > Unless required by applicable law or agreed to in writing, software 132 | > distributed under the License is distributed on an "AS IS" BASIS, 133 | > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134 | > See the License for the specific language governing permissions and 135 | > limitations under the License. 136 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "adil.dev.lib.material_number_picker" 8 | minSdkVersion 14 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile 'com.android.support:appcompat-v7:25.1.1' 25 | compile project(':MaterialPickerDialog') 26 | 27 | } 28 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/Adil/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/adil/dev/lib/material_number_picker/MainActivity.java: -------------------------------------------------------------------------------- 1 | package adil.dev.lib.material_number_picker; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.view.View; 6 | import android.widget.Toast; 7 | 8 | import adil.dev.lib.materialnumberpicker.dialog.GenderPickerDialog; 9 | import adil.dev.lib.materialnumberpicker.dialog.NumberPickerDialog; 10 | 11 | public class MainActivity extends AppCompatActivity { 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_main); 17 | findViewById(R.id.number_picker).setOnClickListener(new View.OnClickListener() { 18 | @Override 19 | public void onClick(View view) { 20 | NumberPickerDialog dialog=new NumberPickerDialog(MainActivity.this, -50, 50, new NumberPickerDialog.NumberPickerCallBack() { 21 | @Override 22 | public void onSelectingValue(int value) { 23 | Toast.makeText(MainActivity.this, "Selected "+String.valueOf(value), Toast.LENGTH_SHORT).show(); 24 | } 25 | }); 26 | dialog.show(); 27 | } 28 | }); 29 | findViewById(R.id.year_picker).setOnClickListener(new View.OnClickListener() { 30 | @Override 31 | public void onClick(View view) { 32 | NumberPickerDialog dialog=new NumberPickerDialog(MainActivity.this, 1992, 2017, new NumberPickerDialog.NumberPickerCallBack() { 33 | @Override 34 | public void onSelectingValue(int value) { 35 | Toast.makeText(MainActivity.this, "Selected Year "+String.valueOf(value), Toast.LENGTH_SHORT).show(); 36 | } 37 | }); 38 | dialog.show(); 39 | } 40 | }); 41 | findViewById(R.id.gender_picker).setOnClickListener(new View.OnClickListener() { 42 | @Override 43 | public void onClick(View view) { 44 | GenderPickerDialog dialog=new GenderPickerDialog(MainActivity.this); 45 | dialog.setOnSelectingGender(new GenderPickerDialog.OnGenderSelectListener() { 46 | @Override 47 | public void onSelectingGender(String value) { 48 | Toast.makeText(MainActivity.this, "Selected "+value, Toast.LENGTH_SHORT).show(); 49 | } 50 | }); 51 | dialog.show(); 52 | } 53 | }); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 |