Skip to content

Instantly share code, notes, and snippets.

@johngan
Created June 15, 2016 06:35
Show Gist options
  • Save johngan/f3a4236373b4100df5952a9cd48a10e2 to your computer and use it in GitHub Desktop.
Save johngan/f3a4236373b4100df5952a9cd48a10e2 to your computer and use it in GitHub Desktop.
Android Notes
```
# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
out/
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
# Android Studio captures folder
captures/
# Intellij
*.iml
# Keystore files
*.jks
```
Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
```
# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
# Gradle:
.idea/gradle.xml
.idea/libraries
# Mongo Explorer plugin:
.idea/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
```

Product Flavor

    productFlavors {
        dev {
            applicationId "com.example.ngan.bottombarsample.dev"
        }

        prod {
            applicationId "com.example.ngan.bottombarsample"
        }
    }
# Retrofit 2.0 Notes
### Dependency
```
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
```
### Create service generator
```
public class ServiceGenerator {
private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
private static Retrofit.Builder builder =
new Retrofit.Builder()
.baseUrl(BuildConfig.HOST)
.addConverterFactory(GsonConverterFactory.create());
public static <S> S createService(Class<S> serviceClass) {
Retrofit retrofit = builder.client(httpClient.build()).build();
return retrofit.create(serviceClass);
}
}
```
### Create Model
```
public class Person {
@SerializedName("id")
public int id;
@SerializedName("name")
public String name;
}
```
### Create interface for API services
```
public interface ApiService {
@GET("/path")
Call<List<Person>> getPersonList();
}
```
### Using the API service
```
apiService = ServiceGenerator.createService(ApiService.class);
Call<List<Person>> call = apiService.getPersonList();
call.enqueue(new Callback<List<Person>>() {
@Override
public void onResponse(Call<List<Person>> call, Response<List<Person>> response) {
if (response.isSuccessful()) {
// tasks available
} else {
// error response, no access to resource?
}
}
@Override
public void onFailure(Call<List<Person>> call, Throwable t) {
// something went completely south (like no internet connection)
Log.d("Error", t.getMessage());
}
});
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment