add project adins

This commit is contained in:
Alfrid Sanjaya Leo Putra 2024-07-25 14:44:22 +07:00
commit f8f85d679d
5299 changed files with 625430 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 B

View file

@ -0,0 +1,545 @@
package com.adins.mss.coll.fragments;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.widget.AppCompatSpinner;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import com.adins.mss.base.GlobalData;
import com.adins.mss.base.dynamicform.SurveyHeaderBean;
import com.adins.mss.base.todolist.ToDoList;
import com.adins.mss.base.util.Utility;
import com.adins.mss.coll.NewMCMainActivity;
import com.adins.mss.coll.R;
import com.adins.mss.coll.commons.Toaster;
import com.adins.mss.coll.tool.Constants;
import com.adins.mss.constant.Global;
import com.adins.mss.dao.DepositReportH;
import com.adins.mss.dao.Scheme;
import com.adins.mss.dao.TaskD;
import com.adins.mss.dao.TaskH;
import com.adins.mss.dao.User;
import com.adins.mss.foundation.db.dataaccess.DepositReportHDataAccess;
import com.adins.mss.foundation.db.dataaccess.GeneralParameterDataAccess;
import com.adins.mss.foundation.db.dataaccess.SchemeDataAccess;
import com.adins.mss.foundation.db.dataaccess.TaskDDataAccess;
import com.adins.mss.foundation.db.dataaccess.TaskHDataAccess;
import com.adins.mss.foundation.db.dataaccess.UserDataAccess;
import com.adins.mss.foundation.formatter.Tool;
import org.acra.ACRA;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class DepositReportRecapitulateFragmentNew extends Fragment {
private TextView formNameBatch;
private TextView submitDateBatch;
private FormAdapter formAdapter;
private UserAdapter userAdapter;
private BatchAdapter batchAdapter;
public static String selectedDepositScheme;
public static String selectedDepositSchemeName;
public static String selectedDepositUser;
public static String selectedBatchId;
public static User selectedDepositUserObject = null;
protected double total = 0;
private int totalNeedPrint;
private List<TaskH> listTaskH;
private List<String> listTaskBatch;
private ToDoList toDoList;
private RefreshBackgroundTask backgroundTask;
List<TaskD> reportsReconcile = new ArrayList<TaskD>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
toDoList = new ToDoList(getActivity());
listTaskH = toDoList.getListTaskInStatusForMultiUser(ToDoList.SEARCH_BY_BATCH_ID, "BATCHID");
selectedDepositScheme = null;
return inflater.inflate(R.layout.fragment_deposit_report_recapitulate_new, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ACRA.getErrorReporter().putCustomData("LAST_CLASS_ACCESSED", getClass().getSimpleName());
List<Scheme> formListName = new ArrayList<>();
formListName.clear();
formListName.addAll(SchemeDataAccess.getAllActivePriorityScheme(getActivity()));
List<TaskH> batchIdList = new ArrayList<>();
batchIdList.clear();
List<TaskH> listTask = new ArrayList<>();
listTaskBatch = getListBatchId();
if (listTaskBatch != null && listTaskBatch.size() > 0) {
for (String batch : listTaskBatch) {
if (batch != null) {
TaskH taskHBatch = TaskHDataAccess.getAllHeader(getActivity(), batch);
listTask.add(taskHBatch);
}
}
}
batchIdList.addAll(listTask);
List<User> userListName = new ArrayList<>();
userListName.clear();
userListName.addAll(UserDataAccess.getAllUserActive(getActivity()));
AppCompatSpinner spinnerForm = (AppCompatSpinner) view.findViewById(R.id.priorityViewByForm);
formAdapter = new FormAdapter(getActivity(), R.layout.spinner_style, R.id.text_spin, formListName);
formAdapter.setDropDownViewResource(R.layout.spinner_style);
AppCompatSpinner spinnerUser = (AppCompatSpinner) view.findViewById(R.id.priorityViewByUser);
userAdapter = new UserAdapter(getActivity(), R.layout.spinner_style, R.id.text_spin, userListName);
userAdapter.setDropDownViewResource(R.layout.spinner_style);
spinnerForm.setVisibility(View.GONE);
spinnerUser.setVisibility(View.GONE);
ImageView imgExpandForm = (ImageView) view.findViewById(R.id.img_expand_by_form);
ImageView imgExpandUser = (ImageView) view.findViewById(R.id.img_expand_by_user);
imgExpandForm.setVisibility(View.GONE);
imgExpandUser.setVisibility(View.GONE);
AppCompatSpinner spinnerBatch = (AppCompatSpinner) view.findViewById(R.id.priorityViewByBatch);
batchAdapter = new BatchAdapter(getActivity(), R.layout.spinner_style, R.id.text_spin, batchIdList);
batchAdapter.setDropDownViewResource(R.layout.spinner_style);
spinnerForm.setAdapter(formAdapter);
spinnerForm.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
selectedDepositScheme = formAdapter.getItem(position).getUuid_scheme();
selectedDepositSchemeName = formAdapter.getItem(position).getScheme_description();
loadData();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
spinnerUser.setAdapter(userAdapter);
spinnerUser.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
selectedDepositUser = userAdapter.getItem(position).getUuid_user();
selectedDepositUserObject = userAdapter.getItem(position);
loadData();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
spinnerBatch.setAdapter(batchAdapter);
spinnerBatch.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
selectedBatchId = batchAdapter.getItem(position).getBatch_id();
loadData();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
final Button transferButton = (Button) view.findViewById(R.id.transferButton);
transferButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
total = sumOfItems(reportsReconcile);
if (total != 0) {
transferButton.setEnabled(false);
transfer();
} else {
Toast.makeText(getActivity(), getString(R.string.transfer_failed), Toast.LENGTH_SHORT).show();
}
}
});
//make sure that first selected user is current logged user
User defaultUser = GlobalData.getSharedGlobalData().getUser();
int position = -1;
for (User user : userListName) {
position++;
if (user.getUuid_user().equalsIgnoreCase(defaultUser.getUuid_user())) {
if (selectedDepositUserObject == null) {
selectedDepositUser = userListName.get(position).getUuid_user();
selectedDepositUserObject = userListName.get(position);
}
spinnerUser.setSelection(position);
break;
}
}
formNameBatch = (TextView) getView().findViewById(R.id.formBatchValue);
submitDateBatch = (TextView) getView().findViewById(R.id.dateBatchValue);
initialize();
}
@Override
public void onDestroyView() {
super.onDestroyView();
Utility.freeMemory();
}
private void initialize() {
loadData();
}
private void loadData() {
reportsReconcile.clear();
List<TaskD> reports = TaskDDataAccess.getTaskDTagTotalbyBatchId(getActivity(), selectedBatchId);
for (TaskD taskD : reports) {
TaskH taskH = TaskHDataAccess.getOneHeader(getActivity(), taskD.getUuid_task_h());
selectedDepositScheme = taskH.getUuid_scheme();
selectedDepositSchemeName = SchemeDataAccess.getOneSchemeName(getActivity(), selectedDepositScheme);
if (taskH != null && taskH.getIs_reconciled() != null) {
if (taskH.getIs_reconciled().equals("0")) {
reportsReconcile.add(taskD);
}
}
if (taskH != null) {
int printCount = taskH.getPrint_count() != null ? taskH.getPrint_count() : 0;
String rvNumber = taskH.getRv_number();
boolean isRVinFront = GeneralParameterDataAccess.isRvInFrontEnable(getActivity(), GlobalData.getSharedGlobalData().getUser().getUuid_user());
if (printCount > 0 || (rvNumber != null && !rvNumber.isEmpty()) || isRVinFront) {
// do nothing
} else {
try {
String uuidScheme = taskH.getUuid_scheme();
Scheme scheme = SchemeDataAccess.getOne(getActivity(), uuidScheme);
if (scheme != null) {
if (scheme.getIs_printable().equals(Global.TRUE_STRING))
totalNeedPrint++;
}
} catch (Exception e) {
totalNeedPrint++;
}
}
formNameBatch.setText(selectedDepositSchemeName);
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
submitDateBatch.setText(df.format(taskH.getSubmit_date()));
}
}
ListView list = (ListView) getView().findViewById(R.id.recapitulationList);
list.setAdapter(new RecapitulationListAdapter(
getActivity(),
R.layout.item_recapitulation_detail,
reportsReconcile.toArray(new TaskD[reportsReconcile.size()])
)
);
}
private List<String> getListBatchId() {
List<String> depositedBatchList = new ArrayList<>();
List<DepositReportH> depositedBatch = DepositReportHDataAccess.listOfBacth(getActivity());
if (depositedBatch != null) {
for (DepositReportH depositHeader : depositedBatch) {
depositedBatchList.add(depositHeader.getBatch_id());
}
}
List<String> undeposited = TaskHDataAccess.getAllBatchIdList(getActivity(), depositedBatchList);
return undeposited;
}
void transfer() {
ListView list = (ListView) getView().findViewById(R.id.recapitulationList);
if (list.getAdapter().getCount() <= 1) {
Toaster.warning(getActivity(), getString(R.string.nothing_to_report));
return;
} else if (totalNeedPrint > 0) {
Toaster.warning(getActivity(), getActivity().getString(R.string.prompt_printRV));
return;
}
BigDecimal totalValue = BigDecimal.valueOf(total);
Bundle bundle = new Bundle();
bundle.putString(Constants.KEY_BUND_BATCHID, selectedBatchId);
bundle.putString("TOTAL_DEPOSIT", totalValue.toString());
bundle.putString("FORM", selectedDepositSchemeName);
DepositReportTransferFragmentNew fragment = new DepositReportTransferFragmentNew();
fragment.setArguments(bundle);
FragmentTransaction transaction = NewMCMainActivity.fragmentManager.beginTransaction();
transaction.setCustomAnimations(R.anim.activity_open_translate, R.anim.activity_close_scale, R.anim.activity_open_scale, R.anim.activity_close_translate);
transaction.replace(R.id.content_frame, fragment);
transaction.addToBackStack(null);
transaction.commit();
}
private class RecapitulationListAdapter extends ArrayAdapter<TaskD> {
private final TaskD[] originalItems;
public RecapitulationListAdapter(Context context, int resource, TaskD[] objects) {
super(context, resource, objects);
originalItems = objects;
}
@Override
public int getCount() {
return super.getCount() + 1;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = LayoutInflater.from(getContext()).inflate(R.layout.item_recapitulation_detail, parent, false);
TextView label = (TextView) view.findViewById(R.id.itemLabel);
TextView value = (TextView) view.findViewById(R.id.itemValue);
if (position == getCount() - 1) {
label.setText("Total");
value.setText(Tool.separateThousand(String.valueOf(sumOfItems(new ArrayList<TaskD>(Arrays.asList(originalItems))))));
value.setText(Tool.separateThousand(String.valueOf(sumOfItems(new ArrayList<TaskD>(Arrays.asList(originalItems))))));
} else {
TaskD item = getItem(position);
label.setText(item.getTaskH().getAppl_no());
value.setText(Tool.separateThousand(item.getText_answer()));
}
return view;
}
}
private double sumOfItems(List<TaskD> items) {
double sum = 0;
try {
for (TaskD item : items) {
String value = item.getText_answer();
if (value == null || value.equals("")) value = "0";
String tempAnswer = Tool.deleteAll(value, ",");
String[] intAnswer = Tool.split(tempAnswer, ".");
if (intAnswer.length > 1) {
if (intAnswer[1].equals("00"))
value = intAnswer[0];
else {
value = tempAnswer;
}
} else {
value = tempAnswer;
}
double finalValue = Double.parseDouble(value);
sum += finalValue;
}
} catch (Exception e) {
e.printStackTrace();
}
return sum;
}
public class FormAdapter extends ArrayAdapter<Scheme> {
private Context context;
private List<Scheme> values;
public FormAdapter(Context context, int resource, int textViewResourceId, List<Scheme> objects) {
super(context, resource, textViewResourceId, objects);
this.context = context;
this.values = objects;
}
public int getCount() {
return values.size();
}
public Scheme getItem(int position) {
return values.get(position);
}
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.spinner_style, parent, false);
TextView label = (TextView) view.findViewById(R.id.text_spin);
label.setText("Form : " + values.get(position).getScheme_description());
return label;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.spinner_style, parent, false);
TextView label = (TextView) view.findViewById(R.id.text_spin);
label.setText(values.get(position).getScheme_description());
return label;
}
}
public class BatchAdapter extends ArrayAdapter<TaskH> {
private Context context;
private List<TaskH> values;
public BatchAdapter(Context context, int resource, int textViewResourceId, List<TaskH> objects) {
super(context, resource, textViewResourceId, objects);
this.context = context;
this.values = objects;
}
public int getCount() {
return values.size();
}
public TaskH getItem(int position) {
return values.get(position);
}
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.spinner_style, parent, false);
TextView label = (TextView) view.findViewById(R.id.text_spin);
label.setText("Batch : " + values.get(position).getBatch_id());
return label;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.spinner_style, parent, false);
TextView label = (TextView) view.findViewById(R.id.text_spin);
label.setText(values.get(position).getBatch_id());
return label;
}
}
public class UserAdapter extends ArrayAdapter<User> {
private Context context;
private List<User> values;
public UserAdapter(Context context, int resource, int textViewResourceId, List<User> objects) {
super(context, resource, textViewResourceId, objects);
this.context = context;
this.values = objects;
}
public int getCount() {
return values.size();
}
public User getItem(int position) {
return values.get(position);
}
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.spinner_style, parent, false);
TextView label = (TextView) view.findViewById(R.id.text_spin);
label.setText("User : " + values.get(position).getLogin_id());
return label;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.spinner_style, parent, false);
TextView label = (TextView) view.findViewById(R.id.text_spin);
label.setText(values.get(position).getLogin_id());
return label;
}
}
@Override
public void onResume() {
super.onResume();
if (listTaskH != null) {
initiateRefresh();
}
}
private void initiateRefresh() {
cancelRefreshTask();
backgroundTask = new RefreshBackgroundTask();
backgroundTask.execute();
}
private void cancelRefreshTask() {
if (backgroundTask != null) {
backgroundTask.cancel(true);
backgroundTask = null;
}
}
private class RefreshBackgroundTask extends AsyncTask<Void, Void, List<TaskH>> {
static final int TASK_DURATION = 2 * 1000; // 2 seconds
@Override
protected List<TaskH> doInBackground(Void... params) {
// Sleep for a small amount of time to simulate a background-task
try {
Thread.sleep(TASK_DURATION);
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
listTaskH.clear();
listTaskH.addAll(toDoList.getListTaskInStatus(ToDoList.SEARCH_BY_BATCH_ID, "BATCHID"));
ToDoList.listOfSurveyStatus = null;
List<SurveyHeaderBean> list = new ArrayList<SurveyHeaderBean>();
for (TaskH h : listTaskH) {
list.add(new SurveyHeaderBean(h));
}
ToDoList.listOfSurveyStatus = list;
// Return a new random list of cheeses
return listTaskH;
}
@Override
protected void onCancelled() {
super.onCancelled();
}
@Override
protected void onPostExecute(List<TaskH> result) {
super.onPostExecute(result);
}
}
}

View file

@ -0,0 +1,129 @@
/*
* Copyright 2013, Edmodo, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License.
* You may obtain a copy of the License in the LICENSE file, or at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package com.edmodo.cropper.util;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.view.View;
import android.widget.ImageView;
/**
* Utility class that deals with operations with an ImageView.
*/
public class ImageViewUtil {
/**
* Gets the rectangular position of a Bitmap if it were placed inside a View
* with scale type set to {@link ImageView#ScaleType #CENTER_INSIDE}.
*
* @param bitmap the Bitmap
* @param view the parent View of the Bitmap
* @return the rectangular position of the Bitmap
*/
public static Rect getBitmapRectCenterInside(Bitmap bitmap, View view) {
final int bitmapWidth = bitmap.getWidth();
final int bitmapHeight = bitmap.getHeight();
final int viewWidth = view.getWidth();
final int viewHeight = view.getHeight();
return getBitmapRectCenterInsideHelper(bitmapWidth, bitmapHeight, viewWidth, viewHeight);
}
/**
* Gets the rectangular position of a Bitmap if it were placed inside a View
* with scale type set to {@link ImageView#ScaleType #CENTER_INSIDE}.
*
* @param bitmapWidth the Bitmap's width
* @param bitmapHeight the Bitmap's height
* @param viewWidth the parent View's width
* @param viewHeight the parent View's height
* @return the rectangular position of the Bitmap
*/
public static Rect getBitmapRectCenterInside(int bitmapWidth,
int bitmapHeight,
int viewWidth,
int viewHeight) {
return getBitmapRectCenterInsideHelper(bitmapWidth, bitmapHeight, viewWidth, viewHeight);
}
/**
* Helper that does the work of the above functions. Gets the rectangular
* position of a Bitmap if it were placed inside a View with scale type set
* to {@link ImageView#ScaleType #CENTER_INSIDE}.
*
* @param bitmapWidth the Bitmap's width
* @param bitmapHeight the Bitmap's height
* @param viewWidth the parent View's width
* @param viewHeight the parent View's height
* @return the rectangular position of the Bitmap
*/
private static Rect getBitmapRectCenterInsideHelper(int bitmapWidth,
int bitmapHeight,
int viewWidth,
int viewHeight) {
double resultWidth;
double resultHeight;
int resultX;
int resultY;
double viewToBitmapWidthRatio = Double.POSITIVE_INFINITY;
double viewToBitmapHeightRatio = Double.POSITIVE_INFINITY;
// Checks if either width or height needs to be fixed
if (viewWidth < bitmapWidth) {
viewToBitmapWidthRatio = (double) viewWidth / (double) bitmapWidth;
}
if (viewHeight < bitmapHeight) {
viewToBitmapHeightRatio = (double) viewHeight / (double) bitmapHeight;
}
// If either needs to be fixed, choose smallest ratio and calculate from
// there
if (viewToBitmapWidthRatio != Double.POSITIVE_INFINITY || viewToBitmapHeightRatio != Double.POSITIVE_INFINITY) {
if (viewToBitmapWidthRatio <= viewToBitmapHeightRatio) {
resultWidth = viewWidth;
resultHeight = (bitmapHeight * resultWidth / bitmapWidth);
} else {
resultHeight = viewHeight;
resultWidth = (bitmapWidth * resultHeight / bitmapHeight);
}
}
// Otherwise, the picture is within frame layout bounds. Desired width
// is simply picture size
else {
resultHeight = bitmapHeight;
resultWidth = bitmapWidth;
}
// Calculate the position of the bitmap inside the ImageView.
if (resultWidth == viewWidth) {
resultX = 0;
resultY = (int) Math.round((viewHeight - resultHeight) / 2);
} else if (resultHeight == viewHeight) {
resultX = (int) Math.round((viewWidth - resultWidth) / 2);
resultY = 0;
} else {
resultX = (int) Math.round((viewWidth - resultWidth) / 2);
resultY = (int) Math.round((viewHeight - resultHeight) / 2);
}
final Rect result = new Rect(resultX,
resultY,
resultX + (int) Math.ceil(resultWidth),
resultY + (int) Math.ceil(resultHeight));
return result;
}
}

View file

@ -0,0 +1,81 @@
package com.adins.mss.foundation.db.dataaccess;
import android.content.Context;
import com.adins.mss.dao.DaoSession;
import com.adins.mss.dao.GroupTask;
import com.adins.mss.dao.GroupTaskDao;
import com.adins.mss.foundation.db.DaoOpenHelper;
import java.util.List;
import de.greenrobot.dao.query.QueryBuilder;
/**
* Created by olivia.dg on 11/20/2017.
*/
public class GroupTaskDataAccess {
protected static DaoSession getDaoSession(Context context){
return DaoOpenHelper.getDaoSession(context);
}
protected static GroupTaskDao getGroupTaskDao(Context context) {
return getDaoSession(context).getGroupTaskDao();
}
public static void add(Context context, GroupTask groupTask){
getGroupTaskDao(context).insert(groupTask);
getDaoSession(context).clear();
}
public static void add(Context context, List<GroupTask> groupTaskList){
getGroupTaskDao(context).insertInTx(groupTaskList);
getDaoSession(context).clear();
}
public static void addOrReplace(Context context, GroupTask groupTask){
getGroupTaskDao(context).insertOrReplaceInTx(groupTask);
getDaoSession(context).clear();
}
public static void addOrReplace(Context context, List<GroupTask> groupTaskList){
getGroupTaskDao(context).insertOrReplaceInTx(groupTaskList);
getDaoSession(context).clear();
}
public static void clean(Context context){
getGroupTaskDao(context).deleteAll();
}
public static void delete(Context context, GroupTask groupTask){
getGroupTaskDao(context).delete(groupTask);
getDaoSession(context).clear();
}
public static void update(Context context, GroupTask groupTask){
getGroupTaskDao(context).update(groupTask);
}
public static List<GroupTask> getAll(Context context){
QueryBuilder<GroupTask> qb = getGroupTaskDao(context).queryBuilder();
qb.build();
return qb.list();
}
public static List<GroupTask> getAllByAccount(Context context, String uuidAccount){
QueryBuilder<GroupTask> qb = getGroupTaskDao(context).queryBuilder();
qb.where(GroupTaskDao.Properties.Uuid_account.eq(uuidAccount));
qb.build();
return qb.list();
}
public static GroupTask getOneHeader(Context context, String groupTaskId){
QueryBuilder<GroupTask> qb = getGroupTaskDao(context).queryBuilder();
qb.where(GroupTaskDao.Properties.Group_task_id.eq(groupTaskId));
qb.build();
if ((qb.list() == null) || qb.list().isEmpty()) return null;
return qb.list().get(0);
}
}

View file

@ -0,0 +1,242 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/svy_perform_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg_grayscale"
android:visibility="visible">
<View
android:id="@+id/actionbar"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentTop="true"
android:background="@color/tv_dark"/>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/actionbar"
android:paddingLeft="5dp"
android:paddingRight="5dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<LinearLayout
android:id="@+id/searchBy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:visibility="visible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:ems="10"
android:text="@string/filter_by"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"/>
<RelativeLayout
android:id="@+id/filterLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp">
<Spinner
android:id="@+id/cbSearchBy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:ems="10"
android:entries="@array/cbSearchBy"
android:padding="3dp"/>
<ImageButton
android:id="@+id/btnRefresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/cbSearchBy"
android:layout_alignRight="@+id/cbSearchBy"
android:layout_margin="4dp"
android:background="@android:color/transparent"
android:src="@drawable/dropdown_right"/>
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:id="@+id/byEstimatedDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:visibility="gone">
<TextView
android:id="@+id/startdate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:ems="10"
android:text="@string/lblStartDate"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"/>
<EditText
android:id="@+id/txtStartDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/startdate"
android:layout_toLeftOf="@+id/btnStartDate"
android:editable="false"
android:hint="@string/lblEndDate"
android:ems="10"/>
<TextView
android:id="@+id/enddate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txtStartDate"
android:layout_centerHorizontal="true"
android:ems="10"
android:text="@string/lblEndDate"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"/>
<EditText
android:id="@+id/txtEndDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/txtStartDate"
android:layout_below="@+id/enddate"
android:hint="@string/lblEndDate"
android:editable="false"
android:ems="10"/>
<ImageButton
android:id="@+id/btnStartDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/txtStartDate"
android:layout_alignParentRight="true"
android:layout_marginLeft="5dp"
android:background="@drawable/ic_calendar"/>
<ImageButton
android:id="@+id/btnEndDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/txtEndDate"
android:layout_alignParentRight="true"
android:layout_marginLeft="5dp"
android:background="@drawable/ic_calendar"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/byDay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:visibility="visible">
<EditText
android:id="@+id/txtDateDay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/btnDate"
android:editable="false"
android:ems="10"/>
<ImageButton
android:id="@+id/btnDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/txtDateDay"
android:layout_alignParentRight="true"
android:layout_marginLeft="5dp"
android:background="@drawable/ic_calendar"/>
</RelativeLayout>
<LinearLayout
android:id="@+id/byMonth"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:visibility="gone">
<RelativeLayout
android:id="@+id/filterByLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp">
<Spinner
android:id="@+id/cbSearchByMonth"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/mediumpriority_background"
android:ems="10"
android:entries="@array/cbSearchByMonth"
android:popupBackground="@drawable/mediumpriority_background"
android:padding="3dp"/>
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/cbSearchByMonth"
android:layout_alignRight="@+id/cbSearchByMonth"
android:layout_margin="4dp"
android:background="@android:color/transparent"
android:src="@drawable/dropdown_right"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/byDay"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="20dp"
android:paddingTop="20dp">
<Button
android:id="@+id/btnSearchOrder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_weight="1"
android:background="@drawable/button_background"
android:ems="10"
android:text="@string/btnOk"
android:textColor="#ffffff">
</Button>
</LinearLayout>
</LinearLayout>
</ScrollView>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/scrollView1"
android:id="@+id/resultListView"
android:visibility="visible"
android:padding="5dp">
</ListView>
</RelativeLayout>

View file

@ -0,0 +1,441 @@
package com.adins.mss.coll.commons;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.ImageFormat;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.Toast;
import com.adins.mss.base.GlobalData;
import com.adins.mss.base.crashlytics.FireCrash;
import com.adins.mss.base.util.LocaleHelper;
import com.adins.mss.coll.R;
import com.adins.mss.constant.Global;
import com.adins.mss.dao.User;
import com.adins.mss.foundation.camera.Camera;
import com.adins.mss.foundation.camera.ImageCallBack;
import com.adins.mss.foundation.image.Utils;
import com.adins.mss.foundation.location.LocationTrackingManager;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/**
* Created by winy.firdasari on 14/01/2015.
*/
public class CameraPreviewActivity extends Activity {
public static final String REQUESTED_FILE = "CameraPreviewActivity.REQUESTED_FILE";
// ---
private static final int BACK_MENU_ID = Menu.FIRST;
private static final int OPTIONS_MENU_ID = Menu.FIRST + 1;
private static final int CAPTURE_MENU_ID = Menu.FIRST + 2;
private static final int AUTOFLASH_MENU_ID = Menu.FIRST + 3;
private static final int FLASHON_MENU_ID = Menu.FIRST + 4;
private static final int FLASHOFF_MENU_ID = Menu.FIRST + 5;
Context context;
boolean hasCamera;
private Preview mPreview;
private ListAdapter listPicSize;
private int rotate = 0;
private Activity activity;
private String requestedFileName;
private int actualWidht = 240;
private int actualHeight = 320;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// this is set manual for testing
GlobalData.getSharedGlobalData().setUser(new User("Bong"));
GlobalData.getSharedGlobalData().getUser().setLogin_id("Bong");
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
LocationTrackingManager manager = new LocationTrackingManager(tm, lm, getApplicationContext());
manager.setMinimalDistanceChangeLocation(100);
manager.setMinimalTimeChangeLocation(5000);
manager.applyLocationListener(getApplicationContext());
Global.LTM = manager;
requestedFileName = getIntent().getStringExtra(REQUESTED_FILE);
// Hide the window title.
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
context = this;
mPreview = new Preview(this);
setContentView(mPreview);
hasCamera = Camera.checkCameraHardware(this);
this.activity = this;
}
@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);
}
}
public boolean getLCDSceenTipeLandscape() {
boolean result = false;
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
String str_ScreenSize = "The Android Screen is: W="
+ dm.widthPixels
+ " x H="
+ dm.heightPixels;
System.out.println(str_ScreenSize);
if (dm.widthPixels > dm.heightPixels) {
result = true;
} else {
result = false;
}
return result;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, BACK_MENU_ID, 0, "Back");
menu.add(0, CAPTURE_MENU_ID, 0, "Capture");
menu.add(0, AUTOFLASH_MENU_ID, 0, "Auto Flash");
menu.add(0, FLASHON_MENU_ID, 0, "Flash On");
menu.add(0, FLASHOFF_MENU_ID, 0, "Flash Off");
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case BACK_MENU_ID:
this.finish();
return true;
case OPTIONS_MENU_ID:
this.showOptions();
return true;
case CAPTURE_MENU_ID:
mPreview.mCamera.getPicture(new ImageCallBack() {
@Override
public void onPictureTaken(byte[] bytes, Object o) {
File file = new File(requestedFileName);
Utils.saveBitmapHeadertoPath(getApplicationContext(), Utils.byteToBitmap(bytes));
Intent data = new Intent();
data.putExtra(REQUESTED_FILE, file.getAbsolutePath());
setResult(RESULT_OK);
}
});
return true;
case AUTOFLASH_MENU_ID:
mPreview.mCamera.setFlashAuto();
return true;
case FLASHON_MENU_ID:
mPreview.mCamera.setFlashOn();
return true;
case FLASHOFF_MENU_ID:
mPreview.mCamera.setFlashOff();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void showOptions() {
this.loadSupportedPicSize();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Picture Size");
builder.setSingleChoiceItems(listPicSize, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
String resolution = (String) listPicSize.getItem(item);
String[] sz = resolution.split("x");
int w = Integer.parseInt(sz[0]);
int h = Integer.parseInt(sz[1]);
mPreview.setPictureSize(w, h);
mPreview.mCamera.getCamera().stopPreview();
android.hardware.Camera.Size previewSize = mPreview.getOptimalPreviewSize(w, h);
mPreview.setPreviewSize(previewSize.width, previewSize.height);
mPreview.mCamera.getCamera().startPreview();
try {
dialog.dismiss();
dialog = null;
} catch (Exception e) {
FireCrash.log(e);
}
Toast.makeText(getApplicationContext(), getString(R.string.picture_resolution, resolution), Toast.LENGTH_SHORT).show();
}
});
builder.create().show();
}
private void loadSupportedPicSize() {
if (listPicSize == null) {
List<String> listSize = mPreview.getSupportedPictureSize();
listPicSize = new ArrayAdapter<String>(this, R.layout.picture_size_list, listSize);
}
}
public class Preview extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder mHolder;
private Camera mCamera;
public Preview(Context context) {
super(context);
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public List<String> getSupportedPictureSize() {
List<android.hardware.Camera.Size> listSize = mCamera.getCamera().getParameters().getSupportedPictureSizes();
List<String> listSizeStr = new ArrayList<>();
for (android.hardware.Camera.Size size : listSize) {
listSizeStr.add(size.width + "x" + size.height);
}
return listSizeStr;
}
public void surfaceCreated(SurfaceHolder holder) {
try {
android.hardware.Camera cam = android.hardware.Camera.open();
mCamera = new Camera(context, activity, cam, cam.getParameters());
} catch (Exception e) {
FireCrash.log(e);
}
// default to set picture size to lowest resolution
List<android.hardware.Camera.Size> listSupportedSize = mCamera.getCamera().getParameters().getSupportedPictureSizes();
if (listSupportedSize != null && !listSupportedSize.isEmpty()) {
android.hardware.Camera.Size minimumSize = listSupportedSize.get(searchMostSuportedSizeFromParam(listSupportedSize));
android.hardware.Camera.Parameters parameters = mCamera.getCamera().getParameters();
parameters.setPictureSize(minimumSize.width, minimumSize.height);
mCamera.getCamera().setParameters(parameters);
}
try {
mCamera.getCamera().setPreviewDisplay(holder);
} catch (IOException exception) {
mCamera.getCamera().release();
mCamera = null;
}
}
public int searchMostSuportedSizeFromParam(List<android.hardware.Camera.Size> listSupportedSize) {
android.hardware.Camera.Size suportedSize;
int idx = 0;
//search for match w x h
for (int i = 0; i < listSupportedSize.size(); i++) {
if (listSupportedSize.get(i).width == actualWidht && listSupportedSize.get(i).height == actualHeight) {
return i;
}
}
//search for match h
for (int i = 0; i < listSupportedSize.size(); i++) {
if (listSupportedSize.get(i).height == actualHeight) {
return i;
}
}
//search for match w
for (int i = 0; i < listSupportedSize.size(); i++) {
if (listSupportedSize.get(i).width == actualWidht) {
return i;
}
}
return listSupportedSize.size() - 1;
}
public void surfaceDestroyed(SurfaceHolder holder) {
mCamera.getCamera().stopPreview();
mCamera.getCamera().release();
mCamera = null;
}
@SuppressLint("NewApi")
@TargetApi(Build.VERSION_CODES.FROYO)
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
android.hardware.Camera.Parameters parameters = mCamera.getCamera().getParameters();
android.hardware.Camera.Size resultSize = null;
try {
resultSize = getOptimalPreviewSize(w, h);
if (resultSize != null) {
w = resultSize.width;
h = resultSize.height;
}
if (resultSize != null)
parameters.setPreviewSize(w, h);
} catch (Exception e) {
FireCrash.log(e);
resultSize = null;
}
parameters.setPictureFormat(ImageFormat.JPEG);
parameters.setFocusMode(android.hardware.Camera.Parameters.FOCUS_MODE_AUTO);
parameters.setFlashMode(android.hardware.Camera.Parameters.FLASH_MODE_OFF);
if (resultSize != null) {
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
android.hardware.Camera.CameraInfo info =
new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK, info);
int degrees = 0;
switch (rotation) {
case Surface.ROTATION_0:
degrees = 0;
break;
case Surface.ROTATION_90:
degrees = 90;
break;
case Surface.ROTATION_180:
degrees = 180;
break;
case Surface.ROTATION_270:
degrees = 270;
break;
default:
break;
}
int result;
if (info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = (info.orientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
} else { // back-facing
result = (info.orientation - degrees + 360) % 360;
}
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
rotate = 90;
}
//khusus untuk device dengan lcd landscape, ex: htc chacha
if (result == 90 && getLCDSceenTipeLandscape()) {
result = 0;
} else if (result == 0 && !getLCDSceenTipeLandscape()) {
result = 270;
} else if (result == 180 && !getLCDSceenTipeLandscape()) {
result = 90;
} else if (result == 270 && getLCDSceenTipeLandscape()) {
result = 180;
}
mCamera.getCamera().setDisplayOrientation(result);
}
try {
mCamera.getCamera().setParameters(parameters);
} catch (Exception e) {
FireCrash.log(e);
parameters = mCamera.getCamera().getParameters();
parameters.setPictureFormat(ImageFormat.JPEG);
parameters.setFocusMode(android.hardware.Camera.Parameters.FOCUS_MODE_AUTO);
parameters.setFlashMode(android.hardware.Camera.Parameters.FLASH_MODE_AUTO);
try {
mCamera.getCamera().setParameters(parameters);
} catch (Exception e2) {
parameters = mCamera.getCamera().getParameters();
mCamera.getCamera().setParameters(parameters);
}
}
mCamera.getCamera().startPreview();
}
public void setPictureSize(int width, int height) {
android.hardware.Camera.Parameters cp = mCamera.getCamera().getParameters();
cp.setPictureSize(width, height);
mCamera.getCamera().setParameters(cp);
}
public android.hardware.Camera.Size getOptimalPreviewSize(int picWidth, int picHeight) {
List<android.hardware.Camera.Size> sizes = mCamera.getCamera().getParameters().getSupportedPreviewSizes();
final double ASPECT_TOLERANCE = 0.1;
double targetRatio = (double) picWidth / picHeight;
if (sizes == null)
return null;
android.hardware.Camera.Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = picHeight;
// Try to find an size match aspect ratio and size
for (android.hardware.Camera.Size size : sizes) {
double ratio = (double) size.width / size.height;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
continue;
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
// Cannot find the one match the aspect ratio, ignore the
// requirement
if (optimalSize == null) {
minDiff = Double.MAX_VALUE;
for (android.hardware.Camera.Size size : sizes) {
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
}
return optimalSize;
}
public void setPreviewSize(int width, int height) {
android.hardware.Camera.Parameters cp = mCamera.getCamera().getParameters();
cp.setPreviewSize(width, height);
mCamera.getCamera().setParameters(cp);
}
}
}

View file

@ -0,0 +1,117 @@
package com.services;
import android.content.Context;
import com.adins.mss.base.GlobalData;
import com.adins.mss.base.crashlytics.FireCrash;
import com.adins.mss.base.util.GsonHelper;
import com.adins.mss.base.util.Utility;
import com.adins.mss.constant.Global;
import com.adins.mss.dao.GeneralParameter;
import com.adins.mss.dao.PrintDate;
import com.adins.mss.foundation.db.dataaccess.GeneralParameterDataAccess;
import com.adins.mss.foundation.db.dataaccess.PrintDateDataAccess;
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.print.SubmitPrintRequest;
import com.adins.mss.foundation.print.SubmitPrintResponse;
import com.google.firebase.perf.FirebasePerformance;
import com.google.firebase.perf.metrics.HttpMetric;
import java.util.List;
/**
* Created by angga.permadi on 3/8/2016.
*/
public class PrintSubmitThread extends Thread {
private Context context;
private volatile boolean keepRunning = true;
private int interval;
public PrintSubmitThread(Context context) {
this.context = context;
try {
GeneralParameter gp = GeneralParameterDataAccess.getOne(context,
GlobalData.getSharedGlobalData().getUser().getUuid_user(),
Global.GS_INTERVAL_AUTOSEND);
if (gp != null) {
interval = Global.SECOND * Integer.parseInt(gp.getGs_value());
}
} catch (Exception e) {
FireCrash.log(e);
e.printStackTrace();
interval = Global.MINUTE * 2;
}
}
@Override
public void run() {
super.run();
while (keepRunning) {
if (Tool.isInternetconnected(context)) {
System.gc();
List<PrintDate> listPrint = PrintDateDataAccess.getAll(context);
if (listPrint != null && listPrint.size() > 0) {
SubmitPrintRequest request = new SubmitPrintRequest();
request.setAudit(GlobalData.getSharedGlobalData().getAuditData());
request.setListPrint(listPrint);
String json = GsonHelper.toJson(request);
String url = GlobalData.getSharedGlobalData().getURL_SUBMIT_PRINT_COUNT();
boolean encrypt = GlobalData.getSharedGlobalData().isEncrypt();
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
HttpCryptedConnection httpConn = new HttpCryptedConnection(context, encrypt, decrypt);
HttpConnectionResult serverResult = null;
HttpMetric networkMetric =
FirebasePerformance.getInstance().newHttpMetric(url, FirebasePerformance.HttpMethod.POST);
Utility.metricStart(networkMetric, json);
try {
serverResult = httpConn.requestToServer(url, json, Global.DEFAULTCONNECTIONTIMEOUT);
Utility.metricStop(networkMetric, serverResult);
} catch (Exception e) {
FireCrash.log(e);
e.printStackTrace();
}
if (serverResult != null && serverResult.isOK()) {
try {
String result = serverResult.getResult();
SubmitPrintResponse response = GsonHelper.fromJson(result, SubmitPrintResponse.class);
if (response.getStatus().getCode() == 0) {
// PrintSubmitDataAccess.delete(context, listPrint);
// PrintDateDataAccess.clean(context);
for(PrintDate print : listPrint) {
PrintDateDataAccess.delete(context, print.getDtm_print().getTime());
}
keepRunning = false;
break;
}
} catch (Exception e) {
FireCrash.log(e);
e.printStackTrace();
}
}
}
}
try {
sleep(interval);
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
}
}
public void requestStop() {
keepRunning = false;
}
}

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/spinner_background">
<TextView
android:id="@+id/txtNoOrder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:text="1234567"
android:paddingLeft="10dp"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/txtDivider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:text="-"
android:paddingLeft="10dp"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/txtCustomerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:text="Nama Customer"
android:paddingLeft="10dp"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

View file

@ -0,0 +1,16 @@
package com.adins.mss.printer;
import android.app.Activity;
import android.os.Bundle;
import com.adins.mss.base.R;
public class main_winson extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_winson);
}
}

View file

@ -0,0 +1,170 @@
package com.adins.mss.base;
import android.content.Context;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.Toast;
import com.adins.mss.base.util.LocaleHelper;
import com.adins.mss.constant.Global;
import com.adins.mss.foundation.config.ConfigFileReader;
import com.adins.mss.foundation.security.storepreferences.ObscuredSharedPreferences;
import com.google.firebase.analytics.FirebaseAnalytics;
import java.util.Locale;
import java.util.Properties;
public class DeveloperOptionActivity extends AppCompatActivity {
private Button btnSave;
private Switch switchEncrypt;
private Switch switchDecrypt;
private Switch switchAccessToken;
private Switch switchDevMode;
private LinearLayout clientIdLayout;
private EditText edtClientId;
private boolean isEncrypt;
private boolean isDecrypt;
private boolean isAccessTokenEnable;
private boolean isByPassEnable;
private FirebaseAnalytics screenName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
screenName = FirebaseAnalytics.getInstance(this);
setContentView(R.layout.new_developer_option_activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitleTextColor(getResources().getColor(R.color.fontColorWhite));
setSupportActionBar(toolbar);
initViews();
}
@Override
protected void onResume() {
super.onResume();
//Set Firebase screen name
screenName.setCurrentScreen(this, getString(R.string.screen_name_developer_option), null);
}
@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);
}
}
private void initViews() {
btnSave = (Button) findViewById(R.id.btnSave);
switchDecrypt = (Switch) findViewById(R.id.switchDecrypt);
switchEncrypt = (Switch) findViewById(R.id.switchEncrypt);
switchAccessToken = (Switch) findViewById(R.id.switchAccessToken);
switchDevMode = (Switch) findViewById(R.id.switchDevMode);
clientIdLayout = (LinearLayout) findViewById(R.id.layoutClientId);
edtClientId = (EditText) findViewById(R.id.edtClientId);
final ObscuredSharedPreferences sharedPref = ObscuredSharedPreferences.getPrefs(getApplicationContext(),
"GlobalData", Context.MODE_PRIVATE);
Properties prop = ConfigFileReader.propertiesFromFile(this, GlobalData.PROPERTY_FILENAME);
boolean encrypt = Boolean.parseBoolean(prop.getProperty(GlobalData.PROP_ENCRYPT, "false"));
boolean decrypt = Boolean.parseBoolean(prop.getProperty(GlobalData.PROP_DECRYPT, "false"));
String propClientId = prop.getProperty(GlobalData.PROP_CLIENT_ID, "android");
boolean byPassEnable = Boolean.parseBoolean(prop.getProperty(GlobalData.PROP_IS_BYPASS_DEVELOPER, "false"));
boolean hasEncrypt = sharedPref.getBoolean("IS_ENCRYPT", encrypt);
boolean hasDecrypt = sharedPref.getBoolean("IS_DECRYPT", decrypt);
boolean tokenFromPropValue = Boolean.parseBoolean(prop.getProperty(GlobalData.PROP_IS_REQUIRED_ACCESS_TOKEN, "false"));
boolean isTokenEnable = sharedPref.getBoolean("IS_ACCESS_TOKEN_ENABLE",false);
String firstSetting = sharedPref.getString("IS_DEV_FIRST_SETTING", Global.TRUE_STRING);
if(!isTokenEnable && tokenFromPropValue && Global.TRUE_STRING.equalsIgnoreCase(firstSetting)){
isTokenEnable = tokenFromPropValue;
}
final String clientId = sharedPref.getString("CLIENT_ID", propClientId);
isByPassEnable = sharedPref.getBoolean("IS_BYPASS_ENABLE", byPassEnable);
switchAccessToken.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
clientIdLayout.setVisibility(View.VISIBLE);
edtClientId.setText(clientId);
} else {
clientIdLayout.setVisibility(View.GONE);
}
}
});
if (hasEncrypt) {
switchEncrypt.setChecked(true);
}
if (hasDecrypt) {
switchDecrypt.setChecked(true);
}
if (isTokenEnable) {
switchAccessToken.setChecked(true);
clientIdLayout.setVisibility(View.VISIBLE);
edtClientId.setText(clientId);
} else {
clientIdLayout.setVisibility(View.GONE);
}
if (isByPassEnable) {
switchDevMode.setChecked(true);
}
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ObscuredSharedPreferences.Editor sharedPrefEditor = sharedPref.edit();
isEncrypt = switchEncrypt.isChecked();
isDecrypt = switchDecrypt.isChecked();
isAccessTokenEnable = switchAccessToken.isChecked();
isByPassEnable = switchDevMode.isChecked();
if (isAccessTokenEnable && edtClientId.getText() != null && edtClientId.getText().length() > 0) {
String clientId = edtClientId.getText().toString();
sharedPrefEditor.putString("CLIENT_ID", clientId);
GlobalData.getSharedGlobalData().setClientId(clientId);
}
GlobalData.getSharedGlobalData().setEncrypt(isEncrypt);
GlobalData.getSharedGlobalData().setDecrypt(isDecrypt);
GlobalData.getSharedGlobalData().setRequiresAccessToken(isAccessTokenEnable);
GlobalData.getSharedGlobalData().setByPassDeveloper(isByPassEnable);
String isFirstSetting = sharedPref.getString("IS_DEV_FIRST_SETTING", Global.TRUE_STRING);
if(Global.TRUE_STRING.equalsIgnoreCase(isFirstSetting)){
sharedPrefEditor.putString("IS_DEV_FIRST_SETTING",Global.FALSE_STRING);
}
sharedPrefEditor.putBoolean("IS_ENCRYPT", isEncrypt);
sharedPrefEditor.putBoolean("IS_DECRYPT", isDecrypt);
sharedPrefEditor.putBoolean("IS_ACCESS_TOKEN_ENABLE", isAccessTokenEnable);
sharedPrefEditor.putBoolean("IS_BYPASS_ENABLE", isByPassEnable);
sharedPrefEditor.commit();
Toast.makeText(DeveloperOptionActivity.this, getString(R.string.options_saved), Toast.LENGTH_SHORT).show();
finish();
}
});
}
}

View file

@ -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/fontColorWhite"
android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.87 -3.13,-7 -7,-7zM12,11.5c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5 2.5,1.12 2.5,2.5 -1.12,2.5 -2.5,2.5z"/>
</vector>

View file

@ -0,0 +1,71 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<View
android:id="@+id/actionbar"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentTop="true"
android:background="@drawable/actionbar_background" />
<TextView
android:id="@+id/contentComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="6dp"
android:text="@string/profile__title"/>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp" >
<ImageView
android:id="@+id/profilePicture"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="6dp"
android:layout_marginLeft="32dp"
android:src="@drawable/profile_image" />
<Button
android:id="@+id/btnChangeProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="31dp"
android:text="@string/btnChange"/>
</LinearLayout>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:text="@string/header__title"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp" >
<ImageView
android:id="@+id/headerPicture"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="@drawable/dummy" />
<Button
android:id="@+id/btnChangeHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="24dp"
android:text="@string/btnChange"/>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,123 @@
package com.adins.mss.base.common;
import com.adins.mss.base.util.GsonHelper;
import com.adins.mss.constant.Global;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* Created by adityapurwa on 12/03/15.
* Used to convert a hash map to object, because Java is cursed with type erasure.
*/
public class LinkedHashMapToObject {
/**
* Convert a hash map into object.
*
* @param hashMap The hashmap to convert.
* @param metadata Object metadata.
* @param <T> Object type.
* @return Object representing the hash map.
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws NoSuchMethodException
* @throws InstantiationException
*/
public static <T> T convert(LinkedHashMap hashMap, Class<T> metadata, boolean generateUuid) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException {
Constructor constructor = metadata.getConstructor();
T instance = (T) constructor.newInstance();
Iterator iterator = hashMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, String> entry = (Map.Entry<String, String>) iterator.next();
String property = String.valueOf(entry.getKey());
String value = String.valueOf(entry.getValue());
Method[] methods = instance.getClass().getMethods();
for (Method m : methods) {
if (m.getName().toLowerCase().equals("set" + property.toLowerCase())) {
Class<?> paramType = m.getParameterTypes()[0];
Object castedValue = resolveValue(value, paramType);
m.invoke(instance, castedValue);
break;
}
}
}
if (generateUuid) {
Method uuidSetter = null;
for (Method m : metadata.getMethods()) {
if (m.getName().toLowerCase().equals("setuuid_" + metadata.getSimpleName().toLowerCase())) {
uuidSetter = m;
break;
}
}
if (uuidSetter != null) {
uuidSetter.invoke(instance, UUID.randomUUID().toString());
}
}
return instance;
}
/**
* Resolve a value based on the type.
*
* @param value Value to resolve.
* @param paramType Type of the value.
* @return Casted value, or original value if the value type is not recognized.
*/
private static Object resolveValue(String value, Class<?> paramType) {
Object castedValue = value;
try {
if (paramType.getSimpleName().equals("Date")) {
castedValue = GsonHelper.fromJson(value, Date.class);
}
if (paramType.getSimpleName().equals("Integer")) {
castedValue = GsonHelper.fromJson(value, Integer.class);
}
if (paramType.getSimpleName().equals("Long")) {
castedValue = GsonHelper.fromJson(value, Long.class);
}
if (paramType.getSimpleName().equals("String")) {
castedValue = GsonHelper.fromJson(value, String.class);
}
} catch (Exception ex) {
if (Global.IS_DEV)
ex.printStackTrace();
}
return castedValue;
}
/**
* Convert hash map list into list of object that represents it.
*
* @param <T> Object type.
* @param hashMapList List of hash map.
* @param metadata Object metadata.
* @param generateUuid
* @return List of object that represent the list of hash map.
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws NoSuchMethodException
* @throws InstantiationException
*/
public static <T> List<T> convert(List<LinkedHashMap> hashMapList, Class<T> metadata, boolean generateUuid) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException {
List<T> converted = new ArrayList<T>();
for (LinkedHashMap hashMap : hashMapList) {
T dummyItem = convert(hashMap, metadata, generateUuid);
converted.add(dummyItem);
}
return converted;
}
}