Skip to content

Commit

Permalink
Main Activity Attendance
Browse files Browse the repository at this point in the history
#2
- Picasso loading user and company images
  • Loading branch information
eurosecom committed Sep 17, 2017
1 parent 13904de commit b02aa79
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 22 deletions.
102 changes: 84 additions & 18 deletions app/src/main/java/com/eusecom/attendance/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.squareup.picasso.NetworkPolicy;
import com.squareup.picasso.Picasso;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
Expand All @@ -69,6 +71,7 @@
import java.util.Map;
import android.Manifest;

import static com.squareup.picasso.NetworkPolicy.NO_CACHE;
import static java.lang.System.out;

public class MainActivity extends ActionBarActivity {
Expand Down Expand Up @@ -482,25 +485,43 @@ private void getCompanyIcon(FirebaseUser user) {
String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
String imgUser = baseDir + File.separator + "/eusecom/attendance/photo" + myID + ".png";
File fileUser = new File(imgUser);
if(!fileUser.exists()){
imgUser = baseDir + File.separator + "/eusecom/attendance/photo" + myID + ".jpg";
fileUser = new File(imgUser);
}
Log.d("imgUser ", imgUser);

String myICO = SettingsActivity.getUsIco(MainActivity.this);
String imgIco = baseDir + File.separator + "/eusecom/attendance/photo" + myICO + ".png";
File fileIco = new File(imgIco);
if(!fileIco.exists()){
imgIco = baseDir + File.separator + "/eusecom/attendance/photo" + myICO + ".jpg";
fileIco = new File(imgIco);
}
Log.d("imgIco ", imgIco);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

if(fileUser.exists()){
Bitmap bmp = BitmapFactory.decodeFile(imgUser);
mUserImage.setImageBitmap(bmp);
//Bitmap bmp = BitmapFactory.decodeFile(imgUser);
//mUserImage.setImageBitmap(bmp);
//Picasso.with(this).invalidate(new File(imgUser));
Picasso.with(this).load(new File(imgUser))
.resize(800, 600)
.centerInside()
.into(mUserImage);
}else{
mUserImage.setImageDrawable(getResources().getDrawable(R.drawable.zamestnanec, getApplicationContext().getTheme()));
}

if(fileIco.exists()){
Bitmap bmp2 = BitmapFactory.decodeFile(imgIco);
mIntoworkImage.setImageBitmap(bmp2);
//Bitmap bmp2 = BitmapFactory.decodeFile(imgIco);
//mIntoworkImage.setImageBitmap(bmp2);
//.with(this).invalidate(new File(imgIco));
Picasso.with(this).load(new File(imgIco))
.resize(800, 600)
.centerInside()
.into(mIntoworkImage);
}else{
mIntoworkImage.setImageDrawable(getResources().getDrawable(R.drawable.add2new, getApplicationContext().getTheme()));
}
Expand All @@ -509,15 +530,25 @@ private void getCompanyIcon(FirebaseUser user) {
} else {

if(fileUser.exists()){
Bitmap bmp = BitmapFactory.decodeFile(imgUser);
mUserImage.setImageBitmap(bmp);
//Bitmap bmp = BitmapFactory.decodeFile(imgUser);
//mUserImage.setImageBitmap(bmp);
//Picasso.with(this).invalidate(new File(imgUser));
Picasso.with(this).load(new File(imgUser))
.resize(800, 600)
.centerInside()
.into(mUserImage);
}else{
mUserImage.setImageDrawable(getResources().getDrawable(R.drawable.zamestnanec));
}

if(fileIco.exists()){
Bitmap bmp2 = BitmapFactory.decodeFile(imgIco);
mIntoworkImage.setImageBitmap(bmp2);
//Bitmap bmp2 = BitmapFactory.decodeFile(imgIco);
//mIntoworkImage.setImageBitmap(bmp2);
//Picasso.with(this).invalidate(new File(imgIco));
Picasso.with(this).load(new File(imgIco))
.resize(800, 600)
.centerInside()
.into(mIntoworkImage);
}else{
mIntoworkImage.setImageDrawable(getResources().getDrawable(R.drawable.add2new));
}
Expand All @@ -532,21 +563,35 @@ private void getCompanyIcon(FirebaseUser user) {
String myICO3 = SettingsActivity.getUsIco(MainActivity.this);
String imgIco3 = baseDir3 + File.separator + "/eusecom/attendance/photo" + myICO3 + ".png";
File fileIco3 = new File(imgIco3);
if(!fileIco3.exists()){
imgIco3 = baseDir + File.separator + "/eusecom/attendance/photo" + myICO3 + ".jpg";
fileIco3 = new File(imgIco3);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

if(fileIco.exists()){
Bitmap bmp3 = BitmapFactory.decodeFile(imgIco3);
mCompanyImage.setImageBitmap(bmp3);
if(fileIco3.exists()){
//Bitmap bmp3 = BitmapFactory.decodeFile(imgIco3);
//mCompanyImage.setImageBitmap(bmp3);
//Picasso.with(this).invalidate(new File(imgIco3));
Picasso.with(this).load(new File(imgIco3))
.resize(800, 600)
.centerInside()
.into(mCompanyImage);
}else{
mCompanyImage.setImageDrawable(getResources().getDrawable(R.drawable.add2new, getApplicationContext().getTheme()));
}

} else {

if(fileIco.exists()){
Bitmap bmp3 = BitmapFactory.decodeFile(imgIco3);
mCompanyImage.setImageBitmap(bmp3);
//Bitmap bmp3 = BitmapFactory.decodeFile(imgIco3);
//mCompanyImage.setImageBitmap(bmp3);
//Picasso.with(this).invalidate(new File(imgIco3));
Picasso.with(this).load(new File(imgIco3))
.resize(800, 600)
.centerInside()
.into(mCompanyImage);
}else{
mCompanyImage.setImageDrawable(getResources().getDrawable(R.drawable.add2new));
}
Expand Down Expand Up @@ -870,13 +915,34 @@ void savefile(String selectedImagePath, int ximage)
{

String sourceFilename= selectedImagePath;

String usuidx = SettingsActivity.getUserUid(this);
String destinationFilename = Environment.getExternalStorageDirectory().getPath()+File.separatorChar+"eusecom/attendance/photo" + usuidx + ".png";
if(ximage == 2 ){
String mextension = selectedImagePath.substring(selectedImagePath.lastIndexOf("."));
String destinationFilename ="";
if(ximage == 1 ) {
String usuidx = SettingsActivity.getUserUid(this);
destinationFilename = Environment.getExternalStorageDirectory().getPath() + File.separatorChar + "eusecom/attendance/photo" + usuidx + mextension;
String delfilejpg = Environment.getExternalStorageDirectory().getPath()+File.separatorChar+"eusecom/attendance/photo" + usuidx + ".jpg";
File filedelj = new File(delfilejpg);
filedelj.delete();
Picasso.with(this).invalidate(new File(delfilejpg));
String delfilepng = Environment.getExternalStorageDirectory().getPath()+File.separatorChar+"eusecom/attendance/photo" + usuidx + ".png";
File filedelp = new File(delfilepng);
filedelp.delete();
Picasso.with(this).invalidate(new File(delfilepng));
}else{
String usicox = SettingsActivity.getUsIco(this);
destinationFilename = Environment.getExternalStorageDirectory().getPath()+File.separatorChar+"eusecom/attendance/photo" + usicox + ".png";
destinationFilename = Environment.getExternalStorageDirectory().getPath()+File.separatorChar+"eusecom/attendance/photo" + usicox + mextension;
String delfilejpg = Environment.getExternalStorageDirectory().getPath()+File.separatorChar+"eusecom/attendance/photo" + usicox + ".jpg";
File filedelj = new File(delfilejpg);
filedelj.delete();
Picasso.with(this).invalidate(new File(delfilejpg));
String delfilepng = Environment.getExternalStorageDirectory().getPath()+File.separatorChar+"eusecom/attendance/photo" + usicox + ".png";
File filedelp = new File(delfilepng);
filedelp.delete();
Picasso.with(this).invalidate(new File(delfilepng));
}


Log.d("selectedImagePath ext", mextension);
Log.d("selectedImagePath sour", sourceFilename);
Log.d("selectedImagePath dest", destinationFilename);

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-sk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@

<!-- Save image -->
<string name="saveicoimage" >Uložiť obrázok firmy</string>
<string name="saveicoimagemsg" >Musíte uložiť PNG obrázok max. 150kB do adresára /sdcard/eusecom/attendance/photo%s.png</string>
<string name="saveicoimagemsg" >Musíte uložiť PNG, JPG obrázok do adresára /sdcard/eusecom/attendance/photo%s.png[jpg]</string>
<string name="saveuserimage" >Uložiť obrázok užívateľa</string>
<string name="saveuserimagemsg" >Musíte uložiť PNG obrázok max. 150kB do adresára /sdcard/eusecom/attendance/photo%s.png</string>
<string name="saveuserimagemsg" >Musíte uložiť PNG, JPG obrázok do adresára /sdcard/eusecom/attendance/photo%s.png[jpg]</string>


<!-- Tests-->
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@

<!-- Save image -->
<string name="saveicoimage">Save Company Image</string>
<string name="saveicoimagemsg">You have to save PNG image max. 150kB to folder /sdcard/eusecom/attendance/photo%s.png</string>
<string name="saveicoimagemsg">You have to save PNG, JPG image to folder /sdcard/eusecom/attendance/photo%s.png[jpg]</string>
<string name="saveuserimage">Save User Image</string>
<string name="saveuserimagemsg">You have to save PNG image max. 150kB to folder /sdcard/eusecom/attendance/photo%s.png</string>
<string name="saveuserimagemsg">You have to save PNG, JPG image to folder /sdcard/eusecom/attendance/photo%s.png[jpg]</string>

<!-- Tests-->
<string name="myteststring">My test String</string>
Expand Down

0 comments on commit b02aa79

Please sign in to comment.