Archive for the ‘Google’ Category

03
Oct
<EditText android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:singleLine="false"
            android:lines="5"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:gravity="top|left"
            />

Here the android:lines attribute is used to set the no. of lines visible. The android:gravity attribute sets the cursor to top left corner.

, , , , , ,

30
Sep
private boolean isMyServiceRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if ("com.example.MyService".equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

, , ,

30
Sep
private void enableHttpResponseCache() {
    try {
        long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
        File httpCacheDir = new File(getCacheDir(), "http");
        Class.forName("android.net.http.HttpResponseCache")
            .getMethod("install", File.class, long.class)
            .invoke(null, httpCacheDir, httpCacheSize);
    } catch (Exception httpResponseCacheNotAvailable) {
    }
}

30
Sep
public int getVersion(Context context) {
        try {
            PackageInfo pInfo = context.getPackageManager().getPackageInfo("com.test.package", PackageManager.GET_META_DATA);
            return pInfo.versionCode;
        } catch (NameNotFoundException e) {
            return 0;
        }
    }
}

, , ,

30
Sep
public boolean enableWIFI()
    {
        WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
        if(wifiManager.isWifiEnabled()){
            if(wifiManager.setWifiEnabled(false))
                return true;
          }else{
            if(wifiManager.setWifiEnabled(true))
                return true;
        }
        return false;

}

, ,

30
Sep

The following codes will do the trick.

Consider a display object dispObj and a function eventFun(event), then

For Adding event listener

dispObj:addEventListener("touch", eventFun)  // This will add the touch event to dispObj

For Removing event listener

dispObj:removeEventListener("touch", eventFun)  // This will remove the touch event from dispObj

, , , ,

30
Sep

Consider a display object dispobj. Now we can scale the display object using two methods:

Method 1:

dispobj:scale(0.5,0.5)

Method 2:

dispobj:xScale = 0.5

dispobj:yScale = 0.5

, ,

30
Sep

The following code is used to split a string in Corona.

local stringobj = "hai,hello,man"

local stringarray = str.split(stringobj, ",")

 

Here in this code, the string stringobj will be split into an array named stringarray with values hai,hello and man. Here ‘,’ is used as the split string.

, , , ,

30
Sep

The following code is used to create activity indicator in Corona.

native.setActivityIndicator( true );

Based on the platform in which the app is run the nature of the activity indicator changes automatically.

To remove the activity indicator, use the following code.

native.setActivityIndicator( false );

, , ,

22
Sep

We know about the Linnkify class in android. Have you ever wondered that we can use this same class to add a market link?
Here is a sample code for the same.


TextView txtView = (TextView) findViewById(R.id.linkme);

Pattern WordMatcher = Pattern.compile("\\b[A-Z]+[a-z0-9]+[A-Z][A-Za-z0-9]+\\b");
String MarketURL = "market://details?id=com.schogini.geeta.pack&hl=pt_PT";
Linkify.addLinks(txtView, WordMatcher, MarketURL);

, , , , ,