-------------------------------LoginSignUP----------------------------------
--------------------------------------Manifest---------------------------------
--------------------------------------Manifest---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.meenakshi.loginsignupapi"> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <application
android:name=".AppController"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"> <activity android:name=".LoginActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".SignupActivity"></activity> </application> </manifest>
---------Appcontroller-----------------------
package com.example.meenakshi.loginsignupapi; import android.support.multidex.MultiDex; import android.support.multidex.MultiDexApplication; import android.text.TextUtils; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.toolbox.DiskBasedCache; import com.android.volley.toolbox.Volley; /** * Created by meenakshi on 8/23/2017. */ public class AppController extends MultiDexApplication { public static final String TAG = AppController.class.getSimpleName(); private RequestQueue mRequestQueue; private static AppController mInstance; DiskBasedCache cache; @Override public void onCreate() { super.onCreate(); mInstance = this; // new LoginDataHelper(this);// new UserDetailDataHelper(this);MultiDex.install(this); // Create global configuration and initialize ImageLoader with this config} public DiskBasedCache getDiskCache() { if (cache == null) { cache = new DiskBasedCache(getExternalCacheDir(), 209715200); } return cache; } public static synchronized AppController getInstance() { return mInstance; } 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); } public void cancelPendingRequests(Object tag) { if (mRequestQueue != null) { mRequestQueue.cancelAll(tag); } } }---------------Helper-------------------
package com.example.meenakshi.loginsignupapi; /** * Created by meenakshi on 8/23/2017. */public interface Helper { public void backResponse(String response); }----------JASONparser-----------------------
package com.example.meenakshi.loginsignupapi; 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.JsonArrayRequest; import com.android.volley.toolbox.JsonObjectRequest; import com.android.volley.toolbox.StringRequest; import org.json.JSONArray; 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() { @Overridepublic 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 queueAppController.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>(){@Overridepublic 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() { @Overridepublic 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.!"); } }) { @Overrideprotected Map<String, String> getParams() throws AuthFailureError { //returning parametersreturn params; } }; // Adding request to request queueAppController.getInstance().addToRequestQueue(jsObjRequest); } else { M.E("Invalid Request Method"); } } public void parseVollyStringRequestWithautProgressBar(String url, int method, final Map<String, String> params, final Helper h) { //method GET=0,POST=1if (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>() { @Overridepublic 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() { @Overridepublic 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.!"); } }) { @Overrideprotected Map<String, String> getParams() throws AuthFailureError { //returning parametersreturn params; } }; // Adding request to request queueAppController.getInstance().addToRequestQueue(jsObjRequest); } else { M.E("Invalid Request Method"); } } else { // M.T(cx, cx.getString(R.string.no_internet)); } } }------------LoginActivity.Activity----------
package com.example.meenakshi.loginsignupapi; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import org.json.JSONException; import org.json.JSONObject; import java.util.HashMap; import java.util.Map; public class LoginActivity extends AppCompatActivity { EditText Login_mobile_numberEt,Login_passwordEt; TextView Login_signupTv; Button Login_buttonBt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Login_mobile_numberEt=(EditText)findViewById(R.id.Login_mobile_numberEt); Login_passwordEt=(EditText)findViewById(R.id.Login_passwordEt); Login_buttonBt=(Button)findViewById(R.id.Login_buttonBt); Login_signupTv=(TextView)findViewById(R.id.Login_signupTv); Loginmethod(); Login_signupTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent=new Intent(LoginActivity.this,SignupActivity.class); startActivity(intent); } }); } private void Loginmethod() { Log.e("Prams --- ","" + getPrams()); new JSONParser(this).parseVollyStringRequest(WebServiceURL.URL.LOGIN, 1, getPrams(), new Helper() { @Override public void backResponse(String response) { try { JSONObject jsonObject = new JSONObject(response); if (jsonObject.getString("status").equals("200")) { JSONObject data=jsonObject.getJSONObject("data"); finish(); }else { // S.T(LoginActivity.this,"Enter a valid Mobile Number & Password"); } } catch (JSONException e) { Log.e("","exception" + e); } } }); } private Map<String, String> getPrams() { Map<String, String> param = new HashMap<String, String>(); param.put("mobile", Login_mobile_numberEt.getText().toString()); param.put("password", Login_passwordEt.getText().toString()); return param; } @Override public void onBackPressed() { //check if first fragment in wizard is loaded, if true get abandon confirmation before going back// Intent intent=new Intent(LoginActivity.this,MainActivity.class);// startActivity(intent); finish(); } }----------SignUpActivity.Activity-------------
package com.example.meenakshi.loginsignupapi; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import org.json.JSONException; import org.json.JSONObject; import java.util.HashMap; import java.util.Map; public class SignupActivity extends AppCompatActivity { EditText Signup_mobile_numberEt,Signup_password_numberEt,Signup_otp_numberEt; Button Signup_signupBt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_signup); Signup_mobile_numberEt=(EditText)findViewById(R.id.Signup_mobile_numberEt); Signup_password_numberEt=(EditText)findViewById(R.id.Signup_password_numberEt); Signup_otp_numberEt=(EditText)findViewById(R.id.Signup_otp_numberEt); Signup_signupBt=(Button)findViewById(R.id.Signup_signupBt); Signup(); } private void Signup() { Log.e("Prams --- ","" + getPrams()); new JSONParser(this).parseVollyStringRequest(WebServiceURL.URL.SIGN_UP , 1, getPrams(), new Helper() { @Override public void backResponse(String response) { try { JSONObject jsonObject = new JSONObject(response); if (jsonObject.getString("status").equals("200")) { JSONObject data=jsonObject.getJSONObject("data"); finish(); }else { // S.T(LoginActivity.this,"Enter a valid Mobile Number & Password"); } } catch (JSONException e) { Log.e("","exception" + e); } } }); } private Map<String, String> getPrams() { Map<String, String> param = new HashMap<String, String>(); param.put("mobile", Signup_mobile_numberEt.getText().toString()); param.put("password", Signup_password_numberEt.getText().toString()); param.put("otp", Signup_otp_numberEt.getText().toString()); return param; } @Override public void onBackPressed() { //check if first fragment in wizard is loaded, if true get abandon confirmation before going back// Intent intent=new Intent(LoginActivity.this,MainActivity.class);// startActivity(intent); finish(); } }-----------------M class---------------------
package com.example.meenakshi.loginsignupapi; 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 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")); } }----------NeworkUtil---------------------
package com.example.meenakshi.loginsignupapi; /** * 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 deprecationNetworkInfo[] info = connectivityManager.getAllNetworkInfo(); if (info != null) { for (NetworkInfo anInfo : info) { if (anInfo.getState() == NetworkInfo.State.CONNECTED) { return true; } } } } } return false; } }------------WebServiceUrl--------------------
package com.example.meenakshi.loginsignupapi; /** * Created by meenakshi on 8/23/2017. */public class WebServiceURL { public interface URL { public static String login_url = "http://bookmyservice.info/control/bookMyServiceApi/index.php/Webservice/"; public static String signup_url = "http://bookmyservice.info/control/bookMyServiceApi/index.php/Webservice/"; public static String host_url = "http://activegrowthinc.com/tiffin/Webservice/"; public static String LOGIN = host_url + "login"; public static String SIGN_UP = host_url + "signUp"; } }----------activity_main.xml-------------
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.meenakshi.loginsignupapi.LoginActivity"> <LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"> <TextView android:layout_width="match_parent"
android:layout_height="match_parent"android:text="Login page"android:textSize="20sp"android:gravity="center"/> <LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:orientation="vertical"> <EditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="16sp"android:id="@+id/Login_mobile_numberEt"android:hint="Mobile number" /> <EditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/Login_passwordEt"android:textSize="16sp"android:hint="Password"/>
<Buttonandroid:layout_width="match_parent"
android:layout_height="wrap_content"android:layout_marginTop="20dp"android:id="@+id/Login_buttonBt"android:text="Login" /> </LinearLayout> </LinearLayout> <TextView android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:gravity="center"android:textSize="18sp"android:id="@+id/Login_signupTv"android:text="You have no account! SignUP"/> </RelativeLayout>--------------activity_signup-----------
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/activity_main"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"> <LinearLayoutandroid:layout_width="match_parent"
android:layout_height="wrap_content"android:orientation="vertical"> <TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:text="SignUp page"android:textSize="20sp" /> <LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:orientation="vertical"> <EditTextandroid:id="@+id/Signup_mobile_numberEt"android:layout_width="match_parent"android:layout_height="wrap_content"android:hint="Mobile number"android:textSize="16sp" /> <EditTextandroid:id="@+id/Signup_password_numberEt"android:layout_width="match_parent"android:layout_height="wrap_content"
android:hint="Password"android:textSize="16sp" /> <EditTextandroid:id="@+id/Signup_otp_numberEt"android:layout_width="match_parent"android:layout_height="wrap_content"android:hint="OTP"android:textSize="16sp" /> <Buttonandroid:id="@+id/Signup_signupBt"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:text="Signup" /> </LinearLayout> </LinearLayout> </RelativeLayout>-------------build.gradle(app)2no.---------
apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26.0.1" defaultConfig { applicationId "com.example.meenakshi.loginsignupapi" minSdkVersion 15 targetSdkVersion 26 versionCode 1 versionName "1.0" multiDexEnabled true testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled falseproguardFiles 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:26.0.0-alpha1'testCompile 'junit:junit:4.12' compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'testCompile 'junit:junit:4.12'compile 'com.squareup.picasso:picasso:2.5.2'compile 'com.mcxiaoke.volley:library-aar:1.0.0'compile 'com.google.code.gson:gson:2.3.1'compile 'com.android.support:multidex:1.0.1'compile 'com.afollestad.material-dialogs:core:0.9.0.1' }
No comments:
Post a Comment