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

View file

@ -0,0 +1,21 @@
package com.adins.mss.foundation.print;
import com.adins.mss.dao.PrintDate;
import com.adins.mss.foundation.http.MssRequestType;
import java.util.List;
/**
* Created by angga.permadi on 3/3/2016.
*/
public class SubmitPrintRequest extends MssRequestType {
private List<PrintDate> listPrint;
public List<PrintDate> getListPrint() {
return listPrint;
}
public void setListPrint(List<PrintDate> listPrint) {
this.listPrint = listPrint;
}
}

View file

@ -0,0 +1,210 @@
package com.github.jjobes.slidedatetimepicker;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.text.format.DateFormat;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.DatePicker;
import android.widget.NumberPicker;
import android.widget.NumberPicker.OnValueChangeListener;
import android.widget.TimePicker;
import com.adins.mss.base.R;
/**
* The fragment for the second page in the ViewPager that holds
* the TimePicker.
*
* @author jjobes
*/
public class TimeFragment extends Fragment {
private TimeChangedListener mCallback;
private TimePicker mTimePicker;
public TimeFragment() {
// Required empty public constructor for fragment.
}
/**
* Return an instance of TimeFragment with its bundle filled with the
* constructor arguments. The values in the bundle are retrieved in
* below to properly initialize the TimePicker.
*
* @param theme
* @param hour
* @param minute
* @param isClientSpecified24HourTime
* @param is24HourTime
* @return
*/
public static final TimeFragment newInstance(int theme, int hour, int minute,
boolean isClientSpecified24HourTime, boolean is24HourTime) {
TimeFragment f = new TimeFragment();
Bundle b = new Bundle();
b.putInt("theme", theme);
b.putInt("hour", hour);
b.putInt("minute", minute);
b.putBoolean("isClientSpecified24HourTime", isClientSpecified24HourTime);
b.putBoolean("is24HourTime", is24HourTime);
f.setArguments(b);
return f;
}
/**
* Cast the reference to {@link SlideDateTimeDialogFragment} to a
* {@link TimeChangedListener}.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
// mCallback = (TimeChangedListener) getTargetFragment();
mCallback = (TimeChangedListener) getParentFragment();
} catch (ClassCastException e) {
throw new ClassCastException("Calling fragment must implement " +
"TimeFragment.TimeChangedListener interface");
}
}
/**
* Create and return the user interface view for this fragment.
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
int theme = getArguments().getInt("theme");
int initialHour = getArguments().getInt("hour");
int initialMinute = getArguments().getInt("minute");
boolean isClientSpecified24HourTime = getArguments().getBoolean("isClientSpecified24HourTime");
boolean is24HourTime = getArguments().getBoolean("is24HourTime");
// Unless we inflate using a cloned inflater with a Holo theme,
// on Lollipop devices the TimePicker will be the new-style
// radial TimePicker, which is not what we want. So we will
// clone the inflater that we're given but with our specified
// theme, then inflate the layout with this new inflater.
Context contextThemeWrapper = new ContextThemeWrapper(
getActivity(),
theme == SlideDateTimePicker.HOLO_DARK ?
android.R.style.Theme_Holo :
android.R.style.Theme_Holo_Light);
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
View v = localInflater.inflate(R.layout.fragment_time, container, false);
mTimePicker = (TimePicker) v.findViewById(R.id.timePicker);
// block keyboard popping up on touch
mTimePicker.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);
mTimePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
mCallback.onTimeChanged(hourOfDay, minute);
}
});
// If the client specifies a 24-hour time format, set it on
// the TimePicker.
if (isClientSpecified24HourTime) {
mTimePicker.setIs24HourView(is24HourTime);
} else {
// If the client does not specify a 24-hour time format, use the
// device default.
mTimePicker.setIs24HourView(DateFormat.is24HourFormat(
getTargetFragment().getActivity()));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mTimePicker.setHour(initialHour);
} else {
mTimePicker.setCurrentHour(initialHour);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mTimePicker.setMinute(initialMinute);
} else {
mTimePicker.setCurrentMinute(initialMinute);
}
// Fix for the bug where a TimePicker's onTimeChanged() is not called when
// the user toggles the AM/PM button. Only applies to 4.0.0 and 4.0.3.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH &&
Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
fixTimePickerBug18982();
}
return v;
}
/**
* Workaround for bug in Android TimePicker where the onTimeChanged() callback
* is not invoked when the user toggles between AM/PM. But we need to be able
* to detect this in order to dynamically update the tab title properly when
* the user toggles between AM/PM.
* <p>
* Registered as Issue 18982:
* <p>
* https://code.google.com/p/android/issues/detail?id=18982
*/
private void fixTimePickerBug18982() {
View amPmView = ((ViewGroup) mTimePicker.getChildAt(0)).getChildAt(3);
if (amPmView instanceof NumberPicker) {
((NumberPicker) amPmView).setOnValueChangedListener(new OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
if (picker.getValue() == 1) // PM
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (mTimePicker.getHour() < 12)
mTimePicker.setHour(mTimePicker.getHour() + 12);
} else {
if (mTimePicker.getCurrentHour() < 12) {
mTimePicker.setCurrentHour(mTimePicker.getCurrentHour() + 12);
}
}
} else // AM
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (mTimePicker.getHour() >= 12)
mTimePicker.setHour(mTimePicker.getHour() - 12);
} else {
if (mTimePicker.getCurrentHour() >= 12)
mTimePicker.setCurrentHour(mTimePicker.getCurrentHour() - 12);
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mCallback.onTimeChanged(
mTimePicker.getHour(),
mTimePicker.getMinute());
} else {
mCallback.onTimeChanged(
mTimePicker.getCurrentHour(),
mTimePicker.getCurrentMinute()
);
}
}
});
}
}
/**
* Used to communicate back to the parent fragment as the user
* is changing the time spinners so we can dynamically update
* the tab text.
*/
public interface TimeChangedListener {
void onTimeChanged(int hour, int minute);
}
}

View file

@ -0,0 +1,110 @@
package com.adins.mss.odr.accounts.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
import com.adins.mss.odr.R;
import java.util.HashMap;
import java.util.List;
/**
* Created by muhammad.aap on 11/28/2018.
*/
public class AccountButtonOpportunitiesAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
public AccountButtonOpportunitiesAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_lead, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.txtProductAcc);
txtListChild.setText(childText);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_groupbutton, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="oval">
<solid android:color="@color/tv_light"/>
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="@color/tv_light"/>
</shape>
</item>
</selector>

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid
android:color="#005baa"></solid>
<padding
android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
</shape>
</item>
</selector>

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_select_all"
android:icon="@drawable/ic_select_all"
android:orderInCategory="100"
android:title="Select All"
app:showAsAction="always" />
<item
android:id="@+id/action_deselect_all"
android:icon="@drawable/ic_unselect_all"
android:orderInCategory="200"
android:title="Deselect All"
app:showAsAction="always" />
<item
android:id="@+id/action_done"
android:icon="@drawable/ic_done_control"
android:orderInCategory="300"
android:title="Done"
app:showAsAction="always" />
</menu>

View file

@ -0,0 +1,283 @@
package com.adins.mss.dao;
import java.util.List;
import com.adins.mss.dao.DaoSession;
import de.greenrobot.dao.DaoException;
import com.adins.mss.base.util.ExcludeFromGson;
import com.google.gson.annotations.SerializedName;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit.
/**
* Entity mapped to table "TR_DEPOSITREPORT_H".
*/
public class DepositReportH {
/** Not-null value. */
@SerializedName("uuid_deposit_report_h")
private String uuid_deposit_report_h;
@SerializedName("last_update")
private java.util.Date last_update;
@SerializedName("batch_id")
private String batch_id;
@SerializedName("bank_account")
private String bank_account;
@SerializedName("bank_name")
private String bank_name;
@SerializedName("cashier_name")
private String cashier_name;
@SerializedName("transfered_date")
private java.util.Date transfered_date;
@SerializedName("usr_crt")
private String usr_crt;
@SerializedName("dtm_crt")
private java.util.Date dtm_crt;
@SerializedName("image")
private byte[] image;
@SerializedName("uuid_user")
private String uuid_user;
@SerializedName("flag")
private String flag;
@SerializedName("branch_payment")
private String branch_payment;
@SerializedName("code_channel")
private String code_channel;
@SerializedName("no_transaction")
private String no_transaction;
/** Used to resolve relations */
private transient DaoSession daoSession;
/** Used for active entity operations. */
private transient DepositReportHDao myDao;
private User user;
private String user__resolvedKey;
private List<DepositReportD> depositReportDList;
public DepositReportH() {
}
public DepositReportH(String uuid_deposit_report_h) {
this.uuid_deposit_report_h = uuid_deposit_report_h;
}
public DepositReportH(String uuid_deposit_report_h, java.util.Date last_update, String batch_id, String bank_account, String bank_name, String cashier_name, java.util.Date transfered_date, String usr_crt, java.util.Date dtm_crt, byte[] image, String uuid_user, String flag, String branch_payment, String code_channel, String no_transaction) {
this.uuid_deposit_report_h = uuid_deposit_report_h;
this.last_update = last_update;
this.batch_id = batch_id;
this.bank_account = bank_account;
this.bank_name = bank_name;
this.cashier_name = cashier_name;
this.transfered_date = transfered_date;
this.usr_crt = usr_crt;
this.dtm_crt = dtm_crt;
this.image = image;
this.uuid_user = uuid_user;
this.flag = flag;
this.branch_payment = branch_payment;
this.code_channel = code_channel;
this.no_transaction = no_transaction;
}
/** called by internal mechanisms, do not call yourself. */
public void __setDaoSession(DaoSession daoSession) {
this.daoSession = daoSession;
myDao = daoSession != null ? daoSession.getDepositReportHDao() : null;
}
/** Not-null value. */
public String getUuid_deposit_report_h() {
return uuid_deposit_report_h;
}
/** Not-null value; ensure this value is available before it is saved to the database. */
public void setUuid_deposit_report_h(String uuid_deposit_report_h) {
this.uuid_deposit_report_h = uuid_deposit_report_h;
}
public java.util.Date getLast_update() {
return last_update;
}
public void setLast_update(java.util.Date last_update) {
this.last_update = last_update;
}
public String getBatch_id() {
return batch_id;
}
public void setBatch_id(String batch_id) {
this.batch_id = batch_id;
}
public String getBank_account() {
return bank_account;
}
public void setBank_account(String bank_account) {
this.bank_account = bank_account;
}
public String getBank_name() {
return bank_name;
}
public void setBank_name(String bank_name) {
this.bank_name = bank_name;
}
public String getCashier_name() {
return cashier_name;
}
public void setCashier_name(String cashier_name) {
this.cashier_name = cashier_name;
}
public java.util.Date getTransfered_date() {
return transfered_date;
}
public void setTransfered_date(java.util.Date transfered_date) {
this.transfered_date = transfered_date;
}
public String getUsr_crt() {
return usr_crt;
}
public void setUsr_crt(String usr_crt) {
this.usr_crt = usr_crt;
}
public java.util.Date getDtm_crt() {
return dtm_crt;
}
public void setDtm_crt(java.util.Date dtm_crt) {
this.dtm_crt = dtm_crt;
}
public byte[] getImage() {
return image;
}
public void setImage(byte[] image) {
this.image = image;
}
public String getUuid_user() {
return uuid_user;
}
public void setUuid_user(String uuid_user) {
this.uuid_user = uuid_user;
}
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
public String getBranch_payment() {
return branch_payment;
}
public void setBranch_payment(String branch_payment) {
this.branch_payment = branch_payment;
}
public String getCode_channel() {
return code_channel;
}
public void setCode_channel(String code_channel) {
this.code_channel = code_channel;
}
public String getNo_transaction() {
return no_transaction;
}
public void setNo_transaction(String no_transaction) {
this.no_transaction = no_transaction;
}
/** To-one relationship, resolved on first access. */
public User getUser() {
String __key = this.uuid_user;
if (user__resolvedKey == null || user__resolvedKey != __key) {
if (daoSession == null) {
throw new DaoException("Entity is detached from DAO context");
}
UserDao targetDao = daoSession.getUserDao();
User userNew = targetDao.load(__key);
synchronized (this) {
user = userNew;
user__resolvedKey = __key;
}
}
return user;
}
public void setUser(User user) {
synchronized (this) {
this.user = user;
uuid_user = user == null ? null : user.getUuid_user();
user__resolvedKey = uuid_user;
}
}
/** To-many relationship, resolved on first access (and after reset). Changes to to-many relations are not persisted, make changes to the target entity. */
public List<DepositReportD> getDepositReportDList() {
if (depositReportDList == null) {
if (daoSession == null) {
throw new DaoException("Entity is detached from DAO context");
}
DepositReportDDao targetDao = daoSession.getDepositReportDDao();
List<DepositReportD> depositReportDListNew = targetDao._queryDepositReportH_DepositReportDList(uuid_deposit_report_h);
synchronized (this) {
if(depositReportDList == null) {
depositReportDList = depositReportDListNew;
}
}
}
return depositReportDList;
}
/** Resets a to-many relationship, making the next get call to query for a fresh result. */
public synchronized void resetDepositReportDList() {
depositReportDList = null;
}
/** Convenient call for {@link AbstractDao#delete(Object)}. Entity must attached to an entity context. */
public void delete() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.delete(this);
}
/** Convenient call for {@link AbstractDao#update(Object)}. Entity must attached to an entity context. */
public void update() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.update(this);
}
/** Convenient call for {@link AbstractDao#refresh(Object)}. Entity must attached to an entity context. */
public void refresh() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.refresh(this);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View file

@ -0,0 +1,170 @@
package com.adins.mss.odr.assignment;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.annotation.Keep;
import android.view.View;
import android.widget.AdapterView;
import com.adins.mss.base.GlobalData;
import com.adins.mss.base.util.GsonHelper;
import com.adins.mss.base.util.LocaleHelper;
import com.adins.mss.base.util.Utility;
import com.adins.mss.constant.Global;
import com.adins.mss.foundation.dialog.NiftyDialogBuilder;
import com.adins.mss.foundation.http.HttpConnectionResult;
import com.adins.mss.foundation.http.HttpCryptedConnection;
import com.adins.mss.odr.R;
import com.adins.mss.odr.model.JsonRequestDetailOrder;
import com.adins.mss.odr.model.JsonResponseServer;
import com.adins.mss.odr.model.JsonResponseServer.ResponseServer;
import com.androidquery.AQuery;
import com.google.firebase.perf.FirebasePerformance;
import com.google.firebase.perf.metrics.HttpMetric;
import org.acra.ACRA;
import java.util.List;
import java.util.Locale;
public class LookupAssignment extends Activity{
AQuery query ;
OrderAssignmentAdapter adapter;
List<ResponseServer> responseServer;
String uuid_user = GlobalData.getSharedGlobalData().getUser().getUuid_user();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.default_listview);
ACRA.getErrorReporter().putCustomData("LAST_CLASS_ACCESSED", getClass().getSimpleName());
query = new AQuery(this);
query.id(android.R.id.list).itemClicked(this, "itemClick");
String flag = getIntent().getStringExtra(Global.BUND_KEY_TASK);
String uuid_task_h = getIntent().getStringExtra(Global.BUND_KEY_UUID_TASKH);
new GetRequestDataLookup(uuid_task_h,flag).execute();
}
@Override
protected void attachBaseContext(Context newBase) {
Context context = newBase;
Locale locale;
try {
locale = new Locale(GlobalData.getSharedGlobalData().getLocale());
if (null == locale) {
locale = new Locale(LocaleHelper.ENGLSIH);
}
context = LocaleHelper.wrap(newBase, locale);
} catch (Exception e) {
locale = new Locale(LocaleHelper.ENGLSIH);
context = LocaleHelper.wrap(newBase, locale);
} finally {
super.attachBaseContext(context);
}
}
@Keep
public void itemClick(AdapterView<?> parent, View v, int position, long id){
Intent intent = new Intent();
intent.putExtra(Global.BUND_KEY_ASSIGNEE_ID, responseServer.get(position).getKey());
intent.putExtra(Global.BUND_KEY_ASSIGNEE_VALUE, responseServer.get(position).getValue());
intent.putExtra(Global.BUND_KEY_ASSIGNEE_JOB, responseServer.get(position).getFlag());
setResult(Global.REQUEST_CODE_LOOKUP, intent);
finish();
}
private class GetRequestDataLookup extends AsyncTask<Void, Void, JsonResponseServer> {
private ProgressDialog progressDialog;
private String errMessage = null;
private String uuid_task_h;
private String flag;
public GetRequestDataLookup(String uuid_task_h, String flag) {
this.flag = flag;
this.uuid_task_h=uuid_task_h;
}
@Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(LookupAssignment.this,
"", getString(R.string.progressWait), true);
}
@Override
protected JsonResponseServer doInBackground(Void... params) {
String result = null;
JsonRequestDetailOrder request = new JsonRequestDetailOrder();
request.setAudit(GlobalData.getSharedGlobalData().getAuditData());
request.setUuid_task_h(uuid_task_h);
request.setFlag(flag);
String json = GsonHelper.toJson(request);
String url = GlobalData.getSharedGlobalData().getURL_GET_LOOKUP();
boolean encrypt = GlobalData.getSharedGlobalData().isEncrypt();
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
HttpCryptedConnection httpConn = new HttpCryptedConnection(getApplicationContext(), 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);
result = serverResult.getResult();
Utility.metricStop(networkMetric, serverResult);
}
catch (Exception e) {
e.printStackTrace();
try {
progressDialog.dismiss();
} catch (Exception ex) {
}
errMessage = e.getMessage();
}
finally {
}
JsonResponseServer response =null;
try {
response = GsonHelper.fromJson(result, JsonResponseServer.class);
} catch (Exception e) {
errMessage = e.getMessage();
}
return response;
}
@Override
protected void onPostExecute(JsonResponseServer result){
if (progressDialog.isShowing()){
try {
progressDialog.dismiss();
} catch (Exception e) {
}
}
if(errMessage!=null){
NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(LookupAssignment.this);
dialogBuilder.withTitle(getString(R.string.error_capital))
.withMessage(errMessage)
.show();
}
else if(result==null){
NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(LookupAssignment.this);
dialogBuilder.withTitle(getString(R.string.info_capital))
.withMessage(errMessage)
.show();
}else{
if(result.getStatus().getCode()==0){
responseServer = result.getListResponseServer();
adapter = new OrderAssignmentAdapter(getApplicationContext(), responseServer, true);
query.id(android.R.id.list).adapter(adapter);
}else{
NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(LookupAssignment.this);
dialogBuilder.withTitle(getString(R.string.info_capital))
.withMessage(result.getStatus().getMessage())
.show();
}
}
}
}
}

View file

@ -0,0 +1,273 @@
package com.adins.mss.foundation.image;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;
import com.adins.mss.base.GlobalData;
import com.adins.mss.base.R;
import com.adins.mss.base.avatar.AvatarUploadRequestJson;
import com.adins.mss.base.avatar.AvatarUploader;
import com.adins.mss.base.crashlytics.FireCrash;
import com.adins.mss.base.timeline.Constants;
import com.adins.mss.base.util.LocaleHelper;
import com.adins.mss.dao.User;
import com.adins.mss.foundation.camerainapp.helper.Logger;
import com.adins.mss.foundation.db.dataaccess.UserDataAccess;
import com.adins.mss.foundation.dialog.DialogManager;
import com.edmodo.cropper.CropImageView;
import com.google.firebase.analytics.FirebaseAnalytics;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
/**
* @author gigin.ginanjar
*/
public class CroppingImageActivity extends Activity implements AvatarUploader.AvatarUploadHandler {
// Static final constants
private static final int DEFAULT_ASPECT_RATIO_VALUES = 10;
private static final int ROTATE_NINETY_DEGREES = 90;
private static final String ASPECT_RATIO_X = "ASPECT_RATIO_X";
private static final String ASPECT_RATIO_Y = "ASPECT_RATIO_Y";
private static final int ON_TOUCH = 1;
public static String BUND_KEY_ABSOLUTEPATH = "ABSOLUTE PATH";
public ExifInterface exif = null;
Bitmap croppedImage;
InputStream is = null;
Bitmap bitmap = null;
// Instance variables
private int mAspectRatioX = DEFAULT_ASPECT_RATIO_VALUES;
private int mAspectRatioY = DEFAULT_ASPECT_RATIO_VALUES;
private AvatarUploader avatarUploader;
private FirebaseAnalytics screenName;
// Saves the state upon rotating the screen/restarting the activity
@Override
protected void onSaveInstanceState(Bundle bundle) {
super.onSaveInstanceState(bundle);
bundle.putInt(ASPECT_RATIO_X, mAspectRatioX);
bundle.putInt(ASPECT_RATIO_Y, mAspectRatioY);
}
// Restores the state upon rotating the screen/restarting the activity
@Override
protected void onRestoreInstanceState(Bundle bundle) {
super.onRestoreInstanceState(bundle);
mAspectRatioX = bundle.getInt(ASPECT_RATIO_X);
mAspectRatioY = bundle.getInt(ASPECT_RATIO_Y);
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.cropping_image_layout);
String path = getIntent().getStringExtra(BUND_KEY_ABSOLUTEPATH);
final CropImageView cropImageView = (CropImageView) findViewById(R.id.CropImageView);
cropImageView.setFixedAspectRatio(true);
Uri sourceUri = Uri.parse(path);
final Button rotateButton = (Button) findViewById(R.id.Button_rotate);
final Button cancelButton = (Button) findViewById(R.id.Button_cancel);
final Button cropButton = (Button) findViewById(R.id.Button_crop);
avatarUploader = new AvatarUploader(this,this);
screenName = FirebaseAnalytics.getInstance(this);
try {
int sampleSize = calculateBitmapSampleSize(sourceUri);
is = getContentResolver().openInputStream(sourceUri);
BitmapFactory.Options option = new BitmapFactory.Options();
option.inSampleSize = sampleSize;
bitmap = BitmapFactory.decodeStream(is, null, option);
bitmap = Utils.resizeImageByPath(bitmap);
} catch (IOException e) {
Logger.e("Error reading image: " + e.getMessage(), e);
Toast.makeText(getApplicationContext(), getString(R.string.error_reading), Toast.LENGTH_SHORT).show();
rotateButton.setEnabled(false);
rotateButton.setClickable(false);
cropButton.setEnabled(false);
cropButton.setClickable(false);
} catch (OutOfMemoryError e) {
Logger.e("OOM reading image: " + e.getMessage(), e);
rotateButton.setEnabled(false);
rotateButton.setClickable(false);
cropButton.setEnabled(false);
cropButton.setClickable(false);
} catch (NullPointerException e) {
Logger.e("Null pointer image: " + e.getMessage(), e);
Toast.makeText(getApplicationContext(), getString(R.string.error_image_invalid), Toast.LENGTH_SHORT).show();
rotateButton.setEnabled(false);
rotateButton.setClickable(false);
cropButton.setEnabled(false);
cropButton.setClickable(false);
}
try {
cropImageView.setGuidelines(1);
ExifFromGallery sourceExif = new ExifFromGallery(sourceUri, this);
exif = sourceExif.getExif();
cropImageView.setImageBitmap(bitmap, exif);
} catch (Exception e) {
FireCrash.log(e);
// TODO: handle exception
try {
exif = new ExifInterface(sourceUri.getPath());
cropImageView.setImageBitmap(bitmap, exif);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
cropImageView.setImageBitmap(bitmap);
}
}
rotateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cropImageView.rotateImage(ROTATE_NINETY_DEGREES);
}
});
if (Constants.flag_edit == 0) {
cropImageView.setAspectRatio(16, 10);
} else if (Constants.flag_edit == 1) {
cropImageView.setAspectRatio(1, 1);
}
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
finish();
}
});
cropButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
croppedImage = cropImageView.getCroppedImage();
if(croppedImage == null){
finish();
}
//resized bitmap
croppedImage = Utils.getResizedBitmap(croppedImage,160,160);
if (Constants.flag_edit == 0) {
String temp_uuid_user = GlobalData.getSharedGlobalData().getUser().getUuid_user();
byte[] avatarByte = Utils.bitmapToByte(croppedImage);
User user = UserDataAccess.getOne(getApplicationContext(), temp_uuid_user);
user.setImage_cover(avatarByte);
UserDataAccess.addOrReplace(getApplicationContext(), user);
GlobalData.getSharedGlobalData().setUser(user);
uploadAvatar(avatarByte);
} else {
byte[] avatarByte = Utils.bitmapToByte(croppedImage);
uploadAvatar(avatarByte);
}
}
});
}
@Override
protected void onResume() {
super.onResume();
//Set Firebase screen name
screenName.setCurrentScreen(this, getString(R.string.screen_name_cropping_image), 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 uploadAvatar(byte[] avatarImg){
AvatarUploadRequestJson avatarUploadRequestJson = new AvatarUploadRequestJson();
avatarUploadRequestJson.setAudit(GlobalData.getSharedGlobalData().getAuditData());
avatarUploadRequestJson.setUuid_user(GlobalData.getSharedGlobalData().getUser().getUuid_user());
avatarUploadRequestJson.setBase64Img(Utils.byteToBase64(avatarImg));
avatarUploader.uploadAvatar(avatarUploadRequestJson);
}
private int calculateBitmapSampleSize(Uri bitmapUri) throws IOException {
InputStream is = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try {
is = getContentResolver().openInputStream(bitmapUri);
BitmapFactory.decodeStream(is, null, options); // Just get image size
} finally {
}
int maxSize = 1024;
int sampleSize = 1;
while (options.outHeight / sampleSize > maxSize || options.outWidth / sampleSize > maxSize) {
sampleSize = sampleSize << 1;
}
return sampleSize;
}
@Override
protected void onDestroy() {
super.onDestroy();
try {
is.close();
if (bitmap != null)
bitmap.recycle();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onUploadSuccess(String resultmsg, String image) {
String temp_uuid_user = GlobalData.getSharedGlobalData().getUser().getUuid_user();
User user = UserDataAccess.getOne(getApplicationContext(), temp_uuid_user);
byte[] avatarByte = Utils.base64ToByte(image);
user.setImage_profile(avatarByte);
UserDataAccess.addOrReplace(getApplicationContext(), user);
GlobalData.getSharedGlobalData().setUser(user);
Toast.makeText(this, resultmsg, Toast.LENGTH_SHORT).show();
finish();
}
@Override
public void onUploadFail(String errormsg) {
if(GlobalData.isRequireRelogin()){
DialogManager.showForceExitAlert(this,getString(com.adins.mss.base.R.string.msgLogout));
return;
}
Toast.makeText(this, errormsg, Toast.LENGTH_SHORT).show();
finish();
}
}