Skip to content

Instantly share code, notes, and snippets.

View mtsahakis's full-sized avatar

Manos Tsahakis mtsahakis

  • Bishops Stortford, United Kingdom
View GitHub Profile
@mtsahakis
mtsahakis / android_database.sh
Last active August 30, 2019 16:42
This script takes three command line arguments, device id {as read from adb devices -l}, your application's package id {like com.mobile.myapp} and database name as exists inside data/data/{package id}/databases directory of the device or emulator. It then starts sqlitebrowser pointing to the database just pulled from the device.
#!/usr/bin/env bash
# check if a device is supplied as a command line argument
DEVICE_ID=$1
if [[ "$DEVICE_ID" == "" ]]; then
echo "No device id supplied"
exit 1
fi
# check if a package id is supplied as a command line argument
# The Gradle daemon aims to improve the startup and execution time of Gradle.
# When set to true the Gradle daemon is to run the build.
org.gradle.daemon=true
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx6144m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
@mtsahakis
mtsahakis / Installing Android SDK on a headless server.md
Last active May 15, 2022 12:31
This document describes how to install Android SDK on a headless Linux server, i.e. a server with no GUI, just a shell. This proved very useful when I had to set up Android builds for Continuous Integration.

Installing Android SDK, NDK and toolset

Search for the download page of Android command line tools. As of this writing, download page is https://developer.android.com/studio/ but this is highly likely to change in the future.

Navigate to the aforementioned download page and search for Command Line Tools link for the specific platform you are targeting. The most likely target platform is Linux.

After locating the link, ssh to your server, preferably as root. Create directory that would ultimately host Android binaries and use wget tool to download Command Line Tools, as per bellow:

mkdir /opt/android
@mtsahakis
mtsahakis / TrampolineSchedulerRule.java
Created December 5, 2017 20:24
Rule for junit testing so as to run RxJava code on the junit Thread of execution. Instantiate as field member on a junit test class: @rule public TrampolineSchedulerRule mTrampolineSchedulerRule = new TrampolineSchedulerRule();
@Override
public Statement apply(final Statement base, Description d) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
RxJavaPlugins.setIoSchedulerHandler(scheduler -> Schedulers.trampoline());
RxJavaPlugins.setComputationSchedulerHandler(scheduler -> Schedulers.trampoline());
RxJavaPlugins.setNewThreadSchedulerHandler(scheduler -> Schedulers.trampoline());
RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerCallable -> Schedulers.trampoline());
package com.mtsahakis.activity;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.projection.MediaProjectionManager;
import android.os.Bundle;
@TargetApi(21)
package com.mtsahakis.mediaprojectiondemo;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.projection.MediaProjectionManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
package com.mtsahakis.mediaprojectiondemo;
import android.app.Activity;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.hardware.display.DisplayManager;
@mtsahakis
mtsahakis / QueryPreferences.java
Created March 30, 2016 15:13
A simple utility class that checks whether an app is started for the first time. If so, it sets a boolean shared preferences value accordingly.
import android.content.Context;
import android.preference.PreferenceManager;
public class QueryPreferences {
private static final String sIsFirstRun = "IS_FIRST_RUN";
public static boolean isFirstRun(Context context) {
boolean result = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(sIsFirstRun, true);
if(result) {
@mtsahakis
mtsahakis / PermissionUtils.java
Last active January 6, 2024 09:16
Android Permission Utility class. A collection of static convenience methods for checking if Android Runtime permissions are required.
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.v4.app.Fragment;
import java.util.List;
@mtsahakis
mtsahakis / GridFragment.java
Last active April 25, 2021 22:40
Dynamically set span count in an Android RecyclerView's GridLayoutManager. Implementation is taken from a Fragment.
private RecyclerView mRecyclerView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_view, container, false);
mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
// ommiting other recycler view set up, such as adapter and Layout manager set up ..
ViewTreeObserver viewTreeObserver = mRecyclerView.getViewTreeObserver();
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {