org.appcelerator.titanium.TiApplication Java Examples

The following examples show how to use org.appcelerator.titanium.TiApplication. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CollectionViewProxy.java    From TiCollectionView with MIT License 6 votes vote down vote up
@Kroll.setProperty @Kroll.method
public void setSections(Object sections)
{
	if (!(sections instanceof Object[])) {
		Log.e(TAG, "Invalid argument type to setSection(), needs to be an array", Log.DEBUG_MODE);
		return;
	}
	//Update java and javascript property
	setProperty(TiC.PROPERTY_SECTIONS, sections);

	Object[] sectionsArray = (Object[]) sections;
	TiUIView listView = peekView();
	//Preload sections if listView is not opened.
	if (listView == null) {
		preload = true;
		clearPreloadSections();
		addPreloadSections(sectionsArray, -1, true);
	} else {
		if (TiApplication.isUIThread()) {
			((CollectionView)listView).processSectionsAndNotify(sectionsArray);
		} else {
			TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_SECTIONS), sectionsArray);
		}
		
	}
}
 
Example #2
Source File: ActionbarextrasModule.java    From actionbarextras with MIT License 6 votes vote down vote up
/**
 * Sets Up icon color
 * @param obj
 */
private void handleSetUpColor(String color){
	
	ActionBar actionBar = getActionBar();
	
	try {
		TiApplication appContext = TiApplication.getInstance();
		AppCompatActivity _activity = (AppCompatActivity) appContext.getCurrentActivity();

		final int res_id = TiRHelper.getResource("drawable.abc_ic_ab_back_material", true);
		final Drawable upArrow = ContextCompat.getDrawable(_activity, res_id);

		upArrow.setColorFilter(TiConvert.toColor(color), PorterDuff.Mode.SRC_ATOP);
		actionBar.setHomeAsUpIndicator(upArrow);
	}catch(Exception e){
		Log.e(TAG, e.toString());
	}
}
 
Example #3
Source File: ActionbarextrasModule.java    From actionbarextras with MIT License 6 votes vote down vote up
@Kroll.onAppCreate
public static void onAppCreate(TiApplication app) {
	// hack taken from:
	// http://stackoverflow.com/questions/9286822/how-to-force-use-of-overflow-menu-on-devices-with-menu-button
	try {
		ViewConfiguration config = ViewConfiguration.get(app);
		java.lang.reflect.Field menuKeyField = ViewConfiguration.class
				.getDeclaredField("sHasPermanentMenuKey");
		if (menuKeyField != null) {
			menuKeyField.setAccessible(true);
			menuKeyField.setBoolean(config, false);
		}
	} catch (Exception ex) {
		// Ignore
	}
}
 
Example #4
Source File: ImagePickerActivity.java    From titanium-imagepicker with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPostExecute(ArrayList<ImageAdapaterArray> items) {
	if (items.size() > 0) {
		totalSelectedImages = 0;

		adapter.clear();
    	adapter.addAll(items);

    	setupMaxCountSize();
    	setTotalCount();

        adapterSet.notifyDataSetChanged();

	} else {
		Toast.makeText(TiApplication.getAppCurrentActivity().getApplicationContext(), "No pictures available in your gallery.", Toast.LENGTH_SHORT).show();
		onBackPressed();
	}
}
 
Example #5
Source File: TiGooshModule.java    From ti.goosh with MIT License 6 votes vote down vote up
@Kroll.method
public void unregisterForPushNotifications() {
	final String senderId = getSenderId();
	final Context context = TiApplication.getInstance().getApplicationContext();

	new AsyncTask<Void, Void, Void>() {
		@Override
		protected Void doInBackground(Void... params) {
			try {
				InstanceID.getInstance(context).deleteToken(senderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE);
				Log.d(LCAT, "delete instanceid succeeded");
			} catch (final IOException e) {
				Log.e(LCAT, "remove token failed - error: " + e.getMessage());
			}
			return null;
		}
	}.execute();
}
 
Example #6
Source File: ImagePickerActivity.java    From titanium-imagepicker with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPostExecute(ArrayList<ImageAdapaterArray> items) {
 	if (items.size() > 0) {
 		totalSelectedImages = 0;
	
 		adapter.clear();
     	adapter.addAll(items);
	
     	setupMaxCountSize();
     	setTotalCount();
	
         adapterSet.notifyDataSetChanged();
	
 	} else {
 		Toast.makeText(TiApplication.getAppCurrentActivity().getApplicationContext(), "No pictures available in your gallery.", Toast.LENGTH_SHORT).show();
 		onBackPressed();
 	}
}
 
Example #7
Source File: NovarumbluetoothModule.java    From NovarumBluetooth with MIT License 6 votes vote down vote up
@Kroll.method
public boolean searchDevices()
{
	Log.d(TAG, "searchDevices called");
	
	//Halilk: if not enabled, enable bluetooth
	enableBluetooth();
	
	//Get Current activity//
	TiApplication appContext = TiApplication.getInstance();
	Activity activity = appContext.getCurrentActivity();		
	
       IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
       activity.registerReceiver(myReceiver, intentFilter);
       bluetoothAdapter.cancelDiscovery(); //cancel if it's already searching
       bluetoothAdapter.startDiscovery();		

	return true;
}
 
Example #8
Source File: CollectionSectionProxy.java    From TiCollectionView with MIT License 6 votes vote down vote up
@Kroll.method
public void replaceItemsAt(int index, int count, Object data) {
	if (!isIndexValid(index)) {
		return;
	}

	if (TiApplication.isUIThread()) {
		handleReplaceItemsAt(index, count, data);
	} else {
		KrollDict d = new KrollDict();
		d.put(TiC.EVENT_PROPERTY_INDEX, index);
		d.put(TiC.PROPERTY_COUNT, count);
		d.put(TiC.PROPERTY_DATA, data);
		TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_REPLACE_ITEMS_AT), d);
	}
}
 
Example #9
Source File: ActionbarextrasModule.java    From actionbarextras with MIT License 5 votes vote down vote up
/**
 * Helper function to process font objects used for title and subtitle
 * 
 * @param Context - TiApplication context
 * @param Object - the properties as hashmap
 * @param Text - SpannableStringBuilder that should get the properties applied
 * @param TypefaceSpan - font reference (for title or subtitle)
 */
private SpannableStringBuilder applyFontProperties(TiApplication appContext, HashMap<String, String> d, SpannableStringBuilder ssb, TypefaceSpan font){
	
	if (d.containsKey(TiC.PROPERTY_FONTFAMILY)){
		String fontFamily = d.get(TiC.PROPERTY_FONTFAMILY).replaceAll("\\.(ttf|otf|fnt)$", "");
		font = new TypefaceSpan(appContext, fontFamily);
		ssb.setSpan(font, 0, ssb.length(),
				Spannable.SPAN_INCLUSIVE_INCLUSIVE);
	}
	
	if (d.containsKey(TiC.PROPERTY_FONTSIZE)){
		Object value = d.get(TiC.PROPERTY_FONTSIZE);
		boolean dip = false;
		int fontSize;
		
		if (value instanceof String){
			// is there a better way to convert Strings ("16px", "22sp" etc.) to dip?
			fontSize = (int) TiUIHelper.getRawSize(
					TiUIHelper.getSizeUnits((String) value), 
					TiUIHelper.getSize((String) value), 
					appContext
			);
		}else {
			fontSize = (Integer) value;
			dip = true;
		}
		
		ssb.setSpan(new AbsoluteSizeSpan(fontSize, dip), 0, ssb.length(),
				Spannable.SPAN_INCLUSIVE_INCLUSIVE);
	}
	
	if (d.containsKey(TiC.PROPERTY_FONTWEIGHT)){
		String fontWeight = d.get(TiC.PROPERTY_FONTWEIGHT);
		ssb.setSpan(new StyleSpan(TiUIHelper.toTypefaceStyle(fontWeight, null)), 0, ssb.length(),
				Spannable.SPAN_INCLUSIVE_INCLUSIVE);
	}
	
	return ssb;
}
 
Example #10
Source File: CollectionSectionProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method @Kroll.setProperty
public void setFooterView(TiViewProxy footerView) {
	if (TiApplication.isUIThread()) {
		handleSetFooterView(footerView);
	} else {
		TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_FOOTER_VIEW), footerView);
	}
}
 
Example #11
Source File: CollectionSectionProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method @Kroll.setProperty
public void setHeaderTitle(String headerTitle) {
	if (TiApplication.isUIThread()) {
		handleSetHeaderTitle(headerTitle);
	} else {
		TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_HEADER_TITLE), headerTitle);
	}
}
 
Example #12
Source File: CollectionSectionProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method
public void updateItemAt(int index, Object data) {
	if (!isIndexValid(index) || !(data instanceof HashMap)) {
		return;
	}

	if (TiApplication.isUIThread()) {
		handleUpdateItemAt(index,  new Object[]{data});
	} else {
		KrollDict d = new KrollDict();
		d.put(TiC.EVENT_PROPERTY_INDEX, index);
		d.put(TiC.PROPERTY_DATA, new Object[]{data});
		TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_UPDATE_ITEM_AT), d);
	}
}
 
Example #13
Source File: ActionbarextrasModule.java    From actionbarextras with MIT License 5 votes vote down vote up
/**
 * returns the height of the Actionbar as absolute pixels
 * @return int	actionbar height
 */
@Kroll.getProperty @Kroll.method
public int getActionbarHeight() {
	TiApplication appContext = TiApplication.getInstance();
	final TypedArray styledAttributes = appContext.getTheme().obtainStyledAttributes(
               new int[] { android.R.attr.actionBarSize }
       );
	int mActionBarSize = (int) styledAttributes.getDimension(0, 0);
	styledAttributes.recycle();
	return mActionBarSize;
}
 
Example #14
Source File: CollectionViewProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method
public void replaceSectionAt(int index, Object section) {
	if (TiApplication.isUIThread()) {
		handleReplaceSectionAt(index, section);
	} else {
		sendReplaceSectionMessage(index, section);
	}
}
 
Example #15
Source File: ViewProxy.java    From TiTouchImageView with MIT License 5 votes vote down vote up
@Kroll.method
public void scrollTo(float x, float y) {
	if (!TiApplication.isUIThread()) {
		TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SCROLL_TO, (int)x, (int)y), getActivity());
	} else {
		handleScrollTo(x,y);
	}
}
 
Example #16
Source File: DrawerProxy.java    From Ti.DrawerLayout with MIT License 5 votes vote down vote up
@Kroll.method
public void closeLeftWindow() {
	if (TiApplication.isUIThread()) {
		handleCloseLeftView();
		return;
	}
	Message message = getMainHandler().obtainMessage(MSG_CLOSE_LEFT_VIEW);
	message.sendToTarget();
}
 
Example #17
Source File: TicroutonModule.java    From TiCrouton with MIT License 5 votes vote down vote up
@Kroll.method
public void showText(final String text, final int style)
{
	Log.d(TAG, "showText called");
	TiUIHelper.runUiDelayedIfBlock(new Runnable() {
 			@Override
 			public void run() {
 				Crouton.showText(TiApplication.getInstance().getCurrentActivity(), text, getStyle(style));
 			}
 		});
	
}
 
Example #18
Source File: TicroutonModule.java    From TiCrouton with MIT License 5 votes vote down vote up
@Kroll.onAppCreate
public static void onAppCreate(TiApplication app)
{
	Log.d(TAG, "inside onAppCreate");
	// put module init code that needs to run when the application is created
	
	
}
 
Example #19
Source File: GCMModule.java    From gcmpush with Apache License 2.0 5 votes vote down vote up
@Kroll.method
@Kroll.getProperty
@SuppressWarnings("unchecked")
public KrollDict getNotificationSettings() {
    Log.d(LCAT, "Getting notification settings");
    Map map = new Gson().fromJson(TiApplication.getInstance().getAppProperties().getString(GCMModule.NOTIFICATION_SETTINGS, null), Map.class);
    return map != null ? new KrollDict(map) : null;
}
 
Example #20
Source File: CollectionSectionProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method @Kroll.setProperty
public void setHeaderView(TiViewProxy headerView) {
	if (TiApplication.isUIThread()) {
		handleSetHeaderView(headerView);
	} else {
		TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_HEADER_VIEW), headerView);
	}
}
 
Example #21
Source File: CollectionViewProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method @Kroll.getProperty
public CollectionSectionProxy[] getSections()
{
	if (TiApplication.isUIThread()) {
		return handleSections();
	} else {
		return (CollectionSectionProxy[]) TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_GET_SECTIONS));
	}
}
 
Example #22
Source File: CollectionSectionProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method @Kroll.setProperty
public void setItems(Object data) {
	if (TiApplication.isUIThread()) {
		handleSetItems(data);
	} else {
		TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_ITEMS), data);
	}
}
 
Example #23
Source File: CollectionViewProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method
public void insertSectionAt(int index, Object section) {
	if (TiApplication.isUIThread()) {
		handleInsertSectionAt(index, section);
	} else {
		sendInsertSectionMessage(index, section);
	}
}
 
Example #24
Source File: NovarumbluetoothModule.java    From NovarumBluetooth with MIT License 5 votes vote down vote up
@Kroll.method
public void makeDiscoverable() 
{	
	if(bluetoothAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE)
	{		
		TiApplication appContext = TiApplication.getInstance();
		Activity activity = appContext.getCurrentActivity();
		
		Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
	    discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
	    activity.startActivity(discoverableIntent);
	}
}
 
Example #25
Source File: CollectionViewProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method
public void appendSection(Object section) {
	if (TiApplication.isUIThread()) {
		handleAppendSection(section);
	} else {
		TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_APPEND_SECTION), section);
	}
}
 
Example #26
Source File: CollectionViewProxy.java    From TiCollectionView with MIT License 5 votes vote down vote up
@Kroll.method @Kroll.getProperty
public int getSectionCount() {
	if (TiApplication.isUIThread()) {
		return handleSectionCount();
	} else {
		return (Integer) TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SECTION_COUNT));
	}
}
 
Example #27
Source File: NovarumbluetoothModule.java    From NovarumBluetooth with MIT License 5 votes vote down vote up
@Kroll.onAppCreate
public static void onAppCreate(TiApplication app)
{
	Log.d(TAG, "inside onAppCreate");
	// put module init code that needs to run when the application is created
	
	bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
	
}
 
Example #28
Source File: GCMModule.java    From gcmpush with Apache License 2.0 5 votes vote down vote up
/**
 * Cancel a notification by the id given in the payload.
 * @param notificationId
 */
@Kroll.method
public void cancelNotificationById(int notificationId) {
    try {
        NotificationManager notificationManager = (NotificationManager) TiApplication.getInstance().getApplicationContext().getSystemService(TiApplication.NOTIFICATION_SERVICE);
        notificationManager.cancel(notificationId);
        Log.i(LCAT, "Notification " + notificationId + " cleared successfully");
    } catch (Exception ex) {
        Log.e(LCAT, "Cannot cancel notification:" + notificationId + " Error: " + ex.getMessage());
    }
}
 
Example #29
Source File: GCMModule.java    From gcmpush with Apache License 2.0 5 votes vote down vote up
@Kroll.method
@Kroll.getProperty
@SuppressWarnings("unchecked")
public KrollDict getLastData() {
    Map map = new Gson().fromJson(TiApplication.getInstance().getAppProperties().getString(LAST_DATA, null), Map.class);
    return map != null ? new KrollDict(map) : null;
}
 
Example #30
Source File: GCMModule.java    From gcmpush with Apache License 2.0 5 votes vote down vote up
public String getToken(String senderId){
    // get token and return it
    try {
        InstanceID instanceID = InstanceID.getInstance(TiApplication.getInstance());
        return instanceID.getToken(senderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
    } catch (Exception ex) {
        return null;
    }
}