Sunday, August 7, 2016

VR sample 1.1

/* Copyright 2015 Samsung Electronics Co., LTD * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */
package org.gearvrf.balloons;
import org.gearvrf.GVRActivity;import org.gearvrf.scene_objects.view.GVRTextView;
import android.content.Intent;import android.graphics.Color;import android.os.Bundle;import android.view.Gravity;import android.view.MotionEvent;
public class BalloonActivity extends GVRActivity {

    BalloonMain main;    GVRTextView mTextView;    @Override    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        mTextView = new GVRTextView(this);        mTextView.setText("Android's Rederable Views");        mTextView.setTextColor(Color.WHITE);
//        GVRTextView textView = new GVRTextView(this, 1000, 500);//        textView.setBackgroundColor(Color.BLACK);//        textView.setTextColor(Color.WHITE);//        textView.setTextSize(18);//        textView.setGravity(Gravity.CENTER);//        textView.setText("tttttttttttttttttttttttttttt");        main = new BalloonMain(this);      //  main = new BalloonMain(mTextView);
        setMain(main, "gvr.xml");    }

    @Override    public boolean onTouchEvent(MotionEvent event) {
        main.onTouchEvent(event);        return super.onTouchEvent(event);    }

    @Override    public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
        if(intent==null){
            intent=new Intent();        }
        super.startActivityForResult(intent, requestCode, options);    }

}

VR sample 1

/* Copyright 2015 Samsung Electronics Co., LTD * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */
package org.gearvrf.balloons;
import org.gearvrf.FutureWrapper;import org.gearvrf.GVRAndroidResource;import org.gearvrf.GVRContext;import org.gearvrf.GVRDirectLight;import org.gearvrf.GVRMaterial;import org.gearvrf.GVRMesh;import org.gearvrf.GVRPhongShader;import org.gearvrf.GVRPicker;import org.gearvrf.GVRScene;import org.gearvrf.GVRSceneObject;import org.gearvrf.GVRMain;import org.gearvrf.GVRRenderData;import org.gearvrf.GVRRenderData.GVRRenderingOrder;import org.gearvrf.GVRSphereCollider;import org.gearvrf.GVRTexture;import org.gearvrf.IPickEvents;import org.gearvrf.scene_objects.GVRSphereSceneObject;import org.gearvrf.scene_objects.GVRTextViewSceneObject;import org.gearvrf.scene_objects.GVRVideoSceneObject;import org.gearvrf.scene_objects.GVRViewSceneObject;import org.gearvrf.scene_objects.view.GVRTextView;import org.gearvrf.scene_objects.view.GVRView;
import android.app.Activity;import android.content.Context;import android.content.ContextWrapper;import android.content.Intent;import android.content.pm.ActivityInfo;import android.content.pm.PackageInfo;import android.content.pm.PackageManager;import android.content.pm.ResolveInfo;import android.content.res.AssetFileDescriptor;import android.graphics.Color;import android.graphics.drawable.Drawable;import android.media.AudioManager;import android.media.MediaPlayer;import android.media.SoundPool;import android.net.Uri;import android.os.Bundle;import android.util.Log;import android.view.Gravity;import android.view.MotionEvent;import android.widget.ImageView;
import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.List;import java.util.concurrent.Future;
public class BalloonMain extends GVRMain {
    private GVRScene mScene = null;    private PickHandler mPickHandler;    private PickHandler mPickHandler2;    private GVRContext mGVRContext22 = null;    private SoundPool   mAudioEngine;    private SoundEffect mPopSound;    String appName;
    GVRViewSceneObject mTextSceneObject; //   GVRTextView mTextView;
    GVRView gvrView;    private Context context2;    private ImageView imageView;    private PackageManager manager;    private List<AppDetail> apps;    GVRTextViewSceneObject sceneObject;    BalloonActivity mActivity;    GVRTextViewSceneObject textviews;    public class PickHandler implements IPickEvents
    {
        public GVRSceneObject   PickedObject = null;
        public void onEnter(GVRSceneObject sceneObj, GVRPicker.GVRPickedObject pickInfo)
        {
            sceneObj.getRenderData().getMaterial().setDiffuseColor(1, 0, 0, 1);        }
        public void onExit(GVRSceneObject sceneObj){
            sceneObj.getRenderData().getMaterial().setDiffuseColor(1, 1, 1, 1);        }
        public void onNoPick(GVRPicker picker)
        {
            if (PickedObject != null)
            {

                PickedObject.getRenderData().getMaterial().setDiffuseColor(1, 0, 0, 0.5f);            }
            PickedObject = null;        }
        public void onPick(GVRPicker picker)
        {
            GVRPicker.GVRPickedObject picked = picker.getPicked()[0];            PickedObject = picked.hitObject;            PickedObject.getRenderData().getMaterial().setDiffuseColor(1, 0, 1, 0.5f);
            mAudioEngine = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);            try            {
                mPopSound = new SoundEffect(mGVRContext22, mAudioEngine, "pop.wav", false);                mPopSound.setVolume(0.6f);            }
            catch (IOException ex)
            {
                org.gearvrf.utility.Log.e("Audio", "Cannot load pop.wav");            }
        }

        public void onInside(GVRSceneObject sceneObj, GVRPicker.GVRPickedObject pickInfo) { }
    }
    public class PickHandler2 implements IPickEvents
    {
        public GVRSceneObject   PickedObject = null;
        public void onEnter(GVRSceneObject sceneObj, GVRPicker.GVRPickedObject pickInfo) { }
        public void onExit(GVRSceneObject sceneObj) { }
        public void onNoPick(GVRPicker picker)
        {
            if (PickedObject != null)
            {

                PickedObject.getRenderData().getMaterial().setDiffuseColor(1, 0, 0, 0.5f);            }
            PickedObject = null;        }
        public void onPick(GVRPicker picker)
        {
            GVRPicker.GVRPickedObject picked = picker.getPicked()[0];            PickedObject = picked.hitObject;            PickedObject.getRenderData().getMaterial().setDiffuseColor(1, 0, 1, 0.5f);

        }

        public void onInside(GVRSceneObject sceneObj, GVRPicker.GVRPickedObject pickInfo) { }
    }

  //  private final GVRTextView textView;
    BalloonMain(BalloonActivity activity) {
        mActivity = activity;    }
//    public BalloonMain(GVRTextView textView) {//        this.mTextView = textView;//    }
    @Override    public void onInit(GVRContext context) {
        /*         * Set the background color         */        context2=context.getContext();        mGVRContext22=context;        mScene = context.getNextMainScene();        mScene.getMainCameraRig().getLeftCamera().setBackgroundColor(1.0f, 1.0f, 1.0f, 1.0f);        mScene.getMainCameraRig().getRightCamera().setBackgroundColor(1.0f, 1.0f, 1.0f, 1.0f);        apps = new ArrayList<AppDetail>();
        /*         * Set up a head-tracking pointer         */        GVRSceneObject headTracker = new GVRSceneObject(context,                context.createQuad(0.1f, 0.1f),context.loadTexture(new GVRAndroidResource(context, R.drawable.cu)));
        headTracker.getTransform().setPosition(0.0f, 0.0f, -1.0f);        headTracker.getRenderData().setDepthTest(false);        headTracker.getRenderData().setRenderingOrder(100000);        mScene.getMainCameraRig().addChildObject(headTracker);
        //manager = context2.getPackageManager();        manager = mActivity.getPackageManager();

      //  mTextSceneObject = new GVRViewSceneObject(context,mTextView, 2.0f, 1.0f);       // context.getMainScene().addSceneObject(mTextSceneObject);

        Intent i = new Intent(Intent.ACTION_MAIN, null);        i.addCategory(Intent.CATEGORY_LAUNCHER);
        List<ResolveInfo> appList = manager.queryIntentActivities(i, 0);
//        Collections.sort(appList, new ResolveInfo.DisplayNameComparator(manager));////        for (ResolveInfo temp : appList) {////            Log.v("Indika logs", "Indika Activity name ==============   "//                    + temp.activityInfo.name);//            AppDetail app = new AppDetail();//            app.label = temp.loadLabel(manager);//            app.name = temp.activityInfo.packageName;//            app.icon = temp.activityInfo.loadIcon(manager);//            apps.add(app);////        }
       // com.sec.android.app.popupcalculator.Calculator        // appName="com.sec.android.app.samsungapps.SamsungAppsMainActivity";        // com.sec.android.app.camera.Camera        appName="org.gearvrf.pickandmove.PickandmoveActivity";

//===============================================================================
      //  GVRViewSceneObject text = new GVRViewSceneObject(context, textView,        //        context.createQuad(30.0f, 20.0f));       // text.getTransform().setPosition(0.0f, 1.0f, -5.0f);       // text.getRenderData().setRenderingOrder(10002);
       // mScene.addSceneObject(text);//==============================================================================//        GVRTextViewSceneObject(GVRContext gvrContext,//                GVRActivity gvrActivity,//        float width,//        float height,//        int viewWidth,//        int viewHeight,//        CharSequence text)        //GVRTextViewSceneObject text2 = new GVRTextViewSceneObject(context, mActivity,"ttttttttt");//===============================================================================
       // GVRSceneObject balloon3 = makeBalloon3(context);      //  mScene.addSceneObject(sceneObject);
        GVRSceneObject balloon4 = makeBalloon4(context);        mScene.addSceneObject(balloon4);//////        GVRSceneObject balloon = makeBalloon(context);        mScene.addSceneObject(balloon);

        GVRSceneObject environment = makeEnvironment(context);        mScene.addSceneObject(environment);
        mScene.getMainCameraRig().getOwnerObject().attachComponent(new GVRPicker(context, mScene));        mPickHandler = new PickHandler();        mScene.getEventReceiver().addListener(mPickHandler);//        mScene.getMainCameraRig().getOwnerObject().attachComponent(new GVRPicker(context, mScene));        mPickHandler2 = new PickHandler();        mScene.getEventReceiver().addListener(mPickHandler2);
      //  mScene.addSceneObject( video );    }

    public class AppDetail {
        CharSequence label;        CharSequence name;        Drawable icon;    }
//    GVRSceneObject makeBalloon3(GVRContext context) {//        // load texture//        GVRTexture texture = context.loadTexture(new GVRAndroidResource(//                context, R.drawable.asd));//        // create a scene object (this constructor creates a rectangular scene//        // object that uses the standard 'unlit' shader)//        GVRSceneObject sceneObject = new GVRSceneObject(context, 4.0f, 2.0f, texture);//        sceneObject.getTransform().setPositionZ(-5.0f);//        sceneObject.getTransform().setPositionX(3.5f);//        sceneObject.getTransform().setPositionY(0.0f);//        return sceneObject;//    }    GVRSceneObject makeBalloon4(GVRContext context) {
        // load texture        GVRTexture texture = context.loadTexture(new GVRAndroidResource(
                context, R.drawable.aaa));        // create a scene object (this constructor creates a rectangular scene        // object that uses the standard 'unlit' shader)        GVRSceneObject sceneObject = new GVRSceneObject(context, 4.0f, 2.0f, texture);        sceneObject.getTransform().setPositionZ(-5.0f);        sceneObject.getTransform().setPositionX(0.0f);        sceneObject.getTransform().setPositionY(3.2f);        return sceneObject;    }
    GVRSceneObject makeBalloon5(GVRContext context) {
        // load texture        GVRTexture texture = context.loadTexture(new GVRAndroidResource(
                context, R.drawable.ut));        // create a scene object (this constructor creates a rectangular scene        // object that uses the standard 'unlit' shader)        GVRSceneObject sceneObject = new GVRSceneObject(context, 4.0f, 2.0f, texture);        sceneObject.getTransform().setPositionZ(-5.0f);        sceneObject.getTransform().setPositionX(-4.5f);        sceneObject.getTransform().setPositionY(3.0f);        return sceneObject;    }
    GVRSceneObject makeBalloon(GVRContext context)
    {
        GVRSceneObject sphere = new GVRSceneObject(context,  4.0f, 4.0f);        GVRRenderData rdata = sphere.getRenderData();        GVRMaterial mtl = new GVRMaterial(context);
        GVRSphereCollider collider = new GVRSphereCollider(context);        collider.setRadius(1.0f);        sphere.attachComponent(collider);
        mtl.setDiffuseColor(0.1f, 5.1f, 1.0f, 0.5f);        sphere.setName("balloon");        rdata.setShaderTemplate(GVRPhongShader.class);        rdata.setAlphaBlend(true);        rdata.setMaterial(mtl);        rdata.setRenderingOrder(GVRRenderingOrder.TRANSPARENT);        sphere.getTransform().setPositionZ(-5.0f);        sphere.getTransform().setPositionX(0.0f);        sphere.getTransform().setPositionY(0.0f);        return sphere;    }


    GVRSceneObject makeEnvironment(GVRContext context)
    {
        Future<GVRTexture> tex = context.loadFutureCubemapTexture(new GVRAndroidResource(context, R.raw.lycksele3));        GVRMaterial material = new GVRMaterial(context, GVRMaterial.GVRShaderType.Cubemap.ID);        material.setMainTexture(tex);        GVRSphereSceneObject environment = new GVRSphereSceneObject(context, 18, 36, false, material, 4, 4);        environment.getTransform().setScale(20.0f, 20.0f, 20.0f);
        GVRDirectLight sunLight = new GVRDirectLight(context);        sunLight.setAmbientIntensity(0.4f, 0.4f, 0.4f, 1.0f);        sunLight.setDiffuseIntensity(0.6f, 0.6f, 0.6f, 1.0f);        environment.attachComponent(sunLight);        return environment;    }

    @Override    public void onStep() {
        FPSCounter.tick();    }

    public void onLongPress(MotionEvent e) {

            mPickHandler2.PickedObject.getRenderData().getMaterial().setDiffuseColor(1, 0, 0, 0.5f);            GVRSceneObject balloon4 = makeBalloon4(mGVRContext22);            mScene.addSceneObject(balloon4);
    }
    public void onTouchEvent(MotionEvent event)
    {
        switch (event.getAction() & MotionEvent.ACTION_MASK)
        {
            case MotionEvent.ACTION_DOWN:
                if (mPickHandler.PickedObject != null)
            {
                mPickHandler.PickedObject.getRenderData().getMaterial().setDiffuseColor(1, 0, 1, 0.5f);                GVRSceneObject balloon5 = makeBalloon5(mGVRContext22);                mScene.addSceneObject(balloon5);  mPopSound.play();
               // Intent i = manager.getLaunchIntentForPackage(appName);               // mActivity.startActivity(i);


               // BalloonMain.this.
               // Intent myIntent = new Intent(mContext, theNewActivity.class);
            }

                break;
            default:
                break;        }
    }

}

Saturday, August 6, 2016

How to open dial pad in

 Intent intent = new Intent("android.intent.action.DIAL");//                    intent.setData(Uri.parse("tel:0123456789"));//                    mActivity.startActivity(intent);

Thursday, August 4, 2016

Add Video in Gear VRF framework in android studio

// create sphere / meshGVRSphereSceneObject sphere = new GVRSphereSceneObject(context, false);GVRMesh mesh = sphere.getRenderData().getMesh();
// create mediaplayer instanceMediaPlayer mediaPlayer = new MediaPlayer();AssetFileDescriptor afd;try {
    afd = context.getContext().getAssets().openFd("dino.mp4");    android.util.Log.d("Minimal360Video", "Assets was found.");    mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());    android.util.Log.d("Minimal360Video", "DataSource was set.");    afd.close();    mediaPlayer.prepare();
    //GVRVideoSceneObject(GVRContext gvrContext, float width, float height, MediaPlayer mediaPlayer, int videoType)    //Play a video on a 2D, rectangular scene object, using the Android MediaPlayer
} catch (IOException e) {
    e.printStackTrace();    context.getActivity().finish();    android.util.Log.e("Minimal360Video", "Assets were not loaded. Stopping application!");}

mediaPlayer.setLooping( true );android.util.Log.d("Minimal360Video", "starting player.");mediaPlayer.start();
// create video sceneGVRVideoSceneObject video = new GVRVideoSceneObject( context, mesh, mediaPlayer, GVRVideoSceneObject.GVRVideoType.MONO );video.setName( "video" );
// apply video to scene

mScene.addSceneObject( video );

Tuesday, June 28, 2016

Check Web service status in php

<?php

function getSSLPage($url) {   
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSLVERSION,3);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_exec($ch);
    $result=curl_getinfo ($ch);
    curl_close($ch);
    return $result;
}
$url = 'http://www.kbslit.com';
$result = getSSLPage($url);
//print_r($result);
$status=$result['http_code'];
echo $status;
?>