List of usage examples for android.widget ImageButton ImageButton
public ImageButton(Context context)
From source file:com.murrayc.galaxyzoo.app.QuestionHelpFragment.java
private void addRowForAnswer(final Context context, final TableLayout tableLayout, final DecisionTree.Question question, final DecisionTree.BaseButton answer) { final TableRow row = new TableRow(context); final TableLayout.LayoutParams params = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT); params.setMargins(0, UiUtils.getPxForDpResource(context, R.dimen.standard_large_margin), 0, 0); tableLayout.addView(row, params);//from ww w. jav a2s . c om final LinearLayout layoutVertical = new LinearLayout(context); layoutVertical.setOrientation(LinearLayout.VERTICAL); final TextView textViewAnswer = new AppCompatTextView(context); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { textViewAnswer.setTextAppearance(R.style.TextAppearance_AppCompat_Subhead); } else { //noinspection deprecation textViewAnswer.setTextAppearance(context, R.style.TextAppearance_AppCompat_Subhead); } textViewAnswer.setText(answer.getText()); layoutVertical.addView(textViewAnswer, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); final LinearLayout layoutHorizontal = new LinearLayout(context); layoutHorizontal.setOrientation(LinearLayout.HORIZONTAL); final LinearLayout.LayoutParams paramsHorizontal = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); paramsHorizontal.setMargins(0, UiUtils.getPxForDpResource(context, R.dimen.standard_margin), 0, 0); layoutVertical.addView(layoutHorizontal, paramsHorizontal); final BitmapDrawable icon = getIcon(context, answer); final ImageView imageIcon = new ImageView(context); imageIcon.setImageDrawable(icon); layoutHorizontal.addView(imageIcon); final LinearLayout.LayoutParams paramsImage = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); // TODO: Use a custom FlowTable class to avoid items going off the right edge of the screen // when there are too many. final Singleton singleton = getSingleton(); for (int i = 0; i < answer.getExamplesCount(); i++) { final String iconName = answer.getExampleIconName(question.getId(), i); final BitmapDrawable iconExample = singleton.getIconDrawable(context, iconName); final ImageButton imageExample = new ImageButton(context); //Remove the space between the image and the outside of the button: imageExample.setPadding(0, 0, 0, 0); imageExample.setImageDrawable(iconExample); //Needed to make the image expand as a transition into the SubjectViewerActivity, //which uses the same name in fragment_subject.xml ViewCompat.setTransitionName(imageExample, getString(R.string.transition_subject_image)); //This requires API level 17: paramsImage.setMarginStart(getPxForDp(activity, MARGIN_MEDIUM_DP)); //imageExample.setLayoutParams(paramsImage); MarginLayoutParamsCompat.setMarginStart(paramsImage, UiUtils.getPxForDpResource(context, R.dimen.standard_large_margin)); final int answerIndex = i; imageExample.setOnClickListener(new View.OnClickListener() { public void onClick(final View v) { // Perform action on click onExampleImageClicked(v, answer, answerIndex); } }); layoutHorizontal.addView(imageExample, paramsImage); } row.addView(layoutVertical, new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); }
From source file:mobisocial.musubi.ui.fragments.AppSelectDialog.java
private void setActionItems(ViewGroup view) { final Context context = mActivity; FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); List<FeedAction> actions = FeedAction.getFeedActions(); for (final FeedAction a : actions) { if (a.isActive(context)) { ft.add(a, a.getName());/*from w w w . ja va 2s . co m*/ ImageButton b = new ImageButton(context); b.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); b.setImageDrawable(a.getIcon(mActivity)); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { a.onClick(context, mFeedUri); Dialog d = getDialog(); if (d != null) d.dismiss(); } }); view.addView(b); } } ft.commit(); }
From source file:bigshots.people_helping_people.scroll_iew_lib.PagerSlidingTabStrip.java
private void addIconTab(final int position, int resId) { ImageButton tab = new ImageButton(getContext()); tab.setImageResource(resId);/* ww w . j a v a2 s. c o m*/ addTab(position, tab); }
From source file:com.qhzlwh.yigua.view.PagerTab.java
@SuppressWarnings("unused") private void addIconTab(final int position, int resId) { ImageButton tab = new ImageButton(getContext()); tab.setImageResource(resId);//from www.ja va 2 s. c o m addTab(position, tab); }
From source file:com.scoreflex.ScoreflexView.java
/** * The constructor of the view.//from w w w . j av a 2 s . c o m * @param activity The activity holding the view. * @param attrs * @param defStyle */ @SuppressWarnings("deprecation") public ScoreflexView(Activity activity, AttributeSet attrs, int defStyle) { super(activity, attrs, defStyle); // Keep a reference on the activity mParentActivity = activity; // Default layout params if (null == getLayoutParams()) { setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Scoreflex.getDensityIndependantPixel(R.dimen.scoreflex_panel_height))); } // Set our background color setBackgroundColor(getContext().getResources().getColor(R.color.scoreflex_background_color)); // Create the top bar View topBar = new View(getContext()); topBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height), Gravity.TOP)); topBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.scoreflex_gradient_background)); addView(topBar); // Create the retry button LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); mErrorLayout = (ViewGroup) inflater.inflate(R.layout.scoreflex_error_layout, null); if (mErrorLayout != null) { // Configure refresh button Button refreshButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_retry_button); if (null != refreshButton) { refreshButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { if (null == Scoreflex.getPlayerId()) { setUserInterfaceState(new LoadingState()); loadUrlAfterLoggedIn(mInitialResource, mInitialRequestParams); } else if (null == mWebView.getUrl()) { setResource(mInitialResource); } else { mWebView.reload(); } } }); } // Configure cancel button Button cancelButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_cancel_button); if (null != cancelButton) { cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { close(); } }); } // Get hold of the message view mMessageView = (TextView) mErrorLayout.findViewById(R.id.scoreflex_error_message_view); addView(mErrorLayout); } // Create the close button mCloseButton = new ImageButton(getContext()); Drawable closeButtonDrawable = getResources().getDrawable(R.drawable.scoreflex_close_button); int closeButtonMargin = (int) ((getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height) - closeButtonDrawable.getIntrinsicHeight()) / 2.0f); FrameLayout.LayoutParams closeButtonLayoutParams = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.TOP | Gravity.RIGHT); closeButtonLayoutParams.setMargins(0, closeButtonMargin, closeButtonMargin, 0); mCloseButton.setLayoutParams(closeButtonLayoutParams); mCloseButton.setImageDrawable(closeButtonDrawable); mCloseButton.setBackgroundDrawable(null); mCloseButton.setPadding(0, 0, 0, 0); mCloseButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { close(); } }); addView(mCloseButton); // Create the web view mWebView = new WebView(mParentActivity); mWebView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // mWebView.setBackgroundColor(Color.RED); mWebView.setWebViewClient(new ScoreflexWebViewClient()); mWebView.setWebChromeClient(new WebChromeClient() { @Override public boolean onConsoleMessage(ConsoleMessage cm) { Log.d("Scoreflex", "javascript Error: " + String.format("%s @ %d: %s", cm.message(), cm.lineNumber(), cm.sourceId())); return true; } public void openFileChooser(ValueCallback<Uri> uploadMsg) { // mtbActivity.mUploadMessage = uploadMsg; mUploadMessage = uploadMsg; String fileName = "picture.jpg"; ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, fileName); // mOutputFileUri = mParentActivity.getContentResolver().insert( // MediaStore.Images.Media.DATA, values); final List<Intent> cameraIntents = new ArrayList<Intent>(); final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); final PackageManager packageManager = mParentActivity.getPackageManager(); final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0); for (ResolveInfo res : listCam) { final String packageName = res.activityInfo.packageName; final Intent intent = new Intent(captureIntent); intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); intent.setPackage(packageName); cameraIntents.add(intent); } // Filesystem. final Intent galleryIntent = new Intent(); galleryIntent.setType("image/*"); galleryIntent.setAction(Intent.ACTION_GET_CONTENT); // Chooser of filesystem options. final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source please"); // Add the camera options. chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {})); mParentActivity.startActivityForResult(chooserIntent, Scoreflex.FILECHOOSER_RESULTCODE); } public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { openFileChooser(uploadMsg); } public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { openFileChooser(uploadMsg); } }); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setDomStorageEnabled(true); mWebView.getSettings().setDatabasePath( getContext().getFilesDir().getPath() + "/data/" + getContext().getPackageName() + "/databases/"); addView(mWebView); TypedArray a = mParentActivity.obtainStyledAttributes(attrs, R.styleable.ScoreflexView, defStyle, 0); String resource = a.getString(R.styleable.ScoreflexView_resource); if (null != resource) setResource(resource); a.recycle(); // Create the animated spinner mProgressBar = (ProgressBar) ((LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.scoreflex_progress_bar, null); mProgressBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER)); addView(mProgressBar); LocalBroadcastManager.getInstance(activity).registerReceiver(mLoginReceiver, new IntentFilter(Scoreflex.INTENT_USER_LOGED_IN)); setUserInterfaceState(new InitialState()); }
From source file:dk.nordfalk.aktivitetsliste.PagerSlidingTabStrip.java
private void addIconTab(final int position, int resId, String contentDescription) { ImageButton tab = new ImageButton(getContext()); tab.setContentDescription(contentDescription); tab.setImageResource(resId);//from w w w. j av a2 s .c o m addTab(position, tab); }
From source file:com.metinkale.prayerapp.utils.PagerSlidingTabStrip.java
private void addIconTab(int position, int resId) { ImageButton tab = new ImageButton(getContext()); tab.setImageResource(resId);/*from ww w . j ava 2 s. c o m*/ addTab(position, tab); }
From source file:mobisocial.musubi.ui.fragments.AccountLinkDialog.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LinearLayout window = new LinearLayout(mActivity); window.setLayoutParams(CommonLayouts.FULL_SCREEN); window.setOrientation(LinearLayout.VERTICAL); LinearLayout socialBox = new LinearLayout(mActivity); socialBox.setLayoutParams(CommonLayouts.FULL_WIDTH); socialBox.setOrientation(LinearLayout.HORIZONTAL); socialBox.setWeightSum(1.0f * DISPLAYED_SERVICES); /** Google **/ ImageButton google = new ImageButton(mActivity); google.setImageResource(R.drawable.google); google.setOnClickListener(mGoogleClickListener); google.setLayoutParams(// w ww . j ava 2 s . c o m new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f)); google.setAdjustViewBounds(true); socialBox.addView(google); /** Facebook **/ ImageButton facebook = new ImageButton(mActivity); facebook.setImageResource(R.drawable.facebook); facebook.setOnClickListener(mFacebookClickListener); facebook.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f)); facebook.setAdjustViewBounds(true); socialBox.addView(facebook); /** Phone Number **/ ImageButton phone = new ImageButton(mActivity); phone.setImageResource(R.drawable.phone); phone.setOnClickListener(mPhoneClickListener); phone.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f)); phone.setAdjustViewBounds(true); //socialBox.addView(phone); /** List of known accounts **/ TextView chooseService = new TextView(mActivity); chooseService.setText("Choose a service to connect."); chooseService.setVisibility(View.GONE); chooseService.setLayoutParams(CommonLayouts.FULL_SCREEN); chooseService.setTextSize(20); mAccountAdapter = new AccountAdapter(getActivity()); mAccountList = new ListView(getActivity()); mAccountList.setAdapter(mAccountAdapter); mAccountList.setPadding(6, 10, 6, 0); mAccountList.setLayoutParams(CommonLayouts.FULL_SCREEN); mAccountList.setEmptyView(chooseService); /** Put it together **/ window.addView(socialBox); window.addView(mAccountList); window.addView(chooseService); initialize(); return window; }
From source file:com.agenmate.lollipop.addedit.AddEditFragment.java
@Nullable @Override//from ww w. j a v a 2 s. c om public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_edit, container, false); unbinder = ButterKnife.bind(this, rootView); timePickerLayout.setColorArcMenu(colorButtons); formatText(titleText, "<b>T</b>itle"); formatText(titleEdit, null); formatText(descText, "<b>D</b>escription"); formatText(descEdit, null); formatText(colorText, "<b>C</b>olor <b>T</b>ag"); formatText(priorityText, "<b>P</b>riority"); formatText(dueDateText, "<b>D</b>ue <b>D</b>ate"); formatText(dueDateTeller, null); formatText(dueDateStatus, "(Scroll up to set)"); seekBar.setProgressDrawable(R.drawable.progress_bar); seekBar.setItems(new String[] { "Low", "Medium", "High" }); seekBar.setTextIndicatorColor(Color.BLACK); seekBar.setIndicatorColor(ContextCompat.getColor(getActivity(), R.color.md_grey_300)); seekBar.setTextSize(14); seekBar.setIndicatorSize(4); BottomSheetBehavior.from(sheet).setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { @Override public void onStateChanged(@NonNull View bottomSheet, int newState) { switch (newState) { case BottomSheetBehavior.STATE_DRAGGING: dueDateStatus.setText(""); break; case BottomSheetBehavior.STATE_COLLAPSED: if (previousState == BottomSheetBehavior.STATE_EXPANDED) { previousState = newState; ButterKnife.apply(bottomViews, ALPHA_APPEAR); onColorArcExpanded(); setDueDateText(dueDateStatus); if (timeMenu.isExpanded()) timeMenu.switchState(); } break; case BottomSheetBehavior.STATE_EXPANDED: if (previousState == BottomSheetBehavior.STATE_COLLAPSED) { previousState = newState; ButterKnife.apply(bottomViews, ALPHA_FADE); for (int i = 0; i < 7; i++) colorButtons[i].setAlpha(1f); if (!timeMenu.isExpanded()) timePickerLayout.getDayArcMenu().switchState(); } break; } } @Override public void onSlide(View bottomSheet, float slideOffset) { } }); /*ViewUtils.waitForLayoutPrepared(seekBar, new ViewUtils.LayoutPreparedListener() { @Override public void onLayoutPrepared(final View preparedView) { seekBar.setProgressToIndex(1); } });*/ for (int i = 0; i < 7; i++) { final int index = i; final ImageButton button = new ImageButton(getActivity()); button.setBackgroundResource(colorDrawables[i]); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { button.setElevation(ScreenUtils.dpToPx(getActivity(), 2)); } colorButtons[i] = button; arcMenu.addItem(button, v -> { v.setAlpha(0.5f); if (index != selectedColor) { colorButtons[selectedColor].setAlpha(1f); setColor(index); } }); } timeMenu = timePickerLayout.getDayArcMenu(); arcMenu.setOnArcAnimationEndListener(isExpanded -> { if (isExpanded) onColorArcExpanded(); }); arcMenu.switchState(); return rootView; }
From source file:com.jumeng.shop.view.PagerSlidingTabStrip.java
private void addIconTab(final int position, int resId) { ImageButton tab = new ImageButton(getContext()); tab.setImageResource(resId);/*ww w . java 2s .c om*/ addTab(position, tab); }