Skip to content

Instantly share code, notes, and snippets.

View ssaurel's full-sized avatar

Sylvain Saurel ssaurel

View GitHub Profile
@ssaurel
ssaurel / ByteArrayDataSource.java
Created March 9, 2017 20:45
ByteArrayDataSource for the Java Mail API on Android Tutorial
public class ByteArrayDataSource implements DataSource {
private byte[] data;
private String type;
public ByteArrayDataSource(byte[] data, String type) {
super();
this.data = data;
this.type = type;
}
@ssaurel
ssaurel / GMailSender.java
Created March 9, 2017 20:48
GMailSender class for the Java Mail API on Android tutorial
public class GMailSender extends javax.mail.Authenticator {
private String mailhost = "smtp.gmail.com";
private String user;
private String password;
private Session session;
static {
Security.addProvider(new JSSEProvider());
}
@ssaurel
ssaurel / Thread.java
Last active March 9, 2017 20:50
Block of code to call the GMailSender class
new Thread(new Runnable() {
@Override
public void run() {
try {
GMailSender sender = new GMailSender("sylvain.saurel@gmail.com",
"your_password");
sender.sendMail("Hello from JavaMail", "Body from JavaMail",
"sylvain.saurel@gmail.com", "sylvain.saurel@gmail.com");
} catch (Exception e) {
@ssaurel
ssaurel / activity_main.xml
Created March 20, 2017 13:38
Layout for the phone call tutorial on Android
<?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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
@ssaurel
ssaurel / CheckPermission.java
Last active March 20, 2017 13:39
CheckPermission method for the phone call tutorial
private boolean checkPermission(String permission) {
return ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED;
}
@ssaurel
ssaurel / RequestPermissions.java
Created March 20, 2017 13:40
Request permissions call for the phone call tutorial on Android
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE}, MAKE_CALL_PERMISSION_REQUEST_CODE);
@ssaurel
ssaurel / OnRequestPermissionsResult.java
Created March 20, 2017 13:41
Request Permission Result method for the phone call Android tutorial
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch(requestCode) {
case MAKE_CALL_PERMISSION_REQUEST_CODE :
if (grantResults.length > 0 && (grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
dial.setEnabled(true);
Toast.makeText(this, "You can call the number by clicking on the button", Toast.LENGTH_SHORT).show();
}
return;
}
@ssaurel
ssaurel / ActivityMain.java
Created March 20, 2017 13:42
Main Activity for the phone call tutorial on Android
package com.ssaurel.phonetut;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
@ssaurel
ssaurel / main_layout.xml
Created April 17, 2017 06:14
Main Layout for the Slot Machine
<?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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.ssaurel.slotmachine.MainActivity"
android:background="#FFFFFF">
@ssaurel
ssaurel / Wheel.java
Created April 17, 2017 06:15
Wheel implementation for the Slot Machine
public class Wheel extends Thread {
interface WheelListener {
void newImage(int img);
}
private static int[] imgs = {R.drawable.slot1, R.drawable.slot2, R.drawable.slot3, R.drawable.slot4,
R.drawable.slot5, R.drawable.slot6};
public int currentIndex;
private WheelListener wheelListener;