Skip to content

Instantly share code, notes, and snippets.

View mr5z's full-sized avatar
🎯
Focusing

mark mr5z

🎯
Focusing
View GitHub Profile
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;
@mr5z
mr5z / matrix.java
Last active September 3, 2015 19:54
private float[] mSegmentCoords = {
103, 56,
96, 103,
93, 121,
86, 170,
78, 177,
24, 177,
@mr5z
mr5z / bitmap.java
Last active September 3, 2015 20:12
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));
}
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;
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";
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 October 6, 2015 08:51
upload image in localhost:8080
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 November 10, 2015 03:07
A service thread that polls the command queue
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 December 7, 2015 08:25
preferencefragment is shit
private void showSettings() {
getFragmentManager()
.beginTransaction()
.replace(android.R.id.content, new Settings())
.addToBackStack("settings")
.commit();
mSettingsShown = true;
}
private void hideSettings() {
@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;
}