edit layout

This commit is contained in:
Ilia Kurtov 2016-08-23 15:16:25 +03:00
parent bed718f773
commit a9fdb2bfaf
9 changed files with 130 additions and 88 deletions

View File

@ -1,12 +1,12 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "me.nereo.multiimageselector"
minSdkVersion 12
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
@ -21,6 +21,8 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-compat:24.2.0'
compile 'com.android.support:design:24.2.0'
compile project(':multi-image-selector')
}

View File

@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle:2.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View File

@ -1,6 +1,6 @@
#Wed May 18 11:49:16 CST 2016
#Tue Aug 23 14:55:54 MSK 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

View File

@ -5,13 +5,13 @@ import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import java.io.File;
import java.util.ArrayList;
@ -22,43 +22,52 @@ import java.util.ArrayList;
* Updated by nereo on 2016/1/19.
* Updated by nereo on 2016/5/18.
*/
public class MultiImageSelectorActivity extends AppCompatActivity
implements MultiImageSelectorFragment.Callback{
public class MultiImageSelectorActivity extends AppCompatActivity implements MultiImageSelectorFragment.Callback {
// Single choice
public static final int MODE_SINGLE = 0;
// Multi choice
public static final int MODE_MULTI = 1;
/** Max image sizeint{@link #DEFAULT_IMAGE_SIZE} by default */
/**
* Max image sizeint{@link #DEFAULT_IMAGE_SIZE} by default
*/
public static final String EXTRA_SELECT_COUNT = "max_select_count";
/** Select mode{@link #MODE_MULTI} by default */
/**
* Select mode{@link #MODE_MULTI} by default
*/
public static final String EXTRA_SELECT_MODE = "select_count_mode";
/** Whether show cameratrue by default */
/**
* Whether show cameratrue by default
*/
public static final String EXTRA_SHOW_CAMERA = "show_camera";
/** Result data setArrayList<String>*/
/**
* Result data setArrayList<String>
*/
public static final String EXTRA_RESULT = "select_result";
/** Original data set */
/**
* Original data set
*/
public static final String EXTRA_DEFAULT_SELECTED_LIST = "default_list";
// Default image size
private static final int DEFAULT_IMAGE_SIZE = 9;
@NonNull
private ArrayList<String> resultList = new ArrayList<>();
private Button mSubmitButton;
private int mDefaultCount = DEFAULT_IMAGE_SIZE;
private View submitButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.MIS_NO_ACTIONBAR);
setContentView(R.layout.mis_activity_default);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(Color.BLACK);
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if(toolbar != null){
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
}
@ -68,37 +77,36 @@ public class MultiImageSelectorActivity extends AppCompatActivity
}
final Intent intent = getIntent();
mDefaultCount = intent.getIntExtra(EXTRA_SELECT_COUNT, DEFAULT_IMAGE_SIZE);
final int mDefaultCount = intent.getIntExtra(EXTRA_SELECT_COUNT, DEFAULT_IMAGE_SIZE);
final int mode = intent.getIntExtra(EXTRA_SELECT_MODE, MODE_MULTI);
final boolean isShow = intent.getBooleanExtra(EXTRA_SHOW_CAMERA, true);
if(mode == MODE_MULTI && intent.hasExtra(EXTRA_DEFAULT_SELECTED_LIST)) {
if (mode == MODE_MULTI && intent.hasExtra(EXTRA_DEFAULT_SELECTED_LIST)) {
resultList = intent.getStringArrayListExtra(EXTRA_DEFAULT_SELECTED_LIST);
}
mSubmitButton = (Button) findViewById(R.id.commit);
if(mode == MODE_MULTI){
updateDoneText(resultList);
mSubmitButton.setVisibility(View.VISIBLE);
mSubmitButton.setOnClickListener(new View.OnClickListener() {
submitButton = findViewById(R.id.multi_image_selector_submit_button);
if (mode == MODE_MULTI) {
updateSubmitButton();
submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(resultList != null && resultList.size() >0){
public void onClick(final View v) {
if (!resultList.isEmpty()) {
// Notify success
Intent data = new Intent();
data.putStringArrayListExtra(EXTRA_RESULT, resultList);
setResult(RESULT_OK, data);
}else{
} else {
setResult(RESULT_CANCELED);
}
finish();
}
});
}else{
mSubmitButton.setVisibility(View.GONE);
} else {
submitButton.setVisibility(View.GONE);
}
if(savedInstanceState == null){
Bundle bundle = new Bundle();
if (savedInstanceState == null) {
final Bundle bundle = new Bundle();
bundle.putInt(MultiImageSelectorFragment.EXTRA_SELECT_COUNT, mDefaultCount);
bundle.putInt(MultiImageSelectorFragment.EXTRA_SELECT_MODE, mode);
bundle.putBoolean(MultiImageSelectorFragment.EXTRA_SHOW_CAMERA, isShow);
@ -122,26 +130,13 @@ public class MultiImageSelectorActivity extends AppCompatActivity
return super.onOptionsItemSelected(item);
}
/**
* Update done button by select image data
* @param resultList selected image data
*/
private void updateDoneText(ArrayList<String> resultList){
int size = 0;
if(resultList == null || resultList.size()<=0){
mSubmitButton.setText(R.string.mis_action_done);
mSubmitButton.setEnabled(false);
}else{
size = resultList.size();
mSubmitButton.setEnabled(true);
}
mSubmitButton.setText(getString(R.string.mis_action_button_string,
getString(R.string.mis_action_done), size, mDefaultCount));
private void updateSubmitButton() {
submitButton.setEnabled(!resultList.isEmpty());
}
@Override
public void onSingleImageSelected(String path) {
Intent data = new Intent();
public void onSingleImageSelected(final String path) {
final Intent data = new Intent();
resultList.add(path);
data.putStringArrayListExtra(EXTRA_RESULT, resultList);
setResult(RESULT_OK, data);
@ -149,24 +144,24 @@ public class MultiImageSelectorActivity extends AppCompatActivity
}
@Override
public void onImageSelected(String path) {
if(!resultList.contains(path)) {
public void onImageSelected(final String path) {
if (!resultList.contains(path)) {
resultList.add(path);
}
updateDoneText(resultList);
updateSubmitButton();
}
@Override
public void onImageUnselected(String path) {
if(resultList.contains(path)){
public void onImageUnselected(final String path) {
if (resultList.contains(path)) {
resultList.remove(path);
}
updateDoneText(resultList);
updateSubmitButton();
}
@Override
public void onCameraShot(File imageFile) {
if(imageFile != null) {
public void onCameraShot(final File imageFile) {
if (imageFile != null) {
// notify system the image has change
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(imageFile)));
@ -177,4 +172,4 @@ public class MultiImageSelectorActivity extends AppCompatActivity
finish();
}
}
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#999" android:state_enabled="false"/>
<item android:color="@color/mis_global_main_dark_blue"/>
</selector>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/mis_global_black_12">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="@android:color/white"/>
</shape>
</item>
</ripple>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/mis_global_black_12" android:state_pressed="true"/>
</selector>

View File

@ -1,40 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="#181819"
android:layout_width="match_parent"
android:layout_height="match_parent">
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
<android.support.design.widget.AppBarLayout
android:id="@+id/main_app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/mis_actionbar_color"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:minHeight="?android:attr/actionBarSize">
android:layout_height="56dp"
android:background="@color/mis_global_main_gray">
<Button
android:id="@+id/commit"
android:background="@drawable/mis_action_btn"
android:minHeight="1dp"
android:minWidth="1dp"
android:layout_marginRight="16dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textColor="@color/mis_default_text_color"
android:textSize="14sp"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentInsetLeft="17dp"
app:contentInsetStart="17dp">
</android.support.v7.widget.Toolbar>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:textColor="@color/mis_global_main_dark_gray"
android:textSize="20sp"
android:text="Все фотографии"/>
<TextView
android:id="@+id/multi_image_selector_submit_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:background="@drawable/mis_global_dark_selector"
android:textColor="@color/mis_main_menu_button_selector"
android:textSize="14sp"
android:text="Добавить"
android:paddingRight="19dp"
android:paddingLeft="19dp"
android:textAllCaps="true"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/image_grid"
android:background="@color/mis_global_main_gray"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"/>
</LinearLayout>

View File

@ -1,4 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="mis_actionbar_color">#21282C</color>
<color name="mis_global_main_gray">#e8e8e8</color>
<color name="mis_global_main_dark_gray">#333</color>
<color name="mis_global_black_12">#1e000000</color>
<color name="mis_global_main_dark_blue">#205090</color>
</resources>