xxxxxxxxxx
public class TestPopupActivity extends Activity {
//The "x" and "y" position of the "Show Button" on screen.
Point p;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn_show = (Button) findViewById(R.id.show_popup);
btn_show.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
//Open popup window
if (p != null)
showPopup(TestPopupActivity.this, p);
}
});
}
// Get the x and y position after the button is draw on screen
// (It's important to note that we can't get the position in the onCreate(),
// because at that stage most probably the view isn't drawn yet, so it will return (0, 0))
@Override
public void onWindowFocusChanged(boolean hasFocus) {
int[] location = new int[2];
Button button = (Button) findViewById(R.id.show_popup);
// Get the x, y location and store it in the location[] array
// location[0] = x, location[1] = y.
button.getLocationOnScreen(location);
//Initialize the Point with x, and y positions
p = new Point();
p.x = location[0];
p.y = location[1];
}
// The method that displays the popup.
private void showPopup(final Activity context, Point p) {
int popupWidth = 200;
int popupHeight = 150;
// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);
// Creating the PopupWindow
final PopupWindow popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(popupWidth);
popup.setHeight(popupHeight);
popup.setFocusable(true);
// Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
int OFFSET_X = 30;
int OFFSET_Y = 30;
// Clear the default translucent background
popup.setBackgroundDrawable(new BitmapDrawable());
// Displaying the popup at the specified location, + offsets.
popup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);
// Getting a reference to Close button, and close the popup when clicked.
Button close = (Button) layout.findViewById(R.id.close);
close.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
popup.dismiss();
}
});
}
}
xxxxxxxxxx
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<config-file parent="com.apple.developer.associated-domains" target="*-Debug.plist">
<array>
<string>applinks:dianzishu.app</string>
</array>
</config-file>
<config-file parent="com.apple.developer.associated-domains" target="*-Release.plist">
<array>
<string>applinks:dianzishu.app</string>
</array>
</config-file>
<config-file parent="GADApplicationIdentifier" target="*-Info.plist">
<string>***ca-app-pub-3187198988135366~3590221682***</string>
</config-file>
<config-file parent="GADIsAdManagerApp" target="*-Info.plist">
<true />
</config-file>
xxxxxxxxxx
const ratings = asyncHandler(async (req, res) => {
const { _id } = req.user
const { star, prodId } = req.body;
try {
const product = await Product.findById(prodId);
let alreadyRated = product.ratings.find((userId) => userId.postedby.toString() === _id.toString())
if (alreadyRated) {
const updateRating = await Product.updateOne({
ratings: { $elemMatch: alreadyRated },
}, {
$set: { "ratings.$.star": star }
}, {
new: true,
})
} else {
const rateProduct = await Product.findByIdAndUpdate(prodId, {
$push: {
ratings: {
star: star,
postedby: _id,
},
},
}, {
new: true,
})
}
const getallratings = await Product.findById(prodId);
let totalRatings = getallratings.ratings.length;
let sumRatings = getallratings.ratings
.filter((item) => typeof item.star === 'number')
.map((item) => item.star)
.reduce((prev, current) => prev + current, 0);
let actualRatings = Math.round(sumRatings / totalRatings);
let finalproduct = await Product.findByIdAndUpdate(prodId, {
totalrating: actualRatings
}, { new: true });
res.json(finalproduct);
} catch (error) {
throw new Error(error);
}
})
xxxxxxxxxx
# RenameUnpickler
import io
import pickle
class RenameUnpickler(pickle.Unpickler):
def find_class(self, module, name):
renamed_module = module
if module == "tools":
renamed_module = "whyteboard.tools"
return super(RenameUnpickler, self).find_class(renamed_module, name)
def renamed_load(file_obj):
return RenameUnpickler(file_obj).load()
def renamed_loads(pickled_bytes):
file_obj = io.BytesIO(pickled_bytes)
return renamed_load(file_obj)