Quickblox sample chat Android privacy settings (block or unblock) - android

in quickblock sample chat, trying to add block and unblock for user 1-1 was unable to include ALL of the desired items .Only one user was adding to list always this is my code
privacyListsManager = QBChatService.getInstance().getPrivacyListsManager();
privacyListsManager.addPrivacyListListener(privacyListListener);
privacyListsManager.setPrivacyListAsActive("public");
QBPrivacyList list_all = null;
try {
list_all = privacyListsManager.getPrivacyList("public");
Log.e("lists", "privacyCheck: " + list_all + list_all.getItems());
privacyListsManager.setPrivacyList(list_all);
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
}
and on click of block, private void blockUser() {
List<Integer> userIds = qbChatDialog.getOccupants();
Log.e("userid ", "blockUser: " + id);
QBPrivacyList list = new QBPrivacyList();
list.setName("public");
ArrayList<QBPrivacyListItem> items = new ArrayList<QBPrivacyListItem>();
QBPrivacyListItem item1 = new QBPrivacyListItem();
item1.setAllow(false);
item1.setType(QBPrivacyListItem.Type.USER_ID);
item1.setValueForType(String.valueOf(id));
items.add(item1);
list.setItems(items);
try {
privacyListsManager.setPrivacyList(list);
privacyListsManager.setPrivacyListAsDefault("public");
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
}
privacyListListener = new QBPrivacyListListener() {
#Override
public void setPrivacyList(String listName, List<QBPrivacyListItem> listItem){
Log.e("block", "setPrivacyList: " );
}
#Override
public void updatedPrivacyList(String listName) {
Log.e("unblock", "setPrivacyList: " );
}
};
}
The problem is `QBPrivacyList always used to be override with the block click values but I want the previous data to be saved.

Related

Multiuserchat InvitationListener Smack: 4.1.0 not getting called

I have already gone through related questions on stack but all in vain. I am not getting callback in Invitation Listener. Any help will be appreciated.
MultiUserChatListener
MultiUserChatManager.getInstanceFor(connection).addInvitationListener(new InvitationListener() {
#Override
public void invitationReceived(XMPPConnection conn, MultiUserChat room, String inviter, String reason, String password, Message message) {
String nickname = AppSharedPereference.getInstance(mContext).getUserName();
try {
mchat.join(nickname);
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
}
});
}
sendInvitation Method
public void sendInvites(ArrayList<ContactData.Usercontactsdetail> usercontactsdetail) {
try {
for (int i = 0; i < usercontactsdetail.size(); i++) {
String userID = usercontactsdetail.get(i).getContactid();
String user = userID + "#" + connection.getHost();
mchat.invite(user,
userID + "_user");
}
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}finally {
usercontactsdetail = null;
}
try {
mchat.sendMessage("New group created");
} catch (SmackException.NotConnectedException e1) {
e1.printStackTrace();
}
}

XMPP error reply received from myroom#conference.****/myroom#conference.****: XMPPError: item-not-found - cancel

I am not able to join the room. I have gone through the documentation XMPP Instant Room Error
Here is how i am creating instant room:
try {
UserSearchManager usm = new UserSearchManager(Utils.connection);
List<DomainBareJid> services = usm.getSearchServices();
String roomjid = "myroom#" + services.get(0);
mucJid = JidCreate.entityBareFrom(roomjid);
Log.d(TAG, mucJid.toString());
// Create the nickname.
nickname = Resourcepart.from(roomjid);
Log.d(TAG, nickname.toString());
} catch (XmppStringprepException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
}
// Get the MultiUserChatManager
manager = MultiUserChatManager.getInstanceFor(Utils.connection);
// Get a MultiUserChat using MultiUserChatManager
MultiUserChat muc = manager.getMultiUserChat(mucJid);
// Create the room and send an empty configuration form to make this an instant room
try {
// Prepare a list of owners of the new room
Set<Jid> owners = JidUtil.jidSetFrom(new String[] { "54321#rahul", "12345#rahul" });
muc.create(nickname)
.getConfigFormManager()
.setRoomOwners(owners)
.submitConfigurationForm();
muc.sendConfigurationForm(new Form(DataForm.Type.submit));
muc.join(nickname);
EntityBareJid invitemucJid = JidCreate.entityBareFrom("12345#rahul");
muc.invite(invitemucJid, "testing");
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (MultiUserChatException.MucAlreadyJoinedException e) {
e.printStackTrace();
} catch (MultiUserChatException.MissingMucCreationAcknowledgeException e) {
e.printStackTrace();
} catch (MultiUserChatException.NotAMucServiceException e) {
e.printStackTrace();
} catch (XmppStringprepException e) {
e.printStackTrace();
} catch (MultiUserChatException.MucConfigurationNotSupportedException e) {
e.printStackTrace();
}
The MUC room is getting created successfully. But when i am checking through Invitation Listener and trying to join the room. It is giving error.
The Invitation listener code is as follow:
try {
Resourcepart nickname = Resourcepart.from(room.getRoom().toString());
room.join(nickname);
Log.d(TAG, "room status---> " + room.isJoined());
runOnUiThread(new Runnable() {
#Override
public void run() {
if (room.isJoined()) {
Toast.makeText(FriendListActivity.this, "Joined", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(FriendListActivity.this, "Not joined", Toast.LENGTH_SHORT).show();
}
}
});
} catch (XmppStringprepException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (MultiUserChatException.NotAMucServiceException e) {
e.printStackTrace();
}
Below is screen shot of the stack Trace
As per the documentation it says that the MUC room is locked. But I have created instant room along with default configuration.
Maybe it's a network error, I do somethings wrong if I use Wifi but get corrcet result with cellular network.

Smack 4.2.0-beta1 Error in creating group chat 'MultiUserChat. Cannot be accessed from outside package

I am developing Chat application. I have done one to one chat. But I cannot create Group chat because it shows an below error
'MultiUserChat(org.jivesoftware.smack.XMPPConnection, org.jxmpp.jid.EntityBareJid, org.jivesoftware.smackx.muc.MultiUserChatManager)' is not public in 'org.jivesoftware.smackx.muc.MultiUserChat'. 
Cannot be accessed from outside package
I have seen some answers about creating groups everyone using multiUserChat = new MultiUserChat(connection,room_name); to create a Group chat.
But in 4.2.0-beta1 version is not allowing us to access this class.
I have added my code below
public void createGroupChat() {
// Create a MultiUserChat using a Connection for a room
// (room name as the second parameter)
try {
Resourcepart nikname = Resourcepart.from("admin");
MultiUserChat mMultiUserChat = new MultiUserChat(connection, "room#conference.myserver");
mMultiUserChat.create(nikname);
Form form = mMultiUserChat.getConfigurationForm().createAnswerForm();
form.setAnswer("muc#roomconfig_publicroom", true);
form.setAnswer("muc#roomconfig_roomname", "room");
form.setAnswer("muc#roomconfig_roomowners", "owner");
form.setAnswer("muc#roomconfig_persistentroom", true);
mMultiUserChat.sendConfigurationForm(form);
} catch (XmppStringprepException e) {
e.printStackTrace();
} catch (MultiUserChatException.MucAlreadyJoinedException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (MultiUserChatException.MissingMucCreationAcknowledgeException e) {
e.printStackTrace();
} catch (NotConnectedException e) {
e.printStackTrace();
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (MultiUserChatException.NotAMucServiceException e) {
e.printStackTrace();
}
}
Can anyone tell me how to create group in Latest smack 4.2.0-beta1 version?
If I asked anything wrong sorry for that.
I Found an answer to create group chat from this below link
https://github.com/igniterealtime/Smack/blob/master/documentation/extensions/muc.md
I have added my new code also. It can be helpful for some of other developers
public void createGroupChat() {
// Create a MultiUserChat using a Connection for a room
// Get the MultiUserChatManager
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
try {
EntityBareJid jid = JidCreate.entityBareFrom("myroom" + "#"
+ context.getString(R.string.serviceNameOld));
// Create a MultiUserChat using an XMPPConnection for a room
MultiUserChat muc = manager.getMultiUserChat(jid);
// Prepare a list of owners of the new room
Set<Jid> owners = JidUtil.jidSetFrom(new String[]{"mathan#example.org", "kumar#example.org"});
// Create the room
Resourcepart nickname = Resourcepart.from("mathan");
muc.create(nickname).getConfigFormManager().setRoomOwners(owners).submitConfigurationForm();
} catch (XmppStringprepException e) {
e.printStackTrace();
} catch (MultiUserChatException.MucAlreadyJoinedException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (MultiUserChatException.MissingMucCreationAcknowledgeException e) {
e.printStackTrace();
} catch (NotConnectedException e) {
e.printStackTrace();
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (MultiUserChatException.NotAMucServiceException e) {
e.printStackTrace();
} catch (MultiUserChatException.MucConfigurationNotSupportedException e) {
e.printStackTrace();
}
}

Android: Activity freezes while running code that takes a while to complete

The app I am working on takes JSONs from a server and has to interpret them. I have around 6-7 JSONs that are requested.
As such, this is bound to take some time.
This code runs whenever the user types in information to an EditText and clicks a button. After the search button is clicked, the app freezes and will not do anything until all the data is loaded.
I tried having the code like this:
Button button = (Button) findViewById(R.id.search_button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
InputMethodManager imm = (InputMethodManager) getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(summonerNameET.getWindowToken(), 0);
final CollectUserData c = new CollectUserData();
c.setRegion(region);
c.setSummonerName(summonerNameET.getText().toString());
Runnable r = new Runnable() {
#Override
public void run() {
try {
c.setUpTheJSONs();
updateUI(c);
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
};
r.run();
}
});
But it still freezes. Here is the code for setUpTheJSON();
public void setUpTheJSONs() throws IOException, JSONException, URISyntaxException {
jsonSummonerInfo = getJsonSummonerInfo();
if(canIContinue()) {
jsonSummonerStats = getJsonSummaryStats();
//jsonSummonerRankedStats = getJsonRankedStats();
jsonSummonerMatchHistory = getJsonMatchHistory();
jsonSummonerLeagueInfo = getJsonSummonerLeagueInfo();
jsonSummonerRecentGames = getJsonSummonerRecentGames();
}
}
And here is the code for unpdateUI(c);
public void updateUI(CollectUserData c) {
if (c.canIContinue()) {
String league = "";
try {
league = c.getMundaneCurrentLeague();
} catch (JSONException e) {
e.printStackTrace();
}
setLeague(tierIV, league);
try {
summonerNameTV.setText(c.getSummonerName());
} catch (JSONException e) {
e.printStackTrace();
}
try {
tierTV.setText(c.getTier());
} catch (JSONException e) {
e.printStackTrace();
}
try {
leaguePointsTV.setText(c.getLeaguePoints() + "");
} catch (JSONException e) {
e.printStackTrace();
}
try {
winsTV.setText("W: " + c.getWins());
} catch (JSONException e) {
e.printStackTrace();
}
slashTV.setText("/");
try {
lossesTV.setText("L: " + c.getLosses());
} catch (JSONException e) {
e.printStackTrace();
}
try {
lastSeasonRankTV.setText("Season 4: " + c.getRankOfLastSeason());
} catch (JSONException e) {
e.printStackTrace();
}
try {
gameModeGameOneTV.setText(c.getGameType(1));
} catch (JSONException e) {
e.printStackTrace();
}
try {
gameOneChampion.setBackground(c.getChampionPicturePlayed(1));
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
gameOneKillsTV.setText(c.getKills(1) + "");
} catch (JSONException e) {
e.printStackTrace();
}
gameOneSlashOneTV.setText(" / ");
try {
gameOneDeathsTV.setText(c.getDeaths(1) + "");
} catch (JSONException e) {
e.printStackTrace();
}
gameOneSlashTwoTV.setText(" / ");
try {
gameOneAssistsTV.setText(c.getAssists(1) + "");
} catch (JSONException e) {
e.printStackTrace();
}
try {
gameOneGoldTV.setText(c.getGold(1) + " K");
} catch (JSONException e) {
e.printStackTrace();
}
try {
gameOneCSTV.setText(" " + c.getMinionsKilled(1) + " CS");
} catch (JSONException e) {
e.printStackTrace();
}
boolean gameOneWon = true;
try {
gameOneWon = c.isGameWon(1);
} catch (JSONException e) {
e.printStackTrace();
}
if (gameOneWon) {
gameOneTitleBar.setBackgroundColor(Color.parseColor("#d604c429"));
gameOne.setBackgroundColor(Color.parseColor("#4600FF06"));
}
if (!gameOneWon) {
gameOneTitleBar.setBackgroundColor(Color.parseColor("#d6ff0100"));
gameOne.setBackgroundColor(Color.parseColor("#4fff0100"));
}
try {
gameOneItemOneIV.setBackground(c.getItemFromMatchHistory(1, 0, getResources()));
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
gameOneItemTwoIV.setBackground(c.getItemFromMatchHistory(1, 1, getResources()));
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
gameOneItemThreeIV.setBackground(c.getItemFromMatchHistory(1, 2, getResources()));
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
gameOneItemFourIV.setBackground(c.getItemFromMatchHistory(1, 3, getResources()));
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
gameOneItemFiveIV.setBackground(c.getItemFromMatchHistory(1, 4, getResources()));
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
gameOneItemSixIV.setBackground(c.getItemFromMatchHistory(1, 5, getResources()));
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Drawable[] tempDrawable = null;
try {
tempDrawable = c.getTeamPlayerChampionIcon(1, 100);
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (tempDrawable != null) {
gameOneTeamOnePlayerOne.setBackground(tempDrawable[0]);
gameOneTeamOnePlayerTwo.setBackground(tempDrawable[1]);
gameOneTeamOnePlayerThree.setBackground(tempDrawable[2]);
gameOneTeamOnePlayerFour.setBackground(tempDrawable[3]);
gameOneTeamOnePlayerFive.setBackground(tempDrawable[4]);
}
Drawable[] tempDrawable2 = null;
try {
tempDrawable2 = c.getTeamPlayerChampionIcon(1, 200);
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (tempDrawable != null) {
gameOneTeamTwoPlayerOne.setBackground(tempDrawable2[0]);
gameOneTeamTwoPlayerTwo.setBackground(tempDrawable2[1]);
gameOneTeamTwoPlayerThree.setBackground(tempDrawable2[2]);
gameOneTeamTwoPlayerFour.setBackground(tempDrawable2[3]);
gameOneTeamTwoPlayerFive.setBackground(tempDrawable2[4]);
}
String[] tempString = null;
try {
tempString = c.getTeamPlayerName(1, 100);
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (tempString != null) {
gameOneTeamOnePlayerOneName.setText(tempString[0]);
gameOneTeamOnePlayerTwoName.setText(tempString[1]);
gameOneTeamOnePlayerThreeName.setText(tempString[2]);
gameOneTeamOnePlayerFourName.setText(tempString[3]);
gameOneTeamOnePlayerFiveName.setText(tempString[4]);
}
String[] tempString2 = null;
try {
tempString2 = c.getTeamPlayerName(1, 200);
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (tempString2 != null) {
gameOneTeamTwoPlayerOneName.setText(tempString2[0]);
gameOneTeamTwoPlayerTwoName.setText(tempString2[1]);
gameOneTeamTwoPlayerThreeName.setText(tempString2[2]);
gameOneTeamTwoPlayerFourName.setText(tempString2[3]);
gameOneTeamTwoPlayerFiveName.setText(tempString2[4]);
}
}
}
Anyone know a fix for this?
Thanks ☺
You need to introduce multi threading. The r.run() command needs to be started by another thread.
http://developer.android.com/training/multiple-threads/index.html
You are running the Runnable in the UI Thread and this is why you are getting your UI blocked until it finished.
Try something like this:
Button button = (Button) findViewById(R.id.search_button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
InputMethodManager imm = (InputMethodManager) getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(summonerNameET.getWindowToken(), 0);
final CollectUserData c = new CollectUserData();
c.setRegion(region);
c.setSummonerName(summonerNameET.getText().toString());
new Thread(new Runnable() {
#Override
public void run() {
try {
c.setUpTheJSONs();
updateUI(c);
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
}).start();
}
});
Put your downloading files in a separate thread. Use AsyncTask or Java Thread. Just simply.
class MyTask extends AsyncTask<Void, Void, Void> {
#Override
protected void onPreExecute() {
super.onPreExecute();
//Show progress dialog, if u want
}
#Override
protected Void doInBackground(Void... params) {
//Do all your processing here!
return null;
}
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
//Return some result to UI
}
}

How to show selection marker on EditText

In my app I programmatically set start and end selection on EditText via setSelection(int start, int end) method, but user doesn't see selection markers. How can I show markers programmatically?
When I said marker I mean this:
I found answer. Hope it will help someone. Need use method show when need show pins and in onSelectionChange need use hidePins, because pins don't hide after used showPins.
public void showPins() {
Class TV = TextView.class;
try {
Field GetEditor = TV.getDeclaredField("mEditor");
GetEditor.setAccessible(true);
Object editor = GetEditor.get(this);
Method GetInsController = editor.getClass().getDeclaredMethod("getSelectionController");
GetInsController.setAccessible(true);
Object insController = GetInsController.invoke(editor);
if (insController != null) {
Method Show = insController.getClass().getDeclaredMethod("show");
Show.setAccessible(true);
Show.invoke(insController);
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
public void hideTwoPins() {
Class TV = TextView.class;
try {
Field GetEditor = TV.getDeclaredField("mEditor");
GetEditor.setAccessible(true);
Object editor = GetEditor.get(this);
Method GetInsController = editor.getClass().getDeclaredMethod("getSelectionController");
GetInsController.setAccessible(true);
Object insController = GetInsController.invoke(editor);
if (insController != null) {
Method hide = insController.getClass().getDeclaredMethod("hide");
hide.setAccessible(true);
hide.invoke(insController);
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
custom method
/**
* Method allocates filtering substring in all contacts yellow color,
* that satisfy the user's search
* #param inputText - DisplayName
* filtText - filtering Text
* #return String with allocating substring (Spannable)
*/
public static Spannable changeBackgroungFiltText(CharSequence inputText, String filtText, int color) {
Spannable str = null;
if(inputText != null)
{
String inputStr = inputText.toString();
String inputLowerCaseStr = inputStr.toLowerCase();
String filtLowerCaseStr = filtText.toLowerCase();
// Spannable str = new SpannableStringBuilder(inputStr);
str = new SpannableStringBuilder(inputStr);
if (filtText.length() != 0)
{
int indexStart = 0;
while (true)
{
int indexCur = inputLowerCaseStr.indexOf(filtLowerCaseStr, indexStart);
if (indexCur != -1) {
int start = indexCur;
int end = indexCur + filtText.length();
int flag = Spannable.SPAN_EXCLUSIVE_EXCLUSIVE;
str.setSpan(new ForegroundColorSpan(color),start, end, flag);
//str.setSpan(new BackgroundColorSpan(highlightColor), start, end, flag);
indexStart = indexCur + 1;
} else {
return str;
}
}
} else {
return str;
}
}
return str;
}
Here is how to show the left or right pin,
based on the code of the second post (thanks a lot by the way).
public static void showSelectionPins(TextView textView, boolean left, boolean right) {
Class TV = TextView.class;
try {
Field GetEditor = TV.getDeclaredField("mEditor");
GetEditor.setAccessible(true);
Object editor = GetEditor.get(textView);
Method GetInsController = editor.getClass().getDeclaredMethod("getSelectionController");
GetInsController.setAccessible(true);
Object insController = GetInsController.invoke(editor);
if (insController != null) {
Method Show = insController.getClass().getDeclaredMethod("show");
Show.setAccessible(true);
Show.invoke(insController);
}
/**
* since the {#code mStartHandle} and {#code mEndHandle} are created lazily<br/>
* we must access them after {#code show()} has been called.
*/
if (!left) {
Field SelectionStartHandleView = insController.getClass().getDeclaredField("mStartHandle");
SelectionStartHandleView.setAccessible(true);
Object startHandleView = SelectionStartHandleView.get(insController);
Method handleViewHideMethod = startHandleView.getClass().getSuperclass().getDeclaredMethod("hide");
handleViewHideMethod.setAccessible(true);
handleViewHideMethod.invoke(startHandleView);
}
if (!right) {
Field SelectionEndHandleView = insController.getClass().getDeclaredField("mEndHandle");
SelectionEndHandleView.setAccessible(true);
Object endHandleView = SelectionEndHandleView.get(insController);
Method handleViewHideMethod = endHandleView.getClass().getSuperclass().getDeclaredMethod("hide");
handleViewHideMethod.setAccessible(true);
handleViewHideMethod.invoke(endHandleView);
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
Here is how to show the insertion pin,
also based on the code of the second post (thanks a lot by the way).
public static void showInsertionPin(TextView textView) {
Class TV = TextView.class;
try {
Field GetEditor = TV.getDeclaredField("mEditor");
GetEditor.setAccessible(true);
Object editor = GetEditor.get(textView);
Method GetInsertionPointCursorController = editor.getClass().getDeclaredMethod("getInsertionController");
GetInsertionPointCursorController.setAccessible(true);
Object insController = GetInsertionPointCursorController.invoke(editor);
if (insController != null) {
Method hide = insController.getClass().getDeclaredMethod("show");
hide.setAccessible(true);
hide.invoke(insController);
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}

Categories

Resources