Example usage for java.lang CharSequence length

List of usage examples for java.lang CharSequence length

Introduction

In this page you can find the example usage for java.lang CharSequence length.

Prototype

int length();

Source Link

Document

Returns the length of this character sequence.

Usage

From source file:com.example.carsharing.LongWayActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    photouri = Uri//from   w  w w.ja va2s .c o  m
            .fromFile(new File(this.getExternalFilesDir(Environment.DIRECTORY_PICTURES), IMAGE_FILE_NAME2));
    System.out.println("abc");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_long_way);

    activity_drawer = new Drawer(this, R.id.long_way_layout);
    mDrawerToggle = activity_drawer.newdrawer();
    mDrawerLayout = activity_drawer.setDrawerLayout();

    // 
    standard_date = new SimpleDateFormat("yyyy-MM-dd", Locale.SIMPLIFIED_CHINESE);
    primary_date = new SimpleDateFormat("yyyyMMdd", Locale.SIMPLIFIED_CHINESE);

    queue = Volley.newRequestQueue(this);
    exchange = (ImageView) findViewById(R.id.longway_exchange);
    exchange.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            String temp = startplace.getText().toString();

            startplace.setText(endplace.getText().toString());
            endplace.setText(temp);

        }
    });

    bdriver = true;

    datebutton = (Button) findViewById(R.id.longway_dates);
    increase = (Button) findViewById(R.id.longway_increase);
    decrease = (Button) findViewById(R.id.longway_decrease);
    s1 = (TextView) findViewById(R.id.longway_count);
    sure = (Button) findViewById(R.id.longway_sure);
    sure.setEnabled(false);
    startplace = (EditText) findViewById(R.id.longway_start_place);
    endplace = (EditText) findViewById(R.id.longway_end_place);
    noteinfo = (EditText) findViewById(R.id.longway_remarkText);
    commute = findViewById(R.id.drawer_commute);
    shortway = findViewById(R.id.drawer_shortway);
    longway = findViewById(R.id.drawer_longway);
    drawericon = (ImageView) findViewById(R.id.drawer_icon);
    drawername = (TextView) findViewById(R.id.drawer_name);
    drawernum = (TextView) findViewById(R.id.drawer_phone);
    carbrand = (EditText) findViewById(R.id.longway_CarBrand);
    model = (EditText) findViewById(R.id.longway_CarModel);
    color = (EditText) findViewById(R.id.longway_color);
    setting = findViewById(R.id.drawer_setting);
    licensenum = (EditText) findViewById(R.id.longway_Num);

    licensenum.addTextChangedListener(numTextWatcher);
    carbrand.addTextChangedListener(detTextWatcher);
    color.addTextChangedListener(coTextWatcher);
    model.addTextChangedListener(moTextWatcher);
    startplace.addTextChangedListener(spTextWatcher);
    endplace.addTextChangedListener(epTextWatcher);

    final TextView content = (TextView) findViewById(R.id.longway_content);
    longway_group = (RadioGroup) findViewById(R.id.longway_radiobutton);
    passangerRadioButton = (RadioButton) findViewById(R.id.longway_radioButton02);
    driverRadioButton = (RadioButton) findViewById(R.id.longway_radioButton01);
    personalcenter = findViewById(R.id.drawer_personalcenter);
    taxi = findViewById(R.id.drawer_taxi);

    // judge the value of "pre_page"
    Bundle bundle = this.getIntent().getExtras();
    String PRE_PAGE = bundle.getString("pre_page");
    if (PRE_PAGE.compareTo("ReOrder") == 0) { // 
        startplace.setText(bundle.getString("stpmapname"));
        bstart = true;
        endplace.setText(bundle.getString("epmapname"));
        bend = true;
        datebutton.setText(bundle.getString("re_longway_startdate"));
        bdate = true;
    }
    // judge the value of "pre_page"

    // 
    SharedPreferences sharedPref = this.getSharedPreferences(getString(R.string.PreferenceDefaultName),
            Context.MODE_PRIVATE);
    UserPhoneNumber = sharedPref.getString(getString(R.string.PreferenceUserPhoneNumber), "0");

    // database
    db = new DatabaseHelper(getApplicationContext(), UserPhoneNumber, null, 1);
    db1 = db.getWritableDatabase();
    about = findViewById(R.id.drawer_respond);
    about.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent about = new Intent(LongWayActivity.this, AboutActivity.class);
            startActivity(about);
        }
    });
    setting.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent setting = new Intent(LongWayActivity.this, SettingActivity.class);
            startActivity(setting);
        }
    });

    // database end

    taxi.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
        }
    });

    personalcenter.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent personalcenter = new Intent(LongWayActivity.this, PersonalCenterActivity.class);
            personalcenter.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(personalcenter);
        }
    });

    // RadioGroup

    longway_group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup arg0, int checkedId) {
            // TODO Auto-generated method stub18
            // ID

            // """"textView
            if (checkedId == passangerRadioButton.getId()) {
                bpassenager = true;
                bdriver = false;

                licensenum.setEnabled(false);
                carbrand.setEnabled(false);
                color.setEnabled(false);
                model.setEnabled(false);

                licensenum.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
                    }
                } });
                carbrand.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
                    }
                } });
                color.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
                    }
                } });
                model.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
                    }
                } });
                content.setText(getString(R.string.warningInfo_seatNeed));
                licensenum.setHintTextColor(Color.parseColor("#cccccc"));
                carbrand.setHintTextColor(Color.parseColor("#cccccc"));
                color.setHintTextColor(Color.parseColor("#cccccc"));
                model.setHintTextColor(Color.parseColor("#cccccc"));
                licensenum.setInputType(InputType.TYPE_NULL);
                carbrand.setInputType(InputType.TYPE_NULL);
                color.setInputType(InputType.TYPE_NULL);
                model.setInputType(InputType.TYPE_NULL);
            } else {
                bpassenager = false;
                bdriver = true;

                licensenum.setEnabled(true);
                carbrand.setEnabled(true);
                color.setEnabled(true);
                model.setEnabled(true);

                licensenum.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {

                        return null;
                    }
                } });
                carbrand.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return null;
                    }
                } });
                color.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {

                        return null;
                    }
                } });
                model.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {

                        return null;
                    }
                } });
                content.setText(getString(R.string.warningInfo_seatOffer));
                licensenum.setHintTextColor(Color.parseColor("#9F35FF"));
                carbrand.setHintTextColor(Color.parseColor("#9F35FF"));
                color.setHintTextColor(Color.parseColor("#9F35FF"));
                model.setHintTextColor(Color.parseColor("#9F35FF"));
                // licensenum.setText("");
                // carbrand.setText("");
                // color.setText("");
                // model.setText("");
                licensenum.setInputType(InputType.TYPE_CLASS_TEXT);
                carbrand.setInputType(InputType.TYPE_CLASS_TEXT);
                color.setInputType(InputType.TYPE_CLASS_TEXT);
                model.setInputType(InputType.TYPE_CLASS_TEXT);

                // start!
                selectcarinfo(UserPhoneNumber);
                // end!
            }
            confirm();
        }

        private void selectcarinfo(final String phonenum) {
            // TODO Auto-generated method stub
            String carinfo_selectrequest_baseurl = getString(R.string.uri_base)
                    + getString(R.string.uri_CarInfo) + getString(R.string.uri_selectcarinfo_action);

            Log.d("carinfo_selectrequest_baseurl", carinfo_selectrequest_baseurl);
            StringRequest stringRequest = new StringRequest(Request.Method.POST, carinfo_selectrequest_baseurl,
                    new Response.Listener<String>() {

                        @Override
                        public void onResponse(String response) {
                            // TODO Auto-generated method stub
                            Log.d("carinfo_select", response);
                            String jas_id = null;
                            JSONObject json1 = null;
                            try {
                                json1 = new JSONObject(response);
                                JSONObject json = json1.getJSONObject("result");
                                jas_id = json.getString("id");

                                if (jas_id.compareTo("") != 0) { // 

                                    carinfochoosing_type = 2;

                                    carbrand.setText(json.getString("carBrand"));
                                    model.setText(json.getString("carModel"));
                                    licensenum.setText(json.getString("carNum"));
                                    color.setText(json.getString("carColor"));

                                }
                                {
                                    carinfochoosing_type = 1;
                                }

                            } catch (JSONException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }

                    }, new Response.ErrorListener() {

                        @Override
                        public void onErrorResponse(VolleyError error) {
                            // TODO Auto-generated method stub
                            Log.e("carinfo_selectresult_result", error.getMessage(), error);
                        }
                    }) {
                protected Map<String, String> getParams() {
                    Map<String, String> params = new HashMap<String, String>();
                    params.put("phonenum", phonenum);
                    return params;
                }
            };

            queue.add(stringRequest);
        }
    });

    sure.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

            if (longway_group.getCheckedRadioButtonId() == passangerRadioButton.getId())
                userrole = "p";
            else
                userrole = "d";

            // start!
            Context phonenumber = LongWayActivity.this;
            SharedPreferences filename = phonenumber
                    .getSharedPreferences(getString(R.string.PreferenceDefaultName), Context.MODE_PRIVATE);
            username = filename.getString("refreshfilename", "0");
            longway_request(username, userrole, datebutton.getText().toString(),
                    startplace.getText().toString(), endplace.getText().toString(),
                    noteinfo.getText().toString());
            // end!
        }

        private void longway_request(final String longway_phonenum, final String longway_userrole,
                final String longway_startdate, final String longway_startplace,
                final String longway_destination, final String longway_noteinfo) {
            // TODO Auto-generated method stub

            String longway_addrequest_baseurl = getString(R.string.uri_base)
                    + getString(R.string.uri_LongwayPublish) + getString(R.string.uri_addpublish_action);
            // + "phonenum=" + longway_phonenum
            // + "&userrole=" + longway_userrole
            // + "&startdate=" + standard_longway_startdate
            // + "&startplace=" + longway_startplace
            // + "&destination=" + longway_destination
            // + "&noteinfo=" + longway_noteinfo;

            // Log.d("longway_baseurl",longway_addrequest_baseurl);

            StringRequest stringRequest = new StringRequest(Request.Method.POST, longway_addrequest_baseurl,
                    new Response.Listener<String>() {

                        @Override
                        public void onResponse(String response) {
                            Log.d("longway_result", response);
                            JSONObject json1 = null;
                            try {
                                json1 = new JSONObject(response);
                                requestok = json1.getBoolean("result");
                            } catch (JSONException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                            if (requestok == true) {

                                if (carinfochoosing_type == 1) {
                                    // add
                                    // start!
                                    carinfo(longway_phonenum, licensenum.getText().toString(),
                                            carbrand.getText().toString(), model.getText().toString(),
                                            color.getText().toString(), String.valueOf(sum), 1);
                                    // end!
                                } else {
                                    // update
                                    // start!
                                    carinfo(longway_phonenum, licensenum.getText().toString(),
                                            carbrand.getText().toString(), model.getText().toString(),
                                            color.getText().toString(), String.valueOf(sum), 2);
                                    // end!
                                }

                                Intent sure = new Intent(LongWayActivity.this, OrderResponseActivity.class);
                                sure.putExtra(getString(R.string.request_response), "true");
                                sure.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                startActivity(sure);
                            } else {
                                // Toast errorinfo =
                                // Toast.makeText(getApplicationContext(),
                                // "", Toast.LENGTH_LONG);
                                // errorinfo.show();
                                Intent sure = new Intent(LongWayActivity.this, OrderResponseActivity.class);
                                sure.putExtra(getString(R.string.request_response), "false");
                                sure.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                startActivity(sure);
                            }
                        }
                    }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Log.e("longway_result", error.getMessage(), error);
                            // Toast errorinfo = Toast.makeText(null,
                            // "", Toast.LENGTH_LONG);
                            // errorinfo.show();
                            Intent sure = new Intent(LongWayActivity.this, OrderResponseActivity.class);
                            sure.putExtra(getString(R.string.request_response), "false");
                            sure.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            startActivity(sure);
                        }
                    }) {
                protected Map<String, String> getParams() {
                    // POSTgetParams

                    // start
                    try {
                        test_date = primary_date.parse(longway_startdate);
                        standard_longway_startdate = standard_date.format(test_date);
                    } catch (ParseException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    // end!

                    Map<String, String> params = new HashMap<String, String>();
                    params.put(getString(R.string.uri_phonenum), longway_phonenum);
                    params.put(getString(R.string.uri_userrole), longway_userrole);
                    params.put(getString(R.string.uri_startplace), longway_startplace);
                    params.put(getString(R.string.uri_destination), longway_destination);
                    params.put(getString(R.string.uri_startdate), standard_longway_startdate);
                    params.put(getString(R.string.uri_noteinfo), longway_noteinfo);

                    return params;
                }
            };
            queue.add(stringRequest);
        }
    });

    // start!
    shortway.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent shortway = new Intent(LongWayActivity.this, ShortWayActivity.class);
            startActivity(shortway);
        }
    });

    longway.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
        }
    });

    commute.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent commute = new Intent(LongWayActivity.this, CommuteActivity.class);
            startActivity(commute);
        }
    });

    // end!

    increase.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            sum++;
            s1.setText("" + sum);
            confirm();
        }
    });

    decrease.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            sum--;
            if (sum < 0) {
                sum = 0;
            }
            s1.setText("" + sum);
            confirm();
        }
    });

    datebutton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            showDialog(DATE_DIALOG);
        }
    });
}

From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    final ImgurHoloActivity activity = (ImgurHoloActivity) getActivity();
    final SharedPreferences settings = activity.getApiCall().settings;
    sort = settings.getString("CommentSort", "Best");
    boolean newData = true;
    if (commentData != null) {
        newData = false;//from w ww  .  j av  a  2s. com
    }

    mainView = inflater.inflate(R.layout.single_image_layout, container, false);
    String[] mMenuList = getResources().getStringArray(R.array.emptyList);
    if (commentAdapter == null)
        commentAdapter = new CommentAdapter(mainView.getContext());
    commentLayout = (ListView) mainView.findViewById(R.id.comment_thread);
    commentLayout.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    if (settings.getString("theme", MainActivity.HOLO_LIGHT).equals(MainActivity.HOLO_LIGHT))
        imageLayoutView = (LinearLayout) View.inflate(getActivity(), R.layout.image_view, null);
    else
        imageLayoutView = (LinearLayout) View.inflate(getActivity(), R.layout.dark_image_view, null);

    mPullToRefreshLayout = (PullToRefreshLayout) mainView.findViewById(R.id.ptr_layout);
    ActionBarPullToRefresh.from(getActivity())
            // Mark All Children as pullable
            .allChildrenArePullable()
            // Set the OnRefreshListener
            .listener(this)
            // Finally commit the setup to our PullToRefreshLayout
            .setup(mPullToRefreshLayout);
    if (savedInstanceState != null && newData) {
        imageData = savedInstanceState.getParcelable("imageData");
        inGallery = savedInstanceState.getBoolean("inGallery");
    }
    LinearLayout layout = (LinearLayout) imageLayoutView.findViewById(R.id.image_buttons);
    TextView imageDetails = (TextView) imageLayoutView.findViewById(R.id.single_image_details);
    layout.setVisibility(View.VISIBLE);
    ImageButton imageFullscreen = (ImageButton) imageLayoutView.findViewById(R.id.fullscreen);
    imageUpvote = (ImageButton) imageLayoutView.findViewById(R.id.rating_good);
    imageDownvote = (ImageButton) imageLayoutView.findViewById(R.id.rating_bad);
    ImageButton imageFavorite = (ImageButton) imageLayoutView.findViewById(R.id.rating_favorite);
    imageComment = (ImageButton) imageLayoutView.findViewById(R.id.comment);
    ImageButton imageUser = (ImageButton) imageLayoutView.findViewById(R.id.user);
    imageScore = (TextView) imageLayoutView.findViewById(R.id.single_image_score);
    TextView imageInfo = (TextView) imageLayoutView.findViewById(R.id.single_image_info);
    Log.d("imageData", imageData.getJSONObject().toString());
    if (imageData.getJSONObject().has("ups")) {
        imageUpvote.setVisibility(View.VISIBLE);
        imageDownvote.setVisibility(View.VISIBLE);
        imageScore.setVisibility(View.VISIBLE);
        imageComment.setVisibility(View.VISIBLE);
        ImageUtils.updateImageFont(imageData, imageScore);
    }
    imageInfo.setVisibility(View.VISIBLE);
    ImageUtils.updateInfoFont(imageData, imageInfo);
    imageUser.setVisibility(View.VISIBLE);
    imageFavorite.setVisibility(View.VISIBLE);
    try {
        if (!imageData.getJSONObject().has("account_url")
                || imageData.getJSONObject().getString("account_url").equals("null")
                || imageData.getJSONObject().getString("account_url").equals("[deleted]"))
            imageUser.setVisibility(View.GONE);
        if (!imageData.getJSONObject().has("vote")) {
            imageUpvote.setVisibility(View.GONE);
            imageDownvote.setVisibility(View.GONE);
        } else {
            if (imageData.getJSONObject().getString("vote") != null
                    && imageData.getJSONObject().getString("vote").equals("up"))
                imageUpvote.setImageResource(R.drawable.green_rating_good);
            else if (imageData.getJSONObject().getString("vote") != null
                    && imageData.getJSONObject().getString("vote").equals("down"))
                imageDownvote.setImageResource(R.drawable.red_rating_bad);
        }
        if (imageData.getJSONObject().getString("favorite") != null
                && imageData.getJSONObject().getBoolean("favorite"))
            imageFavorite.setImageResource(R.drawable.green_rating_favorite);
    } catch (JSONException e) {
        Log.e("Error!", e.toString());
    }
    imageFavorite.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ImageUtils.favoriteImage(singleImageFragment, imageData, (ImageButton) view, activity.getApiCall());
        }
    });
    imageUser.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ImageUtils.gotoUser(singleImageFragment, imageData);
        }
    });
    imageComment.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Activity activity = getActivity();
            final EditText newBody = new EditText(activity);
            newBody.setHint(R.string.body_hint_body);
            newBody.setLines(3);
            final TextView characterCount = new TextView(activity);
            characterCount.setText("140");
            LinearLayout commentReplyLayout = new LinearLayout(activity);
            newBody.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                    //
                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                    characterCount.setText(String.valueOf(140 - charSequence.length()));
                }

                @Override
                public void afterTextChanged(Editable editable) {
                    for (int i = editable.length(); i > 0; i--) {
                        if (editable.subSequence(i - 1, i).toString().equals("\n"))
                            editable.replace(i - 1, i, "");
                    }
                }
            });
            commentReplyLayout.setOrientation(LinearLayout.VERTICAL);
            commentReplyLayout.addView(newBody);
            commentReplyLayout.addView(characterCount);
            new AlertDialog.Builder(activity).setTitle(R.string.dialog_comment_on_image_title)
                    .setView(commentReplyLayout)
                    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            if (newBody.getText() != null && newBody.getText().toString().length() < 141) {
                                HashMap<String, Object> commentMap = new HashMap<String, Object>();
                                try {
                                    commentMap.put("comment", newBody.getText().toString());
                                    commentMap.put("image_id", imageData.getJSONObject().getString("id"));
                                    Fetcher fetcher = new Fetcher(singleImageFragment, "3/comment/",
                                            ApiCall.POST, commentMap,
                                            ((ImgurHoloActivity) getActivity()).getApiCall(), POSTCOMMENT);
                                    fetcher.execute();
                                } catch (JSONException e) {
                                    Log.e("Error!", e.toString());
                                }
                            }
                        }
                    }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            // Do nothing.
                        }
                    }).show();
        }
    });
    imageUpvote.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ImageUtils.upVote(singleImageFragment, imageData, imageUpvote, imageDownvote,
                    activity.getApiCall());
            ImageUtils.updateImageFont(imageData, imageScore);
        }
    });
    imageDownvote.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ImageUtils.downVote(singleImageFragment, imageData, imageUpvote, imageDownvote,
                    activity.getApiCall());
            ImageUtils.updateImageFont(imageData, imageScore);
        }
    });
    if (popupWindow != null) {
        popupWindow.dismiss();
    }
    popupWindow = new PopupWindow();
    imageFullscreen.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ImageUtils.fullscreen(singleImageFragment, imageData, popupWindow, mainView);
        }
    });
    ArrayAdapter<String> tempAdapter = new ArrayAdapter<String>(mainView.getContext(),
            R.layout.drawer_list_item, mMenuList);
    Log.d("URI", "YO I'M IN YOUR SINGLE FRAGMENT gallery:" + inGallery);
    imageView = (ImageView) imageLayoutView.findViewById(R.id.single_image_view);
    loadImage();
    TextView imageTitle = (TextView) imageLayoutView.findViewById(R.id.single_image_title);
    TextView imageDescription = (TextView) imageLayoutView.findViewById(R.id.single_image_description);

    try {
        String size = String
                .valueOf(NumberFormat.getIntegerInstance()
                        .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_WIDTH)))
                + "x"
                + NumberFormat.getIntegerInstance()
                        .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_HEIGHT))
                + " (" + NumberFormat.getIntegerInstance()
                        .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_SIZE))
                + "B)";
        String initial = imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE) + " "
                + Html.fromHtml("&#8226;") + " " + size + " " + Html.fromHtml("&#8226;") + " " + "Views: "
                + NumberFormat.getIntegerInstance()
                        .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_VIEWS));
        imageDetails.setText(initial);
        Log.d("imagedata", imageData.getJSONObject().toString());
        if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE).equals("null"))
            imageTitle.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE));
        else
            imageTitle.setVisibility(View.GONE);
        if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION).equals("null")) {
            imageDescription
                    .setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION));
            imageDescription.setVisibility(View.VISIBLE);
        } else
            imageDescription.setVisibility(View.GONE);
        commentLayout.addHeaderView(imageLayoutView);
        commentLayout.setAdapter(tempAdapter);
    } catch (JSONException e) {
        Log.e("Text Error!", e.toString());
    }
    if ((savedInstanceState == null || commentData == null) && newData) {
        commentData = new JSONParcelable();
        getComments();
        commentLayout.setAdapter(commentAdapter);
    } else if (newData) {
        commentArray = savedInstanceState.getParcelableArrayList("commentData");
        commentAdapter.addAll(commentArray);
        commentLayout.setAdapter(commentAdapter);
        commentAdapter.notifyDataSetChanged();
    } else if (commentArray != null) {
        commentAdapter.addAll(commentArray);
        commentLayout.setAdapter(commentAdapter);
        commentAdapter.notifyDataSetChanged();
    }
    return mainView;
}

From source file:jef.tools.StringUtils.java

/**
 * HTML/*www.j  a va 2s. c o m*/
 */
public static CharSequence escapeHtml(CharSequence s, boolean unicode) {
    if (unicode)
        return StringEscapeUtils.escapeHtml(s.toString());
    StringBuilder sb = new StringBuilder(s.length() + 16);
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        int n = htmlEscEntities.indexOf(c);
        if (n > -1) {
            sb.append(htmlEscapeSequence[n]);
        } else {
            sb.append(c);
        }
    }
    return sb.length() == s.length() ? s : sb.toString();// ??string?
}

From source file:de.escidoc.core.common.util.xml.XmlUtility.java

/**
 * Create the content of the DC datastream to store in Fedora.
 *
 * @param nsUri          nsUri of the md record. Through this URI is the mapping schema selected.
 * @param mdRecordXml    Xml representation of the md record to parse.
 * @param objID          The objid of the Fedora object. A triple is created with this objid.
 * @param contentModelID The objid of the content-model.
 * @return The content of the DC datastream or null if content is empty.
 * @throws WebserverSystemException If an error occurs.
 *//*  w w w.ja v  a2s .c om*/
public static String createDC(final String nsUri, final String mdRecordXml, final CharSequence objID,
        final String contentModelID) throws WebserverSystemException {
    String result = null;
    Transformer t = null;
    final String transformerKey = nsUri + ';' + contentModelID;
    try {
        t = (Transformer) TRANSFORMER_POOL.borrowObject(transformerKey);
        if (objID != null && objID.length() > 0) {
            t.setParameter("ID", objID);
        } else {
            t.clearParameters();
        }
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        t.transform(new StreamSource(new ByteArrayInputStream(mdRecordXml.getBytes(CHARACTER_ENCODING))),
                new StreamResult(out));

        result = out.toString(CHARACTER_ENCODING).trim();
    } catch (final Exception e) {
        throw new WebserverSystemException("Mapping of Metadata to DC failed.", e);
    } finally {
        try {
            TRANSFORMER_POOL.returnObject(transformerKey, t);
        } catch (final Exception e) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("Returning transformer to pool failed.");
            }
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Returning transformer to pool failed.", e);
            }
        }
    }
    // check if result is empty
    if (result != null && result.length() == 0) {
        result = null;
    }
    return result;
}

From source file:com.servoy.j2db.util.Utils.java

/**
 * Checks whether the <code>string</code> is considered empty. Empty means that the string may contain whitespace, but no visible characters.
 *
 * "\n\t " is considered empty, while " a" is not.
 *
 * @param str the string//w ww .  ja va2  s  .co  m
 * @return true if the string is null or ""
 */
public static boolean stringIsEmpty(final CharSequence str) {
    return str == null || str.length() == 0 || str.toString().trim().length() == 0;
}

From source file:com.servoy.j2db.util.Utils.java

public static CharSequence stringLimitLenght(final CharSequence str, int length) {
    if (str == null)
        return null;
    return (str.length() > length ? str.subSequence(0, length) : str);
}

From source file:net.kidlogger.kidlogger.KLService.java

private void doScanClipboard() {
    ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    String content = "";
    int cSize = 0;
    if (cm.hasText()) {
        CharSequence tmp = cm.getText();
        cSize = tmp.length();
        if ((prevClipSize != cSize) && (cSize != 0)) {
            if (cSize > 30)
                content = tmp.subSequence(0, 30).toString();
            else//from   w  w  w.  j  av  a2s. com
                content = tmp.toString();

            prevClipSize = cSize;

            // Log clipboard content
            final String cnt = new String(content);
            new Thread(new Runnable() {
                public void run() {
                    sync.writeLog(".htm", Templates.getClipboardLog(cnt));
                }
            }).start();
            //WriteThread wcb = new WriteThread(sync, ".htm",
            //      Templates.getClipboardLog(content));
        }
    }
}

From source file:com.servoy.j2db.util.Utils.java

/**
 * Converts a String to multiline HTML markup by replacing newlines with line break entities (&lt;br/&gt;) and multiple occurrences of newline with
 * paragraph break entities (&lt;p&gt;).
 *
 * @param s String to transform//from w  w  w.ja v  a  2 s  . c  om
 * @return String with all single occurrences of newline replaced with &lt;br/&gt; and all multiple occurrences of newline replaced with &lt;p&gt;.
 */
public static CharSequence toMultilineMarkup(final CharSequence s) {
    if (s == null) {
        return null;
    }

    final StringBuilder buffer = new StringBuilder();
    int newlineCount = 0;

    buffer.append("<p>"); //$NON-NLS-1$
    for (int i = 0; i < s.length(); i++) {
        final char c = s.charAt(i);

        switch (c) {
        case '\n':
            newlineCount++;
            break;

        case '\r':
            break;

        default:
            if (newlineCount == 1) {
                buffer.append("<br/>"); //$NON-NLS-1$
            } else if (newlineCount > 1) {
                buffer.append("</p><p>"); //$NON-NLS-1$
            }

            buffer.append(c);
            newlineCount = 0;
            break;
        }
    }
    if (newlineCount == 1) {
        buffer.append("<br/>"); //$NON-NLS-1$
    } else if (newlineCount > 1) {
        buffer.append("</p><p>"); //$NON-NLS-1$
    }
    buffer.append("</p>"); //$NON-NLS-1$
    return buffer;
}

From source file:com.orange.ocara.ui.activity.BaseActivityManagingAudit.java

public void showAuditObjectProgress(AuditObject auditObject, final boolean terminateActivityWhenDone) {
    CharSequence info = getText(com.orange.ocara.R.string.auditing_progress_info);

    Spannable auditingStatus = new SpannableString("");
    int color = getResources().getColor(com.orange.ocara.R.color.black);
    switch (auditObject.getResponse()) {
    case OK:/*from  www.j a  v a 2s .  com*/
        auditingStatus = new SpannableString(getText(com.orange.ocara.R.string.auditing_progress_status_ok));
        color = getResources().getColor(com.orange.ocara.R.color.green);
        break;
    case NOK:
        if (auditObject.hasAtLeastOneBlockingRule()) {
            auditingStatus = new SpannableString(
                    getText(com.orange.ocara.R.string.auditing_progress_status_nok));
            color = getResources().getColor(com.orange.ocara.R.color.red);
        } else {

            auditingStatus = new SpannableString(
                    getText(com.orange.ocara.R.string.auditing_progress_status_anoying));
            color = getResources().getColor(com.orange.ocara.R.color.orange);
        }
        break;
    case DOUBT:
        auditingStatus = new SpannableString(getText(com.orange.ocara.R.string.auditing_progress_status_doubt));
        color = getResources().getColor(com.orange.ocara.R.color.yellow);
        break;
    case NoAnswer:
        auditingStatus = new SpannableString(
                getText(com.orange.ocara.R.string.auditing_progress_status_no_answer));
        color = getResources().getColor(com.orange.ocara.R.color.blue);
        break;
    }

    auditingStatus.setSpan(new ForegroundColorSpan(color), info.length(), auditingStatus.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    StringBuffer stringBuffer = new StringBuffer(info);
    stringBuffer.append("<br>").append(auditingStatus);

    // get application preference to know if he wants to audit object now

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    int displayAuditingProgessDialog = Integer.parseInt(sharedPreferences
            .getString(getString(com.orange.ocara.R.string.setting_display_auditing_progress_key), "1"));

    switch (displayAuditingProgessDialog) {
    case 1:
        final NotificationDialogBuilder dialogBuilder = new NotificationDialogBuilder(this);
        final AlertDialog dialog = dialogBuilder.setInfo(auditingStatus)
                .setOption(getString(com.orange.ocara.R.string.auditing_progress_option)).setCancelable(false)
                .setTitle(com.orange.ocara.R.string.auditing_progress_title)
                .setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialog) {

                        auditingProgressDismiss(dialogBuilder.getOptionValue());

                        if (terminateActivityWhenDone) {
                            BaseActivityManagingAudit.this.finish();
                        }
                    }
                }).setPositiveButton(com.orange.ocara.R.string.action_close, null).create();

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                dialog.dismiss();
            }

        }, 3500);
        dialog.show();

        break;
    default:
        if (terminateActivityWhenDone) {
            BaseActivityManagingAudit.this.finish();
        }
        break;
    }

}

From source file:com.healthmarketscience.jackcess.impl.ColumnImpl.java

/**
 * Encodes a text value, possibly compressing.
 */// w w w .  j  ava  2  s.com
ByteBuffer encodeTextValue(Object obj, int minChars, int maxChars, boolean forceUncompressed)
        throws IOException {
    CharSequence text = toCharSequence(obj);
    if ((text.length() > maxChars) || (text.length() < minChars)) {
        throw new IOException("Text is wrong length for " + getType() + " column, max " + maxChars + ", min "
                + minChars + ", got " + text.length());
    }

    // may only compress if column type allows it
    if (!forceUncompressed && isCompressedUnicode()
            && (text.length() <= getFormat().MAX_COMPRESSED_UNICODE_SIZE)) {

        // for now, only do very simple compression (only compress text which is
        // all ascii text)
        if (isAsciiCompressible(text)) {

            byte[] encodedChars = new byte[TEXT_COMPRESSION_HEADER.length + text.length()];
            encodedChars[0] = TEXT_COMPRESSION_HEADER[0];
            encodedChars[1] = TEXT_COMPRESSION_HEADER[1];
            for (int i = 0; i < text.length(); ++i) {
                encodedChars[i + TEXT_COMPRESSION_HEADER.length] = (byte) text.charAt(i);
            }
            return ByteBuffer.wrap(encodedChars);
        }
    }

    return encodeUncompressedText(text, getCharset());
}