diff --git a/GSKMTOrange/build.gradle b/GSKMTOrange/build.gradle index cabd1b3..a379ea0 100644 --- a/GSKMTOrange/build.gradle +++ b/GSKMTOrange/build.gradle @@ -39,4 +39,5 @@ dependencies { compile 'com.google.android.gms:play-services-location:9.0.2' compile 'com.google.android.gms:play-services-maps:9.0.2' compile 'com.android.support:cardview-v7:24.2.1' + compile 'com.google.android.gms:play-services-appindexing:9.0.2' } diff --git a/GSKMTOrange/src/main/AndroidManifest.xml b/GSKMTOrange/src/main/AndroidManifest.xml index e548e34..7fd8be3 100644 --- a/GSKMTOrange/src/main/AndroidManifest.xml +++ b/GSKMTOrange/src/main/AndroidManifest.xml @@ -18,7 +18,6 @@ android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> - - - - + android:theme="@style/AppTheme.NoActionBar" + android:screenOrientation="portrait"/> + - - - + - + android:screenOrientation="portrait"/> + android:windowSoftInputMode="adjustPan" + android:screenOrientation="portrait"/> - + android:windowSoftInputMode="adjustPan" + android:screenOrientation="portrait"/> + - + android:windowSoftInputMode="adjustPan" + android:screenOrientation="portrait"/> + + + + + + + + android:windowSoftInputMode="adjustPan" + android:screenOrientation="portrait"/> + + \ No newline at end of file diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/Database/GSKOrangeDB.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/Database/GSKOrangeDB.java index 13c6ae6..5f6b0a1 100644 --- a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/Database/GSKOrangeDB.java +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/Database/GSKOrangeDB.java @@ -11,20 +11,32 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import cpm.com.gskmtorange.GetterSetter.CoverageBean; +import cpm.com.gskmtorange.GetterSetter.GeotaggingBeans; import cpm.com.gskmtorange.GetterSetter.StoreBean; + +import cpm.com.gskmtorange.xmlGetterSetter.DisplayChecklistMasterGetterSetter; +import cpm.com.gskmtorange.xmlGetterSetter.GapsChecklistGetterSetter; + +import cpm.com.gskmtorange.xmlGetterSetter.JourneyPlanGetterSetter; +import cpm.com.gskmtorange.xmlGetterSetter.MappingDisplayChecklistGetterSetter; +import cpm.com.gskmtorange.xmlGetterSetter.MappingPromotionGetterSetter; +import cpm.com.gskmtorange.xmlGetterSetter.SkuGetterSetter; +import cpm.com.gskmtorange.xmlGetterSetter.T2PGetterSetter; +import cpm.com.gskmtorange.xmlGetterSetter.TableBean; + import cpm.com.gskmtorange.constant.CommonString; + import cpm.com.gskmtorange.xmlGetterSetter.BrandMasterGetterSetter; -import cpm.com.gskmtorange.xmlGetterSetter.CategoryGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.CategoryMasterGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.DisplayMasterGetterSetter; -import cpm.com.gskmtorange.xmlGetterSetter.JourneyPlanGetterSetter; + import cpm.com.gskmtorange.xmlGetterSetter.MAPPINGT2PGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.MSL_AvailabilityGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.MappingStockGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.SkuMasterGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.Stock_FacingGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.SubCategoryMasterGetterSetter; -import cpm.com.gskmtorange.xmlGetterSetter.TableBean; /** * Created by ashishc on 29-12-2016. @@ -62,10 +74,20 @@ public class GSKOrangeDB extends SQLiteOpenHelper { db.execSQL(TableBean.getMappingStock()); db.execSQL(TableBean.getMappingT2p()); + + db.execSQL(CommonString.CREATE_TABLE_STORE_GEOTAGGING); + db.execSQL(CommonString.CREATE_TABLE_COVERAGE_DATA); + + + db.execSQL(TableBean.getDisplayChecklistMaster()); + db.execSQL(TableBean.getMappingDisplayChecklist()); + db.execSQL(CommonString.CREATE_TABLE_INSERT_MSL_AVAILABILITY); db.execSQL(CommonString.CREATE_TABLE_INSERT_STOCK_FACING_HEADER); db.execSQL(CommonString.CREATE_TABLE_INSERT_STOCK_FACING_CHILD); + + } @Override @@ -128,6 +150,182 @@ public class GSKOrangeDB extends SQLiteOpenHelper { } } + public ArrayList getT2PDefaultData(String store_id){ + + ArrayList t2PList = new ArrayList<>(); + Cursor dbcursor = null; + + try { + + dbcursor = db.rawQuery("Select BM.BRAND As BRAND, BM.BRAND_ID As BRAND_ID, DM.DISPLAY As DISPLAY, DM.DISPLAY_ID As DISPLAY_ID from BRAND_MASTER BM INNER JOIN MAPPING_T2P T ON BM.BRAND_ID = T.BRAND_ID INNER JOIN DISPLAY_MASTER DM ON T.DISPLAY_ID= DM.DISPLAY_ID WHERE T.STORE_ID = '"+ store_id +"'",null); + if(dbcursor != null){ + dbcursor.moveToFirst(); + while(!dbcursor.isAfterLast()){ + + T2PGetterSetter t2p = new T2PGetterSetter(); + + t2p.setBrand_id(dbcursor.getString(dbcursor + .getColumnIndexOrThrow("BRAND_ID"))); + + t2p.setBrand(dbcursor.getString(dbcursor + .getColumnIndexOrThrow("BRAND"))); + + t2p.setDisplay_id(dbcursor.getString(dbcursor + .getColumnIndexOrThrow("DISPLAY_ID"))); + + t2p.setDisplay(dbcursor.getString(dbcursor + .getColumnIndexOrThrow("DISPLAY"))); + + t2p.setImage(""); + + t2p.setRemark(""); + + t2p.isPresent(); + + t2PList.add(t2p); + + dbcursor.moveToNext(); + } + + dbcursor.close(); + return t2PList; + } + } + catch (Exception e){ + + Log.d("Exception get T2P", e.toString()); + return t2PList; + } + + return t2PList; + } + + //get Gaps data + public ArrayList getGapsDefaultData(String display_id){ + + ArrayList checkList = new ArrayList<>(); + Cursor dbcursor = null; + + try { + + dbcursor = db.rawQuery("Select DC.CHECKLIST_ID As CHECKLIST_ID, DC.CHECKLIST As CHECKLIST, C.DISPLAY_ID As DISPLAY_ID from MAPPING_DISPLAY_CHECKLIST C INNER JOIN DISPLAY_CHECKLIST_MASTER DC ON C.CHECKLIST_ID= DC.CHECKLIST_ID WHERE C.DISPLAY_ID = '"+ display_id +"'",null); + if(dbcursor != null){ + dbcursor.moveToFirst(); + while(!dbcursor.isAfterLast()){ + + GapsChecklistGetterSetter check = new GapsChecklistGetterSetter(); + + check.setChecklist_id(dbcursor.getString(dbcursor + .getColumnIndexOrThrow("CHECKLIST_ID"))); + + check.setChecklist(dbcursor.getString(dbcursor + .getColumnIndexOrThrow("CHECKLIST"))); + + check.setDisplay_id(dbcursor.getString(dbcursor + .getColumnIndexOrThrow("DISPLAY_ID"))); + + check.isPresent(); + + checkList.add(check); + + dbcursor.moveToNext(); + } + + dbcursor.close(); + return checkList; + } + } + catch (Exception e){ + + Log.d("Exception get T2P", e.toString()); + return checkList; + } + + return checkList; + } + + //get Brand data for T2P + public ArrayList getBrandT2PData(String store_type_id, String class_id, String key_account_id ){ + + ArrayList brandList = new ArrayList<>(); + Cursor dbcursor = null; + + try { + + dbcursor = db.rawQuery("SELECT DISTINCT BR.BRAND_ID, SCM.SUB_CATEGORY||'-'||BR.BRAND AS BRAND FROM MAPPING_STOCK MS INNER JOIN SKU_MASTER SM ON MS.SKU_ID = SM.SKU_ID INNER JOIN BRAND_MASTER BR ON SM.BRAND_ID=BR.BRAND_ID INNER JOIN SUB_CATEGORY_MASTER SCM ON BR.SUB_CATEGORY_ID = SCM.SUB_CATEGORY_ID WHERE MS.KEYACCOUNT_ID ='"+key_account_id +"' AND STORETYPE_ID ='" + store_type_id + "' AND CLASS_ID = "+ class_id +"'",null); + if(dbcursor != null){ + dbcursor.moveToFirst(); + while(!dbcursor.isAfterLast()){ + + BrandMasterGetterSetter brand = new BrandMasterGetterSetter(); + + brand.setBRAND(dbcursor.getString(dbcursor + .getColumnIndexOrThrow("BRAND"))); + + brand.setBRAND_ID(dbcursor.getString(dbcursor + .getColumnIndexOrThrow("BRAND_ID"))); + + + brandList.add(brand); + + dbcursor.moveToNext(); + } + + dbcursor.close(); + return brandList; + } + } + catch (Exception e){ + + Log.d("Exception get T2P", e.toString()); + return brandList; + } + + return brandList; + } + + //get Sku data for T2P + public ArrayList getSkuT2PData(String store_type_id, String class_id, String key_account_id , String brand_id){ + + ArrayList skuList = new ArrayList<>(); + Cursor dbcursor = null; + + try { + + dbcursor = db.rawQuery("SELECT DISTINCT SM.SKU, SM.SKU_ID, BR.BRAND_ID FROM MAPPING_STOCK MS INNER JOIN SKU_MASTER SM ON MS.SKU_ID = SM.SKU_ID INNER JOIN BRAND_MASTER BR ON SM.BRAND_ID=BR.BRAND_ID INNER JOIN SUB_CATEGORY_MASTER SCM ON BR.SUB_CATEGORY_ID = SCM.SUB_CATEGORY_ID WHERE MS.KEYACCOUNT_ID ='"+key_account_id +"' AND STORETYPE_ID ='" + store_type_id + "' AND CLASS_ID = "+ class_id +"' AND SM.BRAND_ID='"+ brand_id + "'",null); + if(dbcursor != null){ + dbcursor.moveToFirst(); + while(!dbcursor.isAfterLast()){ + + SkuGetterSetter sku = new SkuGetterSetter(); + + sku.setSKU(dbcursor.getString(dbcursor + .getColumnIndexOrThrow("SKU"))); + + sku.setBRAND_ID(dbcursor.getString(dbcursor + .getColumnIndexOrThrow("BRAND_ID"))); + + sku.setSKU_ID(dbcursor.getString(dbcursor + .getColumnIndexOrThrow("SKU_ID"))); + + skuList.add(sku); + + dbcursor.moveToNext(); + } + + dbcursor.close(); + return skuList; + } + } + catch (Exception e){ + + Log.d("Exception get T2P", e.toString()); + return skuList; + } + + return skuList; + } + public ArrayList getStoreData(String date) { ArrayList list = new ArrayList(); Cursor dbcursor = null; @@ -244,6 +442,24 @@ public class GSKOrangeDB extends SQLiteOpenHelper { } } + //insert MAPPING_DISPLAY_CHECKLIST + public void InsertMappingDisplayChecklist(MappingDisplayChecklistGetterSetter data) { + db.delete("MAPPING_DISPLAY_CHECKLIST", null, null); + + ContentValues values = new ContentValues(); + try { + for (int i = 0; i < data.getCHECKLIST_ID().size(); i++) { + + values.put("DISPLAY_ID", data.getDISPLAY_ID().get(i)); + values.put("CHECKLIST_ID", data.getCHECKLIST_ID().get(i)); + + db.insert("MAPPING_DISPLAY_CHECKLIST", null, values); + } + } catch (Exception ex) { + Log.d("Exception ", " in MAPPING_STOCK " + ex.toString()); + } + } + public void InsertSubCategoryMaster(SubCategoryMasterGetterSetter data) { db.delete("SUB_CATEGORY_MASTER", null, null); @@ -303,6 +519,24 @@ public class GSKOrangeDB extends SQLiteOpenHelper { } } + //insert DISPLAY_CHECKLIST_MASTER + public void InsertDisplayChecklistMaster(DisplayChecklistMasterGetterSetter data) { + db.delete("DISPLAY_CHECKLIST_MASTER", null, null); + + ContentValues values = new ContentValues(); + try { + for (int i = 0; i < data.getCHECKLIST_ID().size(); i++) { + + values.put("CHECKLIST_ID", data.getCHECKLIST_ID().get(i)); + values.put("CHECKLIST", data.getCHECKLIST().get(i)); + + db.insert("DISPLAY_CHECKLIST_MASTER", null, values); + } + } catch (Exception ex) { + Log.d("Exception ", " in DISPLAY_CHECKLIST_MASTER " + ex.toString()); + } + } + public void InsertDisplayMaster(DisplayMasterGetterSetter data) { db.delete("DISPLAY_MASTER", null, null); @@ -340,6 +574,206 @@ public class GSKOrangeDB extends SQLiteOpenHelper { } + public void InsertSTOREgeotag(String storeid, double lat, double longitude, String path,String status) { + + ContentValues values = new ContentValues(); + + try { + + values.put("STORE_ID", storeid); + values.put("LATITUDE", Double.toString(lat)); + values.put("LONGITUDE", Double.toString(longitude)); + values.put("FRONT_IMAGE", path); + values.put("GEO_TAG", status); + values.put("STATUS", status); + + db.insert(CommonString.TABLE_STORE_GEOTAGGING, null, values); + + } catch (Exception ex) { + Log.d("Database Exception ", ex.toString()); + } + + } + + public void updateStatus(String id, String status, double lat, double longtitude) { + + ContentValues values = new ContentValues(); + + try { + + values.put("GEO_TAG", status); + + db.update(CommonString.KEY_JOURNEY_PLAN, values, CommonString.KEY_STORE_ID + "='" + id + "'", null); + + } catch (Exception ex) { + + } + + } + + + + + public void updateCheckoutStatus(String id, String status) { + + ContentValues values = new ContentValues(); + + try { + + values.put("CHECKOUT_STATUS", status); + + db.update(CommonString.KEY_JOURNEY_PLAN, values, CommonString.KEY_STORE_ID + "='" + id + "'", null); + + } catch (Exception ex) { + + } + + } + + + public ArrayList getinsertGeotaggingData(String status) { + + + ArrayList geodata = new ArrayList(); + + Cursor dbcursor = null; + + try { + dbcursor = db.rawQuery("SELECT * from " + CommonString.TABLE_STORE_GEOTAGGING + " WHERE GEO_TAG = '" + status + "'", null); + + if (dbcursor != null) { + int numrows = dbcursor.getCount(); + + dbcursor.moveToFirst(); + for (int i = 1; i <= numrows; ++i) { + + GeotaggingBeans data = new GeotaggingBeans(); + + data.setStoreid(dbcursor.getString(dbcursor.getColumnIndexOrThrow("STORE_ID"))); + data.setLatitude(Double.parseDouble(dbcursor.getString(dbcursor.getColumnIndexOrThrow("LATITUDE")))); + data.setLongitude(Double.parseDouble(dbcursor.getString(dbcursor.getColumnIndexOrThrow("LONGITUDE")))); + data.setUrl1(dbcursor.getString(dbcursor.getColumnIndexOrThrow("FRONT_IMAGE"))); + + geodata.add(data); + dbcursor.moveToNext(); + } + + dbcursor.close(); + + } + + } catch (Exception e) { + + } + finally { + if (dbcursor != null && !dbcursor.isClosed()) { + dbcursor.close(); + } + } + + + return geodata; + + } + + + public void updateGeoTagData(String storeid,String status) { + + try { + + ContentValues values = new ContentValues(); + values.put("GEO_TAG", status); + + int l = db.update(CommonString.TABLE_STORE_GEOTAGGING, values, + CommonString.KEY_STORE_ID + "=?", new String[] { storeid }); + System.out.println("update : " + l); + } catch (Exception e) { + Log.d("Database Data ", e.toString()); + + } + } + + public void updateDataStatus(String id,String status) { + + ContentValues values = new ContentValues(); + + try { + + values.put("GEO_TAG", status); + + db.update(CommonString.KEY_JOURNEY_PLAN, values, + CommonString.KEY_STORE_ID + "='" + id + "'", null); + + } catch (Exception ex) { + + } + + } + + + public void deleteGeoTagData(String storeid) { + + try { + db.delete(CommonString.TABLE_STORE_GEOTAGGING, CommonString.KEY_STORE_ID + "='" + storeid + "'", null); + } catch (Exception e) { + + } + } + + public ArrayList getCoverageData(String visitdate) { + + ArrayList list = new ArrayList(); + Cursor dbcursor = null; + + try { + + dbcursor = db.rawQuery("SELECT * from " + CommonString.TABLE_COVERAGE_DATA + " where " + + CommonString.KEY_VISIT_DATE + "='" + visitdate + "'", + null); + + + if (dbcursor != null) { + + dbcursor.moveToFirst(); + while (!dbcursor.isAfterLast()) { + CoverageBean sb = new CoverageBean(); + + sb.setStoreId(dbcursor.getString(dbcursor + .getColumnIndexOrThrow(CommonString.KEY_STORE_ID))); + sb.setUserId((dbcursor.getString(dbcursor + .getColumnIndexOrThrow(CommonString.KEY_USER_ID)))); + sb.setInTime(((dbcursor.getString(dbcursor + .getColumnIndexOrThrow(CommonString.KEY_IN_TIME))))); + sb.setOutTime(((dbcursor.getString(dbcursor + .getColumnIndexOrThrow(CommonString.KEY_OUT_TIME))))); + sb.setVisitDate((((dbcursor.getString(dbcursor + .getColumnIndexOrThrow(CommonString.KEY_VISIT_DATE)))))); + sb.setLatitude(((dbcursor.getString(dbcursor + .getColumnIndexOrThrow(CommonString.KEY_LATITUDE))))); + sb.setLongitude(((dbcursor.getString(dbcursor + .getColumnIndexOrThrow(CommonString.KEY_LONGITUDE))))); + sb.setStatus((((dbcursor.getString(dbcursor + .getColumnIndexOrThrow(CommonString.KEY_COVERAGE_STATUS)))))); + sb.setImage((((dbcursor.getString(dbcursor + .getColumnIndexOrThrow(CommonString.KEY_IMAGE)))))); + sb.setReason((((dbcursor.getString(dbcursor + .getColumnIndexOrThrow(CommonString.KEY_REASON)))))); + sb.setReasonid((((dbcursor.getString(dbcursor + .getColumnIndexOrThrow(CommonString.KEY_REASON_ID)))))); + sb.setMID(Integer.parseInt(((dbcursor.getString(dbcursor + .getColumnIndexOrThrow(CommonString.KEY_ID)))))); + if(dbcursor.getString(dbcursor + .getColumnIndexOrThrow(CommonString.KEY_COVERAGE_REMARK))==null){ + sb.setRemark(""); + } + else{ + sb.setRemark((((dbcursor.getString(dbcursor + .getColumnIndexOrThrow(CommonString.KEY_COVERAGE_REMARK)))))); + } + + list.add(sb); + + //Category List public ArrayList getCategoryListData(String keyAccountId, String storeTypeId, String classId) { ArrayList list = new ArrayList<>(); @@ -778,17 +1212,52 @@ public class GSKOrangeDB extends SQLiteOpenHelper { cd.setFacing(dbcursor.getString(dbcursor.getColumnIndexOrThrow("FACEUP_VALUE"))); list.add(cd); + dbcursor.moveToNext(); } dbcursor.close(); return list; } + } catch (Exception e) { Log.d("Exception ", "get Stock_Facing Sku After Save Data!" + e.toString()); return list; } return list; } + + public long InsertCoverageData(CoverageBean data) { + + //db.delete(CommonString1.TABLE_COVERAGE_DATA, "STORE_ID" + "='" + data.getStoreId() + "'", null); + + ContentValues values = new ContentValues(); + + try { + + values.put(CommonString.KEY_STORE_ID, data.getStoreId()); + values.put(CommonString.KEY_USER_ID, data.getUserId()); + values.put(CommonString.KEY_IN_TIME, data.getInTime()); + values.put(CommonString.KEY_OUT_TIME, data.getOutTime()); + values.put(CommonString.KEY_VISIT_DATE, data.getVisitDate()); + values.put(CommonString.KEY_LATITUDE, data.getLatitude()); + values.put(CommonString.KEY_LONGITUDE, data.getLongitude()); + values.put(CommonString.KEY_REASON_ID, data.getReasonid()); + values.put(CommonString.KEY_REASON, data.getReason()); + values.put(CommonString.KEY_COVERAGE_STATUS, data.getStatus()); + values.put(CommonString.KEY_IMAGE, data.getImage()); + values.put(CommonString.KEY_COVERAGE_REMARK, data.getRemark()); + values.put(CommonString.KEY_REASON_ID, data.getReasonid()); + values.put(CommonString.KEY_REASON, data.getReason()); + values.put(CommonString.KEY_GEO_TAG, data.getGEO_TAG()); + + return db.insert(CommonString.TABLE_COVERAGE_DATA, null, values); + + } catch (Exception ex) { + Log.d("Database Exception ", ex.toString()); + } + return 0; + } + public boolean checkStockAndFacingData(String store_id, String category_id) { Log.d("Stock_Facing ", "Stock data--------------->Start<------------"); @@ -860,4 +1329,5 @@ public class GSKOrangeDB extends SQLiteOpenHelper { Log.d("Exception ", " in Insert MSL_Availability " + ex.toString()); } } + } diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/GeoTag/GeoTagActivity.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/GeoTag/GeoTagActivity.java index c5f53bd..483b1e7 100644 --- a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/GeoTag/GeoTagActivity.java +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/GeoTag/GeoTagActivity.java @@ -1,39 +1,128 @@ package cpm.com.gskmtorange.GeoTag; +import android.Manifest; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.content.res.ColorStateList; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Color; +import android.location.Geocoder; import android.location.Location; import android.location.LocationManager; +import android.net.Uri; +import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; +import android.os.Environment; import android.preference.PreferenceManager; +import android.provider.MediaStore; +import android.provider.Settings; import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; +import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; +import android.util.Log; +import android.view.View; +import android.widget.ProgressBar; +import android.widget.TextView; +import android.widget.Toast; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.appindexing.Thing; +import com.google.android.gms.common.ConnectionResult; +import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.location.LocationListener; +import com.google.android.gms.location.LocationRequest; +import com.google.android.gms.location.LocationServices; +import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; +import com.google.android.gms.maps.model.LatLng; +import com.google.android.gms.maps.model.MarkerOptions; + +import org.ksoap2.SoapEnvelope; +import org.ksoap2.serialization.SoapObject; +import org.ksoap2.serialization.SoapSerializationEnvelope; +import org.ksoap2.transport.HttpTransportSE; +import org.xml.sax.InputSource; +import org.xml.sax.XMLReader; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.StringReader; +import java.net.SocketException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; import cpm.com.gskmtorange.R; +import cpm.com.gskmtorange.constant.CommonString; +import cpm.com.gskmtorange.Database.GSKOrangeDB; +import cpm.com.gskmtorange.GetterSetter.GeotaggingBeans; +import cpm.com.gskmtorange.messgae.AlertMessage; +import cpm.com.gskmtorange.upload.Base64; +import cpm.com.gskmtorange.xmlGetterSetter.FailureGetterSetter; +import cpm.com.gskmtorange.xmlHandlers.FailureXMLHandler; /** * Created by ashishc on 27-12-2016. */ -public class GeoTagActivity extends AppCompatActivity { - //implements OnMapReadyCallback,GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener{ +public class GeoTagActivity extends AppCompatActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener { + + String result, errormsg = ""; + ; + private ProgressBar pb; private GoogleMap mMap; - double latitude =0.0; - double longitude =0.0; - LocationManager locationManager; + double latitude = 0.0; + double longitude = 0.0; + protected String diskpath = "", _path, _pathforcheck, img_str = "", status; private Location mLastLocation; private LocationManager locmanager = null; - FloatingActionButton fab,fabcarmabtn; + FloatingActionButton fab, fabcarmabtn; SupportMapFragment mapFragment; SharedPreferences preferences; - + String username, storeid, str, storename, visitData; + GSKOrangeDB db; + LocationManager locationManager; + Geocoder geocoder; + boolean enabled; + private Dialog dialog; + private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 1000; + private GoogleApiClient mGoogleApiClient; + private LocationRequest mLocationRequest; + private static int UPDATE_INTERVAL = 500; // 5 sec + private static int FATEST_INTERVAL = 100; // 1 sec + private static int DISPLACEMENT = 5; // 10 meters + private static final String TAG = GeoTagActivity.class.getSimpleName(); + String defaultCameraPackage = ""; + File file; + private int factor, k; + ArrayList geotaglist = new ArrayList(); + private TextView percentage, message; + private FailureGetterSetter failureGetterSetter = null; + /** + * ATTENTION: This was auto-generated to implement the App Indexing API. + * See https://g.co/AppIndexing/AndroidStudio for more information. + */ + private GoogleApiClient client; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -41,30 +130,867 @@ public class GeoTagActivity extends AppCompatActivity { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); preferences = PreferenceManager.getDefaultSharedPreferences(this); - //username = preferences.getString(CommonString.KEY_USERNAME, null); + username = preferences.getString(CommonString.KEY_USERNAME, null); + storeid = preferences.getString(CommonString.KEY_STORE_ID, null); + storename = preferences.getString(CommonString.KEY_STORE_NAME, null); + visitData = preferences.getString(CommonString.KEY_VISIT_DATE, null); + final PackageManager packageManager = getPackageManager(); + fab = (FloatingActionButton) findViewById(R.id.fab); fabcarmabtn = (FloatingActionButton) findViewById(R.id.camrabtn); + db = new GSKOrangeDB(GeoTagActivity.this); + db.open(); + //storeid = getIntent().getStringExtra("Storeid"); + str = CommonString.FILE_PATH; mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); - //mapFragment.getMapAsync(this); - // mapFragment.getMapAsync(this); + + mapFragment.getMapAsync(this); + + locationManager = (LocationManager) this + .getSystemService(LOCATION_SERVICE); + geocoder = new Geocoder(this); + Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); + if (checkPlayServices()) { + + // Building the GoogleApi client + buildGoogleApiClient(); + } + if (checkPlayServices()) { + + // Building the GoogleApi client + buildGoogleApiClient(); + + createLocationRequest(); + } + + locmanager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); + enabled = locmanager.isProviderEnabled(LocationManager.GPS_PROVIDER); + + if (!enabled) { + AlertDialog.Builder alertDialog = new AlertDialog.Builder( + GeoTagActivity.this); + + // Setting Dialog Title + alertDialog.setTitle("GPS IS DISABLED..."); + + // Setting Dialog Message + alertDialog.setMessage("Click ok to enable GPS."); + + // Setting Positive "Yes" Button + alertDialog.setPositiveButton("YES", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + + Intent intent = new Intent( + Settings.ACTION_LOCATION_SOURCE_SETTINGS); + startActivity(intent); + } + }); + + // Setting Negative "NO" Button + alertDialog.setNegativeButton("NO", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + // Write your code here to invoke NO event + + dialog.cancel(); + } + }); + + // Showing Alert Message + alertDialog.show(); + + } + + + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (!img_str.equalsIgnoreCase("")) { + status = "Y"; + db.updateStatus(storeid, status, latitude, longitude); + + db.InsertSTOREgeotag(storeid, latitude, longitude, img_str, status); + img_str = ""; + + new GeoTagUpload(GeoTagActivity.this).execute(); + + + } else { + Snackbar.make(view, "Please Take Image Before Save", Snackbar.LENGTH_LONG).setAction("Action", null).show(); + + + } + + } + }); + + fabcarmabtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + List list = packageManager.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES); + for (int n = 0; n < list.size(); n++) { + if ((list.get(n).flags & ApplicationInfo.FLAG_SYSTEM) == 1) { + Log.d("TAG", "Installed Applications : " + list.get(n).loadLabel(packageManager).toString()); + Log.d("TAG", "package name : " + list.get(n).packageName); + if (list.get(n).loadLabel(packageManager).toString().equalsIgnoreCase("Camera")) { + defaultCameraPackage = list.get(n).packageName; + break; + } + } + } + + _pathforcheck = storeid + "Store" + "Image" + getCurrentTime().replace(":", "") + ".jpg"; + + _path = CommonString.FILE_PATH + _pathforcheck; + + + startCameraActivity(); + + } + }); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + private boolean checkPlayServices() { + int resultCode = GooglePlayServicesUtil + .isGooglePlayServicesAvailable(this); + if (resultCode != ConnectionResult.SUCCESS) { + if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { + GooglePlayServicesUtil.getErrorDialog(resultCode, this, + PLAY_SERVICES_RESOLUTION_REQUEST).show(); + } else { + Toast.makeText(getApplicationContext(), + "This device is not supported.", Toast.LENGTH_LONG) + .show(); + finish(); + } + return false; + } + return true; + } + + protected synchronized void buildGoogleApiClient() { + mGoogleApiClient = new GoogleApiClient.Builder(this) + .addConnectionCallbacks(this) + .addOnConnectionFailedListener(this) + .addApi(LocationServices.API).build(); + } + + + protected void createLocationRequest() { + mLocationRequest = new LocationRequest(); + mLocationRequest.setInterval(UPDATE_INTERVAL); + mLocationRequest.setFastestInterval(FATEST_INTERVAL); + mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); + mLocationRequest.setSmallestDisplacement(DISPLACEMENT); + } + + protected void startLocationUpdates() { + + + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED + || ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { + + LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this); + + } + + } + + /** + * Stopping location updates + */ + protected void stopLocationUpdates() { + LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this); + } + + @Override + public void onConnected(Bundle bundle) { + + mLastLocation = LocationServices.FusedLocationApi + .getLastLocation(mGoogleApiClient); + + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED + || ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { + if (mLastLocation != null) { + latitude = mLastLocation.getLatitude(); + longitude = mLastLocation.getLongitude(); + + mMap.setMyLocationEnabled(true); + + // Add a marker of latest location and move the camera + LatLng latLng = new LatLng(latitude, longitude); + mMap.addMarker(new MarkerOptions().position(latLng)); + mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); + mMap.animateCamera(CameraUpdateFactory.zoomTo(15)); + } + } + + + // if (mRequestingLocationUpdates) { + startLocationUpdates(); + // } + + // startLocationUpdates(); + } + + @Override + public void onConnectionSuspended(int i) { + mGoogleApiClient.connect(); + } + + @Override + public void onLocationChanged(Location location) { + + } + + @Override + public void onConnectionFailed(ConnectionResult connectionResult) { + Log.i(TAG, "Connection failed: ConnectionResult.getErrorCode() = " + connectionResult.getErrorCode()); + } + + @Override + public void onMapReady(GoogleMap googleMap) { + mMap = googleMap; + } + + protected void onStart() { + super.onStart();// ATTENTION: This was auto-generated to implement the App Indexing API. +// See https://g.co/AppIndexing/AndroidStudio for more information. + client.connect(); + if (mGoogleApiClient != null) { + mGoogleApiClient.connect(); + } + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + AppIndex.AppIndexApi.start(client, getIndexApiAction()); + } + + @Override + protected void onResume() { + super.onResume(); + + /* checkPlayServices(); + + // Resuming the periodic location updates + if (mGoogleApiClient.isConnected() && mRequestingLocationUpdates) { + startLocationUpdates(); + }*/ + } + + @Override + protected void onStop() { + super.onStop();// ATTENTION: This was auto-generated to implement the App Indexing API. +// See https://g.co/AppIndexing/AndroidStudio for more information. + AppIndex.AppIndexApi.end(client, getIndexApiAction()); + if (mGoogleApiClient.isConnected()) { + mGoogleApiClient.disconnect(); + } + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client.disconnect(); + } + + @Override + protected void onPause() { + super.onPause(); + stopLocationUpdates(); + } + + public String getCurrentTime() { + + Calendar m_cal = Calendar.getInstance(); + + SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss:mmm"); + String cdate = formatter.format(m_cal.getTime()); + + /* String intime = m_cal.get(Calendar.HOUR_OF_DAY) + ":" + + m_cal.get(Calendar.MINUTE) + ":" + m_cal.get(Calendar.SECOND);*/ + + return cdate; + + } + + protected void startCameraActivity() { + /* Log.i("MakeMachine", "startCameraActivity()"); + file = new File(_path); + Uri outputFileUri = Uri.fromFile(file); + + + Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + + + takePictureIntent.setPackage(defaultCameraPackage); + + takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); + + startActivityForResult(takePictureIntent, 1);*/ + + Log.i("MakeMachine", "startCameraActivity()"); + File file = new File(_path); + Uri outputFileUri = Uri.fromFile(file); + + String defaultCameraPackage=""; + final PackageManager packageManager = getPackageManager(); + List list = packageManager.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES); + for (int n=0;n= Build.VERSION_CODES.KITKAT) { + if (list.get(n).loadLabel(packageManager).toString().equalsIgnoreCase("Camera")) { + defaultCameraPackage = list.get(n).packageName; + break; + } + } else { + if (list.get(n).loadLabel(packageManager).toString().equalsIgnoreCase("Gallery")) { + defaultCameraPackage = list.get(n).packageName; + break; + } + } + } + + } + + Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + + + takePictureIntent.setPackage(defaultCameraPackage); + + takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); + + startActivityForResult(takePictureIntent, 1); } + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + + Log.i("MakeMachine", "resultCode: " + resultCode); + switch (resultCode) { + case 0: + Log.i("MakeMachine", "User cancelled"); + break; + + case -1: + + if (_pathforcheck != null && !_pathforcheck.equals("")) { + if (new File(str + _pathforcheck).exists()) { + + + fabcarmabtn.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.mipmap.camera_icon_done)); + + fabcarmabtn.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#4DB6AC"))); + + img_str = _pathforcheck; + _pathforcheck = ""; + + } + } + + break; + } + + super.onActivityResult(requestCode, resultCode, data); + } + + /** + * ATTENTION: This was auto-generated to implement the App Indexing API. + * See https://g.co/AppIndexing/AndroidStudio for more information. + */ + public Action getIndexApiAction() { + Thing object = new Thing.Builder() + .setName("GeoTag Page") // TODO: Define a title for the content shown. + // TODO: Make sure this auto-generated URL is correct. + .setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]")) + .build(); + return new Action.Builder(Action.TYPE_VIEW) + .setObject(object) + .setActionStatus(Action.STATUS_TYPE_COMPLETED) + .build(); + } + + + public class GeoTagUpload extends AsyncTask { + + private Context context; + + GeoTagUpload(Context context) { + this.context = context; + } + + @Override + protected void onPreExecute() { + + super.onPreExecute(); + + dialog = new Dialog(context); + dialog.setContentView(R.layout.custom); + dialog.setTitle("Uploading Data"); + dialog.setCancelable(false); + dialog.show(); + pb = (ProgressBar) dialog.findViewById(R.id.progressBar1); + percentage = (TextView) dialog.findViewById(R.id.percentage); + message = (TextView) dialog.findViewById(R.id.message); + } + + @Override + protected String doInBackground(Void... params) { + try { + + GSKOrangeDB db = new GSKOrangeDB(GeoTagActivity.this); + db.open(); + + geotaglist = db.getinsertGeotaggingData("Y"); + + // uploading Geotag + + SAXParserFactory saxPF = SAXParserFactory.newInstance(); + SAXParser saxP = saxPF.newSAXParser(); + XMLReader xmlR = saxP.getXMLReader(); + + + String geo_xml = ""; + ArrayList geotemplist = new ArrayList(); + if (geotaglist.size() > 0) { + + for (int i = 0; i < geotaglist.size(); i++) { + + runOnUiThread(new Runnable() { + public void run() { + // TODO Auto-generated method stub + k = k + factor; + pb.setProgress(k); + percentage.setText(k + "%"); + message.setText("Uploading Geotag Data..."); + } + }); + + String onXML = "[GeoTag_DATA][STORE_ID]" + + geotaglist.get(i).getStoreid() + + "[/STORE_ID]" + + "[LATTITUDE]" + + geotaglist.get(i).getLatitude() + + "[/LATTITUDE]" + + "[LONGITUDE]" + + geotaglist.get(i).getLongitude() + + "[/LONGITUDE]" + + "[FRONT_IMAGE]" + + geotaglist.get(i).getUrl1() + + "[/FRONT_IMAGE]" + + "[CREATED_BY]" + username + + "[/CREATED_BY][/GeoTag_DATA]"; + + geo_xml = geo_xml + onXML; + + geotemplist.add(geotaglist.get(i).getStoreid()); + + } + + geo_xml = "[DATA]" + geo_xml + + "[/DATA]"; + + SoapObject request = new SoapObject(CommonString.NAMESPACE, + CommonString.METHOD_UPLOAD_STOCK_XML_DATA); + request.addProperty("MID", "0"); + request.addProperty("KEYS", "GEOTAG_NEW_DATA"); + request.addProperty("USERNAME", username); + + request.addProperty("XMLDATA", geo_xml); + + SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( + SoapEnvelope.VER11); + envelope.dotNet = true; + envelope.setOutputSoapObject(request); + + HttpTransportSE androidHttpTransport = new HttpTransportSE( + CommonString.URL); + androidHttpTransport.call( + CommonString.SOAP_ACTION_UPLOAD_ASSET_XMLDATA, envelope); + Object result = (Object) envelope.getResponse(); + + if (result.toString().equalsIgnoreCase( + CommonString.KEY_SUCCESS)) { + String statusD = "D"; + + for (int i = 0; i < geotemplist.size(); i++) { + db.updateGeoTagData(geotemplist.get(i).toString(), statusD); + + db.updateDataStatus(geotemplist.get(i).toString(), statusD); + + } + + } else { + + if (result.toString().equalsIgnoreCase( + CommonString.KEY_FALSE)) { + return CommonString.METHOD_UPLOAD_ASSET; + } + + // for failure + FailureXMLHandler failureXMLHandler = new FailureXMLHandler(); + xmlR.setContentHandler(failureXMLHandler); + + InputSource is = new InputSource(); + is.setCharacterStream(new StringReader(result + .toString())); + xmlR.parse(is); + + failureGetterSetter = failureXMLHandler + .getFailureGetterSetter(); + + if (failureGetterSetter.getStatus().equalsIgnoreCase( + CommonString.KEY_FAILURE)) { + return CommonString.METHOD_UPLOAD_ASSET + "," + + failureGetterSetter.getErrorMsg(); + + } else { + + } + } + } + + + return CommonString.KEY_SUCCESS; + + } catch (SocketException ex) { + ex.printStackTrace(); + + + } catch (Exception ex) { + + + ex.printStackTrace(); + } + + + return ""; + + } + + + @Override + protected void onPostExecute(String result) { + super.onPostExecute(result); + + dialog.dismiss(); + + if (result.equals(CommonString.KEY_SUCCESS)) { + + + new GeoTagImageUpload(GeoTagActivity.this).execute(); + + Intent intent = new Intent( + GeoTagActivity.this, + GeoTagStoreList.class); + + startActivity(intent); + + GeoTagActivity.this.finish(); + + } + else if(!result.equals(CommonString.KEY_SUCCESS)) + { + + AlertMessage message = new AlertMessage( + GeoTagActivity.this, AlertMessage.MESSAGE_DATA_NOT + + result, "failure", null); + message.showMessage(); + + + } + + else if (!result.equals("")) { + + + } + + } + + } + + public class GeoTagImageUpload extends AsyncTask { + + private Context context; + + GeoTagImageUpload(Context context) { + this.context = context; + } + + @Override + protected void onPreExecute() { + + super.onPreExecute(); + + dialog = new Dialog(context); + dialog.setContentView(R.layout.custom); + dialog.setTitle("Uploading Geotag Images"); + dialog.setCancelable(false); + dialog.show(); + pb = (ProgressBar) dialog.findViewById(R.id.progressBar1); + percentage = (TextView) dialog.findViewById(R.id.percentage); + message = (TextView) dialog.findViewById(R.id.message); + } + + + @Override + protected String doInBackground(Void... params) { + try { + + GSKOrangeDB db = new GSKOrangeDB(GeoTagActivity.this); + db.open(); + + + geotaglist = db.getinsertGeotaggingData("D"); + + // Uploading Geotag + + SAXParserFactory saxPF = SAXParserFactory.newInstance(); + SAXParser saxP = saxPF.newSAXParser(); + XMLReader xmlR = saxP.getXMLReader(); + + + if (geotaglist.size() > 0) { + + for (int i = 0; i < geotaglist.size(); i++) { + + runOnUiThread(new Runnable() { + + public void run() { + // TODO Auto-generated method stub + k = k + factor; + pb.setProgress(k); + percentage.setText(k + "%"); + message.setText("Uploading Geotag Images..."); + } + }); + + if (geotaglist.get(i).getUrl1() != null + && !geotaglist.get(i).getUrl1() + .equalsIgnoreCase("")) { + + if (new File(Environment.getExternalStorageDirectory() + "/GSK_MT_Images/" + + geotaglist.get(i).getUrl1()).exists()) { + result = UploadGeoImage(geotaglist.get(i).getUrl1(), "GeoTag"); + + + if (!result.toString().equalsIgnoreCase(CommonString.KEY_SUCCESS)) { + + return "GeoTag"; + } + + + if (result.toString().equalsIgnoreCase(CommonString.KEY_FALSE)) { + + return CommonString.METHOD_Get_DR_STORE_IMAGES_GEO; + } else if (result + .equalsIgnoreCase(CommonString.KEY_FAILURE)) { + + return CommonString.METHOD_Get_DR_STORE_IMAGES_GEO + "," + errormsg; + } + /* runOnUiThread(new Runnable() { + + public void run() { + // TODO Auto-generated method stub + + message.setText("Image1 Upload"); + } + });*/ + } + } + + +// for(int i =0 ; i < geotaglist.size(); i++){ + +// } + + + } + + + } + + + return CommonString.KEY_SUCCESS; + + } + catch (SocketException ex) { + + ex.printStackTrace(); + } + + catch (Exception ex) { + ex.printStackTrace(); + + } + + return ""; + + } + + + @Override + protected void onPostExecute(String result) { + super.onPostExecute(result); + + dialog.dismiss(); + + if (result.equalsIgnoreCase(CommonString.KEY_SUCCESS)) { + + + //Toast.makeText(getApplicationContext(),"GeoTag Uploaded ",Toast.LENGTH_LONG).show(); + + String Statustag = "U"; + db.open(); + + for (int i = 0; i < geotaglist.size(); i++) { + + + db.updateGeoTagData(geotaglist.get(i).getStoreid(), Statustag); + + db.updateDataStatus(geotaglist.get(i).getStoreid(), Statustag); + + // db.updateGeoTagDataInMain(geotaglist.get(i).getStoreid()); + + db.deleteGeoTagData(geotaglist.get(i).getStoreid()); + + + } + + + + AlertMessage message = new AlertMessage( + GeoTagActivity.this, AlertMessage.MESSAGE_ERROR + + result, "success", null); + message.showMessage(); + + + } + else if(!result.equals(CommonString.KEY_SUCCESS)) + { + + AlertMessage message = new AlertMessage( + GeoTagActivity.this, AlertMessage.MESSAGE_DATA_NOT + + result, "failure", null); + message.showMessage(); + + + } + + + + else if (!result.equals("")) { + + } + + } + + } + + public String UploadGeoImage(String path, String folder) throws Exception { + + errormsg = ""; + BitmapFactory.Options o = new BitmapFactory.Options(); + o.inJustDecodeBounds = true; + BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/GSK_MT_Images/" + path, o); + + // The new size we want to scale to + final int REQUIRED_SIZE = 1024; + + // Find the correct scale value. It should be the power of 2. + int width_tmp = o.outWidth, height_tmp = o.outHeight; + int scale = 1; + + while (true) { + if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE) + break; + width_tmp /= 2; + height_tmp /= 2; + scale *= 2; + } + + // Decode with inSampleSize + BitmapFactory.Options o2 = new BitmapFactory.Options(); + o2.inSampleSize = scale; + Bitmap bitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/GSK_MT_Images/" + path, o2); + + ByteArrayOutputStream bao = new ByteArrayOutputStream(); + bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bao); + byte[] ba = bao.toByteArray(); + String ba1 = Base64.encodeBytes(ba); + + SoapObject request = new SoapObject(CommonString.NAMESPACE, + CommonString.METHOD_Get_DR_POSM_IMAGES); + + request.addProperty("img", ba1); + request.addProperty("name", path); + request.addProperty("FolderName", folder); + + SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( + SoapEnvelope.VER11); + envelope.dotNet = true; + envelope.setOutputSoapObject(request); + + HttpTransportSE androidHttpTransport = new HttpTransportSE( + CommonString.URL); + + androidHttpTransport.call( + CommonString.SOAP_ACTION_Get_DR_POSM_IMAGES, envelope); + Object result = (Object) envelope.getResponse(); + + if (result.toString().equalsIgnoreCase(CommonString.KEY_SUCCESS)) { + + new File(Environment.getExternalStorageDirectory() + "/GSK_MT_Images/" + path).delete(); + + + + /*SAXParserFactory saxPF = SAXParserFactory.newInstance(); + SAXParser saxP = saxPF.newSAXParser(); + XMLReader xmlR = saxP.getXMLReader(); + + // for failure + FailureXMLHandler failureXMLHandler = new FailureXMLHandler(); + xmlR.setContentHandler(failureXMLHandler); + + InputSource is = new InputSource(); + is.setCharacterStream(new StringReader(result.toString())); + xmlR.parse(is); + + failureGetterSetter = failureXMLHandler + .getFailureGetterSetter(); + + if (failureGetterSetter.getStatus().equalsIgnoreCase( + CommonString.KEY_FAILURE)) { + errormsg = failureGetterSetter.getErrorMsg(); + return CommonString.KEY_FAILURE; + }*/ + + } else if (result.toString().equalsIgnoreCase(CommonString.KEY_FALSE)) { + return CommonString.KEY_FALSE; + } else { + return CommonString.KEY_FAILURE; + } + + return result.toString(); + } } diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/GeoTag/GeoTagStoreList.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/GeoTag/GeoTagStoreList.java index 230add1..d65b90b 100644 --- a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/GeoTag/GeoTagStoreList.java +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/GeoTag/GeoTagStoreList.java @@ -1,34 +1,387 @@ package cpm.com.gskmtorange.GeoTag; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; +import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.Toolbar; +import android.view.LayoutInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.ListView; +import android.widget.RelativeLayout; +import android.widget.TextView; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import cpm.com.gskmtorange.MainActivity; + +import cpm.com.gskmtorange.Database.GSKOrangeDB; +import cpm.com.gskmtorange.GetterSetter.StoreBean; import cpm.com.gskmtorange.R; +import cpm.com.gskmtorange.constant.CommonString; /** * Created by ashishc on 27-12-2016. */ -public class GeoTagStoreList extends AppCompatActivity { +public class GeoTagStoreList extends AppCompatActivity implements View.OnClickListener { - - ListView lv; + private SharedPreferences preferences; + ArrayList storelist = new ArrayList(); + String date,visit_status; + GSKOrangeDB db; + // ListView list; + ValueAdapter adapter; + RecyclerView recyclerView; + private SharedPreferences.Editor editor = null; LinearLayout parent_linear,nodata_linear; protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.storelistlayout); - lv = (ListView) findViewById(R.id.list); - nodata_linear = (LinearLayout) findViewById(R.id.no_data_lay); - parent_linear = (LinearLayout) findViewById(R.id.parent_linear); + //list = (ListView) findViewById(R.id.list_id); + + recyclerView=(RecyclerView) findViewById(R.id.drawer_layout_recycle); + + // nodata_linear = (LinearLayout) findViewById(R.id.no_data_lay); + //parent_linear = (LinearLayout) findViewById(R.id.parent_linear); + + + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + getSupportActionBar().setHomeButtonEnabled(true); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + preferences = PreferenceManager.getDefaultSharedPreferences(this); + date = preferences.getString(CommonString.KEY_DATE, null); + visit_status = preferences.getString(CommonString.KEY_STOREVISITED_STATUS, ""); + + db = new GSKOrangeDB(GeoTagStoreList.this); + db.open(); + + storelist = db.getStoreData(date); + + if (storelist.size()>0) { + + adapter=new ValueAdapter(getApplicationContext(),storelist); + recyclerView.setAdapter(adapter); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + + } + else + { + + } + + + } + +/* + private class MyAdaptor extends BaseAdapter { + + @Override + public int getCount() { + + return storelist.size(); + } + + @Override + public Object getItem(int position) { + + return position; + } + + @Override + public long getItemId(int position) { + + return position; + } + + @Override + public View getView(final int position, View convertView, ViewGroup parent) { + GeoTagStoreList.ViewHolder holder = null; + if (convertView == null) { + holder = new GeoTagStoreList.ViewHolder(); + + LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); + convertView = inflater.inflate(R.layout.geotagstorelist, null); + + holder.storename = (TextView) convertView.findViewById(R.id.geolistviewxml_storename); + + holder.imgtick = (ImageView) convertView + .findViewById(R.id.imageView1); + + convertView.setTag(holder); + + } else { + holder = (GeoTagStoreList.ViewHolder) convertView.getTag(); + } + holder.storename.setText(storelist.get(position).getSTORE_NAME()); + //holder.storeaddress.setText(storelist.get(position).getCITY()); + + return convertView; + } + + } +*/ + + /*private class ViewHolder { + TextView storename, storeaddress; + ImageView imgtick; + Button checkout; + + RelativeLayout l1; + + }*/ + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + if(id==android.R.id.home){ + + + finish(); + + overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out); + + } + + return super.onOptionsItemSelected(item); + } + @Override + public void onBackPressed() { + // TODO Auto-generated method stub + Intent intent = new Intent(GeoTagStoreList.this, MainActivity.class); + + startActivity(intent); + GeoTagStoreList.this.finish(); + } + + + /*protected void onListItemClick(ListView l, View v, int position, long id) { + // TODO Auto-generated method stub + // super.onListItemClick(l, v, position, id); + + storelist = db.getStoreData(date); + StoreBean sb = storelist.get(position); + + // When clicked, show a toast with the TextView text + if (storelist.get(position).getGEO_TAG().equalsIgnoreCase("U")) { + + + Snackbar.make(v, R.string.title_geo_tag_activity_upload_data, Snackbar.LENGTH_LONG).setAction("Action", null).show(); + + + } else if (storelist.get(position).getGEO_TAG().equalsIgnoreCase("D")){ + + + Snackbar.make(v, R.string.title_geo_tag_activity_geo_data, Snackbar.LENGTH_LONG).setAction("Action", null).show(); + + + } + + else if (storelist.get(position).getGEO_TAG().equalsIgnoreCase("Y")) { + + + Snackbar.make(v, R.string.title_geo_tag_activity_geo_already_done, Snackbar.LENGTH_LONG).setAction("Action", null).show(); + } else if (storelist.get(position).getGEO_TAG().equalsIgnoreCase("P")) { + + Snackbar.make(v, R.string.title_geo_tag_activity_geo_already_done, Snackbar.LENGTH_LONG).setAction("Action", null).show(); + + } else { + + // PUT IN PREFERENCES + editor = preferences.edit(); + editor.putString(CommonString.KEY_STORE_ID, sb.getSTORE_ID()); + editor.putString(CommonString.KEY_STORE_NAME, sb.getSTORE_NAME()); + editor.putString(CommonString.KEY_VISIT_DATE, sb.getVISIT_DATE()); + editor.commit(); + + Intent intent = new Intent(GeoTagStoreList.this, GeoTagActivity.class); + startActivity(intent); + GeoTagStoreList(); + } + } + + @Override + public void onClick(View arg0) { + // TODO Auto-generated method stub + + } + + + public void GeoTagStoreList() { + + this.finish(); + + }*/ + + public class ValueAdapter extends RecyclerView.Adapter{ + + private LayoutInflater inflator; + + List data= Collections.emptyList(); + + public ValueAdapter(Context context, List data){ + + inflator = LayoutInflater.from(context); + this.data=data; + + } + + @Override + public ValueAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int i) { + + View view=inflator.inflate(R.layout.geotagstorelist,parent,false); + + MyViewHolder holder=new MyViewHolder(view); + + return holder; + } + + @Override + public void onBindViewHolder(final ValueAdapter.MyViewHolder viewHolder, final int position) { + + final StoreBean current=data.get(position); + + //viewHolder.txt.setText(current.txt); + + viewHolder.txt.setText(current.getSTORE_NAME()); + + if(current.getGEO_TAG().equalsIgnoreCase("Y")) + { + viewHolder.imageview.setVisibility(View.VISIBLE); + viewHolder.imageview.setBackgroundResource(R.mipmap.geopin); + } + else if(current.getGEO_TAG().equalsIgnoreCase("D")){ + viewHolder.imageview.setVisibility(View.VISIBLE); + viewHolder.imageview.setBackgroundResource(R.mipmap.tick_d); + } + else if(current.getGEO_TAG().equalsIgnoreCase("U")){ + viewHolder.imageview.setVisibility(View.VISIBLE); + viewHolder.imageview.setBackgroundResource(R.mipmap.tick_u); + } + else if(current.getGEO_TAG().equalsIgnoreCase("P")){ + viewHolder.imageview.setVisibility(View.VISIBLE); + viewHolder.imageview.setBackgroundResource(R.mipmap.tick_p); + } + else + { + viewHolder.imageview.setVisibility(View.INVISIBLE); + } + + viewHolder.relativelayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + if(current.getGEO_TAG().equalsIgnoreCase("Y")) + { + Snackbar.make(v, R.string.title_geo_tag_activity_geo_already_done, Snackbar.LENGTH_LONG).setAction("Action", null).show(); + } + else if(current.getGEO_TAG().equalsIgnoreCase("D")){ + + Snackbar.make(v, R.string.title_geo_tag_activity_geo_data, Snackbar.LENGTH_LONG).setAction("Action", null).show(); + + } + else if(current.getGEO_TAG().equalsIgnoreCase("U")){ + + Snackbar.make(v, R.string.title_geo_tag_activity_upload_data, Snackbar.LENGTH_LONG).setAction("Action", null).show(); + + + } + else if(current.getGEO_TAG().equalsIgnoreCase("P")){ + + Snackbar.make(v, R.string.title_geo_tag_activity_geo_data, Snackbar.LENGTH_LONG).setAction("Action", null).show(); + } + else + { + + // PUT IN PREFERENCES + editor = preferences.edit(); + editor.putString(CommonString.KEY_STORE_ID, current.getSTORE_ID()); + editor.putString(CommonString.KEY_STORE_NAME, current.getSTORE_NAME()); + editor.putString(CommonString.KEY_VISIT_DATE, current.getVISIT_DATE()); + editor.commit(); + + Intent in =new Intent(GeoTagStoreList.this,GeoTagActivity.class); + startActivity(in); + finish(); + } + + } + }); + } + + @Override + public int getItemCount() { + return data.size(); + } + + class MyViewHolder extends RecyclerView.ViewHolder{ + + TextView txt; + ImageView icon; + RelativeLayout relativelayout; + ImageView imageview; + + public MyViewHolder(View itemView) { + super(itemView); + txt=(TextView) itemView.findViewById(R.id.geolistviewxml_storename); + relativelayout=(RelativeLayout) itemView.findViewById(R.id.relativelayout); + imageview=(ImageView) itemView.findViewById(R.id.imageView1); + + } + } + + } + + + public List getdata() { + List data = new ArrayList<>(); + + storelist = db.getStoreData(date); + + StoreBean storelistdata=new StoreBean(); + + + for(int i=0;i coverage; ArrayList storelist = new ArrayList(); - - - ListView list; + //ListView list; private SharedPreferences preferences; - - String date,visit_status; + String date, visit_status; GSKOrangeDB db; - + StoreListActivity.ValueAdapter adapter; + RecyclerView recyclerView; + private SharedPreferences.Editor editor = null; + LinearLayout linearlay; + String store_id; + private Dialog dialog; + boolean result_flag = false, leaveflag = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -64,136 +79,35 @@ public class StoreListActivity extends AppCompatActivity { db.open(); - list = (ListView)findViewById(R .id.list_id); + linearlay = (LinearLayout) findViewById(R.id.linearlayout); + recyclerView = (RecyclerView) findViewById(R.id.drawer_layout_recycle); + + } + + + protected void onResume() { + // TODO Auto-generated method stub + super.onResume(); + storelist = db.getStoreData(date); + coverage=db.getCoverageData(date); + if (storelist.size() > 0) { + //list.setAdapter(new MyAdaptor()); + adapter = new StoreListActivity.ValueAdapter(getApplicationContext(), storelist); + recyclerView.setAdapter(adapter); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); - if (storelist.size()>0) { - list.setAdapter(new MyAdaptor()); - } + } else { - list.setOnItemClickListener(new AdapterView.OnItemClickListener() { - - @Override - public void onItemClick(AdapterView parent, View view, - int position, long id) { - - - Toast.makeText(getApplicationContext(),"Click",Toast.LENGTH_LONG).show(); - - - - } - }); - - } - - - private class MyAdaptor extends BaseAdapter { - - @Override - public int getCount() { - - return storelist.size(); - } - - @Override - public Object getItem(int position) { - - return position; - } - - @Override - public long getItemId(int position) { - - return position; - } - - @Override - public View getView(final int position, View convertView, ViewGroup parent) { - ViewHolder holder = null; - if (convertView == null) { - holder = new ViewHolder(); - - LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); - convertView = inflater.inflate(R.layout.storeviewlist, null); - - holder.storename = (TextView) convertView - .findViewById(R.id.storelistviewxml_storename); - holder.storeaddress = (TextView) convertView - .findViewById(R.id.storelistviewxml_storeaddress); - - holder.imgtick = (ImageView) convertView - .findViewById(R.id.storelistviewxml_storeico); - - holder.checkout = (Button) convertView - .findViewById(R.id.chkout); - - holder.l1 = (RelativeLayout) convertView - .findViewById(R.id.storenamelistview_layout); - - convertView.setTag(holder); - - } else { - holder = (ViewHolder) convertView.getTag(); - } - holder.storename.setText(storelist.get(position).getSTORE_NAME()); - holder.storeaddress.setText(storelist.get(position).getCITY()); - - - - - - holder.checkout.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - - AlertDialog.Builder builder = new AlertDialog.Builder( - StoreListActivity.this); - builder.setMessage("Are you sure you want to checkout") - .setCancelable(false) - .setPositiveButton("OK", - new DialogInterface.OnClickListener() { - public void onClick( - DialogInterface dialog, int id) { - - - } - }) - .setNegativeButton("Cancel", - new DialogInterface.OnClickListener() { - public void onClick( - DialogInterface dialog, int id) { - dialog.cancel(); - } - }); - AlertDialog alert = builder.create(); - alert.show(); - - } - }); - - - - return convertView; + recyclerView.setVisibility(View.INVISIBLE); + linearlay.setVisibility(View.VISIBLE); } } - - private class ViewHolder { - TextView storename, storeaddress; - ImageView imgtick; - Button checkout; - - RelativeLayout l1; - - } - - @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will @@ -201,7 +115,7 @@ public class StoreListActivity extends AppCompatActivity { // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); - if(id==android.R.id.home){ + if (id == android.R.id.home) { // NavUtils.navigateUpFromSameTask(this); finish(); @@ -214,4 +128,286 @@ public class StoreListActivity extends AppCompatActivity { } + public class ValueAdapter extends RecyclerView.Adapter { + + private LayoutInflater inflator; + + List data = Collections.emptyList(); + + public ValueAdapter(Context context, List data) { + + inflator = LayoutInflater.from(context); + this.data = data; + + } + + @Override + public StoreListActivity.ValueAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int i) { + + View view = inflator.inflate(R.layout.storeviewlist, parent, false); + + StoreListActivity.ValueAdapter.MyViewHolder holder = new StoreListActivity.ValueAdapter.MyViewHolder(view); + + return holder; + } + + @Override + public void onBindViewHolder(final StoreListActivity.ValueAdapter.MyViewHolder viewHolder, final int position) { + + final StoreBean current = data.get(position); + + + String storeid = current.getSTORE_ID(); + //viewHolder.txt.setText(current.txt); + + viewHolder.txt.setText(current.getSTORE_NAME()); + viewHolder.address.setText(current.getADDRESS()); + + if (current.getCHECKOUT_STATUS().equalsIgnoreCase(CommonString.KEY_VALID)) { + viewHolder.chkbtn.setVisibility(View.VISIBLE); + viewHolder.imageview.setVisibility(View.INVISIBLE); + } else if (current.getUPLOAD_STATUS().equalsIgnoreCase(CommonString.KEY_U)) { + viewHolder.imageview.setVisibility(View.VISIBLE); + viewHolder.imageview.setBackgroundResource(R.mipmap.tick_u); + viewHolder.chkbtn.setVisibility(View.INVISIBLE); + } else if (current.getUPLOAD_STATUS().equalsIgnoreCase(CommonString.KEY_D)) { + viewHolder.imageview.setVisibility(View.VISIBLE); + viewHolder.imageview.setBackgroundResource(R.mipmap.tick_d); + viewHolder.chkbtn.setVisibility(View.INVISIBLE); + } else if (current.getCHECKOUT_STATUS().equalsIgnoreCase(CommonString.KEY_C)) { + viewHolder.imageview.setVisibility(View.VISIBLE); + viewHolder.imageview.setBackgroundResource(R.mipmap.tick_c); + viewHolder.chkbtn.setVisibility(View.INVISIBLE); + } else if (current.getUPLOAD_STATUS().equalsIgnoreCase(CommonString.KEY_P)) { + viewHolder.imageview.setVisibility(View.VISIBLE); + viewHolder.imageview.setBackgroundResource(R.mipmap.tick_p); + viewHolder.chkbtn.setVisibility(View.INVISIBLE); + } else if (current.getUPLOAD_STATUS().equalsIgnoreCase(CommonString.KEY_L)) { + viewHolder.imageview.setVisibility(View.VISIBLE); + viewHolder.imageview.setBackgroundResource(R.mipmap.tickl); + viewHolder.chkbtn.setVisibility(View.INVISIBLE); + } else if (current.getCHECKOUT_STATUS().equalsIgnoreCase(CommonString.KEY_INVALID)) { + + + if (coverage.size() > 0) { + + int i; + + for (i = 0; i < coverage.size(); i++) { + + + if (coverage.get(i).getInTime() != null) { + + if (coverage.get(i).getOutTime() == null) { + + if (storeid.equals(coverage.get(i).getStoreId())) { + viewHolder.imageview.setVisibility(View.VISIBLE); + viewHolder.imageview.setBackgroundResource(R.mipmap.checkin); + viewHolder.chkbtn.setVisibility(View.INVISIBLE); + + } + break; + } + + } + + } + } + } else { + viewHolder.imageview.setVisibility(View.INVISIBLE); + viewHolder.chkbtn.setVisibility(View.INVISIBLE); + } + + + viewHolder.relativelayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + store_id = current.getSTORE_ID(); + + + if (current.getUPLOAD_STATUS().equalsIgnoreCase(CommonString.KEY_U)) { + Snackbar.make(v, R.string.title_store_list_activity_store_already_done, Snackbar.LENGTH_LONG).setAction("Action", null).show(); + } else if (current.getUPLOAD_STATUS().equalsIgnoreCase(CommonString.KEY_D)) { + + Snackbar.make(v, R.string.title_store_list_activity_store_data_uploaded, Snackbar.LENGTH_LONG).setAction("Action", null).show(); + } else if (current.getCHECKOUT_STATUS().equalsIgnoreCase(CommonString.KEY_C)) { + + Snackbar.make(v, R.string.title_store_list_activity_store_already_checkout, Snackbar.LENGTH_LONG).setAction("Action", null).show(); + + } else if (current.getUPLOAD_STATUS().equalsIgnoreCase(CommonString.KEY_P)) { + + Snackbar.make(v, R.string.title_store_list_activity_store_again_uploaded, Snackbar.LENGTH_LONG).setAction("Action", null).show(); + } else if (current.getUPLOAD_STATUS().equalsIgnoreCase(CommonString.KEY_L)) { + Snackbar.make(v, R.string.title_store_list_activity_store_closed, Snackbar.LENGTH_LONG).setAction("Action", null).show(); + } else { + + // PUT IN PREFERENCES + editor = preferences.edit(); + editor.putString(CommonString.KEY_STORE_ID, current.getSTORE_ID()); + editor.putString(CommonString.KEY_STORE_NAME, current.getSTORE_NAME()); + editor.putString(CommonString.KEY_VISIT_DATE, current.getVISIT_DATE()); + editor.putString(CommonString.KEY_CAMERA_ALLOW, current.getCAMERA_ALLOW()); + editor.putString(CommonString.KEY_CHECKOUT_STATUS, current.getCHECKOUT_STATUS()); + editor.putString(CommonString.KEY_CLASS_ID, current.getCLASS_ID()); + editor.putString(CommonString.KEY_EMP_ID, current.getEMP_ID()); + editor.putString(CommonString.KEY_GEO_TAG, current.getGEO_TAG()); + editor.putString(CommonString.KEY_KEYACCOUNT_ID, current.getKEYACCOUNT_ID()); + editor.putString(CommonString.KEY_STORETYPE_ID, current.getSTORETYPE_ID()); + editor.putString(CommonString.KEY_UPLOAD_STATUS, current.getUPLOAD_STATUS()); + editor.commit(); + + // showMyDialog(store_id, current.getSTORE_NAME(), "Yes", current.getVISIT_DATE(), current.getCHECKOUT_STATUS()); + + if (!setcheckedmenthod(store_id)) { + boolean enteryflag = true; + if (coverage.size() > 0) { + int i; + for (i = 0; i < coverage.size(); i++) { + + if (coverage.get(i).getInTime() != null) { + + if (coverage.get(i).getOutTime() == null) { + if (!store_id.equals(coverage.get(i).getStoreId())) { + Snackbar.make(v, R.string.title_store_list_checkout_current, Snackbar.LENGTH_SHORT).setAction("Action", null).show(); + enteryflag = false; + } + break; + } + } + } + } + + if (enteryflag) { + showMyDialog(store_id, current.getSTORE_NAME(), "Yes", current.getVISIT_DATE(), current.getCHECKOUT_STATUS()); + } + } else { + Snackbar.make(v, R.string.title_store_list_checkout_Already_filled, Snackbar.LENGTH_SHORT).setAction("Action", null).show(); + } + } + } + }); + } + + @Override + public int getItemCount() { + return data.size(); + } + + class MyViewHolder extends RecyclerView.ViewHolder { + + TextView txt, address; + ImageView icon; + RelativeLayout relativelayout; + ImageView imageview; + Button chkbtn; + + public MyViewHolder(View itemView) { + super(itemView); + txt = (TextView) itemView.findViewById(R.id.storelistviewxml_storename); + address = (TextView) itemView.findViewById(R.id.storelistviewxml_storeaddress); + + relativelayout = (RelativeLayout) itemView.findViewById(R.id.storenamelistview_layout); + imageview = (ImageView) itemView.findViewById(R.id.imageView2); + + chkbtn = (Button) itemView.findViewById(R.id.chkout); + + } + } + + } + + + void showMyDialog(final String storeCd, final String storeName, final String status, final String visitDate, final String checkout_status) { + dialog = new Dialog(this); + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + dialog.setContentView(R.layout.dialogbox); + + RadioGroup radioGroup = (RadioGroup) dialog.findViewById(R.id.radiogrpvisit); + + radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + // find which radio button is selected + if (checkedId == R.id.yes) { + + Intent in = new Intent(StoreListActivity.this, StoreimageActivity.class); + startActivity(in); + + overridePendingTransition(R.anim.activity_in, R.anim.activity_out); + + dialog.cancel(); + + } else if (checkedId == R.id.no) { + + dialog.cancel(); + + if (checkout_status.equals(CommonString.KEY_INVALID) || checkout_status.equals(CommonString.KEY_VALID)) { + AlertDialog.Builder builder = new AlertDialog.Builder(StoreListActivity.this); + builder.setMessage(CommonString.DATA_DELETE_ALERT_MESSAGE) + .setCancelable(false) + .setPositiveButton("Yes", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, + int id) { + + + + /*Intent in = new Intent(StoreListActivity.this, NonWorkingReason.class); + startActivity(in);*/ + + } + }) + .setNegativeButton("No", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, + int id) { + + + dialog.cancel(); + } + }); + AlertDialog alert = builder.create(); + + alert.show(); + } else { + + + + + /* Intent in = new Intent(StoreListActivity.this, NonWorkingReason.class); + startActivity(in);*/ + } + + } + } + + }); + + + dialog.show(); + } + + + public boolean setcheckedmenthod(String store_cd) { + + + for (int i = 0; i < coverage.size(); i++) { + if (store_cd.equals(coverage.get(i).getStoreId())) { + if (coverage.get(i).getOutTime() != null) { + result_flag = true; + break; + } + } else { + + result_flag = false; + + } + } + + return result_flag; + } + + } diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/dailyentry/StoreimageActivity.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/dailyentry/StoreimageActivity.java new file mode 100644 index 0000000..46d34ce --- /dev/null +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/dailyentry/StoreimageActivity.java @@ -0,0 +1,381 @@ +package cpm.com.gskmtorange.dailyentry; + +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.location.Location; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.provider.MediaStore; +import android.support.v4.content.ContextCompat; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.util.Log; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.Toast; +import com.google.android.gms.common.ConnectionResult; +import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.location.LocationServices; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; + +import cpm.com.gskmtorange.R; +import cpm.com.gskmtorange.constant.CommonString; +import cpm.com.gskmtorange.Database.GSKOrangeDB; +import cpm.com.gskmtorange.GetterSetter.CoverageBean; + +/** + * Created by ashishc on 31-05-2016. + */ +public class StoreimageActivity extends AppCompatActivity implements View.OnClickListener,GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { + + + ImageView img_cam,img_clicked; + Button btn_save; + + String _pathforcheck,_path,str; + + String store_id,visit_date,username,intime,date; + private SharedPreferences preferences; + AlertDialog alert; + String img_str; + private GSKOrangeDB database; + + String lat,lon; + GoogleApiClient mGoogleApiClient; + ArrayList coverage_list; + + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_storeimage); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + + getSupportActionBar().setHomeButtonEnabled(true); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + img_cam = (ImageView) findViewById(R.id.img_selfie); + img_clicked = (ImageView) findViewById(R.id.img_cam_selfie); + + btn_save = (Button) findViewById(R.id.btn_save_selfie); + + preferences = PreferenceManager.getDefaultSharedPreferences(this); + + store_id = preferences.getString(CommonString.KEY_STORE_ID, null); + + visit_date = preferences.getString(CommonString.KEY_DATE, null); + date = preferences.getString(CommonString.KEY_DATE, null); + username = preferences.getString(CommonString.KEY_USERNAME, null); + + intime = preferences.getString(CommonString.KEY_STORE_IN_TIME, ""); + + str = CommonString.FILE_PATH; + + database = new GSKOrangeDB(this); + database.open(); + + + coverage_list = database.getCoverageData(date); + + img_cam.setOnClickListener(this); + img_clicked.setOnClickListener(this); + btn_save.setOnClickListener(this); + + // Create an instance of GoogleAPIClient. + if (mGoogleApiClient == null) { + mGoogleApiClient = new GoogleApiClient.Builder(this) + .addConnectionCallbacks(this) + .addOnConnectionFailedListener(this) + .addApi(LocationServices.API) + .build(); + } + + if ( Build.VERSION.SDK_INT >= 23 && + ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && + ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + return ; + } + + + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + if(id==android.R.id.home){ + + // NavUtils.navigateUpFromSameTask(this); + finish(); + + overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out); + + } + + return super.onOptionsItemSelected(item); + } + + @Override + public void onBackPressed() { + /*Intent i = new Intent(this, DailyEntryScreen.class); + startActivity(i);*/ + + finish(); + + + overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out); + } + + @Override + public void onClick(View v) { + + int id = v.getId(); + + switch (id){ + + case R.id.img_cam_selfie: + + _pathforcheck = store_id + "Store" + + "Image" + visit_date.replace("/","") + getCurrentTime().replace(":","")+".jpg"; + + _path = CommonString.FILE_PATH + _pathforcheck; + + intime = getCurrentTime(); + + startCameraActivity(); + + break; + + case R.id.btn_save_selfie: + + if (img_str !=null) { + + AlertDialog.Builder builder = new AlertDialog.Builder( + StoreimageActivity.this); + builder.setMessage("Do you want to save the data ") + .setCancelable(false) + .setPositiveButton("OK", + new DialogInterface.OnClickListener() { + public void onClick( + DialogInterface dialog, + int id) { + + alert.getButton( + AlertDialog.BUTTON_POSITIVE) + .setEnabled(false); + + String status ="INVALID"; + + + CoverageBean cdata = new CoverageBean(); + cdata.setStoreId(store_id); + cdata.setVisitDate(visit_date); + cdata.setUserId(username); + cdata.setInTime(intime); + cdata.setReason(""); + cdata.setReasonid("0"); + cdata.setLatitude(lat); + cdata.setLongitude(lon); + cdata.setImage(img_str); + cdata.setRemark(""); + cdata.setStatus(CommonString.KEY_CHECK_IN); + + database.InsertCoverageData(cdata); + + database.updateCheckoutStatus(store_id, status); + + /* SharedPreferences.Editor editor = preferences.edit(); + + editor.putString(CommonString.KEY_STOREVISITED_STATUS, ""); + editor.putString(CommonString.KEY_STORE_IN_TIME, ""); + + editor.commit();*/ + + + /* Intent in=new Intent(StoreimageActivity.this,StoreEntry.class); + startActivity(in); + + + + finish();*/ + } + }) + .setNegativeButton("Cancel", + new DialogInterface.OnClickListener() { + public void onClick( + DialogInterface dialog, + int id) { + dialog.cancel(); + } + }); + + alert = builder.create(); + alert.show(); + + } + else { + Toast.makeText(getApplicationContext(), + "Please click the image", Toast.LENGTH_SHORT).show(); + + } + + break; + + } + + } + + protected void startCameraActivity() { + + try { + /*Log.i("MakeMachine", "startCameraActivity()"); + File file = new File(_path); + Uri outputFileUri = Uri.fromFile(file); + + Intent intent = new Intent( + MediaStore.ACTION_IMAGE_CAPTURE); + intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); + + startActivityForResult(intent, 0);*/ + + Log.i("MakeMachine", "startCameraActivity()"); + File file = new File(_path); + Uri outputFileUri = Uri.fromFile(file); + + String defaultCameraPackage=""; + final PackageManager packageManager = getPackageManager(); + List list = packageManager.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES); + for (int n=0;n= Build.VERSION_CODES.KITKAT) { + if (list.get(n).loadLabel(packageManager).toString().equalsIgnoreCase("Camera")) { + defaultCameraPackage = list.get(n).packageName; + break; + } + } else { + if (list.get(n).loadLabel(packageManager).toString().equalsIgnoreCase("Gallery")) { + defaultCameraPackage = list.get(n).packageName; + break; + } + } + } + + } + + Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); + intent.setPackage(defaultCameraPackage); + startActivityForResult(intent, 0); + + + } catch (Exception e) { + + e.printStackTrace(); + } + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + + Log.i("MakeMachine", "resultCode: " + resultCode); + switch (resultCode) { + case 0: + Log.i("MakeMachine", "User cancelled"); + break; + + case -1: + + if (_pathforcheck != null && !_pathforcheck.equals("")) { + if (new File(str + _pathforcheck).exists()) { + + + Bitmap bmp = BitmapFactory.decodeFile(str + _pathforcheck); + + img_cam.setImageBitmap(bmp); + + img_clicked.setVisibility(View.GONE); + img_cam.setVisibility(View.VISIBLE); + + img_str = _pathforcheck; + _pathforcheck = ""; + + + } + } + + break; + } + + + super.onActivityResult(requestCode, resultCode, data); + } + + + public String getCurrentTime() { + + Calendar m_cal = Calendar.getInstance(); + + SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss:mmm"); + String cdate = formatter.format(m_cal.getTime()); + + /* String intime = m_cal.get(Calendar.HOUR_OF_DAY) + ":" + + m_cal.get(Calendar.MINUTE) + ":" + m_cal.get(Calendar.SECOND);*/ + + return cdate; + + } + + @Override + public void onConnected(Bundle bundle) { + + Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); + if (mLastLocation != null) { + lat = String.valueOf(mLastLocation.getLatitude()); + lon = String.valueOf(mLastLocation.getLongitude()); + } + + } + + @Override + public void onConnectionSuspended(int i) { + + } + + @Override + public void onConnectionFailed(ConnectionResult connectionResult) { + + } + + protected void onStart() { + mGoogleApiClient.connect(); + super.onStart(); + } + + protected void onStop() { + mGoogleApiClient.disconnect(); + super.onStop(); + } + + } diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/dailyentry/T2PComplianceActivity.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/dailyentry/T2PComplianceActivity.java new file mode 100644 index 0000000..4c5ee9b --- /dev/null +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/dailyentry/T2PComplianceActivity.java @@ -0,0 +1,239 @@ +package cpm.com.gskmtorange.dailyentry; + +import android.app.Dialog; +import android.graphics.drawable.ColorDrawable; +import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.Toolbar; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.ProgressBar; +import android.widget.TextView; +import android.widget.ToggleButton; + +import java.util.ArrayList; + +import cpm.com.gskmtorange.Database.GSKOrangeDB; +import cpm.com.gskmtorange.R; +import cpm.com.gskmtorange.xmlGetterSetter.BrandMasterGetterSetter; +import cpm.com.gskmtorange.xmlGetterSetter.GapsChecklistGetterSetter; +import cpm.com.gskmtorange.xmlGetterSetter.SkuMasterGetterSetter; +import cpm.com.gskmtorange.xmlGetterSetter.T2PGetterSetter; + +public class T2PComplianceActivity extends AppCompatActivity { + + GSKOrangeDB db; + ArrayList t2PGetterSetters; + T2PAdapter t2PAdapter; + RecyclerView rec_t2p; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_t2_pcompliance); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + db = new GSKOrangeDB(T2PComplianceActivity.this); + db.open(); + + rec_t2p = (RecyclerView) findViewById(R.id.rec_t2p); + + FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) + .setAction("Action", null).show(); + } + }); + } + + @Override + protected void onResume() { + super.onResume(); + + t2PGetterSetters = db.getT2PDefaultData("1"); + + if(t2PGetterSetters.size()>0){ + rec_t2p.setLayoutManager(new LinearLayoutManager(getApplicationContext())); + t2PAdapter = new T2PAdapter(t2PGetterSetters); + rec_t2p.setAdapter(t2PAdapter); + + } + } + + public class T2PAdapter extends RecyclerView.Adapter { + + private ArrayList list; + + public T2PAdapter(ArrayList t2PList) { + list = t2PList; + } + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.t2p_item_layout, parent, false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(final ViewHolder holder, int position) { + + final T2PGetterSetter mItem = list.get(position); + holder.tv_brand.setText(mItem.getBrand()); + holder.tv_display.setText(mItem.getDisplay().trim()); + + holder.btn_gaps.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + ArrayList gapsChecklist = showGapsDialog(mItem.getDisplay_id()); + if(gapsChecklist.size()>0){ + + } + } + }); + + holder.btn_sku.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showSkuDialog(); + } + }); + + } + + @Override + public int getItemCount() { + return list.size(); + } + + public class ViewHolder extends RecyclerView.ViewHolder { + public final View mView; + public final LinearLayout parentLayout; + public final TextView tv_brand, tv_display; + public final ImageView img_cam, img_remark; + public final Button btn_gaps, btn_sku, btn_ref_img; + + + public ViewHolder(View view) { + super(view); + + mView = view; + + tv_brand = (TextView) mView.findViewById(R.id.tv_brand); + tv_display = (TextView) mView.findViewById(R.id.tv_display); + img_cam = (ImageView) mView.findViewById(R.id.img_cam); + img_remark = (ImageView) mView.findViewById(R.id.img_remark); + btn_gaps = (Button) mView.findViewById(R.id.btn_gaps); + btn_sku = (Button) mView.findViewById(R.id.btn_sku); + btn_ref_img = (Button) mView.findViewById(R.id.btn_ref_image); + parentLayout = (LinearLayout) mView.findViewById(R.id.parent_layout); + + } + + } + } + + public ArrayList showGapsDialog(String display_id){ + ArrayList gapsChecklist = db.getGapsDefaultData(display_id); + + Dialog dialog = new Dialog(T2PComplianceActivity.this); + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); + dialog.setContentView(R.layout.gaps_dialog_layout); + //pb = (ProgressBar) dialog.findViewById(R.id.progressBar1); + RecyclerView rec_gap_checklist = (RecyclerView) dialog.findViewById(R.id.rec_gap_checklist); + rec_gap_checklist.setLayoutManager(new LinearLayoutManager(getApplicationContext())); + GapsAdapter gapAdapter = new GapsAdapter(gapsChecklist); + rec_gap_checklist.setAdapter(gapAdapter); + + //dialog.setCancelable(false); + dialog.show(); + + return gapsChecklist; + } + + public void showSkuDialog(){ + + ArrayList brandList = db.getBrandT2PData("1", "1", "1"); + // ArrayList skuMasterGetterSetterArrayList = db.getSkuT2PData("1", "1", "1",) + + Dialog dialog = new Dialog(T2PComplianceActivity.this); + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); + dialog.setContentView(R.layout.t2p_sku_dialog_layout); + //pb = (ProgressBar) dialog.findViewById(R.id.progressBar1); + //dialog.setCancelable(false); + dialog.show(); + + } + + public class GapsAdapter extends RecyclerView.Adapter { + + private ArrayList list; + + public GapsAdapter(ArrayList gapsPList) { + list = gapsPList; + } + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.gap_checklist_item, parent, false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(final ViewHolder holder, int position) { + + final GapsChecklistGetterSetter mItem = list.get(position); + holder.tv_checklist.setText(mItem.getChecklist()); + + holder.tb_present.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + } + }); + + } + + @Override + public int getItemCount() { + return list.size(); + } + + public class ViewHolder extends RecyclerView.ViewHolder { + public final View mView; + public final LinearLayout parentLayout; + public final TextView tv_checklist; + public final ToggleButton tb_present; + + + public ViewHolder(View view) { + super(view); + + mView = view; + + tv_checklist = (TextView) mView.findViewById(R.id.tv_checklist); + tb_present = (ToggleButton) mView.findViewById(R.id.btn_is_present); + parentLayout = (LinearLayout) mView.findViewById(R.id.parent_layout); + + } + + } + } + +} diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/download/DownloadActivity.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/download/DownloadActivity.java index 13ea84e..94d8263 100644 --- a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/download/DownloadActivity.java +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/download/DownloadActivity.java @@ -27,16 +27,19 @@ import java.net.MalformedURLException; import cpm.com.gskmtorange.Database.GSKOrangeDB; -import cpm.com.gskmtorange.LoginActivity; import cpm.com.gskmtorange.R; import cpm.com.gskmtorange.constant.CommonString; import cpm.com.gskmtorange.xmlGetterSetter.BrandMasterGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.CategoryMasterGetterSetter; +import cpm.com.gskmtorange.xmlGetterSetter.DisplayChecklistMasterGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.DisplayMasterGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.JourneyPlanGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.MAPPINGT2PGetterSetter; +import cpm.com.gskmtorange.xmlGetterSetter.MappingDisplayChecklistGetterSetter; +import cpm.com.gskmtorange.xmlGetterSetter.MappingPromotionGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.MappingStockGetterSetter; +import cpm.com.gskmtorange.xmlGetterSetter.NonWorkingReasonGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.SkuMasterGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.SubCategoryMasterGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.TableBean; @@ -61,6 +64,10 @@ public class DownloadActivity extends AppCompatActivity { DisplayMasterGetterSetter displayMasterGetterSetter; MappingStockGetterSetter mappingStockGetterSetter; MAPPINGT2PGetterSetter mappingt2PGetterSetter; + DisplayChecklistMasterGetterSetter checklistMasterGetterSetter; + MappingDisplayChecklistGetterSetter mappingChecklistGetterSetter; + NonWorkingReasonGetterSetter nonWorkingReasonGetterSetter; + MappingPromotionGetterSetter mappingPromotionGetterSetter; @Override protected void onCreate(Bundle savedInstanceState) { @@ -394,13 +401,149 @@ public class DownloadActivity extends AppCompatActivity { TableBean.setMappingT2p(t2ptable); } } else { - return "MAPPING_T2P"; + //return "MAPPING_T2P"; } data.value = 100; data.name = "MAPPING_T2P Data Download"; } publishProgress(data); + // DISPLAY_CHECKLIST_MASTER + request = new SoapObject(CommonString.NAMESPACE, CommonString.METHOD_NAME_UNIVERSAL_DOWNLOAD); + request.addProperty("UserName", userId); + request.addProperty("Type", "DISPLAY_CHECKLIST_MASTER"); + request.addProperty("cultureid", culture_id); + + envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); + envelope.dotNet = true; + envelope.setOutputSoapObject(request); + + androidHttpTransport = new HttpTransportSE(CommonString.URL); + androidHttpTransport.call(CommonString.SOAP_ACTION_UNIVERSAL, envelope); + + result = (Object) envelope.getResponse(); + + if (result.toString() != null) { + xpp.setInput(new StringReader(result.toString())); + xpp.next(); + eventType = xpp.getEventType(); + checklistMasterGetterSetter = XMLHandlers.mappingDisplayChecklistMasterXMLHandler(xpp, eventType); + if (checklistMasterGetterSetter.getCHECKLIST_ID().size() > 0) { + String checklist_master_table = checklistMasterGetterSetter.getTable_DISPLAY_CHECKLIST_MASTER(); + if (checklist_master_table != null) { + resultHttp = CommonString.KEY_SUCCESS; + TableBean.setDisplayChecklistMaster(checklist_master_table); + } + } else { + return "DISPLAY_CHECKLIST_MASTER"; + } + data.value = 100; + data.name = "DISPLAY_CHECKLIST_MASTER Data Download"; + } + publishProgress(data); + + // MAPPING_DISPLAY_CHECKLIST + request = new SoapObject(CommonString.NAMESPACE, CommonString.METHOD_NAME_UNIVERSAL_DOWNLOAD); + request.addProperty("UserName", userId); + request.addProperty("Type", "MAPPING_DISPLAY_CHECKLIST"); + request.addProperty("cultureid", culture_id); + + envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); + envelope.dotNet = true; + envelope.setOutputSoapObject(request); + + androidHttpTransport = new HttpTransportSE(CommonString.URL); + androidHttpTransport.call(CommonString.SOAP_ACTION_UNIVERSAL, envelope); + + result = (Object) envelope.getResponse(); + + if (result.toString() != null) { + xpp.setInput(new StringReader(result.toString())); + xpp.next(); + eventType = xpp.getEventType(); + mappingChecklistGetterSetter = XMLHandlers.mappingMappingDisplayChecklistXMLHandler(xpp, eventType); + if (mappingChecklistGetterSetter.getCHECKLIST_ID().size() > 0) { + String mapping_display_checklisttable = mappingChecklistGetterSetter.getTable_MAPPING_DISPLAY_CHECKLIST(); + if (mapping_display_checklisttable != null) { + resultHttp = CommonString.KEY_SUCCESS; + TableBean.setMappingDisplayChecklist(mapping_display_checklisttable); + } + } else { + //return "MAPPING_DISPLAY_CHECKLIST"; + } + data.value = 100; + data.name = "MAPPING_DISPLAY_CHECKLIST Data Download"; + } + publishProgress(data); + + + // NON_WORKING_REASON + request = new SoapObject(CommonString.NAMESPACE, CommonString.METHOD_NAME_UNIVERSAL_DOWNLOAD); + request.addProperty("UserName", userId); + request.addProperty("Type", "NON_WORKING_REASON"); + request.addProperty("cultureid", culture_id); + + envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); + envelope.dotNet = true; + envelope.setOutputSoapObject(request); + + androidHttpTransport = new HttpTransportSE(CommonString.URL); + androidHttpTransport.call(CommonString.SOAP_ACTION_UNIVERSAL, envelope); + + result = (Object) envelope.getResponse(); + + if (result.toString() != null) { + xpp.setInput(new StringReader(result.toString())); + xpp.next(); + eventType = xpp.getEventType(); + nonWorkingReasonGetterSetter = XMLHandlers.nonWorkingReasonXMLHandler(xpp, eventType); + if (nonWorkingReasonGetterSetter.getREASON_ID().size() > 0) { + String reasontable = nonWorkingReasonGetterSetter.getTable_NON_WORKING_REASON(); + if (reasontable != null) { + resultHttp = CommonString.KEY_SUCCESS; + TableBean.setNonWorkingReason(reasontable); + } + } else { + return "NON_WORKING_REASON"; + } + data.value = 100; + data.name = "NON_WORKING_REASON Data Download"; + } + publishProgress(data); + + // MAPPING_PROMOTION + request = new SoapObject(CommonString.NAMESPACE, CommonString.METHOD_NAME_UNIVERSAL_DOWNLOAD); + request.addProperty("UserName", userId); + request.addProperty("Type", "MAPPING_PROMOTION"); + request.addProperty("cultureid", culture_id); + + envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); + envelope.dotNet = true; + envelope.setOutputSoapObject(request); + + androidHttpTransport = new HttpTransportSE(CommonString.URL); + androidHttpTransport.call(CommonString.SOAP_ACTION_UNIVERSAL, envelope); + + result = (Object) envelope.getResponse(); + + if (result.toString() != null) { + xpp.setInput(new StringReader(result.toString())); + xpp.next(); + eventType = xpp.getEventType(); + mappingPromotionGetterSetter = XMLHandlers.mappingPromotionXMLHandler(xpp, eventType); + if (mappingPromotionGetterSetter.getSTORE_ID().size() > 0) { + String mapping_promotion_table = mappingPromotionGetterSetter.getTable_MAPPING_PROMOTION(); + if (mapping_promotion_table != null) { + resultHttp = CommonString.KEY_SUCCESS; + TableBean.setMappingPromotion(mapping_promotion_table); + } + } else { + //return "MAPPING_PROMOTION"; + } + data.value = 100; + data.name = "MAPPING_PROMOTION Data Download"; + } + publishProgress(data); db.open(); db.InsertJCP(jcpgettersetter); @@ -412,7 +555,8 @@ public class DownloadActivity extends AppCompatActivity { db.InsertMAPPING_T2P(mappingt2PGetterSetter); db.InsertMappingStock(mappingStockGetterSetter); - + db.InsertDisplayChecklistMaster(checklistMasterGetterSetter); + db.InsertMappingDisplayChecklist(mappingChecklistGetterSetter); } catch (MalformedURLException e) { /*final AlertMessage message = new AlertMessage( diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/gettersetter/CoverageBean.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/gettersetter/CoverageBean.java new file mode 100644 index 0000000..5023fd5 --- /dev/null +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/gettersetter/CoverageBean.java @@ -0,0 +1,223 @@ +package cpm.com.gskmtorange.gettersetter; + +public class CoverageBean +{ + protected int MID; + protected String process_id; + + public String getGEO_TAG() { + return GEO_TAG; + } + + public void setGEO_TAG(String GEO_TAG) { + this.GEO_TAG = GEO_TAG; + } + + protected String GEO_TAG; + public String getProcess_id() { + return process_id; + } + + public void setProcess_id(String process_id) { + this.process_id = process_id; + } + + protected String storeId; + protected String storename; + + public String getStorename() { + return storename; + } + + public void setStorename(String storename) { + this.storename = storename; + } + + protected String Remark; + + public String getRemark() { + return Remark; + } + + public void setRemark(String remark) { + Remark = remark; + } + + protected String userId; + protected String app_version; + protected String image_allow; + + public String getImage_allow() { + return image_allow; + } + + public void setImage_allow(String image_allow) { + this.image_allow = image_allow; + } + + public String getApp_version() { + return app_version; + } + + public void setApp_version(String app_version) { + this.app_version = app_version; + } + + protected String inTime; + + protected String outTime; + + protected String visitDate; + + protected String keycontactId; + + protected String isdDeploy; + + protected String uploadStatus; + + private String latitude; + + private String longitude; + + private String reasonid=""; + + private String sub_reasonId=""; + + public String getSub_reasonId() { + return sub_reasonId; + } + + public void setSub_reasonId(String sub_reasonId) { + this.sub_reasonId = sub_reasonId; + } + + private String reason=""; + + private String status="N"; + + private String image=""; + + + public String getImage() { + return image; + } + + public void setImage(String image) { + this.image = image; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public int getMID() { + return MID; + } + + public void setMID(int mID) { + MID = mID; + } + + public String getStoreId() { + return storeId; + } + + public void setStoreId(String storeId) { + this.storeId = storeId; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getInTime() { + return inTime; + } + + public void setInTime(String inTime) { + this.inTime = inTime; + } + + public String getOutTime() { + return outTime; + } + + public void setOutTime(String outTime) { + this.outTime = outTime; + } + + public String getVisitDate() { + return visitDate; + } + + public void setVisitDate(String visitDate) { + this.visitDate = visitDate; + } + + public String getKeycontactId() { + return keycontactId; + } + + public void setKeycontactId(String keycontactId) { + this.keycontactId = keycontactId; + } + + public String getIsdDeploy() { + return isdDeploy; + } + + public void setIsdDeploy(String isdDeploy) { + this.isdDeploy = isdDeploy; + } + + public String getUploadStatus() { + return uploadStatus; + } + + public void setUploadStatus(String uploadStatus) { + this.uploadStatus = uploadStatus; + } + + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getReasonid() { + return reasonid; + } + + public void setReasonid(String reasonid) { + this.reasonid = reasonid; + } + + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + + +} diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/gettersetter/GeotaggingBeans.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/gettersetter/GeotaggingBeans.java new file mode 100644 index 0000000..4470b5f --- /dev/null +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/gettersetter/GeotaggingBeans.java @@ -0,0 +1,78 @@ +package cpm.com.gskmtorange.gettersetter; + +public class GeotaggingBeans { + + + + public String storeid; + public String url1; + public String url2; + public String status; + public String getStatus() { + return status; + } + public void setStatus(String status) { + this.status = status; + } + + public String url3; + public double Latitude ; + public double Longitude; + + public String getStoreid() { + return storeid; + } + public void setStoreid(String storeid) { + this.storeid = storeid; + } + public double getLatitude() { + return Latitude; + } + public void setLatitude(double d) { + Latitude = d; + } + public double getLongitude() { + return Longitude; + } + public void setLongitude(double d) { + Longitude = d; + } + + + public void setUrl1(String url1) + { + + this.url1=url1; + } + + public String getUrl1() + { + + return url1; + } + + public void setUrl2(String url2) + { + + this.url2=url2; + } + + public String getUrl2() + { + + return url2; + } + + public void setUrl3(String url3) + { + + this.url3=url3; + } + + public String getUrl3() + { + + return url3; + } + +} diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/messgae/AlertMessage.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/messgae/AlertMessage.java new file mode 100644 index 0000000..9820940 --- /dev/null +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/messgae/AlertMessage.java @@ -0,0 +1,112 @@ +package cpm.com.gskmtorange.messgae; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; + +import cpm.com.gskmtorange.GeoTag.GeoTagStoreList; + +/** + * Created by ashishc on 03-01-2017. + */ + +public class AlertMessage { + + public static final String MESSAGE_ERROR = "Network Error , "; + + public static final String MESSAGE_DATA_NOT = "Data Not Uploaded , "; + + private Exception exception; + String value; + private String data, condition,exceptionString; + private Activity activity; + private String error; + + + + public AlertMessage(Activity activity, String data, String condition, + Exception exception) { + this.activity = activity; + this.data = data; + this.condition = condition; + this.exception = exception; + } + + public AlertMessage(Activity activity, String data, String condition, + String exception, String a) { + this.activity = activity; + this.data = data; + this.condition = condition; + this.exceptionString = exception; + this.error = a; + } + + + public void showMessage() { + + if (condition.equals("success")) { + + ShowAlert1(data); + } + else if(condition.equals("failure")) + { + ShowAlertSocket(data); + } + + + + } + + public void ShowAlert1(String str) { + + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setTitle("Parinaam"); + builder.setMessage(str).setCancelable(false) + .setPositiveButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + + Intent i = new Intent(activity, GeoTagStoreList.class); + activity.startActivity(i); + + activity.finish(); + + } + }); + AlertDialog alert = builder.create(); + alert.show(); + + } + + + public void ShowAlertSocket(String str) { + + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setTitle("Parinaam"); + builder.setMessage(str).setCancelable(false) + .setPositiveButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + + Intent i = new Intent(activity, GeoTagStoreList.class); + activity.startActivity(i); + + activity.finish(); + + } + }); + AlertDialog alert = builder.create(); + alert.show(); + + } + + + + + + +} + + + + + diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/upload/Base64.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/upload/Base64.java new file mode 100644 index 0000000..0853330 --- /dev/null +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/upload/Base64.java @@ -0,0 +1,1810 @@ +package cpm.com.gskmtorange.upload; + + +/** + *

Encodes and decodes to and from Base64 notation.

+ *

Homepage: http://iharder.net/base64.

+ * + *

The options parameter, which appears in a few places, is used to pass + * several pieces of information to the encoder. In the "higher level" methods such as + * encodeBytes( bytes, options ) the options parameter can be used to indicate such + * things as first gzipping the bytes before encoding them, not inserting linefeeds + * (though that breaks strict Base64 compatibility), and encoding using the URL-safe + * and Ordered dialects.

+ * + *

The constants defined in Base64 can be OR-ed together to combine options, so you + * might make a call like this:

+ * + * String encoded = Base64.encodeBytes( mybytes, Base64.GZIP | Base64.DONT_BREAK_LINES ); + * + *

to compress the data before encoding it and then making the output have no newline characters.

+ * + * + *

+ * Change Log: + *

+ *
    + *
  • v2.2.2 - Fixed encodeFileToFile and decodeFileToFile to use the + * Base64.InputStream class to encode and decode on the fly which uses + * less memory than encoding/decoding an entire file into memory before writing.
  • + *
  • v2.2.1 - Fixed bug using URL_SAFE and ORDERED encodings. Fixed bug + * when using very small files (~< 40 bytes).
  • + *
  • v2.2 - Added some helper methods for encoding/decoding directly from + * one file to the next. Also added a main() method to support command line + * encoding/decoding from one file to the next. Also added these Base64 dialects: + *
      + *
    1. The default is RFC3548 format.
    2. + *
    3. Calling Base64.setFormat(Base64.BASE64_FORMAT.URLSAFE_FORMAT) generates + * URL and file name friendly format as described in Section 4 of RFC3548. + * http://www.faqs.org/rfcs/rfc3548.html
    4. + *
    5. Calling Base64.setFormat(Base64.BASE64_FORMAT.ORDERED_FORMAT) generates + * URL and file name friendly format that preserves lexical ordering as described + * in http://www.faqs.org/qa/rfcc-1940.html
    6. + *
    + * Special thanks to Jim Kellerman at http://www.powerset.com/ + * for contributing the new Base64 dialects. + *
  • + * + *
  • v2.1 - Cleaned up javadoc comments and unused variables and methods. Added + * some convenience methods for reading and writing to and from files.
  • + *
  • v2.0.2 - Now specifies UTF-8 encoding in places where the code fails on systems + * with other encodings (like EBCDIC).
  • + *
  • v2.0.1 - Fixed an error when decoding a single byte, that is, when the + * encoded data was a single byte.
  • + *
  • v2.0 - I got rid of methods that used booleans to set options. + * Now everything is more consolidated and cleaner. The code now detects + * when data that's being decoded is gzip-compressed and will decompress it + * automatically. Generally things are cleaner. You'll probably have to + * change some method calls that you were making to support the new + * options format (ints that you "OR" together).
  • + *
  • v1.5.1 - Fixed bug when decompressing and decoding to a + * byte[] using decode( String s, boolean gzipCompressed ). + * Added the ability to "suspend" encoding in the Output Stream so + * you can turn on and off the encoding if you need to embed base64 + * data in an otherwise "normal" stream (like an XML file).
  • + *
  • v1.5 - Output stream pases on flush() command but doesn't do anything itself. + * This helps when using GZIP streams. + * Added the ability to GZip-compress objects before encoding them.
  • + *
  • v1.4 - Added helper methods to read/write files.
  • + *
  • v1.3.6 - Fixed OutputStream.flush() so that 'position' is reset.
  • + *
  • v1.3.5 - Added flag to turn on and off line breaks. Fixed bug in input stream + * where last buffer being read, if not completely full, was not returned.
  • + *
  • v1.3.4 - Fixed when "improperly padded stream" error was thrown at the wrong time.
  • + *
  • v1.3.3 - Fixed I/O streams which were totally messed up.
  • + *
+ * + *

+ * I am placing this code in the Public Domain. Do with it as you will. + * This software comes with no guarantees or warranties but with + * plenty of well-wishing instead! + * Please visit http://iharder.net/base64 + * periodically to check for updates or to contribute improvements. + *

+ * + * @author Robert Harder + * @author rob@iharder.net + * @version 2.2.2 + */ +public class Base64 +{ + +/* ******** P U B L I C F I E L D S ******** */ + + + /** No options specified. Value is zero. */ + public final static int NO_OPTIONS = 0; + + /** Specify encoding. */ + public final static int ENCODE = 1; + + + /** Specify decoding. */ + public final static int DECODE = 0; + + + /** Specify that data should be gzip-compressed. */ + public final static int GZIP = 2; + + + /** Don't break lines when encoding (violates strict Base64 specification) */ + public final static int DONT_BREAK_LINES = 8; + + /** + * Encode using Base64-like encoding that is URL- and Filename-safe as described + * in Section 4 of RFC3548: + * http://www.faqs.org/rfcs/rfc3548.html. + * It is important to note that data encoded this way is not officially valid Base64, + * or at the very least should not be called Base64 without also specifying that is + * was encoded using the URL- and Filename-safe dialect. + */ + public final static int URL_SAFE = 16; + + + /** + * Encode using the special "ordered" dialect of Base64 described here: + * http://www.faqs.org/qa/rfcc-1940.html. + */ + public final static int ORDERED = 32; + + +/* ******** P R I V A T E F I E L D S ******** */ + + + /** Maximum line length (76) of Base64 output. */ + private final static int MAX_LINE_LENGTH = 76; + + + /** The equals sign (=) as a byte. */ + private final static byte EQUALS_SIGN = (byte)'='; + + + /** The new line character (\n) as a byte. */ + private final static byte NEW_LINE = (byte)'\n'; + + + /** Preferred encoding. */ + private final static String PREFERRED_ENCODING = "UTF-8"; + + + // I think I end up not using the BAD_ENCODING indicator. + //private final static byte BAD_ENCODING = -9; // Indicates error in encoding + private final static byte WHITE_SPACE_ENC = -5; // Indicates white space in encoding + private final static byte EQUALS_SIGN_ENC = -1; // Indicates equals sign in encoding + + +/* ******** S T A N D A R D B A S E 6 4 A L P H A B E T ******** */ + + /** The 64 valid Base64 values. */ + //private final static byte[] ALPHABET; + /* Host platform me be something funny like EBCDIC, so we hardcode these values. */ + private final static byte[] _STANDARD_ALPHABET = + { + (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G', + (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N', + (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', + (byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z', + (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g', + (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n', + (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', + (byte)'v', (byte)'w', (byte)'x', (byte)'y', (byte)'z', + (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', + (byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'+', (byte)'/' + }; + + + /** + * Translates a Base64 value to either its 6-bit reconstruction value + * or a negative number indicating some other meaning. + **/ + private final static byte[] _STANDARD_DECODABET = + { + -9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 0 - 8 + -5,-5, // Whitespace: Tab and Linefeed + -9,-9, // Decimal 11 - 12 + -5, // Whitespace: Carriage Return + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 14 - 26 + -9,-9,-9,-9,-9, // Decimal 27 - 31 + -5, // Whitespace: Space + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 33 - 42 + 62, // Plus sign at decimal 43 + -9,-9,-9, // Decimal 44 - 46 + 63, // Slash at decimal 47 + 52,53,54,55,56,57,58,59,60,61, // Numbers zero through nine + -9,-9,-9, // Decimal 58 - 60 + -1, // Equals sign at decimal 61 + -9,-9,-9, // Decimal 62 - 64 + 0,1,2,3,4,5,6,7,8,9,10,11,12,13, // Letters 'A' through 'N' + 14,15,16,17,18,19,20,21,22,23,24,25, // Letters 'O' through 'Z' + -9,-9,-9,-9,-9,-9, // Decimal 91 - 96 + 26,27,28,29,30,31,32,33,34,35,36,37,38, // Letters 'a' through 'm' + 39,40,41,42,43,44,45,46,47,48,49,50,51, // Letters 'n' through 'z' + -9,-9,-9,-9 // Decimal 123 - 126 + /*,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 127 - 139 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 166 - 178 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 179 - 191 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 192 - 204 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 */ + }; + + +/* ******** U R L S A F E B A S E 6 4 A L P H A B E T ******** */ + + /** + * Used in the URL- and Filename-safe dialect described in Section 4 of RFC3548: + * http://www.faqs.org/rfcs/rfc3548.html. + * Notice that the last two bytes become "hyphen" and "underscore" instead of "plus" and "slash." + */ + private final static byte[] _URL_SAFE_ALPHABET = + { + (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G', + (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N', + (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', + (byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z', + (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g', + (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n', + (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', + (byte)'v', (byte)'w', (byte)'x', (byte)'y', (byte)'z', + (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', + (byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'-', (byte)'_' + }; + + /** + * Used in decoding URL- and Filename-safe dialects of Base64. + */ + private final static byte[] _URL_SAFE_DECODABET = + { + -9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 0 - 8 + -5,-5, // Whitespace: Tab and Linefeed + -9,-9, // Decimal 11 - 12 + -5, // Whitespace: Carriage Return + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 14 - 26 + -9,-9,-9,-9,-9, // Decimal 27 - 31 + -5, // Whitespace: Space + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 33 - 42 + -9, // Plus sign at decimal 43 + -9, // Decimal 44 + 62, // Minus sign at decimal 45 + -9, // Decimal 46 + -9, // Slash at decimal 47 + 52,53,54,55,56,57,58,59,60,61, // Numbers zero through nine + -9,-9,-9, // Decimal 58 - 60 + -1, // Equals sign at decimal 61 + -9,-9,-9, // Decimal 62 - 64 + 0,1,2,3,4,5,6,7,8,9,10,11,12,13, // Letters 'A' through 'N' + 14,15,16,17,18,19,20,21,22,23,24,25, // Letters 'O' through 'Z' + -9,-9,-9,-9, // Decimal 91 - 94 + 63, // Underscore at decimal 95 + -9, // Decimal 96 + 26,27,28,29,30,31,32,33,34,35,36,37,38, // Letters 'a' through 'm' + 39,40,41,42,43,44,45,46,47,48,49,50,51, // Letters 'n' through 'z' + -9,-9,-9,-9 // Decimal 123 - 126 + /*,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 127 - 139 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 166 - 178 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 179 - 191 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 192 - 204 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 */ + }; + + + +/* ******** O R D E R E D B A S E 6 4 A L P H A B E T ******** */ + + /** + * I don't get the point of this technique, but it is described here: + * http://www.faqs.org/qa/rfcc-1940.html. + */ + private final static byte[] _ORDERED_ALPHABET = + { + (byte)'-', + (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', + (byte)'5', (byte)'6', (byte)'7', (byte)'8', (byte)'9', + (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G', + (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N', + (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', + (byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z', + (byte)'_', + (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g', + (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n', + (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', + (byte)'v', (byte)'w', (byte)'x', (byte)'y', (byte)'z' + }; + + /** + * Used in decoding the "ordered" dialect of Base64. + */ + private final static byte[] _ORDERED_DECODABET = + { + -9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 0 - 8 + -5,-5, // Whitespace: Tab and Linefeed + -9,-9, // Decimal 11 - 12 + -5, // Whitespace: Carriage Return + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 14 - 26 + -9,-9,-9,-9,-9, // Decimal 27 - 31 + -5, // Whitespace: Space + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 33 - 42 + -9, // Plus sign at decimal 43 + -9, // Decimal 44 + 0, // Minus sign at decimal 45 + -9, // Decimal 46 + -9, // Slash at decimal 47 + 1,2,3,4,5,6,7,8,9,10, // Numbers zero through nine + -9,-9,-9, // Decimal 58 - 60 + -1, // Equals sign at decimal 61 + -9,-9,-9, // Decimal 62 - 64 + 11,12,13,14,15,16,17,18,19,20,21,22,23, // Letters 'A' through 'M' + 24,25,26,27,28,29,30,31,32,33,34,35,36, // Letters 'N' through 'Z' + -9,-9,-9,-9, // Decimal 91 - 94 + 37, // Underscore at decimal 95 + -9, // Decimal 96 + 38,39,40,41,42,43,44,45,46,47,48,49,50, // Letters 'a' through 'm' + 51,52,53,54,55,56,57,58,59,60,61,62,63, // Letters 'n' through 'z' + -9,-9,-9,-9 // Decimal 123 - 126 + /*,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 127 - 139 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 166 - 178 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 179 - 191 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 192 - 204 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 */ + }; + + +/* ******** D E T E R M I N E W H I C H A L H A B E T ******** */ + + + /** + * Returns one of the _SOMETHING_ALPHABET byte arrays depending on + * the options specified. + * It's possible, though silly, to specify ORDERED and URLSAFE + * in which case one of them will be picked, though there is + * no guarantee as to which one will be picked. + */ + private final static byte[] getAlphabet( int options ) + { + if( (options & URL_SAFE) == URL_SAFE ) return _URL_SAFE_ALPHABET; + else if( (options & ORDERED) == ORDERED ) return _ORDERED_ALPHABET; + else return _STANDARD_ALPHABET; + + } // end getAlphabet + + + /** + * Returns one of the _SOMETHING_DECODABET byte arrays depending on + * the options specified. + * It's possible, though silly, to specify ORDERED and URL_SAFE + * in which case one of them will be picked, though there is + * no guarantee as to which one will be picked. + */ + private final static byte[] getDecodabet( int options ) + { + if( (options & URL_SAFE) == URL_SAFE ) return _URL_SAFE_DECODABET; + else if( (options & ORDERED) == ORDERED ) return _ORDERED_DECODABET; + else return _STANDARD_DECODABET; + + } // end getAlphabet + + + + /** Defeats instantiation. */ + private Base64(){} + + + /** + * Encodes or decodes two files from the command line; + * feel free to delete this method (in fact you probably should) + * if you're embedding this code into a larger program. + */ + public final static void main( String[] args ) + { + if( args.length < 3 ){ + usage("Not enough arguments."); + } // end if: args.length < 3 + else { + String flag = args[0]; + String infile = args[1]; + String outfile = args[2]; + if( flag.equals( "-e" ) ){ + Base64.encodeFileToFile( infile, outfile ); + } // end if: encode + else if( flag.equals( "-d" ) ) { + Base64.decodeFileToFile( infile, outfile ); + } // end else if: decode + else { + usage( "Unknown flag: " + flag ); + } // end else + } // end else + } // end main + + /** + * Prints command line usage. + * + * @param msg A message to include with usage info. + */ + private final static void usage( String msg ) + { + System.err.println( msg ); + System.err.println( "Usage: java Base64 -e|-d inputfile outputfile" ); + } // end usage + + +/* ******** E N C O D I N G M E T H O D S ******** */ + + + /** + * Encodes up to the first three bytes of array threeBytes + * and returns a four-byte array in Base64 notation. + * The actual number of significant bytes in your array is + * given by numSigBytes. + * The array threeBytes needs only be as big as + * numSigBytes. + * Code can reuse a byte array by passing a four-byte array as b4. + * + * @param b4 A reusable byte array to reduce array instantiation + * @param threeBytes the array to convert + * @param numSigBytes the number of significant bytes in your array + * @return four byte array in Base64 notation. + * @since 1.5.1 + */ + private static byte[] encode3to4( byte[] b4, byte[] threeBytes, int numSigBytes, int options ) + { + encode3to4( threeBytes, 0, numSigBytes, b4, 0, options ); + return b4; + } // end encode3to4 + + + /** + *

Encodes up to three bytes of the array source + * and writes the resulting four Base64 bytes to destination. + * The source and destination arrays can be manipulated + * anywhere along their length by specifying + * srcOffset and destOffset. + * This method does not check to make sure your arrays + * are large enough to accomodate srcOffset + 3 for + * the source array or destOffset + 4 for + * the destination array. + * The actual number of significant bytes in your array is + * given by numSigBytes.

+ *

This is the lowest level of the encoding methods with + * all possible parameters.

+ * + * @param source the array to convert + * @param srcOffset the index where conversion begins + * @param numSigBytes the number of significant bytes in your array + * @param destination the array to hold the conversion + * @param destOffset the index where output will be put + * @return the destination array + * @since 1.3 + */ + private static byte[] encode3to4( + byte[] source, int srcOffset, int numSigBytes, + byte[] destination, int destOffset, int options ) + { + byte[] ALPHABET = getAlphabet( options ); + + // 1 2 3 + // 01234567890123456789012345678901 Bit position + // --------000000001111111122222222 Array position from threeBytes + // --------| || || || | Six bit groups to index ALPHABET + // >>18 >>12 >> 6 >> 0 Right shift necessary + // 0x3f 0x3f 0x3f Additional AND + + // Create buffer with zero-padding if there are only one or two + // significant bytes passed in the array. + // We have to shift left 24 in order to flush out the 1's that appear + // when Java treats a value as negative that is cast from a byte to an int. + int inBuff = ( numSigBytes > 0 ? ((source[ srcOffset ] << 24) >>> 8) : 0 ) + | ( numSigBytes > 1 ? ((source[ srcOffset + 1 ] << 24) >>> 16) : 0 ) + | ( numSigBytes > 2 ? ((source[ srcOffset + 2 ] << 24) >>> 24) : 0 ); + + switch( numSigBytes ) + { + case 3: + destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ]; + destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ]; + destination[ destOffset + 2 ] = ALPHABET[ (inBuff >>> 6) & 0x3f ]; + destination[ destOffset + 3 ] = ALPHABET[ (inBuff ) & 0x3f ]; + return destination; + + case 2: + destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ]; + destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ]; + destination[ destOffset + 2 ] = ALPHABET[ (inBuff >>> 6) & 0x3f ]; + destination[ destOffset + 3 ] = EQUALS_SIGN; + return destination; + + case 1: + destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ]; + destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ]; + destination[ destOffset + 2 ] = EQUALS_SIGN; + destination[ destOffset + 3 ] = EQUALS_SIGN; + return destination; + + default: + return destination; + } // end switch + } // end encode3to4 + + + + /** + * Serializes an object and returns the Base64-encoded + * version of that serialized object. If the object + * cannot be serialized or there is another error, + * the method will return null. + * The object is not GZip-compressed before being encoded. + * + * @param serializableObject The object to encode + * @return The Base64-encoded object + * @since 1.4 + */ + public static String encodeObject( java.io.Serializable serializableObject ) + { + return encodeObject( serializableObject, NO_OPTIONS ); + } // end encodeObject + + + + /** + * Serializes an object and returns the Base64-encoded + * version of that serialized object. If the object + * cannot be serialized or there is another error, + * the method will return null. + *

+ * Valid options:

+		 *	 GZIP: gzip-compresses object before encoding it.
+		 *	 DONT_BREAK_LINES: don't break lines at 76 characters
+		 *		 Note: Technically, this makes your encoding non-compliant.
+		 * 
+ *

+ * Example: encodeObject( myObj, Base64.GZIP ) or + *

+ * Example: encodeObject( myObj, Base64.GZIP | Base64.DONT_BREAK_LINES ) + * + * @param serializableObject The object to encode + * @param options Specified options + * @return The Base64-encoded object + * @see Base64#GZIP + * @see Base64#DONT_BREAK_LINES + * @since 2.0 + */ + public static String encodeObject( java.io.Serializable serializableObject, int options ) + { + // Streams + java.io.ByteArrayOutputStream baos = null; + java.io.OutputStream b64os = null; + java.io.ObjectOutputStream oos = null; + java.util.zip.GZIPOutputStream gzos = null; + + // Isolate options + int gzip = (options & GZIP); + int dontBreakLines = (options & DONT_BREAK_LINES); + + try + { + // ObjectOutputStream -> (GZIP) -> Base64 -> ByteArrayOutputStream + baos = new java.io.ByteArrayOutputStream(); + b64os = new Base64.OutputStream( baos, ENCODE | options ); + + // GZip? + if( gzip == GZIP ) + { + gzos = new java.util.zip.GZIPOutputStream( b64os ); + oos = new java.io.ObjectOutputStream( gzos ); + } // end if: gzip + else + oos = new java.io.ObjectOutputStream( b64os ); + + oos.writeObject( serializableObject ); + } // end try + catch( java.io.IOException e ) + { + e.printStackTrace(); + return null; + } // end catch + finally + { + try{ oos.close(); } catch( Exception e ){} + try{ gzos.close(); } catch( Exception e ){} + try{ b64os.close(); } catch( Exception e ){} + try{ baos.close(); } catch( Exception e ){} + } // end finally + + // Return value according to relevant encoding. + try + { + return new String( baos.toByteArray(), PREFERRED_ENCODING ); + } // end try + catch (java.io.UnsupportedEncodingException uue) + { + return new String( baos.toByteArray() ); + } // end catch + + } // end encode + + + + /** + * Encodes a byte array into Base64 notation. + * Does not GZip-compress data. + * + * @param source The data to convert + * @since 1.4 + */ + public static String encodeBytes( byte[] source ) + { + return encodeBytes( source, 0, source.length, NO_OPTIONS ); + } // end encodeBytes + + + + /** + * Encodes a byte array into Base64 notation. + *

+ * Valid options:

+		 *	 GZIP: gzip-compresses object before encoding it.
+		 *	 DONT_BREAK_LINES: don't break lines at 76 characters
+		 *		 Note: Technically, this makes your encoding non-compliant.
+		 * 
+ *

+ * Example: encodeBytes( myData, Base64.GZIP ) or + *

+ * Example: encodeBytes( myData, Base64.GZIP | Base64.DONT_BREAK_LINES ) + * + * + * @param source The data to convert + * @param options Specified options + * @see Base64#GZIP + * @see Base64#DONT_BREAK_LINES + * @since 2.0 + */ + public static String encodeBytes( byte[] source, int options ) + { + return encodeBytes( source, 0, source.length, options ); + } // end encodeBytes + + + /** + * Encodes a byte array into Base64 notation. + * Does not GZip-compress data. + * + * @param source The data to convert + * @param off Offset in array where conversion should begin + * @param len Length of data to convert + * @since 1.4 + */ + public static String encodeBytes( byte[] source, int off, int len ) + { + return encodeBytes( source, off, len, NO_OPTIONS ); + } // end encodeBytes + + + + /** + * Encodes a byte array into Base64 notation. + *

+ * Valid options:

+		 *	 GZIP: gzip-compresses object before encoding it.
+		 *	 DONT_BREAK_LINES: don't break lines at 76 characters
+		 *		 Note: Technically, this makes your encoding non-compliant.
+		 * 
+ *

+ * Example: encodeBytes( myData, Base64.GZIP ) or + *

+ * Example: encodeBytes( myData, Base64.GZIP | Base64.DONT_BREAK_LINES ) + * + * + * @param source The data to convert + * @param off Offset in array where conversion should begin + * @param len Length of data to convert + * @param options Specified options + * @param options alphabet type is pulled from this (standard, url-safe, ordered) + * @see Base64#GZIP + * @see Base64#DONT_BREAK_LINES + * @since 2.0 + */ + public static String encodeBytes( byte[] source, int off, int len, int options ) + { + // Isolate options + int dontBreakLines = ( options & DONT_BREAK_LINES ); + int gzip = ( options & GZIP ); + + // Compress? + if( gzip == GZIP ) + { + java.io.ByteArrayOutputStream baos = null; + java.util.zip.GZIPOutputStream gzos = null; + Base64.OutputStream b64os = null; + + + try + { + // GZip -> Base64 -> ByteArray + baos = new java.io.ByteArrayOutputStream(); + b64os = new Base64.OutputStream( baos, ENCODE | options ); + gzos = new java.util.zip.GZIPOutputStream( b64os ); + + gzos.write( source, off, len ); + gzos.close(); + } // end try + catch( java.io.IOException e ) + { + e.printStackTrace(); + return null; + } // end catch + finally + { + try{ gzos.close(); } catch( Exception e ){} + try{ b64os.close(); } catch( Exception e ){} + try{ baos.close(); } catch( Exception e ){} + } // end finally + + // Return value according to relevant encoding. + try + { + return new String( baos.toByteArray(), PREFERRED_ENCODING ); + } // end try + catch (java.io.UnsupportedEncodingException uue) + { + return new String( baos.toByteArray() ); + } // end catch + } // end if: compress + + // Else, don't compress. Better not to use streams at all then. + else + { + // Convert option to boolean in way that code likes it. + boolean breakLines = dontBreakLines == 0; + + int len43 = len * 4 / 3; + byte[] outBuff = new byte[ ( len43 ) // Main 4:3 + + ( (len % 3) > 0 ? 4 : 0 ) // Account for padding + + (breakLines ? ( len43 / MAX_LINE_LENGTH ) : 0) ]; // New lines + int d = 0; + int e = 0; + int len2 = len - 2; + int lineLength = 0; + for( ; d < len2; d+=3, e+=4 ) + { + encode3to4( source, d+off, 3, outBuff, e, options ); + + lineLength += 4; + if( breakLines && lineLength == MAX_LINE_LENGTH ) + { + outBuff[e+4] = NEW_LINE; + e++; + lineLength = 0; + } // end if: end of line + } // en dfor: each piece of array + + if( d < len ) + { + encode3to4( source, d+off, len - d, outBuff, e, options ); + e += 4; + } // end if: some padding needed + + + // Return value according to relevant encoding. + try + { + return new String( outBuff, 0, e, PREFERRED_ENCODING ); + } // end try + catch (java.io.UnsupportedEncodingException uue) + { + return new String( outBuff, 0, e ); + } // end catch + + } // end else: don't compress + + } // end encodeBytes + + + + + +/* ******** D E C O D I N G M E T H O D S ******** */ + + + /** + * Decodes four bytes from array source + * and writes the resulting bytes (up to three of them) + * to destination. + * The source and destination arrays can be manipulated + * anywhere along their length by specifying + * srcOffset and destOffset. + * This method does not check to make sure your arrays + * are large enough to accomodate srcOffset + 4 for + * the source array or destOffset + 3 for + * the destination array. + * This method returns the actual number of bytes that + * were converted from the Base64 encoding. + *

This is the lowest level of the decoding methods with + * all possible parameters.

+ * + * + * @param source the array to convert + * @param srcOffset the index where conversion begins + * @param destination the array to hold the conversion + * @param destOffset the index where output will be put + * @param options alphabet type is pulled from this (standard, url-safe, ordered) + * @return the number of decoded bytes converted + * @since 1.3 + */ + private static int decode4to3( byte[] source, int srcOffset, byte[] destination, int destOffset, int options ) + { + byte[] DECODABET = getDecodabet( options ); + + // Example: Dk== + if( source[ srcOffset + 2] == EQUALS_SIGN ) + { + // Two ways to do the same thing. Don't know which way I like best. + //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 ) + // | ( ( DECODABET[ source[ srcOffset + 1] ] << 24 ) >>> 12 ); + int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) + | ( ( DECODABET[ source[ srcOffset + 1] ] & 0xFF ) << 12 ); + + destination[ destOffset ] = (byte)( outBuff >>> 16 ); + return 1; + } + + // Example: DkL= + else if( source[ srcOffset + 3 ] == EQUALS_SIGN ) + { + // Two ways to do the same thing. Don't know which way I like best. + //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 ) + // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 ) + // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 ); + int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) + | ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 ) + | ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6 ); + + destination[ destOffset ] = (byte)( outBuff >>> 16 ); + destination[ destOffset + 1 ] = (byte)( outBuff >>> 8 ); + return 2; + } + + // Example: DkLE + else + { + try{ + // Two ways to do the same thing. Don't know which way I like best. + //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 ) + // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 ) + // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 ) + // | ( ( DECODABET[ source[ srcOffset + 3 ] ] << 24 ) >>> 24 ); + int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) + | ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 ) + | ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6) + | ( ( DECODABET[ source[ srcOffset + 3 ] ] & 0xFF ) ); + + + destination[ destOffset ] = (byte)( outBuff >> 16 ); + destination[ destOffset + 1 ] = (byte)( outBuff >> 8 ); + destination[ destOffset + 2 ] = (byte)( outBuff ); + + return 3; + }catch( Exception e){ + System.out.println(""+source[srcOffset]+ ": " + ( DECODABET[ source[ srcOffset ] ] ) ); + System.out.println(""+source[srcOffset+1]+ ": " + ( DECODABET[ source[ srcOffset + 1 ] ] ) ); + System.out.println(""+source[srcOffset+2]+ ": " + ( DECODABET[ source[ srcOffset + 2 ] ] ) ); + System.out.println(""+source[srcOffset+3]+ ": " + ( DECODABET[ source[ srcOffset + 3 ] ] ) ); + return -1; + } // end catch + } + } // end decodeToBytes + + + + + /** + * Very low-level access to decoding ASCII characters in + * the form of a byte array. Does not support automatically + * gunzipping or any other "fancy" features. + * + * @param source The Base64 encoded data + * @param off The offset of where to begin decoding + * @param len The length of characters to decode + * @return decoded data + * @since 1.3 + */ + public static byte[] decode( byte[] source, int off, int len, int options ) + { + byte[] DECODABET = getDecodabet( options ); + + int len34 = len * 3 / 4; + byte[] outBuff = new byte[ len34 ]; // Upper limit on size of output + int outBuffPosn = 0; + + byte[] b4 = new byte[4]; + int b4Posn = 0; + int i = 0; + byte sbiCrop = 0; + byte sbiDecode = 0; + for( i = off; i < off+len; i++ ) + { + sbiCrop = (byte)(source[i] & 0x7f); // Only the low seven bits + sbiDecode = DECODABET[ sbiCrop ]; + + if( sbiDecode >= WHITE_SPACE_ENC ) // White space, Equals sign or better + { + if( sbiDecode >= EQUALS_SIGN_ENC ) + { + b4[ b4Posn++ ] = sbiCrop; + if( b4Posn > 3 ) + { + outBuffPosn += decode4to3( b4, 0, outBuff, outBuffPosn, options ); + b4Posn = 0; + + // If that was the equals sign, break out of 'for' loop + if( sbiCrop == EQUALS_SIGN ) + break; + } // end if: quartet built + + } // end if: equals sign or better + + } // end if: white space, equals sign or better + else + { + System.err.println( "Bad Base64 input character at " + i + ": " + source[i] + "(decimal)" ); + return null; + } // end else: + } // each input character + + byte[] out = new byte[ outBuffPosn ]; + System.arraycopy( outBuff, 0, out, 0, outBuffPosn ); + return out; + } // end decode + + + + + /** + * Decodes data from Base64 notation, automatically + * detecting gzip-compressed data and decompressing it. + * + * @param s the string to decode + * @return the decoded data + * @since 1.4 + */ + public static byte[] decode( String s ) + { + return decode( s, NO_OPTIONS ); + } + + + /** + * Decodes data from Base64 notation, automatically + * detecting gzip-compressed data and decompressing it. + * + * @param s the string to decode + * @param options encode options such as URL_SAFE + * @return the decoded data + * @since 1.4 + */ + public static byte[] decode( String s, int options ) + { + byte[] bytes; + try + { + bytes = s.getBytes( PREFERRED_ENCODING ); + } // end try + catch( java.io.UnsupportedEncodingException uee ) + { + bytes = s.getBytes(); + } // end catch + // + + // Decode + bytes = decode( bytes, 0, bytes.length, options ); + + + // Check to see if it's gzip-compressed + // GZIP Magic Two-Byte Number: 0x8b1f (35615) + if( bytes != null && bytes.length >= 4 ) + { + + int head = ((int)bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); + if( java.util.zip.GZIPInputStream.GZIP_MAGIC == head ) + { + java.io.ByteArrayInputStream bais = null; + java.util.zip.GZIPInputStream gzis = null; + java.io.ByteArrayOutputStream baos = null; + byte[] buffer = new byte[2048]; + int length = 0; + + try + { + baos = new java.io.ByteArrayOutputStream(); + bais = new java.io.ByteArrayInputStream( bytes ); + gzis = new java.util.zip.GZIPInputStream( bais ); + + while( ( length = gzis.read( buffer ) ) >= 0 ) + { + baos.write(buffer,0,length); + } // end while: reading input + + // No error? Get new bytes. + bytes = baos.toByteArray(); + + } // end try + catch( java.io.IOException e ) + { + // Just return originally-decoded bytes + } // end catch + finally + { + try{ baos.close(); } catch( Exception e ){} + try{ gzis.close(); } catch( Exception e ){} + try{ bais.close(); } catch( Exception e ){} + } // end finally + + } // end if: gzipped + } // end if: bytes.length >= 2 + + return bytes; + } // end decode + + + + + /** + * Attempts to decode Base64 data and deserialize a Java + * Object within. Returns null if there was an error. + * + * @param encodedObject The Base64 data to decode + * @return The decoded and deserialized object + * @since 1.5 + */ + public static Object decodeToObject( String encodedObject ) + { + // Decode and gunzip if necessary + byte[] objBytes = decode( encodedObject ); + + java.io.ByteArrayInputStream bais = null; + java.io.ObjectInputStream ois = null; + Object obj = null; + + try + { + bais = new java.io.ByteArrayInputStream( objBytes ); + ois = new java.io.ObjectInputStream( bais ); + + obj = ois.readObject(); + } // end try + catch( java.io.IOException e ) + { + e.printStackTrace(); + obj = null; + } // end catch + catch( ClassNotFoundException e ) + { + e.printStackTrace(); + obj = null; + } // end catch + finally + { + try{ bais.close(); } catch( Exception e ){} + try{ ois.close(); } catch( Exception e ){} + } // end finally + + return obj; + } // end decodeObject + + + + /** + * Convenience method for encoding data to a file. + * + * @param dataToEncode byte array of data to encode in base64 form + * @param filename Filename for saving encoded data + * @return true if successful, false otherwise + * + * @since 2.1 + */ + public static boolean encodeToFile( byte[] dataToEncode, String filename ) + { + boolean success = false; + Base64.OutputStream bos = null; + try + { + bos = new Base64.OutputStream( + new java.io.FileOutputStream( filename ), Base64.ENCODE ); + bos.write( dataToEncode ); + success = true; + } // end try + catch( java.io.IOException e ) + { + + success = false; + } // end catch: IOException + finally + { + try{ bos.close(); } catch( Exception e ){} + } // end finally + + return success; + } // end encodeToFile + + + /** + * Convenience method for decoding data to a file. + * + * @param dataToDecode Base64-encoded data as a string + * @param filename Filename for saving decoded data + * @return true if successful, false otherwise + * + * @since 2.1 + */ + public static boolean decodeToFile( String dataToDecode, String filename ) + { + boolean success = false; + Base64.OutputStream bos = null; + try + { + bos = new Base64.OutputStream( + new java.io.FileOutputStream( filename ), Base64.DECODE ); + bos.write( dataToDecode.getBytes( PREFERRED_ENCODING ) ); + success = true; + } // end try + catch( java.io.IOException e ) + { + success = false; + } // end catch: IOException + finally + { + try{ bos.close(); } catch( Exception e ){} + } // end finally + + return success; + } // end decodeToFile + + + + + /** + * Convenience method for reading a base64-encoded + * file and decoding it. + * + * @param filename Filename for reading encoded data + * @return decoded byte array or null if unsuccessful + * + * @since 2.1 + */ + public static byte[] decodeFromFile( String filename ) + { + byte[] decodedData = null; + Base64.InputStream bis = null; + try + { + // Set up some useful variables + java.io.File file = new java.io.File( filename ); + byte[] buffer = null; + int length = 0; + int numBytes = 0; + + // Check for size of file + if( file.length() > Integer.MAX_VALUE ) + { + System.err.println( "File is too big for this convenience method (" + file.length() + " bytes)." ); + return null; + } // end if: file too big for int index + buffer = new byte[ (int)file.length() ]; + + // Open a stream + bis = new Base64.InputStream( + new java.io.BufferedInputStream( + new java.io.FileInputStream( file ) ), Base64.DECODE ); + + // Read until done + while( ( numBytes = bis.read( buffer, length, 4096 ) ) >= 0 ) + length += numBytes; + + // Save in a variable to return + decodedData = new byte[ length ]; + System.arraycopy( buffer, 0, decodedData, 0, length ); + + } // end try + catch( java.io.IOException e ) + { + System.err.println( "Error decoding from file " + filename ); + } // end catch: IOException + finally + { + try{ bis.close(); } catch( Exception e) {} + } // end finally + + return decodedData; + } // end decodeFromFile + + + + /** + * Convenience method for reading a binary file + * and base64-encoding it. + * + * @param filename Filename for reading binary data + * @return base64-encoded string or null if unsuccessful + * + * @since 2.1 + */ + public static String encodeFromFile( String filename ) + { + String encodedData = null; + Base64.InputStream bis = null; + try + { + // Set up some useful variables + java.io.File file = new java.io.File( filename ); + byte[] buffer = new byte[ Math.max((int)(file.length() * 1.4),40) ]; // Need max() for math on small files (v2.2.1) + int length = 0; + int numBytes = 0; + + // Open a stream + bis = new Base64.InputStream( + new java.io.BufferedInputStream( + new java.io.FileInputStream( file ) ), Base64.ENCODE ); + + // Read until done + while( ( numBytes = bis.read( buffer, length, 4096 ) ) >= 0 ) + length += numBytes; + + // Save in a variable to return + encodedData = new String( buffer, 0, length, Base64.PREFERRED_ENCODING ); + + } // end try + catch( java.io.IOException e ) + { + System.err.println( "Error encoding from file " + filename ); + } // end catch: IOException + finally + { + try{ bis.close(); } catch( Exception e) {} + } // end finally + + return encodedData; + } // end encodeFromFile + + + + + /** + * Reads infile and encodes it to outfile. + * + * @param infile Input file + * @param outfile Output file + * @return true if the operation is successful + * @since 2.2 + */ + public static boolean encodeFileToFile( String infile, String outfile ) + { + boolean success = false; + java.io.InputStream in = null; + java.io.OutputStream out = null; + try{ + in = new Base64.InputStream( + new java.io.BufferedInputStream( + new java.io.FileInputStream( infile ) ), + Base64.ENCODE ); + out = new java.io.BufferedOutputStream( new java.io.FileOutputStream( outfile ) ); + byte[] buffer = new byte[65536]; // 64K + int read = -1; + while( ( read = in.read(buffer) ) >= 0 ){ + out.write( buffer,0,read ); + } // end while: through file + success = true; + } catch( java.io.IOException exc ){ + exc.printStackTrace(); + } finally{ + try{ in.close(); } catch( Exception exc ){} + try{ out.close(); } catch( Exception exc ){} + } // end finally + + return success; + } // end encodeFileToFile + + + + /** + * Reads infile and decodes it to outfile. + * + * @param infile Input file + * @param outfile Output file + * @return true if the operation is successful + * @since 2.2 + */ + public static boolean decodeFileToFile( String infile, String outfile ) + { + boolean success = false; + java.io.InputStream in = null; + java.io.OutputStream out = null; + try{ + in = new Base64.InputStream( + new java.io.BufferedInputStream( + new java.io.FileInputStream( infile ) ), + Base64.DECODE ); + out = new java.io.BufferedOutputStream( new java.io.FileOutputStream( outfile ) ); + byte[] buffer = new byte[65536]; // 64K + int read = -1; + while( ( read = in.read(buffer) ) >= 0 ){ + out.write( buffer,0,read ); + } // end while: through file + success = true; + } catch( java.io.IOException exc ){ + exc.printStackTrace(); + } finally{ + try{ in.close(); } catch( Exception exc ){} + try{ out.close(); } catch( Exception exc ){} + } // end finally + + return success; + } // end decodeFileToFile + + + /* ******** I N N E R C L A S S I N P U T S T R E A M ******** */ + + + + /** + * A {@link Base64.InputStream} will read data from another + * java.io.InputStream, given in the constructor, + * and encode/decode to/from Base64 notation on the fly. + * + * @see Base64 + * @since 1.3 + */ + public static class InputStream extends java.io.FilterInputStream + { + private boolean encode; // Encoding or decoding + private int position; // Current position in the buffer + private byte[] buffer; // Small buffer holding converted data + private int bufferLength; // Length of buffer (3 or 4) + private int numSigBytes; // Number of meaningful bytes in the buffer + private int lineLength; + private boolean breakLines; // Break lines at less than 80 characters + private int options; // Record options used to create the stream. + private byte[] alphabet; // Local copies to avoid extra method calls + private byte[] decodabet; // Local copies to avoid extra method calls + + + /** + * Constructs a {@link Base64.InputStream} in DECODE mode. + * + * @param in the java.io.InputStream from which to read data. + * @since 1.3 + */ + public InputStream( java.io.InputStream in ) + { + this( in, DECODE ); + } // end constructor + + + /** + * Constructs a {@link Base64.InputStream} in + * either ENCODE or DECODE mode. + *

+ * Valid options:

+				 *	 ENCODE or DECODE: Encode or Decode as data is read.
+				 *	 DONT_BREAK_LINES: don't break lines at 76 characters
+				 *		 (only meaningful when encoding)
+				 *		 Note: Technically, this makes your encoding non-compliant.
+				 * 
+ *

+ * Example: new Base64.InputStream( in, Base64.DECODE ) + * + * + * @param in the java.io.InputStream from which to read data. + * @param options Specified options + * @see Base64#ENCODE + * @see Base64#DECODE + * @see Base64#DONT_BREAK_LINES + * @since 2.0 + */ + public InputStream( java.io.InputStream in, int options ) + { + super( in ); + this.breakLines = (options & DONT_BREAK_LINES) != DONT_BREAK_LINES; + this.encode = (options & ENCODE) == ENCODE; + this.bufferLength = encode ? 4 : 3; + this.buffer = new byte[ bufferLength ]; + this.position = -1; + this.lineLength = 0; + this.options = options; // Record for later, mostly to determine which alphabet to use + this.alphabet = getAlphabet(options); + this.decodabet = getDecodabet(options); + } // end constructor + + /** + * Reads enough of the input stream to convert + * to/from Base64 and returns the next byte. + * + * @return next byte + * @since 1.3 + */ + public int read() throws java.io.IOException + { + // Do we need to get data? + if( position < 0 ) + { + if( encode ) + { + byte[] b3 = new byte[3]; + int numBinaryBytes = 0; + for( int i = 0; i < 3; i++ ) + { + try + { + int b = in.read(); + + // If end of stream, b is -1. + if( b >= 0 ) + { + b3[i] = (byte)b; + numBinaryBytes++; + } // end if: not end of stream + + } // end try: read + catch( java.io.IOException e ) + { + // Only a problem if we got no data at all. + if( i == 0 ) + throw e; + + } // end catch + } // end for: each needed input byte + + if( numBinaryBytes > 0 ) + { + encode3to4( b3, 0, numBinaryBytes, buffer, 0, options ); + position = 0; + numSigBytes = 4; + } // end if: got data + else + { + return -1; + } // end else + } // end if: encoding + + // Else decoding + else + { + byte[] b4 = new byte[4]; + int i = 0; + for( i = 0; i < 4; i++ ) + { + // Read four "meaningful" bytes: + int b = 0; + do{ b = in.read(); } + while( b >= 0 && decodabet[ b & 0x7f ] <= WHITE_SPACE_ENC ); + + if( b < 0 ) + break; // Reads a -1 if end of stream + + b4[i] = (byte)b; + } // end for: each needed input byte + + if( i == 4 ) + { + numSigBytes = decode4to3( b4, 0, buffer, 0, options ); + position = 0; + } // end if: got four characters + else if( i == 0 ){ + return -1; + } // end else if: also padded correctly + else + { + // Must have broken out from above. + throw new java.io.IOException( "Improperly padded Base64 input." ); + } // end + + } // end else: decode + } // end else: get data + + // Got data? + if( position >= 0 ) + { + // End of relevant data? + if( /*!encode &&*/ position >= numSigBytes ) + return -1; + + if( encode && breakLines && lineLength >= MAX_LINE_LENGTH ) + { + lineLength = 0; + return '\n'; + } // end if + else + { + lineLength++; // This isn't important when decoding + // but throwing an extra "if" seems + // just as wasteful. + + int b = buffer[ position++ ]; + + if( position >= bufferLength ) + position = -1; + + return b & 0xFF; // This is how you "cast" a byte that's + // intended to be unsigned. + } // end else + } // end if: position >= 0 + + // Else error + else + { + // When JDK1.4 is more accepted, use an assertion here. + throw new java.io.IOException( "Error in Base64 code reading stream." ); + } // end else + } // end read + + + /** + * Calls {@link #read()} repeatedly until the end of stream + * is reached or len bytes are read. + * Returns number of bytes read into array or -1 if + * end of stream is encountered. + * + * @param dest array to hold values + * @param off offset for array + * @param len max number of bytes to read into array + * @return bytes read into array or -1 if end of stream is encountered. + * @since 1.3 + */ + public int read( byte[] dest, int off, int len ) throws java.io.IOException + { + int i; + int b; + for( i = 0; i < len; i++ ) + { + b = read(); + + //if( b < 0 && i == 0 ) + // return -1; + + if( b >= 0 ) + dest[off + i] = (byte)b; + else if( i == 0 ) + return -1; + else + break; // Out of 'for' loop + } // end for: each byte read + return i; + } // end read + + } // end inner class InputStream + + + + + + + /* ******** I N N E R C L A S S O U T P U T S T R E A M ******** */ + + + + /** + * A {@link Base64.OutputStream} will write data to another + * java.io.OutputStream, given in the constructor, + * and encode/decode to/from Base64 notation on the fly. + * + * @see Base64 + * @since 1.3 + */ + public static class OutputStream extends java.io.FilterOutputStream + { + private boolean encode; + private int position; + private byte[] buffer; + private int bufferLength; + private int lineLength; + private boolean breakLines; + private byte[] b4; // Scratch used in a few places + private boolean suspendEncoding; + private int options; // Record for later + private byte[] alphabet; // Local copies to avoid extra method calls + private byte[] decodabet; // Local copies to avoid extra method calls + + /** + * Constructs a {@link Base64.OutputStream} in ENCODE mode. + * + * @param out the java.io.OutputStream to which data will be written. + * @since 1.3 + */ + public OutputStream( java.io.OutputStream out ) + { + this( out, ENCODE ); + } // end constructor + + + /** + * Constructs a {@link Base64.OutputStream} in + * either ENCODE or DECODE mode. + *

+ * Valid options:

+				 *	 ENCODE or DECODE: Encode or Decode as data is read.
+				 *	 DONT_BREAK_LINES: don't break lines at 76 characters
+				 *		 (only meaningful when encoding)
+				 *		 Note: Technically, this makes your encoding non-compliant.
+				 * 
+ *

+ * Example: new Base64.OutputStream( out, Base64.ENCODE ) + * + * @param out the java.io.OutputStream to which data will be written. + * @param options Specified options. + * @see Base64#ENCODE + * @see Base64#DECODE + * @see Base64#DONT_BREAK_LINES + * @since 1.3 + */ + public OutputStream( java.io.OutputStream out, int options ) + { + super( out ); + this.breakLines = (options & DONT_BREAK_LINES) != DONT_BREAK_LINES; + this.encode = (options & ENCODE) == ENCODE; + this.bufferLength = encode ? 3 : 4; + this.buffer = new byte[ bufferLength ]; + this.position = 0; + this.lineLength = 0; + this.suspendEncoding = false; + this.b4 = new byte[4]; + this.options = options; + this.alphabet = getAlphabet(options); + this.decodabet = getDecodabet(options); + } // end constructor + + + /** + * Writes the byte to the output stream after + * converting to/from Base64 notation. + * When encoding, bytes are buffered three + * at a time before the output stream actually + * gets a write() call. + * When decoding, bytes are buffered four + * at a time. + * + * @param theByte the byte to write + * @since 1.3 + */ + public void write(int theByte) throws java.io.IOException + { + // Encoding suspended? + if( suspendEncoding ) + { + super.out.write( theByte ); + return; + } // end if: supsended + + // Encode? + if( encode ) + { + buffer[ position++ ] = (byte)theByte; + if( position >= bufferLength ) // Enough to encode. + { + out.write( encode3to4( b4, buffer, bufferLength, options ) ); + + lineLength += 4; + if( breakLines && lineLength >= MAX_LINE_LENGTH ) + { + out.write( NEW_LINE ); + lineLength = 0; + } // end if: end of line + + position = 0; + } // end if: enough to output + } // end if: encoding + + // Else, Decoding + else + { + // Meaningful Base64 character? + if( decodabet[ theByte & 0x7f ] > WHITE_SPACE_ENC ) + { + buffer[ position++ ] = (byte)theByte; + if( position >= bufferLength ) // Enough to output. + { + int len = Base64.decode4to3( buffer, 0, b4, 0, options ); + out.write( b4, 0, len ); + //out.write( Base64.decode4to3( buffer ) ); + position = 0; + } // end if: enough to output + } // end if: meaningful base64 character + else if( decodabet[ theByte & 0x7f ] != WHITE_SPACE_ENC ) + { + throw new java.io.IOException( "Invalid character in Base64 data." ); + } // end else: not white space either + } // end else: decoding + } // end write + + + + /** + * Calls {@link #write(int)} repeatedly until len + * bytes are written. + * + * @param theBytes array from which to read bytes + * @param off offset for array + * @param len max number of bytes to read into array + * @since 1.3 + */ + public void write( byte[] theBytes, int off, int len ) throws java.io.IOException + { + // Encoding suspended? + if( suspendEncoding ) + { + super.out.write( theBytes, off, len ); + return; + } // end if: supsended + + for( int i = 0; i < len; i++ ) + { + write( theBytes[ off + i ] ); + } // end for: each byte written + + } // end write + + + + /** + * Method added by PHIL. [Thanks, PHIL. -Rob] + * This pads the buffer without closing the stream. + */ + public void flushBase64() throws java.io.IOException + { + if( position > 0 ) + { + if( encode ) + { + out.write( encode3to4( b4, buffer, position, options ) ); + position = 0; + } // end if: encoding + else + { + throw new java.io.IOException( "Base64 input not properly padded." ); + } // end else: decoding + } // end if: buffer partially full + + } // end flush + + + /** + * Flushes and closes (I think, in the superclass) the stream. + * + * @since 1.3 + */ + public void close() throws java.io.IOException + { + // 1. Ensure that pending characters are written + flushBase64(); + + // 2. Actually close the stream + // Base class both flushes and closes. + super.close(); + + buffer = null; + out = null; + } // end close + + + + /** + * Suspends encoding of the stream. + * May be helpful if you need to embed a piece of + * base640-encoded data in a stream. + * + * @since 1.5.1 + */ + public void suspendEncoding() throws java.io.IOException + { + flushBase64(); + this.suspendEncoding = true; + } // end suspendEncoding + + + /** + * Resumes encoding of the stream. + * May be helpful if you need to embed a piece of + * base640-encoded data in a stream. + * + * @since 1.5.1 + */ + public void resumeEncoding() + { + this.suspendEncoding = false; + } // end resumeEncoding + + + + } // end inner class OutputStream + + +} // end class Base64 \ No newline at end of file diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/DisplayChecklistMasterGetterSetter.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/DisplayChecklistMasterGetterSetter.java new file mode 100644 index 0000000..8604038 --- /dev/null +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/DisplayChecklistMasterGetterSetter.java @@ -0,0 +1,40 @@ +package cpm.com.gskmtorange.xmlGetterSetter; + +import java.util.ArrayList; + +/** + * Created by yadavendras on 03-01-2017. + */ + +public class DisplayChecklistMasterGetterSetter { + + String table_DISPLAY_CHECKLIST_MASTER; + + public String getTable_DISPLAY_CHECKLIST_MASTER() { + return table_DISPLAY_CHECKLIST_MASTER; + } + + public void setTable_DISPLAY_CHECKLIST_MASTER(String table_DISPLAY_CHECKLIST_MASTER) { + this.table_DISPLAY_CHECKLIST_MASTER = table_DISPLAY_CHECKLIST_MASTER; + } + + public ArrayList getCHECKLIST_ID() { + return CHECKLIST_ID; + } + + public void setCHECKLIST_ID(String CHECKLIST_ID) { + this.CHECKLIST_ID.add(CHECKLIST_ID); + } + + public ArrayList getCHECKLIST() { + return CHECKLIST; + } + + public void setCHECKLIST(String CHECKLIST) { + this.CHECKLIST.add(CHECKLIST); + } + + ArrayList CHECKLIST_ID = new ArrayList<>(); + ArrayList CHECKLIST = new ArrayList<>(); + +} diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/GapsChecklistGetterSetter.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/GapsChecklistGetterSetter.java new file mode 100644 index 0000000..055c66a --- /dev/null +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/GapsChecklistGetterSetter.java @@ -0,0 +1,43 @@ +package cpm.com.gskmtorange.xmlGetterSetter; + +/** + * Created by yadavendras on 04-01-2017. + */ + +public class GapsChecklistGetterSetter { + + String checklist, checklist_id, display_id; + boolean present; + + public String getChecklist() { + return checklist; + } + + public void setChecklist(String checklist) { + this.checklist = checklist; + } + + public String getChecklist_id() { + return checklist_id; + } + + public void setChecklist_id(String checklist_id) { + this.checklist_id = checklist_id; + } + + public boolean isPresent() { + return present; + } + + public void setPresent(boolean present) { + this.present = present; + } + + public String getDisplay_id() { + return display_id; + } + + public void setDisplay_id(String display_id) { + this.display_id = display_id; + } +} diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/MappingDisplayChecklistGetterSetter.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/MappingDisplayChecklistGetterSetter.java new file mode 100644 index 0000000..908d632 --- /dev/null +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/MappingDisplayChecklistGetterSetter.java @@ -0,0 +1,39 @@ +package cpm.com.gskmtorange.xmlGetterSetter; + +import java.util.ArrayList; + +/** + * Created by yadavendras on 03-01-2017. + */ + +public class MappingDisplayChecklistGetterSetter { + + String table_MAPPING_DISPLAY_CHECKLIST; + + ArrayList DISPLAY_ID = new ArrayList<>(); + ArrayList CHECKLIST_ID = new ArrayList<>(); + + public String getTable_MAPPING_DISPLAY_CHECKLIST() { + return table_MAPPING_DISPLAY_CHECKLIST; + } + + public void setTable_MAPPING_DISPLAY_CHECKLIST(String table_MAPPING_DISPLAY_CHECKLIST) { + this.table_MAPPING_DISPLAY_CHECKLIST = table_MAPPING_DISPLAY_CHECKLIST; + } + + public ArrayList getDISPLAY_ID() { + return DISPLAY_ID; + } + + public void setDISPLAY_ID(String DISPLAY_ID) { + this.DISPLAY_ID.add(DISPLAY_ID); + } + + public ArrayList getCHECKLIST_ID() { + return CHECKLIST_ID; + } + + public void setCHECKLIST_ID(String CHECKLIST_ID) { + this.CHECKLIST_ID.add(CHECKLIST_ID); + } +} diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/MappingPromotionGetterSetter.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/MappingPromotionGetterSetter.java new file mode 100644 index 0000000..f9e18ae --- /dev/null +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/MappingPromotionGetterSetter.java @@ -0,0 +1,66 @@ +package cpm.com.gskmtorange.xmlGetterSetter; + +import java.util.ArrayList; + +/** + * Created by yadavendras on 03-01-2017. + */ + +public class MappingPromotionGetterSetter { + + String table_MAPPING_PROMOTION; + + ArrayList STORE_ID = new ArrayList<>(); + ArrayList SKU_ID = new ArrayList<>(); + ArrayList SKU = new ArrayList<>(); + ArrayList PROMO_ID = new ArrayList<>(); + ArrayList PROMO = new ArrayList<>(); + + public String getTable_MAPPING_PROMOTION() { + return table_MAPPING_PROMOTION; + } + + public void setTable_MAPPING_PROMOTION(String table_MAPPING_PROMOTION) { + this.table_MAPPING_PROMOTION = table_MAPPING_PROMOTION; + } + + public ArrayList getSTORE_ID() { + return STORE_ID; + } + + public void setSTORE_ID(String STORE_ID) { + this.STORE_ID.add(STORE_ID); + } + + public ArrayList getSKU_ID() { + return SKU_ID; + } + + public void setSKU_ID(String SKU_ID) { + this.SKU_ID.add(SKU_ID); + } + + public ArrayList getSKU() { + return SKU; + } + + public void setSKU(String SKU) { + this.SKU.add(SKU); + } + + public ArrayList getPROMO_ID() { + return PROMO_ID; + } + + public void setPROMO_ID(String PROMO_ID) { + this.PROMO_ID.add(PROMO_ID); + } + + public ArrayList getPROMO() { + return PROMO; + } + + public void setPROMO(String PROMO) { + this.PROMO.add(PROMO); + } +} diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/NonWorkingReasonGetterSetter.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/NonWorkingReasonGetterSetter.java new file mode 100644 index 0000000..78383dc --- /dev/null +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/NonWorkingReasonGetterSetter.java @@ -0,0 +1,57 @@ +package cpm.com.gskmtorange.xmlGetterSetter; + +import java.util.ArrayList; + +/** + * Created by yadavendras on 03-01-2017. + */ + +public class NonWorkingReasonGetterSetter { + + String table_NON_WORKING_REASON; + + ArrayList REASON_ID = new ArrayList<>(); + ArrayList REASON = new ArrayList<>(); + ArrayList ENTRY_ALLOW = new ArrayList<>(); + ArrayList IMAGE_ALLOW = new ArrayList<>(); + + public String getTable_NON_WORKING_REASON() { + return table_NON_WORKING_REASON; + } + + public void setTable_NON_WORKING_REASON(String table_NON_WORKING_REASON) { + this.table_NON_WORKING_REASON = table_NON_WORKING_REASON; + } + + public ArrayList getREASON_ID() { + return REASON_ID; + } + + public void setREASON_ID(String REASON_ID) { + this.REASON_ID.add(REASON_ID); + } + + public ArrayList getREASON() { + return REASON; + } + + public void setREASON(String REASON) { + this.REASON.add(REASON); + } + + public ArrayList getENTRY_ALLOW() { + return ENTRY_ALLOW; + } + + public void setENTRY_ALLOW(String ENTRY_ALLOW) { + this.ENTRY_ALLOW.add(ENTRY_ALLOW); + } + + public ArrayList getIMAGE_ALLOW() { + return IMAGE_ALLOW; + } + + public void setIMAGE_ALLOW(String IMAGE_ALLOW) { + this.IMAGE_ALLOW.add(IMAGE_ALLOW); + } +} diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/T2PGetterSetter.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/T2PGetterSetter.java new file mode 100644 index 0000000..56d6639 --- /dev/null +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/T2PGetterSetter.java @@ -0,0 +1,67 @@ +package cpm.com.gskmtorange.xmlGetterSetter; + +/** + * Created by yadavendras on 02-01-2017. + */ + +public class T2PGetterSetter { + + String brand_id, display_id, brand, display, image, remark; + boolean isPresent; + + public String getBrand_id() { + return brand_id; + } + + public void setBrand_id(String brand_id) { + this.brand_id = brand_id; + } + + public String getDisplay_id() { + return display_id; + } + + public void setDisplay_id(String display_id) { + this.display_id = display_id; + } + + public String getBrand() { + return brand; + } + + public void setBrand(String brand) { + this.brand = brand; + } + + public String getDisplay() { + return display; + } + + public void setDisplay(String display) { + this.display = display; + } + + public String getImage() { + return image; + } + + public void setImage(String image) { + this.image = image; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public boolean isPresent() { + return isPresent; + } + + public void setPresent(boolean present) { + isPresent = present; + } +} diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/TableBean.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/TableBean.java index 6e347c9..2d6362e 100644 --- a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/TableBean.java +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlGetterSetter/TableBean.java @@ -14,6 +14,10 @@ public class TableBean { public static String DISPLAY_MASTER; public static String MAPPING_STOCK; public static String MAPPING_T2P; + public static String DISPLAY_CHECKLIST_MASTER; + public static String MAPPING_DISPLAY_CHECKLIST; + public static String NON_WORKING_REASON; + public static String MAPPING_PROMOTION; public static String getJourneyPlan() { return JOURNEY_PLAN; @@ -78,4 +82,36 @@ public class TableBean { public static void setMappingT2p(String mappingT2p) { MAPPING_T2P = mappingT2p; } + + public static String getDisplayChecklistMaster() { + return DISPLAY_CHECKLIST_MASTER; + } + + public static void setDisplayChecklistMaster(String displayChecklistMaster) { + DISPLAY_CHECKLIST_MASTER = displayChecklistMaster; + } + + public static String getMappingDisplayChecklist() { + return MAPPING_DISPLAY_CHECKLIST; + } + + public static void setMappingDisplayChecklist(String mappingDisplayChecklist) { + MAPPING_DISPLAY_CHECKLIST = mappingDisplayChecklist; + } + + public static String getNonWorkingReason() { + return NON_WORKING_REASON; + } + + public static void setNonWorkingReason(String nonWorkingReason) { + NON_WORKING_REASON = nonWorkingReason; + } + + public static String getMappingPromotion() { + return MAPPING_PROMOTION; + } + + public static void setMappingPromotion(String mappingPromotion) { + MAPPING_PROMOTION = mappingPromotion; + } } diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlHandlers/FailureXMLHandler.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlHandlers/FailureXMLHandler.java new file mode 100644 index 0000000..710890b --- /dev/null +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlHandlers/FailureXMLHandler.java @@ -0,0 +1,53 @@ +package cpm.com.gskmtorange.xmlHandlers; + + + +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +import cpm.com.gskmtorange.xmlGetterSetter.FailureGetterSetter; + +public class FailureXMLHandler extends DefaultHandler{ + + private String elementValue; + private FailureGetterSetter failureGetterSetter = null; + + + public FailureGetterSetter getFailureGetterSetter() + { + return failureGetterSetter; + } + + @Override + public void startDocument() throws SAXException { + // TODO Auto-generated method stub + super.startDocument(); + + failureGetterSetter = new FailureGetterSetter(); + } + + @Override + public void characters(char[] ch, int start, int length) + throws SAXException { + // TODO Auto-generated method stub + super.characters(ch, start, length); + + elementValue = new String(ch, start, length); + } + + @Override + public void endElement(String uri, String localName, String qName) + throws SAXException { + // TODO Auto-generated method stub + super.endElement(uri, localName, qName); + + if(qName.equals("STATUS")) + { + failureGetterSetter.setStatus(elementValue); + } + else if(qName.equals("ERRORMSG")) + { + failureGetterSetter.setErrorMsg(elementValue); + } + } +} diff --git a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlHandlers/XMLHandlers.java b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlHandlers/XMLHandlers.java index 6305d29..ba39c9c 100644 --- a/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlHandlers/XMLHandlers.java +++ b/GSKMTOrange/src/main/java/cpm/com/gskmtorange/xmlHandlers/XMLHandlers.java @@ -7,12 +7,16 @@ import java.io.IOException; import cpm.com.gskmtorange.xmlGetterSetter.BrandMasterGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.CategoryMasterGetterSetter; +import cpm.com.gskmtorange.xmlGetterSetter.DisplayChecklistMasterGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.DisplayMasterGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.FailureGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.JourneyPlanGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.LoginGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.MAPPINGT2PGetterSetter; +import cpm.com.gskmtorange.xmlGetterSetter.MappingDisplayChecklistGetterSetter; +import cpm.com.gskmtorange.xmlGetterSetter.MappingPromotionGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.MappingStockGetterSetter; +import cpm.com.gskmtorange.xmlGetterSetter.NonWorkingReasonGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.SkuMasterGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.SubCategoryMasterGetterSetter; @@ -405,7 +409,7 @@ public class XMLHandlers { return stock; } - // MAPPING_STOCK XML HANDLER + // MAPPING_T2P XML HANDLER public static MAPPINGT2PGetterSetter mappingT2pXMLHandler(XmlPullParser xpp, int eventType) { MAPPINGT2PGetterSetter t2p = new MAPPINGT2PGetterSetter(); @@ -437,4 +441,140 @@ public class XMLHandlers { } return t2p; } + + // DISPLAY_CHECKLIST_MASTER XML HANDLER + public static DisplayChecklistMasterGetterSetter mappingDisplayChecklistMasterXMLHandler(XmlPullParser xpp, + int eventType) { + DisplayChecklistMasterGetterSetter checklist = new DisplayChecklistMasterGetterSetter(); + + try { + while (xpp.getEventType() != XmlPullParser.END_DOCUMENT) { + if (xpp.getEventType() == XmlPullParser.START_TAG) { + if (xpp.getName().equals("META_DATA")) { + checklist.setTable_DISPLAY_CHECKLIST_MASTER(xpp.nextText()); + } + if (xpp.getName().equals("CHECKLIST_ID")) { + checklist.setCHECKLIST_ID(xpp.nextText()); + } + if (xpp.getName().equals("CHECKLIST")) { + checklist.setCHECKLIST(xpp.nextText()); + } + + } + xpp.next(); + } + } catch (XmlPullParserException e) { + + e.printStackTrace(); + } catch (IOException e) { + + e.printStackTrace(); + } + return checklist; + } + + // MAPPING_DISPLAY_CHECKLIST XML HANDLER + public static MappingDisplayChecklistGetterSetter mappingMappingDisplayChecklistXMLHandler(XmlPullParser xpp, + int eventType) { + MappingDisplayChecklistGetterSetter checklist = new MappingDisplayChecklistGetterSetter(); + + try { + while (xpp.getEventType() != XmlPullParser.END_DOCUMENT) { + if (xpp.getEventType() == XmlPullParser.START_TAG) { + if (xpp.getName().equals("META_DATA")) { + checklist.setTable_MAPPING_DISPLAY_CHECKLIST(xpp.nextText()); + } + if (xpp.getName().equals("CHECKLIST_ID")) { + checklist.setCHECKLIST_ID(xpp.nextText()); + } + if (xpp.getName().equals("DISPLAY_ID")) { + checklist.setDISPLAY_ID(xpp.nextText()); + } + } + xpp.next(); + } + } catch (XmlPullParserException e) { + + e.printStackTrace(); + } catch (IOException e) { + + e.printStackTrace(); + } + return checklist; + } + + // NON_WORKING_REASON XML HANDLER + public static NonWorkingReasonGetterSetter nonWorkingReasonXMLHandler(XmlPullParser xpp, + int eventType) { + NonWorkingReasonGetterSetter reason = new NonWorkingReasonGetterSetter(); + + try { + while (xpp.getEventType() != XmlPullParser.END_DOCUMENT) { + if (xpp.getEventType() == XmlPullParser.START_TAG) { + if (xpp.getName().equals("META_DATA")) { + reason.setTable_NON_WORKING_REASON(xpp.nextText()); + } + if (xpp.getName().equals("REASON_ID")) { + reason.setREASON_ID(xpp.nextText()); + } + if (xpp.getName().equals("REASON")) { + reason.setREASON(xpp.nextText()); + } + if (xpp.getName().equals("ENTRY_ALLOW")) { + reason.setENTRY_ALLOW(xpp.nextText()); + } + if (xpp.getName().equals("IMAGE_ALLOW")) { + reason.setIMAGE_ALLOW(xpp.nextText()); + } + } + xpp.next(); + } + } catch (XmlPullParserException e) { + + e.printStackTrace(); + } catch (IOException e) { + + e.printStackTrace(); + } + return reason; + } + + // MAPPING_PROMOTION XML HANDLER + public static MappingPromotionGetterSetter mappingPromotionXMLHandler(XmlPullParser xpp, + int eventType) { + MappingPromotionGetterSetter t2p = new MappingPromotionGetterSetter(); + + try { + while (xpp.getEventType() != XmlPullParser.END_DOCUMENT) { + if (xpp.getEventType() == XmlPullParser.START_TAG) { + if (xpp.getName().equals("META_DATA")) { + t2p.setTable_MAPPING_PROMOTION(xpp.nextText()); + } + if (xpp.getName().equals("STORE_ID")) { + t2p.setSTORE_ID(xpp.nextText()); + } + if (xpp.getName().equals("SKU_ID")) { + t2p.setSKU_ID(xpp.nextText()); + } + if (xpp.getName().equals("SKU")) { + t2p.setSKU(xpp.nextText()); + } + if (xpp.getName().equals("PROMO_ID")) { + t2p.setPROMO_ID(xpp.nextText()); + } + if (xpp.getName().equals("PROMO")) { + t2p.setPROMO(xpp.nextText()); + } + } + xpp.next(); + } + } catch (XmlPullParserException e) { + + e.printStackTrace(); + } catch (IOException e) { + + e.printStackTrace(); + } + return t2p; + } } diff --git a/GSKMTOrange/src/main/res/drawable-v21/list_selector.xml b/GSKMTOrange/src/main/res/animator-hdpi/list_selector.xml similarity index 100% rename from GSKMTOrange/src/main/res/drawable-v21/list_selector.xml rename to GSKMTOrange/src/main/res/animator-hdpi/list_selector.xml diff --git a/GSKMTOrange/src/main/res/drawable/cam_active.png b/GSKMTOrange/src/main/res/drawable/cam_active.png new file mode 100644 index 0000000..c70be43 Binary files /dev/null and b/GSKMTOrange/src/main/res/drawable/cam_active.png differ diff --git a/GSKMTOrange/src/main/res/drawable/cam_deactive.png b/GSKMTOrange/src/main/res/drawable/cam_deactive.png new file mode 100644 index 0000000..7b64187 Binary files /dev/null and b/GSKMTOrange/src/main/res/drawable/cam_deactive.png differ diff --git a/GSKMTOrange/src/main/res/drawable/edit_active.png b/GSKMTOrange/src/main/res/drawable/edit_active.png new file mode 100644 index 0000000..caf544d Binary files /dev/null and b/GSKMTOrange/src/main/res/drawable/edit_active.png differ diff --git a/GSKMTOrange/src/main/res/drawable/edit_deactive.png b/GSKMTOrange/src/main/res/drawable/edit_deactive.png new file mode 100644 index 0000000..36eeb40 Binary files /dev/null and b/GSKMTOrange/src/main/res/drawable/edit_deactive.png differ diff --git a/GSKMTOrange/src/main/res/layout/activity_storeimage.xml b/GSKMTOrange/src/main/res/layout/activity_storeimage.xml new file mode 100644 index 0000000..af63741 --- /dev/null +++ b/GSKMTOrange/src/main/res/layout/activity_storeimage.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + diff --git a/GSKMTOrange/src/main/res/layout/activity_t2_pcompliance.xml b/GSKMTOrange/src/main/res/layout/activity_t2_pcompliance.xml new file mode 100644 index 0000000..091fc7b --- /dev/null +++ b/GSKMTOrange/src/main/res/layout/activity_t2_pcompliance.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/GSKMTOrange/src/main/res/layout/content_t2_pcompliance.xml b/GSKMTOrange/src/main/res/layout/content_t2_pcompliance.xml new file mode 100644 index 0000000..26c17ce --- /dev/null +++ b/GSKMTOrange/src/main/res/layout/content_t2_pcompliance.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/GSKMTOrange/src/main/res/layout/contentstoreimage.xml b/GSKMTOrange/src/main/res/layout/contentstoreimage.xml new file mode 100644 index 0000000..4abae3d --- /dev/null +++ b/GSKMTOrange/src/main/res/layout/contentstoreimage.xml @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +