Example usage for android.widget PopupWindow setBackgroundDrawable

List of usage examples for android.widget PopupWindow setBackgroundDrawable

Introduction

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

Prototype

public void setBackgroundDrawable(Drawable background) 

Source Link

Document

Specifies the background drawable for this popup window.

Usage

From source file:fr.univsavoie.ltp.client.map.Popup.java

/**
 * Afficher une boite au milieu de la carte si aucun utilisateur est connects
 * pour proposer a l'invit, de se connecter ou s'incrire aupres du service LTP.
 *//*from ww  w .  java2s . c  o  m*/
public final void popupGuest() {
    DisplayMetrics dm = new DisplayMetrics();
    this.activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

    //final int height = dm.heightPixels;
    final int width = dm.widthPixels;
    //final int height = dm.heightPixels;

    int popupWidth = (int) (width * 0.75);
    //int popupHeight = height / 2;

    // Inflate the popup_layout.xml
    LinearLayout viewGroup = (LinearLayout) this.activity.findViewById(R.id.popupGuest);
    LayoutInflater layoutInflater = (LayoutInflater) this.activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    final View layout = layoutInflater.inflate(R.layout.popup_guest, viewGroup);
    layout.setBackgroundResource(R.drawable.popup_gradient);

    // Crer le PopupWindow
    final PopupWindow popupGuest = new PopupWindow(layout, popupWidth, LayoutParams.WRAP_CONTENT, true);
    popupGuest.setBackgroundDrawable(new BitmapDrawable());
    popupGuest.setOutsideTouchable(true);

    // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
    final int OFFSET_X = 0;
    final int OFFSET_Y = 0;

    // Displaying the popup at the specified location, + offsets.
    this.activity.findViewById(R.id.layoutMain).post(new Runnable() {
        public void run() {
            popupGuest.showAtLocation(layout, Gravity.CENTER, OFFSET_X, OFFSET_Y);
        }
    });

    /*
     * Evenements composants du PopupWindow
     */

    // Ecouteur d'vnement sur le bouton des paramtres
    Button btLogin = (Button) layout.findViewById(R.id.btnPopupLogin);
    btLogin.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            // La constante CODE_MON_ACTIVITE reprsente lidentifiant de la requte
            // (requestCode) qui sera utilis plus tard pour identifier lactivit
            // renvoyant la valeur de retour.
            Intent i = new Intent(activity, LoginActivity.class);
            activity.startActivityForResult(i, 1);

            popupGuest.dismiss();
        }
    });

    // Ecouteur d'vnement sur le bouton des paramtres
    Button btSignup = (Button) layout.findViewById(R.id.btnPopupSignup);
    btSignup.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            // La constante CODE_MON_ACTIVITE reprsente lidentifiant de la requte
            // (requestCode) qui sera utilis plus tard pour identifier lactivit
            // renvoyant la valeur de retour.
            Intent i = new Intent(activity, SignupActivity.class);
            activity.startActivityForResult(i, 3);

            popupGuest.dismiss();
        }
    });

    // Ecouteur d'vnement sur le bouton pour fermer l'application
    Button close = (Button) layout.findViewById(R.id.btnPopupClose);
    close.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            popupGuest.dismiss();
        }
    });
}

From source file:ab.util.AbDialogUtil.java

/**
 * /*from   ww  w. j  a v a2 s  .  c  o m*/
 */
public static MyPop showDatePopWindowHour(Context context, View contentView, View targetView) {
    // 
    hourArrayString = getHMArray(24);
    // ??
    c = Calendar.getInstance();
    PopupWindow popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
    popupWindow.setWidth(context.getResources().getDisplayMetrics().widthPixels);
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(targetView, Gravity.BOTTOM, 0, 0);

    hourWV = (WheelView) contentView.findViewById(R.id.time_hour);
    // ?
    hourWV.setVisibleItems(5);
    // 
    hourWV.setLabel(":00");
    hourWV.setCyclic(true);
    setHourData();
    return new MyPop(popupWindow, yearWV, monthWV, dayWV, hourWV, minuteWV);
}

From source file:fr.univsavoie.ltp.client.map.Popup.java

public final void popupGetStatus(JSONArray pStatusesArray) {
    DisplayMetrics dm = new DisplayMetrics();
    this.activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

    //final int height = dm.heightPixels;
    final int width = dm.widthPixels;
    final int height = dm.heightPixels;

    int popupWidth = (int) (width * 0.75);
    int popupHeight = height;

    // Inflate the popup_layout.xml
    ScrollView viewGroup = (ScrollView) this.activity.findViewById(R.id.popupGetStatus);
    LayoutInflater layoutInflater = (LayoutInflater) this.activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    final View layout = layoutInflater.inflate(R.layout.popup_get_status, viewGroup);
    layout.setBackgroundResource(R.drawable.popup_gradient);

    // Crer le PopupWindow
    final PopupWindow popupPublishStatus = new PopupWindow(layout, popupWidth, LayoutParams.WRAP_CONTENT, true);
    popupPublishStatus.setBackgroundDrawable(new BitmapDrawable());
    popupPublishStatus.setOutsideTouchable(true);

    // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
    final int OFFSET_X = 0;
    final int OFFSET_Y = 0;

    // Displaying the popup at the specified location, + offsets.
    this.activity.findViewById(R.id.layoutMain).post(new Runnable() {
        public void run() {
            popupPublishStatus.showAtLocation(layout, Gravity.CENTER, OFFSET_X, OFFSET_Y);
        }/*w w  w  .ja  v a 2  s .c  o m*/
    });

    /*
     * Evenements composants du PopupWindow
     */

    // Find the ListView resource. 
    ListView mainListView = (ListView) layout.findViewById(R.id.listViewStatus);

    ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

    SimpleAdapter adapter = new SimpleAdapter(this.activity, list, R.layout.custom_row_view,
            new String[] { "content", "lat", "lon" }, new int[] { R.id.text1, R.id.text2, R.id.text3 });

    try {
        // Appel REST pour recuperer les status de l'utilisateur connect
        //Session session = new Session(this.activity);
        //session.parseJSONUrl("https://jibiki.univ-savoie.fr/ltpdev/rest.php/api/1/statuses", "STATUSES", "GET");

        // Parser la liste des amis dans le OverlayItem ArrayList
        HashMap<String, String> temp;
        for (int i = 0; (i < 6); i++) {
            // Obtenir le status
            JSONObject status = pStatusesArray.getJSONObject(i);

            temp = new HashMap<String, String>();
            temp.put("content", status.getString("content"));
            temp.put("lat", String.valueOf(status.getDouble("lat")));
            temp.put("lon", String.valueOf(status.getDouble("lon")));
            list.add(temp);
        }
    } catch (JSONException jex) {
        Log.e("Catch", "popupGetStatus / JSONException : " + jex.getStackTrace());
    } catch (Exception ex) {
        Log.e("Catch", "popupGetStatus / Exception : " + ex.getLocalizedMessage());
    }

    mainListView.setAdapter(adapter);
}

From source file:ab.util.AbDialogUtil.java

/**
 * popupwindow//from  w w w.ja  v a2s. c om
 */
public static PopupWindow showPopWindow(Context context, View targetView, View contentView, Integer width) {
    PopupWindow popupWindow = null;
    popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    if (width != null) {
        popupWindow.setWidth(width);
    }
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAsDropDown(targetView);
    return popupWindow;
}

From source file:ab.util.AbDialogUtil.java

/**
 * popupwindow//w  ww  .ja v a 2  s.  c o m
 */
public static PopupWindow showPopWindow2(Context context, View targetView, View contentView, Integer width) {
    PopupWindow popupWindow = null;
    popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    if (width != null) {
        popupWindow.setWidth(width);
    }
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(targetView, Gravity.BOTTOM, 0, 0);
    return popupWindow;
}

From source file:ab.util.AbDialogUtil.java

/**
 * popupwindow/* www  .j  ava  2s . co  m*/
 */
public static PopupWindow showPopWindow3(Context context, View targetView, View contentView, Integer width) {
    PopupWindow popupWindow = null;
    popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    if (width != null) {
        popupWindow.setWidth(width);
    }
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(targetView, Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
    return popupWindow;
}

From source file:ab.util.AbDialogUtil.java

public static MyPop showDatePopWindow(Context context, View contentView, View targetView) {
    // //from   w  w w. j a va  2  s. c o m
    yearArrayString = getYEARArray(2016, 30);
    monthArrayString = getDayArray(12);
    hourArrayString = getHMArray(24);
    minuteArrayString = getHMArray(60);
    // ??
    c = Calendar.getInstance();
    PopupWindow popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    popupWindow.setWidth(context.getResources().getDisplayMetrics().widthPixels);
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(targetView, Gravity.BOTTOM, 0, 0);
    yearWV = (WheelView) contentView.findViewById(R.id.time_year);
    monthWV = (WheelView) contentView.findViewById(R.id.time_month);
    dayWV = (WheelView) contentView.findViewById(R.id.time_day);
    hourWV = (WheelView) contentView.findViewById(R.id.time_hour);
    minuteWV = (WheelView) contentView.findViewById(R.id.time_minute);

    // ?
    yearWV.setVisibleItems(5);
    monthWV.setVisibleItems(5);
    dayWV.setVisibleItems(5);
    hourWV.setVisibleItems(5);
    minuteWV.setVisibleItems(5);

    // 
    yearWV.setLabel("");
    monthWV.setLabel("");
    dayWV.setLabel("");
    hourWV.setLabel("");
    minuteWV.setLabel("");
    yearWV.setCyclic(true);
    monthWV.setCyclic(true);
    dayWV.setCyclic(true);
    hourWV.setCyclic(true);
    minuteWV.setCyclic(true);
    setData();
    return new MyPop(popupWindow, yearWV, monthWV, dayWV, hourWV, minuteWV);
}

From source file:ab.util.AbDialogUtil.java

/**
 * /*from  w w  w  . j  a va2s  . c o  m*/
 */
public static MyPop showDatePopWindowDate(Context context, View contentView, View targetView) {
    // 
    yearArrayString = getYEARArray(2016, 36);
    monthArrayString = getDayArray(12);
    hourArrayString = getHMArray(24);
    minuteArrayString = getHMArray(60);
    // ??
    c = Calendar.getInstance();
    PopupWindow popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
    popupWindow.setWidth(context.getResources().getDisplayMetrics().widthPixels);
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(targetView, Gravity.BOTTOM, 0, 0);
    yearWV = (WheelView) contentView.findViewById(R.id.time_year);
    monthWV = (WheelView) contentView.findViewById(R.id.time_month);
    dayWV = (WheelView) contentView.findViewById(R.id.time_day);
    hourWV = (WheelView) contentView.findViewById(R.id.time_hour);
    minuteWV = (WheelView) contentView.findViewById(R.id.time_minute);
    hourWV.setVisibility(View.GONE);
    minuteWV.setVisibility(View.GONE);
    // ?
    yearWV.setVisibleItems(5);
    monthWV.setVisibleItems(5);
    dayWV.setVisibleItems(5);
    hourWV.setVisibleItems(5);
    minuteWV.setVisibleItems(5);

    // 
    yearWV.setLabel("");
    monthWV.setLabel("");
    dayWV.setLabel("");
    hourWV.setLabel("");
    minuteWV.setLabel("");
    yearWV.setCyclic(true);
    monthWV.setCyclic(true);
    dayWV.setCyclic(true);
    hourWV.setCyclic(true);
    minuteWV.setCyclic(true);
    setData();
    return new MyPop(popupWindow, yearWV, monthWV, dayWV, hourWV, minuteWV);
}

From source file:bruce.kk.brucetodos.MainActivity.java

/**
 * ? /*ww  w. j  a  v  a  2s  .  c  o m*/
 */
private void showAddPop() {
    final EditText editText = new EditText(MainActivity.this);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    editText.setLayoutParams(layoutParams);
    //        editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    editText.setTextColor(getResources().getColor(android.R.color.holo_green_light));
    editText.setHint("?~");
    editText.setHintTextColor(getResources().getColor(android.R.color.holo_orange_dark));
    editText.setBackgroundColor(getResources().getColor(android.R.color.black));
    final PopupWindow popupWindow = new PopupWindow(editText, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setBackgroundDrawable(new BitmapDrawable()); // ?
    popupWindow.setTouchable(true);
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(contentMain, Gravity.CENTER, 0, 0);

    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            LogDetails.d(": " + editText.getText().toString());
            if (!TextUtils.isEmpty(editText.getText().toString().trim())) {
                ProgressDialogUtils.showProgressDialog();
                UnFinishItem item = new UnFinishItem();
                Date date = new Date();
                item.createDay = date;
                item.content = editText.getText().toString().trim();
                item.modifyDay = date;
                dataList.add(item);
                refreshData(true);
                presenter.addItem(item);
            }
        }
    });
}

From source file:bruce.kk.brucetodos.MainActivity.java

/**
 * ???/*  ww w  .j  av a 2  s.  c om*/
 *
 * @param position
 */
private void modifyItem(final int position) {
    final UnFinishItem item = dataList.get(position);
    LogDetails.d(item);
    LinearLayout linearLayout = new LinearLayout(MainActivity.this);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    linearLayout.setLayoutParams(layoutParams);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setBackgroundColor(getResources().getColor(android.R.color.black));

    final EditText editText = new EditText(MainActivity.this);
    editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    editText.setTextColor(getResources().getColor(android.R.color.holo_green_light));
    editText.setHint(item.content);
    editText.setHintTextColor(getResources().getColor(android.R.color.holo_orange_dark));

    linearLayout.addView(editText);

    Button btnModify = new Button(MainActivity.this);
    btnModify.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    btnModify.setText("");
    btnModify.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    btnModify.setTextColor(getResources().getColor(android.R.color.holo_blue_bright));
    btnModify.setBackgroundColor(getResources().getColor(android.R.color.black));

    linearLayout.addView(btnModify);

    Button btnDeleteItem = new Button(MainActivity.this);
    btnDeleteItem.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    btnDeleteItem.setText("");
    btnDeleteItem.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    btnDeleteItem.setTextColor(getResources().getColor(android.R.color.holo_blue_bright));
    btnDeleteItem.setBackgroundColor(getResources().getColor(android.R.color.black));

    linearLayout.addView(btnDeleteItem);

    final PopupWindow popupWindow = new PopupWindow(linearLayout, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setBackgroundDrawable(new BitmapDrawable()); // ?
    popupWindow.setTouchable(true);
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(contentMain, Gravity.CENTER, 0, 0);

    btnModify.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            LogDetails.d(": " + editText.getText().toString());
            if (!TextUtils.isEmpty(editText.getText().toString().trim())) {
                Date date = new Date();
                item.content = editText.getText().toString().trim();
                item.modifyDay = date;
                item.finishDay = null;
                ProgressDialogUtils.showProgressDialog();
                presenter.modifyItem(item);
                dataList.set(position, item);
                refreshData(true);
                popupWindow.dismiss();
            } else {
                Toast.makeText(MainActivity.this, "~", Toast.LENGTH_SHORT).show();
            }
        }
    });
    btnDeleteItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dataList.remove(position);
            presenter.deleteItem(item);
            refreshData(false);
            popupWindow.dismiss();
        }
    });
}