Skip to content

Instantly share code, notes, and snippets.

View Gongcu's full-sized avatar
🏠
Working from home

Chaeun Gong Gongcu

🏠
Working from home
View GitHub Profile
@Gongcu
Gongcu / GetHashKey.kt
Created September 3, 2020 12:09
Android Get Hash Key Method
fun getHashKey(){
val info: PackageInfo
try {
info = packageManager.getPackageInfo("com.example.a2ndaccidentprevention", PackageManager.GET_SIGNATURES)
for (signature in info.signatures) {
var md: MessageDigest
md = MessageDigest.getInstance("SHA")
md.update(signature.toByteArray())
val something: String = String(Base64.encode(md.digest(), 0))
//String something = new String(Base64.encodeBytes(md.digest()));
@Gongcu
Gongcu / fcm.php
Created March 24, 2020 11:53
Push notification using FCM.
<?php
define('API_ACCESS_KEY','your_firebase_server_key');
$fcmUrl = 'https://fcm.googleapis.com/fcm/send';
$token='target_user's_token';
$notification = [
'title' =>'title',
'body' => 'body of message.',
'icon' =>'myIcon',
'sound' => 'mySound'
@Gongcu
Gongcu / ChildAdapter.java
Last active March 11, 2020 06:41
Sqlite를 이용한 중첩된 동적 리사이클러뷰. 하나의 리사이클러뷰의 items이 다시 리사이클러뷰로 구현.(운동기록에 사용되었음)
public class ChildAdapter extends RecyclerView.Adapter<ChildAdapter.ItemViewHolder>{
private AdapterListener listener;
private CalculatorEditDialog dialog;
private long parent_id;
private List<String> dateList= new ArrayList<>();
private List<Long> id= new ArrayList<>();
private List<NoteContract> noteList;
private DateContract data;
private String date;
@Gongcu
Gongcu / AlarmService.java
Created March 5, 2020 11:43
Background Service(JobIntentService) + BroadcastReceiver
package com.health.myapplication.alarm;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
@Gongcu
Gongcu / UploadPost.java
Created March 5, 2020 11:35
Firebase에서 Firestore와 Firestorage의 활용 - 게시물 업로드
private void uploadPost(){
progressON();
final String text = textInputEditText.getText().toString();
final Long time = System.currentTimeMillis();
final String filename = user.getUid()+"_"+time;
StorageReference storageRef = storage.getReference();
final StorageReference ImagesRef = storageRef.child("posts/"+filename+".jpg");
imageView.setDrawingCacheEnabled(true);
imageView.buildDrawingCache();
@Gongcu
Gongcu / RecyclerViewAdapter_post.java
Created March 5, 2020 11:13
Loading RecyclerView와 SwipeRefreshLayout의 결합
public class RecyclerViewAdapter_post extends RecyclerView.Adapter<RecyclerViewAdapter_post.ItemViewHolder> {
private Activity activity;
private RecyclerView recyclerView;
private PostScrollToPositionListener postScrollToPositionListener; //to notify item change, so parent should know
private SwipeRefreshLayout refreshLayout;
/**
* Constructor For PostActivity
*/
public RecyclerViewAdapter_post(final Activity activity, FragmentManager fragmentManager, RecyclerView recyclerView, SwipeRefreshLayout refreshLayout) {
@Gongcu
Gongcu / AndroidSignUpRegex.java
Created March 5, 2020 11:03
안드로이드에서 이메일과 비밀번호 정규식
private void signUpRegex(final String email, final String password){
//키보드 내리기
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
String pwPattern = "^(?=.*\\d)(?=.*[~`!@#$%\\^&*()-])(?=.*[a-z])(?=.*[A-Z]).{9,12}$";
Matcher matcher = Pattern.compile(pwPattern).matcher(password);
@Gongcu
Gongcu / FCM_Push.java
Last active March 2, 2020 09:08
FCM - okHttp, Json, Gson, 싱글톤 패턴
package com.example.healthtagram.fcm;
public class FCMpush {
private static final MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
private static final String uri = "https://fcm.googleapis.com/fcm/send";
private static final String serverKey = "AIzaSyD....";
private Gson gson;
private OkHttpClient httpClient;
//싱글톤 패턴을 위해 생성사를 private으로 선언
@Gongcu
Gongcu / CropBitmapToCircle
Created February 12, 2020 12:00 — forked from jewelzqiu/CropBitmapToCircle.java
Crop a bitmap to circle in Android
public static Bitmap getCircledBitmap(Bitmap bitmap) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));