Skip to content

Instantly share code, notes, and snippets.

View lucamtudor's full-sized avatar

Tudor Luca lucamtudor

View GitHub Profile
@lucamtudor
lucamtudor / AndroidManifest.xml
Created July 2, 2013 10:00
Method to check if the Android device is connected to the Internet.
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
@lucamtudor
lucamtudor / ImageHelper.java
Created July 2, 2013 10:14
ImageHelper that has the following features: - getRoundedCornerBitmap() : Create a round shape cropped Bitmap from an existing Bitmap. - decodeUri() : Obtains an image at a specified Uri.
/**
* @author Tudor Luca
*/
public class ImageHelper {
public static class Options {
/**
* If not set, the source Bitmap width will be used.
*/
@lucamtudor
lucamtudor / Config.java
Created July 2, 2013 10:19
Helper methods that make logging more consistent throughout the application.
public class Config {
public static final boolean DEBUG = true;
}
@lucamtudor
lucamtudor / ViewServer.java
Created July 2, 2013 10:24
This class can be used to enable the use of HierarchyViewer inside an * application. HierarchyViewer is an Android SDK tool that can be used to * inspect and debug the user interface of running applications. For security * reasons, HierarchyViewer does not work on production builds (for instance * phones bought in store.) By using this class, yo…
/*
* Copyright (C) 2011 The Android Open Source Project Licensed under the Apache
* License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
* or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
/*
* Copyright 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.trifork.example"
android:installLocation="auto"
android:versionName="@string/client_info" >
<!-- ... -->
<application
android:hardwareAccelerated="true"
<provider
android:name=".providers.AssetProvider"
android:authorities="@string/provider_asset"
android:multiprocess="true"
android:exported="true"/>
<provider
android:name=".providers.AssetTagProvider"
android:authorities="@string/provider_assettags"
android:multiprocess="true"
@lucamtudor
lucamtudor / .gitignore
Created January 10, 2014 23:06
Android .gitignore, both for Eclipse ADT and Android Studio/Intellij IDEA based projects.
# OSX files
.DS_Store
# Ignore gradle files
.gradle
.gradletasknamecache
# generated files
bin/
public class ColorUtils {
private static final double LM_RED_COEFFICIENT = 0.2126;
private static final double LM_GREEN_COEFFICIENT = 0.7152;
private static final double LM_BLUE_COEFFICIENT = 0.0722;
public static int calculateRelativeLuminance(int color) {
int red = (int) (Color.red(color) * LM_RED_COEFFICIENT);
int green = (int) (Color.green(color) * LM_GREEN_COEFFICIENT);
int blue = (int) (Color.blue(color) * LM_BLUE_COEFFICIENT);
return red + green + blue;
@lucamtudor
lucamtudor / Example.java
Created September 18, 2014 12:33
An array adapter that uses the last item as a hint. Use with a spinner
String[] strings = getResources().getStringArray(R.array.spinner_options);
HintAdapter<String> hintAdapter = new HintAdapter<String>(this, android.R.layout.simple_spinner_item, strings);
hintAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpinner.setAdapter(hintAdapter);
mSpinner.setSelection(hintAdapter.getCount());