Skip to content

Instantly share code, notes, and snippets.

@poemsk
Last active May 2, 2020 11:55
Show Gist options
  • Save poemsk/d973ac46d7df11dd74db9cdcc1ef3acd to your computer and use it in GitHub Desktop.
Save poemsk/d973ac46d7df11dd74db9cdcc1ef3acd to your computer and use it in GitHub Desktop.
Building Android Library From Scratch
public class ExampleClient {
public static final String ENVIRONMENT_DEV = "DEV";
public static final String ENVIRONMENT_PROD = "PROD";
public static final String ENVIRONMENT_STAGING = "STG";
@Retention(RetentionPolicy.SOURCE)
@StringDef({ENVIRONMENT_DEV, ENVIRONMENT_PROD, ENVIRONMENT_STAGING})
public @interface Environment {
}
private ExampleClient(Context context, String key, int logLevel, @Environment String environment) {
}
private static Builder {
private Context context;
private String key;
private int logLevel;
private String environment
public Builder(Context context, String key) {
this.context = context;
this.key = key;
}
public Builder setLogLevel(int logLevel) {
this.logLevel = logLevel;
return this;
}
public Builder setEnvironment(@Environment String environment) {
this.environment = environment;
return this;
}
public ExampleClient build() {
return new ExampleClient(this.context, this.key, this.logLevel, this.environment)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment