Skip to content

Instantly share code, notes, and snippets.

Yannick Lemin theyann

Block or report user

Report or block theyann

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@theyann
theyann / KeyStoreCompat.java
Created Apr 15, 2017
KeyStoreCompat is a simple class that takes care of dealing with KeyStore and using the AndroidKeyStore when it can, or another type if it can't. You're welcome.
View KeyStoreCompat.java
package YOUR_PACKAGE;
import android.content.Context;
import android.os.Build;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.cert.Certificate;
@theyann
theyann / StringHelper.java
Created Dec 11, 2015
StringHelper is a utility class using a similar interface and proposing similar functionalities than commons lang StringUtils. Internally it is using Android system methods.
View StringHelper.java
package X.Y.Z;
import android.text.TextUtils;
import android.util.Base64;
/**
* Created by ylemin on 07/09/15.
*
* This class is similar in functionalities as the commons.lang.StringUtils, but using as much
* of the Android built-in tools and helpers as possible
@theyann
theyann / PrefUtils.java
Created Dec 11, 2015
PrefUtils is a base class intended to simplify and clarify the code relative to dealing with SharedPreferences. It is very simple and it is meant to be.
View PrefUtils.java
package X.Y.Z;
import android.content.SharedPreferences;
/**
* Created by ylemin on 21/11/15.
*
* This class is a bunch of recurring methods used when dealing with SharedPreferences.
* It is intended to be a base class which receives the SharedPreferences instance from the child class.
* There should only be one instance of SharedPreferences per app.
@theyann
theyann / WidgetProvider.java - onDelete
Created Nov 14, 2015
AppWidgetProvider for configurable widget, onDelete example
View WidgetProvider.java - onDelete
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
super.onDeleted(context, appWidgetIds);
WidgetEntryDao dao = new WidgetEntryDao(new DbHelper(context));
final int N = appWidgetIds.length;
for (int i = 0; i < N; i++) {
dao.deleteByWidgetId(appWidgetIds[i]);
}
@theyann
theyann / EmailIntent.java
Last active Nov 14, 2015
Two ways to open email apps from intent, pre-filling datas. These two methods
View EmailIntent.java
// creating the intent with all the information we want to pre-fill
Intent intent = new Intent(Intent.ACTION_SEND);
// array of destination email addresses
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "email1@company.com", "email2@othercompany.com" });
intent.putExtra(Intent.EXTRA_SUBJECT, "my subject");
intent.putExtra(Intent.EXTRA_TEXT, "some message body");
// This type narrows down the amount of apps that will be displayed in the app choice dialog
intent.setType("message/rfc822"); // it should be mostly email apps
@theyann
theyann / WidgetProvider.java - onUpdate
Last active Nov 14, 2015
AppWidgetProvider for configurable widget, onUpdate example
View WidgetProvider.java - onUpdate
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
WidgetEntryDao dao = new WidgetEntryDao(new DbHelper(context));
final int N = appWidgetIds.length;
// Perform this loop procedure for each App Widget that belongs to this provider
for (int i = 0; i < N; i++) {
int appWidgetId = appWidgetIds[i];
You can’t perform that action at this time.