Example usage for android.widget LinearLayout setVisibility

List of usage examples for android.widget LinearLayout setVisibility

Introduction

In this page you can find the example usage for android.widget LinearLayout setVisibility.

Prototype

@RemotableViewMethod
public void setVisibility(@Visibility int visibility) 

Source Link

Document

Set the visibility state of this view.

Usage

From source file:org.numixproject.hermes.activity.ConversationActivity.java

/**
 * On create//from w ww.j a  v a2 s .c  om
 */
@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());
}

From source file:com.stikyhive.stikyhive.ChattingActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    getWindow().setBackgroundDrawableResource(R.drawable.chat_bg);
    // this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    recipientStkid = getIntent().getExtras().getString("recipientStkid");
    chatRecipient = getIntent().getExtras().getString("chatRecipient");
    chatRecipientUrl = getIntent().getExtras().getString("chatRecipientUrl");
    senderToken = getIntent().getExtras().getString("senderToken");
    recipientToken = getIntent().getExtras().getString("recipientToken");
    noti = getIntent().getExtras().getBoolean("noti");
    message = getIntent().getExtras().getString("message");
    rows = getIntent().getExtras().getInt("rows");
    flagChatting = true;//from  ww  w  .j a  v  a  2  s.com
    pref = PreferenceManager.getDefaultSharedPreferences(this);
    offerId = 0;
    offerStatus = 0;
    ws = new JsonWebService();
    dbHelper = new DBHelper(this);
    dialog = new ProgressDialog(this);
    listChatContact = new ArrayList<>();
    listChatContact = dbHelper.getChatContact();
    Log.i(" Chat Contact ", " " + listChatContact.size());
    metrics = this.getResources().getDisplayMetrics();
    //to change font
    faceSemi_bold = Typeface.createFromAsset(getAssets(), fontOSSemi_bold);
    Typeface faceLight = Typeface.createFromAsset(getAssets(), fontOSLight);
    faceRegular = Typeface.createFromAsset(getAssets(), fontOSRegular);

    imageLoader = ImageLoader.getInstance();
    if (!imageLoader.isInited()) {
        imageLoader.init(ImageLoaderConfiguration.createDefault(this));
    }

    start = new Date();
    SimpleDateFormat oFormat = new SimpleDateFormat("dd MMM HH:mm");
    timeSend = oFormat.format(start);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.chat);

    layoutTalk = (LinearLayout) findViewById(R.id.layoutTalk);
    txtUserName = (TextView) findViewById(R.id.txtChatName);
    edTxtMsg = (EditText) findViewById(R.id.edTxtMsg);
    imgViewProfile = (ImageView) findViewById(R.id.imgViewChat);
    imgViewAddCon = (ImageView) findViewById(R.id.imgAddContact);
    lv = (ListView) findViewById(R.id.listView1);
    layoutLabel = (LinearLayout) findViewById(R.id.layoutLabel);
    txtLabel1 = (TextView) findViewById(R.id.txtLabel1);
    txtLabel2 = (TextView) findViewById(R.id.txtLabel2);
    txtLabel3 = (TextView) findViewById(R.id.txtLabel3);
    txtLabel2.setText(" " + chatRecipient + " ");
    txtLabel1.setTypeface(faceLight);
    txtLabel2.setTypeface(faceRegular);
    txtLabel3.setTypeface(faceLight);

    for (ChatContact contact : listChatContact) {
        if (contact.getContactId().equals(recipientStkid)) {
            imgViewAddCon.setVisibility(View.INVISIBLE);
            layoutLabel.setVisibility(View.GONE);
            break;
        }
    }
    Log.i(TAG, " come back again");
    adapter = new ChatArrayAdapter(this, R.layout.chatting_listview, faceSemi_bold, faceRegular, recipientStkid,
            senderToken, recipientToken);
    lv.setAdapter(adapter);
    // adapter.add(new StikyChat(chatRecipientUrl, "Hello", false, "12.10.2015", "12.1.2014"));

    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
    // BEGIN_INCLUDE (change_colors)
    // Set the color scheme of the SwipeRefreshLayout by providing 4 color resource ids
    swipeRefreshLayout.setColorScheme(R.color.swipe_color_1, R.color.swipe_color_2, R.color.swipe_color_3,
            R.color.swipe_color_4);
    limitMsg = 7;
    // END_INCLUDE (change_colors)
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            Log.i(" Refresh Layout ", "onRefresh called from SwipeRefreshLayout");
            if (limitMsg < rows) {
                Log.i("Limit Message ", " " + limitMsg);
                limitMsg *= 2;
                fetchRecords();
            } else if ((!(rows <= 7)) && limitMsg > rows && (limitMsg - rows < 7)) {
                fetchRecords();
            } else {
                Log.i("No data ", "to refresh");
                swipeRefreshLayout.setRefreshing(false);
                Toast.makeText(getApplicationContext(), "No data to refresh!", Toast.LENGTH_SHORT).show();
            }
            // initiateRefresh();
        }
    });

    LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout headerLayout = (LinearLayout) findViewById(R.id.header);
    View header = inflator.inflate(R.layout.header, null);

    TextView textView = (TextView) header.findViewById(R.id.textView1);
    textView.setText("StikyChat");
    textView.setTypeface(faceSemi_bold);
    textView.setVisibility(View.VISIBLE);
    headerLayout.addView(header);
    LinearLayout layoutRight = (LinearLayout) header.findViewById(R.id.layoutRight);
    layoutRight.setVisibility(View.GONE);

    txtUserName.setText(chatRecipient);
    Log.i(TAG, "Activity Name " + txtUserName.getText().toString());
    txtUserName.setTypeface(faceSemi_bold);

    String url = "";

    Log.i(TAG, " ^^^ " + chatRecipientUrl + " ");
    if (chatRecipientUrl != null) {
        if (chatRecipientUrl.contains("http")) {
            url = chatRecipientUrl;
        } else if (chatRecipientUrl != "null") {
            url = this.getResources().getString(R.string.url) + "/" + chatRecipientUrl;
        }
    }
    addAndroidUniversalImageLoader(imgViewProfile, url);
    //        if (noti && (!message.equals(""))) {
    //            adapter.add(new StikyChat(chatRecipientUrl, message, true, timeSend, ""));
    //            lv.smoothScrollToPosition(adapter.getCount() - 1);
    //        }

    //to show history chats between two users(sender & recipient)
    dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    dateFormat2 = new SimpleDateFormat("dd MMM HH:mm");
    listHistory = dbHelper.getStikyChat();
    if (listHistory.size() > 0) {
        Collections.reverse(listHistory);
        for (final StikyChatTb chatTb : listHistory) {
            String getDate = chatTb.getSendDate();
            String durationStr = null;
            String fromStikyBee = chatTb.getSender();
            try {
                final String createDate = dateFormat2.format(dateFormat.parse(getDate));
                if (chatTb.getFileName().contains("voice")) {
                    MediaPlayer mPlayer = new MediaPlayer();
                    String voiceFileName = getResources().getString(R.string.url) + "/" + chatTb.getFileName();
                    try {
                        mPlayer.setDataSource(voiceFileName);
                        mPlayer.prepare();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                    //mPlayer.start();
                    int duration = mPlayer.getDuration();
                    mPlayer.release();
                    duration = (int) Math.ceil(duration / 1024);

                    if (duration < 10) {
                        durationStr = "00:0" + duration;
                    } else {
                        durationStr = "00:" + duration;
                    }
                    // Log.i(TAG, "Duration Srt " + durationStr);
                }
                if (fromStikyBee.equals(pref.getString("stkid", ""))) {
                    //String url1 = getResources().getString(R.string.url) + "/" + chatTb.getFileName();
                    // Log.i(TAG, " Offer Id " + chatTb.getOfferId() + " Price " + chatTb.getPrice() + " Name " + chatTb.getName());
                    //first false = right, second false = Offer
                    //  Log.i(TAG, " Duration " + chatTb.getRate() + " File Name " + chatTb.getFileName());
                    if (!chatTb.getFileName().contains("voice")) {
                        Log.i(TAG, " Voice is not ");
                        adapter.add(new StikyChat(chatRecipientUrl, chatTb.getMessage(), false, createDate,
                                chatTb.getFileName(), chatTb.getOfferId(), chatTb.getOfferStatus(),
                                chatTb.getPrice(), chatTb.getRate(), chatTb.getName(), null,
                                chatTb.getOriFName()));
                    } else {
                        Log.i(TAG, " Voice is ");
                        adapter.add(new StikyChat(chatRecipientUrl, chatTb.getMessage(), false, createDate,
                                chatTb.getFileName(), chatTb.getOfferId(), chatTb.getOfferStatus(),
                                chatTb.getPrice(), chatTb.getRate(), durationStr, null, chatTb.getOriFName()));
                    }
                } else {
                    /* Bitmap bmImg = BitmapFactory.decodeFile(getResources().getString(R.string.url) + "/" + chatTb.getFileName());
                     Bitmap resBm = getResizedBitmap(bmImg, 500);*/
                    // String url1 = getResources().getString(R.string.url) + "/" + chatTb.getFileName();
                    if (!chatTb.getFileName().contains("voice")) {
                        adapter.add(new StikyChat(chatRecipientUrl, chatTb.getMessage(), true, createDate,
                                chatTb.getFileName(), chatTb.getOfferId(), chatTb.getOfferStatus(),
                                chatTb.getPrice(), chatTb.getRate(), chatTb.getName(), null,
                                chatTb.getOriFName()));
                    } else {
                        adapter.add(new StikyChat(chatRecipientUrl, chatTb.getMessage(), true, createDate,
                                chatTb.getFileName(), chatTb.getOfferId(), chatTb.getOfferStatus(),
                                chatTb.getPrice(), chatTb.getRate(), durationStr, null, chatTb.getOriFName()));
                    }
                }
                lv.smoothScrollToPosition(adapter.getCount() - 1);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
    }

    mRegistrationBroadcastReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
            fileNameGCM = sharedPreferences.getString("fileName", "");
            messageGCM = sharedPreferences.getString("message", "");
            offerIdGCM = sharedPreferences.getInt("offerId", 0);
            offerStatusGCM = sharedPreferences.getInt("offerStatus", 0);
            priceGCM = sharedPreferences.getString("price", "");
            rateGCM = sharedPreferences.getString("rate", "");
            nameGCM = sharedPreferences.getString("name", "");
            recipientProfileGCM = sharedPreferences.getString("chatRecipientUrl", "");
            recipientNameGCM = sharedPreferences.getString("chatRecipientName", "");
            recipientStkidGCM = sharedPreferences.getString("recipientStkid", "");
            recipientTokenGCM = sharedPreferences.getString("recipientToken", "");
            senderTokenGCM = sharedPreferences.getString("senderToken", "");

            Log.i(TAG, " FileName GCM " + fileNameGCM + " " + " Name Rate Price &&&&& *** " + messageGCM + " "
                    + priceGCM + " " + rateGCM);
            if (firstConnect) {
                if (recipientStkidGCM.trim() == recipientStkid.trim()
                        || recipientStkidGCM.equals(recipientStkid)) {
                    MyGcmListenerService.flagSendNoti = false;
                    Log.i(TAG, " " + message);
                    // (1) get today's date
                    start = new Date();
                    SimpleDateFormat oFormat = new SimpleDateFormat("dd MMM HH:mm");
                    timeSend = oFormat.format(start);

                    Log.i(TAG, "First connect " + firstConnect);
                    Log.i(TAG, " File Name GCMMMMMM " + fileNameGCM);
                    /*if (!fileNameGCM.equals("") && !fileNameGCM.equals("null") && !fileNameGCM.equals(null)) {
                    oriFName = saveFileAndImage(fileNameGCM);
                    }*/
                    /*if (fileNameGCM.contains("voice")) {
                    String durationStr;
                    MediaPlayer mPlayer = new MediaPlayer();
                    String voiceFileName = getResources().getString(R.string.url) + "/" + fileNameGCM;
                    try {
                        mPlayer.setDataSource(voiceFileName);
                        mPlayer.prepare();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                            
                    //mPlayer.start();
                    int duration = mPlayer.getDuration();
                    mPlayer.release();
                    duration = (int) Math.ceil(duration / 1024);
                            
                    if (duration < 10) {
                        durationStr = "00:0" + duration;
                    } else {
                        durationStr = "00:" + duration;
                    }
                    StikyChat stikyChat = new StikyChat(recipientProfileGCM, messageGCM, true, timeSend, fileNameGCM.trim(), offerIdGCM, offerStatusGCM, priceGCM, rateGCM, durationStr, null, oriFName);
                    adapter.add(stikyChat);
                    } else {*/
                    StikyChat stikyChat = new StikyChat(recipientProfileGCM, messageGCM, true, timeSend,
                            fileNameGCM.trim(), offerIdGCM, offerStatusGCM, priceGCM, rateGCM, nameGCM, null,
                            oriFName);
                    adapter.add(stikyChat);
                    //  }
                    Log.i(TAG, " First " + message + " " + recipientProfileGCM + " " + timeSend);
                    Log.i(TAG, "User " + txtUserName.getText().toString());

                    adapter.notifyDataSetChanged();
                    lv.setSelection(adapter.getCount() - 1);
                    new regTask2().execute("Obj ");
                } else {
                    /* if (!fileNameGCM.equals("") && !fileNameGCM.equals("null") && !fileNameGCM.equals(null)) {
                    saveFileAndImage(fileNameGCM);
                     }*/
                    Log.i(TAG, "..." + recipientStkidGCM.trim());
                    Log.i(TAG, "&&&" + recipientStkid.trim());
                    Log.i(TAG, "else casee");
                    //notificaton send
                    flagNotifi = true;
                    new regTask2().execute("Notification");
                }
                firstConnect = false;
            }
            lv.setSelection(adapter.getCount() - 1);
        }
    };

    /*edTxtMsg.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        layoutTalk.setLayoutParams(params);
        layoutTalk.setGravity(Gravity.CENTER);
      Toast.makeText(getBaseContext(),
                ((EditText) v).getId() + " has focus - " + hasFocus,
                Toast.LENGTH_LONG).show();
    }
    });*/
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    edTxtMsg.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, 0);
            params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            layoutTalk.setLayoutParams(params);
            layoutTalk.setGravity(Gravity.CENTER);
            flagRecord = false;
            /*getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
            );*/
            Toast.makeText(getBaseContext(), "Touch ...", Toast.LENGTH_LONG).show();
            return false;
        }
    });
}

From source file:org.linphone.InCallActivity.java

private void displayCall(Resources resources, LinphoneCall call, int index) {
    String sipUri = call.getRemoteAddress().asStringUriOnly();
    LinphoneAddress lAddress;//from ww  w  . j av  a 2s  .  c om
    try {
        lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri);
    } catch (LinphoneCoreException e) {
        Log.e("Incall activity cannot parse remote address", e);
        lAddress = LinphoneCoreFactory.instance().createLinphoneAddress("uknown", "unknown", "unkonown");
    }

    // Control Row
    LinearLayout callView = (LinearLayout) inflater.inflate(R.layout.active_call_control_row, container, false);
    callView.setId(index + 1);
    setContactName(callView, lAddress, sipUri, resources);
    displayCallStatusIconAndReturnCallPaused(callView, call);
    setRowBackground(callView, index);
    registerCallDurationTimer(callView, call);
    callsList.addView(callView);

    // Image Row
    LinearLayout imageView = (LinearLayout) inflater.inflate(R.layout.active_call_image_row, container, false);
    Contact contact = ContactsManager.getInstance()
            .findContactWithAddress(imageView.getContext().getContentResolver(), lAddress);
    if (contact != null) {
        displayOrHideContactPicture(imageView, contact.getPhotoUri(), contact.getThumbnailUri(), false);
    } else {
        displayOrHideContactPicture(imageView, null, null, false);
    }
    callsList.addView(imageView);

    callView.setTag(imageView);
    callView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (v.getTag() != null) {
                View imageView = (View) v.getTag();
                if (imageView.getVisibility() == View.VISIBLE)
                    imageView.setVisibility(View.GONE);
                else
                    imageView.setVisibility(View.VISIBLE);
                callsList.invalidate();
            }
        }
    });
}

From source file:org.epstudios.epcoding.ProcedureDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.procedure_codes, container, false);
    context = getActivity();/*from   w  w w . j  a  va  2s  .  c om*/

    LinearLayout primaryCheckBoxLayout = (LinearLayout) rootView.findViewById(R.id.primary_checkbox_layout);
    LinearLayout secondaryCheckBoxLayout = (LinearLayout) rootView.findViewById(R.id.secondary_checkbox_layout);
    TextView primaryCodeTextView = (TextView) rootView.findViewById(R.id.primary_code_textView);
    TextView secondaryCodeTextView = (TextView) rootView.findViewById(R.id.secondary_code_textView);

    loadSettings();

    switch (mItem) {
    case allProcedures:
        procedure = new AllCodes();
        break;
    case afbAblation:
        procedure = new AfbAblation();
        break;
    case svtAblation:
        procedure = new SvtAblation();
        break;
    case vtAblation:
        procedure = new VtAblation();
        break;
    case avnAblation:
        procedure = new AvnAblation();
        break;
    case epTesting:
        procedure = new EpTesting();
        break;
    case newPpm:
        procedure = new NewPpm();
        break;
    case newIcd:
        procedure = new NewIcd();
        break;
    case ppmReplacement:
        procedure = new PpmReplacement();
        break;
    case icdReplacement:
        procedure = new IcdReplacement();
        break;
    case deviceUpgrade:
        procedure = new DeviceUpgrade();
        break;
    case subQIcd:
        procedure = new SubQIcd();
        break;
    case otherProcedure:
        procedure = new OtherProcedure();
        break;
    default:
        procedure = new AllCodes();
        break;
    }

    getActivity().setTitle(procedure.title(context));

    Code[] secondaryCodes = procedure.secondaryCodes();

    if (secondaryCodes.length > 0) {
        createCheckBoxLayoutAndCodeMap(secondaryCodes, secondaryCheckBoxMap, secondaryCheckBoxLayout);
    } else {
        secondaryCheckBoxLayout.setVisibility(View.GONE);
        secondaryCodeTextView.setVisibility(View.GONE);
    }

    if (mItem == allProcedures) {
        primaryCodeTextView.setText(getString(R.string.all_codes_primary_title));
    }

    Code[] primaryCodes = procedure.primaryCodes();
    String[] disabledCodeNumbers = procedure.disabledCodeNumbers();

    for (int i = 0; i < disabledCodeNumbers.length; ++i)
        secondaryCheckBoxMap.get(disabledCodeNumbers[i]).disable();

    createCheckBoxLayoutAndCodeMap(primaryCodes, primaryCheckBoxMap, primaryCheckBoxLayout);

    if (procedure.disablePrimaryCodes()) {
        // check and disable primary checkboxes for ablation type items
        for (Map.Entry<String, CodeCheckBox> entry : primaryCheckBoxMap.entrySet()) {
            entry.getValue().setEnabled(false);
            entry.getValue().setChecked(true);
        }
    }

    // apply saved configurations here
    if (null != savedInstanceState) {
        // restore state
        boolean[] primaryCodesState = savedInstanceState.getBooleanArray("primary_codes");
        boolean[] secondaryCodesState = savedInstanceState.getBooleanArray("secondary_codes");
        int i = 0;
        for (Map.Entry<String, CodeCheckBox> entry : primaryCheckBoxMap.entrySet())
            entry.getValue().setChecked(primaryCodesState[i++]);
        i = 0;
        for (Map.Entry<String, CodeCheckBox> entry : secondaryCheckBoxMap.entrySet())
            entry.getValue().setChecked(secondaryCodesState[i++]);
    } else
        loadCoding();
    // set up buttons
    Button summarizeButton = (Button) rootView.findViewById(R.id.summary_button);
    summarizeButton.setOnClickListener(this);
    Button clearButton = (Button) rootView.findViewById(R.id.clear_button);
    clearButton.setOnClickListener(this);
    return rootView;
}

From source file:com.master.metehan.filtereagle.AdapterAccess.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    final long id = cursor.getLong(colID);
    final int version = cursor.getInt(colVersion);
    final int protocol = cursor.getInt(colProtocol);
    final String daddr = cursor.getString(colDaddr);
    final int dport = cursor.getInt(colDPort);
    long time = cursor.getLong(colTime);
    int allowed = cursor.getInt(colAllowed);
    int block = cursor.getInt(colBlock);
    long sent = cursor.isNull(colSent) ? -1 : cursor.getLong(colSent);
    long received = cursor.isNull(colReceived) ? -1 : cursor.getLong(colReceived);
    int connections = cursor.isNull(colConnections) ? -1 : cursor.getInt(colConnections);

    // Get views/* w  w  w  .ja v  a  2  s.c o  m*/
    TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
    ImageView ivBlock = (ImageView) view.findViewById(R.id.ivBlock);
    final TextView tvDest = (TextView) view.findViewById(R.id.tvDest);
    LinearLayout llTraffic = (LinearLayout) view.findViewById(R.id.llTraffic);
    TextView tvConnections = (TextView) view.findViewById(R.id.tvConnections);
    TextView tvTraffic = (TextView) view.findViewById(R.id.tvTraffic);

    // Set values
    tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time));
    if (block < 0)
        ivBlock.setImageDrawable(null);
    else {
        ivBlock.setImageResource(block > 0 ? R.drawable.host_blocked : R.drawable.host_allowed);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivBlock.getDrawable());
            DrawableCompat.setTint(wrap, block > 0 ? colorOff : colorOn);
        }
    }

    tvDest.setText(
            Util.getProtocolName(protocol, version, true) + " " + daddr + (dport > 0 ? "/" + dport : ""));

    if (Util.isNumericAddress(daddr) && tvDest.getTag() == null)
        new AsyncTask<String, Object, String>() {
            @Override
            protected void onPreExecute() {
                tvDest.setTag(id);
            }

            @Override
            protected String doInBackground(String... args) {
                try {
                    return InetAddress.getByName(args[0]).getHostName();
                } catch (UnknownHostException ignored) {
                    return args[0];
                }
            }

            @Override
            protected void onPostExecute(String addr) {
                Object tag = tvDest.getTag();
                if (tag != null && (Long) tag == id)
                    tvDest.setText(Util.getProtocolName(protocol, version, true) + " >" + addr
                            + (dport > 0 ? "/" + dport : ""));
                tvDest.setTag(null);
            }
        }.execute(daddr);

    if (allowed < 0)
        tvDest.setTextColor(colorText);
    else if (allowed > 0)
        tvDest.setTextColor(colorOn);
    else
        tvDest.setTextColor(colorOff);

    llTraffic.setVisibility(connections > 0 || sent > 0 || received > 0 ? View.VISIBLE : View.GONE);
    if (connections > 0)
        tvConnections.setText(context.getString(R.string.msg_count, connections));

    if (sent > 1024 * 1204 * 1024L || received > 1024 * 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_gb, (sent > 0 ? sent / (1024 * 1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024 * 1024f) : 0)));
    else if (sent > 1204 * 1024L || received > 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_mb, (sent > 0 ? sent / (1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024f) : 0)));
    else
        tvTraffic.setText(context.getString(R.string.msg_kb, (sent > 0 ? sent / 1024f : 0),
                (received > 0 ? received / 1024f : 0)));
}

From source file:com.tweetlanes.android.view.ProfileFragment.java

void configureView() {

    TextView fullNameTextView = (TextView) mProfileView.findViewById(R.id.fullNameTextView);
    TextView followingTextView = (TextView) mProfileView.findViewById(R.id.followState);
    TextView descriptionTextView = (TextView) mProfileView.findViewById(R.id.bioTextView);
    TextView tweetCount = (TextView) mProfileView.findViewById(R.id.tweetCountLabel);
    TextView followingCount = (TextView) mProfileView.findViewById(R.id.followingCountLabel);
    TextView followersCount = (TextView) mProfileView.findViewById(R.id.followersCountLabel);
    TextView favoritesCount = (TextView) mProfileView.findViewById(R.id.favorites_count);
    LinearLayout linkLayout = (LinearLayout) mProfileView.findViewById(R.id.linkLayout);
    TextView link = (TextView) mProfileView.findViewById(R.id.link);
    LinearLayout locationLayout = (LinearLayout) mProfileView.findViewById(R.id.locationLayout);
    TextView location = (TextView) mProfileView.findViewById(R.id.location);
    LinearLayout detailsLayout = (LinearLayout) mProfileView.findViewById(R.id.detailsLayout);
    ImageView privateAccountImage = (ImageView) mProfileView.findViewById(R.id.private_account_image);
    mFriendshipButton = (Button) mProfileView.findViewById(R.id.friendship_button);
    mFriendshipDivider = (View) mProfileView.findViewById(R.id.friendship_divider);

    if (mUser != null) {
        ImageView avatar = (ImageView) mProfileView.findViewById(R.id.profileImage);
        //String imageUrl = TwitterManager.getProfileImageUrl(mUser.getScreenName(), TwitterManager.ProfileImageSize.ORIGINAL);
        String imageUrl = mUser.getProfileImageUrl(TwitterManager.ProfileImageSize.ORIGINAL);
        UrlImageViewHelper.setUrlDrawable(avatar, imageUrl, R.drawable.ic_contact_picture);
        //avatar.setImageURL(imageUrl);

        ImageView coverImage = (ImageView) mProfileView.findViewById(R.id.coverImage);
        if (coverImage != null) {
            String url = mUser.getCoverImageUrl();
            if (url != null) {
                UrlImageViewHelper.setUrlDrawable(coverImage, url, R.drawable.ic_contact_picture);
            }/*from   w  w w.  j  a va 2 s .c  om*/
        }

        fullNameTextView.setText(mUser.getName());
        if (mFollowsLoggedInUser != null && mFollowsLoggedInUser.booleanValue() == true) {
            followingTextView.setText(R.string.follows_you);
        } else {
            followingTextView.setText(null);
        }

        String description = mUser.getDescription();
        if (description != null) {
            String descriptionMarkup = TwitterUtil.getTextMarkup(description);
            descriptionTextView.setText(Html.fromHtml(descriptionMarkup + " "));
            descriptionTextView.setMovementMethod(LinkMovementMethod.getInstance());
            URLSpanNoUnderline.stripUnderlines(descriptionTextView);
        }

        detailsLayout.setVisibility(View.VISIBLE);
        privateAccountImage.setVisibility(mUser.getProtected() ? View.VISIBLE : View.GONE);

        tweetCount.setText(Util.getPrettyCount(mUser.getStatusesCount()));
        followingCount.setText(Util.getPrettyCount(mUser.getFriendsCount()));
        followersCount.setText(Util.getPrettyCount(mUser.getFollowersCount()));
        if (favoritesCount != null) {
            favoritesCount.setText(Util.getPrettyCount(mUser.getFavoritesCount()));
        }

        if (mUser.getUrl() != null) {
            linkLayout.setVisibility(View.VISIBLE);
            //link.setText(mUser.getUrl());
            //URLSpanNoUnderline.stripUnderlines(link);
            link.setText(Html.fromHtml("<a href=\"" + mUser.getUrl() + "\">" + mUser.getUrl() + "</a>"));
            link.setMovementMethod(LinkMovementMethod.getInstance());
            URLSpanNoUnderline.stripUnderlines(link);
        } else {
            linkLayout.setVisibility(View.GONE);
        }

        if (mUser.getLocation() != null) {
            locationLayout.setVisibility(View.VISIBLE);
            location.setText(mUser.getLocation());
        } else {
            locationLayout.setVisibility(View.GONE);
        }

        configureFriendshipButtonVisibility(mLoggedInUserFollows);

        getBaseLaneActivity().setComposeTweetDefault();
    } else {
        fullNameTextView.setText(null);
        followingTextView.setText(null);
        descriptionTextView.setText(null);

        detailsLayout.setVisibility(View.GONE);
        linkLayout.setVisibility(View.GONE);
        locationLayout.setVisibility(View.GONE);
        mFriendshipButton.setVisibility(View.GONE);
        mFriendshipDivider.setVisibility(View.GONE);
        privateAccountImage.setVisibility(View.GONE);
    }
}

From source file:org.xingjitong.LinphoneActivity.java

private void changeFragmentForTablets(Fragment newFragment, FragmentsAvailable newFragmentType,
        boolean withoutAnimation) {
    if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) {
        if (newFragmentType == FragmentsAvailable.DIALER) {
            showStatusBar();/*from  ww w. j  a v  a2s  .co  m*/
        } else {
            hideStatusBar();
        }
    }

    LinearLayout ll = (LinearLayout) findViewById(R.id.fragmentContainer); //yyppsize R.id.fragmentContainer2);

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    if (newFragmentType.shouldAddItselfToTheRightOf(currentFragment)) {
        ll.setVisibility(View.VISIBLE);

        transaction.addToBackStack(newFragmentType.toString());
        transaction.replace(R.id.fragmentContainer, newFragment); //yyppsize R.id.fragmentContainer2);
    } else {
        if (newFragmentType == FragmentsAvailable.DIALER
                // || newFragmentType == FragmentsAvailable.ABOUT
                // || newFragmentType ==
                // FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT
                // || newFragmentType ==
                // FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS
                || newFragmentType == FragmentsAvailable.SETTINGS
                || newFragmentType == FragmentsAvailable.ACCOUNT_SETTINGS) {
            ll.setVisibility(View.GONE);
        } else {
            ll.setVisibility(View.INVISIBLE);
        }

        if (!withoutAnimation && !isAnimationDisabled && currentFragment.shouldAnimate()) {
            if (newFragmentType.isRightOf(currentFragment)) {
                transaction.setCustomAnimations(R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left,
                        R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right);
            } else {
                transaction.setCustomAnimations(R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right,
                        R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left);
            }
        }

        try {
            getSupportFragmentManager().popBackStackImmediate(newFragmentType.toString(),
                    FragmentManager.POP_BACK_STACK_INCLUSIVE);
        } catch (java.lang.IllegalStateException e) {

        }

        transaction.addToBackStack(newFragmentType.toString());
        transaction.replace(R.id.fragmentContainer, newFragment);
    }
    transaction.commitAllowingStateLoss();
    getSupportFragmentManager().executePendingTransactions();

    currentFragment = newFragmentType;
}

From source file:com.todotxt.todotxttouch.TodoTxtTouch.java

void setFilteredTasks(boolean reload) {
    if (reload) {
        try {// ww w  .j a  va2 s.  co  m
            taskBag.reload();
        } catch (Exception e) {
            Log.e(TAG, e.getMessage(), e);
        }
    }

    if (mScrollPosition < 0) {
        calculateScrollPosition();
    }

    m_adapter.clear();
    for (Task task : taskBag.getTasks(FilterFactory.generateAndFilter(m_app.m_prios, m_app.m_contexts,
            m_app.m_projects, m_app.m_search, false), m_app.sort.getComparator())) {
        m_adapter.add(task);
    }

    ListView lv = getListView();
    lv.setSelectionFromTop(mScrollPosition, mScrollTop);

    final TextView filterText = (TextView) findViewById(R.id.filter_text);
    final LinearLayout actionbar = (LinearLayout) findViewById(R.id.actionbar);
    final ImageView actionbar_icon = (ImageView) findViewById(R.id.actionbar_icon);

    if (filterText != null) {
        if (m_app.m_filters.size() > 0) {
            String filterTitle = getString(R.string.title_filter_applied) + " ";
            int count = m_app.m_filters.size();

            for (int i = 0; i < count; i++) {
                filterTitle += m_app.m_filters.get(i) + " ";
            }

            if (!Strings.isEmptyOrNull(m_app.m_search)) {
                filterTitle += getString(R.string.filter_tab_search);
            }

            actionbar_icon.setImageResource(R.drawable.ic_actionbar_filter);

            actionbar.setVisibility(View.VISIBLE);
            filterText.setText(filterTitle);
        } else if (!Strings.isEmptyOrNull(m_app.m_search)) {
            if (filterText != null) {
                actionbar_icon.setImageResource(R.drawable.ic_actionbar_search);
                filterText.setText(getString(R.string.title_search_results) + " " + m_app.m_search);

                actionbar.setVisibility(View.VISIBLE);
            }
        } else {
            filterText.setText("");
            actionbar.setVisibility(View.GONE);
        }
    }

    m_swipeList.setEnabled(!inActionMode());
}

From source file:eu.faircode.netguard.AdapterAccess.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    final int version = cursor.getInt(colVersion);
    final int protocol = cursor.getInt(colProtocol);
    final String daddr = cursor.getString(colDaddr);
    final int dport = cursor.getInt(colDPort);
    long time = cursor.getLong(colTime);
    int allowed = cursor.getInt(colAllowed);
    int block = cursor.getInt(colBlock);
    int count = cursor.getInt(colCount);
    long sent = cursor.isNull(colSent) ? -1 : cursor.getLong(colSent);
    long received = cursor.isNull(colReceived) ? -1 : cursor.getLong(colReceived);
    int connections = cursor.isNull(colConnections) ? -1 : cursor.getInt(colConnections);

    // Get views/*  w  w w.j a  va 2  s.c om*/
    TextView tvTime = view.findViewById(R.id.tvTime);
    ImageView ivBlock = view.findViewById(R.id.ivBlock);
    final TextView tvDest = view.findViewById(R.id.tvDest);
    LinearLayout llTraffic = view.findViewById(R.id.llTraffic);
    TextView tvConnections = view.findViewById(R.id.tvConnections);
    TextView tvTraffic = view.findViewById(R.id.tvTraffic);

    // Set values
    tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time));
    if (block < 0)
        ivBlock.setImageDrawable(null);
    else {
        ivBlock.setImageResource(block > 0 ? R.drawable.host_blocked : R.drawable.host_allowed);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivBlock.getDrawable());
            DrawableCompat.setTint(wrap, block > 0 ? colorOff : colorOn);
        }
    }

    String dest = Util.getProtocolName(protocol, version, true) + " " + daddr + (dport > 0 ? "/" + dport : "")
            + (count > 1 ? " ?" + count : "");
    SpannableString span = new SpannableString(dest);
    span.setSpan(new UnderlineSpan(), 0, dest.length(), 0);
    tvDest.setText(span);

    if (Util.isNumericAddress(daddr))
        new AsyncTask<String, Object, String>() {
            @Override
            protected void onPreExecute() {
                ViewCompat.setHasTransientState(tvDest, true);
            }

            @Override
            protected String doInBackground(String... args) {
                try {
                    return InetAddress.getByName(args[0]).getHostName();
                } catch (UnknownHostException ignored) {
                    return args[0];
                }
            }

            @Override
            protected void onPostExecute(String addr) {
                tvDest.setText(Util.getProtocolName(protocol, version, true) + " >" + addr
                        + (dport > 0 ? "/" + dport : ""));
                ViewCompat.setHasTransientState(tvDest, false);
            }
        }.execute(daddr);

    if (allowed < 0)
        tvDest.setTextColor(colorText);
    else if (allowed > 0)
        tvDest.setTextColor(colorOn);
    else
        tvDest.setTextColor(colorOff);

    llTraffic.setVisibility(connections > 0 || sent > 0 || received > 0 ? View.VISIBLE : View.GONE);
    if (connections > 0)
        tvConnections.setText(context.getString(R.string.msg_count, connections));

    if (sent > 1024 * 1204 * 1024L || received > 1024 * 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_gb, (sent > 0 ? sent / (1024 * 1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024 * 1024f) : 0)));
    else if (sent > 1204 * 1024L || received > 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_mb, (sent > 0 ? sent / (1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024f) : 0)));
    else
        tvTraffic.setText(context.getString(R.string.msg_kb, (sent > 0 ? sent / 1024f : 0),
                (received > 0 ? received / 1024f : 0)));
}

From source file:com.shafiq.mytwittle.view.ProfileFragment.java

void configureView() {

    TextView fullNameTextView = (TextView) mProfileView.findViewById(R.id.fullNameTextView);
    TextView followingTextView = (TextView) mProfileView.findViewById(R.id.followState);
    TextView descriptionTextView = (TextView) mProfileView.findViewById(R.id.bioTextView);
    TextView tweetCount = (TextView) mProfileView.findViewById(R.id.tweetCountLabel);
    TextView followingCount = (TextView) mProfileView.findViewById(R.id.followingCountLabel);
    TextView followersCount = (TextView) mProfileView.findViewById(R.id.followersCountLabel);
    TextView favoritesCount = (TextView) mProfileView.findViewById(R.id.favorites_count);
    LinearLayout linkLayout = (LinearLayout) mProfileView.findViewById(R.id.linkLayout);
    TextView link = (TextView) mProfileView.findViewById(R.id.link);
    LinearLayout locationLayout = (LinearLayout) mProfileView.findViewById(R.id.locationLayout);
    TextView location = (TextView) mProfileView.findViewById(R.id.location);
    LinearLayout detailsLayout = (LinearLayout) mProfileView.findViewById(R.id.detailsLayout);
    ImageView privateAccountImage = (ImageView) mProfileView.findViewById(R.id.private_account_image);
    mFriendshipButton = (Button) mProfileView.findViewById(R.id.friendship_button);
    mFriendshipDivider = (View) mProfileView.findViewById(R.id.friendship_divider);

    if (mUser != null) {
        ImageView avatar = (ImageView) mProfileView.findViewById(R.id.profileImage);
        // String imageUrl =
        // TwitterManager.getProfileImageUrl(mUser.getScreenName(),
        // TwitterManager.ProfileImageSize.ORIGINAL);
        String imageUrl = mUser.getProfileImageUrl(TwitterManager.ProfileImageSize.ORIGINAL);
        UrlImageViewHelper.setUrlDrawable(avatar, imageUrl, R.drawable.ic_contact_picture);
        // avatar.setImageURL(imageUrl);

        ImageView coverImage = (ImageView) mProfileView.findViewById(R.id.coverImage);
        if (coverImage != null) {
            String url = mUser.getCoverImageUrl();
            if (url != null) {
                UrlImageViewHelper.setUrlDrawable(coverImage, url, R.drawable.ic_contact_picture);
            }/* www. j av a 2  s  .c  om*/
        }

        fullNameTextView.setText(mUser.getName());
        if (mFollowsLoggedInUser != null && mFollowsLoggedInUser.booleanValue() == true) {
            followingTextView.setText(R.string.follows_you);
        } else {
            followingTextView.setText(null);
        }

        String description = mUser.getDescription();
        if (description != null) {
            String descriptionMarkup = TwitterUtil.getTextMarkup(description);
            descriptionTextView.setText(Html.fromHtml(descriptionMarkup + " "));
            descriptionTextView.setMovementMethod(LinkMovementMethod.getInstance());
            URLSpanNoUnderline.stripUnderlines(descriptionTextView);
        }

        detailsLayout.setVisibility(View.VISIBLE);
        privateAccountImage.setVisibility(mUser.getProtected() ? View.VISIBLE : View.GONE);

        tweetCount.setText(Util.getPrettyCount(mUser.getStatusesCount()));
        followingCount.setText(Util.getPrettyCount(mUser.getFriendsCount()));
        followersCount.setText(Util.getPrettyCount(mUser.getFollowersCount()));
        if (favoritesCount != null) {
            favoritesCount.setText(Util.getPrettyCount(mUser.getFavoritesCount()));
        }

        if (mUser.getUrl() != null) {
            linkLayout.setVisibility(View.VISIBLE);
            // link.setText(mUser.getUrl());
            // URLSpanNoUnderline.stripUnderlines(link);
            link.setText(Html.fromHtml("<a href=\"" + mUser.getUrl() + "\">" + mUser.getUrl() + "</a>"));
            link.setMovementMethod(LinkMovementMethod.getInstance());
            URLSpanNoUnderline.stripUnderlines(link);
        } else {
            linkLayout.setVisibility(View.GONE);
        }

        if (mUser.getLocation() != null) {
            locationLayout.setVisibility(View.VISIBLE);
            location.setText(mUser.getLocation());
        } else {
            locationLayout.setVisibility(View.GONE);
        }

        configureFriendshipButtonVisibility(mLoggedInUserFollows);

        getBaseLaneActivity().setComposeTweetDefault();
    } else {
        fullNameTextView.setText(null);
        followingTextView.setText(null);
        descriptionTextView.setText(null);

        detailsLayout.setVisibility(View.GONE);
        linkLayout.setVisibility(View.GONE);
        locationLayout.setVisibility(View.GONE);
        mFriendshipButton.setVisibility(View.GONE);
        mFriendshipDivider.setVisibility(View.GONE);
        privateAccountImage.setVisibility(View.GONE);
    }
}