Implement emojis in android keyboard with popupwindow - android

I've developed a keyboard and now i need to add emojis to it , from other questions i've realized the best way is with popupwindow,
Here's what i've done:
case -102:
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.emoji_view, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
popupWindow.showAsDropDown(getWindow().getOwnerActivity().getCurrentFocus(),50, -30);
Unfortunatly this doesn't work , showAsDropDown needs a view as its first var , and if the keyboard is in another app i don't have a view to give him...
Is there a way to fix that ?
or am i going about it all wrong and there is a better way...
all help will be appreciated!

Given that you are using the official SoftKeyBoard implementation as a template for your keyboard:
//Cut some pieces of the code for clarity
case -102:
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.emoji_view, null);
PopupWindow popupWindow = new PopupWindow(popupView, MATCH_PARENT, MATCH_PARENT);
popupWindow.showAsDropDown(mInputView);
Use the view that you have inflated for your keyboard, in the offical SoftKeyBoard and the snippet above it is called mInputView.

hi i have done same things. I have made one custom keyboard in android.
EmoticonsPagerAdapter emojiAdapter;
/**
* Defining all components of emoticons keyboard
*/
private void enablePopUpView() {
final ViewPager pager = (ViewPager) popUpView
.findViewById(R.id.emoticons_pager);
pager.setOffscreenPageLimit(3);
final ArrayList<EmojiItem> paths = EmojiUtil.getInstance(acitiviy)
.getAllEmojis();
final ArrayList<EmojiItem>[] groups = new ArrayList[5];
for (EmojiItem emoji : paths) {
if (groups[emoji.emojiGroup] == null) {
groups[emoji.emojiGroup] = new ArrayList<EmojiItem>();
}
groups[emoji.emojiGroup].add(emoji);
}
final ArrayList<EmojiItem> history = new ArrayList<EmojiItem>();
ArrayList<Integer> historyIds = SettingsUtil.getHistoryItems(acitiviy);
for (Integer his : historyIds) {
for (EmojiItem emoji : paths) {
if (emoji.id == his) {
history.add(emoji);
break;
}
}
}
history.add(paths.get(0));
final KeyClickListener onEmojiClick = new KeyClickListener() {
#Override
public void keyClickedIndex(EmojiItem index) {
int cursorPosition = editMessage.getSelectionStart();
editMessage.getText().insert(cursorPosition, index.emojiText);
try {
editMessage.getText().setSpan(
new ImageSpan(index.emojiDrawable), cursorPosition,
cursorPosition + 1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} catch (Exception e) {
}
if (history.get(0) != index)
history.add(0, index);
SettingsUtil.setHistoryItems(acitiviy, history);
emojiAdapter.notifyDataSetChanged();
pager.setAdapter(emojiAdapter);
}
};
((ImageButton) popUpView.findViewById(R.id.emoji2))
.setImageDrawable(groups[0].get(0).emojiDrawable);
((ImageButton) popUpView.findViewById(R.id.emoji3))
.setImageDrawable(groups[1].get(0).emojiDrawable);
((ImageButton) popUpView.findViewById(R.id.emoji4))
.setImageDrawable(groups[2].get(0).emojiDrawable);
((ImageButton) popUpView.findViewById(R.id.emoji5))
.setImageDrawable(groups[3].get(0).emojiDrawable);
((ImageButton) popUpView.findViewById(R.id.emoji6))
.setImageDrawable(groups[4].get(0).emojiDrawable);
popUpView.findViewById(R.id.emoji1).setOnClickListener(
new OnClickListener() {
#Override
public void onClick(View v) {
emojiAdapter.emojis = history;
emojiAdapter.notifyDataSetChanged();
pager.setAdapter(emojiAdapter);
}
});
popUpView.findViewById(R.id.emoji2).setOnClickListener(
new OnClickListener() {
#Override
public void onClick(View v) {
emojiAdapter.emojis = groups[0];
emojiAdapter.notifyDataSetChanged();
pager.setAdapter(emojiAdapter);
}
});
popUpView.findViewById(R.id.emoji3).setOnClickListener(
new OnClickListener() {
#Override
public void onClick(View v) {
emojiAdapter.emojis = groups[1];
emojiAdapter.notifyDataSetChanged();
pager.setAdapter(emojiAdapter);
}
});
popUpView.findViewById(R.id.emoji4).setOnClickListener(
new OnClickListener() {
#Override
public void onClick(View v) {
emojiAdapter.emojis = groups[2];
emojiAdapter.notifyDataSetChanged();
pager.setAdapter(emojiAdapter);
}
});
popUpView.findViewById(R.id.emoji5).setOnClickListener(
new OnClickListener() {
#Override
public void onClick(View v) {
emojiAdapter.emojis = groups[3];
emojiAdapter.notifyDataSetChanged();
pager.setAdapter(emojiAdapter);
}
});
popUpView.findViewById(R.id.emoji6).setOnClickListener(
new OnClickListener() {
#Override
public void onClick(View v) {
emojiAdapter.emojis = groups[4];
emojiAdapter.notifyDataSetChanged();
pager.setAdapter(emojiAdapter);
}
});
emojiAdapter = new EmoticonsPagerAdapter(acitiviy, groups[0],
onEmojiClick);
pager.setAdapter(emojiAdapter);
// Creating a pop window for emoticons keyboard
popupWindow = new PopupWindow(popUpView, LayoutParams.MATCH_PARENT,
(int) keyboardHeight, false);
View backSpace = (View) popUpView.findViewById(R.id.imageBackspace);
backSpace.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0,
0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
editMessage.dispatchKeyEvent(event);
}
});
popupWindow.setOnDismissListener(new OnDismissListener() {
#Override
public void onDismiss() {
emoticonsCover.setVisibility(LinearLayout.GONE);
}
});
ViewPager pagerStickers = (ViewPager) popUpView
.findViewById(R.id.stickers_pager);
pagerStickers.setOffscreenPageLimit(3);
}
private void showKeyboardPopup(View root, boolean attaches) {
if (!popupWindow.isShowing()) {
popupWindow.setHeight((int) (keyboardHeight));
if (isKeyBoardVisible) {
imageEmoji.setImageResource(R.drawable.emoji_kbd);
emoticonsCover.setVisibility(LinearLayout.GONE);
} else {
imageEmoji.setImageResource(R.drawable.ic_down);
emoticonsCover.setVisibility(LinearLayout.VISIBLE);
}
try {
popupWindow.showAtLocation(root, Gravity.BOTTOM, 0, 0);
} catch (Exception e) {
}
} else {
imageEmoji.setImageResource(R.drawable.emoji_btn_normal);
popupWindow.dismiss();
return;
}
imageAttaches.setBackgroundColor(attaches ? 0xFF808080 : 0x00000000);
imageEmojis.setBackgroundColor(attaches ? 0x00000000 : 0xFF808080);
imageStickers.setBackgroundColor(0x00000000);
layoutEmojis.setVisibility(attaches ? View.GONE : View.VISIBLE);
layoutStickers.setVisibility(View.GONE);
}
Please checkout for more details click here.
Thanks hope this will help you.It is bit old but you can try it.

you can refer this github link for complete code
EmojiIcon

Related

Why PopWindow make the screen black for a short time when the Activity finish

private void openInput(View v, String nickname) {
if (popInputNickName == null) {
View view = LayoutInflater.from(UserInfoActivity.this).inflate(R.layout.pop_nickname_modify, null);
popInputNickName = new InputPopWindow(view, LinearLayout.LayoutParams.MATCH_PARENT
, LinearLayout.LayoutParams.WRAP_CONTENT, true);
popInputNickName.setAnimationStyle(R.style.NewContentAnim);
popInputNickName.setBackgroundDrawable(new BitmapDrawable());
popInputNickName.setFocusable(true);
popInputNickName.setTouchable(true);
popInputNickName.setOutsideTouchable(true);
edit_nickname = (EditText) view.findViewById(R.id.edit_pop_nickname);
text_commit = (TextView) view.findViewById(R.id.text_pop_commit);
text_cancel = (TextView) view.findViewById(R.id.text_pop_cancel);
if (!TextUtils.isEmpty(nickname)) {
edit_nickname.setText(nickname);
}
text_commit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String nickName = edit_nickname.getText().toString().trim();
if (!TextUtils.isEmpty(nickName)) {
modifyNickName(nickName);
} else {
ToastUtil.Infotoast(UserInfoActivity.this, getString(R.string.null_nickname));
}
}
});
text_cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
popInputNickName.dismiss();
}
});
} else {
if (!TextUtils.isEmpty(nickname)) {
edit_nickname.setText(nickname);
}
}
popInputNickName.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
popInputNickName.showAtLocation(v, Gravity.BOTTOM, 0, 0);
edit_nickname.requestFocus();
InputMethodManager imm = (InputMethodManager) edit_nickname.getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
openInputTime = System.currentTimeMillis();
}
the popwindow show
When I enter to an activity(call it A) & shows a popwindow to modify user's nickname. When I finish A, the screen will be black for a while. But when i enter A and not open the popwindow, then no black screen appears, it completes as normal. So i wonder what caused this problem and how to fix it.
I am so sorry that the question is not clear. In the end I solved the problem.I used a custom-view that caused this problem.The edit_nickname in the PopWindow is a custom-view that extends EditText.
public class TfEditView extends EditText {
private OnFinishComposingListener mFinishComposingListener;
public TfEditView(Context context) {
super(context);
}
public TfEditView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TfEditView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void setOnFinishComposingListener(OnFinishComposingListener listener) {
this.mFinishComposingListener = listener;
}
#Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
return new MyInputConnection(super.onCreateInputConnection(outAttrs), false);
}
public class MyInputConnection extends InputConnectionWrapper {
public MyInputConnection(InputConnection target, boolean mutable) {
super(target, mutable);
}
#Override
public boolean finishComposingText() {
boolean finishComposing = super.finishComposingText();
if (mFinishComposingListener != null) {
mFinishComposingListener.finishComposing();
}
return finishComposing;
}
}
public interface OnFinishComposingListener {
void finishComposing();
}
}
private long openInputTime = 0;
private final long canHideTime = 500;
private void openInput(View v, String nickname) {
if (popInputNickName == null) {
View view = LayoutInflater.from(UserInfoActivity.this).inflate(R.layout.pop_nickname_modify, null);
popInputNickName = new InputPopWindow(view, LinearLayout.LayoutParams.MATCH_PARENT
, LinearLayout.LayoutParams.WRAP_CONTENT, true);
popInputNickName.setAnimationStyle(R.style.NewContentAnim);
popInputNickName.setBackgroundDrawable(new BitmapDrawable());
popInputNickName.setFocusable(true);
popInputNickName.setTouchable(true);
popInputNickName.setOutsideTouchable(true);
edit_nickname = (TfEditView) view.findViewById(R.id.edit_pop_nickname);
text_commit = (TextView) view.findViewById(R.id.text_pop_commit);
text_cancel = (TextView) view.findViewById(R.id.text_pop_cancel);
if (!TextUtils.isEmpty(nickname)) {
edit_nickname.setText(nickname);
}
edit_nickname.setOnFinishComposingListener(new TfEditView.OnFinishComposingListener() {
#Override
public void finishComposing() {
if (popInputNickName != null && popInputNickName.isShowing() && openInputTime != 0 && (System.currentTimeMillis() - openInputTime > canHideTime)) {
popInputNickName.dismiss();
}
}
});
text_commit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String nickName = edit_nickname.getText().toString().trim();
if (!TextUtils.isEmpty(nickName)) {
modifyNickName(nickName);
} else {
ToastUtil.Infotoast(UserInfoActivity.this, getString(R.string.null_nickname));
}
}
});
text_cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
popInputNickName.dismiss();
}
});
} else {
if (!TextUtils.isEmpty(nickname)) {
edit_nickname.setText(nickname);
}
}
popInputNickName.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
popInputNickName.showAtLocation(v, Gravity.BOTTOM, 0, 0);
edit_nickname.requestFocus();
InputMethodManager imm = (InputMethodManager) edit_nickname.getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
openInputTime = System.currentTimeMillis();
}
In the code above ,the popindow can dismissed longer than 500ms from the popwindow begin to show.

Android - Unable to add window

I am using AwesomeValidation to validate all forms in my app.
It works well for every other form other than a form which has a PopupWindow when user clicks a TextView.
When I click on the PopupWindow's button which validates the form inside it, it does nothing. But after I input anything inside the EditText, it shows
android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W#15f1d142 is not valid; is your activity running?
Here's my code for the popup window :
View.OnClickListener phoneReinputHandler = new View.OnClickListener() {
public void onClick(View arg0) {
/*Intent intent = new Intent(SignupStepTwoActivity.this, PopupHandphone.class);
backDim = (RelativeLayout) findViewById(R.id.bac_dim_layout);
//backDim.setVisibility(View.VISIBLE);
startActivity(intent);*/
mainLayout = (RelativeLayout)findViewById(R.id.activity_signup_step_two_mainLayout);
backDim = (RelativeLayout)findViewById(R.id.bac_dim_layout);
backDim.setVisibility(View.VISIBLE);
int width = displayMetrics.widthPixels;
int height = displayMetrics.heightPixels;
inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//View popupLayoutInflater = inflater.inflate(R.layout.popup_handphone, mainLayout);
PopupWindow pw = new PopupWindow(
inflater.inflate(R.layout.popup_handphone, null, false),
(int)(width * .8),
(int)(height*.35),
true);
//pw.setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
pw.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
pw.setOutsideTouchable(true);
RelativeLayout popupFunctionalitiesWrapper = (RelativeLayout)pw.getContentView().findViewById(R.id.popup_handphone_functionalities);
//popupFunctionalitiesWrapper.setGravity(Gravity.CENTER);
int popupFunctionalitiesWrapperWidth = layoutResize.width(70);
RelativeLayout.LayoutParams popupFunctionalitiesWrapperParams = (RelativeLayout.LayoutParams)popupFunctionalitiesWrapper.getLayoutParams();
popupFunctionalitiesWrapperParams.width = popupFunctionalitiesWrapperWidth;
popupFunctionalitiesWrapperParams.addRule(Gravity.CENTER);
popupFunctionalitiesWrapper.setLayoutParams(popupFunctionalitiesWrapperParams);
userPhonePopup = (EditText)pw.getContentView().findViewById((R.id.popup_handphone_phoneNumber));
mAwesomeValidation.addValidation(userPhonePopup, Patterns.PHONE, "Phone number must not be empty");
userPhoneCfmPopup = (EditText)pw.getContentView().findViewById((R.id.popup_handphone_phoneNumberConfirm));
Button buttonPhoneCodeResend = (Button)pw.getContentView().findViewById(R.id.popup_handphone_phoneNumberButton);
buttonPhoneCodeResend.setOnClickListener(new View.OnClickListener() {
AwesomeValidation resendPhoneValidation = new AwesomeValidation(ValidationStyle.COLORATION);
#Override
public void onClick(View v) {
Context context = v.getContext();
if(!((Activity) context).isFinishing())
{
if (!userPhonePopup.getText().toString().equals(userPhoneCfmPopup.getText().toString())) {
resendPhoneValidation.addValidation(userPhoneCfmPopup, "/^" + userPhonePopup.getText().toString() + "$/", "Nomor handphone harus sama");
}
resendPhoneValidation.validate();
}
}
});
pw.showAtLocation(mainLayout, Gravity.CENTER, 0, 0);
pw.setOnDismissListener(new PopupWindow.OnDismissListener() {
#Override
public void onDismiss() {
backDim.setVisibility(View.GONE);
}
});
}
};
A problem with Context?

multiple popups in android

I have two Linear Layouts in single activity .
I want to display custom popups on each of them when clicked.
When I click on first layout, popup apperas,then on clicking on 2nd layout ,both popups are displayed. how can i have only single popup displayed at a time?
this is my code
workLinearLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LayoutInflater layoutInflater=
(LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate
(R.layout.activity_your_places__work__popup, null);
updateTextView = (TextView)
popupView.findViewById(R.id.UpdateTextView);
updateTextView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(Your_Places2Activity.this,
UpdateWorkAddressActivity.class);
startActivity(i);
}
});
deleteTextView = (TextView)
popupView.findViewById(R.id.DeleteTextView);
deleteTextView.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v) {
//code to delete address
}
});
popupWindowWork = new PopupWindow(
popupView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
//dismiss other popup if is showing
if(popupWindowHome.isShowing())
{
popupWindowHome.dismiss();}
//display popup
popupWindowWork.showAsDropDown(workLinearLayout, 0, -70);
}
});
i have done same thing on other linear layout
popupWindowWork = new PopupWindow(
popupView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
if(popupWindowHome.isShowing())
{
popupWindowHome.dismiss();
}
in this line, you are dismissing the popupWindowHome dialog if popupWindowHome is showing, with popupWindowHome being the NEW dialog. Move the if statement before the constructor call.
if(popupWindowHome != null && popupWindowHome.isShowing())
{
popupWindowHome.dismiss();
}
popupWindowWork = new PopupWindow(
popupView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);

Multiple buttons in a popup, trying to stay organized

I'm implementing a popup in fragment Tab3Fragment and would like to keep the popup code in,
public void showPopup(View anchorView){
}
and minimized elsewhere in the Tab3Fragment as much as possible to keep things tidy.
Currently showPopup looks something like this,
public void showPopup(View anchorView) {
Button btnDismiss, btnFirstRecord, btnPreviousRecord, btnNextRecord, btnLastRecord;
LayoutInflater layoutInflater = (LayoutInflater)getActivity().getSystemServi (Context.LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup_layout, null);
final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
TextView tv = (TextView)popupView.findViewById(R.id.tv);
tv.setText("Blah, blah, blah");
btnDismiss = (Button)popupView.findViewById(R.id.btnDismissxml);
btnFirstRecord = (Button)popupView.findViewById(R.id.btnFirstRecordxml);
btnPreviousRecord = (Button)popupView.findViewById(R.id.btnPreviousRecordxml);
btnNextRecord = (Button)popupView.findViewById(R.id.btnNextRecordxml);
btnLastRecord = (Button)popupView.findViewById(R.id.btnLastRecordxml);
popupWindow.setFocusable(true);
int location[] = new int[2];
anchorView.getLocationOnScreen(location);
popupWindow.showAtLocation(anchorView, Gravity.CENTER, 0, 0);
}
}
QUESTION: Is there any way to implement an onClick method case-switch statement inside of showPopup that would handle this? Perhaps something like,
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnFirstRecordxml:
//firstRecord(v);
break;
case R.id.btnPreviousRecordxml:
//previousRecord(v);
break;
case R.id.btnNextRecordxml:
//nextRecord(v);
break;
case R.id.btnLastRecordxml:
//lastRecord(v);
break;
case R.id.btnDismissxml:
//closePopup(v);
break;
}}
Other solutions such as putting onClick in popup_layout.xml thusly,
<Button
android:id="#+id/btnFirstRecordxml"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/pszFirstRecordButton"
android:onClick="Tab3Fragment.firstRecord"/>
to handle button clicks would be highly appreciated. Thanks in advance...
Update, 23 Nov 2014.
Here is a solution that does work for more than one button's code in showPopup(). I'll have several buttons in the popup....
private void showPopup(){
LayoutInflater layoutInflater = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup_layout, null);
Button btnDismiss=(Button)popupView.findViewById(R.id.btnDismissxml);
Button btnSaveRecord=(Button)popupView.findViewById(R.id.btnSaveRecordxml);
final PopupWindow popupWindow=new PopupWindow(popupView,480,500,true);
popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 40);
//first button
btnSaveRecord.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
saveRecord();
}
});
//second button
btnDismiss.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}
});
}
Any way to insert a case-switch structure to allow other button code in showPopup()? This would avoid creating separate onClickListener-onClicks for each button as shown above.
Modify the xml like this, use android:onClick="ClickEvent" this formet in all the button
<Button
android:id="#+id/btnFirstRecordxml"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/pszFirstRecordButton"
android:onClick="ClickEvent"/>
<Button
android:id="#+id/btnPreviousRecordxml"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/pszPreviousRecordButton"
android:onClick="ClickEvent"/>
use the click funcationality like this,
public void clickEvent(View v)
{
switch (v.getId()) {
case R.id.btnFirstRecordxml:
//firstRecord(v);
break;
case R.id.btnPreviousRecordxml:
//previousRecord(v);
break;
case R.id.btnNextRecordxml:
//nextRecord(v);
break;
case R.id.btnLastRecordxml:
//lastRecord(v);
break;
case R.id.btnDismissxml:
//closePopup(v);
break;
}
}
Or try this,
btn.setOnClickListener(btnaction); set like this listener for all buttons,
OnClickListener btnaction = new OnClickListener() {
#Override
public void onClick(View v) {
//use the switch conditons...
}
};
btn1.setOnClickListener(btnaction);
btn2.setOnClickListener(btnaction);
public void showPopup(View anchorView) {
Button btnDismiss, btnFirstRecord, btnPreviousRecord, btnNextRecord, btnLastRecord;
LayoutInflater layoutInflater = (LayoutInflater)getActivity().getSystemServi (Context.LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup_layout, null);
final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
TextView tv = (TextView)popupView.findViewById(R.id.tv);
tv.setText("Blah, blah, blah");
btnDismiss = (Button)popupView.findViewById(R.id.btnDismissxml);
btnFirstRecord = (Button)popupView.findViewById(R.id.btnFirstRecordxml);
btnPreviousRecord = (Button)popupView.findViewById(R.id.btnPreviousRecordxml);
btnNextRecord = (Button)popupView.findViewById(R.id.btnNextRecordxml);
btnLastRecord = (Button)popupView.findViewById(R.id.btnLastRecordxml);
btnFirstRecord.setOnClickListener(new Listener());
btnPreviousRecord.setOnClickListener(new Listener());
btnNextRecord .setOnClickListener(new Listener());
btnLastRecord .setOnClickListener(new Listener());
popupWindow.setFocusable(true);
int location[] = new int[2];
anchorView.getLocationOnScreen(location);
popupWindow.showAtLocation(anchorView, Gravity.CENTER, 0, 0);
}
}
Class Listener implements OnClickListener
{
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnFirstRecordxml:
//firstRecord(v);
break;
case R.id.btnPreviousRecordxml:
//previousRecord(v);
break;
case R.id.btnNextRecordxml:
//nextRecord(v);
break;
case R.id.btnLastRecordxml:
//lastRecord(v);
break;
case R.id.btnDismissxml:
//closePopup(v);
break;
}
}
}

Android radial menu increase radial redius

I want to implement a radial menu widget and i have used radial-menu-v4 jar. My code is as follows...
public class RadialMenuActivity extends Activity {
private RadialMenuWidget pieMenu;
public Activity activity = this;
RelativeLayout l1;
public RadialMenuItem menuItem1,menuItem2,menuItem3,menuItem4,menuItem5,menuItem6,menuItem7,menuItem8,menuItem9,menuItem10, menuCloseItem, menuExpandItem;
public RadialMenuItem firstChildItem, secondChildItem, thirdChildItem;
private List<RadialMenuItem> children = new ArrayList<RadialMenuItem>();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.radial);
pieMenu = new RadialMenuWidget(this);
l1 = (RelativeLayout)findViewById(R.id.reltv1);
l1.addView(pieMenu);
menuCloseItem = new RadialMenuItem("Close", "Menu");
//menuCloseItem.setDisplayIcon(android.R.drawable.ic_menu_close_clear_cancel);
menuItem1 = new RadialMenuItem("1","j");
menuItem1.setDisplayIcon(android.R.drawable.ic_menu_close_clear_cancel);
/*firstChildItem = new RadialMenuItem("First","First");
firstChildItem.setOnMenuItemPressed(new RadialMenuItem.RadialMenuItemClickListener() {
#Override
public void execute() {
startActivity(new Intent(RadialMenuActivity.this, TestActivity.class));
pieMenu.dismiss();
}
});
secondChildItem = new RadialMenuItem("Second",null);
secondChildItem.setDisplayIcon(R.drawable.ic_launcher);
secondChildItem.setOnMenuItemPressed(new RadialMenuItem.RadialMenuItemClickListener() {
#Override
public void execute() {
Toast.makeText(RadialMenuActivity.this, "Second inner menu selected.", Toast.LENGTH_LONG).show();
}
});
thirdChildItem = new RadialMenuItem("Third","Third");
thirdChildItem.setDisplayIcon(R.drawable.ic_launcher);
thirdChildItem.setOnMenuItemPressed(new RadialMenuItem.RadialMenuItemClickListener() {
#Override
public void execute() {
Toast.makeText(RadialMenuActivity.this, "Third inner menu selected.", Toast.LENGTH_LONG).show();
}
});*/
menuItem2 = new RadialMenuItem("2", "a");
menuItem2.setDisplayIcon(android.R.drawable.ic_menu_close_clear_cancel);
menuItem3 = new RadialMenuItem("3", "i");
menuItem3.setDisplayIcon(android.R.drawable.ic_menu_close_clear_cancel);
menuItem4 = new RadialMenuItem("4", "b");
menuItem4.setDisplayIcon(android.R.drawable.ic_menu_close_clear_cancel);
menuItem5 = new RadialMenuItem("5", "c");
menuItem5.setDisplayIcon(android.R.drawable.ic_menu_close_clear_cancel);
menuItem6 = new RadialMenuItem("6", "d");
menuItem6.setDisplayIcon(android.R.drawable.ic_menu_close_clear_cancel);
menuItem7 = new RadialMenuItem("7", "e");
menuItem7.setDisplayIcon(android.R.drawable.ic_menu_close_clear_cancel);
menuItem8 = new RadialMenuItem("8", "f");
menuItem8.setDisplayIcon(android.R.drawable.ic_menu_close_clear_cancel);
menuItem9 = new RadialMenuItem("9", "g");
menuItem9.setDisplayIcon(android.R.drawable.ic_menu_close_clear_cancel);
menuItem10 = new RadialMenuItem("10", "h");
menuItem10.setDisplayIcon(android.R.drawable.ic_menu_close_clear_cancel);
/*children.add(firstChildItem);
children.add(secondChildItem);
children.add(thirdChildItem);*/
//menuExpandItem.setMenuChildren(children);
menuCloseItem.setOnMenuItemPressed(new RadialMenuItem.RadialMenuItemClickListener() {
#Override
public void execute() {
//menuLayout.removeAllViews();
pieMenu.dismiss();
}
});
menuItem1.setOnMenuItemPressed(new RadialMenuItem.RadialMenuItemClickListener() {
#Override
public void execute() {
startActivity(new Intent(RadialMenuActivity.this, TestActivity.class));
pieMenu.dismiss();
}
});
//pieMenu.setDismissOnOutsideClick(true, menuLayout);
int xLayoutSize = l1.getWidth();
int yLayoutSize = l1.getHeight();
pieMenu.setAnimationSpeed(0L);
//pieMenu.setSourceLocation(200, 200);
pieMenu.setSourceLocation(1000,1000);
pieMenu.setIconSize(10, 20);
pieMenu.setTextSize(10);
pieMenu.setOutlineColor(Color.WHITE, 225);
//pieMenu.setInnerRingColor(0xAA66CC, 10000000);
//pieMenu.setOuterRingColor(0x0099CC, 10000000);
//pieMenu.setCenterCircleRadius(40);
pieMenu.setOuterRingRadius(600, 600);
//pieMenu.setInnerRingRadius(100,100);
//pieMenu.setHeader("Test Menu", 20);
pieMenu.setCenterCircle(menuCloseItem);
pieMenu.addMenuEntry(new ArrayList<RadialMenuItem>() {{
add(menuItem1);
add(menuItem2);
add(menuItem3);
add(menuItem4);
add(menuItem5);
add(menuItem6);
add(menuItem7);
add(menuItem8);
add(menuItem9);
add(menuItem10);
}});
//pieMenu.addMenuEntry(menuItem);
//pieMenu.addMenuEntry(menuExpandItem);
/*Button testButton = (Button) this.findViewById(R.id.radial_menu_btn);
testButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//menuLayout.addView(pieMenu);
pieMenu.show(v);
}
});*/
}
But I cant increase outer radius of the circle. I am using min sdk version 8. Please help me with this. Thank you in advance.

Categories

Resources