List of usage examples for android.widget ScrollView addView
@Override public void addView(View child, ViewGroup.LayoutParams params)
From source file:org.telegram.ui.ChannelEditTypeActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override// ww w .java2s . c o m public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { if (donePressed) { return; } if (!isPrivate && ((currentChat.username == null && nameTextView.length() != 0) || (currentChat.username != null && !currentChat.username .equalsIgnoreCase(nameTextView.getText().toString())))) { if (nameTextView.length() != 0 && !lastNameAvailable) { Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { v.vibrate(200); } AndroidUtilities.shakeView(checkTextView, 2, 0); return; } } donePressed = true; String oldUserName = currentChat.username != null ? currentChat.username : ""; String newUserName = isPrivate ? "" : nameTextView.getText().toString(); if (!oldUserName.equals(newUserName)) { MessagesController.getInstance().updateChannelUserName(chatId, newUserName); } finishFragment(); } } }); ActionBarMenu menu = actionBar.createMenu(); menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); fragmentView = new ScrollView(context); fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); ScrollView scrollView = (ScrollView) fragmentView; scrollView.setFillViewport(true); linearLayout = new LinearLayout(context); scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); linearLayout.setOrientation(LinearLayout.VERTICAL); if (currentChat.megagroup) { actionBar.setTitle(LocaleController.getString("GroupType", R.string.GroupType)); } else { actionBar.setTitle(LocaleController.getString("ChannelType", R.string.ChannelType)); } LinearLayout linearLayout2 = new LinearLayout(context); linearLayout2.setOrientation(LinearLayout.VERTICAL); linearLayout2.setElevation(AndroidUtilities.dp(2)); linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); radioButtonCell1 = new RadioButtonCell(context); radioButtonCell1.setElevation(0); radioButtonCell1.setBackgroundResource(R.drawable.list_selector); if (currentChat.megagroup) { radioButtonCell1.setTextAndValue(LocaleController.getString("MegaPublic", R.string.MegaPublic), LocaleController.getString("MegaPublicInfo", R.string.MegaPublicInfo), !isPrivate, false); } else { radioButtonCell1.setTextAndValue(LocaleController.getString("ChannelPublic", R.string.ChannelPublic), LocaleController.getString("ChannelPublicInfo", R.string.ChannelPublicInfo), !isPrivate, false); } linearLayout2.addView(radioButtonCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); radioButtonCell1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!isPrivate) { return; } isPrivate = false; updatePrivatePublic(); } }); radioButtonCell2 = new RadioButtonCell(context); radioButtonCell2.setElevation(0); radioButtonCell2.setForeground(R.drawable.list_selector); if (currentChat.megagroup) { radioButtonCell2.setTextAndValue(LocaleController.getString("MegaPrivate", R.string.MegaPrivate), LocaleController.getString("MegaPrivateInfo", R.string.MegaPrivateInfo), isPrivate, false); } else { radioButtonCell2.setTextAndValue(LocaleController.getString("ChannelPrivate", R.string.ChannelPrivate), LocaleController.getString("ChannelPrivateInfo", R.string.ChannelPrivateInfo), isPrivate, false); } linearLayout2.addView(radioButtonCell2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); radioButtonCell2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isPrivate) { return; } isPrivate = true; updatePrivatePublic(); } }); sectionCell = new ShadowSectionCell(context); linearLayout.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); linkContainer = new LinearLayout(context); linkContainer.setOrientation(LinearLayout.VERTICAL); linkContainer.setElevation(AndroidUtilities.dp(2)); linkContainer.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linearLayout.addView(linkContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); headerCell = new HeaderCell(context); headerCell.setElevation(0); headerCell.setBackground(null); linkContainer.addView(headerCell); publicContainer = new LinearLayout(context); publicContainer.setOrientation(LinearLayout.HORIZONTAL); linkContainer.addView(publicContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 17, 7, 17, 0)); EditText editText = new EditText(context); editText.setText("telegram.me/"); editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); //editText.setHintTextColor(0xff979797); editText.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); editText.setMaxLines(1); editText.setLines(1); editText.setEnabled(false); editText.setBackgroundDrawable(null); editText.setPadding(0, 0, 0, 0); editText.setSingleLine(true); editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT); editText.setImeOptions(EditorInfo.IME_ACTION_DONE); publicContainer.addView(editText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 36)); nameTextView = new EditText(context); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); if (!isPrivate) { nameTextView.setText(currentChat.username); } //nameTextView.setHintTextColor(0xff979797); nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); nameTextView.setMaxLines(1); nameTextView.setLines(1); nameTextView.setBackgroundDrawable(null); nameTextView.setPadding(0, 0, 0, 0); nameTextView.setSingleLine(true); nameTextView.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT); nameTextView.setImeOptions(EditorInfo.IME_ACTION_DONE); nameTextView.setHint( LocaleController.getString("ChannelUsernamePlaceholder", R.string.ChannelUsernamePlaceholder)); AndroidUtilities.clearCursorDrawable(nameTextView); publicContainer.addView(nameTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36)); nameTextView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { checkUserName(nameTextView.getText().toString()); } @Override public void afterTextChanged(Editable editable) { } }); privateContainer = new TextBlockCell(context); privateContainer.setForeground(R.drawable.list_selector); linkContainer.addView(privateContainer); privateContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (invite == null) { return; } try { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext .getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("label", invite.link); clipboard.setPrimaryClip(clip); Toast.makeText(getParentActivity(), LocaleController.getString("LinkCopied", R.string.LinkCopied), Toast.LENGTH_SHORT) .show(); } catch (Exception e) { FileLog.e("tmessages", e); } } }); checkTextView = new TextView(context); checkTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); checkTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); checkTextView.setVisibility(View.GONE); linkContainer.addView(checkTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 17, 3, 17, 7)); typeInfoCell = new TextInfoPrivacyCell(context); //typeInfoCell.setBackgroundResource(R.drawable.greydivider_bottom); linearLayout.addView(typeInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); loadingAdminedCell = new LoadingCell(context); linearLayout.addView(loadingAdminedCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); adminedInfoCell = new TextInfoPrivacyCell(context); //adminedInfoCell.setBackgroundResource(R.drawable.greydivider_bottom); linearLayout.addView(adminedInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); updatePrivatePublic(); return fragmentView; }
From source file:org.telegram.ui.ChannelEditActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override// w ww .j a v a2s.c o m public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { if (donePressed) { return; } if (nameTextView.length() == 0) { Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { v.vibrate(200); } AndroidUtilities.shakeView(nameTextView, 2, 0); return; } donePressed = true; if (avatarUpdater.uploadingAvatar != null) { createAfterUpload = true; progressDialog = new ProgressDialog(getParentActivity()); progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading)); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCancelable(false); progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { createAfterUpload = false; progressDialog = null; donePressed = false; try { dialog.dismiss(); } catch (Exception e) { FileLog.e("tmessages", e); } } }); progressDialog.show(); return; } if (!currentChat.title.equals(nameTextView.getText().toString())) { MessagesController.getInstance().changeChatTitle(chatId, nameTextView.getText().toString()); } if (info != null && !info.about.equals(descriptionTextView.getText().toString())) { MessagesController.getInstance().updateChannelAbout(chatId, descriptionTextView.getText().toString(), info); } if (signMessages != currentChat.signatures) { currentChat.signatures = true; MessagesController.getInstance().toogleChannelSignatures(chatId, signMessages); } if (uploadedAvatar != null) { MessagesController.getInstance().changeChatAvatar(chatId, uploadedAvatar); } else if (avatar == null && currentChat.photo instanceof TLRPC.TL_chatPhoto) { MessagesController.getInstance().changeChatAvatar(chatId, null); } finishFragment(); } } }); ActionBarMenu menu = actionBar.createMenu(); doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); LinearLayout linearLayout; fragmentView = new ScrollView(context); fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); ScrollView scrollView = (ScrollView) fragmentView; scrollView.setFillViewport(true); linearLayout = new LinearLayout(context); scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); linearLayout.setOrientation(LinearLayout.VERTICAL); actionBar.setTitle(LocaleController.getString("ChannelEdit", R.string.ChannelEdit)); LinearLayout linearLayout2 = new LinearLayout(context); linearLayout2.setOrientation(LinearLayout.VERTICAL); linearLayout2.setElevation(AndroidUtilities.dp(2)); linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); FrameLayout frameLayout = new FrameLayout(context); linearLayout2.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); avatarImage = new BackupImageView(context); avatarImage.setRoundRadius(AndroidUtilities.dp(32)); avatarDrawable.setInfo(5, null, null, false); avatarDrawable.setDrawPhoto(true); frameLayout.addView(avatarImage, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12)); avatarImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items; if (avatar != null) { items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("DeletePhoto", R.string.DeletePhoto) }; } else { items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley) }; } builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (i == 0) { avatarUpdater.openCamera(); } else if (i == 1) { avatarUpdater.openGallery(); } else if (i == 2) { avatar = null; uploadedAvatar = null; avatarImage.setImage(avatar, "50_50", avatarDrawable); } } }); showDialog(builder.create()); } }); nameTextView = new EditText(context); if (currentChat.megagroup) { nameTextView.setHint(LocaleController.getString("GroupName", R.string.GroupName)); } else { nameTextView.setHint(LocaleController.getString("EnterChannelName", R.string.EnterChannelName)); } nameTextView.setMaxLines(4); nameTextView.setGravity(Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT)); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); //nameTextView.setHintTextColor(0xff979797); nameTextView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); nameTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); nameTextView.setPadding(0, 0, 0, AndroidUtilities.dp(8)); InputFilter[] inputFilters = new InputFilter[1]; inputFilters[0] = new InputFilter.LengthFilter(100); nameTextView.setFilters(inputFilters); AndroidUtilities.clearCursorDrawable(nameTextView); nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 16 : 96, 0, LocaleController.isRTL ? 96 : 16, 0)); nameTextView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { avatarDrawable.setInfo(5, nameTextView.length() > 0 ? nameTextView.getText().toString() : null, null, false); avatarImage.invalidate(); } }); View lineView = new View(context); lineView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_divider)); linearLayout.addView(lineView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1)); linearLayout2 = new LinearLayout(context); linearLayout2.setOrientation(LinearLayout.VERTICAL); linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linearLayout2.setElevation(AndroidUtilities.dp(2)); linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); descriptionTextView = new EditText(context); descriptionTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); //descriptionTextView.setHintTextColor(0xff979797); descriptionTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); descriptionTextView.setPadding(0, 0, 0, AndroidUtilities.dp(6)); descriptionTextView.setBackgroundDrawable(null); descriptionTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); descriptionTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT); descriptionTextView.setImeOptions(EditorInfo.IME_ACTION_DONE); inputFilters = new InputFilter[1]; inputFilters[0] = new InputFilter.LengthFilter(255); descriptionTextView.setFilters(inputFilters); descriptionTextView.setHint(LocaleController.getString("DescriptionOptionalPlaceholder", R.string.DescriptionOptionalPlaceholder)); AndroidUtilities.clearCursorDrawable(descriptionTextView); linearLayout2.addView(descriptionTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 17, 12, 17, 6)); descriptionTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) { doneButton.performClick(); return true; } return false; } }); descriptionTextView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void afterTextChanged(Editable editable) { } }); ShadowSectionCell sectionCell = new ShadowSectionCell(context); sectionCell.setSize(20); linearLayout.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); if (currentChat.megagroup || !currentChat.megagroup) { frameLayout = new FrameLayout(context); frameLayout.setElevation(AndroidUtilities.dp(2)); frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); typeCell = new TextSettingsCell(context); updateTypeCell(); typeCell.setForeground(R.drawable.list_selector); frameLayout.addView(typeCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); lineView = new View(context); lineView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_divider)); linearLayout.addView(lineView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1)); frameLayout = new FrameLayout(context); frameLayout.setElevation(AndroidUtilities.dp(2)); frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); if (!currentChat.megagroup) { TextCheckCell textCheckCell = new TextCheckCell(context); textCheckCell.setForeground(R.drawable.list_selector); textCheckCell.setTextAndCheck( LocaleController.getString("ChannelSignMessages", R.string.ChannelSignMessages), signMessages, false); frameLayout.addView(textCheckCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); textCheckCell.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { signMessages = !signMessages; ((TextCheckCell) v).setChecked(signMessages); } }); TextInfoPrivacyCell infoCell = new TextInfoPrivacyCell(context); //infoCell.setBackgroundResource(R.drawable.greydivider); infoCell.setText( LocaleController.getString("ChannelSignMessagesInfo", R.string.ChannelSignMessagesInfo)); linearLayout.addView(infoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); } else { adminCell = new TextSettingsCell(context); updateAdminCell(); adminCell.setForeground(R.drawable.list_selector); frameLayout.addView(adminCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); adminCell.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle args = new Bundle(); args.putInt("chat_id", chatId); args.putInt("type", 1); presentFragment(new ChannelUsersActivity(args)); } }); sectionCell = new ShadowSectionCell(context); sectionCell.setSize(20); linearLayout.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); /*if (!currentChat.creator) { sectionCell.setBackgroundResource(R.drawable.greydivider_bottom); }*/ } } if (currentChat.creator) { frameLayout = new FrameLayout(context); frameLayout.setElevation(AndroidUtilities.dp(2)); frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); TextSettingsCell textCell = new TextSettingsCell(context); textCell.setTextColor(0xffed3d39); textCell.setBackgroundResource(R.drawable.list_selector); if (currentChat.megagroup) { textCell.setText(LocaleController.getString("DeleteMega", R.string.DeleteMega), false); } else { textCell.setText(LocaleController.getString("ChannelDelete", R.string.ChannelDelete), false); } frameLayout.addView(textCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); textCell.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); if (currentChat.megagroup) { builder.setMessage(LocaleController.getString("MegaDeleteAlert", R.string.MegaDeleteAlert)); } else { builder.setMessage( LocaleController.getString("ChannelDeleteAlert", R.string.ChannelDeleteAlert)); } builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats); if (AndroidUtilities.isTablet()) { NotificationCenter.getInstance().postNotificationName( NotificationCenter.closeChats, -(long) chatId); } else { NotificationCenter.getInstance() .postNotificationName(NotificationCenter.closeChats); } MessagesController.getInstance().deleteUserFromChat(chatId, MessagesController.getInstance().getUser(UserConfig.getClientUserId()), info); finishFragment(); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } }); TextInfoPrivacyCell infoCell = new TextInfoPrivacyCell(context); //infoCell.setBackgroundResource(R.drawable.greydivider_bottom); if (currentChat.megagroup) { infoCell.setText(LocaleController.getString("MegaDeleteInfo", R.string.MegaDeleteInfo)); } else { infoCell.setText(LocaleController.getString("ChannelDeleteInfo", R.string.ChannelDeleteInfo)); } linearLayout.addView(infoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); } nameTextView.setText(currentChat.title); nameTextView.setSelection(nameTextView.length()); if (info != null) { descriptionTextView.setText(info.about); } if (currentChat.photo != null) { avatar = currentChat.photo.photo_small; avatarImage.setImage(avatar, "50_50", avatarDrawable); } else { avatarImage.setImageDrawable(avatarDrawable); } return fragmentView; }
From source file:org.telegram.ui.ChangePhoneActivity.java
@Override public View createView(Context context) { actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName)); actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override//www. j a v a 2 s. c o m public void onItemClick(int id) { if (id == done_button) { views[currentViewNum].onNextPressed(); } else if (id == -1) { finishFragment(); } } }); ActionBarMenu menu = actionBar.createMenu(); doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); fragmentView = new ScrollView(context); ScrollView scrollView = (ScrollView) fragmentView; scrollView.setFillViewport(true); FrameLayout frameLayout = new FrameLayout(context); scrollView.addView(frameLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT)); views[0] = new PhoneView(context); views[1] = new LoginActivitySmsView(context, 1); views[2] = new LoginActivitySmsView(context, 2); views[3] = new LoginActivitySmsView(context, 3); views[4] = new LoginActivitySmsView(context, 4); for (int a = 0; a < views.length; a++) { views[a].setVisibility(a == 0 ? View.VISIBLE : View.GONE); frameLayout.addView(views[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, a == 0 ? LayoutHelper.WRAP_CONTENT : LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 26 : 18, 30, AndroidUtilities.isTablet() ? 26 : 18, 0)); //LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 16, 30, 16, 0) } actionBar.setTitle(views[0].getHeaderName()); return fragmentView; }
From source file:org.telegram.ui.ChannelCreateActivity.java
@Override public View createView(Context context) { searching = false;//from www.jav a 2 s . co m searchWas = false; actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { if (currentStep == 0) { if (donePressed) { return; } if (nameTextView.length() == 0) { Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { v.vibrate(200); } AndroidUtilities.shakeView(nameTextView, 2, 0); return; } donePressed = true; if (avatarUpdater.uploadingAvatar != null) { createAfterUpload = true; progressDialog = new ProgressDialog(getParentActivity()); progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading)); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCancelable(false); progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { createAfterUpload = false; progressDialog = null; donePressed = false; try { dialog.dismiss(); } catch (Exception e) { FileLog.e("tmessages", e); } } }); progressDialog.show(); return; } final int reqId = MessagesController.getInstance().createChat( nameTextView.getText().toString(), new ArrayList<Integer>(), descriptionTextView.getText().toString(), ChatObject.CHAT_TYPE_CHANNEL, ChannelCreateActivity.this); progressDialog = new ProgressDialog(getParentActivity()); progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading)); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCancelable(false); progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ConnectionsManager.getInstance().cancelRequest(reqId, true); donePressed = false; try { dialog.dismiss(); } catch (Exception e) { FileLog.e("tmessages", e); } } }); progressDialog.show(); } else if (currentStep == 1) { if (!isPrivate) { if (nameTextView.length() == 0) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.getString("ChannelPublicEmptyUsername", R.string.ChannelPublicEmptyUsername)); builder.setPositiveButton(LocaleController.getString("Close", R.string.Close), null); showDialog(builder.create()); return; } else { if (!lastNameAvailable) { Vibrator v = (Vibrator) getParentActivity() .getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { v.vibrate(200); } AndroidUtilities.shakeView(checkTextView, 2, 0); return; } else { MessagesController.getInstance().updateChannelUserName(chatId, lastCheckName); } } } Bundle args = new Bundle(); args.putInt("step", 2); args.putInt("chat_id", chatId); presentFragment(new ChannelCreateActivity(args), true); } else { ArrayList<TLRPC.InputUser> result = new ArrayList<>(); for (Integer uid : selectedContacts.keySet()) { TLRPC.InputUser user = MessagesController .getInputUser(MessagesController.getInstance().getUser(uid)); if (user != null) { result.add(user); } } MessagesController.getInstance().addUsersToChannel(chatId, result, null); NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); Bundle args2 = new Bundle(); args2.putInt("chat_id", chatId); presentFragment(new ChatActivity(args2), true); } } } }); ActionBarMenu menu = actionBar.createMenu(); doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); if (currentStep != 2) { fragmentView = new ScrollView(context); ScrollView scrollView = (ScrollView) fragmentView; scrollView.setFillViewport(true); linearLayout = new LinearLayout(context); scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } else { fragmentView = new LinearLayout(context); fragmentView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); linearLayout = (LinearLayout) fragmentView; } linearLayout.setOrientation(LinearLayout.VERTICAL); if (currentStep == 0) { actionBar.setTitle(LocaleController.getString("NewChannel", R.string.NewChannel)); fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); FrameLayout frameLayout = new FrameLayout(context); linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); avatarImage = new BackupImageView(context); avatarImage.setRoundRadius(AndroidUtilities.dp(32)); avatarDrawable.setInfo(5, null, null, false); avatarDrawable.setDrawPhoto(true); avatarImage.setImageDrawable(avatarDrawable); frameLayout.addView(avatarImage, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12)); avatarImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items; if (avatar != null) { items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("DeletePhoto", R.string.DeletePhoto) }; } else { items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley) }; } builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (i == 0) { avatarUpdater.openCamera(); } else if (i == 1) { avatarUpdater.openGallery(); } else if (i == 2) { avatar = null; uploadedAvatar = null; avatarImage.setImage(avatar, "50_50", avatarDrawable); } } }); showDialog(builder.create()); } }); nameTextView = new EditText(context); nameTextView.setHint(LocaleController.getString("EnterChannelName", R.string.EnterChannelName)); if (nameToSet != null) { nameTextView.setText(nameToSet); nameToSet = null; } nameTextView.setMaxLines(4); nameTextView .setGravity(Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT)); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); //nameTextView.setHintTextColor(0xff979797); nameTextView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); nameTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); InputFilter[] inputFilters = new InputFilter[1]; inputFilters[0] = new InputFilter.LengthFilter(100); nameTextView.setFilters(inputFilters); nameTextView.setPadding(0, 0, 0, AndroidUtilities.dp(8)); AndroidUtilities.clearCursorDrawable(nameTextView); nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 16 : 96, 0, LocaleController.isRTL ? 96 : 16, 0)); nameTextView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { avatarDrawable.setInfo(5, nameTextView.length() > 0 ? nameTextView.getText().toString() : null, null, false); avatarImage.invalidate(); } }); descriptionTextView = new EditText(context); descriptionTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); //descriptionTextView.setHintTextColor(0xff979797); descriptionTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); descriptionTextView.setPadding(0, 0, 0, AndroidUtilities.dp(6)); descriptionTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); descriptionTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT); descriptionTextView.setImeOptions(EditorInfo.IME_ACTION_DONE); inputFilters = new InputFilter[1]; inputFilters[0] = new InputFilter.LengthFilter(120); descriptionTextView.setFilters(inputFilters); descriptionTextView .setHint(LocaleController.getString("DescriptionPlaceholder", R.string.DescriptionPlaceholder)); AndroidUtilities.clearCursorDrawable(descriptionTextView); linearLayout.addView(descriptionTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 24, 18, 24, 0)); descriptionTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) { doneButton.performClick(); return true; } return false; } }); descriptionTextView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void afterTextChanged(Editable editable) { } }); TextView helpTextView = new TextView(context); helpTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); //helpTextView.setTextColor(0xff6d6d72); helpTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); helpTextView.setText(LocaleController.getString("DescriptionInfo", R.string.DescriptionInfo)); linearLayout.addView(helpTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 24, 10, 24, 20)); } else if (currentStep == 1) { actionBar.setTitle(LocaleController.getString("ChannelSettings", R.string.ChannelSettings)); fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); LinearLayout linearLayout2 = new LinearLayout(context); linearLayout2.setOrientation(LinearLayout.VERTICAL); linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linearLayout2.setElevation(AndroidUtilities.dp(2)); linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); radioButtonCell1 = new RadioButtonCell(context); radioButtonCell1.setElevation(0); radioButtonCell1.setForeground(R.drawable.list_selector); radioButtonCell1.setTextAndValue(LocaleController.getString("ChannelPublic", R.string.ChannelPublic), LocaleController.getString("ChannelPublicInfo", R.string.ChannelPublicInfo), !isPrivate, false); linearLayout2.addView(radioButtonCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); radioButtonCell1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!isPrivate) { return; } isPrivate = false; updatePrivatePublic(); } }); radioButtonCell2 = new RadioButtonCell(context); radioButtonCell2.setElevation(0); radioButtonCell2.setForeground(R.drawable.list_selector); radioButtonCell2.setTextAndValue(LocaleController.getString("ChannelPrivate", R.string.ChannelPrivate), LocaleController.getString("ChannelPrivateInfo", R.string.ChannelPrivateInfo), isPrivate, false); linearLayout2.addView(radioButtonCell2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); radioButtonCell2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isPrivate) { return; } isPrivate = true; updatePrivatePublic(); } }); sectionCell = new ShadowSectionCell(context); linearLayout.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); linkContainer = new LinearLayout(context); linkContainer.setOrientation(LinearLayout.VERTICAL); linkContainer.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linkContainer.setElevation(AndroidUtilities.dp(2)); linearLayout.addView(linkContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); headerCell = new HeaderCell(context); linkContainer.addView(headerCell); publicContainer = new LinearLayout(context); publicContainer.setOrientation(LinearLayout.HORIZONTAL); linkContainer.addView(publicContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 17, 7, 17, 0)); EditText editText = new EditText(context); editText.setText("telegram.me/"); editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); //editText.setHintTextColor(0xff979797); editText.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); editText.setMaxLines(1); editText.setLines(1); editText.setEnabled(false); editText.setBackgroundDrawable(null); editText.setPadding(0, 0, 0, 0); editText.setSingleLine(true); editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT); editText.setImeOptions(EditorInfo.IME_ACTION_DONE); publicContainer.addView(editText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 36)); nameTextView = new EditText(context); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); //nameTextView.setHintTextColor(0xff979797); nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); nameTextView.setMaxLines(1); nameTextView.setLines(1); nameTextView.setBackgroundDrawable(null); nameTextView.setPadding(0, 0, 0, 0); nameTextView.setSingleLine(true); nameTextView.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT); nameTextView.setImeOptions(EditorInfo.IME_ACTION_DONE); nameTextView.setHint( LocaleController.getString("ChannelUsernamePlaceholder", R.string.ChannelUsernamePlaceholder)); AndroidUtilities.clearCursorDrawable(nameTextView); publicContainer.addView(nameTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36)); nameTextView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { checkUserName(nameTextView.getText().toString()); } @Override public void afterTextChanged(Editable editable) { } }); privateContainer = new TextBlockCell(context); privateContainer.setForeground(R.drawable.list_selector); privateContainer.setElevation(0); linkContainer.addView(privateContainer); privateContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (invite == null) { return; } try { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext .getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("label", invite.link); clipboard.setPrimaryClip(clip); Toast.makeText(getParentActivity(), LocaleController.getString("LinkCopied", R.string.LinkCopied), Toast.LENGTH_SHORT) .show(); } catch (Exception e) { FileLog.e("tmessages", e); } } }); checkTextView = new TextView(context); checkTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); checkTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); checkTextView.setVisibility(View.GONE); linkContainer.addView(checkTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 17, 3, 17, 7)); typeInfoCell = new TextInfoPrivacyCell(context); //typeInfoCell.setBackgroundResource(R.drawable.greydivider_bottom); linearLayout.addView(typeInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); loadingAdminedCell = new LoadingCell(context); linearLayout.addView(loadingAdminedCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); adminedInfoCell = new TextInfoPrivacyCell(context); //adminedInfoCell.setBackgroundResource(R.drawable.greydivider_bottom); linearLayout.addView(adminedInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); updatePrivatePublic(); } else if (currentStep == 2) { actionBar.setTitle(LocaleController.getString("ChannelAddMembers", R.string.ChannelAddMembers)); actionBar.setSubtitle(LocaleController.formatPluralString("Members", selectedContacts.size())); searchListViewAdapter = new SearchAdapter(context, null, false, false, false, false); searchListViewAdapter.setCheckedMap(selectedContacts); searchListViewAdapter.setUseUserCell(true); listViewAdapter = new ContactsAdapter(context, 1, false, null, false); listViewAdapter.setCheckedMap(selectedContacts); FrameLayout frameLayout = new FrameLayout(context); frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.chat_list_background)); linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); nameTextView = new EditText(context); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); //nameTextView.setHintTextColor(0xff979797); nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); nameTextView.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_MULTI_LINE); nameTextView.setMinimumHeight(AndroidUtilities.dp(54)); nameTextView.setSingleLine(false); nameTextView.setLines(2); nameTextView.setMaxLines(2); nameTextView.setVerticalScrollBarEnabled(true); nameTextView.setHorizontalScrollBarEnabled(false); nameTextView.setPadding(0, 0, 0, 0); nameTextView.setHint(LocaleController.getString("AddMutual", R.string.AddMutual)); nameTextView.setTextIsSelectable(false); nameTextView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI); nameTextView .setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL); AndroidUtilities.clearCursorDrawable(nameTextView); frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 10, 0, 10, 0)); nameTextView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) { if (!ignoreChange) { beforeChangeIndex = nameTextView.getSelectionStart(); changeString = new SpannableString(charSequence); } } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void afterTextChanged(Editable editable) { if (!ignoreChange) { boolean search = false; int afterChangeIndex = nameTextView.getSelectionEnd(); if (editable.toString().length() < changeString.toString().length()) { String deletedString = ""; try { deletedString = changeString.toString().substring(afterChangeIndex, beforeChangeIndex); } catch (Exception e) { FileLog.e("tmessages", e); } if (deletedString.length() > 0) { if (searching && searchWas) { search = true; } Spannable span = nameTextView.getText(); for (int a = 0; a < allSpans.size(); a++) { ChipSpan sp = allSpans.get(a); if (span.getSpanStart(sp) == -1) { allSpans.remove(sp); selectedContacts.remove(sp.uid); } } actionBar.setSubtitle( LocaleController.formatPluralString("Members", selectedContacts.size())); listView.invalidateViews(); } else { search = true; } } else { search = true; } if (search) { String text = nameTextView.getText().toString().replace("<", ""); if (text.length() != 0) { searching = true; searchWas = true; if (listView != null) { listView.setAdapter(searchListViewAdapter); searchListViewAdapter.notifyDataSetChanged(); listView.setFastScrollAlwaysVisible(false); listView.setFastScrollEnabled(false); listView.setVerticalScrollBarEnabled(true); } if (emptyTextView != null) { emptyTextView .setText(LocaleController.getString("NoResult", R.string.NoResult)); } searchListViewAdapter.searchDialogs(text); } else { searchListViewAdapter.searchDialogs(null); searching = false; searchWas = false; listView.setAdapter(listViewAdapter); listViewAdapter.notifyDataSetChanged(); listView.setFastScrollAlwaysVisible(true); listView.setFastScrollEnabled(true); listView.setVerticalScrollBarEnabled(false); emptyTextView .setText(LocaleController.getString("NoContacts", R.string.NoContacts)); } } } } }); LinearLayout emptyTextLayout = new LinearLayout(context); emptyTextLayout.setVisibility(View.INVISIBLE); emptyTextLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(emptyTextLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); emptyTextLayout.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); emptyTextView = new TextView(context); emptyTextView.setTextColor(0xff808080); emptyTextView.setTextSize(20); emptyTextView.setGravity(Gravity.CENTER); emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts)); emptyTextLayout.addView(emptyTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f)); FrameLayout frameLayout2 = new FrameLayout(context); emptyTextLayout.addView(frameLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f)); listView = new LetterSectionsListView(context); listView.setEmptyView(emptyTextLayout); listView.setVerticalScrollBarEnabled(false); listView.setDivider(null); listView.setDividerHeight(0); listView.setFastScrollEnabled(true); listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); listView.setAdapter(listViewAdapter); listView.setFastScrollAlwaysVisible(true); listView.setVerticalScrollbarPosition( LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT); linearLayout.addView(listView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { TLRPC.User user; if (searching && searchWas) { user = (TLRPC.User) searchListViewAdapter.getItem(i); } else { int section = listViewAdapter.getSectionForPosition(i); int row = listViewAdapter.getPositionInSectionForPosition(i); if (row < 0 || section < 0) { return; } user = (TLRPC.User) listViewAdapter.getItem(section, row); } if (user == null) { return; } boolean check = true; if (selectedContacts.containsKey(user.id)) { check = false; try { ChipSpan span = selectedContacts.get(user.id); selectedContacts.remove(user.id); SpannableStringBuilder text = new SpannableStringBuilder(nameTextView.getText()); text.delete(text.getSpanStart(span), text.getSpanEnd(span)); allSpans.remove(span); ignoreChange = true; nameTextView.setText(text); nameTextView.setSelection(text.length()); ignoreChange = false; } catch (Exception e) { FileLog.e("tmessages", e); } } else { ignoreChange = true; ChipSpan span = createAndPutChipForUser(user); if (span != null) { span.uid = user.id; } ignoreChange = false; if (span == null) { return; } } actionBar.setSubtitle(LocaleController.formatPluralString("Members", selectedContacts.size())); if (searching || searchWas) { ignoreChange = true; SpannableStringBuilder ssb = new SpannableStringBuilder(""); for (ImageSpan sp : allSpans) { ssb.append("<<"); ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE); } nameTextView.setText(ssb); nameTextView.setSelection(ssb.length()); ignoreChange = false; searchListViewAdapter.searchDialogs(null); searching = false; searchWas = false; listView.setAdapter(listViewAdapter); listViewAdapter.notifyDataSetChanged(); listView.setFastScrollAlwaysVisible(true); listView.setFastScrollEnabled(true); listView.setVerticalScrollBarEnabled(false); emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts)); } else { if (view instanceof UserCell) { ((UserCell) view).setChecked(check, true); } } } }); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { if (i == SCROLL_STATE_TOUCH_SCROLL) { AndroidUtilities.hideKeyboard(nameTextView); } if (listViewAdapter != null) { listViewAdapter.setIsScrolling(i != SCROLL_STATE_IDLE); } } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (absListView.isFastScrollEnabled()) { AndroidUtilities.clearDrawableAnimation(absListView); } } }); } return fragmentView; }
From source file:org.zeroxlab.zeroxbenchmark.Benchmark.java
private void initViews() { /*//from w w w. ja v a 2 s . c o m mRun = (Button)findViewById(R.id.btn_run); mRun.setOnClickListener(this); mShow = (Button)findViewById(R.id.btn_show); mShow.setOnClickListener(this); mShow.setClickable(false); mLinearLayout = (LinearLayout)findViewById(R.id.list_container); mMainView = (LinearLayout)findViewById(R.id.main_view); mBannerInfo = (TextView)findViewById(R.id.banner_info); mBannerInfo.setText("Hello!\nSelect cases to Run.\nUploaded results:\nhttp://0xbenchmark.appspot.com"); */ mTabHost = getTabHost(); int length = mCases.size(); mCheckList = new CheckBox[length]; mDesc = new TextView[length]; for (int i = 0; i < length; i++) { mCheckList[i] = new CheckBox(this); mCheckList[i].setText(mCases.get(i).getTitle()); mDesc[i] = new TextView(this); mDesc[i].setText(mCases.get(i).getDescription()); mDesc[i].setTextSize(mDesc[i].getTextSize() - 2); mDesc[i].setPadding(42, 0, 10, 10); } TabContentFactory mTCF = new TabContentFactory() { public View createTabContent(String tag) { ViewGroup.LayoutParams fillParent = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); ViewGroup.LayoutParams fillWrap = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wrapContent = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); wrapContent.gravity = Gravity.CENTER; LinearLayout.LayoutParams weightedFillWrap = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); weightedFillWrap.weight = 1; if (tag.equals(MAIN)) { LinearLayout mMainView = new LinearLayout(Benchmark.this); mMainView.setOrientation(1); ScrollView mListScroll = new ScrollView(Benchmark.this); LinearLayout mMainViewContainer = new LinearLayout(Benchmark.this); mMainViewContainer.setOrientation(1); ImageView mIconView = new ImageView(Benchmark.this); mIconView.setImageResource(R.drawable.icon); TextView mBannerInfo = new TextView(Benchmark.this); mBannerInfo.setText("0xbench\nSelect benchmarks in the tabs,\nor batch select:"); d2CheckBox = new CheckBox(Benchmark.this); d2CheckBox.setText(D2); d2CheckBox.setOnClickListener(Benchmark.this); d3CheckBox = new CheckBox(Benchmark.this); d3CheckBox.setText(D3); d3CheckBox.setOnClickListener(Benchmark.this); mathCheckBox = new CheckBox(Benchmark.this); mathCheckBox.setText(MATH); mathCheckBox.setOnClickListener(Benchmark.this); vmCheckBox = new CheckBox(Benchmark.this); vmCheckBox.setText(VM); vmCheckBox.setOnClickListener(Benchmark.this); nativeCheckBox = new CheckBox(Benchmark.this); nativeCheckBox.setText(NATIVE); nativeCheckBox.setOnClickListener(Benchmark.this); miscCheckBox = new CheckBox(Benchmark.this); miscCheckBox.setText(MISC); miscCheckBox.setOnClickListener(Benchmark.this); TextView mWebInfo = new TextView(Benchmark.this); mWebInfo.setText("Uploaded results:\nhttp://0xbenchmark.appspot.com"); LinearLayout mButtonContainer = new LinearLayout(Benchmark.this); mRun = new Button(Benchmark.this); mShow = new Button(Benchmark.this); mRun.setText("Run"); mShow.setText("Show"); mRun.setOnClickListener(Benchmark.this); mShow.setOnClickListener(Benchmark.this); mButtonContainer.addView(mRun, weightedFillWrap); mButtonContainer.addView(mShow, weightedFillWrap); WebView mTracker = new WebView(Benchmark.this); mTracker.clearCache(true); mTracker.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { Log.i(TAG, "Tracker: " + view.getTitle() + " -> " + url); } public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "Track err: " + description); } }); mTracker.loadUrl(trackerUrl); mMainViewContainer.addView(mIconView, wrapContent); mMainViewContainer.addView(mBannerInfo); mMainViewContainer.addView(mathCheckBox); mMainViewContainer.addView(d2CheckBox); mMainViewContainer.addView(d3CheckBox); mMainViewContainer.addView(vmCheckBox); mMainViewContainer.addView(nativeCheckBox); mMainViewContainer.addView(miscCheckBox); mMainViewContainer.addView(mWebInfo); mMainViewContainer.addView(mButtonContainer, fillWrap); mMainViewContainer.addView(mTracker, 0, 0); mListScroll.addView(mMainViewContainer, fillParent); mMainView.addView(mListScroll, fillWrap); return mMainView; } LinearLayout mMainView = new LinearLayout(Benchmark.this); mMainView.setOrientation(1); ScrollView mListScroll = new ScrollView(Benchmark.this); LinearLayout mListContainer = new LinearLayout(Benchmark.this); mListContainer.setOrientation(1); mListScroll.addView(mListContainer, fillParent); mMainView.addView(mListScroll, fillWrap); boolean gray = true; int length = mCases.size(); Log.i(TAG, "L: " + length); Log.i(TAG, "TCF: " + tag); for (int i = 0; i < length; i++) { if (!mCategory.get(tag).contains(mCases.get(i))) continue; Log.i(TAG, "Add: " + i); mListContainer.addView(mCheckList[i], fillWrap); mListContainer.addView(mDesc[i], fillWrap); if (gray) { int color = 0xFF333333; //ARGB mCheckList[i].setBackgroundColor(color); mDesc[i].setBackgroundColor(color); } gray = !gray; } return mMainView; } }; mTabHost.addTab(mTabHost.newTabSpec(MAIN).setIndicator(MAIN, getResources().getDrawable(R.drawable.ic_eye)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D2).setIndicator(D2, getResources().getDrawable(R.drawable.ic_2d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D3).setIndicator(D3, getResources().getDrawable(R.drawable.ic_3d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(MATH).setIndicator(MATH, getResources().getDrawable(R.drawable.ic_pi)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(VM).setIndicator(VM, getResources().getDrawable(R.drawable.ic_vm)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(NATIVE) .setIndicator(NATIVE, getResources().getDrawable(R.drawable.ic_c)).setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(MISC).setIndicator(MISC, getResources().getDrawable(R.drawable.ic_misc)) .setContent(mTCF)); }
From source file:com.skytree.epubtest.BookViewActivity.java
public void makeFontBox() { int boxColor = Color.rgb(241, 238, 229); int innerBoxColor = Color.rgb(246, 244, 239); int inlineColor = Color.rgb(133, 105, 75); int width = 450; int height = 500; fontBox = new SkyBox(this); fontBox.setBoxColor(boxColor);/*from www . j av a2 s. c o m*/ fontBox.setArrowHeight(ps(25)); fontBox.setArrowDirection(false); setFrame(fontBox, ps(50), ps(200), ps(width), ps(height)); ScrollView fontBoxScrollView = new ScrollView(this); this.setFrame(fontBoxScrollView, ps(5), ps(10), ps(440), ps(height - 50)); fontBox.contentView.addView(fontBoxScrollView); // NEW SkyLayout contentLayout = new SkyLayout(this); fontBoxScrollView.addView(contentLayout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); // #1 first make brightness controller // brView is the box containing the bright slider. int FY = 10; View brView = new View(this); RoundRectShape rrs = new RoundRectShape( new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null); SkyDrawable srd = new SkyDrawable(rrs, innerBoxColor, inlineColor, 1); brView.setBackgroundDrawable(srd); setFrame(brView, ps(20), ps(FY), ps(width - 40), ps(53)); contentLayout.addView(brView); // darker and brighter icons int SBS = 60; ImageButton sbb = this.makeImageButton(9005, R.drawable.brightness2x, ps(SBS), ps(SBS)); setFrame(sbb, ps(50), ps(FY), ps(SBS), ps(SBS)); sbb.setAlpha(200); int BBS = 70; ImageButton bbb = this.makeImageButton(9006, R.drawable.brightness2x, ps(BBS), ps(BBS)); setFrame(bbb, ps(width - 110), ps(FY - 5), ps(BBS), ps(BBS)); bbb.setAlpha(200); contentLayout.addView(sbb); contentLayout.addView(bbb); // making bright slider brightBar = new SeekBar(this); brightBar.setMax(999); brightBar.setId(997); brightBar.setBackgroundColor(Color.TRANSPARENT); brightBar.setOnSeekBarChangeListener(new SeekBarDelegate()); brightBar.setProgressDrawable(new LineDrawable(Color.rgb(160, 160, 160), ps(10))); brightBar.setThumbOffset(-1); setFrame(brightBar, ps(100), ps(FY + 4), ps(width - 210), ps(50)); contentLayout.addView(brightBar); // #2 second make decrese/increse font size buttons // decrease font size Button int FBY = 80; decreaseButton = new Button(this); setFrame(decreaseButton, ps(20), ps(FBY), ps(width - 40 - 20) / 2, ps(60)); decreaseButton.setText(getString(R.string.chara)); decreaseButton.setGravity(Gravity.CENTER); decreaseButton.setTextSize(14); decreaseButton.setId(5000); RoundRectShape drs = new RoundRectShape( new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null); SkyDrawable drd = new SkyDrawable(drs, innerBoxColor, inlineColor, 1); decreaseButton.setBackgroundDrawable(drd); decreaseButton.setOnClickListener(listener); decreaseButton.setOnTouchListener(new ButtonHighlighterOnTouchListener(decreaseButton)); contentLayout.addView(decreaseButton); // inccrease font size Button increaseButton = new Button(this); setFrame(increaseButton, ps(10 + width / 2), ps(FBY), ps(width - 40 - 20) / 2, ps(60)); increaseButton.setText(getString(R.string.chara)); increaseButton.setTextSize(18); increaseButton.setGravity(Gravity.CENTER); increaseButton.setId(5001); RoundRectShape irs = new RoundRectShape( new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null); SkyDrawable ird = new SkyDrawable(irs, innerBoxColor, inlineColor, 1); increaseButton.setBackgroundDrawable(ird); increaseButton.setOnClickListener(listener); increaseButton.setOnTouchListener(new ButtonHighlighterOnTouchListener(increaseButton)); contentLayout.addView(increaseButton); // # 3 make the button to increase/decrese line spacing. int LBY = 145; // deccrease line space Button decreaseLineSpaceButton = this.makeImageButton(9005, R.drawable.decline2x, ps(30), ps(30)); setFrame(decreaseLineSpaceButton, ps(20), ps(LBY), ps(width - 40 - 20) / 2, ps(60)); decreaseLineSpaceButton.setId(4000); drs = new RoundRectShape(new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null); drd = new SkyDrawable(drs, innerBoxColor, inlineColor, 1); decreaseLineSpaceButton.setBackgroundDrawable(drd); decreaseLineSpaceButton.setOnClickListener(listener); decreaseLineSpaceButton .setOnTouchListener(new ImageButtonHighlighterOnTouchListener(decreaseLineSpaceButton)); contentLayout.addView(decreaseLineSpaceButton); // inccrease line space Button increaseLineSpaceButton = this.makeImageButton(9005, R.drawable.incline2x, ps(30), ps(30)); setFrame(increaseLineSpaceButton, ps(10 + width / 2), ps(LBY), ps(width - 40 - 20) / 2, ps(60)); increaseLineSpaceButton.setId(4001); irs = new RoundRectShape(new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null); ird = new SkyDrawable(irs, innerBoxColor, inlineColor, 1); increaseLineSpaceButton.setBackgroundDrawable(ird); increaseLineSpaceButton.setOnClickListener(listener); increaseLineSpaceButton .setOnTouchListener(new ImageButtonHighlighterOnTouchListener(increaseLineSpaceButton)); contentLayout.addView(increaseLineSpaceButton); // #4 make themes selector. int TY = 220; int TH = 70; int TW = (width - 40 - 20) / 3; HorizontalScrollView themeScrollView = new HorizontalScrollView(this); themesView = new LinearLayout(this); themesView.setOrientation(LinearLayout.HORIZONTAL); themeScrollView.addView(themesView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); for (int i = 0; i < this.themes.size(); i++) { Theme theme = themes.get(i); Button themeButton = new Button(this); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ps(TW), ps(TH)); layoutParams.setMargins(0, 0, 24, 0); themesView.addView(themeButton, layoutParams); RoundRectShape rs = new RoundRectShape( new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null); SkyDrawable brd = new SkyDrawable(rs, theme.backgroundColor, Color.BLACK, 1); themeButton.setBackgroundDrawable(brd); themeButton.setText(theme.name); themeButton.setTextColor(theme.foregroundColor); themeButton.setId(7000 + i); themeButton.setOnClickListener(listener); } this.setFrame(themeScrollView, ps(20), ps(TY), ps(width - 40), ps(90)); contentLayout.addView(themeScrollView); // #5 font list box int SY = 310; int fontButtonHeight = 80; int fontListHeight; fontListHeight = fontButtonHeight * fonts.size(); fontListView = new LinearLayout(this); fontListView.setOrientation(LinearLayout.VERTICAL); contentLayout.addView(fontListView); this.setFrame(fontListView, ps(20), ps(SY), ps(width - 40), ps(fontListHeight)); int inlineColor2 = Color.argb(140, 133, 105, 75); for (int i = 0; i < fonts.size(); i++) { CustomFont customFont = fonts.get(i); Button fontButton = new Button(this); fontButton.setText(customFont.fontFaceName); fontButton.setTextSize(20); Typeface tf = null; if (customFont.fontFileName == null || customFont.fontFileName.isEmpty()) { tf = this.getTypeface(customFont.fontFaceName, Typeface.BOLD); } else { tf = Typeface.createFromAsset(getAssets(), "fonts/" + customFont.fontFileName); } if (tf != null) fontButton.setTypeface(tf); fontButton.setId(5100 + i); RoundRectShape rs = new RoundRectShape( new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null); SkyDrawable brd = new SkyDrawable(rs, innerBoxColor, inlineColor2, 1); fontButton.setBackgroundDrawable(brd); this.setFrame(fontButton, ps(0), ps(0), ps(width - 40), ps(fontButtonHeight)); fontListView.addView(fontButton); fontButton.setOnClickListener(listener); fontButton.setOnTouchListener(new ButtonHighlighterOnTouchListener(fontButton)); } this.ePubView.addView(fontBox); this.hideFontBox(); }
From source file:org.zeroxlab.benchmark.Benchmark.java
private void initViews() { /*/*from ww w . ja v a 2 s . com*/ mRun = (Button)findViewById(R.id.btn_run); mRun.setOnClickListener(this); mShow = (Button)findViewById(R.id.btn_show); mShow.setOnClickListener(this); mShow.setClickable(false); mLinearLayout = (LinearLayout)findViewById(R.id.list_container); mMainView = (LinearLayout)findViewById(R.id.main_view); mBannerInfo = (TextView)findViewById(R.id.banner_info); mBannerInfo.setText("Hello!\nSelect cases to Run.\nUploaded results:\nhttp://0xbenchmark.appspot.com"); */ mTabHost = getTabHost(); int length = mCases.size(); mCheckList = new CheckBox[length]; mDesc = new TextView[length]; for (int i = 0; i < length; i++) { mCheckList[i] = new CheckBox(this); mCheckList[i].setText(mCases.get(i).getTitle()); mDesc[i] = new TextView(this); mDesc[i].setText(mCases.get(i).getDescription()); mDesc[i].setTextSize(mDesc[i].getTextSize() - 2); mDesc[i].setPadding(42, 0, 10, 10); } TabContentFactory mTCF = new TabContentFactory() { public View createTabContent(String tag) { ViewGroup.LayoutParams fillParent = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); ViewGroup.LayoutParams fillWrap = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wrapContent = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); wrapContent.gravity = Gravity.CENTER; LinearLayout.LayoutParams weightedFillWrap = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); weightedFillWrap.weight = 1; if (tag.equals(MAIN)) { LinearLayout mMainView = new LinearLayout(Benchmark.this); mMainView.setOrientation(1); ScrollView mListScroll = new ScrollView(Benchmark.this); LinearLayout mMainViewContainer = new LinearLayout(Benchmark.this); mMainViewContainer.setOrientation(1); ImageView mIconView = new ImageView(Benchmark.this); mIconView.setImageResource(R.drawable.icon); TextView mBannerInfo = new TextView(Benchmark.this); mBannerInfo.setText("0xbench\nSelect benchmarks in the tabs,\nor batch select:"); d2CheckBox = new CheckBox(Benchmark.this); d2CheckBox.setText(D2); d2CheckBox.setOnClickListener(Benchmark.this); d2HWCheckBox = new CheckBox(Benchmark.this); d2HWCheckBox.setText(D2HW); d2HWCheckBox.setOnClickListener(Benchmark.this); d2SW1CheckBox = new CheckBox(Benchmark.this); d2SW1CheckBox.setText(D2SW1); d2SW1CheckBox.setOnClickListener(Benchmark.this); d2SW2CheckBox = new CheckBox(Benchmark.this); d2SW2CheckBox.setText(D2SW2); d2SW2CheckBox.setOnClickListener(Benchmark.this); d3CheckBox = new CheckBox(Benchmark.this); d3CheckBox.setText(D3); d3CheckBox.setOnClickListener(Benchmark.this); mathCheckBox = new CheckBox(Benchmark.this); mathCheckBox.setText(MATH); mathCheckBox.setOnClickListener(Benchmark.this); vmCheckBox = new CheckBox(Benchmark.this); vmCheckBox.setText(VM); vmCheckBox.setOnClickListener(Benchmark.this); nativeCheckBox = new CheckBox(Benchmark.this); nativeCheckBox.setText(NATIVE); nativeCheckBox.setOnClickListener(Benchmark.this); miscCheckBox = new CheckBox(Benchmark.this); miscCheckBox.setText(MISC); miscCheckBox.setOnClickListener(Benchmark.this); filterBitmapCheckBox = new CheckBox(Benchmark.this); filterBitmapCheckBox.setText("Filter Bitmap in Draw Image"); filterBitmapCheckBox.setOnClickListener(Benchmark.this); useGradientCheckBox = new CheckBox(Benchmark.this); useGradientCheckBox.setText("Use Gradient in Draw Canvas/Circle/Rect/Arc"); useGradientCheckBox.setOnClickListener(Benchmark.this); useTextureCheckBox = new CheckBox(Benchmark.this); useTextureCheckBox.setText("Use Texture in Draw Canvas/Circle/Rect/Arc"); useTextureCheckBox.setOnClickListener(Benchmark.this); TextView mWebInfo = new TextView(Benchmark.this); mWebInfo.setText("Uploaded results:\nhttp://0xbenchmark.appspot.com"); LinearLayout mButtonContainer = new LinearLayout(Benchmark.this); mRun = new Button(Benchmark.this); mShow = new Button(Benchmark.this); mRun.setText("Run"); mShow.setText("Show"); mRun.setOnClickListener(Benchmark.this); mShow.setOnClickListener(Benchmark.this); mButtonContainer.addView(mRun, weightedFillWrap); mButtonContainer.addView(mShow, weightedFillWrap); WebView mTracker = new WebView(Benchmark.this); mTracker.clearCache(true); mTracker.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { Log.i(TAG, "Tracker: " + view.getTitle() + " -> " + url); } public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "Track err: " + description); } }); mTracker.loadUrl(trackerUrl); mMainViewContainer.addView(mIconView, wrapContent); mMainViewContainer.addView(mBannerInfo); mMainViewContainer.addView(mathCheckBox); mMainViewContainer.addView(d2CheckBox); mMainViewContainer.addView(d2HWCheckBox); mMainViewContainer.addView(d2SW1CheckBox); mMainViewContainer.addView(d2SW2CheckBox); mMainViewContainer.addView(d3CheckBox); mMainViewContainer.addView(vmCheckBox); mMainViewContainer.addView(nativeCheckBox); mMainViewContainer.addView(miscCheckBox); mMainViewContainer.addView(filterBitmapCheckBox); mMainViewContainer.addView(useGradientCheckBox); mMainViewContainer.addView(useTextureCheckBox); mMainViewContainer.addView(mWebInfo); mMainViewContainer.addView(mButtonContainer, fillWrap); mMainViewContainer.addView(mTracker, 0, 0); mListScroll.addView(mMainViewContainer, fillParent); mMainView.addView(mListScroll, fillWrap); return mMainView; } LinearLayout mMainView = new LinearLayout(Benchmark.this); mMainView.setOrientation(1); ScrollView mListScroll = new ScrollView(Benchmark.this); LinearLayout mListContainer = new LinearLayout(Benchmark.this); mListContainer.setOrientation(1); mListScroll.addView(mListContainer, fillParent); mMainView.addView(mListScroll, fillWrap); boolean gray = true; int length = mCases.size(); Log.i(TAG, "L: " + length); Log.i(TAG, "TCF: " + tag); for (int i = 0; i < length; i++) { if (!mCategory.get(tag).contains(mCases.get(i))) continue; Log.i(TAG, "Add: " + i); mListContainer.addView(mCheckList[i], fillWrap); mListContainer.addView(mDesc[i], fillWrap); if (gray) { int color = 0xFF333333; //ARGB mCheckList[i].setBackgroundColor(color); mDesc[i].setBackgroundColor(color); } gray = !gray; } return mMainView; } }; mTabHost.addTab(mTabHost.newTabSpec(MAIN).setIndicator(MAIN, getResources().getDrawable(R.drawable.ic_eye)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D2).setIndicator(D2, getResources().getDrawable(R.drawable.ic_2d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D2HW).setIndicator(D2HW, getResources().getDrawable(R.drawable.ic_2d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D2SW1).setIndicator(D2SW1, getResources().getDrawable(R.drawable.ic_2d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D2SW2).setIndicator(D2SW2, getResources().getDrawable(R.drawable.ic_2d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(D3).setIndicator(D3, getResources().getDrawable(R.drawable.ic_3d)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(MATH).setIndicator(MATH, getResources().getDrawable(R.drawable.ic_pi)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(VM).setIndicator(VM, getResources().getDrawable(R.drawable.ic_vm)) .setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(NATIVE) .setIndicator(NATIVE, getResources().getDrawable(R.drawable.ic_c)).setContent(mTCF)); mTabHost.addTab(mTabHost.newTabSpec(MISC).setIndicator(MISC, getResources().getDrawable(R.drawable.ic_misc)) .setContent(mTCF)); }