Skip to content

Instantly share code, notes, and snippets.

View dominicthomas's full-sized avatar

Dominic Thomas dominicthomas

View GitHub Profile
@dominicthomas
dominicthomas / ffmpeg wav -> mp3
Created October 7, 2014 09:30
Convert a wav to a 320k mp3 using ffmpeg.
ffmpeg -i inputfile.wav -ab 320k outputfile.mp3
@dominicthomas
dominicthomas / Android - Launch another app
Created November 28, 2013 16:16
Launch another app using an intent with package name if app has a launcher activity or using package name and class name of main activity.
// only works if app has a launcher activity
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.yourapp");
startActivity(launchIntent);
// works if we know the name of the main activity, even if not a launcher
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.example.yourapp", "com.example.yourapp.MainActivity");
startActivity(intent);
@dominicthomas
dominicthomas / max_height_linear_layout.txt
Created December 8, 2016 12:23
Enables you to set a max height for a linear layout while also using wrap content.. this means the layout will be collapsable but also have height constraints!
public class MaxHeightLinearLayout extends LinearLayout {
private int maxHeightDp;
public MaxHeightLinearLayout(Context context) {
super(context);
}
public MaxHeightLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
@dominicthomas
dominicthomas / json_from_raw
Created June 16, 2015 10:46
Open a json file from the android raw directory and construct using GSON.
public class JSONUtils {
/**
* Open a json file from raw and construct as class using Gson.
*
* @param resources
* @param resId
* @param classType
* @param <T>
* @return
@dominicthomas
dominicthomas / MatchChildViewWithText.kt
Created June 6, 2018 14:01
Use this to iterate through a recycler view item and check each position to see if a view exists that has some specific text set
fun matchChildViewOfAccountTile(accountName: String, targetViewId: Int, itemMatcher: Matcher<View>): Matcher<View> =
object : BoundedMatcher<View, RecyclerView>(RecyclerView::class.java) {
override fun describeTo(description: Description) {
description.appendText("Has view id $targetViewId and matches $itemMatcher for item with name $accountName")
}
public override fun matchesSafely(recyclerView: RecyclerView): Boolean {
val itemCount = recyclerView.adapter.itemCount
for (i in 0 until itemCount) {
val holder = recyclerView.findViewHolderForAdapterPosition(i)
@dominicthomas
dominicthomas / Android Display Content Height
Created January 4, 2014 16:41
Get screen height excluding the action bar and notification bar.
public int getDisplayContentHeight() {
final WindowManager windowManager = getWindowManager();
final Point size = new Point();
int screenHeight = 0, actionBarHeight = 0;
if (getActionBar() != null) {
actionBarHeight = getActionBar().getHeight();
}
int contentTop = ((ViewGroup) findViewById(android.R.id.content)).getTop();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
windowManager.getDefaultDisplay().getSize(size);
@dominicthomas
dominicthomas / adb_iso_country.txt
Created November 3, 2016 14:31
This enables you to change the sim country iso of the android emulator. This and more info here: http://stackoverflow.com/questions/2637606/how-do-i-change-the-mobile-country-code-mcc-in-the-android-emulator
adb shell setprop gsm.sim.operator.iso-country gb
@dominicthomas
dominicthomas / ripple_gradient_layer-list.xml
Created August 22, 2019 14:11
A ripple with a gradient overlay
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/colorPrimary">
<item>
<layer-list>
<item>
<shape android:shape="rectangle">
<gradient
android:angle="90"
android:centerColor="#00ffffff"
android:endColor="#00ffffff"
@dominicthomas
dominicthomas / android_instructions.md
Created May 13, 2019 14:13 — forked from patrickhammond/android_instructions.md
Easily setup an Android development environment on a Mac

Here is a high level overview for what you need to do to get most of an Android environment setup and maintained.

Prerequisites (for Homebrew at a minimum, lots of other tools need these too):

  • XCode is installed (via the App Store)
  • XCode command line tools are installed (xcode-select --install will prompt up a dialog)
  • Java

Install Homebrew:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

@dominicthomas
dominicthomas / setup_bottom_navigation_view.txt
Created January 23, 2017 16:24
Quick guide on setting up a BottomNavigationView programatically..
final BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation_view);
bottomNavigationView.inflateMenu(R.menu.bottom_navigation_main);
bottomNavigationView.setItemBackgroundResource(R.color.colorPrimary);
bottomNavigationView.setItemTextColor(ContextCompat.getColorStateList(bottomNavigationView.getContext(), R.color.bottom_navigation_color_selector));
bottomNavigationView.setItemIconTintList(ContextCompat.getColorStateList(bottomNavigationView.getContext(), R.color.bottom_navigation_color_selector));
bottomNavigationView.setOnNavigationItemSelectedListener(...);