Guest User

Untitled

a guest
Feb 13th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.11 KB | None | 0 0
  1. import android.support.v4.app.FragmentManager;
  2. import android.support.v7.app.AppCompatActivity;
  3. import android.os.Bundle;
  4.  
  5. public class MainActivity extends AppCompatActivity {
  6.  
  7. @Override
  8. protected void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.activity_main);
  11.  
  12. FragmentManager fm = getSupportFragmentManager();
  13. fm.beginTransaction().replace(R.id.escenario, new SesionFragment()).commit();
  14. }
  15. }
  16.  
  17. <?xml version="1.0" encoding="utf-8"?>
  18. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  19. xmlns:app="http://schemas.android.com/apk/res-auto"
  20. xmlns:tools="http://schemas.android.com/tools"
  21. android:id="@+id/escenario"
  22. android:layout_width="match_parent"
  23. android:layout_height="match_parent"
  24. tools:context="com.programming.narvaez.narvalogin.MainActivity">
  25.  
  26. </android.support.constraint.ConstraintLayout>
  27.  
  28. import android.support.v7.app.AppCompatActivity;
  29. import android.os.Bundle;
  30. import android.widget.TextView;
  31.  
  32. public class Main2Activity extends AppCompatActivity {
  33. public static final String nombres="names";
  34. TextView txtBienvenido;
  35. @Override
  36. protected void onCreate(Bundle savedInstanceState) {
  37. super.onCreate(savedInstanceState);
  38. setContentView(R.layout.activity_main2);
  39.  
  40. txtBienvenido=(TextView)findViewById(R.id.txtbienvenido);
  41. String usuario=getIntent().getStringExtra("names");
  42. txtBienvenido.setText("¡Bienvenido "+ usuario + "!");
  43. }
  44. }
  45.  
  46. <?xml version="1.0" encoding="utf-8"?>
  47. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  48. xmlns:app="http://schemas.android.com/apk/res-auto"
  49. xmlns:tools="http://schemas.android.com/tools"
  50. android:layout_width="match_parent"
  51. android:layout_height="match_parent"
  52. tools:context="com.programming.narvaez.narvalogin.Main2Activity">
  53.  
  54. <TextView
  55. android:id="@+id/txtbienvenido"
  56. android:layout_width="wrap_content"
  57. android:layout_height="wrap_content"
  58. android:layout_marginBottom="8dp"
  59. android:layout_marginTop="8dp"
  60. android:text="TextView"
  61. android:textColor="@android:color/background_dark"
  62. android:textSize="20sp"
  63. app:layout_constraintBottom_toBottomOf="parent"
  64. app:layout_constraintEnd_toEndOf="parent"
  65. app:layout_constraintLeft_toLeftOf="parent"
  66. app:layout_constraintRight_toRightOf="parent"
  67. app:layout_constraintStart_toStartOf="parent"
  68. app:layout_constraintTop_toTopOf="parent"
  69. app:layout_constraintVertical_bias="0.117" />
  70. </android.support.constraint.ConstraintLayout>
  71.  
  72. import android.content.Context;
  73. import android.content.Intent;
  74. import android.net.Uri;
  75. import android.os.Bundle;
  76. import android.support.v4.app.Fragment;
  77. import android.view.LayoutInflater;
  78. import android.view.View;
  79. import android.view.ViewGroup;
  80. import android.widget.Button;
  81. import android.widget.EditText;
  82. import android.widget.Toast;
  83.  
  84. import com.android.volley.Request;
  85. import com.android.volley.RequestQueue;
  86. import com.android.volley.Response;
  87. import com.android.volley.VolleyError;
  88. import com.android.volley.toolbox.JsonObjectRequest;
  89. import com.android.volley.toolbox.JsonRequest;
  90. import com.android.volley.toolbox.Volley;
  91.  
  92. import org.json.JSONArray;
  93. import org.json.JSONException;
  94. import org.json.JSONObject;
  95.  
  96. public class SesionFragment extends Fragment implements Response.Listener<JSONObject>, Response.ErrorListener {
  97. RequestQueue rq;
  98. JsonRequest jrq;
  99. EditText txtUser, txtPwd;
  100. Button btnSesion, btnRegistrar;
  101.  
  102. @Override
  103. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  104. Bundle savedInstanceState) {
  105.  
  106. View vista = inflater.inflate(R.layout.fragment_sesion, container, false);
  107. txtUser = (EditText) vista.findViewById(R.id.txtuser);
  108. txtPwd = (EditText) vista.findViewById(R.id.txtpwd);
  109.  
  110. btnSesion = (Button) vista.findViewById(R.id.btnsesion);
  111. btnRegistrar = (Button) vista.findViewById(R.id.btnregistrar);
  112. rq = Volley.newRequestQueue(getContext());
  113.  
  114. btnSesion.setOnClickListener(new View.OnClickListener() {
  115. @Override
  116. public void onClick(View view) {
  117. iniciar_sesion();
  118. }
  119. });
  120.  
  121. btnRegistrar.setOnClickListener(new View.OnClickListener() {
  122. @Override
  123. public void onClick(View view) {
  124. registrar_usuario();
  125. }
  126. });
  127.  
  128. // Inflate the layout for this fragment
  129. return vista;
  130. }
  131.  
  132. @Override
  133. public void onErrorResponse(VolleyError error) {
  134. Toast.makeText(getContext(), "No Se encontró el usuario " +error.toString()+ txtUser.getText().toString(), Toast.LENGTH_LONG).show();
  135. }
  136.  
  137. @Override
  138. public void onResponse(JSONObject response) {
  139. Toast.makeText(getContext(), "Se encontró el usuario " + txtUser.getText().toString(), Toast.LENGTH_SHORT).show();
  140. User usuario = new User();
  141. JSONArray jsonArray = response.optJSONArray("datos");
  142. JSONObject jsonObject = null;
  143.  
  144. try {
  145. jsonObject = jsonArray.getJSONObject(0);
  146. usuario.setUser(jsonObject.optString("user"));
  147. usuario.setPwd(jsonObject.optString("pwd"));
  148. usuario.setNames(jsonObject.optString("names"));
  149. } catch (JSONException e) {
  150. e.printStackTrace();
  151. }
  152.  
  153. Intent intencion = new Intent(getContext(), Main2Activity.class);
  154. intencion.putExtra(Main2Activity.nombres, usuario.getNames());
  155. startActivity(intencion);
  156. }
  157.  
  158. void iniciar_sesion() {
  159. //192.168.1.66(172.29.243.3
  160. String url = "http://192.168.1.66/login/sesion.php?user=" + txtUser.getText().toString() +
  161. "&pwd=" + txtPwd.getText().toString();
  162. jrq = new JsonObjectRequest(Request.Method.GET, url, null, this, this);
  163. rq.add(jrq);
  164. }
  165.  
  166. void registrar_usuario(){
  167. RegistrarFragment fr=new RegistrarFragment();
  168. //fr.setArguments(fr);
  169. getActivity().getSupportFragmentManager().beginTransaction()
  170. .replace(R.id.escenario,fr)
  171. .addToBackStack(null)
  172. .commit();
  173. }
  174. }
  175.  
  176. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  177. xmlns:app="http://schemas.android.com/apk/res-auto"
  178. xmlns:tools="http://schemas.android.com/tools"
  179. android:layout_width="match_parent"
  180. android:layout_height="match_parent"
  181. tools:context="com.programming.narvaez.narvalogin.SesionFragment">
  182.  
  183. <!-- TODO: Update blank fragment layout -->
  184. <TextView
  185. android:id="@+id/textView"
  186. android:layout_width="0dp"
  187. android:layout_height="0dp"
  188. android:text="@string/hello_blank_fragment"
  189. app:layout_constraintBottom_toBottomOf="parent"
  190. app:layout_constraintEnd_toEndOf="parent"
  191. app:layout_constraintHorizontal_bias="0.0"
  192. app:layout_constraintLeft_toLeftOf="parent"
  193. app:layout_constraintRight_toRightOf="parent"
  194. app:layout_constraintStart_toStartOf="parent"
  195. app:layout_constraintTop_toTopOf="parent"
  196. app:layout_constraintVertical_bias="0.0" />
  197.  
  198. <TextView
  199. android:id="@+id/textView2"
  200. android:layout_width="wrap_content"
  201. android:layout_height="wrap_content"
  202. android:layout_marginBottom="8dp"
  203. android:layout_marginEnd="8dp"
  204. android:layout_marginLeft="16dp"
  205. android:layout_marginStart="8dp"
  206. android:layout_marginTop="8dp"
  207. android:text="@string/user_fragment"
  208. android:textColor="@android:color/background_dark"
  209. android:textSize="20sp"
  210. app:layout_constraintBottom_toBottomOf="parent"
  211. app:layout_constraintEnd_toEndOf="parent"
  212. app:layout_constraintHorizontal_bias="0.103"
  213. app:layout_constraintLeft_toLeftOf="parent"
  214. app:layout_constraintStart_toStartOf="parent"
  215. app:layout_constraintTop_toTopOf="@+id/textView"
  216. app:layout_constraintVertical_bias="0.094" />
  217.  
  218. <TextView
  219. android:id="@+id/textView3"
  220. android:layout_width="wrap_content"
  221. android:layout_height="wrap_content"
  222. android:layout_marginBottom="8dp"
  223. android:layout_marginEnd="8dp"
  224. android:layout_marginLeft="16dp"
  225. android:layout_marginStart="8dp"
  226. android:layout_marginTop="8dp"
  227. android:text="@string/pwd_fragment"
  228. android:textColor="@android:color/background_dark"
  229. android:textSize="20sp"
  230. app:layout_constraintBottom_toBottomOf="parent"
  231. app:layout_constraintEnd_toEndOf="parent"
  232. app:layout_constraintHorizontal_bias="0.03"
  233. app:layout_constraintLeft_toLeftOf="parent"
  234. app:layout_constraintStart_toStartOf="parent"
  235. app:layout_constraintTop_toBottomOf="@+id/textView2"
  236. app:layout_constraintVertical_bias="0.077" />
  237.  
  238. <EditText
  239. android:id="@+id/txtuser"
  240. android:layout_width="wrap_content"
  241. android:layout_height="wrap_content"
  242. android:layout_marginBottom="8dp"
  243. android:layout_marginEnd="8dp"
  244. android:layout_marginStart="8dp"
  245. android:layout_marginTop="8dp"
  246. android:ems="10"
  247. android:inputType="textPersonName"
  248. app:layout_constraintBottom_toBottomOf="parent"
  249. app:layout_constraintEnd_toEndOf="parent"
  250. app:layout_constraintHorizontal_bias="0.275"
  251. app:layout_constraintStart_toEndOf="@+id/textView2"
  252. app:layout_constraintTop_toTopOf="parent"
  253. app:layout_constraintVertical_bias="0.055" />
  254.  
  255. <EditText
  256. android:id="@+id/txtpwd"
  257. android:layout_width="wrap_content"
  258. android:layout_height="wrap_content"
  259. android:layout_marginBottom="8dp"
  260. android:layout_marginEnd="8dp"
  261. android:layout_marginStart="8dp"
  262. android:layout_marginTop="8dp"
  263. android:ems="10"
  264. android:inputType="textPassword"
  265. app:layout_constraintBottom_toBottomOf="parent"
  266. app:layout_constraintEnd_toEndOf="parent"
  267. app:layout_constraintHorizontal_bias="0.81"
  268. app:layout_constraintStart_toStartOf="parent"
  269. app:layout_constraintTop_toBottomOf="@+id/txtuser"
  270. app:layout_constraintVertical_bias="0.021" />
  271.  
  272. <Button
  273. android:id="@+id/btnsesion"
  274. android:layout_width="wrap_content"
  275. android:layout_height="wrap_content"
  276. android:layout_marginBottom="232dp"
  277. android:layout_marginEnd="8dp"
  278. android:layout_marginStart="8dp"
  279. android:text="@string/sesion_fragment"
  280. app:layout_constraintBottom_toBottomOf="@+id/textView"
  281. app:layout_constraintEnd_toEndOf="@+id/textView"
  282. app:layout_constraintLeft_toLeftOf="parent"
  283. app:layout_constraintRight_toRightOf="parent"
  284. app:layout_constraintStart_toStartOf="parent" />
  285.  
  286. <Button
  287. android:id="@+id/btnregistrar"
  288. android:layout_width="wrap_content"
  289. android:layout_height="wrap_content"
  290. android:layout_marginBottom="8dp"
  291. android:layout_marginTop="8dp"
  292. android:text="@string/registrar_fragment"
  293. app:layout_constraintBottom_toBottomOf="parent"
  294. app:layout_constraintEnd_toEndOf="parent"
  295. app:layout_constraintLeft_toLeftOf="parent"
  296. app:layout_constraintRight_toRightOf="parent"
  297. app:layout_constraintStart_toStartOf="parent"
  298. app:layout_constraintTop_toBottomOf="@+id/btnsesion"
  299. app:layout_constraintVertical_bias="0.315" />
  300.  
  301. </android.support.constraint.ConstraintLayout>
  302.  
  303. import android.content.Intent;
  304. import android.os.Bundle;
  305. import android.support.v4.app.Fragment;
  306. import android.view.LayoutInflater;
  307. import android.view.View;
  308. import android.view.ViewGroup;
  309. import android.widget.Button;
  310. import android.widget.EditText;
  311. import android.widget.Toast;
  312. import com.android.volley.Request;
  313. import com.android.volley.RequestQueue;
  314. import com.android.volley.Response;
  315. import com.android.volley.VolleyError;
  316. import com.android.volley.toolbox.JsonObjectRequest;
  317. import com.android.volley.toolbox.JsonRequest;
  318. import com.android.volley.toolbox.Volley;
  319.  
  320. import org.json.JSONArray;
  321. import org.json.JSONException;
  322. import org.json.JSONObject;
  323.  
  324.  
  325. public class RegistrarFragment extends Fragment implements Response.Listener<JSONObject>, Response.ErrorListener {
  326. RequestQueue rq;
  327. JsonRequest jrq;
  328. EditText txtUser, txtPwd, txtNames;
  329. Button btnSesion, btnRegistrar;
  330.  
  331. @Override
  332. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  333. Bundle savedInstanceState) {
  334.  
  335. View vista = inflater.inflate(R.layout.fragment_registrar, container, false);
  336. txtUser = (EditText) vista.findViewById(R.id.txtuser);
  337. txtPwd = (EditText) vista.findViewById(R.id.txtpwd);
  338. txtNames= (EditText) vista.findViewById(R.id.txtnames);
  339.  
  340. btnSesion = (Button) vista.findViewById(R.id.btnsesion);
  341. btnRegistrar = (Button) vista.findViewById(R.id.btnregistrar);
  342. rq = Volley.newRequestQueue(getContext());
  343.  
  344. btnSesion.setOnClickListener(new View.OnClickListener() {
  345. @Override
  346. public void onClick(View view) {
  347. iniciar_sesion();
  348. }
  349. });
  350.  
  351. btnRegistrar.setOnClickListener(new View.OnClickListener() {
  352. @Override
  353. public void onClick(View view) {
  354. registrar_usuario();
  355. }
  356. });
  357.  
  358. // Inflate the layout for this fragment
  359. return vista;
  360. }
  361.  
  362. @Override
  363. public void onErrorResponse(VolleyError error) {
  364. Toast.makeText(getContext(), "No Se pudó registrar el usuario " +error.toString()+ txtUser.getText().toString(), Toast.LENGTH_LONG).show();
  365. }
  366.  
  367. @Override
  368. public void onResponse(JSONObject response) {
  369. Toast.makeText(getContext(), "Se ha registrado el usuario " + txtUser.getText().toString(), Toast.LENGTH_SHORT).show();
  370. limpiarCajas();
  371. }
  372.  
  373. void limpiarCajas() {
  374. txtNames.setText("");
  375. txtUser.setText("");
  376. txtPwd.setText("");
  377. }
  378. void iniciar_sesion() {
  379.  
  380. SesionFragment fr=new SesionFragment();
  381. //fr.setArguments(bn);
  382. getActivity().getSupportFragmentManager().beginTransaction()
  383. .replace(R.id.escenario,fr)
  384. .addToBackStack(null)
  385. .commit();
  386. }
  387.  
  388. void registrar_usuario(){
  389. //192.168.1.66(172.29.243.3
  390. String url = "http://192.168.1.66/login/registrar.php?names=" +txtNames.getText().toString()+"&user="+ txtUser.getText().toString() +
  391. "&pwd=" + txtPwd.getText().toString();
  392.  
  393. jrq = new JsonObjectRequest(Request.Method.GET, url, null, this, this);
  394. rq.add(jrq);
  395. }
  396. }
  397.  
  398. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  399. xmlns:app="http://schemas.android.com/apk/res-auto"
  400. xmlns:tools="http://schemas.android.com/tools"
  401. android:layout_width="match_parent"
  402. android:layout_height="match_parent"
  403. tools:context="com.programming.narvaez.narvalogin.SesionFragment">
  404.  
  405. <!-- TODO: Update blank fragment layout -->
  406.  
  407. <TextView
  408. android:id="@+id/textView2"
  409. android:layout_width="wrap_content"
  410. android:layout_height="wrap_content"
  411. android:layout_marginBottom="8dp"
  412. android:layout_marginEnd="8dp"
  413. android:layout_marginLeft="16dp"
  414. android:layout_marginStart="8dp"
  415. android:layout_marginTop="8dp"
  416. android:text="@string/user_fragment"
  417. android:textColor="@android:color/background_dark"
  418. android:textSize="20sp"
  419. app:layout_constraintBottom_toBottomOf="parent"
  420. app:layout_constraintEnd_toEndOf="parent"
  421. app:layout_constraintHorizontal_bias="0.153"
  422. app:layout_constraintLeft_toLeftOf="parent"
  423. app:layout_constraintStart_toStartOf="parent"
  424. app:layout_constraintTop_toTopOf="parent"
  425. app:layout_constraintVertical_bias="0.267" />
  426.  
  427. <EditText
  428. android:id="@+id/txtuser"
  429. android:layout_width="wrap_content"
  430. android:layout_height="wrap_content"
  431. android:layout_marginBottom="8dp"
  432. android:layout_marginEnd="8dp"
  433. android:layout_marginRight="16dp"
  434. android:layout_marginStart="8dp"
  435. android:layout_marginTop="8dp"
  436. android:ems="10"
  437. android:inputType="textPersonName"
  438. app:layout_constraintBottom_toBottomOf="parent"
  439. app:layout_constraintEnd_toEndOf="parent"
  440. app:layout_constraintHorizontal_bias="0.947"
  441. app:layout_constraintRight_toRightOf="parent"
  442. app:layout_constraintStart_toStartOf="parent"
  443. app:layout_constraintTop_toTopOf="parent"
  444. app:layout_constraintVertical_bias="0.236" />
  445.  
  446. <TextView
  447. android:id="@+id/textView3"
  448. android:layout_width="wrap_content"
  449. android:layout_height="wrap_content"
  450. android:layout_marginBottom="8dp"
  451. android:layout_marginEnd="8dp"
  452. android:layout_marginLeft="16dp"
  453. android:layout_marginStart="8dp"
  454. android:layout_marginTop="8dp"
  455. android:text="@string/pwd_fragment"
  456. android:textColor="@android:color/background_dark"
  457. android:textSize="20sp"
  458. app:layout_constraintBottom_toBottomOf="parent"
  459. app:layout_constraintEnd_toEndOf="parent"
  460. app:layout_constraintHorizontal_bias="0.123"
  461. app:layout_constraintLeft_toLeftOf="parent"
  462. app:layout_constraintStart_toStartOf="parent"
  463. app:layout_constraintTop_toTopOf="parent"
  464. app:layout_constraintVertical_bias="0.416" />
  465.  
  466. <EditText
  467. android:id="@+id/txtpwd"
  468. android:layout_width="wrap_content"
  469. android:layout_height="wrap_content"
  470. android:layout_marginBottom="8dp"
  471. android:layout_marginEnd="8dp"
  472. android:layout_marginRight="16dp"
  473. android:layout_marginStart="8dp"
  474. android:layout_marginTop="8dp"
  475. android:ems="10"
  476. android:inputType="textPassword"
  477. app:layout_constraintBottom_toBottomOf="parent"
  478. app:layout_constraintEnd_toEndOf="parent"
  479. app:layout_constraintHorizontal_bias="1.0"
  480. app:layout_constraintRight_toRightOf="parent"
  481. app:layout_constraintStart_toStartOf="parent"
  482. app:layout_constraintTop_toTopOf="parent"
  483. app:layout_constraintVertical_bias="0.407" />
  484.  
  485. <Button
  486. android:id="@+id/btnsesion"
  487. android:layout_width="123dp"
  488. android:layout_height="50dp"
  489. android:layout_marginBottom="8dp"
  490. android:layout_marginStart="128dp"
  491. android:layout_marginTop="8dp"
  492. android:text="@string/sesion_fragment"
  493. app:layout_constraintBottom_toBottomOf="parent"
  494. app:layout_constraintLeft_toLeftOf="parent"
  495. app:layout_constraintRight_toRightOf="parent"
  496. app:layout_constraintStart_toStartOf="parent"
  497. app:layout_constraintTop_toTopOf="parent"
  498. app:layout_constraintVertical_bias="0.721" />
  499.  
  500. <Button
  501. android:id="@+id/btnregistrar"
  502. android:layout_width="wrap_content"
  503. android:layout_height="wrap_content"
  504. android:layout_marginBottom="8dp"
  505. android:layout_marginTop="8dp"
  506. android:text="@string/registrar_fragment"
  507. app:layout_constraintBottom_toBottomOf="parent"
  508. app:layout_constraintEnd_toEndOf="parent"
  509. app:layout_constraintHorizontal_bias="0.502"
  510. app:layout_constraintLeft_toLeftOf="parent"
  511. app:layout_constraintRight_toRightOf="parent"
  512. app:layout_constraintStart_toStartOf="parent"
  513. app:layout_constraintTop_toTopOf="parent"
  514. app:layout_constraintVertical_bias="0.577" />
  515.  
  516. <TextView
  517. android:id="@+id/textView4"
  518. android:layout_width="wrap_content"
  519. android:layout_height="wrap_content"
  520. android:layout_marginBottom="8dp"
  521. android:layout_marginEnd="24dp"
  522. android:layout_marginLeft="16dp"
  523. android:layout_marginTop="8dp"
  524. android:text="@string/names_fragment"
  525. android:textColor="@android:color/background_dark"
  526. android:textSize="22sp"
  527. app:layout_constraintBottom_toBottomOf="parent"
  528. app:layout_constraintEnd_toStartOf="@+id/txtnames"
  529. app:layout_constraintLeft_toLeftOf="parent"
  530. app:layout_constraintTop_toTopOf="parent"
  531. app:layout_constraintVertical_bias="0.131"
  532. tools:text="@string/names_fragment" />
  533.  
  534. <EditText
  535. android:id="@+id/txtnames"
  536. android:layout_width="wrap_content"
  537. android:layout_height="wrap_content"
  538. android:layout_marginBottom="8dp"
  539. android:layout_marginEnd="8dp"
  540. android:layout_marginRight="16dp"
  541. android:layout_marginStart="8dp"
  542. android:layout_marginTop="8dp"
  543. android:ems="10"
  544. android:inputType="textPersonName"
  545. app:layout_constraintBottom_toBottomOf="parent"
  546. app:layout_constraintEnd_toEndOf="parent"
  547. app:layout_constraintHorizontal_bias="0.947"
  548. app:layout_constraintRight_toRightOf="parent"
  549. app:layout_constraintStart_toStartOf="parent"
  550. app:layout_constraintTop_toTopOf="parent"
  551. app:layout_constraintVertical_bias="0.1" />
  552.  
  553. <TextView
  554. android:id="@+id/textView5"
  555. android:layout_width="wrap_content"
  556. android:layout_height="wrap_content"
  557. android:layout_marginBottom="8dp"
  558. android:layout_marginTop="8dp"
  559. android:text="@string/registrar_fragment"
  560. android:textColor="@color/colorPrimary"
  561. android:textSize="24sp"
  562. app:layout_constraintBottom_toBottomOf="parent"
  563. app:layout_constraintEnd_toEndOf="parent"
  564. app:layout_constraintLeft_toLeftOf="parent"
  565. app:layout_constraintRight_toRightOf="parent"
  566. app:layout_constraintStart_toStartOf="parent"
  567. app:layout_constraintTop_toTopOf="parent"
  568. app:layout_constraintVertical_bias="0.016" />
  569.  
  570. </android.support.constraint.ConstraintLayout>
  571.  
  572. /**
  573. * Created by NARVAEZ on 17/05/2018.
  574. */
  575.  
  576. public class User {
  577. private String names, user, pwd;
  578.  
  579. public String getNames() {
  580. return names;
  581. }
  582.  
  583. public void setNames(String names) {
  584. this.names = names;
  585. }
  586.  
  587. public String getUser() {
  588. return user;
  589. }
  590.  
  591. public void setUser(String user) {
  592. this.user = user;
  593. }
  594.  
  595. public String getPwd() {
  596. return pwd;
  597. }
  598.  
  599. public void setPwd(String pwd) {
  600. this.pwd = pwd;
  601. }
  602. }
  603.  
  604. <resources>
  605. <string name="app_name">Narváez Sesión</string>
  606.  
  607. <!-- TODO: Remove or change this placeholder text -->
  608. <string name="hello_blank_fragment">Inicio de Sesión</string>
  609. <string name="user_fragment">Usuario:</string>
  610. <string name="pwd_fragment">Contraseña:</string>
  611. <string name="sesion_fragment">Inciar Sesión</string>
  612. <string name="registrar_fragment">Registrar usuario</string>
  613. <string name="names_fragment">Nombres: </string>
  614.  
  615. </resources>
  616.  
  617. compile 'com.android.volley:volley:1.1.0'
  618.  
  619. configurations.all {
  620. resolutionStrategy.force 'com.android.support:support-annotations:23.1.0'
  621. }
  622.  
  623. <uses-permission android:name="android.permission.INTERNET"/>
  624.  
  625. <?PHP
  626. $hostname="localhost";
  627. $database="tu_bd";
  628. $username="root";
  629. $password="";
  630. $json=array();
  631. if(isset($_GET["names"])&&($_GET["user"]) && isset($_GET["pwd"])){
  632. $names=$_GET['names']
  633. $user=$_GET['user'];
  634. $pwd=$_GET['pwd'];
  635.  
  636. $conexion=mysqli_connect($hostname,$username,$password,$database);
  637.  
  638. $consulta="INSERT INTO usuarios(names, user, pwd) VALUES ('{$names}','{$user}' , '{$pwd}')";
  639. $resultado=mysqli_query($conexion,$consulta);
  640.  
  641. if($consulta){
  642. $consulta="SELECT * FROM usuarios WHERE names='{$names}'";
  643. $resultado=mysqli_query($conexion,$consulta);
  644.  
  645. if($reg=mysqli_fetch_array($resultado)){
  646. $json['datos'][]=$reg;
  647. }
  648. mysqli_close($conexion);
  649. echo json_encode($json);
  650. }
  651.  
  652. else{
  653. $results["names"]='';
  654. $results["user"]='';
  655. $results["pwd"]='';
  656. $json['datos'][]=$results;
  657. echo json_encode($json);
  658. }
  659.  
  660. }
  661. else{
  662. $results["names"]='';
  663. $results["user"]='';
  664. $results["pwd"]='';
  665. $json['datos'][]=$results;
  666. echo json_encode($json);
  667. }
  668. ?>
Add Comment
Please, Sign In to add comment