Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving library #23

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
/local.properties
/.idea/workspace.xml
/.idea/libraries
/.idea/gradle.xml
/.idea/misc.xml
/.idea/modules.xml
.DS_Store
/build
/captures
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Spinner with searchable items.

Searchable Spinner is a dialog spinner with the search feature which allows to search the items loaded in the spinner.

![Alt text](https://github.com/miteshpithadiya/SearchableSpinner/blob/master/searchablespinnerlibrary/src/main/res/nobleltevzwLMY47XMeditab02192016201518.gif "Searchable Spinner")
![Alt text](https://github.com/pedrofsn/SearchableSpinner/raw/master/image.gif "Searchable Spinner")

# Gradle
dependencies {
Expand All @@ -18,8 +18,15 @@ Searchable Spinner is a dialog spinner with the search feature which allows to s
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

searchableSpinner.setTitle("Select Item");
searchableSpinner.setPositiveButton("OK");
searchableSpinner.setHint("Please, select something"); // Hint
searchableSpinner.setTitle("Select Item"); // Change the title of dialog
searchableSpinner.setPositiveButton("OK"); // Change the name of dialog "close button"
searchableSpinner.setOnSearchTextChangedListener(this); // Listener to get text that is inputted on search
searchableSpinner.setAdapter(new ArrayAdapter<>[..]); // Set adapter of list
searchableSpinner.searchableItemClick(3); // If you want set a selection by position
searchableSpinner.setPositiveButton("Hi!", new DialogInterface.OnClickListener[...]); // Change the name of dialog "close button" and use a listener to click event



# Changelog
* <b>1.3.1</b>
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
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 @@
#Mon Apr 25 14:39:33 GMT+05:30 2016
#Wed Jul 12 22:58:49 BRT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
Binary file added image.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion '25.0.0'

defaultConfig {
applicationId "com.toptoche.sample"
Expand All @@ -23,6 +23,5 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1'
// compile project(':searchablespinnerlibrary')
compile project(':searchablespinnerlibrary')
}
6 changes: 3 additions & 3 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.toptoche.sample">
package="com.toptoche.sample">

<application
android:allowBackup="true"
Expand All @@ -10,9 +10,9 @@
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Expand Down
48 changes: 47 additions & 1 deletion sample/src/main/java/com/toptoche/sample/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,59 @@
package com.toptoche.sample;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
import com.toptoche.searchablespinnerlibrary.OnSearchTextChanged;
import com.toptoche.searchablespinnerlibrary.SearchableSpinner;

public class MainActivity extends AppCompatActivity implements DialogInterface.OnClickListener, OnSearchTextChanged {

private SearchableSpinner searchableSpinner;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

searchableSpinner = (SearchableSpinner) findViewById(R.id.searchableSpinner);

searchableSpinner.setHint(getString(R.string.you_know_nothing));
searchableSpinner.setTitle(getString(R.string.select_a_person));
searchableSpinner.setPositiveButton(getString(android.R.string.ok), this);
searchableSpinner.setOnSearchTextChangedListener(this);

searchableSpinner.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.starks)));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menuItem:
searchableSpinner.searchableItemClick(3); // JON SNOW POSITION!
break;
}

return super.onOptionsItemSelected(item);
}

@Override
public void onClick(DialogInterface dialogInterface, int position) {
Toast.makeText(this, getString(android.R.string.ok), Toast.LENGTH_SHORT).show();
}

@Override
public void onSearchTextChanged(String newText) {
Toast.makeText(this, String.format(getString(R.string.search_string_changed_to_x), newText), Toast.LENGTH_SHORT).show();
}
}
10 changes: 4 additions & 6 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -12,9 +10,9 @@
tools:context="com.toptoche.sample.MainActivity">

<com.toptoche.searchablespinnerlibrary.SearchableSpinner
android:id="@+id/spinner"
android:id="@+id/searchableSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/planets"
app:hintText="SEKECCTTT"/>
android:layout_centerInParent="true" />

</RelativeLayout>
6 changes: 6 additions & 0 deletions sample/src/main/res/menu/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menuItem"
android:title="@string/answer" />
</menu>
6 changes: 0 additions & 6 deletions sample/src/main/res/values-w820dp/dimens.xml

This file was deleted.

13 changes: 13 additions & 0 deletions sample/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string-array name="starks">
<item>Robb</item>
<item>Sansa</item>
<item>Arya</item>
<item>Jon Snow</item>
<item>Brandon</item>
<item>Rickon</item>
</string-array>

</resources>
18 changes: 5 additions & 13 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
<resources>
<string name="app_name">Sample</string>

<string-array name="planets">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
<item>Jupiter</item>
<item>Saturn</item>
<item>Uranus</item>
<item>Neptune</item>
<item>Pluto</item>
</string-array>
<string name="app_name">Sample SearchableSpinner</string>
<string name="search_string_changed_to_x">Search string changed to \'%s\'</string>
<string name="you_know_nothing">You know nothing</string>
<string name="select_a_person">Select a Person</string>
<string name="answer">Answer</string>
</resources>
2 changes: 1 addition & 1 deletion searchablespinnerlibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def gitUrl = 'https://github.com/miteshpithadiya/SearchableSpinner.git'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion '25.0.0'

defaultConfig {
minSdkVersion 15
Expand Down
7 changes: 3 additions & 4 deletions searchablespinnerlibrary/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<manifest package="com.toptoche.searchablespinnerlibrary"
xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.toptoche.searchablespinnerlibrary">

<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
>
android:supportsRtl="true">

</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.toptoche.searchablespinnerlibrary;

/**
* Created by pedrofsn on 26/08/2016.
*/
public interface OnSearchTextChanged {

void onSearchTextChanged(String strText);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.toptoche.searchablespinnerlibrary;

import java.io.Serializable;

/**
* Created by pedrofsn on 26/08/2016.
*/
public interface SearchableItem<T> extends Serializable {

void onSearchableItemClicked(T item, int position);

}
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ private void setData(View rootView) {
_listViewItems = (ListView) rootView.findViewById(R.id.listItems);

//create the adapter by passing your ArrayList data
listAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1,
items);
listAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, items);
//attach the adapter to the list
_listViewItems.setAdapter(listAdapter);

Expand Down Expand Up @@ -186,9 +185,7 @@ public boolean onQueryTextSubmit(String s) {

@Override
public boolean onQueryTextChange(String s) {
// listAdapter.filterData(s);
if (TextUtils.isEmpty(s)) {
// _listViewItems.clearTextFilter();
((ArrayAdapter) _listViewItems.getAdapter()).getFilter().filter(null);
} else {
((ArrayAdapter) _listViewItems.getAdapter()).getFilter().filter(s);
Expand All @@ -198,12 +195,4 @@ public boolean onQueryTextChange(String s) {
}
return true;
}

public interface SearchableItem<T> extends Serializable {
void onSearchableItemClicked(T item, int position);
}

public interface OnSearchTextChanged {
void onSearchTextChanged(String strText);
}
}
Loading