List of usage examples for android.widget ImageView setImageResource
@android.view.RemotableViewMethod(asyncImpl = "setImageResourceAsync") public void setImageResource(@DrawableRes int resId)
From source file:com.google.samples.apps.iosched.util.LPreviewUtilsBase.java
public void setOrAnimatePlusCheckIcon(final ImageView imageView, boolean isCheck, boolean allowAnimate) { final int imageResId = isCheck ? R.drawable.add_schedule_button_icon_checked : R.drawable.add_schedule_button_icon_unchecked; if (imageView.getTag() != null) { if (imageView.getTag() instanceof Animator) { Animator anim = (Animator) imageView.getTag(); anim.end();// w ww . ja va 2 s . co m imageView.setAlpha(1f); } } if (allowAnimate && isCheck) { int duration = mActivity.getResources().getInteger(android.R.integer.config_shortAnimTime); Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f); outAnimator.setDuration(duration / 2); outAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setImageResource(imageResId); } }); AnimatorSet inAnimator = new AnimatorSet(); outAnimator.setDuration(duration); inAnimator.playTogether(ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f), ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f), ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f)); AnimatorSet set = new AnimatorSet(); set.playSequentially(outAnimator, inAnimator); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setTag(null); } }); imageView.setTag(set); set.start(); } else { mHandler.post(new Runnable() { @Override public void run() { imageView.setImageResource(imageResId); } }); } }
From source file:ca.zadrox.dota2esportticker.ui.BaseActivity.java
private View makeNavDrawerItem(final int itemId, ViewGroup container) { boolean selected = getSelfNavDrawerItem() == itemId; int layoutToInflate = 0; if (itemId == NAVDRAWER_ITEM_SEPARATOR) { layoutToInflate = R.layout.navdrawer_separator; } else {// ww w . j a v a2s. c om layoutToInflate = R.layout.navdrawer_item; } View view = getLayoutInflater().inflate(layoutToInflate, container, false); if (isSeparator(itemId)) { // we are done UIUtils.setAccessibilityIgnore(view); return view; } ImageView iconView = (ImageView) view.findViewById(R.id.icon); TextView titleView = (TextView) view.findViewById(R.id.title); int iconId = itemId >= 0 && itemId < NAVDRAWER_ICON_RES_ID.length ? NAVDRAWER_ICON_RES_ID[itemId] : 0; int titleId = itemId >= 0 && itemId < NAVDRAWER_TITLE_RES_ID.length ? NAVDRAWER_TITLE_RES_ID[itemId] : 0; // set icon and text iconView.setVisibility(iconId > 0 ? View.VISIBLE : View.GONE); if (iconId > 0) { iconView.setImageResource(iconId); } titleView.setText(getString(titleId)); formatNavDrawerItem(view, itemId, selected); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onNavDrawerItemClicked(itemId); } }); return view; }
From source file:com.cloverstudio.spika.utils.BitmapManager.java
public void queueJob(final String url, final ImageView imageView, final ProgressBar pbLoading) { /* Create handler in UI thread. */ final Handler handler = new Handler() { @Override//from w ww. j a v a2s .co m public void handleMessage(Message msg) { String tag = imageViews.get(imageView); if (tag != null && tag.equals(url)) { if (msg.obj != null) { if (smallImg) { imageView.setScaleType(ImageView.ScaleType.CENTER); } else { imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); } imageView.setImageBitmap((Bitmap) msg.obj); if (pbLoading != null) pbLoading.setVisibility(View.GONE); } else { // imageView.setImageBitmap(placeholder); imageView.setImageResource(R.drawable.image_stub); if (pbLoading != null) pbLoading.setVisibility(View.GONE); } } } }; pool.submit(new Runnable() { @Override public void run() { final Bitmap bmp = downloadBitmap(url); Message message = Message.obtain(); message.obj = bmp; handler.sendMessage(message); } }); }
From source file:com.hunch.ImageManager.java
/** * Get the image for a Hunch category. These images are cached into internal storage * after the first time they are downloaded. If the image is not present in the cache, * it will be downloaded in a background thread then cached, and a placeholder image * will be displayed it its place.//from w w w . j a v a 2 s .c o m * * @param context Application context (to get to internal storage dir) * @param image The ImageView that will display the image * @param imgURL The URL to the image. */ public void getCategoryImage(final Context context, final ImageView image, final String imgURL) { URL url = stringToURL(imgURL); Drawable cachedDrawable = getCachedCategoryImage(context, url); if (cachedDrawable != null) { // the image is in the cache image.setImageDrawable(cachedDrawable); } else { // the image is not in the cache, must download downloadCategoryDrawable(url, context, new Callback() { @Override public void callComplete(Drawable d) { image.setImageDrawable(d); } }); // set it to the placeholder image for now image.setImageResource(Const.CAT_DEFAULT_IMG); } }
From source file:com.example.android.navigationdrawerexample.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); StrictMode.enableDefaults(); //STRICT MODE ENABLED db = new DBHelper(this); session = new Session(getApplicationContext()); inflatedView = getLayoutInflater().inflate(R.layout.full_layout, null); mTitle = mDrawerTitle = getTitle();/*from w ww . j a va2s .c o m*/ login_layout = (RelativeLayout) findViewById(R.id.login_layout); // order_list_layout= (RelativeLayout) findViewById(R.id.order_list_layout); signup_layout = (RelativeLayout) findViewById(R.id.signup_layout); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); actionBar = getActionBar(); text = (TextView) inflatedView.findViewById(R.id.user_name); login_option = (TextView) inflatedView.findViewById(R.id.textView1); mDrawerList = (ListView) findViewById(R.id.left_drawer); order_list = (ListView) findViewById(R.id.order_list); final LayoutInflater factory = getLayoutInflater(); final View vendor_menu = factory.inflate(R.layout.vendor_menu, null); final View order_menu = factory.inflate(R.layout.my_order, null); menu_list = (ListView) vendor_menu.findViewById(R.id.menu_list); // loginPopup= (TextView) vendor_menu.findViewById(R.id.menu_title); // Log.d //menu_list.addView(order_menu,0); Signup = (Button) findViewById(R.id.Signup); Gosignup = (Button) findViewById(R.id.Gosignup); Login = (ImageButton) findViewById(R.id.Login); Sign_username = (EditText) findViewById(R.id.SignUsername); Sign_name = (EditText) findViewById(R.id.vendor); Sign_pass = (EditText) findViewById(R.id.SignPass); Sign_cpass = (EditText) findViewById(R.id.SignCpass); Sign_phone = (EditText) findViewById(R.id.Phone); Login_pass = (EditText) findViewById(R.id.Logpass); Login_email = (EditText) findViewById(R.id.Logusername); // Log_username= (EditText) findViewById(R.id.Logusername); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener adapter = new MyAdapter(this); //adapter2=new MyAdapter2(this); // menu_adapter=new MyAdapter2(this); mDrawerList.setAdapter(adapter); mDrawerList.setDividerHeight(0); //mDrawerList.setAdapter(adapter); // order_list.setAdapter(adapter2); // menu_list.setAdapter(menu_adapter); menu_list.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, adapter.mPlanetTitles)); ImageView floatoption = new ImageView(this); floatoption.setImageResource(R.drawable.foption); ImageView floatadd = new ImageView(this); floatadd.setImageResource(R.drawable.fplus); floatin = new ImageView(this); floatin.setImageResource(R.drawable.flogin); floatout = new ImageView(this); floatout.setImageResource(R.drawable.flogout); ImageView floatrefresh = new ImageView(this); floatrefresh.setImageResource(R.drawable.refresh); itemBuilder = new SubActionButton.Builder(this); loginout = itemBuilder.setContentView(floatin).build(); refresh = itemBuilder.setContentView(floatrefresh).build(); additem = itemBuilder.setContentView(floatadd).build(); actionButton = new FloatingActionButton.Builder(this).setContentView(floatoption).build(); actionMenu = new FloatingActionMenu.Builder(this).addSubActionView(loginout).addSubActionView(additem) .addSubActionView(refresh) // ... .attachTo(actionButton).build(); Signup.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { View v = mDrawerList.getChildAt(0); View v2 = mDrawerList.getChildAt(5); text = (TextView) v.findViewById(R.id.user_name); login_option = (TextView) v2.findViewById(R.id.textView1); profile = (ImageView) v.findViewById(R.id.user_image); profile.setImageResource(R.drawable.welcome); text.setTextSize(20); text.setTextColor(Color.MAGENTA); text.setText("" + Sign_name.getText().toString()); login_option.setText("Logout"); floatout.setImageResource(R.drawable.flogout); // loginout.setContentView(floatout); long id = db.Insert(Sign_username.getText().toString(), Sign_name.getText().toString(), Sign_pass.getText().toString(), Sign_phone.getText().toString()); Log.d("This is-----------==", (String) text.getText() + id); //mDrawerList.invalidateViews(); //mDrawerList.removeViewAt(0); adapter.notifyDataSetChanged(); loginout.removeView(floatin); loginout.setContentView(floatout); order_list.setVisibility(View.VISIBLE); signup_layout.setVisibility(View.INVISIBLE); login_layout.setVisibility(View.INVISIBLE); } }); Login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { user_name = Login_email.getText().toString(); user_pass = Login_pass.getText().toString(); new GetAllCustomerTask().execute(new ApiConnector()); new Order_details().execute(new ApiConnector()); } }); if (!session.getusename().equals("")) { user_id = session.getusename(); user_name = session.getusename(); user_pass = session.getpassword(); login_layout.setVisibility(View.INVISIBLE); new GetAllCustomerTask().execute(new ApiConnector()); // new Order_details().execute(new ApiConnector()); // View vt = mDrawerList.getChildAt(0); //login_check(jsonArray); //new Order_details().execute(new ApiConnector()); } additem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (logged_in) { Intent i = new Intent(getApplicationContext(), Add_Item.class); startActivity(i); } else Toast.makeText(getApplicationContext(), "You Need To Login...", Toast.LENGTH_LONG).show(); } }); loginout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (logged_in) { session.setusename("", ""); finish(); startActivity(getIntent()); Toast.makeText(getApplicationContext(), "You are Loged Out", Toast.LENGTH_SHORT).show(); } else Toast.makeText(getApplicationContext(), "You Need To Login...", Toast.LENGTH_LONG).show(); } }); Login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { user_name = Login_email.getText().toString(); user_pass = Login_pass.getText().toString(); new GetAllCustomerTask().execute(new ApiConnector()); // new Order_details().execute(new ApiConnector()); } }); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); order_list.setOnItemClickListener(new OrderItemClickListener()); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); ActionBar actionBar = getActionBar(); actionBar.setBackgroundDrawable(new ColorDrawable(0xFF3BBD8F)); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() text = (TextView) inflatedView.findViewById(R.id.user_name); Log.d("Thit is----------------", (String) text.getText()); } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }
From source file:com.jimsuplee.scottishwhiskydistilleries.Scottishwhiskydistilleries.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { // ---check if the request code is 0 1 2 3 4 5--- Log.w(TAG, "In Scottishdistilleries.onActivityResult(), checking reqCod"); if (requestCode == 0) { Log.w(TAG, "In Scottishdistilleries.onActivityResult(int-reqCode=0,int-resCode,Intent-data)"); if (resultCode == RESULT_OK) { String distillery = data.getData().toString(); TextView tvname = (TextView) findViewById(R.id.txt_Distilleryname); Toast.makeText(this, "Loading " + distillery, Toast.LENGTH_LONG).show(); tvname.setText(distillery);/* www . j ava 2 s .com*/ TextView tv = (TextView) findViewById(R.id.txt_Distillerysdata); Integer distilleryTextId = distilleryMap.get(distillery); if (distilleryTextId != null) { tv.setText(distilleryTextId); } else { tv.setText(R.string.zero_results); } ImageView iv = (ImageView) findViewById(R.id.imagedetail); Integer photoId = photoMap.get(distillery); if (photoId != null) { iv.setImageResource(photoMap.get(distillery)); } else { iv.setImageResource(R.drawable.zero_results); } } } else if (requestCode == 1) { Log.w(TAG, "In Scottishwhiskydistilleries.onAcvityResult(int-reqCode=1,int-resCode,Intent-data)"); if (resultCode == RESULT_OK) { String owner = data.getData().toString(); Intent iDistillery = new Intent("com.jimsuplee.scottishwhiskydistilleries.Distillery"); iDistillery.putExtra("owner", owner); startActivityForResult(iDistillery, 0); } } else if (requestCode == 2) { Log.w(TAG, "In Scottishwhiskydistilleries.onAcvityResult(int-reqCode=2,int-resCode,Intent-data)"); if (resultCode == RESULT_OK) { String region = data.getData().toString(); Intent iDistillery = new Intent("com.jimsuplee.scottishwhiskydistilleries.Distillery"); iDistillery.putExtra("region", region); startActivityForResult(iDistillery, 0); } } else if (requestCode == 3) { Log.w(TAG, "In Scottishwhiskydistilleries.onAcvityResult(int-reqCode=3,int-resCode,Intent-data)"); if (resultCode == RESULT_OK) { String location = data.getData().toString(); Intent iDistillery = new Intent("com.jimsuplee.scottishwhiskydistilleries.Distillery"); iDistillery.putExtra("location", location); startActivityForResult(iDistillery, 0); } } }
From source file:com.openerp.support.listview.OEListViewAdapter.java
/** * Handle binary background.//from w ww.j a v a 2s. com * * @param row_id * the row_id * @param key * the key * @param resource * the resource * @param viewRow * the view row * @param position * the position */ private void handleBinaryBackground(final int row_id, final String key, int resource, View viewRow, final int position) { final ImageView booleanView = (ImageView) viewRow.findViewById(resource); int flag = 0; String rowKeyVal = rows.get(position).getRow_data().get(key).toString(); if (isFlagged.containsKey(String.valueOf(position))) { if (isFlagged.get(String.valueOf(position)).toString().equals("true")) { flag = 1; } } else { if (rowKeyVal.equals("true")) { isFlagged.put(String.valueOf(position), "true"); flag = 1; } } booleanView.setImageResource(binary_flag[flag]); booleanView.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { try { if (OpenERPServerConnection.isNetworkAvailable(context)) { OEListViewRows newRow = callbacks.get(key).updateFlagValues(rows.get(position), booleanView); rowdata = newRow.getRow_data(); rows.get(position).setRow_data(newRow.getRow_data()); isFlagged.put(String.valueOf(position), rowdata.get(key).toString()); } else { Toast.makeText(context, "Please Check your connection to server.", Toast.LENGTH_LONG) .show(); } } catch (Exception e) { } } }); }
From source file:com.nd.teacherplatform.util.ImageDownloader.java
/** * Same as download but the image is always downloaded and the cache is not * used. Kept private at the moment as its interest is not clear. *//*from www.j a v a2s.co m*/ private void forceDownload(String url, ImageView imageView, int loadingDrawable_ID, int failDrawable_ID, boolean isSaveLocal, ImageDownLoaderAction action) { if (url == null) { imageView.setImageResource(failDrawable_ID); return; } if (cancelPotentialDownload(url, imageView)) { /* modeCORRECT */ switch (mode) { case NO_ASYNC_TASK: Bitmap bitmap = downloadBitmap(url); addBitmapToCache(url, bitmap); imageView.setImageBitmap(bitmap); break; case NO_DOWNLOADED_DRAWABLE: imageView.setMinimumHeight(156); BitmapDownloaderTask task = new BitmapDownloaderTask(imageView, failDrawable_ID, isSaveLocal, action); task.execute(url); break; case CORRECT: task = new BitmapDownloaderTask(imageView, failDrawable_ID, isSaveLocal, action); DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task, loadingDrawable_ID); imageView.setImageDrawable(downloadedDrawable); imageView.setMinimumHeight(156); try { task.execute(url); } catch (RejectedExecutionException localRejectedExecutionException) { } break; } } }
From source file:com.laevatein.internal.ui.adapter.AlbumPhotoAdapter.java
@Override public void bindView(View view, final Context context, Cursor cursor) { final Item item = Item.valueOf(cursor); ImageView thumbnail = (ImageView) view.findViewById(mResources.getImageViewId()); final CheckBox check = (CheckBox) view.findViewById(mResources.getCheckBoxId()); thumbnail.setOnClickListener(new View.OnClickListener() { @Override/*from www . j a va2 s. c om*/ public void onClick(View v) { if (item.isCapture()) { PhotoGridViewHelper.callCamera(context); } else { PhotoGridViewHelper.callPreview(context, item, mCollection.asList()); } } }); check.setVisibility(item.isCapture() ? View.GONE : View.VISIBLE); check.setChecked(mCollection.isSelected(item.buildContentUri())); check.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PhotoGridViewHelper.syncCheckState(context, mCollection, item, check); PhotoGridViewHelper.callCheckStateListener(mListener); } }); if (item.isCapture()) { thumbnail.setImageResource(R.drawable.l_ic_capture); } else { Picasso.with(context).load(item.buildContentUri()) .resizeDimen(R.dimen.l_gridItemImageWidth, R.dimen.l_gridItemImageHeight).centerCrop() .into(thumbnail); } mBindListener.onBindView(context, view, item.buildContentUri()); }
From source file:com.b44t.ui.Components.PasscodeView.java
public PasscodeView(final Context context) { super(context); setWillNotDraw(false);/*from w w w .j a va2s. c om*/ setVisibility(GONE); backgroundFrameLayout = new FrameLayout(context); addView(backgroundFrameLayout); LayoutParams layoutParams = (LayoutParams) backgroundFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; backgroundFrameLayout.setLayoutParams(layoutParams); passwordFrameLayout = new FrameLayout(context); addView(passwordFrameLayout); layoutParams = (LayoutParams) passwordFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP | Gravity.LEFT; passwordFrameLayout.setLayoutParams(layoutParams); ImageView imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setImageResource(R.drawable.ic_launcher /* EDIT BY MR -- was: passcode_logo */); passwordFrameLayout.addView(imageView); layoutParams = (LayoutParams) imageView.getLayoutParams(); if (AndroidUtilities.density < 1) { layoutParams.width = AndroidUtilities.dp(30); layoutParams.height = AndroidUtilities.dp(30); } else { layoutParams.width = AndroidUtilities.dp(40); layoutParams.height = AndroidUtilities.dp(40); } layoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; layoutParams.bottomMargin = AndroidUtilities.dp(100); imageView.setLayoutParams(layoutParams); passcodeTextView = new TextView(context); passcodeTextView.setTextColor(0xffffffff); passcodeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); passcodeTextView.setGravity(Gravity.CENTER_HORIZONTAL); passwordFrameLayout.addView(passcodeTextView); layoutParams = (LayoutParams) passcodeTextView.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.bottomMargin = AndroidUtilities.dp(62); layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; passcodeTextView.setLayoutParams(layoutParams); passwordEditText = new EditText(context); passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36); passwordEditText.setTextColor(0xffffffff); passwordEditText.setMaxLines(1); passwordEditText.setLines(1); passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL); passwordEditText.setSingleLine(true); passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE); passwordEditText.setTypeface(Typeface.DEFAULT); passwordEditText.setBackgroundDrawable(null); AndroidUtilities.clearCursorDrawable(passwordEditText); passwordFrameLayout.addView(passwordEditText); layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams(); layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.leftMargin = AndroidUtilities.dp(70); layoutParams.rightMargin = AndroidUtilities.dp(70); layoutParams.bottomMargin = AndroidUtilities.dp(6); layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; passwordEditText.setLayoutParams(layoutParams); passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_DONE) { processDone(false); return true; } return false; } }); passwordEditText.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) { if (passwordEditText.length() == 4 && UserConfig.passcodeType == 0) { processDone(false); } } }); passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() { public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } public void onDestroyActionMode(ActionMode mode) { } public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } }); checkImage = new ImageView(context); checkImage.setImageResource(R.drawable.passcode_check); checkImage.setScaleType(ImageView.ScaleType.CENTER); checkImage.setBackgroundResource(R.drawable.bar_selector_lock); passwordFrameLayout.addView(checkImage); layoutParams = (LayoutParams) checkImage.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(60); layoutParams.height = AndroidUtilities.dp(60); layoutParams.bottomMargin = AndroidUtilities.dp(4); layoutParams.rightMargin = AndroidUtilities.dp(10); layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT; checkImage.setLayoutParams(layoutParams); checkImage.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { processDone(false); } }); FrameLayout lineFrameLayout = new FrameLayout(context); lineFrameLayout.setBackgroundColor(0x26ffffff); passwordFrameLayout.addView(lineFrameLayout); layoutParams = (LayoutParams) lineFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = AndroidUtilities.dp(1); layoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT; layoutParams.leftMargin = AndroidUtilities.dp(20); layoutParams.rightMargin = AndroidUtilities.dp(20); lineFrameLayout.setLayoutParams(layoutParams); numbersFrameLayout = new FrameLayout(context); addView(numbersFrameLayout); layoutParams = (LayoutParams) numbersFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP | Gravity.LEFT; numbersFrameLayout.setLayoutParams(layoutParams); lettersTextViews = new ArrayList<>(10); numberTextViews = new ArrayList<>(10); numberFrameLayouts = new ArrayList<>(10); for (int a = 0; a < 10; a++) { TextView textView = new TextView(context); textView.setTextColor(0xffffffff); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36); textView.setGravity(Gravity.CENTER); textView.setText(String.format(Locale.US, "%d", a)); numbersFrameLayout.addView(textView); layoutParams = (LayoutParams) textView.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(50); layoutParams.height = AndroidUtilities.dp(50); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; textView.setLayoutParams(layoutParams); numberTextViews.add(textView); textView = new TextView(context); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); textView.setTextColor(0x7fffffff); textView.setGravity(Gravity.CENTER); numbersFrameLayout.addView(textView); layoutParams = (LayoutParams) textView.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(50); layoutParams.height = AndroidUtilities.dp(20); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; textView.setLayoutParams(layoutParams); switch (a) { case 0: textView.setText("+"); break; case 2: textView.setText("ABC"); break; case 3: textView.setText("DEF"); break; case 4: textView.setText("GHI"); break; case 5: textView.setText("JKL"); break; case 6: textView.setText("MNO"); break; case 7: textView.setText("PQRS"); break; case 8: textView.setText("TUV"); break; case 9: textView.setText("WXYZ"); break; default: break; } lettersTextViews.add(textView); } eraseView = new ImageView(context); eraseView.setScaleType(ImageView.ScaleType.CENTER); eraseView.setImageResource(R.drawable.passcode_delete); numbersFrameLayout.addView(eraseView); layoutParams = (LayoutParams) eraseView.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(50); layoutParams.height = AndroidUtilities.dp(50); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; eraseView.setLayoutParams(layoutParams); for (int a = 0; a < 11; a++) { FrameLayout frameLayout = new FrameLayout(context); frameLayout.setBackgroundResource(R.drawable.bar_selector_lock); frameLayout.setTag(a); if (a == 10) { frameLayout.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { passwordEditText.setText(""); return true; } }); } frameLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { int tag = (Integer) v.getTag(); switch (tag) { case 0: appendCharacter("0"); break; case 1: appendCharacter("1"); break; case 2: appendCharacter("2"); break; case 3: appendCharacter("3"); break; case 4: appendCharacter("4"); break; case 5: appendCharacter("5"); break; case 6: appendCharacter("6"); break; case 7: appendCharacter("7"); break; case 8: appendCharacter("8"); break; case 9: appendCharacter("9"); break; case 10: String text = passwordEditText.getText().toString(); if (text.length() > 0) { passwordEditText.setText(text.substring(0, text.length() - 1)); } break; } if (passwordEditText.getText().toString().length() == 4) { processDone(false); } } }); numberFrameLayouts.add(frameLayout); } for (int a = 10; a >= 0; a--) { FrameLayout frameLayout = numberFrameLayouts.get(a); numbersFrameLayout.addView(frameLayout); layoutParams = (LayoutParams) frameLayout.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(100); layoutParams.height = AndroidUtilities.dp(100); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; frameLayout.setLayoutParams(layoutParams); } }