Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- apply plugin: 'com.android.application'
- android {
- compileSdkVersion 26
- buildToolsVersion "26.0.2"
- defaultConfig {
- applicationId "com.example.marcos.unasphtquizz"
- minSdkVersion 15
- targetSdkVersion 26
- versionCode 1
- versionName "1.0"
- testInstrumentationRunner
- "android.support.test.runner.AndroidJUnitRunner"
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'),
- 'proguard-rules.pro'
- }
- }
- }
- dependencies {
- compile fileTree(include: ['*.jar'], dir: 'libs')
- androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
- {
- exclude group: 'com.android.support', module: 'support-annotations'
- })
- compile 'com.android.support:appcompat-v7:26.+'
- compile 'com.android.support.constraint:constraint-layout:1.0.2'
- testCompile 'junit:junit:4.12'
- compileOnly files('C:/Users/Italo/Downloads/UnaspHTQuizz-
- 9a866e25dab5336ad318dca4f9364c4355b64400/UnaspHTQuizz-
- 9a866e25dab5336ad318dca4f9364c4355b64400/libs/postgresql-42.1.4.jar')
- }
- package com.example.marcos.unasphtquizz;
- import android.app.AlertDialog;
- import android.content.DialogInterface;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.concurrent.ExecutionException;
- public class DB{
- private static Connection conn;
- private static Connection conecta() throws SQLException,
- ClassNotFoundException, InstantiationException, IllegalAccessException {
- Class.forName("org.postgresql.Driver").newInstance();
- String url = "jdbc:postgresql://something.postgresql.dbaas.com.br";
- String user = "user";
- String pass = "password";
- conn = DriverManager.getConnection(url, user, pass);
- return conn;
- }
- private static void desconecta() throws SQLException {
- if (conn != null){
- try{
- conn.close();
- }catch (Exception e){
- throw e;
- }finally {
- conn = null;
- }
- }
- }
- public static ResultSet select(String query) throws SQLException,
- ClassNotFoundException, InterruptedException, ExecutionException,
- InstantiationException, IllegalAccessException{
- ResultSet resultSet = null;
- conecta();
- resultSet = new ExecuteDB(conn, query).execute().get();
- return resultSet;
- }
- public static ResultSet execute(String query) throws SQLException,
- ClassNotFoundException, InstantiationException, IllegalAccessException{
- ResultSet resultSet = null;
- conecta();
- resultSet = conecta().prepareStatement(query).executeQuery();;
- return resultSet;
- }
- }
- package com.example.marcos.unasphtquizz;
- import android.annotation.SuppressLint;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.support.v7.app.AlertDialog;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import java.sql.ResultSet;
- public class LoginActivity extends AppCompatActivity {
- private EditText editLogin, editSenha;
- @SuppressLint("WrongViewCast")
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
- editLogin = (EditText) findViewById(R.id.loginText);
- editSenha = (EditText) findViewById(R.id.SenhaText);
- }
- public void exibirTexto(String titulo, String txt){
- AlertDialog alertDialog = new
- AlertDialog.Builder(LoginActivity.this).create();
- alertDialog.setTitle(titulo);
- alertDialog.setMessage(txt);
- alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- }
- });
- alertDialog.show();
- }
- public void login(View view){
- ResultSet rs;
- try {
- String testelogin = editLogin.getText().toString();
- String testesenha = editSenha.getText().toString();
- rs = DB.execute("SELECT login, senha, tipousuario FROM usuario WHERE
- login == '" + testelogin + "' AND senha == '" + testesenha + "'");
- while (rs.next()){
- String login = rs.getString("login");
- String senha = rs.getString("senha");;
- int tipo = Integer.parseInt(rs.getString("tipousuario"));
- if (login.equals(testelogin)){
- if (senha.equals(testesenha)){
- Intent intent = null;
- switch (tipo){
- case 1:
- intent = new Intent(this, Jogando.class);
- break;
- case 2:
- intent = new Intent(this,
- CadastrarQuizz.class);
- break;
- case 3:
- intent = new Intent(this,
- CadastrarCurso.class);
- break;
- }
- startActivity(intent);
- }
- }
- }
- } catch (Exception e) {
- exibirTexto("Erro", e.getMessage());
- }
- }
- public void criarUsuario(View view){
- try {
- Intent intent = new Intent(this, CadastrarUsuario.class);
- startActivity(intent);
- }
- catch (Exception e){
- exibirTexto("Erro", e.getMessage());
- }
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.example.marcos.unasphtquizz">
- <uses-permission android:name="android.permission.INTERNET" />
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:roundIcon="@mipmap/ic_launcher_round"
- android:supportsRtl="true"
- android:theme="@style/AppTheme">
- <activity android:name=".LoginActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <activity android:name=".CadastrarQuizz" />
- <activity android:name=".ListaActivity" />
- <activity android:name=".MainActivity" />
- <activity android:name=".CadastrarUsuario" />
- <activity android:name=".MenuJogo" />
- <activity android:name=".Jogando" />
- <activity android:name=".CadastrarCurso"></activity>
- </application>
- </manifest>
Add Comment
Please, Sign In to add comment