Skip to content

Commit

Permalink
Merge pull request #7 from sadra/spinnerEnable
Browse files Browse the repository at this point in the history
Spinner enable
  • Loading branch information
sadra authored Dec 6, 2018
2 parents bfeb108 + 6cb861c commit 70cc921
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
/build
/captures
.externalNativeBuild

.idea/instapk.xml
instapk.log*
3 changes: 3 additions & 0 deletions .hgignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

.idea/instapk.xml
instapk.log*
15 changes: 1 addition & 14 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions AwesomeSpinner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
buildToolsVersion '26.0.2'

defaultConfig {
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
versionName "1.1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand All @@ -22,10 +22,6 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:appcompat-v7:25.4.0'
testCompile 'junit:junit:4.12'
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
* Created by sadra on 5/26/17.
Expand Down Expand Up @@ -108,16 +109,17 @@ private void initiateSpinnerString(){
_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

Log.d(TAG, "position selected: " + position);
if (AwesomeSpinner.this._callback == null) {
throw new IllegalStateException("callback cannot be null");
}
if(_allowToSelect){
_isSelected = true;
Object item = AwesomeSpinner.this._spinner.getItemAtPosition(position);
AwesomeSpinner.this._callback.onItemSelected(position, (String) item);
_hintButton.setText(_spinner.getSelectedItem().toString());
_hintButton.setTextColor(Color.BLACK);
_isSelected = true;
setHitButtonStyle();
}
_allowToSelect = true;

Expand All @@ -141,16 +143,17 @@ private void initiateSpinnerCharSequence(){
_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

Log.d(TAG, "position selected: " + position);
if (AwesomeSpinner.this._callback == null) {
throw new IllegalStateException("callback cannot be null");
}
if(_allowToSelect){
_isSelected = true;
Object item = AwesomeSpinner.this._spinner.getItemAtPosition(position);
AwesomeSpinner.this._callback.onItemSelected(position, (String) item);
_hintButton.setText(_spinner.getSelectedItem().toString());
_hintButton.setTextColor(Color.BLACK);
_isSelected = true;
setHitButtonStyle();
}
_allowToSelect = true;

Expand Down Expand Up @@ -233,5 +236,19 @@ public interface onSpinnerItemClickListener<T> {
void onItemSelected(int position, T itemAtPosition);
}

public void setSpinnerEnable(boolean enable){
this._spinner.setEnabled(enable);
this._hintButton.setEnabled(enable);
this._downArrow.setAlpha(enable ? 1.0f : 0.6f);
setHitButtonStyle();
}

public boolean isSpinnerEnable(){
return this._spinner.isEnabled();
}

private void setHitButtonStyle(){
this._hintButton.setTextColor(this._hintButton.isEnabled() ? Color.BLACK : Color.parseColor("#BDBDBD"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#aaa" android:state_enabled="false"/>
<item android:color="#000000"/>
</selector>
1 change: 1 addition & 0 deletions AwesomeSpinner/src/main/res/layout/spinner_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:textAlignment="inherit"
android:textColor="@color/spinner_list_item_selector"
android:textAllCaps="false"/>
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ allprojects {

**Step 2.** Add the dependency:
```groovy
compile 'com.github.amlashi-sadra:AwesomeSpinner:1.0.7'
implementation 'com.github.sadra:AwesomeSpinner:1.1.0'
```

## How To Use
Expand Down Expand Up @@ -87,10 +87,12 @@ there is some controls for your spinner:

| Control | Requierement | Info |
| :------------- |:-------------:| :-----|
| getSelectedItem() | - | result = `String`: returns the selected item |
| isSelected() | - | result = `boolean`: returns **true** if any item selected, and vice versa |
| setSelection(NUMBER) | `int` position | you should pass the **position of item** to select the item programatically |
| setSelection(TEXT) | `String` value | you should pass the **item value** to select the item programatically |
| getSelectedItem() | - | Result = `String`: Returns the selected item |
| isSelected() | - | Result = `boolean`: Returns **true** if any item selected, and vice versa |
| setSelection(NUMBER) | `int` position | You should pass the **position of item** to select the item programatically |
| setSelection(TEXT) | `String` value | You should pass the **item value** to select the item programatically |
| setSpinnerEnable(BOOLEAN); | `Boolean` value | If you want enable or disable the spinner, you should call this method. |
| isSpinnerEnable(); | - | Result = `boolean`: Returns **true** if the spinner is enabled, and vice versa |

You can see the [EXAMPLE PROJECT](https://github.com/amlashi-sadra/AwesomeSpinner/tree/master/app/src/main) for more infromation.

Expand Down
17 changes: 8 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ allprojects {

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
buildToolsVersion '26.0.2'
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g"
}
defaultConfig {
applicationId "com.isapanah.awsomespinnerexample"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
versionName "1.0.8"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -26,11 +30,6 @@ android {
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.github.amlashi-sadra:AwesomeSpinner:1.0.7'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.4.0'
implementation 'com.github.sadra:AwesomeSpinner:1.1.0'
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.isapanah.awsomespinnerexample;

import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.isapanah.awesomespinner.AwesomeSpinner;
Expand All @@ -31,14 +33,13 @@ protected void onCreate(Bundle savedInstanceState) {
spinnerRTL = (AwesomeSpinner) findViewById(R.id.awesomeSpinner_example_rtl);
spinnerLTR = (AwesomeSpinner) findViewById(R.id.awesomeSpinner_example_ltr);


//Initialize the Adapter and spinnerRTL listener
ArrayAdapter<CharSequence> provincesAdapter = ArrayAdapter.createFromResource(this, R.array.iran_provinces, android.R.layout.simple_spinner_item);
spinnerRTL.setAdapter(provincesAdapter, 0);
spinnerRTL.setOnSpinnerItemClickListener(new AwesomeSpinner.onSpinnerItemClickListener<String>() {
@Override
public void onItemSelected(int position, String itemAtPosition) {
Toast.makeText(getApplicationContext(), "Position: "+position+" | Item: "+itemAtPosition, Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "Position: "+position+" | Item: "+itemAtPosition+" | isSelected:"+spinnerLTR.isSelected(), Toast.LENGTH_LONG).show();
}
});

Expand All @@ -57,10 +58,21 @@ public void onItemSelected(int position, String itemAtPosition) {
spinnerLTR.setOnSpinnerItemClickListener(new AwesomeSpinner.onSpinnerItemClickListener<String>() {
@Override
public void onItemSelected(int position, String itemAtPosition) {
Toast.makeText(getApplicationContext(), "Position: "+position+" | Item: "+itemAtPosition, Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "Position: "+position+" | Item: "+itemAtPosition+" | isSelected:"+spinnerLTR.isSelected(), Toast.LENGTH_LONG).show();
}
});

new Handler().postDelayed(new Runnable() {
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
spinnerLTR.setSelection(2);
}
});
}
}, 100);


FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
Expand All @@ -76,10 +88,27 @@ public void onClick(View view) {
.setAction("OK", null).show();
}

}
});


final TextView disable_spinners = (TextView) findViewById(R.id.disable_spinners);
disable_spinners.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(spinnerLTR.isSpinnerEnable()){
spinnerLTR.setSpinnerEnable(false);
spinnerRTL.setSpinnerEnable(false);
disable_spinners.setText("Enable Spinners");
}else{
spinnerLTR.setSpinnerEnable(true);
spinnerRTL.setSpinnerEnable(true);
disable_spinners.setText("Disable Spinners");
}
}
});


}

}
10 changes: 10 additions & 0 deletions app/src/main/res/layout/content_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,14 @@
app:spinnerDirection="ltr"
app:spinnerHint="Select a category" />


<Button
android:layout_marginTop="16dp"
android:id="@+id/disable_spinners"
android:text="Disable Spinners"
android:textAllCaps="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />


</LinearLayout>
10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -13,6 +17,10 @@ buildscript {
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri May 26 00:26:35 IRDT 2017
#Thu Dec 06 21:38:06 IRST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

0 comments on commit 70cc921

Please sign in to comment.