Android- Capture & Display Photo

MainActivity.java

package com.imslbd.firstcameraapp;

import android.content.Intent;
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    TextView txtChangeName;
    ImageView mImageView;
    static final int REQUEST_IMAGE_CAPTURE = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

       txtChangeName =(TextView) findViewById(R.id.txtDisplayName);
        mImageView=(ImageView) findViewById(R.id.imageView);
    }

    public  void ChangeName(View view)
    {
        dispatchTakePictureIntent();
        txtChangeName.setText("Hello");
    }

    private void dispatchTakePictureIntent() {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            Bitmap imageBitmap = (Bitmap) extras.get("data");
            mImageView.setImageBitmap(imageBitmap);
        }
    }
}

actiivity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.imslbd.firstcameraapp.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:id="@+id/txtDisplayName" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/btnButton"
        android:layout_below="@+id/txtDisplayName"
        android:layout_alignParentStart="true"
        android:onClick="ChangeName" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/btnButton"
        android:layout_marginTop="41dp">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageView"
            android:layout_gravity="center_vertical" />
    </LinearLayout>

</RelativeLayout>


-------------------------------------------------------

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.imslbd.firstcameraapp">

    <uses-feature android:name="android.hardware.camera"  android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Dynamically enumerate properties from a class

//Let's have a class first- 
public class Student
{
    public int StudentId { get; set; }
    public string StudentName { get; set; }
}


using System;
using System.Collections.Generic;
using System.Reflection;

//In case of single object
-----------------------------
void EnumerateField<T>(T t)
{
    PropertyInfo[] props = typeof(T).GetProperties();
    foreach (PropertyInfo property in props)
    {
        string propertyName = property.Name.ToString();
        string propertyType = property.PropertyType.ToString();
        string propertyValue = property.GetValue(t).ToString();
    }
}

//Usage-
Student student = new Student() { StudentId = 100, StudentName = "Shindhu-100" };
EnumerateField(student);


//In case of list<T>
-----------------------------------
void EnumerateFields<T>(List<T> ListOfT)
{
    PropertyInfo[] props = typeof(T).GetProperties();
    foreach (var t in ListOfT)
    {
        foreach (PropertyInfo property in props)
        {
            string propertyName = property.Name.ToString();
            string propertyType = property.PropertyType.ToString();
            string propertyValue = property.GetValue(t).ToString();
        }
    }
}

//Usage-
List<Student> students = new List<Student>();
students.Add(new Student() { StudentId = 1, StudentName = "a" });
students.Add(new Student() { StudentId = 2, StudentName = "b" });
Student st = new Student() { StudentId = 100, StudentName = "Shindhu-100" };
students.Add(st);
EnumerateFields<Student>(students);