List of usage examples for android.text Editable toString
public String toString();
From source file:org.zywx.wbpalmstar.plugin.chatkeyboard.ACEChatKeyboardView.java
private void jsonSendDataJsonCallback() { // TODO send callback Json if (mUexBaseObj != null) { JSONObject jsonObject = new JSONObject(); try {//from www.j a v a2 s .co m Editable editable = mEditText.getText(); jsonObject.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_EMOJICONS_TEXT, editable.toString()); JSONArray array = new JSONArray(); ForegroundColorSpan[] spans = editable.getSpans(0, editable.length(), ForegroundColorSpan.class); for (ForegroundColorSpan span : spans) { JSONObject insertObj = new JSONObject(); int spanStart = editable.getSpanStart(span); int spanEnd = editable.getSpanEnd(span); String insertText = editable.subSequence(spanStart, spanEnd).toString(); String insertTextColor = "#" + Integer.toHexString(span.getForegroundColor()).substring(2); insertObj.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_START, spanStart); insertObj.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_END, spanEnd); insertObj.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_INSERTTEXT, insertText); insertObj.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_INSERTTEXTCOLOR, insertTextColor); array.put(insertObj); } jsonObject.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_INSERTTEXTS, array); String js = EUExChatKeyboard.SCRIPT_HEADER + "if(" + EChatKeyboardUtils.CHATKEYBOARD_FUN_ON_COMMIT_JSON + "){" + EChatKeyboardUtils.CHATKEYBOARD_FUN_ON_COMMIT_JSON + "(" + jsonObject.toString() + ");}"; mUexBaseObj.onCallback(js); } catch (Exception e) { e.printStackTrace(); } } }
From source file:org.mozilla.focus.widget.InlineAutocompleteEditText.java
/** * Convert any autocomplete text to regular text * * @param text Current text content that may include autocomplete text *//*from ww w . j a va 2 s . c o m*/ private boolean commitAutocomplete(final Editable text) { final int start = text.getSpanStart(AUTOCOMPLETE_SPAN); if (start < 0) { // No autocomplete text return false; } beginSettingAutocomplete(); // Remove all spans here to convert from autocomplete text to regular text for (final Object span : mAutoCompleteSpans) { text.removeSpan(span); } // Keep mAutoCompleteResult the same because the result has not changed. // Reset mAutoCompletePrefixLength because the prefix now includes the autocomplete text. mAutoCompletePrefixLength = text.length(); // Reshow the cursor. setCursorVisible(true); endSettingAutocomplete(); // Filter on the new text if (mFilterListener != null) { mFilterListener.onFilter(text.toString(), null); } return true; }
From source file:org.mariotaku.twidere.fragment.support.MessagesConversationFragment.java
private void setupEditText() { EditTextEnterHandler.attach(mEditText, new EnterListener() { @Override/*from w ww . j a va2 s . c om*/ public void onHitEnter() { sendDirectMessage(); } }, mPreferences.getBoolean(KEY_QUICK_SEND, false)); mEditText.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(final Editable s) { Utils.removeLineBreaks(s); mTextChanged = s.length() == 0; } @Override public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) { } @Override public void onTextChanged(final CharSequence s, final int start, final int before, final int count) { if (mSendButton == null || s == null) return; mSendButton.setEnabled(mValidator.isValidTweet(s.toString())); } }); }
From source file:de.baumann.hhsmoodle.data_schedule.Schedule_Fragment.java
private void setScheduleList() { final int line = sharedPref.getInt("getLine", 1); //display data final int layoutstyle = R.layout.list_item_schedule; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.att_notes, R.id.textView_create_notes }; String[] column = new String[] { "schedule_title", "schedule_content", "schedule_attachment", "schedule_creation" }; final Cursor row = db.fetchAllData(); adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) { @Override//from w ww . ja va 2 s . c om public View getView(final int position, View convertView, ViewGroup parent) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title")); final String schedule_content = row2.getString(row2.getColumnIndexOrThrow("schedule_content")); final String schedule_icon = row2.getString(row2.getColumnIndexOrThrow("schedule_icon")); final String schedule_attachment = row2 .getString(row2.getColumnIndexOrThrow("schedule_attachment")); final String schedule_creation = row2.getString(row2.getColumnIndexOrThrow("schedule_creation")); final String schedule_id = row2.getString(row2.getColumnIndexOrThrow("schedule_id")); View v = super.getView(position, convertView, parent); ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes); if (position == line) { v.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorAccent_trans)); } else { v.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.color_trans)); } if (schedule_title.equals(getActivity().getString(R.string.schedule_weekend)) || schedule_title.equals(getActivity().getString(R.string.schedule_def_title))) { sharedPref.edit().putString("hour_" + schedule_id, "false").apply(); } else { sharedPref.edit().putString("hour_" + schedule_id, "true").apply(); } Subjects_helper.switchIcon(getActivity(), schedule_icon, "schedule_color", iv_icon); iv_icon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final helper_main.Item[] items = { new helper_main.Item(getString(R.string.subjects_color_red), R.drawable.circle_red), new helper_main.Item(getString(R.string.subjects_color_pink), R.drawable.circle_pink), new helper_main.Item(getString(R.string.subjects_color_purple), R.drawable.circle_purple), new helper_main.Item(getString(R.string.subjects_color_blue), R.drawable.circle_blue), new helper_main.Item(getString(R.string.subjects_color_teal), R.drawable.circle_teal), new helper_main.Item(getString(R.string.subjects_color_green), R.drawable.circle_green), new helper_main.Item(getString(R.string.subjects_color_lime), R.drawable.circle_lime), new helper_main.Item(getString(R.string.subjects_color_yellow), R.drawable.circle_yellow), new helper_main.Item(getString(R.string.subjects_color_orange), R.drawable.circle_orange), new helper_main.Item(getString(R.string.subjects_color_brown), R.drawable.circle_brown), new helper_main.Item(getString(R.string.subjects_color_grey), R.drawable.circle_grey), }; ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(), android.R.layout.select_dialog_item, android.R.id.text1, items) { @NonNull public View getView(int position, View convertView, @NonNull ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); tv.setTextSize(18); tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "1", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 1) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "2", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 2) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "3", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 3) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "4", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 4) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "5", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 5) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "6", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 6) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "7", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 7) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "8", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 8) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "9", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 9) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "10", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 10) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "11", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } } }).show(); } }); return v; } }; //display data by filter final String note_search = sharedPref.getString("filter_scheduleBY", "schedule_title"); sharedPref.edit().putString("filter_scheduleBY", "schedule_title").apply(); filter.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s.toString()); } }); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return db.fetchDataByFilter(constraint.toString(), note_search); } }); lv.setAdapter(adapter); //onClick function lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title")); final CharSequence[] options = { getString(R.string.schedule_todo), getString(R.string.schedule_notes) }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.schedule_todo))) { sharedPref.edit().putString("filter_todo_subject", schedule_title).apply(); new Handler().postDelayed(new Runnable() { public void run() { helper_main.switchToActivity(getActivity(), Popup_todo.class, false); } }, 200); } if (options[item].equals(getString(R.string.schedule_notes))) { sharedPref.edit().putString("filter_note_subject", schedule_title).apply(); new Handler().postDelayed(new Runnable() { public void run() { helper_main.switchToActivity(getActivity(), Popup_note.class, false); } }, 200); } } }).show(); } }); lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title")); final String schedule_content = row2.getString(row2.getColumnIndexOrThrow("schedule_content")); final String schedule_icon = row2.getString(row2.getColumnIndexOrThrow("schedule_icon")); final String schedule_attachment = row2 .getString(row2.getColumnIndexOrThrow("schedule_attachment")); final String schedule_creation = row2.getString(row2.getColumnIndexOrThrow("schedule_creation")); final String schedule_id = row2.getString(row2.getColumnIndexOrThrow("schedule_id")); final CharSequence[] options = { getString(R.string.number_edit_entry), getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_menu), getString(R.string.bookmark_createNote), getString(R.string.count_create), getString(R.string.bookmark_createEvent) }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @SuppressWarnings("ConstantConditions") @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.number_edit_entry))) { final CharSequence[] options = { getString(R.string.schedule_fromSubjectList), getString(R.string.todo_from_new) }; new AlertDialog.Builder(getActivity()).setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item] .equals(getString(R.string.schedule_fromSubjectList))) { sharedPref.edit().putString("edit_yes", "true") .putInt("scroll", Integer.parseInt(schedule_id)) .putString("handleSubjectCreation", schedule_creation) .putString("handleSubject_id", schedule_id) .putString("handle_id", _id).apply(); helper_main.switchToActivity(getActivity(), Popup_subjects.class, false); } if (options[item].equals(getString(R.string.todo_from_new))) { LayoutInflater inflater = getActivity().getLayoutInflater(); final ViewGroup nullParent = null; View dialogView = inflater .inflate(R.layout.dialog_edit_subject, nullParent); final EditText titleInput = (EditText) dialogView .findViewById(R.id.subject_title_); titleInput.setSelection(titleInput.getText().length()); titleInput.setText(schedule_title); final EditText teacherInput = (EditText) dialogView .findViewById(R.id.subject_teacher); teacherInput.setText(schedule_content); final EditText roomInput = (EditText) dialogView .findViewById(R.id.subject_room); roomInput.setText(schedule_attachment); helper_main.showKeyboard(getActivity(), titleInput); final ImageButton be = (ImageButton) dialogView .findViewById(R.id.imageButtonPri); assert be != null; Subjects_helper.switchIcon(getActivity(), schedule_icon, "schedule_color", be); be.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final helper_main.Item[] items = { new helper_main.Item(getString( R.string.subjects_color_red), R.drawable.circle_red), new helper_main.Item(getString( R.string.subjects_color_pink), R.drawable.circle_pink), new helper_main.Item(getString( R.string.subjects_color_purple), R.drawable.circle_purple), new helper_main.Item(getString( R.string.subjects_color_blue), R.drawable.circle_blue), new helper_main.Item(getString( R.string.subjects_color_teal), R.drawable.circle_teal), new helper_main.Item(getString( R.string.subjects_color_green), R.drawable.circle_green), new helper_main.Item(getString( R.string.subjects_color_lime), R.drawable.circle_lime), new helper_main.Item(getString( R.string.subjects_color_yellow), R.drawable.circle_yellow), new helper_main.Item(getString( R.string.subjects_color_orange), R.drawable.circle_orange), new helper_main.Item(getString( R.string.subjects_color_brown), R.drawable.circle_brown), new helper_main.Item(getString( R.string.subjects_color_grey), R.drawable.circle_grey), }; ListAdapter adapter = new ArrayAdapter<helper_main.Item>( getActivity(), android.R.layout.select_dialog_item, android.R.id.text1, items) { @NonNull public View getView(int position, View convertView, @NonNull ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v .findViewById(android.R.id.text1); tv.setTextSize(18); tv.setCompoundDrawablesWithIntrinsicBounds( items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (24 * getActivity().getResources() .getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new android.app.AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int whichButton) { dialog.cancel(); } }) .setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int item) { if (item == 0) { be.setImageResource( R.drawable.circle_red); sharedPref.edit() .putString( "schedule_color", "1") .apply(); } else if (item == 1) { be.setImageResource( R.drawable.circle_pink); sharedPref.edit() .putString( "schedule_color", "2") .apply(); } else if (item == 2) { be.setImageResource( R.drawable.circle_purple); sharedPref.edit() .putString( "schedule_color", "3") .apply(); } else if (item == 3) { be.setImageResource( R.drawable.circle_blue); sharedPref.edit() .putString( "schedule_color", "4") .apply(); } else if (item == 4) { be.setImageResource( R.drawable.circle_teal); sharedPref.edit() .putString( "schedule_color", "5") .apply(); } else if (item == 5) { be.setImageResource( R.drawable.circle_green); sharedPref.edit() .putString( "schedule_color", "6") .apply(); } else if (item == 6) { be.setImageResource( R.drawable.circle_lime); sharedPref.edit() .putString( "schedule_color", "7") .apply(); } else if (item == 7) { be.setImageResource( R.drawable.circle_yellow); sharedPref.edit() .putString( "schedule_color", "8") .apply(); } else if (item == 8) { be.setImageResource( R.drawable.circle_orange); sharedPref.edit() .putString( "schedule_color", "9") .apply(); } else if (item == 9) { be.setImageResource( R.drawable.circle_brown); sharedPref.edit() .putString( "schedule_color", "10") .apply(); } else if (item == 10) { be.setImageResource( R.drawable.circle_grey); sharedPref.edit() .putString( "schedule_color", "11") .apply(); } } }) .show(); } }); android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder( getActivity()); builder.setTitle(R.string.subjects_edit); builder.setView(dialogView); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTitle = titleInput.getText() .toString().trim(); String inputTeacher = teacherInput.getText() .toString().trim(); String inputRoom = roomInput.getText() .toString().trim(); db.update(Integer.parseInt(_id), inputTitle, inputTeacher, sharedPref.getString( "schedule_color", ""), inputRoom, schedule_creation, schedule_id); dialog.dismiss(); setScheduleList(); lv.setSelection( Integer.parseInt(schedule_id) - 1); Snackbar.make(lv, R.string.bookmark_added, Snackbar.LENGTH_SHORT).show(); } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final android.support.v7.app.AlertDialog dialog2 = builder .create(); dialog2.show(); } } }).show(); } if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) { Snackbar snackbar = Snackbar .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { db.update(Integer.parseInt(_id), getString(R.string.schedule_def_teacher), getString(R.string.schedule_def_teacher), "11", getString(R.string.schedule_def_teacher), schedule_creation, schedule_id); setScheduleList(); lv.setSelection(Integer.parseInt(schedule_id) - 1); } }); snackbar.show(); } if (options[item].equals(getString(R.string.todo_menu))) { Todo_helper.newTodo(getActivity(), schedule_title, schedule_content, getActivity().getString(R.string.note_content)); } if (options[item].equals(getString(R.string.count_create))) { Count_helper.newCount(getActivity(), schedule_title, schedule_content, getActivity().getString(R.string.note_content), false); } if (options[item].equals(getString(R.string.bookmark_createEvent))) { helper_main.createCalendarEvent(getActivity(), schedule_title, schedule_content); } if (options[item].equals(getString(R.string.bookmark_createNote))) { Notes_helper.newNote(getActivity(), schedule_title, schedule_content, "", "", "", ""); } } }).show(); return true; } }); scrollToNow(); }
From source file:com.money.manager.ex.transactions.EditTransactionCommonFunctions.java
public void initNotesControls() { if (!(TextUtils.isEmpty(transactionEntity.getNotes()))) { viewHolder.edtNotes.setText(transactionEntity.getNotes()); }//from w w w .j a v a 2 s. co m viewHolder.edtNotes.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { setDirty(true); transactionEntity.setNotes(editable.toString()); } }); }
From source file:org.mariotaku.twidere.fragment.MessagesConversationFragment.java
private void setupEditText() { EditTextEnterHandler.attach(mEditText, new EnterListener() { @Override// w ww. ja v a 2 s.com public boolean shouldCallListener() { return true; } @Override public boolean onHitEnter() { sendDirectMessage(); return true; } }, mPreferences.getBoolean(KEY_QUICK_SEND, false)); mEditText.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(final Editable s) { mTextChanged = s.length() == 0; } @Override public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) { } @Override public void onTextChanged(final CharSequence s, final int start, final int before, final int count) { if (mSendButton == null || s == null) return; mSendButton.setEnabled(mValidator.isValidDirectMessage(s.toString())); } }); }
From source file:org.matrix.console.activity.HomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { if (CommonActivityUtils.shouldRestartApp()) { Log.e(LOG_TAG, "Restart the application."); CommonActivityUtils.restartApp(this); }//from www.j av a 2s . c o m super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); mMyRoomList = (ExpandableListView) findViewById(R.id.listView_myRooms); // the chevron is managed in the header view mMyRoomList.setGroupIndicator(null); mAdapter = new ConsoleRoomSummaryAdapter(this, Matrix.getMXSessions(this), R.layout.adapter_item_my_rooms, R.layout.adapter_room_section_header); if (null != savedInstanceState) { if (savedInstanceState.containsKey(PUBLIC_ROOMS_LIST_LIST)) { Serializable map = savedInstanceState.getSerializable(PUBLIC_ROOMS_LIST_LIST); if (null != map) { HashMap<String, List<PublicRoom>> hash = (HashMap<String, List<PublicRoom>>) map; mPublicRoomsListList = new ArrayList<List<PublicRoom>>(hash.values()); mHomeServerNames = new ArrayList<>(hash.keySet()); } } } final Intent intent = getIntent(); if (intent.hasExtra(EXTRA_JUMP_TO_ROOM_ID)) { mAutomaticallyOpenedRoomId = intent.getStringExtra(EXTRA_JUMP_TO_ROOM_ID); } if (intent.hasExtra(EXTRA_JUMP_MATRIX_ID)) { mAutomaticallyOpenedMatrixId = intent.getStringExtra(EXTRA_JUMP_MATRIX_ID); } if (intent.hasExtra(EXTRA_ROOM_INTENT)) { mOpenedRoomIntent = intent.getParcelableExtra(EXTRA_ROOM_INTENT); } String action = intent.getAction(); String type = intent.getType(); // send files from external application if ((Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) && type != null) { this.runOnUiThread(new Runnable() { @Override public void run() { CommonActivityUtils.sendFilesTo(HomeActivity.this, intent); } }); } mMyRoomList.setAdapter(mAdapter); Collection<MXSession> sessions = Matrix.getMXSessions(HomeActivity.this); // check if there is some valid session // the home activity could be relaunched after an application crash // so, reload the sessions before displaying the hidtory if (sessions.size() == 0) { Log.e(LOG_TAG, "Weird : onCreate : no session"); if (null != Matrix.getInstance(this).getDefaultSession()) { Log.e(LOG_TAG, "No loaded session : reload them"); startActivity(new Intent(HomeActivity.this, SplashActivity.class)); HomeActivity.this.finish(); return; } } for (MXSession session : sessions) { addSessionListener(session); } mMyRoomList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { if (mAdapter.isRecentsGroupIndex(groupPosition)) { String roomId = null; MXSession session = null; RoomSummary roomSummary = mAdapter.getRoomSummaryAt(groupPosition, childPosition); session = Matrix.getInstance(HomeActivity.this).getSession(roomSummary.getMatrixId()); roomId = roomSummary.getRoomId(); Room room = session.getDataHandler().getRoom(roomId); // cannot join a leaving room if ((null == room) || room.isLeaving()) { roomId = null; } if (mAdapter.resetUnreadCount(groupPosition, roomId)) { session.getDataHandler().getStore().flushSummary(roomSummary); } if (null != roomId) { CommonActivityUtils.goToRoomPage(session, roomId, HomeActivity.this, null); } } else if (mAdapter.isPublicsGroupIndex(groupPosition)) { joinPublicRoom(mAdapter.getHomeServerURLAt(groupPosition), mAdapter.getPublicRoomAt(groupPosition, childPosition)); } return true; } }); mMyRoomList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { long packedPos = ((ExpandableListView) parent).getExpandableListPosition(position); final int groupPosition = ExpandableListView.getPackedPositionGroup(packedPos); if (mAdapter.isRecentsGroupIndex(groupPosition)) { final int childPosition = ExpandableListView.getPackedPositionChild(packedPos); FragmentManager fm = HomeActivity.this.getSupportFragmentManager(); IconAndTextDialogFragment fragment = (IconAndTextDialogFragment) fm .findFragmentByTag(TAG_FRAGMENT_ROOM_OPTIONS); if (fragment != null) { fragment.dismissAllowingStateLoss(); } final Integer[] lIcons = new Integer[] { R.drawable.ic_material_exit_to_app }; final Integer[] lTexts = new Integer[] { R.string.action_leave }; fragment = IconAndTextDialogFragment.newInstance(lIcons, lTexts); fragment.setOnClickListener(new IconAndTextDialogFragment.OnItemClickListener() { @Override public void onItemClick(IconAndTextDialogFragment dialogFragment, int position) { Integer selectedVal = lTexts[position]; if (selectedVal == R.string.action_leave) { HomeActivity.this.runOnUiThread(new Runnable() { @Override public void run() { final RoomSummary roomSummary = mAdapter.getRoomSummaryAt(groupPosition, childPosition); final MXSession session = Matrix.getInstance(HomeActivity.this) .getSession(roomSummary.getMatrixId()); String roomId = roomSummary.getRoomId(); Room room = session.getDataHandler().getRoom(roomId); if (null != room) { room.leave(new SimpleApiCallback<Void>(HomeActivity.this) { @Override public void onSuccess(Void info) { mAdapter.removeRoomSummary(groupPosition, roomSummary); mAdapter.notifyDataSetChanged(); } }); } } }); } } }); fragment.show(fm, TAG_FRAGMENT_ROOM_OPTIONS); return true; } } return false; } }); mMyRoomList.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() { @Override public void onGroupExpand(int groupPosition) { if (mAdapter.isPublicsGroupIndex(groupPosition)) { refreshPublicRoomsList(); } } }); mMyRoomList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { return mAdapter.getGroupCount() < 2; } }); mSearchRoomEditText = (EditText) this.findViewById(R.id.editText_search_room); mSearchRoomEditText.addTextChangedListener(new TextWatcher() { public void afterTextChanged(android.text.Editable s) { mAdapter.setSearchedPattern(s.toString()); mMyRoomList.smoothScrollToPosition(0); } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }); }
From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterActivityContent.java
@Override public void onComposingBarCreated() { MessageCenterComposingActionBarView barView = messageCenterListAdapter.getComposingActionBarView(); if (barView != null) { barView.showConfirmation = true; int attachmentCount = imageAttachmentstList.size(); if (attachmentCount == 0) { Editable content = getPendingComposingContent(); final String messageText = (content != null) ? content.toString().trim() : ""; barView.showConfirmation = !(messageText.isEmpty()); }/*from w w w.j a v a 2 s.c o m*/ if (attachmentCount == viewActivity.getResources() .getInteger(R.integer.apptentive_image_grid_default_attachments_total)) { AnimationUtil.fadeOutGone(barView.attachButton); } else { if (barView.attachButton.getVisibility() != View.VISIBLE) { AnimationUtil.fadeIn(barView.attachButton, null); } } if (barView.showConfirmation == true) { barView.sendButton.setEnabled(true); barView.sendButton.setColorFilter( Util.getThemeColorFromAttrOrRes(viewActivity, R.attr.colorAccent, R.color.colorAccent)); } else { barView.sendButton.setEnabled(false); barView.sendButton.setColorFilter(Util.getThemeColorFromAttrOrRes(viewActivity, R.attr.apptentive_material_disabled_icon, R.color.apptentive_material_dark_disabled_icon)); } } }
From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterActivityContent.java
@Override public void onCancelComposing() { messageCenterListAdapter.setForceShowKeyboard(false); Util.hideSoftKeyboard(viewActivity, viewActivity.findViewById(android.R.id.content)); JSONObject data = new JSONObject(); try {//from w w w . j av a2s. co m Editable content = getPendingComposingContent(); int bodyLength = (content != null) ? content.toString().trim().length() : 0; data.put("body_length", bodyLength); } catch (JSONException e) { // } EngagementModule.engageInternal(viewActivity, interaction, MessageCenterInteraction.EVENT_NAME_COMPOSE_CLOSE, data.toString()); clearComposingUi(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { if (contextualMessage != null) { messages.remove(contextualMessage); contextualMessage = null; } messages.remove(actionBarItem); messages.remove(composingItem); actionBarItem = null; composingItem = null; messageEditText = null; messageCenterListAdapter.clearComposing(); addExpectationStatusIfNeeded(); messageCenterListAdapter.notifyDataSetChanged(); imageAttachmentstList.clear(); showFab(); showProfileButton(); // messageEditText has been set to null, pending composing message will reset clearPendingComposingMessage(); } @Override public void onAnimationCancel(Animator animation) { } }, null, DEFAULT_DELAYMILLIS); //clearComposingUi(null, null, 0); }