Search in sources :

Example 36 with PopupWindow

use of android.widget.PopupWindow in project smoke by textbrowser.

the class Miscellaneous method showNotification.

public static void showNotification(Context context, Intent intent, View view) {
    if (context == null || intent == null || view == null)
        return;
    if (intent.getAction().equals("org.purple.smoke.chat_message")) {
        if (((Activity) context).isFinishing())
            return;
        String message = intent.getStringExtra("org.purple.smoke.message");
        String name = intent.getStringExtra("org.purple.smoke.name");
        String sipHashId = intent.getStringExtra("org.purple.smoke.sipHashId");
        if (message == null || name == null || sipHashId == null)
            return;
        long sequence = intent.getLongExtra("org.purple.smoke.sequence", 1);
        long timestamp = intent.getLongExtra("org.purple.smoke.timestamp", 0);
        State.getInstance().logChatMessage(message, name, sipHashId, sequence, timestamp);
        message = message.trim();
        TextView textView1 = new TextView(context);
        final PopupWindow popupWindow = new PopupWindow(context);
        if (name.length() > 15) {
            name = name.substring(0, 15);
            if (!name.endsWith("...")) {
                if (name.endsWith(".."))
                    name += ".";
                else if (name.endsWith("."))
                    name += "..";
                else
                    name += "...";
            }
        }
        if (message.length() > 15) {
            message = message.substring(0, 15);
            if (!message.endsWith("...")) {
                if (message.endsWith(".."))
                    message += ".";
                else if (message.endsWith("."))
                    message += "..";
                else
                    message += "...";
            }
        }
        textView1.setBackgroundColor(Color.rgb(244, 200, 117));
        textView1.setText("A message (" + message + ") from " + name + " has arrived.");
        textView1.setTextSize(16);
        popupWindow.setContentView(textView1);
        popupWindow.setOutsideTouchable(true);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            popupWindow.setHeight(300);
            popupWindow.setWidth(450);
        }
        popupWindow.showAtLocation(view, Gravity.START | Gravity.TOP, 75, 75);
        try {
            Ringtone ringtone = null;
            Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            ringtone = RingtoneManager.getRingtone(context, notification);
            ringtone.play();
        } catch (Exception e) {
        }
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                popupWindow.dismiss();
            }
        }, // 10 Seconds
        10000);
    }
}
Also used : Ringtone(android.media.Ringtone) PopupWindow(android.widget.PopupWindow) Activity(android.app.Activity) Handler(android.os.Handler) TextView(android.widget.TextView) Uri(android.net.Uri)

Example 37 with PopupWindow

use of android.widget.PopupWindow in project ShelterApp by farzamtn.

the class MapsMasterActivity method newPopup.

/**
 * Event handler for FAB which filters the pins displyed on the map. - Farzam
 */
public void newPopup(View view) {
    // instantiate the maps_master_popup.xml layout file
    LayoutInflater layoutInflater = (LayoutInflater) MapsMasterActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View customView = layoutInflater.inflate(R.layout.maps_master_popup, null);
    men_checkbox = (CheckBox) customView.findViewById(R.id.men_checkbox);
    women_checkbox = (CheckBox) customView.findViewById(R.id.women_checkbox);
    youngAdult_checkbox = (CheckBox) customView.findViewById(R.id.youngAdult_checkbox);
    children_checkbox = (CheckBox) customView.findViewById(R.id.children_checkbox);
    families_checkbox = (CheckBox) customView.findViewById(R.id.families_checkbox);
    veterans_checkbox = (CheckBox) customView.findViewById(R.id.veterans_checkbox);
    Button closePopupBtn = (Button) customView.findViewById(R.id.closePopupBtn);
    Button resetBtn = (Button) customView.findViewById(R.id.resetBtn);
    // Retrieving saved instances of checkedboxes
    SharedPreferences sp = getSharedPreferences("Men Check Boxes", MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    men_checkbox.setChecked(sp.getBoolean("men check", false));
    women_checkbox.setChecked(sp.getBoolean("women check", false));
    youngAdult_checkbox.setChecked(sp.getBoolean("young adult check", false));
    children_checkbox.setChecked(sp.getBoolean("children check", false));
    families_checkbox.setChecked(sp.getBoolean("families check", false));
    veterans_checkbox.setChecked(sp.getBoolean("veterans check", false));
    // instantiate popup window
    popupWindow = new PopupWindow(customView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    popupWindow.setOutsideTouchable(false);
    popupWindow.setFocusable(true);
    CoordinatorLayout c = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);
    // display the popup window
    popupWindow.showAtLocation(c, Gravity.CENTER, 0, 0);
    // set filter and close the popupwindow
    closePopupBtn.setOnClickListener(v -> {
        // Saving checkbox instances
        editor.putBoolean("men check", men_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("women check", women_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("young adult check", youngAdult_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("children check", children_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("families check", families_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("veterans check", veterans_checkbox.isChecked());
        editor.apply();
        // If all filters all selected show everything
        if (!(men_checkbox.isChecked() && women_checkbox.isChecked() && youngAdult_checkbox.isChecked() && children_checkbox.isChecked() && families_checkbox.isChecked() && veterans_checkbox.isChecked())) {
            for (Marker m : markers) {
                m.setVisible(true);
            }
        }
        // Making sure at leats one filter is selected
        if (men_checkbox.isChecked() || women_checkbox.isChecked() || youngAdult_checkbox.isChecked() || children_checkbox.isChecked() || families_checkbox.isChecked() || veterans_checkbox.isChecked()) {
            for (Marker m : markers) {
                m.setVisible(false);
                ShelterData s = model.findItemByName(m.getTitle());
                // Displaying shelters with no restrictions for all filters
                if (s.getRestrictions().trim().toLowerCase().equals("anyone") || s.getRestrictions().toLowerCase().equals("no restrictions")) {
                    m.setVisible(true);
                }
                if (men_checkbox.isChecked()) {
                    if (s.getRestrictions().trim().toLowerCase().equals("men")) {
                        m.setVisible(true);
                    }
                }
                if (women_checkbox.isChecked()) {
                    if (s.getRestrictions().trim().toLowerCase().contains("women")) {
                        m.setVisible(true);
                    }
                }
                if (youngAdult_checkbox.isChecked()) {
                    if (s.getRestrictions().toLowerCase().equals("young adults")) {
                        m.setVisible(true);
                    }
                }
                if (children_checkbox.isChecked()) {
                    if (s.getRestrictions().trim().toLowerCase().contains("children")) {
                        m.setVisible(true);
                    }
                }
                if (families_checkbox.isChecked()) {
                    if (s.getRestrictions().trim().toLowerCase().contains("famil")) {
                        m.setVisible(true);
                    }
                }
                if (veterans_checkbox.isChecked()) {
                    if (s.getRestrictions().trim().toLowerCase().equals("veterans")) {
                        m.setVisible(true);
                    }
                }
            }
        }
        popupWindow.dismiss();
    });
    // show all markers again and close the popupwindow
    resetBtn.setOnClickListener(view1 -> {
        for (Marker m : markers) {
            m.setVisible(true);
        }
        // Move camera to GT (DEFAULT) coordinates - Added by Farzam
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mDefaultLocation, DEFAULT_ZOOM));
        // Clearing all check boxes and their saved instances
        men_checkbox.setChecked(false);
        women_checkbox.setChecked(false);
        youngAdult_checkbox.setChecked(false);
        children_checkbox.setChecked(false);
        families_checkbox.setChecked(false);
        veterans_checkbox.setChecked(false);
        editor.putBoolean("men check", men_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("women check", women_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("young adult check", youngAdult_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("children check", children_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("families check", families_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("veterans check", veterans_checkbox.isChecked());
        editor.apply();
        popupWindow.dismiss();
    });
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) ShelterData(com.CS2340.shelterapp.Model.ShelterData) Button(android.widget.Button) FloatingActionButton(android.support.design.widget.FloatingActionButton) SharedPreferences(android.content.SharedPreferences) LayoutInflater(android.view.LayoutInflater) PopupWindow(android.widget.PopupWindow) Marker(com.google.android.gms.maps.model.Marker) NavigationView(android.support.design.widget.NavigationView) View(android.view.View)

Example 38 with PopupWindow

use of android.widget.PopupWindow in project mongol-library by suragch.

the class Keyboard method layoutAndShowPopupWindow.

private void layoutAndShowPopupWindow(Key key, int xPosition) {
    popupWindow = new PopupWindow(popupView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    int[] location = new int[2];
    key.getLocationInWindow(location);
    int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    popupView.measure(measureSpec, measureSpec);
    int popupWidth = popupView.getMeasuredWidth();
    int spaceAboveKey = key.getHeight() / 4;
    int x = xPosition - popupWidth / popupView.getChildCount() / 2;
    int y = location[1] - popupView.getMeasuredHeight() - spaceAboveKey;
    popupWindow.showAtLocation(key, Gravity.NO_GRAVITY, x, y);
}
Also used : PopupWindow(android.widget.PopupWindow)

Example 39 with PopupWindow

use of android.widget.PopupWindow in project BaseProject by fly803.

the class ViewUtils method showPopupWindow.

/**
 * 显示PopupWindow
 * @param context
 * @param resId
 * @param root
 * @param paramsType
 * @return
 */
public static View showPopupWindow(Context context, int resId, View root, int paramsType) {
    View popupView;
    popupView = LayoutInflater.from(context).inflate(resId, null);
    switch(paramsType) {
        case 1:
            popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
            break;
        case 2:
            popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
            break;
        case 3:
            popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
            break;
        case 4:
            popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
            break;
        default:
            popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
            break;
    }
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setTouchable(true);
    popupWindow.setBackgroundDrawable(new BitmapDrawable());
    popupWindow.showAsDropDown(root);
    return popupView;
}
Also used : PopupWindow(android.widget.PopupWindow) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TextView(android.widget.TextView)

Example 40 with PopupWindow

use of android.widget.PopupWindow in project AndroidStudy by tinggengyan.

the class NavigationMainActivity method showPop.

private void showPop() {
    final PopupWindow popupWindow = new PopupWindow(this);
    popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
    ColorDrawable dw = new ColorDrawable(getResources().getColor(R.color.pop_background));
    popupWindow.setBackgroundDrawable(dw);
    View popView = LayoutInflater.from(this).inflate(R.layout.layout_popwindow, null);
    RecyclerView navigationRecyclerView = (RecyclerView) popView.findViewById(R.id.navigationRecyclerView);
    ArrayList<NavigationAdapter.NavigationItem> data = new ArrayList<>();
    int size = 10;
    for (int i = 0; i < size; i++) {
        NavigationAdapter.NavigationItem item = new NavigationAdapter.NavigationItem((1 + i) + "", "第" + i + "title");
        // item.setLast(i == size - 1);
        ArrayList<String> ss = new ArrayList<>();
        for (int i1 = 0; i1 < i; i1++) {
            ss.add("景点" + i1);
        }
        item.setScenic(ss);
        data.add(item);
    }
    NavigationAdapter adapter = new NavigationAdapter(data, navigationRecyclerView);
    adapter.setItemClickListener(new NavigationAdapter.OnRecyclerViewItemClickListener() {

        @Override
        public void onItemClick(NavigationAdapter.NavigationItem data) {
            Toast.makeText(NavigationMainActivity.this, data.getTitle(), Toast.LENGTH_SHORT).show();
            if (popupWindow.isShowing()) {
                popupWindow.dismiss();
            }
        }
    });
    // 创建默认的线性LayoutManager ;设置成横向的,默认为竖屏的
    LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
    mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    navigationRecyclerView.setLayoutManager(mLayoutManager);
    navigationRecyclerView.setAdapter(adapter);
    popupWindow.setContentView(popView);
    popupWindow.setOutsideTouchable(false);
    popupWindow.setFocusable(true);
    popupWindow.setAnimationStyle(R.style.navigationPopWindowStyle);
    popupWindow.showAtLocation(getWindow().getDecorView(), Gravity.RIGHT, 0, 0);
}
Also used : PopupWindow(android.widget.PopupWindow) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) ColorDrawable(android.graphics.drawable.ColorDrawable) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

PopupWindow (android.widget.PopupWindow)133 View (android.view.View)66 TextView (android.widget.TextView)48 ColorDrawable (android.graphics.drawable.ColorDrawable)27 ImageView (android.widget.ImageView)24 Paint (android.graphics.Paint)22 Key (android.inputmethodservice.Keyboard.Key)14 AdapterView (android.widget.AdapterView)14 LinearLayout (android.widget.LinearLayout)14 LayoutInflater (android.view.LayoutInflater)13 Button (android.widget.Button)13 ListView (android.widget.ListView)13 Activity (android.app.Activity)12 BitmapDrawable (android.graphics.drawable.BitmapDrawable)12 OnClickListener (android.view.View.OnClickListener)11 ViewGroup (android.view.ViewGroup)11 Context (android.content.Context)10 Resources (android.content.res.Resources)10 EditText (android.widget.EditText)10 ScrollView (android.widget.ScrollView)10