Skip to content

Commit

Permalink
完成Demo
Browse files Browse the repository at this point in the history
  • Loading branch information
ai2101039 committed Jan 22, 2019
1 parent db503d5 commit b7c5dc1
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 10 deletions.
11 changes: 10 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@ android {
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':library')

// https://muyangmin.github.io/glide-docs-cn/
implementation ("com.github.bumptech.glide:glide:4.8.0") {
exclude group: "com.android.support"
}

implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.ylcircleimageview">
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
Expand Down
134 changes: 132 additions & 2 deletions app/src/main/java/com/android/ylcircleimageview/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,142 @@

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
import com.android.library.YLCircleImageView;
import com.bumptech.glide.Glide;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener {

@BindView(R.id.tvOriginal)
TextView tvOriginal;
@BindView(R.id.ivOriginal)
ImageView ivOriginal;
@BindView(R.id.circle6)
YLCircleImageView circle6;
@BindView(R.id.sbTopLeft)
SeekBar sbLeftTop;
@BindView(R.id.sbBottomLeft)
SeekBar sbLeftBottom;
@BindView(R.id.sbTopRight)
SeekBar sbRightTop;
@BindView(R.id.sbBottomRight)
SeekBar sbRightBottom;
@BindView(R.id.spinnerType)
Spinner spinnerType;
@BindView(R.id.spinnerMode)
Spinner spinnerMode;
@BindView(R.id.sbBorderWidth)
SeekBar sbBorderWidth;
@BindView(R.id.sbBorderSpace)
SeekBar sbBorderSpace;

private String[] urls;
private int[] imgMode;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);

urls = new String[]{"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1547631452111&di=7cfb58904518ac97e3ec4a1c746125ae&imgtype=0&src=http%3A%2F%2Fimg.11665.com%2Fimg_p4%2Fi3%2F3297404733%2FTB2wPerc8HH8KJjy0FbXXcqlpXa_%2521%25213297404733.jpg"
, "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1547623076229&di=83847f4a3c83df891eafe2236181f5b1&imgtype=0&src=http%3A%2F%2Fimg3.duitang.com%2Fuploads%2Fitem%2F201509%2F28%2F20150928190319_QNizx.jpeg"
, "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1547628416050&di=28f29927c60bcdd1b1940e3d209baacd&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201512%2F28%2F20151228012100_STzAf.jpeg"
, "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1547630900188&di=66a0f961060f7f42f30f667c587fdb13&imgtype=0&src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fq_70%2Cc_zoom%2Cw_640%2Fimages%2F20180611%2F69c6014e4f844c6391c75b594c9804d0.gif"
, "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2564207084,3623649273&fm=26&gp=0.jpg"};

imgMode = new int[]{YLCircleImageView.TOP, YLCircleImageView.CENTER, YLCircleImageView.BOTTOM, YLCircleImageView.FITXY};

initImg(0);

sbLeftTop.setOnSeekBarChangeListener(this);
sbLeftBottom.setOnSeekBarChangeListener(this);
sbRightTop.setOnSeekBarChangeListener(this);
sbRightBottom.setOnSeekBarChangeListener(this);
sbBorderWidth.setOnSeekBarChangeListener(this);
sbBorderSpace.setOnSeekBarChangeListener(this);

spinnerMode.setOnItemSelectedListener(this);
spinnerType.setOnItemSelectedListener(this);
}

private void initImg(int i) {
if (i == 3) {
Glide.with(this).asGif().load(urls[i]).into(circle6);
Glide.with(this).asGif().load(urls[i]).into(ivOriginal);
return;
}
Glide.with(this).load(urls[i]).into(ivOriginal);
Glide.with(this).load(urls[i]).into(circle6);
}

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress = dpToPx(progress);
switch (seekBar.getId()) {
case R.id.sbTopLeft:
circle6.setTopLeftRadius(progress);
break;
case R.id.sbBottomLeft:
circle6.setBottomLeftRadius(progress);
break;
case R.id.sbTopRight:
circle6.setTopRightRadius(progress);
break;
case R.id.sbBottomRight:
circle6.setBottomRightRadius(progress);
break;
case R.id.sbBorderWidth:
circle6.setBorderWidth(progress);
break;
case R.id.sbBorderSpace:
circle6.setBorderSpace(progress);
break;
default:
}
circle6.invalidate();
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}

public int dpToPx(float dp) {
final float scale = getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (parent.getId()) {
case R.id.spinnerType:
initImg(position);
break;
case R.id.spinnerMode:
circle6.setStyleType(imgMode[position]);
circle6.invalidate();
break;
default:
}
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
}
}
111 changes: 104 additions & 7 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#999"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".MainActivity">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Spinner
android:id="@+id/spinnerType"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:dropDownVerticalOffset="50dp"
android:entries="@array/imgType"
android:popupBackground="@color/colorAccent" />

<Spinner
android:id="@+id/spinnerMode"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:dropDownVerticalOffset="50dp"
android:entries="@array/imgMode"
android:popupBackground="@color/colorAccent" />
</LinearLayout>


<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_marginTop="20dp">

<SeekBar
android:id="@+id/sbTopLeft"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:max="50"
android:progress="50" />

<SeekBar
android:id="@+id/sbBorderWidth"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:max="50"
android:progress="0" />

<SeekBar
android:id="@+id/sbBottomLeft"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:max="50"
android:progress="50" />

<com.android.library.YLCircleImageView
android:id="@+id/circle6"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:layout_toRightOf="@id/sbTopLeft"
app:radius="50dp"/>

<SeekBar
android:id="@+id/sbTopRight"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/circle6"
android:max="50"
android:progress="50" />

<SeekBar
android:id="@+id/sbBorderSpace"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/circle6"
android:max="50"
android:progress="0" />

<SeekBar
android:id="@+id/sbBottomRight"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/circle6"
android:max="50"
android:progress="50" />
</RelativeLayout>

<TextView
android:id="@+id/tvOriginal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:layout_marginTop="10dp"
android:text="原图" />

<ImageView
android:id="@+id/ivOriginal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside" />


</android.support.constraint.ConstraintLayout>
</LinearLayout>
17 changes: 17 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="imgType">
<item>普通</item>
<item>宽度大高度小</item>
<item>宽度小高度大</item>
<item>Gif</item>
<item>小图</item>
</string-array>

<string-array name="imgMode">
<item>TOP</item>
<item>CENTER</item>
<item>BOTTOM</item>
<item>FITXY</item>
</string-array>
</resources>

0 comments on commit b7c5dc1

Please sign in to comment.