Adsense Ad

Saturday, 16 December 2017

Displaying Images with the Glide Library

Overview

Glide is an Image Loader Library for Android developed by bumptech and is a library that is recommended by Google. It has been used in many Google open source projects including Google I/O 2014 official application. It provides animated GIF support and handles image loading/caching.

Setup

Add to your app/build.gradle file:
dependencies {
  compile 'com.github.bumptech.glide:glide:3.8.0'
}

Basic Usage

Glide.with(context)
    .load("http://via.placeholder.com/300.png")
    .into(ivImg);

Advanced Usage

Resizing images with:
Glide.with(context)
    .load("http://via.placeholder.com/300.png")
    .override(300, 200)
    .into(ivImg);
Placeholder and error images:
Glide.with(context)
    .load("http://via.placeholder.com/300.png")
    .placeholder(R.drawable.placeholder)
    .error(R.drawable.imagenotfound)
    .into(ivImg);
Cropping images with:
Glide.with(context)
    .load("http://via.placeholder.com/300.png")
    .centerCrop()
    .into(ivImg);

Configuration

You can configure Glide by creating a GlideConfiguration.java file:
public class GlideConfiguration implements GlideModule {

    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        // Apply options to the builder here.
        // Glide default Bitmap Format is set to RGB_565 since it 
        // consumed just 50% memory footprint compared to ARGB_8888.
        // Increase memory usage for quality with:
        builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    }

    @Override
    public void registerComponents(Context context, Glide glide) {
        // register ModelLoaders here.
    }
}
And then define it as meta-data inside AndroidManifest.xml:
<meta-data android:name="my.app.namespace.utils.GlideConfiguration"
            android:value="GlideModule"/>

Resizing

Ideally, an image's dimensions would match exactly those of the ImageView in which it is being displayed, but as this is often not the case, care must be taken to resize and/or scale the image appropriately. Android's native support for this isn't robust, especially when displaying very large images (such as bitmaps returned from the camera) in smaller image views, which can often lead to errors (see Troubleshooting).
Glide automatically limits the size of the image it holds in memory to the ImageView dimensions. Picasso has the same ability, but requires a call to fit(). With Glide, if you don't want the image to be automatically fitted to the ImageView, you can call override(horizontalSize, verticalSize). This will resize the image before displaying it in the ImageView but without respect to the image's aspect ratio:
Glide.with(context)
    .load("http://via.placeholder.com/300.png")
    .override(100, 200) // resizes the image to 100x200 pixels but does not respect aspect ratio
    .into(ivImg);
Resizing images in this way without respect to the original aspect ratio will often make the image appear skewed or distorted. In most cases, this should be avoided, and Glide offers two standard scaling transformation options to prevent this: centerCrop and fitCenter.
If you only want to resize one dimension, use Target.SIZE_ORIGINAL as a placeholder for the other dimension:
Glide.with(context)
    .load("http://via.placeholder.com/300.png")
    .override(100, Target.SIZE_ORIGINAL) // resizes width to 100, preserves original height, does not respect aspect ratio
    .into(ivImg);

centerCrop()

Calling centerCrop() scales the image so that it fills the requested bounds of the ImageView and then crops the extra. The ImageView will be filled completely, but the entire image might not be displayed.
Glide.with(context)
    .load("http://via.placeholder.com/300.png")
    .override(100, 200) 
    .centerCrop() // scale to fill the ImageView and crop any extra
    .into(ivImg);

fitCenter()

Calling fitCenter() scales the image so that both dimensions are equal to or less than the requested bounds of the ImageView. The image will be displayed completely, but might not fill the entire ImageView.
Glide.with(context)
    .load("http://via.placeholder.com/300.png")
    .override(100, 200) 
    .fitCenter() // scale to fit entire image within ImageView
    .into(ivImg);

Troubleshooting

OutOfMemoryError Loading Errors

If an image or set of images aren't loading, make sure to check the Android monitor log in Android Studio. There's a good chance you might see an java.lang.OutOfMemoryError "Failed to allocate a [...] byte allocation with [...] free bytes" or a Out of memory on a 51121168-byte allocation.. This is quite common and means that you are loading one or more large imagesthat have not been properly resized.
First, you have to find which image(s) being loaded are likely causing this error. For any given Glide call, we can fix this by one or more of the following approaches:
  • Add an explicit width or height to the ImageView by setting layout_width=500dp in the layout file.
  • Call .override(width, height) during the Glide load and explicitly set a width or height for the image such as: Glide.with(...).load(imageUri).override(500, 500).into(...).
  • Try removing android:adjustViewBounds="true" from your ImageView if present and if you not calling .override()
  • Open up your static placeholder or error images and make sure their dimensions are relatively small (< 500px width). If not, resize those static images and save them back to your project.
Applying these tips to all of your Glide image loads should resolve any out of memory issues. As a fallback, you might want to open up your AndroidManifest.xml and then add android:largeHeapto your manifest:
<application
        android:name=".MyApplication"
        ...
        android:largeHeap="true"
        ...
Note that this is not generally a good idea, but can be used temporarily to trigger fewer out of memory errors.

Loading Errors

If you experience errors loading images, you can create a RequestListener<String, GlideDrawable> and pass it in via Glide.listener() to intercept errors:
Glide.with(context)
        .load("http://via.placeholder.com/300.png")
        .placeholder(R.drawable.placeholder)
        .error(R.drawable.imagenotfound)
        .listener(new RequestListener<String, GlideDrawable>() {
            @Override
            public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                // log exception
                Log.e("TAG", "Error loading image", e);
                return false; // important to return false so the error placeholder can be placed
            }

            @Override
            public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                return false;
            }
        })
        .into(ivImg);

Transformations

Transformations are supported by an additional third-party library, glide-transformations. First, add the dependencies:
dependencies {
    compile 'jp.wasabeef:glide-transformations:2.0.2'
    // If you want to use the GPU Filters
    compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
}

Rounded Corners

int radius = 30; // corner radius, higher value = more rounded
int margin = 10; // crop margin, set to 0 for corners with no crop
Glide.with(this)
        .load("http://via.placeholder.com/300.png")
        .bitmapTransform(new RoundedCornersTransformation(context, radius, margin))
        .into(ivImg);

Crop

Circle crop:
Glide.with(this)
        .load("http://via.placeholder.com/300.png")
        .bitmapTransform(new CropCircleTransformation(context))
        .into(ivImg);

Effects

Blur:
Glide.with(this)
        .load("http://via.placeholder.com/300.png")
        .bitmapTransform(new BlurTransformation(context))
        .into(ivImg);
Multiple transforms:
Glide.with(this)
        .load("http://via.placeholder.com/300.png")
        .bitmapTransform(new BlurTransformation(context, 25), new CropCircleTransformation(context))
        .into(ivImg);

Advanced Usages

Showing a ProgressBar

Add a ProgressBar or otherwise handle callbacks for an image that is loading:
progressBar.setVisibility(View.VISIBLE);

Glide.with(this)
        .load("http://via.placeholder.com/300.png")
        .listener(new RequestListener<String, GlideDrawable>() {
            @Override
            public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                progressBar.setVisibility(View.GONE);
                return false; // important to return false so the error placeholder can be placed
            }

            @Override
            public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                progressBar.setVisibility(View.GONE);
                return false;
            }
        })
        .into(ivImg);

Adjusting Image Size Dynamically

To readjust the ImageView size after the image has been retrieved, first define a SimpleTarget<Bitmap> object to intercept the Bitmap once it is loaded:
private SimpleTarget target = new SimpleTarget<Bitmap>() {  
    @Override
    public void onResourceReady(Bitmap bitmap, GlideAnimation glideAnimation) {
        // do something with the bitmap
        // set it to an ImageView
        imageView.setImageBitmap(bitmap);
    }
};
Next, pass the SimpleTarget to Glide via into():
Glide.with(context)
        .load("http://via.placeholder.com/300.png")
        .asBitmap()
        .into(target);
Note: The SimpleTarget object must be stored as a member field or method and cannot be an anonymous class otherwise this won't work as expected. The reason is that Glide accepts this parameter as a weak memory reference, and because anonymous classes are eligible for garbage collection when there are no more references, the network request to fetch the image may finish after this anonymous class has already been reclaimed. See this Stack Overflow discussion for more details.
In other words, you cannot do this all inline Glide.with(this).load("url").into(new SimpleTarget<Bitmap>() { ... }) as in other scenarios.

Networking

By default, Glide uses the Volley networking library.

Using with OkHttp

There is a way to use Glide to use OkHttp instead, which may be useful if you need to do authenticated requests. First, add the okhttp3-integration library as a dependency:
dependencies {
    compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar'
}
Next, you can configure Glide to use OkHttp in XML or through Java. The Java approach is useful especially if you already have a shared instance of OkHttpClient:
OkHttpClient okHttpClient = new OkHttpClient();
Glide.get(application).register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(okHttpClient));
Alternatively, you can declare Glide to use OkHttp by declaring it in your AndroidManifest.xml file:
<meta-data
    android:name="com.bumptech.glide.integration.okhttp3.OkHttpGlideModule"
    android:value="GlideModule" />
Review this section if are configuring Glide for use with ProGuard.

References

Saturday, 2 December 2017

Oracle Forms 10G crashes on Internet Explorer while using Oracle JInitiator - FIXED


Problem: when running form modules using Internet Explorer and JInitiator 1.3.1.x, the browser window opens and crashes immediately before the applet starts. When using Mozilla Firefox, there’s no problem at all.

Several notes on Metalink about this: 602001.1, 430359.1, 550301.1
The issue does not occur when using Sun JRE version 1.4, 1.5 and 1.6.

This issue is first logged as JInitiator Bug 5643502 – INTERNET EXPLORER WITH WINDOWS LIVE TOOLBAR PLUG-IN CRASHES, but based on Sun Bug 4741238, the bug occurs in JRE version 1.3 (JInitiator is based on JRE 1.3) and the bug is fixed in JRE versions 1.4 and higher.

Solution according the notes
To avoid the crash,
(1) Use Sun JRE 1.4 and higher
– OR –
(2) Uninstall Windows Live Toolbar (or other software what you suspect is the cause)
– OR –
(3) Disable the toolbar’s associated Add-ons as the following:
1. Open Internet Explorer
2. From the menu open Tools -> Manage Add-ons -> Enable or Disable Add-ons
3. Select the following Add-ons and disable each of them by clicking the “Disable” button

– Windows Live Sign-In Helper
– Windows Live Toolbar
– Windows Live Toolbar Helper
– Windows Messenger
4. Restart Internet Explorer
– OR –
(4) Disable 3rd-party browser extensions as follows:
– From the browser menu Tools -> Internet Options -> Advanced
– Uncheck “Enable third-party browser extensions”

First I chose for the last option, the policy was changed by the Windows system administrators for all the clients in the network, and done.. But there were (un)expected side-affects, like a particular SSO-application couldn't be reached anymore. People didn’t appreciate this


So finally I went for a solution which isn’t in the note, but spread around the internet:

Download & Copy the jvm.dll from
Your (directory)
C:\Program Files\Oracle\JInitiator 1.3.1.22\bin\hotspot

Or if you installed jre version then just copy jvm.dll file from 
Your (directory)
C:\Program Files\Java\jre1.6.0_07\bin\client (jre1.4.2 does work as well..)
to (directory)
C:\Program Files\Oracle\JInitiator 1.3.1.22\bin\hotspot

Thursday, 23 November 2017

Internet Explorer crash with Forms 10g, How to Replace Jinitiator with JRE


Oracle Jinitiator is no longer compatible with oracle forms services. By default, Oracle Forms services 10g uses Jinitiator 1.3.1.22 to run Forms applications. Jinitiator was compatible with Internet Explorer 6 and Firefox version 2.0. But latest internet explorer like IE 8 and 9 crash with Jinitiator. Similar behavior is seen with Firfox version 3.0 and later.
To resolve this problem, you must configure JRE to work with forms services 10g. It is really easy and requires only very little work. Forms services 10g are by default configured to run with JRE 1.4.2_06. To get this working, locate following lines in your FORMSWEB.CFG file,
# System parameter: default base HTML file
baseHTML=base.htm
# System parameter: base HTML file for use with JInitiator client
baseHTMLjinitiator=basejini.htm
# System parameter: base HTML file for use with Sun’s Java Plug-In
baseHTMLjpi=basejpi.htm
Make changes as shown in bold face below.
# System parameter: default base HTML file
baseHTML=basejpi.htm
# System parameter: base HTML file for use with JInitiator client
baseHTMLjinitiator=basejpi.htm
# System parameter: base HTML file for use with Sun’s Java Plug-In
baseHTMLjpi=basejpi.htm
Make sue that following parmaments in FORMSWEB.CFG are as mentioned below.
jpi_download_page=http://java.sun.com/products/archive/j2se/1.4.2_06/index.html
jpi_classid=clsid:CAFEEFAC-0014-0002-0006-ABCDEFFEDCBA
jpi_codebase=http://java.sun.com/products/plugin/autodl/jinstall-1_4_2-windows-i586.cab#Version=1,4,2,06
jpi_mimetype=application/x-java-applet;jpi-version=1.4.2_06
Now install J2RE version 1.4.2_06 from following URL,

How to Enable Forms 6i short keys in Forms 10g / 11g

Shortcuts in Forms 10g and 11g are different from Forms 6i keys. For example, Forms 6i uses F10 as short key to save records while in Forms 10g and 11g, CTRL+S is default short key to save or commit changes. If you have migrated an app from older version then probably you would be looking some way to retain key shortcuts. This can be done by using a resource file named “fmrpcweb.res”. By default, Forms 10g and 11g use “frmweb.res”to manage key mapping. Do following steps to enable older short keys.
Create a new configuration in Formsweb.cfg and use “otherparams” parameter to supply resource file for key mapping as under,

[myConfiguration]
otherparams= term=/home/oracle/1010202Mid/forms/admin/resource/US/fmrpcweb.res
Now you should use myConfiguration while calling forms as under,
http://servername:port/forms/frmservlet?config=myConfiguration
The “fmrpcweb.res” resource file is located in Forms directory under middleWare home. in Forms 11g, this file can be located at following location
$Instance_home/config/FormsComponent/forms/admin/resource/US
In Forms 10g, fmrpcweb.res can be located in \forms directory
If you want to customize one ore more specific keys, visit following link to see how this can be done.

Hide username and password while calling oracle Reports. USING CGICMD.DAT file

If you have not configured reports with Oracle Single Sign-on, Oracle report server explicitly requires username and password when report is called using Web.Show_document(). Username and password is required in report calling URL, for example following method calls a reports using Web.Show_Documnet().
Web.Show_Document('http://domainname.com:8090/reports/rwservlet?userid=username/password@db& server=ReportsServer_1&desformat=PDF&destype=cache&report=report.rdf&paramform=yes','_blank');
In above call username and password are visible in URL, causing security problem. Oracle has provieded serveral methods to resolve this problem, one of these solution is to define keymapping in CGICMD.DAT file. In Reports services 11g this file is located at following location
$DOMAIN_HOME/servers/WLS_REPORTS/stage/reports/reports/configuration/cgicmd.dat
In Oracle Reports services 10g this file can be located in reportsconfdirectory.
To define a key mapping, append follwing line at the end of the file
userlogin: userid=username/password@db %*
Restart reports server/Managed server, now you can call your report using following URL
Web.Show_Document('http://domainname.com:8090/reports/rwservlet?userlogin&server=ReportsServer_1&desformat=PDF&destype=cache&report=report.rdf&paramform=yes','_blank');
You can define key mapping for as many parameter as you need using following syntax,
userlogin: userid=username/password@db server=ReportsServer_1 desformat=PDF destype=cache %*
If reports have been configured with SSO, simply pass ssoconn=configparameter in reports calling URL, here config is the Resource Access Descriptor defined in OID. This parameter will automatically get login information from Oracle Internet Directory.

Thursday, 9 November 2017

What does ERP stand for and what does it do for businesses today?


ERP stands for Enterprise Resource Planning, is a large-scale software program designed for modern businesses, both large and small. A simple definition is that ERP systems aid the flow of internal business processes and allow for communication between a business’s departments and its internal functions and data. 

Using software-generated automated reports, enterprise resource planning systems are able to give companies an immediate picture of its real-time operations: production, inventory and order processing. ERP software tracks a business’s resources (raw materials, cash, employees), overhead and commitments (employee payroll, purchase orders and customer orders) for individual departments and for the company as a whole. Most ERP systems are modular. 

Workers can access only the modules they need in order to complete their duties while higher-ups can access all modules in order to both create and review data and reports. By keeping work zones modular, the security of the company is better protected as a whole.

 The more modules offered by an ERP system, the more specific reports and projects could get if necessary; one potential drawback to a company having many modules is that each module represents an additional cost for the purchasing company. 

ERP systems are a powerful way for companies to manage costs, service and production.