Guest User

Untitled

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