Skip to content

Instantly share code, notes, and snippets.

@enyachoke
Last active August 29, 2015 14:03
Show Gist options
  • Save enyachoke/84000c94e0d645e22cbc to your computer and use it in GitHub Desktop.
Save enyachoke/84000c94e0d645e22cbc to your computer and use it in GitHub Desktop.
Android bootcamp gists
public class QuoteAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mInflator;
private DataSource mDataSource;
public QuoteAdapter(Context c) {
mContext = c;
mInflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mDataSource = new DataSource();
}
@Override
public int getCount() {
return mDataSource.getDataSourceLength();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView thumbnail;
TextView quote;
if(convertView == null) {
convertView = mInflator.inflate(R.layout.list_item_layout, parent, false);
}
thumbnail = (ImageView) convertView.findViewById(R.list.thumb);
thumbnail.setImageResource(mDataSource.getmPhotoPool().get(position));
quote = (TextView) convertView.findViewById(R.list.text);
quote.setText(mDataSource.getmQuotePool().get(position));
return convertView;
}
}
mListView = (ListView) findViewById(R.id.quotes_list);
mListView.setAdapter(new QuoteAdapter(this));
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
Intent i = new Intent(QuoteReaderActivity.this, QuoteDetail.class);
i.putExtra("position", position);
startActivity(i);
}
});
import java.util.ArrayList;
public class DataSource {
private ArrayList<Integer> mPhotoPool;
private ArrayList<Integer> mQuotePool;
private ArrayList<Integer> mPhotoHdPool;
public ArrayList<Integer> getmPhotoHdPool() {
return mPhotoHdPool;
}
public ArrayList<Integer> getmPhotoPool() {
return mPhotoPool;
}
public ArrayList<Integer> getmQuotePool() {
return mQuotePool;
}
private void setupPhotoPool() {
mPhotoPool.add(R.drawable.steve_1);
mPhotoPool.add(R.drawable.steve_2);
mPhotoPool.add(R.drawable.steve_3);
mPhotoPool.add(R.drawable.steve_4);
mPhotoPool.add(R.drawable.steve_5);
mPhotoPool.add(R.drawable.steve_6);
mPhotoPool.add(R.drawable.steve_7);
mPhotoPool.add(R.drawable.steve_8);
mPhotoPool.add(R.drawable.steve_9);
mPhotoPool.add(R.drawable.steve_10);
}
private void setupQuotePool() {
mQuotePool.add(R.string.quote_1);
mQuotePool.add(R.string.quote_2);
mQuotePool.add(R.string.quote_3);
mQuotePool.add(R.string.quote_4);
mQuotePool.add(R.string.quote_5);
mQuotePool.add(R.string.quote_6);
mQuotePool.add(R.string.quote_7);
mQuotePool.add(R.string.quote_8);
mQuotePool.add(R.string.quote_9);
mQuotePool.add(R.string.quote_10);
}
private void setupPhotoHDPool() {
mPhotoHdPool.add(R.drawable.steve_hd_1);
mPhotoHdPool.add(R.drawable.steve_hd_2);
mPhotoHdPool.add(R.drawable.steve_hd_3);
mPhotoHdPool.add(R.drawable.steve_hd_4);
mPhotoHdPool.add(R.drawable.steve_hd_5);
mPhotoHdPool.add(R.drawable.steve_hd_6);
mPhotoHdPool.add(R.drawable.steve_hd_7);
mPhotoHdPool.add(R.drawable.steve_hd_8);
mPhotoHdPool.add(R.drawable.steve_hd_9);
mPhotoHdPool.add(R.drawable.apple_hd);
}
public int getDataSourceLength() {
return mPhotoPool.size();
}
public DataSource() {
mPhotoPool = new ArrayList<Integer>();
mQuotePool = new ArrayList<Integer>();
mPhotoHdPool = new ArrayList<Integer>();
setupPhotoPool();
setupQuotePool();
setupPhotoHDPool();
}
}
public class Fish {
private String mSpecies;
private String mColor;
private int mSize;
Fish() {
// generic fish
mSpecies = "unknown";
mColor = "unknown";
mSize = 0;
}
Fish(String species, String color, int size) {
mSpecies = species;
mColor = color;
mSize = size;
}
public void eat() {
// eat some algae
};
public void eat(Fish fishToEat) {
// eat another fish!
};
public void sleep() {
// sleep
};
public void makeBabyFish(Fish fishSpouse, int numBabies) {
// Make numBabies worth of baby fish with Fish spouse
};
}
public class FreshwaterFish extends Fish
{
private void lake(){
}
private void pound(){
}
private void river(){
}
}
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
public class QuoteDetail extends Activity {
private ImageView mImageView;
private TextView mQuote;
private int mPosition;
private DataSource mDataSource;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.quote_detail);
Intent i = getIntent();
mPosition = i.getIntExtra("position", 0);
mDataSource = new DataSource();
mImageView = (ImageView) findViewById(R.detail.image);
mQuote = (TextView) findViewById(R.detail.quote);
mImageView.setImageResource(mDataSource.getmPhotoHdPool().get(mPosition));
mQuote.setText(getResources().getString(mDataSource.getmQuotePool().get(mPosition)));
}
}
public class SaltWaterFish extends Fish{
@Override
public void makeBabyFish(Fish fishSpouse, int numBabies) {
// call parent method
super.makeBabyFish(fishSpouse, numBabies);
// eat mate
eat(fishSpouse);
}
public void sea(){
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, QuoteReaderActivity!</string>
<string name="app_name">QuoteReader</string>
<string name="quote_1">Innovation distinguished between a leader and a follower</string>
<string name="quote_2">I want to put a ding in the universe!</string>
<string name="quote_3">People don\'t know what they want until you show it to them.</string>
<!-- add rest of quotes, up to quote_10 -->
<string name="quote_4">The only way to be truly satisfied is to do what you believe is great work.</string>
<string name="quote_5">That\'s been one of my mantras -- focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it\'s worth it in the end because once you get there, you can move mountains.</string>
<string name="quote_6">Great things in business are never done by one person, they\'re done by a team of people.</string>
<string name="quote_7">You can\'t connect the dots looking forward; you can only connect them looking backward.</string>
<string name="quote_8">Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work.</string>
<string name="quote_9">I\'m the only person I know that\'s lost a quarter of a billion dollars in one year. ... It\'s very character-building.</string>
<string name="quote_10">It\'s more fun to be a pirate than join the Navy.</string>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment