Skip to content

Instantly share code, notes, and snippets.

View Suleiman19's full-sized avatar

Suleiman Ali Shakir Suleiman19

View GitHub Profile
@Suleiman19
Suleiman19 / Spinner Setup (Activity)
Last active October 11, 2022 14:10
Theme Aware Material Design Spinner
Spinner spinner = (Spinner) findViewById(R.id.main_spinner);
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getSupportActionBar().getThemedContext(),
R.layout.spinner_list_style,
getResources().getStringArray(R.array.countries));
spinnerAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
spinner.setAdapter(spinnerAdapter);
public static Bitmap DownloadImageBitmap(String url) {
Bitmap bm = null;
try {
URL aURL = new URL(url);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
@Suleiman19
Suleiman19 / activity_animate_toolbar.xml
Last active June 25, 2020 13:39
Flexible Space with Image pattern XML layout. Using Design Support library widgets.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
@Suleiman19
Suleiman19 / Header.java
Last active June 27, 2019 14:31
Sample code snippets for using mikepenz/FastAdapter library and its various features
public class Header extends AbstractItem<Header, Header.ViewHolder> {
String title;
public Header(String title) {
this.title = title;
}
public String getTitle() {
return title;
@Suleiman19
Suleiman19 / RecyclerView Click Listener Util
Last active February 1, 2019 08:05
Small Util class to set a click listener for RecyclerViews
public class CustomRecyclerClickListener implements RecyclerView.OnItemTouchListener {
private OnItemClickListener mListener;
public interface OnItemClickListener {
public void onItemClick(View view, int position);
}
GestureDetector mGestureDetector;
public CustomRecyclerClickListener(Context context, OnItemClickListener listener) {
@Suleiman19
Suleiman19 / PaginationScrollListener.java
Last active October 23, 2018 07:15
RecyclerView OnScrollListener for Pagination support
public abstract class PaginationScrollListener extends RecyclerView.OnScrollListener {
LinearLayoutManager layoutManager;
public PaginationScrollListener(LinearLayoutManager layoutManager) {
this.layoutManager = layoutManager;
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
@Suleiman19
Suleiman19 / activity_parallax_tabs.xml
Last active August 19, 2018 18:16
Android XML Layout for Parallax scrolling with header Tabs. Uses Design Support Library.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/htab_maincontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
@Suleiman19
Suleiman19 / TabsHeaderActivity.java
Created April 1, 2017 06:51
A simple ViewPager adapter that populates Fragments to create the parallax scrolling effect for Tabs.
private static class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mmFragmentTitleList FragmentList = new ArrayList<>();
private final List<String> = new ArrayList<>();
public ViewPagerAdapter(FragmentManager manager) {
super(manager);
}
@Override
public Fragment getItem(int position) {
@Suleiman19
Suleiman19 / TabsHeaderActivity.java
Created April 1, 2017 07:03
Palette API that fetches a dynamic color from a Bitmap and also includes fallback colors on failure.
try {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.header);
Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
@SuppressWarnings("ResourceType")
@Override
public void onGenerated(Palette palette) {
int vibrantColor = palette.getVibrantColor(R.color.primary_500);
int vibrantDarkColor = palette.getDarkVibrantColor(R.color.primary_700);
collapsingToolbarLayout.setContentScrimColor(vibrantColor);
@Suleiman19
Suleiman19 / TabsHeaderActivity.java
Last active April 1, 2017 06:47
Dummy Fragment that contains a scrollable list to demonstrate parallax scroll effect.
public static class DummyFragment extends Fragment {
int color;
public DummyFragment() {
}
@SuppressLint("ValidFragment")
public DummyFragment(int color) {
this.color = color;
}