package com.android_app.matan.ara.sagi.thesocialnotework; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.ImageView; public class SettingsFragment extends Fragment { private static final String ARG_PARAM1 = "param1"; private static final String ARG_PARAM2 = "param2"; private static final String TAG = "Settings" ; private static final int REQUEST_IMAGE_CAPTURE = 1; private Button cameraBtn; private ImageView avatarImage; // private OnFragmentInteractionListener mListener; public SettingsFragment() { // Required empty public constructor } /** * Use this factory method to create a new instance of * this fragment using the provided parameters. * * @param param1 Parameter 1. * @param param2 Parameter 2. * @return A new instance of fragment SettingsFragment. */ // TODO: Rename and change types and number of parameters public static SettingsFragment newInstance(String param1, String param2) { SettingsFragment fragment = new SettingsFragment(); Bundle args = new Bundle(); args.putString(ARG_PARAM1, param1); args.putString(ARG_PARAM2, param2); fragment.setArguments(args); return fragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_settings, container, false); cameraBtn = (Button) view.findViewById(R.id.camera_button); cameraBtn.setOnClickListener(cameraBtnListener); avatarImage = (ImageView) view.findViewById(R.id.settings_userAvater_iamgeView); return view; } // // TODO: Rename method, update argument and hook method into UI event // public void onButtonPressed(Uri uri) { // if (mListener != null) { // mListener.onFragmentInteraction(uri); // } // } @Override public void onAttach(Context context) { super.onAttach(context); } @Override public void onDetach() { super.onDetach(); } // /** // * This interface must be implemented by activities that contain this // * fragment to allow an interaction in this fragment to be communicated // * to the activity and potentially other fragments contained in that // * activity. // *

// * See the Android Training lesson Communicating with Other Fragments for more information. // */ // public interface OnFragmentInteractionListener { // // TODO: Update argument type and name // void onFragmentInteraction(Uri uri); // } private View.OnClickListener cameraBtnListener = new View.OnClickListener() { public void onClick(View v) { Log.d(TAG, "in camera Button"); Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intent, REQUEST_IMAGE_CAPTURE); } }; @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { Log.d(TAG, "on activity result"); Log.d(TAG, "requestCode: "+requestCode); Log.d(TAG, "resultCode: "+resultCode); Log.d(TAG, "Activity.RESULT_OK: "+Activity.RESULT_OK); if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == Activity.RESULT_OK) { Log.d(TAG, "inside if"); Bundle extras = data.getExtras(); Bitmap imageBitmap= (Bitmap) extras.get("data"); Log.d(TAG, "bitmap: "+imageBitmap.toString()); // Bitmap imageBitmap = (Bitmap) extras.get("data"); avatarImage.setImageBitmap(imageBitmap); } } }