Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Galeev committed Feb 17, 2015
1 parent 15bc3b0 commit 45f269c
Show file tree
Hide file tree
Showing 27 changed files with 183 additions and 1,042 deletions.
6 changes: 3 additions & 3 deletions http/.classpath
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.xtend.XTEND_CONTAINER"/>
<classpathentry exported="true" kind="con" path="org.eclipse.xtend.XTEND_CONTAINER"/>
<classpathentry kind="src" path="xtend-gen"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
3 changes: 1 addition & 2 deletions http/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:label="@string/app_name">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
Expand Down
3 changes: 1 addition & 2 deletions http/bin/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:label="@string/app_name">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
Expand Down
948 changes: 0 additions & 948 deletions http/bin/R.txt

This file was deleted.

Binary file added http/bin/classes.dex
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added http/bin/http.apk
Binary file not shown.
5 changes: 0 additions & 5 deletions http/bin/jarlist.cache

This file was deleted.

Binary file added http/bin/res/crunch/drawable-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added http/bin/res/crunch/drawable-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added http/bin/resources.ap_
Binary file not shown.
1 change: 1 addition & 0 deletions http/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
tools:context="com.ncom.http.MainActivity" >

<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
Expand Down
5 changes: 0 additions & 5 deletions http/res/menu/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,5 @@
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.ncom.http.MainActivity" >

<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"/>

</menu>
11 changes: 0 additions & 11 deletions http/res/values-v11/styles.xml

This file was deleted.

12 changes: 0 additions & 12 deletions http/res/values-v14/styles.xml

This file was deleted.

18 changes: 0 additions & 18 deletions http/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,2 @@
<resources>

<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

</resources>
109 changes: 109 additions & 0 deletions http/src/com/ncom/http/HTTP.xtend
Original file line number Diff line number Diff line change
@@ -1,5 +1,114 @@
package com.ncom.http

import android.os.Handler
import android.os.Message
import android.util.Log
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.Timer
import java.util.TimerTask
import org.apache.http.client.methods.HttpPost
import org.apache.http.entity.StringEntity
import org.apache.http.impl.client.DefaultHttpClient
import org.apache.http.params.HttpConnectionParams
import org.apache.http.protocol.BasicHttpContext

class HTTP {

val MSG_DONE = 1

int socketTimeout
int requestTimeout
BasicHttpContext localContext

new(int socketTimeout, int requestTimeout) {
this.socketTimeout = socketTimeout
this.requestTimeout = requestTimeout
localContext = new BasicHttpContext()
}

new() {
this(5000, 25000)
}

def Log(String s) {
Log.d("HTTP", s)
}

static class Param {
(String) => void callback
String result

new((String) => void callback, String result) {
this.callback = callback
this.result = result
}
}

val cbHandler = new Handler() {
override handleMessage(Message m) {
val r = m.obj as Param
Log("RES: " + r.result)
r.callback.apply(r.result)
}

}

static class TimeOutTask extends TimerTask {
String url
Thread t
new(Thread t, String url) {
this.t = t
this.url = url
}
override run() {
if (t.isAlive()) {
t.interrupt()
}
}
}

def String convertInputStreamToString(InputStream inputStream) {
val builder = new StringBuilder()
val reader = new BufferedReader(new InputStreamReader(inputStream))

var line = ""
while( (line = reader.readLine()) != null) {
builder.append(line)
}
return builder.toString()
}

def Post(String url, String body, (String) => void callback) {
Log("REQ: " + url)

val r = new Thread() {

override run() {

val client = new DefaultHttpClient()
val param = client.getParams()

HttpConnectionParams.setConnectionTimeout(param, socketTimeout)
HttpConnectionParams.setSoTimeout(param, socketTimeout)

val req = new HttpPost(url)

if (body.length() > 0) {
req.setEntity(new StringEntity(body))
req.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")
}

val inputStream = client.execute(req, new BasicHttpContext()).getEntity().getContent()

val result = convertInputStreamToString(inputStream)

cbHandler.obtainMessage(MSG_DONE, new Param(callback, result)).sendToTarget()
}
}

new Timer(true).schedule(new TimeOutTask(r, url), requestTimeout)
r.start()
}
}
36 changes: 0 additions & 36 deletions http/src/com/ncom/http/MainActivity.java

This file was deleted.

28 changes: 28 additions & 0 deletions http/src/com/ncom/http/MainActivity.xtend
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.ncom.http

import android.os.Bundle
import android.view.Menu
import android.widget.TextView
import android.app.Activity

public class MainActivity extends Activity {


override void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
request()
}


override boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu)
return true
}

def request() {
val http = new HTTP()
val v = findViewById(R.id.textview) as TextView
http.Post("http://mnp.tele2.ru/gateway.php?9273193358", "", [ String res | v.setText(res) ])
}
}
2 changes: 2 additions & 0 deletions http/xtend-gen/com/ncom/http/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/.HTTP.java._trace
/HTTP.java
/.MainActivity.java._trace
/.TimeOutTask.java._trace
38 changes: 38 additions & 0 deletions http/xtend-gen/com/ncom/http/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.ncom.http;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.TextView;
import com.ncom.http.HTTP;
import com.ncom.http.R;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;

@SuppressWarnings("all")
public class MainActivity extends Activity {
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_main);
this.request();
}

public boolean onCreateOptionsMenu(final Menu menu) {
MenuInflater _menuInflater = this.getMenuInflater();
_menuInflater.inflate(com.ncom.http.R.menu.main, menu);
return true;
}

public void request() {
final HTTP http = new HTTP();
View _findViewById = this.findViewById(R.id.textview);
final TextView v = ((TextView) _findViewById);
final Procedure1<String> _function = new Procedure1<String>() {
public void apply(final String res) {
v.setText(res);
}
};
http.Post("http://mnp.tele2.ru/gateway.php?9273193358", "", _function);
}
}

0 comments on commit 45f269c

Please sign in to comment.