Skip to content

Commit

Permalink
Merge branch 'release/v1.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelCatalan committed Jan 7, 2016
2 parents ca7789a + 2c2f211 commit 984acfc
Show file tree
Hide file tree
Showing 16 changed files with 364 additions and 53 deletions.
57 changes: 56 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Cute library to implement SearchView in a Material Design Approach. *Works from
**Add the dependencies to your gradle file:**
```javascript
dependencies {
compile 'com.miguelcatalan:materialsearchview:1.3.0'
compile 'com.miguelcatalan:materialsearchview:1.3.1'
}
```
**Add MaterialSearchView to your layout file along with the Toolbar** *(Add this block at the bottom of your layout, in order to display it over the rest of the view)*:
Expand Down Expand Up @@ -168,6 +168,61 @@ Cute library to implement SearchView in a Material Design Approach. *Works from
```java
searchView.setCursorDrawable(R.drawable.custom_cursor);
```

# Using AppBarLayout?
It is a little bit tricky but can be achieved using this:
```xml
<RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
android:id=“@+id/container”
android:layout_width=“match_parent”
android:layout_height=“match_parent”>

<!— Irrelevant stuff —>
<android.support.v4.view.ViewPager
android:id=“@+id/viewpager”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:layout_below=“@+id/appbarlayout”
app:layout_behavior=“@string/appbar_scrolling_view_behavior” />

<!— Must be last for right layering display —>
<android.support.design.widget.AppBarLayout
android:id=“@+id/appbarlayout”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:background=“@color/search_layover_bg”>

<FrameLayout
android:id=“@+id/toolbar_container”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”>

<android.support.v7.widget.Toolbar
android:id=“@+id/toolbar”
android:layout_width=“match_parent”
android:layout_height=“?attr/actionBarSize”
android:background=“@color/theme_primary” />

<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id=“@+id/search_view”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:visibility=“gone” />
</FrameLayout>

<android.support.design.widget.TabLayout
android:id=“@+id/tabs”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:background=“@color/theme_primary”
app:tabGravity=“fill”
app:tabMode=“fixed” />

</android.support.design.widget.AppBarLayout>

</RelativeLayout>
```
# Bonus
**Close on backpressed:**
```java
Expand Down
7 changes: 4 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ android {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.3.0"
versionName "1.3.1"
}
buildTypes {
release {
Expand All @@ -30,14 +30,15 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}

publish {
userOrg = 'miguelcatalan'
groupId = 'com.miguelcatalan'
artifactId = 'materialsearchview'
publishVersion = '1.3.0'
publishVersion = '1.3.1'
desc = 'Cute library to implement SearchView in a Material Design Approach'
website = 'https://github.com/MiguelCatalan/MaterialSearchView'
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class MaterialSearchView extends FrameLayout implements Filter.FilterList

private MenuItem mMenuItem;
private boolean mIsSearchOpen = false;

private int mAnimationDuration;
private boolean mClearingFocus;

//Views
Expand Down Expand Up @@ -161,6 +161,7 @@ private void initiateView() {
initSearchView();

mSuggestionsListView.setVisibility(GONE);
setAnimationDuration(AnimationUtil.ANIMATION_DURATION_MEDIUM);
}

private void initSearchView() {
Expand Down Expand Up @@ -473,6 +474,15 @@ public boolean isSearchOpen() {
return mIsSearchOpen;
}

/**
* Sets animation duration. ONLY FOR PRE-LOLLIPOP!!
*
* @param duration duration of the animation
*/
public void setAnimationDuration(int duration) {
mAnimationDuration = duration;
}

/**
* Open Search View. This will animate the showing of the view.
*/
Expand All @@ -481,9 +491,9 @@ public void showSearch() {
}

/**
* Open Search View. if animate is true, Animate the showing of the view.
* Open Search View. If animate is true, Animate the showing of the view.
*
* @param animate
* @param animate true for animate
*/
public void showSearch(boolean animate) {
if (isSearchOpen()) {
Expand Down Expand Up @@ -532,7 +542,7 @@ public boolean onAnimationCancel(View view) {
AnimationUtil.reveal(mSearchTopBar, animationListener);

} else {
AnimationUtil.fadeInView(mSearchLayout, AnimationUtil.ANIMATION_DURATION_MEDIUM, animationListener);
AnimationUtil.fadeInView(mSearchLayout, mAnimationDuration, animationListener);
}
}

Expand Down Expand Up @@ -603,11 +613,9 @@ public void clearFocus() {

@Override
public Parcelable onSaveInstanceState() {
//begin boilerplate code that allows parent classes to save state
Parcelable superState = super.onSaveInstanceState();

mSavedState = new SavedState(superState);
//end
mSavedState.query = mUserQuery != null ? mUserQuery.toString() : null;
mSavedState.isSearchOpen = this.mIsSearchOpen;

Expand All @@ -616,7 +624,6 @@ public Parcelable onSaveInstanceState() {

@Override
public void onRestoreInstanceState(Parcelable state) {
//begin boilerplate code so parent classes can restore state
if (!(state instanceof SavedState)) {
super.onRestoreInstanceState(state);
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.miguelcatalan.materialsearchview;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
Expand All @@ -17,28 +16,27 @@
import java.util.List;

/**
* Suggestions Adapter.
*
* @author Miguel Catalan Bañuls
*/
public class SearchAdapter extends BaseAdapter implements Filterable {

private ArrayList<String> data;

private String[] typeAheadData;

private String[] suggestions;
private Drawable suggestionIcon;
private LayoutInflater inflater;

LayoutInflater inflater;

public SearchAdapter(Context context, String[] typeAheadData) {
public SearchAdapter(Context context, String[] suggestions) {
inflater = LayoutInflater.from(context);
data = new ArrayList<>();
this.typeAheadData = typeAheadData;
this.suggestions = suggestions;
}

public SearchAdapter(Context context, String[] typeAheadData, Drawable suggestionIcon) {
public SearchAdapter(Context context, String[] suggestions, Drawable suggestionIcon) {
inflater = LayoutInflater.from(context);
data = new ArrayList<>();
this.typeAheadData = typeAheadData;
this.suggestions = suggestions;
this.suggestionIcon = suggestionIcon;
}

Expand All @@ -49,12 +47,13 @@ public Filter getFilter() {
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults filterResults = new FilterResults();
if (!TextUtils.isEmpty(constraint)) {

// Retrieve the autocomplete results.
List<String> searchData = new ArrayList<>();

for (String str : typeAheadData) {
if (str.toLowerCase().startsWith(constraint.toString().toLowerCase())) {
searchData.add(str);
for (String string : suggestions) {
if (string.toLowerCase().startsWith(constraint.toString().toLowerCase())) {
searchData.add(string);
}
}

Expand Down Expand Up @@ -93,29 +92,30 @@ public long getItemId(int position) {

@Override
public View getView(int position, View convertView, ViewGroup parent) {
MyViewHolder mViewHolder;

SuggestionsViewHolder viewHolder;

if (convertView == null) {
convertView = inflater.inflate(R.layout.suggest_item, parent, false);
mViewHolder = new MyViewHolder(convertView);
convertView.setTag(mViewHolder);
viewHolder = new SuggestionsViewHolder(convertView);
convertView.setTag(viewHolder);
} else {
mViewHolder = (MyViewHolder) convertView.getTag();
viewHolder = (SuggestionsViewHolder) convertView.getTag();
}

String currentListData = (String) getItem(position);

mViewHolder.textView.setText(currentListData);

viewHolder.textView.setText(currentListData);

return convertView;
}

private class MyViewHolder {
private class SuggestionsViewHolder {

TextView textView;
ImageView imageView;

public MyViewHolder(View convertView) {
public SuggestionsViewHolder(View convertView) {
textView = (TextView) convertView.findViewById(R.id.suggestion_text);
if (suggestionIcon != null) {
imageView = (ImageView) convertView.findViewById(R.id.suggestion_icon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
public class AnimationUtil {

public static final int ANIMATION_DURATION_SHORT = 150;
public static final int ANIMATION_DURATION_MEDIUM = 400;
public static final int ANIMATION_DURATION_LONG = 800;
public static int ANIMATION_DURATION_SHORT = 150;
public static int ANIMATION_DURATION_MEDIUM = 400;
public static int ANIMATION_DURATION_LONG = 800;

public interface AnimationListener {
/**
Expand Down Expand Up @@ -57,24 +57,19 @@ public static void fadeInView(View view, int duration, final AnimationListener l
@Override
public void onAnimationStart(View view) {
if (!listener.onAnimationStart(view)) {
//execute Parent MEthod
view.setDrawingCacheEnabled(true);
}
}

@Override
public void onAnimationEnd(View view) {
if (!listener.onAnimationEnd(view)) {
//execute Parent MEthod
view.setDrawingCacheEnabled(false);
}
}

@Override
public void onAnimationCancel(View view) {
if (!listener.onAnimationCancel(view)) {
//execute Parent MEthod
}
}
};
}
Expand Down Expand Up @@ -127,26 +122,20 @@ public static void fadeOutView(View view, int duration, final AnimationListener
@Override
public void onAnimationStart(View view) {
if (listener == null || !listener.onAnimationStart(view)) {
//execute Parent MEthod
view.setDrawingCacheEnabled(true);
}
}

@Override
public void onAnimationEnd(View view) {
if (listener == null || !listener.onAnimationEnd(view)) {
//execute Parent MEthod
view.setVisibility(View.GONE);
//view.setAlpha(1f);
view.setDrawingCacheEnabled(false);
}
}

@Override
public void onAnimationCancel(View view) {
if (listener == null || !listener.onAnimationCancel(view)) {
//execute Parent MEthod
}
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.miguelcatalan.materialsearchview.sample"
minSdkVersion 14
targetSdkVersion 23
versionCode 5
versionName "1.3.0"
versionCode 6
versionName "1.3.1"
}
buildTypes {
release {
Expand Down
7 changes: 5 additions & 2 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
</activity>
<activity
android:name=".StickyActivity"
android:label="@string/title_activity_sticky"
android:theme="@style/AppTheme" >
android:label="@string/title_activity_sticky">
</activity>
<activity
android:name=".TabActivity"
android:label="@string/title_activity_tab">
</activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.miguelcatalan.materialsearchview.sample;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
* @author Miguel Catalan Bañuls
*/
public class DummyFragment extends Fragment {

public DummyFragment() {
// Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_dummy, container, false);
}
}
Loading

0 comments on commit 984acfc

Please sign in to comment.