/**
* GZip를 이용한 스트링 압축
* @author jksong
* @Param
* @since 2019-09-09 오전 8:30
**/
public static byte[] zipStringToBytes(String input) throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(gzipOutputStream);
bufferedOutputStream.write(input.getBytes());
bufferedOutputStream.close();
byteArrayOutputStream.close();
return byteArrayOutputStream.toByteArray();
}

/**
* GZIPInputStream을 이용하여 byte배열 압축해제하기
* @author jksong
* @Param
* @since 2019-09-09 오전 8:30
**/
public String unzipStringFromBytes(byte[] bytes) throws IOException {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
GZIPInputStream gzipInputStream = new GZIPInputStream(byteArrayInputStream);
BufferedInputStream bufferedInputStream = new BufferedInputStream(gzipInputStream);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

byte[] buffer = new byte[100];
int length;
while((length = bufferedInputStream.read(buffer)) > 0) {
byteArrayOutputStream.write(buffer, 0, length);
}

bufferedInputStream.close();
gzipInputStream.close();
byteArrayInputStream.close();
byteArrayOutputStream.close();

return byteArrayOutputStream.toString();
}

public class SwipeViewPager extends ViewPager {
private boolean enabled;

public SwipeViewPager(Context context) {
super(context);
}

public SwipeViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (enabled) {
return super.onInterceptTouchEvent(ev);
} else {
if (MotionEventCompat.getActionMasked(ev) == MotionEvent.ACTION_MOVE) {
// ignore move action
} else {
if (super.onInterceptTouchEvent(ev)) {
super.onTouchEvent(ev);
}
}
return false;
}
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
if (enabled) {
return super.onTouchEvent(ev);
} else {
return MotionEventCompat.getActionMasked(ev) != MotionEvent.ACTION_MOVE && super.onTouchEvent(ev);
}
}

public void setPagingEnabled(boolean enabled) {
this.enabled = enabled;
}
}

 

setPagingEnabled(false)를 하면 스와이프해서 페이지 이동을 막을 수 있음

'android' 카테고리의 다른 글

android studio plugin  (0) 2021.07.28
startActivityForResult @Deprecated 되어 변경된 코드 예시  (0) 2021.06.25
안드로이드 로그 레벨 색상  (0) 2019.08.12
String to byte 계산  (0) 2019.04.08
urlEncode, urlDecode  (0) 2019.04.08

로그레벨별 추천하는 색상

Debug : 6897BB 

Info : 6A8759 

Warn : BBB529 

Error : FF6B68 

Assert : 9876AA



출처: https://gun0912.tistory.com/31 [박상권의 삽질블로그]

SELECT *
  FROM (SELECT * FROM 테이블 ORDER BY ROWNUM DESC)
 WHERE ROWNUM = 1

  public static String byteCalculation(String bytes) {
    String retFormat = "0";
    Double size = Double.parseDouble(bytes);
    int unit = 1024;
    DecimalFormat df = null;
    
    String[] s = {"B", "KB", "MB", "GB", "TB", "PB"};
    
    if (!bytes.equals("0")) {
      if (size < unit) {
        df = new DecimalFormat("#,###.###");
        double t = size / unit;
        return String.valueOf(df.format(t)) + " " + s[1];
        
      } else {
        int idx = (int) Math.floor(Math.log(size) / Math.log(unit));
        df = new DecimalFormat("#,###");
        double ret = ((size / Math.pow(unit, Math.floor(idx))));
        retFormat = df.format(ret) + " " + s[idx];
      }
    } else {
      retFormat += " " + s[0];
    }
    
    return retFormat;
  }

'android' 카테고리의 다른 글

뷰페이저 스와이프해서 프래그먼튼 이동 막기  (0) 2019.09.30
안드로이드 로그 레벨 색상  (0) 2019.08.12
urlEncode, urlDecode  (0) 2019.04.08
Base64Encode, Decode  (0) 2019.04.08
SharedPreferences  (0) 2019.04.08

  public static String urlEncode(String content, String lngType) throws UnsupportedEncodingException {
    return URLEncoder.encode(content, lngType);
  }
  
  public static String urlDecode(String content, String lngType) throws UnsupportedEncodingException {
    return URLDecoder.decode(content, lngType);
  }

'android' 카테고리의 다른 글

안드로이드 로그 레벨 색상  (0) 2019.08.12
String to byte 계산  (0) 2019.04.08
Base64Encode, Decode  (0) 2019.04.08
SharedPreferences  (0) 2019.04.08
앱 이름 가져오기  (0) 2019.04.08

  public static String base64Encode(String str) {
    return Base64.encodeToString(str.getBytes(), 0);
  }
  
  public static String base64Decode(String str) {
    return new String(Base64.decode(str, 0));
  }

'android' 카테고리의 다른 글

String to byte 계산  (0) 2019.04.08
urlEncode, urlDecode  (0) 2019.04.08
SharedPreferences  (0) 2019.04.08
앱 이름 가져오기  (0) 2019.04.08
버전 정보 가져오기  (0) 2019.04.08

  public static String getAppName(Context mContext) {
    ApplicationInfo applicationInfo = mContext.getApplicationInfo();
    int stringId = applicationInfo.labelRes;
    return stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : mContext.getString(stringId);
  }

'android' 카테고리의 다른 글

Base64Encode, Decode  (0) 2019.04.08
SharedPreferences  (0) 2019.04.08
버전 정보 가져오기  (0) 2019.04.08
JSON String 파싱하기  (0) 2019.03.20
안드로이드 UI 라이브러리 모음  (0) 2019.03.05

  public static String getVersion(Context context) {
    String version = null;
    
    try {
      PackageInfo i = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
      version = i.versionName;
    } catch (PackageManager.NameNotFoundException e) {
      
    }
    
    return version;
  }

'android' 카테고리의 다른 글

SharedPreferences  (0) 2019.04.08
앱 이름 가져오기  (0) 2019.04.08
JSON String 파싱하기  (0) 2019.03.20
안드로이드 UI 라이브러리 모음  (0) 2019.03.05
setDisplayShowCustomEnabled 뒤로 가기 색상 변경  (0) 2018.10.30

+ Recent posts