Sunday, September 13, 2020

Script to check Titanium modules for references to UIWebView

 

  1. Create a file called check-modules.sh and copy the above contents into the file
  2. Ensure that file has executable permissions chmod +x <path>
  3. Run the file against each module ./check-modules <path> where path is the full path of a module including the platform and version. Making sure to either escape the spaces (like below) or wrapping your path in quotes
  • For example ./check-module.sh /Users/awam/Library/Application\ Support/Titanium/modules/iphone/ti.googlesignin/2.0.4

If the module contains UIWebView references then that will be logged


Code: https://gist.github.com/ewanharris/bf7aa969dd0a99cd83c019feb512e800

Tuesday, February 4, 2020

How to to handle app's orientation properly.


The app's "alloy.js" is listening to the "orientationchange" event to re-layout content. The problem with this is that the "orientationchange" event provides the orientation of the "device", not the "app". The native device orientation change event will always occur before the app is rotated by the OS. And some devices will be faster or slower to respond to the device orientation change before rotating the app.
Also note that the "device" orientation and "app" orientation can differ as well. Especially when using split-screen mode on a tablet, because when you hold the tablet "landscape", both of the displayed apps will be in "portrait" form. The attached app code mishandles this case.
What you should be doing is listening to the window's "postlayout" event, fetch the window's width/height, and determine if it is portrait/landscape. This will also handle the split-screen case.

//////////////
var window = Ti.UI.createWindow();
window.addEventListener("postlayout", function() {
 var windowSize = window.size;
 var isPortrait = (windowSize.height >= windowSize.width);
 if (isPortrait) {
  Ti.API.info("### Window is in portrait form.");
 } else {
  Ti.API.info("### Window is in landscape form.");
 }
});
window.open();

//////////////
Note that the use-case for "device" orientation is for fixed orientation apps (ex: portrait-only) that want to rotate the UI manually based on device orientation. Camera apps do this.


I hope this helps.

Tuesday, November 5, 2019

remote image best practices

You can check out this sample code for remote image
https://gist.github.com/MotiurRahman/57535845ebf40bd2041448991ebd92fc

Secondly, If you would like to resize image before adding it to the window then you can use httpclient the response will be a blob, for instance, this.responseData inside the onLoad callback. Sample code - https://gist.github.com/MotiurRahman/130b7f232a74956b0c26d7ddf4ac6b34

Hope this helps.

Wednesday, October 9, 2019

Monday, April 29, 2019

Social share for android

Sample code


========
 var share_body = "https://play.google.com/store/apps/details?id=motiur_bdresult.bd.com.bdresult";
        var share_subject = "Please download it from the below link";

        var intent = Ti.Android.createIntent({
            action: Ti.Android.ACTION_SEND,
            type: "text/plain"
        });

        intent.putExtra(Ti.Android.EXTRA_SUBJECT, share_subject);
        intent.putExtra(Ti.Android.EXTRA_TEXT, share_body);
        intent.addCategory(Ti.Android.CATEGORY_DEFAULT);
        Ti.Android.currentActivity.startActivity(intent);

========

Hope this help.

Tuesday, March 19, 2019

Thursday, January 24, 2019

Monday, January 14, 2019

Friday, November 2, 2018

Appc is not recognized as an internal or external command

Try the following steps.

1.  uninstalled appcelerator (npm uninstall -g appcelerator).

2. Then uninstalled Node.

3. Also, delete any node directory to make sure any traces of Node was removed.

4. Reinstall Node - https://nodejs.org/en/#download

5. Reinstall appcelerator (npm install -g appcelerator)
6. Run - appc use latest -l trace

7. Run - appc setup -l trace


Hope this helps.

Tuesday, June 5, 2018

How to change action bar hamburger icon color.

You have to use a custom theme for changing the hamburger icon color. Here is the sample code and doc link

- https://gist.github.com/MotiurRahman/419344fbf8e9d4fb2aa262a4b9054743

- https://docs.appcelerator.com/platform/latest/#!/guide/Android_Action_Bar

Hope this helps.

Wednesday, April 4, 2018

Hyperloop: Example code for checking the notification is enabled or not.

After adding hyperloop module run the following sample code

////////

var Activity = require('android.app.Activity');
var activity = new Activity(Ti.Android.currentActivity);
var contextValue = activity.getApplicationContext();

var notification = require('android.support.v4.app.NotificationManagerCompat');

var notificationObject = notification.from(contextValue);


function doClick(e) {
alert(notificationObject.areNotificationsEnabled());

}

////

Thanks!

Friday, March 9, 2018

How to choose a pdf/doc/image file from the device and upload to the server.

You can try with the following sample code


var window = Ti.UI.createWindow({
backgroundColor : 'red',
layout : "vertical"
});
// Create a Button.
var request = Ti.UI.createButton({
title : 'GO',
height : 100,
width : 100,
backgroundImage : "motiur.jpg",
top : 50
});
request.addEventListener('click', function(e) {
var intent = Ti.Android.createIntent({
action : Ti.Android.ACTION_GET_CONTENT,
type : "application/pdf"

});
intent.addCategory(Ti.Android.CATEGORY_OPENABLE);
var x = Ti.Android.createIntentChooser(intent, "Select");
window.getActivity().startActivityForResult(x, function(e) {

//alert("fileData:" + JSON.parse(e.intent.data));
var doc = Ti.Filesystem.getFile(e.intent.data);
Ti.API.info(JSON.stringify(doc));

var file = Ti.Filesystem.getFile(doc.nativePath);
Ti.API.info("File:" + doc.nativePath);
alert("File path:" + doc.nativePath);

// write here http code for file uploading to the server.

});
});
window.add(request);
window.open();

Thanks!

Thursday, February 22, 2018

Android: does not show the Map || How to create API key for map

Usually, Map does not show if your API key is not correct or Map module version is not compatible. So the following steps can help to generate the API key

Go to the following link and "Detailed guide for users of the standard Google Maps Android API" section
You have to create your API key with the exact package name (<id> tag value) and SHA-1 certificate fingerprint. 
You can generate your SHA-1 certificate fingerprint using this command for the development App
  • keytool -list -v -keystore ~/Library/Application\ Support/Titanium/mobilesdk/osx/7.0.2.GA/android/dev_keystore
No need password, just press enter.

For production App:

You have to use production keystore file for generating SHA-1 certificate fingerprint

- keytool -list -v -keystore <here drag and drop your keystore file then press enter>



Now, use that API key in your tiapp.xml file. You can follow this doc link to do that
Hope this helps


Monday, February 19, 2018

How to play an audio and video file using hyperloop.

Here is an example code for android

var Activity = require('android.app.Activity');
var AudioManager = require('android.media.AudioManager');
var MediaPlayer = require('android.media.MediaPlayer');
var Uri = require('android.net.Uri');
var activity = new Activity(Ti.Android.currentActivity);
var context = activity.getApplicationContext();
var mMediaPlayer;

var contentUri = Uri.parse('android.resource://' + activity.getPackageName() + '/raw/abc');
//var myUri = Uri.parse("app/platform/android/res/raw/five.mp3");
//Ti.API.info("myUri=" + myUri);

mMediaPlayer = new MediaPlayer();
mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener({
onCompletion : function(mediaPlayer) {
Ti.API.info('MediaPlayer playback completed');
}
}));
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setDataSource(context, contentUri);
mMediaPlayer.prepare();

function startMedia() {
mMediaPlayer.start();
}

function stopMedia() {
mMediaPlayer.pause();

// NOTE: You can also stop it, but then you have to prepare() it again as well
// mMediaPlayer.stop();
// mMediaPlayer.prepare();
}

$.win1.open();



Hope this helps.

Thursday, December 14, 2017

Friday, December 1, 2017

Arrow CRUD operation using custom object

Please take a look following GitHub link for ArrowDB CRUD operation

- https://gist.github.com/MotiurRahman/86a57d86fde36dcfe6044a402564b834

Hope this helps.