Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Mozilla Public License 

import android.app.Activity;

import android.gesture.GestureOverlayView;

import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

public class Main {
    /**
     * add GestureOverlayView to an activity
     * @param activity
     * @return added GestureOverlayView
     */
    public static GestureOverlayView addGestureViewToActivity(Activity activity) {
        View contentView = getContentView(activity);
        GestureOverlayView view = new GestureOverlayView(activity);
        view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT, 1));

        activity.setContentView(view);
        view.addView(contentView); // adds the PhoneGap browser
        view.getChildAt(0).setLayoutParams(new FrameLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.MATCH_PARENT, 1));

        activity.setContentView(view);
        view.setGestureVisible(false);

        return view;
    }

    /**
     * getContentView from an activity
     * @param activity
     * @return View
     */
    public static View getContentView(Activity activity) {
        ViewGroup view = (ViewGroup) activity.getWindow().getDecorView();
        ViewGroup content = (ViewGroup) view.findViewById(android.R.id.content);
        return content.getChildAt(0);
    }
}