List of usage examples for android.widget LinearLayout setLayoutParams
public void setLayoutParams(ViewGroup.LayoutParams params)
From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java
public static AlertDialog getaddtextdialog(String title, final int itemnumber, Context ctx) { AlertDialog.Builder getaddtext = new AlertDialog.Builder(ctx); final LinearLayout linearlayout = new LinearLayout(ctx); linearlayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); linearlayout.setOrientation(LinearLayout.VERTICAL); final EditText nameet = new EditText(ctx); nameet.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); final TextView fontname = new TextView(ctx); fontname.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); final TextView colorname = new TextView(ctx); colorname.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); final Spinner fontsizespinner = new Spinner(ctx); fontsizespinner.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); final Spinner colorspinner = new Spinner(ctx); fontsizespinner.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); List<String> fontsizelist = new ArrayList<String>(); for (int t = 1; t < 200; t++) { fontsizelist.add(u.s(t));//w w w . ja va 2 s. c o m } ArrayAdapter<String> fontsizearrayadapter = new ArrayAdapter<String>(ctx, R.layout.spinnertextview, fontsizelist); fontsizearrayadapter.setDropDownViewResource(R.layout.spinnertextview); List<String> colorlist = new ArrayList<String>(); { colorlist.add("RED"); colorlist.add("BLACK"); colorlist.add("BLUE"); colorlist.add("GREEN"); colorlist.add("WHITE"); colorlist.add("GRAY"); } ArrayAdapter<String> colorlistarrayadapter = new ArrayAdapter<String>(ctx, R.layout.spinnertextview, colorlist); fontsizearrayadapter.setDropDownViewResource(R.layout.spinnertextview); colorspinner.setAdapter(colorlistarrayadapter); fontsizespinner.setAdapter(fontsizearrayadapter); fontsizespinner.setSelection(getIndexofSpinner(fontsizespinner, "25")); fontname.setText("Select Font Size"); fontname.setTextSize(20f); colorname.setText("Select Color"); colorname.setTextSize(20f); linearlayout.addView(nameet); linearlayout.addView(fontname); linearlayout.addView(fontsizespinner); linearlayout.addView(colorname); linearlayout.addView(colorspinner); if (!(itemnumber == view.i)) { nameet.setText(view.ITEMstring[itemnumber]); fontsizespinner.setSelection(getIndexofSpinner(fontsizespinner, u.s(view.ITEMfontsize[itemnumber]))); colorspinner.setSelection(getIndexofSpinner(colorspinner, u.s(view.ITEMfontcolor[itemnumber]))); } getaddtext.setView(linearlayout); getaddtext.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); getaddtext.setTitle(title); getaddtext.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub String string = nameet.getText().toString(); float fontsize = fontsizespinner.getSelectedItemPosition() + 1; //ITEMelcnumber[itemselectednumber]=u.i(string); int colpos = colorspinner.getSelectedItemPosition(); int[] col = new int[] { Color.RED, Color.BLACK, Color.BLUE, Color.GREEN, Color.WHITE, Color.GRAY }; int color = col[colpos]; Log.d("addtext", u.s((int) fontsize) + colpos + color); view.ITEMstring[itemnumber] = string; view.ITEMfontsize[itemnumber] = (int) fontsize; view.ITEMfontcolor[itemnumber] = color; view.itemname = string; view.fontsize = (int) fontsize; view.color = color; view.invalidate(); dialog.dismiss(); FloorPlanActivity.writeonedbitem(itemnumber); } }); return getaddtext.create(); }
From source file:info.tellmetime.TellmetimeActivity.java
private void resizeClock() { final LinearLayout mClock = (LinearLayout) findViewById(R.id.clock); // Set width of #mClock layout to the screen's shorter edge size, so clock is not // expanded in landscape mode, but has rather somewhat a square shape. RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.CENTER_IN_PARENT); lp.width = mShorterEdge;/*from w ww . ja va 2 s .co m*/ mClock.setLayoutParams(lp); final float mItemSize = mShorterEdge / mClock.getChildCount(); final int mRowMargin = (int) -(mItemSize / 2.2); // Scale text size according to shorter edge and set spacing between rows. for (int i = 0; i < mClock.getChildCount(); i++) { LinearLayout row = (LinearLayout) mClock.getChildAt(i); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) row.getLayoutParams(); params.bottomMargin = mRowMargin; row.setLayoutParams(params); for (int j = 0; j < row.getChildCount(); j++) ((TextView) row.getChildAt(j)).setTextSize(TypedValue.COMPLEX_UNIT_PX, mItemSize); } LinearLayout lastRow = (LinearLayout) mClock.getChildAt(mClock.getChildCount() - 1); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) lastRow.getLayoutParams(); params.bottomMargin = 0; lastRow.setLayoutParams(params); TextView twenty = (TextView) findViewById(R.id.twenty); params = (LinearLayout.LayoutParams) twenty.getLayoutParams(); params.leftMargin = 0; twenty.setLayoutParams(params); // Inflates minutes indicators and attaches them to main view. FrameLayout minutesLayout = (FrameLayout) findViewById(R.id.minutes_indicators); minutesLayout.removeAllViews(); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); final boolean isLandscape = getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; inflater.inflate(isLandscape ? R.layout.minutes_land : R.layout.minutes_portrait, minutesLayout); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, isLandscape ? FrameLayout.LayoutParams.MATCH_PARENT : FrameLayout.LayoutParams.WRAP_CONTENT); if (!isLandscape) { layoutParams.addRule(RelativeLayout.BELOW, R.id.clock); layoutParams.topMargin = (int) -TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize / 3, getResources().getDisplayMetrics()); } minutesLayout.setLayoutParams(layoutParams); ViewGroup minutesDots = (ViewGroup) findViewById(R.id.minutes_dots); for (int i = 0; i < minutesDots.getChildCount(); i++) ((TextView) minutesDots.getChildAt(i)).setTextSize(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize); }
From source file:com.example.android.recyclingbanks.MainActivity.java
private View prepareInfoView(final Marker marker) { // TODO change this to xml? //prepare InfoView programmatically final LinearLayout infoView = new LinearLayout(MainActivity.this); LinearLayout.LayoutParams infoViewParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); infoView.setOrientation(LinearLayout.VERTICAL); // attach the above layout to the infoView infoView.setLayoutParams(infoViewParams); String markerLongitude = Double.toString(marker.getPosition().longitude); String markerLatitude = Double.toString(marker.getPosition().latitude); final String imageURL = "https://maps.googleapis.com/maps/api/streetview?size=" + "500x300&location=" + markerLatitude + "," + markerLongitude + "&fov=120&heading=0&pitch=0"; //create street view preview @ top ImageView streetViewPreviewIV = new ImageView(MainActivity.this); Log.wtf("comparing TAG", String.valueOf(marker.getTag())); if (marker.getTag() == null) { Log.i("prepareInfoView", "fetching image"); Picasso.with(this).load(imageURL).fetch(new MarkerCallback(marker)); } else {// w w w . j a v a2s . c om Log.wtf("prepareInfoView", "building info window"); // this scales the image to match parents WIDTH?, but retain image's height?? LinearLayout.LayoutParams streetViewImageViewParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); streetViewPreviewIV.setLayoutParams(streetViewImageViewParams); // TODO upon conversion to xml, the imageView needs these to scale image to box // android:scaleType="fitStart" // android:adjustViewBounds="true" Picasso.with(MainActivity.this).load(imageURL).into(streetViewPreviewIV); infoView.addView(streetViewPreviewIV); //Log.wtf("prepareInfoView, marker tag set?", String.valueOf(marker.getTag())); //Picasso.with(this).setLoggingEnabled(true); } // create text boxes LinearLayout subInfoView = new LinearLayout(MainActivity.this); LinearLayout.LayoutParams subInfoViewParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); subInfoView.setOrientation(LinearLayout.VERTICAL); subInfoView.setLayoutParams(subInfoViewParams); TextView titleTextView = new TextView(MainActivity.this); titleTextView.setText(marker.getTitle()); TextView snippetTextView = new TextView(MainActivity.this); snippetTextView.setText(marker.getSnippet()); subInfoView.addView(titleTextView); subInfoView.addView(snippetTextView); infoView.addView(subInfoView); // add the image on the right ImageView streetViewIcon = new ImageView(MainActivity.this); // this scales the image to match parents height. LinearLayout.LayoutParams imageViewParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); streetViewIcon.setLayoutParams(imageViewParams); Drawable drawable = ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_streetview); streetViewIcon.setImageDrawable(drawable); infoView.addView(streetViewIcon); //Picasso.with(this).load(imageURL).into(streetViewPreviewIV, new MarkerCallback(marker)); return infoView; }
From source file:com.asksven.betterbatterystats.StatsActivity.java
public Dialog getShareDialog() { final ArrayList<Integer> selectedSaveActions = new ArrayList<Integer>(); AlertDialog.Builder builder = new AlertDialog.Builder(this); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); boolean saveDumpfile = sharedPrefs.getBoolean("save_dumpfile", true); boolean saveLogcat = sharedPrefs.getBoolean("save_logcat", false); boolean saveDmesg = sharedPrefs.getBoolean("save_dmesg", false); if (saveDumpfile) { selectedSaveActions.add(0);/*from w ww . j a v a 2 s. c o m*/ } if (saveLogcat) { selectedSaveActions.add(1); } if (saveDmesg) { selectedSaveActions.add(2); } //---- LinearLayout layout = new LinearLayout(this); LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); layout.setOrientation(LinearLayout.VERTICAL); layout.setLayoutParams(parms); layout.setGravity(Gravity.CLIP_VERTICAL); layout.setPadding(2, 2, 2, 2); final TextView editTitle = new TextView(StatsActivity.this); editTitle.setText(R.string.share_dialog_edit_title); editTitle.setPadding(40, 40, 40, 40); editTitle.setGravity(Gravity.LEFT); editTitle.setTextSize(20); final EditText editDescription = new EditText(StatsActivity.this); LinearLayout.LayoutParams tv1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); tv1Params.bottomMargin = 5; layout.addView(editTitle, tv1Params); layout.addView(editDescription, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); //---- // Set the dialog title builder.setTitle(R.string.title_share_dialog) .setMultiChoiceItems(R.array.saveAsLabels, new boolean[] { saveDumpfile, saveLogcat, saveDmesg }, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { // If the user checked the item, add it to the // selected items selectedSaveActions.add(which); } else if (selectedSaveActions.contains(which)) { // Else, if the item is already in the array, // remove it selectedSaveActions.remove(Integer.valueOf(which)); } } }) .setView(layout) // Set the action buttons .setPositiveButton(R.string.label_button_share, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { ArrayList<Uri> attachements = new ArrayList<Uri>(); Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName, StatsActivity.this); Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName, StatsActivity.this); Reading reading = new Reading(StatsActivity.this, myReferenceFrom, myReferenceTo); // save as text is selected if (selectedSaveActions.contains(0)) { attachements.add(reading.writeDumpfile(StatsActivity.this, editDescription.getText().toString())); } // save logcat if selected if (selectedSaveActions.contains(1)) { attachements.add(StatsProvider.getInstance().writeLogcatToFile()); } // save dmesg if selected if (selectedSaveActions.contains(2)) { attachements.add(StatsProvider.getInstance().writeDmesgToFile()); } if (!attachements.isEmpty()) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE); shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachements); shareIntent.setType("text/*"); startActivity(Intent.createChooser(shareIntent, "Share info to..")); } } }).setNeutralButton(R.string.label_button_save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { try { Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName, StatsActivity.this); Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName, StatsActivity.this); Reading reading = new Reading(StatsActivity.this, myReferenceFrom, myReferenceTo); // save as text is selected if (selectedSaveActions.contains(0)) { reading.writeDumpfile(StatsActivity.this, editDescription.getText().toString()); } // save logcat if selected if (selectedSaveActions.contains(1)) { StatsProvider.getInstance().writeLogcatToFile(); } // save dmesg if selected if (selectedSaveActions.contains(2)) { StatsProvider.getInstance().writeDmesgToFile(); } Snackbar.make(findViewById(android.R.id.content), getString(R.string.info_files_written) + ": " + StatsProvider.getWritableFilePath(), Snackbar.LENGTH_LONG).show(); } catch (Exception e) { Log.e(TAG, "an error occured writing files: " + e.getMessage()); Snackbar.make(findViewById(android.R.id.content), R.string.info_files_write_error, Snackbar.LENGTH_LONG).show(); } } }).setNegativeButton(R.string.label_button_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // do nothing } }); return builder.create(); }
From source file:com.geoffreybuttercrumbs.arewethereyet.DrawerFragment.java
private void recent() { LayoutInflater inflater = getActivity().getLayoutInflater(); SharedPreferences prefs = getActivity().getSharedPreferences("AreWeThereYet", Context.MODE_WORLD_WRITEABLE); for (int i = 1; i <= 5; i++) { Location location = new Location("POINT_LOCATION"); String address = prefs.getString(POINT_ADDRESS_KEY + i, ""); location.setLatitude(0);/*from w w w . j a v a 2s .c o m*/ location.setLongitude(0); if (prefs.contains(POINT_LATITUDE_KEY + i)) { location.setLatitude(prefs.getFloat(POINT_LATITUDE_KEY + i, 0)); } if (prefs.contains(POINT_LONGITUDE_KEY + i)) { location.setLongitude(prefs.getFloat(POINT_LONGITUDE_KEY + i, 0)); } LinearLayout RecentParent = (LinearLayout) V.findViewById(R.id.group_recent); View Recent = inflater.inflate(R.layout.saved_item, null); Recent.setOnClickListener(this); CharSequence name; if (!address.equals("")) { name = address; ((TextView) Recent.findViewById(R.id.savedLabel)).setTextColor(0xDDFFFFFF); ((CompoundButton) Recent.findViewById(R.id.saveCB)).setOnCheckedChangeListener(this); } else { name = "No Recent Alarms"; ((TextView) Recent.findViewById(R.id.savedLabel)).setTextColor(0xDD999999); Recent.findViewById(R.id.saveCB).setEnabled(false); } ((TextView) Recent.findViewById(R.id.savedLabel)).setText(name); ((TextView) Recent.findViewById(R.id.savedLabel)).setTextSize(14); Recent.findViewById(R.id.saveCB).setTag(i); Recent.setId(i); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); RecentParent.setLayoutParams(params); RecentParent.addView(Recent); } }
From source file:net.momodalo.app.vimtouch.VimTouch.java
public void showCmdHistory() { final Dialog dialog = new Dialog(this, R.style.DialogSlideAnim); // Setting dialogview Window window = dialog.getWindow(); window.setGravity(Gravity.BOTTOM);/*w w w. j ava 2 s. c o m*/ window.setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); dialog.setTitle(null); dialog.setContentView(R.layout.hist_list); dialog.setCancelable(true); LinearLayout layout = (LinearLayout) dialog.findViewById(R.id.hist_layout); if (AndroidCompat.SDK >= 11) { layout.setShowDividers(LinearLayout.SHOW_DIVIDER_BEGINNING | LinearLayout.SHOW_DIVIDER_MIDDLE | LinearLayout.SHOW_DIVIDER_END); } LayoutParams params = layout.getLayoutParams(); params.width = mScreenWidth; layout.setLayoutParams(params); LayoutInflater inflater = LayoutInflater.from(this); boolean exists = false; for (int i = 1; i <= 10; i++) { TextView button = (TextView) inflater.inflate(R.layout.histbutton, layout, false); String cmd = Exec.getCmdHistory(i); if (cmd.length() == 0) break; exists = true; button.setText(":" + cmd); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { TextView text = (TextView) v; CharSequence cmd = text.getText(); Exec.doCommand(cmd.subSequence(1, cmd.length()).toString()); dialog.dismiss(); } }); layout.addView((View) button); } if (exists) dialog.show(); }
From source file:org.noise_planet.noisecapture.CommentActivity.java
private void addTag(String tagName, int id, ViewGroup column, int color) { ToggleButton tagButton = new ToggleButton(this); if (color != -1) { LinearLayout colorBox = new LinearLayout(this); // Convert the dps to pixels, based on density scale final int tagPaddingPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()); final int tagPaddingPxBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3, getResources().getDisplayMetrics()); //use a GradientDrawable with only one color set, to make it a solid color colorBox.setBackgroundResource(R.drawable.tag_round_corner); GradientDrawable gradientDrawable = (GradientDrawable) colorBox.getBackground(); gradientDrawable.setColor(color); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.setMargins(tagPaddingPx, tagPaddingPx, tagPaddingPx, tagPaddingPxBottom); colorBox.setLayoutParams(params); colorBox.addView(tagButton);// ww w.jav a 2 s. c o m column.addView(colorBox); } else { column.addView(tagButton); } tagButton.setTextOff(tagName); tagButton.setTextOn(tagName); boolean isChecked = checkedTags.contains(id); tagButton.setChecked(isChecked); if (isChecked) { tagButton.setTextColor(selectedColor); } tagButton.setOnCheckedChangeListener(new TagStateListener(id, checkedTags)); tagButton.setMinHeight(0); tagButton.setMinimumHeight(0); tagButton.setTextSize(Dimension.SP, 12); tagButton.setEnabled(record == null || record.getUploadId().isEmpty()); tagButton.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); tagButton.invalidate(); }
From source file:org.cryptsecure.Utility.java
/** * Sets the content view with custom title. This is necessary for a holo * layout where a custom title bar is normally not permitted. * //from w ww . j a va 2 s . co m * @param activity * the activity * @param resIdMainLayout * the res id main layout * @param resIdTitle * the res id title * @return the linear layout */ public static LinearLayout setContentViewWithCustomTitle(Activity activity, int resIdMainLayout, int resIdTitle) { Context context = activity.getApplicationContext(); // Inflate the given layouts LayoutInflater inflaterInfo = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View titleView = (View) inflaterInfo.inflate(resIdTitle, null); View mainView = (View) inflaterInfo.inflate(resIdMainLayout, null); // Own custom title bar // // ATTENTION: // ADD THIS TO THEME <item name="android:windowNoTitle">true</item> activity.requestWindowFeature(Window.FEATURE_NO_TITLE); // We can ONLY disable the original title bar because you cannot combine // HOLO theme with a CUSTOM title bar :( // So we make our own title bar instead! // ALSO REMOVE TITLEBAR FROM APPLICATION AT STARTUP: // ADD TO MANIFEST // android:theme="@android:style/Theme.NoTitleBar" // THE FOLLOWING IS NOT WORKING WITH HOLO // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // setContentView(R.layout.activity_main); // getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, // R.layout.title_main); // Create title layout LinearLayout.LayoutParams lpTitle = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); LinearLayout titleLayout = new LinearLayout(context); titleLayout.setOrientation(LinearLayout.VERTICAL); titleLayout.addView(titleView); titleLayout.setLayoutParams(lpTitle); // Create main layout LinearLayout.LayoutParams lpMain = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); LinearLayout mainLayout = new LinearLayout(context); mainLayout.setOrientation(LinearLayout.VERTICAL); mainLayout.addView(mainView); mainLayout.setLayoutParams(lpMain); // Create root outer layout LinearLayout outerLayout = new LinearLayout(context); outerLayout.setOrientation(LinearLayout.VERTICAL); outerLayout.addView(titleLayout); outerLayout.addView(mainLayout); // outerLayout.setBackgroundColor(Color.rgb(255, 0, 0)); // mainLayout.setBackgroundColor(Color.rgb(0, 255, 0)); // titleLayout.setBackgroundColor(Color.rgb(0, 0, 255)); // lpSectionInnerLeft.setMargins(20, 5, 0, 15); // LinearLayout.LayoutParams lpSectionInnerRight = new // LinearLayout.LayoutParams( // 90, LinearLayout.LayoutParams.WRAP_CONTENT, 0f); // lpSectionInnerRight.setMargins(0, 5, 15, 15); // After setting NO TITLE .. apply the layout activity.setContentView(outerLayout); return mainLayout; }
From source file:org.telegram.ui.ProfileNotificationsActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override/*ww w. ja v a 2s. c o m*/ public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); listView = new ListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); AndroidUtilities.setListViewEdgeEffectColor(listView, AvatarDrawable.getProfileBackColorForId(5)); frameLayout.addView(listView); final FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; listView.setLayoutParams(layoutParams); listView.setAdapter(new ListAdapter(context)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) { if (i == settingsVibrateRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("Vibrate", R.string.Vibrate)); builder.setItems( new CharSequence[] { LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled), LocaleController.getString("SettingsDefault", R.string.SettingsDefault), LocaleController.getString("SystemDefault", R.string.SystemDefault), LocaleController.getString("Short", R.string.Short), LocaleController.getString("Long", R.string.Long) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); if (which == 0) { editor.putInt("vibrate_" + dialog_id, 2); } else if (which == 1) { editor.putInt("vibrate_" + dialog_id, 0); } else if (which == 2) { editor.putInt("vibrate_" + dialog_id, 4); } else if (which == 3) { editor.putInt("vibrate_" + dialog_id, 1); } else if (which == 4) { editor.putInt("vibrate_" + dialog_id, 3); } editor.commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == settingsNotificationsRow) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setItems( new CharSequence[] { LocaleController.getString("Default", R.string.Default), LocaleController.getString("Enabled", R.string.Enabled), LocaleController.getString("NotificationsDisabled", R.string.NotificationsDisabled) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface d, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("notify2_" + dialog_id, which); if (which == 2) { NotificationsController.getInstance() .removeNotificationsForDialog(dialog_id); } MessagesStorage.getInstance().setDialogFlags(dialog_id, which == 2 ? 1 : 0); editor.commit(); TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict .get(dialog_id); if (dialog != null) { dialog.notify_settings = new TLRPC.TL_peerNotifySettings(); if (which == 2) { dialog.notify_settings.mute_until = Integer.MAX_VALUE; } } if (listView != null) { listView.invalidateViews(); } NotificationsController.updateServerNotificationsSettings(dialog_id); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == settingsSoundRow) { try { Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); Uri currentSound = null; String defaultPath = null; Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI; if (defaultUri != null) { defaultPath = defaultUri.getPath(); } String path = preferences.getString("sound_path_" + dialog_id, defaultPath); if (path != null && !path.equals("NoSound")) { if (path.equals(defaultPath)) { currentSound = defaultUri; } else { currentSound = Uri.parse(path); } } tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound); startActivityForResult(tmpIntent, 12); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (i == settingsLedRow) { if (getParentActivity() == null) { return; } LinearLayout linearLayout = new LinearLayout(getParentActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); final ColorPickerView colorPickerView = new ColorPickerView(getParentActivity()); linearLayout.addView(colorPickerView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); if (preferences.contains("color_" + dialog_id)) { colorPickerView.setOldCenterColor(preferences.getInt("color_" + dialog_id, 0xff00ff00)); } else { if ((int) dialog_id < 0) { colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00)); } else { colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00)); } } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor)); builder.setView(linearLayout); builder.setPositiveButton(LocaleController.getString("Set", R.string.Set), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int which) { final SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("color_" + dialog_id, colorPickerView.getColor()); editor.commit(); listView.invalidateViews(); } }); builder.setNeutralButton(LocaleController.getString("LedDisabled", R.string.LedDisabled), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("color_" + dialog_id, 0); editor.commit(); listView.invalidateViews(); } }); builder.setNegativeButton(LocaleController.getString("Default", R.string.Default), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.remove("color_" + dialog_id); editor.commit(); listView.invalidateViews(); } }); showDialog(builder.create()); } else if (i == settingsPriorityRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle( LocaleController.getString("NotificationsPriority", R.string.NotificationsPriority)); builder.setItems( new CharSequence[] { LocaleController.getString("SettingsDefault", R.string.SettingsDefault), LocaleController.getString("NotificationsPriorityDefault", R.string.NotificationsPriorityDefault), LocaleController.getString("NotificationsPriorityHigh", R.string.NotificationsPriorityHigh), LocaleController.getString("NotificationsPriorityMax", R.string.NotificationsPriorityMax) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { which = 3; } else { which--; } SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); preferences.edit().putInt("priority_" + dialog_id, which).commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == smartRow) { if (getParentActivity() == null) { return; } SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); int notifyMaxCount = preferences.getInt("smart_max_count_" + dialog_id, 2); int notifyDelay = preferences.getInt("smart_delay_" + dialog_id, 3 * 60); if (notifyMaxCount == 0) { notifyMaxCount = 2; } LinearLayout linearLayout = new LinearLayout(getParentActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); LinearLayout linearLayout2 = new LinearLayout(getParentActivity()); linearLayout2.setOrientation(LinearLayout.HORIZONTAL); linearLayout.addView(linearLayout2); LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) linearLayout2 .getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; linearLayout2.setLayoutParams(layoutParams1); TextView textView = new TextView(getParentActivity()); textView.setText(LocaleController.getString("SmartNotificationsSoundAtMost", R.string.SmartNotificationsSoundAtMost)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); linearLayout2.addView(textView); layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; textView.setLayoutParams(layoutParams1); final NumberPicker numberPickerTimes = new NumberPicker(getParentActivity()); numberPickerTimes.setMinValue(1); numberPickerTimes.setMaxValue(10); numberPickerTimes.setValue(notifyMaxCount); linearLayout2.addView(numberPickerTimes); layoutParams1 = (LinearLayout.LayoutParams) numberPickerTimes.getLayoutParams(); layoutParams1.width = AndroidUtilities.dp(50); numberPickerTimes.setLayoutParams(layoutParams1); textView = new TextView(getParentActivity()); textView.setText(LocaleController.getString("SmartNotificationsTimes", R.string.SmartNotificationsTimes)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); linearLayout2.addView(textView); layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; textView.setLayoutParams(layoutParams1); linearLayout2 = new LinearLayout(getParentActivity()); linearLayout2.setOrientation(LinearLayout.HORIZONTAL); linearLayout.addView(linearLayout2); layoutParams1 = (LinearLayout.LayoutParams) linearLayout2.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; linearLayout2.setLayoutParams(layoutParams1); textView = new TextView(getParentActivity()); textView.setText(LocaleController.getString("SmartNotificationsWithin", R.string.SmartNotificationsWithin)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); linearLayout2.addView(textView); layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; textView.setLayoutParams(layoutParams1); final NumberPicker numberPickerMinutes = new NumberPicker(getParentActivity()); numberPickerMinutes.setMinValue(1); numberPickerMinutes.setMaxValue(10); numberPickerMinutes.setValue(notifyDelay / 60); linearLayout2.addView(numberPickerMinutes); layoutParams1 = (LinearLayout.LayoutParams) numberPickerMinutes.getLayoutParams(); layoutParams1.width = AndroidUtilities.dp(50); numberPickerMinutes.setLayoutParams(layoutParams1); textView = new TextView(getParentActivity()); textView.setText(LocaleController.getString("SmartNotificationsMinutes", R.string.SmartNotificationsMinutes)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); linearLayout2.addView(textView); layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; textView.setLayoutParams(layoutParams1); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("SmartNotifications", R.string.SmartNotifications)); builder.setView(linearLayout); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); preferences.edit() .putInt("smart_max_count_" + dialog_id, numberPickerTimes.getValue()) .commit(); preferences.edit() .putInt("smart_delay_" + dialog_id, numberPickerMinutes.getValue() * 60) .commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("SmartNotificationsDisabled", R.string.SmartNotificationsDisabled), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); preferences.edit().putInt("smart_max_count_" + dialog_id, 0).commit(); if (listView != null) { listView.invalidateViews(); } } }); showDialog(builder.create()); } } }); return fragmentView; }
From source file:com.saulcintero.moveon.fragments.Statistics.java
private void paintData(int sql_option, int activity) { boolean isMetric = FunctionUtils.checkIfUnitsAreMetric(mContext); sum_distance = 0;/*w ww . j a v a 2s . c om*/ sum_kcal = 0; sum_time = 0; sum_up_accum_altitude = 0; sum_down_accum_altitude = 0; sum_avg_speed = 0; sum_steps = 0; sum_avg_hr = 0; practices_counter = 0; hr_practices_counter = 0; int[] colors = { Color.rgb(111, 183, 217), Color.rgb(54, 165, 54), Color.rgb(246, 103, 88), Color.rgb(234, 206, 74), Color.rgb(246, 164, 83), Color.LTGRAY, Color.rgb(35, 142, 36), Color.rgb(0, 129, 125), Color.rgb(0, 0, 220), Color.rgb(255, 255, 0), Color.rgb(255, 215, 0), Color.rgb(184, 134, 11), Color.rgb(245, 245, 220), Color.rgb(139, 137, 137), Color.rgb(96, 57, 138), Color.rgb(176, 0, 103), Color.rgb(77, 19, 106), Color.rgb(218, 0, 0), Color.rgb(252, 115, 0), Color.rgb(243, 42, 0), Color.rgb(255, 202, 44), Color.rgb(176, 214, 7), Color.rgb(255, 235, 44), Color.rgb(255, 255, 255), Color.rgb(186, 29, 29), Color.rgb(146, 436, 20), Color.rgb(245, 175, 209), Color.rgb(29, 91, 139), Color.rgb(128, 128, 0), Color.rgb(128, 0, 128), Color.rgb(0, 128, 128), Color.rgb(246, 233, 207), Color.rgb(231, 56, 142), Color.rgb(173, 141, 193), Color.rgb(191, 199, 32), Color.rgb(0, 128, 0), Color.rgb(4, 136, 125), Color.rgb(140, 0, 255), Color.rgb(135, 0, 118), Color.rgb(2, 132, 132), Color.rgb(0, 127, 204), Color.rgb(128, 250, 255), Color.rgb(192, 192, 192), Color.rgb(207, 94, 97), Color.rgb(137, 189, 199), Color.rgb(138, 168, 161), Color.rgb(171, 166, 191), Color.rgb(199, 153, 125) }; DBManager = null; cursor = null; distance_distribution = null; kcal_distribution = null; time_distribution = null; DBManager = new DataManager(mContext); DBManager.Open(); cursor = DBManager.CustomQuery(getString(R.string.checking_routes), "SELECT * FROM routes"); cursor.moveToFirst(); if (cursor.getCount() > 0) { between_dates_query_part = ""; DatesTypes whichDate = DatesTypes.values()[sql_option]; switch (whichDate) { case ALL_DATES: removeCustomDataValues(); if (activity > 0) { cursor = DBManager.CustomQuery( getString(R.string.selecting_all_routes) + " " + getString(R.string.filter_by_activity) + " " + getString(R.string.and) + " " + getString(R.string.group_by_activities), "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, " + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, " + "SUM(up_accum_altitude) AS sum_up_accum_altitude, " + "SUM(down_accum_altitude) AS sum_down_accum_altitude, " + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE category_id = '" + activity + "' " + "GROUP BY category_id"); } else { cursor = DBManager.CustomQuery( getString(R.string.selecting_all_routes) + " " + getString(R.string.group_by_activities), "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, " + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, " + "SUM(up_accum_altitude) AS sum_up_accum_altitude, " + "SUM(down_accum_altitude) AS sum_down_accum_altitude, " + "SUM(steps) AS sum_steps " + "FROM routes GROUP BY category_id"); } break; case THIS_YEAR: removeCustomDataValues(); if (activity > 0) { cursor = DBManager.CustomQuery( getString(R.string.selecting_this_year_routes) + " " + getString(R.string.filter_by_activity) + " " + getString(R.string.and) + " " + getString(R.string.group_by_activities), "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, " + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, " + "SUM(up_accum_altitude) AS sum_up_accum_altitude, " + "SUM(down_accum_altitude) AS sum_down_accum_altitude, " + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE substr(date,7) = '" + Calendar.getInstance().get(Calendar.YEAR) + "' " + "AND category_id = '" + activity + "' " + "GROUP BY category_id"); } else { cursor = DBManager.CustomQuery( getString(R.string.selecting_this_year_routes) + " " + getString(R.string.group_by_activities), "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, " + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, " + "SUM(up_accum_altitude) AS sum_up_accum_altitude, " + "SUM(down_accum_altitude) AS sum_down_accum_altitude, " + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE substr(date,7) = '" + Calendar.getInstance().get(Calendar.YEAR) + "' " + "GROUP BY category_id"); } between_dates_query_part = "substr(date,7) = '" + Calendar.getInstance().get(Calendar.YEAR) + "' "; break; case THIS_MONTH: removeCustomDataValues(); int month = Calendar.getInstance().get(Calendar.MONTH) + 1; String sMonth = String.valueOf(month); if (month < 10) sMonth = "0" + sMonth; if (activity > 0) { cursor = DBManager.CustomQuery( getString(R.string.selecting_this_month_routes) + " " + getString(R.string.filter_by_activity) + " " + getString(R.string.and) + " " + getString(R.string.group_by_activities), "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, " + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, " + "SUM(up_accum_altitude) AS sum_up_accum_altitude, " + "SUM(down_accum_altitude) AS sum_down_accum_altitude, " + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE substr(date,4,2) = '" + sMonth + "' " + "AND substr(date,7) = '" + Calendar.getInstance().get(Calendar.YEAR) + "' " + "AND category_id = '" + activity + "' " + "GROUP BY category_id"); } else { cursor = DBManager.CustomQuery( getString(R.string.selecting_this_month_routes) + " " + getString(R.string.group_by_activities), "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, " + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, " + "SUM(up_accum_altitude) AS sum_up_accum_altitude, " + "SUM(down_accum_altitude) AS sum_down_accum_altitude, " + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE substr(date,4,2) = '" + sMonth + "' " + "AND substr(date,7) = '" + Calendar.getInstance().get(Calendar.YEAR) + "' " + "GROUP BY category_id"); } between_dates_query_part = "substr(date,4,2) = '" + sMonth + "' AND substr(date,7) = '" + Calendar.getInstance().get(Calendar.YEAR) + "' "; break; case THIS_WEAK: removeCustomDataValues(); Calendar c1 = Calendar.getInstance(); c1.setFirstDayOfWeek(Calendar.MONDAY); c1.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); int y = c1.get(Calendar.YEAR); int m = c1.get(Calendar.MONTH) + 1; int d = c1.get(Calendar.DAY_OF_MONTH); String sYear1 = String.valueOf(y); String sMonth1 = String.valueOf(m); if (m < 10) sMonth1 = "0" + sMonth1; String sDay1 = String.valueOf(d); if (d < 10) sDay1 = "0" + sDay1; c1.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); int y2 = c1.get(Calendar.YEAR); int m2 = c1.get(Calendar.MONTH) + 1; int d2 = c1.get(Calendar.DAY_OF_MONTH); String sYear2 = String.valueOf(y2); String sMonth2 = String.valueOf(m2); if (m2 < 10) sMonth2 = "0" + sMonth2; String sDay2 = String.valueOf(d2); if (d2 < 10) sDay2 = "0" + sDay2; if (activity > 0) { cursor = DBManager.CustomQuery( getString(R.string.selecting_this_weak_routes) + " " + getString(R.string.filter_by_activity) + " " + getString(R.string.and) + " " + getString(R.string.group_by_activities), "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, " + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, " + "SUM(up_accum_altitude) AS sum_up_accum_altitude, " + "SUM(down_accum_altitude) AS sum_down_accum_altitude, " + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '" + sYear1 + sMonth1 + sDay1 + "' AND '" + sYear2 + sMonth2 + sDay2 + "' " + "AND category_id = '" + activity + "' " + "GROUP BY category_id"); } else { cursor = DBManager.CustomQuery( getString(R.string.selecting_this_weak_routes) + " " + getString(R.string.group_by_activities), "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, " + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, " + "SUM(up_accum_altitude) AS sum_up_accum_altitude, " + "SUM(down_accum_altitude) AS sum_down_accum_altitude, " + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '" + sYear1 + sMonth1 + sDay1 + "' AND '" + sYear2 + sMonth2 + sDay2 + "' " + "GROUP BY category_id"); } between_dates_query_part = "substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '" + sYear1 + sMonth1 + sDay1 + "' AND '" + sYear2 + sMonth2 + sDay2 + "' "; break; case BETWEEN_TWO_DATES: String mYear1 = String.valueOf(year1); String mMonth1 = String.valueOf(month1); if (month1 < 10) mMonth1 = "0" + mMonth1; String mDay1 = String.valueOf(day1); if (day1 < 10) mDay1 = "0" + mDay1; String mYear2 = String.valueOf(year2); String mMonth2 = String.valueOf(month2); if (month2 < 10) mMonth2 = "0" + mMonth2; String mDay2 = String.valueOf(day2); if (day2 < 10) mDay2 = "0" + mDay2; customDay1 = mDay1; customDay2 = mDay2; customMonth1 = mMonth1; customMonth2 = mMonth2; customYear1 = mYear1; customYear2 = mYear2; if (activity > 0) { cursor = DBManager.CustomQuery("Seleccionando las rutas de este mes agrupadas por actividad", "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, " + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, " + "SUM(up_accum_altitude) AS sum_up_accum_altitude, " + "SUM(down_accum_altitude) AS sum_down_accum_altitude, " + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '" + customYear1 + customMonth1 + customDay1 + "' AND '" + customYear2 + customMonth2 + customDay2 + "' " + "AND category_id = '" + activity + "' " + "GROUP BY category_id"); } else { cursor = DBManager.CustomQuery("Seleccionando las rutas de este mes agrupadas por actividad", "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, " + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, " + "SUM(up_accum_altitude) AS sum_up_accum_altitude, " + "SUM(down_accum_altitude) AS sum_down_accum_altitude, " + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '" + customYear1 + customMonth1 + customDay1 + "' AND '" + customYear2 + customMonth2 + customDay2 + "' " + "GROUP BY category_id"); } between_dates_query_part = "substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '" + customYear1 + customMonth1 + customDay1 + "' AND '" + customYear2 + customMonth2 + customDay2 + "' "; break; } cursor.moveToFirst(); base_layout.setVisibility(View.VISIBLE); scrollView.setVisibility(View.VISIBLE); layout1.setVisibility(View.VISIBLE); layout2.setVisibility(View.VISIBLE); layout3.setVisibility(View.VISIBLE); layout4.setVisibility(View.VISIBLE); distance_distribution = new float[cursor.getCount()]; kcal_distribution = new int[cursor.getCount()]; time_distribution = new int[cursor.getCount()]; int i = 0; mTableLayout.removeAllViews(); while (!cursor.isAfterLast()) { TextView color = new TextView(mContext); TextView label = new TextView(mContext); TextView value = new TextView(mContext); LinearLayout.LayoutParams colorLayoutParams = new LinearLayout.LayoutParams( new LayoutParams(FunctionUtils.calculateDpFromPx(mContext, 20), FunctionUtils.calculateDpFromPx(mContext, 20))); colorLayoutParams.setMargins(0, 1, 5, 1); color.setLayoutParams(colorLayoutParams); label.setLayoutParams( new LayoutParams(FunctionUtils.calculateDpFromPx(mContext, 95), LayoutParams.WRAP_CONTENT)); label.setTypeface(null, Typeface.BOLD); label.setTextColor(Color.parseColor("#b5b5b5")); value.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); value.setTextColor(res.getColor(R.color.white)); color.setBackgroundColor(colors[i]); label.setText(activities[cursor.getInt(cursor.getColumnIndex("category_id")) - 1] + ":"); value.setText((isMetric ? String.valueOf(cursor.getFloat(cursor.getColumnIndex("sum_distance"))) + " " + getString(R.string.long_unit1_detail_1) + ", " : String.valueOf(FunctionUtils.customizedRound( ((cursor.getFloat(cursor.getColumnIndex("sum_distance")) * 1000f) / 1609f), 2)) + " " + getString(R.string.long_unit2_detail_1) + ", ") + String.valueOf((int) cursor.getFloat(cursor.getColumnIndex("sum_kcal"))) + " " + getString(R.string.tell_calories_setting_details) + ", " + String.valueOf(FunctionUtils.statisticsFormatTime(mContext, (long) cursor.getFloat(cursor.getColumnIndex("sum_time"))))); LinearLayout mLinearLayout = new LinearLayout(mContext); mLinearLayout .setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mLinearLayout.setOrientation(0); mLinearLayout.addView(color); mLinearLayout.addView(label); mLinearLayout.addView(value); mTableLayout.addView(mLinearLayout); sum_distance = sum_distance + cursor.getFloat(cursor.getColumnIndex("sum_distance")); sum_kcal = sum_kcal + cursor.getInt(cursor.getColumnIndex("sum_kcal")); sum_time = sum_time + cursor.getInt(cursor.getColumnIndex("sum_time")); sum_up_accum_altitude = sum_up_accum_altitude + cursor.getInt(cursor.getColumnIndex("sum_up_accum_altitude")); sum_down_accum_altitude = sum_down_accum_altitude + cursor.getInt(cursor.getColumnIndex("sum_down_accum_altitude")); sum_avg_speed = sum_avg_speed + cursor.getFloat(cursor.getColumnIndex("sum_avg_speed")); sum_steps = sum_steps + cursor.getInt(cursor.getColumnIndex("sum_steps")); distance_distribution[i] = cursor.getFloat(cursor.getColumnIndex("sum_distance")); kcal_distribution[i] = cursor.getInt(cursor.getColumnIndex("sum_kcal")); time_distribution[i] = cursor.getInt(cursor.getColumnIndex("sum_time")); practices_counter = practices_counter + (int) cursor.getFloat(cursor.getColumnIndex("count_practices")); i++; cursor.moveToNext(); } String activity_query_part = ""; if (activity > 0) activity_query_part = " AND category_id = '" + activity + "'"; if (between_dates_query_part.length() > 0) { cursor = DBManager.CustomQuery(getString(R.string.routes_with_hr), "SELECT avg_hr FROM routes WHERE avg_hr > 0 AND " + between_dates_query_part + activity_query_part); } else { cursor = DBManager.CustomQuery(getString(R.string.routes_with_hr), "SELECT avg_hr FROM routes WHERE avg_hr > 0" + activity_query_part); } cursor.moveToFirst(); if (cursor.getCount() > 0) { while (!cursor.isAfterLast()) { sum_avg_hr = sum_avg_hr + cursor.getInt(cursor.getColumnIndex("avg_hr")); hr_practices_counter += 1; cursor.moveToNext(); } } text8.setText(""); if (between_dates_query_part.length() > 0) { if (activity > 0) activity_query_part = " AND category_id = '" + activity + "' "; cursor = DBManager.CustomQuery(getString(R.string.selecting_most_used_shoes), "SELECT shoe_id, COUNT(shoe_id) AS count_shoes " + "FROM routes " + "WHERE " + between_dates_query_part + activity_query_part + "GROUP BY shoe_id " + "ORDER BY count_shoes DESC"); } else { if (activity > 0) activity_query_part = "WHERE category_id = '" + activity + "' "; cursor = DBManager.CustomQuery(getString(R.string.selecting_most_used_shoes_in_data_range), "SELECT shoe_id, COUNT(shoe_id) AS count_shoes " + "FROM routes " + activity_query_part + "GROUP BY shoe_id " + "ORDER BY count_shoes DESC"); } cursor.moveToFirst(); if (cursor.getCount() > 0) { int shoe = cursor.getInt(cursor.getColumnIndex("shoe_id")); if (cursor.getCount() > 1) { int[] shoes = new int[cursor.getCount()]; int m = 0; while (!cursor.isAfterLast()) { shoes[m] = cursor.getInt(cursor.getColumnIndex("shoe_id")); m++; cursor.moveToNext(); } if (shoe == 0 && shoes.length > 1) shoe = shoes[1]; } if (shoe > 0) { cursor = DBManager.CustomQuery(getString(R.string.shoe_name), "SELECT name FROM shoes WHERE _id = '" + shoe + "'"); cursor.moveToFirst(); text8.setText(cursor.getString(cursor.getColumnIndex("name"))); } } text1.setText(String.valueOf(practices_counter)); text2.setText(String.valueOf(FunctionUtils.statisticsFormatTime(mContext, (long) sum_time))); text3.setText(isMetric ? String.valueOf(FunctionUtils.customizedRound(sum_distance, 2)) + " " + getString(R.string.long_unit1_detail_1) : String.valueOf(FunctionUtils.customizedRound(((sum_distance * 1000f) / 1609f), 2)) + " " + getString(R.string.long_unit2_detail_1)); text4.setText( isMetric ? String.valueOf(sum_up_accum_altitude) + " " + getString(R.string.long_unit1_detail_4) : String.valueOf((int) (sum_up_accum_altitude * 1.0936f)) + " " + getString(R.string.long_unit2_detail_4)); text5.setText(isMetric ? String.valueOf(sum_down_accum_altitude) + " " + getString(R.string.long_unit1_detail_4) : String.valueOf((int) (sum_down_accum_altitude * 1.0936f)) + " " + getString(R.string.long_unit2_detail_4)); if ((sum_avg_speed > 0) && (practices_counter > 0)) { text6.setText((isMetric ? String.valueOf(FunctionUtils.customizedRound((sum_avg_speed / practices_counter), 2)) + " " + getString(R.string.long_unit1_detail_2) : String.valueOf(FunctionUtils .customizedRound((((sum_avg_speed * 1000f) / 1609f) / practices_counter), 2)) + " " + getString(R.string.long_unit2_detail_2))); } else { text6.setText( getString(R.string.zero_value) + " " + (isMetric ? getString(R.string.long_unit1_detail_2) : mContext.getString(R.string.long_unit2_detail_2))); } text7.setText(String.valueOf( FunctionUtils.calculateRitm(mContext, sum_time, String.valueOf(sum_distance), isMetric, false)) + " " + (isMetric ? getString(R.string.long_unit1_detail_3) : mContext.getString(R.string.long_unit2_detail_3))); text9.setText(String.valueOf(sum_kcal) + " " + getString(R.string.tell_calories_setting_details)); text10.setText(String.valueOf(sum_steps)); if ((sum_avg_hr > 0) && (hr_practices_counter > 0)) { text11.setText(String.valueOf(sum_avg_hr / hr_practices_counter) + " " + getString(R.string.beats_per_minute)); } else { text11.setText(getString(R.string.zero_value) + " " + getString(R.string.beats_per_minute)); } if (sum_kcal > 0) { text12.setText(String.valueOf(sum_kcal / Constants.CHEESE_BURGER)); } else { text12.setText(getString(R.string.zero_value)); } if (sum_distance > 0) { text13.setText(String.valueOf( FunctionUtils.customizedRound((sum_distance / Constants.ALL_THE_WAY_AROUND_THE_WORLD), 3))); } else { text13.setText(getString(R.string.zero_with_three_decimal_places_value)); } if (sum_distance > 0) { double moon_distance = ((double) sum_distance) / ((double) Constants.TO_THE_MOON); text14.setText(String.valueOf( FunctionUtils.customizedRound(Float.parseFloat(String.valueOf(moon_distance)), 1))); } else { text14.setText(getString(R.string.zero_with_one_decimal_place_value)); } layout1.removeAllViews(); layout2.removeAllViews(); layout3.removeAllViews(); mChartView1 = null; mChartView2 = null; mChartView3 = null; for (int h = 0; h < distance_distribution.length; h++) { float percent = 0; if (distance_distribution[h] > 0) percent = (distance_distribution[h] * 100) / sum_distance; if (sum_distance == 0) percent = 100 / distance_distribution.length; distance_distribution[h] = percent; } for (int b = 0; b < kcal_distribution.length; b++) { int percent = 0; if (sum_kcal > 0) percent = (kcal_distribution[b] * 100) / sum_kcal; if (sum_kcal == 0) percent = 100 / kcal_distribution.length; kcal_distribution[b] = percent; } final CategorySeries distance_distributionSeries = new CategorySeries(""); for (int g = 0; g < distance_distribution.length; g++) { if (distance_distribution.length == 1) { distance_distributionSeries.add("", 100); } else { distance_distributionSeries.add("", distance_distribution[g]); } } final CategorySeries kcal_distributionSeries = new CategorySeries(""); for (int p = 0; p < kcal_distribution.length; p++) { if (kcal_distribution.length == 1) { kcal_distributionSeries.add("", 100); } else { kcal_distributionSeries.add("", kcal_distribution[p]); } } final CategorySeries time_distributionSeries = new CategorySeries(""); for (int l = 0; l < time_distribution.length; l++) { if (time_distribution.length == 1) { time_distributionSeries.add("", 100); } else { time_distributionSeries.add("", time_distribution[l]); } } DefaultRenderer defaultRenderer = new DefaultRenderer(); DefaultRenderer defaultRenderer2 = new DefaultRenderer(); DefaultRenderer defaultRenderer3 = new DefaultRenderer(); defaultRenderer.setShowLabels(false); defaultRenderer.setZoomButtonsVisible(false); defaultRenderer.setStartAngle(180); defaultRenderer.setDisplayValues(false); defaultRenderer.setClickEnabled(true); defaultRenderer.setInScroll(true); defaultRenderer.setShowLegend(false); defaultRenderer2.setShowLabels(false); defaultRenderer2.setZoomButtonsVisible(false); defaultRenderer2.setStartAngle(180); defaultRenderer2.setDisplayValues(false); defaultRenderer2.setClickEnabled(true); defaultRenderer2.setInScroll(true); defaultRenderer2.setShowLegend(false); defaultRenderer3.setShowLabels(false); defaultRenderer3.setZoomButtonsVisible(false); defaultRenderer3.setStartAngle(180); defaultRenderer3.setDisplayValues(false); defaultRenderer3.setClickEnabled(true); defaultRenderer3.setInScroll(true); defaultRenderer3.setShowLegend(false); for (int u = 0; u < distance_distribution.length; u++) { SimpleSeriesRenderer seriesRenderer = new SimpleSeriesRenderer(); seriesRenderer.setColor(colors[u]); seriesRenderer.setDisplayChartValues(true); seriesRenderer.setHighlighted(false); defaultRenderer.addSeriesRenderer(seriesRenderer); } for (int p = 0; p < kcal_distribution.length; p++) { SimpleSeriesRenderer seriesRenderer2 = new SimpleSeriesRenderer(); seriesRenderer2.setColor(colors[p]); seriesRenderer2.setDisplayChartValues(true); seriesRenderer2.setHighlighted(false); defaultRenderer2.addSeriesRenderer(seriesRenderer2); } for (int o = 0; o < distance_distribution.length; o++) { SimpleSeriesRenderer seriesRenderer3 = new SimpleSeriesRenderer(); seriesRenderer3.setColor(colors[o]); seriesRenderer3.setDisplayChartValues(true); seriesRenderer3.setHighlighted(false); defaultRenderer3.addSeriesRenderer(seriesRenderer3); } mChartView1 = ChartFactory.getPieChartView(mContext, distance_distributionSeries, defaultRenderer); mChartView2 = ChartFactory.getPieChartView(mContext, kcal_distributionSeries, defaultRenderer2); mChartView3 = ChartFactory.getPieChartView(mContext, time_distributionSeries, defaultRenderer3); layout1.addView(mChartView1); layout2.addView(mChartView2); layout3.addView(mChartView3); } else { base_layout.setVisibility(View.INVISIBLE); scrollView.setVisibility(View.INVISIBLE); layout1.setVisibility(View.INVISIBLE); layout2.setVisibility(View.INVISIBLE); layout3.setVisibility(View.INVISIBLE); layout4.setVisibility(View.INVISIBLE); } cursor.close(); DBManager.Close(); }