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,850 @@
|
|||
package com.adins.mss.base.mainmenu.fragment;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.MediaStore;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.text.format.DateFormat;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.NewMainActivity;
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.dialogfragments.ChangePasswordDialog;
|
||||
import com.adins.mss.base.dynamictheme.DynamicTheme;
|
||||
import com.adins.mss.base.dynamictheme.ThemeLoader;
|
||||
import com.adins.mss.base.dynamictheme.ThemeUtility;
|
||||
import com.adins.mss.base.fragments.SettingFragment;
|
||||
import com.adins.mss.base.mainmenu.MainMenuHelper;
|
||||
import com.adins.mss.base.mainmenu.NewMenuItem;
|
||||
import com.adins.mss.base.mainmenu.adapter.NewMainMenuAdapter;
|
||||
import com.adins.mss.base.timeline.Constants;
|
||||
import com.adins.mss.base.timeline.NewTimelineFragment;
|
||||
import com.adins.mss.base.timeline.TimelineImpl;
|
||||
import com.adins.mss.base.timeline.TimelineListener;
|
||||
import com.adins.mss.base.todolist.ToDoList;
|
||||
import com.adins.mss.base.util.Utility;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.Timeline;
|
||||
import com.adins.mss.dao.User;
|
||||
import com.adins.mss.foundation.UserHelp.UserHelp;
|
||||
import com.adins.mss.foundation.db.dataaccess.GeneralParameterDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.MenuDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.UserDataAccess;
|
||||
import com.adins.mss.foundation.dialog.DialogManager;
|
||||
import com.adins.mss.foundation.dialog.NiftyDialogBuilder_PL;
|
||||
import com.adins.mss.foundation.formatter.Tool;
|
||||
import com.adins.mss.foundation.image.CroppingImageActivity;
|
||||
import com.adins.mss.foundation.image.Utils;
|
||||
import com.adins.mss.foundation.security.storepreferences.ObscuredSharedPreferences;
|
||||
import com.androidquery.AQuery;
|
||||
import com.soundcloud.android.crop.Crop;
|
||||
|
||||
import org.acra.ACRA;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import de.hdodenhof.circleimageview.CircleImageView;
|
||||
|
||||
import static com.adins.mss.constant.Global.SHOW_USERHELP_DELAY_DEFAULT;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link NewMenuFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class NewMenuFragment extends Fragment implements TimelineListener, ThemeLoader.ColorSetLoaderCallback {
|
||||
public static NewMenuItem mnTaskList;
|
||||
public static NewMenuItem mnSurveyAssign;
|
||||
public static NewMenuItem mnSurveyVerif;
|
||||
public static NewMenuItem mnSurveyApproval;
|
||||
public static NewMenuItem mnVerifByBranch;
|
||||
public static NewMenuItem mnApprovalByBranch;
|
||||
public static NewMainMenuAdapter adapter;
|
||||
private static NewMainMenuAdapter.OnItemClickListener itemClickListener;
|
||||
private static AQuery query;
|
||||
private static Menu mainMenu;
|
||||
private List<NewMenuItem> menuItems;
|
||||
private TimelineImpl timelineImpl;
|
||||
private BottomNavigationView bottomNav;
|
||||
private TextView counter;
|
||||
private CircleImageView profilePic;
|
||||
private RecyclerView recyclerView;
|
||||
private NewMainMenuAdapter.OnItemClickListener onItemClickListener = new NewMainMenuAdapter.OnItemClickListener() {
|
||||
@Override
|
||||
public NewMenuItem OnItemClick(NewMenuItem menuItem, int position) {
|
||||
switch (menuItem.getName()) {
|
||||
case "Tasklist":
|
||||
|
||||
break;
|
||||
case "Timeline":
|
||||
Fragment fragment = new NewTimelineFragment();
|
||||
FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
|
||||
transaction.replace(R.id.content_frame, fragment);
|
||||
transaction.commit();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return menuItem;
|
||||
}
|
||||
};
|
||||
private View accountlayout;
|
||||
private int syncMenuPosition;
|
||||
|
||||
public NewMenuFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @return A new instance of fragment NewMenuFragment.
|
||||
*/
|
||||
public static NewMenuFragment newInstance(NewMainMenuAdapter.OnItemClickListener onItemClickListener) {
|
||||
NewMenuFragment fragment = new NewMenuFragment();
|
||||
|
||||
itemClickListener = onItemClickListener;
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
|
||||
if (null != getActivity().findViewById(R.id.mnGPS))
|
||||
getActivity().findViewById(R.id.mnGPS).clearAnimation();
|
||||
|
||||
mainMenu = menu;
|
||||
|
||||
List<String> listMenu = getMatchToolbarMenu();
|
||||
boolean isHaveChangePass = false;
|
||||
boolean isHaveSettings = false;
|
||||
|
||||
// olivia : set tampilan toolbar untuk masing" density
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
||||
if(displayMetrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM || displayMetrics.densityDpi == DisplayMetrics.DENSITY_HIGH){
|
||||
for (int i = 0; i < listMenu.size(); i++) {
|
||||
if (listMenu.get(i).equalsIgnoreCase(getString(R.string.title_mn_changepassword)))
|
||||
isHaveChangePass = true;
|
||||
else if (listMenu.get(i).equalsIgnoreCase(getString(R.string.title_mn_setting)))
|
||||
isHaveSettings = true;
|
||||
}
|
||||
if (isHaveChangePass || isHaveSettings)
|
||||
menu.findItem(R.id.more).setVisible(true);
|
||||
}else{
|
||||
for (int i = 0; i < listMenu.size(); i++) {
|
||||
if (listMenu.get(i).equalsIgnoreCase(getString(R.string.title_mn_changepassword)))
|
||||
menu.findItem(R.id.mnChangePassword).setVisible(true);
|
||||
else if (listMenu.get(i).equalsIgnoreCase(getString(R.string.title_mn_setting)))
|
||||
menu.findItem(R.id.mnSetting).setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
|
||||
List<String> listMenu = getServerMenuTitle();
|
||||
|
||||
// olivia : set tampilan toolbar untuk masing" density
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
||||
switch (displayMetrics.densityDpi) {
|
||||
case DisplayMetrics.DENSITY_MEDIUM:
|
||||
if (!Global.isMenuMoreClicked) {
|
||||
if (id == R.id.more) {
|
||||
for (int i = 0; i < listMenu.size(); i++) {
|
||||
if (listMenu.get(i).equalsIgnoreCase(getString(R.string.mn_changepassword)))
|
||||
mainMenu.findItem(R.id.moreChangePassword).setVisible(true);
|
||||
else if (listMenu.get(i).equalsIgnoreCase(getString(R.string.mn_setting)))
|
||||
mainMenu.findItem(R.id.moreSetting).setVisible(true);
|
||||
}
|
||||
Global.isMenuMoreClicked = false;
|
||||
}
|
||||
if (id == R.id.moreChangePassword) {
|
||||
ChangePasswordDialog fragment = new ChangePasswordDialog();
|
||||
fragment.show(fragmentManager, "Change Password");
|
||||
Global.isMenuMoreClicked = true;
|
||||
} else if (id == R.id.moreSetting) {
|
||||
Global.isMenuMoreClicked = true;
|
||||
getActivity().setTitle(getString(R.string.mn_setting));
|
||||
Fragment fragment = new SettingFragment();
|
||||
FragmentTransaction transaction = NewMainActivity.fragmentManager.beginTransaction();
|
||||
transaction.setCustomAnimations(R.anim.slide_up, 0, R.anim.slide_up, 0);
|
||||
transaction.replace(R.id.content_frame, fragment);
|
||||
transaction.addToBackStack(null);
|
||||
transaction.commit();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DisplayMetrics.DENSITY_HIGH:
|
||||
if (!Global.isMenuMoreClicked) {
|
||||
if (id == R.id.more) {
|
||||
for (int i = 0; i < listMenu.size(); i++) {
|
||||
|
||||
if (listMenu.get(i).equalsIgnoreCase(getString(R.string.mn_changepassword))) {
|
||||
//resize icon agar rapi
|
||||
Drawable icon = mainMenu.findItem(R.id.moreChangePassword).getIcon();
|
||||
Bitmap resizedIconBitmap = Utils.getResizedBitmap(((BitmapDrawable) icon).getBitmap(),50,50);
|
||||
Drawable resizedIcon = new BitmapDrawable(getResources(),resizedIconBitmap);
|
||||
|
||||
mainMenu.findItem(R.id.moreChangePassword).setIcon(resizedIcon);
|
||||
mainMenu.findItem(R.id.moreChangePassword).setVisible(true);
|
||||
}
|
||||
else if (listMenu.get(i).equalsIgnoreCase(getString(R.string.mn_setting))) {
|
||||
//resize icon agar rapi
|
||||
Drawable icon = mainMenu.findItem(R.id.moreSetting).getIcon();
|
||||
Bitmap resizedIconBitmap = Utils.getResizedBitmap(((BitmapDrawable) icon).getBitmap(),45,45);
|
||||
Drawable resizedIcon = new BitmapDrawable(getResources(),resizedIconBitmap);
|
||||
|
||||
mainMenu.findItem(R.id.moreSetting).setIcon(resizedIcon);
|
||||
mainMenu.findItem(R.id.moreSetting).setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (id == R.id.moreChangePassword) {
|
||||
ChangePasswordDialog fragment = new ChangePasswordDialog();
|
||||
fragment.show(fragmentManager, "Change Password");
|
||||
Global.isMenuMoreClicked = true;
|
||||
} else if (id == R.id.moreSetting) {
|
||||
getActivity().setTitle(getString(R.string.mn_setting));
|
||||
Fragment fragment = new SettingFragment();
|
||||
FragmentTransaction transaction = NewMainActivity.fragmentManager.beginTransaction();
|
||||
transaction.setCustomAnimations(R.anim.slide_up, 0, R.anim.slide_up, 0);
|
||||
transaction.replace(R.id.content_frame, fragment);
|
||||
transaction.addToBackStack(null);
|
||||
transaction.commit();
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (id == R.id.mnSetting) {
|
||||
getActivity().setTitle(getString(R.string.mn_setting));
|
||||
Fragment fragment = new SettingFragment();
|
||||
FragmentTransaction transaction = NewMainActivity.fragmentManager.beginTransaction();
|
||||
transaction.setCustomAnimations(R.anim.slide_up, 0, R.anim.slide_up, 0);
|
||||
transaction.replace(R.id.content_frame, fragment);
|
||||
transaction.addToBackStack(null);
|
||||
transaction.commit();
|
||||
} else if (id == R.id.mnChangePassword) {
|
||||
ChangePasswordDialog fragment = new ChangePasswordDialog();
|
||||
fragment.show(fragmentManager, "Change Password");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(id == R.id.mnGuide && !Global.BACKPRESS_RESTRICTION){
|
||||
Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UserHelp.showAllUserHelpWithRecycler(NewMenuFragment.this.getActivity(),
|
||||
NewMenuFragment.this.getClass().getSimpleName(),
|
||||
recyclerView,
|
||||
syncMenuPosition);
|
||||
}
|
||||
}, SHOW_USERHELP_DELAY_DEFAULT);
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
menuItems = getMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
final View view = inflater.inflate(R.layout.new_fragment_menu, container, false);
|
||||
|
||||
getActivity().findViewById(R.id.search).setVisibility(View.GONE);
|
||||
getActivity().findViewById(R.id.spinner).setVisibility(View.GONE);
|
||||
getActivity().setTitle("MENU");
|
||||
|
||||
bottomNav = (BottomNavigationView) getActivity().findViewById(R.id.bottomNav);
|
||||
counter = (TextView) getActivity().findViewById(R.id.counter);
|
||||
|
||||
profilePic = (CircleImageView) view.findViewById(R.id.imageProfile);
|
||||
|
||||
String application = GlobalData.getSharedGlobalData().getAuditData().getApplication();
|
||||
|
||||
profilePic.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
changeProfile(view);
|
||||
}
|
||||
});
|
||||
|
||||
query = new AQuery(view);
|
||||
|
||||
String temp_uuid_user;
|
||||
try {
|
||||
temp_uuid_user = GlobalData.getSharedGlobalData().getUser().getUuid_user();
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
ACRA.getErrorReporter().putCustomData("errorGetUUIDUser", e.getMessage());
|
||||
ACRA.getErrorReporter().putCustomData("errorGetUUIDUser", DateFormat.format("yyyy.MM.dd G \'at\' HH:mm:ss z", Calendar.getInstance().getTime()).toString());
|
||||
ACRA.getErrorReporter().handleSilentException(new Exception("Exception saat get UUID User"));
|
||||
NewMainActivity.InitializeGlobalDataIfError(getActivity().getApplicationContext());
|
||||
try {
|
||||
temp_uuid_user = GlobalData.getSharedGlobalData().getUser().getUuid_user();
|
||||
} catch (Exception e2) {
|
||||
ACRA.getErrorReporter().putCustomData("errorGetUUIDUser", e.getMessage());
|
||||
ACRA.getErrorReporter().putCustomData("errorGetUUIDUser", DateFormat.format("yyyy.MM.dd G \'at\' HH:mm:ss z", Calendar.getInstance().getTime()).toString());
|
||||
ACRA.getErrorReporter().handleSilentException(new Exception("Exception saat get UUID User"));
|
||||
ObscuredSharedPreferences sharedPref = ObscuredSharedPreferences.getPrefs(getActivity(),
|
||||
"GlobalData", Context.MODE_PRIVATE);
|
||||
temp_uuid_user = sharedPref.getString("UUID_USER", "");
|
||||
}
|
||||
}
|
||||
User user = UserDataAccess.getOne(view.getContext(), temp_uuid_user);
|
||||
if (user == null) {
|
||||
String message = getActivity().getString(R.string.data_corrupt);
|
||||
DialogManager.showForceExitAlert(getActivity(), message);
|
||||
return view;
|
||||
}
|
||||
query.id(R.id.txtName).text(user.getFullname());
|
||||
query.id(R.id.txtJob).text(user.getJob_description());
|
||||
|
||||
setCashOnHandUI();
|
||||
|
||||
if (application == null)
|
||||
application = GlobalData.getSharedGlobalData().getApplication();
|
||||
if (Global.APPLICATION_ORDER.equalsIgnoreCase(application)) {
|
||||
if (user.getIs_branch() == null) {
|
||||
query.id(R.id.txtDealer).text(user.getDealer_name());
|
||||
} else {
|
||||
if (user.getIs_branch().equals("0")) {
|
||||
query.id(R.id.txtDealer).text(user.getDealer_name());
|
||||
} else {
|
||||
query.id(R.id.txtDealer).text(user.getBranch_name());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
query.id(R.id.txtDealer).text(user.getBranch_name());
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
accountlayout = view.findViewById(R.id.account);
|
||||
RecyclerView mainMenu = (RecyclerView) view.findViewById(R.id.menuRecycle);
|
||||
recyclerView = mainMenu;
|
||||
GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), 3);
|
||||
mainMenu.setHasFixedSize(true);
|
||||
mainMenu.setLayoutManager(layoutManager);
|
||||
|
||||
adapter = new NewMainMenuAdapter(view.getContext(), menuItems, itemClickListener);
|
||||
mainMenu.setAdapter(adapter);
|
||||
loadColorSet();
|
||||
|
||||
Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UserHelp.showAllUserHelpWithRecycler(NewMenuFragment.this.getActivity(),
|
||||
NewMenuFragment.this.getClass().getSimpleName(),
|
||||
recyclerView,
|
||||
syncMenuPosition);
|
||||
}
|
||||
}, SHOW_USERHELP_DELAY_DEFAULT);
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return UserDataAccess.getOne(getContext(), GlobalData.getSharedGlobalData().getUser().getUuid_user());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
Global.isMenuMoreClicked = false;
|
||||
|
||||
try {
|
||||
if (mnTaskList != null)
|
||||
mnTaskList.setCounter(String.valueOf(ToDoList.getCounterTaskList(getContext())));
|
||||
if (mnSurveyAssign != null)
|
||||
mnSurveyAssign.setCounter(String.valueOf(GlobalData.getSharedGlobalData().getCounterAssignment()));
|
||||
if (mnSurveyVerif != null)
|
||||
mnSurveyVerif.setCounter(String.valueOf(ToDoList.getCounterVerificationTask(getContext())));
|
||||
if (mnSurveyApproval != null)
|
||||
mnSurveyApproval.setCounter(String.valueOf(ToDoList.getCounterApprovalTask(getContext())));
|
||||
if (mnVerifByBranch != null)
|
||||
mnVerifByBranch.setCounter(String.valueOf(ToDoList.getCounterVerificationTaskByBranch(getContext())));
|
||||
if (mnApprovalByBranch != null)
|
||||
mnApprovalByBranch.setCounter(String.valueOf(ToDoList.getCounterApprovalTaskByBranch(getContext())));
|
||||
counter.setText(String.valueOf(ToDoList.getCounterTaskList(getContext())));
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.getMessage();
|
||||
}
|
||||
|
||||
bottomNav.getMenu().findItem(R.id.menuNav).setEnabled(false);
|
||||
|
||||
getActivity().findViewById(R.id.search).setVisibility(View.GONE);
|
||||
getActivity().findViewById(R.id.spinner).setVisibility(View.GONE);
|
||||
getActivity().setTitle("MENU");
|
||||
|
||||
timelineImpl.refreshImageBitmap(R.id.imageProfile, R.drawable.profile_pic, getUser().getImage_profile())
|
||||
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
setCashOnHandUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
query.id(R.id.imageProfile).recycle(getView());
|
||||
bottomNav.getMenu().findItem(R.id.menuNav).setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
try {
|
||||
query.id(R.id.imageProfile).recycle(getView());
|
||||
} catch (NullPointerException e) {
|
||||
ACRA.getErrorReporter().putCustomData("errorOnDestroy", e.getMessage());
|
||||
ACRA.getErrorReporter().putCustomData("errorOnDestroy", DateFormat.format("yyyy.MM.dd G \'at\' HH:mm:ss z", Calendar.getInstance().getTime()).toString());
|
||||
ACRA.getErrorReporter().handleSilentException(new Exception("Exception saat recycle view"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
query.id(R.id.imageProfile).recycle(getView());
|
||||
bottomNav.getMenu().findItem(R.id.menuNav).setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context activity) {
|
||||
super.onAttach(activity);
|
||||
setHasOptionsMenu(true);
|
||||
ACRA.getErrorReporter().putCustomData("LAST_CLASS_ACCESSED", getClass().getSimpleName());
|
||||
|
||||
timelineImpl = new TimelineImpl(getActivity(), this);
|
||||
timelineImpl.setContext(activity);
|
||||
}
|
||||
|
||||
public ArrayList<String> getTemplateToolbarMenu() {
|
||||
ArrayList<String> templateMenuTitle = new ArrayList<>();
|
||||
templateMenuTitle.add(getString(R.string.mn_changepassword));
|
||||
templateMenuTitle.add(getString(R.string.mn_setting));
|
||||
return templateMenuTitle;
|
||||
}
|
||||
|
||||
public List<String> getToolbarMenu() {
|
||||
if (GlobalData.getSharedGlobalData().getUser() == null) {
|
||||
NewMainActivity.InitializeGlobalDataIfError(getActivity());
|
||||
}
|
||||
List<String> menu = MainMenuHelper.matchingMenu(getServerMenuTitle(), getTemplateToolbarMenu());
|
||||
return menu;
|
||||
}
|
||||
|
||||
public List<String> getMatchToolbarMenu() {
|
||||
List<String> newMenu = new ArrayList<>();
|
||||
List<String> oldMenu = getToolbarMenu();
|
||||
|
||||
for (int i = 0; i < oldMenu.size(); i++) {
|
||||
if (oldMenu.get(i).equals(getString(R.string.mn_changepassword)))
|
||||
newMenu.add(getString(R.string.title_mn_changepassword));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_setting)))
|
||||
newMenu.add(getString(R.string.title_mn_setting));
|
||||
}
|
||||
return newMenu;
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> getTemplateIcon() {
|
||||
HashMap<String, Integer> templateIcon = new HashMap<>();
|
||||
templateIcon.put(getString(R.string.mn_newtask), R.drawable.menu_newtask);
|
||||
templateIcon.put(getString(R.string.mn_tasklist), R.drawable.menu_tasklist);
|
||||
templateIcon.put(getString(R.string.mn_log), R.drawable.menu_log);
|
||||
templateIcon.put(getString(R.string.mn_absentin), R.drawable.menu_attendance);
|
||||
templateIcon.put(getString(R.string.mn_synchronize), R.drawable.menu_synchronize);
|
||||
templateIcon.put(getString(R.string.mn_exit), R.drawable.menu_exit);
|
||||
templateIcon.put(getString(R.string.mn_about), R.drawable.menu_about);
|
||||
templateIcon.put(getString(R.string.mn_surveyperformance), R.drawable.menu_surveyperformance);
|
||||
templateIcon.put(getString(R.string.mn_reportsummary), R.drawable.menu_surveyperformance);
|
||||
templateIcon.put(getString(R.string.mn_depositreport), R.drawable.menu_deposit);
|
||||
templateIcon.put(getString(R.string.mn_depositreport_ac), R.drawable.menu_deposit);
|
||||
templateIcon.put(getString(R.string.mn_depositreport_pc), R.drawable.menu_deposit);
|
||||
templateIcon.put(getString(R.string.mn_closing_task), R.drawable.menu_closingtask);
|
||||
templateIcon.put(getString(R.string.mn_surveyassign), R.drawable.menu_surveyassignment);
|
||||
templateIcon.put(getString(R.string.mn_surveyreassign), R.drawable.menu_surveyreassignment);
|
||||
templateIcon.put(getString(R.string.mn_surveyverification), R.drawable.menu_surveyverification);
|
||||
templateIcon.put(getString(R.string.mn_surveyapproval), R.drawable.menu_surveyapproval);
|
||||
templateIcon.put(getString(R.string.mn_verification_bybranch), R.drawable.menu_surveyverification);
|
||||
templateIcon.put(getString(R.string.mn_approval_bybranch), R.drawable.menu_surveyapproval);
|
||||
templateIcon.put(getString(R.string.mn_checkorder), R.drawable.menu_checkorder);
|
||||
templateIcon.put(getString(R.string.mn_cancelorder), R.drawable.menu_cancelorder);
|
||||
templateIcon.put(getString(R.string.mn_promo), R.drawable.menu_promotion);
|
||||
templateIcon.put(getString(R.string.mn_orderassign), R.drawable.menu_surveyassignment);
|
||||
templateIcon.put(getString(R.string.mn_orderreassign), R.drawable.menu_surveyreassignment);
|
||||
templateIcon.put(getString(R.string.mn_neworder), R.drawable.menu_newtask);
|
||||
templateIcon.put(getString(R.string.mn_dashboard), R.drawable.icon_coin);
|
||||
templateIcon.put(getString(R.string.mn_dashboard_collection),R.drawable.ic_dashboard_coll);
|
||||
templateIcon.put(getString(R.string.mn_guideline_faq), R.drawable.menu_guideline_faq);
|
||||
|
||||
|
||||
return templateIcon;
|
||||
}
|
||||
|
||||
public ArrayList<String> getTemplateMenuTitle() {
|
||||
ArrayList<String> templateMenuTitle = new ArrayList<>();
|
||||
templateMenuTitle.add(getString(R.string.mn_newtask));
|
||||
templateMenuTitle.add(getString(R.string.mn_newlead));
|
||||
templateMenuTitle.add(getString(R.string.mn_account));
|
||||
templateMenuTitle.add(getString(R.string.mn_products));
|
||||
templateMenuTitle.add(getString(R.string.mn_opportunities));
|
||||
templateMenuTitle.add(getString(R.string.mn_followup));
|
||||
templateMenuTitle.add(getString(R.string.mn_catalogue));
|
||||
templateMenuTitle.add(getString(R.string.mn_marketingreport));
|
||||
templateMenuTitle.add(getString(R.string.mn_neworder));
|
||||
templateMenuTitle.add(getString(R.string.mn_tasklist));
|
||||
templateMenuTitle.add(getString(R.string.mn_taskApproval));
|
||||
templateMenuTitle.add(getString(R.string.mn_log));
|
||||
templateMenuTitle.add(getString(R.string.mn_checkorder));
|
||||
templateMenuTitle.add(getString(R.string.mn_cancelorder));
|
||||
templateMenuTitle.add(getString(R.string.mn_orderassign));
|
||||
templateMenuTitle.add(getString(R.string.mn_orderreassign));
|
||||
templateMenuTitle.add(getString(R.string.mn_promo));
|
||||
templateMenuTitle.add(getString(R.string.mn_surveyassign));
|
||||
templateMenuTitle.add(getString(R.string.mn_surveyreassign));
|
||||
templateMenuTitle.add(getString(R.string.mn_surveyverification));
|
||||
templateMenuTitle.add(getString(R.string.mn_surveyapproval));
|
||||
templateMenuTitle.add(getString(R.string.mn_verification_bybranch));
|
||||
templateMenuTitle.add(getString(R.string.mn_approval_bybranch));
|
||||
templateMenuTitle.add(getString(R.string.mn_surveyperformance));
|
||||
templateMenuTitle.add(getString(R.string.mn_closing_task));
|
||||
templateMenuTitle.add(getString(R.string.mn_depositreport));
|
||||
templateMenuTitle.add(getString(R.string.mn_depositreport_ac));
|
||||
templateMenuTitle.add(getString(R.string.mn_depositreport_pc));
|
||||
templateMenuTitle.add(getString(R.string.mn_reportsummary));
|
||||
templateMenuTitle.add(getString(R.string.mn_absentin));
|
||||
templateMenuTitle.add(getString(R.string.mn_dashboard));
|
||||
templateMenuTitle.add(getString(R.string.mn_dashboard_collection));
|
||||
templateMenuTitle.add(getString(R.string.mn_synchronize));
|
||||
templateMenuTitle.add(getString(R.string.mn_about));
|
||||
templateMenuTitle.add(getString(R.string.mn_guideline_faq));
|
||||
templateMenuTitle.add(getString(R.string.mn_exit));
|
||||
|
||||
return templateMenuTitle;
|
||||
}
|
||||
|
||||
public ArrayList<String> getServerMenuTitle() {
|
||||
ArrayList<String> serverMenuTitle = new ArrayList<>();
|
||||
try {
|
||||
List<com.adins.mss.dao.Menu> menu = MenuDataAccess.getAll(getActivity(), GlobalData.getSharedGlobalData().getUser().getUuid_user());
|
||||
|
||||
for (com.adins.mss.dao.Menu menu2 : menu) {
|
||||
serverMenuTitle.add(menu2.getUuid_menu());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
|
||||
}
|
||||
return serverMenuTitle;
|
||||
}
|
||||
|
||||
public List<String> getMainMenuTitle() {
|
||||
if (GlobalData.getSharedGlobalData().getUser() == null) {
|
||||
NewMainActivity.InitializeGlobalDataIfError(getActivity());
|
||||
}
|
||||
return MainMenuHelper.matchingMenu(getServerMenuTitle(), getTemplateMenuTitle());
|
||||
}
|
||||
|
||||
public List<Integer> getMainMenuIcon() {
|
||||
return MainMenuHelper.matchingIcon(getMainMenuTitle(), getTemplateIcon());
|
||||
}
|
||||
|
||||
// olivia : update bahasa indonesia untuk menu
|
||||
public List<String> getMatchMenuLanguage() {
|
||||
List<String> newMenu = new ArrayList<>();
|
||||
List<String> oldMenu = getMainMenuTitle();
|
||||
|
||||
for (int i = 0; i < oldMenu.size(); i++) {
|
||||
if (oldMenu.get(i).equals(getString(R.string.mn_newtask)))
|
||||
newMenu.add(getString(R.string.title_mn_newtask));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_tasklist)))
|
||||
newMenu.add(getString(R.string.title_mn_tasklist));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_log)))
|
||||
newMenu.add(getString(R.string.title_mn_log));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_checkorder)))
|
||||
newMenu.add(getString(R.string.title_mn_checkorder));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_cancelorder)))
|
||||
newMenu.add(getString(R.string.title_mn_cancelorder));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_orderassign)))
|
||||
newMenu.add(getString(R.string.title_mn_orderassign));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_orderreassign)))
|
||||
newMenu.add(getString(R.string.title_mn_orderreassign));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_promo)))
|
||||
newMenu.add(getString(R.string.title_mn_promo));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_surveyassign)))
|
||||
newMenu.add(getString(R.string.title_mn_surveyassign));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_surveyreassign)))
|
||||
newMenu.add(getString(R.string.title_mn_surveyreassign));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_surveyverification)))
|
||||
newMenu.add(getString(R.string.title_mn_surveyverification));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_surveyapproval)))
|
||||
newMenu.add(getString(R.string.title_mn_surveyapproval));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_verification_bybranch)))
|
||||
newMenu.add(getString(R.string.title_mn_verification_bybranch));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_approval_bybranch)))
|
||||
newMenu.add(getString(R.string.title_mn_approval_bybranch));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_closing_task)))
|
||||
newMenu.add(getString(R.string.title_mn_closing_task));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_depositreport)))
|
||||
newMenu.add(getString(R.string.title_mn_depositreport));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_reportsummary)))
|
||||
newMenu.add(getString(R.string.title_mn_reportsummary));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_surveyperformance)))
|
||||
newMenu.add(getString(R.string.title_mn_surveyperformance));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_absentin)))
|
||||
newMenu.add(getString(R.string.title_mn_absentin));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_synchronize)))
|
||||
newMenu.add(getString(R.string.title_mn_synchronize));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_about)))
|
||||
newMenu.add(getString(R.string.title_mn_about));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_exit)))
|
||||
newMenu.add(getString(R.string.title_mn_exit));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_account)))
|
||||
newMenu.add(getString(R.string.title_mn_account));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_catalogue)))
|
||||
newMenu.add(getString(R.string.title_mn_catalogue));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_newlead)))
|
||||
newMenu.add(getString(R.string.title_mn_newlead));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_products)))
|
||||
newMenu.add(getString(R.string.title_mn_products));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_opportunities)))
|
||||
newMenu.add(getString(R.string.title_mn_opportunities));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_followup)))
|
||||
newMenu.add(getString(R.string.title_mn_followup));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_marketingreport)))
|
||||
newMenu.add(getString(R.string.title_mn_marketingreport));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_neworder)))
|
||||
newMenu.add(getString(R.string.title_mn_neworder));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_dashboard)))
|
||||
newMenu.add(getString(R.string.title_mn_dashboard));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_dashboard_collection)))
|
||||
newMenu.add(getString(R.string.title_mn_dashboard_collection));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_depositreport_ac)))
|
||||
newMenu.add(getString(R.string.title_mn_depositreportAC));
|
||||
else if (oldMenu.get(i).equals(getString(R.string.mn_depositreport_pc)))
|
||||
newMenu.add(getString(R.string.title_mn_depositreportPC));
|
||||
else if(oldMenu.get(i).equals(getString(R.string.mn_guideline_faq)))
|
||||
newMenu.add(getString(R.string.title_mn_guideline_faq));
|
||||
}
|
||||
return newMenu;
|
||||
}
|
||||
|
||||
private List<NewMenuItem> getMenu() {
|
||||
List<NewMenuItem> menuItems = new ArrayList<>();
|
||||
|
||||
List<String> menuTitle = getMatchMenuLanguage();
|
||||
List<Integer> menuIcon = getMainMenuIcon();
|
||||
|
||||
for (int i = 0; i < menuTitle.size(); i++) {
|
||||
if (menuTitle.get(i).equalsIgnoreCase(getString(R.string.title_mn_tasklist))) {
|
||||
mnTaskList = new NewMenuItem(menuTitle.get(i), menuIcon.get(i), "0");
|
||||
menuItems.add(mnTaskList);
|
||||
} else if (menuTitle.get(i).equalsIgnoreCase(getString(R.string.title_mn_surveyassign))) {
|
||||
mnSurveyAssign = new NewMenuItem(menuTitle.get(i), menuIcon.get(i), "0");
|
||||
menuItems.add(mnSurveyAssign);
|
||||
} else if (menuTitle.get(i).equalsIgnoreCase(getString(R.string.title_mn_surveyverification))) {
|
||||
mnSurveyVerif = new NewMenuItem(menuTitle.get(i), menuIcon.get(i), "0");
|
||||
menuItems.add(mnSurveyVerif);
|
||||
} else if (menuTitle.get(i).equalsIgnoreCase(getString(R.string.title_mn_surveyapproval))) {
|
||||
mnSurveyApproval = new NewMenuItem(menuTitle.get(i), menuIcon.get(i), "0");
|
||||
menuItems.add(mnSurveyApproval);
|
||||
} else if (menuTitle.get(i).equalsIgnoreCase(getString(R.string.title_mn_verification_bybranch))) {
|
||||
mnVerifByBranch = new NewMenuItem(menuTitle.get(i), menuIcon.get(i), "0");
|
||||
menuItems.add(mnVerifByBranch);
|
||||
} else if (menuTitle.get(i).equalsIgnoreCase(getString(R.string.title_mn_approval_bybranch))) {
|
||||
mnApprovalByBranch = new NewMenuItem(menuTitle.get(i), menuIcon.get(i), "0");
|
||||
menuItems.add(mnApprovalByBranch);
|
||||
} else
|
||||
menuItems.add(new NewMenuItem(menuTitle.get(i), menuIcon.get(i), null));
|
||||
|
||||
if(menuTitle.get(i).equalsIgnoreCase(getString(R.string.title_mn_synchronize))){
|
||||
syncMenuPosition = i;
|
||||
}
|
||||
}
|
||||
return menuItems;
|
||||
}
|
||||
|
||||
public void changeProfile(View view) {
|
||||
final NiftyDialogBuilder_PL dialogBuilder = NiftyDialogBuilder_PL.getInstance(getContext());
|
||||
dialogBuilder.withTitle(getString(com.adins.mss.base.R.string.profile__title)).withNoMessage()
|
||||
.withButton1Text(getString(com.adins.mss.base.R.string.btn_camera)).setButton1Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Constants.flag_edit = 1;
|
||||
dialogBuilder.dismiss();
|
||||
final Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
|
||||
File file = new File(getContext().getExternalFilesDir(null) + File.separator + "imgProfile.jpg");
|
||||
|
||||
// olivia : untuk sdk >= 24 harus pakai FileProvider
|
||||
Uri uri;
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
uri = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", file);
|
||||
} else
|
||||
uri = Uri.fromFile(file);
|
||||
|
||||
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
startActivityForResult(intent, Utils.REQUEST_CAMERA);
|
||||
}
|
||||
|
||||
}, 100);
|
||||
}
|
||||
})
|
||||
.withButton2Text(getString(com.adins.mss.base.R.string.btn_galery)).setButton2Click(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Constants.flag_edit = 1;
|
||||
dialogBuilder.dismiss();
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Crop.pickImage(getContext(), NewMenuFragment.this);
|
||||
}
|
||||
|
||||
}, 100);
|
||||
}
|
||||
}).isCancelable(false).isCancelableOnTouchOutside(true).show();
|
||||
}
|
||||
|
||||
private void setCashOnHandUI() {
|
||||
if (GlobalData.getSharedGlobalData().getApplication().equals(Global.APPLICATION_COLLECTION)) {
|
||||
|
||||
String cashLimit = GlobalData.getSharedGlobalData().getUser().getCash_limit();
|
||||
if(cashLimit == null || cashLimit.equalsIgnoreCase("null")){
|
||||
cashLimit = "0";
|
||||
}
|
||||
double limit = Double.parseDouble(cashLimit);
|
||||
|
||||
String cashOnHand = GlobalData.getSharedGlobalData().getUser().getCash_on_hand();
|
||||
if(cashOnHand == null || cashOnHand.equalsIgnoreCase("null")){
|
||||
cashOnHand = "0";
|
||||
}
|
||||
double coh = Double.parseDouble(cashOnHand);
|
||||
|
||||
String setLimit = Tool.separateThousand(limit);
|
||||
String setCOH = Tool.separateThousand(coh);
|
||||
|
||||
if (limit > 0 && isCOHAktif()) {
|
||||
query.id(R.id.txtCurrentCOH).visibility(View.VISIBLE);
|
||||
query.id(R.id.txtLimitCOH).visibility(View.VISIBLE);
|
||||
query.id(R.id.txtCurrentCOH).text(setCOH);
|
||||
query.id(R.id.txtLimitCOH).text(setLimit);
|
||||
} else {
|
||||
query.id(R.id.txtCurrentCOH).visibility(View.VISIBLE);
|
||||
query.id(R.id.txtCurrentCOH).text(setCOH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCOHAktif() {
|
||||
String parameter = GeneralParameterDataAccess.getOne(getActivity(), GlobalData.getSharedGlobalData().getUser().getUuid_user(),
|
||||
Global.GS_CASHONHAND).getGs_value();
|
||||
return parameter != null && parameter.equals(Global.TRUE_STRING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent result) {
|
||||
super.onActivityResult(requestCode, resultCode, result);
|
||||
Utility.freeMemory();
|
||||
if (requestCode == Crop.REQUEST_PICK && resultCode == Activity.RESULT_OK) {
|
||||
Intent intent = new Intent(getActivity(), CroppingImageActivity.class);
|
||||
intent.putExtra(CroppingImageActivity.BUND_KEY_ABSOLUTEPATH, result.getData().toString());
|
||||
startActivity(intent);
|
||||
} else if (requestCode == Utils.REQUEST_CAMERA && resultCode == Activity.RESULT_OK) {
|
||||
File file = new File(getContext().getExternalFilesDir(null) + File.separator + "imgProfile.jpg");
|
||||
Uri outputUri = Uri.fromFile(file);
|
||||
Intent intent = new Intent(getActivity(), CroppingImageActivity.class);
|
||||
intent.putExtra(CroppingImageActivity.BUND_KEY_ABSOLUTEPATH, outputUri.toString());
|
||||
startActivity(intent);
|
||||
}
|
||||
Utility.freeMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccessBackgroundTask(List<Timeline> timelines) {
|
||||
//EMPTY
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccessImageBitmap(Bitmap bitmap, int imageView, int defaultImage) {
|
||||
if (bitmap != null) query.id(imageView).image(bitmap);
|
||||
else query.id(imageView).image(defaultImage);
|
||||
}
|
||||
|
||||
private void applyColorTheme(DynamicTheme colorSet){
|
||||
int accountBgColor = Color.parseColor(ThemeUtility.getColorItemValue(colorSet,"bg_solid"));
|
||||
ThemeUtility.setViewBackground(accountlayout,accountBgColor);
|
||||
}
|
||||
|
||||
private void loadColorSet(){
|
||||
ThemeLoader themeLoader = new ThemeLoader(this.getContext());
|
||||
themeLoader.loadSavedColorSet(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHasLoaded(DynamicTheme dynamicTheme) {
|
||||
if(dynamicTheme != null){
|
||||
applyColorTheme(dynamicTheme);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHasLoaded(DynamicTheme dynamicTheme, boolean needUpdate) {
|
||||
//EMPTY
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
|
@ -0,0 +1,157 @@
|
|||
/*
|
||||
* Copyright 2010 Kevin Gaudin
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.acra.collector;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.provider.Settings.System;
|
||||
|
||||
import org.acra.ACRA;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.acra.ACRA.LOG_TAG;
|
||||
|
||||
/**
|
||||
* Helper to collect data from {@link System} and {@link Secure} Settings
|
||||
* classes.
|
||||
*
|
||||
* @author Kevin Gaudin
|
||||
*/
|
||||
final class SettingsCollector {
|
||||
|
||||
/**
|
||||
* Collect data from {@link android.provider.Settings.System}. This
|
||||
* collector uses reflection to be sure to always get the most accurate data
|
||||
* whatever Android API level it runs on.
|
||||
*
|
||||
* @param ctx Application context.
|
||||
* @return A human readable String containing one key=value pair per line.
|
||||
*/
|
||||
public static String collectSystemSettings(Context ctx) {
|
||||
final StringBuilder result = new StringBuilder();
|
||||
final Field[] keys = Settings.System.class.getFields();
|
||||
for (final Field key : keys) {
|
||||
// Avoid retrieving deprecated fields... it is useless, has an
|
||||
// impact on perfs, and the system writes many warnings in the
|
||||
// logcat.
|
||||
if (!key.isAnnotationPresent(Deprecated.class) && key.getType() == String.class) {
|
||||
try {
|
||||
final Object value = Settings.System.getString(ctx.getContentResolver(), (String) key.get(null));
|
||||
if (value != null) {
|
||||
result.append(key.getName()).append("=").append(value).append("\n");
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
ACRA.log.w(LOG_TAG, "Error : ", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
ACRA.log.w(LOG_TAG, "Error : ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect data from {@link android.provider.Settings.Secure}. This
|
||||
* collector uses reflection to be sure to always get the most accurate data
|
||||
* whatever Android API level it runs on.
|
||||
*
|
||||
* @param ctx Application context.
|
||||
* @return A human readable String containing one key=value pair per line.
|
||||
*/
|
||||
public static String collectSecureSettings(Context ctx) {
|
||||
final StringBuilder result = new StringBuilder();
|
||||
final Field[] keys = Settings.Secure.class.getFields();
|
||||
for (final Field key : keys) {
|
||||
if (!key.isAnnotationPresent(Deprecated.class) && key.getType() == String.class && isAuthorized(key)) {
|
||||
try {
|
||||
final Object value = Settings.Secure.getString(ctx.getContentResolver(), (String) key.get(null));
|
||||
if (value != null) {
|
||||
result.append(key.getName()).append("=").append(value).append("\n");
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
ACRA.log.w(LOG_TAG, "Error : ", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
ACRA.log.w(LOG_TAG, "Error : ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect data from {@link android.provider.Settings.Global}. This
|
||||
* collector uses reflection to be sure to always get the most accurate data
|
||||
* whatever Android API level it runs on.
|
||||
*
|
||||
* @param ctx Application context.
|
||||
* @return A human readable String containing one key=value pair per line.
|
||||
*/
|
||||
public static String collectGlobalSettings(Context ctx) {
|
||||
if (Compatibility.getAPILevel() < 17) {
|
||||
return "";
|
||||
}
|
||||
|
||||
final StringBuilder result = new StringBuilder();
|
||||
try {
|
||||
final Class<?> globalClass = Class.forName("android.provider.Settings$Global");
|
||||
final Field[] keys = globalClass.getFields();
|
||||
final Method getString = globalClass.getMethod("getString", ContentResolver.class, String.class);
|
||||
for (final Field key : keys) {
|
||||
if (!key.isAnnotationPresent(Deprecated.class) && key.getType() == String.class && isAuthorized(key)) {
|
||||
final Object value = getString.invoke(null, ctx.getContentResolver(), (String) key.get(null));
|
||||
if (value != null) {
|
||||
result.append(key.getName()).append("=").append(value).append("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
ACRA.log.w(LOG_TAG, "Error : ", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
ACRA.log.w(LOG_TAG, "Error : ", e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
ACRA.log.w(LOG_TAG, "Error : ", e);
|
||||
} catch (SecurityException e) {
|
||||
ACRA.log.w(LOG_TAG, "Error : ", e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
ACRA.log.w(LOG_TAG, "Error : ", e);
|
||||
} catch (InvocationTargetException e) {
|
||||
ACRA.log.w(LOG_TAG, "Error : ", e);
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private static boolean isAuthorized(Field key) {
|
||||
if (key == null || key.getName().startsWith("WIFI_AP")) {
|
||||
return false;
|
||||
}
|
||||
for (String regex : ACRA.getConfig().excludeMatchingSettingsKeys()) {
|
||||
if (key.getName().matches(regex)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,291 @@
|
|||
package com.adins.mss.coll.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.adins.mss.coll.R;
|
||||
import com.adins.mss.coll.fragments.DashBoardFragment.OnListFragmentInteractionListener;
|
||||
import com.adins.mss.coll.fragments.dummy.DummyContent.DummyItem;
|
||||
import com.adins.mss.coll.fragments.view.GridDashBoardAdapter;
|
||||
import com.adins.mss.foundation.formatter.Tool;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* {@link RecyclerView.Adapter} that can display a {@link DummyItem} and makes a call to the
|
||||
* specified {@link OnListFragmentInteractionListener}.
|
||||
* TODO: Replace the implementation with code for your data type.
|
||||
*/
|
||||
public class MyDashBoardItemRecyclerViewAdapter extends RecyclerView.Adapter<MyDashBoardItemRecyclerViewAdapter.ViewHolder> {
|
||||
|
||||
private final OnListFragmentInteractionListener mListener;
|
||||
private final Context mContext;
|
||||
private DetailKompetisiResponse dataDetailKompetisi;
|
||||
|
||||
|
||||
public MyDashBoardItemRecyclerViewAdapter(OnListFragmentInteractionListener listener, Context context) {
|
||||
mListener = listener;
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public DetailKompetisiResponse getDataDetailKompetisi() {
|
||||
return dataDetailKompetisi;
|
||||
}
|
||||
|
||||
public void setDataDetailKompetisi(DetailKompetisiResponse dataDetailKompetisi) {
|
||||
this.dataDetailKompetisi = dataDetailKompetisi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_dashboard, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final ViewHolder holder, final int position) {
|
||||
holder.mItem = dataDetailKompetisi;
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Date now = calendar.getTime();
|
||||
|
||||
Date mydate = new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24));
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy");
|
||||
String yestr = dateFormat.format(mydate);
|
||||
|
||||
SimpleDateFormat simpleDate = new SimpleDateFormat("dd MMM yyyy");
|
||||
SimpleDateFormat simpleDate1 = new SimpleDateFormat("d");
|
||||
holder.labelPointSaya.setText(mContext.getString(R.string.my_point_competition, yestr));
|
||||
|
||||
DateFormat inputFormatter1 = new SimpleDateFormat("dd-MM-yyyy");
|
||||
Date datetanggal1 = null;
|
||||
try {
|
||||
datetanggal1 = inputFormatter1.parse(dataDetailKompetisi.getResultList().get(position).getMEMBERSHIP_PROGRAM_START_DATE());
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
DateFormat outputFormatter1 = new SimpleDateFormat("MM/dd/yyyy");
|
||||
DateFormat outputFormatter2 = new SimpleDateFormat("dd MMM yyyy");
|
||||
String outputtanggal1 = outputFormatter2.format(datetanggal1); //
|
||||
Date datetanggal2 = null;
|
||||
try {
|
||||
datetanggal2 = inputFormatter1.parse(dataDetailKompetisi.getResultList().get(position).getMEMBERSHIP_PROGRAM_EXPIRED_DATE());
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String outputtanggal2 = outputFormatter2.format(datetanggal2); //
|
||||
|
||||
holder.startDate.setText(outputtanggal1 + " - " + outputtanggal2);
|
||||
holder.competitionName.setText(dataDetailKompetisi.getResultList().get(position).getMEMBERSHIP_PROGRAM_NAME());
|
||||
|
||||
final double d = Double.parseDouble(dataDetailKompetisi.getResultList().get(position).getTEAM_MEMBER().get(0).getPOINT_PERIOD());
|
||||
String pointPeriod = Tool.formatToCurrency(d);
|
||||
holder.totalPoinKompetisi.setText(pointPeriod);
|
||||
|
||||
if (dataDetailKompetisi.getResultList().get(position).getTEAM_MEMBER().get(0).getPOINT_PERIOD().length() > 6) {
|
||||
holder.totalPoinKompetisi.setTextSize(16);
|
||||
} else if (dataDetailKompetisi.getResultList().get(position).getTEAM_MEMBER().get(0).getPOINT_PERIOD().length() > 4) {
|
||||
holder.totalPoinKompetisi.setTextSize(20);
|
||||
} else {
|
||||
holder.totalPoinKompetisi.setTextSize(25);
|
||||
}
|
||||
|
||||
Integer gracepointnow = Integer.parseInt(dataDetailKompetisi.getResultList().get(position).getTEAM_MEMBER().get(0).getPOINT_PERIOD());
|
||||
Integer gracepointbefore = Integer.parseInt(dataDetailKompetisi.getResultList().get(position).getTEAM_MEMBER().get(0).getPOINT_PERIOD_BEFORE());
|
||||
if (gracepointnow < gracepointbefore) {
|
||||
holder.upDownGracePoint.setText("-" + String.valueOf(gracepointbefore - gracepointnow));
|
||||
holder.upDownGracePoint.setTextColor(Color.parseColor("#FF0000"));
|
||||
} else if (gracepointnow > gracepointbefore) {
|
||||
holder.upDownGracePoint.setText("+" + String.valueOf(gracepointnow - gracepointbefore));
|
||||
holder.upDownGracePoint.setTextColor(Color.parseColor("#008000"));
|
||||
} else {
|
||||
holder.upDownGracePoint.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
double dpoinmonth = Double.parseDouble(dataDetailKompetisi.getResultList().get(position).getTEAM_MEMBER().get(0).getPOINT_MONTH());
|
||||
String poinMonth = Tool.formatToCurrency(dpoinmonth);
|
||||
holder.pointMonth.setText(poinMonth);
|
||||
|
||||
Integer pointmonthnow = Integer.parseInt(dataDetailKompetisi.getResultList().get(position).getTEAM_MEMBER().get(0).getPOINT_MONTH());
|
||||
|
||||
Integer pointmonthbefore = Integer.parseInt(dataDetailKompetisi.getResultList().get(position).getTEAM_MEMBER().get(0).getPOINT_MONTH_BEFORE());
|
||||
double dpoinmonthbefore = Double.valueOf(pointmonthbefore);
|
||||
String poinmonthbeforestring = Tool.formatToCurrency(dpoinmonthbefore);
|
||||
|
||||
if (pointmonthnow < pointmonthbefore) {
|
||||
holder.textarrowUpDownMonth.setText(poinmonthbeforestring);
|
||||
holder.arrowUpDownMonth.setImageDrawable(mContext.getResources().getDrawable(R.drawable.arrowdownred));
|
||||
} else if (pointmonthnow > pointmonthbefore) {
|
||||
holder.textarrowUpDownMonth.setText(poinmonthbeforestring);
|
||||
holder.arrowUpDownMonth.setImageDrawable(mContext.getResources().getDrawable(R.drawable.arrowupgreen));
|
||||
} else {
|
||||
holder.textarrowUpDownMonth.setVisibility(View.INVISIBLE);
|
||||
holder.arrowUpDownMonth.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
GetLogoKompetisi getLogoKompetisi = new GetLogoKompetisi(mContext, dataDetailKompetisi.getResultList().get(position).getMEMBERSHIP_PROGRAM_CODE(), holder.logoKompetisi);
|
||||
getLogoKompetisi.execute();
|
||||
|
||||
//DAILY AVERAGE MONTH
|
||||
String totaltanggal = simpleDate1.format(now);
|
||||
Integer tanggalHariIni = Integer.parseInt(totaltanggal);
|
||||
|
||||
Integer kalender8total;
|
||||
if ((tanggalHariIni - 1) == 0) {
|
||||
kalender8total = 0;
|
||||
} else {
|
||||
kalender8total = pointmonthnow / (tanggalHariIni - 1);
|
||||
}
|
||||
|
||||
String poinhari = Tool.formatToCurrency(kalender8total);
|
||||
|
||||
Integer kalender8totalbefore;
|
||||
if ((tanggalHariIni - 1) == 0) {
|
||||
kalender8totalbefore = 0;
|
||||
} else {
|
||||
kalender8totalbefore = pointmonthbefore / (tanggalHariIni - 1);
|
||||
}
|
||||
|
||||
String poin8beforestring = Tool.formatToCurrency(kalender8totalbefore);
|
||||
|
||||
if (kalender8total < kalender8totalbefore) {
|
||||
holder.textratatotalhari.setText(poinhari);
|
||||
holder.textarrowUpDownRata.setText(poin8beforestring);
|
||||
holder.arrowUpDownRata.setImageDrawable(mContext.getResources().getDrawable(R.drawable.arrowdownred));
|
||||
} else if (kalender8total > kalender8totalbefore && kalender8totalbefore >= 0) {
|
||||
holder.textratatotalhari.setText(poinhari);
|
||||
holder.textarrowUpDownRata.setText(poin8beforestring);
|
||||
holder.arrowUpDownRata.setImageDrawable(mContext.getResources().getDrawable(R.drawable.arrowupgreen));
|
||||
} else {
|
||||
holder.textratatotalhari.setText(poinhari);
|
||||
holder.textratatotalhari.setVisibility(View.VISIBLE);
|
||||
holder.textarrowUpDownRata.setVisibility(View.INVISIBLE);
|
||||
holder.arrowUpDownRata.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH);
|
||||
String waktusekarang = sdf.format(now);
|
||||
|
||||
Date date1 = null;
|
||||
try {
|
||||
date1 = inputFormatter1.parse(dataDetailKompetisi.getResultList().get(position).getMEMBERSHIP_PROGRAM_START_DATE());
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String output1 = outputFormatter1.format(date1); //
|
||||
|
||||
Date firstDate = null;
|
||||
try {
|
||||
firstDate = sdf.parse(output1);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Date secondDate = null;
|
||||
try {
|
||||
secondDate = sdf.parse(waktusekarang);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
long diffInMillies = Math.abs(secondDate.getTime() - firstDate.getTime());
|
||||
long diff = TimeUnit.DAYS.convert(diffInMillies, TimeUnit.MILLISECONDS);
|
||||
int days = (int) (long) diff;
|
||||
|
||||
int dailyAvgPeriodPoint;
|
||||
if (days <= 1) {
|
||||
dailyAvgPeriodPoint = 0;
|
||||
} else {
|
||||
dailyAvgPeriodPoint = gracepointnow / days;
|
||||
}
|
||||
|
||||
String poinharirata = Tool.formatToCurrency(dailyAvgPeriodPoint);
|
||||
holder.textratatotal.setText(poinharirata);
|
||||
|
||||
|
||||
ArrayList<TeamMember.DataGroupRank> dataGroupRank = dataDetailKompetisi.getResultList().get(position).getTEAM_MEMBER().get(0).getDATA_GROUP_RANK();
|
||||
|
||||
holder.totalPoinKompetisi.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (null != mListener) {
|
||||
// Notify the active callbacks interface (the activity, if the
|
||||
// fragment is attached to one) that an item has been selected.
|
||||
if (d == 0) {
|
||||
Toast.makeText(mContext, mContext.getString(R.string.points_detail_not_found), Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("MembershipProgramCode", dataDetailKompetisi.getResultList().get(position).getMEMBERSHIP_PROGRAM_CODE());
|
||||
bundle.putString("MembershipProgramName", dataDetailKompetisi.getResultList().get(position).getMEMBERSHIP_PROGRAM_NAME());
|
||||
bundle.putString("ProgramStartDate", dataDetailKompetisi.getResultList().get(position).getMEMBERSHIP_PROGRAM_START_DATE());
|
||||
mListener.onListFragmentInteraction(bundle);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
GridDashBoardAdapter adapter = new GridDashBoardAdapter(mContext, dataGroupRank);
|
||||
holder.gridView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return dataDetailKompetisi.getResultList().size();
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
private final TextView competitionName;
|
||||
private final TextView totalPoinKompetisi;
|
||||
private final TextView pointMonth;
|
||||
private final TextView startDate;
|
||||
private final TextView labelPointSaya;
|
||||
private final GridView gridView;
|
||||
private final ImageView logoKompetisi;
|
||||
private final ImageView arrowUpDownMonth;
|
||||
private final ImageView arrowUpDownRata;
|
||||
private final TextView textarrowUpDownMonth;
|
||||
private final TextView textarrowUpDownRata;
|
||||
private final TextView textratatotal;
|
||||
private final TextView textratatotalhari;
|
||||
private final TextView upDownGracePoint;
|
||||
private DetailKompetisiResponse mItem;
|
||||
|
||||
private ViewHolder(View view) {
|
||||
super(view);
|
||||
competitionName = (TextView) view.findViewById(R.id.namaKompetisi);
|
||||
totalPoinKompetisi = (TextView) view.findViewById(R.id.poinPeriod);
|
||||
pointMonth = (TextView) view.findViewById(R.id.angka1);
|
||||
textratatotalhari = (TextView) view.findViewById(R.id.angka2);
|
||||
labelPointSaya = (TextView) view.findViewById(R.id.labelPoinSaya);
|
||||
|
||||
startDate = (TextView) view.findViewById(R.id.dateEvent);
|
||||
gridView = (GridView) view.findViewById(R.id.gridview);
|
||||
logoKompetisi = (ImageView) view.findViewById(R.id.logoKompetisi);
|
||||
|
||||
arrowUpDownMonth = (ImageView) view.findViewById(R.id.updownallcalender);
|
||||
arrowUpDownRata = (ImageView) view.findViewById(R.id.updownallcalender2);
|
||||
|
||||
textarrowUpDownMonth = (TextView) view.findViewById(R.id.updatePointMonth);
|
||||
textarrowUpDownRata = (TextView) view.findViewById(R.id.updatePointRata);
|
||||
textratatotal = (TextView) view.findViewById(R.id.angka3);
|
||||
upDownGracePoint = (TextView) view.findViewById(R.id.updownGracePoin);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="svn" />
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
After Width: | Height: | Size: 542 B |
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
|
@ -0,0 +1,432 @@
|
|||
package com.adins.mss.odr.other;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.ImageFormat;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.location.LocationManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.User;
|
||||
import com.adins.mss.foundation.camera.Camera;
|
||||
import com.adins.mss.foundation.camera.ImageCallBack;
|
||||
import com.adins.mss.foundation.image.Utils;
|
||||
import com.adins.mss.foundation.location.LocationTrackingManager;
|
||||
import com.adins.mss.odr.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by winy.firdasari on 14/01/2015.
|
||||
*/
|
||||
public class CameraPreviewActivity extends Activity {
|
||||
|
||||
private Preview mPreview;
|
||||
private ListAdapter listPicSize;
|
||||
private int rotate = 0;
|
||||
|
||||
// ---
|
||||
private static final int BACK_MENU_ID = Menu.FIRST;
|
||||
private static final int OPTIONS_MENU_ID = Menu.FIRST + 1;
|
||||
private static final int CAPTURE_MENU_ID = Menu.FIRST + 2;
|
||||
private static final int AUTOFLASH_MENU_ID = Menu.FIRST + 3;
|
||||
private static final int FLASHON_MENU_ID = Menu.FIRST + 4;
|
||||
private static final int FLASHOFF_MENU_ID = Menu.FIRST + 5;
|
||||
|
||||
Context context;
|
||||
boolean hasCamera;
|
||||
private Activity activity;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// TODO need take ltm value from Global
|
||||
// this is set manual for testing
|
||||
GlobalData.getSharedGlobalData().setUser(new User("Bong"));
|
||||
GlobalData.getSharedGlobalData().getUser().setLogin_id("Bong");
|
||||
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
||||
LocationTrackingManager manager = new LocationTrackingManager(tm, lm, getApplicationContext());
|
||||
manager.setMinimalDistanceChangeLocation(100);
|
||||
manager.setMinimalTimeChangeLocation(5000);
|
||||
manager.applyLocationListener(getApplicationContext());
|
||||
Global.LTM = manager;
|
||||
|
||||
// Hide the window title.
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
context=this;
|
||||
mPreview = new Preview(this);
|
||||
setContentView(mPreview);
|
||||
|
||||
hasCamera = Camera.checkCameraHardware(this);
|
||||
// if (hasCamera) {
|
||||
// android.hardware.Camera cam = android.hardware.Camera.open();
|
||||
// android.hardware.Camera.Parameters params = cam.getParameters();
|
||||
// camera = new Camera(getApplicationContext(), getParent(), cam, params, questionInFocus);
|
||||
// }
|
||||
|
||||
this.activity=this;
|
||||
}
|
||||
|
||||
public boolean getLCDSceenTipeLandscape(){
|
||||
boolean result = false;
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(dm);
|
||||
String str_ScreenSize = "The Android Screen is: W="
|
||||
+ dm.widthPixels
|
||||
+ " x H="
|
||||
+ dm.heightPixels;
|
||||
|
||||
System.out.println(str_ScreenSize);
|
||||
if(dm.widthPixels>dm.heightPixels){
|
||||
result = true;
|
||||
}else{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
menu.add(0, BACK_MENU_ID, 0, "Back");
|
||||
menu.add(0, CAPTURE_MENU_ID, 0, "Capture");
|
||||
menu.add(0, AUTOFLASH_MENU_ID, 0, "Auto Flash");
|
||||
menu.add(0, FLASHON_MENU_ID, 0, "Flash On");
|
||||
menu.add(0, FLASHOFF_MENU_ID, 0, "Flash Off");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case BACK_MENU_ID:
|
||||
this.finish();
|
||||
return true;
|
||||
case OPTIONS_MENU_ID:
|
||||
this.showOptions();
|
||||
return true;
|
||||
case CAPTURE_MENU_ID:
|
||||
mPreview.mCamera.getPicture(new ImageCallBack() {
|
||||
@Override
|
||||
public void onPictureTaken(byte[] bytes, Object o) {
|
||||
if(getIntent().getIntExtra("EDIT_MODE_IMAGE",-1) == 0){
|
||||
File file = new File(context.getExternalFilesDir(null)+File.separator + "imgHeader.jpg");
|
||||
File filesave = new File(context.getFilesDir()+"/imgHeader");
|
||||
Utils.saveBitmapHeadertoPath(getApplicationContext(), Utils.byteToBitmap(bytes));
|
||||
Uri outputUri = Uri.fromFile(filesave);
|
||||
}else{
|
||||
File file = new File(context.getExternalFilesDir(null)+File.separator + "imgProfile.jpg");
|
||||
File filesave = new File(context.getFilesDir()+"/imgProfile");
|
||||
Utils.saveBitmapProfiletoPath(getApplicationContext(), Utils.byteToBitmap(bytes));
|
||||
Uri outputUri = Uri.fromFile(filesave);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
return true;
|
||||
case AUTOFLASH_MENU_ID:
|
||||
mPreview.mCamera.setFlashAuto();
|
||||
return true;
|
||||
case FLASHON_MENU_ID:
|
||||
mPreview.mCamera.setFlashOn();
|
||||
return true;
|
||||
case FLASHOFF_MENU_ID:
|
||||
mPreview.mCamera.setFlashOff();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void showOptions() {
|
||||
this.loadSupportedPicSize();
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("Picture Size");
|
||||
builder.setSingleChoiceItems(listPicSize, -1, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
String resolution = (String) listPicSize.getItem(item);
|
||||
String[] sz = resolution.split("x");
|
||||
int w = Integer.parseInt(sz[0]);
|
||||
int h = Integer.parseInt(sz[1]);
|
||||
|
||||
mPreview.setPictureSize(w, h);
|
||||
mPreview.mCamera.getCamera().stopPreview();
|
||||
android.hardware.Camera.Size previewSize = mPreview.getOptimalPreviewSize(w, h);
|
||||
mPreview.setPreviewSize(previewSize.width, previewSize.height);
|
||||
mPreview.mCamera.getCamera().startPreview();
|
||||
try {
|
||||
dialog.dismiss();
|
||||
dialog=null;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
Toast.makeText(getApplicationContext(), "Picture size: " + resolution, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
}
|
||||
|
||||
private void loadSupportedPicSize() {
|
||||
if (listPicSize == null) {
|
||||
List<String> listSize = mPreview.getSupportedPictureSize();
|
||||
listPicSize = new ArrayAdapter<String>(this, R.layout.picture_size_list, listSize);
|
||||
}
|
||||
}
|
||||
|
||||
private int actualWidht = 240;
|
||||
private int actualHeight=320;
|
||||
private int jpegQuality=70;
|
||||
|
||||
public class Preview extends SurfaceView implements SurfaceHolder.Callback {
|
||||
private SurfaceHolder mHolder;
|
||||
private Camera mCamera;
|
||||
|
||||
public List<String> getSupportedPictureSize() {
|
||||
List<android.hardware.Camera.Size> listSize = mCamera.getCamera().getParameters().getSupportedPictureSizes();
|
||||
List<String> listSizeStr = new ArrayList<String>();
|
||||
|
||||
for (android.hardware.Camera.Size size : listSize) {
|
||||
listSizeStr.add(size.width + "x" + size.height);
|
||||
}
|
||||
|
||||
return listSizeStr;
|
||||
}
|
||||
|
||||
public Preview(Context context) {
|
||||
super(context);
|
||||
mHolder = getHolder();
|
||||
mHolder.addCallback(this);
|
||||
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
||||
}
|
||||
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
try {
|
||||
android.hardware.Camera cam = android.hardware.Camera.open();
|
||||
mCamera = new Camera(context, activity, cam, cam.getParameters());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
// default to set picture size to lowest resolution
|
||||
List<android.hardware.Camera.Size> listSupportedSize = mCamera.getCamera().getParameters().getSupportedPictureSizes();
|
||||
if (listSupportedSize != null && listSupportedSize.size() > 0) {
|
||||
android.hardware.Camera.Size minimumSize = listSupportedSize.get(searchMostSuportedSizeFromParam(listSupportedSize));
|
||||
android.hardware.Camera.Parameters parameters = mCamera.getCamera().getParameters();
|
||||
parameters.setPictureSize(minimumSize.width, minimumSize.height);
|
||||
mCamera.getCamera().setParameters(parameters);
|
||||
}
|
||||
|
||||
try {
|
||||
mCamera.getCamera().setPreviewDisplay(holder);
|
||||
}
|
||||
catch (IOException exception) {
|
||||
mCamera.getCamera().release();
|
||||
mCamera = null;
|
||||
}
|
||||
}
|
||||
|
||||
public int searchMostSuportedSizeFromParam(List<android.hardware.Camera.Size> listSupportedSize){
|
||||
android.hardware.Camera.Size suportedSize;
|
||||
int idx = 0;
|
||||
//search for match w x h
|
||||
for (int i = 0; i < listSupportedSize.size(); i++) {
|
||||
if(listSupportedSize.get(i).width==actualWidht&&listSupportedSize.get(i).height==actualHeight){
|
||||
return i;
|
||||
//break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//search for match h
|
||||
for (int i = 0; i < listSupportedSize.size(); i++) {
|
||||
if(listSupportedSize.get(i).height==actualHeight){
|
||||
|
||||
return i;
|
||||
//break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//search for match w
|
||||
for (int i = 0; i < listSupportedSize.size(); i++) {
|
||||
if(listSupportedSize.get(i).width==actualWidht){
|
||||
|
||||
return i;
|
||||
//break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return listSupportedSize.size() - 1 ;
|
||||
}
|
||||
|
||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||
mCamera.getCamera().stopPreview();
|
||||
mCamera.getCamera().release();
|
||||
mCamera = null;
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@TargetApi(Build.VERSION_CODES.FROYO)
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
|
||||
android.hardware.Camera.Parameters parameters = mCamera.getCamera().getParameters();
|
||||
android.hardware.Camera.Size resultSize=null;
|
||||
|
||||
try {
|
||||
resultSize = getOptimalPreviewSize( w, h );
|
||||
if(resultSize!=null){
|
||||
w = resultSize.width;
|
||||
h = resultSize.height;
|
||||
}
|
||||
if(resultSize!=null)
|
||||
parameters.setPreviewSize(w, h);
|
||||
|
||||
} catch (Exception e) {
|
||||
resultSize=null;
|
||||
}
|
||||
|
||||
parameters.setPictureFormat(ImageFormat.JPEG);
|
||||
parameters.setFocusMode(android.hardware.Camera.Parameters.FOCUS_MODE_AUTO);
|
||||
parameters.setFlashMode(android.hardware.Camera.Parameters.FLASH_MODE_OFF);
|
||||
|
||||
if(resultSize!=null){
|
||||
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
|
||||
android.hardware.Camera.CameraInfo info =
|
||||
new android.hardware.Camera.CameraInfo();
|
||||
android.hardware.Camera.getCameraInfo(android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK, info);
|
||||
int degrees = 0;
|
||||
switch (rotation) {
|
||||
case Surface.ROTATION_0: degrees = 0; break;
|
||||
case Surface.ROTATION_90: degrees = 90; break;
|
||||
case Surface.ROTATION_180: degrees = 180; break;
|
||||
case Surface.ROTATION_270: degrees = 270; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
int result;
|
||||
if (info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT) {
|
||||
result = (info.orientation + degrees) % 360;
|
||||
result = (360 - result) % 360; // compensate the mirror
|
||||
} else { // back-facing
|
||||
result = (info.orientation - degrees + 360) % 360;
|
||||
}
|
||||
|
||||
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
|
||||
rotate = 90;
|
||||
}
|
||||
|
||||
//khusus untuk device dengan lcd landscape, ex: htc chacha
|
||||
if(result==90&&getLCDSceenTipeLandscape()){
|
||||
result=0;
|
||||
} else if(result==0&&!getLCDSceenTipeLandscape()){
|
||||
result = 270;
|
||||
}else if(result==180&&!getLCDSceenTipeLandscape()){
|
||||
result = 90;
|
||||
}else if(result==270&&getLCDSceenTipeLandscape()){
|
||||
result = 180;
|
||||
}
|
||||
|
||||
mCamera.getCamera().setDisplayOrientation(result);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
mCamera.getCamera().setParameters(parameters);
|
||||
} catch (Exception e) {
|
||||
parameters = mCamera.getCamera().getParameters();
|
||||
parameters.setPictureFormat(ImageFormat.JPEG);
|
||||
parameters.setFocusMode(android.hardware.Camera.Parameters.FOCUS_MODE_AUTO);
|
||||
parameters.setFlashMode(android.hardware.Camera.Parameters.FLASH_MODE_AUTO);
|
||||
|
||||
try {
|
||||
mCamera.getCamera().setParameters(parameters);
|
||||
} catch (Exception e2) {
|
||||
parameters = mCamera.getCamera().getParameters();
|
||||
mCamera.getCamera().setParameters(parameters);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mCamera.getCamera().startPreview();
|
||||
}
|
||||
|
||||
public void setPictureSize(int width, int height) {
|
||||
android.hardware.Camera.Parameters cp = mCamera.getCamera().getParameters();
|
||||
cp.setPictureSize(width, height);
|
||||
mCamera.getCamera().setParameters(cp);
|
||||
}
|
||||
|
||||
public android.hardware.Camera.Size getOptimalPreviewSize(int picWidth, int picHeight) {
|
||||
List<android.hardware.Camera.Size> sizes = mCamera.getCamera().getParameters().getSupportedPreviewSizes();
|
||||
final double ASPECT_TOLERANCE = 0.1;
|
||||
double targetRatio = (double) picWidth / picHeight;
|
||||
if (sizes == null)
|
||||
return null;
|
||||
|
||||
android.hardware.Camera.Size optimalSize = null;
|
||||
double minDiff = Double.MAX_VALUE;
|
||||
|
||||
int targetHeight = picHeight;
|
||||
|
||||
// Try to find an size match aspect ratio and size
|
||||
for (android.hardware.Camera.Size size : sizes) {
|
||||
double ratio = (double) size.width / size.height;
|
||||
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
|
||||
continue;
|
||||
if (Math.abs(size.height - targetHeight) < minDiff) {
|
||||
optimalSize = size;
|
||||
minDiff = Math.abs(size.height - targetHeight);
|
||||
}
|
||||
}
|
||||
|
||||
// Cannot find the one match the aspect ratio, ignore the
|
||||
// requirement
|
||||
if (optimalSize == null) {
|
||||
minDiff = Double.MAX_VALUE;
|
||||
for (android.hardware.Camera.Size size : sizes) {
|
||||
if (Math.abs(size.height - targetHeight) < minDiff) {
|
||||
optimalSize = size;
|
||||
minDiff = Math.abs(size.height - targetHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
return optimalSize;
|
||||
}
|
||||
|
||||
public void setPreviewSize(int width, int height) {
|
||||
android.hardware.Camera.Parameters cp = mCamera.getCamera().getParameters();
|
||||
cp.setPreviewSize(width, height);
|
||||
mCamera.getCamera().setParameters(cp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue