https://github.com/chrynan/glimpse

Android View Styleable Attribute Binding

https://github.com/chrynan/glimpse

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.5%) to scientific vocabulary

Keywords

android android-library annotation-processor

Keywords from Contributors

parcel
Last synced: 5 months ago · JSON representation

Repository

Android View Styleable Attribute Binding

Basic Info
  • Host: GitHub
  • Owner: chRyNaN
  • License: apache-2.0
  • Language: Java
  • Default Branch: master
  • Homepage:
  • Size: 106 KB
Statistics
  • Stars: 5
  • Watchers: 2
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
android android-library annotation-processor
Created almost 9 years ago · Last pushed almost 9 years ago
Metadata Files
Readme License

README.md

glimpse

Android View Styleable Attribute Binding

Easily obtain and bind styleable attribute values. Consider the following custom View class:

```java public class CustomView extends View {

boolean showText; @ColorInt int textColor;

public CustomView(Context context) { this(context, null); }

public CustomView(Context context, AttributeSet attrs) { if (attrs != null) { // Set fields defined in attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomView, 0, 0);

  try {
    showText = a.getBoolean(R.styleable.CustomView_showText, false);
    textColor = a.getColor(R.styleable.CustomView_textColor, getResources().getColor(R.color.default_text_color));
  } finally {
    a.recycle();
  }
} else {
  // Set defaults
  textColor = getResources().getColor(R.color.default_text_color);
}

} ```

This verbose code gets worse the more attributes there are. Glimpse removes the need to write this boilerplate code. With Glimpse, simply annotate your fields with the @Styleable annotation providing their attribute names:

java @Styleable(R.styleable.CustomView_showText) boolean showText; @ColorInt @Styleable(value = R.styleable.CustomView_textColor, defaultRes = R.color.default_text_color) int textColor;

Then call the static obtain method providing the View object instance as the target, the AttributeSet containing the values, and any additional parameters:

java Glimpse.obtain(this, attrs);

Using the library

Currently, in order to use the library, you must clone the repo and run the ./gradlew build command. There should be two jars generated in the following locations:

LOCATION_TO_CLONED_GLIMPSE_FOLDER/compiler/build/libs/glimpse-compiler-VERSION_NUMBER.jar LOCATION_TO_CLONED_GLIMPSE_FOLDER/annotation/build/libs/glimpse-annotation-VERSION_NUMBER.jar

Add these jars to your application's top level libs folder. Then add the following lines to your app module's build.gradle file:

apt files('../libs/glimpse-compiler-VERSION_NAME.jar') compile files('../libs/glimpse-annotation-VERSION_NAME.jar')

Note: If you are using the Jack tool chain with the a newer Gradle version, you can replace the apt command with the annotationProcessor command.

Finally, sync and build your project.

Owner

  • Name: Christopher
  • Login: chRyNaN
  • Kind: user
  • Location: Austin, TX
  • Company: Starry

GitHub Events

Total
Last Year

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 4
  • Total Committers: 2
  • Avg Commits per committer: 2.0
  • Development Distribution Score (DDS): 0.25
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Chris c****n@s****m 3
Christopher b****p@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 7 months ago


Dependencies

annotation/build.gradle maven
  • com.android.support:support-annotations 25.1.1 compile
  • com.google.android:android 4.1.1.4 compileOnly
app/build.gradle maven
  • com.android.support:appcompat-v7 25.1.1 compile
  • junit:junit 4.12 testCompile
compiler/build.gradle maven
  • com.squareup:javapoet 1.8.0 compile