Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void takePic(View v) {
}

public void chooseMeme(View view){
Intent popularMemeIntent = new Intent(MainActivity.this, MemeList.class);
Intent popularMemeIntent = new Intent(MainActivity.this, TemplateActivity.class);
startActivity(popularMemeIntent);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package madelyntav.c4q.nyc.memeproject;

public class Template {

private int _id;
private String _name;
private int _image;

public Template() {

}

public Template(int _id, String _name, int _image) {
this._id = _id;
this._name = _name;
this._image = _image;
}

public int get_id() {
return _id;
}

public void set_id(int _id) {
this._id = _id;
}

public String get_name() {
return _name;
}

public void set_name(String _name) {
this._name = _name;
}

public int get_image() {
return _image;
}

public void set_image(int _image) {
this._image = _image;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package madelyntav.c4q.nyc.memeproject;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import java.util.concurrent.ExecutionException;

public class TemplateActivity extends Activity {

ListView listView;
TemplateDBAsyncTask templateDBAsyncTask;
TemplateAdapter templateAdapter;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_meme_list);

listView = (ListView) findViewById(R.id.listView);
templateDBAsyncTask.execute();

try {
templateAdapter = new TemplateAdapter(this, templateDBAsyncTask.get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}

listView.setAdapter(templateAdapter);

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(TemplateActivity.this, EditPhoto.class);

//todo: select image from db and load
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package madelyntav.c4q.nyc.memeproject;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class TemplateAdapter extends BaseAdapter {

Context context;
List<Template> templates;
LayoutInflater layoutInflater;
ImageView memeImage;
TextView memeName;

public TemplateAdapter(Context context, List<Template> templates) {
this.context = context;
this.templates = templates;
}

@Override
public int getCount() {
return templates.size();
}

@Override
public Object getItem(int position) {
return templates.get(position);
}

@Override
public long getItemId(int position) {
return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
layoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.list_item, null);
memeImage = (ImageView) convertView.findViewById(R.id.memeImage);
memeName = (TextView) convertView.findViewById(R.id.memeName);
}

memeImage.setImageResource(templates.get(position).get_image());
memeName.setText(templates.get(position).get_name());

return convertView;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package madelyntav.c4q.nyc.memeproject;

import android.provider.BaseColumns;

public class TemplateContract {

public static final String PRIMARY_KEY = " PRIMARY KEY";
public static final String INT_TYPE = " INTEGER";
public static final String TEXT_TYPE = " TEXT";
public static final String COMMA_SEP = ",";

public static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + TemplateEntry.TABLE_NAME +
" (" +
TemplateEntry._ID + INT_TYPE + PRIMARY_KEY + COMMA_SEP +
TemplateEntry.COLUMN_NAME + TEXT_TYPE + COMMA_SEP +
TemplateEntry.COLUMN_IMAGE + INT_TYPE +
")";

public static final String SQL_DELETE_ENTRIES =
"DROP TABLE IF EXISTS " + TemplateEntry.TABLE_NAME;

public static abstract class TemplateEntry implements BaseColumns {
public static final String TABLE_NAME = "TEMPLATES";
//inherit _ID constant from BaseColumns for the unique id of each row
public static final String COLUMN_NAME = "NAME";
public static final String COLUMN_IMAGE = "IMAGE";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package madelyntav.c4q.nyc.memeproject;

import android.content.Context;
import android.os.AsyncTask;

import java.util.List;

public class TemplateDBAsyncTask extends AsyncTask<Void, Void, List<Template>> {

public Context mContext;

@Override
protected List<Template> doInBackground(Void... params) {
TemplateDBHandler handler = new TemplateDBHandler(mContext);
handler.insertTemplate("Actual Advice Mallard", R.drawable.actual_advice_mallard);
handler.insertTemplate("But That's None Of My Business", R.drawable.but_thats_none_of_my_business);
handler.insertTemplate("Creepy Condescending Wonka", R.drawable.creepy_condescending_wonka);
handler.insertTemplate("Skeptical Fry", R.drawable.futurama_fry);
handler.insertTemplate("Good Guy Greg", R.drawable.good_guy_greg);
handler.insertTemplate("Liam Neeson Taken", R.drawable.liam_neeson_taken);
handler.insertTemplate("One Does Not Simply", R.drawable.one_does_not_simply);
handler.insertTemplate("Scumbag Steve", R.drawable.scumbag_steve);
handler.insertTemplate("Shut Up And Take My Money", R.drawable.shut_up_and_take_my_money_fry);
handler.insertTemplate("Ten Guy", R.drawable.ten_guy);
handler.insertTemplate("The Most Interesting Man In The World", R.drawable.the_most_interesting_man_in_the_world);
handler.insertTemplate("Third World Skeptical Kid", R.drawable.third_world_skeptical_kid);
handler.insertTemplate("Unhelpful High School Teacher", R.drawable.unhelpful_high_school_teacher);
handler.insertTemplate("Yao Ming", R.drawable.yao_ming);
handler.insertTemplate("You The Real MVP", R.drawable.you_the_real_mvp);
return handler.loadTemplates();
}

@Override
protected void onPostExecute(List<Template> templates) {
super.onPostExecute(templates);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package madelyntav.c4q.nyc.memeproject;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import java.util.ArrayList;

public class TemplateDBHandler extends SQLiteOpenHelper {

private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "templates.db";

public TemplateDBHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(TemplateContract.SQL_CREATE_ENTRIES);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(TemplateContract.SQL_DELETE_ENTRIES);
onCreate(db);
}

public void insertTemplate(String name, int image) {
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put(TemplateContract.TemplateEntry.COLUMN_NAME, name);
values.put(TemplateContract.TemplateEntry.COLUMN_IMAGE, image);
db.insert(TemplateContract.TemplateEntry.TABLE_NAME, null, values);
db.close();
}

public void deleteTemplate(Template template) {
SQLiteDatabase db = getWritableDatabase();
db.execSQL("DELETE FROM " + TemplateContract.TemplateEntry.TABLE_NAME + " WHERE " + TemplateContract.TemplateEntry.COLUMN_NAME + "=\"" + template.get_name() + "\";");
}

public ArrayList<Template> loadTemplates() {

String[] projection = {
TemplateContract.TemplateEntry._ID,
TemplateContract.TemplateEntry.COLUMN_NAME,
TemplateContract.TemplateEntry.COLUMN_IMAGE
};

SQLiteDatabase db = getWritableDatabase();

ArrayList<Template> templates = new ArrayList<Template>();

Cursor cursor = db.query(TemplateContract.TemplateEntry.TABLE_NAME, projection, null, null, null, null, TemplateContract.TemplateEntry.COLUMN_NAME + " ASC");
while (cursor.moveToNext()) {
templates.add(
new Template(
cursor.getInt(cursor.getColumnIndex(TemplateContract.TemplateEntry._ID)),
cursor.getString(cursor.getColumnIndex(TemplateContract.TemplateEntry.COLUMN_NAME)),
cursor.getInt(cursor.getColumnIndex(TemplateContract.TemplateEntry.COLUMN_IMAGE))
)
);
}

cursor.close();

return templates;
}

}