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:fr.cph.chicago.core.activity.StationActivity.java

@SuppressWarnings("unchecked")
private void setUpStopLayouts(@NonNull final Map<TrainLine, List<Stop>> stopByLines) {
    Stream.of(stopByLines.entrySet()).forEach(entry -> {
        final TrainLine line = entry.getKey();
        final List<Stop> stops = entry.getValue();
        final View lineTitleView = getLayoutInflater().inflate(R.layout.activity_station_line_title, viewGroup,
                false);// www. ja v  a  2  s  .  c  om

        final TextView testView = (TextView) lineTitleView.findViewById(R.id.train_line_title);
        testView.setText(line.toStringWithLine());
        testView.setBackgroundColor(line.getColor());
        if (line == TrainLine.YELLOW) {
            testView.setBackgroundColor(yellowLine);
        }

        stopsView.addView(lineTitleView);

        Stream.of(stops).sorted().forEach(stop -> {
            final LinearLayout linearLayout = new LinearLayout(this);
            linearLayout.setOrientation(LinearLayout.HORIZONTAL);
            linearLayout.setLayoutParams(paramsStop);

            final AppCompatCheckBox checkBox = new AppCompatCheckBox(this);
            checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> Preferences
                    .saveTrainFilter(getApplicationContext(), stationId, line, stop.getDirection(), isChecked));
            checkBox.setOnClickListener(v -> {
                if (checkBox.isChecked()) {
                    trainArrivalObservable.subscribe(new SubscriberTrainArrival(this, swipeRefreshLayout));
                }
            });
            checkBox.setChecked(
                    Preferences.getTrainFilter(getApplicationContext(), stationId, line, stop.getDirection()));
            checkBox.setTypeface(checkBox.getTypeface(), Typeface.BOLD);
            checkBox.setText(stop.getDirection().toString());
            checkBox.setTextColor(grey);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                checkBox.setBackgroundTintList(ColorStateList.valueOf(line.getColor()));
                checkBox.setButtonTintList(ColorStateList.valueOf(line.getColor()));
                if (line == TrainLine.YELLOW) {
                    checkBox.setBackgroundTintList(ColorStateList.valueOf(yellowLine));
                    checkBox.setButtonTintList(ColorStateList.valueOf(yellowLine));
                }
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                checkBox.setForegroundTintList(ColorStateList.valueOf(line.getColor()));
                if (line == TrainLine.YELLOW) {
                    checkBox.setForegroundTintList(ColorStateList.valueOf(yellowLine));
                }
            }

            linearLayout.addView(checkBox);

            final LinearLayout arrivalTrainsLayout = new LinearLayout(this);
            arrivalTrainsLayout.setOrientation(LinearLayout.VERTICAL);
            arrivalTrainsLayout.setLayoutParams(paramsStop);
            int id = Util.generateViewId();
            arrivalTrainsLayout.setId(id);
            ids.put(line.toString() + "_" + stop.getDirection().toString(), id);

            linearLayout.addView(arrivalTrainsLayout);
            stopsView.addView(linearLayout);
        });
    });
}

From source file:com.example.android.naradaoffline.DatagramFragment.java

/**
 * Set up the UI and background operations for chat.
 */// ww w . ja va2  s  .  c  om
private void setupChat() {
    Log.d(TAG);

    // Initialize the array adapter for the conversation thread
    mConversationArrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.message);

    //mConversationView.setAdapter(mConversationArrayAdapter);

    // Initialize the compose field with a listener for the return key
    //        mOutEditText.setOnEditorActionListener(mWriteListener);

    // Initialize the send button with a listener that for click events

    mGetNewsPaper.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Send a message using content of the edit text widget
            View view = getView();
            if (null != view) {

                //                    TextView textView = (TextView) view.findViewById(R.id.edit_text_out);
                DatagramRequest d = new DatagramRequest(DatagramRequestType.GET_NEWSPAPER,
                        mConnectedDeviceName);
                sendDatagramRequest(d);
            }
        }
    });

    // Initialize the send button with a listener that for click events
    mGetEmail.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Send a message using content of the edit text widget
            View view = getView();
            if (null != view) {
                //                    TextView textView = (TextView) view.findViewById(R.id.edit_text_out);

                Log.i(TAG, "button clicked");

                AlertDialog.Builder builder = new AlertDialog.Builder(DatagramFragment.this.getContext());
                builder.setTitle("Write your email here");

                LinearLayout layout = new LinearLayout(getContext());
                layout.setOrientation(LinearLayout.VERTICAL);

                // Set up the input
                final EditText email = new EditText(DatagramFragment.this.getContext());
                email.setHint("Recipient e-mail address");
                // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
                email.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
                layout.addView(email);
                final EditText input = new EditText(DatagramFragment.this.getContext());
                // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
                input.setHint("Type your e-mail here");
                input.setInputType(InputType.TYPE_CLASS_TEXT);
                layout.addView(input);

                builder.setView(layout);
                // Set up the buttons
                builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mEmail = email.getText().toString();
                        mText = input.getText().toString();
                        DatagramRequest d = new DatagramRequest(DatagramRequestType.SEND_EMAIL,
                                mConnectedDeviceName, "", mEmail, mText);
                        sendDatagramRequest(d);

                    }
                });
                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });

                builder.show();

            }
        }
    });

    // Initialize the BluetoothDatagramService to perform bluetooth connections
    mChatService = new BluetoothDatagramService(getActivity(), mHandler);

    // Initialize the buffer for outgoing messages
    mOutStringBuffer = new StringBuffer("");
}

From source file:au.com.cybersearch2.classyfy.TitleSearchResultsActivityTest.java

@Test
public void test_dynamic_layout() throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS", new Locale("en", "AU"));
    RecordCategory recordCategory = new RecordCategory();
    Date created = sdf.parse("2014-02-05 18:45:46.145000");
    Date modified = sdf.parse("2014-02-12 11:55:23.121000");
    recordCategory.setCreated(created);//from   w w  w . j av  a 2  s  .  co m
    recordCategory.setModified(modified);
    recordCategory.setCreator("admin");
    recordCategory.setDescription("Information Technology");
    recordCategory.setIdentifier("2014-1391586274589");
    FieldDescriptor descriptionField = new FieldDescriptor();
    descriptionField.setOrder(1);
    descriptionField.setName("description");
    descriptionField.setTitle("Description");
    FieldDescriptor createdField = new FieldDescriptor();
    createdField.setOrder(2);
    createdField.setName("created");
    createdField.setTitle("Created");
    FieldDescriptor creatorField = new FieldDescriptor();
    creatorField.setOrder(3);
    creatorField.setName("creator");
    creatorField.setTitle("Creator");
    FieldDescriptor modifiedField = new FieldDescriptor();
    modifiedField.setOrder(4);
    modifiedField.setName("modified");
    modifiedField.setTitle("Modified");
    FieldDescriptor modifier = new FieldDescriptor();
    modifier.setOrder(5);
    modifier.setName("modifier");
    modifier.setTitle("Modifier");
    FieldDescriptor identifierField = new FieldDescriptor();
    identifierField.setOrder(6);
    identifierField.setName("identifier");
    identifierField.setTitle("Identifier");
    Set<FieldDescriptor> fieldSet = new TreeSet<FieldDescriptor>();
    fieldSet.add(descriptionField);
    fieldSet.add(createdField);
    fieldSet.add(creatorField);
    fieldSet.add(modifiedField);
    fieldSet.add(modifier);
    fieldSet.add(identifierField);
    @SuppressWarnings("unchecked")
    Map<String, Object> valueMap = PropertyUtils.describe(recordCategory);
    titleSearchResultsActivity = (TitleSearchResultsActivity) controller.create().get();
    LinearLayout dynamicLayout = new LinearLayout(titleSearchResultsActivity);
    dynamicLayout.setOrientation(LinearLayout.VERTICAL);
    int layoutHeight = LinearLayout.LayoutParams.MATCH_PARENT;
    int layoutWidth = LinearLayout.LayoutParams.WRAP_CONTENT;
    for (FieldDescriptor descriptor : fieldSet) {
        Object value = valueMap.get(descriptor.getName());
        if (value == null)
            continue;
        TextView titleView = new TextView(titleSearchResultsActivity);
        titleView.setText(descriptor.getTitle());
        TextView valueView = new TextView(titleSearchResultsActivity);
        valueView.setText(value.toString());
        LinearLayout fieldLayout = new LinearLayout(titleSearchResultsActivity);
        fieldLayout.setOrientation(LinearLayout.HORIZONTAL);
        fieldLayout.addView(titleView, new LinearLayout.LayoutParams(layoutWidth, layoutHeight));
        fieldLayout.addView(valueView, new LinearLayout.LayoutParams(layoutWidth, layoutHeight));
    }
}

From source file:com.example.damerap_ver1.IntroVideoActivity.java

/**
* Create the view in which the video will be rendered.
*//*  www.  jav  a2  s . c  om*/
private void setupView() {
    LinearLayout lLinLayout = new LinearLayout(this);
    lLinLayout.setId(1);
    lLinLayout.setOrientation(LinearLayout.VERTICAL);
    lLinLayout.setGravity(Gravity.CENTER);
    lLinLayout.setBackgroundColor(Color.BLACK);

    LayoutParams lLinLayoutParms = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT);
    lLinLayout.setLayoutParams(lLinLayoutParms);

    this.setContentView(lLinLayout);

    RelativeLayout lRelLayout = new RelativeLayout(this);
    lRelLayout.setId(2);
    lRelLayout.setGravity(Gravity.CENTER);
    lRelLayout.setBackgroundColor(Color.BLACK);
    android.widget.RelativeLayout.LayoutParams lRelLayoutParms = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
    lRelLayout.setLayoutParams(lRelLayoutParms);
    lLinLayout.addView(lRelLayout);

    mVideoView = new VideoView(this);
    mVideoView.setId(3);
    android.widget.RelativeLayout.LayoutParams lVidViewLayoutParams = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lVidViewLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    mVideoView.setLayoutParams(lVidViewLayoutParams);
    lRelLayout.addView(mVideoView);

    mProgressBar = new ProgressBar(this);
    mProgressBar.setId(4);
    android.widget.RelativeLayout.LayoutParams lProgressBarLayoutParms = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lProgressBarLayoutParms.addRule(RelativeLayout.CENTER_IN_PARENT);
    mProgressBar.setLayoutParams(lProgressBarLayoutParms);
    lRelLayout.addView(mProgressBar);

    mProgressMessage = new TextView(this);
    mProgressMessage.setId(5);
    android.widget.RelativeLayout.LayoutParams lProgressMsgLayoutParms = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lProgressMsgLayoutParms.addRule(RelativeLayout.CENTER_HORIZONTAL);
    lProgressMsgLayoutParms.addRule(RelativeLayout.BELOW, 4);
    mProgressMessage.setLayoutParams(lProgressMsgLayoutParms);
    mProgressMessage.setTextColor(Color.LTGRAY);
    mProgressMessage.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8);
    mProgressMessage.setText("...");
    lRelLayout.addView(mProgressMessage);
}

From source file:org.getlantern.firetweet.activity.support.SignInActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE);
    mResolver = getContentResolver();//from w ww  .  j  a  va2 s .  c om
    mApplication = FiretweetApplication.getInstance(this);
    setContentView(R.layout.activity_sign_in);
    setSupportProgressBarIndeterminateVisibility(false);
    final long[] account_ids = getActivatedAccountIds(this);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(account_ids.length > 0);
    }

    if (savedInstanceState != null) {
        mAPIUrlFormat = savedInstanceState.getString(Accounts.API_URL_FORMAT);
        mAuthType = savedInstanceState.getInt(Accounts.AUTH_TYPE);
        mSameOAuthSigningUrl = savedInstanceState.getBoolean(Accounts.SAME_OAUTH_SIGNING_URL);
        mConsumerKey = trim(savedInstanceState.getString(Accounts.CONSUMER_KEY));
        mConsumerSecret = trim(savedInstanceState.getString(Accounts.CONSUMER_SECRET));
        mUsername = savedInstanceState.getString(Accounts.SCREEN_NAME);
        mPassword = savedInstanceState.getString(Accounts.PASSWORD);
        mAPIChangeTimestamp = savedInstanceState.getLong(EXTRA_API_LAST_CHANGE);
    }

    Typeface font = Typeface.createFromAsset(getAssets(), "fonts/ProximaNova-Semibold.ttf");

    mSigninSignupContainer.setOrientation(
            mAuthType == Accounts.AUTH_TYPE_TWIP_O_MODE ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL);

    final Resources resources = getResources();
    final ColorStateList color = ColorStateList.valueOf(resources.getColor(R.color.material_light_blue));

    mSignInButton.setTextColor(Color.parseColor("#38c6f3"));
    mSignInButton.setBackgroundColor(Color.parseColor("#E7E7E7"));
    mSignInButton.setBackgroundResource(R.drawable.sign_in_btn);
    mSignInButton.setTypeface(font);
    mSignUpButton.setTypeface(font);
    poweredByButton.setTypeface(font);

    autoTweetCheckBox = (CheckBox) findViewById(R.id.autotweet_checkbox);
    autoTweetText = (TextView) findViewById(R.id.should_send_autotweet);

    // don't display the auto tweet text on subsequent runs
    if (mPreferences.contains(APP_RAN_BEFORE)) {
        autoTweetCheckBox.setVisibility(View.GONE);
        autoTweetText.setVisibility(View.GONE);
    } else {
        // the checkbox color attribute isn't a simple attribute
        // we have to grab the default checkbox and apply a color filter
        int id = Resources.getSystem().getIdentifier("btn_check_holo_light", "drawable", "android");
        Drawable drawable = ResourcesCompat.getDrawable(getResources(), id, null);
        if (drawable != null) {
            drawable.setColorFilter(Color.parseColor("white"), PorterDuff.Mode.SRC_ATOP);
            autoTweetCheckBox.setButtonDrawable(drawable);
        }

        autoTweetText.setTypeface(font);
        autoTweetText.setTextColor(Color.parseColor("white"));
    }

    setSignInButton();
}

From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // handle item selection
    final Activity activity = getActivity();
    switch (item.getItemId()) {
    case R.id.action_sort:
        return true;
    case R.id.menuSortNewest:
        sort = "New";
        refreshComments();/*from w w w . ja v  a2s .c  om*/
        activity.invalidateOptionsMenu();
        return true;
    case R.id.menuSortTop:
        sort = "Top";
        refreshComments();
        activity.invalidateOptionsMenu();
        return true;
    case R.id.menuSortBest:
        sort = "Best";
        refreshComments();
        activity.invalidateOptionsMenu();
        return true;
    case R.id.action_refresh:
        refreshComments();
        return true;
    case R.id.action_submit:
        final EditText newGalleryTitle = new EditText(activity);
        newGalleryTitle.setHint("Title");
        newGalleryTitle.setSingleLine();
        new AlertDialog.Builder(activity).setTitle("Set Gallery Title/Press OK to remove")
                .setView(newGalleryTitle)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        if (newGalleryTitle.getText() == null)
                            return;
                        HashMap<String, Object> galleryMap = new HashMap<String, Object>();
                        galleryMap.put("terms", "1");
                        galleryMap.put(ImgurHoloActivity.IMAGE_DATA_TITLE,
                                newGalleryTitle.getText().toString());
                        newGalleryString = newGalleryTitle.getText().toString();
                        try {
                            Fetcher fetcher = new Fetcher(singleImageFragment,
                                    "3/gallery/image/" + imageData.getJSONObject().getString("id"), ApiCall.GET,
                                    galleryMap, ((ImgurHoloActivity) getActivity()).getApiCall(), GALLERY);
                            fetcher.execute();
                        } catch (Exception e) {
                            Log.e("Error!", e.toString());
                        }
                    }
                }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Do nothing.
                    }
                }).show();

        return true;
    case R.id.action_edit:
        try {
            final EditText newTitle = new EditText(activity);
            newTitle.setSingleLine();
            if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE).equals("null"))
                newTitle.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE));
            final EditText newBody = new EditText(activity);
            newBody.setHint(R.string.body_hint_description);
            newTitle.setHint(R.string.body_hint_title);
            if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION).equals("null"))
                newBody.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION));
            LinearLayout linearLayout = new LinearLayout(activity);
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            linearLayout.addView(newTitle);
            linearLayout.addView(newBody);
            new AlertDialog.Builder(activity).setTitle(R.string.dialog_edit_title).setView(linearLayout)
                    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            TextView imageTitle = (TextView) imageLayoutView
                                    .findViewById(R.id.single_image_title);
                            TextView imageDescription = (TextView) imageLayoutView
                                    .findViewById(R.id.single_image_description);
                            if (newTitle.getText() != null && !newTitle.getText().toString().equals("")) {
                                imageTitle.setText(newTitle.getText().toString());
                                imageTitle.setVisibility(View.VISIBLE);
                            } else
                                imageTitle.setVisibility(View.GONE);
                            if (newBody.getText() != null && !newBody.getText().toString().equals("")) {
                                imageDescription.setText(newBody.getText().toString());
                                imageDescription.setVisibility(View.VISIBLE);
                            } else
                                imageDescription.setVisibility(View.GONE);
                            HashMap<String, Object> editImageMap = new HashMap<String, Object>();
                            editImageMap.put(ImgurHoloActivity.IMAGE_DATA_TITLE, newTitle.getText().toString());
                            editImageMap.put(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION,
                                    newBody.getText().toString());
                            try {
                                Fetcher fetcher = new Fetcher(singleImageFragment,
                                        "3/image/" + imageData.getJSONObject().getString("id"), ApiCall.POST,
                                        editImageMap, ((ImgurHoloActivity) getActivity()).getApiCall(),
                                        EDITIMAGE);
                                fetcher.execute();
                            } catch (JSONException e) {
                                Log.e("Error!", e.toString());
                            }
                        }
                    }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            // Do nothing.
                        }
                    }).show();
        } catch (JSONException e) {
            Log.e("Error!", "oops, some image fields missing values" + e.toString());
        }
        return true;
    case R.id.action_download:
        ImageUtils.downloadImage(this, imageData);
        return true;
    case R.id.action_delete:
        new AlertDialog.Builder(activity).setTitle(R.string.dialog_delete_confirmation_title)
                .setMessage(R.string.dialog_delete_confirmation_summary)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        try {
                            Fetcher fetcher = new Fetcher(singleImageFragment,
                                    "3/image/" + imageData.getJSONObject().getString("id"), ApiCall.DELETE,
                                    null, ((ImgurHoloActivity) getActivity()).getApiCall(), DELETE);
                            fetcher.execute();
                        } catch (JSONException e) {
                            Log.e("Error!", e.toString());
                        }
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Do nothing.
                    }
                }).show();
        return true;
    case R.id.action_copy:
        ImageUtils.copyImageURL(this, imageData);
        return true;
    case R.id.action_share:
        ImageUtils.shareImage(this, imageData);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:de.gebatzens.ggvertretungsplan.fragment.RemoteDataFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle bundle) {
    LinearLayout l = new LinearLayout(getActivity());
    l.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    l.setOrientation(LinearLayout.VERTICAL);
    if (GGApp.GG_APP.getDataForFragment(type) != null)
        createRootView(inflater, l);//from  w w  w  .  j  a  v a2 s. c om
    return l;
}

From source file:com.github.wakhub.monodict.activity.FlashcardActivity.java

@UiThread
void showAutoPlayAlertDialog() {
    if (autoPlayDialog != null) {
        return;//from w  w  w  . j  a  va 2s .com
    }

    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    layout.setPadding(20, 20, 20, 20);
    autoPlayDisplayText = new TextView(this);
    autoPlayDisplayText.setTypeface(Typeface.DEFAULT_BOLD);
    layout.addView(autoPlayDisplayText);
    autoPlayTranslateText = new TextView(this);
    autoPlayTranslateText.setText(R.string.message_in_processing);
    layout.addView(autoPlayTranslateText);

    autoPlayDialog = new AlertDialog.Builder(this).setTitle(R.string.action_auto_play)
            .setIcon(R.drawable.ic_action_play).setView(layout)
            .setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialogInterface) {
                    autoPlayDisplayText = null;
                    autoPlayTranslateText = null;
                    stopAutoPlay();
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.cancel();
                }
            }).show();
}

From source file:fr.cph.chicago.core.adapter.FavoritesAdapter.java

private void handleStation(@NonNull final FavoritesViewHolder holder, @NonNull final Station station) {
    final int stationId = station.getId();
    final Set<TrainLine> trainLines = station.getLines();

    holder.favoriteImage.setImageResource(R.drawable.ic_train_white_24dp);
    holder.stationNameTextView.setText(station.getName());
    holder.detailsButton.setOnClickListener(v -> {
        if (!Util.isNetworkAvailable(context)) {
            Util.showNetworkErrorMessage(activity);
        } else {/*from   w w  w.  ja va  2 s .  c om*/
            // Start station activity
            final Bundle extras = new Bundle();
            final Intent intent = new Intent(context, StationActivity.class);
            extras.putInt(activity.getString(R.string.bundle_train_stationId), stationId);
            intent.putExtras(extras);
            activity.startActivity(intent);
        }
    });

    holder.mapButton.setText(activity.getString(R.string.favorites_view_trains));
    holder.mapButton.setOnClickListener(v -> {
        if (!Util.isNetworkAvailable(context)) {
            Util.showNetworkErrorMessage(activity);
        } else {
            if (trainLines.size() == 1) {
                startActivity(trainLines.iterator().next());
            } else {
                final List<Integer> colors = new ArrayList<>();
                final List<String> values = Stream.of(trainLines).flatMap(line -> {
                    final int color = line != TrainLine.YELLOW ? line.getColor()
                            : ContextCompat.getColor(context, R.color.yellowLine);
                    colors.add(color);
                    return Stream.of(line.toStringWithLine());
                }).collect(Collectors.toList());

                final PopupFavoritesTrainAdapter ada = new PopupFavoritesTrainAdapter(activity, values, colors);

                final List<TrainLine> lines = new ArrayList<>();
                lines.addAll(trainLines);

                final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                builder.setAdapter(ada, (dialog, position) -> startActivity(lines.get(position)));

                final int[] screenSize = Util.getScreenSize(context);
                final AlertDialog dialog = builder.create();
                dialog.show();
                if (dialog.getWindow() != null) {
                    dialog.getWindow().setLayout((int) (screenSize[0] * 0.7), LayoutParams.WRAP_CONTENT);
                }
            }
        }
    });

    Stream.of(trainLines).forEach(trainLine -> {
        boolean newLine = true;
        int i = 0;
        final Map<String, StringBuilder> etas = favoritesData.getTrainArrivalByLine(stationId, trainLine);
        for (final Entry<String, StringBuilder> entry : etas.entrySet()) {
            final LinearLayout.LayoutParams containParam = getInsideParams(newLine, i == etas.size() - 1);
            final LinearLayout container = new LinearLayout(context);
            container.setOrientation(LinearLayout.HORIZONTAL);
            container.setLayoutParams(containParam);

            // Left
            final RelativeLayout.LayoutParams leftParam = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            final RelativeLayout left = new RelativeLayout(context);
            left.setLayoutParams(leftParam);

            final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, trainLine);
            int lineId = Util.generateViewId();
            lineIndication.setId(lineId);

            final RelativeLayout.LayoutParams destinationParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            destinationParams.addRule(RelativeLayout.RIGHT_OF, lineId);
            destinationParams.setMargins(pixelsHalf, 0, 0, 0);

            final String destination = entry.getKey();
            final TextView destinationTextView = new TextView(context);
            destinationTextView.setTextColor(grey5);
            destinationTextView.setText(destination);
            destinationTextView.setLines(1);
            destinationTextView.setLayoutParams(destinationParams);

            left.addView(lineIndication);
            left.addView(destinationTextView);

            // Right
            final LinearLayout.LayoutParams rightParams = new LinearLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            rightParams.setMargins(marginLeftPixel, 0, 0, 0);
            final LinearLayout right = new LinearLayout(context);
            right.setOrientation(LinearLayout.VERTICAL);
            right.setLayoutParams(rightParams);

            final StringBuilder currentEtas = entry.getValue();
            final TextView arrivalText = new TextView(context);
            arrivalText.setText(currentEtas);
            arrivalText.setGravity(Gravity.END);
            arrivalText.setSingleLine(true);
            arrivalText.setTextColor(grey5);
            arrivalText.setEllipsize(TextUtils.TruncateAt.END);

            right.addView(arrivalText);

            container.addView(left);
            container.addView(right);

            holder.mainLayout.addView(container);

            newLine = false;
            i++;
        }
    });
}

From source file:jp.ne.sakura.kkkon.android.exceptionhandler.testapp.ExceptionHandlerReportApp.java

/** Called when the activity is first created. */
@Override/*from   www . j  a v a  2  s  .  co  m*/
public void onCreate(Bundle savedInstanceState) {
    final Context context = this.getApplicationContext();

    {
        ExceptionHandler.initialize(context);
        if (ExceptionHandler.needReport()) {
            final String fileName = ExceptionHandler.getBugReportFileAbsolutePath();
            final File file = new File(fileName);
            final File fileZip;
            {
                String strFileZip = file.getAbsolutePath();
                {
                    int index = strFileZip.lastIndexOf('.');
                    if (0 < index) {
                        strFileZip = strFileZip.substring(0, index);
                        strFileZip += ".zip";
                    }
                }
                Log.d(TAG, strFileZip);
                fileZip = new File(strFileZip);
                if (fileZip.exists()) {
                    fileZip.delete();
                }
            }
            if (file.exists()) {
                Log.d(TAG, file.getAbsolutePath());
                InputStream inStream = null;
                ZipOutputStream outStream = null;
                try {
                    inStream = new FileInputStream(file);
                    String strFileName = file.getAbsolutePath();
                    {
                        int index = strFileName.lastIndexOf(File.separatorChar);
                        if (0 < index) {
                            strFileName = strFileName.substring(index + 1);
                        }
                    }
                    Log.d(TAG, strFileName);

                    outStream = new ZipOutputStream(new FileOutputStream(fileZip));
                    byte[] buff = new byte[8124];
                    {
                        ZipEntry entry = new ZipEntry(strFileName);
                        outStream.putNextEntry(entry);

                        int len = 0;
                        while (0 < (len = inStream.read(buff))) {
                            outStream.write(buff, 0, len);
                        }
                        outStream.closeEntry();
                    }
                    outStream.finish();
                    outStream.flush();

                } catch (IOException e) {
                    Log.e(TAG, "got exception", e);
                } finally {
                    if (null != outStream) {
                        try {
                            outStream.close();
                        } catch (Exception e) {
                        }
                    }
                    outStream = null;

                    if (null != inStream) {
                        try {
                            inStream.close();
                        } catch (Exception e) {
                        }
                    }
                    inStream = null;
                }
                Log.i(TAG, "zip created");
            }

            if (file.exists()) {
                // upload or send e-mail
                InputStream inStream = null;
                StringBuilder sb = new StringBuilder();
                try {
                    inStream = new FileInputStream(file);
                    byte[] buff = new byte[8124];
                    int readed = 0;
                    do {
                        readed = inStream.read(buff);
                        for (int i = 0; i < readed; i++) {
                            sb.append((char) buff[i]);
                        }
                    } while (readed >= 0);

                    final String str = sb.toString();
                    Log.i(TAG, str);
                } catch (IOException e) {
                    Log.e(TAG, "got exception", e);
                } finally {
                    if (null != inStream) {
                        try {
                            inStream.close();
                        } catch (Exception e) {
                        }
                    }
                    inStream = null;
                }

                AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
                final Locale defaultLocale = Locale.getDefault();

                String title = "";
                String message = "";
                String positive = "";
                String negative = "";

                boolean needDefaultLang = true;
                if (null != defaultLocale) {
                    if (defaultLocale.equals(Locale.JAPANESE) || defaultLocale.equals(Locale.JAPAN)) {
                        title = "";
                        message = "?????????";
                        positive = "?";
                        negative = "";
                        needDefaultLang = false;
                    }
                }
                if (needDefaultLang) {
                    title = "ERROR";
                    message = "Got unexpected error. Do you want to send information of error.";
                    positive = "Send";
                    negative = "Cancel";
                }
                alertDialog.setTitle(title);
                alertDialog.setMessage(message);
                alertDialog.setPositiveButton(positive + " mail", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface di, int i) {
                        DefaultUploaderMailClient.upload(context, file,
                                new String[] { "diverKon+sakura@gmail.com" });
                    }
                });
                alertDialog.setNeutralButton(positive + " http", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface di, int i) {
                        DefaultUploaderWeb.upload(ExceptionHandlerReportApp.this, fileZip,
                                "http://kkkon.sakura.ne.jp/android/bug");
                    }
                });
                alertDialog.setNegativeButton(negative, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface di, int i) {
                        ExceptionHandler.clearReport();
                    }
                });
                alertDialog.show();
            }
            // TODO separate activity for crash report
            //DefaultCheckerAPK.checkAPK( this, null );
        }
        ExceptionHandler.registHandler();
    }

    super.onCreate(savedInstanceState);

    /* Create a TextView and set its content.
     * the text is retrieved by calling a native
     * function.
     */
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);

    TextView tv = new TextView(this);
    tv.setText("ExceptionHandler");
    layout.addView(tv);

    Button btn1 = new Button(this);
    btn1.setText("invoke Exception");
    btn1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final int count = 2;
            int[] array = new int[count];
            int value = array[count]; // invoke IndexOutOfBOundsException
        }
    });
    layout.addView(btn1);

    Button btn2 = new Button(this);
    btn2.setText("reinstall apk");
    btn2.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            boolean foundApk = false;
            {
                final String apkPath = context.getPackageCodePath(); // API8
                Log.d(TAG, "PackageCodePath: " + apkPath);
                final File fileApk = new File(apkPath);
                if (fileApk.exists()) {
                    foundApk = true;

                    Intent promptInstall = new Intent(Intent.ACTION_VIEW);
                    promptInstall.setDataAndType(Uri.fromFile(fileApk),
                            "application/vnd.android.package-archive");
                    promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(promptInstall);
                }
            }

            if (false == foundApk) {
                for (int i = 0; i < 10; ++i) {
                    File fileApk = new File("/data/app/" + context.getPackageName() + "-" + i + ".apk");
                    Log.d(TAG, "check apk:" + fileApk.getAbsolutePath());
                    if (fileApk.exists()) {
                        Log.i(TAG, "apk found. path=" + fileApk.getAbsolutePath());
                        /*
                         * // require parmission
                        {
                        final String strCmd = "pm install -r " + fileApk.getAbsolutePath();
                        try
                        {
                            Runtime.getRuntime().exec( strCmd );
                        }
                        catch ( IOException e )
                        {
                            Log.e( TAG, "got exception", e );
                        }
                        }
                        */
                        Intent promptInstall = new Intent(Intent.ACTION_VIEW);
                        promptInstall.setDataAndType(Uri.fromFile(fileApk),
                                "application/vnd.android.package-archive");
                        promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(promptInstall);
                        break;
                    }
                }
            }
        }
    });
    layout.addView(btn2);

    Button btn3 = new Button(this);
    btn3.setText("check apk");
    btn3.setOnClickListener(new View.OnClickListener() {
        private boolean checkApk(final File fileApk, final ZipEntryFilter filter) {
            final boolean[] result = new boolean[1];
            result[0] = true;

            final Thread thread = new Thread(new Runnable() {

                @Override
                public void run() {
                    if (fileApk.exists()) {
                        ZipFile zipFile = null;
                        try {
                            zipFile = new ZipFile(fileApk);
                            List<ZipEntry> list = new ArrayList<ZipEntry>(zipFile.size());
                            for (Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements();) {
                                ZipEntry ent = e.nextElement();
                                Log.d(TAG, ent.getName());
                                Log.d(TAG, "" + ent.getSize());
                                final boolean accept = filter.accept(ent);
                                if (accept) {
                                    list.add(ent);
                                }
                            }

                            Log.d(TAG, Build.CPU_ABI); // API 4
                            Log.d(TAG, Build.CPU_ABI2); // API 8

                            final String[] abiArray = { Build.CPU_ABI // API 4
                                    , Build.CPU_ABI2 // API 8
                            };

                            String abiMatched = null;
                            {
                                boolean foundMatched = false;
                                for (final String abi : abiArray) {
                                    if (null == abi) {
                                        continue;
                                    }
                                    if (0 == abi.length()) {
                                        continue;
                                    }

                                    for (final ZipEntry entry : list) {
                                        Log.d(TAG, entry.getName());

                                        final String prefixABI = "lib/" + abi + "/";
                                        if (entry.getName().startsWith(prefixABI)) {
                                            abiMatched = abi;
                                            foundMatched = true;
                                            break;
                                        }
                                    }

                                    if (foundMatched) {
                                        break;
                                    }
                                }
                            }
                            Log.d(TAG, "matchedAbi=" + abiMatched);

                            if (null != abiMatched) {
                                boolean needReInstall = false;

                                for (final ZipEntry entry : list) {
                                    Log.d(TAG, entry.getName());

                                    final String prefixABI = "lib/" + abiMatched + "/";
                                    if (entry.getName().startsWith(prefixABI)) {
                                        final String jniName = entry.getName().substring(prefixABI.length());
                                        Log.d(TAG, "jni=" + jniName);

                                        final String strFileDst = context.getApplicationInfo().nativeLibraryDir
                                                + "/" + jniName;
                                        Log.d(TAG, strFileDst);
                                        final File fileDst = new File(strFileDst);
                                        if (!fileDst.exists()) {
                                            Log.w(TAG, "needReInstall: content missing " + strFileDst);
                                            needReInstall = true;
                                        } else {
                                            assert (entry.getSize() <= Integer.MAX_VALUE);
                                            if (fileDst.length() != entry.getSize()) {
                                                Log.w(TAG, "needReInstall: size broken " + strFileDst);
                                                needReInstall = true;
                                            } else {
                                                //org.apache.commons.io.IOUtils.contentEquals( zipFile.getInputStream( entry ), new FileInputStream(fileDst) );

                                                final int size = (int) entry.getSize();
                                                byte[] buffSrc = new byte[size];

                                                {
                                                    InputStream inStream = null;
                                                    try {
                                                        inStream = zipFile.getInputStream(entry);
                                                        int pos = 0;
                                                        {
                                                            while (pos < size) {
                                                                final int ret = inStream.read(buffSrc, pos,
                                                                        size - pos);
                                                                if (ret <= 0) {
                                                                    break;
                                                                }
                                                                pos += ret;
                                                            }
                                                        }
                                                    } catch (IOException e) {
                                                        Log.d(TAG, "got exception", e);
                                                    } finally {
                                                        if (null != inStream) {
                                                            try {
                                                                inStream.close();
                                                            } catch (Exception e) {
                                                            }
                                                        }
                                                    }
                                                }
                                                byte[] buffDst = new byte[(int) fileDst.length()];
                                                {
                                                    InputStream inStream = null;
                                                    try {
                                                        inStream = new FileInputStream(fileDst);
                                                        int pos = 0;
                                                        {
                                                            while (pos < size) {
                                                                final int ret = inStream.read(buffDst, pos,
                                                                        size - pos);
                                                                if (ret <= 0) {
                                                                    break;
                                                                }
                                                                pos += ret;
                                                            }
                                                        }
                                                    } catch (IOException e) {
                                                        Log.d(TAG, "got exception", e);
                                                    } finally {
                                                        if (null != inStream) {
                                                            try {
                                                                inStream.close();
                                                            } catch (Exception e) {
                                                            }
                                                        }
                                                    }
                                                }

                                                if (Arrays.equals(buffSrc, buffDst)) {
                                                    Log.d(TAG, " content equal " + strFileDst);
                                                    // OK
                                                } else {
                                                    Log.w(TAG, "needReInstall: content broken " + strFileDst);
                                                    needReInstall = true;
                                                }
                                            }

                                        }

                                    }
                                } // for ZipEntry

                                if (needReInstall) {
                                    // need call INSTALL APK
                                    Log.w(TAG, "needReInstall apk");
                                    result[0] = false;
                                } else {
                                    Log.d(TAG, "no need ReInstall apk");
                                }
                            }

                        } catch (IOException e) {
                            Log.d(TAG, "got exception", e);
                        } finally {
                            if (null != zipFile) {
                                try {
                                    zipFile.close();
                                } catch (Exception e) {
                                }
                            }
                        }
                    }
                }

            });
            thread.setName("check jni so");

            thread.start();
            /*
            while ( thread.isAlive() )
            {
            Log.d( TAG, "check thread.id=" + android.os.Process.myTid() + ",state=" + thread.getState() );
            if ( ! thread.isAlive() )
            {
                break;
            }
            AlertDialog.Builder alertDialog = new AlertDialog.Builder( ExceptionHandlerTestApp.this );
            final Locale defaultLocale = Locale.getDefault();
                    
            String title = "";
            String message = "";
            String positive = "";
            String negative = "";
                    
            boolean needDefaultLang = true;
            if ( null != defaultLocale )
            {
                if ( defaultLocale.equals( Locale.JAPANESE ) || defaultLocale.equals( Locale.JAPAN ) )
                {
                    title = "";
                    message = "???????";
                    positive = "?";
                    negative = "";
                    needDefaultLang = false;
                }
            }
            if ( needDefaultLang )
            {
                title = "INFO";
                message = "Now checking installation. Cancel check?";
                positive = "Wait";
                negative = "Cancel";
            }
            alertDialog.setTitle( title );
            alertDialog.setMessage( message );
            alertDialog.setPositiveButton( positive, null);
            alertDialog.setNegativeButton( negative, new DialogInterface.OnClickListener() {
                    
                @Override
                public void onClick(DialogInterface di, int i) {
                    if ( thread.isAlive() )
                    {
                        Log.d( TAG, "request interrupt" );
                        thread.interrupt();
                    }
                    else
                    {
                        // nothing
                    }
                }
            } );
                    
            if ( ! thread.isAlive() )
            {
                break;
            }
                    
            alertDialog.show();
                    
            if ( ! Thread.State.RUNNABLE.equals(thread.getState()) )
            {
                break;
            }
                    
            }
            */

            try {
                thread.join();
            } catch (InterruptedException e) {
                Log.d(TAG, "got exception", e);
            }

            return result[0];
        }

        @Override
        public void onClick(View view) {
            boolean foundApk = false;
            {
                final String apkPath = context.getPackageCodePath(); // API8
                Log.d(TAG, "PackageCodePath: " + apkPath);
                final File fileApk = new File(apkPath);
                this.checkApk(fileApk, new ZipEntryFilter() {
                    @Override
                    public boolean accept(ZipEntry entry) {
                        if (entry.isDirectory()) {
                            return false;
                        }

                        final String filename = entry.getName();
                        if (filename.startsWith("lib/")) {
                            return true;
                        }

                        return false;
                    }
                });
            }

        }
    });
    layout.addView(btn3);

    Button btn4 = new Button(this);
    btn4.setText("print dir and path");
    btn4.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            {
                final File file = context.getCacheDir();
                Log.d(TAG, "Ctx.CacheDir=" + file.getAbsoluteFile());
            }
            {
                final File file = context.getExternalCacheDir(); // API 8
                if (null == file) {
                    // no permission
                    Log.d(TAG, "Ctx.ExternalCacheDir=");
                } else {
                    Log.d(TAG, "Ctx.ExternalCacheDir=" + file.getAbsolutePath());
                }
            }
            {
                final File file = context.getFilesDir();
                Log.d(TAG, "Ctx.FilesDir=" + file.getAbsolutePath());
            }
            {
                final String value = context.getPackageResourcePath();
                Log.d(TAG, "Ctx.PackageResourcePath=" + value);
            }
            {
                final String[] files = context.fileList();
                if (null == files) {
                    Log.d(TAG, "Ctx.fileList=" + files);
                } else {
                    for (final String filename : files) {
                        Log.d(TAG, "Ctx.fileList=" + filename);
                    }
                }
            }

            {
                final File file = Environment.getDataDirectory();
                Log.d(TAG, "Env.DataDirectory=" + file.getAbsolutePath());
            }
            {
                final File file = Environment.getDownloadCacheDirectory();
                Log.d(TAG, "Env.DownloadCacheDirectory=" + file.getAbsolutePath());
            }
            {
                final File file = Environment.getExternalStorageDirectory();
                Log.d(TAG, "Env.ExternalStorageDirectory=" + file.getAbsolutePath());
            }
            {
                final File file = Environment.getRootDirectory();
                Log.d(TAG, "Env.RootDirectory=" + file.getAbsolutePath());
            }
            {
                final ApplicationInfo appInfo = context.getApplicationInfo();
                Log.d(TAG, "AppInfo.dataDir=" + appInfo.dataDir);
                Log.d(TAG, "AppInfo.nativeLibraryDir=" + appInfo.nativeLibraryDir); // API 9
                Log.d(TAG, "AppInfo.publicSourceDir=" + appInfo.publicSourceDir);
                {
                    final String[] sharedLibraryFiles = appInfo.sharedLibraryFiles;
                    if (null == sharedLibraryFiles) {
                        Log.d(TAG, "AppInfo.sharedLibraryFiles=" + sharedLibraryFiles);
                    } else {
                        for (final String fileName : sharedLibraryFiles) {
                            Log.d(TAG, "AppInfo.sharedLibraryFiles=" + fileName);
                        }
                    }
                }
                Log.d(TAG, "AppInfo.sourceDir=" + appInfo.sourceDir);
            }
            {
                Log.d(TAG, "System.Properties start");
                final Properties properties = System.getProperties();
                if (null != properties) {
                    for (final Object key : properties.keySet()) {
                        String value = properties.getProperty((String) key);
                        Log.d(TAG, " key=" + key + ",value=" + value);
                    }
                }
                Log.d(TAG, "System.Properties end");
            }
            {
                Log.d(TAG, "System.getenv start");
                final Map<String, String> mapEnv = System.getenv();
                if (null != mapEnv) {
                    for (final Map.Entry<String, String> entry : mapEnv.entrySet()) {
                        final String key = entry.getKey();
                        final String value = entry.getValue();
                        Log.d(TAG, " key=" + key + ",value=" + value);
                    }
                }
                Log.d(TAG, "System.getenv end");
            }
        }
    });
    layout.addView(btn4);

    Button btn5 = new Button(this);
    btn5.setText("check INSTALL_NON_MARKET_APPS");
    btn5.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            SettingsCompat.initialize(context);
            if (SettingsCompat.isAllowedNonMarketApps()) {
                Log.d(TAG, "isAllowdNonMarketApps=true");
            } else {
                Log.d(TAG, "isAllowdNonMarketApps=false");
            }
        }
    });
    layout.addView(btn5);

    Button btn6 = new Button(this);
    btn6.setText("send email");
    btn6.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent mailto = new Intent();
            mailto.setAction(Intent.ACTION_SENDTO);
            mailto.setType("message/rfc822");
            mailto.setData(Uri.parse("mailto:"));
            mailto.putExtra(Intent.EXTRA_EMAIL, new String[] { "" });
            mailto.putExtra(Intent.EXTRA_SUBJECT, "[BugReport] " + context.getPackageName());
            mailto.putExtra(Intent.EXTRA_TEXT, "body text");
            //mailto.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
            //context.startActivity( mailto );
            Intent intent = Intent.createChooser(mailto, "Send Email");
            if (null != intent) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                try {
                    context.startActivity(intent);
                } catch (android.content.ActivityNotFoundException e) {
                    Log.d(TAG, "got Exception", e);
                }
            }
        }
    });
    layout.addView(btn6);

    Button btn7 = new Button(this);
    btn7.setText("upload http thread");
    btn7.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Log.d(TAG, "brd=" + Build.BRAND);
            Log.d(TAG, "prd=" + Build.PRODUCT);

            //$(BRAND)/$(PRODUCT)/$(DEVICE)/$(BOARD):$(VERSION.RELEASE)/$(ID)/$(VERSION.INCREMENTAL):$(TYPE)/$(TAGS)
            Log.d(TAG, "fng=" + Build.FINGERPRINT);
            final List<NameValuePair> list = new ArrayList<NameValuePair>(16);
            list.add(new BasicNameValuePair("fng", Build.FINGERPRINT));

            final Thread thread = new Thread(new Runnable() {

                @Override
                public void run() {
                    Log.d(TAG, "upload thread tid=" + android.os.Process.myTid());
                    try {
                        HttpPost httpPost = new HttpPost("http://kkkon.sakura.ne.jp/android/bug");
                        //httpPost.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, new Integer(5*1000) );
                        httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8));
                        DefaultHttpClient httpClient = new DefaultHttpClient();
                        Log.d(TAG, "socket.timeout="
                                + httpClient.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1));
                        Log.d(TAG, "connection.timeout=" + httpClient.getParams()
                                .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1));
                        httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
                                new Integer(5 * 1000));
                        httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
                                new Integer(5 * 1000));
                        Log.d(TAG, "socket.timeout="
                                + httpClient.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1));
                        Log.d(TAG, "connection.timeout=" + httpClient.getParams()
                                .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1));
                        // <uses-permission android:name="android.permission.INTERNET"/>
                        // got android.os.NetworkOnMainThreadException, run at UI Main Thread
                        HttpResponse response = httpClient.execute(httpPost);
                        Log.d(TAG, "response=" + response.getStatusLine().getStatusCode());
                    } catch (Exception e) {
                        Log.d(TAG, "got Exception. msg=" + e.getMessage(), e);
                    }
                    Log.d(TAG, "upload finish");
                }
            });
            thread.setName("upload crash");

            thread.start();
            /*
            while ( thread.isAlive() )
            {
            Log.d( TAG, "thread tid=" + android.os.Process.myTid() + ",state=" + thread.getState() );
            if ( ! thread.isAlive() )
            {
                break;
            }
            AlertDialog.Builder alertDialog = new AlertDialog.Builder( ExceptionHandlerTestApp.this );
            final Locale defaultLocale = Locale.getDefault();
                    
            String title = "";
            String message = "";
            String positive = "";
            String negative = "";
                    
            boolean needDefaultLang = true;
            if ( null != defaultLocale )
            {
                if ( defaultLocale.equals( Locale.JAPANESE ) || defaultLocale.equals( Locale.JAPAN ) )
                {
                    title = "";
                    message = "???????";
                    positive = "?";
                    negative = "";
                    needDefaultLang = false;
                }
            }
            if ( needDefaultLang )
            {
                title = "INFO";
                message = "Now uploading error information. Cancel upload?";
                positive = "Wait";
                negative = "Cancel";
            }
            alertDialog.setTitle( title );
            alertDialog.setMessage( message );
            alertDialog.setPositiveButton( positive, null);
            alertDialog.setNegativeButton( negative, new DialogInterface.OnClickListener() {
                    
                @Override
                public void onClick(DialogInterface di, int i) {
                    if ( thread.isAlive() )
                    {
                        Log.d( TAG, "request interrupt" );
                        thread.interrupt();
                    }
                    else
                    {
                        // nothing
                    }
                }
            } );
                    
            if ( ! thread.isAlive() )
            {
                break;
            }
                    
            alertDialog.show();
                    
            if ( ! Thread.State.RUNNABLE.equals(thread.getState()) )
            {
                break;
            }
                    
            }
            */

            /*
            try
            {
            thread.join(); // must call. leak handle...
            }
            catch ( InterruptedException e )
            {
            Log.d( TAG, "got Exception", e );
            }
            */
        }
    });
    layout.addView(btn7);

    Button btn8 = new Button(this);
    btn8.setText("upload http AsyncTask");
    btn8.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            AsyncTask<String, Void, Boolean> asyncTask = new AsyncTask<String, Void, Boolean>() {

                @Override
                protected Boolean doInBackground(String... paramss) {
                    Boolean result = true;
                    Log.d(TAG, "upload AsyncTask tid=" + android.os.Process.myTid());
                    try {
                        //$(BRAND)/$(PRODUCT)/$(DEVICE)/$(BOARD):$(VERSION.RELEASE)/$(ID)/$(VERSION.INCREMENTAL):$(TYPE)/$(TAGS)
                        Log.d(TAG, "fng=" + Build.FINGERPRINT);
                        final List<NameValuePair> list = new ArrayList<NameValuePair>(16);
                        list.add(new BasicNameValuePair("fng", Build.FINGERPRINT));

                        HttpPost httpPost = new HttpPost(paramss[0]);
                        //httpPost.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, new Integer(5*1000) );
                        httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8));
                        DefaultHttpClient httpClient = new DefaultHttpClient();
                        Log.d(TAG, "socket.timeout="
                                + httpClient.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1));
                        Log.d(TAG, "connection.timeout=" + httpClient.getParams()
                                .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1));
                        httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
                                new Integer(5 * 1000));
                        httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
                                new Integer(5 * 1000));
                        Log.d(TAG, "socket.timeout="
                                + httpClient.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1));
                        Log.d(TAG, "connection.timeout=" + httpClient.getParams()
                                .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1));
                        // <uses-permission android:name="android.permission.INTERNET"/>
                        // got android.os.NetworkOnMainThreadException, run at UI Main Thread
                        HttpResponse response = httpClient.execute(httpPost);
                        Log.d(TAG, "response=" + response.getStatusLine().getStatusCode());
                    } catch (Exception e) {
                        Log.d(TAG, "got Exception. msg=" + e.getMessage(), e);
                        result = false;
                    }
                    Log.d(TAG, "upload finish");
                    return result;
                }

            };

            asyncTask.execute("http://kkkon.sakura.ne.jp/android/bug");
            asyncTask.isCancelled();
        }
    });
    layout.addView(btn8);

    Button btn9 = new Button(this);
    btn9.setText("call checkAPK");
    btn9.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final boolean result = DefaultCheckerAPK.checkAPK(ExceptionHandlerReportApp.this, null);
            Log.i(TAG, "checkAPK result=" + result);
        }
    });
    layout.addView(btn9);

    setContentView(layout);
}