diff --git a/app/build.gradle b/app/build.gradle index 44b82fd..1ba8d38 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -58,11 +58,13 @@ dependencies { compile 'com.squareup.okhttp3:logging-interceptor:3.5.0' compile 'de.hdodenhof:circleimageview:2.2.0' - testCompile 'junit:junit:4.12' + //testCompile 'junit:junit: 4.12' testCompile 'org.mockito:mockito-core:1.10.19' annotationProcessor 'android.arch.lifecycle:compiler:1.0.0' annotationProcessor 'android.arch.persistence.room:compiler:1.0.0' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' compile 'com.squareup.picasso:picasso:2.5.2' + implementation 'com.github.esafirm.android-image-picker:imagepicker:1.11.1' + compile 'id.zelory:compressor:2.1.0' } diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/AccountsActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/AccountsActivity.java index e74f75b..5a6e248 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/AccountsActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/AccountsActivity.java @@ -4,12 +4,28 @@ import android.app.Activity; import android.arch.lifecycle.LiveData; import android.arch.lifecycle.Observer; import android.arch.lifecycle.ViewModelProviders; +import android.content.Context; +import android.content.ContextWrapper; import android.content.Intent; +import android.content.pm.ResolveInfo; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; import android.os.Bundle; +import android.os.FileObserver; +import android.os.Parcelable; +import android.provider.MediaStore; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; +import com.esafirm.imagepicker.features.ImagePicker; +import com.esafirm.imagepicker.model.Image; +//import com.nicdahlquist.pngquant.LibPngQuant; + +import java.io.File; +import java.io.FileOutputStream; +import java.util.ArrayList; import java.util.List; import butterknife.BindView; @@ -19,6 +35,8 @@ import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.viewmodels.AccountSeedListViewModel; import cy.agorise.crystalwallet.views.AccountSeedListView; +import de.hdodenhof.circleimageview.CircleImageView; +import id.zelory.compressor.Compressor; /** * Created by xd on 1/9/18. @@ -36,6 +54,13 @@ public class AccountsActivity extends AppCompatActivity { @BindView(R.id.vAccountSeedList) AccountSeedListView vAccountSeedList; + @BindView(R.id.user_img) + CircleImageView userImg; + + static final int NEW_PICTURE_REQUEST_CODE = 1; + + FileObserver fileObserver; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -52,6 +77,30 @@ public class AccountsActivity extends AppCompatActivity { vAccountSeedList.setData(accountSeeds); } }); + + loadUserImage(); + } + + @Override + protected void onResume() { + super.onResume(); + + loadUserImage(); + } + + public void loadUserImage(){ + //Search for a existing photo + ContextWrapper cw = new ContextWrapper(getApplicationContext()); + File directory = cw.getDir("profile", Context.MODE_PRIVATE); + if (!directory.exists()) { + directory.mkdir(); + } + File photoFile = new File(directory + File.separator + "photo.png"); + + if (photoFile.exists()){ + Bitmap bitmap = BitmapFactory.decodeFile(photoFile.getPath()); + userImg.setImageBitmap(bitmap); + } } @OnClick(R.id.tvSettings) @@ -65,4 +114,55 @@ public class AccountsActivity extends AppCompatActivity { public void cancel(){ onBackPressed(); } + + @OnClick(R.id.user_img) + public void loadUserImageSetting(){ + ImagePicker.create(this) + .single() + .start(); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (ImagePicker.shouldHandle(requestCode, resultCode, data)) { + // Get a list of picked images + List images = ImagePicker.getImages(data); + // or get a single image only + Image image = ImagePicker.getFirstImageOrNull(data); + + if (image != null){ + ContextWrapper cw = new ContextWrapper(getApplicationContext()); + File directory = cw.getDir("profile", Context.MODE_PRIVATE); + if (!directory.exists()) { + directory.mkdir(); + } + + try { + File imageCompressed = new Compressor(this) + .setCompressFormat(Bitmap.CompressFormat.PNG) + .setMaxWidth(320) + .setMaxHeight(480) + .compressToFile(new File(image.getPath())); + imageCompressed.renameTo(new File(directory + File.separator + "photo.png")); + + + if (imageCompressed.exists()){ + imageCompressed.delete(); + } + imageCompressed.createNewFile(); + //File inputPngFile = new File(image.getPath()); + //File outputPngFile = new File("photo.png"); + //new LibPngQuant().pngQuantFile(inputPngFile, outputPngFile); + + //Bitmap bitmapDecoded= BitmapFactory.decodeFile(image.getPath()); + //Bitmap bitmapResized = Bitmap.createScaledBitmap(bitmapDecoded, 320, 480, false); + //resizedbitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); + //fos.close(); + } catch (Exception e) { + //Log.e("SAVE_IMAGE", e.getMessage(), e); + } + } + } + super.onActivityResult(requestCode, resultCode, data); + } } \ No newline at end of file diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java index 17e0e6f..1d366cd 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java @@ -2,11 +2,18 @@ package cy.agorise.crystalwallet.activities; import android.app.ActivityOptions; import android.arch.lifecycle.ViewModelProviders; +import android.content.Context; +import android.content.ContextWrapper; import android.content.Intent; import android.content.res.Configuration; import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.media.MediaPlayer; +import android.net.Uri; import android.os.Bundle; +import android.os.FileObserver; +import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; @@ -23,6 +30,7 @@ import android.view.View; import android.view.animation.LinearInterpolator; import android.widget.ImageView; +import java.io.File; import java.util.List; import java.util.Locale; @@ -77,6 +85,8 @@ public class BoardActivity extends AppCompatActivity { @BindView(R.id.triangle) public ImageView triangle; + File photoDirectory; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -176,6 +186,30 @@ public class BoardActivity extends AppCompatActivity { } }); + + ContextWrapper cw = new ContextWrapper(getApplicationContext()); + photoDirectory = cw.getDir("profile", Context.MODE_PRIVATE); + if (!photoDirectory.exists()) { + photoDirectory.mkdir(); + } + loadUserImage(); + } + + @Override + protected void onResume() { + super.onResume(); + + loadUserImage(); + } + + public void loadUserImage(){ + //Search for a existing photo + File photoFile = new File(photoDirectory + File.separator + "photo.png"); + + if (photoFile.exists()){ + Bitmap bitmap = BitmapFactory.decodeFile(photoFile.getPath()); + userImage.setImageBitmap(bitmap); + } } /** diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/ProfileSettingsFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/ProfileSettingsFragment.java new file mode 100644 index 0000000..f6ae661 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/ProfileSettingsFragment.java @@ -0,0 +1,58 @@ +package cy.agorise.crystalwallet.fragments; + +import android.os.Bundle; +import android.support.design.widget.TabLayout; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; +import android.text.Editable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.EditText; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import butterknife.OnTextChanged; +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.util.ChildViewPager; + +/** + * Created by henry varona on 4/17/18. + */ + +public class ProfileSettingsFragment extends Fragment { + + @BindView(R.id.etProfileEmail) + EditText etProfileEmail; + + public ProfileSettingsFragment() { + // Required empty public constructor + } + + public static ProfileSettingsFragment newInstance() { + ProfileSettingsFragment fragment = new ProfileSettingsFragment(); + Bundle args = new Bundle(); + fragment.setArguments(args); + return fragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View v = inflater.inflate(R.layout.fragment_profile_settings, container, false); + ButterKnife.bind(this, v); + + return v; + } + + + + @OnTextChanged(value = R.id.etProfileEmail, + callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) + void afterEmailChanged(Editable editable) { + + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/TransactionOrderSpinnerAdapter.java b/app/src/main/java/cy/agorise/crystalwallet/views/TransactionOrderSpinnerAdapter.java index aba92ae..1b8e4e9 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/TransactionOrderSpinnerAdapter.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/TransactionOrderSpinnerAdapter.java @@ -66,7 +66,9 @@ public class TransactionOrderSpinnerAdapter extends ArrayAdapter + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_profile_settings.xml b/app/src/main/res/layout/fragment_profile_settings.xml new file mode 100644 index 0000000..b5954b1 --- /dev/null +++ b/app/src/main/res/layout/fragment_profile_settings.xml @@ -0,0 +1,29 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/transaction_list.xml b/app/src/main/res/layout/transaction_list.xml index 68c494e..1397df5 100644 --- a/app/src/main/res/layout/transaction_list.xml +++ b/app/src/main/res/layout/transaction_list.xml @@ -17,20 +17,24 @@ android:id="@+id/etTransactionSearch" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_alignParentLeft="true" android:layout_alignParentStart="true" - /> + android:layout_toLeftOf="@+id/btnTransactionsFilterDisplay" /> +