-----------------------------AgencySignInActivity.java------------------
package com.dollop.syzygy.agency.activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.dollop.syzygy.agency.R;
import com.dollop.syzygy.agency.Volley.Helper;
import com.dollop.syzygy.agency.Volley.JSONParser;
import com.dollop.syzygy.agency.WebServiceURL;
import com.dollop.syzygy.agency.utilis.SaveData;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
import butterknife.ButterKnife;
public class AgencySignInActivity extends BaseActivity {
Button agencySignInBtn;
EditText AgencyUserNameId, AgencyPassId;
@Override
protected int getContentResId() {
return R.layout.activity_agency_sign_in;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ButterKnife.bind(this);
setToolbarWithBackButton("SignIn");
SaveData.saveUserType("AgencyLogin");
AgencyUserNameId = (EditText) findViewById(R.id.AgencyUserNameId);
AgencyPassId = (EditText) findViewById(R.id.AgencyPassId);
agencySignInBtn = (Button) findViewById(R.id.agencySignInBtn);
agencySignInBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String UserName = AgencyUserNameId.getText().toString();
String Password = AgencyPassId.getText().toString();
if (UserAccount.isEmpty(AgencyUserNameId, AgencyPassId)) {
if (UserAccount.isPasswordValid(AgencyPassId)) {
loginAgencyGiver();
} else {
UserAccount.EditTextPointer.setError("Password must contain 6 chracter!");
UserAccount.EditTextPointer.requestFocus();
}
} else {
UserAccount.EditTextPointer.setError("Fields Can't be Empty!");
UserAccount.EditTextPointer.requestFocus();
}
}
});
}
private void loginAgencyGiver() {
new JSONParser(this).parseVollyStringRequestWithautProgressBar(WebServiceURL.URL.Login_Url, 1, getParms(), new Helper() {
@Override
public void backResponse(String response) {
try {
JSONObject mainobject = new JSONObject(response);
int status = mainobject.getInt("status");
String message = mainobject.getString("message");
String Token = mainobject.getString("Token");
Log.e("Token", "..." + Token);
SaveData.saveToken(Token);
if (status == 200) {
Toast.makeText(AgencySignInActivity.this, "Agency Login successfully...", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(AgencySignInActivity.this, NavigrationAgencyActivity.class);
startActivity(intent);
finish();
} else {
Toast.makeText(AgencySignInActivity.this, "Sorry Id And Password Not Match..", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
private Map<String, String> getParms() {
HashMap<String, String> params = new HashMap<>();
params.put("authority_id", "4");
params.put("user_name", AgencyUserNameId.getText().toString());
params.put("password", AgencyPassId.getText().toString());
return params;
}
}
-------------------------Helper.class------------------
package com.dollop.syzygy.agency.Volley;
/**
* Created by CRUD Technology on 10/5/2015.
*/
public interface Helper {
public void backResponse(String response);
}
--------------------------JSONParser.class-------------
package com.dollop.syzygy.agency.Volley;
import android.content.Context;
import android.util.Log;
import com.afollestad.materialdialogs.MaterialDialog;
import com.android.volley.AuthFailureError;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.dollop.syzygy.agency.AppController;
import com.dollop.syzygy.agency.R;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null, response;
static String json = "";
private Context cx;
// constructor
public JSONParser(Context cx) {
this.cx = cx;
}
// function get json from url
// by making HTTP POST or GET mehtod
public static String convertInputStreamToString(InputStream inputStream)
throws IOException {
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(inputStream));
String line = "";
String result = "";
while ((line = bufferedReader.readLine()) != null)
result += line;
inputStream.close();
return result;
}
public void parseVollyJSONObject(String url, int method, final JSONObject param, final Helper h) {
//method GET=0,POST=1
/* String perameters;
if (param == null) {
perameters = null;
} else {
perameters = param.toString();
}*/
if (method == 0 || method == 1) {
final JsonObjectRequest jsObjRequest = new JsonObjectRequest
(method, url, param, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
//Log.e("Response: ", response.toString());
if (response != null) {
h.backResponse(response.toString());
} else {
M.E("Something went wrong.!");
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
String err = (error.getMessage() == null) ? "Parse Fail" : error.getMessage();
h.backResponse("error");
Log.e("sdcard-err2:", err);
M.E("Something went wrong.!");
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}
};
jsObjRequest.setShouldCache(true);
// Adding request to request queue
AppController.getInstance().
addToRequestQueue(jsObjRequest);
} else {
M.E("Invalid Request Method");
}
}
public void parseVollyStringRequest(String url, int method, final Map<String, String> params, final Helper h) {
//method GET=0,POST=1
if (NetworkUtil.getConnectivityStatus(cx)) {
if (method == 0 || method == 1) {
final MaterialDialog materialDialog = M.initProgressDialog(cx);
final StringRequest jsObjRequest = new StringRequest
(method, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//M.E("Response: " + response.toString());
if (response != null) {
materialDialog.dismiss();
h.backResponse(response.toString());
} else {
M.E("Invalid Request Method");
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
String err = (error.getMessage() == null) ? "Parse Fail" : error.getMessage();
materialDialog.dismiss();
h.backResponse("error");
M.E("sdcard-err2:" + err);
M.E("Something went wrong.!");
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
//returning parameters
return params;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsObjRequest);
} else {
M.E("Invalid Request Method");
}
} else {
M.T(cx, cx.getString(R.string.no_internet));
}
}
public void parseVollyStringRequestWithautProgressBar(String url, int method, final Map<String, String> params, final Helper h) {
//method GET=0,POST=1
if (NetworkUtil.getConnectivityStatus(cx)) {
if (method == 0 || method == 1) {
final MaterialDialog materialDialog = M.initProgressDialog(cx);
final StringRequest jsObjRequest = new StringRequest
(method, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//M.E("Response: " + response.toString());
if (response != null) {
materialDialog.dismiss();
h.backResponse(response.toString());
} else {
M.E("Invalid Request Method");
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
String err = (error.getMessage() == null) ? "Parse Fail" : error.getMessage();
// materialDialog.dismiss();
h.backResponse("error");
M.E("sdcard-err2:" + err);
M.E("Something went wrong.!");
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
//returning parameters
return params;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsObjRequest);
} else {
M.E("Invalid Request Method");
}
} else {
M.T(cx, cx.getString(R.string.no_internet));
}
}
}
--------------------M.class-----------------
package com.dollop.syzygy.agency.Volley;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.afollestad.materialdialogs.MaterialDialog;
/**
* Created by Sohel on 9/17/2015.
*/
public class M {
public static void I(Context cx, Class<?> startActivity, Bundle data) {
Intent i = new Intent(cx, startActivity);
if (data != null)
i.putExtras(data);
cx.startActivity(i);
}
public static void E(String msg) {
Log.e("Log.E By Sohel ", msg);
}
public static void T(Context c, String msg) {
Toast.makeText(c, msg, Toast.LENGTH_SHORT).show();
}
public static MaterialDialog initProgressDialog(Context c) {
return new MaterialDialog.Builder(c)
.title("Please wait...")
.autoDismiss(false)
.content("Wait for a moment.")
.progress(true, 0)
.show();
}
// public static void Popup(Context c,View V, String msg, String title) {
// final Dialog dialog = new Dialog(c);
// dialog.setContentView(R.layout.activity_popup);
// dialog.setTitle(title);
// final TextView textId = (TextView) dialog.findViewById(R.id.textId);
// textId.setText(msg);
// new Handler().postDelayed(new Runnable() {
// @Override
// public void run() {
// dialog.dismiss();
// }
// }
//
// , 3000);
//
// dialog.show();
//
// }
public static void share(Context c, String subject, String shareBody) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
c.startActivity(Intent.createChooser(sharingIntent, "Share via"));
}
}
----------------------------NetworkUtil.class-----------
package com.dollop.syzygy.agency.Volley;
/**
* Created by CRUD Technology on 8/22/2015.
*/
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkInfo;
import android.os.Build;
public class NetworkUtil {
public static Boolean getConnectivityStatus(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Network[] networks = connectivityManager.getAllNetworks();
NetworkInfo networkInfo;
for (Network mNetwork : networks) {
networkInfo = connectivityManager.getNetworkInfo(mNetwork);
if (networkInfo.getState().equals(NetworkInfo.State.CONNECTED)) {
return true;
}
}
} else {
if (connectivityManager != null) {
//noinspection deprecation
NetworkInfo[] info = connectivityManager.getAllNetworkInfo();
if (info != null) {
for (NetworkInfo anInfo : info) {
if (anInfo.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
}
return false;
}
}
----------------AppController.class---------
package com.dollop.syzygy.agency;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.support.annotation.IntDef;
import android.support.multidex.MultiDex;
import android.support.multidex.MultiDexApplication;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Created by androidsys1 on 3/31/2017.
*/
public class AppController extends MultiDexApplication {
private static AppController mInstance;
public static int invoiceId = 0;
private RequestQueue mRequestQueue;
public static final String TAG = AppController.class.getSimpleName();
public static synchronized AppController getInstance() {
return mInstance;
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
@Retention(RetentionPolicy.SOURCE)
@IntDef(
{GRANTED, DENIED, BLOCKED})
public @interface PermissionStatus {
}
public static final int GRANTED = 0;
public static final int DENIED = 1;
public static final int BLOCKED = 2;
@PermissionStatus
public static int getPermissionStatus(Activity activity, String androidPermissionName) {
if (ContextCompat.checkSelfPermission(activity, androidPermissionName) != PackageManager.PERMISSION_GRANTED) {
if (!ActivityCompat.shouldShowRequestPermissionRationale(activity, androidPermissionName)) {
return BLOCKED;
}
return DENIED;
}
return GRANTED;
}
public RequestQueue getRequestQueue() {
if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}
return mRequestQueue;
}
public <T> void addToRequestQueue(Request<T> req, String tag) {
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
getRequestQueue().add(req);
}
public <T> void addToRequestQueue(Request<T> req) {
req.setTag(TAG);
getRequestQueue().add(req);
}
@Override
public void onCreate() {
MultiDex.install(this);
super.onCreate();
mInstance = this;
}
public void handleUncaughtException(Thread thread, Throwable e) {
e.printStackTrace();
}
}
---------------WebServiceURL.class-----------
package com.dollop.syzygy.agency;
/**
* Created by androidsys1 on 4/24/2017.
*/
public class WebServiceURL {
public interface URL {
public static String host_Url = "http://activegrowthinc.com/careApp/";
// public static String GetOtp_Url = host_Url + "getOtp";
// public static String MatechOtpAndRegister_Url = host_Url + "matchOtpAndRegistration";
public static String Login_Url = host_Url + "login";
public static String GetCaregiverAccordingToAgency = host_Url + "getCaregiverAccordingToAgency";
public static String AddPayment = host_Url + "addPayment";
public static String GetAgency = host_Url + "getAgency";
// public static String HireCareGiverHistroy_Url = host_Url + "hireCareGiverHistory";
// public static String GetEmerGencyClientContact_Url = host_Url + "getEmergencyNo";
// public static String Client_ForgotPassword_Url = host_Url + "forgot_password";
// public static String Client_MatchOtp = host_Url + "matchOtp";
// public static String Client_ChangePasword_Url = host_Url + "change_password";
}
}
-----------------SaveData.class--------------
package com.dollop.syzygy.agency.utilis;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.dollop.syzygy.agency.AppController;
/**
* Created by Rahul jain on 24-04-2017.
*/
public class SaveData {
private static final String USERTYPE = "user_type";
private static final String TOKEN = "token_id";
static SharedPreferences prefs;
public static SharedPreferences getInstance() {
if (prefs == null) {
prefs = PreferenceManager.getDefaultSharedPreferences(AppController.getInstance());
}
return prefs;
}
public static String getUserTpye() {
return getInstance().getString(USERTYPE, null);
}
public static void saveUserType(String user_type) {
SharedPreferences.Editor editor = getInstance().edit();
editor.putString(USERTYPE, user_type);
editor.apply();
}
public static String getToken() {
return getInstance().getString(TOKEN, null);
}
public static void saveToken(String user_type) {
SharedPreferences.Editor editor = getInstance().edit();
editor.putString(TOKEN, user_type);
editor.apply();
}
}
-------------build.gradle--------------------
apply plugin: 'com.android.application'
android {
compileSdkVersion 26 buildToolsVersion "26.0.1" defaultConfig {
applicationId "com.dollop.syzygy.agency" minSdkVersion 15 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' }
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations' })
compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support:design:25.3.1' compile 'com.google.android.gms:play-services:11.0.2' compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.google.android.gms:play-services-maps:9.4.0' compile 'com.jakewharton:butterknife:8.5.1' compile 'com.android.support:cardview-v7:25.1.1'
testCompile 'junit:junit:4.12' compile 'com.afollestad.material-dialogs:core:0.9.0.1' compile 'com.mcxiaoke.volley:library-aar:1.0.0' compile 'com.android.support:multidex:1.0.1'
}
---------------AndroidManifest.xml----------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dollop.syzygy.agency">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name=".AppController"
android:allowBackup="true"
android:icon="@drawable/agencynew"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<!-- <activity android:name=".Activity.SplashActivity"> -->
<activity android:name=".Intro.WelcomeAgencyActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".activity.NavigrationAgencyActivity"
android:label="@string/title_activity_navigration_agency"
android:theme="@style/AppTheme" />
<activity android:name=".activity.ActiveUserAgencyActivity" />
<activity android:name=".activity.TrustBudgesActivity" />
<activity android:name=".activity.AgencyProfileActivity" />
<activity android:name=".activity.AgencySignInActivity" />
<activity android:name=".activity.AgencyfragmentActivity" />
<!-- <activity android:name=".Intro.WelcomeAgencyActivity"></activity> -->
<activity android:name=".activity.SplashActivity"></activity>
<activity android:name=".activity.AgencyPaymentActivity"></activity>
</application>
</manifest>