Example usage for android.widget LinearLayout setOrientation

List of usage examples for android.widget LinearLayout setOrientation

Introduction

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

Prototype

public void setOrientation(@OrientationMode int orientation) 

Source Link

Document

Should the layout be a column or a row.

Usage

From source file:org.odk.collect.android.widgets.VideoWidget.java

public VideoWidget(Context context, FormEntryPrompt prompt, @NonNull FileUtil fileUtil,
        @NonNull MediaUtil mediaUtil) {//  ww  w  . j  av  a 2 s.  c  o  m
    super(context, prompt);

    this.fileUtil = fileUtil;
    this.mediaUtil = mediaUtil;

    String appearance = getFormEntryPrompt().getAppearanceHint();
    selfie = appearance != null
            && (appearance.equalsIgnoreCase("selfie") || appearance.equalsIgnoreCase("new-front"));

    captureButton = getSimpleButton(getContext().getString(R.string.capture_video), R.id.capture_video);

    chooseButton = getSimpleButton(getContext().getString(R.string.choose_video), R.id.choose_video);

    playButton = getSimpleButton(getContext().getString(R.string.play_video), R.id.play_video);

    // retrieve answer from data model and update ui
    binaryName = prompt.getAnswerText();
    if (binaryName != null) {
        playButton.setEnabled(true);
    } else {
        playButton.setEnabled(false);
    }

    // finish complex layout
    LinearLayout answerLayout = new LinearLayout(getContext());
    answerLayout.setOrientation(LinearLayout.VERTICAL);
    answerLayout.addView(captureButton);
    answerLayout.addView(chooseButton);
    answerLayout.addView(playButton);
    addAnswerView(answerLayout);

    hideButtonsIfNeeded();

    if (selfie) {
        if (!CameraUtils.isFrontCameraAvailable()) {
            captureButton.setEnabled(false);
            ToastUtils.showLongToast(R.string.error_front_camera_unavailable);
        }
    }
}

From source file:studio.legency.statefragment.ContentFragment.java

/**
 * Provide default implementation to return a simple list view.  Subclasses
 * can override to replace with their own layout.  If doing so, the
 * returned view hierarchy <em>must</em> have a ListView whose id
 * is {@link android.R.id#list android.R.id.list} and can optionally
 * have a sibling view id {@link android.R.id#empty android.R.id.empty}
 * that is to be shown when the list is empty.
 * <p/>/* www .jav a  2s. c  o  m*/
 * <p>If you are overriding this method with your own custom content,
 * consider including the standard layout {@link android.R.layout#list_content}
 * in your layout file, so that you continue to retain all of the standard
 * behavior of ContentFragment.  In particular, this is currently the only
 * way to have the built-in indeterminant progress state be shown.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_CONTENT_CONTAINER_ID);

    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_TEXT_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    ListView lv = new ListView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return root;
}

From source file:com.veniosg.dir.android.fragment.AbsListFragment.java

/**
 * Provide default implementation to return a simple list view.  Subclasses
 * can override to replace with their own layout.  If doing so, the
 * returned view hierarchy <em>must</em> have a AbsListView whose id
 * is {@link android.R.id#list android.R.id.list} and can optionally
 * have a sibling view id {@link android.R.id#empty android.R.id.empty}
 * that is to be shown when the list is empty.
 *
 * <p>If you are overriding this method with your own custom content,
 * consider including the standard layout {@link android.R.layout#list_content}
 * in your layout file, so that you continue to retain all of the standard
 * behavior of ListFragment.  In particular, this is currently the only
 * way to have the built-in indeterminant progress state be shown.
 *//*  w w  w  .j a  va  2s  .co m*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    // ------------------------------------------------------------------

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);

    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    AbsListView lv = new DividerGridView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    return root;
}

From source file:mobisocial.musubi.objects.FileObj.java

@Override
public View createView(Context context, ViewGroup frame) {
    LinearLayout container = new LinearLayout(context);
    container.setLayoutParams(CommonLayouts.FULL_WIDTH);
    container.setOrientation(LinearLayout.HORIZONTAL);
    container.setGravity(Gravity.CENTER);

    ImageView imageView = new ImageView(context);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    TextView valueTV = new TextView(context);

    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.BOTTOM | Gravity.LEFT);
    valueTV.setPadding(4, 0, 0, 0);//from  w w  w .  j a  va  2  s.  co  m

    container.addView(imageView);
    container.addView(valueTV);
    return container;
}

From source file:com.tinfoil.sms.settings.UserKeySettings.java

public void exportKey(View view) {
    if (SMSUtility.isMediaWritable()) {
        phoneBook = new AutoCompleteTextView(this);
        List<String> contact = null;
        if (tc == null) {
            //Do in thread.
            tc = dba.getAllRows(DBAccessor.ALL);
        }/*w  w w  .ja  v  a  2s.co  m*/

        if (tc != null) {
            if (contact == null) {
                contact = SMSUtility.contactDisplayMaker(tc);
            }
        } else {
            contact = null;
        }
        final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getBaseContext(),
                R.layout.auto_complete_list_item, contact);

        phoneBook.setAdapter(adapter);

        final AlertDialog.Builder popup_builder = new AlertDialog.Builder(this);
        popup_builder.setTitle(R.string.import_contacts_title).setCancelable(true).setView(phoneBook)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                    public void onClick(final DialogInterface dialog, final int which) {

                        String[] contactInfo = SMSUtility.parseAutoComplete(phoneBook.getText().toString());
                        //String number = null;

                        boolean invalid = false;
                        if (contactInfo != null) {
                            if (contactInfo[0] == null) {
                                contactInfo[0] = contactInfo[1];
                            }

                            final Number number = dba.getNumber(contactInfo[1]);

                            if (number != null) {
                                AlertDialog.Builder builder = new AlertDialog.Builder(UserKeySettings.this);
                                LinearLayout linearLayout = new LinearLayout(UserKeySettings.this);
                                linearLayout.setOrientation(LinearLayout.VERTICAL);

                                final EditText sharedSecret1 = new EditText(UserKeySettings.this);
                                sharedSecret1
                                        .setHint(UserKeySettings.this.getString(R.string.shared_secret_hint_1));
                                sharedSecret1.setMaxLines(EditNumber.SHARED_INFO_MAX);
                                sharedSecret1.setInputType(InputType.TYPE_CLASS_TEXT);
                                linearLayout.addView(sharedSecret1);

                                final EditText sharedSecret2 = new EditText(UserKeySettings.this);
                                sharedSecret2
                                        .setHint(UserKeySettings.this.getString(R.string.shared_secret_hint_2));
                                sharedSecret2.setMaxLines(EditNumber.SHARED_INFO_MAX);
                                sharedSecret2.setInputType(InputType.TYPE_CLASS_TEXT);
                                linearLayout.addView(sharedSecret2);

                                builder.setMessage(UserKeySettings.this.getString(R.string.set_shared_secrets)
                                        + " " + contactInfo[0] + ", " + number.getNumber())
                                        .setTitle(R.string.set_shared_secrets_title).setCancelable(true)
                                        .setPositiveButton(R.string.save,
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int id) {
                                                        //Save the shared secrets

                                                        String s1 = sharedSecret1.getText().toString();
                                                        String s2 = sharedSecret2.getText().toString();
                                                        if (SMSUtility.checksharedSecret(s1)
                                                                && SMSUtility.checksharedSecret(s2)) {
                                                            number.setSharedInfo1(s1);
                                                            number.setSharedInfo2(s2);
                                                            dba.updateNumberRow(number, number.getNumber(),
                                                                    number.getId());

                                                            number.setInitiator(true);
                                                            dba.updateInitiator(number);

                                                            //TODO add check for shared secrets
                                                            String keyExchangeMessage = KeyExchange.sign(number,
                                                                    dba, SMSUtility.user);

                                                            writeToFile(number.getNumber(), keyExchangeMessage);

                                                            Toast.makeText(UserKeySettings.this,
                                                                    UserKeySettings.this
                                                                            .getString(R.string.written_path)
                                                                            + " " + path + "/"
                                                                            + number.getNumber() + "_" + file,
                                                                    Toast.LENGTH_SHORT).show();

                                                        } else {
                                                            Toast.makeText(UserKeySettings.this,
                                                                    R.string.invalid_secrets, Toast.LENGTH_LONG)
                                                                    .show();
                                                        }
                                                    }
                                                })
                                        .setNegativeButton(android.R.string.cancel,
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface arg0, int arg1) {
                                                        //Cancel the key exchange
                                                        Toast.makeText(UserKeySettings.this,
                                                                R.string.key_exchange_cancelled,
                                                                Toast.LENGTH_LONG).show();
                                                    }
                                                });
                                AlertDialog alert = builder.create();

                                alert.setView(linearLayout);
                                alert.show();
                            } else {
                                invalid = true;
                            }
                        } else {
                            invalid = true;
                        }

                        if (invalid) {
                            Toast.makeText(UserKeySettings.this, R.string.invalid_number_message,
                                    Toast.LENGTH_LONG).show();
                        }
                    }
                });

        popup_alert = popup_builder.create();
        popup_alert.show();

        //getExternalFilesDir(null);
    }
}

From source file:org.borderstone.tagtags.TTStartActivity.java

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

    this.setTheme(R.style.AppTheme);
    this.setContentView(R.layout.activity_start);

    Toolbar toolbar = (Toolbar) this.findViewById(R.id.toolbar);
    //toolbar.inflateMenu(R.menu.menu_start);
    toolbar.setTitle("TagTags");

    toolbar.setVisibility(View.VISIBLE);

    TTStartActivity.me = getApplicationContext();

    protocol.setAction("android.intent.action.PROTOCOL");
    settings.setAction("android.intent.action.SETTINGS");

    Constants.init(new File(this.getFilesDir(), "bsettings.txt"), this.getApplicationContext());
    Constants.fileListener = this;

    /*Load variables that are stored in a text file
      keeping version info and info about third party
      resources here, for easy editing*/
    try {//  w  w w.j  a va2s  . co  m
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(this.getResources().openRawResource(R.raw.appinfo)));

        String line = reader.readLine();

        String[] t;
        while (line != null) {
            t = line.split(":");
            if (line.startsWith("#thirdparty:"))
                thirdparty += t[1] + "\n";
            else if (line.startsWith("#recentchanges:"))
                recentchanges += "-- " + t[1] + "\n";

            line = reader.readLine();
        }

        //just to remove the final new line.
        if (!thirdparty.equals(""))
            thirdparty = thirdparty.substring(0, thirdparty.length() - 1);
        if (!recentchanges.equals(""))
            recentchanges = recentchanges.substring(0, recentchanges.length() - 1);
    } catch (Exception ignored) {
    }

    //Most of the code below is purely for aesthetics!

    txtPhilosophy = new BTitleLabel(this);
    txtPhilosophy.setTypeface(Typeface.DEFAULT_BOLD);
    txtPhilosophy.setLayoutParams(Constants.defaultParams);
    txtPhilosophy.setOnClickListener(this);
    txtPhilosophy.setTextColor(Color.BLACK);

    txtVersion = new BStandardLabel(this);
    txtVersion.setText("Recent changes:\n" + recentchanges);
    txtVersion.setLayoutParams(Constants.defaultParams);
    txtVersion.setTextColor(Color.BLACK);

    try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        toolbar.setSubtitle("v. " + pInfo.versionName);
    } catch (PackageManager.NameNotFoundException ignored) {
    }

    toolbar.setNavigationIcon(R.drawable.drawer);

    ImageView slu = new ImageView(this);
    ImageView sites = new ImageView(this);

    slu.setImageResource(R.drawable.slulogo);
    sites.setImageResource(R.drawable.sites);

    LinearLayout llLogos = new LinearLayout(this);
    llLogos.setOrientation(LinearLayout.HORIZONTAL);
    llLogos.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);

    llLogos.addView(slu);
    llLogos.addView(sites);

    setPhiloText();

    LinearLayout back = (LinearLayout) this.findViewById(R.id.back);
    back.setOrientation(LinearLayout.VERTICAL);

    txtPhilosophy.setLayoutParams(Constants.defaultParams);
    txtPhilosophy.setBackgroundResource(R.drawable.border);

    txtVersion.setLayoutParams(Constants.defaultParams);
    txtVersion.setBackgroundResource(R.drawable.border_recurring);

    back.addView(txtPhilosophy);
    back.addView(txtVersion);
    back.addView(llLogos);

    lblSettings = new BButton(this);
    lblDownload = new BButton(this);

    lblDownload.setIcon(R.drawable.download);
    lblSettings.setIcon(R.drawable.settings);

    lblSettings.setText("Settings");
    lblDownload.setText("Download from server");

    lblSettings.setOnClickListener(this);
    lblDownload.setOnClickListener(this);

    if (!checkPermissions()) {
        final Intent intro = new Intent();
        intro.setAction("android.intent.action.INTRO");

        this.startActivity(intro);
    }

    BTitleLabel lblProperties = new BTitleLabel(this);
    BTitleLabel lblLocal = new BTitleLabel(this);
    fileNavView = new BFileNavView(this, this);

    lblProperties.setTextSize(Constants.fontSize + 2);
    lblLocal.setTextSize(Constants.fontSize + 2);

    lblProperties.setText("PROPERTIES");
    lblProperties.setTextColor(Color.WHITE);
    lblProperties.setGravity(Gravity.CENTER);
    lblLocal.setText("LOCAL FILES");
    lblLocal.setTextColor(Color.WHITE);
    lblLocal.setGravity(Gravity.CENTER);

    final DrawerLayout drawerLayout = (DrawerLayout) this.findViewById(R.id.startDrawerLayout);
    final LinearLayout drawer = (LinearLayout) this.findViewById(R.id.drawer);
    drawer.setClickable(false);
    drawer.bringToFront();

    drawer.addView(lblProperties);
    drawer.addView(lblDownload);
    drawer.addView(lblSettings);
    drawer.addView(lblLocal);
    drawer.addView(fileNavView);

    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!drawerLayout.isDrawerOpen(Gravity.LEFT))
                drawerLayout.openDrawer(Gravity.LEFT);
            else
                drawerLayout.closeDrawer(Gravity.LEFT);
        }
    });
}

From source file:org.odk.collect.android.widgets.ImageWebViewWidget.java

public ImageWebViewWidget(Context context, FormEntryPrompt prompt) {
    super(context, prompt);

    mInstanceFolder = Collect.getInstance().getFormController().getInstancePath().getParent();

    TableLayout.LayoutParams params = new TableLayout.LayoutParams();
    params.setMargins(7, 5, 7, 5);/* w  w w  . j  av  a  2  s.c o  m*/

    mErrorTextView = new TextView(context);
    mErrorTextView.setId(QuestionWidget.newUniqueId());
    mErrorTextView.setText("Selected file is not a valid image");

    // setup capture button
    mCaptureButton = new Button(getContext());
    mCaptureButton.setId(QuestionWidget.newUniqueId());
    mCaptureButton.setText(getContext().getString(R.string.capture_image));
    mCaptureButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
    mCaptureButton.setPadding(20, 20, 20, 20);
    mCaptureButton.setEnabled(!prompt.isReadOnly());
    mCaptureButton.setLayoutParams(params);

    // launch capture intent on click
    mCaptureButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "captureButton", "click",
                    mPrompt.getIndex());
            mErrorTextView.setVisibility(View.GONE);
            Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            // We give the camera an absolute filename/path where to put the
            // picture because of bug:
            // http://code.google.com/p/android/issues/detail?id=1480
            // The bug appears to be fixed in Android 2.0+, but as of feb 2,
            // 2010, G1 phones only run 1.6. Without specifying the path the
            // images returned by the camera in 1.6 (and earlier) are ~1/4
            // the size. boo.

            // if this gets modified, the onActivityResult in
            // FormEntyActivity will also need to be updated.
            Uri tempPath = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID + ".provider",
                    new File(Collect.TMPFILE_PATH));
            i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, tempPath);
            try {
                Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex());
                ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CAPTURE);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(getContext(),
                        getContext().getString(R.string.activity_not_found, "image capture"),
                        Toast.LENGTH_SHORT).show();
                Collect.getInstance().getFormController().setIndexWaitingForData(null);
            }

        }
    });

    // setup chooser button
    mChooseButton = new Button(getContext());
    mChooseButton.setId(QuestionWidget.newUniqueId());
    mChooseButton.setText(getContext().getString(R.string.choose_image));
    mChooseButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
    mChooseButton.setPadding(20, 20, 20, 20);
    mChooseButton.setEnabled(!prompt.isReadOnly());
    mChooseButton.setLayoutParams(params);

    // launch capture intent on click
    mChooseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "chooseButton", "click",
                    mPrompt.getIndex());
            mErrorTextView.setVisibility(View.GONE);
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.setType("image/*");

            try {
                Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex());
                ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CHOOSER);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(getContext(),
                        getContext().getString(R.string.activity_not_found, "choose image"), Toast.LENGTH_SHORT)
                        .show();
                Collect.getInstance().getFormController().setIndexWaitingForData(null);
            }

        }
    });

    // finish complex layout
    LinearLayout answerLayout = new LinearLayout(getContext());
    answerLayout.setOrientation(LinearLayout.VERTICAL);
    answerLayout.addView(mCaptureButton);
    answerLayout.addView(mChooseButton);
    answerLayout.addView(mErrorTextView);

    // and hide the capture and choose button if read-only
    if (prompt.isReadOnly()) {
        mCaptureButton.setVisibility(View.GONE);
        mChooseButton.setVisibility(View.GONE);
    }
    mErrorTextView.setVisibility(View.GONE);

    // retrieve answer from data model and update ui
    mBinaryName = prompt.getAnswerText();

    // Only add the imageView if the user has taken a picture
    if (mBinaryName != null) {
        mImageDisplay = new WebView(getContext());
        mImageDisplay.setId(QuestionWidget.newUniqueId());
        mImageDisplay.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        mImageDisplay.getSettings().setBuiltInZoomControls(true);
        mImageDisplay.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
        mImageDisplay.setVisibility(View.VISIBLE);
        mImageDisplay.setLayoutParams(params);

        // HTML is used to display the image.
        String html = "<body>" + constructImageElement() + "</body>";

        mImageDisplay.loadDataWithBaseURL("file:///" + mInstanceFolder + File.separator, html, "text/html",
                "utf-8", "");
        answerLayout.addView(mImageDisplay);
    }
    addAnswerView(answerLayout);
}

From source file:org.odk.collect.android.widgets.ImageWidget.java

public ImageWidget(Context context, FormEntryPrompt prompt) {
    super(context, prompt);

    mInstanceFolder = Collect.getInstance().getFormController().getInstancePath().getParent();

    TableLayout.LayoutParams params = new TableLayout.LayoutParams();
    params.setMargins(7, 5, 7, 5);/*from www  . ja v a 2s . co  m*/

    mErrorTextView = new TextView(context);
    mErrorTextView.setId(QuestionWidget.newUniqueId());
    mErrorTextView.setText("Selected file is not a valid image");

    // setup capture button
    mCaptureButton = new Button(getContext());
    mCaptureButton.setId(QuestionWidget.newUniqueId());
    mCaptureButton.setText(getContext().getString(R.string.capture_image));
    mCaptureButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
    mCaptureButton.setPadding(20, 20, 20, 20);
    mCaptureButton.setEnabled(!prompt.isReadOnly());
    mCaptureButton.setLayoutParams(params);

    // launch capture intent on click
    mCaptureButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "captureButton", "click",
                    mPrompt.getIndex());
            mErrorTextView.setVisibility(View.GONE);
            Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            // We give the camera an absolute filename/path where to put the
            // picture because of bug:
            // http://code.google.com/p/android/issues/detail?id=1480
            // The bug appears to be fixed in Android 2.0+, but as of feb 2,
            // 2010, G1 phones only run 1.6. Without specifying the path the
            // images returned by the camera in 1.6 (and earlier) are ~1/4
            // the size. boo.

            // if this gets modified, the onActivityResult in
            // FormEntyActivity will also need to be updated.
            i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(getContext(),
                    BuildConfig.APPLICATION_ID + ".provider", new File(Collect.TMPFILE_PATH)));
            try {
                Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex());
                ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CAPTURE);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(getContext(),
                        getContext().getString(R.string.activity_not_found, "image capture"),
                        Toast.LENGTH_SHORT).show();
                Collect.getInstance().getFormController().setIndexWaitingForData(null);
            }

        }
    });

    // setup chooser button
    mChooseButton = new Button(getContext());
    mChooseButton.setId(QuestionWidget.newUniqueId());
    mChooseButton.setText(getContext().getString(R.string.choose_image));
    mChooseButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
    mChooseButton.setPadding(20, 20, 20, 20);
    mChooseButton.setEnabled(!prompt.isReadOnly());
    mChooseButton.setLayoutParams(params);

    // launch capture intent on click
    mChooseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "chooseButton", "click",
                    mPrompt.getIndex());
            mErrorTextView.setVisibility(View.GONE);
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.setType("image/*");

            try {
                Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex());
                ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CHOOSER);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(getContext(),
                        getContext().getString(R.string.activity_not_found, "choose image"), Toast.LENGTH_SHORT)
                        .show();
                Collect.getInstance().getFormController().setIndexWaitingForData(null);
            }

        }
    });

    // finish complex layout
    LinearLayout answerLayout = new LinearLayout(getContext());
    answerLayout.setOrientation(LinearLayout.VERTICAL);
    answerLayout.addView(mCaptureButton);
    answerLayout.addView(mChooseButton);
    answerLayout.addView(mErrorTextView);

    // and hide the capture and choose button if read-only
    if (prompt.isReadOnly()) {
        mCaptureButton.setVisibility(View.GONE);
        mChooseButton.setVisibility(View.GONE);
    }
    mErrorTextView.setVisibility(View.GONE);

    // retrieve answer from data model and update ui
    mBinaryName = prompt.getAnswerText();

    // Only add the imageView if the user has taken a picture
    if (mBinaryName != null) {
        mImageView = new ImageView(getContext());
        mImageView.setId(QuestionWidget.newUniqueId());
        Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay();
        int screenWidth = display.getWidth();
        int screenHeight = display.getHeight();

        File f = new File(mInstanceFolder + File.separator + mBinaryName);

        if (f.exists()) {
            Bitmap bmp = FileUtils.getBitmapScaledToDisplay(f, screenHeight, screenWidth);
            if (bmp == null) {
                mErrorTextView.setVisibility(View.VISIBLE);
            }
            mImageView.setImageBitmap(bmp);
        } else {
            mImageView.setImageBitmap(null);
        }

        mImageView.setPadding(10, 10, 10, 10);
        mImageView.setAdjustViewBounds(true);
        mImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Collect.getInstance().getActivityLogger().logInstanceAction(this, "viewButton", "click",
                        mPrompt.getIndex());
                Intent i = new Intent("android.intent.action.VIEW");
                Uri uri = MediaUtils
                        .getImageUriFromMediaProvider(mInstanceFolder + File.separator + mBinaryName);
                if (uri != null) {
                    Log.i(t, "setting view path to: " + uri);
                    i.setDataAndType(uri, "image/*");
                    try {
                        getContext().startActivity(i);
                    } catch (ActivityNotFoundException e) {
                        Toast.makeText(getContext(),
                                getContext().getString(R.string.activity_not_found, "view image"),
                                Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });
        answerLayout.addView(mImageView);
    }
    addAnswerView(answerLayout);
}

From source file:net.peterkuterna.android.apps.devoxxsched.ui.GridFragment.java

/**
 * Provide default implementation to return a simple grid view. Subclasses
 * can override to replace with their own layout. If doing so, the returned
 * view hierarchy <em>must</em> have a GridView whose id is
 * {@link android.R.id#list android.R.id.list} and can optionally have a
 * sibling view id {@link android.R.id#empty android.R.id.empty} that is to
 * be shown when the list is empty.// w  ww.  java 2  s . c  om
 * 
 * <p>
 * If you are overriding this method with your own custom content, consider
 * including the standard layout {@link android.R.layout#list_content} in
 * your layout file, so that you continue to retain all of the standard
 * behavior of GridFragment. In particular, this is currently the only way
 * to have the built-in indeterminant progress state be shown.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    // ------------------------------------------------------------------

    FrameLayout gframe = new FrameLayout(context);
    gframe.setId(INTERNAL_GRID_CONTAINER_ID);

    TextView tv = new TextView(context);
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    gframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    GridView gv = new GridView(context);
    gv.setId(android.R.id.list);
    gv.setDrawSelectorOnTop(false);
    gframe.addView(gv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    root.addView(gframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    return root;
}

From source file:fr.cph.chicago.core.activity.StationActivity.java

/**
 * Draw line/* www  . ja v  a2 s .  c  om*/
 *
 * @param eta the eta
 */
public void drawAllArrivalsTrain(@NonNull final Eta eta) {
    final TrainLine line = eta.getRouteName();
    final Stop stop = eta.getStop();
    final String key = line.toString() + "_" + stop.getDirection().toString();
    // viewId might be not there if CTA API provide wrong data
    if (ids.containsKey(key)) {
        final int viewId = ids.get(key);
        final LinearLayout line3View = (LinearLayout) findViewById(viewId);
        final Integer id = ids
                .get(line.toString() + "_" + stop.getDirection().toString() + "_" + eta.getDestName());
        if (id == null) {
            final LinearLayout insideLayout = new LinearLayout(this);
            insideLayout.setOrientation(LinearLayout.HORIZONTAL);
            insideLayout.setLayoutParams(paramsStop);
            final int newId = Util.generateViewId();
            insideLayout.setId(newId);
            ids.put(line.toString() + "_" + stop.getDirection().toString() + "_" + eta.getDestName(), newId);

            final TextView stopName = new TextView(this);
            final String stopNameData = eta.getDestName() + ": ";
            stopName.setText(stopNameData);
            stopName.setTextColor(grey);
            stopName.setPadding(line3PaddingLeft, line3PaddingTop, 0, 0);
            insideLayout.addView(stopName);

            final TextView timing = new TextView(this);
            final String timingData = eta.getTimeLeftDueDelay() + " ";
            timing.setText(timingData);
            timing.setTextColor(grey);
            timing.setLines(1);
            timing.setEllipsize(TruncateAt.END);
            insideLayout.addView(timing);

            line3View.addView(insideLayout);
        } else {
            final LinearLayout insideLayout = (LinearLayout) findViewById(id);
            final TextView timing = (TextView) insideLayout.getChildAt(1);
            final String timingData = timing.getText() + eta.getTimeLeftDueDelay() + " ";
            timing.setText(timingData);
        }
        line3View.setVisibility(View.VISIBLE);
    }
}