Created
January 27, 2015 19:57
-
-
Save nathanjsweet/fc71131f2d8ce96d9804 to your computer and use it in GitHub Desktop.
Don't want to use the ShareActionProvider? Use the ShareActionAdapter instead
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyActivity extends Activity { | |
private ShareActionAdapter m_share_action_adapter = null; | |
private ListPopupWindow m_popup_social = null; | |
private Button m_share_button = null | |
@Override | |
public void OnCreate(Bundle savedInstance){ | |
setContentView(/*some_view that includes a button*/); | |
m_share_button = findViewById(R.id.my_share_btn); | |
m_share_button = m_actionbar.findViewById(R.id.share_btn); | |
m_share_button.setVisibility(View.VISIBLE); | |
m_share_action_adapter = new ShareActionAdapter(context); | |
m_share_button.setOnClickListener(new OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
setNewPopup(); | |
} | |
}); | |
m_share_action_adapter.setOnMenuListener(new ShareActionAdapter.OnMenuListner() { | |
@Override | |
public void onSeeAllSelected() { | |
m_popup_social.dismiss(); | |
m_share_action_adapter.setSeeAll(true); | |
setNewPopup(); | |
} | |
@Override | |
public void onItemSelected() { | |
m_popup_social.dismiss(); | |
} | |
}); | |
} | |
private void setNewPopup(){ | |
m_popup_social = new ListPopupWindow(getContext(), null, -1, R.style.LocalSaver_PopupMenuStyle); | |
m_popup_social.setAnchorView(m_share_button); | |
m_popup_social.setAdapter(m_share_action_adapter); | |
//R.dimen.popupwidth is 580.dp | |
int maxWidth = Math.max(getResources().getDisplayMetrics().widthPixels / 2, getResources().getDimensionPixelSize(R.dimen.popupwidth)); | |
m_popup_social.setWidth(maxWidth); | |
m_popup_social.setContentWidth(Math.min(maxWidth, m_share_action_adapter.measureContentWidth())); | |
m_popup_social.setModal(true); | |
m_popup_social.show(); | |
m_popup_social.setOnDismissListener(new PopupWindow.OnDismissListener() { | |
@Override | |
public void onDismiss() { | |
m_share_action_adapter.setSeeAll(false); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment