Skip to content

Commit

Permalink
mock android app
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolio authored and BabisAmas committed May 7, 2017
1 parent d39a730 commit 21242e9
Show file tree
Hide file tree
Showing 13 changed files with 399 additions and 55 deletions.
2 changes: 1 addition & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/build
/build
9 changes: 9 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ android {
applicationId "com.example.user.pointie"
minSdkVersion 15
targetSdkVersion 25
multiDexEnabled = true
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -16,6 +17,9 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
packagingOptions {
exclude 'META-INF/*'
}
}
}

Expand All @@ -26,5 +30,10 @@ dependencies {
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'

compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.0.pr3'

testCompile 'junit:junit:4.12'
}
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AddImageActivity"
android:label="@string/title_activity_add_image"
android:theme="@style/AppTheme.NoActionBar"></activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />

</manifest>
69 changes: 69 additions & 0 deletions app/src/main/java/com/example/user/pointie/AddImageActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.example.user.pointie;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import java.io.File;

public class AddImageActivity extends AppCompatActivity {
private File imageFile;
private String filePath;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_image);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);


}

public void process(View view)
{

filePath = Environment.getExternalStorageDirectory() + "/" + System.currentTimeMillis() + ".jpeg";

File file = new File(filePath);

Uri output = Uri.fromFile(file);

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, output);

startActivityForResult(cameraIntent, 0);

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

switch (requestCode) {
case RESULT_OK:

Log.i( "MakeMachine", "resultCode: " + resultCode );
switch( resultCode )
{
case 0:
Log.i( "MakeMachine", "User cancelled" );
break;
case -1:
//Bitmap bm = BitmapFactory.decodeFile(filePath);
break;
}
break;

}

}
}
99 changes: 99 additions & 0 deletions app/src/main/java/com/example/user/pointie/AsyncHttp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.example.user.pointie;

import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;


import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* Created by user on 7/5/2017.
*/

public class AsyncHttp extends AsyncTask<Void, Void, ArrayList<String> >
{
String url;
ArrayList<String> arraylistitem;
public AsyncHttp()
{
arraylistitem = new ArrayList<String>();
if(url=="") this.url= new String();
else this.url = url;
}


@Override
protected ArrayList<String> doInBackground(Void ...params)
{
String[] images = {" ", " "};;
DefaultHttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("https://gitlab.com/snippets/1661382/raw");
HttpResponse response = null;
try {
response = client.execute(request);
} catch (IOException e) {
e.printStackTrace();
}
BufferedReader rd = null;
try {
rd = new BufferedReader
(new InputStreamReader(
response.getEntity().getContent()));
} catch (IOException e) {
e.printStackTrace();
}
String lines = new String();
String line = "";
StringBuilder stringBuilder = new StringBuilder();
try {
while ((line = rd.readLine()) != null) {
stringBuilder.append(line);
// textView.append(line);
}
lines = stringBuilder.toString();
Log.v("Json", lines);

} catch (IOException e) {
e.printStackTrace();
}
ObjectMapper mapper = new ObjectMapper();
try {
JavaType type = mapper.getTypeFactory().constructCollectionType(ArrayList.class, ImagePojo.class);

images= mapper.readValue(lines, String[].class);
} catch (IOException e) {
e.printStackTrace();
}
if (images==null)
arraylistitem = new ArrayList<String>( Arrays.asList(images));
ArrayList<String> s = new ArrayList<String>();
s.add(lines);
return s;
// return arraylistitem;

}
@Override
protected void onPostExecute( ArrayList<String> array) {
super.onPostExecute(array);
onResponse(array);
}
public void onResponse(ArrayList<String> array) {

}


}
80 changes: 80 additions & 0 deletions app/src/main/java/com/example/user/pointie/ImageAdapter.java

Large diffs are not rendered by default.

72 changes: 29 additions & 43 deletions app/src/main/java/com/example/user/pointie/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,61 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.provider.MediaStore;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.content.Intent;
import java.io.File;
import java.util.ArrayList;

import android.os.Environment;
import android.net.Uri;
import android.widget.GridView;
import android.widget.Toast;

import static android.R.attr.value;

public class MainActivity extends AppCompatActivity {
public void showTiles() {
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));



}

private File imageFile;
private String filePath;

private ArrayList<String> array;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void process(View view)
{
/*Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg");
Uri temp = Uri.fromFile(imageFile);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

intent.putExtra(MediaStore.EXTRA_OUTPUT, value); //Media
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);

startActivityForResult(intent, 0);*/
startActivity(new Intent(MainActivity.this, AddImageActivity.class));
// Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
// .setAction("Action", null).show();
}
});
new AsyncHttp() {
@Override
public void onResponse( ArrayList<String> array) {
super.onResponse(array);

filePath = Environment.getExternalStorageDirectory() + "/" + System.currentTimeMillis() + ".jpeg";
showTiles();
}
}.execute();

File file = new File(filePath);

Uri output = Uri.fromFile(file);

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, output);

startActivityForResult(cameraIntent, 0);

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

switch (requestCode) {
case RESULT_OK:

Log.i( "MakeMachine", "resultCode: " + resultCode );
switch( resultCode )
{
case 0:
Log.i( "MakeMachine", "User cancelled" );
break;
case -1:
//Bitmap bm = BitmapFactory.decodeFile(filePath);
break;
}
break;

}

}
}
57 changes: 57 additions & 0 deletions app/src/main/res/layout/activity_add_image.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.user.pointie.AddImageActivity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_add_image"
android:id="@+id/include" />

<Button
android:id="@+id/button3"
android:layout_width="145dp"
android:layout_height="107dp"
android:layout_marginBottom="25dp"
android:layout_gravity="center_vertical|center_horizontal"
android:text="Upload it!"
app:layout_anchor="@+id/include"
app:layout_anchorGravity="bottom|center_horizontal" />

<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:text="Camera"
android:onClick="process"
app:layout_anchor="@+id/include"
app:layout_anchorGravity="center_vertical|center_horizontal" />

<EditText
android:id="@+id/editText"
android:layout_marginTop="205dp"
android:layout_marginLeft="70dp"
android:layout_width="wrap_content"
android:layout_height="57dp"
android:ems="10"
android:inputType="textPersonName"
android:text="City" />


</android.support.design.widget.CoordinatorLayout>
Loading

0 comments on commit 21242e9

Please sign in to comment.