Skip to content

Commit

Permalink
add ucrop
Browse files Browse the repository at this point in the history
  • Loading branch information
wangqiong committed Feb 24, 2016
1 parent 08da129 commit 736a709
Show file tree
Hide file tree
Showing 45 changed files with 3,953 additions and 123 deletions.
42 changes: 27 additions & 15 deletions app/src/main/java/com/eq/gallery/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,20 @@

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBarActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.AppCompatButton;
import android.support.v7.widget.AppCompatCheckBox;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v7.widget.AppCompatSeekBar;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;

import com.wq.photo.MediaChoseActivity;
import com.wq.photo.PhotoGalleryFragment;
import com.wq.photo.widget.PickConfig;
import com.yalantis.ucrop.UCrop;

import java.util.ArrayList;

Expand All @@ -31,45 +24,64 @@ public class MainActivity extends AppCompatActivity {

LinearLayout ll_max_chose_layout;
ListView listview;
AppCompatCheckBox cb_is_single_mode,cb_is_need_camera,cb_is_need_crop,cb_is_need_actionbar;
AppCompatCheckBox cb_is_single_mode,cb_is_need_camera,cb_is_need_crop,cb_is_square;
EditText ed_span_count,ed_maxchose_count;
LinearLayout ll_cropinfo;
AppCompatSeekBar seekBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekBar= (AppCompatSeekBar) findViewById(R.id.seekbar);
listview= (ListView) findViewById(R.id.listview);
cb_is_single_mode=(AppCompatCheckBox)findViewById(R.id.cb_is_single_mode);
cb_is_need_camera=(AppCompatCheckBox)findViewById(R.id.cb_is_need_camera);
cb_is_need_crop=(AppCompatCheckBox)findViewById(R.id.cb_is_need_crop);
cb_is_need_actionbar=(AppCompatCheckBox)findViewById(R.id.cb_is_need_actionbar);
ed_span_count= (EditText) findViewById(R.id.ed_span_count);
cb_is_square= (AppCompatCheckBox) findViewById(R.id.cb_is_square);
ed_maxchose_count= (EditText) findViewById(R.id.ed_maxchose_count);
ll_cropinfo= (LinearLayout) findViewById(R.id.ll_cropinfo);
ll_max_chose_layout= (LinearLayout) findViewById(R.id.ll_max_chose_layout);

cb_is_single_mode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked){
cb_is_need_crop.setEnabled(true);
cb_is_need_actionbar.setEnabled(true);
ll_max_chose_layout.setVisibility(View.GONE);
}else {
cb_is_need_actionbar.setChecked(false);
cb_is_need_crop.setChecked(false);
cb_is_need_crop.setEnabled(false);
cb_is_need_actionbar.setEnabled(false);
ll_max_chose_layout.setVisibility(View.VISIBLE);
}
}
});

cb_is_need_crop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked){
ll_cropinfo.setVisibility(View.VISIBLE);
}else {
ll_cropinfo.setVisibility(View.GONE);
}
}
});

findViewById(R.id.bt_start_chose).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int chose_mode=cb_is_single_mode.isChecked()?PickConfig.MODE_SINGLE_PICK:PickConfig.MODE_MULTIP_PICK;
UCrop.Options options = new UCrop.Options();
options.setCompressionFormat(Bitmap.CompressFormat.JPEG);
options.setCompressionQuality(seekBar.getProgress());
new PickConfig.Builder(MainActivity.this)
.isneedcrop(cb_is_need_crop.isChecked())
.actionBarcolor(Color.parseColor("#E91E63"))
.statusBarcolor(Color.parseColor("#D81B60"))
.isneedcamera(cb_is_need_camera.isChecked())
.isSqureCrop(cb_is_square.isChecked())
.setUropOptions(options)
.maxPickSize(Integer.parseInt(ed_maxchose_count.getText().toString()))
.spanCount(Integer.parseInt(ed_span_count.getText().toString()))
.pickMode(chose_mode).build();
Expand Down
61 changes: 46 additions & 15 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@


<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/cb_is_single_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:id="@+id/cb_is_single_mode"
android:minHeight="38dp"
android:text="是否单选" />

<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/cb_is_need_camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:minHeight="38dp"
android:id="@+id/cb_is_need_camera"
android:text="是否需要相机" />

<LinearLayout
Expand All @@ -41,51 +41,83 @@
android:text="一行显示几张照片" />

<EditText
android:inputType="number"
android:id="@+id/ed_span_count"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:inputType="number"
android:text="2" />


</LinearLayout>

<LinearLayout
android:id="@+id/ll_max_chose_layout"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="42dp"
android:orientation="horizontal">
android:orientation="horizontal"
android:visibility="gone">

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="做多选择几张照片" />

<EditText
android:inputType="number"
android:id="@+id/ed_maxchose_count"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:inputType="number"
android:text="1" />
</LinearLayout>

<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/cb_is_need_crop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:minHeight="38dp"
android:id="@+id/cb_is_need_crop"
android:text="是否需要剪裁" />

<android.support.v7.widget.AppCompatCheckBox
android:layout_width="wrap_content"

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:minHeight="38dp"
android:id="@+id/cb_is_need_actionbar"
android:text="是否需要ActionBar" />
android:orientation="vertical">



<LinearLayout
android:id="@+id/ll_cropinfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/cb_is_square"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:minHeight="38dp"
android:text="是否正方形剪裁" />

</LinearLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="图片压缩比"
android:textSize="11sp" />

<android.support.v7.widget.AppCompatSeekBar
android:id="@+id/seekbar"
android:progress="80"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="4dp" />
</LinearLayout>

<Button
android:id="@+id/bt_start_chose"
Expand All @@ -99,7 +131,6 @@
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/ll">
</ListView>
android:layout_below="@+id/ll"></ListView>

</RelativeLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#03A9F4</item>
<item name="colorPrimaryDark">#0288D1</item>
Expand Down
18 changes: 15 additions & 3 deletions photogallery/photogallery.iml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
<afterSyncTasks>
<task>generateDebugAndroidTestSources</task>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
Expand Down Expand Up @@ -51,13 +48,27 @@
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
Expand All @@ -72,6 +83,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/mockable-android-23.jar" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
Expand Down
4 changes: 4 additions & 0 deletions photogallery/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
android:allowBackup="true"
android:label="@string/app_name" >
<activity
android:theme="@style/AppTheme"
android:name=".MediaChoseActivity"
android:label="@string/title_activity_media_chose" >
</activity>
<activity
android:name=".CropImageActivity"
android:label="@string/title_activity_crop_image" >
</activity>
<activity android:name="com.yalantis.ucrop.UCropActivity"
android:theme="@style/AppTheme"
></activity>
</application>

</manifest>
Loading

0 comments on commit 736a709

Please sign in to comment.