├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── ic_launcher-web.png
│ │ ├── res
│ │ │ ├── drawable-hdpi
│ │ │ │ ├── ic_edit.png
│ │ │ │ ├── ic_email.png
│ │ │ │ ├── ic_person.png
│ │ │ │ ├── ic_phone.png
│ │ │ │ ├── ic_birthday.png
│ │ │ │ ├── ic_business.png
│ │ │ │ ├── ic_cellphone.png
│ │ │ │ ├── ic_location.png
│ │ │ │ ├── ic_person_add.png
│ │ │ │ ├── ic_arrow_drop_down.png
│ │ │ │ └── ic_delete_forever_black_24dp.png
│ │ │ ├── drawable-mdpi
│ │ │ │ ├── ic_edit.png
│ │ │ │ ├── ic_email.png
│ │ │ │ ├── ic_person.png
│ │ │ │ ├── ic_phone.png
│ │ │ │ ├── ic_birthday.png
│ │ │ │ ├── ic_business.png
│ │ │ │ ├── ic_cellphone.png
│ │ │ │ ├── ic_location.png
│ │ │ │ ├── ic_person_add.png
│ │ │ │ ├── ic_arrow_drop_down.png
│ │ │ │ └── ic_delete_forever_black_24dp.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── ic_edit.png
│ │ │ │ ├── ic_email.png
│ │ │ │ ├── ic_person.png
│ │ │ │ ├── ic_phone.png
│ │ │ │ ├── ic_birthday.png
│ │ │ │ ├── ic_business.png
│ │ │ │ ├── ic_location.png
│ │ │ │ ├── ic_cellphone.png
│ │ │ │ ├── ic_person_add.png
│ │ │ │ ├── ic_arrow_drop_down.png
│ │ │ │ └── ic_delete_forever_black_24dp.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── ic_edit.png
│ │ │ │ ├── ic_email.png
│ │ │ │ ├── ic_phone.png
│ │ │ │ ├── ic_person.png
│ │ │ │ ├── ic_birthday.png
│ │ │ │ ├── ic_business.png
│ │ │ │ ├── ic_cellphone.png
│ │ │ │ ├── ic_location.png
│ │ │ │ ├── ic_person_add.png
│ │ │ │ ├── ic_arrow_drop_down.png
│ │ │ │ └── ic_delete_forever_black_24dp.png
│ │ │ ├── drawable-xxxhdpi
│ │ │ │ ├── ic_edit.png
│ │ │ │ ├── ic_email.png
│ │ │ │ ├── ic_person.png
│ │ │ │ ├── ic_phone.png
│ │ │ │ ├── ic_birthday.png
│ │ │ │ ├── ic_business.png
│ │ │ │ ├── ic_cellphone.png
│ │ │ │ ├── ic_location.png
│ │ │ │ ├── ic_person_add.png
│ │ │ │ ├── ic_arrow_drop_down.png
│ │ │ │ └── ic_delete_forever_black_24dp.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── arrays.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ └── layout
│ │ │ │ ├── activity_cliente_lista_item.xml
│ │ │ │ ├── activity_cliente_lista.xml
│ │ │ │ └── activity_cliente_agregar.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── jmarkstar
│ │ │ │ └── sesion4
│ │ │ │ ├── util
│ │ │ │ ├── Constants.java
│ │ │ │ └── StringUtils.java
│ │ │ │ ├── adapters
│ │ │ │ └── ClienteAdapter.java
│ │ │ │ ├── database
│ │ │ │ ├── Sesion4DatabaseHelper.java
│ │ │ │ └── dao
│ │ │ │ │ └── ClienteDao.java
│ │ │ │ ├── activities
│ │ │ │ ├── ClienteListaActivity.java
│ │ │ │ └── ClienteAgregarActivity.java
│ │ │ │ └── model
│ │ │ │ └── ClienteModel.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── jmarkstar
│ │ │ └── sesion4
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── jmarkstar
│ │ └── sesion4
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | *.iml
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | .idea
4 | /local.properties
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-hdpi/ic_edit.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-mdpi/ic_edit.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_email.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-hdpi/ic_email.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_person.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-hdpi/ic_person.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_phone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-hdpi/ic_phone.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_email.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-mdpi/ic_email.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_person.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-mdpi/ic_person.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_phone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-mdpi/ic_phone.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xhdpi/ic_edit.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_email.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xhdpi/ic_email.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_person.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xhdpi/ic_person.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_phone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xhdpi/ic_phone.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxhdpi/ic_edit.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_email.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxhdpi/ic_email.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_phone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxhdpi/ic_phone.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxxhdpi/ic_edit.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_birthday.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-hdpi/ic_birthday.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_business.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-hdpi/ic_business.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_cellphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-hdpi/ic_cellphone.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_location.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-hdpi/ic_location.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_birthday.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-mdpi/ic_birthday.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_business.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-mdpi/ic_business.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_cellphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-mdpi/ic_cellphone.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_location.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-mdpi/ic_location.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_birthday.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xhdpi/ic_birthday.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_business.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xhdpi/ic_business.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_location.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xhdpi/ic_location.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_person.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxhdpi/ic_person.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_email.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxxhdpi/ic_email.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_person.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxxhdpi/ic_person.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_phone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxxhdpi/ic_phone.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_person_add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-hdpi/ic_person_add.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_person_add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-mdpi/ic_person_add.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_cellphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xhdpi/ic_cellphone.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_person_add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xhdpi/ic_person_add.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_birthday.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxhdpi/ic_birthday.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_business.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxhdpi/ic_business.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_cellphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxhdpi/ic_cellphone.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_location.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxhdpi/ic_location.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_person_add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxhdpi/ic_person_add.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_birthday.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxxhdpi/ic_birthday.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_business.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxxhdpi/ic_business.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_cellphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxxhdpi/ic_cellphone.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_location.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxxhdpi/ic_location.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_person_add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxxhdpi/ic_person_add.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_arrow_drop_down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-hdpi/ic_arrow_drop_down.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_arrow_drop_down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-mdpi/ic_arrow_drop_down.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_arrow_drop_down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xhdpi/ic_arrow_drop_down.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_arrow_drop_down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxhdpi/ic_arrow_drop_down.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_arrow_drop_down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxxhdpi/ic_arrow_drop_down.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_delete_forever_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-hdpi/ic_delete_forever_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_delete_forever_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-mdpi/ic_delete_forever_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_delete_forever_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xhdpi/ic_delete_forever_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_delete_forever_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxhdpi/ic_delete_forever_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_delete_forever_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmarkstar/SQLiteNativo/HEAD/app/src/main/res/drawable-xxxhdpi/ic_delete_forever_black_24dp.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Sesion4
2 | Este proyecto es un App que básicamente usa la base de datos SQLite para poder crear un mantenimiento, brinda la introducción a SQLiteOpenHelper, Adapters y algunos componentes UI utiles para comenzar en android.
3 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jmarkstar/sesion4/util/Constants.java:
--------------------------------------------------------------------------------
1 | package com.jmarkstar.sesion4.util;
2 |
3 | /**
4 | * Created by Lenovo on 13/05/2017.
5 | */
6 |
7 | public class Constants {
8 |
9 | public static final String EMPTY = "";
10 | }
11 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed May 10 15:11:29 PET 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #FFFFFF
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jmarkstar/sesion4/util/StringUtils.java:
--------------------------------------------------------------------------------
1 | package com.jmarkstar.sesion4.util;
2 |
3 | /**
4 | * Created by jmarkstar on 12/05/2017.
5 | */
6 |
7 | public class StringUtils {
8 |
9 | public static boolean validarFormatoEmail(String email){
10 | return email.matches("[a-zA-Z0-9._-]+@[a-z]+.[a-z]+");
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | - Seleccione Empresa
5 | - Claro Peru
6 | - Telefonica
7 | - Interbank
8 | - BCP
9 | - Profuturo
10 | - Ford
11 | - Cineplanet
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/jmarkstar/sesion4/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.jmarkstar.sesion4;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/jmarkstar/sesion4/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.jmarkstar.sesion4;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.jmarkstar.sesion4", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/jmarkstar/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.jmarkstar.sesion4"
8 | minSdkVersion 16
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 |
28 |
29 | compile 'com.android.support:appcompat-v7:25.3.1'
30 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
31 | compile 'com.jakewharton:butterknife:8.5.1'
32 | testCompile 'junit:junit:4.12'
33 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_cliente_lista_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
25 |
26 |
34 |
35 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_cliente_lista.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
25 |
26 |
32 |
33 |
34 |
35 |
39 |
40 |
43 |
44 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jmarkstar/sesion4/adapters/ClienteAdapter.java:
--------------------------------------------------------------------------------
1 | package com.jmarkstar.sesion4.adapters;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.support.annotation.NonNull;
6 | import android.support.annotation.Nullable;
7 | import android.util.Log;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.ArrayAdapter;
12 | import android.widget.ImageView;
13 | import android.widget.TextView;
14 | import com.jmarkstar.sesion4.R;
15 | import com.jmarkstar.sesion4.activities.ClienteAgregarActivity;
16 | import com.jmarkstar.sesion4.model.ClienteModel;
17 | import java.util.List;
18 |
19 | /**
20 | * Created by jmarkstar on 13/05/2017.
21 | */
22 | public class ClienteAdapter extends ArrayAdapter {
23 |
24 | private static final String TAG = "ClienteAdapter";
25 |
26 | public ClienteAdapter(@NonNull Context context, @NonNull List objects) {
27 | super(context, 0, objects);
28 | }
29 |
30 | @NonNull
31 | @Override
32 | public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
33 | ClienteModel cliente = getItem(position);
34 | Log.d(TAG, "cliente = "+cliente.toString());
35 |
36 | if(convertView == null){
37 | convertView = LayoutInflater.from(getContext()).inflate(R.layout.activity_cliente_lista_item, parent, false);
38 | }
39 |
40 | TextView tvEmpresa = (TextView)convertView.findViewById(R.id.tv_empresa_cliente);
41 | TextView tvTelefono = (TextView)convertView.findViewById(R.id.tv_telefono);
42 | TextView tvNombreCompleto = (TextView)convertView.findViewById(R.id.tv_nombre_completo);
43 |
44 | ImageView ivEdit = (ImageView)convertView.findViewById(R.id.iv_edit);
45 | ivEdit.setTag(position);
46 |
47 | ivEdit.setOnClickListener(new View.OnClickListener() {
48 | @Override public void onClick(View v) {
49 | Integer position = (Integer)v.getTag();
50 | Log.v("adapter", "position = "+position);
51 | ClienteModel cliente = getItem(position);
52 | Intent intent = new Intent(getContext(), ClienteAgregarActivity.class);
53 | intent.putExtra(ClienteAgregarActivity.CLIENTE, cliente);
54 | getContext().startActivity(intent);
55 | }
56 | });
57 |
58 | //Para obtener el nombre de la empresa que el usuario ha selecionado antes, tenemos que buscarlo en el array xml.
59 | String [] empresasArray = getContext().getResources().getStringArray(R.array.empresas_clientes);
60 |
61 | tvEmpresa.setText(empresasArray[cliente.getIdEmpresaCliente()]);
62 | tvTelefono.setText(cliente.getTelefono());
63 | tvNombreCompleto.setText(cliente.getNombreCompleto());
64 |
65 | return convertView;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Sesion 4
3 | Aún no tienes clientes.
4 | Agregar
5 | El registro fue eliminado correctamente.
6 | Ocurrió un problema al eliminar el registro.
7 | Lista de Clientes
8 | Desea eliminar este registro?
9 |
10 | Dirección
11 | Celular
12 | Registrar
13 | Tiene Hijos?
14 | Divorsiado
15 | Viudo
16 | Casado
17 | Soltero
18 | Estado Civil
19 | Cumpleaños
20 | Nombre Completo
21 | Email
22 | Telefono
23 | Debes ingresar el nombre completo del cliente.
24 | Debes ingresar el email del cliente.
25 | El email es incorrecto.
26 | Debes ingresar el telefono del cliente.
27 | El telefono es incorrecto.
28 | Debes ingresar la dirección del cliente.
29 | Debes seleccionar un estado civil.
30 | Debes selecionar el cumpleaños del cliente.
31 | El cliente se guardó correctamente.
32 | Ocurrio un error al guardar el registro.
33 | Debes selecionar una Empresa.
34 | Agregar Cliente
35 |
36 | Editar Cliente
37 | Ocurrio un error al editar el registro.
38 | El cliente se editó correctamente.
39 |
40 | ACEPTAR
41 | CANCELAR
42 | Registrar
43 | Editar
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jmarkstar/sesion4/database/Sesion4DatabaseHelper.java:
--------------------------------------------------------------------------------
1 | package com.jmarkstar.sesion4.database;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 | import android.database.sqlite.SQLiteOpenHelper;
6 | import com.jmarkstar.sesion4.model.ClienteModel;
7 |
8 | /** Esta clase que extiende de la clase {SQLiteOpenHelper} es el encargado de crear y acceder
9 | * a la base de datos SQLite.
10 | *
11 | * Created by jmarkstar on 11/05/2017.
12 | */
13 | public class Sesion4DatabaseHelper extends SQLiteOpenHelper {
14 |
15 | private static final String DB_NAME = "mydb.db";
16 | private static final Integer DB_VERSION = 1;
17 |
18 | private final StringBuffer SQL_CREATE_TABLE_CLIENTE = new StringBuffer()
19 | .append("CREATE TABLE IF NOT EXISTS "+ ClienteModel.TABLE_NAME+" ( ")
20 | .append(ClienteModel.ID_FIELD+" INTEGER PRIMARY KEY AUTOINCREMENT, ")
21 | .append(ClienteModel.NOMBRE_FIELD+" TEXT, ")
22 | .append(ClienteModel.EMAIL_FIELD+" TEXT, ")
23 | .append(ClienteModel.TELEFONO_FIELD+" TEXT, ")
24 | .append(ClienteModel.DIRECCION_FIELD+" TEXT, ")
25 | .append(ClienteModel.ID_EMPRESA_FIELD+" INTEGER, ")
26 | .append(ClienteModel.FECHA_NAC_FIELD+" TEXT, ")
27 | .append(ClienteModel.ID_ESTADO_CIVIL_FIELD+" INTEGER, ")
28 | .append(ClienteModel.TIENE_HIJOS_FIELD+" INTEGER ")
29 | .append(")");
30 |
31 | private final StringBuffer SQL_DELETE_TABLE_CLIENTE = new StringBuffer()
32 | .append("DROP TABLE IF EXISTS " + ClienteModel.TABLE_NAME);
33 |
34 | public Sesion4DatabaseHelper(Context context){
35 | super(context, DB_NAME, null, DB_VERSION);
36 | }
37 |
38 | /** EL metodo es ejecutado cuando se va crear por primera vez la Base de datos,
39 | * Aquí, podríamos poner algunas sentencias SQL como crear tablas, insertar algunos datos
40 | * iniciales a algunas tablas, entre otra cosas.
41 | * */
42 | @Override public void onCreate(SQLiteDatabase db) {
43 |
44 | //El metodo execSQL() de la clase SQLiteDatabase ejecuta cualquier sentencia SQL.
45 | //recibe como parametro un String.
46 |
47 | db.execSQL(SQL_CREATE_TABLE_CLIENTE.toString());
48 | }
49 |
50 | /** Si por ejemplo, tenemos en el google play nuetro app con la version de base de datos 1, y un futuro cercano
51 | * lo actualizamos y en nuestra actualización tambien modificamos nuestra base de datos.
52 | * Entonces tenemos que aumentar la versión a la DB en la variable {DB_VERSION}, En ese momento, cuando el usuario actualize la version
53 | * de su app, el metodo pasará por aquí, ya no por onCreate(). Por eso, en este metodo debemos hacer cosas como eliminar las tables y volverlos
54 | * a crear, entre otras cosas.
55 | * */
56 | @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
57 |
58 | //Elimina la tabla
59 | db.execSQL(SQL_DELETE_TABLE_CLIENTE.toString());
60 |
61 | //llamammos al metodo onCreate() para ejecutar su contenido que en este caso es crear la tabla cliente.
62 | onCreate(db);
63 | }
64 |
65 | @Override
66 | public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
67 | super.onDowngrade(db, oldVersion, newVersion);
68 |
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jmarkstar/sesion4/activities/ClienteListaActivity.java:
--------------------------------------------------------------------------------
1 | package com.jmarkstar.sesion4.activities;
2 |
3 | import android.content.DialogInterface;
4 | import android.content.Intent;
5 | import android.support.v7.app.AlertDialog;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.os.Bundle;
8 | import android.view.View;
9 | import android.widget.AdapterView;
10 | import android.widget.ListView;
11 | import android.widget.TextView;
12 | import android.widget.Toast;
13 | import com.jmarkstar.sesion4.R;
14 | import com.jmarkstar.sesion4.adapters.ClienteAdapter;
15 | import com.jmarkstar.sesion4.database.dao.ClienteDao;
16 | import com.jmarkstar.sesion4.model.ClienteModel;
17 | import java.util.List;
18 | import butterknife.BindView;
19 | import butterknife.ButterKnife;
20 | import butterknife.OnClick;
21 |
22 | public class ClienteListaActivity extends AppCompatActivity
23 | implements AdapterView.OnItemClickListener{
24 |
25 | @BindView(R.id.lv_lista_clientes) ListView mLvClientes;
26 | @BindView(R.id.tv_mensaje_vacio) TextView mTvListaVacia;
27 | @BindView(R.id.tv_cantidad_lista) TextView mTvCantidadLista;
28 |
29 | private ClienteDao mClienteDao;
30 | private ClienteAdapter mClienteAdapter;
31 | private List mClientes;
32 |
33 | @Override protected void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | setContentView(R.layout.activity_cliente_lista);
36 | ButterKnife.bind(this);
37 |
38 | //agregando titulo a la pantalla
39 | setTitle(getString(R.string.lista_titulo));
40 |
41 | mClienteDao = new ClienteDao(this);
42 |
43 | //pasandole el evento onItemClick de nuestro activity al listview.
44 | mLvClientes.setOnItemClickListener(this);
45 | }
46 |
47 | @Override protected void onResume() {
48 | super.onResume();
49 | mClientes = mClienteDao.getClientes();
50 | if(mClientes.size() > 0){
51 | mLvClientes.setVisibility(View.VISIBLE);
52 | mTvCantidadLista.setVisibility(View.VISIBLE);
53 | mTvListaVacia.setVisibility(View.GONE);
54 | mClienteAdapter = new ClienteAdapter(this, mClientes);
55 | mLvClientes.setAdapter(mClienteAdapter);
56 | mTvCantidadLista.setText("Tienes "+mClientes.size()+" items");
57 | }else{
58 | mLvClientes.setVisibility(View.GONE);
59 | mTvCantidadLista.setVisibility(View.GONE);
60 | mTvListaVacia.setVisibility(View.VISIBLE);
61 | }
62 | }
63 |
64 | @OnClick(R.id.btn_agregar) public void onAgregar(){
65 | Intent intent = new Intent(this, ClienteAgregarActivity.class);
66 | startActivity(intent);
67 | }
68 |
69 | @Override public void onItemClick(AdapterView> parent, View view, final int position, long id) {
70 | final ClienteModel cliente = mClientes.get(position);
71 | AlertDialog.Builder alert = new AlertDialog.Builder(ClienteListaActivity.this);
72 | alert.setTitle(R.string.app_name);
73 | alert.setMessage(R.string.lista_dialog_eliminar_msj);
74 | alert.setPositiveButton(R.string.dialog_aceptar, new DialogInterface.OnClickListener() {
75 |
76 | @Override public void onClick(DialogInterface dialog, int which) {
77 | int success = mClienteDao.eliminarCliente(cliente.getId());
78 | if(success != 0){
79 | mostrarMensaje(getString(R.string.lista_eliminar_correcto));
80 | mClientes.remove(position);
81 |
82 | if(mClientes.size()>0){
83 | //nos permite refrescar el adapter oor hemos eliminado un dato.
84 | mClienteAdapter.notifyDataSetChanged();
85 | mTvCantidadLista.setText("Tienes "+mClientes.size()+" items");
86 | mLvClientes.setVisibility(View.VISIBLE);
87 | mTvListaVacia.setVisibility(View.VISIBLE);
88 | mTvListaVacia.setVisibility(View.GONE);
89 | }else{
90 | mLvClientes.setVisibility(View.GONE);
91 | mTvCantidadLista.setVisibility(View.GONE);
92 | mTvListaVacia.setVisibility(View.VISIBLE);
93 | }
94 | }else{
95 | mostrarMensaje(getString(R.string.lista_eliminar_error));
96 | }
97 | dialog.dismiss();
98 | }
99 | });
100 | alert.setNegativeButton(R.string.dialog_cancelar, new DialogInterface.OnClickListener() {
101 |
102 | @Override public void onClick(DialogInterface dialog, int which) {
103 | dialog.dismiss();
104 | }
105 | });
106 | alert.show();
107 | }
108 |
109 | /** Este metodo mostrará en mensaje al usuario.
110 | * @param mensaje texto a mostrar.
111 | * */
112 | private void mostrarMensaje(String mensaje){
113 | Toast.makeText(this, mensaje, Toast.LENGTH_SHORT).show();
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jmarkstar/sesion4/model/ClienteModel.java:
--------------------------------------------------------------------------------
1 | package com.jmarkstar.sesion4.model;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | /**
7 | * Podemos usar Parcelable o Serializable para poder pasar datos entre activities.
8 | *
9 | * Created by jmarkstar on 11/05/2017.
10 | */
11 | public class ClienteModel implements Parcelable {
12 |
13 | public static final String TABLE_NAME = "cliente";
14 | public static final String ID_FIELD = "id";
15 | public static final String NOMBRE_FIELD = "nombre_completo";
16 | public static final String EMAIL_FIELD = "email";
17 | public static final String TELEFONO_FIELD = "telefono";
18 | public static final String DIRECCION_FIELD = "direccion";
19 | public static final String ID_EMPRESA_FIELD = "id_empresa";
20 | public static final String FECHA_NAC_FIELD = "fecha_nac";
21 | public static final String ID_ESTADO_CIVIL_FIELD = "id_estado_civil";
22 | public static final String TIENE_HIJOS_FIELD = "tiene_hijos";
23 |
24 | private Integer id;
25 | private String nombreCompleto;
26 | private String email;
27 | private String telefono;
28 | private String direccion;
29 | private Integer idEmpresaCliente;
30 | private String fechNacimiento;
31 | private Integer idEstadoCivil;
32 | private Boolean tieneHijos;
33 |
34 | public Integer getId() {
35 | return id;
36 | }
37 |
38 | public void setId(Integer id) {
39 | this.id = id;
40 | }
41 |
42 | public String getNombreCompleto() {
43 | return nombreCompleto;
44 | }
45 |
46 | public void setNombreCompleto(String nombreCompleto) {
47 | this.nombreCompleto = nombreCompleto;
48 | }
49 |
50 | public String getEmail() {
51 | return email;
52 | }
53 |
54 | public void setEmail(String email) {
55 | this.email = email;
56 | }
57 |
58 | public String getTelefono() {
59 | return telefono;
60 | }
61 |
62 | public void setTelefono(String telefono) {
63 | this.telefono = telefono;
64 | }
65 |
66 | public String getDireccion() {
67 | return direccion;
68 | }
69 |
70 | public void setDireccion(String direccion) {
71 | this.direccion = direccion;
72 | }
73 |
74 | public Integer getIdEmpresaCliente() {
75 | return idEmpresaCliente;
76 | }
77 |
78 | public void setIdEmpresaCliente(Integer idEmpresaCliente) {
79 | this.idEmpresaCliente = idEmpresaCliente;
80 | }
81 |
82 | public String getFechNacimiento() {
83 | return fechNacimiento;
84 | }
85 |
86 | public void setFechNacimiento(String fechNacimiento) {
87 | this.fechNacimiento = fechNacimiento;
88 | }
89 |
90 | public Integer getIdEstadoCivil() {
91 | return idEstadoCivil;
92 | }
93 |
94 | public void setIdEstadoCivil(Integer idEstadoCivil) {
95 | this.idEstadoCivil = idEstadoCivil;
96 | }
97 |
98 | public Boolean getTieneHijos() {
99 | return tieneHijos;
100 | }
101 |
102 | public void setTieneHijos(Boolean tieneHijos) {
103 | this.tieneHijos = tieneHijos;
104 | }
105 |
106 | @Override
107 | public String toString() {
108 | return "ClienteModel{" +
109 | "id=" + id +
110 | ", nombreCompleto='" + nombreCompleto + '\'' +
111 | ", email='" + email + '\'' +
112 | ", telefono='" + telefono + '\'' +
113 | ", direccion='" + direccion + '\'' +
114 | ", idEmpresaCliente=" + idEmpresaCliente +
115 | ", fechNacimiento='" + fechNacimiento + '\'' +
116 | ", idEstadoCivil=" + idEstadoCivil +
117 | ", tieneHijos=" + tieneHijos +
118 | '}';
119 | }
120 |
121 | //METODO PARCELABLE
122 |
123 | @Override public int describeContents() {
124 | return 0;
125 | }
126 |
127 | @Override public void writeToParcel(Parcel destino, int flags) {
128 | destino.writeValue(this.id);
129 | destino.writeString(this.nombreCompleto);
130 | destino.writeString(this.email);
131 | destino.writeString(this.telefono);
132 | destino.writeString(this.direccion);
133 | destino.writeValue(this.idEmpresaCliente);
134 | destino.writeString(this.fechNacimiento);
135 | destino.writeValue(this.idEstadoCivil);
136 | destino.writeValue(this.tieneHijos);
137 | }
138 |
139 | public ClienteModel() {
140 | }
141 |
142 | protected ClienteModel(Parcel in) {
143 | this.id = (Integer) in.readValue(Integer.class.getClassLoader());
144 | this.nombreCompleto = in.readString();
145 | this.email = in.readString();
146 | this.telefono = in.readString();
147 | this.direccion = in.readString();
148 | this.idEmpresaCliente = (Integer) in.readValue(Integer.class.getClassLoader());
149 | this.fechNacimiento = in.readString();
150 | this.idEstadoCivil = (Integer) in.readValue(Integer.class.getClassLoader());
151 | this.tieneHijos = (Boolean) in.readValue(Boolean.class.getClassLoader());
152 | }
153 |
154 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
155 | @Override
156 | public ClienteModel createFromParcel(Parcel source) {
157 | return new ClienteModel(source);
158 | }
159 |
160 | @Override
161 | public ClienteModel[] newArray(int size) {
162 | return new ClienteModel[size];
163 | }
164 | };
165 | }
166 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jmarkstar/sesion4/database/dao/ClienteDao.java:
--------------------------------------------------------------------------------
1 | package com.jmarkstar.sesion4.database.dao;
2 |
3 | import android.content.ContentValues;
4 | import android.content.Context;
5 | import android.database.Cursor;
6 | import android.database.SQLException;
7 | import android.database.sqlite.SQLiteDatabase;
8 | import android.util.Log;
9 | import com.jmarkstar.sesion4.database.Sesion4DatabaseHelper;
10 | import com.jmarkstar.sesion4.model.ClienteModel;
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | /**
15 | * Created by jmarkstar on 12/05/2017.
16 | */
17 | public class ClienteDao {
18 |
19 | private static final String TAG = "ClienteDao";
20 |
21 | private final String ALL_COLUMNS [] = {
22 | ClienteModel.ID_FIELD,
23 | ClienteModel.NOMBRE_FIELD,
24 | ClienteModel.EMAIL_FIELD,
25 | ClienteModel.TELEFONO_FIELD,
26 | ClienteModel.DIRECCION_FIELD,
27 | ClienteModel.ID_EMPRESA_FIELD,
28 | ClienteModel.FECHA_NAC_FIELD,
29 | ClienteModel.ID_ESTADO_CIVIL_FIELD,
30 | ClienteModel.TIENE_HIJOS_FIELD};
31 |
32 | private SQLiteDatabase mSQLiteDatabase;
33 |
34 | public ClienteDao(Context context){
35 | mSQLiteDatabase = new Sesion4DatabaseHelper(context).getWritableDatabase();
36 | }
37 |
38 | public List getClientes(){
39 | Cursor mCursor = mSQLiteDatabase.query(true, ClienteModel.TABLE_NAME, ALL_COLUMNS, null, null, null, null, null, null);
40 | return convertCursorToList(mCursor);
41 | }
42 |
43 | public ClienteModel getClienteById(Integer idCliente){
44 | return null;
45 | }
46 |
47 | public long insertCliente(ClienteModel clienteModel){
48 |
49 | /*try{
50 | //escribirmos nuestra sentencia sql.
51 | }catch(SQLException ex){
52 | Log.v(TAG, "ex - "+ex);
53 | }*/
54 |
55 | /*
56 | mSQLiteDatabase.beginTransaction();
57 | //podemos todos los sql que queremos ejecutar.
58 | mSQLiteDatabase.endTransaction();
59 | */
60 |
61 | long status = mSQLiteDatabase.insert(ClienteModel.TABLE_NAME, null, convertClienteToContentValues(clienteModel));
62 | //En metodo 'insert' retorna un long, podría ser el ID de la fila o -1 si ocurre un error.
63 | Log.v(TAG,"status = "+status);
64 | return status;
65 | }
66 |
67 | public int updateCliente(ClienteModel clienteModel){
68 | String strFilter = ClienteModel.ID_FIELD+"="+clienteModel.getId();
69 | return mSQLiteDatabase.update(ClienteModel.TABLE_NAME, convertClienteToContentValues(clienteModel), strFilter, null);
70 | }
71 |
72 | public int eliminarCliente(Integer idCliente){
73 | String strWhere = ClienteModel.ID_FIELD+"=?";
74 | String [] whereArgs = new String [] { String.valueOf(idCliente) };
75 | return mSQLiteDatabase.delete(ClienteModel.TABLE_NAME, strWhere, whereArgs);
76 | }
77 |
78 | private ContentValues convertClienteToContentValues(ClienteModel cliente){
79 | ContentValues contentValues = new ContentValues();
80 | contentValues.put(ClienteModel.NOMBRE_FIELD, cliente.getNombreCompleto());
81 | contentValues.put(ClienteModel.EMAIL_FIELD, cliente.getEmail());
82 | contentValues.put(ClienteModel.TELEFONO_FIELD, cliente.getTelefono());
83 | contentValues.put(ClienteModel.DIRECCION_FIELD, cliente.getDireccion());
84 | contentValues.put(ClienteModel.ID_EMPRESA_FIELD, cliente.getIdEmpresaCliente());
85 | contentValues.put(ClienteModel.FECHA_NAC_FIELD, cliente.getFechNacimiento());
86 | contentValues.put(ClienteModel.ID_ESTADO_CIVIL_FIELD, cliente.getIdEstadoCivil());
87 |
88 | //debido a que SQLite no puede guardar booleanos, estamos convirtiendo el Boolean a Integer
89 | //para poder guardar.
90 | Integer tieneHijosInteger = cliente.getTieneHijos()?1:0;
91 | contentValues.put(ClienteModel.TIENE_HIJOS_FIELD, tieneHijosInteger);
92 | return contentValues;
93 | }
94 |
95 | private List convertCursorToList(Cursor mCursor){
96 | List arrClientes = new ArrayList<>();
97 | if (mCursor.moveToFirst()) {
98 | do {
99 | ClienteModel clienteItem = new ClienteModel();
100 | clienteItem.setId(mCursor.getInt(mCursor.getColumnIndex(ClienteModel.ID_FIELD)));
101 | clienteItem.setNombreCompleto(mCursor.getString(mCursor.getColumnIndex(ClienteModel.NOMBRE_FIELD)));
102 | clienteItem.setEmail(mCursor.getString(mCursor.getColumnIndex(ClienteModel.EMAIL_FIELD)));
103 | clienteItem.setTelefono(mCursor.getString(mCursor.getColumnIndex(ClienteModel.TELEFONO_FIELD)));
104 | clienteItem.setDireccion(mCursor.getString(mCursor.getColumnIndex(ClienteModel.DIRECCION_FIELD)));
105 | clienteItem.setIdEmpresaCliente(mCursor.getInt(mCursor.getColumnIndex(ClienteModel.ID_EMPRESA_FIELD)));
106 | clienteItem.setFechNacimiento(mCursor.getString(mCursor.getColumnIndex(ClienteModel.FECHA_NAC_FIELD)));
107 | clienteItem.setIdEstadoCivil(mCursor.getInt(mCursor.getColumnIndex(ClienteModel.ID_ESTADO_CIVIL_FIELD)));
108 |
109 | //recuperando Integer y convirtiendolo a Booleano.
110 | Boolean tieneHijos = mCursor.getInt(mCursor.getColumnIndex(ClienteModel.TIENE_HIJOS_FIELD)) == 1;
111 | clienteItem.setTieneHijos(tieneHijos);
112 |
113 | arrClientes.add(clienteItem);
114 | }while (mCursor.moveToNext());
115 | }
116 | return arrClientes;
117 | }
118 |
119 | }
120 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_cliente_agregar.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
20 |
21 |
26 |
27 |
34 |
35 |
36 |
37 |
42 |
43 |
48 |
49 |
56 |
57 |
58 |
59 |
64 |
65 |
70 |
71 |
79 |
80 |
81 |
82 |
83 |
88 |
89 |
94 |
95 |
102 |
103 |
104 |
105 |
110 |
111 |
116 |
117 |
122 |
123 |
124 |
125 |
130 |
131 |
136 |
137 |
141 |
142 |
150 |
151 |
159 |
160 |
161 |
162 |
163 |
164 |
169 |
170 |
175 |
176 |
181 |
182 |
186 |
187 |
191 |
192 |
196 |
197 |
201 |
202 |
203 |
204 |
205 |
206 |
211 |
212 |
218 |
219 |
220 |
221 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jmarkstar/sesion4/activities/ClienteAgregarActivity.java:
--------------------------------------------------------------------------------
1 | package com.jmarkstar.sesion4.activities;
2 |
3 | import android.app.DatePickerDialog;
4 | import android.content.Context;
5 | import android.support.annotation.IdRes;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.os.Bundle;
8 | import android.util.Log;
9 | import android.view.MotionEvent;
10 | import android.view.View;
11 | import android.view.inputmethod.InputMethodManager;
12 | import android.widget.AdapterView;
13 | import android.widget.ArrayAdapter;
14 | import android.widget.Button;
15 | import android.widget.CheckBox;
16 | import android.widget.DatePicker;
17 | import android.widget.EditText;
18 | import android.widget.RadioGroup;
19 | import android.widget.Spinner;
20 | import android.widget.TextView;
21 | import android.widget.Toast;
22 | import com.jmarkstar.sesion4.R;
23 | import com.jmarkstar.sesion4.database.dao.ClienteDao;
24 | import com.jmarkstar.sesion4.model.ClienteModel;
25 | import com.jmarkstar.sesion4.util.StringUtils;
26 | import java.util.Calendar;
27 | import butterknife.BindView;
28 | import butterknife.ButterKnife;
29 | import butterknife.OnClick;
30 |
31 | /** Este activity nos permitirá crear un nuevo cliente en la base de datos SQLite.
32 | * @author jmarkstar
33 | * */
34 | public class ClienteAgregarActivity extends AppCompatActivity {
35 |
36 | private static final String TAG = "ClienteAgregarActivity";
37 |
38 | public static final String CLIENTE = "cliente_editar";
39 |
40 | @BindView(R.id.et_nombre_completo) EditText mEtNombreCompleto;
41 | @BindView(R.id.et_email) EditText mEtEmail;
42 | @BindView(R.id.et_phone) EditText mEtPhone;
43 | @BindView(R.id.et_address) EditText mEtAddress;
44 | @BindView(R.id.sp_empresas_clientes) Spinner mSpEmpresasClientes;
45 | @BindView(R.id.tv_cumpleanio) TextView mTvCumpleanio;
46 | @BindView(R.id.rg_estado_civil) RadioGroup mRgEstadoCivil;
47 | @BindView(R.id.cb_tiene_hijos) CheckBox mCbTieneHijos;
48 | @BindView(R.id.btn_accion) Button mBtnAccion;
49 |
50 | private ClienteDao mClienteDao;
51 |
52 | /* Esta variable almacenará el estado civil que seleccionaremos en la pantalla.
53 | * La variable iniciará en NULL, y los valores que selecionaremos tendrán los posibles valores {1,2,3,4 }
54 | * */
55 | private Integer mEstadoCivilSeleccionado = null;
56 |
57 | private Integer mEmpresaClienteSeleccionado = 0;
58 |
59 | private int anio, mes, dia;
60 | private String mFechaSelecionada = null;
61 |
62 | private ClienteModel clienteActualizar = null;
63 |
64 | @Override protected void onCreate(Bundle savedInstanceState) {
65 | super.onCreate(savedInstanceState);
66 | setContentView(R.layout.activity_cliente_agregar);
67 |
68 | //Iniciando la libreria ButterKnife en el Activity.
69 | ButterKnife.bind(this);
70 |
71 | //Iniciando nuestro DAO.
72 | mClienteDao = new ClienteDao(this);
73 |
74 | //Cargando el Spinner
75 | String [] empresaClientesArray = getResources().getStringArray(R.array.empresas_clientes);
76 | ArrayAdapter adapterSpinner = new ArrayAdapter(this, android.R.layout.simple_spinner_item, empresaClientesArray);
77 | adapterSpinner.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
78 | mSpEmpresasClientes.setAdapter(adapterSpinner);
79 |
80 | mSpEmpresasClientes.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
81 | @Override public void onItemSelected(AdapterView> parent, View view, int position, long id) {
82 | mEmpresaClienteSeleccionado = position;
83 | }
84 |
85 | @Override public void onNothingSelected(AdapterView> parent) {
86 |
87 | }
88 | });
89 |
90 | /* Este listener nos permite ocultar el keyboard del dispositivo cuando el usuario
91 | // hace click en el spinner.
92 | * */
93 | mSpEmpresasClientes.setOnTouchListener(new View.OnTouchListener() {
94 | @Override public boolean onTouch(View v, MotionEvent event) {
95 |
96 | View view = getCurrentFocus();
97 | if (view != null) {
98 | InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
99 | imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
100 | }
101 |
102 | return false;
103 | }
104 | });
105 |
106 | /* De esta forma capturamos el checkbox seleccionado por el usuario. */
107 | mRgEstadoCivil.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
108 | @Override public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
109 |
110 | /* El parametro 'checkedId' es el id del CheckBox que el usuario ha selecionado,
111 | * Para poder saber que opcion ha selecionado tenemos que verificarlo uno por uno
112 | * y asignarle el valor a la variable 'mEstadoCivilSeleccionado' segun la condición.
113 | * */
114 |
115 | if(checkedId == R.id.rb_soltero){
116 | mEstadoCivilSeleccionado = 1;
117 | }else if(checkedId == R.id.rb_casado){
118 | mEstadoCivilSeleccionado = 2;
119 | }else if(checkedId == R.id.rb_viudo){
120 | mEstadoCivilSeleccionado = 3;
121 | }else if(checkedId == R.id.rb_divorsiado){
122 | mEstadoCivilSeleccionado = 4;
123 | }
124 | }
125 | });
126 |
127 | //VALIDACION SI LA OPERACION SERA PARA EDITAR O AGREGAR.
128 |
129 | clienteActualizar = getIntent().getParcelableExtra(CLIENTE);
130 | if(clienteActualizar!=null){
131 | Log.v(TAG, "clienteActualizar - "+clienteActualizar.toString());
132 | //agregando titulo a la pantalla
133 | setTitle(getString(R.string.editar_titulo));
134 | mBtnAccion.setText(R.string.registrar_btn_action_editar);
135 |
136 | mEtNombreCompleto.setText(clienteActualizar.getNombreCompleto());
137 | mEtEmail.setText(clienteActualizar.getEmail());
138 | mEtPhone.setText(clienteActualizar.getTelefono());
139 | mEtAddress.setText(clienteActualizar.getDireccion());
140 |
141 | //Precargando datos para el campo fecha de nacimiento
142 | mFechaSelecionada = clienteActualizar.getFechNacimiento();
143 | mTvCumpleanio.setText(clienteActualizar.getFechNacimiento());
144 | mSpEmpresasClientes.setSelection(clienteActualizar.getIdEmpresaCliente());
145 | String [] itemsDate = clienteActualizar.getFechNacimiento().split("/");
146 | dia = Integer.parseInt(itemsDate[0]);
147 | mes = Integer.parseInt(itemsDate[1])-1;//el mes comienza desde 0, por esa razon se resta 1
148 | anio = Integer.parseInt(itemsDate[2]);
149 |
150 | //Preseleccionando el id de estado civil selecionado.
151 |
152 | //chambiando de valor a mEstadoCivilSeleccionado
153 | mEstadoCivilSeleccionado = clienteActualizar.getIdEstadoCivil();
154 |
155 | //preselecionando el radiobutton indicado segun getIdEstadoCivil().
156 | int rbId = 0;
157 | if(clienteActualizar.getIdEstadoCivil() == 1){
158 | rbId = R.id.rb_soltero;
159 | }else if(clienteActualizar.getIdEstadoCivil() == 2){
160 | rbId = R.id.rb_casado;
161 | }else if(clienteActualizar.getIdEstadoCivil() == 3){
162 | rbId = R.id.rb_viudo;
163 | }else if(clienteActualizar.getIdEstadoCivil() == 4){
164 | rbId = R.id.rb_divorsiado;
165 | }
166 | //seleccionando el rb elegido.
167 | mRgEstadoCivil.check(rbId);
168 |
169 | mCbTieneHijos.setChecked(clienteActualizar.getTieneHijos());
170 | }else{
171 | //agregando titulo a la pantalla
172 | setTitle(getString(R.string.registrar_titulo));
173 | mBtnAccion.setText(R.string.registrar_btn_action_registrar);
174 |
175 | //Iniciando valores de anio, mes y dia con la fecha actual.
176 | Calendar calendar = Calendar.getInstance();
177 | anio = calendar.get(Calendar.YEAR);
178 | mes = calendar.get(Calendar.MONTH);
179 | dia = calendar.get(Calendar.DAY_OF_MONTH);
180 | }
181 | }
182 |
183 | @OnClick(R.id.btn_accion) public void onRegistrarNuevoCliente(){
184 | if(validarCampos()){
185 | if(clienteActualizar == null)
186 | registrarCliente();
187 | else
188 | editarCliente();
189 | }
190 | }
191 |
192 | @OnClick(R.id.rl_cumpleanio) public void onAbrirDatePicker(){
193 | /* Creando el DatePicker con el anio, mes y dia que queremos que comienze cuando se muestra.
194 | * la variable 'miDateListener' es un CallBack o Listener, lo que basicamente es permitir recibir los valores que
195 | * el DatePicker retorna, porque para nosotros Datepicker es una cajanegra, la unica forma de como obtejer su valor
196 | * es por medio de este 'OnDateSetListener'.
197 | * */
198 | Log.v(TAG, "dia = "+dia+" - mes = "+mes +" - anio = "+anio);
199 | DatePickerDialog mDatePicker = new DatePickerDialog(this, miDateListener, anio, mes, dia);
200 | mDatePicker.show();
201 | }
202 |
203 | private DatePickerDialog.OnDateSetListener miDateListener = new DatePickerDialog.OnDateSetListener() {
204 | @Override
205 | public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
206 | //se lke suma 1 porque su valor comienza en 0
207 | mFechaSelecionada = dayOfMonth+"/"+(month+1)+"/"+year;
208 | mTvCumpleanio.setText(mFechaSelecionada);
209 | anio = year;
210 | mes = month;
211 | dia = dayOfMonth;
212 | }
213 | };
214 |
215 | private void editarCliente() {
216 | String nombreCompleto = mEtNombreCompleto.getText().toString();
217 | String email = mEtEmail.getText().toString();
218 | String phone = mEtPhone.getText().toString();
219 | String address = mEtAddress.getText().toString();
220 | clienteActualizar.setNombreCompleto(nombreCompleto);
221 | clienteActualizar.setEmail(email);
222 | clienteActualizar.setTelefono(phone);
223 | clienteActualizar.setDireccion(address);
224 | clienteActualizar.setFechNacimiento(mFechaSelecionada);
225 | clienteActualizar.setIdEmpresaCliente(mEmpresaClienteSeleccionado);
226 | clienteActualizar.setIdEstadoCivil(mEstadoCivilSeleccionado);
227 | clienteActualizar.setTieneHijos(mCbTieneHijos.isChecked());
228 | Log.v(TAG, clienteActualizar.toString());
229 | int status = mClienteDao.updateCliente(clienteActualizar);
230 | if(status>0){
231 | mostrarMensaje(getString(R.string.editar_msj_correcto));
232 | finish();//este metodo cierra la pantalla o mata el activity.
233 | }else{
234 | mostrarMensaje(getString(R.string.editar_msj_error));
235 | }
236 | }
237 |
238 | private void registrarCliente(){
239 | String nombreCompleto = mEtNombreCompleto.getText().toString();
240 | String email = mEtEmail.getText().toString();
241 | String phone = mEtPhone.getText().toString();
242 | String address = mEtAddress.getText().toString();
243 |
244 | ClienteModel cliente = new ClienteModel();
245 | cliente.setNombreCompleto(nombreCompleto);
246 | cliente.setEmail(email);
247 | cliente.setTelefono(phone);
248 | cliente.setDireccion(address);
249 | cliente.setFechNacimiento(mFechaSelecionada);
250 | cliente.setIdEmpresaCliente(mEmpresaClienteSeleccionado);
251 | cliente.setIdEstadoCivil(mEstadoCivilSeleccionado);
252 | cliente.setTieneHijos(mCbTieneHijos.isChecked());//guarda el valor de la pregunta si fue checked o no.
253 |
254 | Log.v(TAG, cliente.toString());
255 | long status = mClienteDao.insertCliente(cliente);
256 | if(status>0){
257 | mostrarMensaje(getString(R.string.registrar_msj_correcto));
258 | finish();//este metodo cierra la pantalla o mata el activity.
259 | }else{
260 | mostrarMensaje(getString(R.string.registro_msj_error));
261 | }
262 | }
263 |
264 | /** Este metodo valida todos los campos del formulario.
265 | * @return true o false.
266 | * */
267 | private boolean validarCampos(){
268 | String nombreCompleto = mEtNombreCompleto.getText().toString();
269 | String email = mEtEmail.getText().toString();
270 | String phone = mEtPhone.getText().toString();
271 | String address = mEtAddress.getText().toString();
272 |
273 | if(nombreCompleto.isEmpty()){
274 | mostrarMensaje(getString(R.string.registrar_validacion_nombre_vacio));
275 | return false;
276 | }
277 |
278 | if(email.isEmpty()){
279 | mostrarMensaje(getString(R.string.registrar_validacion_email_vacio));
280 | return false;
281 | }else{
282 | if(!StringUtils.validarFormatoEmail(email)){
283 | mostrarMensaje(getString(R.string.registrar_validacion_email_incorrecto));
284 | return false;
285 | }
286 | }
287 |
288 | if(phone.isEmpty()){
289 | mostrarMensaje(getString(R.string.registrar_validacion_telefono_vacio));
290 | return false;
291 | }else{
292 | if(phone.length() < 7){
293 | mostrarMensaje(getString(R.string.registrar_validacion_telefono_incorrecto));
294 | return false;
295 | }
296 | }
297 |
298 | if(address.isEmpty()){
299 | mostrarMensaje(getString(R.string.registrar_validacion_direccion_vacio));
300 | return false;
301 | }
302 |
303 | if(mEmpresaClienteSeleccionado==0){
304 | mostrarMensaje(getString(R.string.register_validacion_selecione_empresa));
305 | return false;
306 | }
307 |
308 | if(mFechaSelecionada==null){
309 | mostrarMensaje(getString(R.string.registrar_validacion_cumpleanos_vacio));
310 | return false;
311 | }
312 |
313 | if(mEstadoCivilSeleccionado == null){
314 | mostrarMensaje(getString(R.string.registrar_validacion_estado_civil_no_selecionado));
315 | return false;
316 | }
317 |
318 | return true;
319 | }
320 |
321 | /** Este metodo mostrará en mensaje al usuario.
322 | * @param mensaje texto a mostrar.
323 | * */
324 | private void mostrarMensaje(String mensaje){
325 | Toast.makeText(this, mensaje, Toast.LENGTH_SHORT).show();
326 | }
327 | }
328 |
--------------------------------------------------------------------------------