Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.66 KB | None | 0 0
  1. LoginActivity.java:
  2.  
  3. btnGallery.setOnClickListener(new OnClickListener() {
  4.  
  5. @Override
  6. public void onClick(View v) {
  7. // TODO Auto-generated method stub
  8. AlertDialog.Builder alertdialog = new AlertDialog.Builder(LoginActivity.this);
  9. alertdialog.setTitle(getResources().getString(R.string.app_name));
  10. alertdialog.setMessage("No Images found in UploadActivity");
  11. alertdialog.setPositiveButton("OK", new DialogInterface.OnClickListener()
  12. {
  13. public void onClick(DialogInterface dialog, int which) {
  14. finish(); //Finish your UploadActivity here.
  15. }
  16. });
  17. alertdialog.show();
  18.  
  19. }
  20. });
  21.  
  22.  
  23. UploadActivity.java:-
  24.  
  25. public class UploadActivity extends Activity {
  26.  
  27. final private static int DIALOG_LOGIN = 1;
  28. EditText editPersonName, editPersonaEmail, editPersonTelephone, parental_email ;
  29. TextView editImageName ;
  30. String fileName;
  31.  
  32. static ListView lstView;
  33. private Handler handler = new Handler();;
  34.  
  35. static List <String> ImageList;
  36. String strPath;
  37.  
  38. CheckBox chkOption3;
  39.  
  40. TextView tv1, tv2;
  41. CheckBox chkOption1, chkOption2 ;
  42.  
  43. int position ;
  44.  
  45. static File f1;
  46.  
  47. static String folder = null ;
  48.  
  49. Intent i;
  50. Intent intent ;
  51.  
  52. TextView textHeading1;
  53.  
  54. static File[] files;
  55. static File file ;
  56.  
  57. static List <String> it ;
  58.  
  59. static String textHeading = null;
  60. // new Class DB
  61. final myDBClasss myDb = new myDBClasss(this);
  62.  
  63. @Override
  64. public void onCreate(Bundle savedInstanceState) {
  65. super.onCreate(savedInstanceState);
  66.  
  67. setContentView(R.layout.activity_upload);
  68.  
  69. textHeading1 = (TextView) findViewById(R.id.txtEventNameDate1);
  70. textHeading1.setText(CameraLauncherActivity.folder);
  71.  
  72. final ImageButton buttonBack = (ImageButton) findViewById(R.id.back_btn);
  73. buttonBack.setOnClickListener(new View.OnClickListener() {
  74. public void onClick(View v) {
  75. // Perform action on click
  76. CameraLauncherActivity.isReturning = true;
  77. i = new Intent(getApplicationContext(), CameraLauncherActivity.class);
  78. i.putExtra("folder_name", CameraLauncherActivity.folder);
  79. i.putExtra("isReturning", true);
  80. startActivity(i);
  81. }
  82. });
  83.  
  84. ImageButton buttonSync = (ImageButton) findViewById(R.id.sync_btn);
  85. buttonSync.setOnClickListener(new OnClickListener() {
  86.  
  87. @Override
  88. public void onClick(View arg0) {
  89. // TODO Auto-generated method stub
  90.  
  91. for(int i=0; i<lstView.getChildCount(); i++)
  92. {
  93. startUpload(i);
  94. }
  95. }
  96. });
  97.  
  98.  
  99. /*** Get Images from SDCard ***/
  100. ImageList = getSD();
  101.  
  102. // ListView and imageAdapter
  103. lstView = (ListView) findViewById(R.id.listView1);
  104. lstView.setAdapter(new ImageAdapter(this));
  105. }
  106.  
  107.  
  108. public static List <String> getSD()
  109. {
  110. it = new ArrayList <String>();
  111. String string = "/mnt/sdcard/Pictures/Awesome/";
  112. f1 = new File (string+ CameraLauncherActivity.folder+ "/");
  113. files = f1.listFiles ();
  114.  
  115. for (int i = 0; i < files.length; i++)
  116. {
  117. file = files[i];
  118. Log.d("Count",file.getPath());
  119. it.add (file.getPath());
  120. }
  121. return it;
  122. }
  123.  
  124.  
  125. public class ImageAdapter extends BaseAdapter
  126. {
  127. private Context context;
  128.  
  129. public ImageAdapter(Context c)
  130. {
  131. // TODO Auto-generated method stub
  132. context = c;
  133. }
  134.  
  135. public int getCount() {
  136. // TODO Auto-generated method stub
  137. return ImageList.size();
  138. }
  139.  
  140. public Object getItem(int position) {
  141. // TODO Auto-generated method stub
  142. return position;
  143. }
  144.  
  145. public long getItemId(int position) {
  146. // TODO Auto-generated method stub
  147. return position;
  148. }
  149.  
  150. public View getView(final int position, View convertView, ViewGroup parent) {
  151. // TODO Auto-generated method stub
  152.  
  153. LayoutInflater inflater = (LayoutInflater) context
  154. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  155.  
  156. if (convertView == null) {
  157. convertView = inflater.inflate(R.layout.list_upload, null);
  158. }
  159.  
  160. // ColImgName
  161. TextView txtName = (TextView) convertView.findViewById(R.id.ColImgName);
  162. strPath = ImageList.get(position).toString();
  163.  
  164. // Get File Name
  165. fileName = strPath.substring( strPath.lastIndexOf('/')+1, strPath.length() );
  166. file = new File(strPath);
  167. @SuppressWarnings("unused")
  168. long length = file.length();
  169. txtName.setText(fileName);
  170.  
  171. // Image Resource
  172. ImageView imageView = (ImageView) convertView.findViewById(R.id.ColImgPath);
  173. final BitmapFactory.Options options = new BitmapFactory.Options();
  174.  
  175. options.inSampleSize = 8;
  176.  
  177. Bitmap bm = BitmapFactory.decodeFile(strPath,options);
  178. imageView.setImageBitmap(bm);
  179.  
  180.  
  181. // ColStatus
  182. final ImageView txtStatus = (ImageView) convertView.findViewById(R.id.ColStatus);
  183. txtStatus.setImageResource(R.drawable.bullet_button);
  184.  
  185. // progressBar
  186. final ProgressBar progress = (ProgressBar) convertView.findViewById(R.id.progressBar);
  187. progress.setVisibility(View.GONE);
  188.  
  189. //btnUpload
  190. final ImageButton btnUpload = (ImageButton) convertView.findViewById(R.id.btnUpload);
  191. btnUpload.setOnClickListener(new View.OnClickListener() {
  192. public void onClick(View v) {
  193. // Upload
  194. btnUpload.setEnabled(false);
  195.  
  196. startUpload(position);
  197. }
  198. });
  199.  
  200.  
  201. return convertView;
  202.  
  203. }
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement