org.appcelerator.titanium.util.TiUIHelper Java Examples

The following examples show how to use org.appcelerator.titanium.util.TiUIHelper. 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: RealSwitch.java    From RealSwitch with MIT License 6 votes vote down vote up
@Override
public void propertyChanged(String key, Object oldValue, Object newValue,
		KrollProxy proxy) {


	CompoundButton cb = (CompoundButton) getNativeView();
	if (key.equals(TiC.PROPERTY_TITLE_OFF)) {
		((Switch) cb).setTextOff((String) newValue);
	} else if (key.equals(TiC.PROPERTY_TITLE_ON)) {
		((Switch) cb).setTextOff((String) newValue);
	} else if (key.equals(TiC.PROPERTY_VALUE)) {
		cb.setChecked(TiConvert.toBoolean(newValue));
	} else if (key.equals(TiC.PROPERTY_COLOR)) {
		cb.setTextColor(TiConvert.toColor(TiConvert.toString(newValue)));
	} else if (key.equals(TiC.PROPERTY_FONT)) {
		TiUIHelper.styleText(cb, (KrollDict) newValue);
	} else if (key.equals(TiC.PROPERTY_TEXT_ALIGN)) {
		TiUIHelper.setAlignment(cb, TiConvert.toString(newValue), null);
		cb.requestLayout();
	} else if (key.equals(TiC.PROPERTY_VERTICAL_ALIGN)) {
		TiUIHelper.setAlignment(cb, null, TiConvert.toString(newValue));
		cb.requestLayout();
	} else {
		super.propertyChanged(key, oldValue, newValue, proxy);
	}
}
 
Example #2
Source File: ActionbarextrasModule.java    From actionbarextras with MIT License 6 votes vote down vote up
/**
 * Sets the homeAsUp icon
 * @param icon
 */
private void handleSetHomeAsUpIcon(Object obj) {
	ActionBar actionBar = getActionBar();

	if (actionBar == null) {
		return;
	}

	if (obj instanceof HashMap) {
		HashMap args = (HashMap) obj;
		actionBar.setHomeAsUpIndicator(getDrawableFromFont(args));
	} else if (obj instanceof String) {
		int resId = TiUIHelper.getResourceId(resolveUrl(null, (String)obj));
		if (resId != 0) {
			actionBar.setHomeAsUpIndicator(resId);
		} else {
			Log.e(TAG, "Couldn't resolve " + (String)obj);
		}
	} else {
		Log.e(TAG, "Please pass an Object or String to handleSetHomeAsUpIcon");
	}

}
 
Example #3
Source File: MultiPickerProxy.java    From TiDialogs with MIT License 6 votes vote down vote up
@Override
protected void handleShow(KrollDict options) {
	super.handleShow(options);
	// If there's a lock on the UI message queue, there's a good chance
	// we're in the middle of activity stack transitions. An alert
	// dialog should occur above the "topmost" activity, so if activity
	// stack transitions are occurring, try to give them a chance to
	// "settle"
	// before determining which Activity should be the context for the
	// AlertDialog.
	TiUIHelper.runUiDelayedIfBlock(new Runnable() {
		@Override
		public void run() {
			MultiPicker d = (MultiPicker) getOrCreateView();
			d.show();
		}
	});
}
 
Example #4
Source File: RealSwitch.java    From RealSwitch with MIT License 5 votes vote down vote up
@Override
public void processProperties(KrollDict d) {
	super.processProperties(d);

	// Create Real Switch
	CompoundButton button = new Switch(proxy.getActivity()) {
		@Override
		protected void onLayout(boolean changed, int left, int top,
				int right, int bottom) {
			super.onLayout(changed, left, top, right, bottom);
			TiUIHelper.firePostLayoutEvent(proxy);
		}
	};

	setNativeView(button);
	updateButton(button, proxy.getProperties());
	button.setOnCheckedChangeListener(this);

	if (d.containsKey(TiC.PROPERTY_VALUE)) {
		oldValue = TiConvert.toBoolean(d, TiC.PROPERTY_VALUE);
	}

	View nativeView = getNativeView();
	if (nativeView != null) {
		updateButton((CompoundButton) nativeView, d);
	}
}
 
Example #5
Source File: RealSwitch.java    From RealSwitch with MIT License 5 votes vote down vote up
protected void updateButton(CompoundButton cb, KrollDict d) {
	if (d.containsKey(TiC.PROPERTY_TITLE_OFF)) {
		((Switch) cb).setTextOff(TiConvert.toString(d,
				TiC.PROPERTY_TITLE_OFF));
	}
	if (d.containsKey(TiC.PROPERTY_TITLE_ON)) {
		((Switch) cb).setTextOn(TiConvert.toString(d,
				TiC.PROPERTY_TITLE_ON));
	}
	if (d.containsKey(TiC.PROPERTY_VALUE)) {
		cb.setChecked(TiConvert.toBoolean(d, TiC.PROPERTY_VALUE));
	}
	if (d.containsKey(TiC.PROPERTY_COLOR)) {
		cb.setTextColor(TiConvert.toColor(d, TiC.PROPERTY_COLOR));
	}
	if (d.containsKey(TiC.PROPERTY_FONT)) {
		TiUIHelper.styleText(cb, d.getKrollDict(TiC.PROPERTY_FONT));
	}
	if (d.containsKey(TiC.PROPERTY_TEXT_ALIGN)) {
		String textAlign = d.getString(TiC.PROPERTY_TEXT_ALIGN);
		TiUIHelper.setAlignment(cb, textAlign, null);
	}
	if (d.containsKey(TiC.PROPERTY_VERTICAL_ALIGN)) {
		String verticalAlign = d.getString(TiC.PROPERTY_VERTICAL_ALIGN);
		TiUIHelper.setAlignment(cb, null, verticalAlign);
	}
	cb.invalidate();
}
 
Example #6
Source File: Manager.java    From TiCrouton with MIT License 5 votes vote down vote up
/**
  * Removes the {@link Crouton}'s view after it's display
  * durationInMilliseconds.
  *
  * @param crouton
  *     The {@link Crouton} added to a {@link ViewGroup} and should be
  *     removed.
  */
 protected void removeCrouton(Crouton crouton) {
   View croutonView = crouton.getView();
   ViewGroup croutonParentView = (ViewGroup) croutonView.getParent();

if (null != croutonParentView) {
	final View mCroutonView = croutonView;
	final ViewGroup mCroutonParentView = croutonParentView;
	final Crouton mCrouton = crouton;
	TiUIHelper.runUiDelayedIfBlock(new Runnable() {
		@Override
		public void run() {
			mCroutonView.startAnimation(mCrouton.getOutAnimation());
			// Remove the Crouton from the queue.
			Crouton removed = croutonQueue.poll();

			// Remove the crouton from the view's parent.
			mCroutonParentView.removeView(mCroutonView);
			if (null != removed) {
				removed.detachActivity();
				removed.detachViewGroup();
				if (null != removed.getLifecycleCallback()) {
					removed.getLifecycleCallback().onRemoved();
				}
				removed.detachLifecycleCallback();
				removed.fireEvent("finish");
			}

			// Send a message to display the next crouton but delay it
			// by the out
			// animation duration to make sure it finishes
			sendMessageDelayed(mCrouton, Messages.DISPLAY_CROUTON,
					mCrouton.getOutAnimation().getDuration());
		}
	});
}
 }
 
Example #7
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 #8
Source File: ViewProxy.java    From TiTouchImageView with MIT License 5 votes vote down vote up
private Bitmap loadImageFromApplication(String imageName) {
	Bitmap result = null;
	try {
		// Load the image from the application assets
		String url = getPathToApplicationAsset(imageName);
		TiBaseFile file = TiFileFactory.createTitaniumFile(new String[] { url }, false);
		result = TiUIHelper.createBitmap(file.getInputStream());
	} catch (IOException e) {
		Log.e(LCAT, " TiTouchImageView only supports local image files");
	}
	return result;
}
 
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: TypefaceSpan.java    From actionbarextras with MIT License 5 votes vote down vote up
/**
 * Load the {@link Typeface} and apply to a {@link Spannable}.
 */
public TypefaceSpan(Context context, String typefaceName) {
    mTypeface = sTypefaceCache.get(typefaceName);
    if (mTypeface == null) {
    	mTypeface = TiUIHelper.toTypeface( context, typefaceName );
 
        // Cache the loaded Typeface
        sTypefaceCache.put(typefaceName, mTypeface);
    }
}
 
Example #11
Source File: TimePickerProxy.java    From TiDialogs with MIT License 5 votes vote down vote up
@Override
protected void handleShow(KrollDict options) {
	super.handleShow(options);
	TiUIHelper.runUiDelayedIfBlock(new Runnable() {
		@Override
		public void run() {
			BasicDatePicker d = (BasicDatePicker) getOrCreateView();
			d.show();
		}
	});
}
 
Example #12
Source File: DatePickerProxy.java    From TiDialogs with MIT License 5 votes vote down vote up
@Override
protected void handleShow(KrollDict options) {
	super.handleShow(options);
	TiUIHelper.runUiDelayedIfBlock(new Runnable() {
		@Override
		public void run() {
			BasicDatePicker d = (BasicDatePicker) getOrCreateView();
			d.show();
		}
	});
}
 
Example #13
Source File: TicroutonModule.java    From TiCrouton with MIT License 4 votes vote down vote up
@Kroll.method
public void show(KrollDict args)
{
	Log.d(TAG, "show called");
	
	final Crouton crouton;
	
	Activity activity;
	String text = "";
	Style style = null;
	Builder config = new Configuration.Builder();
	
	if (args.containsKey(TiC.PROPERTY_ACTIVITY)){
		ActivityProxy activityProxy = (ActivityProxy) args.get(TiC.PROPERTY_ACTIVITY);
		activity = activityProxy.getActivity();
       }else{
       	activity = TiApplication.getInstance().getCurrentActivity();
       }
	
	if (args.containsKey(TiC.PROPERTY_TEXT)){
           text = TiConvert.toString(args.get(TiC.PROPERTY_TEXT));
       }
	
	if (args.containsKey(TiC.PROPERTY_STYLE)){
           style = getStyle(TiConvert.toInt(args.get(TiC.PROPERTY_STYLE)));
       }
	
	if (args.containsKey(TiC.PROPERTY_COLOR)){
		
		String color = (String) args.get(TiC.PROPERTY_COLOR);
		
		style = new Style.Builder()
			.setBackgroundColorValue(TiConvert.toColor(color))
			.build();
	}
	
	if (style == null){
		style = Style.INFO;
	}
	
	crouton = Crouton.makeText(activity, text, style);
	
	if (args.containsKey(TiC.PROPERTY_DURATION)){
		config.setDuration(TiConvert.toInt(args.get(TiC.PROPERTY_DURATION)));
		crouton.setConfiguration(config.build());
	}
	
	TiUIHelper.runUiDelayedIfBlock(new Runnable() {
 			@Override
 			public void run() {
 				crouton.show();
 			}
 		});
	
}
 
Example #14
Source File: ActionbarextrasModule.java    From actionbarextras with MIT License 4 votes vote down vote up
private IconDrawable getDrawableFromFont(HashMap args) {
	Typeface iconFontTypeface = TiUIHelper.toTypeface(TiApplication.getInstance(), (String) args.get(TiC.PROPERTY_FONTFAMILY));
	return new IconDrawable(TiApplication.getInstance(), (String) args.get(TiC.PROPERTY_ICON), iconFontTypeface).actionBarSize().color(TiConvert.toColor((String) args.get(TiC.PROPERTY_COLOR)));
}