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 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

3 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. 3 Mobile Devices Today

4 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. 4 Android Evolution

5 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. 5 Android in a Glance Android SDK Dalvik Eclipse vs. Android Studio ADT Debug & Testing Tools DDMS Open Source Libraries

6 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. 6 Android Step by Step

7 7 Android Step by Step Create an Android Project

8 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. 8 Android Step by Step Project Architecture Manifest File <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mentormate.java2days" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.mentormate.java2days.MainActivity" android:label="@string/app_name" >

9 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. 9 Android Step by Step MainActivity & main_layuout Show main screen without anything in it Add Volley and gson libs

10 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. 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 mDiskCache; @Override 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 (10); @Override public void putBitmap(String url, Bitmap bitmap) {..} @Override public Bitmap getBitmap(String url) {...} }; mDiskCache = new ImageLoader.ImageCache() { private final DiskBasedCache mCache = new iskBasedCache(getCacheDir(), Constants.DEFAULT_MAX_CACHE_LIMIT); @Override public void putBitmap(String url, Bitmap bitmap) {...} @Override 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 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. 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 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. 12 Android Step by Step List View MainActivity public class MainActivity extends Activity { private ListView mListView; protected GalleryAdapter mAdapter; private RequestQueue mQueue; private MenuItem refreshItem; @Override 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); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.volley, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_refresh: refreshItem = item; refresh(); break; default: break; } return true; }

13 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. 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() {...} @Override 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 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. 14 Android Step by Step Refresh Button Animation <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromDegrees="0" android:interpolator="@android:anim/linear_interpolator" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360" /> 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 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. 15 Android Step by Step Navigate to the Second screen DetailsActivity v.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(mContext, DetailsActivity.class); intent.putExtra("image_url", result.getUrl()); mContext.startActivity(intent); } }); /** * * @author MentorMate LLC. 2013 * */ public class DetailsActivity extends Activity { private NetworkImageView ivImage; private ProgressBar mLoadingBar; @Override 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 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. 16 Android Step by Step Add Progress loader Details layout <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <ProgressBar android:id="@+id/loading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" /> <com.android.volley.toolbox.NetworkImageView android:id="@+id/image" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5dp" android:adjustViewBounds="true" android:scaleType="fitCenter" />

17 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. 17 Android Step by Step Talk about resources (dimensions, strings, styles) in more details if there is any time

18 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. 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