Example usage for android.widget TextView setTextColor

List of usage examples for android.widget TextView setTextColor

Introduction

In this page you can find the example usage for android.widget TextView setTextColor.

Prototype

@android.view.RemotableViewMethod
public void setTextColor(ColorStateList colors) 

Source Link

Document

Sets the text color.

Usage

From source file:com.com.easemob.chatuidemo.adapter.MessageAdapter.java

private void setRobotMenuMessageLayout(LinearLayout parentView, JSONArray jsonArr) {
    try {/*from   ww w  . j a v  a 2 s  .  co m*/
        parentView.removeAllViews();
        for (int i = 0; i < jsonArr.length(); i++) {
            final String itemStr = jsonArr.getString(i);
            final TextView textView = new TextView(context);
            textView.setText(itemStr);
            textView.setTextSize(15);
            try {
                XmlPullParser xrp = context.getResources().getXml(R.drawable.menu_msg_text_color);
                textView.setTextColor(ColorStateList.createFromXml(context.getResources(), xrp));
            } catch (Exception e) {
                e.printStackTrace();
            }
            textView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    ((ChatMessage) context).sendText(itemStr);
                }
            });
            LinearLayout.LayoutParams llLp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            llLp.bottomMargin = DensityUtil.dip2px(context, 3);
            llLp.topMargin = DensityUtil.dip2px(context, 3);
            parentView.addView(textView, llLp);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

}

From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java

@Override
protected void onServiceBound() {
    T.UI();/*  w  ww .  j  a v a 2s . co  m*/
    if (mNotYetProcessedIntent != null) {
        processIntent(mNotYetProcessedIntent);
        mNotYetProcessedIntent = null;
    }

    setContentView(R.layout.registration2);

    //Apply Fonts
    TextUtils.overrideFonts(this, findViewById(android.R.id.content));

    final Typeface faTypeFace = Typeface.createFromAsset(getAssets(), "FontAwesome.ttf");
    final int[] visibleLogos;
    final int[] goneLogos;
    if (AppConstants.FULL_WIDTH_HEADERS) {
        visibleLogos = FULL_WIDTH_ROGERTHAT_LOGOS;
        goneLogos = NORMAL_WIDTH_ROGERTHAT_LOGOS;
        View viewFlipper = findViewById(R.id.registration_viewFlipper);
        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) viewFlipper.getLayoutParams();
        params.setMargins(0, 0, 0, 0);
    } else {
        visibleLogos = NORMAL_WIDTH_ROGERTHAT_LOGOS;
        goneLogos = FULL_WIDTH_ROGERTHAT_LOGOS;
    }

    for (int id : visibleLogos)
        findViewById(id).setVisibility(View.VISIBLE);
    for (int id : goneLogos)
        findViewById(id).setVisibility(View.GONE);

    handleScreenOrientation(getResources().getConfiguration().orientation);

    ScrollView rc = (ScrollView) findViewById(R.id.registration_container);
    Resources resources = getResources();
    if (CloudConstants.isRogerthatApp()) {
        rc.setBackgroundColor(resources.getColor(R.color.mc_page_dark));
    } else {
        rc.setBackgroundColor(resources.getColor(R.color.mc_homescreen_background));
    }

    TextView rogerthatWelcomeTextView = (TextView) findViewById(R.id.rogerthat_welcome);

    TextView tosTextView = (TextView) findViewById(R.id.registration_tos);
    Typeface FONT_THIN_ITALIC = Typeface.createFromAsset(getAssets(), "fonts/lato_light_italic.ttf");
    tosTextView.setTypeface(FONT_THIN_ITALIC);
    tosTextView.setTextColor(ContextCompat.getColor(RegistrationActivity2.this, R.color.mc_words_color));

    Button agreeBtn = (Button) findViewById(R.id.registration_agree_tos);

    TextView tvRegistration = (TextView) findViewById(R.id.registration);
    tvRegistration.setText(getString(R.string.registration_city_app_sign_up, getString(R.string.app_name)));

    mEnterEmailAutoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.registration_enter_email);

    if (CloudConstants.isEnterpriseApp()) {
        rogerthatWelcomeTextView
                .setText(getString(R.string.rogerthat_welcome_enterprise, getString(R.string.app_name)));
        tosTextView.setVisibility(View.GONE);
        agreeBtn.setText(R.string.start_registration);
        mEnterEmailAutoCompleteTextView.setHint(R.string.registration_enter_email_hint_enterprise);
    } else {
        rogerthatWelcomeTextView
                .setText(getString(R.string.registration_welcome_text, getString(R.string.app_name)));

        tosTextView.setText(Html.fromHtml(
                "<a href=\"" + CloudConstants.TERMS_OF_SERVICE_URL + "\">" + tosTextView.getText() + "</a>"));
        tosTextView.setMovementMethod(LinkMovementMethod.getInstance());

        agreeBtn.setText(R.string.registration_btn_agree_tos);

        mEnterEmailAutoCompleteTextView.setHint(R.string.registration_enter_email_hint);
    }

    agreeBtn.getBackground().setColorFilter(Message.GREEN_BUTTON_COLOR, PorterDuff.Mode.MULTIPLY);
    agreeBtn.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            sendRegistrationStep(RegistrationWizard2.REGISTRATION_STEP_AGREED_TOS);
            mWiz.proceedToNextPage();

        }
    });

    initLocationUsageStep(faTypeFace);

    View.OnClickListener emailLoginListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            sendRegistrationStep(RegistrationWizard2.REGISTRATION_STEP_EMAIL_LOGIN);
            mWiz.proceedToNextPage();
        }
    };

    findViewById(R.id.login_via_email).setOnClickListener(emailLoginListener);

    Button facebookButton = (Button) findViewById(R.id.login_via_fb);

    View.OnClickListener facebookLoginListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Check network connectivity
            if (!mService.getNetworkConnectivityManager().isConnected()) {
                UIUtils.showNoNetworkDialog(RegistrationActivity2.this);
                return;
            }

            sendRegistrationStep(RegistrationWizard2.REGISTRATION_STEP_FACEBOOK_LOGIN);

            FacebookUtils.ensureOpenSession(RegistrationActivity2.this,
                    AppConstants.PROFILE_SHOW_GENDER_AND_BIRTHDATE
                            ? Arrays.asList("email", "user_friends", "user_birthday")
                            : Arrays.asList("email", "user_friends"),
                    PermissionType.READ, new Session.StatusCallback() {
                        @Override
                        public void call(Session session, SessionState state, Exception exception) {
                            if (session != Session.getActiveSession()) {
                                session.removeCallback(this);
                                return;
                            }

                            if (exception != null) {
                                session.removeCallback(this);
                                if (!(exception instanceof FacebookOperationCanceledException)) {
                                    L.bug("Facebook SDK error during registration", exception);
                                    AlertDialog.Builder builder = new AlertDialog.Builder(
                                            RegistrationActivity2.this);
                                    builder.setMessage(R.string.error_please_try_again);
                                    builder.setPositiveButton(R.string.rogerthat, null);
                                    AlertDialog dialog = builder.create();
                                    dialog.show();
                                }
                            } else if (session.isOpened()) {
                                session.removeCallback(this);
                                if (session.getPermissions().contains("email")) {
                                    registerWithAccessToken(session.getAccessToken());
                                } else {
                                    AlertDialog.Builder builder = new AlertDialog.Builder(
                                            RegistrationActivity2.this);
                                    builder.setMessage(R.string.facebook_registration_email_missing);
                                    builder.setPositiveButton(R.string.rogerthat, null);
                                    AlertDialog dialog = builder.create();
                                    dialog.show();
                                }
                            }
                        }
                    }, false);
        }

        ;
    };

    facebookButton.setOnClickListener(facebookLoginListener);

    final Button getAccountsButton = (Button) findViewById(R.id.get_accounts);
    if (configureEmailAutoComplete()) {
        // GET_ACCOUNTS permission is granted
        getAccountsButton.setVisibility(View.GONE);
    } else {
        getAccountsButton.setTypeface(faTypeFace);
        getAccountsButton.setOnClickListener(new SafeViewOnClickListener() {
            @Override
            public void safeOnClick(View v) {
                ActivityCompat.requestPermissions(RegistrationActivity2.this,
                        new String[] { Manifest.permission.GET_ACCOUNTS }, PERMISSION_REQUEST_GET_ACCOUNTS);
            }
        });
    }

    mEnterPinEditText = (EditText) findViewById(R.id.registration_enter_pin);

    mEnterPinEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() == PIN_LENGTH)
                onPinEntered();
        }
    });

    Button requestNewPinButton = (Button) findViewById(R.id.registration_request_new_pin);
    requestNewPinButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mWiz.setEmail(null);
            hideNotification();
            mWiz.reInit();
            mWiz.goBackToPrevious();
            mEnterEmailAutoCompleteTextView.setText("");
        }
    });

    mWiz = RegistrationWizard2.getWizard(mService);
    mWiz.setFlipper((ViewFlipper) findViewById(R.id.registration_viewFlipper));
    setFinishHandler();
    addAgreeTOSHandler();
    addIBeaconUsageHandler();
    addChooseLoginMethodHandler();
    addEnterPinHandler();
    mWiz.run();
    mWiz.setDeviceId(Installation.id(this));

    handleEnterEmail();

    if (mWiz.getBeaconRegions() != null && mBeaconManager == null) {
        bindBeaconManager();
    }

    if (CloudConstants.USE_GCM_KICK_CHANNEL && GoogleServicesUtils.checkPlayServices(this, true)) {
        GoogleServicesUtils.registerGCMRegistrationId(mService, new GCMRegistrationIdFoundCallback() {
            @Override
            public void idFound(String registrationId) {
                mGCMRegistrationId = registrationId;
            }
        });
    }
}

From source file:com.cssweb.android.base.QuoteGridActivity.java

private void AddViewItem(String paramString, int paramInt1, LinearLayout paramLinearLayout, int paramInt2,
        int paramInt3, int paramInt4, boolean paramBoolean) {
    TextView localTextView = new TextView(this);
    float f = this.mFontSize;

    localTextView.setTextSize(f);/*  w  w  w .  ja  v a  2s . c  o  m*/
    //??4?
    if (paramInt2 == paramInt4 && paramInt3 == 0 && nameOrcode) {

        if (this.mPaint.measureText(paramString) > textWeight)
            localTextView.setTextSize(13);
    }

    if (n2 == paramInt2) {
        String str = (n1 == 0) ? paramString + low : (n1 == 1) ? paramString + top : paramString;
        localTextView.setText(str);
    } else {
        localTextView.setText(paramString);
    }
    localTextView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
    localTextView.setFocusable(paramBoolean);
    localTextView.setOnClickListener(mClickListener);
    localTextView.setOnLongClickListener(mLongClickListener);
    localTextView.setOnTouchListener(this); //touch
    localTextView.setTag(paramInt2);
    localTextView.setEnabled(paramBoolean);
    localTextView.setSingleLine(false);
    if (paramInt4 == 0 && paramInt3 >= 0) {//
        localTextView.setGravity(Gravity.CENTER);
        int i1 = this.residTitleCol;
        int i8 = 0;
        localTextView.setTextColor(paramInt1);
        if (paramInt3 == 0) {
            localDrawable = getResources().getDrawable(i1);
            i8 = localDrawable.getIntrinsicWidth();
        } else if (paramInt3 == 100) {
            localDrawable = getResources().getDrawable(this.residTitleScrollCol[2]);
            i8 = localDrawable.getIntrinsicWidth();
        } else if (paramInt3 == 13) {
            localDrawable = getResources().getDrawable(this.residTitleScrollCol[0]);
            i8 = localDrawable.getIntrinsicWidth();
            i8 += 20;
        } else if (paramInt3 == 8) {
            localDrawable = getResources().getDrawable(this.residTitleScrollCol[0]);
            i8 = localDrawable.getIntrinsicWidth();
            i8 += 10;
        } else if (paramInt3 % 2 == 0) {
            localDrawable = getResources().getDrawable(this.residTitleScrollCol[1]);
            i8 = localDrawable.getIntrinsicWidth();
        } else {
            localDrawable = getResources().getDrawable(this.residTitleScrollCol[0]);
            i8 = localDrawable.getIntrinsicWidth();
        }
        localTextView.setBackgroundDrawable(localDrawable);
        int i6 = localDrawable.getIntrinsicHeight();
        localTextView.setHeight(i6 + CssSystem.getTableTitleHeight(this));
        //int i9 = (int) Math.max(i8, mPaint.measureText(paramString));
        localTextView.setWidth(i8);
        paramLinearLayout.addView(localTextView);
        return;
    }
    if (paramInt4 != 0 && paramInt3 >= 0) {
        int i8 = 0;
        localTextView.setTextColor(paramInt1);
        if (paramInt3 == 0) {
            localDrawable = getResources().getDrawable(this.residCol);
            i8 = localDrawable.getIntrinsicWidth();
        } else if (paramInt3 == 100) {
            localDrawable = getResources().getDrawable(this.residScrollCol[2]);
            localTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            i8 = localDrawable.getIntrinsicWidth();
        } else if (paramInt3 == 13) {
            localDrawable = getResources().getDrawable(this.residScrollCol[0]);
            localTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            i8 = localDrawable.getIntrinsicWidth();
            i8 += 20;
            //localTextView.setWidth(i8+20);
        } else if (paramInt3 == 8) {
            localDrawable = getResources().getDrawable(this.residScrollCol[0]);
            localTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            i8 = localDrawable.getIntrinsicWidth();
            i8 += 10;
            //localTextView.setWidth(i8+20);
        } else if (paramInt3 % 2 == 0) {
            localDrawable = getResources().getDrawable(this.residScrollCol[1]);
            localTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            i8 = localDrawable.getIntrinsicWidth();
        } else {
            localDrawable = getResources().getDrawable(this.residScrollCol[0]);
            localTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            i8 = localDrawable.getIntrinsicWidth();
        }
        localTextView.setBackgroundDrawable(localDrawable);
        int i6 = localDrawable.getIntrinsicHeight();
        localTextView.setHeight(i6 + rowHeight);
        //int i9 = (int) Math.max(i8, mPaint.measureText(paramString));
        localTextView.setWidth(i8);
        paramLinearLayout.addView(localTextView);
        return;
    }
    //      if ((paramInt3 == j) && (paramInt4 == l)) {
    //         int i13 = this.residTitleScrollCol[l];
    //         localDrawable = localResources.getDrawable(i13);
    //         localTextView.setTextColor(paramInt1);
    //         localTextView.setBackgroundDrawable(localDrawable);
    //         paramLinearLayout.addView(localTextView);
    //         return;
    //      }
}

From source file:gc.david.dfm.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Mint.initAndStartSession(MainActivity.this, "6f2149e6");
    // Enable logging
    Mint.enableLogging(true);//from w w  w  .  java2 s  .  co  m
    Mint.leaveBreadcrumb("MainActivity::onCreate");

    setContentView(R.layout.activity_main);
    inject(this);

    DEVICE_DENSITY = getResources().getDisplayMetrics().density;

    googleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API)
            .addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();

    final SupportMapFragment fragment = ((SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map));
    googleMap = fragment.getMap();

    if (googleMap != null) {
        googleMap.setMyLocationEnabled(true);
        googleMap.getUiSettings().setZoomControlsEnabled(true);
        googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);

        // InMobi Ads
        InMobi.initialize(this, "9b61f509a1454023b5295d8aea4482c2");
        banner = (IMBanner) findViewById(R.id.banner);
        if (banner != null) {
            // Si no hay red el banner no carga ni aunque est vaco
            banner.setRefreshInterval(30);
            banner.setIMBannerListener(new IMBannerListener() {
                @Override
                public void onShowBannerScreen(IMBanner arg0) {
                    Mint.leaveBreadcrumb("MainActivity::banner onShowBannerScreen");
                }

                @Override
                public void onLeaveApplication(IMBanner arg0) {
                    Mint.leaveBreadcrumb("MainActivity::banner onLeaveApplication");
                }

                @Override
                public void onDismissBannerScreen(IMBanner arg0) {
                    Mint.leaveBreadcrumb("MainActivity::banner onDismissBannerScreen");
                }

                @Override
                public void onBannerRequestSucceeded(IMBanner arg0) {
                    Mint.leaveBreadcrumb("MainActivity::banner onBannerRequestSucceeded");
                    bannerShown = true;
                    fixMapPadding();
                }

                @Override
                public void onBannerRequestFailed(IMBanner arg0, IMErrorCode arg1) {
                    Mint.leaveBreadcrumb("MainActivity::banner onBannerRequestFailed");
                }

                @Override
                public void onBannerInteraction(IMBanner arg0, Map<String, String> arg1) {
                    Mint.leaveBreadcrumb("MainActivity::banner onBannerInteraction");
                    Mint.logEvent("Ad tapped");
                }
            });
            banner.loadBanner();
        }

        if (!isOnline(getApplicationContext())) {
            showWifiAlertDialog();
        }

        googleMap.setOnMapLongClickListener(new OnMapLongClickListener() {
            @Override
            public void onMapLongClick(LatLng point) {
                Mint.leaveBreadcrumb("MainActivity::googleMap onMapLongClick");
                calculatingDistance = true;

                if (distanceMode == DistanceMode.DISTANCE_FROM_ANY_POINT) {
                    if (coordinates == null || coordinates.isEmpty()) {
                        toastIt(getString(R.string.toast_first_point_needed), getApplicationContext());
                    } else {
                        coordinates.add(point);
                        drawAndShowMultipleDistances(coordinates, "", false, true);
                    }
                }
                // Si no hemos encontrado la posicin actual, no podremos
                // calcular la distancia
                else if (currentLocation != null) {
                    if ((distanceMode == DistanceMode.DISTANCE_FROM_CURRENT_POINT) && (coordinates.isEmpty())) {
                        coordinates
                                .add(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()));
                    }
                    coordinates.add(point);
                    drawAndShowMultipleDistances(coordinates, "", false, true);
                }

                calculatingDistance = false;
            }
        });

        googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
            @Override
            public void onMapClick(LatLng point) {
                Mint.leaveBreadcrumb("MainActivity::googleMap onMapClick");
                if (distanceMode == DistanceMode.DISTANCE_FROM_ANY_POINT) {
                    if (!calculatingDistance) {
                        coordinates.clear();
                    }

                    calculatingDistance = true;

                    if (coordinates.isEmpty()) {
                        googleMap.clear();
                    }
                    coordinates.add(point);
                    googleMap.addMarker(new MarkerOptions().position(point));
                } else {
                    // Si no hemos encontrado la posicin actual, no podremos
                    // calcular la distancia
                    if (currentLocation != null) {
                        if (coordinates != null) {
                            if (!calculatingDistance) {
                                coordinates.clear();
                            }
                            calculatingDistance = true;

                            if (coordinates.isEmpty()) {
                                googleMap.clear();
                                coordinates.add(new LatLng(currentLocation.getLatitude(),
                                        currentLocation.getLongitude()));
                            }
                            coordinates.add(point);
                            googleMap.addMarker(new MarkerOptions().position(point));
                        } else {
                            final IllegalStateException illegalStateException = new IllegalStateException(
                                    "Empty coordinates list");
                            Mint.logException(illegalStateException);
                            throw illegalStateException;
                        }
                    }
                }
            }
        });

        // TODO Future release
        // Cambiar esto: debera modificar solamentela posicin que estemos tuneando y recalcular
        //         googleMap.setOnMarkerDragListener(new OnMarkerDragListener() {
        ////            private String selectedMarkerId;
        //
        //            @Override
        //            public void onMarkerDragStart(Marker marker) {
        ////               selectedMarkerId = null;
        ////               final String markerId = marker.getId();
        ////               if (coordinates.contains(markerId)) {
        ////                  for (int i = 0; i < coordinates.size(); i++) {
        ////                     final LatLng position = coordinates.get(i);
        ////                     if (markerId.latitude == position.latitude &&
        ////                           markerId.longitude == position.longitude) {
        ////                        selectedMarkerId = i;
        ////                        break;
        ////                     }
        ////                  }
        ////               }
        //            }
        //
        //            @Override
        //            public void onMarkerDragEnd(Marker marker) {
        ////               if (selectedMarkerId != -1) {
        ////                  coordinates.set(selectedMarkerId, marker.getPosition());
        ////               }
        ////               // NO movemos el zoom porque estamos simplemente afinando la
        ////               // posicin
        ////               drawAndShowMultipleDistances(coordinates, "", false, false);
        //            }
        //
        //            @Override
        //            public void onMarkerDrag(Marker marker) {
        //               // nothing
        //            }
        //         });

        googleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
            @Override
            public void onInfoWindowClick(Marker marker) {
                Mint.leaveBreadcrumb("MainActivity::googleMap onInfoWindowClick");
                final Intent showInfoActivityIntent = new Intent(MainActivity.this, ShowInfoActivity.class);

                showInfoActivityIntent.putExtra(ShowInfoActivity.POSITIONS_LIST_EXTRA_KEY_NAME,
                        Lists.newArrayList(coordinates));
                showInfoActivityIntent.putExtra(ShowInfoActivity.DISTANCE_EXTRA_KEY_NAME,
                        distanceMeasuredAsText);
                startActivity(showInfoActivityIntent);
            }
        });

        googleMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter(this));

        // Iniciando la app
        if (currentLocation == null) {
            toastIt(getString(R.string.toast_loading_position), getApplicationContext());
        }

        handleIntents(getIntent());

        final List<String> distanceModes = Lists.newArrayList(
                getString(R.string.navigation_drawer_starting_point_current_position_item),
                getString(R.string.navigation_drawer_starting_point_any_position_item));
        final List<Integer> distanceIcons = Lists.newArrayList(R.drawable.ic_action_device_gps_fixed,
                R.drawable.ic_action_communication_location_on);
        drawerList = (ListView) findViewById(R.id.left_drawer);

        // TODO cambiar esto por un header como dios manda
        final LayoutInflater inflater = (LayoutInflater) getApplicationContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View convertView = inflater.inflate(R.layout.simple_textview_list_item, drawerList, false);
        final TextView tvListElement = (TextView) convertView.findViewById(R.id.simple_textview);
        tvListElement.setText(getString(R.string.navigation_drawer_starting_point_header));
        tvListElement.setClickable(false);
        tvListElement.setTextColor(getResources().getColor(R.color.white));
        drawerList.addHeaderView(convertView);
        drawerList.setAdapter(new NavigationDrawerItemAdapter(this, distanceModes, distanceIcons));

        drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                selectItem(position);
            }
        });

        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
                R.string.progressdialog_search_position_message,
                R.string.progressdialog_search_position_message) {
            @Override
            public void onDrawerOpened(View drawerView) {
                Mint.leaveBreadcrumb("MainActivity::actionBarDrawerToggle onDrawerOpened");
                super.onDrawerOpened(drawerView);
                supportInvalidateOptionsMenu();
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                Mint.leaveBreadcrumb("MainActivity::actionBarDrawerToggle onDrawerClosed");
                super.onDrawerClosed(drawerView);
                supportInvalidateOptionsMenu();
            }
        };

        drawerLayout.setDrawerListener(actionBarDrawerToggle);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);

        if (savedInstanceState == null) {
            Mint.leaveBreadcrumb("MainActivity savedInstanceState == null");
            // TODO change this because the header!!!!
            selectItem(FIRST_DRAWER_ITEM_INDEX);
        }
    }
}

From source file:com.benefit.buy.library.http.query.AbstractAQuery.java

/**
 * Set the text color of a TextView./* ww w.  j av  a 2 s.c o  m*/
 * @param color the color
 * @return self
 */
public T textColor(int color) {
    if (view instanceof TextView) {
        TextView tv = (TextView) view;
        tv.setTextColor(color);
    }
    return self();
}

From source file:android_network.hetnet.vpn_service.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 a2 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))
        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.adithya321.sharesanalysis.fragments.DetailFragment.java

private void setShareHoldings(View view) {
    TextView percentageChangeTV = (TextView) view.findViewById(R.id.detail__percent_change);
    TextView noOfDaysTV = (TextView) view.findViewById(R.id.detail_no_of_days);
    TextView totalProfitTV = (TextView) view.findViewById(R.id.detail_total_profit);
    TextView currentNoOfSharesTV = (TextView) view.findViewById(R.id.detail_currents_no_of_shares);
    TextView currentStockValueTV = (TextView) view.findViewById(R.id.detail_current_value);
    TextView targetTotalProfitTV = (TextView) view.findViewById(R.id.detail_target_total_profit);
    TextView rewardTV = (TextView) view.findViewById(detail_reward);

    int totalSharesPurchased = 0;
    int totalSharesSold = 0;
    double totalValuePurchased = 0;
    double totalValueSold = 0;
    double averageShareValue = 0;
    double percentageChange = 0;
    double totalProfit = 0;
    double targetTotalProfit = 0;
    double reward = 0;
    double currentStockValue = 0;

    RealmList<Purchase> purchases = share.getPurchases();
    for (Purchase purchase : purchases) {
        if (purchase.getType().equals("buy")) {
            totalSharesPurchased += purchase.getQuantity();
            totalValuePurchased += (purchase.getQuantity() * purchase.getPrice());
        } else if (purchase.getType().equals("sell")) {
            totalSharesSold += purchase.getQuantity();
            totalValueSold += (purchase.getQuantity() * purchase.getPrice());
        }/*from   w  ww  .ja  v a2  s  .  co  m*/
    }
    if (totalSharesPurchased != 0)
        averageShareValue = totalValuePurchased / totalSharesPurchased;

    if (averageShareValue != 0)
        percentageChange = ((share.getCurrentShareValue() - averageShareValue) / averageShareValue) * 100;
    Date today = new Date();
    Date start = share.getDateOfInitialPurchase();
    long noOfDays = DateUtils.getDateDiff(start, today, TimeUnit.DAYS);

    SharedPreferences sharedPreferences = getActivity().getSharedPreferences("prefs", 0);

    int currentNoOfShares = totalSharesPurchased - totalSharesSold;
    totalProfit = totalValueSold - totalValuePurchased;
    currentStockValue = currentNoOfShares * share.getCurrentShareValue();
    double target = sharedPreferences.getFloat("target", 0);
    targetTotalProfit = (target / 100) * totalValuePurchased * ((double) noOfDays / 365);
    reward = totalProfit - targetTotalProfit;
    if (reward < 0)
        rewardTV.setTextColor(getResources().getColor((android.R.color.holo_red_dark)));
    else
        rewardTV.setTextColor(getResources().getColor((R.color.colorPrimary)));

    currentNoOfSharesTV.setText(String.valueOf(currentNoOfShares));
    percentageChangeTV.setText(String.valueOf(NumberUtils.round(percentageChange, 2)));
    noOfDaysTV.setText(String.valueOf(noOfDays));
    totalProfitTV.setText(String.valueOf(NumberUtils.round(totalProfit, 2)));
    currentStockValueTV.setText(String.valueOf(NumberUtils.round(currentStockValue, 2)));
    targetTotalProfitTV.setText(String.valueOf(NumberUtils.round(targetTotalProfit, 2)));
    rewardTV.setText(String.valueOf(NumberUtils.round(reward, 2)));
}

From source file:com.cellbots.logger.LoggerActivity.java

private void updateSensorUi(int sensorType, int accuracy, float[] values) {
    // IMPORTANT: DO NOT UPDATE THE CONTENTS INSIDE A DRAWER IF IT IS BEING
    // ANIMATED VIA A CALL TO animateOpen/animateClose!!!
    // Updating anything inside will stop the animation from running.
    // Note that this does not seem to affect the animation if it had been
    // triggered by dragging the drawer instead of being called
    // programatically.
    if (mDataDrawer.isMoving()) {
        return;/*from   www.j av  a 2s .c  om*/
    }
    TextView xTextView;
    TextView yTextView;
    TextView zTextView;
    if (sensorType == Sensor.TYPE_ACCELEROMETER) {
        xTextView = mAccelXTextView;
        yTextView = mAccelYTextView;
        zTextView = mAccelZTextView;
    } else if (sensorType == Sensor.TYPE_GYROSCOPE) {
        xTextView = mGyroXTextView;
        yTextView = mGyroYTextView;
        zTextView = mGyroZTextView;
    } else if (sensorType == Sensor.TYPE_MAGNETIC_FIELD) {
        xTextView = mMagXTextView;
        yTextView = mMagYTextView;
        zTextView = mMagZTextView;
    } else {
        return;
    }

    int textColor = Color.WHITE;
    String prefix = "";
    switch (accuracy) {
    case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
        prefix = "  ";
        break;
    case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
        prefix = "  *";
        break;
    case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
        prefix = "  **";
        break;
    case SensorManager.SENSOR_STATUS_UNRELIABLE:
        prefix = "  ***";
        break;
    }

    xTextView.setTextColor(textColor);
    yTextView.setTextColor(textColor);
    zTextView.setTextColor(textColor);
    xTextView.setText(prefix + numberDisplayFormatter(values[0]));
    yTextView.setText(prefix + numberDisplayFormatter(values[1]));
    zTextView.setText(prefix + numberDisplayFormatter(values[2]));

}

From source file:net.phase.wallet.Currency.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    double exchrate = Currency.getRate(context.getActiveCurrency());

    LayoutInflater inflater = LayoutInflater.from(context);

    View v = inflater.inflate(R.layout.walletlayout, null);
    v.setLongClickable(true);/* ww  w  .j a v a 2 s.co m*/
    v.setOnClickListener(context);
    v.setTag(position);

    DecimalFormat df = new DecimalFormat(WalletActivity.decimalString(decimalpoints));

    TextView balanceTextView = (TextView) v.findViewById(R.id.walletBalanceText);
    balanceTextView.setText(df.format(wallets[position].balance / BalanceRetriever.SATOSHIS_PER_BITCOIN));

    TextView curTextView = (TextView) v.findViewById(R.id.walletCurText);
    curTextView.setTextSize(10);

    if (exchrate != 0) {
        curTextView.setText(
                "(" + df.format(wallets[position].balance * exchrate / BalanceRetriever.SATOSHIS_PER_BITCOIN)
                        + context.getActiveCurrency() + ")");
    } else {
        curTextView.setText("");
    }

    balanceTextView.setTextSize(20);
    balanceTextView.setTextColor(Color.GREEN);

    TextView nameTextView = (TextView) v.findViewById(R.id.walletNameText);
    nameTextView.setText(wallets[position].name);
    nameTextView.setTextColor(Color.BLACK);
    nameTextView.setTextSize(16);

    TextView lastUpdatedTextView = (TextView) v.findViewById(R.id.lastUpdatedText);

    lastUpdatedTextView.setTextColor(Color.GRAY);
    lastUpdatedTextView.setTextSize(8);
    lastUpdatedTextView.setText("Last Updated: " + getTimeStampString(wallets[position].lastUpdated));

    TextView infoTextView = (TextView) v.findViewById(R.id.infoText);

    infoTextView.setTextColor(Color.GRAY);
    infoTextView.setTextSize(8);
    infoTextView.setText(
            wallets[position].keys.length + " keys (" + wallets[position].getActiveKeyCount() + " in use)");

    TextView txLastUpdatedTextView = (TextView) v.findViewById(R.id.txLastUpdatedText);
    txLastUpdatedTextView.setTextColor(Color.GRAY);
    txLastUpdatedTextView.setTextSize(8);

    TextView txInfoTextView = (TextView) v.findViewById(R.id.txInfoText);
    txInfoTextView.setTextColor(Color.GRAY);
    txInfoTextView.setTextSize(8);

    if (wallets[position].transactions != null && wallets[position].transactions.length > 0) {
        txLastUpdatedTextView.setText(
                "Last Transaction: " + getTimeStampString(Transaction.latest(wallets[position].transactions)));
        txInfoTextView.setText(wallets[position].transactions.length + " transactions ("
                + Transaction.compressTransactions(wallets[position].transactions).length + " unique)");
    } else {
        txLastUpdatedTextView.setText("");
        txInfoTextView.setText("");
    }

    Button button = (Button) v.findViewById(R.id.updateButton);
    button.setTag(position);
    button.setOnClickListener(context);
    return v;
}

From source file:org.sirimangalo.meditationplus.AdapterMed.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

    View rowView;/*from w  ww .  j  a  va 2  s  .c o  m*/

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rowView = inflater.inflate(R.layout.list_item_med, parent, false);
    } else {
        rowView = convertView;
    }

    JSONObject p = values.get(position);

    TextView walk = (TextView) rowView.findViewById(R.id.one_walking);
    TextView sit = (TextView) rowView.findViewById(R.id.one_sitting);
    ImageView status = (ImageView) rowView.findViewById(R.id.one_status);
    TextView name = (TextView) rowView.findViewById(R.id.one_med);
    ImageView flag = (ImageView) rowView.findViewById(R.id.one_flag);

    View anuView = rowView.findViewById(R.id.anumodana_shell);
    TextView anuText = (TextView) rowView.findViewById(R.id.anumodana);

    try {
        String wo = p.getString("walking");
        String so = p.getString("sitting");
        int wi = Integer.parseInt(wo);
        int si = Integer.parseInt(so);
        int ti = Integer.parseInt(p.getString("start"));
        int ei = Integer.parseInt(p.getString("end"));

        long nowL = System.currentTimeMillis() / 1000;

        int now = (int) nowL;

        boolean finished = false;

        String ws = "0";
        String ss = "0";

        if (ei > now) {

            float secs = now - ti;

            if (secs > wi * 60 || wi == 0) { //walking done
                float ssecs = (int) (secs - (wi * 60));
                if (ssecs < si * 60) // still sitting
                    ss = Integer.toString((int) Math.floor(si - ssecs / 60));
                status.setImageResource(R.drawable.sitting_icon);
            } else { // still walking
                ws = Integer.toString((int) Math.floor(wi - secs / 60));
                ss = so;
                status.setImageResource(R.drawable.walking_icon);
            }

            ws += "/" + wo;
            ss += "/" + so;
        } else {
            ws = wo;
            ss = so;

            double age = 1 - (now - ei) / MAX_AGE;

            String ageColor = Integer.toHexString((int) (255 * age));

            if (ageColor.length() == 1)
                ageColor = "0" + ageColor;

            int alpha = Color.parseColor("#" + ageColor + "000000");

            walk.setTextColor(alpha);
            sit.setTextColor(alpha);
            name.setTextColor(alpha);
            status.setAlpha((float) age);
            flag.setAlpha((float) age);

        }

        walk.setText(ws);
        sit.setText(ss);

        if (p.has("country")) {
            int id = context.getResources().getIdentifier("flag_" + p.getString("country").toLowerCase(),
                    "drawable", context.getPackageName());
            flag.setImageResource(id);
            flag.setVisibility(View.VISIBLE);
        }

        final String username = p.getString("username");
        final String edit = p.getString("can_edit");
        name.setText(username);

        name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                context.showProfile(username);
            }
        });

        String type = p.getString("type");
        if ("love".equals(type))
            status.setImageResource(R.drawable.love_icon);

        String anu = p.getString("anumodana");
        if (!anu.equals("0"))
            anuText.setText(anu);

        if (p.getString("anu_me").equals("1")) {
            anuText.setTextColor(0xFF00BB00);
            anuText.setTypeface(null, Typeface.BOLD);
        }

        final String sid = p.getString("sid");

        anuView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d(TAG, "anu clicked");
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
                String loggedUsername = prefs.getString("username", "");
                String loginToken = prefs.getString("login_token", "");
                ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();
                nvp.add(new BasicNameValuePair("form_id", "anumed_" + sid));
                nvp.add(new BasicNameValuePair("login_token", loginToken));
                nvp.add(new BasicNameValuePair("submit", "Refresh"));
                nvp.add(new BasicNameValuePair("username", loggedUsername));
                nvp.add(new BasicNameValuePair("source", "android"));
                PostTaskRunner postTask = new PostTaskRunner(postHandler, context);
                postTask.doPostTask(nvp);

            }
        });

    } catch (Exception e) {
        e.printStackTrace();
    }
    return rowView;
}