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 || !(context instanceof Activity) || intent == null || intent.getAction() == null || view == null)
return;
String message = "";
String sipHashId = "";
switch(intent.getAction()) {
case "org.purple.smoke.chat_message":
if (((Activity) context).isFinishing())
return;
message = intent.getStringExtra("org.purple.smoke.message");
if (message == null)
return;
String name = intent.getStringExtra("org.purple.smoke.name");
if (name == null)
return;
else
name = name.trim();
sipHashId = intent.getStringExtra("org.purple.smoke.sipHashId");
if (sipHashId == null)
return;
else
sipHashId = sipHashId.toUpperCase();
if (name.isEmpty())
name = "unknown";
boolean purple = intent.getBooleanExtra("org.purple.smoke.purple", false);
long sequence = intent.getLongExtra("org.purple.smoke.sequence", 1L);
long timestamp = intent.getLongExtra("org.purple.smoke.timestamp", 0L);
State.getInstance().logChatMessage(message, name, sipHashId, purple, sequence, timestamp);
message = message.trim();
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 += "...";
}
}
if (message.isEmpty())
message = "A message from " + name + " has arrived.";
else
message = "A message (" + message + ") from " + name + " has arrived.";
break;
case "org.purple.smoke.siphash_share_confirmation":
sipHashId = intent.getStringExtra("org.purple.smoke.sipHashId");
if (sipHashId == null)
return;
else
sipHashId = sipHashId.toUpperCase();
if (Cryptography.SIPHASH_IDENTITY_LENGTH == sipHashId.length())
message = "A SmokeStack has received the Smoke Identity " + sipHashId + ".";
else
message = "A SmokeStack has received the Smoke Identity.";
break;
case "org.purple.smoke.time":
{
String string = intent.getStringExtra("org.purple.smoke.extra1");
if (string == null)
return;
else
message = string;
break;
}
case "org.purple.smoke.steam_added":
{
String string1 = intent.getStringExtra("org.purple.smoke.extra1");
String string2 = intent.getStringExtra("org.purple.smoke.extra2");
message = "A new Steam (" + string2 + ") has arrived from " + string1 + "!";
break;
}
default:
break;
}
if (message.isEmpty())
return;
TextView textView1 = new TextView(context);
final WeakReference<PopupWindow> popupWindow = new WeakReference<>(new PopupWindow(context));
textView1.setBackgroundColor(Color.rgb(255, 236, 179));
textView1.setText(message);
float density = context.getResources().getDisplayMetrics().density;
textView1.setPaddingRelative((int) (10 * density), (int) (10 * density), (int) (10 * density), (int) (10 * density));
textView1.setTextSize(16);
popupWindow.get().setContentView(textView1);
popupWindow.get().setOutsideTouchable(true);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
popupWindow.get().setHeight(300);
popupWindow.get().setWidth(450);
}
popupWindow.get().showAtLocation(view, Gravity.START | Gravity.TOP, 75, 75);
try {
if (s_ringtone != null)
s_ringtone.stop();
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
s_ringtone = RingtoneManager.getRingtone(context, notification);
s_ringtone.play();
} catch (Exception exception) {
}
Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (popupWindow.get() != null)
popupWindow.get().dismiss();
}
}, // 10 seconds.
10000L);
}
use of android.widget.PopupWindow in project ShelterApp by farzamtn.
the class MapsMasterActivity method newPopup.
/**
* Event handler for FAB which filters the pins displayed on the map. - Farzam
*
* @param view the current view
*/
public void newPopup(View view) {
// instantiate the maps_master_popup.xml layout file
LayoutInflater layoutInflater = (LayoutInflater) MapsMasterActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
assert layoutInflater != null;
View customView = layoutInflater.inflate(R.layout.maps_master_popup, null);
men_checkbox = customView.findViewById(R.id.men_checkbox);
women_checkbox = customView.findViewById(R.id.women_checkbox);
youngAdult_checkbox = customView.findViewById(R.id.youngAdult_checkbox);
children_checkbox = customView.findViewById(R.id.children_checkbox);
families_checkbox = customView.findViewById(R.id.families_checkbox);
veterans_checkbox = customView.findViewById(R.id.veterans_checkbox);
Button closePopupBtn = customView.findViewById(R.id.closePopupBtn);
Button resetBtn = 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 = 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 least 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());
assert s != null;
String restrictions = s.getRestrictions().trim().toLowerCase();
// Displaying shelters with no restrictions for all filters
if ("anyone".equals(restrictions) || "no restrictions".equals(restrictions)) {
m.setVisible(true);
}
if (men_checkbox.isChecked()) {
if ("men".equals(restrictions)) {
m.setVisible(true);
}
}
if (women_checkbox.isChecked()) {
if (restrictions.contains("women")) {
m.setVisible(true);
}
}
if (youngAdult_checkbox.isChecked()) {
if ("young adults".equals(s.getRestrictions().toLowerCase())) {
m.setVisible(true);
}
}
if (children_checkbox.isChecked()) {
if (restrictions.contains("children")) {
m.setVisible(true);
}
}
if (families_checkbox.isChecked()) {
if (restrictions.contains("famil")) {
m.setVisible(true);
}
}
if (veterans_checkbox.isChecked()) {
if ("veterans".equals(restrictions)) {
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();
});
}
use of android.widget.PopupWindow in project PowerMenu by skydoves.
the class AbstractPowerMenu method initialize.
protected void initialize(Context context, Boolean isMaterial) {
this.layoutInflater = LayoutInflater.from(context);
assert layoutInflater != null;
this.backgroundView = LayoutPowerBackgroundLibrarySkydovesBinding.inflate(layoutInflater, null, false).getRoot();
this.backgroundView.setOnClickListener(background_clickListener);
this.backgroundView.setAlpha(0.5f);
this.backgroundWindow = new PopupWindow(backgroundView, RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
this.backgroundWindow.setClippingEnabled(false);
this.menuView = getMenuRoot(isMaterial);
this.menuListView = getMenuList(isMaterial);
this.menuCard = getMenuCard(isMaterial);
this.menuWindow = new PopupWindow(menuView, FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
setFocusable(false);
setTouchInterceptor(onTouchListener);
setOnMenuItemClickListener(onMenuItemClickListener);
contentViewPadding = ConvertUtil.convertDpToPixel(10, context);
MenuPreferenceManager.initialize(context);
}
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);
popupWindow.setClippingEnabled(false);
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 screenWidth = getScreenWidth();
if (x < 0) {
x = 0;
} else if (x + popupWidth > screenWidth) {
x = screenWidth - popupWidth;
}
int y = location[1] - popupView.getMeasuredHeight() - spaceAboveKey;
popupWindow.showAtLocation(key, Gravity.NO_GRAVITY, x, y);
// popupWindow.showAsDropDown(key, 0, -500);
}
use of android.widget.PopupWindow in project ADWLauncher2 by boombuler.
the class Launcher method dismissPreview.
@SuppressWarnings({ "unchecked" })
private void dismissPreview(final View v) {
final PopupWindow window = (PopupWindow) v.getTag();
if (window != null) {
window.setOnDismissListener(new PopupWindow.OnDismissListener() {
public void onDismiss() {
ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
int count = group.getChildCount();
for (int i = 0; i < count; i++) {
((ImageView) group.getChildAt(i)).setImageDrawable(null);
}
ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
for (Bitmap bitmap : bitmaps) bitmap.recycle();
v.setTag(R.id.workspace, null);
v.setTag(R.id.icon, null);
window.setOnDismissListener(null);
}
});
window.dismiss();
}
v.setTag(null);
}
Aggregations