Commit 70a195da by Tuomas Riihimäki

Merge branch 'devel' of codecrew.fi:bortal into devel

2 parents 5ee58374 4a46eba9
Showing with 672 additions and 5 deletions
package fi.codecrew.moya.beans; package fi.codecrew.moya.beans;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Calendar;
import java.util.List; import java.util.List;
import javax.annotation.security.DeclareRoles; import javax.annotation.security.DeclareRoles;
...@@ -287,4 +288,17 @@ public class PlaceGroupBean implements PlaceGroupBeanLocal { ...@@ -287,4 +288,17 @@ public class PlaceGroupBean implements PlaceGroupBeanLocal {
public List<PlaceGroup> getPlacegroups(EventUser user) { public List<PlaceGroup> getPlacegroups(EventUser user) {
return pgfacade.find(user); return pgfacade.find(user);
} }
@Override
public void markGrouMembershipEntered(GroupMembership membership) {
membership.setEnteredEvent(Calendar.getInstance());
membership = gmemfacade.merge(membership);
}
@Override
public void markGrouMembershipNotEntered(GroupMembership membership) {
membership.setEnteredEvent(null);
membership = gmemfacade.merge(membership);
}
} }
...@@ -22,6 +22,8 @@ public interface PlaceGroupBeanLocal { ...@@ -22,6 +22,8 @@ public interface PlaceGroupBeanLocal {
List<GroupMembership> getMembershipsAndCreations(EventUser user); List<GroupMembership> getMembershipsAndCreations(EventUser user);
List<GroupMembership> getMemberships(EventUser user); List<GroupMembership> getMemberships(EventUser user);
List<PlaceGroup> getPlacegroups(EventUser user); List<PlaceGroup> getPlacegroups(EventUser user);
...@@ -30,4 +32,8 @@ public interface PlaceGroupBeanLocal { ...@@ -30,4 +32,8 @@ public interface PlaceGroupBeanLocal {
boolean associateToToken(EventUser user, String token); boolean associateToToken(EventUser user, String token);
void markGrouMembershipEntered(GroupMembership row);
void markGrouMembershipNotEntered(GroupMembership row);
} }
...@@ -138,7 +138,7 @@ public class GroupMembership extends GenericEntity { ...@@ -138,7 +138,7 @@ public class GroupMembership extends GenericEntity {
public void setEnteredEvent(Calendar enteredEvent) { public void setEnteredEvent(Calendar enteredEvent) {
this.enteredEvent = enteredEvent; this.enteredEvent = enteredEvent;
} }
public void setInviteToken(String inviteToken) { public void setInviteToken(String inviteToken) {
this.inviteToken = inviteToken; this.inviteToken = inviteToken;
} }
......
...@@ -110,6 +110,7 @@ public class Product extends GenericEntity { ...@@ -110,6 +110,7 @@ public class Product extends GenericEntity {
}) })
private List<Discount> discounts; private List<Discount> discounts;
@Column(name = "vat", nullable = false, precision = 4, scale = 3)
private BigDecimal vat = BigDecimal.ZERO; private BigDecimal vat = BigDecimal.ZERO;
private String unitName = ""; private String unitName = "";
......
...@@ -8,5 +8,10 @@ public enum ActionLogMessageState { ...@@ -8,5 +8,10 @@ public enum ActionLogMessageState {
public String getKey(){ public String getKey(){
return "actionlog.messagestate." + name(); return "actionlog.messagestate." + name();
} }
public String getName() {
return name();
}
} }
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<!-- f:event type="preRenderView" listener="#{newsListView.initView}" /--> <!-- f:event type="preRenderView" listener="#{newsListView.initView}" /-->
</f:metadata> </f:metadata>
<ui:define name="content"> <ui:define name="content">
<h:outputStylesheet library="style" name="insomnia2/css/actionlog.css" /> <h:outputStylesheet library="style" name="templates/insomnia2/css/actionlog.css" />
<h1>#{i18n['actionlog.messagelist.header']}</h1> <h1>#{i18n['actionlog.messagelist.header']}</h1>
<p>#{i18n['actionlog.messagelist.description']}</p> <p>#{i18n['actionlog.messagelist.description']}</p>
<h:form id="actionlog_create"> <h:form id="actionlog_create">
...@@ -45,8 +45,9 @@ ...@@ -45,8 +45,9 @@
<h2>#{i18n['actionlog.tasklist.header']}</h2> <h2>#{i18n['actionlog.tasklist.header']}</h2>
<div id="actionlog"> <div id="actionlog">
<h:form id="refresh"> <h:form id="refresh">
<p:poll interval="1" update="actionlogtable" onerror="location.reload();" /> <p:poll interval="10" update="actionlogtable" onerror="location.reload();" />
<p:dataTable styleClass="bordertable" id="actionlogtable" value="#{actionLogMessageView.messages}" var="message" paginator="true" rows="30" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="10,20,30,50,100" > <p:dataTable styleClass="bordertable" rowStyleClass="#{message.state.name}"
id="actionlogtable" value="#{actionLogMessageView.messages}" var="message" paginator="true" rows="30" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="30,50,100" >
<p:column> <p:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['actionlog.time']}" /> <h:outputText value="#{i18n['actionlog.time']}" />
...@@ -75,6 +76,13 @@ ...@@ -75,6 +76,13 @@
<h:outputText value="#{message.message}" /> <h:outputText value="#{message.message}" />
</p:column> </p:column>
<p:column> <p:column>
<f:facet name="header">
<h:outputText value="#{i18n['actionlog.state']}" />
</f:facet>
<h:outputText value="#{i18n[message.state.key]}" />
</p:column>
<p:column>
<h:link rendered="#{!empty message.state}" outcome="taskview"> <h:link rendered="#{!empty message.state}" outcome="taskview">
<f:param name="id" value="#{message.id}" /> <f:param name="id" value="#{message.id}" />
Näytä tehtävä Näytä tehtävä
......
...@@ -39,6 +39,47 @@ ...@@ -39,6 +39,47 @@
</h:panelGrid> </h:panelGrid>
<h:outputText rendered="#{empty incomingView.groupMemberships}" value="#{i18n['placegroupview.noMemberships']}" />
<h:form rendered="#{!empty incomingViewgroupMemberships}" id="placelistform">
<p:dataTable value="#{incomingView.groupMemberships}" var="member">
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['placegroupview.reservationName']}" />
</f:facet>
<h:outputText value="#{member.placeReservation.name}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['placegroupview.reservationProduct']}" />
</f:facet>
<h:outputText value="#{member.placeReservation.product.name}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['placegroupview.token']}" />
</f:facet>
<h:outputText rendered="#{empty member.user}" value="#{member.inviteToken}" />
<h:outputText rendered="#{!empty member.user}" value="#{member.user.firstnames} #{member.user.lastname} (#{member.user.nick})" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['placegroupview.groupCreator']}" />
</f:facet>
<h:outputText value="#{member.placeGroup.creator.firstnames} #{member.placeGroup.creator.lastname} (#{member.placeGroup.creator.nick})" />
</p:column>
<p:column>
<h:commandButton rendered="#{empty member.enteredEvent}" action="#{incomingView.givePlace}" value="#{i18n['incomingflow.giveplace']}" />
<h:commandButton rendered="#{!empty member.enteredEvent}" action="#{incomingView.ungivePlace}" value="#{i18n['incomingflow.ungiveplace']}" />
</p:column>
</p:dataTable>
</h:form>
<h1>#{i18n['incomingflow.search']}</h1> <h1>#{i18n['incomingflow.search']}</h1>
<h:form> <h:form>
......
...@@ -31,7 +31,9 @@ ...@@ -31,7 +31,9 @@
<h:message for="unitName" /> <h:message for="unitName" />
<h:outputLabel for="vat" value="#{i18n['product.vat']}:" /> <h:outputLabel for="vat" value="#{i18n['product.vat']}:" />
<h:inputText id="vat" value="#{productView.product.vat}" /> <h:inputText id="vat" value="#{productView.product.vat}">
<f:convertNumber type="percent" />
</h:inputText>
<h:message for="vat" /> <h:message for="vat" />
<h:outputLabel for="sort" value="#{i18n['product.sort']}:" /> <h:outputLabel for="sort" value="#{i18n['product.sort']}:" />
......
/* Actionlog */
#actionlog_create .row {
display: block;
clear: both;
}
#actionlog_create div, #actionlog_create h3 {
display: block;
float: left;
}
#actionlog_create h3 {
margin-bottom: 2px;
}
#actionlog_create .header {
font-weight: bold;
}
#actionlog_create .actionlog_create_role {
width: 100px;
}
#actionlog_create .actionlog_create_role select {
width: 100%;
margin: 0;
padding: 0;
border: 1px solid #aaa;
}
#actionlog_create .actionlog_create_message {
margin-left: 10px;
width: 420px;
}
#actionlog_create .actionlog_create_message input {
width: 100%;
margin: 0;
border: 1px solid #aaa;
}
#actionlog_create .actionlog_create_istask {
margin-left: 10px;
width: 60px;
}
#actionlog_create .actionlog_create_istask input {
display: block;
margin-left: auto;
margin-right: auto;
}
#actionlog_create input.sendbutton {
border: 1px solid #aaa;
margin-left: 10px;
}
#actionlog {
}
#actionlog table {
width: 100%;
border-collapse:collapse;
}
#actionlog tr {
}
#actionlog td {
}
#actionlog tr.roweven {
background-color: #aeaeae;
}
#actionlog tr.rowodd {
background-color: #9a9a9a;
}
.taskHeader {
color: #7DAC0C;
font-size: 120%;
font-weight: bold;
}
.sendbutton2 {
border: 1px solid #aaa;
margin-left: 10px;
}
/* End of actionlog */
#actionlog .DONE {
color: #006600;
}
#actionlog .NEW {
color: #660000;
}
#actionlog .PENDING {
color: #666600;
}
.expired {
color: #c0c0c0;
}
.paid {
color: #006600;
}
\ No newline at end of file
...@@ -14,12 +14,14 @@ ...@@ -14,12 +14,14 @@
<meta name="author" content="CodeCrew ry" /> <meta name="author" content="CodeCrew ry" />
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Language" content="#{sessionHandler.locale}" /> <meta http-equiv="Content-Language" content="#{sessionHandler.locale}" />
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/templates/custom_components.css" />
<link rel="icon" href="#{request.contextPath}/favicon.ico" type="image/x-icon" /> <link rel="icon" href="#{request.contextPath}/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="#{request.contextPath}/resources/templates/template1/css/normalize.min.css" /> <link rel="stylesheet" href="#{request.contextPath}/resources/templates/template1/css/normalize.min.css" />
<link rel="stylesheet" href="#{request.contextPath}/resources/templates/template1/css//main.css" /> <link rel="stylesheet" href="#{request.contextPath}/resources/templates/template1/css//main.css" />
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/templates/template1/css/style.css" /> <link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/templates/template1/css/style.css" />
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/templates/template1/css/general.css" /> <link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/templates/template1/css/general.css" />
<script src="#{request.contextPath}/resources/templates/template1/js/modernizr-2.6.2.min.js"></script> <script src="#{request.contextPath}/resources/templates/template1/js/modernizr-2.6.2.min.js"></script>
<h:outputStylesheet> <h:outputStylesheet>
.bgColor1 { .bgColor1 {
......
...@@ -157,6 +157,8 @@ global.save = Save ...@@ -157,6 +157,8 @@ global.save = Save
httpsession.creationTime = Created httpsession.creationTime = Created
incomingflow.giveplace = Merkitse annetuksi
lanEventPrivateProperty.defaultValue = Default value lanEventPrivateProperty.defaultValue = Default value
lanEventPrivateProperty.editProperty = Edit property lanEventPrivateProperty.editProperty = Edit property
lanEventPrivateProperty.save = Save lanEventPrivateProperty.save = Save
......
...@@ -409,8 +409,10 @@ importuser.file = File ...@@ -409,8 +409,10 @@ importuser.file = File
importuser.template = Template importuser.template = Template
incomingflow.barcode = Barcode incomingflow.barcode = Barcode
incomingflow.giveplace = Mark given
incomingflow.multisearch = Multisearch incomingflow.multisearch = Multisearch
incomingflow.search = Search incomingflow.search = Search
incomingflow.ungiveplace = Mark not given
incomingflow.userdetails = User details incomingflow.userdetails = User details
infoview.back = Back infoview.back = Back
......
...@@ -418,8 +418,10 @@ importuser.file = Tiedosto ...@@ -418,8 +418,10 @@ importuser.file = Tiedosto
importuser.template = Malli importuser.template = Malli
incomingflow.barcode = Viivakoodi incomingflow.barcode = Viivakoodi
incomingflow.giveplace = Merkitse annetuksi
incomingflow.multisearch = Monihaku incomingflow.multisearch = Monihaku
incomingflow.search = Etsi incomingflow.search = Etsi
incomingflow.ungiveplace = Ei olekkaan annettu
incomingflow.userdetails = K\u00E4ytt\u00E4j\u00E4n tiedot incomingflow.userdetails = K\u00E4ytt\u00E4j\u00E4n tiedot
index.title = Etusivu index.title = Etusivu
......
package fi.codecrew.moya.web.flow; package fi.codecrew.moya.web.flow;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.List; import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped; import javax.enterprise.context.ConversationScoped;
import javax.faces.model.ListDataModel;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
...@@ -16,11 +18,14 @@ import fi.codecrew.moya.beans.BarcodeBeanLocal; ...@@ -16,11 +18,14 @@ import fi.codecrew.moya.beans.BarcodeBeanLocal;
import fi.codecrew.moya.beans.CardTemplateBeanLocal; import fi.codecrew.moya.beans.CardTemplateBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal; import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.PlaceBeanLocal; import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.beans.PlaceGroupBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal; import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.enums.CardState; import fi.codecrew.moya.enums.CardState;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.enums.apps.UserPermission; import fi.codecrew.moya.enums.apps.UserPermission;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.GroupMembership; import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.PrintedCard; import fi.codecrew.moya.model.PrintedCard;
import fi.codecrew.moya.util.UserSearchQuery; import fi.codecrew.moya.util.UserSearchQuery;
import fi.codecrew.moya.utilities.SearchResult; import fi.codecrew.moya.utilities.SearchResult;
...@@ -64,11 +69,17 @@ public class IncomingView extends GenericCDIView { ...@@ -64,11 +69,17 @@ public class IncomingView extends GenericCDIView {
@EJB @EJB
private UserBeanLocal userbean; private UserBeanLocal userbean;
@EJB
private transient PlaceGroupBeanLocal placegroupBean;
private String searchBarcode = ""; private String searchBarcode = "";
private EventUser searchMulti = null; private EventUser searchMulti = null;
ListDataModel<GroupMembership> memberlist = null;
public void initView() { public void initView() {
super.beginConversation(); super.beginConversation();
} }
...@@ -116,6 +127,7 @@ public class IncomingView extends GenericCDIView { ...@@ -116,6 +127,7 @@ public class IncomingView extends GenericCDIView {
private boolean initialized = false; private boolean initialized = false;
public void initPrintCardView() { public void initPrintCardView() {
memberlist = null;
if (!permbean.hasPermission(UserPermission.MODIFY) || namecontainer.getReaderId() == null || namecontainer.getReaderId() <= 0) { if (!permbean.hasPermission(UserPermission.MODIFY) || namecontainer.getReaderId() == null || namecontainer.getReaderId() <= 0) {
super.navihandler.redirectNavigation("index.jsf"); super.navihandler.redirectNavigation("index.jsf");
} }
...@@ -179,6 +191,7 @@ public class IncomingView extends GenericCDIView { ...@@ -179,6 +191,7 @@ public class IncomingView extends GenericCDIView {
public String selectUser() { public String selectUser() {
EventUser user = readerView.getUser(); EventUser user = readerView.getUser();
memberlist = null;
if (user == null) { if (user == null) {
logger.debug("got no user from barcode"); logger.debug("got no user from barcode");
...@@ -215,5 +228,37 @@ public class IncomingView extends GenericCDIView { ...@@ -215,5 +228,37 @@ public class IncomingView extends GenericCDIView {
public void setSearchMulti(EventUser searchMulti) { public void setSearchMulti(EventUser searchMulti) {
this.searchMulti = searchMulti; this.searchMulti = searchMulti;
} }
public ListDataModel<GroupMembership> getGroupMemberships() {
memberlist = new ListDataModel<GroupMembership>(
placegroupBean.getMembershipsAndCreations(user));
return memberlist;
}
public String givePlace() {
GroupMembership row = memberlist.getRowData();
if (row != null) {
placegroupBean.markGrouMembershipEntered(row);
memberlist = null;
}
return null;
}
public String ungivePlace() {
GroupMembership row = memberlist.getRowData();
if (row != null) {
placegroupBean.markGrouMembershipNotEntered(row);
memberlist = null;
}
return null;
}
} }
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<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.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>AndroidBarcode</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.source=1.6
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fi.codecrew.androidbarcode"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="fi.codecrew.androidbarcode.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# 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 *;
#}
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-19
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/readBarcode"
android:onClick="readBarcode"
/>
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/readedCode"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/readedCode"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true"
android:inputType="text" />
<TextView
android:id="@+id/success_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/success"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#00AA00" />
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="70dp"
android:text="@string/readerName"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/seenInMoya"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="@+id/readerName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text" >
</EditText>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/change"
android:onClick="changeReaderName"
/>
</LinearLayout>
</ScrollView>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
</menu>
<resources>
<!--
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw600dp devices (e.g. 7" tablets) here.
-->
</resources>
<resources>
<!--
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
-->
<dimen name="activity_horizontal_margin">128dp</dimen>
</resources>
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">AndroidBarcode</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="readBarcode">Read Barcode</string>
<string name="readedCode">Got barcode</string>
<string name="readerName">Reader Name</string>
<string name="seenInMoya">(as seen in Moya)</string>
<string name="shared_pref_readername">readername</string>
<string name="change">Change</string>
<string name="success">Success</string>
</resources>
<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="android:Theme.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>
package fi.codecrew.androidbarcode;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
private static String URL = "http://demo.codecrew.fi/MoyaWeb/shop/rfidListener.jsf";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText readedCode = (EditText) findViewById(R.id.readedCode);
readedCode.requestFocus();
EditText readerName = (EditText) findViewById(R.id.readerName);
readerName.setText(getReaderName());
TextView successText = (TextView) findViewById(R.id.success_text);
successText.setVisibility(View.INVISIBLE);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void readBarcode(View view) {
TextView successText = (TextView) findViewById(R.id.success_text);
successText.setVisibility(View.INVISIBLE);
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
// intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE",
// "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
public void changeReaderName(View view) {
EditText readerName = (EditText) findViewById(R.id.readerName);
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString(getString(R.string.shared_pref_readername), readerName.getText().toString());
editor.commit();
readerName.clearFocus();
EditText readedCode = (EditText) findViewById(R.id.readedCode);
readedCode.requestFocus();
}
private String getReaderName() {
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
return sharedPref.getString(getString(R.string.shared_pref_readername), android.os.Build.USER + "_" + android.os.Build.HOST);
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
EditText readedCode = (EditText) findViewById(R.id.readedCode);
readedCode.requestFocus();
readedCode.setText(contents);
TextView successText = (TextView) findViewById(R.id.success_text);
if(sendBarcode(contents)) {
successText.setVisibility(View.VISIBLE);
}
Button readBcode = (Button) findViewById(R.id.button1);
readBcode.requestFocus();
} else if (resultCode == RESULT_CANCELED) {
}
}
}
private boolean sendBarcode(String barcode) {
try {
HttpClient client = new DefaultHttpClient();
String getUrl = URL + "?tag="+barcode+"&reader="+getReaderName();
HttpGet get = new HttpGet(getUrl);
HttpResponse responseGet = client.execute(get);
HttpEntity resEntityGet = responseGet.getEntity();
if (resEntityGet != null) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!