Skip to content

Commit

Permalink
can pick picture
Browse files Browse the repository at this point in the history
  • Loading branch information
yuichi10 committed Aug 20, 2015
1 parent c7f6af1 commit 51b0960
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

/**
* Created by yuichi on 8/20/15.
*/
public class SignUP extends Activity implements View.OnClickListener{
//code for return image
static int mRequestCode = 1001;
//image view
ImageView mImageView;
//Edit text
EditText email;
EditText password1;
EditText password2;
EditText name;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -22,14 +34,36 @@ public void onCreate(Bundle savedInstanceState) {

Button thumbnail = (Button)findViewById(R.id.signUpGetImage);
thumbnail.setOnClickListener(this);
email = (EditText)findViewById(R.id.signUpEmail_e);
email.setWidth(email.getWidth());
password1 = (EditText)findViewById(R.id.signUpPassword_e);
password1.setWidth(password1.getWidth());
password2 = (EditText)findViewById(R.id.signUpPassword2_e);
password2.setWidth(password2.getWidth());
name = (EditText)findViewById(R.id.signUpName_e);
name.setWidth(name.getWidth());
}

public void onActivityResult( int requestCode, int resultCode, Intent intent ){
if(requestCode == this.mRequestCode){
if(resultCode == Activity.RESULT_OK){
// 返却されてきたintentから値を取り出す
String str = intent.getStringExtra( "key" );
Log.d("aa",str);
// Bundle bundle = intent.getExtras();
String path = intent.getStringExtra("key");
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
Bitmap bmp = BitmapFactory.decodeFile(path, options);
int maxSize = 100;
int imageScaleWidth = options.outWidth / maxSize;
int imageScaleHeight = options.outHeight / maxSize;
int imageScale = (int)Math.floor((imageScaleWidth > imageScaleHeight ? imageScaleHeight : imageScaleWidth));
for (int i = 2; i <= imageScale; i *= 2) {
options.inSampleSize = i;
}
options.inJustDecodeBounds = false;
bmp = BitmapFactory.decodeFile(path, options);
mImageView = (ImageView)findViewById(R.id.singUpShowImage);
mImageView.setImageBitmap(bmp);
}
}
}
Expand All @@ -40,7 +74,7 @@ public void onClick(View v) {
case R.id.signUpGetImage:
Intent intent = new Intent();
intent.setClassName(SignIn.packageName, SignIn.packageName + ".ThumbnailImage");
startActivityForResult(intent,this.mRequestCode);
startActivityForResult(intent, this.mRequestCode);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Created by yuichi on 8/20/15.
*/
public class ThumbnailImage extends Activity implements AdapterView.OnItemClickListener{
Map<Long, String>imageMap = new HashMap<Long, String>();
ArrayList<String>imageMap = new ArrayList<String>();
ArrayList<Bitmap>imageList = new ArrayList<Bitmap>();

@Override
Expand All @@ -45,7 +45,7 @@ public void onCreate(Bundle savedInstanceState) {
do{
long idImage = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media._ID));
String pathImage = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
imageMap.put(idImage, pathImage);
imageMap.add(pathImage);
Bitmap bmp = MediaStore.Images.Thumbnails.getThumbnail(resolver,idImage,MediaStore.Images.Thumbnails.MINI_KIND,null);

imageList.add(bmp);
Expand All @@ -64,9 +64,10 @@ public void onCreate(Bundle savedInstanceState) {

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

Intent intent = new Intent();
intent.putExtra("key", "success");
Log.d("aa", imageList.get(position)+"");
intent.putExtra("key", imageMap.get(position));
setResult(Activity.RESULT_OK, intent);
finish();
}
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/layout/sign_up.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
android:id="@+id/signUpPassword_e"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:layout_weight="2"/>
</LinearLayout>

Expand All @@ -58,6 +59,7 @@
android:id="@+id/signUpPassword2_e"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:layout_weight="2"/>
</LinearLayout>

Expand Down Expand Up @@ -109,8 +111,8 @@
android:text="@string/signUpImage"/>
<ImageView
android:id="@+id/singUpShowImage"
android:layout_width="10dp"
android:layout_height="10dp" />
android:layout_width="100dp"
android:layout_height="100dp" />
</LinearLayout>

</LinearLayout>

0 comments on commit 51b0960

Please sign in to comment.