Skip to content

Instantly share code, notes, and snippets.

View ssaurel's full-sized avatar

Sylvain Saurel ssaurel

View GitHub Profile
@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;
@ssaurel
ssaurel / MainActivity.java
Created April 17, 2017 06:16
Main Activity of the Slot Machine
public class MainActivity extends AppCompatActivity {
private TextView msg;
private ImageView img1, img2, img3;
private Wheel wheel1, wheel2, wheel3;
private Button btn;
private boolean isStarted;
public static final Random RANDOM = new Random();
@ssaurel
ssaurel / MorseCode.java
Last active April 24, 2017 07:35
MorseCode object
package com.ssaurel.morseconverter;
import java.util.HashMap;
public class MorseCode {
static String[] ALPHA = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "!", ",", "?",
".", "'" };
static String[] MORSE = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..",
@ssaurel
ssaurel / activity_main.xml
Created April 24, 2017 07:44
MorseCode App Main Layout
<?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 / MainActivity.java
Created April 24, 2017 07:47
MainActivity for the Morse Code App Tutorial
package com.ssaurel.morseconverter;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {