Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Sep 13, 2013

Embedding flash in Facebook link posts

If you want to have custom flash movies embeded in Facebook posts that link to your website, like these one from YouTube or SoundCloud:

 

It's fairly simple. 
BUT, it requires a SSL certificate, so that your website works over HTTPS, without browsers whining about security.

Here's what you do.
You've heard of OpenGraph protocol, right? Right. So, that's all there is to it. Proper metadata in the HTML of your website will instruct Facebook to include your flash movie, like this:
<meta property="og:title" content="Aljažev stolp | Triglav (2864m) | VR panorama"/>
<meta property="og:video" content="http://kafol.net/pano/aljazev-stolp/aljazev.stolp.swf"/> 
<meta property="og:type" content="movie"/>
<meta property="og:url" content="http://kafol.net/pano/aljazev-stolp/"/>
<meta property="og:image" content="http://kafol.net/pano/aljazev-stolp/preview.jpg"/>
<meta property="og:description" content="VR (virtual reality) panorama pri Aljaževem stolpu na vrhu Triglava. Panorama je posneta brez stativa."/>
<meta property="og:video:type" content="application/x-shockwave-flash" />
<meta property="og:video:width" content="400" />
<meta property="og:video:height" content="300" />


The next part depends on what the flash movie actually does. If it's a movie/music player that fetches media from other sources, or even an other part of your website, you'll need to configure crossdomain.xml. You put that file on the root of your website.

Here's a very liberal example, but fine for testing:
<?xml version="1.0" ?>
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>

Nov 18, 2011

Android :: google maps on double tap zoom in

How hard is it to make a simple zoom in call on double tap in MapView in Android?

Not very.

How hard is it to get the information on how to do it?

Very.

Here's what you probably didn't know:
You need to extend the MapView and use this extended class in the Android XML layout file.
In the extended class you instantiate the gesture detector and set on double tap listener.
In the Map Activity you implement OnGestureListener and OnDoubleTapListener.

Example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_horizontal" >
    
 <net.kafol.vlaki.ExtMapView
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/mapview"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:clickable="true"
     android:enabled="true"
     android:apiKey=""
 />

</RelativeLayout>
package net.kafol.vlaki;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.MotionEvent;
import android.view.GestureDetector.OnGestureListener;
import com.google.android.maps.MapView;

public class ExtMapView extends MapView {
 private Context context;
 private GestureDetector gestureDetector;

 public ExtMapView(Context c, AttributeSet attrs) {
  super(c, attrs);
  context = c;

  gestureDetector = new GestureDetector((OnGestureListener) context);
  gestureDetector.setOnDoubleTapListener((OnDoubleTapListener) context);
 }

 public boolean onTouchEvent(MotionEvent ev) {
  if (this.gestureDetector.onTouchEvent(ev))
   return true;
  else
   return super.onTouchEvent(ev);
 }
}
public class Map extends MapActivity implements OnGestureListener, OnDoubleTapListener {
...
 @Override
 public boolean onDoubleTap(MotionEvent e) {
     int x = (int)e.getX(), y = (int)e.getY();;
     Projection p = mapView.getProjection();
     mapView.getController().animateTo(p.fromPixels(x, y)); // zoom in to a point you tapped 
     mapView.getController().zoomIn();
  return true;
 }

Sep 20, 2008

PHP: XML Generator - array to xml converter

I created this class for my Online Briscola project - which is a client-server application, the client application is a flash movie and the server runs on PHP sockets. They comunicate through XML commands, so this class is basicly an array-to-xml converter. It uses PHP's XMLWriter
<?
class xmlgen {

 var $xml;
 var $ver;
 var $charset;
 
 function xmlgen($ver='1.0',$charset='UTF-8') {
  $this->ver = $ver;
  $this->charset = $charset;
 }

 function generate($root,$data=array()) {
  $this->xml = new XmlWriter();
  $this->xml->openMemory();
  $this->xml->startDocument($this->ver,$this->charset);
  $this->xml->startElement($root);
  $this->write($this->xml, $data);
  $this->xml->endElement();
  $this->xml->endDocument();
  $xml = $this->xml->outputMemory(true);
  $this->xml->flush();
  return $xml;
 }
 
 function write(XMLWriter $xml, $data){
     foreach($data as $key => $value){
         if(is_array($value)){
             $xml->startElement($key);
             $this->write($xml,$value);
             $xml->endElement();
             continue;
         }
         $xml->writeElement($key,$value);
     }
 }
 
}
?>
When the object is constructed
$xmlgen = new xmlgen();
you can pass your array to the class' generate() function, for example
$array = array(
 "first_element"=>"element_value",
 "second_element"=>array(
  "second_element_value1"=>"value1_subvalue")
);

echo $xmlgen->generate('root',$array);
The output will be something simmilar to:
<?xml version="1.0" encoding="UTF-8"?>
<root>
 <first_element>
   element_value
 </first_element>
 <second_element>
  <second_element_value1>
      value1_subvalue
  </second_element_value1>
 </second_element>
</root>