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,515 @@
|
|||
package com.adins.mss.foundation.dialog;
|
||||
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.dynamicform.SurveyHeaderBean;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.foundation.audio.AudioRecord;
|
||||
import com.adins.mss.foundation.dialog.gitonway.lib.ColorUtils;
|
||||
import com.adins.mss.foundation.dialog.gitonway.lib.Effectstype;
|
||||
import com.adins.mss.foundation.dialog.gitonway.lib.effects.BaseEffects;
|
||||
import com.adins.mss.foundation.image.ImageViewer;
|
||||
|
||||
/*
|
||||
* Copyright 2014 litao
|
||||
* https://github.com/sd6352051/NiftyDialogEffects
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License 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.
|
||||
*/
|
||||
public class NiftyDialogBuilder_Voice extends Dialog implements DialogInterface {
|
||||
|
||||
private static Context tmpContext;
|
||||
private static int mOrientation = 1;
|
||||
private static NiftyDialogBuilder_Voice instance;
|
||||
private final String defTextColor = "#FFFFFFFF";
|
||||
private final String defDividerColor = "#11000000";
|
||||
private final String defMsgColor = "#FFFFFFFF";
|
||||
private final String defDialogColor = "#FF5f5f5f";
|
||||
private Effectstype type = null;
|
||||
private LinearLayout mLinearLayoutView;
|
||||
private LinearLayout mTaskListLayoutView;
|
||||
private LinearLayout mVerificationLayoutView;
|
||||
private LinearLayout mApprovalLayoutView;
|
||||
private RelativeLayout mRelativeLayoutView;
|
||||
private LinearLayout mLinearLayoutMsgView;
|
||||
private LinearLayout mLinearLayoutTopView;
|
||||
private FrameLayout mFrameLayoutCustomView;
|
||||
private ImageView mImageView;
|
||||
private AutoCompleteTextView mtxtSearch;
|
||||
private View mDialogView;
|
||||
private View mDivider;
|
||||
private TextView mTitle;
|
||||
private TextView mMessage;
|
||||
private TextView mTasklistChoice;
|
||||
private TextView mApprovallistChoice;
|
||||
private TextView mVerificationlistChoice;
|
||||
private ImageView mIcon;
|
||||
private Button mButton1;
|
||||
private Button mButton2;
|
||||
private int mDuration = -1;
|
||||
private boolean isCancelable = true;
|
||||
private ToggleButton btnVoiceNotes;
|
||||
private ImageButton btnPlay;
|
||||
private ImageButton btnStop;
|
||||
private LinearLayout playerLayout;
|
||||
private AudioRecord record;
|
||||
private TextView noVoiceNote;
|
||||
private SurveyHeaderBean header;
|
||||
private int MODE;
|
||||
|
||||
public NiftyDialogBuilder_Voice(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice(Context context, int theme) {
|
||||
super(context, theme);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public static NiftyDialogBuilder_Voice getInstance(Context context) {
|
||||
|
||||
if (instance == null || !tmpContext.equals(context)) {
|
||||
synchronized (NiftyDialogBuilder_Voice.class) {
|
||||
if (instance == null || !tmpContext.equals(context)) {
|
||||
instance = new NiftyDialogBuilder_Voice(context, R.style.dialog_untran);
|
||||
}
|
||||
}
|
||||
}
|
||||
tmpContext = context;
|
||||
return instance;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
WindowManager.LayoutParams params = getWindow().getAttributes();
|
||||
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
|
||||
|
||||
}
|
||||
|
||||
private void init(final Context context) {
|
||||
record = new AudioRecord(context);
|
||||
mDialogView = View.inflate(context, R.layout.dialog_layout_voice, null);
|
||||
|
||||
mLinearLayoutView = (LinearLayout) mDialogView.findViewById(R.id.parentPanelT);
|
||||
mTaskListLayoutView = (LinearLayout) mDialogView.findViewById(R.id.ChoiceTaskList);
|
||||
mApprovalLayoutView = (LinearLayout) mDialogView.findViewById(R.id.ChoiceApprovalList);
|
||||
mVerificationLayoutView = (LinearLayout) mDialogView.findViewById(R.id.ChoiceVerificationlist);
|
||||
mRelativeLayoutView = (RelativeLayout) mDialogView.findViewById(R.id.mainlayout);
|
||||
mLinearLayoutTopView = (LinearLayout) mDialogView.findViewById(R.id.topPanelT);
|
||||
mLinearLayoutMsgView = (LinearLayout) mDialogView.findViewById(R.id.contentPanelT);
|
||||
mFrameLayoutCustomView = (FrameLayout) mDialogView.findViewById(R.id.customPanelT);
|
||||
|
||||
mImageView = (ImageView) mDialogView.findViewById(R.id.imageViewT);
|
||||
mImageView.setOnTouchListener(new ImageViewer());
|
||||
|
||||
mtxtSearch = (AutoCompleteTextView) mDialogView.findViewById(R.id.txtSearch);
|
||||
|
||||
|
||||
mTitle = (TextView) mDialogView.findViewById(R.id.alertTitleT);
|
||||
mMessage = (TextView) mDialogView.findViewById(R.id.messageT);
|
||||
mTasklistChoice = (TextView) mDialogView.findViewById(R.id.Choice1);
|
||||
mVerificationlistChoice = (TextView) mDialogView.findViewById(R.id.Choice2);
|
||||
mApprovallistChoice = (TextView) mDialogView.findViewById(R.id.Choice3);
|
||||
mIcon = (ImageView) mDialogView.findViewById(R.id.iconT);
|
||||
mDivider = mDialogView.findViewById(R.id.titleDividerT);
|
||||
mButton1 = (Button) mDialogView.findViewById(R.id.button1T);
|
||||
mButton2 = (Button) mDialogView.findViewById(R.id.button2T);
|
||||
playerLayout = (LinearLayout) mDialogView.findViewById(R.id.recorderLayout);
|
||||
btnVoiceNotes = (ToggleButton) mDialogView.findViewById(R.id.btnVoiceNotes);
|
||||
noVoiceNote = (TextView) mDialogView.findViewById(R.id.txtNoVoiceNote);
|
||||
btnPlay = (ImageButton) mDialogView.findViewById(R.id.btnPlay);
|
||||
btnStop = (ImageButton) mDialogView.findViewById(R.id.btnStop);
|
||||
setContentView(mDialogView);
|
||||
|
||||
if (header.getVoice_note() != null) {
|
||||
btnVoiceNotes.setVisibility(View.GONE);
|
||||
playerLayout.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
btnVoiceNotes.setVisibility(View.GONE);
|
||||
noVoiceNote.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
this.setOnShowListener(new OnShowListener() {
|
||||
@Override
|
||||
public void onShow(DialogInterface dialogInterface) {
|
||||
|
||||
mLinearLayoutView.setVisibility(View.VISIBLE);
|
||||
if (type == null) {
|
||||
type = Effectstype.Slidetop;
|
||||
}
|
||||
start(type);
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
mRelativeLayoutView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (isCancelable) dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
btnVoiceNotes.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (btnVoiceNotes.isChecked()) {
|
||||
//start record
|
||||
record.startRecording(v);
|
||||
playerLayout.setVisibility(View.GONE);
|
||||
} else {
|
||||
//stop record
|
||||
record.stop(v);
|
||||
playerLayout.setVisibility(View.VISIBLE);
|
||||
try {
|
||||
header.setVoice_note(record.saveAudioToByte());
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
header.setVoice_note(header.getVoice_note());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
btnPlay.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (MODE == Global.MODE_SURVEY_TASK ||
|
||||
MODE == Global.MODE_VIEW_SENT_SURVEY) {//
|
||||
AudioRecord.playAudio(context, header.getVoice_note());
|
||||
} else {
|
||||
record.play(v);
|
||||
}
|
||||
}
|
||||
});
|
||||
btnStop.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
record.stopPlay(v);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void toDefault() {
|
||||
mTitle.setTextColor(Color.parseColor(defTextColor));
|
||||
mDivider.setBackgroundColor(Color.parseColor(defDividerColor));
|
||||
mMessage.setTextColor(Color.parseColor(defMsgColor));
|
||||
mLinearLayoutView.setBackgroundColor(Color.parseColor(defDialogColor));
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withTaskListChoice() {
|
||||
mTaskListLayoutView.setVisibility(View.VISIBLE);
|
||||
mLinearLayoutMsgView.setVisibility(View.VISIBLE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice setTaskListChoiceClick(View.OnClickListener click) {
|
||||
mTasklistChoice.setOnClickListener(click);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withVerificationListChoice() {
|
||||
mLinearLayoutMsgView.setVisibility(View.VISIBLE);
|
||||
mVerificationLayoutView.setVisibility(View.VISIBLE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice setVerificationListChoiceClick(View.OnClickListener click) {
|
||||
mVerificationlistChoice.setOnClickListener(click);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withApprovalListChoice() {
|
||||
mApprovalLayoutView.setVisibility(View.VISIBLE);
|
||||
mLinearLayoutMsgView.setVisibility(View.VISIBLE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice setApprovalListChoiceClick(View.OnClickListener click) {
|
||||
mApprovallistChoice.setOnClickListener(click);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withDividerColor(String colorString) {
|
||||
mDivider.setBackgroundColor(Color.parseColor(colorString));
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withDividerColor(int color) {
|
||||
mDivider.setBackgroundColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withTransparentBackground() {
|
||||
mLinearLayoutView.setBackgroundColor(Color.TRANSPARENT);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withTitle(CharSequence title) {
|
||||
toggleView(mLinearLayoutTopView, title);
|
||||
mTitle.setText(title);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withStatusListTitle() {
|
||||
toggleView(mTaskListLayoutView, "Status Task");
|
||||
mTasklistChoice.setText("Status Task");
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withStatusListTitleAndCounter(String count) {
|
||||
toggleView(mTaskListLayoutView, "Status Task");
|
||||
mTasklistChoice.setText("Status Task - [" + count + "]");
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withTaskListTitleAndCounter(String count) {
|
||||
toggleView(mTaskListLayoutView, "Task List");
|
||||
mTasklistChoice.setText("Task List - [" + count + "]");
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withVerificationListTitleAndCounter(String count) {
|
||||
toggleView(mVerificationLayoutView, "Verification List");
|
||||
mVerificationlistChoice.setText("Verification List - [" + count + "]");
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withApprovalListTitleAndCounter(String count) {
|
||||
toggleView(mApprovalLayoutView, "Approval List");
|
||||
mApprovallistChoice.setText("Approval List - [" + count + "]");
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withNoTitle() {
|
||||
mLinearLayoutTopView.setVisibility(View.GONE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withTitleColor(String colorString) {
|
||||
mTitle.setTextColor(Color.parseColor(colorString));
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withTitleColor(int color) {
|
||||
mTitle.setTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withMessage(int textResId) {
|
||||
toggleView(mLinearLayoutMsgView, textResId);
|
||||
mMessage.setText(textResId);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice setHeader(SurveyHeaderBean bean) {
|
||||
this.header = bean;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice setSurveyMode(int mode) {
|
||||
this.MODE = mode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withNoMessage() {
|
||||
mLinearLayoutMsgView.setVisibility(View.GONE);
|
||||
mMessage.setVisibility(View.GONE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withMessage(CharSequence msg) {
|
||||
toggleView(mLinearLayoutMsgView, msg);
|
||||
mMessage.setText(msg);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withMessageColor(String colorString) {
|
||||
mMessage.setTextColor(Color.parseColor(colorString));
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withMessageColor(int color) {
|
||||
mMessage.setTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withImageView(Bitmap bitmap) {
|
||||
mImageView.setVisibility(View.VISIBLE);
|
||||
mImageView.setImageBitmap(bitmap);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withAutoText(ArrayAdapter<String> adapter) {
|
||||
mtxtSearch.setVisibility(View.VISIBLE);
|
||||
mtxtSearch.setText("");
|
||||
mtxtSearch.setAdapter(adapter);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getAutoText() {
|
||||
return mtxtSearch.getText().toString();
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withDialogColor(String colorString) {
|
||||
mLinearLayoutView.getBackground().setColorFilter(ColorUtils.getColorFilter(Color.parseColor(colorString)));
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withDialogColor(int color) {
|
||||
mLinearLayoutView.getBackground().setColorFilter(ColorUtils.getColorFilter(color));
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withIcon(int drawableResId) {
|
||||
mIcon.setImageResource(drawableResId);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withIcon(Drawable icon) {
|
||||
mIcon.setImageDrawable(icon);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withDuration(int duration) {
|
||||
this.mDuration = duration;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withEffect(Effectstype type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withButtonDrawable(int resid) {
|
||||
mButton1.setBackgroundResource(resid);
|
||||
mButton2.setBackgroundResource(resid);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withButton1Text(CharSequence text) {
|
||||
mButton1.setVisibility(View.VISIBLE);
|
||||
mButton1.setText(text);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice withButton2Text(CharSequence text) {
|
||||
mButton2.setVisibility(View.VISIBLE);
|
||||
mButton2.setText(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice setButton1Click(View.OnClickListener click) {
|
||||
mButton1.setOnClickListener(click);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice setButton2Click(View.OnClickListener click) {
|
||||
mButton2.setOnClickListener(click);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice setCustomView(int resId, Context context) {
|
||||
View customView = View.inflate(context, resId, null);
|
||||
if (mFrameLayoutCustomView.getChildCount() > 0) {
|
||||
mFrameLayoutCustomView.removeAllViews();
|
||||
}
|
||||
mFrameLayoutCustomView.addView(customView);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice setCustomView(View view, Context context) {
|
||||
if (mFrameLayoutCustomView.getChildCount() > 0) {
|
||||
mFrameLayoutCustomView.removeAllViews();
|
||||
}
|
||||
mFrameLayoutCustomView.addView(view);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice isCancelableOnTouchOutside(boolean cancelable) {
|
||||
this.isCancelable = cancelable;
|
||||
this.setCanceledOnTouchOutside(cancelable);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NiftyDialogBuilder_Voice isCancelable(boolean cancelable) {
|
||||
this.isCancelable = cancelable;
|
||||
this.setCancelable(cancelable);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void toggleView(View view, Object obj) {
|
||||
if (obj == null) {
|
||||
view.setVisibility(View.GONE);
|
||||
} else {
|
||||
view.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
super.show();
|
||||
}
|
||||
|
||||
private void start(Effectstype type) {
|
||||
BaseEffects animator = type.getAnimator();
|
||||
if (mDuration != -1) {
|
||||
animator.setDuration(Math.abs(mDuration));
|
||||
}
|
||||
animator.start(mRelativeLayoutView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismiss() {
|
||||
super.dismiss();
|
||||
mButton1.setVisibility(View.GONE);
|
||||
mButton2.setVisibility(View.GONE);
|
||||
mTaskListLayoutView.setVisibility(View.GONE);
|
||||
mVerificationLayoutView.setVisibility(View.GONE);
|
||||
mApprovalLayoutView.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,158 @@
|
|||
package com.adins.mss.foundation.questiongenerator.form;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.InputFilter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.foundation.formatter.Tool;
|
||||
import com.adins.mss.foundation.questiongenerator.OptionAnswerBean;
|
||||
import com.adins.mss.foundation.questiongenerator.QuestionBean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MultipleQuestionView extends MultiOptionQuestionViewAbstract {
|
||||
|
||||
private boolean withDescription = false;
|
||||
private boolean withOneDescription = false;
|
||||
private LinearLayout optionGroup;
|
||||
private List<CheckBox> checkBoxes;
|
||||
private List<EditText> txtDescriptions;
|
||||
|
||||
private List<OptionAnswerBean> selectedOptionAnswers = new ArrayList<>();
|
||||
|
||||
public MultipleQuestionView(Context context, QuestionBean bean) {
|
||||
super(context, bean);
|
||||
this.bean = bean;
|
||||
optionGroup = new LinearLayout(context);
|
||||
addView(optionGroup, defLayout);
|
||||
optionGroup.setOrientation(VERTICAL);
|
||||
|
||||
checkBoxes = new ArrayList<>();
|
||||
txtDescriptions = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOptions(Context context, List<OptionAnswerBean> options) {
|
||||
|
||||
this.options = options;
|
||||
|
||||
//clear option before set a new one
|
||||
optionGroup.removeAllViews();
|
||||
checkBoxes.clear();
|
||||
int i = 0;
|
||||
String[] arrSelectedAnswer = null;
|
||||
List<OptionAnswerBean> optSelectedBean = null;
|
||||
try {
|
||||
arrSelectedAnswer = Tool.split(bean.getAnswer(), Global.DELIMETER_DATA);
|
||||
optSelectedBean = bean.getSelectedOptionAnswers();
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
arrSelectedAnswer = new String[0];
|
||||
optSelectedBean = new ArrayList<>();
|
||||
}
|
||||
for (OptionAnswerBean optBean : options) {
|
||||
CheckBox chk = new CheckBox(context);
|
||||
chk.setText(optBean.getValue());
|
||||
chk.setChecked(optBean.isSelected());
|
||||
optionGroup.addView(chk);
|
||||
checkBoxes.add(chk);
|
||||
String optBeanId = optBean.getUuid_lookup();
|
||||
if (withDescription) {
|
||||
EditText desc = new EditText(context);
|
||||
InputFilter[] inputFilters = {new InputFilter.LengthFilter(
|
||||
Global.DEFAULT_MAX_LENGTH)};
|
||||
desc.setFilters(inputFilters);
|
||||
qloop:
|
||||
for (OptionAnswerBean nOptBean : optSelectedBean) {
|
||||
String nOptBeanId = nOptBean.getUuid_lookup();
|
||||
if (optBeanId.equals(nOptBeanId) && nOptBean.isSelected()) {
|
||||
desc.setText(arrSelectedAnswer[i]);
|
||||
i++;
|
||||
break qloop;
|
||||
}
|
||||
}
|
||||
|
||||
optionGroup.addView(desc, defLayout);
|
||||
txtDescriptions.add(desc);
|
||||
}
|
||||
}
|
||||
if (withOneDescription) {
|
||||
EditText desc = new EditText(context);
|
||||
InputFilter[] inputFilters = {new InputFilter.LengthFilter(
|
||||
Global.DEFAULT_MAX_LENGTH)};
|
||||
desc.setFilters(inputFilters);
|
||||
try {
|
||||
desc.setText(bean.getAnswer());
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
optionGroup.addView(desc, defLayout);
|
||||
txtDescriptions.add(desc);
|
||||
}
|
||||
|
||||
//Glen 14 Oct 2014, select saved selected options
|
||||
selectSavedOptionsFromBeans(getSelectedOptionAnswers());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableDescription(Context context) {
|
||||
withDescription = true;
|
||||
}
|
||||
|
||||
public void enableOneDescription(Context context) {
|
||||
withOneDescription = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectOption(int id, String desc) {
|
||||
if (checkBoxes != null && checkBoxes.size() > id) {
|
||||
checkBoxes.get(id).setChecked(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveSelectedOptionToBean() {
|
||||
selectedOptionAnswers.clear();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < checkBoxes.size(); i++) {
|
||||
CheckBox chk = checkBoxes.get(i);
|
||||
if (chk.isChecked()) {
|
||||
OptionAnswerBean optAnsBean = options.get(i); //assume checkbox is the same order as options
|
||||
|
||||
if (sb.length() > 0) {
|
||||
sb.append(Global.DELIMETER_DATA);
|
||||
}
|
||||
|
||||
if (withDescription) {
|
||||
EditText txtDescription = txtDescriptions.get(i);
|
||||
String description = txtDescription.getText().toString();
|
||||
sb.append(description);
|
||||
}
|
||||
optAnsBean.setSelected(true);
|
||||
|
||||
selectedOptionAnswers.add(optAnsBean);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
questionBean.setAnswer(sb.toString());
|
||||
if (withOneDescription) {
|
||||
EditText txtDescription = txtDescriptions.get(0);
|
||||
String description = txtDescription.getText().toString();
|
||||
questionBean.setAnswer(description);
|
||||
}
|
||||
|
||||
//Glen 23 Oct 2014
|
||||
questionBean.setLovCode(sb.toString());
|
||||
|
||||
questionBean.setSelectedOptionAnswers(selectedOptionAnswers);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<solid android:color="@color/fontColorWhite" />
|
||||
<stroke android:width="1dp"
|
||||
android:color="@color/gradient_end" ></stroke>
|
||||
<corners
|
||||
android:topLeftRadius="5dp"
|
||||
android:topRightRadius="5dp"
|
||||
android:bottomRightRadius="5dp"
|
||||
android:bottomLeftRadius="5dp" />
|
||||
|
||||
</shape>
|
|
@ -0,0 +1,37 @@
|
|||
package com.adins.mss.odr.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.adins.mss.odr.model.JsonResponseServer.ResponseServer;
|
||||
|
||||
public class JsonUpdateOrder {
|
||||
List<ResponseServer> listResponseServer;
|
||||
|
||||
public List<ResponseServer> getListResponseServer() {
|
||||
return listResponseServer;
|
||||
}
|
||||
|
||||
public void setListResponseServer(List<ResponseServer> listResponseServer) {
|
||||
this.listResponseServer = listResponseServer;
|
||||
}
|
||||
|
||||
public class ResponseServer {
|
||||
private String key;
|
||||
private String value;
|
||||
public String getkey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setkey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,906 @@
|
|||
package com.adins.mss.foundation.sync;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.core.content.FileProvider;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.NewMainActivity;
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.base.authentication.Authentication;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.dynamicform.CustomerFragment;
|
||||
import com.adins.mss.base.dynamicform.JsonRequestQuestionSet;
|
||||
import com.adins.mss.base.dynamicform.JsonResponseQuestionSet;
|
||||
import com.adins.mss.base.todo.form.JsonRequestScheme;
|
||||
import com.adins.mss.base.todo.form.JsonResponseScheme;
|
||||
import com.adins.mss.base.update.DownloadUpdate;
|
||||
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.Holiday;
|
||||
import com.adins.mss.dao.Lookup;
|
||||
import com.adins.mss.dao.PrintItem;
|
||||
import com.adins.mss.dao.QuestionSet;
|
||||
import com.adins.mss.dao.Scheme;
|
||||
import com.adins.mss.dao.Sync;
|
||||
import com.adins.mss.dao.User;
|
||||
import com.adins.mss.foundation.camerainapp.helper.Logger;
|
||||
import com.adins.mss.foundation.db.dataaccess.HolidayDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.LookupDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.PrintItemDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.QuestionSetDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.SchemeDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.SyncDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.UserDataAccess;
|
||||
import com.adins.mss.foundation.dialog.DialogManager;
|
||||
import com.adins.mss.foundation.dialog.NiftyDialogBuilder;
|
||||
import com.adins.mss.foundation.formatter.Tool;
|
||||
import com.adins.mss.foundation.http.HttpConnection;
|
||||
import com.adins.mss.foundation.http.HttpConnectionResult;
|
||||
import com.adins.mss.foundation.http.HttpCryptedConnection;
|
||||
import com.adins.mss.foundation.security.storepreferences.ObscuredSharedPreferences;
|
||||
import com.adins.mss.foundation.sync.api.DataSynchronizer;
|
||||
import com.adins.mss.foundation.sync.api.FakeSynchronizationCallback;
|
||||
import com.google.firebase.perf.FirebasePerformance;
|
||||
import com.google.firebase.perf.metrics.HttpMetric;
|
||||
|
||||
import org.acra.ACRA;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by olivia.dg on 5/2/2017.
|
||||
*/
|
||||
|
||||
public class BackgroundServiceSynchronize implements BackgroundSynchronize.SynchronizeListener, Authentication.AuthenticationHandler {
|
||||
private static final String SYNCHRONIZATION_PREFERENCE = "com.adins.mss.base.SynchronizationPreference";
|
||||
public static NotificationManager mNotifyManager;
|
||||
public static Notification.Builder mBuilder;
|
||||
public static Notification.BigTextStyle inboxStyle;
|
||||
public Context context;
|
||||
BackgroundSynchronize backgroundSynchronize;
|
||||
private int syncCounter = 0;
|
||||
private int syncMax = 0;
|
||||
private FakeSynchronizationCallback<Sync> syncFakeCallback;
|
||||
private boolean init;
|
||||
private DataSynchronizer datasync;
|
||||
private FakeSynchronizationCallback<Lookup> lookupFakeCallback;
|
||||
private FakeSynchronizationCallback<Holiday> holidayFakeCallback;
|
||||
private FakeSynchronizationCallback<User> cashFakeCallBack;
|
||||
private Sync finalSavedSync;
|
||||
private boolean forceStop;
|
||||
private boolean isFinish = false;
|
||||
private boolean isSyncScheme = false;
|
||||
private boolean isSyncQuestionSet = false;
|
||||
private boolean isSyncLookup = false;
|
||||
private boolean isSyncHoliday = false;
|
||||
private boolean isHoliday = false;
|
||||
private SynchronizeAll synchronizeAll;
|
||||
public static final String NOTIFICATION_CHANNEL_ID = "10002";
|
||||
|
||||
public BackgroundServiceSynchronize(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void authentication(FragmentActivity context) {
|
||||
com.adins.mss.foundation.notification.Notification.getSharedNotification().clearNotifAll(context);
|
||||
String username = GlobalData.getSharedGlobalData().getUser().getLogin_id();
|
||||
String password = GlobalData.getSharedGlobalData().getUser().getPassword();
|
||||
|
||||
if (Global.IS_DEV)
|
||||
System.out.println("this is uname and password = " + username + "-" + password);
|
||||
PackageInfo pInfo = null;
|
||||
try {
|
||||
pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
int buildNumber = 0;
|
||||
if(pInfo != null){
|
||||
Global.BUILD_VERSION = pInfo.versionCode;
|
||||
Global.APP_VERSION = pInfo.versionName;
|
||||
buildNumber = Global.BUILD_VERSION;
|
||||
}
|
||||
Authentication.authenticateOnBackground(
|
||||
context,
|
||||
username,
|
||||
password,
|
||||
buildNumber,
|
||||
this);
|
||||
}
|
||||
|
||||
public void Sync() {
|
||||
start();
|
||||
}
|
||||
|
||||
public void start() {
|
||||
syncFakeCallback = new FakeSynchronizationCallback<Sync>() {
|
||||
@Override
|
||||
public void onSuccess(List<Sync> entities) {
|
||||
syncMax = entities.size() * 2;
|
||||
syncCounter = 0;
|
||||
try {
|
||||
if (!entities.isEmpty()) {
|
||||
for (Sync sync : entities) {
|
||||
syncCounter++;
|
||||
publishCounter();
|
||||
if (init) {
|
||||
List<HashMap<String, String>> lookupArgs = new ArrayList<>();
|
||||
HashMap<String, String> forms = new HashMap<>();
|
||||
forms.put("lov_group", sync.getLov_group());
|
||||
lookupArgs.add(forms);
|
||||
|
||||
try {
|
||||
finalSavedSync = sync;
|
||||
datasync.fakeReflect("MS_LOV", Lookup.class,
|
||||
lookupArgs, lookupFakeCallback, 1,
|
||||
false, DataSynchronizer.IS_SYNCHRONIZE_LOOKUP);
|
||||
if (forceStop) {
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
sendErrorDataToACRA(e.getMessage());
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
error();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
finalSavedSync = SyncDataAccess.getOneByLovGroupName(context, sync.getLov_group());
|
||||
Lookup lookups = LookupDataAccess.getOneByLovGroup(context, sync.getLov_group());
|
||||
boolean isHaveLookupData;
|
||||
isHaveLookupData = lookups != null;
|
||||
if (finalSavedSync != null && isHaveLookupData) {
|
||||
if (finalSavedSync.getDtm_upd().getTime() >= sync
|
||||
.getDtm_upd().getTime()) {
|
||||
syncCounter++;
|
||||
publishCounter();
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
finalSavedSync = sync;
|
||||
}
|
||||
|
||||
List<HashMap<String, Object>> lookupArgs = new ArrayList<>();
|
||||
HashMap<String, Object> forms = new HashMap<>();
|
||||
forms.put("lov_group", sync.getLov_group());
|
||||
|
||||
if (SyncDataAccess.getOneByLovGroupName(context, finalSavedSync.getLov_group()) != null) {/*SyncDataAccess.getOne(activity, finalSavedSync.getUuid_sync()) != null*/
|
||||
forms.put("dtm_upd", finalSavedSync.getDtm_upd());
|
||||
}
|
||||
|
||||
lookupArgs.add(forms);
|
||||
|
||||
try {
|
||||
|
||||
datasync.fakeReflect("MS_LOV", Lookup.class,
|
||||
lookupArgs, lookupFakeCallback, 0,
|
||||
false, DataSynchronizer.IS_SYNCHRONIZE_LOOKUP);
|
||||
if (forceStop) {
|
||||
return;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
sendErrorDataToACRA(e.getMessage());
|
||||
error();
|
||||
return;
|
||||
}
|
||||
}
|
||||
syncCounter++;
|
||||
publishCounter();
|
||||
}
|
||||
} else {
|
||||
progressUpdated(100);
|
||||
isSyncLookup = true;
|
||||
}
|
||||
|
||||
publishCounter();
|
||||
String application = GlobalData.getSharedGlobalData().getAuditData().getApplication();
|
||||
try {
|
||||
datasync.fakeReflect("USER_CASH", User.class,
|
||||
null, cashFakeCallBack, 1,
|
||||
false, DataSynchronizer.IS_SYNCHRONIZE_COH);
|
||||
if (forceStop) {
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
isSyncHoliday = true;
|
||||
publishCounter();
|
||||
}
|
||||
|
||||
try {
|
||||
datasync.fakeReflect("MS_HOLIDAY_D", Holiday.class,
|
||||
null, holidayFakeCallback, 1,
|
||||
false, DataSynchronizer.IS_SYNCHRONIZE_HOLIDAY);
|
||||
if (forceStop) {
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
isSyncHoliday = true;
|
||||
publishCounter();
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
if (Global.IS_DEV)
|
||||
ex.printStackTrace();
|
||||
sendErrorDataToACRA(ex.getMessage());
|
||||
error();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(final String errMessage) {
|
||||
sendErrorDataToACRA(errMessage);
|
||||
error();
|
||||
}
|
||||
};
|
||||
|
||||
holidayFakeCallback = new FakeSynchronizationCallback<Holiday>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(List<Holiday> entities) {
|
||||
try {
|
||||
syncMax = entities.size() * 2;
|
||||
syncCounter = 0;
|
||||
isHoliday = true;
|
||||
for (Holiday holiday : entities) {
|
||||
syncCounter++;
|
||||
publishCounter();
|
||||
HolidayDataAccess.addOrReplace(context, holiday);
|
||||
syncCounter++;
|
||||
publishCounter();
|
||||
}
|
||||
publishCounter();
|
||||
} catch (Exception ex) {
|
||||
sendErrorDataToACRA(ex.getMessage());
|
||||
error();
|
||||
forceStop = true;
|
||||
if (Global.IS_DEV)
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(final String errMessage) {
|
||||
sendErrorDataToACRA(errMessage);
|
||||
error();
|
||||
forceStop = true;
|
||||
}
|
||||
};
|
||||
|
||||
lookupFakeCallback = new FakeSynchronizationCallback<Lookup>() {
|
||||
@Override
|
||||
public void onSuccess(List<Lookup> entities) {
|
||||
try {
|
||||
LookupDataAccess.addOrUpdateAll(context, entities);
|
||||
SyncDataAccess.addOrReplace(context, finalSavedSync);
|
||||
} catch (Exception ex) {
|
||||
sendErrorDataToACRA(ex.getMessage());
|
||||
error();
|
||||
forceStop = true;
|
||||
if (Global.IS_DEV)
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(final String errMessage) {
|
||||
sendErrorDataToACRA(errMessage);
|
||||
error();
|
||||
forceStop = true;
|
||||
}
|
||||
};
|
||||
|
||||
cashFakeCallBack = new FakeSynchronizationCallback<User>() {
|
||||
@Override
|
||||
public void onSuccess(List<User> entities) {
|
||||
if (!entities.isEmpty()) {
|
||||
User ucash = GlobalData.getSharedGlobalData().getUser();
|
||||
ucash.setCash_limit(entities.get(0).getCash_limit());
|
||||
ucash.setCash_on_hand(entities.get(0).getCash_on_hand());
|
||||
UserDataAccess.addOrReplace(context, ucash);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(final String errMessage) {
|
||||
sendErrorDataToACRA(errMessage);
|
||||
error();
|
||||
forceStop = true;
|
||||
}
|
||||
};
|
||||
synchronize();
|
||||
}
|
||||
|
||||
private void synchronize() {
|
||||
datasync = new DataSynchronizer(context);
|
||||
if (synchronizeAll != null)
|
||||
synchronizeAll.cancel(true);
|
||||
synchronizeAll = new SynchronizeAll();
|
||||
synchronizeAll.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionFail(Authentication auth, HttpConnectionResult result) {
|
||||
//EMPTY
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoginFail(Authentication auth, String message) {
|
||||
if (message.contains("Password") || message.contains("password") || message.contains("IMEI") || message.contains("imei")) {
|
||||
DialogManager.showForceExitAlert((Activity) context, context.getString(R.string.password_not_match));
|
||||
} else
|
||||
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onForceUpdate(Authentication auth, String message, final String otaLink) {
|
||||
NiftyDialogBuilder builder = NiftyDialogBuilder.getInstance(context)
|
||||
.withTitle(context.getString(R.string.server))
|
||||
.withMessage(context.getString(R.string.critical_update))
|
||||
.withButton1Text(context.getString(R.string.update)).setButton1Click(
|
||||
new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
openUpdate(otaLink);
|
||||
}
|
||||
}
|
||||
).isCancelable(false)
|
||||
.isCancelableOnTouchOutside(false);
|
||||
builder.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInactiveUser(Authentication auth) {
|
||||
DialogManager.UninstallerHandler((FragmentActivity) context);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoginSuccess(Authentication auth, String otaLink, boolean needUpdatePassword, boolean pwdExp, boolean needUpdateApplication, String message, User authenticatedUser) {
|
||||
Activity activity = (Activity) context;
|
||||
if (needUpdateApplication && !activity.isFinishing() && !activity.isDestroyed()) {
|
||||
showAskForUpdateDialog(otaLink, needUpdatePassword, pwdExp);
|
||||
return;
|
||||
}
|
||||
GlobalData.getSharedGlobalData().setUser(authenticatedUser);
|
||||
Sync();
|
||||
}
|
||||
|
||||
private void showAskForUpdateDialog(final String otaLink, final boolean needUpdatePassword, final boolean pwdExp) {
|
||||
final NiftyDialogBuilder builder = NiftyDialogBuilder.getInstance(context);
|
||||
builder.withTitle(context.getString(R.string.server)).isCancelableOnTouchOutside(false).isCancelable(false)
|
||||
.withMessage(context.getString(R.string.update_available))
|
||||
.withButton1Text(context.getString(R.string.later))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
builder.dismiss();
|
||||
Sync();
|
||||
}
|
||||
})
|
||||
.withButton2Text(context.getString(R.string.update))
|
||||
.setButton2Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
builder.dismiss();
|
||||
openUpdate(otaLink);
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
private void openUpdate(String otaLink) {
|
||||
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
File file = new File(context.getFilesDir(), "app.apk");
|
||||
if (file.exists()) {
|
||||
Uri apkURI = FileProvider.getUriForFile(
|
||||
context, context.getPackageName() + ".provider", file);
|
||||
intent.setDataAndType(apkURI, "application/vnd.android.package-archive");
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
context.startActivity(intent);
|
||||
} else {
|
||||
DownloadUpdate downloadUpdate = new DownloadUpdate(context);
|
||||
downloadUpdate.execute(otaLink);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private String getScheme() {
|
||||
String resultScheme = Global.FALSE_STRING;
|
||||
List<Scheme> listSchemes = SchemeDataAccess.getAll(context);
|
||||
if (Global.getSharedGlobal().getTempSchemeVersion() != null)
|
||||
Global.getSharedGlobal().setTempSchemeVersion(null);
|
||||
Global.getSharedGlobal().setTempSchemeVersion(new HashMap<String, Integer>());
|
||||
|
||||
for (Scheme scheme : listSchemes) {
|
||||
Global.getSharedGlobal().getTempSchemeVersion().put(scheme.getUuid_scheme(), Integer.valueOf(scheme.getForm_version()));
|
||||
}
|
||||
|
||||
try {
|
||||
if (GlobalData.getSharedGlobalData().getUser() == null)
|
||||
NewMainActivity.InitializeGlobalDataIfError(context);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
resultScheme = "Data has gone";
|
||||
return resultScheme;
|
||||
}
|
||||
|
||||
JsonRequestScheme requestScheme = new JsonRequestScheme();
|
||||
if (GlobalData.getSharedGlobalData().getUser() != null && GlobalData.getSharedGlobalData().getUser()
|
||||
.getUuid_user() != null) {
|
||||
requestScheme.setUuid_user(GlobalData.getSharedGlobalData().getUser()
|
||||
.getUuid_user());
|
||||
} else {
|
||||
ObscuredSharedPreferences sharedPref = ObscuredSharedPreferences.getPrefs(context,
|
||||
"GlobalData", Context.MODE_PRIVATE);
|
||||
String uuidUser = sharedPref.getString("UUID_USER", "");
|
||||
if (uuidUser.length() > 0) {
|
||||
requestScheme.setUuid_user(uuidUser);
|
||||
} else {
|
||||
resultScheme = "Data has gone";
|
||||
return resultScheme;
|
||||
}
|
||||
}
|
||||
requestScheme.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
requestScheme.setTask(Global.TASK_GETLIST);
|
||||
|
||||
String json = GsonHelper.toJson(requestScheme);
|
||||
String url = GlobalData.getSharedGlobalData().getURL_GET_SCHEME();
|
||||
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);
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (serverResult != null && serverResult.isOK()) {
|
||||
try {
|
||||
String result = serverResult.getResult();
|
||||
JsonResponseScheme responseScheme = GsonHelper.fromJson(result,
|
||||
JsonResponseScheme.class);
|
||||
List<Scheme> schemes = responseScheme.getListScheme();
|
||||
List<PrintItem> printItems = responseScheme.getListPrintItems();
|
||||
if (schemes != null) {
|
||||
resultScheme = Global.TRUE_STRING;
|
||||
syncMax = schemes.size() + printItems.size();
|
||||
|
||||
SchemeDataAccess.clean(context);
|
||||
|
||||
for (Scheme scheme : schemes) {
|
||||
syncCounter++;
|
||||
publishCounter();
|
||||
Scheme scheme2 = null;
|
||||
try {
|
||||
scheme2 = SchemeDataAccess.getOneByLastUpdate(context,
|
||||
scheme.getUuid_scheme(),
|
||||
scheme.getScheme_last_update());
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
try {
|
||||
PrintItemDataAccess.delete(context, scheme.getUuid_scheme());
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
|
||||
if (scheme2 == null) {
|
||||
if (scheme.getUuid_scheme() != null) {
|
||||
SchemeDataAccess.addOrReplace(context, scheme);
|
||||
}
|
||||
} else {
|
||||
if (scheme.getScheme_last_update().after(scheme2.getScheme_last_update())
|
||||
&& scheme.getUuid_scheme() != null) {
|
||||
SchemeDataAccess.addOrReplace(context, scheme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (PrintItem printItem : printItems) {
|
||||
syncCounter++;
|
||||
publishCounter();
|
||||
Scheme scheme = SchemeDataAccess.getOne(context,
|
||||
printItem.getUuid_scheme());
|
||||
printItem.setScheme(scheme);
|
||||
PrintItemDataAccess.addOrReplace(context, printItem);
|
||||
}
|
||||
|
||||
if (schemes.isEmpty() || printItems.isEmpty()) {
|
||||
progressUpdated(100);
|
||||
isSyncScheme = true;
|
||||
}
|
||||
} else {
|
||||
resultScheme = responseScheme.getStatus().getMessage();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
resultScheme = serverResult.getResult();
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
}
|
||||
return resultScheme;
|
||||
}
|
||||
|
||||
protected void getQuestionSet() {
|
||||
List<Scheme> schemeList = SchemeDataAccess.getAll(context);
|
||||
syncMax = schemeList.size();
|
||||
syncCounter = 0;
|
||||
for (Scheme scheme : schemeList) {
|
||||
List<QuestionSet> qs = new ArrayList<>();
|
||||
try {
|
||||
qs = QuestionSetDataAccess.getAllByFormVersion(context, scheme.getUuid_scheme(), scheme.getForm_version());
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
Logger.e("BackgroundSynchronize", e);
|
||||
}
|
||||
boolean isChange = true;
|
||||
if (!qs.isEmpty()) {
|
||||
try {
|
||||
JsonRequestScheme requestScheme = new JsonRequestScheme();
|
||||
requestScheme.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
requestScheme.setUuid_user(GlobalData.getSharedGlobalData().getUser().getUuid_user());
|
||||
requestScheme.setUuid_scheme(scheme.getUuid_scheme());
|
||||
requestScheme.setTask(Global.TASK_GETONE);
|
||||
|
||||
String json = GsonHelper.toJson(requestScheme);
|
||||
String url = GlobalData.getSharedGlobalData().getURL_GET_SCHEME();
|
||||
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);
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (serverResult != null && serverResult.isOK()) {
|
||||
try {
|
||||
String result = serverResult.getResult();
|
||||
JsonResponseScheme responseScheme = GsonHelper.fromJson(result, JsonResponseScheme.class);
|
||||
List<Scheme> schemes = responseScheme.getListScheme();
|
||||
|
||||
Scheme scheme2 = schemes.get(0);
|
||||
try {
|
||||
//olivia : pengecekan form version
|
||||
if(scheme2!=null) {
|
||||
Integer new_last_update = Integer.valueOf(scheme2.getForm_version());
|
||||
Integer temp_last_update = (Global.getSharedGlobal().getTempSchemeVersion().get(scheme.getUuid_scheme())!= null) ? Global.getSharedGlobal().getTempSchemeVersion().get(scheme.getUuid_scheme()): 0 ;
|
||||
isChange = new_last_update > temp_last_update;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
}
|
||||
if (isChange || qs.isEmpty()) {
|
||||
syncCounter++;
|
||||
publishCounter();
|
||||
JsonRequestQuestionSet request = new JsonRequestQuestionSet();
|
||||
request.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
request.setUuid_scheme(scheme.getUuid_scheme());
|
||||
|
||||
String formVersionScheme = null;
|
||||
String formVersionTaskH = null;
|
||||
try {
|
||||
formVersionScheme = scheme.getForm_version();
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
|
||||
}
|
||||
if (null != formVersionScheme) {
|
||||
request.setForm_version(formVersionScheme);
|
||||
} else if (null != CustomerFragment.getHeader() && null != CustomerFragment.getHeader().getForm_version()) {
|
||||
formVersionTaskH = CustomerFragment.getHeader().getForm_version();
|
||||
request.setForm_version(formVersionTaskH);
|
||||
}
|
||||
|
||||
String json = GsonHelper.toJson(request);
|
||||
String url = GlobalData.getSharedGlobalData().getURL_GET_QUESTIONSET();
|
||||
boolean encrypt = GlobalData.getSharedGlobalData().isEncrypt();
|
||||
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
|
||||
HttpCryptedConnection httpConn = new HttpCryptedConnection(context, encrypt, decrypt);
|
||||
HttpConnectionResult serverResult = null;
|
||||
|
||||
//Firebase Performance Trace HTTP Request
|
||||
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);
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (serverResult != null && serverResult.isOK()) {
|
||||
try {
|
||||
String result = serverResult.getResult();
|
||||
JsonResponseQuestionSet response = GsonHelper.fromJson(result, JsonResponseQuestionSet.class);
|
||||
if (response.getStatus().getCode() == 0) {
|
||||
List<QuestionSet> questionSets = response.getListQuestionSet();
|
||||
|
||||
// Nendi: 2019.09.26 | Clean questionSet
|
||||
QuestionSetDataAccess.delete(context, request.getUuid_scheme(), request.getForm_version());
|
||||
|
||||
List<QuestionSet> newquestionSets = new ArrayList<>();
|
||||
for (QuestionSet questionSet : questionSets) {
|
||||
questionSet.setUuid_question_set(Tool.getUUID());
|
||||
questionSet.setScheme(scheme);
|
||||
newquestionSets.add(questionSet);
|
||||
}
|
||||
QuestionSetDataAccess.addOrReplace(context, scheme.getUuid_scheme(), newquestionSets);
|
||||
} else {
|
||||
if (Global.IS_DEV) {
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
syncMax = 2;
|
||||
syncCounter = 1;
|
||||
publishCounter();
|
||||
progressUpdated(100);
|
||||
}
|
||||
}
|
||||
if (schemeList.isEmpty()) {
|
||||
progressUpdated(100);
|
||||
isSyncQuestionSet = true;
|
||||
}
|
||||
isSyncQuestionSet = true;
|
||||
progressUpdated(1);
|
||||
}
|
||||
|
||||
|
||||
private void syncLookup() throws IOException {
|
||||
List<Scheme> schemeList = SchemeDataAccess.getAll(context);
|
||||
List<Sync> syncs = SyncDataAccess.getAll(context);
|
||||
init = syncs == null || syncs.isEmpty();
|
||||
List<HashMap<String, String>> lookupArgs = new ArrayList<>();
|
||||
for (Scheme scheme : schemeList) {
|
||||
HashMap<String, String> forms = new HashMap<>();
|
||||
forms.put("formId", scheme.getForm_id());
|
||||
lookupArgs.add(forms);
|
||||
}
|
||||
if (!schemeList.isEmpty()) {
|
||||
datasync.fakeReflect("MS_LOV", Sync.class, lookupArgs,
|
||||
syncFakeCallback, init ? 1 : 0, true, DataSynchronizer.IS_SYNCHRONIZE_SYNC);
|
||||
} else {
|
||||
progressUpdated(100);
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String application = GlobalData.getSharedGlobalData().getAuditData().getApplication();
|
||||
if (Global.APPLICATION_COLLECTION.equalsIgnoreCase(application)) {
|
||||
datasync.fakeReflect("USER_CASH", User.class,
|
||||
null, cashFakeCallBack, 1,
|
||||
false, DataSynchronizer.IS_SYNCHRONIZE_COH);
|
||||
}
|
||||
datasync.fakeReflect("MS_HOLIDAY_D", Holiday.class,
|
||||
null, holidayFakeCallback, 1,
|
||||
false, DataSynchronizer.IS_SYNCHRONIZE_HOLIDAY);
|
||||
|
||||
if (forceStop) {
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
progressUpdated(100);
|
||||
isSyncHoliday = true;
|
||||
publishCounter();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
|
||||
private void publishCounter() {
|
||||
float progress = (float) (syncCounter) / (syncMax - 1) * 100;
|
||||
final float finalProgress = progress > 100 ? 100 : progress;
|
||||
progressUpdated(finalProgress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void progressUpdated(float progress) {
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
mNotifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
mBuilder = new Notification.Builder(context);
|
||||
mBuilder.setContentTitle(context.getString(R.string.synchronizing))
|
||||
.setContentText(context.getString(R.string.syncing))
|
||||
.setSmallIcon(R.drawable.ic_synchronize);
|
||||
inboxStyle = new Notification.BigTextStyle();
|
||||
inboxStyle.setBigContentTitle(context.getString(R.string.synchronizing));
|
||||
inboxStyle.bigText(context.getString(R.string.syncing));
|
||||
mBuilder.setStyle(inboxStyle);
|
||||
mBuilder.setProgress(0, 0, true);
|
||||
mBuilder.setOngoing(true);
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)
|
||||
{
|
||||
int importance = NotificationManager.IMPORTANCE_HIGH;
|
||||
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "NOTIFICATION_CHANNEL_NAME", importance);
|
||||
assert mNotifyManager != null;
|
||||
mBuilder.setChannelId(NOTIFICATION_CHANNEL_ID);
|
||||
mNotifyManager.createNotificationChannel(notificationChannel);
|
||||
}
|
||||
|
||||
mNotifyManager.notify(0, mBuilder.build());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
|
||||
if (!isSyncScheme && !isSyncQuestionSet && !isSyncLookup) {
|
||||
|
||||
} else if (isSyncScheme && !isSyncQuestionSet && !isSyncLookup) {
|
||||
|
||||
} else if (isSyncScheme && isSyncQuestionSet && !isSyncLookup) {
|
||||
if (progress >= 100) {
|
||||
isSyncLookup = true;
|
||||
}
|
||||
} else if (isSyncScheme && isSyncQuestionSet && isSyncLookup && !isSyncHoliday) {
|
||||
if (progress >= 100 && isHoliday) {
|
||||
isSyncHoliday = true;
|
||||
}
|
||||
if (progress == -0.0 && isHoliday) {
|
||||
isSyncHoliday = true;
|
||||
}
|
||||
}
|
||||
if (progress > 100)
|
||||
progress = 100;
|
||||
|
||||
if (syncMax == 0 || progress >= 100) {
|
||||
if (!isFinish && isSyncLookup && isSyncHoliday) {
|
||||
isFinish = true;
|
||||
mNotifyManager.cancel(0);
|
||||
|
||||
String application = GlobalData.getSharedGlobalData().getAuditData().getApplication();
|
||||
|
||||
String day = String.valueOf(Calendar.getInstance().get(Calendar.DATE));
|
||||
String month = String.valueOf(Calendar.getInstance().get(Calendar.MONTH) + 1);
|
||||
String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
|
||||
|
||||
ObscuredSharedPreferences synchronizationPreference = ObscuredSharedPreferences.getPrefs(context, SYNCHRONIZATION_PREFERENCE, Context.MODE_PRIVATE);
|
||||
if (Global.APPLICATION_ORDER.equalsIgnoreCase(application)) {
|
||||
synchronizationPreference.edit().putString("MOSyncDate", day + month + year).commit();
|
||||
} else if (Global.APPLICATION_SURVEY.equalsIgnoreCase(application)) {
|
||||
synchronizationPreference.edit().putString("MSSyncDate", day + month + year).commit();
|
||||
} else if (Global.APPLICATION_COLLECTION.equalsIgnoreCase(application)) {
|
||||
synchronizationPreference.edit().putString("MCSyncDate", day + month + year).commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void synchronizeFailed(SynchronizeItem syncItem, HttpConnectionResult errorResult, int numOfRetries) {
|
||||
backgroundSynchronize.resumeSync();
|
||||
}
|
||||
|
||||
private void error() {
|
||||
if (synchronizeAll != null){
|
||||
mNotifyManager.cancel(0);
|
||||
synchronizeAll.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendErrorDataToACRA(String message) {
|
||||
ACRA.getErrorReporter().putCustomData("errorSynchronize", message);
|
||||
ACRA.getErrorReporter().handleSilentException(new Exception("Error: Synchronize Error " + message));
|
||||
}
|
||||
|
||||
public class SynchronizeAll extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
try {
|
||||
final String res1 = getScheme();
|
||||
if (res1.equals(Global.TRUE_STRING)) {
|
||||
isSyncScheme = true;
|
||||
progressUpdated(1);
|
||||
getQuestionSet();
|
||||
syncLookup();
|
||||
} else {
|
||||
if (Global.FALSE_STRING.equals(res1)) {
|
||||
error();
|
||||
} else if (HttpConnection.ERROR_STATUSCODE_FROM_SERVER.equals(res1)) {
|
||||
if (Global.IS_DEV)
|
||||
System.out.print(HttpConnection.ERROR_STATUSCODE_FROM_SERVER);
|
||||
} else {
|
||||
error();
|
||||
}
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
if (Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
sendErrorDataToACRA(e.getMessage());
|
||||
error();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.adins.mss.coll.closingtask.senders;
|
||||
|
||||
/**
|
||||
* Created by angga.permadi on 6/6/2016.
|
||||
*/
|
||||
public interface ClosingTaskListener {
|
||||
|
||||
void onClosingTaskSuccess();
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.adins.mss.foundation.print;
|
||||
|
||||
import com.adins.mss.foundation.http.MssResponseType;
|
||||
|
||||
/**
|
||||
* Created by angga.permadi on 3/7/2016.
|
||||
*/
|
||||
public class SubmitPrintResponse extends MssResponseType {
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.adins.mss.base.depositreport;
|
||||
|
||||
import com.adins.mss.foundation.http.MssRequestType;
|
||||
|
||||
/**
|
||||
* Created by angga.permadi on 8/29/2016.
|
||||
*/
|
||||
public class TaskHDetailRequest extends MssRequestType {
|
||||
}
|
|
@ -0,0 +1,292 @@
|
|||
package com.adins.mss.foundation.questiongenerator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.view.Gravity;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.foundation.formatter.Formatter;
|
||||
import com.adins.mss.foundation.formatter.Tool;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class AnswerViewGenerator {
|
||||
public static final int TYPE_DATE = 1;
|
||||
public static final int TYPE_TIME = 2;
|
||||
public static final int TYPE_DATE_TIME = 3;
|
||||
|
||||
public final LayoutParams defLayout = new LayoutParams(
|
||||
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
|
||||
|
||||
public LinearLayout generateTextAnswer(Activity activity,
|
||||
QuestionBean bean, int number) {
|
||||
|
||||
LinearLayout container = new LinearLayout(activity);
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
TextView label = new TextView(activity);
|
||||
label.setText(number + ". " + bean.getQuestion_label());
|
||||
label.setTextColor(Color.BLACK);
|
||||
container.addView(label, defLayout);
|
||||
|
||||
TextView text = new TextView(activity);
|
||||
text.setText(bean.getAnswer());
|
||||
//Glen 16 Sept 2014, if decimal, use thousand separator
|
||||
//Glen 21 Oct 2014, if calculation, use thousand separator too
|
||||
// if (Global.AT_DECIMAL.equals(bean.getAnswer_type()) ||
|
||||
// Global.AT_CALCULATION.equals(bean.getAnswer_type())){
|
||||
//bong 17 march 15 include at_currecnty
|
||||
if (Global.AT_DECIMAL.equals(bean.getAnswer_type()) ||
|
||||
Global.AT_CALCULATION.equals(bean.getAnswer_type()) ||
|
||||
Global.AT_CURRENCY.equals(bean.getAnswer_type())) {
|
||||
String answer = bean.getAnswer();
|
||||
//Glen 21 Oct 2014, use tool
|
||||
String separatedAnswer = Tool.separateThousand(answer);
|
||||
|
||||
text.setText(separatedAnswer);
|
||||
}
|
||||
text.setTextColor(Color.BLACK);
|
||||
container.addView(text);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
//add 27 juni 2012~bangkit
|
||||
public LinearLayout generateLocationAnswer(Activity activity,
|
||||
QuestionBean bean, int number) {
|
||||
|
||||
LinearLayout container = new LinearLayout(activity);
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
TextView label = new TextView(activity);
|
||||
label.setText(number + ". " + bean.getQuestion_label());
|
||||
label.setTextColor(Color.BLACK);
|
||||
container.addView(label, defLayout);
|
||||
|
||||
TextView text = new TextView(activity);
|
||||
text.setText(bean.getAnswer());
|
||||
text.setTextColor(Color.BLACK);
|
||||
container.addView(text);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
public LinearLayout generateDateTimeAnswer(final Activity activity,
|
||||
QuestionBean bean, int number, int type) throws Exception {
|
||||
|
||||
LinearLayout container = new LinearLayout(activity);
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
TextView label = new TextView(activity);
|
||||
label.setText(number + ". " + bean.getQuestion_label());
|
||||
label.setTextColor(Color.BLACK);
|
||||
container.addView(label, defLayout);
|
||||
|
||||
String format = null;
|
||||
TextView text = new TextView(activity);
|
||||
text.setTextColor(Color.BLACK);
|
||||
|
||||
switch (type) {
|
||||
case TYPE_DATE:
|
||||
format = Global.DATE_STR_FORMAT;
|
||||
break;
|
||||
case TYPE_TIME:
|
||||
format = Global.TIME_STR_FORMAT;
|
||||
break;
|
||||
case TYPE_DATE_TIME:
|
||||
format = Global.DATE_TIME_STR_FORMAT;
|
||||
break;
|
||||
default:
|
||||
format = Global.DATE_STR_FORMAT;
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
String answer = bean.getAnswer();
|
||||
long dtLong = Formatter.stringToDate(answer);
|
||||
Date date = new Date(dtLong);
|
||||
answer = Formatter.formatDate(date, format);
|
||||
text.setText(answer);
|
||||
} catch (Exception ex) {
|
||||
//Glen 6 Aug 2014, add possibility to insert milliseconds
|
||||
String answer = bean.getAnswer();
|
||||
long dtLong = Long.parseLong(answer);
|
||||
Date date = new Date(dtLong);
|
||||
answer = Formatter.formatDate(date, format);
|
||||
text.setText(answer);
|
||||
}
|
||||
container.addView(text);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
public LinearLayout generateOptionsAnswer(Activity activity,
|
||||
QuestionBean bean, int number) {
|
||||
LinearLayout container = new LinearLayout(activity);
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
TextView label = new TextView(activity);
|
||||
label.setText(number + ". " + bean.getQuestion_label());
|
||||
label.setTextColor(Color.BLACK);
|
||||
container.addView(label, defLayout);
|
||||
|
||||
//Glen 15 Oct 2014, use selected list only
|
||||
List<OptionAnswerBean> listOptions = bean.getSelectedOptionAnswers();
|
||||
|
||||
for (OptionAnswerBean optBean : listOptions) {
|
||||
if (optBean.isSelected()) {
|
||||
TextView txt = new TextView(activity);
|
||||
txt.setTextColor(Color.BLACK);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
//Glen 3 Oct 2014, refactor, code can be from optionId or lovCode
|
||||
// sb.append(optBean.getId()).append(" - ").append(optBean.getLabel());
|
||||
String lovCode = optBean.getCode();
|
||||
if (lovCode != null && lovCode.length() > 0) {
|
||||
sb.append(lovCode);
|
||||
} else {
|
||||
sb.append(optBean.getCode());
|
||||
}
|
||||
sb.append(" - ").append(optBean.getValue());
|
||||
|
||||
|
||||
String description = optBean.getValue();
|
||||
if (!Tool.isEmptyString(description)) {
|
||||
sb.append(" / ").append(description);
|
||||
}
|
||||
txt.setText(sb.toString());
|
||||
container.addView(txt);
|
||||
}
|
||||
}
|
||||
|
||||
//Glen 15 Oct 2014, if answer is empty, add empty field
|
||||
if (listOptions.size() == 0) {
|
||||
TextView txt = new TextView(activity);
|
||||
txt.setText("-");
|
||||
container.addView(txt);
|
||||
}
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
public LinearLayout generateImageQuestion(final Activity activity, final QuestionBean bean, int number) {
|
||||
LinearLayout container = new LinearLayout(activity);
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
container.setGravity(Gravity.CENTER);
|
||||
|
||||
TextView label = new TextView(activity);
|
||||
label.setText(number + ". " + bean.getQuestion_label());
|
||||
label.setTextColor(Color.BLACK);
|
||||
container.addView(label, defLayout);
|
||||
|
||||
byte[] img = bean.getImgAnswer();
|
||||
final ImageView thumb = new ImageView(activity);
|
||||
|
||||
|
||||
if (img != null && img.length > 0) {
|
||||
//TODO bangkit- harus di gerelalisasikan
|
||||
final float scale = 0; //TODO bangkit
|
||||
int w = Tool.dpToPixel(scale, Global.THUMBNAIL_WIDTH);
|
||||
int h = Tool.dpToPixel(scale, Global.THUMBNAIL_HEIGHT);
|
||||
ViewGroup.LayoutParams imgLayout = new LayoutParams(w, h);
|
||||
thumb.setLayoutParams(imgLayout);
|
||||
Bitmap bm = BitmapFactory.decodeByteArray(img, 0, img.length);
|
||||
int[] res = Tool.getThumbnailResolution(bm.getWidth(), bm.getHeight());
|
||||
Bitmap thumbnail = Bitmap.createScaledBitmap(bm, res[0], res[1], true);
|
||||
thumb.setImageBitmap(thumbnail);
|
||||
} else {
|
||||
thumb.setImageResource(android.R.drawable.ic_menu_gallery);
|
||||
}
|
||||
container.addView(thumb, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
public LinearLayout generateLookupAnswer(final Activity activity, final QuestionBean bean, int number) {
|
||||
LinearLayout container = new LinearLayout(activity);
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
TextView label = new TextView(activity);
|
||||
label.setText(number + ". " + bean.getQuestion_label());
|
||||
label.setTextColor(Color.BLACK);
|
||||
container.addView(label, defLayout);
|
||||
|
||||
String key = bean.getLovId();
|
||||
if (!Tool.isEmptyString(key)) {
|
||||
TextView txt = new TextView(activity);
|
||||
txt.setTextColor(Color.BLACK);
|
||||
String value = bean.getAnswer();
|
||||
if (key == null || "".equals(key.trim())) {
|
||||
key = "(code)";
|
||||
}
|
||||
if (value == null || "".equals(value.trim())) {
|
||||
value = "(name)";
|
||||
}
|
||||
txt.setText(key + " - " + value);
|
||||
container.addView(txt, defLayout);
|
||||
}
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
public LinearLayout generateByAnswerType(Activity activity,
|
||||
QuestionBean bean, int number) throws Exception {
|
||||
LinearLayout linear = new LinearLayout(activity);
|
||||
linear.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
String answerType = bean.getAnswer_type();
|
||||
if (Global.AT_TEXT.equals(answerType)) {
|
||||
return this.generateTextAnswer(activity, bean, number);
|
||||
}
|
||||
//Glen 17 Oct 2014, new type Calculation
|
||||
else if (Global.AT_CALCULATION.equals(answerType)) {
|
||||
return this.generateTextAnswer(activity, bean, number);
|
||||
} else if (Global.AT_GPS.equals(answerType)) {
|
||||
return this.generateLocationAnswer(activity, bean, number);
|
||||
} else if (Global.AT_GPS_N_LBS.equals(answerType)) {
|
||||
return this.generateLocationAnswer(activity, bean, number);
|
||||
} else if (Global.AT_MULTIPLE.equals(answerType)) {
|
||||
return this.generateOptionsAnswer(activity, bean, number);
|
||||
} else if (Global.AT_MULTIPLE_W_DESCRIPTION.equals(answerType)) {
|
||||
return this.generateOptionsAnswer(activity, bean, number);
|
||||
} else if (Global.AT_RADIO.equals(answerType)) {
|
||||
return this.generateOptionsAnswer(activity, bean, number);
|
||||
} else if (Global.AT_RADIO_W_DESCRIPTION.equals(answerType)) {
|
||||
return this.generateOptionsAnswer(activity, bean, number);
|
||||
} else if (Global.AT_DROPDOWN.equals(answerType)) {
|
||||
return this.generateOptionsAnswer(activity, bean, number);
|
||||
} else if (Global.AT_DROPDOWN_W_DESCRIPTION.equals(answerType)) {
|
||||
return this.generateOptionsAnswer(activity, bean, number);
|
||||
} else if (Global.AT_CURRENCY.equals(answerType)) {
|
||||
return this.generateTextAnswer(activity, bean, number);
|
||||
} else if (Global.AT_NUMERIC.equals(answerType)) {
|
||||
return this.generateTextAnswer(activity, bean, number);
|
||||
} else if (Global.AT_DECIMAL.equals(answerType)) {
|
||||
return this.generateTextAnswer(activity, bean, number);
|
||||
} else if (Global.AT_DATE.equals(answerType)) {
|
||||
return this.generateDateTimeAnswer(activity, bean, number, TYPE_DATE);
|
||||
} else if (Global.AT_TIME.equals(answerType)) {
|
||||
return this.generateDateTimeAnswer(activity, bean, number, TYPE_TIME);
|
||||
} else if (Global.AT_DATE_TIME.equals(answerType)) {
|
||||
return this.generateDateTimeAnswer(activity, bean, number, TYPE_DATE_TIME);
|
||||
} else if (Tool.isImage(answerType)) {
|
||||
return this.generateImageQuestion(activity, bean, number);
|
||||
} else if (Global.AT_LOV.equals(answerType)) {
|
||||
return this.generateLookupAnswer(activity, bean, number);
|
||||
} else if (Global.AT_LOV_W_FILTER.equals(answerType)) {
|
||||
return this.generateLookupAnswer(activity, bean, number);
|
||||
} else if (Global.AT_DRAWING.equals(answerType)) {
|
||||
return this.generateImageQuestion(activity, bean, number);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,237 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/bg_grayscale"
|
||||
android:padding="8dp" >
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/scrollView1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_above="@+id/btnPrintDepReport"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentTop="true" >
|
||||
|
||||
<TableLayout
|
||||
android:id="@+id/tableLayout1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true" >
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/rowBatchId"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/tv_gray"
|
||||
android:paddingBottom="4dp"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:paddingTop="4dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.25"
|
||||
android:text="@string/label_batch_id"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/divider2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.1"
|
||||
android:text="@string/divider_colon"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtBatchId"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.25"
|
||||
android:text="@string/label_batch_id"/>
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/rowTransferBy"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/tv_gray_light"
|
||||
android:paddingBottom="4dp"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:paddingTop="4dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.25"
|
||||
android:text="@string/label_transfer_by"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/divider3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.1"
|
||||
android:text="@string/divider_colon"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txttransferBy"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.25"
|
||||
android:text="@string/label_bank"/>
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/rowCashierName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/tv_gray"
|
||||
android:paddingBottom="4dp"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:paddingTop="4dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.25"
|
||||
android:text="@string/label_cashier_name"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/divider4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.1"
|
||||
android:text="@string/divider_colon"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtCashierName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.25"
|
||||
android:text="@string/label_cashier_name"/>
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/rowAccountNumber"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/tv_gray"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:paddingTop="8dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.25"
|
||||
android:text="@string/label_account_number"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/divider5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.1"
|
||||
android:text="@string/divider_colon"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtAccountNumber"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.25"
|
||||
android:text="@string/dummy_number"/>
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/rowBankName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/tv_gray_light"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:paddingTop="8dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView6"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.25"
|
||||
android:text="@string/label_bank_name"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/divider6"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.1"
|
||||
android:text="@string/divider_colon"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtBankName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.25"
|
||||
android:text="@string/label_bank_name"/>
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/rowEvidenceTransfer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/tv_gray"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:paddingTop="8dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.25"
|
||||
android:text="@string/label_transfer_evidence"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/divider"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.1"
|
||||
android:text="@string/divider_colon"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imgEvidenceTransfer"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="120dp"
|
||||
android:layout_weight="0.25"
|
||||
android:scaleType="fitStart"
|
||||
android:src="@drawable/profile_image" />
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
</ScrollView>
|
||||
|
||||
<!-- <ListView -->
|
||||
<!-- android:id="@+id/recapitulationList" -->
|
||||
<!-- android:layout_width="match_parent" -->
|
||||
<!-- android:layout_height="fill_parent" -->
|
||||
<!-- android:layout_below="@+id/textView2" -->
|
||||
<!-- android:layout_weight="1" > -->
|
||||
<!-- </ListView> -->
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btnPrintDepReport"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:background="@android:color/transparent"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/btn_print" />
|
||||
|
||||
</RelativeLayout>
|
Binary file not shown.
After Width: | Height: | Size: 3 KiB |
Binary file not shown.
After Width: | Height: | Size: 466 B |
Binary file not shown.
After Width: | Height: | Size: 448 B |
Loading…
Add table
Add a link
Reference in a new issue