Skip to content

Commit cd93285

Browse files
committed
Add Feature to show Part Details in an App Activity.
1 parent 985820f commit cd93285

File tree

14 files changed

+619
-8
lines changed

14 files changed

+619
-8
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ For the first Start you has to go to Settings --> General --> Server URL and inp
88
(for example: yourserver.de/part-db ). Then go back on the main site and click on Scan Barcode, then it opens ZXing Reader and when he founds an
99
Barcode, it opens the Details site of the Part in your default browser.
1010

11+
When you want to use the feature to show Part Details internally (now Name, Description, Stock informations and Comment only) you has to
12+
add the show_data.php from the apk folder to your Part-DB Server directory.
13+
1114

1215
License Infos:
1316

14-
Part-DB-android: An Android Barcode Scanner for Part-DB
17+
Part-DB-android: An Android Barcode Scanner for Part-DB
1518
Copyright (C) 2016 by Jan Boehmer
1619

1720
This program is free software: you can redistribute it and/or modify

apks/Part-DBv0.2.apk

1.23 MB
Binary file not shown.

apks/show_data.php

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
/*
3+
part-db version 0.1
4+
Copyright (C) 2005 Christoph Lechner
5+
http://www.cl-projects.de/
6+
7+
part-db version 0.2+
8+
Copyright (C) 2009 K. Jacobs and others (see authors.php)
9+
http://code.google.com/p/part-db/
10+
11+
showData extension
12+
Copyright (C) 2016 J. Boehmer
13+
14+
15+
This program is free software; you can redistribute it and/or
16+
modify it under the terms of the GNU General Public License
17+
as published by the Free Software Foundation; either version 2
18+
of the License, or (at your option) any later version.
19+
20+
This program is distributed in the hope that it will be useful,
21+
but WITHOUT ANY WARRANTY; without even the implied warranty of
22+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23+
GNU General Public License for more details.
24+
25+
You should have received a copy of the GNU General Public License
26+
along with this program; if not, write to the Free Software
27+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28+
*/
29+
30+
include_once('start_session.php');
31+
32+
$messages = array();
33+
$fatal_error = false; // if a fatal error occurs, only the $messages will be printed, but not the site content
34+
35+
function print_details(Part &$p)
36+
{
37+
try {
38+
//Get Infos
39+
$id = strval($p -> get_id());
40+
$name = $p -> get_name();
41+
$desc = $p -> get_description();
42+
$instock = strval($p -> get_instock());
43+
$mininstock = strval($p -> get_mininstock());
44+
$comment = $p -> get_comment();
45+
$obsolete = $p -> get_obsolete();
46+
$visible = $p -> get_visible();
47+
$order_quantity = $p -> get_order_quantity();
48+
$manualorder = $p -> get_manual_order();
49+
$product_url = $p -> get_manufacturer_product_url();
50+
$pic_filename = $p -> get_master_picture_filename(true);
51+
52+
53+
//$footprint = $part->get_footprint();
54+
//$storelocation = $part -> get_storelocation();
55+
//$manufacturer = $part->get_manufacturer();
56+
//$category = $part->get_category();
57+
//$all_orderdetails = $part->get_orderdetails();
58+
59+
//Output Data Format
60+
print("PID@NAME@DESCRIPTION@INSTOCK@MININSTOCK@COMMENT@<p>\n");
61+
62+
//Print the real Part Data
63+
print($id . "@" . $name . "@" . $desc . "@" . $instock . "@" . $mininstock . "@" . $comment . "@<p>\n");
64+
}
65+
catch (Exception $e)
66+
{
67+
$messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
68+
$fatal_error = true;
69+
70+
}
71+
72+
}
73+
74+
/********************************************************************************
75+
*
76+
* Evaluate $_REQUEST
77+
*
78+
*********************************************************************************/
79+
80+
81+
$part_id = isset($_REQUEST['pid']) ? (integer)$_REQUEST['pid'] : 0;
82+
83+
84+
//Get Part Details
85+
try
86+
{
87+
$database = new Database();
88+
$log = new Log($database);
89+
$current_user = new User($database, $current_user, $log, 1); // admin
90+
$part = new Part($database, $current_user, $log, $part_id);
91+
$footprint = $part->get_footprint();
92+
$storelocation = $part->get_storelocation();
93+
$manufacturer = $part->get_manufacturer();
94+
$category = $part->get_category();
95+
$all_orderdetails = $part->get_orderdetails();
96+
97+
print_details($part);
98+
}
99+
catch (Exception $e)
100+
{
101+
$messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
102+
$fatal_error = true;
103+
104+
}
105+
106+
?>

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
applicationId "jbtronics.part_db"
1010
minSdkVersion 14
1111
targetSdkVersion 23
12-
versionName '1.1'
13-
versionCode 2
12+
versionName '0.2'
13+
versionCode 3
1414
}
1515
buildTypes {
1616
release {

app/src/main/AndroidManifest.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="jbtronics.part_db"
4-
>
3+
package="jbtronics.part_db">
54

65
<application
76
android:allowBackup="true"
@@ -24,6 +23,13 @@
2423
android:name="android.support.PARENT_ACTIVITY"
2524
android:value="jbtronics.part_db.barcode_scanner" />
2625
</activity>
26+
<activity android:name=".PartDetails"/>
27+
28+
2729
</application>
2830

31+
<uses-permission android:name="android.permission.INTERNET" />
32+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
33+
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
34+
2935
</manifest>
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/*
2+
* Part-DB-android: An Android Barcode Scanner for Part-DB
3+
* Copyright (C) 2016 by Jan Boehmer
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package jbtronics.part_db;
20+
21+
import android.content.Intent;
22+
import android.content.SharedPreferences;
23+
import android.os.StrictMode;
24+
import android.preference.PreferenceManager;
25+
import android.support.v7.app.AppCompatActivity;
26+
import android.os.Bundle;
27+
import android.util.Log;
28+
import android.widget.TextView;
29+
import android.widget.Toast;
30+
31+
import java.io.BufferedInputStream;
32+
import java.io.ByteArrayOutputStream;
33+
import java.io.File;
34+
import java.io.FileOutputStream;
35+
import java.io.IOException;
36+
import java.io.InputStream;
37+
import java.net.URL;
38+
import java.net.URLConnection;
39+
import java.nio.charset.StandardCharsets;
40+
41+
import jbtronics.part_db_classes.Part;
42+
43+
public class PartDetails extends AppCompatActivity {
44+
45+
public String part_id = "";
46+
public Part part;
47+
48+
//Views
49+
private TextView text_name, text_desc, text_instock, text_mininstock, text_comment;
50+
51+
@Override
52+
protected void onCreate(Bundle savedInstanceState) {
53+
super.onCreate(savedInstanceState);
54+
setContentView(R.layout.activity_part_details);
55+
56+
Intent intent = getIntent();
57+
Bundle b = intent.getExtras();
58+
if(b != null){
59+
if(!b.getString("pid").equals("")) {
60+
part_id = b.getString("pid");
61+
}
62+
}
63+
else{
64+
Toast.makeText(getApplicationContext(), "No Part ID were given", Toast.LENGTH_SHORT).show();
65+
finish();
66+
}
67+
68+
//Get Views
69+
text_name = (TextView) findViewById(R.id.detail_text_name);
70+
text_desc = (TextView) findViewById(R.id.detail_text_desc);
71+
text_instock = (TextView) findViewById(R.id.detail_text_instock);
72+
text_mininstock = (TextView) findViewById(R.id.detail_text_mininstock);
73+
text_comment = (TextView) findViewById(R.id.detail_text_comment);
74+
75+
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
76+
StrictMode.setThreadPolicy(policy);
77+
78+
downloadPartDetails();
79+
80+
}
81+
82+
void downloadPartDetails()
83+
{
84+
SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(this);
85+
String server_url = sPref.getString("part_db_url", "");
86+
//Ensure that server_url always ends with /
87+
server_url = server_url.trim();
88+
if(server_url.charAt(server_url.length()-1) != '/')
89+
{
90+
server_url = server_url + "/";
91+
}
92+
93+
String d = DownloadString(server_url + "show_data.php?pid=" + part_id);
94+
String[] datas = d.split("@<p>\n");
95+
96+
int index = -1;
97+
//ignore Line showing Data Format
98+
for(int n=0;n<datas.length;n++)
99+
{
100+
if(!datas[n].contains("PID@NAME@"))
101+
{
102+
index = n;
103+
}
104+
}
105+
106+
if(index == -1)
107+
{
108+
Toast toast = Toast.makeText(getApplicationContext(), "No Part found", Toast.LENGTH_SHORT);
109+
toast.show();
110+
finish();
111+
}
112+
else
113+
{
114+
part = new Part(datas[index]);
115+
applyPart(part);
116+
}
117+
118+
119+
}
120+
121+
void applyPart(Part p)
122+
{
123+
text_name.setText(p.getName().trim());
124+
text_desc.setText(p.getDescription());
125+
text_instock.setText(String.valueOf(p.getInstock()));
126+
text_mininstock.setText(String.valueOf(p.getMininstock()));
127+
text_comment.setText(p.getComment());
128+
}
129+
130+
public String DownloadString(String url_str) {
131+
try {
132+
URL url = new URL(url_str); //you can write here any link
133+
134+
//Define InputStreams to read from the URLConnection.
135+
InputStream is = url.openStream();
136+
137+
BufferedInputStream bis = new BufferedInputStream(is);
138+
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
139+
//We create an array of bytes
140+
byte[] data = new byte[50];
141+
int current;
142+
143+
while((current = bis.read(data,0,data.length)) != -1){
144+
buffer.write(data,0,current);
145+
}
146+
147+
return buffer.toString();
148+
149+
} catch (IOException e) {
150+
Log.d("Part-DB", "Error: " + e);
151+
Toast toast = Toast.makeText(getApplicationContext(), "Error downloading!", Toast.LENGTH_SHORT);
152+
toast.show();
153+
finish();
154+
}
155+
156+
return "";
157+
}
158+
159+
}

0 commit comments

Comments
 (0)