Android Components


Source link: https://github.com/MartuPuri/Android-Components

Android Components

Android components is an android library which contains improvements of native android components.

Usage

Using Gradle

You can just add the dependency like below

repositories {

  jcenter() 
}
 

And then you can add the library as dependency

dependencies {

  compile 'com.masacre:android-components:1.2.1' 
}
 

Components

ClickableRecyclerView

The ClickableRecyclerView improve the RecyclerView by adding method to handle the android.view.View.OnClickListener and android.view.View.OnLongClickListener of each android.support.v7.widget.RecyclerView.ViewHolder.

There are two exclusive ways of handle the click event.

  1. Register the following listeners OnViewHolderClickListener and/or OnViewHolderLongClickListener in the recycler view
  2. Override the methods android.view.View.OnClickListener# onClick(View) and/or android.view.View.OnLongClickListener# onLongClick(View) in the view holder

Sample

final ClickableRecyclerView recyclerView = (ClickableRecyclerView) findViewById(R.id.recycler_view);
 recyclerView.setLayoutManager(new LinearLayoutManager(this));
  final DCSeriesAdapter dcSeriesAdapter = new DCSeriesAdapter(this, Arrays.asList("Arrow", "The Flash", "DC's Legends of Tomorrow"));
  recyclerView.setAdapter(dcSeriesAdapter);
 

The class DCSeriesAdapter must extends from ClickableRecyclerView.ClickableAdapter<DCViewHolder>, and DCViewHolder must extends from ClickableRecyclerView.ClickableViewHolder

In this example we are going to handle the onClick registering the listener in the recycler view and handle the onLongClick in the DCViewHolder.

When we register the OnViewHolderClickListener the method onClick implemented in the view holder will not be called.

recyclerView.setOnViewHolderClickListener(new ClickableRecyclerView.OnViewHolderClickListener<DCSeriesViewHolder>() {

  @Override
  public void onItemClick(final DCSeriesViewHolder holder, final int position) {

Toast.makeText(MainActivity.this, "Recycler onClick: " + holder.getText(), Toast.LENGTH_SHORT).show();

  
}
 
}
);

Now we have to implement the onLongClick in the DCSeriesViewHolder

public class DCSeriesViewHolder extends ClickableRecyclerView.ClickableViewHolder {

private final Context context;
  private final TextView seriesTitle;

public DCSeriesViewHolder(final Context context, final View view) {

super(view);

this.context = context;

this.seriesTitle = (TextView) view.findViewById(R.id.textview);

  
}

private void findViews(final View view) {

this.seriesTitle = (TextView) view.findViewById(R.id.textview);

  
}

public void show(final String value) {

seriesTitle.setText(value);

  
}

@Override
  public boolean onLongClick(View v) {

Toast.makeText(context, "DCSeriesViewHolder onLongClick: " + textView.getText(), Toast.LENGTH_SHORT).show();

return true;
  
}

public String getText() {

return seriesTitle.getText().toString();

  
}
 
}

PullDownSwipeRefreshLayout

A PullDownSwipeRefreshLayout improve the SwipeRefreshLayout by adding a method to handle the pull down of the swipe refresh layout.

To handle this event you must register a PullDownListener.

Sample

final PullDownSwipeRefreshLayout layoutSwipeRefresh = (PullDownSwipeRefreshLayout) findViewById(R.id.pull_to_refresh);
  layoutSwipeRefresh.setPullDownListener(new PullDownSwipeRefreshLayout.PullDownListener() {

  @Override
  public void onPullDown() {

Toast.makeText(MainActivity.this, "Pull down", Toast.LENGTH_SHORT).show();

  
}
 
}
);
 

ImagePicker

The ImagePicker provides you a full component, that allow you to select a picture from each gallery and camera apps that your device has

Sample

public class MainActivity extends AppCompatActivity {
  private static final int PICK_IMAGE_REQUEST_CODE = 2352;
@Override  protected void onCreate(final Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

 final Button pickPictureButton = (Button) findViewById(R.id.pick_picture_button);

pickPictureButton.setOnClickListener(new View.OnClickListener() {

 @Override
 public void onClick(final View v) {

  final Intent pickImageIntent = ImagePicker.getPickImageIntent(MainActivity.this,

 ImagePicker.ImagePickerIntentType.CAMERA, ImagePicker.ImagePickerIntentType.GALLERY);

  startActivityForResult(pickImageIntent, PICK_IMAGE_REQUEST_CODE);

 
}

}
);
  
}

@Override  protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {

super.onActivityResult(requestCode, resultCode, data);

if (requestCode == PICK_IMAGE_REQUEST_CODE) {

 try {

  final BitmapImage bitmapImage = ImagePicker.getImageFromResult(this, resultCode, data);

  //Use image
 
}
 catch (IOException e) {

  //Handle error
 
}

}
  
}
 
}

Material Typography & Colors

Now, you can use all material typography (Roboto family) and the complete palette colors.

Versions

  • 1.0.0
    • ClickableRecyclerView
  • 1.1.0
    • PullDownSwipeRefreshLayout
    • ImagePicker
  • 1.2.0
    • Material Typography
    • Material Colors
    • Upgrade to compile sdk api level 24
  • 1.2.1
    • Update travis to api level 24

Copyright and License

Copyright 2016 Martin Purita.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License at:

http://www.apache.org/licenses/LICENSE-2.0

Resources

Theo is a Gradle plugin that provides annotations for each "dangerous android permission".

Customized toggle button.

Cicerone is a lightweight library that makes the navigation in an Android app easy.

Custom view to pick up a value from a given range using click button or swiping.

ImageMap is a small android library for displaying multiple image on a view using an adapter, you can then retrieve tap event on defined image.

SpannableBar is a Grid-style spannable bar, that is useful when you need a way to span a bar over columns. The view allows you to set the starting column, the span, the number of columns, and more.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes