Skip to content

Instantly share code, notes, and snippets.

View PanelView.java
package com.nkraft.mcusimulator;
import com.nkraft.mcusimulator.KeypadModule.OnKeypadClickListener;
import com.nkraft.nkraftlibs.Debug;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
View matrix.java
private float[] mSegmentCoords = {
103, 56,
96, 103,
93, 121,
86, 170,
78, 177,
24, 177,
View bitmap.java
protected void setModuleInterface(Context context, int resourceImageId) {
int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceImageId);
float aspectRatio = bitmap.getWidth() / (float) bitmap.getHeight();
int height = Math.round(screenWidth / aspectRatio);
bitmap = Bitmap.createScaledBitmap(bitmap, screenWidth, height, true);
BITMAP_WIDTH = bitmap.getWidth();
BITMAP_HEIGHT = bitmap.getHeight();
setBackground(new BitmapDrawable(context.getResources(), bitmap));
}
View matrix.java
private void scaleMatrix(int screenWidth, int screenHeight) {
// Title bar height
int shift = 100;
int maxWidth = 800;
int maxHeight = 1280 - shift;
int height = screenHeight - ((shift * screenHeight) / maxHeight);
float xDpi = getResources().getDisplayMetrics().xdpi;
float yDpi = getResources().getDisplayMetrics().xdpi;
float density = getResources().getDisplayMetrics().density;
View fuck_this_shit.java
private void appendLog(String msg) {
mLogContent.add(msg);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
String formattedMsg = "";
Iterator<String> iter = mLogContent.iterator();
while( iter.hasNext() ) {
String m = iter.next();
formattedMsg += m + "\n";
View fragmentdialoglistview.java
public class FragmentListCommandDialog extends DialogFragment implements OnItemClickListener {
public interface CommandClickListener {
public void onCommandClick(CommandRow command);
}
/**
* You can found this file in the assets folder
*/
private static final String BC_COMMAND_LIST_FILENAME = "bccommands.json";
@mr5z
mr5z / file_upload.java
Created Oct 6, 2015
upload image in localhost:8080
View file_upload.java
private int uploadImage(File imageFile) {
int serverResponseCode = -1;
String fileName = imageFile.getName();
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
@mr5z
mr5z / CommandQueuePollingExecutor.java
Created Nov 10, 2015
A service thread that polls the command queue
View CommandQueuePollingExecutor.java
public class Test {
public static void main(String[] args) {
Thread t = new Thread(new Executor());
t.start();
System.out.println("I'm from the main thread!");
Thread.sleep(5000);
try {
System.out.println("Interrupting another thread...");
t.interrupt();
@mr5z
mr5z / PreferenceFragmentShit.java
Created Dec 7, 2015
preferencefragment is shit
View PreferenceFragmentShit.java
private void showSettings() {
getFragmentManager()
.beginTransaction()
.replace(android.R.id.content, new Settings())
.addToBackStack("settings")
.commit();
mSettingsShown = true;
}
private void hideSettings() {
View PopupMenuOnClick.java
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.action_forget_device:
// mDevices is an ArrayList<T>
mDevices.remove(index); // determine the index
return true;
default:
return false;
}