Skip to content

Instantly share code, notes, and snippets.

View lethargicpanda's full-sized avatar

Thomas Ezan lethargicpanda

View GitHub Profile
@lethargicpanda
lethargicpanda / PotassiumMainScreen.kt
Created March 20, 2024 04:46
Very basic compose scaffolding for Potassium.
@Composable
fun MainScreen(viewModel: ViewModel) {
val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
var bitmap by remember { mutableStateOf<Bitmap?>(null) }
val textResponse by viewModel.textGenerated.observeAsState()
val isGenerating by viewModel.isGenerating.observeAsState(false)
// Get your image
val resultLauncher =
rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
@lethargicpanda
lethargicpanda / demo_mode.sh
Last active April 22, 2018 20:09
Demo Mode for the Android System UI - force the status bar into a fixed state, useful for taking screenshots with a consistent status bar state, or testing different status icon permutations. Demo mode is available in recent versions of Android. https://android.googlesource.com/platform/frameworks/base/+/master/packages/SystemUI/docs/demo_mode.md
adb shell settings put global sysui_demo_allowed 1
@lethargicpanda
lethargicpanda / rebaseandsqua.sh
Created March 19, 2015 04:49
From rebaseandsqua.sh
#!/bin/sh
set -e
# Get the current branch name.
branch=`git rev-parse --abbrev-ref HEAD`
# Determine the commit at which the current branch diverged.
ancestor=`git merge-base master HEAD`
# Stash any uncommited, changed files.
git stash --all
# Revert the branch back to the ancestor SHA.
@lethargicpanda
lethargicpanda / flavor_manifest.xml
Created November 24, 2014 04:00
Remove permission in manifest
<permission
android:name="your.package.name.permission.BLA"
tools:node="remove"/>
@lethargicpanda
lethargicpanda / duplicate_permission_failure.log
Created November 24, 2014 03:58
INSTALL_FAILED_DUPLICATE_PERMISSION
Failure [INSTALL_FAILED_DUPLICATE_PERMISSION perm=your.package.name.permission.BLA pkg=your.package.name]
@lethargicpanda
lethargicpanda / android_screen_record.sh
Created September 16, 2014 18:53
Android Screen recorder [Script]
adb shell screenrecord /sdcard/video.mp4
adb pull /sdcard/video.mp4
// To instantiate a RippleDrawable:
// new RippleDrawable(null, null), the default constructor isn't public.
// Unfortunately, this has no colors set, so the app will crash, here's another way
int[] attrs = new int[] { android.R.attr.selectableItemBackground};
TypedArray array = getContext().obtainStyledAttributes(attrs);
Drawable drawableFromTheme = array.getDrawable(0);
array.recycle();
setBackground(drawableFromTheme);
@lethargicpanda
lethargicpanda / AccountChecker.java
Last active December 24, 2015 06:29
Check if there is at least one user authenticated on Twitter. Note: this can work for any other app using the AccountManager for the authentication if you pass the right "type". e.g. for vine: "co.vine.android.auth" e.g. for linkedin: "com.linkedin.android"
public boolean isTwitterSignedIn(){
AccountManager manager = AccountManager.get(this);
Account[] account = manager.getAccountsByType("com.twitter.android.auth.login");
if (account.length > 0) {
Log.d("MainActivity", "Authenticated on twitter!");
return true;
} else {
return false;
}
}
@lethargicpanda
lethargicpanda / RunOnUiThread.java
Created August 6, 2013 17:54
Run code on UI thread from a different context.
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
// Code to run on UI
}
});
@lethargicpanda
lethargicpanda / TestStringBlank.java
Last active December 18, 2015 04:09
Checks if a CharSequence is empty ("") or null.
import org.apache.commons.lang3.StringUtils
...
StringUtils.isBlank(myString)