Example usage for android.widget LinearLayout VERTICAL

List of usage examples for android.widget LinearLayout VERTICAL

Introduction

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

Prototype

int VERTICAL

To view the source code for android.widget LinearLayout VERTICAL.

Click Source Link

Usage

From source file:com.lixplor.rocketpulltorefresh.RefreshLayout.java

/**
 * Init of view/*from ww  w  . j  av a2 s . c  om*/
 * @param context Context
 * @param attrs AttributeSet
 */
private void init(Context context, AttributeSet attrs) {
    mContext = context;
    setOrientation(LinearLayout.VERTICAL);
}

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  ww w.  j a  va  2 s . 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:org.mozilla.gecko.PromptService.java

public void Show(String aTitle, String aText, PromptButton[] aButtons, PromptListItem[] aMenuList,
        boolean aMultipleSelection) {
    AlertDialog.Builder builder = new AlertDialog.Builder(GeckoApp.mAppContext);
    if (!aTitle.equals("")) {
        builder.setTitle(aTitle);/*  www.ja v  a  2 s. c  o m*/
    }

    if (!aText.equals("")) {
        builder.setMessage(aText);
    }

    int length = mInputs.length;
    if (aMenuList.length > 0) {
        int resourceId = android.R.layout.select_dialog_item;
        if (mSelected != null && mSelected.length > 0) {
            if (aMultipleSelection) {
                resourceId = android.R.layout.select_dialog_multichoice;
            } else {
                resourceId = android.R.layout.select_dialog_singlechoice;
            }
        }
        PromptListAdapter adapter = new PromptListAdapter(GeckoApp.mAppContext, resourceId, aMenuList);
        if (mSelected != null && mSelected.length > 0) {
            if (aMultipleSelection) {
                adapter.listView = (ListView) mInflater.inflate(R.layout.select_dialog_list, null);
                adapter.listView.setOnItemClickListener(this);
                builder.setInverseBackgroundForced(true);
                adapter.listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
                adapter.listView.setAdapter(adapter);
                builder.setView(adapter.listView);
            } else {
                int selectedIndex = -1;
                for (int i = 0; i < mSelected.length; i++) {
                    if (mSelected[i]) {
                        selectedIndex = i;
                        break;
                    }
                }
                mSelected = null;
                builder.setSingleChoiceItems(adapter, selectedIndex, this);
            }
        } else {
            builder.setAdapter(adapter, this);
            mSelected = null;
        }
    } else if (length == 1) {
        builder.setView(mInputs[0].getView());
    } else if (length > 1) {
        LinearLayout linearLayout = new LinearLayout(GeckoApp.mAppContext);
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        for (int i = 0; i < length; i++) {
            View content = mInputs[i].getView();
            linearLayout.addView(content);
        }
        builder.setView((View) linearLayout);
    }

    length = aButtons.length;
    if (length > 0) {
        builder.setPositiveButton(aButtons[0].label, this);
    }
    if (length > 1) {
        builder.setNeutralButton(aButtons[1].label, this);
    }
    if (length > 2) {
        builder.setNegativeButton(aButtons[2].label, this);
    }

    mDialog = builder.create();
    mDialog.setOnCancelListener(this);
    mDialog.show();
}

From source file:com.yktx.check.widget.OldPagerSlidingTabStrip.java

private void addIconAndTextTab(final int position, int resId, String title) {
    LinearLayout layout = new LinearLayout(getContext());
    layout.setGravity(Gravity.CENTER);//  w w  w .j  ava  2s.  c om
    layout.setOrientation(LinearLayout.VERTICAL);
    ImageView tabImage = new ImageView(getContext());
    tabImage.setImageResource(resId);
    tabImage.setId(R.id.image);
    TextView tabText = new TextView(getContext());
    tabText.setText(title);
    tabText.setSingleLine();
    tabText.setId(R.id.text);
    tabText.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    tabText.setGravity(Gravity.CENTER_HORIZONTAL);
    tabText.setPadding(0, 3, 0, 0);
    layout.addView(tabImage);
    layout.addView(tabText);

    addTab(position, layout);

}

From source file:com.aware.ui.ESM_UI.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    //      getActivity().getWindow().setType(WindowManager.LayoutParams.TYPE_PRIORITY_PHONE);
    //      getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    //        getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    //        getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

    builder = new AlertDialog.Builder(getActivity());
    inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);

    TAG = Aware.getSetting(getActivity().getApplicationContext(), Aware_Preferences.DEBUG_TAG).length() > 0
            ? Aware.getSetting(getActivity().getApplicationContext(), Aware_Preferences.DEBUG_TAG)
            : TAG;// w w w.ja v a 2s  . c  om

    Cursor visible_esm = getActivity().getContentResolver().query(ESM_Data.CONTENT_URI, null,
            ESM_Data.STATUS + "=" + ESM.STATUS_NEW, null, ESM_Data.TIMESTAMP + " ASC LIMIT 1");
    if (visible_esm != null && visible_esm.moveToFirst()) {
        esm_id = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data._ID));

        //Fixed: set the esm as not new anymore, to avoid displaying the same ESM twice due to changes in orientation
        ContentValues update_state = new ContentValues();
        update_state.put(ESM_Data.STATUS, ESM.STATUS_VISIBLE);
        getActivity().getContentResolver().update(ESM_Data.CONTENT_URI, update_state,
                ESM_Data._ID + "=" + esm_id, null);

        esm_type = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.TYPE));
        expires_seconds = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.EXPIRATION_THREASHOLD));

        builder.setTitle(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.TITLE)));

        View ui = null;
        switch (esm_type) {
        case ESM.TYPE_ESM_TEXT:
            ui = inflater.inflate(R.layout.esm_text, null);
            break;
        case ESM.TYPE_ESM_RADIO:
            ui = inflater.inflate(R.layout.esm_radio, null);
            break;
        case ESM.TYPE_ESM_CHECKBOX:
            ui = inflater.inflate(R.layout.esm_checkbox, null);
            break;
        case ESM.TYPE_ESM_LIKERT:
            ui = inflater.inflate(R.layout.esm_likert, null);
            break;
        case ESM.TYPE_ESM_QUICK_ANSWERS:
            ui = inflater.inflate(R.layout.esm_quick, null);
            break;
        }

        final View layout = ui;
        builder.setView(layout);
        current_dialog = builder.create();
        sContext = current_dialog.getContext();

        TextView esm_instructions = (TextView) layout.findViewById(R.id.esm_instructions);
        esm_instructions.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.INSTRUCTIONS)));

        switch (esm_type) {
        case ESM.TYPE_ESM_TEXT:
            final EditText feedback = (EditText) layout.findViewById(R.id.esm_feedback);
            Button cancel_text = (Button) layout.findViewById(R.id.esm_cancel);
            cancel_text.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    inputManager.hideSoftInputFromWindow(feedback.getWindowToken(), 0);
                    current_dialog.cancel();
                }
            });
            Button submit_text = (Button) layout.findViewById(R.id.esm_submit);
            submit_text.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT)));
            submit_text.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    inputManager.hideSoftInputFromWindow(feedback.getWindowToken(), 0);

                    if (expires_seconds > 0 && expire_monitor != null)
                        expire_monitor.cancel(true);

                    ContentValues rowData = new ContentValues();
                    rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());
                    rowData.put(ESM_Data.ANSWER, feedback.getText().toString());
                    rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED);

                    sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData,
                            ESM_Data._ID + "=" + esm_id, null);

                    Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                    getActivity().sendBroadcast(answer);

                    if (Aware.DEBUG)
                        Log.d(TAG, "Answer:" + rowData.toString());

                    current_dialog.dismiss();
                }
            });
            break;
        case ESM.TYPE_ESM_RADIO:
            try {
                final RadioGroup radioOptions = (RadioGroup) layout.findViewById(R.id.esm_radio);
                final JSONArray radios = new JSONArray(
                        visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.RADIOS)));

                for (int i = 0; i < radios.length(); i++) {
                    final RadioButton radioOption = new RadioButton(getActivity());
                    radioOption.setId(i);
                    radioOption.setText(radios.getString(i));
                    radioOptions.addView(radioOption);

                    if (radios.getString(i).equals("Other")) {
                        radioOption.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                final Dialog editOther = new Dialog(getActivity());
                                editOther.setTitle("Can you be more specific, please?");
                                editOther.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                                editOther.getWindow().setGravity(Gravity.TOP);
                                editOther.getWindow().setLayout(LayoutParams.MATCH_PARENT,
                                        LayoutParams.WRAP_CONTENT);

                                LinearLayout editor = new LinearLayout(getActivity());
                                editor.setOrientation(LinearLayout.VERTICAL);

                                editOther.setContentView(editor);
                                editOther.show();

                                final EditText otherText = new EditText(getActivity());
                                editor.addView(otherText);

                                Button confirm = new Button(getActivity());
                                confirm.setText("OK");
                                confirm.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        if (otherText.length() > 0)
                                            radioOption.setText(otherText.getText());
                                        inputManager.hideSoftInputFromWindow(otherText.getWindowToken(), 0);
                                        editOther.dismiss();
                                    }
                                });
                                editor.addView(confirm);
                            }
                        });
                    }
                }
                Button cancel_radio = (Button) layout.findViewById(R.id.esm_cancel);
                cancel_radio.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        current_dialog.cancel();
                    }
                });
                Button submit_radio = (Button) layout.findViewById(R.id.esm_submit);
                submit_radio.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT)));
                submit_radio.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        if (expires_seconds > 0 && expire_monitor != null)
                            expire_monitor.cancel(true);

                        ContentValues rowData = new ContentValues();
                        rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());

                        RadioGroup radioOptions = (RadioGroup) layout.findViewById(R.id.esm_radio);
                        if (radioOptions.getCheckedRadioButtonId() != -1) {
                            RadioButton selected = (RadioButton) radioOptions
                                    .getChildAt(radioOptions.getCheckedRadioButtonId());
                            rowData.put(ESM_Data.ANSWER, selected.getText().toString());
                        }
                        rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED);

                        sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData,
                                ESM_Data._ID + "=" + esm_id, null);

                        Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                        getActivity().sendBroadcast(answer);

                        if (Aware.DEBUG)
                            Log.d(TAG, "Answer:" + rowData.toString());

                        current_dialog.dismiss();
                    }
                });
            } catch (JSONException e) {
                e.printStackTrace();
            }
            break;
        case ESM.TYPE_ESM_CHECKBOX:
            try {
                final LinearLayout checkboxes = (LinearLayout) layout.findViewById(R.id.esm_checkboxes);
                final JSONArray checks = new JSONArray(
                        visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.CHECKBOXES)));

                for (int i = 0; i < checks.length(); i++) {
                    final CheckBox checked = new CheckBox(getActivity());
                    checked.setText(checks.getString(i));
                    checked.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                        @Override
                        public void onCheckedChanged(final CompoundButton buttonView, boolean isChecked) {
                            if (isChecked) {
                                if (buttonView.getText().equals("Other")) {
                                    checked.setOnClickListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            final Dialog editOther = new Dialog(getActivity());
                                            editOther.setTitle("Can you be more specific, please?");
                                            editOther.getWindow()
                                                    .setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                                            editOther.getWindow().setGravity(Gravity.TOP);
                                            editOther.getWindow().setLayout(LayoutParams.MATCH_PARENT,
                                                    LayoutParams.WRAP_CONTENT);

                                            LinearLayout editor = new LinearLayout(getActivity());
                                            editor.setOrientation(LinearLayout.VERTICAL);
                                            editOther.setContentView(editor);
                                            editOther.show();

                                            final EditText otherText = new EditText(getActivity());
                                            editor.addView(otherText);

                                            Button confirm = new Button(getActivity());
                                            confirm.setText("OK");
                                            confirm.setOnClickListener(new View.OnClickListener() {
                                                @Override
                                                public void onClick(View v) {
                                                    if (otherText.length() > 0) {
                                                        inputManager.hideSoftInputFromWindow(
                                                                otherText.getWindowToken(), 0);
                                                        selected_options
                                                                .remove(buttonView.getText().toString());
                                                        checked.setText(otherText.getText());
                                                        selected_options.add(otherText.getText().toString());
                                                    }
                                                    editOther.dismiss();
                                                }
                                            });
                                            editor.addView(confirm);
                                        }
                                    });
                                } else {
                                    selected_options.add(buttonView.getText().toString());
                                }
                            } else {
                                selected_options.remove(buttonView.getText().toString());
                            }
                        }
                    });
                    checkboxes.addView(checked);
                }
                Button cancel_checkbox = (Button) layout.findViewById(R.id.esm_cancel);
                cancel_checkbox.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        current_dialog.cancel();
                    }
                });
                Button submit_checkbox = (Button) layout.findViewById(R.id.esm_submit);
                submit_checkbox.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT)));
                submit_checkbox.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        if (expires_seconds > 0 && expire_monitor != null)
                            expire_monitor.cancel(true);

                        ContentValues rowData = new ContentValues();
                        rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());

                        if (selected_options.size() > 0) {
                            rowData.put(ESM_Data.ANSWER, selected_options.toString());
                        }

                        rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED);

                        sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData,
                                ESM_Data._ID + "=" + esm_id, null);

                        Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                        getActivity().sendBroadcast(answer);

                        if (Aware.DEBUG)
                            Log.d(TAG, "Answer:" + rowData.toString());

                        current_dialog.dismiss();
                    }
                });
            } catch (JSONException e) {
                e.printStackTrace();
            }
            break;
        case ESM.TYPE_ESM_LIKERT:
            final RatingBar ratingBar = (RatingBar) layout.findViewById(R.id.esm_likert);
            ratingBar.setMax(visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX)));
            ratingBar.setStepSize(
                    (float) visible_esm.getDouble(visible_esm.getColumnIndex(ESM_Data.LIKERT_STEP)));
            ratingBar.setNumStars(visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX)));

            TextView min_label = (TextView) layout.findViewById(R.id.esm_min);
            min_label.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.LIKERT_MIN_LABEL)));

            TextView max_label = (TextView) layout.findViewById(R.id.esm_max);
            max_label.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX_LABEL)));

            Button cancel = (Button) layout.findViewById(R.id.esm_cancel);
            cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    current_dialog.cancel();
                }
            });
            Button submit = (Button) layout.findViewById(R.id.esm_submit);
            submit.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT)));
            submit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (expires_seconds > 0 && expire_monitor != null)
                        expire_monitor.cancel(true);

                    ContentValues rowData = new ContentValues();
                    rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());
                    rowData.put(ESM_Data.ANSWER, ratingBar.getRating());
                    rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED);

                    sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData,
                            ESM_Data._ID + "=" + esm_id, null);

                    Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                    getActivity().sendBroadcast(answer);

                    if (Aware.DEBUG)
                        Log.d(TAG, "Answer:" + rowData.toString());

                    current_dialog.dismiss();
                }
            });
            break;
        case ESM.TYPE_ESM_QUICK_ANSWERS:
            try {
                final JSONArray answers = new JSONArray(
                        visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.QUICK_ANSWERS)));
                final LinearLayout answersHolder = (LinearLayout) layout.findViewById(R.id.esm_answers);

                //If we have more than 3 possibilities, better that the UI is vertical for UX
                if (answers.length() > 3) {
                    answersHolder.setOrientation(LinearLayout.VERTICAL);
                }

                for (int i = 0; i < answers.length(); i++) {
                    final Button answer = new Button(getActivity());
                    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                            LayoutParams.WRAP_CONTENT, 1.0f);
                    answer.setLayoutParams(params);
                    answer.setText(answers.getString(i));
                    answer.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {

                            if (expires_seconds > 0 && expire_monitor != null)
                                expire_monitor.cancel(true);

                            ContentValues rowData = new ContentValues();
                            rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());
                            rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED);
                            rowData.put(ESM_Data.ANSWER, (String) answer.getText());

                            sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData,
                                    ESM_Data._ID + "=" + esm_id, null);

                            Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                            getActivity().sendBroadcast(answer);

                            if (Aware.DEBUG)
                                Log.d(TAG, "Answer:" + rowData.toString());

                            current_dialog.dismiss();
                        }
                    });
                    answersHolder.addView(answer);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            break;
        }
    }
    if (visible_esm != null && !visible_esm.isClosed())
        visible_esm.close();

    //Start dialog visibility threshold
    if (expires_seconds > 0) {
        expire_monitor = new ESMExpireMonitor(System.currentTimeMillis(), expires_seconds, esm_id);
        expire_monitor.execute();
    }

    //Fixed: doesn't dismiss the dialog if touched outside or ghost touches
    current_dialog.setCanceledOnTouchOutside(false);

    return current_dialog;
}

From source file:com.google.code.twisty.Twisty.java

/** Called when activity is first created. */
@Override/*www  .  ja  v a2  s .  c  om*/
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    // requestWindowFeature(Window.FEATURE_NO_TITLE);
    requestWindowFeature(Window.FEATURE_ACTION_BAR);

    // Map our built-in game resources to real filenames
    builtinGames.clear();
    builtinGames.put(R.raw.violet, "violet.z8");
    builtinGames.put(R.raw.rover, "rover.gblorb");
    builtinGames.put(R.raw.glulxercise, "glulxercise.ulx");
    builtinGames.put(R.raw.windowtest, "windowtest.ulx");

    UISync.setInstance(this);

    // An imageview to show the twisty icon
    iv = new ImageView(this);
    iv.setBackgroundColor(0xffffff);
    iv.setImageResource(R.drawable.app_icon);
    iv.setAdjustViewBounds(true);
    iv.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    // The main 'welcome screen' window from which games are launched.
    tv = new TextBufferView(this);
    mainWin = new TextBufferIO(tv, new StyleManager());
    //final GlkEventQueue eventQueue = null;
    tv.setFocusableInTouchMode(true);

    // The Glk window layout manager
    glkLayout = new GlkLayout(this);

    // put it all together
    ll = new LinearLayout(this);
    ll.setBackgroundColor(Color.argb(0xFF, 0xFE, 0xFF, 0xCC));
    ll.setOrientation(android.widget.LinearLayout.VERTICAL);
    ll.addView(iv);
    ll.addView(tv);
    glkLayout.setVisibility(View.GONE);
    ll.addView(glkLayout);
    setContentView(ll);

    dialog_handler = new DialogHandler(this);
    terp_handler = new TerpHandler(this);

    // Ensure we can write story files and save games to external storage
    checkWritePermission();

    Uri dataSource = this.getIntent().getData();
    if (dataSource != null) {
        /* Suck down the URI we received to sdcard, launch terp on it. */
        try {
            startTerp(dataSource);
        } catch (Exception e) {
            Log.e(TAG, e.getMessage(), e);
        }
    } else {
        printWelcomeMessage();
    }
}

From source file:cn.bingoogolapple.androidcommon.adapter.BGADivider.java

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    if (parent.getLayoutManager() == null || parent.getAdapter() == null) {
        return;//w  ww .jav a  2  s  .  co  m
    }

    int childAdapterPosition = parent.getChildAdapterPosition(view);
    int itemCount = parent.getAdapter().getItemCount();

    int realChildAdapterPosition = childAdapterPosition;
    int realItemCount = itemCount;

    BGAHeaderAndFooterAdapter headerAndFooterAdapter = getHeaderAndFooterAdapter(parent);
    if (headerAndFooterAdapter != null) {
        // ?? item 
        realChildAdapterPosition = headerAndFooterAdapter.getRealItemPosition(childAdapterPosition);
        // ?? item 
        realItemCount = headerAndFooterAdapter.getRealItemCount();
    }

    if (isNeedSkip(childAdapterPosition, headerAndFooterAdapter, realChildAdapterPosition, realItemCount)) {
        outRect.set(0, 0, 0, 0);
    } else {
        if (mDelegate != null && mDelegate.isNeedCustom(realChildAdapterPosition, realItemCount)) {
            mDelegate.getItemOffsets(this, realChildAdapterPosition, realItemCount, outRect);
        } else {
            if (mOrientation == LinearLayout.VERTICAL) {
                getVerticalItemOffsets(outRect);
            } else {
                outRect.set(mSize, 0, 0, 0);
            }
        }
    }
}

From source file:org.bdigi.andy.MainActivity.java

private Fragment[] getModeFragments() {

    final Context ctx = MainActivity.this;

    Mode modes[] = getModes();/*from ww w.  j a  v  a 2  s  . c  o m*/
    Fragment frags[] = new Fragment[modes.length];
    for (int i = 0; i < modes.length; i++) {
        final Mode mode = modes[i];
        Fragment frag = new Fragment() {

            @Override
            public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
                LinearLayout layout = new LinearLayout(ctx);
                layout.setOrientation(LinearLayout.VERTICAL);
                TextView title = new TextView(ctx);
                title.setClickable(true);
                title.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        setMode(mode);
                    }
                });
                title.setText("Mode: " + mode.name());
                title.setTextAppearance(ctx, R.style.Title);
                layout.addView(title);

                Seq<Property<?>> props = mode.properties().properties();

                for (int i = 0; i < props.size(); i++) {
                    Property p = props.apply(i);

                    if (p instanceof BooleanProperty) {
                        layout.addView(new PropWidget.BooleanPropertyWidget(ctx, (BooleanProperty) p));
                    } else if (p instanceof RadioProperty) {
                        layout.addView(new PropWidget.RadioPropertyWidget(ctx, (RadioProperty) p));
                    }
                }
                return layout;
            }
        };
        frags[i] = frag;
    }
    return frags;
}

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);//from   w ww.  jav a  2  s. c  o m
            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:gr.ioanpier.auth.users.memorypaintings.MainActivityFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    //Language Locale
    String languageToLoad = getActivity().getIntent().getStringExtra(LANGUAGE); // your language
    if (languageToLoad != null) {
        Locale locale = new Locale(languageToLoad);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;//from   w  w  w. ja va2s  .  c  om
        getActivity().getResources().updateConfiguration(config,
                getActivity().getResources().getDisplayMetrics());
    }

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    //Calculate the level and the number of cards.
    level = getActivity().getIntent().getIntExtra(LEVEL_TAG, 0);
    if (level >= layoutsPerLevel.length)
        level = layoutsPerLevel.length - 1;
    numberOfCards = cardsPerLevel[level];

    numberOfBitmapWorkerTasks = numberOfCards / 2;
    instantiateLoadingBar();

    if (!isExternalStorageReadable()) {
        Log.e(LOG, "External storage wasn't readable");
        storedDrawables = null;
    } else {
        File[] imageFiles = getFilesFromDirectory(WelcomeScreen.IMAGES_PATH, ".jpg", ".png");

        if (imageFiles.length > 0) {
            String descriptionsFolder = "Descriptions";
            Locale locale = getActivity().getResources().getConfiguration().locale;
            if (locale.getDisplayLanguage().equals(Locale.ENGLISH.getDisplayLanguage()))
                descriptionsFolder = descriptionsFolder.concat("_en");
            else
                descriptionsFolder = descriptionsFolder.concat("_pl");
            File[] descFiles = getFilesFromDirectory(WelcomeScreen.DESCRIPTIONS_PATH, ".txt");

            //getDrawables
            storedDrawables = getDrawables(imageFiles, descFiles);
        } else {
            Log.e(LOG, "No files found in external storage");
            storedDrawables = null;
        }

    }

    pairs = new int[numberOfCards];
    for (int i = 0; i < numberOfCards; i++) {
        pairs[i] = -1;
    }
    cards = new ImageViewCard[numberOfCards];

    //This is where the layout magic happens.
    LinearLayout linearLayout;
    int index;
    for (int i = 0; i < layoutsPerLevel[level]; i++) {
        //The layout consists of multiple vertical LinearLayout[s] positioned horizontally next to each other.
        linearLayout = new LinearLayout(getActivity());
        linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.MATCH_PARENT, 1.0f));
        linearLayout.setOrientation(LinearLayout.VERTICAL);

        for (int j = 0; j < numberOfCards / layoutsPerLevel[level]; j++) {
            //Each LinearLayout has a number of ImageViewCard[s], each positioned evenly in inside the layout. The number depends on the level.
            //ImageViewCard is an extension of the ViewFlipper class with a built in flipCard method for flipping between 2 images and which also includes animation.
            ImageViewCard card = new ImageViewCard(getActivity());
            card.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT, 1.0f));
            ((LinearLayout.LayoutParams) card.getLayoutParams()).setMargins(16, 16, 16, 16);

            //SquareImageView is an extension of the ImageView class that ensures that the image is square.
            //Two are needed, one for the back of the image and one for the front.
            SquareImageView image1 = new SquareImageView(getActivity());
            image1.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));

            SquareImageView image2 = new SquareImageView(getActivity());
            image2.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));

            //Add the SquareImageView[s] to the ImageViewCard and subsequently that to the LinearLayout.
            card.addView(image1);
            card.addView(image2);
            index = i * numberOfCards / layoutsPerLevel[level] + j;
            linearLayout.addView(card);
            cardsIndex.put(card.hashCode(), index);

            //Set the back of the image.
            ((ImageView) card.getChildAt(0))
                    .setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.black));

            //Save the ImageViewCard for later use.
            cards[index] = card;

        }
        //Add the LinearLayout to the rootView.
        ((LinearLayout) rootView.findViewById(R.id.parent)).addView(linearLayout);
    }

    //Assign a listener for every ImageViewCard.
    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (!stillAnimating && numberOfBitmapWorkerTasks == 0) {
                int cardID = cardsIndex.get(view.hashCode());
                stillAnimating = true;
                synchronized (gameLogicLock) {
                    if (numberOfCardsFound < numberOfCards)
                        onCardFlipped(cardID);
                    else
                        onCardClicked(cardID);
                }

                //Add a delay before the listener can be activated again.
                new AsyncTask<Void, Void, Void>() {
                    @Override
                    protected Void doInBackground(Void... voids) {
                        try {
                            Thread.sleep(250);
                        } catch (InterruptedException e) {
                        }
                        return null;
                    }

                    @Override
                    protected void onPostExecute(Void n) {
                        stillAnimating = false;
                    }
                }.execute();

            } else if (numberOfBitmapWorkerTasks > 0) {
                Toast.makeText(getActivity(), getString(R.string.loading_bar_message), Toast.LENGTH_SHORT)
                        .show();
            }

        }
    };

    for (int i = 0; i < numberOfCards; i++) {
        cards[i].setOnClickListener(onClickListener);
    }

    //Initialize
    found = new boolean[numberOfCards];
    for (int i = 0; i < numberOfCards; i++)
        found[i] = false;

    //Initialize
    int[] chosenDrawables = new int[numberOfCards / 2];
    cardDrawablePairs = new int[numberOfCards];

    //Initialize. Holds the index of every ImageViewCard in cards. Will later be used for the pairs.
    ArrayList<Integer> availablePairs = new ArrayList<>();
    for (int i = 0; i < numberOfCards; i++)
        availablePairs.add(i);
    Collections.shuffle(availablePairs);

    Random r = new Random();
    int pair1, pair2;
    BitmapWorkerTask bitmapWorkerTask;
    for (int i = 0; i < numberOfCards / 2; i++) {
        //Choose at random one of the available images. Make sure it's unique.
        int range;
        if (storedDrawables == null)
            range = colors.length;
        else
            range = storedDrawables.length;
        boolean unique = false;
        while (!unique) {
            unique = true;
            //If there are a lot of images, this should be changed (there will never be a lot)
            chosenDrawables[i] = r.nextInt(range);

            for (int j = 0; j < i; j++) {
                if (chosenDrawables[i] == chosenDrawables[j])
                    unique = false;
            }
        }

        //availablePairs have already been shuffled, so just remove the first 2.
        pair1 = availablePairs.remove(0);
        pair2 = availablePairs.remove(0);

        cardDrawablePairs[pair1] = chosenDrawables[i];
        cardDrawablePairs[pair2] = chosenDrawables[i];

        //Assign the front of the ImageViewCard to the randomly chosen Drawable.
        ImageView imageView1, imageView2;
        String absolutePath;
        if (storedDrawables == null) {
            (cards[pair1].getChildAt(1))
                    .setBackgroundColor(ContextCompat.getColor(getActivity(), colors[chosenDrawables[i]]));
            (cards[pair2].getChildAt(1))
                    .setBackgroundColor(ContextCompat.getColor(getActivity(), colors[chosenDrawables[i]]));
        } else {
            DisplayMetrics displayMetrics = new DisplayMetrics();
            WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE); // the results will be higher than using the activity context object or the getWindowManager() shortcut
            wm.getDefaultDisplay().getMetrics(displayMetrics);
            int screenWidth = displayMetrics.widthPixels / (layoutsPerLevel[level]);
            int screenHeight = displayMetrics.heightPixels / (cardsPerLevel[level] / layoutsPerLevel[level]);

            absolutePath = storedDrawables[chosenDrawables[i]].absolute_path_image;
            imageView1 = ((ImageView) cards[pair1].getChildAt(1));
            imageView2 = ((ImageView) cards[pair2].getChildAt(1));

            bitmapWorkerTask = new BitmapWorkerTask(screenWidth, screenHeight, imageView1, imageView2);
            bitmapWorkerTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, absolutePath);

        }

        //Save the pairs.
        pairs[pair1] = pair2;
        pairs[pair2] = pair1;

    }

    if (storedDrawables == null) {
        numberOfBitmapWorkerTasks = 0;
    }

    return rootView;
}