-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
List of sample companies and new methods SearchLiveo
- Loading branch information
Showing
20 changed files
with
412 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
demo/src/main/java/br/com/liveo/searchview_materialdesign/MainAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package br.com.liveo.searchview_materialdesign; | ||
|
||
import android.databinding.DataBindingUtil; | ||
import android.support.annotation.NonNull; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import java.text.Normalizer; | ||
import java.util.ArrayList; | ||
import java.util.Locale; | ||
|
||
import br.com.liveo.searchview_materialdesign.databinding.ContentMainItemBinding; | ||
import br.com.liveo.searchview_materialdesign.model.Company; | ||
|
||
/** | ||
* Created by rudsonlima on 19/03/18. | ||
*/ | ||
|
||
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> { | ||
|
||
private ArrayList<Company> mCompanys; | ||
private ArrayList<Company> mSearchCompanys; | ||
|
||
public MainAdapter(ArrayList<Company> Companys) { | ||
this.mCompanys = Companys; | ||
this.mSearchCompanys = new ArrayList<>(); | ||
this.mSearchCompanys.addAll(this.mCompanys); | ||
} | ||
|
||
static class ViewHolder extends RecyclerView.ViewHolder { | ||
ViewHolder(View itemView) { | ||
super(itemView); | ||
} | ||
|
||
ContentMainItemBinding getBinding() { | ||
return DataBindingUtil.getBinding(itemView); | ||
} | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public MainAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
return new ViewHolder(DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), | ||
R.layout.content_main_item, parent, false).getRoot()); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { | ||
Company company = mCompanys.get(holder.getAdapterPosition()); | ||
|
||
holder.getBinding().setVariable(BR.company, company); | ||
holder.getBinding().executePendingBindings(); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return (mCompanys == null ? 0 : mCompanys.size()); | ||
} | ||
|
||
private static String removeAccent(String text) { | ||
String result = Normalizer.normalize(text, Normalizer.Form.NFD); | ||
return result.replaceAll("[^\\p{ASCII}]", ""); | ||
} | ||
|
||
void searchCompanyes(CharSequence charText) { | ||
|
||
charText = removeAccent((String) charText).toLowerCase(Locale.getDefault()); | ||
|
||
mCompanys.clear(); | ||
if (charText.length() == 0) { | ||
mCompanys.addAll(mSearchCompanys); | ||
} else { | ||
for (Company Company : mSearchCompanys) { | ||
String name = removeAccent(Company.getName()); | ||
if (name.toLowerCase(Locale.getDefault()).contains(charText)) { | ||
mCompanys.add(Company); | ||
} | ||
} | ||
} | ||
|
||
notifyDataSetChanged(); | ||
} | ||
} | ||
|
78 changes: 78 additions & 0 deletions
78
demo/src/main/java/br/com/liveo/searchview_materialdesign/base/BaseActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package br.com.liveo.searchview_materialdesign.base; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.databinding.DataBindingUtil; | ||
import android.databinding.ViewDataBinding; | ||
import android.os.Bundle; | ||
import android.support.v4.content.ContextCompat; | ||
import android.support.v7.app.ActionBar; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.WindowManager; | ||
|
||
import br.com.liveo.searchview_materialdesign.R; | ||
|
||
@SuppressLint("Registered") | ||
public class BaseActivity extends AppCompatActivity { | ||
|
||
public static boolean mIsTablet; | ||
public static boolean mIsLandscape; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); | ||
} | ||
|
||
protected ViewDataBinding bindView(int layout) { | ||
return DataBindingUtil.setContentView(this, layout); | ||
} | ||
|
||
//region Methods Toolbar | ||
public void onInitToolbar(Toolbar toolBar) { | ||
onInitToolbar(toolBar, getString(R.string.clear), -1, false); | ||
} | ||
|
||
public void onInitToolbar(Toolbar toolBar, String title) { | ||
onInitToolbar(toolBar, title, -1, false); | ||
} | ||
|
||
public void onInitToolbar(Toolbar toolBar, int title) { | ||
onInitToolbar(toolBar, title, -1, false); | ||
} | ||
|
||
public void onInitToolbar(Toolbar toolBar, int title, int icon) { | ||
onInitToolbar(toolBar, getString(title), icon, true); | ||
} | ||
|
||
public void onInitToolbar(Toolbar toolBar, String title, boolean displayHome) { | ||
onInitToolbar(toolBar, title, -1, displayHome); | ||
} | ||
|
||
public void onInitToolbar(Toolbar toolBar, int title, boolean displayHome) { | ||
onInitToolbar(toolBar, title, -1, displayHome); | ||
} | ||
|
||
public void onInitToolbar(Toolbar toolBar, int title, int icon, boolean displayHome) { | ||
onInitToolbar(toolBar, getString(title), icon, displayHome); | ||
} | ||
|
||
public void onInitToolbar(Toolbar toolBar, String title, int icon, boolean displayHome) { | ||
|
||
if (toolBar != null) { | ||
setSupportActionBar(toolBar); | ||
ActionBar actionBar = getSupportActionBar(); | ||
|
||
if (actionBar != null) { | ||
actionBar.setTitle(title); | ||
actionBar.setDisplayShowHomeEnabled(displayHome); | ||
actionBar.setDisplayHomeAsUpEnabled(displayHome); | ||
if (icon != -1 && displayHome) { | ||
toolBar.setNavigationIcon(ContextCompat.getDrawable(this, icon)); | ||
} | ||
} | ||
} | ||
} | ||
//endregion | ||
} |
89 changes: 89 additions & 0 deletions
89
demo/src/main/java/br/com/liveo/searchview_materialdesign/model/Company.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package br.com.liveo.searchview_materialdesign.model; | ||
|
||
import android.databinding.BindingAdapter; | ||
import android.os.Parcel; | ||
import android.os.Parcelable; | ||
import android.support.v7.widget.AppCompatImageView; | ||
|
||
import java.util.ArrayList; | ||
|
||
import br.com.liveo.searchview_materialdesign.R; | ||
|
||
/** | ||
* Created by rudsonlima on 19/03/18. | ||
*/ | ||
|
||
public class Company implements Parcelable { | ||
|
||
private int icon; | ||
private String name; | ||
|
||
@BindingAdapter("icon") | ||
public static void icon(AppCompatImageView imageView, int icon) { | ||
imageView.setImageResource(icon); | ||
} | ||
|
||
@Override | ||
public int describeContents() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void writeToParcel(Parcel dest, int flags) { | ||
dest.writeInt(this.getIcon()); | ||
dest.writeString(this.getName()); | ||
} | ||
|
||
private Company(String name, int icon) { | ||
this.setName(name); | ||
this.setIcon(icon); | ||
} | ||
|
||
private Company(Parcel in) { | ||
this.setIcon(in.readInt()); | ||
this.setName(in.readString()); | ||
} | ||
|
||
public static final Parcelable.Creator<Company> CREATOR = new Parcelable.Creator<Company>() { | ||
@Override | ||
public Company createFromParcel(Parcel source) { | ||
return new Company(source); | ||
} | ||
|
||
@Override | ||
public Company[] newArray(int size) { | ||
return new Company[size]; | ||
} | ||
}; | ||
|
||
public int getIcon() { | ||
return icon; | ||
} | ||
|
||
public void setIcon(int icon) { | ||
this.icon = icon; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public static ArrayList<Company> getCompanies(){ | ||
ArrayList<Company> companies = new ArrayList<>(); | ||
|
||
companies.add(new Company("Appple", R.drawable.ic_apple)); | ||
companies.add(new Company("Google", R.drawable.ic_google)); | ||
companies.add(new Company("Github", R.drawable.ic_github)); | ||
companies.add(new Company("Facebook", R.drawable.ic_facebook)); | ||
companies.add(new Company("Instagram", R.drawable.ic_instagram)); | ||
companies.add(new Company("Linkedin", R.drawable.ic_linkedin)); | ||
companies.add(new Company("Twitter", R.drawable.ic_twitter)); | ||
companies.add(new Company("Microsoft", R.drawable.ic_microsoft)); | ||
|
||
return companies; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.