Skip to content

Instantly share code, notes, and snippets.

View LPirro's full-sized avatar

Leonardo Pirro LPirro

View GitHub Profile
protected BatchAnnotateImagesResponse doInBackground(Object... params) {
try {
GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken);
HttpTransport httpTransport = AndroidHttp.newCompatibleTransport();
JsonFactory jsonFactory = GsonFactory.getDefaultInstance();
Vision.Builder builder = new Vision.Builder
(httpTransport, jsonFactory, credential);
Vision vision = builder.build();
public void performCloudVisionRequest(Uri uri) {
if (uri != null) {
try {
Bitmap bitmap = resizeBitmap(
MediaStore.Images.Media.getBitmap(getContentResolver(), uri));
callCloudVision(bitmap);
selectedImage.setImageBitmap(bitmap);
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
@LPirro
LPirro / MainActivity.kt
Last active May 1, 2018 13:13
Simple animation example using ConstraintLayout and ConstraintSet
private fun showComponents(){
val constraintSet = ConstraintSet()
constraintSet.clone(this, R.layout.circuit_detail)
val transition = ChangeBounds()
transition.interpolator = AnticipateOvershootInterpolator(1.0f)
transition.duration = 1200
TransitionManager.beginDelayedTransition(constraint, transition)
constraintSet.applyTo(constraint)
public class GetOAuthToken extends AsyncTask<Void, Void, Void> {
Activity mActivity;
Account mAccount;
int mRequestCode;
String mScope;
GetOAuthToken(Activity activity, Account account, String scope, int requestCode) {
this.mActivity = activity;
this.mScope = scope;
this.mAccount = account;
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
// Google Cloud Vision API
implementation 'com.google.android.gms:play-services-base:11.8.0'
implementation 'com.google.android.gms:play-services-auth:11.8.0'
implementation 'com.google.apis:google-api-services-vision:v1-rev16-1.22.0'
override fun onClick() {
super.onClick()
val calendarIntent = Intent(Intent.ACTION_EDIT)
calendarIntent.type = "vnd.android.cursor.item/event"
startActivityAndCollapse(calendarIntent)
}
override fun onStartListening() {
super.onStartListening()
val tile = qsTile // this is getQsTile() method form java, used in Kotlin as a property
tile.label = "New Label"
tile.state = Tile.STATE_ACTIVE
tile.icon = Icon.createWithResource(this, R.drawable.other_icon)
tile.updateTile() // you need to call this method to apply changes
}
<service
android:name=".MyTileService"
android:icon="@drawable/ic_tile_calendar"
android:label="@string/calendar_tile_name"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE"/>
</intent-filter>
</service>
class MyTileService: TileService(){
override fun onClick() {
super.onClick()
// Called when the user click the tile
}
override fun onTileRemoved() {
super.onTileRemoved()