Skip to content

Instantly share code, notes, and snippets.

@apupeikis
apupeikis / DoingSomethingGood.java
Created May 10, 2011
Multi-Threaded Canvas Draws
View DoingSomethingGood.java
private ImageView imageView;
// ...
public void onDoingSomethingGood() {
new Thread(new Runnable() {
public void run() {
final Bitmap bitmap = loadImageFromOutside("http://mycloud.com/image.png");
imageView.post(new Runnable() {
public void run() {
imageView.setImageBitmap(bitmap);
@yoshiki
yoshiki / pom.xml
Created Oct 13, 2011
Maven pom.xml for Android library project
View pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.android</groupId>
<artifactId>my-android-library</artifactId>
<version>0.1</version>
<packaging>apklib</packaging>
<name>my-android-library</name>
@stephenhardy
stephenhardy / git-clearHistory
Created Apr 26, 2013
Steps to clear out the history of a git/github repository
View git-clearHistory
-- Remove the history from
rm -rf .git
-- recreate the repos from the current content only
git init
git add .
git commit -m "Initial commit"
-- push to the github remote repos ensuring you overwrite history
git remote add origin git@github.com:<YOUR ACCOUNT>/<YOUR REPOS>.git
@laaptu
laaptu / DpToPxAndPxToDp
Last active Jan 4, 2021
Android convert dp to px and vice versa
View DpToPxAndPxToDp
public static float convertPixelsToDp(float px){
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
float dp = px / (metrics.densityDpi / 160f);
return Math.round(dp);
}
public static float convertDpToPixel(float dp){
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
float px = dp * (metrics.densityDpi / 160f);
return Math.round(px);
@mnoble01
mnoble01 / international phone number mask
Last active Jun 15, 2020
i18n libphonenumber mask (with in-hand country code)
View international phone number mask
/*
This is using the JS port of Google's libphonenumber.
As far as I know, though, all of the APIs are the same or similar
*/
// I just hardcoded "US" as the country, but of course you can use any country iso code
var ctry = 'US';
var exampleNumber = i18n.phonenumbers.PhoneNumberUtil.getInstance()
.getExampleNumberForType(ctry, i18n.phonenumbers.PhoneNumberType.MOBILE); // returns PhoneNumber instance
@srayhunter
srayhunter / android-adb-over-wifi.md
Last active Jan 13, 2021
Android ADB over Wifi
View android-adb-over-wifi.md

Android ADB over Wifi

Here is a simple way to use ADB over wifi with your device. Make sure that ADB can reach your device over the network.

  1. Connect device to usb

  2. Restart the ADB daemon to listening on TCP port

     adb tcpip 5555
    
@brettwold
brettwold / CustomAdapter.java
Last active Sep 24, 2020
Android adding a popup context menu to a RecyclerView
View CustomAdapter.java
public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder> {
private List<CustomObject> objects;
private OnItemSelectedListener listener;
private final boolean withContextMenu;
class ViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener, View.OnCreateContextMenuListener, PopupMenu.OnMenuItemClickListener {
@BindView(R.id.custom_name)
@Pulimet
Pulimet / AdbCommands
Last active Jan 19, 2021
Adb useful commands list
View AdbCommands
adb help // List all comands
== Adb Server
adb kill-server
adb start-server
== Adb Reboot
adb reboot
adb reboot recovery
adb reboot-bootloader
View FixAppBarLayoutBehavior.java
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
You can’t perform that action at this time.