Skip to content

Instantly share code, notes, and snippets.

@Butch78
Created September 27, 2017 12:55
Show Gist options
  • Save Butch78/b52fed5257118538ffa44ba3c9b211a7 to your computer and use it in GitHub Desktop.
Save Butch78/b52fed5257118538ffa44ba3c9b211a7 to your computer and use it in GitHub Desktop.
ImageMetaDataEditor
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.matthew.imagemetadataeditor.form">
<ScrollView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="2dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView
android:id="@+id/imageNameTextView"
style="@style/Base.Theme.AppCompat.Light.Dialog.FixedSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/image_name"
android:textSize="30sp">
</TextView>
<EditText
android:id="@+id/nameText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext|flagNoEnterAction"
android:inputType="textMultiLine"
android:text=""
tools:ignore="LabelFor">
</EditText>
</TableRow>
<TableRow>
<TextView
android:id="@+id/imageLocationTextView"
style="@style/Base.Theme.AppCompat.Light.Dialog.FixedSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/location_taken">
</TextView>
<EditText
android:id="@+id/locationText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="textWebEmailAddress"
android:text=""
tools:ignore="LabelFor">
</EditText>
</TableRow>
</TableLayout>
<TextView
android:id="@+id/KeyWordsTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/keywords">
</TextView>
<EditText
android:id="@+id/keywordText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:text=""
tools:ignore="LabelFor">
</EditText>
<TextView
android:id="@+id/dateTakenTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:text="@string/date_taken">
</TextView>
<EditText
android:id="@+id/dateText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
tools:ignore="LabelFor">
</EditText>
<TextView
android:id="@+id/whoObtainedTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/who_obtained_this_image">
</TextView>
<TextView
android:id="@+id/shareText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Share" />
<ToggleButton
android:id="@+id/shareTgl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textOff="Share"
android:textOn="Share"
android:text="Share" />
<EditText
android:id="@+id/authorEmailText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/email_address"
android:inputType="textWebEmailAddress"
android:text=""
android:textColor="#ff0000">
</EditText>
<TextView
android:id="@+id/ratingTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rating">
</TextView>
<EditText
android:id="@+id/ratingText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:text=""
tools:ignore="LabelFor">
</EditText>
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="116dp"
android:onClick="submitButtonClickHandler"
android:text="@string/submit"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.039"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1" />
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.matthew.imagemetadataeditor.MainActivity">
<ScrollView
android:layout_width="368dp"
android:layout_height="503dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TableLayout
android:layout_width="368dp"
android:layout_height="503dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:src="@drawable/bed"
android:tag="0" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/blacony"
android:tag="1"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/frame"
android:tag="2"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView4"
android:layout_width="match_parent"
android:layout_height="150dp"
android:src="@mipmap/room"
android:tag="3"/>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</TableRow>
</TableLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
package com.example.matthew.imagemetadataeditor;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.view.View.OnFocusChangeListener;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Locale;
import java.util.regex.Pattern;
public class form extends Activity {
Photo photo;
Calendar myCalender = Calendar.getInstance();
Boolean correctInput = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form);
initializeUI();
checkUserInput();
}
private void initializeUI()
{
EditText photoNameText = (EditText) findViewById(R.id.nameText);
EditText locationText = (EditText) findViewById(R.id.locationText);
EditText keywordText = (EditText) findViewById(R.id.keywordText);
EditText dateTakenText = (EditText) findViewById(R.id.dateText);
EditText authorText = (EditText) findViewById(R.id.authorEmailText);
EditText ratingText = (EditText) findViewById(R.id.ratingText);
photoNameText.setOnFocusChangeListener(fcl);
locationText.setOnFocusChangeListener(fcl);
keywordText.setOnFocusChangeListener(fcl);
dateTakenText.setOnFocusChangeListener(fcl);
authorText.setOnFocusChangeListener(fcl);
ratingText.setOnFocusChangeListener(fcl);
Intent i = getIntent();
Photo myParcelableObject = i.getParcelableExtra("data");
photoNameText.setText(myParcelableObject.getImageName());
locationText.setText(myParcelableObject.getLocationTaken());
keywordText.setText(myParcelableObject.getKeywords());
dateTakenText.setText(myParcelableObject.getDateTaken());
authorText.setText(myParcelableObject.getAuthor());
ratingText.setText(myParcelableObject.getRating());
}
private void updateLabel() {
EditText dateInput = (EditText) findViewById(R.id.dateText);
String myFormat = "dd/MM/yy"; //In which you need put here
SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.ENGLISH);
dateInput.setText(sdf.format(myCalender.getTime()));
}
public void checkUserInput()
{
final EditText ratingInput = (EditText)findViewById(R.id.ratingText);
EditText dateInput = (EditText) findViewById(R.id.dateText);
final EditText nameInput = (EditText) findViewById(R.id.nameText);
Context context = getApplicationContext();
CharSequence toastText = "Please enter a Name";
int duration = Toast.LENGTH_SHORT;
final Toast toast = Toast.makeText(context, toastText, duration);
nameInput.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
if(nameInput.equals(""))
{
correctInput = false;
toast.show();
nameInput.setSelection(0);
}
}
});
final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener()
{
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
myCalender.set(Calendar.YEAR, year);
myCalender.set(Calendar.MONTH, monthOfYear);
myCalender.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel();
}
};
dateInput.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
new DatePickerDialog(form.this, date, myCalender
.get(Calendar.YEAR), myCalender.get(Calendar.MONTH),
myCalender.get(Calendar.DAY_OF_MONTH)).show();
}
});
ratingInput.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
String strRating = ratingInput.getText().toString();
if(!strRating.equals(""))
{
Double num = Double.parseDouble(strRating);
if(num < 1 | num > 5)
{
ratingInput.setText("");
correctInput = true;
ratingInput.setSelection(0);
}
else
correctInput = false;
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
}
OnFocusChangeListener fcl = new OnFocusChangeListener()
{
public void onFocusChange(View v, boolean hasFocus)
{
storePhotoDetails();
}
};
public void onBackPressed()
{
checkUserInput();
storePhotoDetails();
Intent resultIntent = new Intent();
ArrayList<Photo> dataList = new ArrayList<Photo>();
dataList.add(photo);
resultIntent.putParcelableArrayListExtra("PHOTO_INFO", dataList);
setResult(RESULT_OK, resultIntent);
super.onBackPressed();
}
public void submitButtonClickHandler(View v)
{
checkUserInput();
storePhotoDetails();
Intent resultIntent = new Intent();
ArrayList<Photo> dataList = new ArrayList<>();
dataList.add(photo);
resultIntent.putParcelableArrayListExtra("PHOTO_INFO", dataList);
setResult(RESULT_OK, resultIntent);
super.onBackPressed();
}
private void storePhotoDetails()
{
EditText photoNameText = (EditText) findViewById(R.id.nameText);
EditText locationText = (EditText) findViewById(R.id.locationText);
EditText keywordText = (EditText) findViewById(R.id.keywordText);
EditText dateTakenText = (EditText) findViewById(R.id.dateText);
EditText authorText = (EditText) findViewById(R.id.authorEmailText);
EditText ratingText = (EditText) findViewById(R.id.ratingText);
String photoName = photoNameText.getText().toString();
String location = locationText.getText().toString();
String keyword = keywordText.getText().toString();
String dateTaken = dateTakenText.getText().toString();
String author = authorText.getText().toString();
String rating = ratingText.getText().toString();
if(photo == null)
photo = new Photo(photoName,location, keyword, dateTaken, author, rating);
else
photo.update(photoName,location, keyword, dateTaken, author, rating);
}
}
package com.example.matthew.imagemetadataeditor;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import java.lang.reflect.Array;
import java.util.ArrayList;
public class MainActivity extends Activity {
private Photo[] DEFAULT_IMAGES = new Photo[4];
private int CURRENT_IMAGE = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("ACTIVITY-RESULT-Intent", "Matthew Rules");
createPhotos();
initializeUI();
}
private void createPhotos()
{
Photo bedPhoto = new Photo("Matthew", "https://www.google.com.au/maps/place/Corowa+NSW+2646/data=!4m2!3m1!1s0x6b212f896bbee329:0x40609b49043c9d0?sa=X&ved=0ahUKEwjE3_CgjMDWAhXFmpQKHXPEALEQ8gEIgwEwCw","Two Blondes and a boy", "22/12/1993", "Matthew@hotmail.com", "1" );
Photo balconyPhoto = new Photo("Lloyd","https://www.google.com.au/maps/place/Melbourne+VIC/data=!4m2!3m1!1s0x6ad646b5d2ba4df7:0x4045675218ccd90?sa=X&ved=0ahUKEwj5jOWZ_sHWAhVSQLwKHSugD7UQ8gEInwEwEg", "Beers with the boys", "10/10/2000", "AJ@hotmail.com", "4");
Photo framePhoto = new Photo("Steph", "https://www.google.com.au/maps/place/Sydney+NSW/@-33.8473552,150.6511087,10z/data=!3m1!4b1!4m5!3m4!1s0x6b129838f39a743f:0x3017d681632a850!8m2!3d-33.8688197!4d151.2092955", "Forget what this photo looks like", "10/12/1993", "Ted@hotmail.com","3");
Photo roomPhoto = new Photo("Ted", "https://www.google.com.au/maps/place/Seoul,+South+Korea/@37.565289,126.8491234,11z/data=!3m1!4b1!4m5!3m4!1s0x357ca28b61c565cd:0x858aedb4e4ea83eb!8m2!3d37.566535!4d126.9779692", "Dark hair", "26/09/2017", "Hannah@hotmail.com", "4");
DEFAULT_IMAGES[0] = bedPhoto;
DEFAULT_IMAGES[1] = balconyPhoto;
DEFAULT_IMAGES[2] = framePhoto;
DEFAULT_IMAGES[3] = roomPhoto;
}
private void initializeUI()
{
TextView bedText = (TextView) findViewById(R.id.textView);
TextView balconyText = (TextView) findViewById(R.id.textView2);
TextView frameText = (TextView) findViewById(R.id.textView3);
TextView roomText = (TextView) findViewById(R.id.textView4);
bedText.setText(DEFAULT_IMAGES[0].getPhotoInfo());
balconyText.setText(DEFAULT_IMAGES[1].getPhotoInfo());
frameText.setText(DEFAULT_IMAGES[2].getPhotoInfo());
roomText.setText(DEFAULT_IMAGES[3].getPhotoInfo());
ImageView bedPicture = (ImageView) findViewById(R.id.imageView);
ImageView balconyPicture = (ImageView) findViewById(R.id.imageView2);
ImageView framePicture = (ImageView) findViewById(R.id.imageView3);
ImageView roomPicture = (ImageView) findViewById(R.id.imageView4);
bedPicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imageClickHandler(v);
}
});
balconyPicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imageClickHandler(v);
}
});
framePicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imageClickHandler(v);
}
});
roomPicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imageClickHandler(v);
}
});
}
public void imageClickHandler(View v)
{
Intent i = new Intent(getApplicationContext(), form.class);
//i.putExtra("name_of_extra", myParcelableObject);
i.putExtra("data", DEFAULT_IMAGES[(Integer.parseInt((String)v.getTag()))]);
CURRENT_IMAGE = Integer.parseInt((String)v.getTag());
startActivityForResult(i, 0);
}
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
TextView bedText = (TextView) findViewById(R.id.textView);
TextView balconyText = (TextView) findViewById(R.id.textView2);
TextView frameText = (TextView) findViewById(R.id.textView3);
TextView roomText = (TextView) findViewById(R.id.textView4);
if(intent == null)
Log.i("ACTIVITY-RESULT-Intent", "IS NULL");
else{
Log.i("ACTIVITY-RESULT-Intent", "Has DATA");
ArrayList<Photo> photoData = intent.getParcelableArrayListExtra("PHOTO_INFO");
Photo p = photoData.get(0);
switch(CURRENT_IMAGE) {
case 0:
DEFAULT_IMAGES[0].update(p.getImageName(), p.getLocationTaken(), p.getKeywords(), p.getDateTaken(), p.getAuthor(), p.getRating());
bedText.setText(p.getPhotoInfo());
break;
case 1:
DEFAULT_IMAGES[1].update(p.getImageName(), p.getLocationTaken(), p.getKeywords(), p.getDateTaken(), p.getAuthor(), p.getRating());
balconyText.setText(p.getPhotoInfo());
break;
case 2:
DEFAULT_IMAGES[2].update(p.getImageName(), p.getLocationTaken(), p.getKeywords(), p.getDateTaken(), p.getAuthor(), p.getRating());
frameText.setText(p.getPhotoInfo());
break;
case 3:
DEFAULT_IMAGES[3].update(p.getImageName(), p.getLocationTaken(), p.getKeywords(), p.getDateTaken(), p.getAuthor(), p.getRating());
roomText.setText(p.getPhotoInfo());
default:
bedText.setText(p.getPhotoInfo());
}
}
}
}
package com.example.matthew.imagemetadataeditor;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.format.DateFormat;
/**
* Created by Matthew on 24/09/2017.
*/
public class Photo implements Parcelable
{
private String imageName;
private String locationTaken;
private String keywords;
private String dateTaken;
private String author;
private String rating;
public Photo(String imageName, String locationTaken, String keywords, String dateTaken, String author, String rating)
{
update(imageName, locationTaken, keywords, dateTaken, author, rating);
}
public void update(String imageName, String locationTaken, String keywords, String dateTaken, String author, String rating)
{
this.imageName = imageName;
this.locationTaken = locationTaken;
this.keywords = keywords;
this.dateTaken = dateTaken;
this.author = author;
this.rating = rating;
}
public String getImageName()
{
return imageName;
}
public String getLocationTaken()
{
return locationTaken;
}
public String getKeywords()
{
return keywords;
}
public String getDateTaken()
{
return dateTaken;
}
public String getAuthor()
{
return author;
}
public String getRating()
{
return rating;
}
public String getPhotoInfo()
{
String str = "Name: "+imageName;
str += "\nDate Taken: "+dateTaken;
return str;
}
public int describeContents() {return 0;}
public void writeToParcel(Parcel out, int flags)
{
out.writeString(imageName);
out.writeString(locationTaken);
out.writeString(keywords);
out.writeString(dateTaken);
out.writeString(author);
out.writeString(rating);
}
public static final Parcelable.Creator<Photo> CREATOR = new Parcelable.Creator<Photo>()
{
public Photo createFromParcel(Parcel in) { return new Photo(in);}
public Photo[] newArray(int size) { return new Photo[size];}
};
private Photo(Parcel in)
{
imageName = in.readString();
locationTaken = in.readString();
keywords = in.readString();
dateTaken = in.readString();
author = in.readString();
rating = in.readString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment