Skip to content

Commit

Permalink
app base + custom 기능 구현
Browse files Browse the repository at this point in the history
- 전반적으로 다듬을 필요 있음
- 신체 부위별 세부 편집 기능 추가 필요
  • Loading branch information
Yuls2 committed Apr 27, 2022
1 parent 3796951 commit 9facda6
Show file tree
Hide file tree
Showing 14 changed files with 337 additions and 21 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ dependencies {
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.github.bumptech.glide:glide:4.13.1'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'jp.wasabeef:glide-transformations:4.3.0'
implementation project(path: ':library')
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.okhttp:okhttp:2.7.5'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
package="com.example.togaether">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/Theme.TOGAETHER">
<activity
android:name=".CustomActivity"
Expand Down
42 changes: 38 additions & 4 deletions app/src/main/java/com/example/togaether/CustomActivity.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,62 @@
package com.example.togaether;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.os.Bundle;
import android.util.Log;
import com.google.android.material.tabs.TabLayout;

import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

public class CustomActivity extends AppCompatActivity {
Fragment[] fragArr = new Fragment[9];

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom);

ViewGroup layBack = findViewById(R.id.lay_preview);
PuppyView puppyView = new PuppyView(layBack, this);

fragArr[0] = new FragCus(puppyView,CustomType.FACE1);
fragArr[1] = new FragCus(puppyView,CustomType.FACE3);
fragArr[2] = new FragCus(puppyView,CustomType.EYE_L); // fragment type 2
fragArr[3] = new FragCus(puppyView,CustomType.NOSE);
fragArr[4] = new FragCus(puppyView,CustomType.MOUTH);
fragArr[5] = new FragCus(puppyView,CustomType.FACE2);
fragArr[6] = new FragCus(puppyView,CustomType.EAR_L); // fragment type 2
fragArr[7] = new FragCus(puppyView,CustomType.EYEBROW_L); // fragment type 2
fragArr[8] = new FragCus(puppyView,CustomType.BODY);

getSupportFragmentManager().beginTransaction().add(R.id.lay_cusframe, fragArr[0]).commit();
TabLayout layTabs = (TabLayout) findViewById(R.id.lay_tabs);
layTabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
Fragment sel = fragArr[tab.getPosition()];
getSupportFragmentManager().beginTransaction().replace(R.id.lay_cusframe, sel).commit();
}

@Override
public void onTabUnselected(TabLayout.Tab tab) {

}

@Override
public void onTabReselected(TabLayout.Tab tab) {

}
});


ImageView imgBack = (ImageView) findViewById(R.id.img_back);
Glide.with(this).load(R.drawable.img_back_cus2).fitCenter().into(imgBack);

PuppyView puppyView = new PuppyView(layBack, this);
puppyView.setColor();

imgBack.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/example/togaether/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
PuppyView puppyView = new PuppyView(findViewById(R.id.lay_main), this);
puppyView.setPosition(100,0);
puppyView.setColor();
}
}
204 changes: 191 additions & 13 deletions app/src/main/java/com/example/togaether/PuppyView.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.example.togaether;

import static com.bumptech.glide.request.RequestOptions.bitmapTransform;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
Expand All @@ -11,41 +16,124 @@
import android.view.ViewTreeObserver;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.bumptech.glide.signature.ObjectKey;


import java.util.HashMap;

import jp.wasabeef.glide.transformations.MaskTransformation;

public class PuppyView {
LayoutInflater layoutInflater;
AppCompatActivity act;
View puppyView, puppy;
ImageView imgFace, imgBody, imgNose, imgMouth, imgEyeLeft, imgEyeRight, imgEarLeft, imgEarRight;
//ImageView imgFace, imgBody, imgNose, imgMouth, imgEyeLeft, imgEyeRight, imgEarLeft, imgEarRight;
HashMap<CustomType, ImageView> imgMap = new HashMap<>();
HashMap<CustomType, PartXY> xyMap = new HashMap<>();
HashMap<CustomType, Integer> dyMap = new HashMap<>();
HashMap<CustomType, Integer> distMap = new HashMap<>();
HashMap<CustomType, Integer> sizeMap = new HashMap<>();
HashMap<CustomType, Integer> colorMap = new HashMap<>();
HashMap<CustomType, String> sourceMap = new HashMap<>();
int w, h;
int oriS;
ViewGroup lay;

PuppyView(ViewGroup lay, AppCompatActivity act) {
this.lay = lay;
this.act = act;
layoutInflater = (LayoutInflater) act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
puppyView = (View) layoutInflater.inflate(R.layout.puppy_view, lay, true);
puppy = puppyView.findViewById(R.id.lay_puppy);

/*
imgFace = (ImageView) puppyView.findViewById(R.id.img_face1);
imgBody = (ImageView) puppyView.findViewById(R.id.img_body);
imgMouth = (ImageView) puppyView.findViewById(R.id.img_mouth);
imgNose = (ImageView) puppyView.findViewById(R.id.img_nose);
imgEarLeft = (ImageView) puppyView.findViewById(R.id.img_ear_left);
imgEarRight = (ImageView) puppyView.findViewById(R.id.img_ear_right);
imgEyeLeft = (ImageView) puppyView.findViewById(R.id.img_eye_left);
imgEyeRight = (ImageView) puppyView.findViewById(R.id.img_eye_right);
*/
imgMap.put(CustomType.FACE1,(ImageView) puppyView.findViewById(R.id.img_face1));
imgMap.put(CustomType.FACE2,(ImageView) puppyView.findViewById(R.id.img_face2));
imgMap.put(CustomType.FACE3,(ImageView) puppyView.findViewById(R.id.img_face3));
imgMap.put(CustomType.BODY,(ImageView) puppyView.findViewById(R.id.img_body));
imgMap.put(CustomType.MOUTH,(ImageView) puppyView.findViewById(R.id.img_mouth));
imgMap.put(CustomType.NOSE,(ImageView) puppyView.findViewById(R.id.img_nose));
imgMap.put(CustomType.EAR_L,(ImageView) puppyView.findViewById(R.id.img_ear_left));
imgMap.put(CustomType.EAR_R,(ImageView) puppyView.findViewById(R.id.img_ear_right));
imgMap.put(CustomType.EYE_L,(ImageView) puppyView.findViewById(R.id.img_eye_left));
imgMap.put(CustomType.EYE_R,(ImageView) puppyView.findViewById(R.id.img_eye_right));
imgMap.put(CustomType.EYEBROW_L,(ImageView) puppyView.findViewById(R.id.img_eyebrow_left));
imgMap.put(CustomType.EYEBROW_R,(ImageView) puppyView.findViewById(R.id.img_eyebrow_right));

sourceMap.put(CustomType.FACE1,"https://togaether.cafe24.com/images/custom/img_cus_f1_1.png");
sourceMap.put(CustomType.FACE2,"https://togaether.cafe24.com/images/custom/img_cus_none.png");
sourceMap.put(CustomType.FACE3,"https://togaether.cafe24.com/images/custom/img_cus_none.png");
sourceMap.put(CustomType.BODY,"https://togaether.cafe24.com/images/custom/img_cus_body_1.png");
sourceMap.put(CustomType.MOUTH,"https://togaether.cafe24.com/images/custom/img_cus_mouth_1.png");
sourceMap.put(CustomType.NOSE,"https://togaether.cafe24.com/images/custom/img_cus_nose_1.png");
sourceMap.put(CustomType.EAR_L,"https://togaether.cafe24.com/images/custom/img_cus_ear_1.png");
sourceMap.put(CustomType.EAR_R,"https://togaether.cafe24.com/images/custom/img_cus_ear_1.png");
sourceMap.put(CustomType.EYE_L,"https://togaether.cafe24.com/images/custom/img_cus_eye_1.png");
sourceMap.put(CustomType.EYE_R,"https://togaether.cafe24.com/images/custom/img_cus_eye_1.png");
sourceMap.put(CustomType.EYEBROW_L,"https://togaether.cafe24.com/images/custom/img_cus_none.png");
sourceMap.put(CustomType.EYEBROW_R,"https://togaether.cafe24.com/images/custom/img_cus_none.png");

Glide.with(lay).load(sourceMap.get(CustomType.FACE3))
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.apply(bitmapTransform(new MultiTransformation<Bitmap>(new CenterCrop(), new MaskTransformation2(imgMap.get(CustomType.FACE1).getDrawable())))).into(imgMap.get(CustomType.FACE3));

for(CustomType t: CustomType.values()) {
ImageView targetView = imgMap.get(t);
dyMap.put(t,0);
distMap.put(t,0);
sizeMap.put(t,100);
colorMap.put(t,Color.parseColor("#ffffff"));
xyMap.put(t,new PartXY(targetView.getX(),targetView.getY()));
}
colorMap.put(CustomType.FACE2,Color.parseColor("#e6e6e6"));
colorMap.put(CustomType.FACE3,Color.parseColor("#6e6e6e"));
colorMap.put(CustomType.EYEBROW_L,Color.parseColor("#6e6e6e"));
colorMap.put(CustomType.EYEBROW_R,Color.parseColor("#6e6e6e"));
colorMap.put(CustomType.EAR_L,Color.parseColor("#452d00"));
colorMap.put(CustomType.EAR_R,Color.parseColor("#452d00"));

//색상 초기화
for(CustomType t: CustomType.values()) {
setColor(t, colorMap.get(t));
}

puppy.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
//Log.e("Width",""+puppy.getWidth());
w = puppy.getWidth();
h = puppy.getHeight();
oriS = imgMap.get(CustomType.FACE1).getWidth();
//oriS = puppy.getWidth();
puppy.setTranslationX(puppy.getX() - w/2);
puppy.setTranslationY(puppy.getY() - h/2);
puppy.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});

imgFace = (ImageView) puppyView.findViewById(R.id.img_face1);
imgBody = (ImageView) puppyView.findViewById(R.id.img_body);
imgMouth = (ImageView) puppyView.findViewById(R.id.img_mouth);
imgNose = (ImageView) puppyView.findViewById(R.id.img_nose);
imgEarLeft = (ImageView) puppyView.findViewById(R.id.img_ear_left);
imgEarRight = (ImageView) puppyView.findViewById(R.id.img_ear_right);
imgEyeLeft = (ImageView) puppyView.findViewById(R.id.img_eye_left);
imgEyeRight = (ImageView) puppyView.findViewById(R.id.img_eye_right);
}
public void setPosition(int x, int y) {
puppy.setTranslationX((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, x, act.getResources().getDisplayMetrics()) - w/2); //puppy.findViewById(R.id.lay_puppy).
Expand All @@ -55,8 +143,98 @@ public void setPositionPX(int x, int y) {
puppy.setTranslationX(x - w/2);
puppy.setTranslationY(y - h/2);
}
public void setColor() {
imgFace.setColorFilter(Color.parseColor("#e28743"), PorterDuff.Mode.MULTIPLY);
imgBody.setColorFilter(Color.parseColor("#e28743"), PorterDuff.Mode.MULTIPLY);
public void setColor(CustomType type, int color) {
imgMap.get(type).setColorFilter(color, PorterDuff.Mode.MULTIPLY);
colorMap.put(type,color);
}
public void setImgSource(CustomType type, String url) {
sourceMap.put(type, url);
if(type == CustomType.FACE1) {
Glide.with(lay).load(url)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
Glide.with(lay).load(sourceMap.get(CustomType.FACE3))
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.apply(bitmapTransform(new MultiTransformation<Bitmap>(new CenterCrop(), new MaskTransformation2(resource)))).into(imgMap.get(CustomType.FACE3));
return false;
}
})
.into(imgMap.get(type));
}
else if(type == CustomType.FACE3) {
Glide.with(lay).load(url)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.apply(bitmapTransform(new MultiTransformation<Bitmap>(new CenterCrop(), new MaskTransformation2(imgMap.get(CustomType.FACE1).getDrawable())))).into(imgMap.get(CustomType.FACE3));
}
else {
Glide.with(lay).load(url).into(imgMap.get(type));
}
}
public void setSize(CustomType type, int size) {
int s = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, size, act.getResources().getDisplayMetrics());
ImageView targetView = imgMap.get(type);
ViewGroup.LayoutParams newSize = targetView.getLayoutParams();
newSize.width = s;
newSize.height = s;
targetView.setLayoutParams(newSize);
sizeMap.put(type, size);
setPartPosition(type);
if(type == CustomType.FACE1) {
setSize(CustomType.FACE3, size);
sizeMap.put(CustomType.FACE3, size);
setPartPosition(CustomType.FACE3);
}
}
public void setDy(CustomType type, int dy) {
dyMap.put(type, dy);
setPartPosition(type);
if(type == CustomType.FACE1) {
CustomType[] ts = {CustomType.FACE2, CustomType.FACE3, CustomType.EAR_L, CustomType.EAR_R, CustomType.NOSE, CustomType.MOUTH, CustomType.EYE_L, CustomType.EYE_R, CustomType.EYEBROW_L, CustomType.EYEBROW_R};
for(CustomType t: ts) {
dyMap.put(t, dy);
setPartPosition(t);
}
}
}
public void setPartPosition(CustomType type) {
int size = sizeMap.get(type);
int s = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, size, act.getResources().getDisplayMetrics());
float dy = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dyMap.get(type), act.getResources().getDisplayMetrics());
ImageView targetView = imgMap.get(type);
targetView.setTranslationX(xyMap.get(type).getX() - (float)(s - oriS)/2);
targetView.setTranslationY(xyMap.get(type).getY() + dy - (float)(s - oriS)/2);
}
}

class PartXY{
private float x, y;

public PartXY(float x, float y){
this.x = x;
this.y = y;
}

public float getX() {
return x;
}

public float getY() {
return y;
}

public void setX(float x) {
this.x = x;
}

public void setY(float y) {
this.y = y;
}
}
Binary file modified app/src/main/res/drawable/img_cus_ear_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9facda6

Please sign in to comment.