Guest User

Untitled

a guest
Nov 15th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.37 KB | None | 0 0
  1. apply plugin: 'com.android.application'
  2.  
  3. android {
  4. compileSdkVersion 26
  5. buildToolsVersion "26.0.2"
  6. defaultConfig {
  7. applicationId "com.example.marcos.unasphtquizz"
  8. minSdkVersion 15
  9. targetSdkVersion 26
  10. versionCode 1
  11. versionName "1.0"
  12. testInstrumentationRunner
  13. "android.support.test.runner.AndroidJUnitRunner"
  14. }
  15. buildTypes {
  16. release {
  17. minifyEnabled false
  18. proguardFiles getDefaultProguardFile('proguard-android.txt'),
  19. 'proguard-rules.pro'
  20. }
  21. }
  22. }
  23.  
  24. dependencies {
  25. compile fileTree(include: ['*.jar'], dir: 'libs')
  26. androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
  27. {
  28. exclude group: 'com.android.support', module: 'support-annotations'
  29. })
  30. compile 'com.android.support:appcompat-v7:26.+'
  31. compile 'com.android.support.constraint:constraint-layout:1.0.2'
  32. testCompile 'junit:junit:4.12'
  33. compileOnly files('C:/Users/Italo/Downloads/UnaspHTQuizz-
  34. 9a866e25dab5336ad318dca4f9364c4355b64400/UnaspHTQuizz-
  35. 9a866e25dab5336ad318dca4f9364c4355b64400/libs/postgresql-42.1.4.jar')
  36. }
  37.  
  38. package com.example.marcos.unasphtquizz;
  39.  
  40. import android.app.AlertDialog;
  41. import android.content.DialogInterface;
  42. import java.sql.Connection;
  43. import java.sql.DriverManager;
  44. import java.sql.ResultSet;
  45. import java.sql.SQLException;
  46. import java.util.concurrent.ExecutionException;
  47.  
  48. public class DB{
  49.  
  50. private static Connection conn;
  51.  
  52. private static Connection conecta() throws SQLException,
  53. ClassNotFoundException, InstantiationException, IllegalAccessException {
  54. Class.forName("org.postgresql.Driver").newInstance();
  55. String url = "jdbc:postgresql://something.postgresql.dbaas.com.br";
  56. String user = "user";
  57. String pass = "password";
  58. conn = DriverManager.getConnection(url, user, pass);
  59. return conn;
  60. }
  61. private static void desconecta() throws SQLException {
  62. if (conn != null){
  63. try{
  64. conn.close();
  65. }catch (Exception e){
  66. throw e;
  67. }finally {
  68. conn = null;
  69. }
  70. }
  71. }
  72.  
  73. public static ResultSet select(String query) throws SQLException,
  74. ClassNotFoundException, InterruptedException, ExecutionException,
  75. InstantiationException, IllegalAccessException{
  76. ResultSet resultSet = null;
  77. conecta();
  78. resultSet = new ExecuteDB(conn, query).execute().get();
  79. return resultSet;
  80. }
  81.  
  82. public static ResultSet execute(String query) throws SQLException,
  83. ClassNotFoundException, InstantiationException, IllegalAccessException{
  84. ResultSet resultSet = null;
  85. conecta();
  86. resultSet = conecta().prepareStatement(query).executeQuery();;
  87. return resultSet;
  88. }
  89. }
  90.  
  91. package com.example.marcos.unasphtquizz;
  92.  
  93. import android.annotation.SuppressLint;
  94. import android.content.DialogInterface;
  95. import android.content.Intent;
  96. import android.support.v7.app.AlertDialog;
  97. import android.support.v7.app.AppCompatActivity;
  98. import android.os.Bundle;
  99. import android.view.View;
  100. import android.widget.EditText;
  101. import java.sql.ResultSet;
  102.  
  103. public class LoginActivity extends AppCompatActivity {
  104.  
  105. private EditText editLogin, editSenha;
  106.  
  107. @SuppressLint("WrongViewCast")
  108. @Override
  109. protected void onCreate(Bundle savedInstanceState) {
  110. super.onCreate(savedInstanceState);
  111. setContentView(R.layout.activity_login);
  112. editLogin = (EditText) findViewById(R.id.loginText);
  113. editSenha = (EditText) findViewById(R.id.SenhaText);
  114. }
  115.  
  116. public void exibirTexto(String titulo, String txt){
  117. AlertDialog alertDialog = new
  118. AlertDialog.Builder(LoginActivity.this).create();
  119. alertDialog.setTitle(titulo);
  120. alertDialog.setMessage(txt);
  121. alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
  122. new DialogInterface.OnClickListener() {
  123. public void onClick(DialogInterface dialog, int which) {
  124. dialog.dismiss();
  125. }
  126. });
  127. alertDialog.show();
  128. }
  129.  
  130. public void login(View view){
  131. ResultSet rs;
  132.  
  133. try {
  134. String testelogin = editLogin.getText().toString();
  135. String testesenha = editSenha.getText().toString();
  136. rs = DB.execute("SELECT login, senha, tipousuario FROM usuario WHERE
  137. login == '" + testelogin + "' AND senha == '" + testesenha + "'");
  138. while (rs.next()){
  139. String login = rs.getString("login");
  140. String senha = rs.getString("senha");;
  141. int tipo = Integer.parseInt(rs.getString("tipousuario"));
  142. if (login.equals(testelogin)){
  143. if (senha.equals(testesenha)){
  144. Intent intent = null;
  145. switch (tipo){
  146. case 1:
  147. intent = new Intent(this, Jogando.class);
  148. break;
  149. case 2:
  150. intent = new Intent(this,
  151. CadastrarQuizz.class);
  152. break;
  153. case 3:
  154. intent = new Intent(this,
  155. CadastrarCurso.class);
  156. break;
  157. }
  158. startActivity(intent);
  159. }
  160. }
  161. }
  162. } catch (Exception e) {
  163. exibirTexto("Erro", e.getMessage());
  164. }
  165. }
  166.  
  167.  
  168. public void criarUsuario(View view){
  169. try {
  170. Intent intent = new Intent(this, CadastrarUsuario.class);
  171. startActivity(intent);
  172. }
  173. catch (Exception e){
  174. exibirTexto("Erro", e.getMessage());
  175. }
  176. }
  177. }
  178.  
  179. <?xml version="1.0" encoding="utf-8"?>
  180. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  181. package="com.example.marcos.unasphtquizz">
  182.  
  183. <uses-permission android:name="android.permission.INTERNET" />
  184. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  185.  
  186. <application
  187. android:allowBackup="true"
  188. android:icon="@mipmap/ic_launcher"
  189. android:label="@string/app_name"
  190. android:roundIcon="@mipmap/ic_launcher_round"
  191. android:supportsRtl="true"
  192. android:theme="@style/AppTheme">
  193. <activity android:name=".LoginActivity">
  194. <intent-filter>
  195. <action android:name="android.intent.action.MAIN" />
  196.  
  197. <category android:name="android.intent.category.LAUNCHER" />
  198. </intent-filter>
  199. </activity>
  200. <activity android:name=".CadastrarQuizz" />
  201. <activity android:name=".ListaActivity" />
  202. <activity android:name=".MainActivity" />
  203. <activity android:name=".CadastrarUsuario" />
  204. <activity android:name=".MenuJogo" />
  205. <activity android:name=".Jogando" />
  206. <activity android:name=".CadastrarCurso"></activity>
  207. </application>
  208.  
  209. </manifest>
Add Comment
Please, Sign In to add comment