Example usage for android.widget AbsoluteLayout AbsoluteLayout

List of usage examples for android.widget AbsoluteLayout AbsoluteLayout

Introduction

In this page you can find the example usage for android.widget AbsoluteLayout AbsoluteLayout.

Prototype

public AbsoluteLayout(Context context) 

Source Link

Usage

From source file:com.hippo.widget.Slider.java

@SuppressWarnings("deprecation")
private void init(Context context, AttributeSet attrs) {
    mContext = context;//from  w w w .j  a v a 2  s  .  c  o  m
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setTextAlign(Paint.Align.CENTER);

    Resources resources = context.getResources();
    mBubbleMinWidth = resources.getDimensionPixelOffset(R.dimen.slider_bubble_width);
    mBubbleMinHeight = resources.getDimensionPixelOffset(R.dimen.slider_bubble_height);

    mBubble = new BubbleView(context, textPaint);
    mBubble.setScaleX(0.0f);
    mBubble.setScaleY(0.0f);
    AbsoluteLayout absoluteLayout = new AbsoluteLayout(context);
    absoluteLayout.addView(mBubble);
    absoluteLayout.setBackgroundDrawable(null);
    mPopup = new PopupWindow(absoluteLayout);
    mPopup.setOutsideTouchable(false);
    mPopup.setTouchable(false);
    mPopup.setFocusable(false);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Slider);
    textPaint.setColor(a.getColor(R.styleable.Slider_textColor, Color.WHITE));
    textPaint.setTextSize(a.getDimensionPixelSize(R.styleable.Slider_textSize, 12));

    updateTextSize();

    setRange(a.getInteger(R.styleable.Slider_start, 0), a.getInteger(R.styleable.Slider_end, 0));
    setProgress(a.getInteger(R.styleable.Slider_slider_progress, 0));
    mThickness = a.getDimension(R.styleable.Slider_thickness, 2);
    mRadius = a.getDimension(R.styleable.Slider_radius, 6);
    setColor(a.getColor(R.styleable.Slider_color, Color.BLACK));

    mBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBgPaint.setColor(a.getBoolean(R.styleable.Slider_dark, false) ? 0x4dffffff : 0x42000000);

    a.recycle();

    mProgressAnimation = new ValueAnimator();
    mProgressAnimation.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR);
    mProgressAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(@NonNull ValueAnimator animation) {
            float value = (Float) animation.getAnimatedValue();
            mDrawPercent = value;
            mDrawProgress = Math.round(MathUtils.lerp((float) mStart, mEnd, value));
            updateBubblePosition();
            mBubble.setProgress(mDrawProgress);
            invalidate();
        }
    });

    mBubbleScaleAnimation = new ValueAnimator();
    mBubbleScaleAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(@NonNull ValueAnimator animation) {
            float value = (Float) animation.getAnimatedValue();
            mDrawBubbleScale = value;
            mBubble.setScaleX(value);
            mBubble.setScaleY(value);
            invalidate();
        }
    });
}

From source file:com.intel.xdk.device.Device.java

@Override
public void initialize(CordovaInterface cordova, final CordovaWebView webView) {
    super.initialize(cordova, webView);

    this.activity = cordova.getActivity();
    this.webView = webView;

    //remote site support
    remoteLayout = new AbsoluteLayout(activity);
    remoteLayout.setBackgroundColor(Color.BLACK);
    //hide the remote site display until needed
    remoteLayout.setVisibility(View.GONE);
    //create the close button
    remoteClose = new ImageButton(activity);
    remoteClose.setBackgroundColor(Color.TRANSPARENT);
    Drawable remoteCloseImage = null;//w  w  w  .  j av a 2s  .  c  om
    remoteCloseImage = activity.getResources().getDrawable(
            activity.getResources().getIdentifier("remote_close", "drawable", activity.getPackageName()));

    File remoteCloseImageFile = new File(activity.getFilesDir(), "_intelxdk/remote_close.png");
    if (remoteCloseImageFile.exists()) {
        remoteCloseImage = (Drawable.createFromPath(remoteCloseImageFile.getAbsolutePath()));
    } else {
        remoteCloseImage = (activity.getResources().getDrawable(
                activity.getResources().getIdentifier("remote_close", "drawable", activity.getPackageName())));
    }

    //set the button image
    //remoteClose.setImageDrawable(remoteCloseImage);
    remoteClose.setBackgroundDrawable(remoteCloseImage);
    //set up the button click action
    remoteClose.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            closeRemoteSite();
        }
    });
    //add the close button
    remoteLayout.addView(remoteClose);

    final ViewGroup parent = (ViewGroup) webView.getEngine().getView().getParent();
    activity.runOnUiThread(new Runnable() {
        public void run() {
            if (parent != null) {
                //add layout to activity root layout
                parent.addView(remoteLayout, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER));

            }
        }
    });

    //Initialize the orientation.
    lastOrientation = "unknown";

    //Listen to the orientation change.
    OrientationEventListener listener = new OrientationEventListener(activity) {

        @Override
        public void onOrientationChanged(int orientation) {
            //Log.d("orientation","orientation: " + orientation);

            String currentOrientation = "unknown";
            boolean orientationChanged = false;
            //int displayOrientation = 0;

            if (orientation > 345 || orientation < 15) {
                currentOrientation = "portrait";
                displayOrientation = 0;
            } else if (orientation > 75 && orientation < 105) {
                currentOrientation = "landscape";
                displayOrientation = 90;
            } else if (orientation > 165 && orientation < 195) {
                currentOrientation = "portrait";
                displayOrientation = 180;
            } else if (orientation > 255 && orientation < 285) {
                currentOrientation = "landscape";
                displayOrientation = -90;
            }

            if (currentOrientation.equals("unknown")) {
                currentOrientation = lastOrientation;
            }

            if (!currentOrientation.equals(lastOrientation)) {
                orientationChanged = true;
                Log.d("orientation", "Orientation changes from " + lastOrientation + " to " + currentOrientation
                        + ", current orientation: " + orientation + ".");
            }

            if (orientationChanged) {
                String js = "javascript:try{intel.xdk.device.orientation='" + displayOrientation
                        + "';}catch(e){}var e = document.createEvent('Events');e.initEvent('intel.xdk.device.orientation.change', true, true);e.success=true;e.orientation='"
                        + displayOrientation + "';document.dispatchEvent(e);";
                injectJS(js);
            }

            lastOrientation = currentOrientation;
        }

    };

    listener.enable();
    registerScreenStatusReceiver();

    //cache references to methods for use in injectJS
    try {
        evaluateJavascript = webView.getClass().getMethod("evaluateJavascript", String.class,
                ValueCallback.class);
    } catch (Exception e) {
    }

    try {
        sendJavascript = webView.getClass().getMethod("sendJavascript", String.class);
    } catch (Exception e) {
    }

    emptyVC = new ValueCallback<String>() {
        @Override
        public void onReceiveValue(String s) {
        }
    };

}

From source file:com.tealeaf.TeaLeaf.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PluginManager.init(this);
    instance = this;
    setFullscreenFlag();//from  w  w  w  .  j  ava  2s  . co  m
    configureActivity();
    String appID = findAppID();
    options = new TeaLeafOptions(this);

    PluginManager.callAll("onCreate", this, savedInstanceState);

    //check intent for test app info
    Bundle bundle = getIntent().getExtras();
    boolean isTestApp = false;
    if (bundle != null) {
        isTestApp = bundle.getBoolean("isTestApp", false);

        if (isTestApp) {
            options.setAppID(appID);
            boolean isPortrait = bundle.getBoolean("isPortrait", false);
            if (isPortrait) {
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            } else {
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            }
            options.setCodeHost(bundle.getString("hostValue"));
            options.setCodePort(bundle.getInt("portValue"));
            String simulateID = bundle.getString("simulateID");
            options.setSimulateID(simulateID);
        }
    }

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

    group = new FrameLayout(this);
    setContentView(group);

    // TextEditViewHandler setup
    textEditView = new TextEditViewHandler(this);

    settings = new Settings(this);
    remoteLogger = (ILogger) getLoggerInstance(this);

    checkUpdate();
    compareVersions();
    setLaunchUri();

    // defer building all of these things until we have the absolutely correct options
    logger.buildLogger(this, remoteLogger);
    resourceManager = new ResourceManager(this, options);
    contactList = new ContactList(this, resourceManager);
    soundQueue = new SoundQueue(this, resourceManager);
    localStorage = new LocalStorage(this, options);

    // start push notifications, but defer for 10 seconds to give us time to start up
    PushBroadcastReceiver.scheduleNext(this, 10);

    glView = new TeaLeafGLSurfaceView(this);
    glViewPaused = false;

    // default screen dimensions
    Display display = getWindow().getWindowManager().getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    int orientation = getRequestedOrientation();

    // gets real screen dimensions without nav bars on recent API versions
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        Point screenSize = new Point();
        try {
            display.getRealSize(screenSize);
            width = screenSize.x;
            height = screenSize.y;
        } catch (NoSuchMethodError e) {
        }
    }

    // flip width and height based on orientation
    if ((orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE && height > width)
            || (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT && width > height)) {
        int tempWidth = width;
        width = height;
        height = tempWidth;
    }

    final AbsoluteLayout absLayout = new AbsoluteLayout(this);
    absLayout.setLayoutParams(new android.view.ViewGroup.LayoutParams(width, height));
    absLayout.addView(glView, new android.view.ViewGroup.LayoutParams(width, height));

    group.addView(absLayout);
    editText = EditTextView.Init(this);

    if (isTestApp) {
        startGame();
    }

    soundQueue.playSound(SoundQueue.LOADING_SOUND);
    doFirstRun();
    remoteLogger.sendLaunchEvent(this);

    paused = false;
    menuButtonHandler = MenuButtonHandlerFactory.getButtonHandler(this);

    group.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        public void onGlobalLayout() {
            // get visible area of the view
            Rect r = new Rect();
            group.getWindowVisibleDisplayFrame(r);

            int visibleHeight = r.bottom;

            // TODO
            // maybe this should be renamed
            if (visibleHeight != lastVisibleHeight) {
                lastVisibleHeight = visibleHeight;
                EventQueue.pushEvent(new KeyboardScreenResizeEvent(visibleHeight));
            }
        }
    });
}