Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hds
flexin
android-app
Commits
62b759f7
Commit
62b759f7
authored
Oct 28, 2017
by
Nastuzzi Samy
Browse files
Print articles for each category
Print articles Optimization Prepare article tabs
parent
fb34bf55
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/fr/utc/simde/payutc/fragments/ArticleFragment.java
View file @
62b759f7
package
fr.utc.simde.payutc.fragments
;
import
android.annotation.SuppressLint
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.os.AsyncTask
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.widget.ImageView
;
...
...
@@ -10,7 +15,19 @@ import android.widget.TextView;
import
com.fasterxml.jackson.databind.JsonNode
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
fr.utc.simde.payutc.R
;
import
fr.utc.simde.payutc.tools.HTTPRequest
;
import
static
android
.
content
.
ContentValues
.
TAG
;
/**
* Created by Samy on 28/10/2017.
...
...
@@ -19,18 +36,21 @@ import fr.utc.simde.payutc.R;
public
class
ArticleFragment
extends
View
{
private
static
final
String
LOG_TAG
=
"_ArticleFragment"
;
private
int
articleI
d
;
private
int
i
d
;
private
int
price
;
private
String
name
;
private
String
u
rl
;
private
String
imageU
rl
;
private
LayoutInflater
layoutInflater
;
private
View
view
;
private
TextView
textView
;
private
ImageView
iv
;
private
HTTPRequest
request
;
private
LinearLayout
linearLayout
;
public
ArticleFragment
(
Activity
activity
,
final
JsonNode
article
)
{
public
ArticleFragment
(
final
Activity
activity
,
final
JsonNode
article
)
{
super
(
activity
);
/*
this.layoutInflater = LayoutInflater.from(activity);
...
...
@@ -38,17 +58,83 @@ public class ArticleFragment extends View {
this.textView = view.findViewById(R.id.text_article);
this.textView.setText(article.get("name").textValue());*/
this
.
id
=
article
.
get
(
"id"
).
intValue
();
this
.
price
=
article
.
get
(
"price"
).
intValue
();
this
.
name
=
article
.
get
(
"name"
).
textValue
();
this
.
imageUrl
=
article
.
get
(
"image_url"
).
textValue
();
setView
(
activity
);
}
public
void
setView
(
final
Activity
activity
)
{
TextView
t
=
new
TextView
(
activity
);
ImageView
iv
=
new
ImageView
(
activity
);
iv
=
new
ImageView
(
activity
);
iv
.
setTag
(
"image_article_"
+
Integer
.
toString
(
this
.
id
));
iv
.
setImageResource
(
R
.
mipmap
.
ic_launcher
);
t
.
setText
(
article
.
get
(
"name"
).
textValue
()
+
": "
);
LinearLayout
.
LayoutParams
parms
=
new
LinearLayout
.
LayoutParams
(
200
,
200
);
iv
.
setLayoutParams
(
parms
);
t
.
setText
(
this
.
name
+
": "
);
TextView
t2
=
new
TextView
(
activity
);
t2
.
setText
((
article
.
get
(
"price"
).
intValue
()
/
100
)
+
"€"
+
((
article
.
get
(
"price"
).
intValue
()
%
100
)
==
0
?
""
:
(((
article
.
get
(
"price"
).
intValue
()
%
100
)
<
10
?
"0"
:
""
)
+
(
article
.
get
(
"price"
).
intValue
()
%
100
))));
t2
.
setText
((
this
.
price
/
100
)
+
"€"
+
((
this
.
price
%
100
)
==
0
?
""
:
(((
this
.
price
%
100
)
<
10
?
"0"
:
""
)
+
(
this
.
price
%
100
))));
this
.
linearLayout
=
new
LinearLayout
(
activity
);
linearLayout
.
addView
(
iv
);
linearLayout
.
addView
(
t
);
linearLayout
.
addView
(
t2
);
if
(
this
.
imageUrl
!=
null
&&
!
this
.
imageUrl
.
equals
(
""
))
{
new
Thread
(){
@Override
public
void
run
()
{
request
=
new
HTTPRequest
(
imageUrl
);
if
(
request
.
get
()
==
200
)
{
activity
.
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
iv
.
setImageBitmap
(
request
.
getImageResponse
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
});
}
}
}.
start
();
//new DownloadImageTask(iv).execute(this.imageUrl);
}
}
public
class
DownloadImageTask
extends
AsyncTask
<
String
,
Void
,
Bitmap
>
{
private
ImageView
imageView
;
private
Bitmap
image
;
public
DownloadImageTask
(
ImageView
imageView
)
{
this
.
imageView
=
imageView
;
}
protected
Bitmap
doInBackground
(
String
...
urls
)
{
String
urldisplay
=
urls
[
0
];
try
{
URL
url
=
new
URL
(
urldisplay
);
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
connection
.
setDoInput
(
true
);
connection
.
connect
();
InputStream
input
=
connection
.
getInputStream
();
image
=
BitmapFactory
.
decodeStream
(
input
);
}
catch
(
Exception
e
)
{
image
=
null
;
}
return
image
;
}
@SuppressLint
(
"NewApi"
)
protected
void
onPostExecute
(
Bitmap
result
)
{
if
(
result
!=
null
)
{
imageView
.
setImageBitmap
(
result
);
}
}
}
public
View
getView
()
{
...
...
app/src/main/java/fr/utc/simde/payutc/fragments/ArticleGroupFragment.java
View file @
62b759f7
...
...
@@ -6,6 +6,7 @@ import android.view.View;
import
android.widget.GridLayout
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.ScrollView
;
import
android.widget.TabHost
;
import
android.widget.TextView
;
...
...
@@ -23,12 +24,13 @@ public class ArticleGroupFragment implements TabHost.TabContentFactory {
private
LayoutInflater
layoutInflater
;
private
View
view
;
private
ScrollView
scrollView
;
private
GridLayout
gridView
;
public
ArticleGroupFragment
(
final
Activity
activity
,
final
JsonNode
articleList
)
throws
Exception
{
this
.
layoutInflater
=
LayoutInflater
.
from
(
activity
);
this
.
view
=
this
.
layoutInflater
.
inflate
(
R
.
layout
.
fragment_article_group
,
null
);
this
.
gridView
=
this
.
view
.
findViewById
(
R
.
id
.
grid_article
);
this
.
gridView
=
this
.
view
.
findViewById
(
R
.
id
.
grid_article
s
);
createArticles
(
activity
,
articleList
);
}
...
...
@@ -36,6 +38,7 @@ public class ArticleGroupFragment implements TabHost.TabContentFactory {
public
void
createArticles
(
final
Activity
activity
,
final
JsonNode
articleList
)
throws
Exception
{
LinearLayout
linearLayout
=
new
LinearLayout
(
activity
);
linearLayout
.
setOrientation
(
LinearLayout
.
VERTICAL
);
for
(
JsonNode
article
:
articleList
)
{
if
(!
article
.
has
(
"id"
)
||
!
article
.
has
(
"price"
)
||
!
article
.
has
(
"name"
)
||
!
article
.
has
(
"active"
)
||
!
article
.
has
(
"cotisant"
)
||
!
article
.
has
(
"alcool"
)
||
!
article
.
has
(
"categorie_id"
)
||
!
article
.
has
(
"image_url"
)
||
!
article
.
has
(
"fundation_id"
))
throw
new
Exception
(
"Unexpected JSON"
);
...
...
app/src/main/res/layout/fragment_article.xml
View file @
62b759f7
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:
orientation=
"vertical
"
android:layout_
width
=
"wrap_content"
android:
layout_height=
"wrap_content
"
>
android:
layout_width=
"match_parent
"
android:layout_
height
=
"wrap_content"
android:
orientation=
"vertical
"
>
<ImageView
android:id=
"@+id/image_article"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
app:srcCompat=
"@mipmap/ic_launcher"
/>
<RelativeLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<ImageView
android:id=
"@+id/image_article"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:src=
"@mipmap/ic_launcher"
/>
</RelativeLayout>
<TextView
android:id=
"@+id/text_article"
...
...
app/src/main/res/layout/fragment_article_group.xml
View file @
62b759f7
...
...
@@ -5,10 +5,16 @@
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<
GridLayout
android:id=
"@+id/
grid
_article"
<
ScrollView
android:id=
"@+id/
scroll
_article
s
"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
android:layout_height=
"match_parent"
>
</GridLayout>
<GridLayout
android:id=
"@+id/grid_articles"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
</GridLayout>
</ScrollView>
</LinearLayout>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment