mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-06-30 21:04:16 +00:00
add project adins
This commit is contained in:
parent
ad06ac5505
commit
f8f85d679d
5299 changed files with 625430 additions and 0 deletions
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:clickable="true">
|
||||
<TextView android:id="@+id/textView1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textIsSelectable="true"
|
||||
android:textColor="@color/tv_dark"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="normal"
|
||||
android:background="@color/child_view_background"/>
|
||||
</LinearLayout>
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/LinearLayout1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:weightSum="1">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0.5" >
|
||||
<ScrollView
|
||||
android:id="@+id/scrollView1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:fillViewport="true" >
|
||||
|
||||
<TableLayout
|
||||
android:id="@+id/orderDetailTable"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:stretchColumns="1" >
|
||||
</TableLayout>
|
||||
</ScrollView>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/Bottomlayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.5">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnLookupCMO"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:onClick="doLookupCMO"
|
||||
android:text="@string/btnLookupCMO" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSubmit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:onClick="doSubmit"
|
||||
android:text="@string/btnSubmit" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/txtNotes"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_above="@+id/btnSubmit"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_below="@+id/txtCMO"
|
||||
android:ems="10"
|
||||
android:hint="@string/notes"
|
||||
android:inputType="textMultiLine" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtCMO"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@+id/btnLookupCMO"
|
||||
android:visibility="gone"
|
||||
android:text="@string/medium_text"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="14dp"
|
||||
android:height="14dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="@color/gradient_end"
|
||||
android:pathData="M16,1L8,1C6.34,1 5,2.34 5,4v16c0,1.66 1.34,3 3,3h8c1.66,0 3,-1.34 3,-3L19,4c0,-1.66 -1.34,-3 -3,-3zM14,21h-4v-1h4v1zM17.25,18L6.75,18L6.75,4h10.5v14z"/>
|
||||
</vector>
|
|
@ -0,0 +1,245 @@
|
|||
package com.adins.mss.base.todolist.form.followup;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.NewMainActivity;
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.todolist.form.OnTaskListClickListener;
|
||||
import com.adins.mss.base.todolist.form.TaskListTabInteractor;
|
||||
import com.adins.mss.base.todolist.form.TasklistView;
|
||||
import com.adins.mss.base.todolist.form.helper.TaskFilterParam;
|
||||
import com.adins.mss.base.todolist.form.helper.TaskPlanFilterObservable;
|
||||
import com.adins.mss.base.util.GsonHelper;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.TaskD;
|
||||
import com.adins.mss.dao.TaskH;
|
||||
import com.adins.mss.foundation.db.dataaccess.TaskHDataAccess;
|
||||
import com.adins.mss.foundation.formatter.Tool;
|
||||
import com.adins.mss.foundation.http.HttpConnectionResult;
|
||||
import com.adins.mss.foundation.http.HttpCryptedConnection;
|
||||
import com.adins.mss.foundation.http.MssRequestType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||
|
||||
public class FollowUpTabFragment extends Fragment implements TaskListTabInteractor.TabPage {
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private FollowUpAdapter followUpAdapter;
|
||||
private List<TaskH> taskHList;
|
||||
private Menu mainMenu;
|
||||
|
||||
public TaskListTabInteractor getTabInteractor() {
|
||||
return tabInteractor;
|
||||
}
|
||||
|
||||
public void setTabInteractor(TaskListTabInteractor tabInteractor) {
|
||||
this.tabInteractor = tabInteractor;
|
||||
}
|
||||
|
||||
private TaskListTabInteractor tabInteractor;
|
||||
|
||||
public FollowUpTabFragment(){
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_follow_up, container, false);
|
||||
recyclerView = view.findViewById(R.id.listTaskRv);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
|
||||
taskHList = new ArrayList<>();
|
||||
followUpAdapter = new FollowUpAdapter(getActivity(), taskHList, new OnTaskListClickListener() {
|
||||
@Override
|
||||
public void onItemClickListener(TaskH taskH, int position) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemLongClickListener(TaskH taskH, int position) {
|
||||
}
|
||||
}, "param");
|
||||
|
||||
recyclerView.setAdapter(followUpAdapter);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
menu.findItem(R.id.menuMore).setVisible(false);
|
||||
|
||||
setToolbar();
|
||||
}
|
||||
|
||||
private void setToolbar() {
|
||||
getActivity().findViewById(R.id.search).setVisibility(View.INVISIBLE);
|
||||
getActivity().findViewById(R.id.spinner).setVisibility(View.GONE);
|
||||
getActivity().setTitle("Menu");
|
||||
// olivia : set tampilan toolbar untuk masing" density
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
||||
switch (displayMetrics.densityDpi) {
|
||||
case DisplayMetrics.DENSITY_MEDIUM:
|
||||
getActivity().findViewById(R.id.search).setLayoutParams(new Toolbar.LayoutParams(200, WRAP_CONTENT));
|
||||
break;
|
||||
case DisplayMetrics.DENSITY_HIGH:
|
||||
if(NewMainActivity.ismnGuideEnabled)
|
||||
getActivity().findViewById(R.id.search).setLayoutParams(new Toolbar.LayoutParams(240, WRAP_CONTENT));
|
||||
else
|
||||
getActivity().findViewById(R.id.search).setLayoutParams(new Toolbar.LayoutParams(300, WRAP_CONTENT));
|
||||
break;
|
||||
case DisplayMetrics.DENSITY_XHIGH:
|
||||
if(NewMainActivity.ismnGuideEnabled)
|
||||
getActivity().findViewById(R.id.search).setLayoutParams(new Toolbar.LayoutParams(370, WRAP_CONTENT));
|
||||
else
|
||||
getActivity().findViewById(R.id.search).setLayoutParams(new Toolbar.LayoutParams(470, WRAP_CONTENT));
|
||||
break;
|
||||
case DisplayMetrics.DENSITY_XXHIGH:
|
||||
if(NewMainActivity.ismnGuideEnabled)
|
||||
getActivity().findViewById(R.id.search).setLayoutParams(new Toolbar.LayoutParams(560, WRAP_CONTENT));
|
||||
else
|
||||
getActivity().findViewById(R.id.search).setLayoutParams(new Toolbar.LayoutParams(710, WRAP_CONTENT));
|
||||
break;
|
||||
case DisplayMetrics.DENSITY_XXXHIGH:
|
||||
if(NewMainActivity.ismnGuideEnabled)
|
||||
getActivity().findViewById(R.id.search).setLayoutParams(new Toolbar.LayoutParams(750, WRAP_CONTENT));
|
||||
else
|
||||
getActivity().findViewById(R.id.search).setLayoutParams(new Toolbar.LayoutParams(950, WRAP_CONTENT));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTabPageName() {
|
||||
return TasklistView.FOLLOWUP_TAB_PAGE_TAG;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnterPage() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLeavePage() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
new LoadTasksAsyncTask().execute();
|
||||
}
|
||||
|
||||
private class LoadTasksAsyncTask extends AsyncTask<Void, Void, List<TaskListResponse>> {
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
progressDialog = ProgressDialog.show(getActivity(), "", getString(R.string.progressWait), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<TaskListResponse> doInBackground(Void... voids) {
|
||||
try {
|
||||
if(Tool.isInternetconnected(getContext())){
|
||||
String result = "";
|
||||
MssRequestType requestType = new MssRequestType();
|
||||
requestType.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
|
||||
String json = GsonHelper.toJson(requestType);
|
||||
String url = GlobalData.getSharedGlobalData().getURL_GET_FOLLOW_UP_LIST();
|
||||
boolean encrypt = GlobalData.getSharedGlobalData().isEncrypt();
|
||||
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
|
||||
HttpCryptedConnection httpConn = new HttpCryptedConnection(getContext(), encrypt, decrypt);
|
||||
HttpConnectionResult serverResult = null;
|
||||
serverResult = httpConn.requestToServer(url, json, Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
|
||||
if(serverResult != null){
|
||||
if(serverResult .isOK()){
|
||||
try {
|
||||
result = serverResult.getResult();
|
||||
FollowUpTaskListResponse response = GsonHelper.fromJson(result, FollowUpTaskListResponse.class);
|
||||
return response.getListFollowUpTask();
|
||||
}catch (Exception e){
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
FireCrash.log(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<TaskListResponse> tasks) {
|
||||
super.onPostExecute(tasks);
|
||||
taskHList.clear();
|
||||
List<FollowUpTask> followUpTasks = new ArrayList<>();
|
||||
if(tasks != null){
|
||||
for(TaskListResponse taskListResponse : tasks){
|
||||
FollowUpTask dummy = new FollowUpTask();
|
||||
TaskH dummyTaskH = new TaskH();
|
||||
|
||||
dummyTaskH.setUuid_task_h(taskListResponse.getUuidTaskH());
|
||||
dummyTaskH.setCustomer_name(taskListResponse.getCustomerName());
|
||||
dummyTaskH.setAppl_no(taskListResponse.getAgreementNo());
|
||||
dummyTaskH.setCustomer_address(taskListResponse.getCustomerAddress());
|
||||
dummyTaskH.setCustomer_phone(taskListResponse.getCustomerPhone());
|
||||
dummyTaskH.setOd(taskListResponse.getOverdueDays());
|
||||
dummyTaskH.setInst_no(taskListResponse.getInstallmentNo());
|
||||
dummyTaskH.setAmt_due(taskListResponse.getAmountDue());
|
||||
dummyTaskH.setStatus("Password");
|
||||
dummy.setTglJanjiBayar(taskListResponse.getTglJanjiBayar());
|
||||
dummy.setFlagTask(taskListResponse.getFlagTask());
|
||||
|
||||
dummy.setFollowUpTaskHeader(dummyTaskH);
|
||||
followUpTasks.add(dummy);
|
||||
}
|
||||
}
|
||||
|
||||
followUpAdapter.setFollowUpTasks(followUpTasks);
|
||||
if(progressDialog != null && progressDialog.isShowing()){
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,176 @@
|
|||
package com.adins.mss.svy.assignment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.util.Utility;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.TaskH;
|
||||
import com.adins.mss.foundation.UserHelp.UserHelp;
|
||||
import com.adins.mss.foundation.dialog.NiftyDialogBuilder;
|
||||
import com.adins.mss.svy.R;
|
||||
import com.adins.mss.svy.reassignment.JsonResponseServer;
|
||||
import com.adins.mss.svy.reassignment.JsonResponseServer.ResponseServer;
|
||||
import com.androidquery.AQuery;
|
||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
|
||||
import org.acra.ACRA;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.adins.mss.constant.Global.SHOW_USERHELP_DELAY_DEFAULT;
|
||||
|
||||
public class OrderAssignmentActivity extends Fragment {
|
||||
|
||||
protected View view;
|
||||
protected AQuery query;
|
||||
protected List<TaskH> allObjects;
|
||||
protected List<TaskH> objects;
|
||||
protected JsonResponseServer results;
|
||||
private List<ResponseServer> responseServer;
|
||||
private Bundle mArguments;
|
||||
// public static boolean isChange = false;
|
||||
public static boolean isChange = false;
|
||||
public static int selectedPosition = 9999;
|
||||
protected OrderAssignmentAdapter adapter;
|
||||
private ListView listView;
|
||||
private FirebaseAnalytics screenName;
|
||||
@Override
|
||||
public void onAttach(Context activity) {
|
||||
super.onAttach(activity);
|
||||
ACRA.getErrorReporter().putCustomData("LAST_CLASS_ACCESSED", getClass().getSimpleName());
|
||||
isChange = false;
|
||||
mArguments = getArguments();
|
||||
// getActivity().getActionBar().setTitle(getString(R.string.title_mn_surveyassign));
|
||||
results = (JsonResponseServer) mArguments.getSerializable("resultJson");
|
||||
responseServer = results.getListResponseServer();
|
||||
|
||||
// olivia : set toolbar
|
||||
getActivity().findViewById(com.adins.mss.base.R.id.search).setVisibility(View.GONE);
|
||||
getActivity().findViewById(com.adins.mss.base.R.id.spinner).setVisibility(View.GONE);
|
||||
getActivity().setTitle(getString(com.adins.mss.base.R.string.title_mn_surveyassign));
|
||||
|
||||
adapter = new OrderAssignmentAdapter(getActivity(), responseServer,false);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
Utility.freeMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume(){
|
||||
super.onResume();
|
||||
// getActivity().getActionBar().setTitle(getString(R.string.title_mn_surveyassign));
|
||||
//Set Firebase screen name
|
||||
screenName.setCurrentScreen(getActivity(), getString(R.string.screen_name_survey_assignment), null);
|
||||
|
||||
// olivia : set toolbar
|
||||
getActivity().findViewById(com.adins.mss.base.R.id.search).setVisibility(View.GONE);
|
||||
getActivity().findViewById(com.adins.mss.base.R.id.spinner).setVisibility(View.GONE);
|
||||
getActivity().setTitle(getString(com.adins.mss.base.R.string.title_mn_surveyassign));
|
||||
|
||||
if(isChange){
|
||||
if(selectedPosition!=9999){
|
||||
responseServer.remove(selectedPosition);
|
||||
adapter = new OrderAssignmentAdapter(getActivity(), responseServer,false);
|
||||
query.id(android.R.id.list).adapter(adapter);
|
||||
isChange=false;
|
||||
selectedPosition=9999;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
if (view != null) {
|
||||
ViewGroup parent = (ViewGroup) view.getParent();
|
||||
if (parent != null)
|
||||
parent.removeView(view);
|
||||
}
|
||||
try {
|
||||
view = inflater.inflate(R.layout.new_fragment_survey_assignment, container, false);
|
||||
query = new AQuery(view);
|
||||
listView = view.findViewById(android.R.id.list);
|
||||
query.id(listView).adapter(adapter);
|
||||
query.id(listView).itemClicked(this, "itemClick");
|
||||
screenName = FirebaseAnalytics.getInstance(getActivity());
|
||||
if(responseServer.size()==0){
|
||||
final NiftyDialogBuilder builder = NiftyDialogBuilder.getInstance(getActivity());
|
||||
builder.withTitle(getString(R.string.info_capital))
|
||||
.withMessage(getString(R.string.data_not_found))
|
||||
.withButton1Text(getString(R.string.btnOk))
|
||||
.isCancelable(false)
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
builder.dismiss();
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UserHelp.showAllUserHelpWithListView(OrderAssignmentActivity.this.getActivity(),
|
||||
OrderAssignmentActivity.this.getClass().getSimpleName(),
|
||||
listView,
|
||||
0);
|
||||
}
|
||||
}, SHOW_USERHELP_DELAY_DEFAULT);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if(item.getItemId() == R.id.mnGuide){
|
||||
if(!Global.BACKPRESS_RESTRICTION) {
|
||||
|
||||
Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UserHelp.showAllUserHelpWithListView(OrderAssignmentActivity.this.getActivity(),
|
||||
OrderAssignmentActivity.this.getClass().getSimpleName(),
|
||||
listView,
|
||||
0);
|
||||
}
|
||||
}, SHOW_USERHELP_DELAY_DEFAULT);
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Keep
|
||||
public void itemClick(AdapterView<?> parent, View v, int position, long id){
|
||||
selectedPosition = position;
|
||||
String nomorOrder = responseServer.get(position).getKey();
|
||||
String uuid_task_h = responseServer.get(position).getFlag();
|
||||
String formName = responseServer.get(position).getFormName();
|
||||
gotoDetailData(nomorOrder, uuid_task_h, formName);
|
||||
}
|
||||
private void gotoDetailData(String nomorOrder,String uuid_task_h,String formName) {
|
||||
Intent intent = new Intent(getActivity(), OrderAssignmentResult.class);
|
||||
intent.putExtra(Global.BUND_KEY_ORDERNO, nomorOrder);
|
||||
intent.putExtra(Global.BUND_KEY_FORM_NAME, formName);
|
||||
intent.putExtra(Global.BUND_KEY_TASK_TYPE, Global.TASK_ORDER_ASSIGNMENT);
|
||||
intent.putExtra(Global.BUND_KEY_UUID_TASKH, uuid_task_h);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,948 @@
|
|||
package com.adins.mss.base.dynamicform.form.questions;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.dynamicform.Constant;
|
||||
import com.adins.mss.base.dynamicform.DynamicFormActivity;
|
||||
import com.adins.mss.base.dynamicform.form.resolver.DateResolver;
|
||||
import com.adins.mss.base.dynamicform.form.resolver.DateTimeResolver;
|
||||
import com.adins.mss.base.dynamicform.form.resolver.TimeResolver;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.Holiday;
|
||||
import com.adins.mss.dao.LocationInfo;
|
||||
import com.adins.mss.dao.Lookup;
|
||||
import com.adins.mss.foundation.db.dataaccess.HolidayDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.LookupDataAccess;
|
||||
import com.adins.mss.foundation.formatter.Formatter;
|
||||
import com.adins.mss.foundation.formatter.Tool;
|
||||
import com.adins.mss.foundation.operators.IfElseFunction;
|
||||
import com.adins.mss.foundation.questiongenerator.NotEqualSymbol;
|
||||
import com.adins.mss.foundation.questiongenerator.OptionAnswerBean;
|
||||
import com.adins.mss.foundation.questiongenerator.QuestionBean;
|
||||
import com.gadberry.utility.expression.Expression;
|
||||
import com.gadberry.utility.expression.OperatorSet;
|
||||
import com.gadberry.utility.expression.symbol.AndSymbol;
|
||||
import com.gadberry.utility.expression.symbol.OrSymbol;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Created by gigin.ginanjar on 30/08/2016.
|
||||
*/
|
||||
public class QuestionsValidator implements QuestionsValidatorInterface {
|
||||
private static String TAG = "QuestionValidator";
|
||||
public static final String HOLIDAY_IS_NOT_ALLOWED = "1";
|
||||
private String msgRequired;
|
||||
private String dropdownRequired;
|
||||
private Context context;
|
||||
|
||||
public QuestionsValidator(String msgRequired, Context context) {
|
||||
this.msgRequired = msgRequired;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public static boolean regexIsMatch(String s, String pattern) {
|
||||
try {
|
||||
Pattern patt = Pattern.compile(pattern);
|
||||
Matcher matcher = patt.matcher(s);
|
||||
return matcher.matches();
|
||||
} catch (RuntimeException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> validateGeneratedQuestionView(QuestionBean bean) {
|
||||
List<String> errMessage = null;
|
||||
String answerType = bean.getAnswer_type();
|
||||
if (bean.getIs_visible().equals(Global.FALSE_STRING))
|
||||
return Collections.emptyList();
|
||||
if (QuestionViewAdapter.IsDropdownQuestion(Integer.valueOf(answerType))){
|
||||
return validateDropdownQuestion(bean);
|
||||
}else if (QuestionViewAdapter.IsTextQuestion(Integer.valueOf(answerType))) {
|
||||
return validateTextQuestion(bean);
|
||||
} else if (QuestionViewAdapter.IsDateTimeQuestion(Integer.valueOf(answerType))) {
|
||||
return validateDateTimeQuestion(bean);
|
||||
} else if (QuestionViewAdapter.IsTextWithSuggestionQuestion(Integer.valueOf(answerType))) {
|
||||
return validateTextWithSuggestionQuestion(bean);
|
||||
} else if (QuestionViewAdapter.IsLocationQuestion(Integer.valueOf(answerType))) {
|
||||
return validateLocationQuestion(bean);
|
||||
} else if (Tool.isOptions(answerType)) {
|
||||
return validateMultipleQuestion(bean);
|
||||
} else if (QuestionViewAdapter.IsImageQuestion(Integer.valueOf(answerType))) {
|
||||
return validateImageQuestion(bean);
|
||||
} else if (QuestionViewAdapter.IsDrawingQuestion(Integer.valueOf(answerType))) {
|
||||
return validateDrawingQuestion(bean);
|
||||
} else if (QuestionViewAdapter.IsLookupQuestion(Integer.valueOf(answerType))) {
|
||||
return validateLookupQuestion(bean);
|
||||
} else if (QuestionViewAdapter.IsValidationQuestion(Integer.valueOf(answerType))) {
|
||||
return validatePhoneNumberQuestion(bean);
|
||||
} else if (QuestionViewAdapter.IsRvMobileQuestion(Integer.valueOf(answerType))) {
|
||||
return validateRvMobileQuestion(bean);
|
||||
} else if (QuestionViewAdapter.isTextOnlineQuestion(Integer.valueOf(answerType))) {
|
||||
return validateTextQuestion(bean);
|
||||
} else if (QuestionViewAdapter.IsButtonViewUrlQuestion(Integer.valueOf(answerType))){
|
||||
return validateTextQuestion(bean);
|
||||
}
|
||||
|
||||
return errMessage;
|
||||
}
|
||||
|
||||
public List<String> validateLookupQuestion(QuestionBean bean) {
|
||||
List<String> errMessage = new ArrayList<>();
|
||||
if(Global.AT_LOOKUP_DUKCAPIL.equals(bean.getAnswer_type())){
|
||||
if (bean.isRelevantMandatory()) {
|
||||
if (bean.getAnswer() == null || bean.getAnswer().isEmpty()) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + msgRequired);
|
||||
}else if(bean.getDataDukcapil()==null || "".equals(bean.getDataDukcapil())){
|
||||
errMessage.add(bean.getQuestion_label() + ": " + context.getString(R.string.validation_required));
|
||||
}
|
||||
}
|
||||
if (bean.getIs_mandatory().equals(Global.TRUE_STRING)) {
|
||||
if (bean.getAnswer() == null || bean.getAnswer().isEmpty()) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + msgRequired);
|
||||
}else if(bean.getDataDukcapil()==null || "".equals(bean.getDataDukcapil())){
|
||||
errMessage.add(bean.getQuestion_label() + ": " + context.getString(R.string.validation_required));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
if (bean.isRelevantMandatory() && (bean.getAnswer() == null || bean.getAnswer().isEmpty())) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + msgRequired);
|
||||
}
|
||||
if (bean.getIs_mandatory().equals(Global.TRUE_STRING) && (bean.getAnswer() == null || bean.getAnswer().isEmpty())) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + msgRequired);
|
||||
}
|
||||
if (errMessage.isEmpty() && bean.getQuestion_validation() != null && !bean.getQuestion_validation().isEmpty() && QuestionBean.isHaveAnswer(bean)) {
|
||||
String script = bean.getQuestion_validation();
|
||||
String answerType = bean.getAnswer_type();
|
||||
String answer = QuestionBean.getAnswer(bean);
|
||||
if (!validateByScript(answer, answerType, script)) {
|
||||
if (bean.getValidate_err_message() != null && !bean.getValidate_err_message().isEmpty()) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + bean.getValidate_err_message());
|
||||
} else {
|
||||
errMessage.add(bean.getQuestion_label() + ": " + context.getString(R.string.input_not_valid));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errMessage;
|
||||
}
|
||||
public List<String> validateDropdownQuestion(QuestionBean bean) {
|
||||
List<String> errMessage = new ArrayList<>();
|
||||
if (Global.AT_DROPDOWN.equals(bean.getAnswer_type()) ||
|
||||
Global.AT_DROPDOWN_W_DESCRIPTION.equals(bean.getAnswer_type())){
|
||||
dropdownRequired = context.getString(R.string.dropdownmsgRequired);
|
||||
if (bean.isRelevantMandatory() && bean.getSelectedOptionAnswers().get(0).getCode().equals(context.getString(R.string.promptChooseOne))) {
|
||||
errMessage.add(dropdownRequired + " "+bean.getQuestion_label());
|
||||
}
|
||||
if (Global.TRUE_STRING.equals(bean.getIs_mandatory()) && null != bean.getSelectedOptionAnswers().get(0).getCode() &&
|
||||
context.getString(R.string.promptChooseOne).equals(bean.getSelectedOptionAnswers().get(0).getCode())) {
|
||||
errMessage.add(dropdownRequired + " "+bean.getQuestion_label());
|
||||
}
|
||||
if (!bean.getRegex().isEmpty() && bean.getAnswer() != null && !regexIsMatch(bean.getAnswer(), bean.getRegex())) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + "Invalid Input Format");
|
||||
}
|
||||
if(bean.getOptionAnswers() == null || bean.getOptionAnswers().isEmpty()){
|
||||
errMessage.add(context.getString(R.string.lookup_not_available, bean.getLov_group()));
|
||||
}
|
||||
if(bean.getSelectedOptionAnswers()!= null && !bean.getSelectedOptionAnswers().isEmpty() ){//validate whether in new task / save draft
|
||||
for(int i = 0 ; i < bean.getOptionAnswers().size() ; i++){
|
||||
if (!bean.getOptionAnswers().get(i).getCode().equals(bean.getSelectedOptionAnswers().get(0).getCode())){ // if LOV changed, set isChange to true
|
||||
bean.setIsCanChange(true);
|
||||
bean.setChange(true);
|
||||
} else {
|
||||
bean.setIsCanChange(false);
|
||||
bean.setChange(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(bean.isChange()){
|
||||
errMessage.add(dropdownRequired + " " + bean.getQuestion_label());
|
||||
}
|
||||
}
|
||||
}
|
||||
return errMessage;
|
||||
}
|
||||
public List<String> validateDrawingQuestion(QuestionBean bean) {
|
||||
List<String> errMessage = new ArrayList<>();
|
||||
|
||||
if (bean.getIs_mandatory().equals(Global.TRUE_STRING)) {
|
||||
byte[] img = bean.getImgAnswer();
|
||||
if (img == null || img.length < 1) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + msgRequired);
|
||||
}
|
||||
}
|
||||
if (bean.isRelevantMandatory()) {
|
||||
byte[] img = bean.getImgAnswer();
|
||||
if (img == null || img.length < 1) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + msgRequired);
|
||||
}
|
||||
}
|
||||
|
||||
return errMessage;
|
||||
}
|
||||
|
||||
public List<String> validateImageQuestion(QuestionBean bean) {
|
||||
List<String> errMessage = new ArrayList<>();
|
||||
if (DynamicFormActivity.getIsVerified() || DynamicFormActivity.getIsApproval()) {
|
||||
} else {
|
||||
if (bean.getIs_mandatory().equals(Global.TRUE_STRING) || bean.isRelevantMandatory()) {
|
||||
byte[] img = bean.getImgAnswer();
|
||||
if (img == null || img.length < 1) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + msgRequired);
|
||||
return errMessage;
|
||||
}
|
||||
String answerType = bean.getAnswer_type();
|
||||
if (answerType.equals(Global.AT_IMAGE_W_LOCATION) ||
|
||||
answerType.equals(Global.AT_IMAGE_W_GPS_ONLY)) {
|
||||
LocationInfo locationInfo = bean.getLocationInfo();
|
||||
if (locationInfo != null) {
|
||||
if (locationInfo.getLatitude().equals("0.0") || locationInfo.getLongitude().equals("0.0")) {
|
||||
if (answerType.equals((Global.AT_IMAGE_W_GPS_ONLY))) {
|
||||
errMessage.add(context.getString(R.string.gps_gd_error));
|
||||
} else {
|
||||
if (locationInfo.getMcc().equals("0") || locationInfo.getMnc().equals("0")) {
|
||||
errMessage.add(context.getString(R.string.lbs_gd_error));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
errMessage.add(context.getString(R.string.gps_error));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errMessage;
|
||||
}
|
||||
|
||||
public List<String> validateMultipleQuestion(QuestionBean bean) {
|
||||
List<String> errMessage = new ArrayList<>();
|
||||
|
||||
if ((bean.getIs_mandatory().equals(Global.TRUE_STRING) || bean.isRelevantMandatory()) && (bean.getSelectedOptionAnswers() == null || bean.getSelectedOptionAnswers().isEmpty())) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + msgRequired);
|
||||
}
|
||||
if (Global.AT_MULTIPLE_ONE_DESCRIPTION.equals(bean.getAnswer_type()) ||
|
||||
Global.AT_RADIO_W_DESCRIPTION.equals(bean.getAnswer_type())) {
|
||||
if ((!bean.getRegex().isEmpty() && bean.getAnswer() != null) && !regexIsMatch(bean.getAnswer(), bean.getRegex())) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + "Invalid Input Format");
|
||||
}
|
||||
} else if (Global.AT_MULTIPLE_W_DESCRIPTION.equals(bean.getAnswer_type()) && !bean.getSelectedOptionAnswers().isEmpty()) {
|
||||
String[] mDescription = bean.getAnswer().split(";");
|
||||
for (int i=0; i<mDescription.length; i++) {
|
||||
mDescription[i] = mDescription[i].trim();
|
||||
if (!mDescription[i].isEmpty() && (!bean.getRegex().isEmpty() && bean.getRegex() != null) && !regexIsMatch(mDescription[i], bean.getRegex())) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + "Invalid Input Format");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (errMessage.isEmpty() && bean.getQuestion_validation() != null && !bean.getQuestion_validation().isEmpty() && QuestionBean.isHaveAnswer(bean)) {
|
||||
String script = bean.getQuestion_validation();
|
||||
String answerType = bean.getAnswer_type();
|
||||
String answer = QuestionBean.getAnswer(bean);
|
||||
if (!validateByScript(answer, answerType, script)) {
|
||||
if (bean.getValidate_err_message() != null && !bean.getValidate_err_message().isEmpty()) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + bean.getValidate_err_message());
|
||||
} else {
|
||||
errMessage.add(bean.getQuestion_label() + ": " + context.getString(R.string.input_not_valid));
|
||||
}
|
||||
}
|
||||
}
|
||||
return errMessage;
|
||||
}
|
||||
|
||||
public List<String> validateTextQuestion(QuestionBean bean) {
|
||||
List<String> errMessage = new ArrayList<>();
|
||||
String answer = bean.getAnswer();
|
||||
if (Global.AT_CURRENCY.equals(bean.getAnswer_type()) && (answer != null && answer.length() > 0)) {
|
||||
String tempAnswer = Tool.deleteAll(answer, ",");
|
||||
String[] intAnswer = Tool.split(tempAnswer, ".");
|
||||
if (intAnswer.length > 1) {
|
||||
if (intAnswer[1].equals("00"))
|
||||
answer = intAnswer[0];
|
||||
else {
|
||||
answer = tempAnswer;
|
||||
}
|
||||
} else {
|
||||
answer = tempAnswer;
|
||||
}
|
||||
}
|
||||
bean.setAnswer(answer);
|
||||
if ((Global.TRUE_STRING.equals(bean.getIs_mandatory()) || bean.isRelevantMandatory()) && (answer == null || "".equals(answer))) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + msgRequired);
|
||||
}
|
||||
|
||||
String regex = "";
|
||||
regex = bean.getRegex();
|
||||
if (regex == null) regex = "";
|
||||
|
||||
if (errMessage.isEmpty() && !regex.equals("") && ((answer != null && !answer.isEmpty()) || bean.isMandatory() || bean.isRelevantMandatory())) {
|
||||
if (Global.IS_DEV) Log.i(TAG,"!regex.equals" + regex);
|
||||
if (!regexIsMatch(bean.getAnswer(), bean.getRegex())) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + "Invalid Input Format");
|
||||
}
|
||||
}
|
||||
if (errMessage.isEmpty() && bean.getQuestion_validation() != null && !bean.getQuestion_validation().isEmpty() && QuestionBean.isHaveAnswer(bean)) {
|
||||
String script = bean.getQuestion_validation();
|
||||
String answerType = bean.getAnswer_type();
|
||||
if (!validateByScript(answer, answerType, script)) {
|
||||
if (bean.getValidate_err_message() != null && !bean.getValidate_err_message().isEmpty()) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + bean.getValidate_err_message());
|
||||
} else {
|
||||
errMessage.add(bean.getQuestion_label() + ": " + context.getString(R.string.input_not_valid));
|
||||
}
|
||||
}
|
||||
}
|
||||
return errMessage;
|
||||
}
|
||||
|
||||
public List<String> validateTextWithSuggestionQuestion(QuestionBean bean) {
|
||||
List<String> errMessage = new ArrayList<>();
|
||||
String answer = bean.getAnswer();
|
||||
Lookup selectedOption = null;
|
||||
if (answer != null && !answer.isEmpty()) {
|
||||
List<OptionAnswerBean> selectedOptions = bean.getSelectedOptionAnswers();
|
||||
if (selectedOptions == null || selectedOptions.isEmpty()) {
|
||||
selectedOption = LookupDataAccess.getOneByValueAndlovGroup(context, bean.getLov_group(), answer);
|
||||
if (selectedOption == null) {
|
||||
if (!Tool.isInternetconnected(context))
|
||||
errMessage.add(bean.getQuestion_label() + ": " + answer + " " + context.getString(R.string.not_available));
|
||||
else
|
||||
errMessage.add(bean.getQuestion_label() + ": " + answer + " " + context.getString(R.string.not_allowed));
|
||||
} else{
|
||||
List<OptionAnswerBean> selected = new ArrayList<>();
|
||||
selected.add(new OptionAnswerBean(selectedOption));
|
||||
bean.setSelectedOptionAnswers(selected);
|
||||
}
|
||||
}else{
|
||||
selectedOption = selectedOptions.get(0);
|
||||
}
|
||||
}
|
||||
if ((Global.TRUE_STRING.equals(bean.getIs_mandatory()) || bean.isRelevantMandatory()) && (answer == null || answer.isEmpty())) {
|
||||
if (!errMessage.isEmpty())
|
||||
errMessage.add("\n");
|
||||
errMessage.add(bean.getQuestion_label() + " " + msgRequired);
|
||||
}
|
||||
String regex = "";
|
||||
regex = bean.getRegex();
|
||||
if (regex == null) regex = "";
|
||||
if (!regex.equals("") && !bean.getAnswer().trim().equals("")) {
|
||||
if (Global.IS_DEV) Log.i(TAG,"!regex.equals" + regex);
|
||||
if (!regexIsMatch(bean.getAnswer(), bean.getRegex())) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + "Invalid Input Format");
|
||||
}
|
||||
}
|
||||
if (errMessage.isEmpty() && selectedOption != null && bean.getQuestion_validation() != null && !bean.getQuestion_validation().isEmpty() && QuestionBean.isHaveAnswer(bean)) {
|
||||
String script = bean.getQuestion_validation();
|
||||
String answerType = bean.getAnswer_type();
|
||||
String answer2 = selectedOption.getCode();
|
||||
if (!validateByScript(answer2, answerType, script)) {
|
||||
if (bean.getValidate_err_message() != null && !bean.getValidate_err_message().isEmpty()) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + bean.getValidate_err_message());
|
||||
} else {
|
||||
errMessage.add(bean.getQuestion_label() + ": " + context.getString(R.string.input_not_valid));
|
||||
}
|
||||
}
|
||||
}
|
||||
return errMessage;
|
||||
}
|
||||
|
||||
public List<String> validateLocationQuestion(QuestionBean bean) {
|
||||
List<String> errMessage = new ArrayList<>();
|
||||
|
||||
if (!DynamicFormActivity.getIsVerified() && !DynamicFormActivity.getIsApproval()) {
|
||||
String answer = bean.getAnswer();
|
||||
|
||||
if ((Global.TRUE_STRING.equals(bean.getIs_mandatory()) || bean.isRelevantMandatory()) && (answer == null || "".equals(answer))) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + msgRequired);
|
||||
}
|
||||
}
|
||||
return errMessage;
|
||||
}
|
||||
|
||||
public List<String> validateDateTimeQuestion(QuestionBean bean) {
|
||||
List<String> errMessage = new ArrayList<>();
|
||||
|
||||
String answer = bean.getAnswer();
|
||||
Date date2 = null;
|
||||
boolean isSet = true;
|
||||
String answerType = bean.getAnswer_type();
|
||||
try {
|
||||
|
||||
String format = null;
|
||||
if (Global.AT_DATE.equals(answerType) || Global.AT_DATE_TIME.equals(answerType)) {
|
||||
format = Global.DATE_STR_FORMAT_GSON;
|
||||
date2 = Formatter.parseDate(answer, format);
|
||||
} else if (Global.AT_TIME.equals(answerType)) {
|
||||
format = Global.TIME_STR_FORMAT2;
|
||||
date2 = Formatter.parseDate(answer, format);
|
||||
}
|
||||
} catch (Exception pe) {
|
||||
try {
|
||||
String format = null;
|
||||
if (Global.AT_DATE.equals(answerType)) {
|
||||
format = Global.DATE_STR_FORMAT;
|
||||
date2 = Formatter.parseDate(answer, format);
|
||||
} else if (Global.AT_TIME.equals(answerType)) {
|
||||
format = Global.TIME_STR_FORMAT;
|
||||
date2 = Formatter.parseDate(answer, format);
|
||||
} else if (Global.AT_DATE_TIME.equals(answerType)) {
|
||||
format = Global.DATE_TIME_STR_FORMAT;
|
||||
date2 = Formatter.parseDate(answer, format);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
isSet = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (bean.getIs_holiday_allowed() != null && !bean.getIs_holiday_allowed().equals(HOLIDAY_IS_NOT_ALLOWED)) {
|
||||
Date date3 = null;
|
||||
if (Global.AT_DATE_TIME.equals(answerType)) {
|
||||
String date4;
|
||||
try {
|
||||
date4 = Formatter.formatDate(date2, Global.DATE_STR_FORMAT2);
|
||||
date3 = Formatter.parseDate(date4, Global.DATE_STR_FORMAT2);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
if(null != answer) {
|
||||
try {
|
||||
date3 = Formatter.parseDate(answer, Global.DATE_STR_FORMAT_GSON);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (date3 != null) {
|
||||
Holiday hday = HolidayDataAccess.getOneByDate(context, date3);
|
||||
if (hday != null) {
|
||||
errMessage.add(bean.getQuestion_label() + " "
|
||||
+ "can not set on " + hday.getH_desc());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((Global.TRUE_STRING.equals(bean.getIs_mandatory()) || bean.isRelevantMandatory()) && !isSet) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + msgRequired);
|
||||
}
|
||||
|
||||
int txtMaxLength = 0;
|
||||
try {
|
||||
//Nendi: 2019.07.01 | Add null check
|
||||
int maxLength = (bean.getMax_length() == null) ? 0 : bean.getMax_length();
|
||||
if (maxLength > 0) {
|
||||
Calendar now = Calendar.getInstance(TimeZone
|
||||
.getDefault());
|
||||
Calendar date = Calendar.getInstance(TimeZone
|
||||
.getDefault());
|
||||
date.setTime(date2);
|
||||
if (Global.AT_TIME.equals(answerType)) {
|
||||
date.set(Calendar.YEAR, now.get(Calendar.YEAR));
|
||||
date.set(Calendar.MONTH, now.get(Calendar.MONTH));
|
||||
date.set(Calendar.DAY_OF_MONTH, now.get(Calendar.DAY_OF_MONTH));
|
||||
}
|
||||
long diff = (date.getTime().getTime() - now.getTime()
|
||||
.getTime());
|
||||
long diffDay = diff / 86400000;
|
||||
long diffHour = diff % 86400000;
|
||||
long diffHours = diffHour / 3600000;
|
||||
if (diffHours > 0) {
|
||||
diffDay += 1;
|
||||
}
|
||||
|
||||
if (diffDay < 0) {
|
||||
txtMaxLength = (int) diffDay;
|
||||
} else if (diffDay > maxLength) {
|
||||
txtMaxLength = (int) diffDay;
|
||||
} else {
|
||||
txtMaxLength = maxLength;
|
||||
}
|
||||
} else {
|
||||
Date today = Tool.getSystemDate();
|
||||
Calendar now = Calendar.getInstance(TimeZone
|
||||
.getDefault());
|
||||
now.setTime(today);
|
||||
Calendar date = Calendar.getInstance(TimeZone
|
||||
.getDefault());
|
||||
date.setTime(date2);
|
||||
if (Global.AT_TIME.equals(answerType)) {
|
||||
date.set(Calendar.YEAR, now.get(Calendar.YEAR));
|
||||
date.set(Calendar.MONTH, now.get(Calendar.MONTH));
|
||||
date.set(Calendar.DAY_OF_MONTH, now.get(Calendar.DAY_OF_MONTH));
|
||||
}
|
||||
long diff = (date.getTime().getTime() - now.getTime()
|
||||
.getTime());
|
||||
long diffDay = diff / 86400000;
|
||||
|
||||
if (diffDay > 0) {
|
||||
txtMaxLength = (int) diffDay;
|
||||
} else if (diffDay < maxLength) {
|
||||
txtMaxLength = (int) diffDay;
|
||||
} else {
|
||||
txtMaxLength = maxLength;
|
||||
}
|
||||
}
|
||||
|
||||
if (maxLength == -999) {
|
||||
if (txtMaxLength > 0) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + context.getString(R.string.date_must_before_today));
|
||||
}
|
||||
} else if (maxLength < 0) {
|
||||
if (txtMaxLength > 0) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + context.getString(R.string.date_must_before_today));
|
||||
} else if (txtMaxLength < maxLength) {
|
||||
Calendar date = Calendar.getInstance(TimeZone
|
||||
.getDefault());
|
||||
date.setTime(Tool.getSystemDateTime());
|
||||
date.add(Calendar.DATE, maxLength);
|
||||
Date newDate = date.getTime();
|
||||
String sDate = Formatter.formatDate(newDate, Global.DATE_STR_FORMAT3);
|
||||
String message = bean.getQuestion_label() + " " + context.getString(R.string.more_than_date, sDate);
|
||||
errMessage.add(message);
|
||||
}
|
||||
} else if (maxLength > 0) {
|
||||
if (txtMaxLength < 0) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + context.getString(R.string.date_must_after_today));
|
||||
} else if (txtMaxLength > maxLength) {
|
||||
Calendar date = Calendar.getInstance(TimeZone
|
||||
.getDefault());
|
||||
date.setTime(Tool.getSystemDateTime());
|
||||
date.add(Calendar.DATE, maxLength);
|
||||
Date newDate = date.getTime();
|
||||
String sDate = Formatter.formatDate(newDate, Global.DATE_STR_FORMAT3);
|
||||
String message = bean.getQuestion_label() + " " + context.getString(R.string.less_than_date, sDate);
|
||||
errMessage.add(message);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (errMessage.isEmpty() && bean.getQuestion_validation() != null && !bean.getQuestion_validation().isEmpty() && QuestionBean.isHaveAnswer(bean)) {
|
||||
String script = bean.getQuestion_validation().trim();
|
||||
if (!validateByScript(answer, answerType, script)) {
|
||||
if (bean.getValidate_err_message() != null && !bean.getValidate_err_message().isEmpty()) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + bean.getValidate_err_message());
|
||||
} else {
|
||||
errMessage.add(bean.getQuestion_label() + ": " + context.getString(R.string.input_not_valid));
|
||||
}
|
||||
}
|
||||
}
|
||||
return errMessage;
|
||||
}
|
||||
|
||||
private List<String> validatePhoneNumberQuestion(QuestionBean bean) {
|
||||
List<String> errMessage = new ArrayList<>();
|
||||
String answer = bean.getAnswer();
|
||||
bean.setAnswer(answer);
|
||||
|
||||
if (bean.getIs_mandatory().equals(Global.TRUE_STRING)) {
|
||||
if (answer == null || "".equals(answer)) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + msgRequired);
|
||||
}
|
||||
}
|
||||
|
||||
String regex = "";
|
||||
regex = bean.getRegex();
|
||||
if (regex == null) regex = "";
|
||||
|
||||
if (errMessage.size() == 0) {
|
||||
if (!regex.equals("")) {
|
||||
if ((answer != null && !answer.isEmpty()) || bean.isMandatory()) {
|
||||
System.out.println("!regex.equals" + regex);
|
||||
if (regexIsMatch(bean.getAnswer(), bean.getRegex())) {
|
||||
|
||||
} else {
|
||||
errMessage.add(bean.getQuestion_label() + " " + "Invalid Input Format");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!bean.isBtnCheckClicked()) {
|
||||
if (!"".equals(answer)) {
|
||||
errMessage.add(bean.getQuestion_label() + ": " + context.getString(R.string.click_button_misscall_required));
|
||||
} else {
|
||||
errMessage.add(bean.getQuestion_label() + " " + msgRequired);
|
||||
}
|
||||
}
|
||||
|
||||
if (errMessage.size() == 0 && bean.getQuestion_validation() != null && !bean.getQuestion_validation().isEmpty() && QuestionBean.isHaveAnswer(bean)) {
|
||||
String script = bean.getQuestion_validation();
|
||||
String answerType = bean.getAnswer_type();
|
||||
if (!validateByScript(answer, answerType, script)) {
|
||||
if (bean.getValidate_err_message() != null && !bean.getValidate_err_message().isEmpty()) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + bean.getValidate_err_message());
|
||||
} else {
|
||||
errMessage.add(bean.getQuestion_label() + ": " + context.getString(R.string.input_not_valid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errMessage;
|
||||
}
|
||||
|
||||
public boolean validateByScript(String answer, String answerType, String script) {
|
||||
boolean isValid = false;
|
||||
String format = null;
|
||||
String convertedExpression = new String(script); //make a copy of
|
||||
if (convertedExpression == null || convertedExpression.length() == 0) {
|
||||
return true;
|
||||
} else {
|
||||
boolean needReplacing = true;
|
||||
while (needReplacing) {
|
||||
int idxOfOpenBrace = convertedExpression.indexOf('{');
|
||||
if (idxOfOpenBrace != -1) {
|
||||
int idxOfCloseBrace = convertedExpression.indexOf('}');
|
||||
String identifier = convertedExpression.substring(idxOfOpenBrace + 1, idxOfCloseBrace);
|
||||
int idxOfOpenAbs = identifier.indexOf("$");
|
||||
if (idxOfOpenAbs != -1) {
|
||||
String finalIdentifier = identifier.substring(idxOfOpenAbs + 1);
|
||||
String flatAnswer = "";
|
||||
if (finalIdentifier.equals(Global.IDF_LOGIN_ID)) {
|
||||
flatAnswer = GlobalData.getSharedGlobalData().getUser().getLogin_id();
|
||||
int idxOfOpenAt = flatAnswer.indexOf('@');
|
||||
if (idxOfOpenAt != -1) {
|
||||
flatAnswer = flatAnswer.substring(0, idxOfOpenAt);
|
||||
}
|
||||
} else if (finalIdentifier.equals(Global.IDF_BRANCH_ID)) {
|
||||
flatAnswer = GlobalData.getSharedGlobalData().getUser().getBranch_id();
|
||||
} else if (finalIdentifier.equals(Global.IDF_BRANCH_NAME)) {
|
||||
flatAnswer = GlobalData.getSharedGlobalData().getUser().getBranch_name();
|
||||
} else if (finalIdentifier.equals(Global.IDF_UUID_USER)) {
|
||||
flatAnswer = GlobalData.getSharedGlobalData().getUser().getUuid_user();
|
||||
} else if (finalIdentifier.equals(Global.IDF_JOB)) {
|
||||
flatAnswer = GlobalData.getSharedGlobalData().getUser().getFlag_job();
|
||||
} else if (finalIdentifier.equals(Global.IDF_DEALER_NAME)) {
|
||||
flatAnswer = GlobalData.getSharedGlobalData().getUser().getDealer_name();
|
||||
} else if (finalIdentifier.equals(Global.IDF_ANSWER_BEAN)) {
|
||||
try {
|
||||
if (answerType.equals(Global.AT_TIME)) {
|
||||
format = Global.TIME_STR_FORMAT;
|
||||
String formatDate = Global.TIME_STR_FORMAT2;
|
||||
Date date2 = null;
|
||||
try {
|
||||
date2 = Formatter.parseDate(answer, formatDate);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
date2 = Formatter.parseDate(answer, format);
|
||||
}
|
||||
Calendar now = Calendar.getInstance(TimeZone
|
||||
.getDefault());
|
||||
Calendar date = Calendar.getInstance(TimeZone
|
||||
.getDefault());
|
||||
date.setTime(date2);
|
||||
date.set(Calendar.YEAR, now.get(Calendar.YEAR));
|
||||
date.set(Calendar.MONTH, now.get(Calendar.MONTH));
|
||||
date.set(Calendar.DAY_OF_MONTH, now.get(Calendar.DAY_OF_MONTH));
|
||||
flatAnswer = Formatter.formatDate(date.getTime(), format);
|
||||
} else if (answerType.equals(Global.AT_DATE_TIME)) {
|
||||
format = Global.DATE_TIME_STR_FORMAT;
|
||||
String formatDate = Global.DATE_STR_FORMAT_GSON;
|
||||
Date date2 = null;
|
||||
try {
|
||||
date2 = Formatter.parseDate(answer, formatDate);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
date2 = Formatter.parseDate(answer, format);
|
||||
}
|
||||
Calendar date = Calendar.getInstance(TimeZone
|
||||
.getDefault());
|
||||
date.setTime(date2);
|
||||
flatAnswer = Formatter.formatDate(date.getTime(), format);
|
||||
} else if (answerType.equals(Global.AT_DATE)) {
|
||||
format = Global.DATE_STR_FORMAT;
|
||||
String formatDate = Global.DATE_STR_FORMAT_GSON;
|
||||
Date date2 = null;
|
||||
try {
|
||||
date2 = Formatter.parseDate(answer, formatDate);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
date2 = Formatter.parseDate(answer, format);
|
||||
}
|
||||
Calendar date = Calendar.getInstance(TimeZone
|
||||
.getDefault());
|
||||
date.setTime(date2);
|
||||
flatAnswer = Formatter.formatDate(date.getTime(), format);
|
||||
} else {
|
||||
flatAnswer = answer;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (finalIdentifier.equals(Global.IDF_THIS_YEAR)) {
|
||||
Calendar cal = Calendar.getInstance(TimeZone.getDefault());
|
||||
flatAnswer = String.valueOf(cal.get(Calendar.YEAR));
|
||||
} else if (finalIdentifier.equals(Global.IDF_NOWADAYS)) {
|
||||
Calendar cal = Calendar.getInstance(TimeZone.getDefault());
|
||||
try {
|
||||
if (answerType.equals(Global.AT_TIME)) {
|
||||
format = Global.TIME_STR_FORMAT;
|
||||
flatAnswer = Formatter.formatDate(cal.getTime(), format);
|
||||
} else if (answerType.equals(Global.AT_DATE)) {
|
||||
format = Global.DATE_STR_FORMAT;
|
||||
flatAnswer = Formatter.formatDate(cal.getTime(), format);
|
||||
} else {
|
||||
format = Global.DATE_TIME_STR_FORMAT;
|
||||
flatAnswer = Formatter.formatDate(cal.getTime(), format);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (finalIdentifier.equals(Global.IDF_YESTERDAY)) {
|
||||
Calendar cal = Calendar.getInstance(TimeZone.getDefault());
|
||||
cal.add(Calendar.DATE, -1);
|
||||
try {
|
||||
if (answerType.equals(Global.AT_TIME)) {
|
||||
format = Global.TIME_STR_FORMAT;
|
||||
flatAnswer = Formatter.formatDate(cal.getTime(), format);
|
||||
} else if (answerType.equals(Global.AT_DATE)) {
|
||||
format = Global.DATE_STR_FORMAT;
|
||||
flatAnswer = Formatter.formatDate(cal.getTime(), format);
|
||||
} else {
|
||||
format = Global.DATE_TIME_STR_FORMAT;
|
||||
flatAnswer = Formatter.formatDate(cal.getTime(), format);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
String regexDigit = "\\d+(?:\\.\\d+)?";
|
||||
if (flatAnswer != null && flatAnswer.length() > 0) {
|
||||
if(flatAnswer.matches(regexDigit)) {
|
||||
convertedExpression = convertedExpression.replace("{" + identifier + "}", flatAnswer);
|
||||
} else {
|
||||
convertedExpression = convertedExpression.replace("{" + identifier + "}", "'"+flatAnswer+"'");
|
||||
}
|
||||
} else {
|
||||
//if there's no answer, just hide the question
|
||||
return false;
|
||||
}
|
||||
|
||||
} else {
|
||||
QuestionBean bean = Constant.getListOfQuestion().get(identifier);
|
||||
if (bean != null) {
|
||||
String flatAnswer = QuestionBean.getAnswer(bean);
|
||||
if (flatAnswer != null && flatAnswer.length() > 0) {
|
||||
//NOTE: though it's possible to just iterate on flatAnswer substrings, we prefer to stay on method if size is 1
|
||||
String[] answers = Tool.split(flatAnswer, Global.DELIMETER_DATA);
|
||||
if (answers.length == 1) {
|
||||
try {
|
||||
if (bean.getAnswer_type().equals(Global.AT_TIME)) {
|
||||
format = Global.TIME_STR_FORMAT;
|
||||
String formatDate = Global.TIME_STR_FORMAT2;
|
||||
Date date2 = null;
|
||||
try {
|
||||
date2 = Formatter.parseDate(answers[0], formatDate);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
date2 = Formatter.parseDate(answers[0], format);
|
||||
}
|
||||
Calendar now = Calendar.getInstance(TimeZone
|
||||
.getDefault());
|
||||
Calendar date = Calendar.getInstance(TimeZone
|
||||
.getDefault());
|
||||
date.setTime(date2);
|
||||
date.set(Calendar.YEAR, now.get(Calendar.YEAR));
|
||||
date.set(Calendar.MONTH, now.get(Calendar.MONTH));
|
||||
date.set(Calendar.DAY_OF_MONTH, now.get(Calendar.DAY_OF_MONTH));
|
||||
flatAnswer = Formatter.formatDate(date.getTime(), format);
|
||||
} else if (bean.getAnswer_type().equals(Global.AT_DATE_TIME)) {
|
||||
format = Global.DATE_TIME_STR_FORMAT;
|
||||
String formatDate = Global.DATE_STR_FORMAT_GSON;
|
||||
Date date2 = null;
|
||||
try {
|
||||
date2 = Formatter.parseDate(answers[0], formatDate);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
date2 = Formatter.parseDate(answers[0], format);
|
||||
}
|
||||
Calendar date = Calendar.getInstance(TimeZone
|
||||
.getDefault());
|
||||
date.setTime(date2);
|
||||
flatAnswer = Formatter.formatDate(date.getTime(), format);
|
||||
} else if (bean.getAnswer_type().equals(Global.AT_DATE)) {
|
||||
format = Global.DATE_STR_FORMAT;
|
||||
String formatDate = Global.DATE_STR_FORMAT_GSON;
|
||||
Date date2 = null;
|
||||
try {
|
||||
date2 = Formatter.parseDate(answers[0], formatDate);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
date2 = Formatter.parseDate(answers[0], format);
|
||||
}
|
||||
Calendar date = Calendar.getInstance(TimeZone
|
||||
.getDefault());
|
||||
date.setTime(date2);
|
||||
flatAnswer = Formatter.formatDate(date.getTime(), format);
|
||||
} else {
|
||||
flatAnswer = answers[0];
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
String regexDigit = "\\d+(?:\\.\\d+)?";
|
||||
if(flatAnswer.matches(regexDigit)) {
|
||||
convertedExpression = convertedExpression.replace("{" + identifier + "}", flatAnswer);
|
||||
} else {
|
||||
convertedExpression = convertedExpression.replace("{" + identifier + "}", "'"+flatAnswer+"'");
|
||||
}
|
||||
} else {
|
||||
//NOTE: going into in-depth loop, won't go outside of this 'else'
|
||||
for (int i = 0; i < answers.length; i++) {
|
||||
String regexDigit = "\\d+(?:\\.\\d+)?";
|
||||
String convertedSubExpression = "";
|
||||
if(answers[i].matches(regexDigit)) {
|
||||
convertedSubExpression = convertedExpression.replace("{" + identifier + "}", answers[i]);
|
||||
} else {
|
||||
convertedSubExpression = convertedExpression.replace("{" + identifier + "}", "'"+answers[i]+"'");
|
||||
}
|
||||
boolean isVisible = validateByScript(answer, answerType, convertedSubExpression);
|
||||
if (isVisible) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
flatAnswer = "0";
|
||||
convertedExpression = convertedExpression.replace("{" + identifier + "}", flatAnswer);
|
||||
}
|
||||
} else {
|
||||
convertedExpression = convertedExpression.replace("{" + identifier + "}", "\"\"");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
needReplacing = false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
OperatorSet opSet = OperatorSet.getStandardOperatorSet();
|
||||
opSet.addOperator("!=", NotEqualSymbol.class);
|
||||
opSet.addOperator("if", IfElseFunction.class);
|
||||
opSet.addOperator("and", AndSymbol.class);
|
||||
opSet.addOperator("or", OrSymbol.class);
|
||||
convertedExpression = convertedExpression.replace("\"","'");
|
||||
Expression exp = new Expression(convertedExpression);
|
||||
exp.setOperatorSet(opSet);
|
||||
if (answerType.equals(Global.AT_DATE_TIME)) {
|
||||
exp.setResolver(new DateTimeResolver());
|
||||
} else if (answerType.equals(Global.AT_DATE)) {
|
||||
exp.setResolver(new DateResolver());
|
||||
} else if (answerType.equals(Global.AT_TIME)) {
|
||||
exp.setResolver(new TimeResolver());
|
||||
}
|
||||
isValid = exp.evaluate().toBoolean();
|
||||
return isValid;
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean validateAllMandatory(List<QuestionBean> listOfQuestions, boolean displayMessage) {
|
||||
boolean result = true;
|
||||
for (QuestionBean bean : listOfQuestions) {
|
||||
if (bean.getIs_mandatory().equals(Global.TRUE_STRING) && bean.getIs_visible().equals(Global.TRUE_STRING)) {
|
||||
boolean isHaveAnswer = QuestionBean.isHaveAnswer(bean);
|
||||
if (!isHaveAnswer) { //tidak ada isi
|
||||
if (displayMessage)
|
||||
Toast.makeText(context, bean.getQuestion_label() + " " + context.getString(R.string.msgRequired), Toast.LENGTH_SHORT).show();
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<String> validateRvMobileQuestion(QuestionBean bean) {//}, TextQuestionViewHolder view) {
|
||||
List<String> errMessage = new ArrayList<>();
|
||||
String answer = bean.getAnswer();//view.mQuestionAnswer.getText().toString().trim();
|
||||
if (Global.AT_CURRENCY.equals(bean.getAnswer_type())) {
|
||||
if (answer != null && answer.length() > 0) {
|
||||
String tempAnswer = Tool.deleteAll(answer, ",");
|
||||
String[] intAnswer = Tool.split(tempAnswer, ".");
|
||||
if (intAnswer.length > 1) {
|
||||
if (intAnswer[1].equals("00"))
|
||||
answer = intAnswer[0];
|
||||
else {
|
||||
answer = tempAnswer;
|
||||
}
|
||||
} else {
|
||||
answer = tempAnswer;
|
||||
}
|
||||
}
|
||||
}
|
||||
bean.setAnswer(answer);
|
||||
if (bean.getIs_mandatory().equals(Global.TRUE_STRING)) {
|
||||
if (answer == null || "".equals(answer)) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + msgRequired);
|
||||
}
|
||||
}
|
||||
|
||||
String regex = "";
|
||||
regex = bean.getRegex();
|
||||
if (regex == null) regex = "";
|
||||
|
||||
if (errMessage.size() == 0) {
|
||||
if (!regex.equals("")) {
|
||||
if ((answer != null && !answer.isEmpty()) || bean.isMandatory()) {
|
||||
System.out.println("!regex.equals" + regex);
|
||||
if (regexIsMatch(bean.getAnswer(), bean.getRegex())) {
|
||||
|
||||
} else {
|
||||
errMessage.add(bean.getQuestion_label() + " " + "Invalid Input Format");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (errMessage.size() == 0 && bean.getQuestion_validation() != null && !bean.getQuestion_validation().isEmpty() && QuestionBean.isHaveAnswer(bean)) {
|
||||
String script = bean.getQuestion_validation();
|
||||
String answerType = bean.getAnswer_type();
|
||||
if (!validateByScript(answer, answerType, script)) {
|
||||
if (bean.getValidate_err_message() != null && !bean.getValidate_err_message().isEmpty()) {
|
||||
errMessage.add(bean.getQuestion_label() + " " + bean.getValidate_err_message());
|
||||
} else {
|
||||
errMessage.add(bean.getQuestion_label() + ": " + context.getString(R.string.input_not_valid));
|
||||
}
|
||||
}
|
||||
}
|
||||
return errMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateCurrentPage(boolean isCekValidate, boolean isSave) {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package com.adins.mss.foundation.camerainapp;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.foundation.camerainapp.helper.BaseLinearLayout;
|
||||
|
||||
/**
|
||||
* Created by angga.permadi on 8/4/2016.
|
||||
*/
|
||||
public class AutoFocusItem extends BaseLinearLayout {
|
||||
|
||||
public AutoFocusItem(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterCreate() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.item_camera_auto_focus;
|
||||
}
|
||||
|
||||
public void bind(FocusMode mMode, float x, float y) {
|
||||
ImageView iv = (ImageView) query.id(R.id.iv_auto_focus).getView();
|
||||
|
||||
PorterDuff.Mode mode = PorterDuff.Mode.SRC_ATOP;
|
||||
Drawable d = null;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
d = getContext().getResources().getDrawable(R.drawable.ic_camera_auto_focus, getContext().getTheme());
|
||||
} else {
|
||||
d = getContext().getResources().getDrawable(R.drawable.ic_camera_auto_focus);
|
||||
}
|
||||
switch (mMode) {
|
||||
case START_FOCUS:
|
||||
// FIXME : image indicator autofocus jadi strech/kecil jika fokus di paling kanan atau bawah view
|
||||
RelativeLayout.LayoutParams params;
|
||||
params = new RelativeLayout.LayoutParams(300, 300);
|
||||
params.leftMargin = (int) x > 150 ? (int) x - 150 : 10;
|
||||
params.topMargin = (int) y > 150 ? (int) y - 150 : 10;
|
||||
iv.setLayoutParams(params);
|
||||
if (d != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
d.setColorFilter(getContext().getResources().getColor(android.R.color.black, getContext().getTheme()), mode);
|
||||
} else {
|
||||
d.setColorFilter(getContext().getResources().getColor(android.R.color.black), mode);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FOCUS_FAILED:
|
||||
if (d != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
d.setColorFilter(getContext().getResources().getColor(R.color.autoFocusFailed, getContext().getTheme()), mode);
|
||||
} else {
|
||||
d.setColorFilter(getContext().getResources().getColor(R.color.autoFocusFailed), mode);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FOCUS_SUCCESS:
|
||||
if (d != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
d.setColorFilter(getContext().getResources().getColor(R.color.autoFocusSuccess, getContext().getTheme()), mode);
|
||||
} else {
|
||||
d.setColorFilter(getContext().getResources().getColor(R.color.autoFocusSuccess), mode);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (d != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
d.setColorFilter(getContext().getResources().getColor(android.R.color.black, getContext().getTheme()), mode);
|
||||
} else {
|
||||
d.setColorFilter(getContext().getResources().getColor(android.R.color.black), mode);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
iv.setImageDrawable(d);
|
||||
}
|
||||
|
||||
public enum FocusMode {
|
||||
START_FOCUS,
|
||||
FOCUS_FAILED,
|
||||
FOCUS_SUCCESS,
|
||||
FOCUS_CONTINUOUS
|
||||
}
|
||||
}
|
|
@ -0,0 +1,363 @@
|
|||
package com.adins.mss.svy.reassignment;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.commons.TaskListener;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.util.GsonHelper;
|
||||
import com.adins.mss.base.util.LocaleHelper;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.foundation.dialog.NiftyDialogBuilder;
|
||||
import com.adins.mss.foundation.formatter.Formatter;
|
||||
import com.adins.mss.foundation.formatter.Tool;
|
||||
import com.adins.mss.foundation.http.HttpConnectionResult;
|
||||
import com.adins.mss.foundation.http.HttpCryptedConnection;
|
||||
import com.adins.mss.svy.R;
|
||||
import com.adins.mss.svy.models.ExpandableListAdapter;
|
||||
import com.adins.mss.svy.reassignment.JsonResponseServer.ResponseServer;
|
||||
|
||||
import org.acra.ACRA;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by winy.firdasari on 20/01/2015.
|
||||
*/
|
||||
public class ResultOrderActivity extends AppCompatActivity {
|
||||
private static String url = GlobalData.getSharedGlobalData().getURL_CHECKORDER();
|
||||
|
||||
protected String getUsedURL(){
|
||||
return GlobalData.getSharedGlobalData().getURL_CHECKORDER();
|
||||
}
|
||||
|
||||
ExpandableListAdapter listAdapter;
|
||||
|
||||
protected ExpandableListView expListView;
|
||||
protected List<String> listDataHeader;
|
||||
protected HashMap<String, List<String>> listDataChild;
|
||||
protected String startDate;
|
||||
protected String endDate;
|
||||
protected String orderNumber;
|
||||
protected String flag;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.new_survey_reassign_activity);
|
||||
|
||||
// olivia : set toolbar
|
||||
Toolbar toolbar = (Toolbar) findViewById(com.adins.mss.base.R.id.toolbar);
|
||||
toolbar.setTitle(getString(R.string.title_mn_surveyreassign));
|
||||
toolbar.setTitleTextColor(getResources().getColor(com.adins.mss.base.R.color.fontColorWhite));
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
ACRA.getErrorReporter().putCustomData("LAST_CLASS_ACCESSED", getClass().getSimpleName());
|
||||
initialize();
|
||||
|
||||
try {
|
||||
generateRequestParam();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
new ResultOrderTask().execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
Context context = newBase;
|
||||
Locale locale;
|
||||
try{
|
||||
locale = new Locale(GlobalData.getSharedGlobalData().getLocale());
|
||||
context = LocaleHelper.wrap(newBase, locale);
|
||||
} catch (Exception e) {
|
||||
locale = new Locale(LocaleHelper.ENGLSIH);
|
||||
context = LocaleHelper.wrap(newBase, locale);
|
||||
} finally {
|
||||
super.attachBaseContext(context);
|
||||
}
|
||||
}
|
||||
|
||||
TaskListener listener = new TaskListener() {
|
||||
@Override
|
||||
public void onCompleteTask(Object result) {
|
||||
processServerResponse(result.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelTask(boolean value) {
|
||||
//EMPTY
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocalData(Object result) {
|
||||
//EMPTY
|
||||
}
|
||||
};
|
||||
|
||||
protected void initialize() {
|
||||
Intent i = getIntent();
|
||||
// Receiving the Data
|
||||
String mStartDate = i.getStringExtra("startDate");
|
||||
String mEndDate = i.getStringExtra("endDate");
|
||||
String newflag= i.getStringExtra("flag");
|
||||
|
||||
ResultOrderActivity.url = getUsedURL();
|
||||
startDate=mStartDate;
|
||||
endDate=mEndDate;
|
||||
flag=Global.FLAG_BY_DATE;
|
||||
|
||||
if(newflag!=null){
|
||||
flag = newflag;
|
||||
}
|
||||
|
||||
if("orderTracking".equalsIgnoreCase(flag)){
|
||||
startDate="1";
|
||||
endDate="1";
|
||||
}
|
||||
|
||||
expListView = (ExpandableListView) findViewById(R.id.resultOrderlist);
|
||||
|
||||
// Listview Group click listener
|
||||
expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
|
||||
@Override
|
||||
public boolean onGroupClick(ExpandableListView parent, View v,
|
||||
int groupPosition, long id) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Listview Group expanded listener
|
||||
expListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
|
||||
@Override
|
||||
public void onGroupExpand(int groupPosition) {
|
||||
Toast.makeText(getApplicationContext(),
|
||||
listDataHeader.get(groupPosition) + " Expanded",
|
||||
Toast.LENGTH_SHORT);
|
||||
}
|
||||
});
|
||||
|
||||
// Listview Group collasped listener
|
||||
expListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
|
||||
@Override
|
||||
public void onGroupCollapse(int groupPosition) {
|
||||
Toast.makeText(getApplicationContext(),
|
||||
listDataHeader.get(groupPosition) + " Collapsed",
|
||||
Toast.LENGTH_SHORT);
|
||||
}
|
||||
});
|
||||
|
||||
// Listview on child click listener
|
||||
expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
|
||||
@Override
|
||||
public boolean onChildClick(ExpandableListView parent, View v,
|
||||
int groupPosition, int childPosition, long id) {
|
||||
|
||||
Toast.makeText(
|
||||
getApplicationContext(),
|
||||
listDataHeader.get(groupPosition)
|
||||
+ " : "
|
||||
+ listDataChild.get(
|
||||
listDataHeader.get(groupPosition)).get(
|
||||
childPosition), Toast.LENGTH_SHORT);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String getDataFromURL(String url) throws IOException {
|
||||
String resp = null;
|
||||
try {
|
||||
List<NameValuePair> param = generateRequestParam();
|
||||
|
||||
JsonRequestCheckOrder requestCheckOrder = new JsonRequestCheckOrder();
|
||||
requestCheckOrder.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
if(param.get(3).getValue().equals(Global.FLAG_BY_DATE)){
|
||||
requestCheckOrder.setStartDate(param.get(0).getValue());
|
||||
requestCheckOrder.setEndDate(param.get(1).getValue());
|
||||
}
|
||||
else if(param.get(3).getValue().equals(Global.FLAG_BY_ORDERNUMBER)){
|
||||
requestCheckOrder.setOrderNumber(param.get(2).getValue());
|
||||
}
|
||||
else if(param.get(3).getValue().equals(Global.FLAG_FOR_CANCELORDER)){
|
||||
if(param.get(2).getValue().equals("1")){
|
||||
requestCheckOrder.setStartDate(param.get(0).getValue());
|
||||
requestCheckOrder.setEndDate(param.get(1).getValue());
|
||||
}else{
|
||||
requestCheckOrder.setOrderNumber(param.get(2).getValue());
|
||||
}
|
||||
}
|
||||
else if(param.get(3).getValue().equals(Global.FLAG_FOR_ORDERREASSIGNMENT)){
|
||||
if(param.get(2).getValue().equals("1")){
|
||||
requestCheckOrder.setStartDate(param.get(0).getValue());
|
||||
requestCheckOrder.setEndDate(param.get(1).getValue());
|
||||
}else{
|
||||
requestCheckOrder.setOrderNumber(param.get(2).getValue());
|
||||
}
|
||||
requestCheckOrder.setFlag(param.get(3).getValue());
|
||||
}
|
||||
String json = GsonHelper.toJson(requestCheckOrder);
|
||||
boolean encrypt = GlobalData.getSharedGlobalData().isEncrypt();
|
||||
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
|
||||
HttpCryptedConnection httpConn = new HttpCryptedConnection(ResultOrderActivity.this, encrypt, decrypt);
|
||||
HttpConnectionResult serverResult = null;
|
||||
try {
|
||||
serverResult = httpConn.requestToServer(url, json, Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
resp = serverResult.getResult();
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
|
||||
resp=e.getMessage();
|
||||
}
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
protected List<NameValuePair> generateRequestParam() throws ParseException {
|
||||
String sdtSDate = "1";
|
||||
String sdtEDate = "1";
|
||||
if(startDate==null||endDate==null||"".equalsIgnoreCase(startDate)||"".equalsIgnoreCase(endDate)
|
||||
||"1".equalsIgnoreCase(startDate)||"1".equalsIgnoreCase(endDate)){
|
||||
|
||||
}else{
|
||||
//convert format date biar bisa di tranlate di DB servernya
|
||||
SimpleDateFormat f = new SimpleDateFormat(Global.DATE_STR_FORMAT);
|
||||
|
||||
Date sDate,eDate;
|
||||
sDate = f.parse(startDate);
|
||||
eDate = f.parse(endDate);
|
||||
sdtSDate = Formatter.formatDate(sDate, Global.DATE_STR_FORMAT_GSON);
|
||||
sdtEDate = Formatter.formatDate(eDate, Global.DATE_STR_FORMAT_GSON);
|
||||
}
|
||||
|
||||
|
||||
List<NameValuePair> param = new ArrayList<>();
|
||||
param.add(new BasicNameValuePair("startdate", sdtSDate));
|
||||
param.add(new BasicNameValuePair("enddate", sdtEDate));
|
||||
param.add(new BasicNameValuePair("ordernumber", orderNumber));
|
||||
param.add(new BasicNameValuePair("flag", flag));
|
||||
return param;
|
||||
}
|
||||
|
||||
protected void processServerResponse(String result) {
|
||||
if(GlobalData.isRequireRelogin()){
|
||||
return;
|
||||
}
|
||||
|
||||
listDataHeader = new ArrayList<>();
|
||||
listDataChild = new HashMap<>();
|
||||
|
||||
try {
|
||||
JsonResponseServer resultOrder = GsonHelper.fromJson(result, JsonResponseServer.class);
|
||||
for(int i=0;i<resultOrder.getListResponseServer().size();i++){
|
||||
ResponseServer responseServer = resultOrder.getListResponseServer().get(i);
|
||||
|
||||
String orderNo = responseServer.getKey();
|
||||
String customerName = responseServer.getValue();
|
||||
|
||||
listDataHeader.add(orderNo+" - "+customerName);
|
||||
List<ResponseServer> SubResultOrder = responseServer.getSubListResponseServer();
|
||||
List<String> statusOrder = new ArrayList<>();
|
||||
for(int ii = 0; ii < SubResultOrder.size(); ii++){
|
||||
ResponseServer subResponseServer = SubResultOrder.get(ii);
|
||||
statusOrder.add(subResponseServer.getValue());
|
||||
}
|
||||
|
||||
listDataChild.put(listDataHeader.get(i), statusOrder);
|
||||
listAdapter = new ExpandableListAdapter(ResultOrderActivity.this, listDataHeader, listDataChild);
|
||||
expListView.setAdapter(listAdapter);
|
||||
}
|
||||
} catch (Exception e) { FireCrash.log(e);
|
||||
if(Global.IS_DEV) System.out.println(e);
|
||||
final NiftyDialogBuilder builder = NiftyDialogBuilder.getInstance(this);
|
||||
builder.withTitle(getString(R.string.info_capital))
|
||||
.withMessage(this.getString(R.string.jsonParseFailed))
|
||||
.withButton1Text(getString(R.string.btnOk))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
builder.dismiss();
|
||||
finish();
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
}
|
||||
|
||||
private class ResultOrderTask extends AsyncTask<String, Void, String> {
|
||||
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
progressDialog = ProgressDialog.show(ResultOrderActivity.this,
|
||||
"", getString(R.string.progressWait), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... arg0) {
|
||||
|
||||
String result = null;
|
||||
if(Tool.isInternetconnected(getApplicationContext())){
|
||||
try {
|
||||
result = ResultOrderActivity.this.getDataFromURL(url);
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
try {
|
||||
progressDialog.dismiss();
|
||||
} catch (Exception e) { FireCrash.log(e);}
|
||||
|
||||
getApplicationContext().getString(R.string.jsonParseFailed);
|
||||
}
|
||||
}
|
||||
else{
|
||||
result = getString(R.string.no_internet_connection);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
|
||||
if (progressDialog!=null&&progressDialog.isShowing()){
|
||||
try {
|
||||
progressDialog.dismiss();
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
}
|
||||
if (getString(R.string.no_internet_connection).equals(result)) {
|
||||
NiftyDialogBuilder builder = NiftyDialogBuilder.getInstance(ResultOrderActivity.this);
|
||||
builder.withTitle(getString(R.string.info_capital))
|
||||
.withMessage(getString(R.string.no_internet_connection))
|
||||
.show();
|
||||
}else{
|
||||
processServerResponse(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 6.9 KiB |
|
@ -0,0 +1,23 @@
|
|||
package com.adins.mss.svy.fragments;
|
||||
|
||||
import com.adins.mss.base.commons.TaskListener;
|
||||
import com.adins.mss.base.todolist.form.TasklistListener;
|
||||
import com.adins.mss.svy.models.SurveyorSearchRequest;
|
||||
|
||||
import org.apache.http.NameValuePair;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by olivia.dg on 1/30/2018.
|
||||
*/
|
||||
|
||||
public interface SurveyActivityInterface {
|
||||
public void executeSearch(final TaskListener listener, SurveyorSearchRequest request, final String date, final int year, final int month, final String startDate,
|
||||
final String endDate, final int position) throws ParseException, IOException;
|
||||
public void getBackgroundTask(TasklistListener listener, boolean isVerification, boolean isBranch);
|
||||
public void gotoDetailData(int taskType, String nomorOrder, String uuid_task_h, String formName);
|
||||
public void getResultTask(TaskListener listener, List<NameValuePair> param);
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 7.5 KiB |
|
@ -0,0 +1,215 @@
|
|||
package com.adins.mss.dao;
|
||||
|
||||
import com.adins.mss.dao.DaoSession;
|
||||
import de.greenrobot.dao.DaoException;
|
||||
|
||||
import com.adins.mss.base.util.ExcludeFromGson;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit.
|
||||
/**
|
||||
* Entity mapped to table "TR_MOBILECONTENT_D".
|
||||
*/
|
||||
public class MobileContentD {
|
||||
|
||||
/** Not-null value. */
|
||||
@SerializedName("uuid_mobile_content_d")
|
||||
private String uuid_mobile_content_d;
|
||||
@SerializedName("menu_id")
|
||||
private String menu_id;
|
||||
@SerializedName("content")
|
||||
private byte[] content;
|
||||
@SerializedName("content_type")
|
||||
private String content_type;
|
||||
@SerializedName("sequence")
|
||||
private Integer sequence;
|
||||
@SerializedName("usr_crt")
|
||||
private String usr_crt;
|
||||
@SerializedName("dtm_crt")
|
||||
private java.util.Date dtm_crt;
|
||||
@SerializedName("usr_upd")
|
||||
private String usr_upd;
|
||||
@SerializedName("uuid_mobile_content_h")
|
||||
private String uuid_mobile_content_h;
|
||||
@SerializedName("start_date")
|
||||
private java.util.Date start_date;
|
||||
@SerializedName("end_date")
|
||||
private java.util.Date end_date;
|
||||
|
||||
/** Used to resolve relations */
|
||||
private transient DaoSession daoSession;
|
||||
|
||||
/** Used for active entity operations. */
|
||||
private transient MobileContentDDao myDao;
|
||||
|
||||
private MobileContentH mobileContentH;
|
||||
private String mobileContentH__resolvedKey;
|
||||
|
||||
|
||||
public MobileContentD() {
|
||||
}
|
||||
|
||||
public MobileContentD(String uuid_mobile_content_d) {
|
||||
this.uuid_mobile_content_d = uuid_mobile_content_d;
|
||||
}
|
||||
|
||||
public MobileContentD(String uuid_mobile_content_d, String menu_id, byte[] content, String content_type, Integer sequence, String usr_crt, java.util.Date dtm_crt, String usr_upd, String uuid_mobile_content_h, java.util.Date start_date, java.util.Date end_date) {
|
||||
this.uuid_mobile_content_d = uuid_mobile_content_d;
|
||||
this.menu_id = menu_id;
|
||||
this.content = content;
|
||||
this.content_type = content_type;
|
||||
this.sequence = sequence;
|
||||
this.usr_crt = usr_crt;
|
||||
this.dtm_crt = dtm_crt;
|
||||
this.usr_upd = usr_upd;
|
||||
this.uuid_mobile_content_h = uuid_mobile_content_h;
|
||||
this.start_date = start_date;
|
||||
this.end_date = end_date;
|
||||
}
|
||||
|
||||
/** called by internal mechanisms, do not call yourself. */
|
||||
public void __setDaoSession(DaoSession daoSession) {
|
||||
this.daoSession = daoSession;
|
||||
myDao = daoSession != null ? daoSession.getMobileContentDDao() : null;
|
||||
}
|
||||
|
||||
/** Not-null value. */
|
||||
public String getUuid_mobile_content_d() {
|
||||
return uuid_mobile_content_d;
|
||||
}
|
||||
|
||||
/** Not-null value; ensure this value is available before it is saved to the database. */
|
||||
public void setUuid_mobile_content_d(String uuid_mobile_content_d) {
|
||||
this.uuid_mobile_content_d = uuid_mobile_content_d;
|
||||
}
|
||||
|
||||
public String getMenu_id() {
|
||||
return menu_id;
|
||||
}
|
||||
|
||||
public void setMenu_id(String menu_id) {
|
||||
this.menu_id = menu_id;
|
||||
}
|
||||
|
||||
public byte[] getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(byte[] content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getContent_type() {
|
||||
return content_type;
|
||||
}
|
||||
|
||||
public void setContent_type(String content_type) {
|
||||
this.content_type = content_type;
|
||||
}
|
||||
|
||||
public Integer getSequence() {
|
||||
return sequence;
|
||||
}
|
||||
|
||||
public void setSequence(Integer sequence) {
|
||||
this.sequence = sequence;
|
||||
}
|
||||
|
||||
public String getUsr_crt() {
|
||||
return usr_crt;
|
||||
}
|
||||
|
||||
public void setUsr_crt(String usr_crt) {
|
||||
this.usr_crt = usr_crt;
|
||||
}
|
||||
|
||||
public java.util.Date getDtm_crt() {
|
||||
return dtm_crt;
|
||||
}
|
||||
|
||||
public void setDtm_crt(java.util.Date dtm_crt) {
|
||||
this.dtm_crt = dtm_crt;
|
||||
}
|
||||
|
||||
public String getUsr_upd() {
|
||||
return usr_upd;
|
||||
}
|
||||
|
||||
public void setUsr_upd(String usr_upd) {
|
||||
this.usr_upd = usr_upd;
|
||||
}
|
||||
|
||||
public String getUuid_mobile_content_h() {
|
||||
return uuid_mobile_content_h;
|
||||
}
|
||||
|
||||
public void setUuid_mobile_content_h(String uuid_mobile_content_h) {
|
||||
this.uuid_mobile_content_h = uuid_mobile_content_h;
|
||||
}
|
||||
|
||||
public java.util.Date getStart_date() {
|
||||
return start_date;
|
||||
}
|
||||
|
||||
public void setStart_date(java.util.Date start_date) {
|
||||
this.start_date = start_date;
|
||||
}
|
||||
|
||||
public java.util.Date getEnd_date() {
|
||||
return end_date;
|
||||
}
|
||||
|
||||
public void setEnd_date(java.util.Date end_date) {
|
||||
this.end_date = end_date;
|
||||
}
|
||||
|
||||
/** To-one relationship, resolved on first access. */
|
||||
public MobileContentH getMobileContentH() {
|
||||
String __key = this.uuid_mobile_content_h;
|
||||
if (mobileContentH__resolvedKey == null || mobileContentH__resolvedKey != __key) {
|
||||
if (daoSession == null) {
|
||||
throw new DaoException("Entity is detached from DAO context");
|
||||
}
|
||||
MobileContentHDao targetDao = daoSession.getMobileContentHDao();
|
||||
MobileContentH mobileContentHNew = targetDao.load(__key);
|
||||
synchronized (this) {
|
||||
mobileContentH = mobileContentHNew;
|
||||
mobileContentH__resolvedKey = __key;
|
||||
}
|
||||
}
|
||||
return mobileContentH;
|
||||
}
|
||||
|
||||
public void setMobileContentH(MobileContentH mobileContentH) {
|
||||
synchronized (this) {
|
||||
this.mobileContentH = mobileContentH;
|
||||
uuid_mobile_content_h = mobileContentH == null ? null : mobileContentH.getUuid_mobile_content_h();
|
||||
mobileContentH__resolvedKey = uuid_mobile_content_h;
|
||||
}
|
||||
}
|
||||
|
||||
/** Convenient call for {@link AbstractDao#delete(Object)}. Entity must attached to an entity context. */
|
||||
public void delete() {
|
||||
if (myDao == null) {
|
||||
throw new DaoException("Entity is detached from DAO context");
|
||||
}
|
||||
myDao.delete(this);
|
||||
}
|
||||
|
||||
/** Convenient call for {@link AbstractDao#update(Object)}. Entity must attached to an entity context. */
|
||||
public void update() {
|
||||
if (myDao == null) {
|
||||
throw new DaoException("Entity is detached from DAO context");
|
||||
}
|
||||
myDao.update(this);
|
||||
}
|
||||
|
||||
/** Convenient call for {@link AbstractDao#refresh(Object)}. Entity must attached to an entity context. */
|
||||
public void refresh() {
|
||||
if (myDao == null) {
|
||||
throw new DaoException("Entity is detached from DAO context");
|
||||
}
|
||||
myDao.refresh(this);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,750 @@
|
|||
package com.adins.mss.foundation.print;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.dynamicform.Constant;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.LogoPrint;
|
||||
import com.adins.mss.dao.PrintResult;
|
||||
import com.adins.mss.foundation.db.dataaccess.LogoPrintDataAccess;
|
||||
import com.bixolon.printer.BixolonPrinter;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
public class BixolonPrintManager extends AbstractPrintManager_ {
|
||||
protected static final String TAG = "TaskManager";
|
||||
Context context;
|
||||
public final Handler mHandler = new Handler(new Handler.Callback() {
|
||||
public boolean handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case BixolonPrinter.MESSAGE_STATE_CHANGE:
|
||||
switch (msg.arg1) {
|
||||
case BixolonPrinter.STATE_CONNECTING:
|
||||
// tried
|
||||
break;
|
||||
case BixolonPrinter.STATE_CONNECTED:
|
||||
connected = true;
|
||||
break;
|
||||
case BixolonPrinter.STATE_NONE:
|
||||
connected = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case BixolonPrinter.MESSAGE_DEVICE_NAME:
|
||||
msg.getData().getString(BixolonPrinter.KEY_STRING_DEVICE_NAME);
|
||||
break;
|
||||
case BixolonPrinter.MESSAGE_TOAST:
|
||||
Toast.makeText(
|
||||
context.getApplicationContext(),
|
||||
msg.getData()
|
||||
.getString(BixolonPrinter.KEY_STRING_TOAST),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
Bitmap logo = null;
|
||||
private BxlService mBxlService;
|
||||
|
||||
public BixolonPrintManager(Context context, List<PrintResult> list) {
|
||||
super(list);
|
||||
|
||||
//olivia : utk dapat logo sesuai nama tenant
|
||||
String tenant = GlobalData.getSharedGlobalData().getTenant();
|
||||
int pos = tenant.indexOf("@");
|
||||
String tenantName = tenant.substring(pos+1, tenant.length());
|
||||
|
||||
LogoPrint logoPrint = LogoPrintDataAccess.getOne(context, tenantName);
|
||||
if (logoPrint != null) {
|
||||
this.logo = BitmapFactory.decodeByteArray(logoPrint.getImage_bitmap(), 0, logoPrint.getImage_bitmap().length);
|
||||
} else {
|
||||
BitmapDrawable drawable = null;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
drawable = (BitmapDrawable) context.getResources().getDrawable(R.drawable.adins_logo, context.getTheme());
|
||||
} else {
|
||||
drawable = (BitmapDrawable) context.getResources().getDrawable(R.drawable.adins_logo);
|
||||
}
|
||||
this.logo = drawable.getBitmap();
|
||||
}
|
||||
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean connect() throws Exception {
|
||||
if (!connected) {
|
||||
mBxlService = new BxlService(BixolonPrintManager.this);
|
||||
connected = mBxlService.Connect() == BxlService.BXL_SUCCESS;
|
||||
}
|
||||
return connected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disconnect() throws Exception {
|
||||
if (connected && mBxlService != null) {
|
||||
mBxlService.Disconnect();
|
||||
mBxlService = null;
|
||||
connected = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String getDataToPrint() {
|
||||
int verticalPosition = 96; // 96, sebagai posisi awal
|
||||
char start = (char) 27;
|
||||
char end = (char) 3;
|
||||
|
||||
StringBuilder sbToPrint = new StringBuilder();
|
||||
for (PrintResult bean : Constant.getListOfPrintItem()) {
|
||||
String type = bean.getPrint_type_id();
|
||||
String vPosition = "";
|
||||
|
||||
if ((verticalPosition + 33) < 100) {
|
||||
verticalPosition = verticalPosition + 33;
|
||||
vPosition = "00" + verticalPosition;
|
||||
} else if ((verticalPosition + 33) < 1000) {
|
||||
verticalPosition = verticalPosition + 33;
|
||||
vPosition = "0" + verticalPosition;
|
||||
} else {
|
||||
vPosition = "" + verticalPosition;
|
||||
verticalPosition = verticalPosition + 33;
|
||||
|
||||
}
|
||||
if (Global.PRINT_NEW_LINE.equals(type)) {
|
||||
String label = bean.getLabel();
|
||||
sbToPrint.append(start).append(
|
||||
"L" + vPosition + "000101111000");
|
||||
sbToPrint.append(start).append("D" + label);
|
||||
} else if (Global.PRINT_LABEL_CENTER.equals(type)) {
|
||||
String label = bean.getLabel();
|
||||
// nilai sebenarnya 384, dikurangi aj bt jaga2 kalo slah perhtungan
|
||||
Vector vt = FontSato.wrap(374, label.trim());
|
||||
|
||||
for (int j = 0; j < vt.size(); j++) {
|
||||
SentencesSato setn = null;
|
||||
|
||||
try {
|
||||
setn = (SentencesSato) vt.elementAt(j);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV) Log.i(TAG, "eato " + e);
|
||||
}
|
||||
|
||||
// ------------- agar posisi bisa ditengah,
|
||||
if(setn == null)
|
||||
continue;
|
||||
|
||||
int iHposition = (384 - setn.getLenghtSentemce()) / 2;
|
||||
String sHposition = "0";
|
||||
|
||||
if (iHposition < 10) {
|
||||
sHposition = "000" + iHposition;
|
||||
} else if (iHposition < 100) {
|
||||
sHposition = "00" + iHposition;
|
||||
} else if (iHposition < 1000) {
|
||||
sHposition = "0" + iHposition;
|
||||
}
|
||||
// -------------
|
||||
|
||||
if (j == 0) {
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPosition
|
||||
+ sHposition
|
||||
+ "01111000");
|
||||
sbToPrint.append(start).append("D"
|
||||
+ setn.getSentence().trim());
|
||||
|
||||
} else {
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPrintPosition(verticalPosition)
|
||||
+ sHposition
|
||||
+ "01111000");
|
||||
sbToPrint.append(start).append("D"
|
||||
+ setn.getSentence().trim());
|
||||
|
||||
verticalPosition = verticalPosition + 33;
|
||||
}
|
||||
|
||||
}
|
||||
} else if (Global.PRINT_ANSWER.equals(type)) {
|
||||
String label = bean.getLabel();
|
||||
String answer = bean.getValue();
|
||||
if (answer != null && !answer.equals("")) {
|
||||
if (label.equals("")
|
||||
|| label == null
|
||||
|| label.equals("null")) { // jika pertanyaan tidak ada labelnya maka posisi ditengahkan
|
||||
|
||||
// nilai sebenarnya 384, dikurangi aj bt jaga2 kalo slah perhtungan
|
||||
Vector vt = FontSato.wrap(374, answer.trim());
|
||||
|
||||
for (int j = 0; j < vt.size(); j++) {
|
||||
|
||||
SentencesSato setn = null;
|
||||
|
||||
try {
|
||||
setn = (SentencesSato) vt.elementAt(j);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV) Log.i(TAG,"eato " + e);
|
||||
}
|
||||
|
||||
// ------------- agar posisi bisa ditengah,
|
||||
int iHposition = (384 - setn.getLenghtSentemce()) / 2;
|
||||
String sHposition = "0";
|
||||
|
||||
if (iHposition < 10) {
|
||||
sHposition = "000" + iHposition;
|
||||
} else if (iHposition < 100) {
|
||||
sHposition = "00" + iHposition;
|
||||
} else if (iHposition < 1000) {
|
||||
sHposition = "0" + iHposition;
|
||||
}
|
||||
// -------------
|
||||
|
||||
if (j == 0) {
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPosition
|
||||
+ sHposition
|
||||
+ "01111000");
|
||||
sbToPrint.append(start).append("D"
|
||||
+ setn.getSentence().trim());
|
||||
} else {
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPrintPosition(verticalPosition)
|
||||
+ sHposition
|
||||
+ "01111000");
|
||||
sbToPrint.append(start).append("D"
|
||||
+ setn.getSentence().trim());
|
||||
verticalPosition = verticalPosition + 33;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPosition
|
||||
+ "000101111000");
|
||||
sbToPrint.append(start).append("D" + label);
|
||||
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPosition
|
||||
+ "020001111000");
|
||||
sbToPrint.append(start).append("D:");
|
||||
|
||||
Vector vt;
|
||||
|
||||
vt = FontSato.wrap(166, answer.trim()); // panjang area yang akan diprint
|
||||
|
||||
for (int j = 0; j < vt.size(); j++) {
|
||||
|
||||
SentencesSato setn = null;
|
||||
|
||||
try {
|
||||
setn = (SentencesSato) vt.elementAt(j);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV) Log.i(TAG,"eato " + e);
|
||||
}
|
||||
if (j == 0) {
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPosition
|
||||
+ "0208"
|
||||
+ "01111000");
|
||||
sbToPrint.append(start).append("D"
|
||||
+ setn.getSentence().trim());
|
||||
} else {
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPrintPosition(verticalPosition)
|
||||
+ "0208"
|
||||
+ "01111000");
|
||||
verticalPosition = verticalPosition + 33;
|
||||
sbToPrint.append(start).append("D"
|
||||
+ setn.getSentence().trim());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
verticalPosition = verticalPosition - 33;
|
||||
}
|
||||
} else if (Global.PRINT_USER_NAME.equals(type)) {
|
||||
String label = bean.getLabel();
|
||||
String answer = GlobalData.getSharedGlobalData().getUser().getFullname();
|
||||
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPosition
|
||||
+ "000101111000");
|
||||
sbToPrint.append(start).append("D" + label);
|
||||
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPosition
|
||||
+ "020001111000");
|
||||
sbToPrint.append(start).append("D:");
|
||||
|
||||
Vector vt = FontSato.wrap(166, answer.trim()); // panjang area yang akan diprint
|
||||
|
||||
for (int j = 0; j < vt.size(); j++) {
|
||||
|
||||
SentencesSato setn = null;
|
||||
|
||||
try {
|
||||
setn = (SentencesSato) vt.elementAt(j);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV) Log.i(TAG,"eato " + e);
|
||||
}
|
||||
if (j == 0) {
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPosition
|
||||
+ "0208"
|
||||
+ "01111000");
|
||||
sbToPrint.append(start).append("D"
|
||||
+ setn.getSentence().trim());
|
||||
} else {
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPrintPosition(verticalPosition)
|
||||
+ "0208"
|
||||
+ "01111000");
|
||||
verticalPosition = verticalPosition + 33;
|
||||
sbToPrint.append(start).append("D"
|
||||
+ setn.getSentence().trim());
|
||||
}
|
||||
|
||||
}
|
||||
} else if (Global.PRINT_LOGIN_ID.equals(type)) {
|
||||
String label = bean.getLabel();
|
||||
String answer = GlobalData.getSharedGlobalData().getUser().getLogin_id();
|
||||
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPosition
|
||||
+ "000101111000");
|
||||
sbToPrint.append(start).append("D" + label);
|
||||
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPosition
|
||||
+ "020001111000");
|
||||
sbToPrint.append(start).append("D:");
|
||||
|
||||
Vector vt = FontSato.wrap(166, answer.trim()); // panjang area yang akan diprint
|
||||
|
||||
for (int j = 0; j < vt.size(); j++) {
|
||||
|
||||
SentencesSato setn = null;
|
||||
|
||||
try {
|
||||
setn = (SentencesSato) vt.elementAt(j);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV) Log.i(TAG,"eato " + e);
|
||||
}
|
||||
if (j == 0) {
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPosition
|
||||
+ "0208"
|
||||
+ "01111000");
|
||||
sbToPrint.append(start).append("D"
|
||||
+ setn.getSentence().trim());
|
||||
} else {
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPrintPosition(verticalPosition)
|
||||
+ "0208"
|
||||
+ "01111000");
|
||||
verticalPosition = verticalPosition + 33;
|
||||
sbToPrint.append(start).append("D"
|
||||
+ setn.getSentence().trim());
|
||||
}
|
||||
|
||||
}
|
||||
} else if (Global.PRINT_TIMESTAMP.equals(type)) {
|
||||
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy hh:mm");
|
||||
Date date = new Date();
|
||||
String answer = df.format(date);
|
||||
String label = bean.getLabel();
|
||||
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPosition
|
||||
+ "000101111000");
|
||||
sbToPrint.append(start).append("D" + label);
|
||||
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPosition
|
||||
+ "020001111000");
|
||||
sbToPrint.append(start).append("D:");
|
||||
|
||||
Vector vt = FontSato.wrap(166, answer.trim()); // panjang area yang akan diprint
|
||||
|
||||
for (int j = 0; j < vt.size(); j++) {
|
||||
|
||||
SentencesSato setn = null;
|
||||
|
||||
try {
|
||||
setn = (SentencesSato) vt.elementAt(j);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV) Log.i(TAG,"eato " + e);
|
||||
}
|
||||
if (j == 0) {
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPosition
|
||||
+ "0208"
|
||||
+ "01111000");
|
||||
sbToPrint.append(start).append("D"
|
||||
+ setn.getSentence().trim());
|
||||
} else {
|
||||
sbToPrint.append(start).append("L"
|
||||
+ vPrintPosition(verticalPosition)
|
||||
+ "0208"
|
||||
+ "01111000");
|
||||
verticalPosition = verticalPosition + 33;
|
||||
sbToPrint.append(start).append("D"
|
||||
+ setn.getSentence().trim());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// ENDING LINE
|
||||
verticalPosition = verticalPosition + 33;
|
||||
sbToPrint.append(start).append(
|
||||
"L" + vPrintPosition(verticalPosition) + "000101222000");
|
||||
sbToPrint.append(start).append("D----------------");
|
||||
|
||||
sbToPrint.append(start).append("Q0001").append(start).append("Z");
|
||||
sbToPrint.append(end);
|
||||
|
||||
return sbToPrint.toString();
|
||||
}
|
||||
|
||||
public String vPrintPosition(int verticalPosition) {
|
||||
String vPosition = "";
|
||||
if ((verticalPosition + 33) < 100) {
|
||||
verticalPosition = verticalPosition + 33;
|
||||
vPosition = "00" + verticalPosition;
|
||||
} else if ((verticalPosition + 33) < 1000) {
|
||||
verticalPosition = verticalPosition + 33;
|
||||
vPosition = "0" + verticalPosition;
|
||||
} else {
|
||||
vPosition = "" + verticalPosition;
|
||||
}
|
||||
|
||||
return vPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean printSato() throws Exception {
|
||||
if (connected) {
|
||||
mBxlService.PrintTextSato(this.getDataToPrint());
|
||||
} else {
|
||||
throw new Exception("Device is not connected to the printer.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String getDataToPrintZebra() {
|
||||
for (PrintResult bean : Constant.getListOfPrintItem()) {
|
||||
String type = bean.getPrint_type_id();
|
||||
if (Global.PRINT_NEW_LINE.equals(type)) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String label = bean.getLabel();
|
||||
sb.append(label);
|
||||
sb.append(blank);
|
||||
} else if (Global.PRINT_LABEL_CENTER.equals(type)) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String label = bean.getLabel();
|
||||
int labelLen = label.length();
|
||||
//1 line = 48 char
|
||||
int spaceLength = (48 - labelLen) / 2;
|
||||
while (spaceLength > 0) {
|
||||
sb.append(blank);
|
||||
spaceLength--;
|
||||
}
|
||||
sb.append(label);
|
||||
} else if (Global.PRINT_USER_NAME.equals(type) || Global.PRINT_LOGIN_ID.equals(type)) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String label = bean.getLabel();
|
||||
int labelLen = label.length();
|
||||
sb.append(label);
|
||||
int spaceLength = separatorStart - labelLen;
|
||||
while (spaceLength > 0) {
|
||||
sb.append(blank);
|
||||
spaceLength--;
|
||||
}
|
||||
sb.append(valueSeparator);
|
||||
sb.append(blank);
|
||||
|
||||
String value = GlobalData.getSharedGlobalData().getUser().getLogin_id();
|
||||
value = (value == null) ? "" : value;
|
||||
sb.append(value);
|
||||
} else if (Global.PRINT_ANSWER.equals(type)) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String label = bean.getLabel();
|
||||
int labelLen = label.length();
|
||||
if (label == null || label.equals("")) {
|
||||
//question no label = center
|
||||
String value = bean.getValue();
|
||||
int valueLen = value.length();
|
||||
int spaceLength = (48 - valueLen) / 2;
|
||||
while (spaceLength > 0) {
|
||||
sb.append(blank);
|
||||
spaceLength--;
|
||||
}
|
||||
sb.append(value);
|
||||
} else {
|
||||
sb.append(label);
|
||||
int spaceLength = separatorStart - labelLen;
|
||||
while (spaceLength > 0) {
|
||||
sb.append(blank);
|
||||
spaceLength--;
|
||||
}
|
||||
sb.append(valueSeparator);
|
||||
sb.append(blank);
|
||||
|
||||
String value = bean.getValue();
|
||||
value = (value == null) ? "" : value;
|
||||
sb.append(value);
|
||||
}
|
||||
} else if (Global.PRINT_TIMESTAMP.equals(type)) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String label = bean.getLabel();
|
||||
int labelLen = label.length();
|
||||
sb.append(label);
|
||||
int spaceLength = separatorStart - labelLen;
|
||||
while (spaceLength > 0) {
|
||||
sb.append(blank);
|
||||
spaceLength--;
|
||||
}
|
||||
sb.append(valueSeparator);
|
||||
sb.append(blank);
|
||||
|
||||
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy hh:mm");
|
||||
Date date = new Date();
|
||||
String value = df.format(date);
|
||||
value = (value == null) ? "" : value;
|
||||
sb.append(value);
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean printZebra() throws Exception {
|
||||
if (connected) {
|
||||
this.getDataToPrintZebra();
|
||||
} else {
|
||||
throw new Exception("Device is not connected to the printer.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean print() throws Exception {
|
||||
boolean isNeedFeedLine = true;
|
||||
if (connected) {
|
||||
for (PrintResult bean : list) {
|
||||
String type = bean.getPrint_type_id();
|
||||
if (Global.PRINT_NEW_LINE.equals(type)) {
|
||||
mBxlService.PrintText(bean.getLabel(),
|
||||
BxlService.BXL_ALIGNMENT_LEFT, BxlService.BXL_FT_DEFAULT,
|
||||
BxlService.BXL_TS_0WIDTH | BxlService.BXL_TS_0HEIGHT);
|
||||
} else if (Global.PRINT_BRANCH_ADDRESS.equals(type)) {
|
||||
mBxlService.PrintText(bean.getLabel(),
|
||||
BxlService.BXL_ALIGNMENT_CENTER, BxlService.BXL_FT_DEFAULT,
|
||||
BxlService.BXL_TS_0WIDTH | BxlService.BXL_TS_0HEIGHT);
|
||||
} else if (Global.PRINT_BRANCH_NAME.equals(type)) {
|
||||
mBxlService.PrintText(bean.getLabel(),
|
||||
BxlService.BXL_ALIGNMENT_CENTER, BxlService.BXL_FT_DEFAULT,
|
||||
BxlService.BXL_TS_0WIDTH | BxlService.BXL_TS_0HEIGHT);
|
||||
} else if (Global.PRINT_LABEL_CENTER.equals(type)) {
|
||||
mBxlService.PrintText(bean.getLabel(),
|
||||
BxlService.BXL_ALIGNMENT_CENTER, BxlService.BXL_FT_DEFAULT,
|
||||
BxlService.BXL_TS_0WIDTH | BxlService.BXL_TS_0HEIGHT);
|
||||
} else if (Global.PRINT_LABEL.equals(type)) {
|
||||
mBxlService.PrintText(bean.getLabel(),
|
||||
BxlService.BXL_ALIGNMENT_LEFT, BxlService.BXL_FT_DEFAULT,
|
||||
BxlService.BXL_TS_0WIDTH | BxlService.BXL_TS_0HEIGHT);
|
||||
} else if (Global.PRINT_LABEL_BOLD.equals(type)) {
|
||||
mBxlService.PrintText(bean.getLabel(),
|
||||
BxlService.BXL_ALIGNMENT_LEFT, BxlService.BXL_FT_BOLD,
|
||||
BxlService.BXL_TS_0WIDTH | BxlService.BXL_TS_0HEIGHT);
|
||||
} else if (Global.PRINT_LABEL_CENTER_BOLD.equals(type)) {
|
||||
mBxlService.PrintText(bean.getLabel(),
|
||||
BxlService.BXL_ALIGNMENT_CENTER, BxlService.BXL_FT_BOLD,
|
||||
BxlService.BXL_TS_0WIDTH | BxlService.BXL_TS_0HEIGHT);
|
||||
} else if (Global.PRINT_LOGO.equals(type)) {
|
||||
int SDK_INT = android.os.Build.VERSION.SDK_INT;
|
||||
if (SDK_INT < 14) {
|
||||
//di bawah ICS masuk sini
|
||||
mBxlService.PrintImage(logo,
|
||||
BxlService.BXL_WIDTH_FULL, BxlService.BXL_ALIGNMENT_CENTER, 20);
|
||||
} else {
|
||||
mBxlService.printBitmap(logo,
|
||||
BixolonPrinter.ALIGNMENT_CENTER, 384, 63, true);
|
||||
}
|
||||
|
||||
|
||||
} else if (Global.PRINT_ANSWER.equals(type)) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
String label = bean.getLabel();
|
||||
int labelLen = label.length();
|
||||
sb.append(label);
|
||||
int spaceLength = separatorStart - labelLen;
|
||||
while (spaceLength > 0) {
|
||||
sb.append(blank);
|
||||
spaceLength--;
|
||||
}
|
||||
sb.append(valueSeparator);
|
||||
sb.append(blank);
|
||||
|
||||
String value = bean.getValue();
|
||||
|
||||
|
||||
value = (value == null) ? "" : value;
|
||||
|
||||
|
||||
if ("".equalsIgnoreCase(value)) {
|
||||
isNeedFeedLine = false;
|
||||
} else {
|
||||
|
||||
if (null == label || "".equalsIgnoreCase(label)) {
|
||||
mBxlService.PrintText(value,
|
||||
BxlService.BXL_ALIGNMENT_CENTER, BxlService.BXL_FT_DEFAULT,
|
||||
BxlService.BXL_TS_0WIDTH | BxlService.BXL_TS_0HEIGHT);
|
||||
} else {
|
||||
sb.append(value);
|
||||
mBxlService.PrintText(sb.toString(),
|
||||
BxlService.BXL_ALIGNMENT_LEFT, BxlService.BXL_FT_DEFAULT,
|
||||
BxlService.BXL_TS_0WIDTH | BxlService.BXL_TS_0HEIGHT);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} else if (Global.PRINT_USER_NAME.equals(type)) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
String label = bean.getLabel();
|
||||
int labelLen = label.length();
|
||||
sb.append(label);
|
||||
int spaceLength = separatorStart - labelLen;
|
||||
while (spaceLength > 0) {
|
||||
sb.append(blank);
|
||||
spaceLength--;
|
||||
}
|
||||
sb.append(valueSeparator);
|
||||
sb.append(blank);
|
||||
|
||||
String value = GlobalData.getSharedGlobalData().getUser().getFullname();
|
||||
value = (value == null) ? "" : value;
|
||||
sb.append(value);
|
||||
|
||||
mBxlService.PrintText(sb.toString(),
|
||||
BxlService.BXL_ALIGNMENT_LEFT, BxlService.BXL_FT_DEFAULT,
|
||||
BxlService.BXL_TS_0WIDTH | BxlService.BXL_TS_0HEIGHT);
|
||||
} else if (Global.PRINT_LOGIN_ID.equals(type)) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
String label = bean.getLabel();
|
||||
int labelLen = label.length();
|
||||
sb.append(label);
|
||||
int spaceLength = separatorStart - labelLen;
|
||||
while (spaceLength > 0) {
|
||||
sb.append(blank);
|
||||
spaceLength--;
|
||||
}
|
||||
sb.append(valueSeparator);
|
||||
sb.append(blank);
|
||||
|
||||
String value = GlobalData.getSharedGlobalData().getUser().getLogin_id();
|
||||
value = (value == null) ? "" : value;
|
||||
sb.append(value);
|
||||
|
||||
mBxlService.PrintText(sb.toString(),
|
||||
BxlService.BXL_ALIGNMENT_LEFT, BxlService.BXL_FT_DEFAULT,
|
||||
BxlService.BXL_TS_0WIDTH | BxlService.BXL_TS_0HEIGHT);
|
||||
} else if (Global.PRINT_BT_ID.equals(type)) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
String label = bean.getLabel();
|
||||
int labelLen = label.length();
|
||||
sb.append(label);
|
||||
int spaceLength = separatorStart - labelLen;
|
||||
while (spaceLength > 0) {
|
||||
sb.append(blank);
|
||||
spaceLength--;
|
||||
}
|
||||
sb.append(valueSeparator);
|
||||
sb.append(blank);
|
||||
String value = "?";
|
||||
try {
|
||||
value = bean.getValue();
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
|
||||
}
|
||||
value = (value == null) ? "" : value;
|
||||
sb.append(value);
|
||||
|
||||
mBxlService.PrintText(sb.toString(),
|
||||
BxlService.BXL_ALIGNMENT_LEFT, BxlService.BXL_FT_DEFAULT,
|
||||
BxlService.BXL_TS_0WIDTH | BxlService.BXL_TS_0HEIGHT);
|
||||
} else if (Global.PRINT_TIMESTAMP.equals(type)) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
String label = bean.getLabel();
|
||||
int labelLen = label.length();
|
||||
sb.append(label);
|
||||
int spaceLength = separatorStart - labelLen;
|
||||
while (spaceLength > 0) {
|
||||
sb.append(blank);
|
||||
spaceLength--;
|
||||
}
|
||||
sb.append(valueSeparator);
|
||||
sb.append(blank);
|
||||
|
||||
SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm");
|
||||
Date date = new Date();
|
||||
String value = df.format(date);
|
||||
|
||||
value = (value == null) ? "" : value;
|
||||
sb.append(value);
|
||||
|
||||
mBxlService.PrintText(sb.toString(),
|
||||
BxlService.BXL_ALIGNMENT_LEFT, BxlService.BXL_FT_DEFAULT,
|
||||
BxlService.BXL_TS_0WIDTH | BxlService.BXL_TS_0HEIGHT);
|
||||
}
|
||||
if (isNeedFeedLine) {
|
||||
mBxlService.LineFeed(1);
|
||||
} else {
|
||||
isNeedFeedLine = true;
|
||||
}
|
||||
|
||||
}
|
||||
mBxlService.LineFeed(2);
|
||||
} else {
|
||||
throw new Exception("Device is not connected to the printer.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue