Example usage for android.widget LinearLayout addView

List of usage examples for android.widget LinearLayout addView

Introduction

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

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:com.taobao.wuzhong.plugins.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject/* w  ww.  j a  v a 2s  . c o  m*/
 */
public String showWebPage(final String url, JSONObject options) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", true);
    }

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        public void run() {
            dialog = new Dialog(ctx.getContext(), android.R.style.Theme_Translucent_NoTitleBar);

            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT, 1.0f);
            LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT);

            LinearLayout main = new LinearLayout(ctx.getContext());
            main.setOrientation(LinearLayout.VERTICAL);

            LinearLayout toolbar = new LinearLayout(ctx.getContext());
            toolbar.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            toolbar.setOrientation(LinearLayout.HORIZONTAL);

            ImageButton back = new ImageButton(ctx.getContext());
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });
            back.setId(1);
            try {
                back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            back.setLayoutParams(backParams);

            ImageButton forward = new ImageButton(ctx.getContext());
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });
            forward.setId(2);
            try {
                forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            forward.setLayoutParams(forwardParams);

            edittext = new EditText(ctx.getContext());
            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;
                }
            });
            edittext.setId(3);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setLayoutParams(editParams);

            ImageButton close = new ImageButton(ctx.getContext());
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });
            close.setId(4);
            try {
                close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            close.setLayoutParams(closeParams);

            webview = new WebView(ctx.getContext());
            webview.setWebChromeClient(new WebChromeClient());
            WebViewClient client = new ChildBrowserClient(edittext);
            webview.setWebViewClient(client);
            WebSettings settings = webview.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginsEnabled(true);
            settings.setDomStorageEnabled(true);
            webview.loadUrl(url);
            webview.setId(5);
            webview.setInitialScale(0);
            webview.setLayoutParams(wvParams);
            webview.requestFocus();
            webview.requestFocusFromTouch();

            toolbar.addView(back);
            toolbar.addView(forward);
            toolbar.addView(edittext);
            toolbar.addView(close);

            if (getShowLocationBar()) {
                main.addView(toolbar);
            }
            main.addView(webview);

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

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            InputStream input = ctx.getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.ctx.runOnUiThread(runnable);
    return "";
}

From source file:com.google.android.gcm.demo.ui.NetworkSchedulerFragment.java

@Override
public void refresh() {
    FrameLayout tasksView = (FrameLayout) getActivity().findViewById(R.id.scheduler_tasks);
    // the view might have been destroyed, in which case we don't do anything
    if (tasksView != null) {
        float density = getActivity().getResources().getDisplayMetrics().density;
        SimpleArrayMap<String, TaskTracker> tasks = mTasks.getTasks();
        LinearLayout tasksList = new LinearLayout(getActivity());
        tasksList.setOrientation(LinearLayout.VERTICAL);
        for (int i = 0; i < tasks.size(); i++) {
            final TaskTracker task = tasks.valueAt(i);
            CardView taskCard = (CardView) getActivity().getLayoutInflater().inflate(R.layout.widget_task,
                    tasksList, false);//ww w.j a v  a 2 s  . c  om
            ImageView taskIcon = (ImageView) taskCard.findViewById(R.id.task_icon);
            taskIcon.setImageResource(R.drawable.check_circle_grey600);
            taskIcon.setPadding(0, 0, (int) (8 * density), 0);
            TextView taskLabel = (TextView) taskCard.findViewById(R.id.task_title);
            TextView taskParams = (TextView) taskCard.findViewById(R.id.task_params);
            if (task.period == 0) {
                taskLabel.setText(getString(R.string.scheduler_oneoff, task.tag));
                taskParams.setText(getString(R.string.scheduler_oneoff_params, task.windowStartElapsedSecs,
                        task.windowStopElapsedSecs));
            } else {
                taskLabel.setText(getString(R.string.scheduler_periodic, task.tag));
                taskParams.setText(getString(R.string.scheduler_periodic_params, task.period, task.flex));
            }
            TextView taskCreatedAt = (TextView) taskCard.findViewById(R.id.task_created_at);
            taskCreatedAt.setText(getString(R.string.scheduler_secs_ago, DateUtils
                    .formatElapsedTime(SystemClock.elapsedRealtime() / 1000 - task.createdAtElapsedSecs)));
            TextView lastExecuted = (TextView) taskCard.findViewById(R.id.task_last_exec);
            if (task.executionTimes.isEmpty()) {
                lastExecuted.setText(getString(R.string.scheduler_na));
            } else {
                long lastExecTime = task.executionTimes.get(task.executionTimes.size() - 1);
                lastExecuted.setText(getString(R.string.scheduler_secs_ago,
                        DateUtils.formatElapsedTime(SystemClock.elapsedRealtime() / 1000 - lastExecTime)));
            }
            TextView state = (TextView) taskCard.findViewById(R.id.task_state);
            if (task.isCancelled()) {
                state.setText(getString(R.string.scheduler_cancelled));
            } else if (task.isExecuted()) {
                state.setText(getString(R.string.scheduler_executed));
            } else {
                state.setText(getString(R.string.scheduler_pending));
            }
            Button cancel = (Button) taskCard.findViewById(R.id.task_cancel);
            cancel.setVisibility(View.VISIBLE);
            cancel.setText(R.string.scheduler_cancel);
            Button delete = (Button) taskCard.findViewById(R.id.task_delete);
            delete.setVisibility(View.VISIBLE);
            delete.setText(R.string.scheduler_delete);
            if (!task.isCancelled() && (!task.isExecuted() || task.period != 0)) {
                cancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        cancelTask(task.tag);
                        refresh();
                    }
                });
                cancel.setEnabled(true);
                delete.setEnabled(false);
            } else {
                cancel.setEnabled(false);
                delete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        mTasks.deleteTask(task.tag);
                        refresh();
                    }
                });
                delete.setEnabled(true);
            }
            tasksList.addView(taskCard);
        }
        tasksView.removeAllViews();
        tasksView.addView(tasksList);
    }
}

From source file:com.xplink.android.carchecklist.CarCheckListActivity.java

/** Called when the activity is first created. */
@Override/*from www . jav a 2 s  . c  o  m*/
public void onCreate(Bundle savedInstanceState) { // end 480
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // deleteAllData();
    // ************************************************************************************
    listValue = restoreCheckList();
    if (listValue != null) {
        SharedPreferences restoreShared = getSharedPreferences("mysettings", Context.MODE_PRIVATE);
        Editor edit = restoreShared.edit();

        Map<String, Boolean> mapList = listValue.get(0);
        Map<String, Integer> mapSetting = listValue.get(1);
        int countChecknum = 0;
        int numPowerChecked = 0;
        int numEngineChecked = 0;
        int numExteriorChecked = 0;
        int numInteriorChecked = 0;
        int numDocumentChecked = 0;

        for (Map.Entry<String, Boolean> entry : mapList.entrySet()) {

            String[] tmp = entry.getKey().split("\\_");
            Log.i("checkkeyvalue", tmp[0] + " : " + tmp[1]);
            String key = tmp[0];

            if ("inside".equals(key)) {
                if (entry.getValue()) {
                    getTotalInterior(true);
                    numInteriorChecked++;
                    Log.i("checkbox", "numInteriorChecked : " + numInteriorChecked);
                }
            } else if ("power".equals(key)) {
                if (entry.getValue()) {
                    getTotalPower(true);
                    numPowerChecked++;
                    Log.i("checkbox", "numPowerChecked : " + numPowerChecked);
                }
            } else if ("engine".equals(key)) {
                if (entry.getValue()) {
                    getTotalEngine(true);
                    numEngineChecked++;
                    Log.i("checkbox", "numEngineChecked : " + numEngineChecked);
                }
            } else if ("outside".equals(key)) {
                if (entry.getValue()) {
                    getTotalExterior(true);
                    numExteriorChecked++;
                    Log.i("checkbox", "numExteriorChecked : " + numExteriorChecked);
                }
            } else if ("doc".equals(key)) {
                if (entry.getValue()) {
                    getTotalDocument(true);
                    numDocumentChecked++;
                    Log.i("checkbox", "numDocumentChecked : " + numDocumentChecked);
                }
            }
            edit.putBoolean(entry.getKey(), entry.getValue());
            // println(entry.getKey() + " : " + entry.getValue());
        }
        Checknum = countChecknum;

        edit.putInt("CheckPowerTotal", numPowerChecked);
        edit.putInt("CheckEngineTotal", numEngineChecked);
        edit.putInt("CheckExteriorTotal", numExteriorChecked);
        edit.putInt("CheckInteriorTotal", numInteriorChecked);
        edit.putInt("CheckDocumentTotal", numDocumentChecked);

        edit.commit();

        CheckPowerTotal = restoreShared.getInt("CheckPowerTotal", 0);
        CheckEngineTotal = restoreShared.getInt("CheckEngineTotal", 0);
        CheckExteriorTotal = restoreShared.getInt("CheckExteriorTotal", 0);
        CheckInteriorTotal = restoreShared.getInt("CheckInteriorTotal", 0);
        CheckDocumentTotal = restoreShared.getInt("CheckDocumentTotal", 0);

        Log.i("checklist", "in listValue - numPowerChecked : " + numPowerChecked);
        Log.i("checklist", "numEngineChecked : " + numEngineChecked);
        Log.i("checklist", "numExteriorChecked : " + numExteriorChecked);
        Log.i("checklist", "numInteriorChecked : " + numInteriorChecked);
        Log.i("checklist", "numDocumentChecked : " + numDocumentChecked);

        Log.i("checklist", "CheckPowerTotal : " + CheckPowerTotal);
        Log.i("checklist", "CheckEngineTotal : " + CheckEngineTotal);
        Log.i("checklist", "CheckExteriorTotal : " + CheckExteriorTotal);
        Log.i("checklist", "CheckInteriorTotal : " + CheckInteriorTotal);
        Log.i("checklist", "CheckDocumentTotal : " + CheckDocumentTotal);

        //edit.commit();
        for (Map.Entry<String, Integer> entry : mapSetting.entrySet()) {

            if ("interior".equals(entry.getKey())) {
                edit.putInt("Interiorbar", entry.getValue());
            } else if ("power".equals(entry.getKey())) {
                edit.putInt("Powerbar", entry.getValue());
            } else if ("engine".equals(entry.getKey())) {
                edit.putInt("Enginebar", entry.getValue());
            } else if ("exterior".equals(entry.getKey())) {
                edit.putInt("Exteriorbar", entry.getValue());
            } else {
                edit.putInt("Documentbar", entry.getValue());
            }
            // Log.i("checkSettingsName", "checkSettingsName : " +
            // entry.getKey());
        }
        edit.commit();

        /*
         * ProgressBar PowerProgress, EngineProgress, ExteriorProgress,
         * InteriorProgress, DocumentProgress, RatioProgress; TextView
         * percenpower, percenengine, percenexterior, perceninterior,
         * percendocument, Ratiotext;
         */
    }
    // ************************************************************************************
    // isSaveCheckBox();
    store = new Bundle();
    db = new DBCarCheckList(this);

    intent = new Intent(getApplicationContext(), RecordActivity.class);

    // getSettingShared();

    // Log.i("dbcarchecklist", "create object DBCarCheckList");

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);

    float height = metrics.heightPixels;
    float width = metrics.widthPixels;

    Log.d("height", "" + height);
    Log.d("width", "" + width);

    int left195 = (int) ((width / 100) * 15.3);
    int left200 = (int) ((width / 100) * 16.25);
    int leftt200 = (int) ((width / 100) * 17);
    int left230 = (int) ((width / 100) * 18);
    int left475 = (int) ((width / 100) * 37.1);
    int left480 = (int) ((width / 100) * 38);
    int left495 = (int) ((width / 100) * 38.7);
    int left500 = (int) ((width / 100) * 40.5);
    int left510 = (int) ((width / 100) * 39.7);
    int left530 = (int) ((width / 100) * 41.2);
    int left865 = (int) ((width / 100) * 67.6);
    int left870 = (int) ((width / 100) * 69.5);
    int leftt870 = (int) ((width / 100) * 68);
    int leftt900 = (int) ((width / 100) * 70);
    int left950 = (int) ((width / 100) * 75);
    int left1150 = (int) ((width / 100) * 93);
    int left1180 = (int) ((width / 100) * 92);

    int top10 = (int) ((height / 100) * 3);
    int top20 = (int) ((height / 100) * 6.5);
    int top40 = (int) ((height / 100) * 5);
    int top95 = (int) ((height / 100) * 12);
    int top100 = (int) ((height / 100) * 12.5);
    int top110 = (int) ((height / 100) * 16.5);
    int top130 = (int) ((height / 100) * 19);
    int top135 = (int) ((height / 100) * 17.5);
    int top225 = (int) ((height / 100) * 28.8);
    int top390 = (int) ((height / 100) * 53);
    int top410 = (int) ((height / 100) * 51.5);
    int top480 = (int) ((height / 100) * 64.5);
    int top500 = (int) ((height / 100) * 63);
    int top505 = (int) ((height / 100) * 63.8);
    int top595 = (int) ((height / 100) * 75);
    int top610 = (int) ((height / 100) * 76);

    Intent intent = getIntent();
    PercenPower = intent.getIntExtra("power", PercenPower);
    PercenEngine = intent.getIntExtra("engine", PercenEngine);
    PercenExterior = intent.getIntExtra("exterior", PercenExterior);
    PercenInterior = intent.getIntExtra("interior", PercenInterior);
    PercenDocument = intent.getIntExtra("document", PercenDocument);

    // follow : get data from shared preferences
    /*
     * SharedPreferences memo = getSharedPreferences("mysettings",
     * Context.MODE_PRIVATE); PercenPower = memo.getInt("PercenPower", 0);
     * PercenEngine = memo.getInt("PercenEngine", 0); PercenExterior =
     * memo.getInt("PercenExterior", 0); PercenInterior =
     * memo.getInt("PercenInterior", 0); PercenDocument =
     * memo.getInt("PercenDocument", 0);
     */

    CheckPowerTotal = intent.getIntExtra("numpower", CheckPowerTotal);
    CheckEngineTotal = intent.getIntExtra("numengine", CheckEngineTotal);
    CheckExteriorTotal = intent.getIntExtra("numexterior", CheckExteriorTotal);
    CheckInteriorTotal = intent.getIntExtra("numinterior", CheckInteriorTotal);
    CheckDocumentTotal = intent.getIntExtra("numdocument", CheckDocumentTotal);

    // Log.d("percen", "" + PercenPower);

    type = Typeface.createFromAsset(getAssets(), "Circular.ttf");

    MyCustomPanel view = new MyCustomPanel(this);

    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(1200, 800);
    params.width = 1200;
    params.height = 800;

    addContentView(view, params);

    RelativeLayout.LayoutParams imgpower = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    imgpower.setMargins(left480, top20, 0, 0);
    RelativeLayout.LayoutParams bdpower = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    bdpower.setMargins(left475, top40, 0, 0);
    RelativeLayout.LayoutParams txtpower = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    txtpower.setMargins(left510, top135, 0, 0);

    ImageView borderpower = (ImageView) findViewById(R.id.powerborder);
    borderpower.setLayoutParams(bdpower);
    percenpower = (TextView) findViewById(R.id.percenpower);
    percenpower.setLayoutParams(txtpower);
    percenpower.setTypeface(type);
    percenpower.setText("" + PercenPower + "%");
    PowerProgress = (ProgressBar) findViewById(R.id.PowerProgressbar);
    PowerProgress.setMax(100);
    PowerProgress.setProgress(PercenPower);
    headpower = (ImageView) findViewById(R.id.headpower);
    btnPower = (ImageButton) findViewById(R.id.battery_button);
    btnPower.setLayoutParams(imgpower);
    btnPower.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            // startAnimation
            SlidePowerLayout();
        }
    });

    RelativeLayout.LayoutParams imgengine = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    imgengine.setMargins(left200, top110, 0, 0);
    RelativeLayout.LayoutParams bdengine = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    bdengine.setMargins(left195, top110, 0, 0);
    RelativeLayout.LayoutParams txtengine = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    txtengine.setMargins(left230, top225, 0, 0);

    ImageView borderengine = (ImageView) findViewById(R.id.engineborder);
    borderengine.setLayoutParams(bdengine);
    percenengine = (TextView) findViewById(R.id.percenengine);
    percenengine.setLayoutParams(txtengine);
    percenengine.setTypeface(type);
    percenengine.setText("" + PercenEngine + "%");
    EngineProgress = (ProgressBar) findViewById(R.id.EngineProgressbar);
    EngineProgress.setMax(100);
    EngineProgress.setProgress(PercenEngine);
    headengine = (ImageView) findViewById(R.id.headengine);
    btnEngine = (ImageButton) findViewById(R.id.engine_button);
    btnEngine.setLayoutParams(imgengine);
    btnEngine.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            // startAnimation
            SlideEngineLayout();
        }
    });

    RelativeLayout.LayoutParams imgexterior = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    imgexterior.setMargins(leftt200, top390, 0, 0);
    RelativeLayout.LayoutParams bdexterior = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    bdexterior.setMargins(left195, top410, 0, 0);
    RelativeLayout.LayoutParams txtexterior = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    txtexterior.setMargins(left230, top505, 0, 0);

    ImageView borderexterior = (ImageView) findViewById(R.id.exteriorborder);
    borderexterior.setLayoutParams(bdexterior);
    percenexterior = (TextView) findViewById(R.id.percenexterior);
    percenexterior.setLayoutParams(txtexterior);
    percenexterior.setTypeface(type);
    percenexterior.setText("" + PercenExterior + "%");
    ExteriorProgress = (ProgressBar) findViewById(R.id.ExteriorProgressbar);
    ExteriorProgress.setMax(100);
    ExteriorProgress.setProgress(PercenExterior);
    headexterior = (ImageView) findViewById(R.id.headexterior);
    btnExterior = (ImageButton) findViewById(R.id.outside_button);
    btnExterior.setLayoutParams(imgexterior);

    btnExterior.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            // startAnimation
            SlideExteriorLayout();
        }
    });

    RelativeLayout.LayoutParams imginterior = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    imginterior.setMargins(left500, top480, 0, 0);
    RelativeLayout.LayoutParams bdinterior = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    bdinterior.setMargins(left495, top500, 0, 0);
    RelativeLayout.LayoutParams txtinterior = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    txtinterior.setMargins(left530, top595, 0, 0);

    ImageView borderinterior = (ImageView) findViewById(R.id.interiorborder);
    borderinterior.setLayoutParams(bdinterior);
    perceninterior = (TextView) findViewById(R.id.perceninterior);
    perceninterior.setLayoutParams(txtinterior);
    perceninterior.setTypeface(type);
    perceninterior.setText("" + PercenInterior + "%");
    InteriorProgress = (ProgressBar) findViewById(R.id.InteriorProgressbar);
    InteriorProgress.setMax(100);
    InteriorProgress.setProgress(PercenInterior);
    headinterior = (ImageView) findViewById(R.id.headinterior);
    btnInterior = (ImageButton) findViewById(R.id.inside_button);
    btnInterior.setLayoutParams(imginterior);
    btnInterior.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            // startAnimation
            SlideInteriorLayout();
        }
    });

    RelativeLayout.LayoutParams imgdocument = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    imgdocument.setMargins(left870, top480, 0, 0);
    RelativeLayout.LayoutParams bddocument = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    bddocument.setMargins(left865, top500, 0, 0);
    RelativeLayout.LayoutParams txtdocument = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    txtdocument.setMargins(leftt900, top595, 0, 0);
    RelativeLayout.LayoutParams progdocument = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    progdocument.setMargins(leftt870, top610, 0, 0);

    ImageView borderdocument = (ImageView) findViewById(R.id.documentborder);
    borderdocument.setLayoutParams(bddocument);
    percendocument = (TextView) findViewById(R.id.percendocument);
    percendocument.setLayoutParams(txtdocument);
    percendocument.setTypeface(type);
    percendocument.setText("" + PercenDocument + "%");
    DocumentProgress = (ProgressBar) findViewById(R.id.DocumentProgressbar);
    DocumentProgress.setMax(100);
    DocumentProgress.setProgress(PercenDocument);
    headdocument = (ImageView) findViewById(R.id.headdocument);
    btnDocument = (ImageButton) findViewById(R.id.document_button);
    btnDocument.setLayoutParams(imgdocument);
    btnDocument.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            SlideDocumentLayout();

        }
    });

    RelativeLayout.LayoutParams imgsetting = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    imgsetting.setMargins(left1180, top10, 0, 0);
    RelativeLayout.LayoutParams txtratio = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    txtratio.setMargins(left950, top95, 0, 0);
    RelativeLayout.LayoutParams ratioprog = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    ratioprog.setMargins(left1150, top100, 0, 0);

    Ratiotext = (TextView) findViewById(R.id.ratiotext);
    Ratiotext.setLayoutParams(txtratio);
    RatioProgress = (ProgressBar) findViewById(R.id.ratio);
    RatioProgress.setLayoutParams(ratioprog);
    RatioProgress.setMax(100);
    headsetting = (ImageView) findViewById(R.id.headsetting);
    btnSetting = (ImageButton) findViewById(R.id.setting_button);
    btnSetting.setLayoutParams(imgsetting);
    btnSetting.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            SlideSettingLayout();

        }
    });

    // addMob
    LinearLayout layout = (LinearLayout) findViewById(R.id.admob);
    adView = new AdView(getApplicationContext());
    adView.setAdSize(AdSize.LEADERBOARD);
    adView.setAdUnitId(admonId);
    //adView.setAdUnitId("C17E5F3A146EC7E805175C72634D8098");
    // Add the adView to it
    layout.addView(adView);
    // Initiate a generic request to load it with an ad
    AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
    adRequestBuilder.addTestDevice("C17E5F3A146EC7E805175C72634D8098");
    // adRequestBuilder.addTestDevice("9F5DF3C9768A51CB506B68902F766B40");
    adView.loadAd(adRequestBuilder.build());
    // adView.loadAd(new AdRequest.Builder().build());
    SharedPreferences shared = getSharedPreferences("mysettings", Context.MODE_PRIVATE);
    // Log.i("checksum",
    // "before call CheckRatio : " + shared.getInt("checknum", 0));
    CheckRatio();
    // Log.i("checklist", "checking percenpower : " +
    // shared.getInt("PercenPower", -1));

    // restoreProgressCheckList();
}

From source file:com.android.launcher3.Utilities.java

public static void showEditMode(final Activity activity, final ShortcutInfo shortcutInfo) {
    ContextThemeWrapper theme;/*from  w  w  w .j  av  a  2s  .co  m*/
    final Set<String> setString = new HashSet<String>();
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
        theme = new ContextThemeWrapper(activity, R.style.AlertDialogCustomAPI23);
    } else {
        theme = new ContextThemeWrapper(activity, R.style.AlertDialogCustom);
    }

    AlertDialog.Builder alert = new AlertDialog.Builder(theme);
    LinearLayout layout = new LinearLayout(activity.getApplicationContext());
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setPadding(100, 0, 100, 100);

    final ImageView img = new ImageView(activity.getApplicationContext());
    Drawable icon = null;
    if (Utilities.getAppIconPackageNamePrefEnabled(activity.getApplicationContext()) != null) {
        if (Utilities.getAppIconPackageNamePrefEnabled(activity.getApplicationContext()).equals("NULL")) {
            if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(),
                    shortcutInfo.getTargetComponent().getPackageName()) != null) {
                icon = new BitmapDrawable(activity.getResources(),
                        Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName()));
            } else {
                icon = new BitmapDrawable(activity.getResources(),
                        shortcutInfo.getIcon(new IconCache(activity.getApplicationContext(),
                                Launcher.getLauncher(activity).getDeviceProfile().inv)));
            }
        } else {

            if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(),
                    shortcutInfo.getTargetComponent().getPackageName()) != null) {
                icon = new BitmapDrawable(activity.getResources(),
                        Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName()));
            } else {
                icon = new BitmapDrawable(activity.getResources(),
                        Launcher.getIcons().get(shortcutInfo.getTargetComponent().getPackageName()));
            }
        }
    } else {

        if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(),
                shortcutInfo.getTargetComponent().getPackageName()) != null) {
            icon = new BitmapDrawable(activity.getResources(),
                    Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName()));
        } else {
            icon = new BitmapDrawable(activity.getResources(),
                    shortcutInfo.getIcon(new IconCache(activity.getApplicationContext(),
                            Launcher.getLauncher(Launcher.getLauncherActivity()).getDeviceProfile().inv)));
        }
    }
    img.setImageDrawable(icon);
    img.setPadding(0, 100, 0, 0);

    img.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showIconPack(activity, shortcutInfo);
        }
    });

    final EditText titleBox = new EditText(activity.getApplicationContext());

    try {
        Set<String> title = new HashSet<>(
                Utilities.getTitle(activity, shortcutInfo.getTargetComponent().getPackageName()));
        for (Iterator<String> it = title.iterator(); it.hasNext();) {
            String titleApp = it.next();
            titleBox.setText(titleApp);
        }
    } catch (Exception e) {
        titleBox.setText(shortcutInfo.title);
    }

    titleBox.getBackground().mutate().setColorFilter(
            ContextCompat.getColor(activity.getApplicationContext(), R.color.colorPrimary),
            PorterDuff.Mode.SRC_ATOP);

    layout.addView(img);
    layout.addView(titleBox);

    alert.setTitle(activity.getApplicationContext().getResources().getString(R.string.edit_label));
    alert.setView(layout);

    alert.setPositiveButton(activity.getApplicationContext().getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    for (ItemInfo itemInfo : AllAppsList.data) {
                        if (shortcutInfo.getTargetComponent().getPackageName()
                                .equals(itemInfo.getTargetComponent().getPackageName())) {
                            setString.add(titleBox.getText().toString());
                            getPrefs(activity.getApplicationContext()).edit()
                                    .putStringSet(itemInfo.getTargetComponent().getPackageName(), setString)
                                    .apply();
                            Launcher.getShortcutsCreation().clearAllLayout();
                            applyChange(activity);
                        }
                    }
                }
            });

    alert.setNegativeButton(activity.getApplicationContext().getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    Launcher.getShortcutsCreation().clearAllLayout();
                }
            });
    alert.show();
}

From source file:reportsas.com.formulapp.Formulario.java

public LinearLayout obtenerLayout(LayoutInflater infla, Pregunta preg) {
    int id;//w  ww. j a va  2 s  . co m
    int tipo_pregunta = preg.getTipoPregunta();
    LinearLayout pregunta;
    TextView textView;
    TextView textAyuda;
    switch (tipo_pregunta) {
    case 1:
        id = R.layout.pregunta_texto;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloPregunta);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        break;
    case 2:
        id = R.layout.pregunta_multitexto;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.mtxtTritulo);
        textAyuda = (TextView) pregunta.findViewById(R.id.mtxtAyuda);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());

        break;
    case 3:
        id = R.layout.pregunta_seleccion;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloSeleccion);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_seleccion);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        RadioGroup rg = (RadioGroup) pregunta.findViewById(R.id.opcionesUnica);
        ArrayList<OpcionForm> opciones = preg.getOpciones();
        final ArrayList<RadioButton> rb = new ArrayList<RadioButton>();

        for (int i = 0; i < opciones.size(); i++) {
            OpcionForm opcion = opciones.get(i);
            rb.add(new RadioButton(this));
            rg.addView(rb.get(i));
            rb.get(i).setText(opcion.getEtInicial());

        }
        final TextView respt = (TextView) pregunta.findViewById(R.id.respuestaGruop);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                int radioButtonID = group.getCheckedRadioButtonId();
                RadioButton radioButton = (RadioButton) group.findViewById(radioButtonID);
                respt.setText(radioButton.getText());
            }
        });

        break;
    case 4:
        id = R.layout.pregunta_multiple;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloMultiple);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_mltiple);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        ArrayList<OpcionForm> opciones2 = preg.getOpciones();
        final EditText ediOtros = new EditText(this);
        ArrayList<CheckBox> cb = new ArrayList<CheckBox>();

        for (int i = 0; i < opciones2.size(); i++) {
            OpcionForm opcion = opciones2.get(i);
            cb.add(new CheckBox(this));
            pregunta.addView(cb.get(i));
            cb.get(i).setText(opcion.getEtInicial());
            if (opcion.getEditble().equals("S")) {

                ediOtros.setEnabled(false);
                ediOtros.setId(R.id.edtTexto);
                pregunta.addView(ediOtros);
                cb.get(i).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked) {
                            ediOtros.setEnabled(true);
                        } else {
                            ediOtros.setText("");
                            ediOtros.setEnabled(false);
                        }
                    }
                });
            }

        }
        TextView spacio = new TextView(this);
        spacio.setText("        ");
        spacio.setVisibility(View.INVISIBLE);
        pregunta.addView(spacio);
        break;
    case 5:
        id = R.layout.pregunta_escala;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloEscala);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_escala);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());

        TextView etInicial = (TextView) pregunta.findViewById(R.id.etInicial);
        TextView etFinal = (TextView) pregunta.findViewById(R.id.etFinal);
        OpcionForm opci = preg.getOpciones().get(0);
        etInicial.setText(opci.getEtInicial());
        etFinal.setText(opci.getEtFinal());
        final TextView respEscala = (TextView) pregunta.findViewById(R.id.seleEscala);
        RatingBar rtBar = (RatingBar) pregunta.findViewById(R.id.escala);
        rtBar.setNumStars(Integer.parseInt(opci.getValores().get(0).getDescripcion()));
        rtBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                respEscala.setText("" + Math.round(rating));
            }
        });

        break;
    case 6:
        id = R.layout.pregunta_lista;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloLista);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_lista);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        ArrayList<OpcionForm> opciones3 = preg.getOpciones();
        //Creamos la lista
        LinkedList<ObjetoSpinner> opcn = new LinkedList<ObjetoSpinner>();
        //La poblamos con los ejemplos
        for (int i = 0; i < opciones3.size(); i++) {
            opcn.add(new ObjetoSpinner(opciones3.get(i).getIdOpcion(), opciones3.get(i).getEtInicial()));
        }

        //Creamos el adaptador*/
        Spinner listad = (Spinner) pregunta.findViewById(R.id.opcionesListado);
        ArrayAdapter<ObjetoSpinner> spinner_adapter = new ArrayAdapter<ObjetoSpinner>(this,
                android.R.layout.simple_spinner_item, opcn);
        //Aadimos el layout para el men y se lo damos al spinner
        spinner_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        listad.setAdapter(spinner_adapter);

        break;
    case 7:
        id = R.layout.pregunta_tabla;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloTabla);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_tabla);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        TableLayout tba = (TableLayout) pregunta.findViewById(R.id.tablaOpciones);
        ArrayList<OpcionForm> opciones4 = preg.getOpciones();
        ArrayList<RadioButton> radiosbotonoes = new ArrayList<RadioButton>();
        for (int i = 0; i < opciones4.size(); i++) {
            TableRow row = (TableRow) LayoutInflater.from(this).inflate(R.layout.row_pregunta_tabla, null);
            RadioGroup tg_valores = (RadioGroup) row.findViewById(R.id.valoresRow);

            final ArrayList<RadioButton> valoOpc = new ArrayList<RadioButton>();
            ArrayList<Valor> valoresT = opciones4.get(i).getValores();
            for (int k = 0; k < valoresT.size(); k++) {
                RadioButton rb_nuevo = new RadioButton(this);
                rb_nuevo.setText(valoresT.get(k).getDescripcion());
                tg_valores.addView(rb_nuevo);
                valoOpc.add(rb_nuevo);
            }

            ((TextView) row.findViewById(R.id.textoRow)).setText(opciones4.get(i).getEtInicial());
            tba.addView(row);
        }
        TextView espacio = new TextView(this);
        espacio.setText("        ");
        pregunta.addView(espacio);
        break;
    case 8:
        id = R.layout.pregunta_fecha;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloFecha);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_fecha);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());

        break;
    case 9:
        id = R.layout.pregunta_hora;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloHora);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_hora);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());

        break;
    default:
        id = R.layout.pregunta_multiple;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloMultiple);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_mltiple);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        break;
    }

    return pregunta;
}

From source file:org.openremote.android.console.AppSettingsActivity.java

/**
 * It contains a list view to display custom servers, 
 * "Add" button to add custom server, "Delete" button to delete custom server.
 * The custom servers would be saved in customServers.xml. If click a list item, it would be saved as current server.
 * /*from   w  w  w  .j ava  2s.  c  o  m*/
 * @return the linear layout
 */
private LinearLayout constructCustomServersView() {
    LinearLayout custumeView = new LinearLayout(this);
    custumeView.setOrientation(LinearLayout.VERTICAL);
    custumeView.setPadding(20, 5, 5, 0);
    custumeView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    ArrayList<String> customServers = new ArrayList<String>();
    initCustomServersFromFile(customServers);

    RelativeLayout buttonsView = new RelativeLayout(this);
    buttonsView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 80));
    Button addServer = new Button(this);
    addServer.setWidth(80);
    RelativeLayout.LayoutParams addServerLayout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    addServerLayout.addRule(RelativeLayout.CENTER_HORIZONTAL);
    addServer.setLayoutParams(addServerLayout);
    addServer.setText("Add");
    addServer.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setClass(AppSettingsActivity.this, AddServerActivity.class);
            startActivityForResult(intent, Constants.REQUEST_CODE);
        }

    });
    Button deleteServer = new Button(this);
    deleteServer.setWidth(80);
    RelativeLayout.LayoutParams deleteServerLayout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    deleteServerLayout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    deleteServer.setLayoutParams(deleteServerLayout);
    deleteServer.setText("Delete");
    deleteServer.setOnClickListener(new OnClickListener() {
        @SuppressWarnings("unchecked")
        public void onClick(View v) {
            int checkedPosition = customListView.getCheckedItemPosition();
            if (!(checkedPosition == ListView.INVALID_POSITION)) {
                customListView.setItemChecked(checkedPosition, false);
                ((ArrayAdapter<String>) customListView.getAdapter())
                        .remove(customListView.getItemAtPosition(checkedPosition).toString());
                currentServer = "";
                AppSettingsModel.setCurrentServer(AppSettingsActivity.this, currentServer);
                writeCustomServerToFile();
            }
        }
    });

    buttonsView.addView(addServer);
    buttonsView.addView(deleteServer);

    customListView = new ListView(this);
    customListView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 200));
    customListView.setCacheColorHint(0);
    final ArrayAdapter<String> serverListAdapter = new ArrayAdapter<String>(appSettingsView.getContext(),
            R.layout.server_list_item, customServers);
    customListView.setAdapter(serverListAdapter);
    customListView.setItemsCanFocus(true);
    customListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    if (currentCustomServerIndex != -1) {
        customListView.setItemChecked(currentCustomServerIndex, true);
        currentServer = (String) customListView.getItemAtPosition(currentCustomServerIndex);
    }
    customListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            currentServer = (String) parent.getItemAtPosition(position);
            AppSettingsModel.setCurrentServer(AppSettingsActivity.this, currentServer);
            writeCustomServerToFile();
            requestPanelList();
            checkAuthentication();
            requestAccess();
        }

    });

    custumeView.addView(customListView);
    custumeView.addView(buttonsView);
    requestPanelList();
    checkAuthentication();
    requestAccess();
    return custumeView;
}

From source file:com.app.plugins.childBrowser.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject /*from w ww  . j  a  v a 2s  .co  m*/
 */
public String showWebPage(final String url, JSONObject options) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", false);
    }

    final WebView parent = this.webView;

    // Create dialog in new thread 
    Runnable runnable = new Runnable() {
        public void run() {
            dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_Black_NoTitleBar_Fullscreen);

            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            //LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
            //LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
            //LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT, 1.0f);
            LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT);

            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);

            LinearLayout toolbar = new LinearLayout(cordova.getActivity());
            toolbar.setOrientation(LinearLayout.HORIZONTAL);

            /*
            ImageButton back = new ImageButton((Context) ctx);
            back.getBackground().setAlpha(0);
            back.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                goBack();
            }
            });
            back.setId(1);
            try {
            back.setImageBitmap(loadDrawable("plugins/childbrowser/icon_arrow_left.png"));
            } catch (IOException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
            }
            back.setLayoutParams(backParams);
                    
            ImageButton forward = new ImageButton((Context) ctx);
            forward.getBackground().setAlpha(0);
            forward.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                goForward();
            }
            });
            forward.setId(2);
            try {
            forward.setImageBitmap(loadDrawable("plugins/childbrowser/icon_arrow_right.png"));
            } catch (IOException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
            }               
            forward.setLayoutParams(forwardParams);
            */

            /*
            edittext = new EditText((Context) ctx);
            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;
            }
            });
            edittext.setId(3);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setLayoutParams(editParams);
            */
            //edittext = new EditText((Context) ctx);
            //edittext.setVisibility(View.GONE);

            LinearLayout.LayoutParams titleParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.FILL_PARENT, 1.0f);
            TextView title = new TextView(cordova.getActivity());
            title.setId(1);
            title.setLayoutParams(titleParams);
            title.setGravity(Gravity.CENTER_VERTICAL);
            title.setTypeface(null, Typeface.BOLD);

            ImageButton close = new ImageButton(cordova.getActivity());
            close.getBackground().setAlpha(0);
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });
            close.setId(4);
            try {
                close.setImageBitmap(loadDrawable("plugins/childbrowser/icon_close.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            close.setLayoutParams(closeParams);

            childWebView = new WebView(cordova.getActivity());
            childWebView.getSettings().setJavaScriptEnabled(true);
            childWebView.getSettings().setBuiltInZoomControls(true);
            WebViewClient client = new ChildBrowserClient(parent, ctx, title/*, edittext*/);
            childWebView.setWebViewClient(client);
            childWebView.loadUrl(url);
            childWebView.setId(5);
            childWebView.setInitialScale(0);
            childWebView.setLayoutParams(wvParams);
            childWebView.requestFocus();
            childWebView.requestFocusFromTouch();

            //toolbar.addView(back);
            //toolbar.addView(forward);
            //toolbar.addView(edittext);
            toolbar.addView(close);
            toolbar.addView(title);

            if (getShowLocationBar()) {
                main.addView(toolbar);
            }
            main.addView(childWebView);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;
            lp.verticalMargin = 0f;
            lp.horizontalMargin = 0f;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            InputStream input = cordova.getActivity().getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.view.TextModalInteractionView.java

@Override
public void doOnCreate(final Activity activity, Bundle onSavedInstanceState) {
    activity.setContentView(R.layout.apptentive_textmodal_interaction_center);

    TextView title = (TextView) activity.findViewById(R.id.title);
    if (interaction.getTitle() == null) {
        title.setVisibility(View.GONE);
    } else {// w  w w  . j  a v a 2 s  .com
        title.setText(interaction.getTitle());
    }
    TextView body = (TextView) activity.findViewById(R.id.body);
    if (interaction.getBody() == null) {
        body.setVisibility(View.GONE);
    } else {
        body.setText(interaction.getBody());
    }

    LinearLayout bottomArea = (LinearLayout) activity.findViewById(R.id.bottom_area);
    List<Action> actions = interaction.getActions().getAsList();
    boolean vertical;
    if (actions != null && !actions.isEmpty()) {
        int totalChars = 0;
        for (Action button : actions) {
            totalChars += button.getLabel().length();
        }
        if (actions.size() == 1) {
            vertical = false;
        } else if (actions.size() == 2) {
            vertical = totalChars > MAX_TEXT_LENGTH_FOR_TWO_BUTTONS;
        } else if (actions.size() == 3) {
            vertical = totalChars > MAX_TEXT_LENGTH_FOR_THREE_BUTTONS;
        } else if (actions.size() == 4) {
            vertical = totalChars > MAX_TEXT_LENGTH_FOR_FOUR_BUTTONS;
        } else {
            vertical = true;
        }
        if (vertical) {
            bottomArea.setOrientation(LinearLayout.VERTICAL);
        } else {
            bottomArea.setOrientation(LinearLayout.HORIZONTAL);
        }

        for (int i = 0; i < actions.size(); i++) {
            final Action buttonAction = actions.get(i);
            final int position = i;
            ApptentiveDialogButton button = new ApptentiveDialogButton(activity);
            button.setText(buttonAction.getLabel());
            switch (buttonAction.getType()) {
            case dismiss:
                button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        JSONObject data = new JSONObject();
                        try {
                            data.put(TextModalInteraction.EVENT_KEY_ACTION_ID, buttonAction.getId());
                            data.put(Action.KEY_LABEL, buttonAction.getLabel());
                            data.put(TextModalInteraction.EVENT_KEY_ACTION_POSITION, position);
                        } catch (JSONException e) {
                            Log.e("Error creating Event data object.", e);
                        }
                        EngagementModule.engageInternal(activity, interaction,
                                TextModalInteraction.EVENT_NAME_DISMISS, data.toString());
                        activity.finish();
                    }
                });
                break;
            case interaction:
                button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        LaunchInteractionAction launchInteractionButton = (LaunchInteractionAction) buttonAction;
                        List<Invocation> invocations = launchInteractionButton.getInvocations();
                        String interactionIdToLaunch = null;
                        for (Invocation invocation : invocations) {
                            if (invocation.isCriteriaMet(activity)) {
                                interactionIdToLaunch = invocation.getInteractionId();
                                break;
                            }
                        }

                        Interaction invokedInteraction = null;
                        if (interactionIdToLaunch != null) {
                            Interactions interactions = InteractionManager.getInteractions(activity);
                            if (interactions != null) {
                                invokedInteraction = interactions.getInteraction(interactionIdToLaunch);
                            }
                        }

                        JSONObject data = new JSONObject();
                        try {
                            data.put(TextModalInteraction.EVENT_KEY_ACTION_ID, buttonAction.getId());
                            data.put(Action.KEY_LABEL, buttonAction.getLabel());
                            data.put(TextModalInteraction.EVENT_KEY_ACTION_POSITION, position);
                            data.put(TextModalInteraction.EVENT_KEY_INVOKED_INTERACTION_ID,
                                    invokedInteraction == null ? JSONObject.NULL : invokedInteraction.getId());
                        } catch (JSONException e) {
                            Log.e("Error creating Event data object.", e);
                        }

                        EngagementModule.engageInternal(activity, interaction,
                                TextModalInteraction.EVENT_NAME_INTERACTION, data.toString());
                        if (invokedInteraction != null) {
                            EngagementModule.launchInteraction(activity, invokedInteraction);
                        }

                        activity.finish();
                    }
                });
                break;
            }
            bottomArea.addView(button);
        }
    } else {
        bottomArea.setVisibility(View.GONE);
    }
}

From source file:com.phonegap.plugins.childBrowser.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url       The url to load./*from w  w  w  . ja  v a  2  s  .c  om*/
 * @param jsonObject 
 */
public String showWebPage(final String url, JSONObject options) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", true);
    }

    // Create dialog in new thread 
    Runnable runnable = new Runnable() {
        public void run() {
            dialog = new Dialog(ctx.getContext());

            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT, 1.0f);
            LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT);

            LinearLayout main = new LinearLayout(ctx.getContext());
            main.setOrientation(LinearLayout.VERTICAL);

            LinearLayout toolbar = new LinearLayout(ctx.getContext());
            toolbar.setOrientation(LinearLayout.HORIZONTAL);

            ImageButton back = new ImageButton(ctx.getContext());
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });
            back.setId(1);
            try {
                back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            back.setLayoutParams(backParams);

            ImageButton forward = new ImageButton(ctx.getContext());
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });
            forward.setId(2);
            try {
                forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            forward.setLayoutParams(forwardParams);

            edittext = new EditText(ctx.getContext());
            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;
                }
            });
            edittext.setId(3);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setLayoutParams(editParams);

            ImageButton close = new ImageButton((Context) ctx);
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });
            close.setId(4);
            try {
                close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            close.setLayoutParams(closeParams);

            webview = new WebView(ctx.getContext());
            webview.getSettings().setJavaScriptEnabled(true);
            webview.getSettings().setBuiltInZoomControls(true);

            // dda: intercept calls to console.log
            webview.setWebChromeClient(new WebChromeClient() {
                public boolean onConsoleMessage(ConsoleMessage cmsg) {
                    // check secret prefix
                    if (cmsg.message().startsWith("MAGIC")) {
                        String msg = cmsg.message().substring(5); // strip off prefix
                        /* process HTML */
                        try {
                            JSONObject obj = new JSONObject();
                            obj.put("type", PAGE_LOADED);
                            obj.put("html", msg);
                            sendUpdate(obj, true);
                        } catch (JSONException e) {
                            Log.d("ChildBrowser", "This should never happen");
                        }
                        return true;
                    }
                    return false;
                }
            });
            // dda: inject the JavaScript on page load
            webview.setWebViewClient(new ChildBrowserClient(edittext) {
                public void onPageFinished(WebView view, String address) {
                    // have the page spill its guts, with a secret prefix
                    Log.d("ChildBrowser", "\n\nInjecting javascript\n\n");
                    view.loadUrl(
                            "javascript:console.log('MAGIC'+document.getElementsByTagName('html')[0].innerHTML);");
                }
            });

            //        webview.setWebViewClient(client);
            webview.loadUrl(url);
            webview.setId(5);
            webview.setInitialScale(0);
            webview.setLayoutParams(wvParams);
            webview.requestFocus();
            webview.requestFocusFromTouch();

            toolbar.addView(back);
            toolbar.addView(forward);
            toolbar.addView(edittext);
            toolbar.addView(close);

            if (getShowLocationBar()) {
                main.addView(toolbar);
            }
            main.addView(webview);

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

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            InputStream input = ctx.getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.ctx.runOnUiThread(runnable);
    return "";
}