Friday, 29 April 2016

constant data

package com.cygnus.apmlive;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONObject;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import android.view.Window;

import com.datatype.apmtest.RecallingData;
import com.datatype.apmtest.UserData;

public class ConstantData {
// public static UserData LoginUser;

public static UserData LoginUser;
static Dialog dialog;
static Dialog dialog2;
static Dialog dialog_;

// Pref to Store user data
public static final String MyPREFERENCES = "MyPrefsSwift";

public static String customername = "";
public static String officername = "";

public static String totalcft = "";

public static String decvalue = "";

public static String imei = "";

public static final String ServerUrl = "http://223.30.71.118/Service2.svc/";

public static final String ServerUrl_survey = "http://223.30.71.117//ApplicationDoc//SurveyPDF//";

public static final String ServerUrl_quotation = "http://223.30.71.117//ApplicationDoc//QuotationPDF//";

public static final String ServerUrl_cfr = "http://223.30.71.117//ApplicationDoc//CFRPDF//";


public static final String ServerUrl_Docket = "http://223.30.71.118/Service3.svc/";


public static Docket_data passdata ;


public static String CardType = "";

public static String CustomerMobile = "";
public static String ExternalRefNum = "";

public static String InvoiceNumber = "";
public static String NameOnCard = "";

public static String PaymentMode = "";

public static String TransactionId = "";
public static double Amount = 0.00;

public static String AuthCode = "";

public static String BatchNumber = "";


public static String LastFourDigits = "";



public static String gcnumber = "";

public static String Version = "";

public static RecallingData passrecalling;
// ===============wishal===========

public static String parseenqdatass;
// ==========================
// public static CfrData cfrdatas;

public static String parseenqdatassss;

public static String directpassenquirydata;

public static JSONObject passenquirydataforsurvey;

public static String lat = "0.00";

public static String lon = "0.00";




public static boolean isValidEmail(String email) {
String EMAIL_PATTERN = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";

Pattern pattern = Pattern.compile(EMAIL_PATTERN);
Matcher matcher = pattern.matcher(email);
return matcher.matches();
}

public static void SetUserData(Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(
MyPREFERENCES, Context.MODE_PRIVATE);
Editor editor = sharedpreferences.edit();

editor.putString(UserData.prefpassword, LoginUser.password);
editor.putString(UserData.prefBrachName, LoginUser.getBrachName());

editor.putString(UserData.prefBranchCode, LoginUser.getBranchCode());

String RemoveSpaceUserId = LoginUser.getUserId().trim();
Log.v("removespace", "msg" + RemoveSpaceUserId);

editor.putString(UserData.prefUserId, RemoveSpaceUserId);
editor.putString(UserData.prefName, LoginUser.getName());

editor.commit();
}

public static UserData GetUserData(Context context) {

SharedPreferences prefs = context.getSharedPreferences(MyPREFERENCES,
Context.MODE_PRIVATE);
ConstantData.LoginUser = new UserData();

try {
ConstantData.LoginUser.password = prefs.getString(
UserData.prefpassword, "");
ConstantData.LoginUser.setBrachName(prefs.getString(
UserData.prefBrachName, ""));

ConstantData.LoginUser.setBranchCode(prefs.getString(
UserData.prefBranchCode, ""));
ConstantData.LoginUser.setName(prefs.getString(UserData.prefName,
""));
ConstantData.LoginUser.setUserId(prefs.getString(
UserData.prefUserId, ""));

} catch (Exception e) {
ConstantData.LoginUser.setUserId("");
ConstantData.LoginUser.password = "";
}

return ConstantData.LoginUser;
}

public static SimpleDateFormat dateformate = new SimpleDateFormat(
"dd MMM yyyy");

public static SimpleDateFormat dateformatesurvey = new SimpleDateFormat(
"dd MMM yyyy HH:mm");

public static Object cfrparsdata;

public static JSONObject passcfrdata;

// public static CfrDatass passcfrfield;

public static String getDateFromJson(String jsonDate) {
try {
jsonDate = jsonDate.substring(jsonDate.indexOf("(") + 1,
jsonDate.indexOf(")"));
Date time = new Date(Long.valueOf(jsonDate));
return ("" + dateformate.format(time));
} catch (Exception e) {
return "Date issue";
}
}

public static String getDateFromJsonSurvey(String jsonDate) {
try {
jsonDate = jsonDate.substring(jsonDate.indexOf("(") + 1,
jsonDate.indexOf(")"));
Date time = new Date(Long.valueOf(jsonDate));
return ("" + dateformatesurvey.format(time));
} catch (Exception e) {
return "Date issue";
}
}

public static String getwsDateJson(String jsonDate) {
try {
jsonDate = jsonDate.substring(jsonDate.indexOf("(") + 1,
jsonDate.indexOf(")"));
Date time = new Date(Long.valueOf(jsonDate));
return ("" + dateformate.format(time));
} catch (Exception e) {
jsonDate = "01 Jan 1990";

return jsonDate;
}
}

public static void DisplayAlert(String title, String message,
Context context) {

AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
builder1.setTitle(title);
builder1.setMessage(message);
builder1.setCancelable(true);
builder1.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert11 = builder1.create();
alert11.show();

}

public static void Displayprogress(Context context) {

dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

dialog.setContentView(R.layout.progressbarr);
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);

dialog.show();

}





public static void Displayprogress_cfr(Context context) {

dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

dialog.setContentView(R.layout.progressbarr);

dialog.show();

}

public static void close_cfr_progress(Context context) {

dialog.dismiss();

}

public static void Displayprogress_download(Context context) {

dialog2 = new Dialog(context);
dialog2.requestWindowFeature(Window.FEATURE_NO_TITLE);

dialog2.setContentView(R.layout.progress_download);

dialog2.setCanceledOnTouchOutside(false);
dialog2.setCancelable(false);
dialog2.show();

}

public static void progressclose_download(Context context) {

dialog2.dismiss();

}

public static void Displayprogress1(Context context) {

dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

dialog.setContentView(R.layout.loadingemail);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);

dialog.show();

}

public static void progressclose(Context context) {

dialog.dismiss();

}

public static void ClearUserData(Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(
MyPREFERENCES, Context.MODE_PRIVATE);
Editor editor = sharedpreferences.edit();

editor.clear();
editor.commit();
}

public static boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

public static boolean isNetworkConnected(Context context) {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni == null)
return false;
else
return true;// return isInternetAvailable(context);
}

public static boolean isInternetAvailable(Context context) {
try {

HttpClient httpclient = new DefaultHttpClient();
HttpGet httppost = new HttpGet(ConstantData.ServerUrl);
httppost.addHeader("Content-Type", "multipart/form-data");
HttpResponse response = httpclient.execute(httppost);
if (response.getStatusLine().getStatusCode() == 200) {
return true;
}
} catch (Exception e) {
Log.i("exce", "" + e.toString());
}
return false;

}
}

No comments:

Post a Comment