A new image library for Android ?


A new image library for Android:

https://code.facebook.com/posts/366199913563917/introducing-fresco-a-new-image-library-for-android/

Fresco offers features that Picasso, UIL, and Glide do not yet have:

1. Images aren’t stored in the Java heap, but in the ashmem heap. Intermediate byte buffers are also stored in the native heap. This leaves a lot more memory available for applications to use. It reduces the risk of OutOfMemoryErrors. It also reduces the amount of garbage collection apps have to do, leading to better performance.

2.  Progressive JPEG images can be streamed, just like in a web browser.

3.  Images can be cropped around any point, not just the centre.

4.  JPEG images can be resized natively. This avoid the problem of OOMing while trying to downsize an image.

 

 

 

 

 

 

Advertisements

MVP Pattern Android ?


In large applications, it’s essential to organize your code very well. MVP allows you to separate business logic from presentation layer. MVP makes views independent from our data source. In Android, activities and data mechanism will be tightly coupled . With MVP we are able to take most of logic out from the activities so that we can test it without using instrumentation tests.

mvp

Presenter:

Presenter contains the UI business logic for the View and a middle man that talks to the View and the Model. The Presenter is also decoupled directly from the View and talks to it through an interface, this is to allow mocking of the View in a unit test.

View :

This view will implemented by Activity or Fragment will contain the reference to Presenter.

Model:

This is provider of the data we want to display in the view.

Implement MVP pattern:

1. Creating an presenter interface

2. Implementation for presenter – As UI logic will be implemented in this PresenterImpl.

3. Create an view interface- where activities or fragements implements this interface

 

References:

1. http://antonioleiva.com/mvp-android/

 

Android Samples at GitHuB


I would like to share my one of the samples I have worked on.

1. https://github.com/rameshkec85/GCMServerTest

This project will allow you test push notifications are working correctly or not at client side.
In order to run this project, we need to follow the below stpes:
i. Simply add server api key
ii. Add a registration id available when app is being registred to GCM server.

2. https://github.com/rameshkec85/uploadservicedemo

This project demonstrates how to upload a file or download a files in a Queue manner where most of the applications are following this pattern.

Notes:
i. Pool is one so that at a one request can be placed or executed.
ii. Using EvenBus to take the advantages of it’s subscribe and post method.

3. https://github.com/rameshkec85/AndroidCropMoveScaleImage

This project demonstrates that crop a image within the box, without moving overlay.
This is result of combination of Cropper library and PhotoView. But added little work to achieve this.

Avoiding the Casting noise in Adapter


For recycling the views, we follow the holder set and get tag methods and need to cast every component . For avoiding noise , have to follow this pattern . This could be helpful in code seems more clean up.

@Override
public View getView(int position, View convertView, ViewGroup parent) {

 if (convertView == null) {
// if it's not recycled, initialize some attributes
//
  LayoutInflater inflater = (LayoutInflater) m_Context
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  convertView = inflater.inflate(R.layout.main, null,false);
 }
 ImageView image=ViewHolderPattern.get(convertView,R.id.alarm_icon/*ImageView resid*/);

 TextView image=ViewHolderPattern.get(convertView,R.id.title/*TextView resid*/);
 return convertView;
}

//
public static class ViewHolderPattern {
// I added a generic return type to reduce the casting noise in client
// code
@SuppressWarnings("unchecked")
public static T get(View view, int resId) {

 SparseArray viewHolder = (SparseArray) view.getTag();
 if (viewHolder == null) {
 viewHolder = new SparseArray();
 view.setTag(viewHolder);
 }
 View childView = viewHolder.get(resId);

 if (childView == null) {
 childView = view.findViewById(resId);
 viewHolder.put(resId, childView);
 }
 return (T) childView;
 }
}

Note: Thanks to Pierre-Yves Ricau . I think this post is worth in sharing .

FragmentTabHost in Android with Bottom Tabs


FragmentTabHost in Android with Bottom Tabs

This is example shows how to use FragmentTabhost in android. 

  1. Withing Fragment

  2. Using in FragmentActivity

  3. Tabs at Bottom. (New)

    Most of the developers are facing this problem, I finally got the solution after i spent a few hours on it.It would be helpful to face this who r trying to make iphone like tabs(Bottom Tabs Feature ).

How to display the pdf in Android ?


Quick start incorporating a PDF viewing activity into your project:

1) Add PdfViewer.jar into your project’s build path

2) Copy the following drawable resources from PdfViewer/res/drawable into YourProject/res/drawable left_arrow.png right_arrow.png zoom_in.png zoom_out.png

3) Copy the following layout resources from PdfViewer/res/layout into YourProject/res/layout dialog_pagenumber.xml pdf_file_password.xml

4) Derive your PDF activity from net.sf.andpdf.pdfviewer.PdfViewerActivity

5) Using the default drawables and layouts:


public int getPreviousPageImageResource() { return R.drawable.left_arrow; }

public int getNextPageImageResource() { return R.drawable.right_arrow; }

public int getZoomInImageResource() { return R.drawable.zoom_in; }

public int getZoomOutImageResource() { return R.drawable.zoom_out; }

public int getPdfPasswordLayoutResource() { return R.layout.pdf_file_password; }

public int getPdfPageNumberResource() { return R.layout.dialog_pagenumber; }

public int getPdfPasswordEditField() { return R.id.etPassword; }

public int getPdfPasswordOkButton() { return R.id.btOK; }

public int getPdfPasswordExitButton() { return R.id.btExit; }

public int getPdfPageNumberEditField() { return R.id.pagenum_edit; }

6) Invoke your PdfViewActivity derived with the following code:


Intent intent = new Intent(this, YourPdfViewerActivity.class);

intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "PATH TO PDF GOES HERE");

startActivity(intent);

Download the source code and demo code from below link here

 

 

EDIT:  Another pdf viewer source for free  at github.

https://github.com/rameshakulapc/PDFViewer

Find the reference  Post by Andhradroid.

How to implement swipe delete in android like iphone ?


Step 1: Just extends below class and implement getListview method.

Step 2: The below MainActivity demonstrates in which direction single item should be swiped and gives the item position of clicked item. We have to manage it in adapter to swipe-delete operation from our own scratch.

SwipeListViewActivity.java:

public abstract class SwipeListViewActivity extends Activity {

private ListView list;
private int REL_SWIPE_MIN_DISTANCE;
private int REL_SWIPE_MAX_OFF_PATH;
private int REL_SWIPE_THRESHOLD_VELOCITY;

/**
*
* @return ListView
*/
public abstract ListView getListView();

/**
*
* @param isRight
* Swiping direction
* @param position
* which item position is swiped
*/
public abstract void getSwipeItem(boolean isRight, int position);

/**
* For single tap/Click
*
* @param adapter
* @param position
*/
public abstract void onItemClickListener(ListAdapter adapter, int position);

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

DisplayMetrics dm = getResources().getDisplayMetrics();
REL_SWIPE_MIN_DISTANCE = (int) (120.0f * dm.densityDpi / 160.0f + 0.5);
REL_SWIPE_MAX_OFF_PATH = (int) (250.0f * dm.densityDpi / 160.0f + 0.5);
REL_SWIPE_THRESHOLD_VELOCITY = (int) (200.0f * dm.densityDpi / 160.0f + 0.5);
}

@Override
protected void onResume() {
super.onResume();
list = getListView();
if (list == null) {
new Throwable("Listview not set exception");
}

@SuppressWarnings("deprecation")
final GestureDetector gestureDetector = new GestureDetector(
new MyGestureDetector());

View.OnTouchListener gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
};
list.setOnTouchListener(gestureListener);

}

private void myOnItemClick(int position) {
if (position < 0)
return;
onItemClickListener(list.getAdapter(), position);

}

class MyGestureDetector extends SimpleOnGestureListener {

private int temp_position = -1;

// Detect a single-click and call my own handler.
@Override
public boolean onSingleTapUp(MotionEvent e) {

int pos = list.pointToPosition((int) e.getX(), (int) e.getY());
myOnItemClick(pos);
return true;
}

@Override
public boolean onDown(MotionEvent e) {

temp_position = list
.pointToPosition((int) e.getX(), (int) e.getY());
return super.onDown(e);
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (Math.abs(e1.getY() - e2.getY()) > REL_SWIPE_MAX_OFF_PATH)
return false;
if (e1.getX() - e2.getX() > REL_SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > REL_SWIPE_THRESHOLD_VELOCITY) {

int pos = list
.pointToPosition((int) e1.getX(), (int) e2.getY());

if (pos >= 0 && temp_position == pos)
getSwipeItem(false, pos);
} else if (e2.getX() - e1.getX() > REL_SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > REL_SWIPE_THRESHOLD_VELOCITY) {

int pos = list
.pointToPosition((int) e1.getX(), (int) e2.getY());
if (pos >= 0 && temp_position == pos)
getSwipeItem(true, pos);

}
return false;
}

}

}
<h3>

MainActivity.java:

public class MainActivity extends SwipeListViewActivity {

private ListView mListView;
 private ArrayAdapter<String> mAdapter;

@Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 mListView = (ListView) findViewById(R.id.listView1);
 mAdapter = new ArrayAdapter<String>(this,
 android.R.layout.simple_list_item_1, new String[] { "Item 1",
 "Item 2", "Item 2", "Item 3", "Item 4", "Item 5" });
 mListView.setAdapter(mAdapter);
 }

@Override
 public ListView getListView() {
 return mListView;
 }

@Override
 public void getSwipeItem(boolean isRight, int position) {
 Toast.makeText(this,
 "Swipe to " + (isRight ? "right" : "left") + " direction",
 Toast.LENGTH_SHORT).show();
 }

@Override
 public void onItemClickListener(ListAdapter adapter, int position) {
 Toast.makeText(this, "Single tap on item position " + position,
 Toast.LENGTH_SHORT).show();
 }

}

Get the source code from the following link .
Let you comment on posts and encourage me for nice posts in future…


This post is very impressed me. It saves a lot of time .Thanks for this post.

Can't talk, computing...

In the recent past I was struggling to get my 1000+ bookmarks organized(folders and sub folders and subsubfolders and on..).

I tend to accumulate every little piece of interesting thing I find on the interweb.
I asked my social-contacts what should I do with too much bookmarks, how to deal with them, how to organized them.
Answers varied from “delete them!” to “You must be organized!” and even to “Bookmarks?”

Yeah, why bookmarks? All in all, I don’t feel like they helped me that much since the web become so full of contents.

And then I searched a little bit and found this page, that kind of pretty much answered my question about the need of bookmarks, and their purpose. They even mention Delicious, that I thought exinct!
I’m the one who tends to bookmark sites to “save” their content.

For time (even before asking my social-contacts) I…

View original post 244 more words