Skip to content

Instantly share code, notes, and snippets.

View yung-yu's full-sized avatar

Andy.li yung-yu

View GitHub Profile
@yung-yu
yung-yu / gist:8485ab28e0bfe736cffddd19d61dbdb4
Created May 11, 2017 06:34
檢查 uri 從google相簿app回來,需要另外處理取得Uri
/**
* 檢查 uri 從google相簿app回來,需要另外處理取得Uri
* @param photoUri
* @return Uri
*/
public static Uri getExternalMediaUriFormContentUri(Uri photoUri){
if(photoUri.getAuthority() != null){
if(photoUri.getAuthority().equals("com.google.android.apps.photos.contentprovider")){
List<String> paths = photoUri.getPathSegments();
if(paths != null && paths.size() > 0){
@yung-yu
yung-yu / gist:8e5afbc632112f52773f93ff2b8927ab
Created May 12, 2017 09:45
Android 截取手機畫面
MediaProjectionManager mediaProjectionManager =
(MediaProjectionManager) getApplication().getSystemService(
Context.MEDIA_PROJECTION_SERVICE);
startActivityForResult(
mediaProjectionManager.createScreenCaptureIntent(), CAPTURE_PERMISSION_REQUEST_CODE);
@yung-yu
yung-yu / gist:7ca188bb8b0d0f9b3222c8892a630996
Created May 15, 2017 03:46
讓Acitvity切換橫向直向不要重啟
AndroidManifest.xml
-----------------------------------
<activity
android:name=".DemoActivity"
android:screenOrientation="unspecified"
android:configChanges="orientation|screenSize"
/>
DemoActivity.java
-------------------------------
import android.animation.Animator;
import android.os.Handler;
import android.os.Message;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import java.util.Timer;
import java.util.TimerTask;
@yung-yu
yung-yu / gist:bdc84feb341a1dcb6c230b7e7c8a0a39
Created June 21, 2017 08:18
Android ListView 簡單的綁定單一class物件使用
public abstract class CommonAdapter<T> extends BaseAdapter {
public List<T> data;
public Context mContext;
public CommonAdapter(Context context) {
this.mContext = context;
}
public void setData(List<T> data) {
this.data = data;
含有英文大小寫和數字,且長度在8~12
^(?!.*[^a-zA-Z0-9])(?=.*\d)(?=.*[a-zA-Z])(?=.*[A-Z])(?=.*[a-z]).{8,12}$
至少一個英文不分大小寫及一個數字 , 8~12位
/^(?!.*[^a-zA-Z0-9])(?=.*\d)(?=.*[a-zA-Z]).{8,12}$/
email格式
/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/
禁止中,英,數,減號( - )以外的字元,至少要連續中文4個字,至少一位數字,字元數共8~40位
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
@yung-yu
yung-yu / gist:d604b61889d2e90089383ca331a787e9
Created January 4, 2018 08:14
Android建立一個遮罩上層下拉選單的view
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_RMISSION) {
if (Settings.canDrawOverlays(this)) {
addProtectView();
}
}
}
@yung-yu
yung-yu / gist:4ea4b06545ea5387d80819ad3f046187
Created January 19, 2018 01:48
android illeagal file name char
private static final String ReservedChars = "|\\?*<\":>+[]/'";
@yung-yu
yung-yu / gist:8bbf8d46e1146a9e2f734f5397693af5
Created February 23, 2018 07:06
台灣行政區域郵遞區號3碼
public static void getZipJsonFile(Context context){
try {
JSONObject result = new JSONObject();
String response = HttpProcessor.get(context, "https://api.opencube.tw/twzipcode/get-citys", 1);
Log.d(response);
JSONObject jsonObject = new JSONObject(response.trim());
JSONArray jsonArray = jsonObject.getJSONArray("data");
for(int i = 0; i< jsonArray.length(); i++){
String city = jsonArray.getString(i);