This commit is contained in:
yadavendras
2016-12-30 11:55:04 +05:30
2 changed files with 74 additions and 7 deletions
@@ -1,10 +1,14 @@
package cpm.com.gskmtorange;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.support.design.widget.Snackbar;
import android.view.LayoutInflater;
import android.view.View;
import android.support.design.widget.NavigationView;
@@ -20,6 +24,13 @@ import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import cpm.com.gskmtorange.Database.GSKOrangeDB;
import cpm.com.gskmtorange.constant.CommonString;
import cpm.com.gskmtorange.gsk_dailyentry.CategoryListActivity;
import cpm.com.gskmtorange.dailyentry.StoreListActivity;
@@ -131,7 +142,7 @@ public class MainActivity extends AppCompatActivity
if (id == R.id.nav_route_plan) {
Intent startDownload = new Intent(this,StoreListActivity.class);
Intent startDownload = new Intent(this, StoreListActivity.class);
startActivity(startDownload);
overridePendingTransition(R.anim.activity_in, R.anim.activity_out);
@@ -153,6 +164,62 @@ public class MainActivity extends AppCompatActivity
} else if (id == R.id.nav_setting) {
startActivity(new Intent(MainActivity.this, CategoryListActivity.class));
} else if (id == R.id.nav_export) {
AlertDialog.Builder builder1 = new AlertDialog.Builder(MainActivity.this);
builder1.setMessage("Are you sure you want to take the backup of your data")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@SuppressWarnings("resource")
public void onClick(DialogInterface dialog, int id) {
try {
/*File file = new File(Environment
.getExternalStorageDirectory(),
"capital_backup");
if (!file.isDirectory()) {
file.mkdir();
}*/
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
long date = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("MMM/dd/yy");
String dateString = sdf.format(date);
String currentDBPath = "//data//cpm.com.gskmtorange//databases//" + GSKOrangeDB.DATABASE_NAME;
String backupDBPath = "GSKMT_ORANGE_Database_backup" + dateString.replace('/', '-');
String path = Environment.getExternalStorageDirectory().getPath();
File currentDB = new File(data, currentDBPath);
File backupDB = new File(path, backupDBPath);
//Snackbar.make(rec_store_data, "Database Exported Successfully", Snackbar.LENGTH_SHORT).show();
if (currentDB.exists()) {
@SuppressWarnings("resource")
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert1 = builder1.create();
alert1.show();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
@@ -71,7 +71,7 @@ public class DownloadActivity extends AppCompatActivity {
preferences = PreferenceManager.getDefaultSharedPreferences(this);
userId = preferences.getString(CommonString.KEY_USERNAME, null);
culture_id = preferences.getString(CommonString.KEY_CULTURE_ID, null);
culture_id = preferences.getString(CommonString.KEY_CULTURE_ID, "");
new UploadTask(DownloadActivity.this).execute();
}
@@ -256,7 +256,7 @@ public class DownloadActivity extends AppCompatActivity {
} else {
return "SUB_CATEGORY_MASTER";
}
data.value = 20;
data.value = 40;
data.name = "SUB_CATEGORY_MASTER Data Download";
}
publishProgress(data);
@@ -291,7 +291,7 @@ public class DownloadActivity extends AppCompatActivity {
} else {
return "CATEGORY_MASTER";
}
data.value = 20;
data.value = 50;
data.name = "CATEGORY_MASTER Data Download";
}
publishProgress(data);
@@ -326,7 +326,7 @@ public class DownloadActivity extends AppCompatActivity {
} else {
return "DISPLAY_MASTER";
}
data.value = 20;
data.value = 60;
data.name = "DISPLAY_MASTER Data Download";
}
publishProgress(data);
@@ -361,7 +361,7 @@ public class DownloadActivity extends AppCompatActivity {
} else {
return "MAPPING_STOCK";
}
data.value = 20;
data.value = 80;
data.name = "MAPPING_STOCK Data Download";
}
publishProgress(data);
@@ -396,7 +396,7 @@ public class DownloadActivity extends AppCompatActivity {
} else {
return "MAPPING_T2P";
}
data.value = 20;
data.value = 100;
data.name = "MAPPING_T2P Data Download";
}
publishProgress(data);