public void release() { if (DBG) { Log.d(LCAT, "Releasing: " + this); } View nv = getNativeView(); if (nv != null) { if (nv instanceof ViewGroup) { ViewGroup vg = (ViewGroup) nv; if (DBG) { Log.d(LCAT, "Group has: " + vg.getChildCount()); } if (!(vg instanceof AdapterView<?>)) { vg.removeAllViews(); } } Drawable d = nv.getBackground(); if (d != null) { nv.setBackgroundDrawable(null); d.setCallback(null); if (d instanceof TiBackgroundDrawable) { ((TiBackgroundDrawable) d).releaseDelegate(); } d = null; } nativeView = null; if (proxy != null) { proxy.setModelListener(null); } } }
public void play() { try { if (mp == null) { setState(STATE_STARTING); initialize(); } if (mp != null) { if (!isPlaying()) { if (DBG) { Log.d(LCAT, "audio is not playing, starting."); } setVolume(volume); if (DBG) { Log.d(LCAT, "Play: Volume set to " + volume); } mp.start(); setState(STATE_PLAYING); paused = false; if (remote) { startProgressTimer(); } } setState(STATE_PLAYING); } } catch (Throwable t) { Log.w(LCAT, "Issue while playing : ", t); reset(); } }
@Override public void onChannelSelected(String channelName) { Log.d(LCAT, "inside onChannelSelected"); Log.d(LCAT, "channelName: " + channelName); BranchUniversalObjectProxy self = BranchUniversalObjectProxy.this; KrollDict response = new KrollDict(); response.put("channelName", channelName); self.fireEvent("bio:shareChannelSelected", response); }
public void setEraseMode(Boolean toggle) { eraseState = toggle; if (eraseState) { Log.d(LCAT, "Setting Erase Mode to True."); tiPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); } else { Log.d(LCAT, "Setting Erase Mode to False."); tiPaint.setXfermode(null); } tiPaint.setAlpha(alphaState); }
@Override public void onLinkCreate(String url, BranchError error) { Log.d(LCAT, "inside onLinkCreate"); BranchUniversalObjectProxy self = BranchUniversalObjectProxy.this; KrollDict response = new KrollDict(); if (error == null) { Log.d(LCAT, "link to share: " + url); response.put("generatedLink", url); } else { String errorMessage = error.getMessage(); Log.d(LCAT, errorMessage); response.put("error", errorMessage); } self.fireEvent("bio:generateShortUrl", response); }
public void stop() { try { if (mp != null) { if (mp.isPlaying() || isPaused()) { if (DBG) { Log.d(LCAT, "audio is playing, stop()"); } setState(STATE_STOPPING); mp.stop(); setState(STATE_STOPPED); if (remote) { stopProgressTimer(); } try { mp.prepare(); } catch (IOException e) { Log.e(LCAT, "Error while preparing audio after stop(). Ignoring."); } catch (IllegalStateException e) { Log.w(LCAT, "Error while preparing audio after stop(). Ignoring."); } } if (isPaused()) { paused = false; } } } catch (Throwable t) { Log.e(LCAT, "Error : ", t); } }
public void onRegistrered(Context context, String registrationId) throws IOException { Log.d(LCAT, "Registered: " + registrationId); KrollDict data = new KrollDict(); data.put("registrationId", registrationId); C2dmModule.getInstance().fireEvent(REGISTER_EVENT, data); }
public int addEventListener(String eventName, Object listener) { int listenerId = -1; int listenerCount = 0; if (eventName != null) { if (proxy != null) { if (listener != null) { synchronized (eventListeners) { HashMap<Integer, KrollListener> listeners = eventListeners.get(eventName); if (listeners == null) { listeners = new HashMap<Integer, KrollListener>(); eventListeners.put(eventName, listeners); } listenerId = listenerIdGenerator.incrementAndGet(); listeners.put(listenerId, new KrollListener(proxy, listener)); if (DBG) { Log.d(TAG, "Added for eventName '" + eventName + "' with id " + listenerId); } listenerCount = listeners.size(); } dispatchOnEventChange(true, eventName, listenerCount, proxy); } else { throw new IllegalStateException("addEventListener expects a non-null listener"); } } else { throw new IllegalStateException("addEventListener expects a non-null KrollProxy"); } } else { throw new IllegalStateException("addEventListener expects a non-null eventName"); } return listenerId; }
public void abort() { if (readyState > READY_STATE_UNSENT && readyState < READY_STATE_DONE) { if (client != null) { if (DBG) { Log.d(LCAT, "Calling shutdown on clientConnectionManager"); } aborted = true; if (handler != null) { handler.client = null; if (handler.is != null) { try { if (handler.entity.isStreaming()) { handler.entity.consumeContent(); } handler.is.close(); } catch (IOException e) { Log.i(LCAT, "Force closing HTTP content input stream", e); } finally { handler.is = null; } } } if (client != null) { client.getConnectionManager().shutdown(); client = null; } } } }
@Override public void register(WebView webView) { String name = super.getModuleName(); if (DBG) { Log.d(LCAT, "Registering TitaniumApp as " + name); } webView.addJavascriptInterface((ITitaniumApp) this, name); }
// Handle creation options @Override public void handleCreationDict(KrollDict options) { super.handleCreationDict(options); if (options.containsKey("message")) { Log.d(TAG, "example created with message: " + options.get("message")); } }
@Override public void onLinkShareResponse(String sharedLink, String sharedChannel, BranchError error) { Log.d(LCAT, "inside onLinkCreate"); BranchUniversalObjectProxy self = BranchUniversalObjectProxy.this; KrollDict response = new KrollDict(); if (error == null) { response.put("sharedLink", sharedLink); response.put("sharedChannel", sharedChannel); Log.d(LCAT, "sharedLink: " + sharedLink); Log.d(LCAT, "sharedChannel: " + sharedChannel); } else { String errorMessage = error.getMessage(); Log.d(LCAT, errorMessage); response.put("error", errorMessage); } self.fireEvent("bio:shareLinkResponse", response); }
public synchronized void postAnalyticsEvent(TiAnalyticsEvent event) { if (!collectAnalytics()) { if (DBG) { Log.i(LCAT, "Analytics are disabled, ignoring postAnalyticsEvent"); } return; } if (DBG) { StringBuilder sb = new StringBuilder(); sb.append("Analytics Event: type=") .append(event.getEventType()) .append("\n event=") .append(event.getEventEvent()) .append("\n timestamp=") .append(event.getEventTimestamp()) .append("\n mid=") .append(event.getEventMid()) .append("\n sid=") .append(event.getEventSid()) .append("\n aguid=") .append(event.getEventAppGuid()) .append("\n isJSON=") .append(event.mustExpandPayload()) .append("\n payload=") .append(event.getEventPayload()); Log.d(LCAT, sb.toString()); } if (event.getEventType() == TiAnalyticsEventFactory.EVENT_APP_ENROLL) { if (needsEnrollEvent) { analyticsModel.addEvent(event); needsEnrollEvent = false; sendAnalytics(); analyticsModel.markEnrolled(); } } else if (event.getEventType() == TiAnalyticsEventFactory.EVENT_APP_START) { if (needsStartEvent) { analyticsModel.addEvent(event); needsStartEvent = false; sendAnalytics(); lastAnalyticsTriggered = System.currentTimeMillis(); } return; } else if (event.getEventType() == TiAnalyticsEventFactory.EVENT_APP_END) { needsStartEvent = true; analyticsModel.addEvent(event); sendAnalytics(); } else { analyticsModel.addEvent(event); long now = System.currentTimeMillis(); if (now - lastAnalyticsTriggered >= STATS_WAIT) { sendAnalytics(); lastAnalyticsTriggered = now; } } }
// Methods @SuppressWarnings("deprecation") private KrollFunction getCallback(final KrollDict options, final String name) throws Exception { if (options.containsKey(name)) { return (KrollFunction) options.get(name); } else { Log.d(LCAT, "Callback not found: " + name); throw new Exception("Callback not found: " + name); } }
public void setReadyState(int readyState) { Log.d(LCAT, "Setting ready state to " + readyState); this.readyState = readyState; fireCallback(ON_READY_STATE_CHANGE); if (readyState == READY_STATE_DONE) { // Fire onload callback fireCallback(ON_LOAD); } }
@Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if (DBG) { Log.d(LCAT, "Page Finished"); } if (activity.getLoadOnPageEnd()) { activity.triggerLoad(); } }
public TiResourceFile(TiContext tiContext, String path) { super(tiContext, TYPE_RESOURCE); this.path = path; this.loadFromSDCard = tiContext.getTiApp().getSystemProperties().getBool(LOAD_FROM_SD_CARD, false); if (loadFromSDCard) { Log.d(LCAT, "Loading data from sdcard"); } }
// Handle creation options @Override public void handleCreationDict(KrollDict options) { super.handleCreationDict(options); // The identifier is what Branch will use to de-dupe the content across many different Universal // Objects if (options.containsKey("canonicalIdentifier")) { Log.d(LCAT, "setCanonicalIdentifier"); branchUniversalObject.setCanonicalIdentifier(options.getString("canonicalIdentifier")); } // This is where you define the open graph structure and how the object will appear on Facebook // or in a deepview if (options.containsKey("title")) { Log.d(LCAT, "setTitle"); branchUniversalObject.setTitle(options.getString("title")); } if (options.containsKey("contentDescription")) { Log.d(LCAT, "setContentDescription"); branchUniversalObject.setContentDescription(options.getString("contentDescription")); } if (options.containsKey("contentImageUrl")) { Log.d(LCAT, "setContentImageUrl"); branchUniversalObject.setContentImageUrl(options.getString("contentImageUrl")); } // You use this to specify whether this content can be discovered publicly - default is public if (options.containsKey("contentIndexingMode")) { Log.d(LCAT, "setContentIndexingMode"); if (options.getString("contentIndexingMode").equals("private")) { Log.d(LCAT, "private"); branchUniversalObject.setContentIndexingMode( BranchUniversalObject.CONTENT_INDEX_MODE.PRIVATE); } else { Log.d(LCAT, "public"); branchUniversalObject.setContentIndexingMode( BranchUniversalObject.CONTENT_INDEX_MODE.PUBLIC); } } // Here is where you can add custom keys/values to the deep link data if (options.containsKey("contentMetadata")) { Log.d(LCAT, "addContentMetadata"); Object contentMetadata = options.get("contentMetadata"); Map<String, String> hashMap = (Map<String, String>) contentMetadata; for (Iterator iterator = hashMap.keySet().iterator(); iterator.hasNext(); ) { String key = (String) iterator.next(); branchUniversalObject.addContentMetadata(key, hashMap.get(key)); } } }
@Override public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy) { if (DBG) { Log.d(LCAT, "Property: " + key + " old: " + oldValue + " new: " + newValue); } if (key.equals(TiC.PROPERTY_SEPARATOR_COLOR)) { tableView.setSeparatorColor(TiConvert.toString(newValue)); } else { super.propertyChanged(key, oldValue, newValue, proxy); } }
public TiUILabel(TiViewProxy proxy) { super(proxy); if (DBG) { Log.d(LCAT, "Creating a text label"); } TextView tv = new TextView(getProxy().getContext()); tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); tv.setPadding(0, 0, 0, 0); tv.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE); setNativeView(tv); }
public TiUIImageView(TiViewProxy proxy) { super(proxy); if (DBG) { Log.d(LCAT, "Creating an ImageView"); } TiImageView view = new TiImageView(proxy.getContext()); setNativeView(view); proxy.getTiContext().addOnLifecycleEventListener(this); }
@Kroll.setProperty @Kroll.method public void setContentIndexingMode(String contentIndexingMode) { Log.d(LCAT, "setContentIndexingMode"); if (contentIndexingMode.equals("private")) { branchUniversalObject.setContentIndexingMode( BranchUniversalObject.CONTENT_INDEX_MODE.PRIVATE); } else { branchUniversalObject.setContentIndexingMode(BranchUniversalObject.CONTENT_INDEX_MODE.PUBLIC); } }
public void scheduleRestart(int delay) { Log.w(LCAT, "Scheduling application restart"); if (DBG) { Log.d( LCAT, "Here is call stack leading to restart. (NOTE: this is not a real exception, just a stack trace.) :"); (new Exception()).printStackTrace(); } if (getRootActivity() != null) { getRootActivity().restartActivity(delay); } }
private Object[] toArray(Scriptable svalue) { int len = (Integer) Context.jsToJava(svalue.get("length", this), Integer.class); Object[] a = new Object[len]; for (int i = 0; i < len; i++) { Object v = svalue.get(i, svalue); if (DBG) { Log.d(LCAT, "Index: " + i + " value: " + v + " type: " + v.getClass().getName()); } a[i] = toNative(v, Object.class); } return a; }
public void run() { try { BitmapWithIndex b = loader.getBitmapQueue().take(); if (DBG) { Log.d(LCAT, "set image: " + b.index); } setImage(b.bitmap); fireChange(b.index); } catch (InterruptedException e) { e.printStackTrace(); } }
public void animate() { TiAnimationBuilder builder = proxy.getPendingAnimation(); if (builder != null && nativeView != null) { AnimationSet as = builder.render(proxy, nativeView); if (DBG) { Log.d(LCAT, "starting animation: " + as); } nativeView.startAnimation(as); // Clean up proxy proxy.clearAnimation(); } }
public void send(Object userData) throws MethodNotSupportedException { // TODO consider using task manager final TiHTTPClient me = this; double totalLength = 0; needMultipart = false; if (userData != null) { if (userData instanceof TiDict) { TiDict data = (TiDict) userData; // first time through check if we need multipart for POST for (String key : data.keySet()) { Object value = data.get(key); if (value instanceof TiBaseFile || value instanceof TiBlob) { needMultipart = true; } } for (String key : data.keySet()) { Object value = data.get(key); if (method.equals("POST") || method.equals("PUT")) { if (value instanceof TiBaseFile || value instanceof TiBlob) { totalLength += addTitaniumFileAsPostData(key, value); } else { String str = TiConvert.toString(value); addPostData(key, str); totalLength += str.length(); } } else if (method.equals("GET")) { uri = uri.buildUpon().appendQueryParameter(key, TiConvert.toString(value)).build(); } } } else { addStringData(TiConvert.toString(userData)); } } request = new DefaultHttpRequestFactory().newHttpRequest(method, uri.toString()); for (String header : headers.keySet()) { request.setHeader(header, headers.get(header)); } clientThread = new Thread( new ClientRunnable(totalLength), "TiHttpClient-" + httpClientThreadCounter.incrementAndGet()); clientThread.setPriority(Thread.MIN_PRIORITY); clientThread.start(); if (DBG) { Log.d(LCAT, "Leaving send()"); } }
@Override protected void onMessage(Context context, Intent intent) { Log.d(LCAT, "Message received: " + intent.getExtras().getString("data.message")); KrollDict data = new KrollDict(); for (String key : intent.getExtras().keySet()) { String eventKey = key.startsWith("data.") ? key.substring(5) : key; data.put(eventKey, intent.getExtras().getString(key)); } C2dmModule.getInstance().fireEvent(MESSAGE_EVENT, data); }
@Override public Object get(String name, Scriptable start) { if (this.has(name, start)) { return super.get(name, start); } if (target instanceof TiProxy) { TiDict constants = ((TiProxy) target).getConstants(); if (constants != null) { if (constants.containsKey(name)) { Object value = constants.get(name); super.putConst(name, start, value); return value; } } } if (DBG) { Log.d(LCAT, "get name: " + name); } Object o = NOT_FOUND; // If starts with Capital letter see if there is a module for it. if (name.matches("^[A-Z].*") || name.matches("iPhone")) { Object p = loadModule(name); if (p != null) { o = new KrollObject(this, p); put(name, this, o); ((TiModule) p).postCreate(); } } else { if (DBG) { Log.d(LCAT, "Start: " + start.getClassName() + " looking for method:" + name); } o = handleMethodOrProperty(name, start, true, null); } return o; }
@Override protected void onResume() { super.onResume(); if (DBG) { Log.d(LCAT, "Activity onResume"); } ((TiApplication) getApplication()).setWindowHandler(this); ((TiApplication) getApplication()).setCurrentActivity(this, this); for (WeakReference<TiContext> contextRef : contexts) { if (contextRef.get() != null) { contextRef.get().dispatchOnResume(); } } }