Skip to content

Instantly share code, notes, and snippets.

View akexorcist's full-sized avatar
🔥

Akexorcist akexorcist

🔥
View GitHub Profile
@akexorcist
akexorcist / gist:7558524
Last active December 28, 2015 20:39
ยกเลิก Focus ที่ Edit Text เมื่อเข้าสู่หน้านั้นๆ
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true" >
<requestFocus />
<ListView
@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 / write_text_file.java
Last active March 5, 2022 14:02
ฟังก์ชันเขียนไฟล์ txt ธรรมดาๆ โดยมีแบบเขียนทับหรือเขียนต่อจากเดิม
public void appendTextFile(String text) {
File file = new File("sdcard/text.txt");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
@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 / app_listing.java
Last active August 29, 2023 02:16
Get application name android package name from all application which have launcher (Not all app in device)
PackageManager pm = getPackageManager();
Intent main = new Intent(Intent.ACTION_MAIN, null);
main.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> packages = pm.queryIntentActivities(main, 0);
ArrayList<String> app_name_list = new ArrayList<String>();
ArrayList<String> app_package_list = new ArrayList<String>();
for(ResolveInfo resolve_info : packages) {
try {
@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;