List of usage examples for android.widget TextView getLocalVisibleRect
public final boolean getLocalVisibleRect(Rect r)
From source file:org.numixproject.hermes.activity.ConversationActivity.java
/** * On create//from w ww.j a v a 2s.co m */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Initialize Facebook SDK FacebookSdk.sdkInitialize(getApplicationContext()); tinydb = new TinyDB(getApplicationContext()); serverId = getIntent().getExtras().getInt("serverId"); server = Hermes.getInstance().getServerById(serverId); loadPinnedItems(); loadRecentItems(); server.setAutoJoinChannels(pinnedRooms); // Remove duplicates from Recent items HashSet hs = new HashSet(); hs.addAll(recentList); recentList.clear(); recentList.addAll(hs); saveRecentItems(); Settings settings = new Settings(this); // Finish activity if server does not exist anymore - See #55 if (server == null) { this.finish(); } String key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5B4Oomgmm2D8XVSxh1DIFGtU3p1N2w6Xi2ZO7MoeZRAhvVjk3B8MfrOatlO9HfozRGhEkCkq0MfstB4Cjci3dsnYZieNmHOVYIFBWERqdwfdtnUIfI554xFsAC3Ah7PTP3MwKE7qTT1VLTTHxxsE7GH4sLtvLwrAzsVrLK+dgQk+e9bDJMvhhEPBgabRFaTvKaTtSzB/BBwrCa5mv0pte6WfrNbugFjiAJC43b7NNY2PV9UA8mukiBNZ9mPrK5fZeSEfcVqenyqbvZZG+P+O/cohAHbIEzPMuAS1EBf0VBsZtm3fjQ45PgCvEB7Ye3ucfR9BQ9ADjDwdqivExvXndQIDAQAB"; inAppPayments = new iap(); bp = inAppPayments.getBilling(this, key); bp.loadOwnedPurchasesFromGoogle(); // Load AdMob Ads if (!inAppPayments.isPurchased()) { mInterstitialAd = new InterstitialAd(this); mInterstitialAd.setAdUnitId("ca-app-pub-2834532364021285/7438037454"); requestNewInterstitial(); mInterstitialAd.setAdListener(new AdListener() { @Override public void onAdClosed() { requestNewInterstitial(); } }); } try { setTitle(server.getTitle()); } catch (Exception e) { } isFirstTimeStarred = tinydb.getBoolean("isFirstTimeStarred", true); isFirstTimeRefresh = tinydb.getBoolean("isFirstTimeRefresh", true); setContentView(R.layout.conversations); boolean isLandscape = (getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE); final ImageView sendButton = (ImageView) findViewById(R.id.send_button); sendButton.setVisibility(View.GONE); input = (AutoCompleteTextView) findViewById(R.id.input); input.setOnKeyListener(inputKeyListener); input.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { // Do nothing } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // Do nothing } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (input.getText().toString().equals("")) { sendButton.setVisibility(View.GONE); } else { sendButton.setVisibility(View.VISIBLE); } } }); pager = (ViewPager) findViewById(R.id.pager); pagerAdapter = new ConversationPagerAdapter(this, server); pager.setAdapter(pagerAdapter); final float density = getResources().getDisplayMetrics().density; indicator = (ConversationIndicator) findViewById(R.id.titleIndicator); indicator.setServer(server); indicator.setViewPager(pager); indicator.setFooterColor(Color.parseColor("#d1d1d1")); indicator.setFooterLineHeight(1); indicator.setPadding(10, 10, 10, 10); indicator.setFooterIndicatorStyle(IndicatorStyle.Underline); indicator.setFooterIndicatorHeight(2 * density); indicator.setSelectedColor(0xFF222222); indicator.setSelectedBold(false); indicator.setBackgroundColor(Color.parseColor("#fff5f5f5")); historySize = settings.getHistorySize(); if (server.getStatus() == Status.PRE_CONNECTING) { server.clearConversations(); pagerAdapter.clearConversations(); server.getConversation(ServerInfo.DEFAULT_NAME).setHistorySize(historySize); } indicator.setTextSize(TypedValue.COMPLEX_UNIT_SP, 35); input.setTypeface(Typeface.SANS_SERIF); // Optimization : cache field lookups Collection<Conversation> mConversations = server.getConversations(); for (Conversation conversation : mConversations) { // Only scroll to new conversation if it was selected before if (conversation.getStatus() == Conversation.STATUS_SELECTED) { onNewConversation(conversation.getName()); } else { createNewConversation(conversation.getName()); } } input.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { openSoftKeyboard(v); updateAutoComplete(); } }); conversationLayout = (FrameLayout) findViewById(R.id.conversationFragment); conversationLayout.setVisibility(LinearLayout.INVISIBLE); roomsLayout = (FrameLayout) findViewById(R.id.roomsLayout); // Create a new scrollback history scrollback = new Scrollback(); getSupportActionBar().setDisplayHomeAsUpEnabled(true); swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh); swipeRefresh.setColorSchemeResources(R.color.refresh_progress_1, R.color.refresh_progress_2, R.color.refresh_progress_3); swipeRefresh.getViewTreeObserver() .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { @Override public void onScrollChanged() { Rect scrollBounds = new Rect(); swipeRefresh.getHitRect(scrollBounds); TextView firstItem = (TextView) findViewById(R.id.firstItem); if (firstItem.getLocalVisibleRect(scrollBounds)) { if (conversationLayout.getVisibility() != View.VISIBLE) { swipeRefresh.setEnabled(true); } else { swipeRefresh.setEnabled(false); } } else { swipeRefresh.setEnabled(false); } } }); swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { if (swipeRefresh.getScrollY() == 0) { refreshActivity(); } } }); // Adapter section roomsList = (ExpandableHeightListView) findViewById(R.id.roomsActivityList); roomsList.setExpanded(true); SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(roomsList, new SwipeDismissListViewTouchListener.DismissCallbacks() { @Override public boolean canDismiss(int position) { return true; } @Override public void onDismiss(ListView listView, int[] reverseSortedPositions) { for (int position : reverseSortedPositions) { roomAdapter.remove(position); } roomAdapter.notifyDataSetChanged(); if (Math.random() * 100 < 30) { showAd(); } } }); roomsList.setOnTouchListener(touchListener); // Setting this scroll listener is required to ensure that during ListView scrolling, // we don't look for swipes. roomsList.setOnScrollListener(touchListener.makeScrollListener()); ArrayList<String> channels = new ArrayList<String>(); ArrayList<String> query = new ArrayList<String>(); channels = server.getCurrentChannelNames(); query = server.getCurrentQueryNames(); for (int i = 0; i < channels.size(); i++) { try { Conversation conversation = server.getConversation(channels.get(i)); int Mentions = conversation.getNewMentions(); RoomsList.add(channels.get(i)); MentionsList.add(Mentions); } catch (Exception E) { // Do nothing } } // FAB section fab = (FloatingActionButton) findViewById(R.id.room_fab); fab.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { joinRoom(v); } return true; } }); roomAdapter = new mentionsAdapter(RoomsList, MentionsList); roomsList.setAdapter(roomAdapter); roomsList.setEmptyView(findViewById(R.id.roomsActivityList_empty)); roomsList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Set conversation VISIBLE invalidateOptionsMenu(); swipeRefresh.setEnabled(false); int pagerPosition; String name; // Find channel name from TextView TextView roomName = (TextView) view.findViewById(R.id.room_name); name = roomName.getText().toString(); // Find room's position in pager pagerPosition = pagerAdapter.getPositionByName(name); // Set position in pager pager.setCurrentItem(pagerPosition, true); showConversationLayout(); } }); // Click on Others CardView otherCard = (CardView) findViewById(R.id.card_view_other); otherCard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { invalidateOptionsMenu(); swipeRefresh.setEnabled(false); pager.setCurrentItem(0); showConversationLayout(); } }); int counter; for (counter = 0; counter < recentList.size(); counter++) { if (RoomsList.contains(recentList.get(counter))) { recentList.remove(counter); saveRecentItems(); } } LinearLayout recentLabel = (LinearLayout) findViewById(R.id.recentName); if (recentList.size() != 0) { recentLabel.setVisibility(View.VISIBLE); } else { recentLabel.setVisibility(View.GONE); } recentView = (ExpandableHeightListView) findViewById(R.id.recentList); loadLastItems(); int k; for (k = 0; k < lastRooms.size(); k++) { String lastRoom = lastRooms.get(k); if (RoomsList.contains(lastRoom)) { } else { recentList.add(lastRoom); } } lastRooms.clear(); saveLastItems(); saveRecentItems(); recentAdapter = new recentAdapter(recentList); recentView.setAdapter(recentAdapter); recentView.setExpanded(true); recentView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View v, int position, long arg3) { final String room = (String) recentAdapter.getRoomAtPosition(position); if (RoomsList.size() > 0) { invalidateOptionsMenu(); new Thread() { @Override public void run() { try { binder.getService().getConnection(serverId).joinChannel(room); } catch (Exception E) { // Do nothing } } }.start(); recentList.remove(position); saveRecentItems(); refreshActivity(); } else { new Thread() { @Override public void run() { try { binder.getService().getConnection(serverId).joinChannel(room); } catch (Exception E) { // Do nothing } } }.start(); saveRecentItems(); refreshActivity(); } } }); SwipeDismissListViewTouchListener touchListenerRecent = new SwipeDismissListViewTouchListener(recentView, new SwipeDismissListViewTouchListener.DismissCallbacks() { @Override public boolean canDismiss(int position) { return true; } @Override public void onDismiss(ListView listView, int[] reverseSortedPositions) { for (int position : reverseSortedPositions) { recentAdapter.remove(position); saveRecentItems(); } recentAdapter.notifyDataSetChanged(); if (Math.random() * 100 < 10) { showAd(); } } }); recentView.setOnTouchListener(touchListenerRecent); // Setting this scroll listener is required to ensure that during ListView scrolling, // we don't look for swipes. recentView.setOnScrollListener(touchListenerRecent.makeScrollListener()); }