Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.mansi.busezon;
- import android.Manifest;
- import android.content.Intent;
- import android.content.pm.PackageManager;
- import android.support.design.widget.FloatingActionButton;
- import android.support.v4.app.ActivityCompat;
- import android.support.v4.content.ContextCompat;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.support.v7.widget.GridLayoutManager;
- import android.support.v7.widget.RecyclerView;
- import android.view.View;
- import com.example.mansi.busezon.adapters.ImagesAdapter;
- import com.haresh.multipleimagepickerlibrary.MultiImageSelector;
- import java.util.ArrayList;
- import java.util.List;
- public class MainActivity extends AppCompatActivity {
- public void sendMess(View view)
- {
- Intent intent = new Intent(MainActivity.this, SELL_BUY.class);
- startActivity(intent);
- }
- private FloatingActionButton floatingActionButton;
- private RecyclerView recyclerViewImages;
- private GridLayoutManager gridLayoutManager;
- private ArrayList<String> mSelectedImagesList = new ArrayList<>();
- private final int MAX_IMAGE_SELECTION_LIMIT=100;
- private static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 401;
- private final int REQUEST_IMAGE=301;
- private MultiImageSelector mMultiImageSelector;
- private ImagesAdapter mImagesAdapter;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- floatingActionButton = (FloatingActionButton) findViewById(R.id.fab);
- recyclerViewImages = (RecyclerView) findViewById(R.id.recycler_view_images);
- gridLayoutManager = new GridLayoutManager(this, 4);
- recyclerViewImages.setHasFixedSize(true);
- recyclerViewImages.setLayoutManager(gridLayoutManager);
- mMultiImageSelector = MultiImageSelector.create();
- floatingActionButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if(checkAndRequestPermissions()) {
- mMultiImageSelector.showCamera(true);
- mMultiImageSelector.count(MAX_IMAGE_SELECTION_LIMIT);
- mMultiImageSelector.multi();
- mMultiImageSelector.origin(mSelectedImagesList);
- mMultiImageSelector.start(MainActivity.this, REQUEST_IMAGE);
- // mMultiImageSelector.showCamera(true);
- // mMultiImageSelector.single();
- // mMultiImageSelector.origin(mSelectedImagesList);
- // mMultiImageSelector.start(MainActivity.this, REQUEST_IMAGE);
- }
- }
- });
- }
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if(requestCode == REQUEST_IMAGE){
- try {
- mSelectedImagesList = data.getStringArrayListExtra(MultiImageSelector.EXTRA_RESULT);
- mImagesAdapter = new ImagesAdapter(this,mSelectedImagesList);
- recyclerViewImages.setAdapter(mImagesAdapter);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- private boolean checkAndRequestPermissions() {
- int externalStoragePermission = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
- List<String> listPermissionsNeeded = new ArrayList<>();
- if (externalStoragePermission != PackageManager.PERMISSION_GRANTED) {
- listPermissionsNeeded.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
- }
- if (!listPermissionsNeeded.isEmpty()) {
- ActivityCompat.requestPermissions(this, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), REQUEST_ID_MULTIPLE_PERMISSIONS);
- return false;
- }
- return true;
- }
- @Override
- public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
- if (requestCode == REQUEST_ID_MULTIPLE_PERMISSIONS) {
- floatingActionButton.performClick();
- }
- }
- }
- =================
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.constraint.ConstraintLayout 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"
- tools:context="com.example.mansi.busezon.MainActivity">
- <TextView
- 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.support.design.widget.FloatingActionButton
- android:id="@+id/fab"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="bottom|end"
- android:layout_margin="@dimen/fab_margin"
- android:tint="@android:color/white"
- app:srcCompat="@android:drawable/ic_input_add" />
- </android.support.constraint.ConstraintLayout>
- ============
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout 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"
- app:layout_behavior="@string/appbar_scrolling_view_behavior"
- tools:context="com.example.mansi.busezon.Add_product"
- tools:showIn="@layout/activity_main">
- <android.support.v7.widget.RecyclerView
- android:id="@+id/recycler_view_images"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_margin="@dimen/fab_margin"/>
- </RelativeLayout>
- ========================
- <?xml version="1.0" encoding="utf-8"?>
- <com.haresh.multipleimagepickerlibrary.views.SquareFrameLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_margin="5dp">
- <com.e.multipleimagepickerlibrary.views.SquaredImageView
- android:id="@+id/image_view"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:scaleType="centerInside"
- android:src="@drawable/default_error"/>
- </com.haresh.multipleimagepickerlibrary.views.SquareFrameLayout>
Add Comment
Please, Sign In to add comment