http://blog.csdn.net/SunBo_Java/article/details/8234092
该Demo抛弃了ListView控件的使用,是直接使用ViewGroup或其子类进行多个子控件封装,从而达到修正多个附件同时下载时,列表中每个控件的显示错乱的问题(如有更好的方法,欢迎交流)。
该Demo采用单线程下载模式,因为项目的需求,所以一直没改。大家可以直接将单线程改为多线程同步,因为该Demo中所用到的适配器就是根据多线程同步而设计的。
下面我会给出整个Demo的完整范例,但没有程序源码,大家可以直接Copy,因为这是直接从我项目中的抽出来的,还请见谅!
好了,废话不多说,开始:
1,先看看适配器的每个Item布局
-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-
xmlns:tools="http://schemas.android.com/tools"
-
style="@style/width_fullscreen"
-
android:padding="7dp"
-
android:background="@drawable/list_selector_bg">
-
<TextView
-
android:id="@+id/AffixName"
-
style="@style/width_fullscreen"
-
android:textSize="17sp"
-
android:textStyle="bold"
-
android:maxLines="2"
-
android:drawablePadding="3.4dp"
-
android:layout_toLeftOf="@+id/AffixDownload" />
-
<TextView
-
android:id="@+id/AffixNotfoundFileErrormsg"
-
style="@style/width_fullscreen"
-
android:text="@string/download_notfoundfile_errormsg"
-
android:textSize="12sp"
-
android:textColor="@color/red"
-
android:layout_marginTop="5dp"
-
android:layout_marginLeft="20dp"
-
android:layout_marginRight="25dp"
-
android:drawableLeft="@drawable/message_status_fail"
-
android:layout_below="@+id/AffixName"
-
android:background="@drawable/popup"
-
android:visibility="gone" />
-
<Button
-
android:id="@+id/AffixDownload"
-
style="@style/width_height_free"
-
android:text="@string/download"
-
android:textColor="@color/DarkSlateGray"
-
android:paddingLeft="10.5dp"
-
android:paddingRight="10.5dp"
-
android:drawableRight="@drawable/icon_download_ics"
-
android:drawablePadding="3dp"
-
android:layout_alignParentRight="true"
-
android:layout_alignTop="@+id/AffixName"
-
android:background="@drawable/button_call_bg" />
-
<RelativeLayout
-
android:id="@+id/AffixDownloadProgressPanel"
-
style="@style/width_fullscreen"
-
android:layout_below="@+id/AffixDownload"
-
android:layout_marginTop="6.5dp"
-
android:visibility="gone">
-
<ProgressBar
-
android:id="@+id/AffixDownloadProgressbar"
-
style="?android:attr/progressBarStyleHorizontal"
-
android:layout_width="match_parent"
-
android:layout_height="13dp"
-
android:progressDrawable="@drawable/progressbar_background" />
-
<TextView
-
android:id="@+id/AffixDownloadProgressValue"
-
style="@style/width_height_free"
-
android:textSize="11sp"
-
android:textColor="@color/ghostwhite"
-
android:layout_centerHorizontal="true" />
-
</RelativeLayout>
-
</RelativeLayout>
2,对应的适配器类:
-
import java.io.File;
-
import java.util.List;
-
-
import android.content.Context;
-
import android.content.SharedPreferences;
-
import android.content.SharedPreferences.Editor;
-
import android.os.Bundle;
-
import android.os.Handler;
-
import android.os.Message;
-
import android.view.LayoutInflater;
-
import android.view.View;
-
import android.view.View.OnClickListener;
-
import android.view.ViewGroup;
-
import android.widget.Button;
-
import android.widget.ProgressBar;
-
import android.widget.RelativeLayout;
-
import android.widget.TextView;
-
-
import com.hwttnet.oa.mobile.aas.R;
-
import com.hwttnet.oa.mobile.app.App;
-
import com.hwttnet.oa.mobile.app.App.Shared;
-
import com.hwttnet.oa.mobile.listener.OnThreadListener;
-
import com.hwttnet.oa.mobile.service.ThreadService;
-
import com.hwttnet.oa.mobile.util.LocationDataProcess;
-
import com.hwttnet.oa.mobile.util.ViewUtil;
-
import com.hwttnet.other.model.AffixInfoBean;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public class AffixDownloadAdapter implements OnClickListener, OnThreadListener
-
{
-
private final Context context;
-
private final SharedPreferences affixShared;
-
-
private final ThreadService threadService = new ThreadService();
-
private final LocationDataProcess locationDateProcess;
-
-
private final ViewUtil mViewUtil;
-
-
public AffixDownloadAdapter(Context context)
-
{
-
this.context = context;
-
affixShared = context.getSharedPreferences(Shared.DOWNLOADAFFIXINFO, Context.MODE_PRIVATE);
-
threadService.setOnThreadListener(this);
-
locationDateProcess = new LocationDataProcess(context);
-
mViewUtil = new ViewUtil(context);
-
}
-
-
public void setupViews(ViewGroup mViewGroup, List<AffixInfoBean> affixs)
-
{
-
if(null == mViewGroup)
-
return;
-
if(mViewGroup.getChildCount() > 0)
-
mViewGroup.removeAllViews();
-
LayoutInflater layoutInflater = LayoutInflater.from(context);
-
for(AffixInfoBean affix : affixs)
-
{
-
ViewHolder mViewHolder = new ViewHolder();
-
mViewHolder.affix = affix;
-
mViewHolder.isOpen = false;
-
View convertView = layoutInflater.inflate(R.layout.affix_download_item, null);
-
mViewHolder.mAffixName = (TextView) convertView.findViewById(R.id.AffixName);
-
mViewHolder.mNotfoundFileErrormsg = (TextView) convertView.findViewById(R.id.AffixNotfoundFileErrormsg);
-
mViewHolder.mButton = (Button) convertView.findViewById(R.id.AffixDownload);
-
mViewHolder.mDownloadProgressPanel = (RelativeLayout) convertView.findViewById(R.id.AffixDownloadProgressPanel);
-
mViewHolder.mProgressBar = (ProgressBar) convertView.findViewById(R.id.AffixDownloadProgressbar);
-
mViewHolder.mDownloadProgressValue = (TextView) convertView.findViewById(R.id.AffixDownloadProgressValue);
-
String identityName = affix.getAffixId() + affix.getAffixName();
-
String key = identityName.substring(0, identityName.lastIndexOf("."));
-
String affixAbspath = affixShared.getString(key, null);
-
if(affixAbspath != null)
-
{
-
mViewHolder.mAffixName.setCompoundDrawablesWithIntrinsicBounds(R.drawable.result_ok, 0, 0, 0);
-
mViewHolder.mButton.setText(R.string.open);
-
mViewHolder.mButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.icon_open_file, 0);
-
mViewHolder.isOpen = true;
-
}
-
mViewHolder.mAffixName.setText(affix.getAffixName());
-
mViewHolder.mButton.setTag(mViewHolder);
-
mViewHolder.mButton.setOnClickListener(this);
-
mViewGroup.addView(convertView);
-
}
-
}
-
-
@Override
-
public void onClick(View v)
-
{
-
Object object = v.getTag();
-
if(object instanceof ViewHolder)
-
{
-
ViewHolder mViewHolder = (ViewHolder) object;
-
if(mViewHolder.isOpen)
-
{
-
AffixInfoBean affix = mViewHolder.affix;
-
String key = affix.getAffixId() + affix.getAffixName();
-
String affixAbspath = affixShared.getString(key.substring(0, key.lastIndexOf(".")), "");
-
File file = new File(affixAbspath);
-
if(!file.exists())
-
{
-
mViewHolder.mButton.setText(R.string.redownload);
-
mViewHolder.mButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.icon_download_ics, 0);
-
mViewHolder.mAffixName.setCompoundDrawablesWithIntrinsicBounds(R.drawable.attitude_falseinfo_icon, 0, 0, 0);
-
mViewUtil.showAnimView(mViewHolder.mNotfoundFileErrormsg);
-
mViewHolder.isOpen = false;
-
} else
-
switch(locationDateProcess.openFile(affixAbspath))
-
{
-
-
case 0:
-
break;
-
-
case -1:
-
break;
-
-
case -2:
-
App.makeText(context, R.string.find_no_editor);
-
break;
-
}
-
} else
-
if(!threadService.isAlive())
-
{
-
threadService.setTag(mViewHolder);
-
threadService.start();
-
} else
-
App.makeText(context, R.string.please_wait);
-
}
-
}
-
-
@Override
-
public void onRun(Handler mHandler)
-
{
-
ViewHolder mViewHolder = (ViewHolder) threadService.getTag();
-
String fileName = mViewHolder.affix.getAffixName();
-
String downloadUrl = mViewHolder.affix.getDownloadUrl();
-
locationDateProcess.download(mHandler, fileName, downloadUrl);
-
}
-
-
@Override
-
public void onResult(Message msg)
-
{
-
ViewHolder mViewHolder = (ViewHolder) threadService.getTag();
-
Bundle data = msg.getData();
-
int filesize = data.getInt("FILE_SIZE");
-
switch(msg.what)
-
{
-
-
case 0:
-
mViewHolder.mProgressBar.setProgress(filesize);
-
mViewHolder.mDownloadProgressValue.setText(R.string.download_ok);
-
mViewHolder.mAffixName.setCompoundDrawablesWithIntrinsicBounds(R.drawable.result_ok, 0, 0, 0);
-
mViewHolder.mButton.setText(R.string.open);
-
mViewHolder.mButton.setEnabled(true);
-
mViewHolder.mButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.icon_open_file, 0);
-
mViewHolder.isOpen = true;
-
String filePath = data.getString("FILE_CACHE_PATH");
-
Editor editor = affixShared.edit();
-
String key = mViewHolder.affix.getAffixId() + mViewHolder.affix.getAffixName();
-
editor.putString(key.substring(0, key.lastIndexOf(".")), filePath);
-
editor.commit();
-
break;
-
-
case 1:
-
mViewUtil.hideAnimView(mViewHolder.mNotfoundFileErrormsg, false);
-
mViewUtil.showAnimView(mViewHolder.mDownloadProgressPanel);
-
mViewHolder.mAffixName.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon_download_manage_downloading, 0, 0, 0);
-
mViewHolder.mProgressBar.setMax(filesize);
-
mViewHolder.mDownloadProgressValue.setText(R.string.start_download);
-
mViewHolder.mButton.setText(R.string.downloading);
-
mViewHolder.mButton.setEnabled(false);
-
break;
-
-
case 2:
-
int downProgress = data.getInt("DOWN_PROGRESS");
-
int progress = (int) ((((float) downProgress) / ((float) filesize)) * 100);
-
mViewHolder.mProgressBar.setProgress(downProgress);
-
mViewHolder.mDownloadProgressValue.setText(progress + "%");
-
break;
-
-
case -1:
-
mViewHolder.mAffixName.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon_download_manage_fail, 0, 0, 0);
-
mViewHolder.mDownloadProgressValue.setText(R.string.download_failed);
-
mViewHolder.mButton.setText(R.string.retry);
-
mViewHolder.mButton.setEnabled(true);
-
mViewHolder.isOpen = false;
-
break;
-
-
case -2:
-
mViewUtil.hideAnimView(mViewHolder.mDownloadProgressPanel, false);
-
mViewHolder.mAffixName.setCompoundDrawablesWithIntrinsicBounds(R.drawable.result_ok, 0, 0, 0);
-
mViewHolder.mButton.setText(R.string.open);
-
mViewHolder.mButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.icon_open_file, 0);
-
mViewHolder.mButton.setEnabled(true);
-
mViewHolder.isOpen = true;
-
String haveFilePath = data.getString("FILE_CACHE_PATH");
-
Editor haveEditor = affixShared.edit();
-
String haveKey = mViewHolder.affix.getAffixId() + mViewHolder.affix.getAffixName();
-
haveEditor.putString(haveKey.substring(0, haveKey.lastIndexOf(".")), haveFilePath);
-
haveEditor.commit();
-
App.makeText(context, R.string.file_already_exists);
-
break;
-
-
case -3:
-
mViewUtil.hideAnimView(mViewHolder.mDownloadProgressPanel, false);
-
App.makeText(context, R.string.download_failed);
-
break;
-
}
-
}
-
-
private final class ViewHolder
-
{
-
private TextView mAffixName;
-
private TextView mNotfoundFileErrormsg;
-
private Button mButton;
-
private RelativeLayout mDownloadProgressPanel;
-
private ProgressBar mProgressBar;
-
private TextView mDownloadProgressValue;
-
private boolean isOpen;
-
private AffixInfoBean affix;
-
}
-
}
类中所用到的其他相关类和方法:
1,ThreadService.java
-
import android.os.Handler;
-
import android.os.Message;
-
-
import com.hwttnet.oa.mobile.listener.OnThreadListener;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public final class ThreadService
-
{
-
private Thread thread;
-
private Object tag;
-
-
private OnThreadListener onThreadListener;
-
-
private final Handler mHandler = new Handler()
-
{
-
@Override
-
public void handleMessage(Message msg)
-
{
-
if (onThreadListener != null)
-
onThreadListener.onResult(msg);
-
}
-
};
-
-
-
-
-
-
-
-
-
public void start()
-
{
-
thread = new Thread()
-
{
-
@Override
-
public void run()
-
{
-
if (onThreadListener != null)
-
onThreadListener.onRun(mHandler);
-
}
-
};
-
thread.start();
-
}
-
-
-
-
-
-
-
public boolean isAlive()
-
{
-
if (thread != null)
-
return thread.isAlive();
-
return false;
-
}
-
-
-
-
-
-
-
-
public void setOnThreadListener(OnThreadListener onThreadListener)
-
{
-
this.onThreadListener = onThreadListener;
-
}
-
-
public Object getTag()
-
{
-
return tag;
-
}
-
-
public void setTag(Object tag)
-
{
-
this.tag = tag;
-
}
-
}
2,OnThreadListener.java
-
import android.os.Handler;
-
import android.os.Message;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public interface OnThreadListener
-
{
-
-
-
-
-
-
-
public void onRun(Handler mHandler);
-
-
-
-
-
-
-
-
public void onResult(Message msg);
-
}
3,LocationDataProcess.java
-
import java.io.BufferedOutputStream;
-
import java.io.File;
-
import java.io.FileOutputStream;
-
import java.io.IOException;
-
import java.io.InputStream;
-
import java.net.URL;
-
import java.net.URLConnection;
-
import java.text.SimpleDateFormat;
-
import java.util.Date;
-
import java.util.LinkedHashMap;
-
-
import android.content.ActivityNotFoundException;
-
import android.content.Context;
-
import android.content.Intent;
-
import android.content.SharedPreferences;
-
import android.content.SharedPreferences.Editor;
-
import android.content.res.Resources;
-
import android.net.Uri;
-
import android.os.Bundle;
-
import android.os.Handler;
-
import android.os.Message;
-
-
import com.hwttnet.oa.mobile.aas.R;
-
import com.hwttnet.oa.mobile.app.App;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public class LocationDataProcess
-
{
-
private final Context context;
-
-
-
-
-
public LocationDataProcess(Context context)
-
{
-
this.context = context;
-
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public void download(Handler mHandler, String fileName, String downloadUrl)
-
{
-
if (null == mHandler || null == downloadUrl)
-
{
-
this.sendMessage(mHandler, -1, 0, 0, null);
-
return;
-
}
-
try
-
{
-
int downProgress = 0;
-
URL url = new URL(downloadUrl);
-
URLConnection connection = url.openConnection();
-
connection.setConnectTimeout(1000 * 30);
-
connection.connect();
-
InputStream inputStream = connection.getInputStream();
-
int fileSize = connection.getContentLength();
-
if (fileSize < 1 || null == inputStream)
-
this.sendMessage(mHandler, -1, fileSize, downProgress, null);
-
else
-
{
-
this.sendMessage(mHandler, 1, fileSize, downProgress, null);
-
File downloadFolder = new File(App.AFFIXSTORAGEPATH);
-
if (!downloadFolder.exists())
-
downloadFolder.mkdirs();
-
File downloadFile = new File(downloadFolder.getAbsolutePath() + "/" + fileName);
-
if (downloadFile.exists())
-
this.sendMessage(mHandler, -2, fileSize, downProgress, downloadFile.getAbsolutePath());
-
else if (downloadFile.createNewFile())
-
{
-
byte[] buffer = new byte[1024 * 8];
-
int length = -1;
-
BufferedOutputStream bufferOutStream = new BufferedOutputStream(new FileOutputStream(downloadFile));
-
while ((length = inputStream.read(buffer)) != -1)
-
{
-
bufferOutStream.write(buffer, 0, length);
-
downProgress += length;
-
this.sendMessage(mHandler, 2, fileSize, downProgress, downloadFile.getAbsolutePath());
-
}
-
bufferOutStream.flush();
-
bufferOutStream.close();
-
inputStream.close();
-
this.sendMessage(mHandler, 0, fileSize, downProgress, downloadFile.getAbsolutePath());
-
} else
-
this.sendMessage(mHandler, -3, fileSize, downProgress, null);
-
}
-
-
} catch (IOException e)
-
{
-
e.printStackTrace();
-
this.sendMessage(mHandler, -1, 0, 0, null);
-
}
-
}
-
-
private void sendMessage(Handler mHandler, int msgWhat, int fileSize,
-
int downProgress, String imageFilePath)
-
{
-
Message msg = mHandler.obtainMessage();
-
msg.what = msgWhat;
-
Bundle data = msg.getData();
-
data.putInt("FILE_SIZE", fileSize);
-
data.putInt("DOWN_PROGRESS", downProgress);
-
data.putString("FILE_CACHE_PATH", imageFilePath);
-
mHandler.sendMessage(msg);
-
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public int openFile(String filePath)
-
{
-
File openFile = new File(filePath);
-
if (!openFile.exists())
-
return -1;
-
int openStauts = 0;
-
String filename = openFile.getName();
-
String suffixName = filename.substring(filename.lastIndexOf("."), filename.length());
-
try
-
{
-
Resources r = context.getResources();
-
String[] officEndingNames = r.getStringArray(R.array.FILEENDINGOFFIC);
-
for(String endingName : officEndingNames)
-
if(suffixName.equals(endingName))
-
context.startActivity(this.getDefaultFileIntent(openFile));
-
String[] mediaEndingNames = r.getStringArray(R.array.FILENDINGMEDIA);
-
for(String endingName : mediaEndingNames)
-
if(suffixName.equals(endingName))
-
context.startActivity(this.getMediaFileIntent(openFile));
-
String[] htmlEndingNames = r.getStringArray(R.array.FILEENDINGHTML);
-
for(String endingName : htmlEndingNames)
-
if(suffixName.equals(endingName))
-
context.startActivity(this.getHtmlFileIntent(openFile));
-
String[] packEndingNames = r.getStringArray(R.array.FILEENDINGPACK);
-
for(String endingName : packEndingNames)
-
if(suffixName.equals(endingName))
-
context.startActivity(this.getPackFileIntent(openFile));
-
} catch (ActivityNotFoundException e)
-
{
-
e.printStackTrace();
-
openStauts = -2;
-
}
-
return openStauts;
-
}
-
-
private Intent getDefaultFileIntent(File defaultFile)
-
{
-
Intent intent = new Intent(Intent.ACTION_VIEW);
-
intent.addCategory(Intent.CATEGORY_DEFAULT);
-
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
Uri uri = Uri.fromFile(defaultFile);
-
String filename = defaultFile.getName();
-
String suffixName = filename.substring(filename.lastIndexOf("."), filename.length());
-
intent.setDataAndType(uri, DT.get(suffixName));
-
return intent;
-
}
-
-
private Intent getHtmlFileIntent(File htmlFile)
-
{
-
Uri uri = Uri.parse(htmlFile.toString()).buildUpon().encodedAuthority("com.android.htmlfileprovider").scheme("content").encodedPath(htmlFile.toString()).build();
-
Intent intent = new Intent(Intent.ACTION_VIEW);
-
String filename = htmlFile.getName();
-
String suffixName = filename.substring(filename.lastIndexOf("."), filename.length());
-
intent.setDataAndType(uri, DT.get(suffixName));
-
return intent;
-
}
-
-
private Intent getMediaFileIntent(File audioFile)
-
{
-
Intent intent = new Intent(Intent.ACTION_VIEW);
-
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
-
intent.putExtra("oneshot", 0);
-
intent.putExtra("configchange", 0);
-
Uri uri = Uri.fromFile(audioFile);
-
String filename = audioFile.getName();
-
String suffixName = filename.substring(filename.lastIndexOf("."), filename.length());
-
intent.setDataAndType(uri, DT.get(suffixName));
-
return intent;
-
}
-
-
private Intent getPackFileIntent(File packFile)
-
{
-
Intent intent = new Intent();
-
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
intent.setAction(android.content.Intent.ACTION_VIEW);
-
Uri uri = Uri.fromFile(packFile);
-
String filename = packFile.getName();
-
String suffixName = filename.substring(filename.lastIndexOf("."), filename.length());
-
intent.setDataAndType(uri, DT.get(suffixName));
-
return intent;
-
}
-
-
private final LinkedHashMap<String, String> DT = new LinkedHashMap<String, String>();
-
{
-
-
DT.put(".png", "image/*");
-
DT.put(".gif", "image/*");
-
DT.put(".jpg", "image/*");
-
DT.put(".jpeg", "image/*");
-
DT.put(".bmp", "image/*");
-
-
DT.put(".mp3", "audio/*");
-
DT.put(".wav", "audio/*");
-
DT.put(".ogg", "audio/*");
-
DT.put(".midi", "audio/*");
-
-
DT.put(".mp4", "video/*");
-
DT.put(".rmvb", "video/*");
-
DT.put(".avi", "video/*");
-
DT.put(".flv", "video/*");
-
-
DT.put(".ppt", "application/vnd.ms-powerpoint");
-
DT.put(".pptx", "application/vnd.ms-powerpoint");
-
DT.put(".xls", "application/vnd.ms-excel");
-
DT.put(".xlsx", "application/vnd.ms-excel");
-
DT.put(".doc", "application/msword");
-
DT.put(".docx", "application/msword");
-
DT.put(".txt", "text/plain");
-
DT.put(".java", "text/plain");
-
DT.put(".c", "text/plain");
-
DT.put(".cpp", "text/plain");
-
DT.put(".py", "text/plain");
-
DT.put(".xml", "text/plain");
-
DT.put(".json", "text/plain");
-
DT.put(".log", "text/plain");
-
DT.put(".pdf", "application/pdf");
-
-
DT.put(".htm", "text/html");
-
DT.put(".html", "text/html");
-
DT.put(".php", "text/html");
-
DT.put(".jsp", "text/html");
-
-
DT.put(".jar", "application/vnd.android.package-archive");
-
DT.put(".zip", "application/vnd.android.package-archive");
-
DT.put(".rar", "application/vnd.android.package-archive");
-
DT.put(".gz", "application/vnd.android.package-archive");
-
DT.put(".apk", "application/vnd.android.package-archive");
-
DT.put(".img", "application/vnd.android.package-archive");
-
}
-
}
4,ViewUtil.java
-
import android.content.Context;
-
import android.os.Handler;
-
import android.view.View;
-
import android.view.animation.AnimationUtils;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public final class ViewUtil
-
{
-
private final Context context;
-
-
private View mView;
-
-
public ViewUtil(Context context)
-
{
-
this.context = context;
-
}
-
-
-
-
-
-
-
-
-
public boolean isShown(View view)
-
{
-
if (view.getVisibility() == View.VISIBLE)
-
return true;
-
return false;
-
}
-
-
-
-
-
-
-
-
public void showView(View view)
-
{
-
if (!this.isShown(view))
-
view.setVisibility(View.VISIBLE);
-
}
-
-
-
-
-
-
-
-
public void showAnimView(View view)
-
{
-
if (!this.isShown(view))
-
{
-
view.setAnimation(AnimationUtils.loadAnimation(context,
-
android.R.anim.fade_in));
-
view.setVisibility(View.VISIBLE);
-
}
-
}
-
-
-
-
-
-
-
-
-
-
public void showAnimView(View view, int id)
-
{
-
if (!this.isShown(view))
-
{
-
view.setAnimation(AnimationUtils.loadAnimation(context, id));
-
view.setVisibility(View.VISIBLE);
-
}
-
}
-
-
-
-
-
-
-
-
-
-
public void hideView(View view, boolean isKeepSeat)
-
{
-
if (this.isShown(view))
-
if (isKeepSeat)
-
view.setVisibility(View.INVISIBLE);
-
else
-
view.setVisibility(View.GONE);
-
}
-
-
-
-
-
-
-
-
-
-
public void hideAnimView(View view, boolean isKeepSeat)
-
{
-
if (this.isShown(view))
-
{
-
view.setAnimation(AnimationUtils.loadAnimation(context,
-
android.R.anim.fade_out));
-
if (isKeepSeat)
-
view.setVisibility(View.INVISIBLE);
-
else
-
view.setVisibility(View.GONE);
-
}
-
}
-
-
-
-
-
-
-
-
-
-
-
-
public void hideAnimView(View view, int id, boolean isKeepSeat)
-
{
-
if (this.isShown(view))
-
{
-
view.setAnimation(AnimationUtils.loadAnimation(context, id));
-
if (isKeepSeat)
-
view.setVisibility(View.INVISIBLE);
-
else
-
view.setVisibility(View.GONE);
-
}
-
}
-
-
-
-
-
-
-
-
-
-
public void setTimeShowAnimView(View view, long displayTime)
-
{
-
this.mView = view;
-
mHandler.removeCallbacks(runnable);
-
this.showAnimView(view);
-
mHandler.postDelayed(runnable, displayTime);
-
}
-
-
private final Handler mHandler = new Handler();
-
private final Runnable runnable = new Runnable()
-
{
-
@Override
-
public void run()
-
{
-
hideAnimView(mView, false);
-
}
-
};
-
}
5,App.Shared.java
-
-
public static final class Shared
-
{
-
-
public static final String AUTOLOGIN = "AUTOLOGIN";
-
-
public static final String WHETHERWARNING = "WHETHERWARNING";
-
-
public static final String DOWNLOADAFFIXINFO = "AFFIXINFO";
-
}
6,AffixInfoBean.java
-
import java.io.Serializable;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public class AffixInfoBean implements Serializable
-
{
-
private static final long serialVersionUID = -5184133590762842112L;
-
private String affixId;
-
private String affixName;
-
private String downloadUrl;
-
private String affixAffiliation;
-
-
public String getAffixId()
-
{
-
return affixId;
-
}
-
-
public void setAffixId(String affixId)
-
{
-
this.affixId = affixId;
-
}
-
-
public String getAffixName()
-
{
-
return affixName;
-
}
-
-
public void setAffixName(String affixName)
-
{
-
this.affixName = affixName;
-
}
-
-
public String getDownloadUrl()
-
{
-
return downloadUrl;
-
}
-
-
public void setDownloadUrl(String downloadUrl)
-
{
-
this.downloadUrl = downloadUrl;
-
}
-
-
public String getAffixAffiliation()
-
{
-
return affixAffiliation;
-
}
-
-
public void setAffixAffiliation(String affixAffiliation)
-
{
-
this.affixAffiliation = affixAffiliation;
-
}
-
}
若有其他没有被上传的,还请见谅,因为太细了,需要什么,请回复,我会尽快的加上去!
3,最后就是调用,至于怎么调用,这里就不说了。
关于布局中所用到的相关资源:图片,文字信息等,在这里可以直接下载