Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.21 KB | None | 0 0
  1. public void multiImageCaptureFunctionality(String title,final String question_id,String require)
  2. {
  3. LinearLayout ll_text = new LinearLayout(this);
  4. LayoutParams ll_text_params = new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
  5. android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
  6. ll_text_params.setMargins(Math.round(49 * multiplier), 0, Math.round(49 * multiplier), 0);
  7. ll_text.setGravity(Gravity.CENTER_VERTICAL);
  8. ll_text.setOrientation(LinearLayout.VERTICAL);
  9. ll_text.setId(Integer.parseInt(question_id));
  10. methodForGeneratingMultiImage(ll_text, ll_text_params, require,question_id);
  11. }
  12. int count_multi=0;
  13. public void methodForGeneratingMultiImage(final LinearLayout ll_multiImage,final LayoutParams ll_multiImageParams,final String requires,final String question_id)
  14. {
  15.  
  16. final TextView tv_question_text = new TextView(this);
  17. LayoutParams text_question_params = new LayoutParams(
  18. Math.round(500*multiplier),
  19. android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
  20. text_question_params.setMargins(0, Math.round(38 * multiplier),0, 0);
  21. tv_question_text.setGravity(Gravity.CENTER_VERTICAL);
  22.  
  23. tv_question_text.setId(Integer.parseInt(question_id));
  24. tv_question_text.setTextSize(16.5f*multiplier);
  25.  
  26. if (Constants.ad_status.matches("1")||Constants.ad_status.matches("3")) {
  27. if (requires.matches("1")) {
  28. tv_question_text.setText(question_no+". "+getTitleString(question_id, tv_question_text)+" *");
  29. } else {
  30. tv_question_text.setText(question_no+". "+getTitleString(question_id, tv_question_text));
  31. }
  32. } else {
  33. if (requires.matches("1")) {
  34. tv_question_text.setText(""+getTitleString(question_id, tv_question_text)+" *");
  35. } else {
  36. tv_question_text.setText(""+getTitleString(question_id, tv_question_text));
  37. }
  38. }
  39.  
  40. tv_question_text.setTextColor(Color.WHITE);
  41. tv_question_text.setTypeface(gotham_rounded_bold);
  42. tv_question_text.setLineSpacing(1.2f, 1.2f);
  43.  
  44. final ImageButton bt_image = new ImageButton(this);
  45. LayoutParams bt_image_params = new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
  46. android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
  47. bt_image_params.setMargins(0, Math.round(23 * multiplier),0, 0);
  48. bt_image.setId(1+count_multi);
  49. bt_image.setPadding(5, 0, 5, 0);
  50. bt_image.setPaddingRelative(15, 0, 15, 0);
  51. bt_image.setBackgroundDrawable(getResources().getDrawable(
  52. R.drawable.image_cap_selector));
  53.  
  54. final LinearLayout ll_image=new LinearLayout(this);
  55. LayoutParams ll_image_params=new LayoutParams(
  56. Math.round(500 * multiplier), Math.round(170 * multiplier));
  57. ll_image_params.setMargins(0, Math.round(23 * multiplier), 0, 0);
  58. ll_image.setOrientation(LinearLayout.HORIZONTAL);
  59. ll_image.setGravity(Gravity.CENTER_VERTICAL);
  60. ll_image.setVisibility(View.GONE);
  61. ll_image.setId(161+count_multi);
  62.  
  63. final ImageView iv_photo=new ImageView(this);
  64. LayoutParams iv_photo_params=new LayoutParams(Math.round(200 * multiplier), Math.round(169 * multiplier));
  65. iv_photo.setBackgroundDrawable(getResources().getDrawable(R.drawable.edittext_bg_with_shadow));
  66. iv_photo_params.setMargins(Math.round(10.0f), 0, 0, 0);
  67. iv_photo.setScaleType(ScaleType.FIT_XY);
  68. iv_photo.setId(34+count_multi);
  69.  
  70. final ImageButton ib_delete=new ImageButton(this);
  71. LayoutParams ib_delete_params=new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
  72. android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
  73. ib_delete_params.setMargins(Math.round(10), 0, 0, 0);
  74. ib_delete.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_delete_selector));
  75. ib_delete.setBaselineAlignBottom(true);
  76. ib_delete.setId(249+count_multi);
  77.  
  78. ll_image.addView(iv_photo, iv_photo_params);
  79. ll_image.addView(ib_delete, ib_delete_params);
  80.  
  81.  
  82. File imagesFolder = new File(image_path);
  83. imagesFolder.mkdirs();
  84. final String image_name=getRandomStringForImage()+".png";
  85. final File image = new File(imagesFolder, ""+image_name);
  86.  
  87. final String strFile=image.toString();
  88. final Uri uriSavedImage = Uri.fromFile(image);
  89. bt_image.setOnClickListener(new OnClickListener() {
  90.  
  91. @Override
  92. public void onClick(View v) {
  93. bt_image.requestFocusFromTouch();
  94.  
  95. Intent intent=new Intent("android.media.action.IMAGE_CAPTURE");
  96. intent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
  97. startActivity(intent);
  98. ll_image.setVisibility(View.VISIBLE);
  99. bt_image.setVisibility(View.GONE);
  100. Calendar c = Calendar.getInstance();
  101. System.out.println("Current time => " + c.getTime());
  102. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
  103. formattedDate_question1 = df.format(c.getTime());
  104.  
  105. SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  106. formattedDate_user1 = df2.format(c.getTime());
  107. Constants.endDateAndTime = df2.format(c.getTime());
  108. new Handler().postDelayed(new Runnable() {
  109.  
  110. @Override
  111. public void run() {
  112. runOnUiThread( new Runnable() {
  113. public void run() {
  114. iv_photo.setBackgroundColor(Color.parseColor(Constants.body_bg_color));
  115. iv_photo.setImageURI(uriSavedImage);
  116. iv_photo.setRotation(90);
  117. Log.d("image", "image="+image+" name="+image_name+" str="+strFile);
  118. if (count_multi!=4&&count_multi<=4) {
  119. methodForGeneratingMultiImage(ll_multiImage, ll_multiImageParams, requires,question_id);
  120. Log.d("eee", ""+count_multi);
  121.  
  122. } else {
  123.  
  124. }
  125. }
  126. });
  127.  
  128. }
  129. }, 10000);
  130. count_multi++;
  131.  
  132.  
  133. ViewTreeObserver viwob=ll_main.getViewTreeObserver();
  134. viwob.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
  135.  
  136. @Override
  137. public void onGlobalLayout() {
  138. ll_main.getViewTreeObserver().removeGlobalOnLayoutListener(this);
  139. int height=ll_main.getMeasuredHeight();
  140. Log.d("rrr", "vidfbsds="+height+" sch="+scrollvalue2);
  141. if (height<scrollvalue2) {
  142. rl_footer.setVisibility(View.VISIBLE);
  143. }else {
  144. rl_footer.setVisibility(View.GONE);
  145. }
  146.  
  147. }
  148. });
  149. }
  150.  
  151.  
  152. });
  153. ib_delete.setOnClickListener(new OnClickListener() {
  154.  
  155. @Override
  156. public void onClick(View v) {
  157. iv_photo.setBackgroundDrawable(getResources().getDrawable(R.drawable.edittext_bg_with_shadow));
  158. iv_photo.setImageURI(null);
  159. ll_image.setVisibility(View.GONE);
  160. bt_image.setVisibility(View.VISIBLE);
  161. deleteMultiImageResponse(question_id, image_name);
  162. ViewTreeObserver viwob=ll_main.getViewTreeObserver();
  163. viwob.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
  164.  
  165. @Override
  166. public void onGlobalLayout() {
  167. ll_main.getViewTreeObserver().removeGlobalOnLayoutListener(this);
  168. int height=ll_main.getMeasuredHeight();
  169. Log.d("rrr", "vidfbsds="+height+" sch="+scrollvalue2);
  170. if (height<scrollvalue2) {
  171. rl_footer.setVisibility(View.VISIBLE);
  172. }else {
  173. rl_footer.setVisibility(View.GONE);
  174. }
  175.  
  176. }
  177. });
  178.  
  179. }
  180. });
  181. if (count_multi==0) {
  182. ll_multiImage.addView(tv_question_text, text_question_params);
  183. } else {
  184. }
  185. ll_multiImage.addView(bt_image, bt_image_params);
  186. ll_multiImage.addView(ll_image, ll_image_params);
  187. try {
  188. ll_main.addView(ll_multiImage, ll_multiImageParams);
  189. } catch (Exception e) {
  190. }
  191.  
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement