/**
*
* @dec 文件重命名
*
*/
public static String GetNewNameFile(File dir, String fileName) {
String[] fileNames = dir.list();
for (int i = 0; i < fileNames.length; i++) {
String tmpName = fileNames[i].substring(0,
fileNames[i].lastIndexOf(".") > -1 ? fileNames[i]
.lastIndexOf(".") : 0);
if (fileName.equals(tmpName)) {
// 获得文件名(无后缀)
String pre = tmpName.substring(0,
fileNames[i].lastIndexOf("(") > -1 ? fileNames[i]
.lastIndexOf("(") : fileNames[i]
.lastIndexOf("."));
// 获得重命名标示符(如(1),(2))
String suff = fileNames[i].substring(
fileNames[i].lastIndexOf("(") > -1 ? fileNames[i]
.lastIndexOf("(") + 1 : 0,
fileNames[i].lastIndexOf(")") > -1 ? fileNames[i]
.lastIndexOf(")") : 0);
if (suff.length() > 0) {
suff = (Integer.parseInt(suff) + 1) + "";
} else {
suff = "1";
}
fileName = pre + "(" + suff + ")";
GetNewNameFile(dir, fileName);
}
}
return fileName;
}
/**
*
* @dec 加载等待框
*
*/
private static ProgressDialog mpDialog = null;
public static void ShowWaittingDialog(Context context, String StringMessage) {
mpDialog = new ProgressDialog(context);
mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mpDialog.setMessage(StringMessage);
mpDialog.setCancelable(true);
mpDialog.show();
}
public static void CancelWaittingDialog() {
if (mpDialog != null) {
mpDialog.cancel();
}
}
/**
*
* @dec 退出确认框
*
*/
public static void showExitDialog(final Activity activity) {
AlertDialog.Builder builder = new Builder(activity);
builder.setIcon(android.R.drawable.ic_dialog_info);
builder.setTitle("确定退出当前页面吗?");
builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
activity.finish();
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int arg1) {
dialog.cancel();
}
});
builder.create().show();
}
/**
*
* 检查网络连接状态
*
*/
public boolean hasNetwork()
{
try
{
ConnectivityManager connectivity = (ConnectivityManager) activity
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null)
{
// 获得网络连接管理的对象
NetworkInfo info = connectivity.getActiveNetworkInfo();
if (info != null && info.isConnected())
{
// 判断当前网络是否已连接
if (info.getState() == NetworkInfo.State.CONNECTED)
;
return true;
}
}
} catch (Exception e)
{
}
return false;
}
具体的可以到不同的项目中稍微改改,其实每个人都能写出这样的操作类,平时写代码时不要做个码农啊
我的
博客其它文章列表
http://my.oschina.net/helu