Guest User

Untitled

a guest
Mar 24th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.00 KB | None | 0 0
  1. package com.example.mansi.busezon;
  2.  
  3. import android.Manifest;
  4. import android.content.Intent;
  5. import android.content.pm.PackageManager;
  6. import android.support.design.widget.FloatingActionButton;
  7. import android.support.v4.app.ActivityCompat;
  8. import android.support.v4.content.ContextCompat;
  9. import android.support.v7.app.AppCompatActivity;
  10. import android.os.Bundle;
  11. import android.support.v7.widget.GridLayoutManager;
  12. import android.support.v7.widget.RecyclerView;
  13. import android.view.View;
  14.  
  15. import com.example.mansi.busezon.adapters.ImagesAdapter;
  16. import com.haresh.multipleimagepickerlibrary.MultiImageSelector;
  17.  
  18. import java.util.ArrayList;
  19. import java.util.List;
  20.  
  21. public class MainActivity extends AppCompatActivity {
  22.  
  23. public void sendMess(View view)
  24. {
  25. Intent intent = new Intent(MainActivity.this, SELL_BUY.class);
  26. startActivity(intent);
  27. }
  28.  
  29. private FloatingActionButton floatingActionButton;
  30. private RecyclerView recyclerViewImages;
  31. private GridLayoutManager gridLayoutManager;
  32.  
  33. private ArrayList<String> mSelectedImagesList = new ArrayList<>();
  34. private final int MAX_IMAGE_SELECTION_LIMIT=100;
  35. private static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 401;
  36. private final int REQUEST_IMAGE=301;
  37.  
  38. private MultiImageSelector mMultiImageSelector;
  39. private ImagesAdapter mImagesAdapter;
  40.  
  41. @Override
  42. protected void onCreate(Bundle savedInstanceState) {
  43. super.onCreate(savedInstanceState);
  44. setContentView(R.layout.activity_main);
  45. floatingActionButton = (FloatingActionButton) findViewById(R.id.fab);
  46. recyclerViewImages = (RecyclerView) findViewById(R.id.recycler_view_images);
  47. gridLayoutManager = new GridLayoutManager(this, 4);
  48. recyclerViewImages.setHasFixedSize(true);
  49. recyclerViewImages.setLayoutManager(gridLayoutManager);
  50.  
  51.  
  52. mMultiImageSelector = MultiImageSelector.create();
  53.  
  54. floatingActionButton.setOnClickListener(new View.OnClickListener() {
  55. @Override
  56. public void onClick(View v) {
  57.  
  58. if(checkAndRequestPermissions()) {
  59. mMultiImageSelector.showCamera(true);
  60. mMultiImageSelector.count(MAX_IMAGE_SELECTION_LIMIT);
  61. mMultiImageSelector.multi();
  62. mMultiImageSelector.origin(mSelectedImagesList);
  63. mMultiImageSelector.start(MainActivity.this, REQUEST_IMAGE);
  64.  
  65. // mMultiImageSelector.showCamera(true);
  66. // mMultiImageSelector.single();
  67. // mMultiImageSelector.origin(mSelectedImagesList);
  68. // mMultiImageSelector.start(MainActivity.this, REQUEST_IMAGE);
  69. }
  70. }
  71. });
  72.  
  73. }
  74.  
  75.  
  76. @Override
  77. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  78. super.onActivityResult(requestCode, resultCode, data);
  79. if(requestCode == REQUEST_IMAGE){
  80. try {
  81. mSelectedImagesList = data.getStringArrayListExtra(MultiImageSelector.EXTRA_RESULT);
  82. mImagesAdapter = new ImagesAdapter(this,mSelectedImagesList);
  83. recyclerViewImages.setAdapter(mImagesAdapter);
  84. } catch (Exception e) {
  85. e.printStackTrace();
  86. }
  87. }
  88. }
  89.  
  90. private boolean checkAndRequestPermissions() {
  91. int externalStoragePermission = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
  92.  
  93. List<String> listPermissionsNeeded = new ArrayList<>();
  94. if (externalStoragePermission != PackageManager.PERMISSION_GRANTED) {
  95. listPermissionsNeeded.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
  96. }
  97.  
  98. if (!listPermissionsNeeded.isEmpty()) {
  99. ActivityCompat.requestPermissions(this, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), REQUEST_ID_MULTIPLE_PERMISSIONS);
  100. return false;
  101. }
  102. return true;
  103. }
  104.  
  105. @Override
  106. public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
  107. if (requestCode == REQUEST_ID_MULTIPLE_PERMISSIONS) {
  108. floatingActionButton.performClick();
  109. }
  110. }
  111.  
  112.  
  113. }
  114.  
  115. =================
  116.  
  117. <?xml version="1.0" encoding="utf-8"?>
  118. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  119. xmlns:app="http://schemas.android.com/apk/res-auto"
  120. xmlns:tools="http://schemas.android.com/tools"
  121. android:layout_width="match_parent"
  122. android:layout_height="match_parent"
  123. tools:context="com.example.mansi.busezon.MainActivity">
  124.  
  125. <TextView
  126. android:layout_width="wrap_content"
  127. android:layout_height="wrap_content"
  128. android:text="Hello World!"
  129. app:layout_constraintBottom_toBottomOf="parent"
  130. app:layout_constraintLeft_toLeftOf="parent"
  131. app:layout_constraintRight_toRightOf="parent"
  132. app:layout_constraintTop_toTopOf="parent" />
  133. <android.support.design.widget.FloatingActionButton
  134. android:id="@+id/fab"
  135. android:layout_width="wrap_content"
  136. android:layout_height="wrap_content"
  137. android:layout_gravity="bottom|end"
  138. android:layout_margin="@dimen/fab_margin"
  139. android:tint="@android:color/white"
  140. app:srcCompat="@android:drawable/ic_input_add" />
  141. </android.support.constraint.ConstraintLayout>
  142.  
  143. ============
  144.  
  145. <?xml version="1.0" encoding="utf-8"?>
  146. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  147. xmlns:app="http://schemas.android.com/apk/res-auto"
  148. xmlns:tools="http://schemas.android.com/tools"
  149. android:layout_width="match_parent"
  150. android:layout_height="match_parent"
  151. app:layout_behavior="@string/appbar_scrolling_view_behavior"
  152. tools:context="com.example.mansi.busezon.Add_product"
  153. tools:showIn="@layout/activity_main">
  154. <android.support.v7.widget.RecyclerView
  155. android:id="@+id/recycler_view_images"
  156. android:layout_width="match_parent"
  157. android:layout_height="match_parent"
  158. android:layout_margin="@dimen/fab_margin"/>
  159.  
  160. </RelativeLayout>
  161.  
  162. ========================
  163.  
  164. <?xml version="1.0" encoding="utf-8"?>
  165. <com.haresh.multipleimagepickerlibrary.views.SquareFrameLayout
  166. xmlns:android="http://schemas.android.com/apk/res/android"
  167. android:layout_width="match_parent"
  168. android:layout_height="match_parent"
  169. android:layout_margin="5dp">
  170.  
  171. <com.e.multipleimagepickerlibrary.views.SquaredImageView
  172. android:id="@+id/image_view"
  173. android:layout_width="match_parent"
  174. android:layout_height="match_parent"
  175. android:scaleType="centerInside"
  176. android:src="@drawable/default_error"/>
  177.  
  178.  
  179. </com.haresh.multipleimagepickerlibrary.views.SquareFrameLayout>
Add Comment
Please, Sign In to add comment