Advertisement
Guest User

Untitled

a guest
Jun 19th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.14 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3. package="com.amobi.newlomapodfix">
  4.  
  5. <uses-permission android:name="android.permission.INTERNET" />
  6. <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  7. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  8.  
  9. <application
  10. android:allowBackup="true"
  11. android:icon="@mipmap/ic_launcher"
  12. android:label="@string/app_name"
  13. android:supportsRtl="true"
  14. android:theme="@style/AppTheme">
  15. <activity
  16. android:name=".MainActivity"
  17. android:label="Article"
  18. android:theme="@style/AppTheme.NoActionBar">
  19. <intent-filter>
  20. <action android:name="android.intent.action.MAIN" />
  21.  
  22. <category android:name="android.intent.category.LAUNCHER" />
  23. </intent-filter>
  24. </activity>
  25. <activity
  26. android:name=".ShopActivity"
  27. android:label="Shop"
  28. android:theme="@style/AppTheme.NoActionBar" />
  29. <activity
  30. android:name=".ReadArtikelActivity"
  31. android:label="Article" />
  32. <activity
  33. android:name=".SignUpActivity"
  34. android:label="Register" />
  35. <activity
  36. android:name=".LoginActivity"
  37. android:label="Login" />
  38. <activity
  39. android:name=".AccountActivity"
  40. android:label="@string/title_activity_account"
  41. android:theme="@style/AppTheme.NoActionBar" />
  42. <activity android:name=".EditAccountActivity" />
  43. <activity android:name=".UploadActivity" />
  44. <activity android:name=".CartActivity" />
  45. <activity android:name=".DetilBarangActivity"></activity>
  46. <!-- ATTENTION: This was auto-generated to add Google Play services to your project for
  47. App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
  48. <meta-data
  49. android:name="com.google.android.gms.version"
  50. android:value="@integer/google_play_services_version" />
  51. </application>
  52.  
  53. </manifest>
  54.  
  55. import android.app.ProgressDialog;
  56. import android.content.Intent;
  57. import android.database.Cursor;
  58. import android.graphics.BitmapFactory;
  59. import android.net.Uri;
  60. import android.os.AsyncTask;
  61. import android.os.StrictMode;
  62. import android.provider.MediaStore;
  63. import android.support.v7.app.AppCompatActivity;
  64. import android.os.Bundle;
  65. import android.support.v7.widget.Toolbar;
  66. import android.util.Log;
  67. import android.view.MenuItem;
  68. import android.view.View;
  69. import android.widget.Button;
  70. import android.widget.ImageView;
  71. import android.widget.Toast;
  72.  
  73. import com.amobi.newlomapodfix.util.SessionManagement;
  74. import com.google.android.gms.appindexing.Action;
  75. import com.google.android.gms.appindexing.AppIndex;
  76. import com.google.android.gms.common.api.GoogleApiClient;
  77.  
  78. import org.apache.http.NameValuePair;
  79. import org.apache.http.message.BasicNameValuePair;
  80. import org.jibble.simpleftp.SimpleFTP;
  81. import org.json.JSONArray;
  82. import org.json.JSONException;
  83. import org.json.JSONObject;
  84.  
  85. import java.io.File;
  86. import java.util.ArrayList;
  87. import java.util.HashMap;
  88. import java.util.List;
  89.  
  90. public class UploadActivity extends AppCompatActivity {
  91.  
  92. private static final String URL_ID_TRANS = "http://amobipets.azurewebsites.net/getIdImage.php";
  93. private static final String URL_INSERT_IMAGE = "http://amobipets.azurewebsites.net/insertImage.php";
  94. private static final String URL_EDIT_TRANS = "http://amobipets.azurewebsites.net/editTrans.php";
  95. private static final String TAG_ID = "id";
  96. private static final String TAG_IMAGE_NAME = "image_name";
  97. private static final String TAG_STATUS = "Status";
  98. private static final String TAG_PESAN = "message";
  99. private static final String TAG_HASIL = "result";
  100. private static final String TAG_TRANS = "message";
  101. private static final String TAG_IMAGE_ID = "id_image";
  102. ProgressDialog pDialog;
  103.  
  104. JSONParser jparser = new JSONParser();
  105. ArrayList<HashMap<String, String>> namelist, idList, imageList;
  106. JSONArray names, names1, names2;
  107.  
  108. private static int RESULT_LOAD_IMG = 1;
  109. String imgDecodableString = null;
  110. Button btn;
  111.  
  112.  
  113. static final String FTP_HOST = "************";
  114. static final String FTP_USER = "************";
  115. static final String FTP_PASS = "************";
  116. String name, vid;
  117. /**
  118. * ATTENTION: This was auto-generated to implement the App Indexing API.
  119. * See https://g.co/AppIndexing/AndroidStudio for more information.
  120. */
  121. private GoogleApiClient client2;
  122. SessionManagement sessionManagement;
  123.  
  124. @Override
  125. protected void onCreate(Bundle savedInstanceState) {
  126. super.onCreate(savedInstanceState);
  127. setContentView(R.layout.activity_upload);
  128. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  129. getSupportActionBar().setHomeButtonEnabled(true);
  130.  
  131. sessionManagement =new SessionManagement(this);
  132. idList = new ArrayList<HashMap<String, String>>();
  133. imageList = new ArrayList<HashMap<String, String>>();
  134.  
  135. Bundle bun = getIntent().getExtras();
  136. vid = bun.getString("id");
  137.  
  138. btn = (Button) findViewById(R.id.buttonUploadPicture);
  139. btn.setOnClickListener(new View.OnClickListener() {
  140. @Override
  141. public void onClick(View v) {
  142. if (imgDecodableString == null) {
  143. Toast.makeText(UploadActivity.this, "Choose image first, please", Toast.LENGTH_LONG);
  144. } else {
  145. File f = new File(imgDecodableString);
  146. name = f.getName();
  147. uploadFile(f);
  148. }
  149. }
  150. });
  151.  
  152. // ATTENTION: This was auto-generated to implement the App Indexing API.
  153. // See https://g.co/AppIndexing/AndroidStudio for more information.
  154. client2 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
  155. }
  156.  
  157.  
  158. public void loadImagefromGallery(View view) {
  159. // Create intent to Open Image applications like Gallery, Google Photos
  160. Intent galleryIntent = new Intent(Intent.ACTION_PICK,
  161. MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  162. // Start the Intent
  163. startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
  164. }
  165.  
  166. @Override
  167. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  168. super.onActivityResult(requestCode, resultCode, data);
  169. try {
  170. // When an Image is picked
  171. if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK
  172. && null != data) {
  173. // Get the Image from data
  174.  
  175.  
  176. Uri selectedImage = data.getData();
  177. String[] filePathColumn = {MediaStore.Images.Media.DATA};
  178.  
  179. // Get the cursor
  180. Cursor cursor = getContentResolver().query(selectedImage,
  181. filePathColumn, null, null, null);
  182. // Move to first row
  183. cursor.moveToFirst();
  184.  
  185. int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
  186. String filename = cursor.getString(columnIndex);
  187. imgDecodableString = cursor.getString(columnIndex);
  188. cursor.close();
  189.  
  190. File f = new File("" + imgDecodableString);
  191. f.getName();
  192. ImageView imgView = (ImageView) findViewById(R.id.imgView);
  193. // Set the Image in ImageView after decoding the String
  194. imgView.setImageBitmap(BitmapFactory
  195. .decodeFile(imgDecodableString));
  196.  
  197. } else {
  198. Toast.makeText(this, "Pilih Bukti Transaksi",
  199. Toast.LENGTH_LONG).show();
  200. }
  201. } catch (Exception e) {
  202. Toast.makeText(this, "Failed to Choose", Toast.LENGTH_LONG)
  203. .show();
  204. }
  205. }
  206.  
  207. public void uploadFile(File fileName) {
  208.  
  209. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
  210. StrictMode.setThreadPolicy(policy);
  211. SimpleFTP ftp=new SimpleFTP();
  212.  
  213. try {
  214. ftp.connect(FTP_HOST, 21, FTP_USER, FTP_PASS);
  215. ftp.bin();
  216. ftp.cwd("/img/");
  217. ftp.stor(fileName);
  218. ftp.disconnect();
  219.  
  220. } catch (Exception e) {
  221. e.printStackTrace();
  222. try {
  223. ftp.disconnect();
  224. Toast.makeText(UploadActivity.this, "disconnect", Toast.LENGTH_LONG).show();
  225. } catch (Exception e2) {
  226. e2.printStackTrace();
  227. Toast.makeText(UploadActivity.this, "failed", Toast.LENGTH_LONG).show();
  228. }
  229. }
  230.  
  231. }
  232.  
  233. @Override
  234. public void onStart() {
  235. super.onStart();
  236.  
  237. // ATTENTION: This was auto-generated to implement the App Indexing API.
  238. // See https://g.co/AppIndexing/AndroidStudio for more information.
  239. client2.connect();
  240. Action viewAction = Action.newAction(
  241. Action.TYPE_VIEW, // TODO: choose an action type.
  242. "Upload Page", // TODO: Define a title for the content shown.
  243. // TODO: If you have web page content that matches this app activity's content,
  244. // make sure this auto-generated web page URL is correct.
  245. // Otherwise, set the URL to null.
  246. Uri.parse("http://host/path"),
  247. // TODO: Make sure this auto-generated app deep link URI is correct.
  248. Uri.parse("android-app://com.amobi.newlomapodfix/http/host/path")
  249. );
  250. AppIndex.AppIndexApi.start(client2, viewAction);
  251. }
  252.  
  253. @Override
  254. public void onStop() {
  255. super.onStop();
  256.  
  257. // ATTENTION: This was auto-generated to implement the App Indexing API.
  258. // See https://g.co/AppIndexing/AndroidStudio for more information.
  259. Action viewAction = Action.newAction(
  260. Action.TYPE_VIEW, // TODO: choose an action type.
  261. "Upload Page", // TODO: Define a title for the content shown.
  262. // TODO: If you have web page content that matches this app activity's content,
  263. // make sure this auto-generated web page URL is correct.
  264. // Otherwise, set the URL to null.
  265. Uri.parse("http://host/path"),
  266. // TODO: Make sure this auto-generated app deep link URI is correct.
  267. Uri.parse("android-app://com.amobi.newlomapodfix/http/host/path")
  268. );
  269. AppIndex.AppIndexApi.end(client2, viewAction);
  270. client2.disconnect();
  271. }
  272.  
  273. /*******
  274. * Used to file upload and show progress
  275. **********/
  276.  
  277. /* public class MyTransferListener implements FTPDataTransferListener {
  278.  
  279. public void started() {
  280.  
  281. btn.setVisibility(View.GONE);
  282. // Transfer started
  283. Toast.makeText(getBaseContext(), " Upload Started ...", Toast.LENGTH_SHORT).show();
  284.  
  285. }
  286.  
  287. public void transferred(int length) {
  288.  
  289. // Yet other length bytes has been transferred since the last time this
  290. // method was called
  291. Toast.makeText(getBaseContext(), " transferred ..." + length, Toast.LENGTH_SHORT).show();
  292. }
  293.  
  294. public void completed() {
  295.  
  296. btn.setVisibility(View.VISIBLE);
  297. // Transfer completed
  298.  
  299. Toast.makeText(getBaseContext(), " completed ...", Toast.LENGTH_LONG).show();
  300.  
  301. new InsertImage(name).execute();
  302.  
  303. }
  304.  
  305. public void aborted() {
  306.  
  307. btn.setVisibility(View.VISIBLE);
  308. // Transfer aborted
  309. Toast.makeText(getBaseContext(), " transfer aborted , please try again...", Toast.LENGTH_SHORT).show();
  310. }
  311.  
  312. public void failed() {
  313.  
  314. btn.setVisibility(View.VISIBLE);
  315. // Transfer failed
  316. System.out.println(" failed ...");
  317. }
  318. }
  319. */
  320. class InsertImage extends AsyncTask<String, String, String> {
  321. int sukses = 0;
  322. String img;
  323.  
  324. public InsertImage(String img) {
  325. this.img = img;
  326. }
  327.  
  328. @Override
  329. protected void onPreExecute() {
  330. }
  331.  
  332. @Override
  333. protected String doInBackground(String... args) {
  334. List<NameValuePair> params = new ArrayList<NameValuePair>();
  335.  
  336. params.add(new BasicNameValuePair("image_name", img));
  337. try {
  338. JSONObject json = jparser.makeHttpRequest(URL_INSERT_IMAGE, "GET", params);
  339.  
  340. if (json != null) {
  341. sukses = json.getInt(TAG_PESAN);
  342.  
  343. if (sukses == 1) {
  344. namelist = new ArrayList<HashMap<String, String>>();
  345. Log.d("Semua Nama: ", json.toString());
  346. names = json.getJSONArray(TAG_HASIL);
  347.  
  348. for (int i = 0; i < names.length(); i++) {
  349. JSONObject c = names.getJSONObject(i);
  350. String img = c.getString(TAG_IMAGE_NAME);
  351. HashMap<String, String> map = new HashMap<String, String>();
  352.  
  353. map.put(TAG_IMAGE_NAME, img);
  354.  
  355. namelist.add(map);
  356. }
  357. }
  358. }
  359. } catch (JSONException e) {
  360. e.printStackTrace();
  361. }
  362. return null;
  363. }
  364.  
  365. @Override
  366. protected void onPostExecute(String file_url) {
  367.  
  368. if (sukses == 1) {
  369. new getID().execute();
  370. }
  371. }
  372. }
  373.  
  374. public class getID extends AsyncTask<String, String, String> {
  375.  
  376. int sukses = 0;
  377.  
  378. public getID() {
  379. pDialog = new ProgressDialog(UploadActivity.this);
  380. }
  381.  
  382. @Override
  383. protected void onPreExecute() {
  384. super.onPreExecute();
  385. pDialog.setMessage("Loading . . .");
  386. pDialog.setIndeterminate(false);
  387. pDialog.setCancelable(false);
  388. pDialog.show();
  389. }
  390.  
  391. @Override
  392. protected String doInBackground(String... args) {
  393.  
  394. List<NameValuePair> params = new ArrayList<NameValuePair>();
  395. try {
  396. JSONObject json = jparser.makeHttpRequest(URL_ID_TRANS, "GET", params);
  397. if (json != null) {
  398. sukses = json.getInt(TAG_PESAN);
  399. if (sukses == 1) {
  400. idList = new ArrayList<HashMap<String, String>>();
  401. Log.d("Semua Nama: ", json.toString());
  402. names1 = json.getJSONArray(TAG_HASIL);
  403.  
  404. for (int i = 0; i < names1.length(); i++) {
  405. JSONObject c = names1.getJSONObject(i);
  406. String id = c.getString(TAG_ID);
  407.  
  408. HashMap<String, String> map = new HashMap<String, String>();
  409.  
  410. map.put(TAG_ID, id);
  411. idList.add(map);
  412. }
  413. }
  414. }
  415. } catch (JSONException e) {
  416. e.printStackTrace();
  417. }
  418.  
  419. return null;
  420. }
  421.  
  422. @Override
  423. protected void onPostExecute(String s) {
  424. pDialog.dismiss();
  425. String id_image;
  426. if(idList.size()==0)
  427. {
  428. id_image="1";
  429. }
  430. else {id_image = idList.get(0).get(TAG_ID);}
  431. new editTrans(id_image, "Uploaded", vid).execute();
  432. }
  433. }
  434.  
  435. class editTrans extends AsyncTask<String, String, String> {
  436. int sukses = 0;
  437. String id_image, status, id_trans;
  438.  
  439. public editTrans(String id_image, String status, String id_trans) {
  440. this.id_image = id_image;
  441. this.status = status;
  442. this.id_trans = id_trans;
  443. }
  444.  
  445. @Override
  446. protected void onPreExecute() {
  447. }
  448.  
  449. @Override
  450. protected String doInBackground(String... args) {
  451. List<NameValuePair> params = new ArrayList<NameValuePair>();
  452.  
  453. params.add(new BasicNameValuePair("id_image", id_image));
  454. params.add(new BasicNameValuePair("Status", status));
  455. params.add(new BasicNameValuePair("id_trans", id_trans));
  456.  
  457. try {
  458. JSONObject json = jparser.makeHttpRequest(URL_EDIT_TRANS, "GET", params);
  459.  
  460. if (json != null) {
  461. sukses = json.getInt(TAG_PESAN);
  462.  
  463. if (sukses == 1) {
  464. imageList = new ArrayList<HashMap<String, String>>();
  465. Log.d("Semua Nama: ", json.toString());
  466. names2 = json.getJSONArray(TAG_HASIL);
  467.  
  468. for (int i = 0; i < names2.length(); i++) {
  469. JSONObject c = names2.getJSONObject(i);
  470. String stat = c.getString(TAG_STATUS);
  471. String image = c.getString(TAG_IMAGE_ID);
  472. HashMap<String, String> map = new HashMap<String, String>();
  473.  
  474. map.put(TAG_IMAGE_ID, image);
  475. map.put(TAG_STATUS, stat);
  476.  
  477. imageList.add(map);
  478. }
  479. }
  480. }
  481. } catch (JSONException e) {
  482. e.printStackTrace();
  483. }
  484. return null;
  485. }
  486.  
  487. @Override
  488. protected void onPostExecute(String file_url) {
  489.  
  490. if (sukses == 1) {
  491. Intent i = new Intent(UploadActivity.this, AccountActivity.class);
  492. startActivity(i);
  493. }
  494. }
  495. }
  496.  
  497. @Override
  498. public boolean onOptionsItemSelected(MenuItem item) {
  499. switch (item.getItemId()) {
  500. case android.R.id.home:
  501. finish();
  502. return true;
  503. case R.id.action_settings:
  504. return true;
  505. case R.id.logout:
  506. sessionManagement.logoutUser();
  507. return true;
  508. default:
  509. return super.onOptionsItemSelected(item);
  510. }
  511. }
  512. }
  513.  
  514. android {
  515. compileSdkVersion 23
  516. buildToolsVersion "23.0.2"
  517.  
  518. defaultConfig {
  519. applicationId "com.amobi.newlomapodfix"
  520. minSdkVersion 17
  521. targetSdkVersion 23
  522. versionCode 1
  523. versionName "1.0"
  524. }
  525. buildTypes {
  526. release {
  527. minifyEnabled false
  528. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  529. }
  530. }
  531.  
  532. lintOptions {
  533. abortOnError false
  534. }
  535. }
  536.  
  537. dependencies {
  538. compile fileTree(include: ['*.jar'], dir: 'libs')
  539. testCompile 'junit:junit:4.12'
  540. compile project(':captcha')
  541. compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
  542. compile 'com.android.support:recyclerview-v7:23.1.1'
  543. compile 'com.android.support:support-v4:23.2.1'
  544. compile 'com.android.support:appcompat-v7:23.1.1'
  545. compile 'com.android.support:design:23.2.1'
  546. compile 'com.squareup.picasso:picasso:2.5.2'
  547. compile 'com.squareup.retrofit:retrofit:1.9.0'
  548. compile 'com.android.support:cardview-v7:23.1.1'
  549. compile 'com.google.android.gms:play-services-appindexing:8.1.0'
  550. compile files('libs/simpleftp.jar')
  551. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement