Example usage for android.provider Browser EXTRA_HEADERS

List of usage examples for android.provider Browser EXTRA_HEADERS

Introduction

In this page you can find the example usage for android.provider Browser EXTRA_HEADERS.

Prototype

String EXTRA_HEADERS

To view the source code for android.provider Browser EXTRA_HEADERS.

Click Source Link

Document

The name of the extra data in the VIEW intent.

Usage

From source file:net.wrolf.android.outages.OutageListFragment.java

/**
 * Load an outage in the default browser when selected by the user.
 *//*from   w  w w . j a  va 2 s.  c  o  m*/
@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
    super.onListItemClick(listView, view, position, id);

    // Get a URI for the selected item, then start an Activity that displays the URI. Any
    // Activity that filters for ACTION_VIEW and a URI can accept this. In most cases, this will
    // be a browser.

    // Get the item at the selected position, in the form of a Cursor.
    Cursor c = (Cursor) mAdapter.getItem(position);

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());

    String method = sharedPref.getString("method_list", "");
    String server = sharedPref.getString("server", "");

    String prefix;
    if (method.equals("http")) {
        prefix = "http://" + server;
    } else if (method.equals("https")) {
        prefix = "https://" + server;
    } else if (method.equals("http8960")) {
        prefix = "http://" + server + ":8960";
    } else { // method == https8443
        prefix = "https://" + server + ":8443";
    }

    String outageUrlString = prefix + "/opennms/outage/detail.htm?id="
            + Long.toString(c.getLong(COLUMN_OUTAGE_ID));
    Log.i(TAG, "Opening URL: " + outageUrlString);

    final String user = sharedPref.getString("user", "");
    Log.d(TAG, "user: " + user);
    final String password = sharedPref.getString("password", "");
    Log.d(TAG, "password: " + password);

    Uri outageURI = Uri.parse(outageUrlString);

    Intent i = new Intent(Intent.ACTION_VIEW, outageURI);

    String authorization = user + ":" + password;
    String authorizationBase64 = Base64.encodeToString(authorization.getBytes(), 0);

    Bundle bundle = new Bundle();
    bundle.putString("Authorization", "Basic " + authorizationBase64);
    i.putExtra(Browser.EXTRA_HEADERS, bundle);
    Log.d(TAG, "intent:" + i.toString());

    startActivity(i);

}

From source file:com.i2max.i2smartwork.common.work.WorkDetailViewFragment.java

public void setFilesLayout(String title, LinearLayout targetLayout, Object object) {
    final List<LinkedTreeMap<String, String>> filesList = (List<LinkedTreeMap<String, String>>) object;
    if (filesList == null || filesList.size() <= 0) {
        targetLayout.setVisibility(View.GONE);
    } else {/*from  ww w  .j  a  va2s .c o  m*/
        Log.e(TAG, "fileList size =" + filesList.size());
        targetLayout.setVisibility(View.VISIBLE);
        targetLayout.removeAllViews();
        //addTitleView
        LinearLayout.LayoutParams tvParam = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        tvParam.setMargins(0, DisplayUtil.dip2px(getActivity(), 12), 0, DisplayUtil.dip2px(getActivity(), 10));

        TextView tvTitle = new TextView(getActivity());
        tvTitle.setLayoutParams(tvParam);
        if (Build.VERSION.SDK_INT < 23) {
            tvTitle.setTextAppearance(getActivity(), android.R.style.TextAppearance_Material_Medium);
        } else {
            tvTitle.setTextAppearance(android.R.style.TextAppearance_Material_Medium);
        }
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
        tvTitle.setTextColor(getResources().getColor(R.color.text_color_black));
        tvTitle.setText(title);

        targetLayout.addView(tvTitle);

        //addFilesView
        for (int i = 0; i < filesList.size(); i++) {
            final LinkedTreeMap<String, String> fileMap = filesList.get(i);
            LayoutInflater inflater = (LayoutInflater) getActivity()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View fileView = inflater.inflate(R.layout.view_item_file, null);

            ImageView ivIcFileExt = (ImageView) fileView.findViewById(R.id.iv_ic_file_ext);
            TextView tvFileNm = (TextView) fileView.findViewById(R.id.tv_file_nm);

            //??  ? 
            ivIcFileExt.setImageResource(R.drawable.ic_file_doc);
            String fileNm = FormatUtil.getStringValidate(fileMap.get("file_nm"));
            tvFileNm.setText(fileNm);
            FileUtil.setFileExtIcon(ivIcFileExt, fileNm);
            final String fileExt = FileUtil.getFileExtsion(fileNm);
            final String downloadURL = I2UrlHelper.File
                    .getDownloadFile(FormatUtil.getStringValidate(fileMap.get("file_id")));

            fileView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = null;
                    if ("Y".equals(FormatUtil.getStringValidate(fileMap.get("conv_yn")))) {
                        //i2viewer ? ( conv_yn='Y')
                        intent = IntentUtil.getI2ViewerIntent(
                                FormatUtil.getStringValidate(fileMap.get("file_id")),
                                FormatUtil.getStringValidate(fileMap.get("file_nm")));
                        getActivity().startActivity(intent);
                    } else if ("mp4".equalsIgnoreCase(fileExt) || "fla".equalsIgnoreCase(fileExt)
                            || "wmv".equalsIgnoreCase(fileExt) || "avi".equalsIgnoreCase(fileExt)) { //video
                        intent = IntentUtil.getVideoPlayIntent(downloadURL);
                    } else {
                        //? ??
                        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(downloadURL));
                        Bundle bundle = new Bundle();
                        bundle.putString("Authorization", I2UrlHelper.getTokenAuthorization());
                        intent.putExtra(Browser.EXTRA_HEADERS, bundle);
                        Log.d(TAG, "intent:" + intent.toString());
                    }
                    getActivity().startActivity(intent);

                }
            });

            targetLayout.addView(fileView);
        }

    }
}

From source file:com.i2max.i2smartwork.common.conference.ConferenceDetailViewFragment.java

public void setFilesLayout(String title, LinearLayout targetLayout, Object object) {

    final List<LinkedTreeMap<String, String>> filesList = (List<LinkedTreeMap<String, String>>) object;
    if (filesList == null || (filesList != null && filesList.size() <= 0)) {
        targetLayout.setVisibility(View.GONE);
    } else {//from  w  ww.j a  va  2s .  c om
        Log.e(TAG, "fileList size =" + filesList.size());
        targetLayout.setVisibility(View.VISIBLE);
        targetLayout.removeAllViews();
        //addTitleView
        LinearLayout.LayoutParams tvParam = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        tvParam.setMargins(0, DisplayUtil.dip2px(getActivity(), 12), 0, DisplayUtil.dip2px(getActivity(), 10));

        TextView tvTitle = new TextView(getActivity());
        tvTitle.setLayoutParams(tvParam);
        if (Build.VERSION.SDK_INT < 23) {
            tvTitle.setTextAppearance(getActivity(), android.R.style.TextAppearance_Material_Medium);
        } else {
            tvTitle.setTextAppearance(android.R.style.TextAppearance_Material_Medium);
        }
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
        tvTitle.setTextColor(getResources().getColor(R.color.text_color_black));
        tvTitle.setText(title);

        targetLayout.addView(tvTitle);

        //addFilesView
        for (int i = 0; i < filesList.size(); i++) {
            final LinkedTreeMap<String, String> fileMap = filesList.get(i);
            LayoutInflater inflater = (LayoutInflater) getActivity()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View fileView = inflater.inflate(R.layout.view_item_file, null);

            ImageView ivIcFileExt = (ImageView) fileView.findViewById(R.id.iv_ic_file_ext);
            TextView tvFileNm = (TextView) fileView.findViewById(R.id.tv_file_nm);

            //??  ? 
            ivIcFileExt.setImageResource(R.drawable.ic_file_doc);
            String fileNm = FormatUtil.getStringValidate(fileMap.get("file_nm"));
            tvFileNm.setText(fileNm);
            FileUtil.setFileExtIcon(ivIcFileExt, fileNm);
            final String fileExt = FileUtil.getFileExtsion(fileNm);
            final String downloadURL = I2UrlHelper.File
                    .getDownloadFile(FormatUtil.getStringValidate(fileMap.get("file_id")));

            fileView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    try {
                        Intent intent = null;
                        if ("Y".equals(FormatUtil.getStringValidate(fileMap.get("conv_yn")))) {
                            //i2viewer ? ( conv_yn='Y')
                            intent = IntentUtil.getI2ViewerIntent(
                                    FormatUtil.getStringValidate(fileMap.get("file_id")),
                                    FormatUtil.getStringValidate(fileMap.get("file_nm")));
                            getActivity().startActivity(intent);
                        } else if ("mp4".equalsIgnoreCase(fileExt) || "fla".equalsIgnoreCase(fileExt)
                                || "wmv".equalsIgnoreCase(fileExt) || "avi".equalsIgnoreCase(fileExt)) { //video
                            intent = IntentUtil.getVideoPlayIntent(downloadURL);
                        } else {
                            //? ??
                            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(downloadURL));
                            Bundle bundle = new Bundle();
                            bundle.putString("Authorization", I2UrlHelper.getTokenAuthorization());
                            intent.putExtra(Browser.EXTRA_HEADERS, bundle);
                            Log.d(TAG, "intent:" + intent.toString());
                        }
                        getActivity().startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        Toast.makeText(getActivity(),
                                "I2Viewer? ?  .\n  ? ?.",
                                Toast.LENGTH_LONG).show();
                        //TODO ? ? ?   URL
                    }
                }
            });

            targetLayout.addView(fileView);
        }

    }
}