List of usage examples for android.widget ImageView setLayoutParams
public void setLayoutParams(ViewGroup.LayoutParams params)
From source file:mobisocial.musubi.service.WebRenderService.java
private void setImageViewBitmapAndLayout(ImageView imageView, Bitmap bitmap) { float scaleFactor; if (getResources().getBoolean(R.bool.is_tablet)) { scaleFactor = 3.0f;/*from w w w . jav a 2s . c o m*/ } else { scaleFactor = 2.0f; } DisplayMetrics dm = getResources().getDisplayMetrics(); int pixels = dm.widthPixels; if (dm.heightPixels < pixels) { pixels = dm.heightPixels; } int width = (int) (pixels / scaleFactor); int height = (int) ((float) width / bitmap.getWidth() * bitmap.getHeight()); int max_height = (int) (AppStateObj.MAX_HEIGHT * dm.density); if (height > max_height) { width = width * max_height / height; height = max_height; } imageView.setLayoutParams(new LinearLayout.LayoutParams(width, height)); imageView.setImageBitmap(bitmap); }
From source file:com.example.sam.savemeapp.StatisticsFragment.java
/** * Sets up the initial legend with the contained categories shown * in the pie chart and bullet points with the corresponding colors. *///from w w w . ja va2s . co m public void setUpPiechart() { pieChart.getDescription().setEnabled(false); Legend pieL = pieChart.getLegend(); Log.d("stats", Float.toString(pieL.getEntries().length)); startLegend = pieL; LegendEntry[] legends = pieL.getEntries(); pieL.setEnabled(false); mLegend.removeAllViews(); //The default legend consist of TextViews and ImageViews which contains a bullet point. //The legends are contained inside of a horizontal LinearLayout which is contained in a vertical LinearLayout. for (int t = 0; t < legends.length - 1; t++) { LegendEntry x = legends[t]; LinearLayout hLayout = new LinearLayout(getContext()); hLayout.setLayoutParams(params); TextView tv = new TextView(getContext()); tv.setText(x.label); tv.setTextColor(x.formColor); tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); LinearLayoutCompat.LayoutParams textViewParams = new LinearLayoutCompat.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); textViewParams.setMarginStart((int) getResources().getDimension(R.dimen.statistics_text_margin)); tv.setLayoutParams(textViewParams); ImageView iv = new ImageView(getContext()); Drawable dot = ContextCompat.getDrawable(getContext(), R.drawable.circle_legend); dot.setColorFilter(x.formColor, PorterDuff.Mode.SRC); iv.setImageDrawable(dot); iv.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); hLayout.addView(iv); hLayout.addView(tv); mLegend.addView(hLayout); } designPiechart(); pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { private int color; @Override public void onValueSelected(Entry e, Highlight h) { //it creates new legends with the information of the subcategories when a // category in the pi chart is clicked ArrayList<LegendEntry> list = new ArrayList<>(); mLegend.removeAllViews(); if (e.getData().equals(Color.parseColor("#00a0ae"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Food & Beverage")) { color = x.formColor; } } list.add(new LegendEntry("Food & Beverage: " + u.categories.get("Food & Beverage").get("Food & Beverage") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Restaurant & Caf: " + u.categories.get("Food & Beverage").get("Restaurant & Caf") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Supermarket: " + u.categories.get("Food & Beverage").get("Supermarket") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); //This category legends consist of the main category in this case "Food & Beverage" in the top of the legend //and the sub categories bellow. The name is also shown together with the amount spend in that category. for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#be3127"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Transportation")) { color = x.formColor; } } list.add(new LegendEntry("Transportation: " + u.categories.get("Transportation").get("Transportation") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Public transport: " + u.categories.get("Transportation").get("Public transport") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Taxi & Uber: " + u.categories.get("Transportation").get("Taxi & Uber") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Petrol: " + u.categories.get("Transportation").get("Petrol") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Maintenance: " + u.categories.get("Transportation").get("Maintenance") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#7dc725"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Shopping")) { color = x.formColor; } } list.add(new LegendEntry( "Shopping: " + u.categories.get("Shopping").get("Shopping") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Clothing: " + u.categories.get("Shopping").get("Clothing") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Electronics: " + u.categories.get("Shopping").get("Electronics") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Books: " + u.categories.get("Shopping").get("Books") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Gifts: " + u.categories.get("Shopping").get("Gifts") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Other: " + u.categories.get("Shopping").get("Other") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#e88300"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Entertainment")) { color = x.formColor; } } list.add(new LegendEntry( "Entertainment: " + u.categories.get("Entertainment").get("Entertainment") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Going out: " + u.categories.get("Entertainment").get("Going out") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Sports: " + u.categories.get("Entertainment").get("Sports") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#dc006d"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Health")) { color = x.formColor; } } list.add(new LegendEntry("Health: " + u.categories.get("Health").get("Health") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Doctor: " + u.categories.get("Health").get("Doctor") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Pharmacy: " + u.categories.get("Health").get("Pharmacy") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#1562a4"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Bills")) { color = x.formColor; } } list.add(new LegendEntry("Bills: " + u.categories.get("Bills").get("Bills") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Water: " + u.categories.get("Bills").get("Water") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Electricity: " + u.categories.get("Bills").get("Electricity") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Gas: " + u.categories.get("Bills").get("Gas") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Rent: " + u.categories.get("Bills").get("Rent") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Phone: " + u.categories.get("Bills").get("Phone") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add( new LegendEntry("Insurance: " + u.categories.get("Bills").get("Insurance") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("TV: " + u.categories.get("Bills").get("TV") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Internet: " + u.categories.get("Bills").get("Internet") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } } @Override public void onNothingSelected() { //Sets up the default legend when nothing is selected pieChart = (PieChart) v.findViewById(R.id.piechart); pieChart.setUsePercentValues(true); LegendEntry[] legends = startLegend.getEntries(); startLegend.setEnabled(false); mLegend.removeAllViews(); for (LegendEntry x : legends) { LinearLayout hLayout = new LinearLayout(getContext()); hLayout.setLayoutParams(params); TextView tv = new TextView(getContext()); tv.setText(x.label); tv.setTextColor(x.formColor); tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); LinearLayoutCompat.LayoutParams textViewParams = new LinearLayoutCompat.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); textViewParams .setMarginStart((int) getResources().getDimension(R.dimen.statistics_text_margin)); tv.setLayoutParams(textViewParams); ImageView iv = new ImageView(getContext()); Drawable dot = ContextCompat.getDrawable(getContext(), R.drawable.circle_legend); dot.setColorFilter(x.formColor, PorterDuff.Mode.SRC); iv.setImageDrawable(dot); iv.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); hLayout.addView(iv); hLayout.addView(tv); mLegend.addView(hLayout); } } }); }
From source file:com.android.systemui.statusbar.phone.NavigationBarView.java
private void addLightsOutButton(LinearLayout root, View v, boolean landscape, boolean empty) { ImageView addMe = new ImageView(mContext); addMe.setLayoutParams(v.getLayoutParams()); addMe.setImageResource(/* w w w .j a v a 2 s. co m*/ empty ? R.drawable.ic_sysbar_lights_out_dot_large : R.drawable.ic_sysbar_lights_out_dot_small); addMe.setScaleType(ImageView.ScaleType.CENTER); addMe.setVisibility(empty ? View.INVISIBLE : View.VISIBLE); if (landscape) root.addView(addMe, 0); else root.addView(addMe); }
From source file:de.msal.shoutemo.adapters.NavigationDrawerAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.listrow_navigationdrawer, parent, false);//from w ww . j a va2 s . co m } ImageView ivIcon = (ImageView) convertView.findViewById(R.id.listrow_navigationdrawer__icon); TextView tvText = (TextView) convertView.findViewById(R.id.listrow_navigationdrawer__text); // normal, clickable list entry if (getItem(position) != null) { ivIcon.setImageDrawable(ContextCompat.getDrawable(getContext(), mDrawables[position])); tvText.setText(mEntries[position]); } // separator line else { tvText.setVisibility(View.GONE); ivIcon.setImageDrawable(ContextCompat.getDrawable(getContext(), R.color.autemo_grey_bright)); ViewGroup.LayoutParams layoutParams = ivIcon.getLayoutParams(); layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; layoutParams.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getContext().getResources().getDisplayMetrics()); ivIcon.setLayoutParams(layoutParams); } return convertView; }
From source file:org.telegram.ui.SessionsActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(LocaleController.getString("SessionsTitle", R.string.SessionsTitle)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override/*from w w w . ja v a 2s.co m*/ public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); listAdapter = new ListAdapter(context); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); emptyLayout = new LinearLayout(context); emptyLayout.setOrientation(LinearLayout.VERTICAL); emptyLayout.setGravity(Gravity.CENTER); //emptyLayout.setBackgroundResource(R.drawable.greydivider_bottom); emptyLayout.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight())); ImageView imageView = new ImageView(context); imageView.setImageResource(R.drawable.devices); emptyLayout.addView(imageView); LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) imageView.getLayoutParams(); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; imageView.setLayoutParams(layoutParams2); TextView textView = new TextView(context); textView.setTextColor(ContextCompat.getColor(context, R.color.disabled_text) /*0xff8a8a8a*/); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17); textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); textView.setText(LocaleController.getString("NoOtherSessions", R.string.NoOtherSessions)); emptyLayout.addView(textView); layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams2.topMargin = AndroidUtilities.dp(16); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; layoutParams2.gravity = Gravity.CENTER; textView.setLayoutParams(layoutParams2); textView = new TextView(context); textView.setTextColor(ContextCompat.getColor(context, R.color.disabled_text) /*0xff8a8a8a*/); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17); textView.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0); textView.setText(LocaleController.getString("NoOtherSessionsInfo", R.string.NoOtherSessionsInfo)); emptyLayout.addView(textView); layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams2.topMargin = AndroidUtilities.dp(14); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; layoutParams2.gravity = Gravity.CENTER; textView.setLayoutParams(layoutParams2); FrameLayout progressView = new FrameLayout(context); frameLayout.addView(progressView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; progressView.setLayoutParams(layoutParams); progressView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); ProgressBar progressBar = new ProgressBar(context); progressView.addView(progressBar); layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.gravity = Gravity.CENTER; progressView.setLayoutParams(layoutParams); ListView listView = new ListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); listView.setDrawSelectorOnTop(true); listView.setEmptyView(progressView); frameLayout.addView(listView); layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP; listView.setLayoutParams(layoutParams); listView.setAdapter(listAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) { if (i == terminateAllSessionsRow) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage( LocaleController.getString("AreYouSureSessions", R.string.AreYouSureSessions)); 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) { TLRPC.TL_auth_resetAuthorizations req = new TLRPC.TL_auth_resetAuthorizations(); ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { if (getParentActivity() == null) { return; } if (error == null && response instanceof TLRPC.TL_boolTrue) { Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("TerminateAllSessions", R.string.TerminateAllSessions), Toast.LENGTH_SHORT); toast.show(); } else { Toast toast = Toast .makeText(getParentActivity(), LocaleController.getString("UnknownError", R.string.UnknownError), Toast.LENGTH_SHORT); toast.show(); } finishFragment(); } }); UserConfig.registeredForPush = false; UserConfig.saveConfig(false); MessagesController.getInstance().registerForPush(UserConfig.pushString); ConnectionsManager.getInstance() .setUserId(UserConfig.getClientUserId()); } }); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i >= otherSessionsStartRow && i < otherSessionsEndRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("TerminateSessionQuestion", R.string.TerminateSessionQuestion)); 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 option) { final ProgressDialog progressDialog = new ProgressDialog(getParentActivity()); progressDialog .setMessage(LocaleController.getString("Loading", R.string.Loading)); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCancelable(false); progressDialog.show(); final TLRPC.TL_authorization authorization = sessions .get(i - otherSessionsStartRow); TLRPC.TL_account_resetAuthorization req = new TLRPC.TL_account_resetAuthorization(); req.hash = authorization.hash; ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { try { progressDialog.dismiss(); } catch (Exception e) { FileLog.e("tmessages", e); } if (error == null) { sessions.remove(authorization); updateRows(); if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } } } }); } }); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } } }); return fragmentView; }
From source file:com.ibuildapp.romanblack.MultiContactsPlugin.ContactDetailsActivity.java
@Override public void create() { try {// w w w. java2 s .c om setContentView(R.layout.grouped_contacts_details); Intent currentIntent = getIntent(); Bundle store = currentIntent.getExtras(); widget = (Widget) store.getSerializable("Widget"); if (widget == null) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100); return; } person = (Person) store.getSerializable("person"); if (person == null) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100); return; } setTopBarTitle(widget.getTitle()); Boolean single = currentIntent.getBooleanExtra("single", true); setTopBarLeftButtonTextAndColor( single ? getResources().getString(R.string.common_home_upper) : getResources().getString(R.string.common_back_upper), getResources().getColor(android.R.color.black), true, new View.OnClickListener() { @Override public void onClick(View view) { finish(); } }); setTopBarTitleColor(getResources().getColor(android.R.color.black)); setTopBarBackgroundColor(Statics.color1); if ((Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_MAIL))) || (Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_SMS))) || (Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_SMS)))) { ImageView shareButton = (ImageView) getLayoutInflater() .inflate(R.layout.grouped_contacts_share_button, null); shareButton.setLayoutParams( new LinearLayout.LayoutParams((int) (29 * getResources().getDisplayMetrics().density), (int) (39 * getResources().getDisplayMetrics().density))); shareButton.setColorFilter(Color.BLACK); setTopBarRightButton(shareButton, getString(R.string.multicontacts_list_share), new View.OnClickListener() { @Override public void onClick(View v) { DialogSharing.Configuration.Builder sharingDialogBuilder = new DialogSharing.Configuration.Builder(); if (Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_MAIL))) sharingDialogBuilder .setEmailSharingClickListener(new DialogSharing.Item.OnClickListener() { @Override public void onClick() { String message = getContactInfo(); Intent email = new Intent(Intent.ACTION_SEND); email.putExtra(Intent.EXTRA_TEXT, message); email.setType("message/rfc822"); startActivity(Intent.createChooser(email, getString(R.string.choose_email_client))); } }); if (Boolean.TRUE.equals(widget.getParameter(PARAM_SEND_SMS))) sharingDialogBuilder .setSmsSharingClickListener(new DialogSharing.Item.OnClickListener() { @Override public void onClick() { String message = getContactInfo(); try { Utils.sendSms(ContactDetailsActivity.this, message); } catch (ActivityNotFoundException e) { e.printStackTrace(); } } }); if (Boolean.TRUE.equals(widget.getParameter(PARAM_ADD_CONTACT))) sharingDialogBuilder.addCustomListener(R.string.multicontacts_add_to_phonebook, R.drawable.gc_add_to_contacts, true, new DialogSharing.Item.OnClickListener() { @Override public void onClick() { createNewContact(person.getName(), person.getPhone(), person.getEmail()); } }); showDialogSharing(sharingDialogBuilder.build()); } }); } boolean hasSchema = store.getBoolean("hasschema"); cachePath = widget.getCachePath() + "/contacts-" + widget.getOrder(); contacts = person.getContacts(); if (widget.getTitle().length() > 0) { setTitle(widget.getTitle()); } root = (LinearLayout) findViewById(R.id.grouped_contacts_details_root); if (hasSchema) { root.setBackgroundColor(Statics.color1); } else if (widget.isBackgroundURL()) { cacheBackgroundFile = cachePath + "/" + Utils.md5(widget.getBackgroundURL()); File backgroundFile = new File(cacheBackgroundFile); if (backgroundFile.exists()) { root.setBackgroundDrawable( new BitmapDrawable(BitmapFactory.decodeStream(new FileInputStream(backgroundFile)))); } else { BackgroundDownloadTask dt = new BackgroundDownloadTask(); dt.execute(widget.getBackgroundURL()); } } else if (widget.isBackgroundInAssets()) { AssetManager am = this.getAssets(); root.setBackgroundDrawable(new BitmapDrawable(am.open(widget.getBackgroundURL()))); } if (contacts != null) { ImageView avatarImage = (ImageView) findViewById(R.id.grouped_contacts_details_avatar); avatarImage.setImageResource(R.drawable.gc_profile_avatar); if (person.hasAvatar() && NetworkUtils.isOnline(this)) { avatarImage.setVisibility(View.VISIBLE); Glide.with(this).load(person.getAvatarUrl()).placeholder(R.drawable.gc_profile_avatar) .dontAnimate().into(avatarImage); } else { avatarImage.setVisibility(View.VISIBLE); avatarImage.setImageResource(R.drawable.gc_profile_avatar); } String name = ""; neededContacts = new ArrayList<>(); for (Contact con : contacts) { if ((con.getType() == 5) || (con.getDescription().length() == 0)) { } else { if (con.getType() == 0) { name = con.getDescription(); } else neededContacts.add(con); } } if (neededContacts.isEmpty()) { handler.sendEmptyMessage(THERE_IS_NO_CONTACT_DATA); return; } headSeparator = findViewById(R.id.gc_head_separator); bottomSeparator = findViewById(R.id.gc_bottom_separator); imageBottom = findViewById(R.id.gc_image_bottom_layout); personName = (TextView) findViewById(R.id.gc_details_description); if ("".equals(name)) personName.setVisibility(View.GONE); else { personName.setVisibility(View.VISIBLE); personName.setText(name); personName.setTextColor(Statics.color3); } if (Statics.isLight) { headSeparator.setBackgroundColor(Color.parseColor("#4d000000")); bottomSeparator.setBackgroundColor(Color.parseColor("#4d000000")); } else { headSeparator.setBackgroundColor(Color.parseColor("#4dFFFFFF")); bottomSeparator.setBackgroundColor(Color.parseColor("#4dFFFFFF")); } ViewUtils.setBackgroundLikeHeader(imageBottom, Statics.color1); ListView list = (ListView) findViewById(R.id.grouped_contacts_details_list_view); list.setDivider(null); ContactDetailsAdapter adapter = new ContactDetailsAdapter(ContactDetailsActivity.this, R.layout.grouped_contacts_details_item, neededContacts, isChemeDark(Statics.color1)); list.setAdapter(adapter); list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View view, int position, long id) { listViewItemClick(position); } }); } if (widget.hasParameter("add_contact")) { HashMap<String, String> hm = new HashMap<>(); for (int i = 0; i < contacts.size(); i++) { switch (contacts.get(i).getType()) { case 0: { hm.put("contactName", contacts.get(i).getDescription()); } break; case 1: { hm.put("contactNumber", contacts.get(i).getDescription()); } break; case 2: { hm.put("contactEmail", contacts.get(i).getDescription()); } break; case 3: { hm.put("contactSite", contacts.get(i).getDescription()); } break; } } addNativeFeature(NATIVE_FEATURES.ADD_CONTACT, null, hm); } if (widget.hasParameter("send_sms")) { HashMap<String, String> hm = new HashMap<>(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < contacts.size(); i++) { sb.append(contacts.get(i).getDescription()); if (i < contacts.size() - 1) { sb.append(", "); } } hm.put("text", sb.toString()); addNativeFeature(NATIVE_FEATURES.SMS, null, hm); } if (widget.hasParameter("send_mail")) { HashMap<String, CharSequence> hm = new HashMap<>(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < contacts.size(); i++) { switch (contacts.get(i).getType()) { case 0: { sb.append("Name: "); } break; case 1: { sb.append("Phone: "); } break; case 2: { sb.append("Email: "); } break; case 3: { sb.append("Site: "); } break; case 4: { sb.append("Address: "); } break; } sb.append(contacts.get(i).getDescription()); sb.append("<br/>"); } if (widget.isHaveAdvertisement()) { sb.append("<br>\n (sent from <a href=\"http://ibuildapp.com\">iBuildApp</a>)"); } hm.put("text", sb.toString()); hm.put("subject", "Contacts"); addNativeFeature(NATIVE_FEATURES.EMAIL, null, hm); } } catch (Exception e) { Log.e(TAG, e.getMessage()); e.printStackTrace(); } }
From source file:com.cyanogenmod.eleven.ui.activities.SearchActivity.java
/** * {@inheritDoc}// w w w . j ava2s .c o m */ @Override public boolean onCreateOptionsMenu(final Menu menu) { // if we are not a top level search view, we do not need to create the search fields if (!mTopLevelSearch) { return super.onCreateOptionsMenu(menu); } // Search view getMenuInflater().inflate(R.menu.search, menu); // Filter the list the user is looking it via SearchView MenuItem searchItem = menu.findItem(R.id.menu_search); mSearchView = (SearchView) searchItem.getActionView(); mSearchView.setOnQueryTextListener(this); mSearchView.setQueryHint(getString(R.string.searchHint).toUpperCase()); // The SearchView has no way for you to customize or get access to the search icon in a // normal fashion, so we need to manually look for the icon and change the // layout params to hide it mSearchView.setIconifiedByDefault(false); mSearchView.setIconified(false); int searchButtonId = getResources().getIdentifier("android:id/search_mag_icon", null, null); ImageView searchIcon = (ImageView) mSearchView.findViewById(searchButtonId); searchIcon.setLayoutParams(new LinearLayout.LayoutParams(0, 0)); searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem item) { return true; } @Override public boolean onMenuItemActionCollapse(MenuItem item) { quit(); return false; } }); menu.findItem(R.id.menu_search).expandActionView(); return super.onCreateOptionsMenu(menu); }
From source file:info.guardianproject.pixelknot.PixelKnotActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); dump = new File(DUMP); if (!dump.exists()) dump.mkdir();//ww w .j a v a2 s. co m d = R.drawable.progress_off_selected; d_ = R.drawable.progress_on; setContentView(R.layout.pixel_knot_activity); ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); scale = Image.getScale(am.getMemoryClass()); if (Build.VERSION.SDK_INT <= 10) getSupportActionBar().hide(); else ((RelativeLayout) findViewById(R.id.pk_header)).setVisibility(View.GONE); imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); options_holder = (LinearLayout) findViewById(R.id.options_holder); action_display = (LinearLayout) findViewById(R.id.action_display); action_display_ = (LinearLayout) findViewById(R.id.action_display_); progress_holder = (LinearLayout) findViewById(R.id.progress_holder); List<Fragment> fragments = new Vector<Fragment>(); if (getIntent().getData() == null) { Fragment cover_image_fragment = Fragment.instantiate(this, CoverImageFragment.class.getName()); Fragment set_message_fragment = Fragment.instantiate(this, SetMessageFragment.class.getName()); Fragment share_fragment = Fragment.instantiate(this, ShareFragment.class.getName()); fragments.add(0, cover_image_fragment); fragments.add(1, set_message_fragment); fragments.add(2, share_fragment); } else { Fragment stego_image_fragment = Fragment.instantiate(this, StegoImageFragment.class.getName()); Bundle args = new Bundle(); args.putString(Keys.COVER_IMAGE_NAME, IO.pullPathFromUri(this, getIntent().getData())); stego_image_fragment.setArguments(args); Fragment decrypt_image_fragment = Fragment.instantiate(this, DecryptImageFragment.class.getName()); fragments.add(0, stego_image_fragment); fragments.add(1, decrypt_image_fragment); } pk_pager = new PKPager(getSupportFragmentManager(), fragments); view_pager = (ViewPager) findViewById(R.id.fragment_holder); view_pager.setAdapter(pk_pager); view_pager.setOnPageChangeListener(this); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lp.setMargins(5, 0, 5, 0); for (int p = 0; p < fragments.size(); p++) { ImageView progress_view = new ImageView(this); progress_view.setLayoutParams(lp); progress_view.setBackgroundResource(p == 0 ? d_ : d); progress_holder.addView(progress_view); } last_diff = 0; activity_root = findViewById(R.id.activity_root); activity_root.getViewTreeObserver().addOnGlobalLayoutListener(this); last_locale = PreferenceManager.getDefaultSharedPreferences(this).getString(Settings.LANGUAGE, "0"); }
From source file:com.radicaldynamic.groupinform.activities.LauncherActivity.java
private void displaySplash() { // Don't show the splash screen if this app appears to be registered if (PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .getString(InformOnlineState.DEVICE_ID, null) instanceof String) { return;/*from www . j ava2 s . co m*/ } // Fetch the splash screen Drawable Drawable image = null; try { // Attempt to load the configured default splash screen // The following code only works in 1.6+ // BitmapDrawable bitImage = new BitmapDrawable(getResources(), FileUtils.SPLASH_SCREEN_FILE_PATH); BitmapDrawable bitImage = new BitmapDrawable( FileUtilsExtended.EXTERNAL_FILES + File.separator + FileUtilsExtended.SPLASH_SCREEN_FILE); if (bitImage.getBitmap() != null && bitImage.getIntrinsicHeight() > 0 && bitImage.getIntrinsicWidth() > 0) { image = bitImage; } } catch (Exception e) { // TODO: log exception for debugging? } // TODO: rework if (image == null) { // no splash provided... // if (FileUtils.storageReady() && !((new File(FileUtils.DEFAULT_CONFIG_PATH)).exists())) { // Show the built-in splash image if the config directory // does not exist. Otherwise, suppress the icon. image = getResources().getDrawable(R.drawable.gc_color); // } if (image == null) return; } // Create ImageView to hold the Drawable... ImageView view = new ImageView(getApplicationContext()); // Initialise it with Drawable and full-screen layout parameters view.setImageDrawable(image); int width = getWindowManager().getDefaultDisplay().getWidth(); int height = getWindowManager().getDefaultDisplay().getHeight(); FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(width, height, 0); view.setLayoutParams(lp); view.setScaleType(ScaleType.CENTER); view.setBackgroundColor(Color.WHITE); // And wrap the image view in a frame layout so that the full-screen layout parameters are honoured FrameLayout layout = new FrameLayout(getApplicationContext()); layout.addView(view); // Create the toast and set the view to be that of the FrameLayout mSplashToast = Toast.makeText(getApplicationContext(), "splash screen", Toast.LENGTH_LONG); mSplashToast.setView(layout); mSplashToast.setGravity(Gravity.CENTER, 0, 0); mSplashToast.show(); }
From source file:com.ushahidi.android.app.ui.phone.AddReportActivity.java
@Override public View makeView() { ImageView i = new ImageView(this); i.setAdjustViewBounds(true);/*from w ww .ja v a2 s. c o m*/ i.setScaleType(ImageView.ScaleType.FIT_CENTER); i.setLayoutParams(new ImageSwitcher.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); return i; }