Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMX committed Feb 16, 2018
0 parents commit a38b2c1
Show file tree
Hide file tree
Showing 47 changed files with 1,044 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
33 changes: 33 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.uriel.lineas"
minSdkVersion 23
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 {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.uriel.lineas

import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("com.example.uriel.lineas", appContext.packageName)
}
}
22 changes: 22 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.uriel.lineas">

<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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".GUICanvas"></activity>
</application>

</manifest>
Binary file added app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
144 changes: 144 additions & 0 deletions app/src/main/java/com/example/uriel/lineas/GUICanvas.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package com.example.uriel.lineas


import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.media.MediaPlayer
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View

import kotlinx.android.synthetic.main.activity_guicanvas.*


class GUICanvas : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_guicanvas)
title = "Grafico"

var zoom = 7f
var arreglo = intent.getIntegerArrayListExtra("valores")
var fondo = Lienzo(this, arreglo)
layaout1.addView(fondo)
layaout1.removeView(button)
layaout1.removeView(button3)
layaout1.addView(button)
layaout1.addView(button3)
button.setOnClickListener {
layaout1.removeView(fondo)
if(zoom<20f) fondo = Lienzo(this, arreglo, ++zoom)
else{
//println("que pasa1? :v")
val mp = MediaPlayer.create(this, R.raw.alert)
mp.start()
mp.setOnCompletionListener { mp.release() }
}
layaout1.addView(fondo)

layaout1.removeView(button3)
layaout1.addView(button3)
layaout1.removeView(button)
layaout1.addView(button)
//button.visibility = View.VISIBLE
//button3.visibility = View.VISIBLE
}
button3.setOnClickListener {
layaout1.removeView(fondo)
layaout1.removeView(fondo)
if(zoom>1f) fondo = Lienzo(this, arreglo, --zoom)
else{
//println("que pasa2? :v")
val mp = MediaPlayer.create(this, R.raw.alert)
mp.start()
mp.setOnCompletionListener { mp.release() }
}
layaout1.addView(fondo)
layaout1.removeView(button)
layaout1.addView(button)
layaout1.removeView(button3)
layaout1.addView(button3)
//button3.visibility = View.VISIBLE
//button.visibility = View.VISIBLE
}

}


override fun onSupportNavigateUp(): Boolean {
finish()
return true
}

class Lienzo(context: Context, arreglo: ArrayList<Int>, tamaño:Float=7f) : View(context) {
val arreglo = arreglo
val tamaño = tamaño
override fun onDraw(canvas: Canvas) {
val A = floatArrayOf(arreglo[0].toFloat(),arreglo[1].toFloat())
val B = floatArrayOf(arreglo[2].toFloat(),arreglo[3].toFloat())
val opc = arreglo[4]
val ancho = canvas.getWidth()
val alto = canvas.getHeight()
val pincel1 = Paint()
val pincel2 = Paint()
val pincel3 = Paint()
val incrementoX = B[0]-A[0]
val incrementoY = B[1]-A[1]
val x = ancho/2f
val y = alto/2f
val incremento = tamaño
var incrementoAux = incremento
var inicio = 0
pincel1.strokeWidth = incremento
pincel2.strokeWidth = 2f
pincel1.setARGB(255, 0, 0, 0)
pincel2.setARGB(255,255,0,0)
pincel3.setARGB(255,0,255,0)
if (incrementoAux<=5) incrementoAux = 5f
for (i in y.toInt()+(incrementoAux/2f).toInt()..alto step incrementoAux.toInt()){
canvas.drawLine(0f,i.toFloat(),ancho.toFloat(),i.toFloat(),pincel3)
canvas.drawLine(0f,y+(y-i),ancho.toFloat(),y+(y-i),pincel3)
}
for (i in (x+(incrementoAux/2f)).toInt()..ancho step incrementoAux.toInt()){
canvas.drawLine(i.toFloat(),0f,i.toFloat(),alto.toFloat(),pincel3)
canvas.drawLine(x-(i-x),0f,x-(i-x),alto.toFloat(),pincel3)
}
canvas.drawLine(0f,alto/2f,ancho.toFloat(),alto/2f,pincel2)
canvas.drawLine(ancho/2f,0f,ancho/2f,alto.toFloat(),pincel2)
val ar:ArrayList<FloatArray>
val pasos:Float

when(opc){
0 -> {
ar = Metodos().Basico(ancho.toFloat(),alto.toFloat(),A,B)
pasos = B[0]-A[0]
for (i in 0..(pasos).toInt()){
canvas.drawPoint(x+((Math.round(ar[0][i]).toFloat()*incremento)),
y-((Math.round(ar[1][i]).toFloat()*incremento)), pincel1)//elimine -(incremento/2f)
// en X y Y para dar soporte a (0,0)
}
}
1 -> {
ar = Metodos().DDA(ancho.toFloat(),alto.toFloat(),A,B)
if (Math.abs(incrementoX)>Math.abs(incrementoY)) {
pasos = Math.abs(incrementoX)
}
else {
pasos = Math.abs(incrementoY)
}
for (i in 0..(pasos).toInt()){
canvas.drawPoint(x+((Math.round(ar[0][i]).toFloat()*incremento)),
y-((Math.round(ar[1][i]).toFloat()*incremento)), pincel1)//elimine -(incremento/2f)
// en X y Y para dar soporte a (0,0)
}

}
2 -> {

}
}

}
}
}
45 changes: 45 additions & 0 deletions app/src/main/java/com/example/uriel/lineas/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.example.uriel.lineas

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.app.AlertDialog
import android.widget.ArrayAdapter
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val opciones = arrayListOf<String>("Basico","DDA","Bressenham")
val adapter = ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,opciones)
spinner2.adapter = adapter

button2.setOnClickListener {
if (x1.text.isNotEmpty()&&x2.text.isNotEmpty()&&y1.text.isNotEmpty()&&y2.text.isNotEmpty()){
val valores = arrayListOf<Int>((x1.text).toString().toInt(),(y1.text).toString().toInt()
,(x2.text).toString().toInt(),(y2.text).toString().toInt(),spinner2.selectedItemPosition)
//val extra = Bundle()
//extra.putIntegerArrayList("valores",valores)
val siguiente = Intent(this,GUICanvas::class.java)//.putExtra("valores",extra)
siguiente.putExtra("valores",valores)
startActivity(siguiente)
}else{
val simpleAlert = AlertDialog.Builder(this@MainActivity).create()
simpleAlert.setTitle("Error:")
simpleAlert.setMessage("No puede dejar espacios vacios")

simpleAlert.setButton(AlertDialog.BUTTON_POSITIVE, "OK", {
dialogInterface, i ->
Toast.makeText(applicationContext, "Ingresa los valores", Toast.LENGTH_SHORT).show()
})

simpleAlert.show()
}

}
}
}
Loading

0 comments on commit a38b2c1

Please sign in to comment.