Skip to content

Instantly share code, notes, and snippets.

View JakeSteam's full-sized avatar
🤖

Jake Lee JakeSteam

🤖
View GitHub Profile
@JakeSteam
JakeSteam / AlertDialogHelper.java
Last active September 16, 2019 13:10
"Custom Alert Dialog With Dynamic Buttons" for GameDevAlgorithms.com
public class AlertDialogHelper {
private static void displayAlertDialog(Context context, String title, String body, DialogAction... actions) {
LayoutInflater inflater = LayoutInflater.from(context);
final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1);
final View inflatedLayout = inflater.inflate(R.layout.custom_alert_dialog, null);
final AlertDialog dialog = new AlertDialog.Builder(context).create();
dialog.setView(inflatedLayout);
((TextView)inflatedLayout.findViewById(R.id.title)).setText(title);
((TextView)inflatedLayout.findViewById(R.id.body)).setText(body);
@JakeSteam
JakeSteam / LanguageHelper.java
Created May 13, 2017 14:48
"Implementing A Locale / Language Selector" for GameDevAlgorithms.com
public class LanguageHelper {
public static void updateLanguage(Context ctx) {
String lang = PreferenceManager.getDefaultSharedPreferences(ctx).getString("locale", "");
updateLanguage(ctx, lang);
}
public static void updateLanguage(Context context, int language) {
updateLanguage(context, getLocaleById(language));
}
@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 / AndroidManifest.xml
Last active February 23, 2023 14:42
"Generic SharedPreferences Utility Class" for blog.jakelee.co.uk
<application
android:allowBackup="true"
android:fullBackupContent="@xml/backup_rules"
@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>
@JakeSteam
JakeSteam / DrawableModifier.kt
Created September 13, 2018 22:27
"Recolouring / modifying multi-layer drawables dynamically in Android" for blog.jakelee.co.uk
// Changing colour
val layerDrawable = (ImageView)findViewById(R.id.my_drawable).drawable as LayerDrawable
val backgroundDrawable = layerDrawable.findDrawableByLayerId(R.id.background_circle) as GradientDrawable
backgroundDrawable.setColor(ContextCompat.getColor(context, R.color.my_colour))
// Changing drawable
layerDrawable.setDrawableByLayerId(R.id.foreground_icon, ContextCompat.getDrawable(context, R.drawable.new_foreground_icon))
@JakeSteam
JakeSteam / ActionHandler.kt
Last active October 22, 2018 21:18
"Adding Callbacks From Fragment To Activity Or Activity To Application In Android" @ http://blog.jakelee.co.uk/2018/10/22/adding-callbacks-from-fragment-to-activity-or-activity-to-application-in-android
interface ActionHandler {
fun handleAction(actionCode: String)
}