use of android.graphics.drawable.BitmapDrawable in project android-Ultra-Pull-To-Refresh by liaohuqiu.
the class RentalsStyleFragment method createView.
@Override
protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_materail_style, null);
setHeaderTitle(R.string.ptr_demo_rentals_style);
final CubeImageView imageView = (CubeImageView) view.findViewById(R.id.material_style_image_view);
final ImageLoader imageLoader = ImageLoaderFactory.create(getContext());
final PtrFrameLayout frame = (PtrFrameLayout) view.findViewById(R.id.material_style_ptr_frame);
// header
final RentalsSunHeaderView header = new RentalsSunHeaderView(getContext());
header.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2));
header.setPadding(0, LocalDisplay.dp2px(15), 0, LocalDisplay.dp2px(10));
header.setUp(frame);
frame.setLoadingMinTime(1000);
frame.setDurationToCloseHeader(1500);
frame.setHeaderView(header);
frame.addPtrUIHandler(header);
// frame.setPullToRefresh(true);
frame.postDelayed(new Runnable() {
@Override
public void run() {
frame.autoRefresh(true);
}
}, 100);
frame.setPtrHandler(new PtrHandler() {
@Override
public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
return true;
}
@Override
public void onRefreshBegin(final PtrFrameLayout frame) {
if (mImageHasLoaded) {
long delay = 1500;
frame.postDelayed(new Runnable() {
@Override
public void run() {
frame.refreshComplete();
}
}, delay);
} else {
mStartLoadingTime = System.currentTimeMillis();
imageView.loadImage(imageLoader, mUrl);
}
}
});
ImageLoadHandler imageLoadHandler = new ImageLoadHandler() {
@Override
public void onLoading(ImageTask imageTask, CubeImageView cubeImageView) {
}
@Override
public void onLoadFinish(ImageTask imageTask, final CubeImageView cubeImageView, final BitmapDrawable bitmapDrawable) {
mImageHasLoaded = true;
long delay = 1500;
frame.postDelayed(new Runnable() {
@Override
public void run() {
if (cubeImageView != null && bitmapDrawable != null) {
TransitionDrawable w1 = new TransitionDrawable(new Drawable[] { new ColorDrawable(Color.WHITE), (Drawable) bitmapDrawable });
imageView.setImageDrawable(w1);
w1.startTransition(200);
}
frame.refreshComplete();
}
}, delay);
}
@Override
public void onLoadError(ImageTask imageTask, CubeImageView cubeImageView, int i) {
}
};
imageLoader.setImageLoadHandler(imageLoadHandler);
return view;
}
use of android.graphics.drawable.BitmapDrawable in project android-Ultra-Pull-To-Refresh by liaohuqiu.
the class MaterialStyleFragment method createView.
@Override
protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_materail_style, null);
setHeaderTitle(R.string.ptr_demo_material_style);
final CubeImageView imageView = (CubeImageView) view.findViewById(R.id.material_style_image_view);
final ImageLoader imageLoader = ImageLoaderFactory.create(getContext());
mPtrFrameLayout = (PtrFrameLayout) view.findViewById(R.id.material_style_ptr_frame);
// header
final MaterialHeader header = new MaterialHeader(getContext());
int[] colors = getResources().getIntArray(R.array.google_colors);
header.setColorSchemeColors(colors);
header.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2));
header.setPadding(0, LocalDisplay.dp2px(15), 0, LocalDisplay.dp2px(10));
header.setPtrFrameLayout(mPtrFrameLayout);
mPtrFrameLayout.setLoadingMinTime(1000);
mPtrFrameLayout.setDurationToCloseHeader(1500);
mPtrFrameLayout.setHeaderView(header);
mPtrFrameLayout.addPtrUIHandler(header);
mPtrFrameLayout.postDelayed(new Runnable() {
@Override
public void run() {
mPtrFrameLayout.autoRefresh(false);
}
}, 100);
mPtrFrameLayout.setPtrHandler(new PtrHandler() {
@Override
public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
return true;
}
@Override
public void onRefreshBegin(final PtrFrameLayout frame) {
if (mImageHasLoaded) {
long delay = (long) (1000 + Math.random() * 2000);
delay = Math.max(0, delay);
delay = 0;
frame.postDelayed(new Runnable() {
@Override
public void run() {
frame.refreshComplete();
}
}, delay);
} else {
mStartLoadingTime = System.currentTimeMillis();
imageView.loadImage(imageLoader, mUrl);
}
}
});
ImageLoadHandler imageLoadHandler = new ImageLoadHandler() {
@Override
public void onLoading(ImageTask imageTask, CubeImageView cubeImageView) {
}
@Override
public void onLoadFinish(ImageTask imageTask, final CubeImageView cubeImageView, final BitmapDrawable bitmapDrawable) {
mImageHasLoaded = true;
long delay = Math.max(0, 1000 - (System.currentTimeMillis() - mStartLoadingTime));
delay = 0;
mPtrFrameLayout.postDelayed(new Runnable() {
@Override
public void run() {
if (cubeImageView != null && bitmapDrawable != null) {
TransitionDrawable w1 = new TransitionDrawable(new Drawable[] { new ColorDrawable(Color.WHITE), (Drawable) bitmapDrawable });
imageView.setImageDrawable(w1);
w1.startTransition(200);
}
mPtrFrameLayout.refreshComplete();
}
}, delay);
}
@Override
public void onLoadError(ImageTask imageTask, CubeImageView cubeImageView, int i) {
}
};
imageLoader.setImageLoadHandler(imageLoadHandler);
return view;
}
use of android.graphics.drawable.BitmapDrawable in project cube-sdk by liaohuqiu.
the class DefaultImageLoadHandler method onLoadFinish.
@Override
public void onLoadFinish(ImageTask imageTask, CubeImageView imageView, BitmapDrawable drawable) {
if (imageView == null) {
return;
}
Drawable d = drawable;
if (drawable != null) {
if (mResizeImageViewAfterLoad) {
int w = drawable.getBitmap().getWidth();
int h = drawable.getBitmap().getHeight();
if (w > 0 && h > 0) {
ViewGroup.LayoutParams lyp = imageView.getLayoutParams();
if (lyp != null) {
lyp.width = w;
lyp.height = h;
imageView.setLayoutParams(lyp);
}
}
}
// RoundedDrawable will not recycle automatically when API level is lower than 11
if ((mDisplayTag & DISPLAY_ROUNDED) == DISPLAY_ROUNDED && Version.hasHoneycomb()) {
d = new RoundedDrawable(drawable.getBitmap(), mCornerRadius);
}
if ((mDisplayTag & DISPLAY_FADE_IN) == DISPLAY_FADE_IN) {
int loadingColor = android.R.color.transparent;
if (mLoadingColor != -1 && (mDisplayTag & DISPLAY_ROUNDED) != DISPLAY_ROUNDED) {
loadingColor = mLoadingColor;
}
final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(loadingColor), d });
imageView.setImageDrawable(td);
td.startTransition(200);
} else {
if (DEBUG) {
Drawable oldDrawable = imageView.getDrawable();
int w = 0, h = 0;
if (oldDrawable != null) {
w = oldDrawable.getIntrinsicWidth();
h = oldDrawable.getIntrinsicHeight();
}
CLog.d(LOG_TAG, MSG_LOAD_FINISH, imageTask, imageView, w, h, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
}
imageView.setImageDrawable(drawable);
}
}
}
use of android.graphics.drawable.BitmapDrawable in project ARChon-Packager by bpear96.
the class activityInstalled method SelectedAPK.
public void SelectedAPK() throws IOException {
//If user selects apk manually. Run this.
String APKFilePath = g.getAPKPath();
PackageManager pm = getPackageManager();
PackageInfo pi = pm.getPackageArchiveInfo(APKFilePath, 0);
// tell package info where app is located.
pi.applicationInfo.sourceDir = APKFilePath;
pi.applicationInfo.publicSourceDir = APKFilePath;
String PackageName = pi.packageName;
String AppName = (String) pi.applicationInfo.loadLabel(pm);
g.setSelectedAppName(AppName);
g.setPackageName(PackageName);
Drawable icon = pi.applicationInfo.loadIcon(pm);
Bitmap bmpIcon = ((BitmapDrawable) icon).getBitmap();
//Make folders on phones storage
setupFolders();
// Extract icon
String extStorageDirectory = Environment.getExternalStorageDirectory().toString() + "/ChromeAPKS/" + AppName + File.separator;
OutputStream outStream = null;
File file = new File(extStorageDirectory, "icon.png");
try {
outStream = new FileOutputStream(file);
bmpIcon.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
} catch (Exception e) {
Toast.makeText(activityInstalled.this, "Error: App Icon was not extracted.", Toast.LENGTH_LONG).show();
}
//Copy APK from selected source to ChromeAPKS location
File apksource = new File(APKFilePath);
File apkdst = new File(Environment.getExternalStorageDirectory().toString() + File.separator + "ChromeAPKS/" + AppName + "/vendor/chromium/crx/" + PackageName + ".apk");
copy(apksource, apkdst);
// End dialog activity to return to app wizard.
finish();
//TODO: Cleanup leftover directories (Unzipped app directory, pulled app directory are not needed.)
}
use of android.graphics.drawable.BitmapDrawable in project ARChon-Packager by bpear96.
the class activityInstalled method pullAPk.
public void pullAPk() {
//Pull APK from selected installed app. Uses PackageInfo and PackageManager.
List<PackageInfo> PackList = getPackageManager().getInstalledPackages(0);
PackageInfo PackInfo = PackList.get(SelectedAppId);
if ((PackInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
File org = new File(PackInfo.applicationInfo.publicSourceDir);
String PackageNamePull = PackInfo.applicationInfo.packageName;
g.setPackageName(PackageNamePull);
//Setup directories.
setupFolders();
//Extract app icon to use with chrome.
PackageManager pm = getPackageManager();
Drawable icon = PackInfo.applicationInfo.loadIcon(pm);
Bitmap bmpIcon = ((BitmapDrawable) icon).getBitmap();
String extStorageDirectory = Environment.getExternalStorageDirectory().toString() + "/ChromeAPKS/" + SelectedAppName + File.separator;
OutputStream outStream = null;
File file = new File(extStorageDirectory, "icon.png");
try {
outStream = new FileOutputStream(file);
bmpIcon.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
} catch (Exception e) {
Toast.makeText(activityInstalled.this, "Error: APK not pulled.", Toast.LENGTH_LONG).show();
}
try {
String file_name = PackInfo.applicationInfo.loadLabel(getPackageManager()).toString();
Log.d("file_name--", " " + file_name);
PackageName = PackInfo.applicationInfo.packageName;
// make directory for pulled apks
File apk = new File(Environment.getExternalStorageDirectory().toString() + "/ChromeAPKS/Pulled");
apk.mkdirs();
// Set pulled apk to its proper name
apk = new File(apk.getPath() + "/" + file_name + ".apk");
// Move APK
apk.createNewFile();
InputStream in = new FileInputStream(org);
OutputStream out = new FileOutputStream(apk);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
System.out.println("File copied.");
} catch (FileNotFoundException ex) {
System.out.println(ex.getMessage() + " in the specified directory.");
} catch (IOException e) {
System.out.println(e.getMessage());
}
g.setAPKPath(Environment.getExternalStorageDirectory() + "/ChromeAPKS/Pulled/" + SelectedAppName + ".apk");
File apksource = new File(Environment.getExternalStorageDirectory() + "/ChromeAPKS/Pulled/" + SelectedAppName + ".apk");
File apkdst = new File(Environment.getExternalStorageDirectory().toString() + File.separator + "ChromeAPKS/" + SelectedAppName + "/vendor/chromium/crx/" + PackageName + ".apk");
try {
copy(apksource, apkdst);
} catch (IOException e) {
e.printStackTrace();
}
}
//Finish activity dialog to return to main wizard.
finish();
}
Aggregations