From ec7ae77b18981701aba6ac400b222169888d210d Mon Sep 17 00:00:00 2001 From: MadelynTav Date: Fri, 19 Jun 2015 17:27:06 -0400 Subject: [PATCH 1/2] trying to replace user image --- app/res/values/strings.xml | 1 + .../mobile/ui/NavigationDrawerFragment.java | 41 +++++++++++++++++++ .../mobile/ui/ref/BranchFileViewActivity.java | 7 +++- .../mobile/ui/search/SearchActivity.java | 1 - 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/app/res/values/strings.xml b/app/res/values/strings.xml index afb0b9dbf..32a921f4a 100644 --- a/app/res/values/strings.xml +++ b/app/res/values/strings.xml @@ -99,6 +99,7 @@ News Issues Gists + Sign Out Commits GitHub search Find Repositories diff --git a/app/src/main/java/com/github/mobile/ui/NavigationDrawerFragment.java b/app/src/main/java/com/github/mobile/ui/NavigationDrawerFragment.java index 22719f1d8..7c4a5048d 100644 --- a/app/src/main/java/com/github/mobile/ui/NavigationDrawerFragment.java +++ b/app/src/main/java/com/github/mobile/ui/NavigationDrawerFragment.java @@ -3,11 +3,17 @@ import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.database.Cursor; +import android.graphics.Bitmap; import android.graphics.Point; + +import android.net.Uri; import android.os.Bundle; import android.preference.PreferenceManager; +import android.provider.MediaStore; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.widget.DrawerLayout; @@ -49,6 +55,7 @@ public class NavigationDrawerFragment extends Fragment implements AdapterView.On private ImageView userImage; private TextView userRealName; private TextView userName; + private int ACTIVITY_SELECT_IMAGE; public NavigationDrawerFragment() { } @@ -63,6 +70,8 @@ public void onCreate(Bundle savedInstanceState) { mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION); mFromSavedInstanceState = true; } + + } @Override @@ -116,6 +125,18 @@ public void setUp(int fragmentId, DrawerLayout drawerLayout, NavigationDrawerAda avatar.bind(userImage, user); userName.setText(user.getLogin()); + userImage.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent i = new Intent(Intent.ACTION_PICK, + android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI); + //ACTIVITY_SELECT_IMAGE = 1234; + i.putExtra("image",ACTIVITY_SELECT_IMAGE); + startActivityForResult(i, 0); + } + + }); + String name = user.getName(); if (name != null) { userRealName.setText(user.getName()); @@ -249,4 +270,24 @@ public int materializedWidth() { return screenSize.x - actionBarHeight; } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + + if(requestCode == 0) + { + if(data != null) + { + Bitmap photo = (Bitmap) data.getExtras().get("data"); + photo = Bitmap.createScaledBitmap(photo, 80, 80, false); + userImage.setImageBitmap(photo); + } + else{ + } + } + } + + + } diff --git a/app/src/main/java/com/github/mobile/ui/ref/BranchFileViewActivity.java b/app/src/main/java/com/github/mobile/ui/ref/BranchFileViewActivity.java index b442a509e..dbb56b341 100644 --- a/app/src/main/java/com/github/mobile/ui/ref/BranchFileViewActivity.java +++ b/app/src/main/java/com/github/mobile/ui/ref/BranchFileViewActivity.java @@ -177,9 +177,12 @@ public boolean onCreateOptionsMenu(final Menu optionsMenu) { public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.m_wrap: - if (editor.getWrap()) + + //enable textWrapping + if (editor.getWrap()){ item.setTitle(R.string.enable_wrapping); - else + codeView.getSettings().setBuiltInZoomControls(true); + } else item.setTitle(R.string.disable_wrapping); editor.toggleWrap(); PreferenceUtils.save(PreferenceUtils.getCodePreferences(this) diff --git a/app/src/main/java/com/github/mobile/ui/search/SearchActivity.java b/app/src/main/java/com/github/mobile/ui/search/SearchActivity.java index d448b0d05..acc5671b5 100644 --- a/app/src/main/java/com/github/mobile/ui/search/SearchActivity.java +++ b/app/src/main/java/com/github/mobile/ui/search/SearchActivity.java @@ -32,7 +32,6 @@ import android.view.Menu; import android.view.MenuItem; import android.widget.ProgressBar; - import com.github.kevinsawicki.wishlist.ViewUtils; import com.github.mobile.R; import com.github.mobile.ui.MainActivity; From 54446cdaab16432c91f4fab445c1dbdb526f69cc Mon Sep 17 00:00:00 2001 From: MadelynTav Date: Fri, 19 Jun 2015 17:46:57 -0400 Subject: [PATCH 2/2] not crashing and selecting image but does not display it on the userImage Icon --- .../mobile/ui/NavigationDrawerFragment.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/github/mobile/ui/NavigationDrawerFragment.java b/app/src/main/java/com/github/mobile/ui/NavigationDrawerFragment.java index 7c4a5048d..8801d9ce4 100644 --- a/app/src/main/java/com/github/mobile/ui/NavigationDrawerFragment.java +++ b/app/src/main/java/com/github/mobile/ui/NavigationDrawerFragment.java @@ -8,8 +8,8 @@ import android.content.res.Configuration; import android.database.Cursor; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.graphics.Point; - import android.net.Uri; import android.os.Bundle; import android.preference.PreferenceManager; @@ -30,6 +30,7 @@ import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; +import android.widget.Toast; import com.github.mobile.R; import com.github.mobile.util.AvatarLoader; @@ -55,7 +56,7 @@ public class NavigationDrawerFragment extends Fragment implements AdapterView.On private ImageView userImage; private TextView userRealName; private TextView userName; - private int ACTIVITY_SELECT_IMAGE; + private static final int IMAGE_PICKER_SELECT = 999; public NavigationDrawerFragment() { } @@ -129,10 +130,8 @@ public void setUp(int fragmentId, DrawerLayout drawerLayout, NavigationDrawerAda @Override public void onClick(View v) { Intent i = new Intent(Intent.ACTION_PICK, - android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI); - //ACTIVITY_SELECT_IMAGE = 1234; - i.putExtra("image",ACTIVITY_SELECT_IMAGE); - startActivityForResult(i, 0); + android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI); + startActivityForResult(i, IMAGE_PICKER_SELECT); } }); @@ -274,20 +273,21 @@ public int materializedWidth() { public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - - if(requestCode == 0) - { - if(data != null) - { - Bitmap photo = (Bitmap) data.getExtras().get("data"); - photo = Bitmap.createScaledBitmap(photo, 80, 80, false); - userImage.setImageBitmap(photo); - } - else{ - } + if (requestCode == IMAGE_PICKER_SELECT && resultCode == Activity.RESULT_OK) { + MainActivity activity = (MainActivity)getActivity(); + Bitmap bitmap = getBitmapFromCameraData(data, activity); + userImage.setImageBitmap(bitmap); } } + public static Bitmap getBitmapFromCameraData(Intent data, Context context){ + Uri selectedImage = data.getData(); + String[] filePathColumn = { MediaStore.Images.Media.DATA }; + Cursor cursor = context.getContentResolver().query(selectedImage,filePathColumn, null, null, null); + cursor.moveToFirst(); + int columnIndex = cursor.getColumnIndex(filePathColumn[0]); + String picturePath = cursor.getString(columnIndex); + cursor.close(); + return BitmapFactory.decodeFile(picturePath); + } - - -} + } \ No newline at end of file