Skip to content

Instantly share code, notes, and snippets.

View JakeSteam's full-sized avatar
🤖

Jake Lee JakeSteam

🤖
View GitHub Profile
@JakeSteam
JakeSteam / PuzzleGenerator.java
Created January 5, 2017 16:00
Asynchronous Puzzle Generator for Android, published on Game Dev Algorithms blog
package uk.co.jakelee.cityflow.components;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.widget.TextView;
import java.util.ArrayList;
@JakeSteam
JakeSteam / DisplayHelper.java
Created January 7, 2017 01:17
"Android: Displaying Levels At Optimum Zoom" core functions for GameDevAlgorithms
public TileDisplaySetup setupTileDisplay(PuzzleDisplayer puzzleDisplayer, List<Tile> tiles, ZoomableViewGroup tileContainer, Tile selectedTile, ImageView selectedTileImage, boolean isEditor) {
tileContainer.removeAllViews();
Setting minimumMillisForDrag = Setting.get(Constants.SETTING_MINIMUM_MILLIS_DRAG);
int dragDelay = minimumMillisForDrag != null ? minimumMillisForDrag.getIntValue() : 200;
Pair<Integer, Integer> maxXY = TileHelper.getMaxXY(tiles);
DisplayValues displayValues = getDisplayValues(puzzleDisplayer.getActivity(), maxXY.first + 1, maxXY.second + 1);
float optimumScale = displayValues.getZoomFactor();
@JakeSteam
JakeSteam / activity_main.xml
Created January 10, 2017 22:21
"Android: Asynchronous Database ORM Install" snippets for GameDevAlgorithms
<RelativeLayout
android:id="@+id/progressWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/mainLogo">
<uk.co.jakelee.cityflow.components.TextViewFont
android:id="@+id/progressText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@JakeSteam
JakeSteam / AnvilActivity.java
Created January 24, 2017 20:15
"Android: Playing Random Sounds" for GameDevAlgorithms.com
SoundHelper.playSound(this, SoundHelper.smithingSounds);
@JakeSteam
JakeSteam / ExportActivity.java
Created April 6, 2017 18:46
"Exporting Levels Into QR Codes Using ZXing" for GameDevAlgorithms.com
private void populateCard() {
...
StorageHelper.fillWithQrDrawable((ImageView) findViewById(R.id.puzzleQrCode), exportedText);
}
@JakeSteam
JakeSteam / BaseActivity.java
Last active June 5, 2017 19:16
"Selectively Playing Tracks Whilst Game Is Active / Open" for GameDevAlgorithms.com
public class BaseActivity extends Activity {
@Override
protected void onResume() {
super.onResume();
MusicHelper.getInstance(this).setMovingInApp(false);
}
@Override
public void onPause() {
super.onPause();
@JakeSteam
JakeSteam / BaseActivity.java
Created June 13, 2017 11:12
"Auto-detecting Device Orientation Whilst Allowing User to Override" for GameDevAlgorithms.com
@Override
protected void onResume() {
super.onResume();
//noinspection ResourceType
setRequestedOrientation(Setting.get(Enums.Setting.Orientation).getIntValue());
}
@JakeSteam
JakeSteam / AndroidManifest.xml
Created July 7, 2017 11:29
"Getting Started with Sugar ORM" for GameDevAlgorithms.com
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourpackagename">
<application
android:name=".MainApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
<meta-data
android:name="DATABASE"
@JakeSteam
JakeSteam / LockableViewPager.kt
Last active September 7, 2018 17:25
"Dynamically preventing scrolling on selected ViewPager pages" for blog.jakelee.co.uk
import android.content.Context
import android.support.v4.view.ViewPager
import android.util.AttributeSet
import android.view.MotionEvent
enum class SwipeDirection { BOTH, LEFT, RIGHT, NONE }
// https://stackoverflow.com/a/34076649/608312
class LockableViewPager(context: Context, attrs: AttributeSet) : ViewPager(context, attrs) {
@JakeSteam
JakeSteam / styles.xml
Created September 10, 2018 18:30
"Using multi-weighted custom fonts on Android" for blog.jakelee.co.uk
<style name="Font_Regular" tools:keep="@style/Font_Regular">
<item name="android:fontFamily">@font/the_sans_c4s</item>
</style>
<style name="Font_Regular_Italic" parent="Font_Regular" tools:keep="@style/Font_Regular_Italic">
<item name="android:textStyle">italic</item>
</style>
<style name="Font_Bold" parent="Font_Regular" tools:keep="@style/Font_Bold">
<item name="android:textStyle">bold</item>