Example usage for android.widget TextView TextView

List of usage examples for android.widget TextView TextView

Introduction

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

Prototype

public TextView(Context context) 

Source Link

Usage

From source file:com.df.app.procedures.CarRecogniseLayout.java

/**
 * ??? (vin)//from  w  w w  . j  av  a  2  s.co  m
 */
private void getCarSettingsFromServer() {
    String vin = getEditViewText(rootView, R.id.vin_edit);

    GetCarSettingsByVinTask getCarSettingsByVinTask = new GetCarSettingsByVinTask(getContext(), vin,
            new GetCarSettingsByVinTask.OnGetCarSettingsFinished() {
                @Override
                public void onFinished(String result) {
                    final List<String> modelNames;
                    final List<JSONObject> jsonObjects;

                    try {
                        JSONArray jsonArray = new JSONArray(result);
                        jsonObjects = new ArrayList<JSONObject>();

                        // ??string list
                        modelNames = new ArrayList<String>();

                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);

                            Country country;
                            Brand brand;
                            Manufacturer manufacturer;
                            Series series;
                            Model model;

                            // ?ID?
                            if (jsonObject.has("countryId"))
                                country = vehicleModel.getCountryById(jsonObject.getString("countryId"));
                            else
                                country = vehicleModel.countries.get(0);

                            if (jsonObject.has("brandId"))
                                brand = country.getBrandById(jsonObject.getString("brandId"));
                            else
                                brand = country.brands.get(0);

                            if (jsonObject.has("manufacturerId"))
                                manufacturer = brand
                                        .getManufacturerById(jsonObject.getString("manufacturerId"));
                            else
                                manufacturer = brand.manufacturers.get(0);

                            if (jsonObject.has("seriesId"))
                                series = manufacturer.getSeriesById(jsonObject.getString("seriesId"));
                            else
                                series = manufacturer.serieses.get(0);

                            if (jsonObject.has("modelId"))
                                model = series.getModelById(jsonObject.getString("modelId"));
                            else
                                model = series.models.get(0);

                            // ??list??
                            jsonObjects.add(jsonObject);
                            modelNames.add(manufacturer.name + " " + series.name + " " + model.name);
                        }

                        String[] tempArray = new String[modelNames.size() + 1];

                        for (int i = 0; i < modelNames.size(); i++) {
                            tempArray[i] = modelNames.get(i);
                        }

                        showModelChooseDialog(tempArray, new OnChooseModelFinished() {
                            @Override
                            public void onFinished(int index) throws JSONException {
                                // ?????
                                if (index == modelNames.size()) {
                                    selectCarManually();
                                }
                                // ?
                                else {
                                    JSONObject jsonObject = jsonObjects.get(index);

                                    Country country = vehicleModel
                                            .getCountryById(jsonObject.getString("countryId"));
                                    Brand brand = country.getBrandById(jsonObject.getString("brandId"));
                                    Manufacturer manufacturer = brand
                                            .getManufacturerById(jsonObject.getString("manufacturerId"));
                                    Series series = manufacturer
                                            .getSeriesById(jsonObject.getString("seriesId"));
                                    Model model = series.getModelById(jsonObject.getString("modelId"));

                                    // ?idspinner?
                                    lastCountryIndex = vehicleModel.getCountryNames().indexOf(country.name);
                                    lastBrandIndex = country.getBrandNames().indexOf(brand.name);
                                    lastManufacturerIndex = brand.getManufacturerNames()
                                            .indexOf(manufacturer.name);
                                    lastSeriesIndex = manufacturer.getSeriesNames().indexOf(series.name);
                                    lastModelIndex = series.getModelNames().indexOf(model.name);

                                    // ??
                                    updateCarSettings();

                                    // UI
                                    updateUi();
                                }
                            }
                        });
                    } catch (JSONException e) {
                        Log.d("DFCarChecker", "Json?" + e.getMessage());
                    }
                }

                @Override
                public void onFailed(String result) {
                    // ??
                    Log.d("DFCarChecker", "???" + result);

                    if (result.equals("VIN??")) {
                        View view1 = ((Activity) getContext()).getLayoutInflater()
                                .inflate(R.layout.popup_layout, null);
                        TableLayout contentArea = (TableLayout) view1.findViewById(R.id.contentArea);
                        TextView content = new TextView(view1.getContext());
                        content.setText("?");
                        content.setTextSize(20f);
                        contentArea.addView(content);

                        setTextView(view1, R.id.title, getResources().getString(R.string.alert));

                        AlertDialog dialog = new AlertDialog.Builder(getContext()).setView(view1)
                                .setPositiveButton(R.string.ok, null)
                                .setOnDismissListener(new DialogInterface.OnDismissListener() {
                                    @Override
                                    public void onDismiss(DialogInterface dialogInterface) {
                                        // ?
                                        selectCarManually();
                                        showView(rootView, R.id.brand_input, true);
                                    }
                                }).create();

                        dialog.show();

                        // ??
                        updateUi();
                    } else {
                        // ??
                        Log.d("DFCarChecker", "???" + result);
                        Toast.makeText(getContext(), result, Toast.LENGTH_LONG).show();
                    }
                }
            });
    getCarSettingsByVinTask.execute();
}

From source file:com.egloos.hyunyi.musicinfo.LinkPopUp.java

private void displayArtistInfo_bk(JSONObject j) throws JSONException {
    if (imageLoader == null)
        imageLoader = ImageLoader.getInstance();
    if (!imageLoader.isInited())
        imageLoader.init(config);/*from   w w  w  . ja va  2s. c o  m*/

    Log.i("musicInfo", "LinkPopUp. displayArtistInfo " + j.toString());

    JSONObject j_artist_info = j.getJSONObject("artist");

    tArtistName.setText(j_artist_info.getString("name"));
    final JSONObject urls = j_artist_info.optJSONObject("urls");
    final JSONArray videos = j_artist_info.optJSONArray("video");
    final JSONArray images = j_artist_info.optJSONArray("images");
    final String fm_image = j.optString("fm_image");
    final JSONArray available_images = new JSONArray();
    ArrayList<String> image_urls = new ArrayList<String>();

    if (fm_image != null) {
        image_urls.add(fm_image);
    }

    Log.i("musicInfo", images.toString());

    if (images != null) {
        for (int i = 0; i < images.length(); i++) {
            JSONObject image = images.getJSONObject(i);
            int width = image.optInt("width", 0);
            int height = image.optInt("height", 0);
            String url = image.optString("url", "");
            Log.i("musicInfo", i + ": " + url);
            if ((width * height > 10000) && (width * height < 100000) && (!url.contains("userserve-ak"))) {
                //if ((width>300&&width<100)&&(height>300&&height<1000)&&(!url.contains("userserve-ak"))) {
                image_urls.add(url);
                Log.i("musicInfo", "Selected: " + url);
                //available_images.put(image);
            }
        }

        int random = (int) (Math.random() * image_urls.size());
        final String f_url = image_urls.get(random);

        //int random = (int) (Math.random() * available_images.length());
        //final JSONObject fImage = available_images.length()>0?available_images.getJSONObject(random > images.length() ? 0 : random):images.getJSONObject(0);

        Log.i("musicInfo",
                "Total image#=" + available_images.length() + " Selected image#=" + random + " " + f_url);

        imageLoader.displayImage(f_url, ArtistImage, new ImageLoadingListener() {
            @Override
            public void onLoadingStarted(String imageUri, View view) {

            }

            @Override
            public void onLoadingFailed(String imageUri, View view, FailReason failReason) {

            }

            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {

                lLinkList.removeAllViews();
                //String attr = fImage.optJSONObject("license").optString("attribution");
                //tAttribution.setText("Credit. " + ((attr == null) || (attr.contains("n/a")) ? "Unknown" : attr));
                if (urls != null) {
                    String[] jsonName = { "wikipedia_url", "mb_url", "lastfm_url", "official_url",
                            "twitter_url" };
                    for (int i = 0; i < jsonName.length; i++) {
                        if ((urls.optString(jsonName[i]) != null) && (urls.optString(jsonName[i]) != "")) {
                            Log.d("musicinfo", "Link URL: " + urls.optString(jsonName[i]));
                            TextView tv = new TextView(getApplicationContext());
                            tv.setTextSize(11);
                            tv.setPadding(16, 16, 16, 16);
                            tv.setTextColor(Color.LTGRAY);
                            tv.setTypeface(Typeface.SANS_SERIF);
                            tv.setGravity(Gravity.CENTER_VERTICAL);
                            tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                                    ViewGroup.LayoutParams.WRAP_CONTENT));

                            switch (jsonName[i]) {
                            case "official_url":
                                tv.setText("HOME.");
                                break;
                            case "wikipedia_url":
                                tv.setText("WIKI.");
                                break;
                            case "mb_url":
                                tv.setText("Music Brainz.");
                                break;
                            case "lastfm_url":
                                tv.setText("Last FM.");
                                break;
                            case "twitter_url":
                                tv.setText("Twitter.");
                                break;
                            }

                            try {
                                tv.setTag(urls.getString(jsonName[i]));
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                            tv.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    Intent intent = new Intent();
                                    intent.setAction(Intent.ACTION_VIEW);
                                    intent.addCategory(Intent.CATEGORY_BROWSABLE);
                                    intent.setData(Uri.parse((String) v.getTag()));
                                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                    startActivity(intent);
                                    Toast.makeText(getApplicationContext(), "Open the Link...",
                                            Toast.LENGTH_SHORT).show();
                                    //finish();
                                }
                            });
                            lLinkList.addView(tv);
                        }
                    }
                } else {
                    TextView tv = new TextView(getApplicationContext());
                    tv.setTextSize(11);
                    tv.setPadding(16, 16, 16, 16);
                    tv.setTextColor(Color.LTGRAY);
                    tv.setTypeface(Typeface.SANS_SERIF);
                    tv.setGravity(Gravity.CENTER_VERTICAL);
                    tv.setText("Sorry, No Link Here...");
                    lLinkList.addView(tv);
                }

                if (videos != null) {
                    jVideoArray = videos;
                    mAdapter = new StaggeredViewAdapter(getApplicationContext(),
                            android.R.layout.simple_list_item_1, generateImageData(videos));
                    //if (mData == null) {
                    mData = generateImageData(videos);
                    //}

                    //mAdapter.clear();

                    for (JSONObject data : mData) {
                        mAdapter.add(data);
                    }
                    mGridView.setAdapter(mAdapter);
                } else {

                }

                adjBottomColor(((ImageView) view).getDrawable());
            }

            @Override
            public void onLoadingCancelled(String imageUri, View view) {

            }
        });
    }

}

From source file:com.google.sample.beaconservice.ManageBeaconFragment.java

private LinearLayout makeAttachmentTableHeader() {
    LinearLayout headerRow = new LinearLayout(getActivity());
    headerRow.addView(makeTextView("Namespace"));
    headerRow.addView(makeTextView("Type"));
    headerRow.addView(makeTextView("Data"));

    // Attachment rows will have four elements, so insert a fake one here with the same
    // layout weight as the delete button.
    TextView dummyView = new TextView(getActivity());
    dummyView.setLayoutParams(BUTTON_COL_LAYOUT);
    headerRow.addView(dummyView);//from  ww  w .j a v a2  s .  co m

    return headerRow;
}

From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java

@Override
protected void onResume() {
    super.onResume();

    try {//from  w  w  w.  j  av a  2s .  c o  m
        this.mWakeLock.acquire(); // ?? ?

        killOnError(); // ?  ?
        mixContext.mixView = this; // ??  
        dataView.doStart(); // ?? 
        dataView.clearEvents(); // ? ?

        double angleX, angleY; // ? x, y

        /*? ?  ? */
        angleX = Math.toRadians(-90);
        m1.set(1f, 0f, 0f, 0f, (float) Math.cos(angleX), (float) -Math.sin(angleX), 0f,
                (float) Math.sin(angleX), (float) Math.cos(angleX));

        angleX = Math.toRadians(-90);
        angleY = Math.toRadians(-90);
        m2.set(1f, 0f, 0f, 0f, (float) Math.cos(angleX), (float) -Math.sin(angleX), 0f,
                (float) Math.sin(angleX), (float) Math.cos(angleX));
        m3.set((float) Math.cos(angleY), 0f, (float) Math.sin(angleY), 0f, 1f, 0f, (float) -Math.sin(angleY),
                0f, (float) Math.cos(angleY));

        m4.toIdentity();

        for (int i = 0; i < histR.length; i++) {
            histR[i] = new Matrix();
        }
        /*   */

        //  ? 
        sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);

        // ?  ?
        // ?? 
        sensors = sensorMgr.getSensorList(Sensor.TYPE_ACCELEROMETER);
        if (sensors.size() > 0) {
            sensorGrav = sensors.get(0);
        }

        // ? 
        sensors = sensorMgr.getSensorList(Sensor.TYPE_MAGNETIC_FIELD);
        if (sensors.size() > 0) {
            sensorMag = sensors.get(0);
        }
        //// TODO: 2016-06-01
        if (sensors.size() > 0) {
            sensors = sensorMgr_ori.getSensorList(Sensor.TYPE_ORIENTATION);
            orientationSensor = sensors.get(0);
        }
        //  ??  ? ? ? ?
        sensorMgr.registerListener(this, sensorGrav, SENSOR_DELAY_GAME);
        sensorMgr.registerListener(this, sensorMag, SENSOR_DELAY_GAME);

        if (orientationSensor != null) {
            sensorMgr_ori.registerListener(this, orientationSensor, sensorMgr_ori.SENSOR_DELAY_GAME);
        }

        try {
            // ?? (Criteria)
            // http://developer.android.com/reference/android/location/Criteria.html
            Criteria c = new Criteria();

            // ? 
            c.setAccuracy(Criteria.ACCURACY_FINE);
            //c.setBearingRequired(true);

            // ?  
            locationMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            // ?? ? ?  ? . 2 , 3 
            locationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 4, this);

            // ?? ? ,   
            String bestP = locationMgr.getBestProvider(c, true);
            isGpsEnabled = locationMgr.isProviderEnabled(bestP);

            // gps, ? ? ?   
            Location hardFix = new Location("reverseGeocoded");

            try {
                //  ? gps, ??     
                Location gps = locationMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                Location network = locationMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

                //  ?  ?   
                //  gps > ? > 
                if (gps != null)
                    mixContext.curLoc = gps;
                else if (network != null)
                    mixContext.curLoc = network;
                else
                    mixContext.curLoc = hardFix;

            } catch (Exception ex2) { //  ? 
                ex2.printStackTrace(); //  
                mixContext.curLoc = hardFix; //   
            }
            // ? ?  ??  
            mixContext.setLocationAtLastDownload(mixContext.curLoc);

            // ?? .   ?   
            GeomagneticField gmf = new GeomagneticField((float) mixContext.curLoc.getLatitude(),
                    (float) mixContext.curLoc.getLongitude(), (float) mixContext.curLoc.getAltitude(),
                    System.currentTimeMillis());

            // ??   
            angleY = Math.toRadians(-gmf.getDeclination());
            m4.set((float) Math.cos(angleY), 0f, (float) Math.sin(angleY), 0f, 1f, 0f,
                    (float) -Math.sin(angleY), 0f, (float) Math.cos(angleY));
            mixContext.declination = gmf.getDeclination();
        } catch (Exception ex) {
            Log.d("mixare", "GPS Initialize Error", ex); //  ? 
        }
        //  ? 
        downloadThread = new Thread(mixContext.downloadManager);
        downloadThread.start();

    } catch (Exception ex) {
        doError(ex); // ? 

        try {
            // ???  
            if (sensorMgr != null) {
                sensorMgr.unregisterListener(this, sensorGrav);
                sensorMgr.unregisterListener(this, sensorMag);
                sensorMgr = null;
            }
            //  ??   
            if (locationMgr != null) {
                locationMgr.removeUpdates(this);
                locationMgr = null;
            }
            // ??  ?? 
            if (mixContext != null) {
                if (mixContext.downloadManager != null)
                    mixContext.downloadManager.stop();
            }
        } catch (Exception ignore) {
        }
    }

    //  ?? 
    // ??   ? ( ?? ) ?    
    if (dataView.isFrozen() && searchNotificationTxt == null) {
        searchNotificationTxt = new TextView(this);
        searchNotificationTxt.setWidth(dWindow.getWidth());
        searchNotificationTxt.setPadding(10, 2, 0, 0);
        searchNotificationTxt.setBackgroundColor(Color.DKGRAY);
        searchNotificationTxt.setTextColor(Color.WHITE);

        searchNotificationTxt.setOnTouchListener(this);
        addContentView(searchNotificationTxt,
                new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    } else if (!dataView.isFrozen() && searchNotificationTxt != null) {
        searchNotificationTxt.setVisibility(View.GONE);
        searchNotificationTxt = null;
    }
}

From source file:org.hfoss.posit.android.functionplugin.reminder.SetReminder.java

/**
 * Called from FindActivity.onActivityResult(). Used to 
 * update the Find's View, specifically the date, lat, long,
 * and alarm icon fields.//from w  ww. ja  v a 2 s  . c  o  m
 * 
 * @param context, the calling Activity
 * @param find, the current Find
 * @param view, the FindActivity's content view
 * @param intent, the Intent that is passed to the menu activity
 */
public void onActivityResultCallback(Context context, Find find, View view, Intent intent) {
    Log.i(TAG, "onActivityResultCallbac");
    // Intent is NOT null, meaning it includes reminder
    // date and location information set by the user
    if (intent != null) {
        Bundle bundle = intent.getExtras();

        // Get date, longitude, and latitude
        String date = bundle.getString(Find.TIME);
        Double longitude = bundle.getDouble(Find.LONGITUDE);
        Double latitude = bundle.getDouble(Find.LATITUDE);

        TextView tv = (TextView) view.findViewById(R.id.isAdhocTextView);

        Integer is_adhoc = bundle.getInt(Find.IS_ADHOC);
        Log.i(TAG, "is_adhoc = " + is_adhoc);
        if (tv != null) {
            Log.i(TAG, "Setting isAdhocTextView to " + is_adhoc);
            tv.setText("" + is_adhoc);
        }

        // Display user specified longitude and latitude
        tv = (TextView) view.findViewById(R.id.longitudeValueTextView);
        tv.setText(String.valueOf(longitude));
        tv = (TextView) view.findViewById(R.id.latitudeValueTextView);
        tv.setText(String.valueOf(latitude));

        // Remove the old row that displays time and replace it
        // with a new row that include an alarm clock icon to
        // visually indicate this find has a reminder attached
        ViewGroup parent = (ViewGroup) view.findViewById(R.id.timeValueTextView).getParent();
        parent.removeAllViews();
        ImageView alarmIcon = new ImageView(context);
        alarmIcon.setImageResource(R.drawable.reminder_alarm);
        TableRow.LayoutParams lp1 = new TableRow.LayoutParams(30, 30);
        lp1.setMargins(0, 6, 80, 0);
        parent.addView(alarmIcon, lp1);
        TextView mCloneTimeTV = new TextView(context);
        mCloneTimeTV.setId(R.id.timeValueTextView);
        mCloneTimeTV.setText(date);
        mCloneTimeTV.setTextSize(12);
        TextView mTimeTV = (TextView) view.findViewById(R.id.timeValueTextView);
        mTimeTV = mCloneTimeTV;
        TableRow.LayoutParams lp2 = new TableRow.LayoutParams();
        lp2.setMargins(6, 6, 0, 0);
        parent.addView(mTimeTV, lp2);
    }
}

From source file:com.initialxy.cordova.themeablebrowser.ThemeableBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url/*www .j av  a  2  s.  com*/
 * @param features
 * @return
 */
public String showWebPage(final String url, final Options features) {
    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        @SuppressLint("NewApi")
        public void run() {
            // Let's create the main dialog
            dialog = new ThemeableBrowserDialog(cordova.getActivity(), android.R.style.Theme_Black_NoTitleBar,
                    features.hardwareback);
            if (!features.disableAnimation) {
                dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            }
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setThemeableBrowser(getThemeableBrowser());

            // Main container layout
            ViewGroup main = null;

            if (features.fullscreen) {
                main = new FrameLayout(cordova.getActivity());
            } else {
                main = new LinearLayout(cordova.getActivity());
                ((LinearLayout) main).setOrientation(LinearLayout.VERTICAL);
            }

            // Toolbar layout
            Toolbar toolbarDef = features.toolbar;
            FrameLayout toolbar = new FrameLayout(cordova.getActivity());
            toolbar.setBackgroundColor(hexStringToColor(
                    toolbarDef != null && toolbarDef.color != null ? toolbarDef.color : "#ffffffff"));
            toolbar.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
                    dpToPixels(toolbarDef != null ? toolbarDef.height : TOOLBAR_DEF_HEIGHT)));

            if (toolbarDef != null && (toolbarDef.image != null || toolbarDef.wwwImage != null)) {
                try {
                    Drawable background = getImage(toolbarDef.image, toolbarDef.wwwImage,
                            toolbarDef.wwwImageDensity);
                    setBackground(toolbar, background);
                } catch (Resources.NotFoundException e) {
                    emitError(ERR_LOADFAIL,
                            String.format("Image for toolbar, %s, failed to load", toolbarDef.image));
                } catch (IOException ioe) {
                    emitError(ERR_LOADFAIL,
                            String.format("Image for toolbar, %s, failed to load", toolbarDef.wwwImage));
                }
            }

            // Left Button Container layout
            LinearLayout leftButtonContainer = new LinearLayout(cordova.getActivity());
            FrameLayout.LayoutParams leftButtonContainerParams = new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            leftButtonContainerParams.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
            leftButtonContainer.setLayoutParams(leftButtonContainerParams);
            leftButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // Right Button Container layout
            LinearLayout rightButtonContainer = new LinearLayout(cordova.getActivity());
            FrameLayout.LayoutParams rightButtonContainerParams = new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            rightButtonContainerParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
            rightButtonContainer.setLayoutParams(rightButtonContainerParams);
            rightButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Back button
            final Button back = createButton(features.backButton, "back button", new View.OnClickListener() {
                public void onClick(View v) {
                    emitButtonEvent(features.backButton, inAppWebView.getUrl());

                    if (features.backButtonCanClose && !canGoBack()) {
                        closeDialog();
                    } else {
                        goBack();
                    }
                }
            });

            if (back != null) {
                back.setEnabled(features.backButtonCanClose);
            }

            // Forward button
            final Button forward = createButton(features.forwardButton, "forward button",
                    new View.OnClickListener() {
                        public void onClick(View v) {
                            emitButtonEvent(features.forwardButton, inAppWebView.getUrl());

                            goForward();
                        }
                    });

            if (forward != null) {
                forward.setEnabled(false);
            }

            // Close/Done button
            Button close = createButton(features.closeButton, "close button", new View.OnClickListener() {
                public void onClick(View v) {
                    emitButtonEvent(features.closeButton, inAppWebView.getUrl());
                    closeDialog();
                }
            });

            // Menu button
            Spinner menu = features.menu != null ? new MenuSpinner(cordova.getActivity()) : null;
            if (menu != null) {
                menu.setLayoutParams(
                        new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                menu.setContentDescription("menu button");
                setButtonImages(menu, features.menu, DISABLED_ALPHA);

                // We are not allowed to use onClickListener for Spinner, so we will use
                // onTouchListener as a fallback.
                menu.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if (event.getAction() == MotionEvent.ACTION_UP) {
                            emitButtonEvent(features.menu, inAppWebView.getUrl());
                        }
                        return false;
                    }
                });

                if (features.menu.items != null) {
                    HideSelectedAdapter<EventLabel> adapter = new HideSelectedAdapter<EventLabel>(
                            cordova.getActivity(), android.R.layout.simple_spinner_item, features.menu.items);
                    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    menu.setAdapter(adapter);
                    menu.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                            if (inAppWebView != null && i < features.menu.items.length) {
                                emitButtonEvent(features.menu.items[i], inAppWebView.getUrl(), i);
                            }
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> adapterView) {
                        }
                    });
                }
            }

            // Title
            final TextView title = features.title != null ? new TextView(cordova.getActivity()) : null;
            final TextView subtitle = features.title != null ? new TextView(cordova.getActivity()) : null;
            if (title != null) {
                FrameLayout.LayoutParams titleParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                        LayoutParams.FILL_PARENT);
                titleParams.gravity = Gravity.CENTER;
                title.setLayoutParams(titleParams);
                title.setSingleLine();
                title.setEllipsize(TextUtils.TruncateAt.END);
                title.setGravity(Gravity.CENTER | Gravity.TOP);
                title.setTextColor(
                        hexStringToColor(features.title.color != null ? features.title.color : "#000000ff"));
                title.setTypeface(title.getTypeface(), Typeface.BOLD);
                title.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8);

                FrameLayout.LayoutParams subtitleParams = new FrameLayout.LayoutParams(
                        LayoutParams.MATCH_PARENT, LayoutParams.FILL_PARENT);
                titleParams.gravity = Gravity.CENTER;
                subtitle.setLayoutParams(subtitleParams);
                subtitle.setSingleLine();
                subtitle.setEllipsize(TextUtils.TruncateAt.END);
                subtitle.setGravity(Gravity.CENTER | Gravity.BOTTOM);
                subtitle.setTextColor(hexStringToColor(
                        features.title.subColor != null ? features.title.subColor : "#000000ff"));
                subtitle.setTextSize(TypedValue.COMPLEX_UNIT_PT, 6);
                subtitle.setVisibility(View.GONE);

                if (features.title.staticText != null) {
                    title.setGravity(Gravity.CENTER);
                    title.setText(features.title.staticText);
                } else {
                    subtitle.setVisibility(View.VISIBLE);
                }
            }

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            final ViewGroup.LayoutParams inAppWebViewParams = features.fullscreen
                    ? new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
                    : new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0);
            if (!features.fullscreen) {
                ((LinearLayout.LayoutParams) inAppWebViewParams).weight = 1;
            }
            inAppWebView.setLayoutParams(inAppWebViewParams);
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new ThemeableBrowserClient(thatWebView, new PageLoadListener() {

                @Override
                public void onPageStarted(String url) {
                    if (inAppWebView != null && title != null && features.title != null
                            && features.title.staticText == null && features.title.showPageTitle
                            && features.title.loadingText != null) {
                        title.setText(features.title.loadingText);
                        subtitle.setText(url);
                    }
                }

                @Override
                public void onPageFinished(String url, boolean canGoBack, boolean canGoForward) {
                    if (inAppWebView != null && title != null && features.title != null
                            && features.title.staticText == null && features.title.showPageTitle) {
                        title.setText(inAppWebView.getTitle());
                        subtitle.setText(inAppWebView.getUrl());
                    }

                    if (back != null) {
                        back.setEnabled(canGoBack || features.backButtonCanClose);
                    }

                    if (forward != null) {
                        forward.setEnabled(canGoForward);
                    }
                }
            });
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(features.zoom);
            settings.setDisplayZoomControls(false);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null
                    || appSettings.getBoolean("ThemeableBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = cordova.getActivity().getApplicationContext()
                        .getDir("themeableBrowserDB", Context.MODE_PRIVATE).getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);

            if (features.clearcache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (features.clearsessioncache) {
                CookieManager.getInstance().removeSessionCookie();
            }

            inAppWebView.loadUrl(url);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            // Add buttons to either leftButtonsContainer or
            // rightButtonsContainer according to user's alignment
            // configuration.
            int leftContainerWidth = 0;
            int rightContainerWidth = 0;

            if (features.customButtons != null) {
                for (int i = 0; i < features.customButtons.length; i++) {
                    final BrowserButton buttonProps = features.customButtons[i];
                    final int index = i;
                    Button button = createButton(buttonProps, String.format("custom button at %d", i),
                            new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    if (inAppWebView != null) {
                                        emitButtonEvent(buttonProps, inAppWebView.getUrl(), index);
                                    }
                                }
                            });

                    if (ALIGN_RIGHT.equals(buttonProps.align)) {
                        rightButtonContainer.addView(button);
                        rightContainerWidth += button.getLayoutParams().width;
                    } else {
                        leftButtonContainer.addView(button, 0);
                        leftContainerWidth += button.getLayoutParams().width;
                    }
                }
            }

            // Back and forward buttons must be added with special ordering logic such
            // that back button is always on the left of forward button if both buttons
            // are on the same side.
            if (forward != null && features.forwardButton != null
                    && !ALIGN_RIGHT.equals(features.forwardButton.align)) {
                leftButtonContainer.addView(forward, 0);
                leftContainerWidth += forward.getLayoutParams().width;
            }

            if (back != null && features.backButton != null && ALIGN_RIGHT.equals(features.backButton.align)) {
                rightButtonContainer.addView(back);
                rightContainerWidth += back.getLayoutParams().width;
            }

            if (back != null && features.backButton != null && !ALIGN_RIGHT.equals(features.backButton.align)) {
                leftButtonContainer.addView(back, 0);
                leftContainerWidth += back.getLayoutParams().width;
            }

            if (forward != null && features.forwardButton != null
                    && ALIGN_RIGHT.equals(features.forwardButton.align)) {
                rightButtonContainer.addView(forward);
                rightContainerWidth += forward.getLayoutParams().width;
            }

            if (menu != null) {
                if (features.menu != null && ALIGN_RIGHT.equals(features.menu.align)) {
                    rightButtonContainer.addView(menu);
                    rightContainerWidth += menu.getLayoutParams().width;
                } else {
                    leftButtonContainer.addView(menu, 0);
                    leftContainerWidth += menu.getLayoutParams().width;
                }
            }

            if (close != null) {
                if (features.closeButton != null && ALIGN_RIGHT.equals(features.closeButton.align)) {
                    rightButtonContainer.addView(close);
                    rightContainerWidth += close.getLayoutParams().width;
                } else {
                    leftButtonContainer.addView(close, 0);
                    leftContainerWidth += close.getLayoutParams().width;
                }
            }

            // Add the views to our toolbar
            toolbar.addView(leftButtonContainer);
            // Don't show address bar.
            // toolbar.addView(edittext);
            toolbar.addView(rightButtonContainer);

            if (title != null) {
                int titleMargin = Math.max(leftContainerWidth, rightContainerWidth);

                FrameLayout.LayoutParams titleParams = (FrameLayout.LayoutParams) title.getLayoutParams();
                titleParams.setMargins(titleMargin, 8, titleMargin, 0);
                toolbar.addView(title);
            }

            if (subtitle != null) {
                int subtitleMargin = Math.max(leftContainerWidth, rightContainerWidth);

                FrameLayout.LayoutParams subtitleParams = (FrameLayout.LayoutParams) subtitle.getLayoutParams();
                subtitleParams.setMargins(subtitleMargin, 0, subtitleMargin, 8);
                toolbar.addView(subtitle);
            }

            if (features.fullscreen) {
                // If full screen mode, we have to add inAppWebView before adding toolbar.
                main.addView(inAppWebView);
            }

            // Don't add the toolbar if its been disabled
            if (features.location) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            if (!features.fullscreen) {
                // If not full screen, we add inAppWebView after adding toolbar.
                main.addView(inAppWebView);
            }

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
            // the goal of openhidden is to load the url and not display it
            // Show() needs to be called to cause the URL to be loaded
            if (features.hidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:cn.hbm.superwechat.adapter.MessageAdapter.java

@SuppressWarnings("ResourceType")
private void setRobotMenuMessageLayout(LinearLayout parentView, JSONArray jsonArr) {
    try {//w w w  .j a v a 2  s.  com
        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) {
                    ((ChatActivity) 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:cn.ucai.fulicenter.adapter.MessageAdapter.java

private void setRobotMenuMessageLayout(LinearLayout parentView, JSONArray jsonArr) {
    try {//w w 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) {
                    ((ChatActivity) 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.df.app.procedures.CarRecogniseLayout.java

/**
 * // w ww. j a va 2  s  .c  om
 */
private void selectCarManually() {
    if (!mCarSettings.getBrandString().equals("")) {
        View view1 = ((Activity) rootView.getContext()).getLayoutInflater().inflate(R.layout.popup_layout,
                null);
        TableLayout contentArea = (TableLayout) view1.findViewById(R.id.contentArea);
        TextView content = new TextView(view1.getContext());
        content.setText(R.string.reMatch);
        content.setTextSize(20f);
        contentArea.addView(content);

        setTextView(view1, R.id.title, getResources().getString(R.string.alert));

        AlertDialog dialog = new AlertDialog.Builder(rootView.getContext()).setView(view1)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        mHideContentCallback.hideContent();
                        showSelectCarDialog();
                    }
                }).setNegativeButton(R.string.cancel, null).create();

        dialog.show();
    } else {
        showSelectCarDialog();
    }
}

From source file:com.max2idea.android.limbo.main.LimboActivity.java

private void promptImportMachines() {
    // TODO Auto-generated method stub

    final AlertDialog alertDialog;
    alertDialog = new AlertDialog.Builder(activity).create();
    alertDialog.setTitle("Import Machines");

    RelativeLayout mLayout = new RelativeLayout(this);
    mLayout.setId(12222);//from   w  w w  .j ava  2 s  . c o m

    TextView imageNameView = new TextView(activity);
    imageNameView.setVisibility(View.VISIBLE);
    imageNameView.setId(201012010);
    imageNameView.setText(
            "Step 1: Place the machine.CSV file you export previously under \"limbo\" directory in your SD card.\n"
                    + "Step 2: WARNING: Any machine with the same name will be replaced!\n"
                    + "Step 3: Press \"OK\".\n");

    RelativeLayout.LayoutParams searchViewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    mLayout.addView(imageNameView, searchViewParams);
    alertDialog.setView(mLayout);

    final Handler handler = this.handler;

    // alertDialog.setMessage(body);
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // For each line create a Machine
            progDialog = ProgressDialog.show(activity, "Please Wait", "Importing Machines...", true);

            ImportMachines importer = new ImportMachines();
            importer.execute();
        }
    });
    alertDialog.setButton2("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

            return;
        }
    });
    alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {

            return;

        }
    });
    alertDialog.show();

}