BaseActivity.java
5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package etelligens.com.foodsafety.utils;
import static etelligens.com.foodsafety.utils.Keyword.DB_LOGIN_USER_DATA;
import static etelligens.com.foodsafety.utils.Keyword.PREF_LANG;
import static etelligens.com.foodsafety.utils.Keyword.PREF_NAME;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Environment;
import android.os.PersistableBundle;
import android.util.Log;
import android.view.inputmethod.InputMethodManager;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.multidex.MultiDex;
import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import etelligens.com.foodsafety.R;
import etelligens.com.foodsafety.activities.Notification.Notification;
import etelligens.com.foodsafety.activities.dashboard.Dashboard;
public class BaseActivity extends AppCompatActivity {
private static final String TAG = "BaseActivity";
private ProgressDialog progress = null;
SharedPreferences DBuserData, langData;
public String userId, userImg, userName, roleName, empID, currentLang,
userEmail, userMob, loginToken, roleID, outletID, partnerID, isAdmin;
@Override
public void onCreate(@Nullable Bundle savedInstanceState,
@Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
}
public void loadershow() {
if (progress == null) {
progress = new ProgressDialog(this, R.style.progressTheme);
}
progress.setTitle("Food Safety");
progress.setMessage(getString(R.string.loading));
progress.setCancelable(false);
progress.show();
}
public void getselectedLanguage() {
langData = getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
currentLang = langData.getString(PREF_LANG, null);
Log.e(TAG, "getselectedLanguage==" + currentLang);
}
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(LocaleHelper.onAttach(newBase));
MultiDex.install(this);
Log.e(TAG, "attachCalled...");
}
public void loaderHide() {
if (progress == null) {
progress = new ProgressDialog(this);
}
progress.dismiss();
}
public void hideKeyBoard() {
final InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null && inputMethodManager.isActive()) {
if (getCurrentFocus() != null) {
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
} //do nothing...
}
}
public void getSavedData() {
DBuserData = getSharedPreferences(DB_LOGIN_USER_DATA, Context.MODE_PRIVATE);
userId = DBuserData.getString("USERID", null);
userImg = DBuserData.getString("userIMG", null);
userName = DBuserData.getString("UserName", null);
roleName = DBuserData.getString("roleName", null);
empID = DBuserData.getString("EmpID", null);
userEmail = DBuserData.getString("userEmail", null);
userMob = DBuserData.getString("phone", null);
loginToken = DBuserData.getString("LoginToken", null);
roleID = DBuserData.getString("roleID", null);
outletID = DBuserData.getString("outletID", null);
partnerID = DBuserData.getString("partnerID", null);
isAdmin = DBuserData.getString("isAdmin", null);
}
public void gotoDashboard() {
Intent i = new Intent(getApplicationContext(), Dashboard.class);
startActivity(i);
finish();
}
public void goToNotificationList() {
Intent i = new Intent(getApplicationContext(), Notification.class);
int values = 1;
i.putExtra("value", values);
startActivity(i);
}
private Bitmap saveImage(Bitmap finalBitmap) {
String root = Environment.getExternalStorageDirectory().toString();
String path = root + "/product/thumb";
System.out.println("LOGGER Path:, " + path);
File myDir = new File(path);
myDir.mkdirs();
@SuppressLint("SimpleDateFormat") String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String fname = "IMG_" + timeStamp + ".jpg";
File file = new File(myDir, fname);
if (file.exists()) file.delete();
try {
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(Bitmap.CompressFormat.JPEG, 70, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
return finalBitmap;
}
public Bitmap saveTempBitmap(Bitmap bitmap) {
if (isExternalStorageWritable()) {
return saveImage(bitmap);
} else {
return null;
//prompt the user or do something
}
}
/* Checks if external storage is available for read and write */
public boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
}