List of usage examples for android.widget PopupWindow PopupWindow
public PopupWindow()
Create a new empty, non focusable popup window of dimension (0,0).
The popup does not provide any background.
From source file:xj.property.activity.HXBaseActivity.ChatActivity.java
private void showPopWindow2() { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View mMenuView = inflater.inflate(R.layout.unservice_time, null); ((TextView) mMenuView.findViewById(R.id.tv_unservicetime)).setText("?" + MainActivity.startTime + "-" + MainActivity.endTime + "????"); ((TextView) mMenuView.findViewById(R.id.tv_unservicetime)) .setTextSize(getResources().getDimension(R.dimen.tv_unservicetime)); final PopupWindow popupWindow = new PopupWindow(); // ?//w w w. j a va2s . c o m // SelectPicPopupWindowView popupWindow.setContentView(mMenuView); // SelectPicPopupWindow popupWindow.setWidth(LinearLayout.LayoutParams.MATCH_PARENT); // SelectPicPopupWindow popupWindow.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT); // SelectPicPopupWindow? // this.setFocusable(true); // SelectPicPopupWindow // popupWindow.setAnimationStyle(R.style.AnimTop); TranslateAnimation translateAnimation = new TranslateAnimation(0, 0.0f, 0, 200f); translateAnimation.setDuration(2000); translateAnimation.setFillAfter(true); ((TextView) mMenuView.findViewById(R.id.tv_unservicetime)).setAnimation(translateAnimation); translateAnimation.start(); // ColorDrawable?? ColorDrawable dw = new ColorDrawable(0xb0000000); // SelectPicPopupWindow // mMenuViewOnTouchListener?????? new Handler().postDelayed(new Runnable() { @Override public void run() { // ,Animation.RELATIVE_TO_SELF,10f,Animation.RELATIVE_TO_SELF,10f popupWindow.showAsDropDown(findViewById(R.id.top_bar)); //popupWindow.showAtLocation(findViewById(R.id.list),Gravity.NO_GRAVITY,0,0); } }, 200); }
From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); final ImgurHoloActivity activity = (ImgurHoloActivity) getActivity(); final SharedPreferences settings = activity.getApiCall().settings; sort = settings.getString("CommentSort", "Best"); boolean newData = true; if (commentData != null) { newData = false;/* ww w .ja va2 s . c o m*/ } mainView = inflater.inflate(R.layout.single_image_layout, container, false); String[] mMenuList = getResources().getStringArray(R.array.emptyList); if (commentAdapter == null) commentAdapter = new CommentAdapter(mainView.getContext()); commentLayout = (ListView) mainView.findViewById(R.id.comment_thread); commentLayout.setChoiceMode(ListView.CHOICE_MODE_SINGLE); if (settings.getString("theme", MainActivity.HOLO_LIGHT).equals(MainActivity.HOLO_LIGHT)) imageLayoutView = (LinearLayout) View.inflate(getActivity(), R.layout.image_view, null); else imageLayoutView = (LinearLayout) View.inflate(getActivity(), R.layout.dark_image_view, null); mPullToRefreshLayout = (PullToRefreshLayout) mainView.findViewById(R.id.ptr_layout); ActionBarPullToRefresh.from(getActivity()) // Mark All Children as pullable .allChildrenArePullable() // Set the OnRefreshListener .listener(this) // Finally commit the setup to our PullToRefreshLayout .setup(mPullToRefreshLayout); if (savedInstanceState != null && newData) { imageData = savedInstanceState.getParcelable("imageData"); inGallery = savedInstanceState.getBoolean("inGallery"); } LinearLayout layout = (LinearLayout) imageLayoutView.findViewById(R.id.image_buttons); TextView imageDetails = (TextView) imageLayoutView.findViewById(R.id.single_image_details); layout.setVisibility(View.VISIBLE); ImageButton imageFullscreen = (ImageButton) imageLayoutView.findViewById(R.id.fullscreen); imageUpvote = (ImageButton) imageLayoutView.findViewById(R.id.rating_good); imageDownvote = (ImageButton) imageLayoutView.findViewById(R.id.rating_bad); ImageButton imageFavorite = (ImageButton) imageLayoutView.findViewById(R.id.rating_favorite); imageComment = (ImageButton) imageLayoutView.findViewById(R.id.comment); ImageButton imageUser = (ImageButton) imageLayoutView.findViewById(R.id.user); imageScore = (TextView) imageLayoutView.findViewById(R.id.single_image_score); TextView imageInfo = (TextView) imageLayoutView.findViewById(R.id.single_image_info); Log.d("imageData", imageData.getJSONObject().toString()); if (imageData.getJSONObject().has("ups")) { imageUpvote.setVisibility(View.VISIBLE); imageDownvote.setVisibility(View.VISIBLE); imageScore.setVisibility(View.VISIBLE); imageComment.setVisibility(View.VISIBLE); ImageUtils.updateImageFont(imageData, imageScore); } imageInfo.setVisibility(View.VISIBLE); ImageUtils.updateInfoFont(imageData, imageInfo); imageUser.setVisibility(View.VISIBLE); imageFavorite.setVisibility(View.VISIBLE); try { if (!imageData.getJSONObject().has("account_url") || imageData.getJSONObject().getString("account_url").equals("null") || imageData.getJSONObject().getString("account_url").equals("[deleted]")) imageUser.setVisibility(View.GONE); if (!imageData.getJSONObject().has("vote")) { imageUpvote.setVisibility(View.GONE); imageDownvote.setVisibility(View.GONE); } else { if (imageData.getJSONObject().getString("vote") != null && imageData.getJSONObject().getString("vote").equals("up")) imageUpvote.setImageResource(R.drawable.green_rating_good); else if (imageData.getJSONObject().getString("vote") != null && imageData.getJSONObject().getString("vote").equals("down")) imageDownvote.setImageResource(R.drawable.red_rating_bad); } if (imageData.getJSONObject().getString("favorite") != null && imageData.getJSONObject().getBoolean("favorite")) imageFavorite.setImageResource(R.drawable.green_rating_favorite); } catch (JSONException e) { Log.e("Error!", e.toString()); } imageFavorite.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.favoriteImage(singleImageFragment, imageData, (ImageButton) view, activity.getApiCall()); } }); imageUser.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.gotoUser(singleImageFragment, imageData); } }); imageComment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Activity activity = getActivity(); final EditText newBody = new EditText(activity); newBody.setHint(R.string.body_hint_body); newBody.setLines(3); final TextView characterCount = new TextView(activity); characterCount.setText("140"); LinearLayout commentReplyLayout = new LinearLayout(activity); newBody.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { // } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { characterCount.setText(String.valueOf(140 - charSequence.length())); } @Override public void afterTextChanged(Editable editable) { for (int i = editable.length(); i > 0; i--) { if (editable.subSequence(i - 1, i).toString().equals("\n")) editable.replace(i - 1, i, ""); } } }); commentReplyLayout.setOrientation(LinearLayout.VERTICAL); commentReplyLayout.addView(newBody); commentReplyLayout.addView(characterCount); new AlertDialog.Builder(activity).setTitle(R.string.dialog_comment_on_image_title) .setView(commentReplyLayout) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (newBody.getText() != null && newBody.getText().toString().length() < 141) { HashMap<String, Object> commentMap = new HashMap<String, Object>(); try { commentMap.put("comment", newBody.getText().toString()); commentMap.put("image_id", imageData.getJSONObject().getString("id")); Fetcher fetcher = new Fetcher(singleImageFragment, "3/comment/", ApiCall.POST, commentMap, ((ImgurHoloActivity) getActivity()).getApiCall(), POSTCOMMENT); fetcher.execute(); } catch (JSONException e) { Log.e("Error!", e.toString()); } } } }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); } }); imageUpvote.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.upVote(singleImageFragment, imageData, imageUpvote, imageDownvote, activity.getApiCall()); ImageUtils.updateImageFont(imageData, imageScore); } }); imageDownvote.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.downVote(singleImageFragment, imageData, imageUpvote, imageDownvote, activity.getApiCall()); ImageUtils.updateImageFont(imageData, imageScore); } }); if (popupWindow != null) { popupWindow.dismiss(); } popupWindow = new PopupWindow(); imageFullscreen.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.fullscreen(singleImageFragment, imageData, popupWindow, mainView); } }); ArrayAdapter<String> tempAdapter = new ArrayAdapter<String>(mainView.getContext(), R.layout.drawer_list_item, mMenuList); Log.d("URI", "YO I'M IN YOUR SINGLE FRAGMENT gallery:" + inGallery); imageView = (ImageView) imageLayoutView.findViewById(R.id.single_image_view); loadImage(); TextView imageTitle = (TextView) imageLayoutView.findViewById(R.id.single_image_title); TextView imageDescription = (TextView) imageLayoutView.findViewById(R.id.single_image_description); try { String size = String .valueOf(NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_WIDTH))) + "x" + NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_HEIGHT)) + " (" + NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_SIZE)) + "B)"; String initial = imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE) + " " + Html.fromHtml("•") + " " + size + " " + Html.fromHtml("•") + " " + "Views: " + NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_VIEWS)); imageDetails.setText(initial); Log.d("imagedata", imageData.getJSONObject().toString()); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE).equals("null")) imageTitle.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE)); else imageTitle.setVisibility(View.GONE); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION).equals("null")) { imageDescription .setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION)); imageDescription.setVisibility(View.VISIBLE); } else imageDescription.setVisibility(View.GONE); commentLayout.addHeaderView(imageLayoutView); commentLayout.setAdapter(tempAdapter); } catch (JSONException e) { Log.e("Text Error!", e.toString()); } if ((savedInstanceState == null || commentData == null) && newData) { commentData = new JSONParcelable(); getComments(); commentLayout.setAdapter(commentAdapter); } else if (newData) { commentArray = savedInstanceState.getParcelableArrayList("commentData"); commentAdapter.addAll(commentArray); commentLayout.setAdapter(commentAdapter); commentAdapter.notifyDataSetChanged(); } else if (commentArray != null) { commentAdapter.addAll(commentArray); commentLayout.setAdapter(commentAdapter); commentAdapter.notifyDataSetChanged(); } return mainView; }