Android Open Source - android_lucidchat Popup Windows






From Project

Back to project page android_lucidchat.

License

The source code is released under:

Apache License

If you think the Android project android_lucidchat listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fi.harism.lucidchat.quickaction;
/*ww  w.  j a v  a2s  .c  om*/
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.PopupWindow;

/**
 * Custom popup window.
 * 
 * @author Lorensius W. L. T <lorenz@londatiga.net>
 * 
 */
public class PopupWindows {
  protected Drawable mBackground = null;
  protected Context mContext;
  protected View mRootView;
  protected PopupWindow mWindow;
  protected WindowManager mWindowManager;

  /**
   * Constructor.
   * 
   * @param context
   *            Context
   */
  public PopupWindows(Context context) {
    mContext = context;
    mWindow = new PopupWindow(context);

    mWindow.setTouchInterceptor(new OnTouchListener() {
      @Override
      public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
          mWindow.dismiss();

          return true;
        }

        return false;
      }
    });

    mWindowManager = (WindowManager) context
        .getSystemService(Context.WINDOW_SERVICE);
  }

  /**
   * Dismiss the popup window.
   */
  public void dismiss() {
    mWindow.dismiss();
  }

  /**
   * On dismiss
   */
  protected void onDismiss() {
  }

  /**
   * On show
   */
  protected void onShow() {
  }

  /**
   * On pre show
   */
  protected void preShow() {
    if (mRootView == null)
      throw new IllegalStateException(
          "setContentView was not called with a view to display.");

    onShow();

    if (mBackground == null)
      mWindow.setBackgroundDrawable(new BitmapDrawable());
    else
      mWindow.setBackgroundDrawable(mBackground);

    mWindow.setWidth(LayoutParams.WRAP_CONTENT);
    mWindow.setHeight(LayoutParams.WRAP_CONTENT);
    mWindow.setTouchable(true);
    mWindow.setFocusable(true);
    mWindow.setOutsideTouchable(true);

    mWindow.setContentView(mRootView);
  }

  /**
   * Set background drawable.
   * 
   * @param background
   *            Background drawable
   */
  public void setBackgroundDrawable(Drawable background) {
    mBackground = background;
  }

  /**
   * Set content view.
   * 
   * @param layoutResID
   *            Resource id
   */
  public void setContentView(int layoutResID) {
    LayoutInflater inflator = (LayoutInflater) mContext
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    setContentView(inflator.inflate(layoutResID, null));
  }

  /**
   * Set content view.
   * 
   * @param root
   *            Root view
   */
  public void setContentView(View root) {
    mRootView = root;

    mWindow.setContentView(root);
  }

  /**
   * Set listener on window dismissed.
   * 
   * @param listener
   */
  public void setOnDismissListener(PopupWindow.OnDismissListener listener) {
    mWindow.setOnDismissListener(listener);
  }
}




Java Source Code List

fi.harism.lucidchat.ContainerCenter.java
fi.harism.lucidchat.ContainerMenu.java
fi.harism.lucidchat.ConversationScrollView.java
fi.harism.lucidchat.DialogConnect.java
fi.harism.lucidchat.MainActivity.java
fi.harism.lucidchat.PreferencesHandler.java
fi.harism.lucidchat.SplashActivity.java
fi.harism.lucidchat.api.Channel.java
fi.harism.lucidchat.api.ChatConnection.java
fi.harism.lucidchat.api.ChatHandler.java
fi.harism.lucidchat.api.Conversation.java
fi.harism.lucidchat.api.Message.java
fi.harism.lucidchat.api.User.java
fi.harism.lucidchat.quickaction.ActionItem.java
fi.harism.lucidchat.quickaction.PopupWindows.java
fi.harism.lucidchat.quickaction.QuickAction.java
fi.harism.lucidchat.websocket.HybiParser.java
fi.harism.lucidchat.websocket.WebSocketClient.java