Android uses open-source libraries to load network images

Source: Internet
Author: User

Android uses open-source libraries to load network images

Android uses open-source libraries to load network images and open-source libraries to load images. Click the pop-up popupwindow dialog box in listview to View Details:

Android clicks the listview pop-up popupwindow pop-up box, and the right-sliding delete button is also included in the box. For details, see: Android uses NineOldAndroids to implement a left-sliding display of the delete itembutton like listview. This way, the project becomes more complex. It gradually adds functions, effects, and code to the project.

 

Project source code: Click

I. view the implementation results

 

Ii. Project Structure

 

Iii. Some source code

1. MyApplication inherits Application

 

Package com. main. listviewsideslip; import java. io. file; import com. nostra13.universalimageloader. cache. disc. impl. unlimitedDiskCache; import com. nostra13.universalimageloader. cache. disc. naming. hashCodeFileNameGenerator; import com. nostra13.universalimageloader. cache. disc. naming. md5FileNameGenerator; import com. nostra13.universalimageloader. cache. memory. impl. lruMemoryCache; import com. nostra13.universalimageloader. cache. memory. impl. usingFreqLimitedMemoryCache; import com. nostra13.universalimageloader. core. displayImageOptions; import com. nostra13.universalimageloader. core. imageLoader; import com. nostra13.universalimageloader. core. imageLoaderConfiguration; import com. nostra13.universalimageloader. core. assist. queueProcessingType; import com. nostra13.universalimageloader. core. decode. baseImageDecoder; import com. nostra13.universalimageloader. core. download. baseImageDownloader; import com. nostra13.universalimageloader. utils. storageUtils; import android. app. application; import android. content. context; public class MyApplication extends Application {public void onCreate () {super. onCreate (); initImageLoader (getApplicationContext ();} public static void initImageLoader (Context context) {// File cacheDir = StorageUtils. getOwnCacheDirectory (context, imageloader/Cache); ImageLoaderConfiguration config = new ImageLoaderConfiguration. builder (context ). memoryCacheExtraOptions (480,800) // max width, max height, that is, the maximum length and width of each cached file. threadPoolSize (3) // Number of threads loaded in the thread pool. threadPriority (Thread. NORM_PRIORITY-2 ). denyCacheImageMultipleSizesInMemory (). diskCacheFileNameGenerator (new Md5FileNameGenerator () // encrypt the URI name stored with MD5. memoryCache (new UsingFreqLimitedMemoryCache (2*1024*1024) // You can pass your own memory cache implementation/You can implement it through your own memory cache. memoryCacheSize (2*1024*1024) // maximum value of the memory cache. diskCacheSize (50*1024*1024) // maximum cached value of 50 Mb SD card (local. tasksProcessingOrder (QueueProcessingType. LIFO) // The original discCache-> diskCache. diskCache (new UnlimitedDiskCache (cacheDir) // customize the cache path. imageDownloader (new BaseImageDownloader (context, 5*1000, 30*1000) // connectTimeout (5 s), readTimeout (30 s) Timeout time. writeDebugLogs () // Remove for release app. build (); // initialize the ImageLoader configuration globally. getInstance (). init (config );}}

2. The network loading configuration is also set in the adapter RecentAdapter.

 

 

Package com. listview. adapter; import java. util. permission list; import android. content. context; import android. view. layoutInflater; import android. view. view; import android. view. view. onClickListener; import android. view. viewGroup; import android. widget. baseAdapter; import android. widget. button; import android. widget. imageView; import android. widget. textView; import com. main. entity. recentItem; import com. main. listviewsideslip. constants; import com. main. listviewsideslip. r; import com. nostra13.universalimageloader. core. displayImageOptions; import com. nostra13.universalimageloader. core. imageLoader; import com. nostra13.universalimageloader. core. display. roundedBitmapDisplayer; import com. view. listview. swipeListView; public class RecentAdapter extends BaseAdapter {private LayoutInflater mInflater; private comment list
 
  
MData; private SwipeListView mListView; private Context mContext; private DisplayImageOptions mOptions; // set the parameter public static String [] mImageUrls; // The image path private ImageLoader mImageLoader; // network image loading class public RecentAdapter (Context context, shortlist
  
   
Data, SwipeListView listview) {mContext = context; this. mInflater = LayoutInflater. from (mContext); mData = data; this. mListView = listview; mImageLoader = ImageLoader. getInstance (); initImageView ();} public void remove (int position) {if (position <mData. size () {mData. remove (position); notifyDataSetChanged () ;}} public void remove (RecentItem item) {if (mData. contains (item) {mData. remove (item); notifyDataSet Changed () ;}} public void addFirst (RecentItem item) {if (mData. contains (item) {mData. remove (item);} mData. addFirst (item); notifyDataSetChanged () ;}@ Overridepublic int getCount () {return mData. size () ;}@ Overridepublic Object getItem (int position) {return mData. get (position) ;}@ Overridepublic long getItemId (int position) {return position ;}@ Overridepublic View getView (final int position, View convertView, ViewGroup parent) {final RecentItem item = mData. get (position); ViewHolder vHolder = null; if (convertView = null) {convertView = mInflater. inflate (R. layout. recent_listview_item, null); vHolder = new ViewHolder (); vHolder. nameTV = (TextView) convertView. findViewById (R. id. recent_list_item_name); vHolder. numTV = (TextView) convertView. findViewById (R. id. unreadmsg); vHolder. headIV = (ImageView) convertView. FindViewById (R. id. icon); vHolder. deleteBtn = (Button) convertView. findViewById (R. id. recent_del_btn); convertView. setTag (vHolder);} else {vHolder = (ViewHolder) convertView. getTag ();} vHolder. nameTV. setText (item. getName ();/*** imageUrl: Specifies the Url of the image. imageView hosts the image's ImageView control options * DisplayImageOptions configuration file */mImageLoader. displayImage (mImageUrls [position], vHolder. headIV, mOptions); int num = item. getNew Num (); if (num> 0) {vHolder. numTV. setVisibility (View. VISIBLE); vHolder. numTV. setText (num +);} else {vHolder. numTV. setVisibility (View. GONE);} vHolder. deleteBtn. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {mData. remove (position); policydatasetchanged (); if (mListView! = Null) mListView. closeOpenedItems () ;}}); return convertView;} class ViewHolder {public TextView nameTV; public TextView numTV; public ImageView headIV; public Button deleteBtn ;}
  
 

 

 

3. How to call it is actually in the above adapter. Take a look at MainActivity.

 

Package com. main. listviewsideslip; import java. util. collections; import java. util. using list; import com. listview. adapter. recentAdapter; import com. main. entity. recentItem; import com. view. listview. baseSwipeListViewListener; import com. view. listview. swipeListView; import com. view. pop. actionItem; import com. view. pop. quickAction; import android. OS. bundle; import android. view. view; import android. widget. textView; import android. app. activity; import android. content. intent; public class MainActivity extends Activity {// listview adapter private RecentAdapter mAdapter; // listview data source public extends list
 
  
MRecentDatas; // custom listviewprivate SwipeListView mRecentListView; private TextView mEmpty; private int mClickItem =-1; // click item to bring up protected QuickAction mItemClickQuickAction = null; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); initView (savedInstanceState); initPop () ;}// when you click an item in listview, pop is displayed. The QuickAction implementation class inherits PopupWindowsprivate void initPop () {// sets ActionmItemClickQuickAction = new QuickAction (this, QuickAction. VERTICAL); ActionItem pointItem = new ActionItem (1, details, null); ActionItem areaItem = new ActionItem (2, Information 2, null); pointItem. setIcon (null); areaItem. setIcon (null); mItemClickQuickAction. addActionItem (pointItem); mItemClickQuickAction. addActionItem (areaItem); mItemClickQuickAction. setOnActionItemClickListener (new QuickAction. onActionItemClickListener () {@ Overridepublic void onItemClick (QuickAction source, int pos, int actionId) {if (pos = 0) {Intent intent = new Intent (source. getActionItemsGroup (). getContext (), ListViewItemShowActivity. class); RecentItem item = new RecentItem (); item = mRecentDatas. get (mClickItem); Bundle bundle = new Bundle (); // bundle. putString (HeadImg, mImageUrls [mClickItem]); bundle. putInt (NewNum, item. getNewNum (); bundle. putString (Name, item. getName (); intent. putExtras (bundle); startActivity (intent);} mItemClickQuickAction. dismiss () ;}}) ;}private void initView (Bundle savedInstanceState) {mRecentListView = (SwipeListView) findViewById (R. id. recent_listview); mRecentDatas = getRecentList (); mAdapter = new RecentAdapter (this, mRecentDatas, mRecentListView); mRecentListView. setAdapter (mAdapter); mEmpty = (TextView) findViewById (R. id. empty); mRecentListView. setEmptyView (mEmpty); mRecentListView. setSwipeListViewListener (new BaseSwipeListViewListener () {@ Overridepublic void onClickFrontView (View view, int position) {mClickItem = position; mItemClickQuickAction. show (view) ;}@ Overridepublic void onClickBackView (int position) {mRecentListView. closeOpenedItems (); // close the opened item} @ Overridepublic void onDismiss (int [] reverseSortedPositions) {for (int position: reverseSortedPositions) {mAdapter. remove (position) ;}});} public comment list
  
   
GetRecentList () {Response List
   
    
List = new external list
    
     
(); NameArray = getResources (). getStringArray (R. array. jazzy_javasts_ch); for (int I = 0; I <20; I ++) {// int icon = heads [I]; String name = nameArray [I]; int num = numArray [I]; RecentItem item = new RecentItem (name, 0, num); list. add (item);} Collections. sort (list); // return list in descending order;} public static int [] numArray = {67,423, 90, 12, 978,}; public static String [] nameArray = new String [21];}
    
   
  
 

 

4. Do not forget to configure network permissions and Applications in AndroidManifest. xml.

 

   
     
          
  
 

 

Related Articles:

1. Android uses NineOldAndroids to implement a left-sliding display of the imitation listview and delete the itembutton

2. In Android, click listview to bring up the popupwindow pop-up box.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.