@Override public void initButtons() { ImageButton take_picture = new ImageButton(a); take_picture.setBackgroundColor(getResources().getColor(android.R.color.transparent)); take_picture.setPadding(0, 0, 0, 0); take_picture.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { ((FragmentListener) a).doWait(true); cover_image_file = new File(DUMP, "temp_img.jpg"); cover_image_uri = Uri.fromFile(cover_image_file); path_to_cover_image = cover_image_file.getAbsolutePath(); Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE) .putExtra(MediaStore.EXTRA_OUTPUT, cover_image_uri); startActivityForResult(cameraIntent, Source.CAMERA); } }); take_picture.setImageResource(R.drawable.camera_selector); ImageButton choose_picture = new ImageButton(a); choose_picture.setBackgroundColor(getResources().getColor(android.R.color.transparent)); choose_picture.setPadding(0, 0, 0, 0); choose_picture.setOnClickListener(choose_picture_listener); choose_picture.setImageResource(R.drawable.gallery_selector); ((FragmentListener) a).setButtonOptions(new ImageButton[] {take_picture, choose_picture}); }
/** * 绘制导航布局 * * @return */ private LinearLayout drawNavTitle() { LinearLayout navTitle = createLinearLayout(LinearLayout.HORIZONTAL, LayoutParams.MATCH_PARENT, 0, 1.5f); navTitle.setGravity(Gravity.CENTER); // 左右按键和中间标题应该很容易看懂 ImageButton left = new ImageButton(getContext()); left.setBackgroundColor(Color.TRANSPARENT); ImageButton right = new ImageButton(getContext()); right.setBackgroundColor(Color.TRANSPARENT); title = new TextView(getContext()); title.setTextSize(getResources().getDimension(R.dimen.calendar_title)); title.setPadding((int) (0.5 * tb), (int) (0.5 * tb), (int) (0.5 * tb), (int) (0.5 * tb)); navTitle.addView(left); navTitle.addView(title); navTitle.addView(right); left.setImageResource(R.drawable.calendar_prev); right.setImageResource(R.drawable.calendar_next); // 点击事件 left.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { lastMonth(); } }); right.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { nextMonth(); } }); return navTitle; }
/** * One of the tabs for KuView, reorganizes the ku list to show the 'recent' haikus * * @param view the screen view */ @OnClick(R.id.recentButton) public void onRecentButtonClicked(View view) { UpdateKus(KuRequest.KU_SORT_RECENT); mHotButton.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.grey_100)); mRecentButton.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.cyan_A700)); Snackbar.make(view, "Showing recent Kus!", Snackbar.LENGTH_LONG) .setAction("Action", null) .show(); }
private void createSaveButton() { mToolbar = ((MainActivity) getActivity()).getToolbar(); mToolbar.inflateMenu(R.menu.menu_save); ImageButton saveButton = (ImageButton) mToolbar.getMenu().findItem(R.id.save_view).getActionView(); saveButton.setImageDrawable( ContextCompat.getDrawable(getActivity(), R.drawable.ic_action_save)); saveButton.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.ColorPrimaryDark)); saveButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { if (isReadyToSave()) { saveUpdatedProfile(); Toast.makeText(getActivity(), "Successfully saved", Toast.LENGTH_SHORT).show(); InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow( view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); ((MainActivity) getActivity()).setupProfileOnDrawer(); ((MainActivity) getActivity()).openDrawer(); } } }); }
private void setZoomLayout(SharedPreferences options) { DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int colorMode = Options.getColorMode(options); int mode = ZOOM_COLOR_NORMAL; if (colorMode == Options.COLOR_MODE_GREEN_ON_BLACK) { mode = ZOOM_COLOR_GREEN; } else if (colorMode == Options.COLOR_MODE_RED_ON_BLACK) { mode = ZOOM_COLOR_RED; } // the zoom buttons if (zoomLayout != null) { activityLayout.removeView(zoomLayout); } zoomLayout = new LinearLayout(this); zoomLayout.setOrientation(LinearLayout.HORIZONTAL); zoomDownButton = new ImageButton(this); zoomDownButton.setImageDrawable(getResources().getDrawable(zoomDownId[mode])); zoomDownButton.setBackgroundColor(Color.TRANSPARENT); zoomLayout.addView( zoomDownButton, (int) (80 * metrics.density), (int) (50 * metrics.density)); // TODO: remove hardcoded values zoomWidthButton = new ImageButton(this); zoomWidthButton.setImageDrawable(getResources().getDrawable(zoomWidthId[mode])); zoomWidthButton.setBackgroundColor(Color.TRANSPARENT); zoomLayout.addView(zoomWidthButton, (int) (58 * metrics.density), (int) (50 * metrics.density)); zoomUpButton = new ImageButton(this); zoomUpButton.setImageDrawable(getResources().getDrawable(zoomUpId[mode])); zoomUpButton.setBackgroundColor(Color.TRANSPARENT); zoomLayout.addView(zoomUpButton, (int) (80 * metrics.density), (int) (50 * metrics.density)); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.CENTER_HORIZONTAL); lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); setZoomButtonHandlers(); activityLayout.addView(zoomLayout, lp); }
public cl(Activity activity, int i) { super(activity); oe = activity; setOnClickListener(this); oP = new ImageButton(activity); oP.setImageResource(0x1080017); oP.setBackgroundColor(0); oP.setOnClickListener(this); oP.setPadding(0, 0, 0, 0); int k = eu.a(activity, i); addView(oP, new android.widget.FrameLayout.LayoutParams(k, k, 17)); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cameraview); // image = (ImageView) findViewById(R.id.image); preview = (SurfaceView) findViewById(R.id.surface); previewHolder = preview.getHolder(); previewHolder.addCallback(surfaceCallback); previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); previewHolder.setFixedSize( getWindow().getWindowManager().getDefaultDisplay().getWidth(), getWindow().getWindowManager().getDefaultDisplay().getHeight()); nextButton = (ImageButton) findViewById(R.id.validateButton); nextButton.setBackgroundColor(Color.TRANSPARENT); nextButton.setPadding(0, 0, 0, 0); nextButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // finishActivity(1); camera.takePicture(null, null, photoCallback); // finish(); } }); String maskPath = getIntent().getStringExtra("maskPath"); try { // URL url = getClass().getResource("/assets/" + maskPath); File file = new File(maskPath); // String path = getFilesDir().getAbsolutePath() + "/assets/" + maskPath; // URL url = new URL(path); // Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream()); FileInputStream stream = new FileInputStream(file); Bitmap bmp = BitmapFactory.decodeStream(stream); imageView = (ImageView) findViewById(R.id.imageView); imageView.setImageBitmap(bmp); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("unable to read file : " + e.toString()); } }
public void earthClicked(View view) { ImageButton footballBtn = (ImageButton) findViewById(R.id.footballBtn); footballBtn.setBackgroundColor(Color.parseColor("#dddddd")); ImageButton pyramidBtn = (ImageButton) findViewById(R.id.pyramidBtn); pyramidBtn.setBackgroundColor(Color.parseColor("#dddddd")); ImageButton earthBtn = (ImageButton) findViewById(R.id.earthBtn); earthBtn.setBackgroundColor(Color.parseColor("#cbcbcb")); EditText feetText = (EditText) findViewById(R.id.feetInput); if (!feetText.getText().toString().equals("")) { feetValue = Integer.parseInt(feetText.getText().toString()); } EditText inchText = (EditText) findViewById(R.id.inchInput); if (!feetText.getText().toString().equals("")) { inchValue = Integer.parseInt(inchText.getText().toString()); } if (feetValue != 0) { Double strideDub = (((feetValue * 12) + inchValue) * 2.54) * 0.414; Integer strideLength = strideDub.intValue(); strideLength /= 10; // compensation for massive distance integer Integer distance = 400750000; totSteps = distance / strideLength; TextView totalSteps = (TextView) findViewById(R.id.totalSteps); totalSteps.setText(totSteps.toString()); reset = true; stopCounting = false; Toast.makeText(getApplicationContext(), "Initializing...", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(), "Please enter your height!", Toast.LENGTH_LONG) .show(); } }
private void initDisplay() { aspcaAlity_ = cat_.getASPCAality(); final int color = cat_.getASPCAalityColor(); final Bitmap bitmap = cat_.getSmPhoto(); imagePhoto_.setImageBitmap(bitmap); imagePhoto_.setBackgroundColor(color); final ImageView imageAdopted = (ImageView) findViewById(R.id.imageAdopted); final int status = cat_.getStatus(); int visibility = View.INVISIBLE; if (status == AppDBAdapter.STATUS_ADOPTED) { visibility = View.VISIBLE; } imageAdopted.setVisibility(visibility); final TextView textAgeSex = (TextView) findViewById(R.id.textAgeSex); final String age_sex = cat_.getAge() + " " + cat_.getSex(); textAgeSex.setText(age_sex); textAgeSex.setBackgroundColor(color); final int aspcaAlityResId = cat_.getASPCAalityResID(); textASPCAality_.setText(aspcaAlityResId); textASPCAality_.setBackgroundColor(color); final String name = cat_.getName(); textName_.setText(name); textName_.setTextColor(color); final TextView textBio = (TextView) findViewById(R.id.textBio); final int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion > android.os.Build.VERSION_CODES.DONUT) { textBio.setAutoLinkMask(Linkify.ALL); } final String bio_en = cat_.getBiography(); final String bioText = Util.concatNoTranslation(this, bio_en); textBio.setText(bioText); final TextView textPetID = (TextView) findViewById(R.id.textPetID); final String petID = getString(R.string.pet_id) + ": " + cat_.getPetID(); textPetID.setText(petID); textPetID.setBackgroundColor(color); }
private View createButton(Map<Object, Object> hash) { Context ctx = RhodesActivity.getContext(); Object actionObj = hash.get("action"); if (actionObj == null || !(actionObj instanceof String)) throw new IllegalArgumentException("'action' should be String"); String action = (String) actionObj; if (action.length() == 0) throw new IllegalArgumentException("'action' should not be empty"); Drawable icon = null; String label = null; View.OnClickListener onClick = null; if (action.equalsIgnoreCase("back")) { icon = ctx.getResources().getDrawable(AndroidR.drawable.back); onClick = new ActionBack(); } else if (action.equalsIgnoreCase("forward")) { if (RhodesService.isJQTouch_mode()) { return null; } icon = ctx.getResources().getDrawable(AndroidR.drawable.next); onClick = new ActionForward(); } else if (action.equalsIgnoreCase("home")) { icon = ctx.getResources().getDrawable(AndroidR.drawable.home); onClick = new ActionHome(); } else if (action.equalsIgnoreCase("options")) { icon = ctx.getResources().getDrawable(AndroidR.drawable.options); onClick = new ActionOptions(); } else if (action.equalsIgnoreCase("refresh")) { icon = ctx.getResources().getDrawable(AndroidR.drawable.refresh); onClick = new ActionRefresh(); } else if (action.equalsIgnoreCase("close") || action.equalsIgnoreCase("exit")) { icon = ctx.getResources().getDrawable(AndroidR.drawable.exit); onClick = new ActionExit(); } else if (action.equalsIgnoreCase("separator")) return null; DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(metrics); Object iconObj = hash.get("icon"); if (iconObj != null) { if (!(iconObj instanceof String)) throw new IllegalArgumentException("'icon' should be String"); String iconPath = "apps/" + (String) iconObj; iconPath = RhoFileApi.normalizePath(iconPath); Bitmap bitmap = BitmapFactory.decodeStream(RhoFileApi.open(iconPath)); if (bitmap == null) throw new IllegalArgumentException("Can't find icon: " + iconPath); bitmap.setDensity(DisplayMetrics.DENSITY_MEDIUM); icon = new BitmapDrawable(bitmap); } if (icon == null) { Object labelObj = hash.get("label"); if (labelObj == null || !(labelObj instanceof String)) throw new IllegalArgumentException("'label' should be String"); label = (String) labelObj; } if (icon == null && label == null) throw new IllegalArgumentException("One of 'icon' or 'label' should be specified"); if (onClick == null) onClick = new ActionCustom(action); View button; if (icon != null) { ImageButton btn = new ImageButton(ctx); btn.setImageDrawable(icon); button = btn; if (mCustomBackgroundColorEnable) { Drawable d = btn.getBackground(); if (d != null) { d.setColorFilter(mCustomBackgroundColor, android.graphics.PorterDuff.Mode.SRC_OVER); } else { btn.setBackgroundColor(mCustomBackgroundColor); } } } else { Button btn = new Button(ctx); btn.setText(label); if (mCustomBackgroundColorEnable) { btn.setBackgroundColor(mCustomBackgroundColor); int gray = (((mCustomBackgroundColor & 0xFF0000) >> 16) + ((mCustomBackgroundColor & 0xFF00) >> 8) + ((mCustomBackgroundColor & 0xFF))) / 3; if (gray > 128) { btn.setTextColor(0xFF000000); } else { btn.setTextColor(0xFFFFFFFF); } } button = btn; } button.setOnClickListener(onClick); return button; }
public void notifyDataSetChanged() { super.removeAllViews(); layout.removeAllViews(); if (!scrollable) { // not scrollable tabs int tabWidth = this.getWidth() / tabs.size(); // set params for resizing tabs width LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(tabWidth, HorizontalScrollView.LayoutParams.MATCH_PARENT); for (MaterialTab t : tabs) { layout.addView(t.getView(), params); } } else { // scrollable tabs if (!isTablet) { for (int i = 0; i < tabs.size(); i++) { LinearLayout.LayoutParams params; MaterialTab tab = tabs.get(i); int tabWidth = (int) (tab.getTabMinWidth() + (24 * density)); // 12dp // + // text/icon // width // + // 12dp if (i == 0) { // first tab View view = new View(layout.getContext()); view.setMinimumWidth((int) (60 * density)); layout.addView(view); } params = new LinearLayout.LayoutParams( tabWidth, HorizontalScrollView.LayoutParams.MATCH_PARENT); layout.addView(tab.getView(), params); if (i == tabs.size() - 1) { // last tab View view = new View(layout.getContext()); view.setMinimumWidth((int) (60 * density)); layout.addView(view); } } } else { // is a tablet for (int i = 0; i < tabs.size(); i++) { LinearLayout.LayoutParams params; MaterialTab tab = tabs.get(i); int tabWidth = (int) (tab.getTabMinWidth() + (48 * density)); // 24dp // + // text/icon // width // + // 24dp params = new LinearLayout.LayoutParams( tabWidth, HorizontalScrollView.LayoutParams.MATCH_PARENT); layout.addView(tab.getView(), params); } } } if (isTablet && scrollable) { // if device is a tablet and have scrollable tabs add right and left // arrows Resources res = getResources(); left = new ImageButton(this.getContext()); left.setId(R.id.left); left.setImageDrawable(res.getDrawable(R.drawable.left_arrow)); left.setBackgroundColor(Color.TRANSPARENT); left.setOnClickListener(this); // set 56 dp width and 48 dp height RelativeLayout.LayoutParams paramsLeft = new LayoutParams((int) (56 * density), (int) (48 * density)); paramsLeft.addRule(RelativeLayout.ALIGN_PARENT_LEFT); paramsLeft.addRule(RelativeLayout.ALIGN_PARENT_TOP); paramsLeft.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); this.addView(left, paramsLeft); right = new ImageButton(this.getContext()); right.setId(R.id.right); right.setImageDrawable(res.getDrawable(R.drawable.right_arrow)); right.setBackgroundColor(Color.TRANSPARENT); right.setOnClickListener(this); RelativeLayout.LayoutParams paramsRight = new LayoutParams((int) (56 * density), (int) (48 * density)); paramsRight.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); paramsRight.addRule(RelativeLayout.ALIGN_PARENT_TOP); paramsRight.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); this.addView(right, paramsRight); RelativeLayout.LayoutParams paramsScroll = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); paramsScroll.addRule(RelativeLayout.LEFT_OF, R.id.right); paramsScroll.addRule(RelativeLayout.RIGHT_OF, R.id.left); this.addView(scrollView, paramsScroll); } else { // if is not a tablet add only scrollable content RelativeLayout.LayoutParams paramsScroll = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); this.addView(scrollView, paramsScroll); } this.setSelectedNavigationItem(tabSelected); }
private void showPhoneDialog(final int position) { LinearLayout layout = new LinearLayout(getActivity()); layout.setOrientation(LinearLayout.HORIZONTAL); final EditText editPhone = new EditText(getActivity()); editPhone.setInputType(InputType.TYPE_CLASS_NUMBER); final String oldPhone = getPhoneAt(position).phone; editPhone.setText(oldPhone); editPhone.setSelection(editPhone.getText().length()); LinearLayout.LayoutParams paramsEdit = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.FILL_PARENT); paramsEdit.weight = 0.8f; paramsEdit.gravity = Gravity.LEFT; editPhone.setLayoutParams(paramsEdit); layout.addView(editPhone); final ImageButton rmPhoneBtn = new ImageButton(getActivity()); rmPhoneBtn.setImageResource(R.drawable.ic_action_delete); rmPhoneBtn.setBackgroundColor(Color.TRANSPARENT); LinearLayout.LayoutParams paramsBtn = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.FILL_PARENT); paramsBtn.weight = 0.2f; paramsBtn.gravity = Gravity.RIGHT; rmPhoneBtn.setLayoutParams(paramsBtn); layout.addView(rmPhoneBtn); final AlertDialog dialog = new AlertDialog.Builder(getActivity()) .setMessage("Izmena Telefona") .setView(layout) .setPositiveButton( android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String newPhone = editPhone.getText().toString(); List<Phone> phones = ClientsIO.getDetailClient().getPhones(); Iterator<Phone> iter = phones.iterator(); while (iter.hasNext()) { Phone p = iter.next(); if (p.phone == oldPhone) { p.phone = newPhone; break; } } populateItems(); notifyDataSetChanged(); } }) .setNegativeButton( android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) {} }) .setIcon(android.R.drawable.ic_dialog_alert) .show(); editPhone.setOnFocusChangeListener( new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { dialog .getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); rmPhoneBtn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Client c = ClientsIO.getDetailClient(); Iterator<Phone> iter = c.getPhones().iterator(); while (iter.hasNext()) { Phone p = iter.next(); if (p.phone == oldPhone) { iter.remove(); break; } } items.remove(position); populateItems(); notifyDataSetChanged(); dialog.cancel(); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_entry); try { FileInputStream fis = openFileInput("SaveData.txt"); ObjectInputStream ois = new ObjectInputStream(fis); items = (ArrayList<RssFeed>) ois.readObject(); ois.close(); } catch (Exception e) { Toast.makeText(this, "error", Toast.LENGTH_SHORT).show(); } // レイアウトID登録 mLoginStatusView = findViewById(R.id.login_status); mPageTitle = (TextView) findViewById(R.id.textView1); mListview = (ListView) findViewById(R.id.listView1); button = (Button) findViewById(R.id.regist_button); mTitleView = (EditText) findViewById(R.id.title); mUriView = (EditText) findViewById(R.id.uri); imageButton = (ImageButton) findViewById(R.id.imageButton1); checkBox = (CheckBox) findViewById(R.id.checkBox1); Bundle args = new Bundle(); if (getIntent().getDataString() != null) { // RSS_Linkクリックから mflag = 2; // タイトル取得を目指す mUri = getIntent().getDataString(); args.putString(ItemDetailFragment.ARG_ITEM_ID, getIntent().getDataString()); } else if (getIntent().getStringExtra(Intent.EXTRA_TEXT) != null) { // ページ共有から mflag = 1; // URI取得を目指す args.putString( ItemDetailFragment.ARG_ITEM_ID, getIntent().getExtras().getString(Intent.EXTRA_TEXT)); } else if (getIntent().getBooleanExtra("EDIT", false)) { // 編集クリックから mflag = 3; // 記事一覧取得を目指す // mItem = getIntent().getParcelableExtra("Parcelable"); mPosition = getIntent().getExtras().getInt("POSITION"); mTitle = items.get(mPosition).getTitle(); mUri = items.get(mPosition).getUrl(); noti = items.get(mPosition).getNoti(); button.setText(R.string.edit); mPageTitle.setText(R.string.rss_feed_edit); args.putString(ItemDetailFragment.ARG_ITEM_ID, mUri); selectColor = items.get(mPosition).getTag(); } if (getIntent().getExtras().getString("ADD") != null) { // 設定の追加ボタンから button.setText(R.string.check); } else { showProgress(true); getLoaderManager().initLoader(mflag, args, this); } // 状態に合わせてUIの文字とか変更 imageButton.setBackgroundColor(selectColor); mTitleView.setText(mTitle); mUriView.setText(mUri); checkBox.setChecked(noti); // チェックボックスがクリックされた時に呼び出されるコールバックリスナーを登録します checkBox.setOnClickListener( new View.OnClickListener() { @Override // チェックボックスがクリックされた時に呼び出されます public void onClick(View v) { CheckBox checkBox = (CheckBox) v; // チェックボックスのチェック状態を取得します noti = checkBox.isChecked(); } }); }