Android Open Source - HistoryCleanerPro Helper From Project Back to project page HistoryCleanerPro .
License The source code is released under:
Copyright (c) 2014, John Phillips
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
...
If you think the Android project HistoryCleanerPro listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package com.ayros.historycleaner.helpers;
/ * w w w . j a v a 2 s . c o m * /
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import android.content.pm.PackageInfo;
import android.graphics.drawable.Drawable;
import com.ayros.historycleaner.Globals;
import com.ayros.historycleaner.R;
public class Helper
{
public static final String CHARSET_ALPHA_LOWER = "abcdefghijklmnopqrstuvwxyz" ;
static List<String> packageNames = null;
static List<PackageInfo> packageList = null;
public static boolean isPackageInstalled(String name)
{
if (packageNames == null)
{
loadPackages(true);
}
return packageNames.contains(name);
}
public static Drawable getPackageIcon(String name)
{
try
{
return Globals.getContext().getPackageManager().getApplicationIcon(name);
}
catch (Exception e)
{
return Globals.getContext().getResources().getDrawable(R.drawable.default_icon);
}
}
private static void loadPackages(boolean force)
{
if (packageList == null || force == true)
{
packageNames = new ArrayList<String>();
packageList = Globals.getContext().getPackageManager().getInstalledPackages(0);
for (PackageInfo pi : packageList)
{
packageNames.add(pi.packageName);
}
}
}
public static String randomString(int len)
{
return randomString(len, CHARSET_ALPHA_LOWER);
}
public static String randomString(int len, String charset)
{
String out = "" ;
for (int i = 0; i < len; i++)
{
out += charset.charAt((int )(Math.random() * charset.length()));
}
return out;
}
public static String urlEncode(String text)
{
try
{
return URLEncoder.encode(text, "UTF-8" );
}
catch (Exception e)
{
return "" ;
}
}
public static String urlDecode(String text)
{
try
{
return URLDecoder.decode(text, "UTF-8" );
}
catch (Exception e)
{
return "" ;
}
}
public static String convertStreamToString(InputStream is)
{
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line).append("\n" );
}
is.close();
return sb.toString();
}
catch (Exception e)
{
Logger.errorST("Could not convert stream to string" , e);
return null;
}
}
public static String getFileContents(String filePath)
{
try
{
File fl = new File (filePath);
FileInputStream fin = new FileInputStream(fl);
return convertStreamToString(fin);
}
catch (Exception e)
{
Logger.errorST("Could not read file contents: " + filePath, e);
return null;
}
}
}
Java Source Code List com.ayros.historycleaner.Globals.java com.ayros.historycleaner.ProfileAdapter.java com.ayros.historycleaner.UIRunner.java com.ayros.historycleaner.cleaning.CategoryList.java com.ayros.historycleaner.cleaning.Category.java com.ayros.historycleaner.cleaning.CleanItem.java com.ayros.historycleaner.cleaning.CleanListener.java com.ayros.historycleaner.cleaning.Cleaner.java com.ayros.historycleaner.cleaning.ProfileList.java com.ayros.historycleaner.cleaning.Profile.java com.ayros.historycleaner.cleaning.SimpleDatabaseItem.java com.ayros.historycleaner.cleaning.SimpleFileItem.java com.ayros.historycleaner.cleaning.items._AdobeReader_Recent.java com.ayros.historycleaner.cleaning.items._FirefoxBeta_Cache.java com.ayros.historycleaner.cleaning.items._FirefoxBeta_Cookies.java com.ayros.historycleaner.cleaning.items._FirefoxBeta_History.java com.ayros.historycleaner.cleaning.items._FirefoxBeta_LocalStorage.java com.ayros.historycleaner.cleaning.items._FirefoxBeta_OpenTabs.java com.ayros.historycleaner.cleaning.items._Firefox_Cache.java com.ayros.historycleaner.cleaning.items._Firefox_Cookies.java com.ayros.historycleaner.cleaning.items._Firefox_History.java com.ayros.historycleaner.cleaning.items._Firefox_LocalStorage.java com.ayros.historycleaner.cleaning.items._Firefox_OpenTabs.java com.ayros.historycleaner.cleaning.items._ONEBrowser_Cache.java com.ayros.historycleaner.cleaning.items._ONEBrowser_LocalStorage.java com.ayros.historycleaner.cleaning.items._System_BrowserHistory.java com.ayros.historycleaner.cleaning.items._System_Cache.java com.ayros.historycleaner.cleaning.items._System_Clipboard.java com.ayros.historycleaner.cleaning.items._System_FrequentContacts.java com.ayros.historycleaner.cleaning.items._System_RecentCalls.java com.ayros.historycleaner.cleaning.items._System_SMS.java com.ayros.historycleaner.helpers.DBHelper.java com.ayros.historycleaner.helpers.DatabaseModifier.java com.ayros.historycleaner.helpers.Helper.java com.ayros.historycleaner.helpers.Logger.java com.ayros.historycleaner.helpers.PrefsModifier.java com.ayros.historycleaner.helpers.RootHelper.java com.ayros.historycleaner.helpers.XML.java com.ayros.historycleaner.locale.Constants.java com.ayros.historycleaner.locale.bundle.BundleScrubber.java com.ayros.historycleaner.locale.bundle.PluginBundleManager.java com.ayros.historycleaner.locale.receiver.FireReceiver.java com.ayros.historycleaner.locale.ui.AbstractPluginActivity.java com.ayros.historycleaner.locale.ui.EditPluginActivity.java com.ayros.historycleaner.ui.CleanFragment.java com.ayros.historycleaner.ui.DataViewActivity.java com.ayros.historycleaner.ui.HelpActivity.java com.ayros.historycleaner.ui.MainActivity.java com.ayros.historycleaner.ui.OnProfileUpdated.java com.ayros.historycleaner.ui.ProfileFragment.java com.ayros.historycleaner.ui.ShortcutActivity.java com.ayros.historycleaner.ui.ShortcutCleanActivity.java com.twofortyfouram.locale.BreadCrumber.java com.twofortyfouram.locale.Constants.java com.twofortyfouram.locale.Intent.java com.twofortyfouram.locale.PackageUtilities.java