Presentation is loading. Please wait.

Presentation is loading. Please wait.

2 0 1 3 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 2 Android Application Step by Step Eleonora Todorova Boyan Iliev.

Similar presentations


Presentation on theme: "2 0 1 3 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 2 Android Application Step by Step Eleonora Todorova Boyan Iliev."— Presentation transcript:

1

2 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 2 Android Application Step by Step Eleonora Todorova Boyan Iliev

3 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 3 Mobile Devices Today

4 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 4 Android Evolution

5 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 5 Android in a Glance Android SDK Dalvik Eclipse vs. Android Studio ADT Debug & Testing Tools DDMS Open Source Libraries

6 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 6 Android Step by Step

7 7 Android Step by Step Create an Android Project

8 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 8 Android Step by Step Project Architecture Manifest File

9 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 9 Android Step by Step MainActivity & main_layuout Show main screen without anything in it Add Volley and gson libs

10 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 10 Android Step by Step Application class & App start point Application class public class LabsApp extends Application { private static Gson sGson; private static RequestQueue sRequestQueue; private static ImageLoader sImageLoader; private ImageLoader.ImageCache mImageCache; private ImageLoader.ImageCache public void onCreate() { super.onCreate(); // init everything sRequestQueue = Volley.newRequestQueue(getApplicationContext()); sGson = new Gson(); // super simple image cache mImageCache = new ImageLoader.ImageCache() { private final LruCache mCache = new LruCache public void putBitmap(String url, Bitmap bitmap) public Bitmap getBitmap(String url) {...} }; mDiskCache = new ImageLoader.ImageCache() { private final DiskBasedCache mCache = new iskBasedCache(getCacheDir(), public void putBitmap(String url, Bitmap bitmap) public Bitmap getBitmap(String url) {... return getBitmapFromBytes(entry.data); } // can't be simpler than this sImageLoader = new ImageLoader(sRequestQueue, Constants.USE_DISK_CACHE ? mDiskCache : mImageCache); } public static ImageLoader getImageLoader() {...} public static RequestQueue getRequestQueue() {...} public static Gson getGsonInstance() {...} }

11 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 11 Android Step by Step - B TBD Copy data classes & RegexUtils and show them briefly Implement Volley and gson – copy most of the content describing what it is

12 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 12 Android Step by Step List View MainActivity public class MainActivity extends Activity { private ListView mListView; protected GalleryAdapter mAdapter; private RequestQueue mQueue; private MenuItem protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_volley); mQueue = LabsApp.getRequestQueue(); mListView = (ListView) findViewById(android.R.id.list); refreshData(); } private void refreshData() {...} public void onStop() { super.onStop(); mQueue.cancelAll(Constants.TAG_IMAGE_REQUEST); public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.volley, menu); return true; public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_refresh: refreshItem = item; refresh(); break; default: break; } return true; }

13 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 13 Android Step by Step List View ListAdapter public class ListAdapter extends BaseAdapter { private Context mContext; private List mOriginalLis;...t public ListAdapter(Context context, List list) {...} public void loadMoreData() public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; ViewHolder viewHolder; if(v == null){ LayoutInflater inflater = (LayoutInflater) getContext(). getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = inflater.inflate(R.layout.list_item_photo_gallery, null, false); viewHolder = new ViewHolder(); if (v != null) { viewHolder.thumbnail = (NetworkImageView) v.findViewById(R.id.thumbnail); viewHolder.description = (TextView) v.findViewById(R.id.description); v.setTag(viewHolder); } } else { viewHolder = (ViewHolder) v.getTag(); } final Result result = mOriginalList.get(position); viewHolder.thumbnail.setDefaultImageResId(android.R.drawable.ic_menu_gallery); viewHolder.thumbnail.setErrorImageResId(android.R.drawable.ic_menu_delete); if (result != null) { if (Constants.USER_NETWORK_IMAGE_VIEWS) { viewHolder.thumbnail.setImageUrl(result.getTbUrl(), LabsApp.getImageLoader()); } else { requestImage(viewHolder.thumbnail, result.getTbUrl()); } viewHolder.description.setText(result.getTitleNoFormatting()); if(closeToEnd(position)) { loadMoreData(); } v.setOnClickListener(new OnClickListener() {…}); return v; } public void requestImage(final ImageView niv, final String imgUrl) {...} private boolean shouldLoadData(long position) {...} }

14 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 14 Android Step by Step Refresh Button Animation private void startAnimation() { /* Attach a rotating ImageView to the refresh item as an ActionView */ LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); ImageView iv = (ImageView) inflater.inflate(layout.action_refresh, null); Animation rotation = AnimationUtils.loadAnimation(this, anim.refresh_rotate); rotation.setRepeatCount(Animation.INFINITE); iv.startAnimation(rotation); if(refreshItem != null && iv != null) refreshItem.setActionView(iv); } private void stopAnimation() { if (refreshItem != null && refreshItem.getActionView() != null) { refreshItem.getActionView().clearAnimation(); refreshItem.setActionView(null); }

15 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 15 Android Step by Step Navigate to the Second screen DetailsActivity v.setOnClickListener(new OnClickListener() public void onClick(View v) { Intent intent = new Intent(mContext, DetailsActivity.class); intent.putExtra("image_url", result.getUrl()); mContext.startActivity(intent); } }); /** * MentorMate LLC * */ public class DetailsActivity extends Activity { private NetworkImageView ivImage; private ProgressBar protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_photo_details); mLoadingBar = (ProgressBar) findViewById(R.id.loading); ivImage = (NetworkImageView) findViewById(R.id.image); ivImage.setImageUrl(getIntent().getExtras().getString("image_url"), LabsApp.getImageLoader()); }

16 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 16 Android Step by Step Add Progress loader Details layout

17 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 17 Android Step by Step Talk about resources (dimensions, strings, styles) in more details if there is any time

18 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 18 QUESTIONS

19 Thank you!


Download ppt "2 0 1 3 M E N T O R M A T E, L L C. A L L R I G H T S R E S E R V E D. 2 Android Application Step by Step Eleonora Todorova Boyan Iliev."

Similar presentations


Ads by Google