Skip to content

Instantly share code, notes, and snippets.

View akexorcist's full-sized avatar
🔥

Akexorcist akexorcist

🔥
View GitHub Profile
public void startReceiver() {
registerReceiver(broadcastReceiver, new IntentFilter(DELIVERED));
}
public void stopReceiver() {
unregisterReceiver(broadcastReceiver);
}
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
@akexorcist
akexorcist / gist:9780281
Last active August 29, 2015 13:57
Model Class
public class QuizModel {
public String strQuiz = null;
public String strAnwser = null;
public QuizModel(String strQuiz, String strAnwser) {
this.strQuiz = strQuiz;
this.strAnwser = strAnwser;
}
public String getQuiz() {
@akexorcist
akexorcist / DirectionActivity.java
Last active August 29, 2015 13:58
Google Direction And Place Sample Code
package app.akexorcist.googledapsample;
import org.w3c.dom.Document;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
@akexorcist
akexorcist / Op1.java
Created May 5, 2014 20:01
ตัวอย่างการใช้ Listener กับหลายๆ View
Button btn1 = (Button)findViewById(R.id.btn1);
btn1.setOnClickLlistener(new OnClickListener() {
public void onClick(View v) {
// Button 1 Command
}
});
Button btn2 = (Button)findViewById(R.id.btn2);
btn2.setOnClickLlistener(new OnClickListener() {
public void onClick(View v) {
@akexorcist
akexorcist / a.java
Last active August 29, 2015 14:01
แปลงหน่วย dp เป็น px และแปลงหน่วย px เป็น dp
public int dpToPx(Context context, int dp) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
return px;
}
public int pxToDp(Context context, int px) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
int dp = Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
return dp;
@akexorcist
akexorcist / check_internet_available.java
Last active August 29, 2015 14:01
ตรวจสอบว่าสามารถเชื่อมต่ออินเตอร์เน็ตได้หรือไม่ โดยใช้วิธี Ping ไปที่เซิฟเวอร์ของ Google
ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected()) {
try {
URL pingUrl = new URL("http://www.google.com");
HttpURLConnection urlc = (HttpURLConnection)pingUrl.openConnection();
urlc.setConnectTimeout(3000);
urlc.connect();
if (urlc.getResponseCode() == 200) {
// ผู้ใช้ต่อเนตและใช้งานได้
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<solid android:color="@color/light_green" />
</shape>
@akexorcist
akexorcist / resizeBitmap.java
Last active August 29, 2015 14:02
Resize bitmap with same ratio
public Bitmap resizeBitmap(Bitmap bm, int maxWidth, int maxHeight) {
int newWidth, newHeight;
int bmWidth = bm.getWidth();
int bmHeight = bm.getHeight();
if(bmWidth > maxWidth && (maxWidth * bmHeight) / bmWidth < maxHeight) {
newWidth = maxWidth;
newHeight = (maxWidth * bmHeight) / bmWidth;
} else {
newWidth = (maxHeight * bmWidth) / bmHeight;
newHeight = maxHeight;
@akexorcist
akexorcist / AndroidManifest.xml
Last active August 29, 2015 14:02
ตัวอย่างคำสั่งเริ่มต้นสำหรับแอปพลิเคชั่นแอนดรอยด์เพื่อเชื่อมต่อกับบอร์ด IOIO หรือ IOIO-Q
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.inex.ioioapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
@akexorcist
akexorcist / AndroidManifest.xml
Last active August 29, 2015 14:02
ตัวอย่างแอปพลิเคชั่นเบื้องต้นเพื่อควบคุมบอร์ด IOIO หรือ IOIO-Q โดยจะสั่งให้ LED ที่อยู่บนบอร์ดติดดับตามที่กด Toggle Button ในแอปพลิเคชั่น
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.inex.ioioapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />